1 /* 2 * Copyright 2007-8 Advanced Micro Devices, Inc. 3 * Copyright 2008 Red Hat Inc. 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 shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 * OTHER DEALINGS IN THE SOFTWARE. 22 * 23 * Authors: Dave Airlie 24 * Alex Deucher 25 */ 26 27 #include <drm/display/drm_dp_mst_helper.h> 28 #include <drm/drm_edid.h> 29 #include <drm/drm_crtc_helper.h> 30 #include <drm/drm_modeset_helper_vtables.h> 31 #include <drm/drm_probe_helper.h> 32 #include <drm/radeon_drm.h> 33 #include "radeon.h" 34 #include "radeon_audio.h" 35 #include "atom.h" 36 37 #include <linux/pm_runtime.h> 38 #include <linux/vga_switcheroo.h> 39 40 void radeon_connector_hotplug(struct drm_connector *connector) 41 { 42 struct drm_device *dev = connector->dev; 43 struct radeon_device *rdev = dev->dev_private; 44 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 45 46 /* bail if the connector does not have hpd pin, e.g., 47 * VGA, TV, etc. 48 */ 49 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) 50 return; 51 52 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd); 53 54 /* if the connector is already off, don't turn it back on */ 55 /* FIXME: This access isn't protected by any locks. */ 56 if (connector->dpms != DRM_MODE_DPMS_ON) 57 return; 58 59 /* just deal with DP (not eDP) here. */ 60 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) { 61 struct radeon_connector_atom_dig *dig_connector = 62 radeon_connector->con_priv; 63 64 /* if existing sink type was not DP no need to retrain */ 65 if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT) 66 return; 67 68 /* first get sink type as it may be reset after (un)plug */ 69 dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector); 70 /* don't do anything if sink is not display port, i.e., 71 * passive dp->(dvi|hdmi) adaptor 72 */ 73 if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT && 74 radeon_hpd_sense(rdev, radeon_connector->hpd.hpd) && 75 radeon_dp_needs_link_train(radeon_connector)) { 76 /* Don't start link training before we have the DPCD */ 77 if (!radeon_dp_getdpcd(radeon_connector)) 78 return; 79 80 /* Turn the connector off and back on immediately, which 81 * will trigger link training 82 */ 83 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF); 84 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON); 85 } 86 } 87 } 88 89 static void radeon_property_change_mode(struct drm_encoder *encoder) 90 { 91 struct drm_crtc *crtc = encoder->crtc; 92 93 if (crtc && crtc->enabled) { 94 drm_crtc_helper_set_mode(crtc, &crtc->mode, 95 crtc->x, crtc->y, crtc->primary->fb); 96 } 97 } 98 99 int radeon_get_monitor_bpc(struct drm_connector *connector) 100 { 101 struct drm_device *dev = connector->dev; 102 struct radeon_device *rdev = dev->dev_private; 103 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 104 struct radeon_connector_atom_dig *dig_connector; 105 int bpc = 8; 106 int mode_clock, max_tmds_clock; 107 108 switch (connector->connector_type) { 109 case DRM_MODE_CONNECTOR_DVII: 110 case DRM_MODE_CONNECTOR_HDMIB: 111 if (radeon_connector->use_digital) { 112 if (connector->display_info.is_hdmi) { 113 if (connector->display_info.bpc) 114 bpc = connector->display_info.bpc; 115 } 116 } 117 break; 118 case DRM_MODE_CONNECTOR_DVID: 119 case DRM_MODE_CONNECTOR_HDMIA: 120 if (connector->display_info.is_hdmi) { 121 if (connector->display_info.bpc) 122 bpc = connector->display_info.bpc; 123 } 124 break; 125 case DRM_MODE_CONNECTOR_DisplayPort: 126 dig_connector = radeon_connector->con_priv; 127 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) || 128 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) || 129 connector->display_info.is_hdmi) { 130 if (connector->display_info.bpc) 131 bpc = connector->display_info.bpc; 132 } 133 break; 134 case DRM_MODE_CONNECTOR_eDP: 135 case DRM_MODE_CONNECTOR_LVDS: 136 if (connector->display_info.bpc) 137 bpc = connector->display_info.bpc; 138 else if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) { 139 const struct drm_connector_helper_funcs *connector_funcs = 140 connector->helper_private; 141 struct drm_encoder *encoder = connector_funcs->best_encoder(connector); 142 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 143 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 144 145 if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR) 146 bpc = 6; 147 else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR) 148 bpc = 8; 149 } 150 break; 151 } 152 153 if (connector->display_info.is_hdmi) { 154 /* hdmi deep color only implemented on DCE4+ */ 155 if ((bpc > 8) && !ASIC_IS_DCE4(rdev)) { 156 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 8 bpc.\n", 157 connector->name, bpc); 158 bpc = 8; 159 } 160 161 /* 162 * Pre DCE-8 hw can't handle > 12 bpc, and more than 12 bpc doesn't make 163 * much sense without support for > 12 bpc framebuffers. RGB 4:4:4 at 164 * 12 bpc is always supported on hdmi deep color sinks, as this is 165 * required by the HDMI-1.3 spec. Clamp to a safe 12 bpc maximum. 166 */ 167 if (bpc > 12) { 168 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 12 bpc.\n", 169 connector->name, bpc); 170 bpc = 12; 171 } 172 173 /* Any defined maximum tmds clock limit we must not exceed? */ 174 if (connector->display_info.max_tmds_clock > 0) { 175 /* mode_clock is clock in kHz for mode to be modeset on this connector */ 176 mode_clock = radeon_connector->pixelclock_for_modeset; 177 178 /* Maximum allowable input clock in kHz */ 179 max_tmds_clock = connector->display_info.max_tmds_clock; 180 181 DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds input clock %d kHz.\n", 182 connector->name, mode_clock, max_tmds_clock); 183 184 /* Check if bpc is within clock limit. Try to degrade gracefully otherwise */ 185 if ((bpc == 12) && (mode_clock * 3/2 > max_tmds_clock)) { 186 if ((connector->display_info.edid_hdmi_rgb444_dc_modes & DRM_EDID_HDMI_DC_30) && 187 (mode_clock * 5/4 <= max_tmds_clock)) 188 bpc = 10; 189 else 190 bpc = 8; 191 192 DRM_DEBUG("%s: HDMI deep color 12 bpc exceeds max tmds clock. Using %d bpc.\n", 193 connector->name, bpc); 194 } 195 196 if ((bpc == 10) && (mode_clock * 5/4 > max_tmds_clock)) { 197 bpc = 8; 198 DRM_DEBUG("%s: HDMI deep color 10 bpc exceeds max tmds clock. Using %d bpc.\n", 199 connector->name, bpc); 200 } 201 } else if (bpc > 8) { 202 /* max_tmds_clock missing, but hdmi spec mandates it for deep color. */ 203 DRM_DEBUG("%s: Required max tmds clock for HDMI deep color missing. Using 8 bpc.\n", 204 connector->name); 205 bpc = 8; 206 } 207 } 208 209 if ((radeon_deep_color == 0) && (bpc > 8)) { 210 DRM_DEBUG("%s: Deep color disabled. Set radeon module param deep_color=1 to enable.\n", 211 connector->name); 212 bpc = 8; 213 } 214 215 DRM_DEBUG("%s: Display bpc=%d, returned bpc=%d\n", 216 connector->name, connector->display_info.bpc, bpc); 217 218 return bpc; 219 } 220 221 static void 222 radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status) 223 { 224 struct drm_device *dev = connector->dev; 225 struct radeon_device *rdev = dev->dev_private; 226 struct drm_encoder *best_encoder; 227 struct drm_encoder *encoder; 228 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private; 229 bool connected; 230 231 best_encoder = connector_funcs->best_encoder(connector); 232 233 drm_connector_for_each_possible_encoder(connector, encoder) { 234 if ((encoder == best_encoder) && (status == connector_status_connected)) 235 connected = true; 236 else 237 connected = false; 238 239 if (rdev->is_atom_bios) 240 radeon_atombios_connected_scratch_regs(connector, encoder, connected); 241 else 242 radeon_combios_connected_scratch_regs(connector, encoder, connected); 243 } 244 } 245 246 static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type) 247 { 248 struct drm_encoder *encoder; 249 250 drm_connector_for_each_possible_encoder(connector, encoder) { 251 if (encoder->encoder_type == encoder_type) 252 return encoder; 253 } 254 255 return NULL; 256 } 257 258 static void radeon_connector_get_edid(struct drm_connector *connector) 259 { 260 struct drm_device *dev = connector->dev; 261 struct radeon_device *rdev = dev->dev_private; 262 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 263 264 if (radeon_connector->edid) 265 return; 266 267 /* on hw with routers, select right port */ 268 if (radeon_connector->router.ddc_valid) 269 radeon_router_select_ddc_port(radeon_connector); 270 271 if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) != 272 ENCODER_OBJECT_ID_NONE) && 273 radeon_connector->ddc_bus->has_aux) { 274 radeon_connector->edid = drm_get_edid(connector, 275 &radeon_connector->ddc_bus->aux.ddc); 276 } else if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) || 277 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) { 278 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv; 279 280 if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT || 281 dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) && 282 radeon_connector->ddc_bus->has_aux) 283 radeon_connector->edid = drm_get_edid(&radeon_connector->base, 284 &radeon_connector->ddc_bus->aux.ddc); 285 else if (radeon_connector->ddc_bus) 286 radeon_connector->edid = drm_get_edid(&radeon_connector->base, 287 &radeon_connector->ddc_bus->adapter); 288 } else if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC && 289 connector->connector_type == DRM_MODE_CONNECTOR_LVDS && 290 radeon_connector->ddc_bus) { 291 radeon_connector->edid = drm_get_edid_switcheroo(&radeon_connector->base, 292 &radeon_connector->ddc_bus->adapter); 293 } else if (radeon_connector->ddc_bus) { 294 radeon_connector->edid = drm_get_edid(&radeon_connector->base, 295 &radeon_connector->ddc_bus->adapter); 296 } 297 298 if (!radeon_connector->edid) { 299 /* don't fetch the edid from the vbios if ddc fails and runpm is 300 * enabled so we report disconnected. 301 */ 302 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0)) 303 return; 304 305 if (rdev->is_atom_bios) { 306 /* some laptops provide a hardcoded edid in rom for LCDs */ 307 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) || 308 (connector->connector_type == DRM_MODE_CONNECTOR_eDP))) 309 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev); 310 } else { 311 /* some servers provide a hardcoded edid in rom for KVMs */ 312 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev); 313 } 314 } 315 } 316 317 static void radeon_connector_free_edid(struct drm_connector *connector) 318 { 319 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 320 321 kfree(radeon_connector->edid); 322 radeon_connector->edid = NULL; 323 } 324 325 static int radeon_ddc_get_modes(struct drm_connector *connector) 326 { 327 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 328 int ret; 329 330 if (radeon_connector->edid) { 331 drm_connector_update_edid_property(connector, radeon_connector->edid); 332 ret = drm_add_edid_modes(connector, radeon_connector->edid); 333 return ret; 334 } 335 drm_connector_update_edid_property(connector, NULL); 336 return 0; 337 } 338 339 static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector) 340 { 341 struct drm_encoder *encoder; 342 343 /* pick the first one */ 344 drm_connector_for_each_possible_encoder(connector, encoder) 345 return encoder; 346 347 return NULL; 348 } 349 350 static void radeon_get_native_mode(struct drm_connector *connector) 351 { 352 struct drm_encoder *encoder = radeon_best_single_encoder(connector); 353 struct radeon_encoder *radeon_encoder; 354 355 if (encoder == NULL) 356 return; 357 358 radeon_encoder = to_radeon_encoder(encoder); 359 360 if (!list_empty(&connector->probed_modes)) { 361 struct drm_display_mode *preferred_mode = 362 list_first_entry(&connector->probed_modes, 363 struct drm_display_mode, head); 364 365 radeon_encoder->native_mode = *preferred_mode; 366 } else { 367 radeon_encoder->native_mode.clock = 0; 368 } 369 } 370 371 /* 372 * radeon_connector_analog_encoder_conflict_solve 373 * - search for other connectors sharing this encoder 374 * if priority is true, then set them disconnected if this is connected 375 * if priority is false, set us disconnected if they are connected 376 */ 377 static enum drm_connector_status 378 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector, 379 struct drm_encoder *encoder, 380 enum drm_connector_status current_status, 381 bool priority) 382 { 383 struct drm_device *dev = connector->dev; 384 struct drm_connector *conflict; 385 struct radeon_connector *radeon_conflict; 386 387 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) { 388 struct drm_encoder *enc; 389 390 if (conflict == connector) 391 continue; 392 393 radeon_conflict = to_radeon_connector(conflict); 394 395 drm_connector_for_each_possible_encoder(conflict, enc) { 396 /* if the IDs match */ 397 if (enc == encoder) { 398 if (conflict->status != connector_status_connected) 399 continue; 400 401 if (radeon_conflict->use_digital) 402 continue; 403 404 if (priority) { 405 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n", 406 conflict->name); 407 DRM_DEBUG_KMS("in favor of %s\n", 408 connector->name); 409 conflict->status = connector_status_disconnected; 410 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected); 411 } else { 412 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n", 413 connector->name); 414 DRM_DEBUG_KMS("in favor of %s\n", 415 conflict->name); 416 current_status = connector_status_disconnected; 417 } 418 break; 419 } 420 } 421 } 422 return current_status; 423 424 } 425 426 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder) 427 { 428 struct drm_device *dev = encoder->dev; 429 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 430 struct drm_display_mode *mode = NULL; 431 struct drm_display_mode *native_mode = &radeon_encoder->native_mode; 432 433 if (native_mode->hdisplay != 0 && 434 native_mode->vdisplay != 0 && 435 native_mode->clock != 0) { 436 mode = drm_mode_duplicate(dev, native_mode); 437 if (!mode) 438 return NULL; 439 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER; 440 drm_mode_set_name(mode); 441 442 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name); 443 } else if (native_mode->hdisplay != 0 && 444 native_mode->vdisplay != 0) { 445 /* mac laptops without an edid */ 446 /* Note that this is not necessarily the exact panel mode, 447 * but an approximation based on the cvt formula. For these 448 * systems we should ideally read the mode info out of the 449 * registers or add a mode table, but this works and is much 450 * simpler. 451 */ 452 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false); 453 if (!mode) 454 return NULL; 455 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER; 456 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name); 457 } 458 return mode; 459 } 460 461 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector) 462 { 463 struct drm_device *dev = encoder->dev; 464 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 465 struct drm_display_mode *mode = NULL; 466 struct drm_display_mode *native_mode = &radeon_encoder->native_mode; 467 int i; 468 struct mode_size { 469 int w; 470 int h; 471 } common_modes[17] = { 472 { 640, 480}, 473 { 720, 480}, 474 { 800, 600}, 475 { 848, 480}, 476 {1024, 768}, 477 {1152, 768}, 478 {1280, 720}, 479 {1280, 800}, 480 {1280, 854}, 481 {1280, 960}, 482 {1280, 1024}, 483 {1440, 900}, 484 {1400, 1050}, 485 {1680, 1050}, 486 {1600, 1200}, 487 {1920, 1080}, 488 {1920, 1200} 489 }; 490 491 for (i = 0; i < 17; i++) { 492 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) { 493 if (common_modes[i].w > 1024 || 494 common_modes[i].h > 768) 495 continue; 496 } 497 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 498 if (common_modes[i].w > native_mode->hdisplay || 499 common_modes[i].h > native_mode->vdisplay || 500 (common_modes[i].w == native_mode->hdisplay && 501 common_modes[i].h == native_mode->vdisplay)) 502 continue; 503 } 504 if (common_modes[i].w < 320 || common_modes[i].h < 200) 505 continue; 506 507 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false); 508 if (!mode) 509 continue; 510 511 drm_mode_probed_add(connector, mode); 512 } 513 } 514 515 static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property, 516 uint64_t val) 517 { 518 struct drm_device *dev = connector->dev; 519 struct radeon_device *rdev = dev->dev_private; 520 struct drm_encoder *encoder; 521 struct radeon_encoder *radeon_encoder; 522 523 if (property == rdev->mode_info.coherent_mode_property) { 524 struct radeon_encoder_atom_dig *dig; 525 bool new_coherent_mode; 526 527 /* need to find digital encoder on connector */ 528 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS); 529 if (!encoder) 530 return 0; 531 532 radeon_encoder = to_radeon_encoder(encoder); 533 534 if (!radeon_encoder->enc_priv) 535 return 0; 536 537 dig = radeon_encoder->enc_priv; 538 new_coherent_mode = val ? true : false; 539 if (dig->coherent_mode != new_coherent_mode) { 540 dig->coherent_mode = new_coherent_mode; 541 radeon_property_change_mode(&radeon_encoder->base); 542 } 543 } 544 545 if (property == rdev->mode_info.audio_property) { 546 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 547 /* need to find digital encoder on connector */ 548 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS); 549 if (!encoder) 550 return 0; 551 552 radeon_encoder = to_radeon_encoder(encoder); 553 554 if (radeon_connector->audio != val) { 555 radeon_connector->audio = val; 556 radeon_property_change_mode(&radeon_encoder->base); 557 } 558 } 559 560 if (property == rdev->mode_info.dither_property) { 561 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 562 /* need to find digital encoder on connector */ 563 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS); 564 if (!encoder) 565 return 0; 566 567 radeon_encoder = to_radeon_encoder(encoder); 568 569 if (radeon_connector->dither != val) { 570 radeon_connector->dither = val; 571 radeon_property_change_mode(&radeon_encoder->base); 572 } 573 } 574 575 if (property == rdev->mode_info.underscan_property) { 576 /* need to find digital encoder on connector */ 577 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS); 578 if (!encoder) 579 return 0; 580 581 radeon_encoder = to_radeon_encoder(encoder); 582 583 if (radeon_encoder->underscan_type != val) { 584 radeon_encoder->underscan_type = val; 585 radeon_property_change_mode(&radeon_encoder->base); 586 } 587 } 588 589 if (property == rdev->mode_info.underscan_hborder_property) { 590 /* need to find digital encoder on connector */ 591 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS); 592 if (!encoder) 593 return 0; 594 595 radeon_encoder = to_radeon_encoder(encoder); 596 597 if (radeon_encoder->underscan_hborder != val) { 598 radeon_encoder->underscan_hborder = val; 599 radeon_property_change_mode(&radeon_encoder->base); 600 } 601 } 602 603 if (property == rdev->mode_info.underscan_vborder_property) { 604 /* need to find digital encoder on connector */ 605 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS); 606 if (!encoder) 607 return 0; 608 609 radeon_encoder = to_radeon_encoder(encoder); 610 611 if (radeon_encoder->underscan_vborder != val) { 612 radeon_encoder->underscan_vborder = val; 613 radeon_property_change_mode(&radeon_encoder->base); 614 } 615 } 616 617 if (property == rdev->mode_info.tv_std_property) { 618 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC); 619 if (!encoder) { 620 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC); 621 } 622 623 if (!encoder) 624 return 0; 625 626 radeon_encoder = to_radeon_encoder(encoder); 627 if (!radeon_encoder->enc_priv) 628 return 0; 629 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) { 630 struct radeon_encoder_atom_dac *dac_int; 631 dac_int = radeon_encoder->enc_priv; 632 dac_int->tv_std = val; 633 } else { 634 struct radeon_encoder_tv_dac *dac_int; 635 dac_int = radeon_encoder->enc_priv; 636 dac_int->tv_std = val; 637 } 638 radeon_property_change_mode(&radeon_encoder->base); 639 } 640 641 if (property == rdev->mode_info.load_detect_property) { 642 struct radeon_connector *radeon_connector = 643 to_radeon_connector(connector); 644 645 if (val == 0) 646 radeon_connector->dac_load_detect = false; 647 else 648 radeon_connector->dac_load_detect = true; 649 } 650 651 if (property == rdev->mode_info.tmds_pll_property) { 652 struct radeon_encoder_int_tmds *tmds = NULL; 653 bool ret = false; 654 /* need to find digital encoder on connector */ 655 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS); 656 if (!encoder) 657 return 0; 658 659 radeon_encoder = to_radeon_encoder(encoder); 660 661 tmds = radeon_encoder->enc_priv; 662 if (!tmds) 663 return 0; 664 665 if (val == 0) { 666 if (rdev->is_atom_bios) 667 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds); 668 else 669 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds); 670 } 671 if (val == 1 || !ret) 672 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds); 673 674 radeon_property_change_mode(&radeon_encoder->base); 675 } 676 677 if (property == dev->mode_config.scaling_mode_property) { 678 enum radeon_rmx_type rmx_type; 679 680 if (connector->encoder) 681 radeon_encoder = to_radeon_encoder(connector->encoder); 682 else { 683 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private; 684 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector)); 685 } 686 687 switch (val) { 688 default: 689 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break; 690 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break; 691 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break; 692 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break; 693 } 694 if (radeon_encoder->rmx_type == rmx_type) 695 return 0; 696 697 if ((rmx_type != DRM_MODE_SCALE_NONE) && 698 (radeon_encoder->native_mode.clock == 0)) 699 return 0; 700 701 radeon_encoder->rmx_type = rmx_type; 702 703 radeon_property_change_mode(&radeon_encoder->base); 704 } 705 706 if (property == rdev->mode_info.output_csc_property) { 707 if (connector->encoder) 708 radeon_encoder = to_radeon_encoder(connector->encoder); 709 else { 710 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private; 711 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector)); 712 } 713 714 if (radeon_encoder->output_csc == val) 715 return 0; 716 717 radeon_encoder->output_csc = val; 718 719 if (connector->encoder && connector->encoder->crtc) { 720 struct drm_crtc *crtc = connector->encoder->crtc; 721 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 722 723 radeon_crtc->output_csc = radeon_encoder->output_csc; 724 725 /* 726 * Our .gamma_set assumes the .gamma_store has been 727 * prefilled and don't care about its arguments. 728 */ 729 crtc->funcs->gamma_set(crtc, NULL, NULL, NULL, 0, NULL); 730 } 731 } 732 733 return 0; 734 } 735 736 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder, 737 struct drm_connector *connector) 738 { 739 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 740 struct drm_display_mode *native_mode = &radeon_encoder->native_mode; 741 struct drm_display_mode *t, *mode; 742 743 /* If the EDID preferred mode doesn't match the native mode, use it */ 744 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) { 745 if (mode->type & DRM_MODE_TYPE_PREFERRED) { 746 if (mode->hdisplay != native_mode->hdisplay || 747 mode->vdisplay != native_mode->vdisplay) 748 drm_mode_copy(native_mode, mode); 749 } 750 } 751 752 /* Try to get native mode details from EDID if necessary */ 753 if (!native_mode->clock) { 754 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) { 755 if (mode->hdisplay == native_mode->hdisplay && 756 mode->vdisplay == native_mode->vdisplay) { 757 drm_mode_copy(native_mode, mode); 758 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V); 759 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n"); 760 break; 761 } 762 } 763 } 764 765 if (!native_mode->clock) { 766 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n"); 767 radeon_encoder->rmx_type = RMX_OFF; 768 } 769 } 770 771 static int radeon_lvds_get_modes(struct drm_connector *connector) 772 { 773 struct drm_encoder *encoder; 774 int ret = 0; 775 struct drm_display_mode *mode; 776 777 radeon_connector_get_edid(connector); 778 ret = radeon_ddc_get_modes(connector); 779 if (ret > 0) { 780 encoder = radeon_best_single_encoder(connector); 781 if (encoder) { 782 radeon_fixup_lvds_native_mode(encoder, connector); 783 /* add scaled modes */ 784 radeon_add_common_modes(encoder, connector); 785 } 786 return ret; 787 } 788 789 encoder = radeon_best_single_encoder(connector); 790 if (!encoder) 791 return 0; 792 793 /* we have no EDID modes */ 794 mode = radeon_fp_native_mode(encoder); 795 if (mode) { 796 ret = 1; 797 drm_mode_probed_add(connector, mode); 798 /* add the width/height from vbios tables if available */ 799 connector->display_info.width_mm = mode->width_mm; 800 connector->display_info.height_mm = mode->height_mm; 801 /* add scaled modes */ 802 radeon_add_common_modes(encoder, connector); 803 } 804 805 return ret; 806 } 807 808 static enum drm_mode_status radeon_lvds_mode_valid(struct drm_connector *connector, 809 struct drm_display_mode *mode) 810 { 811 struct drm_encoder *encoder = radeon_best_single_encoder(connector); 812 813 if ((mode->hdisplay < 320) || (mode->vdisplay < 240)) 814 return MODE_PANEL; 815 816 if (encoder) { 817 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 818 struct drm_display_mode *native_mode = &radeon_encoder->native_mode; 819 820 /* AVIVO hardware supports downscaling modes larger than the panel 821 * to the panel size, but I'm not sure this is desirable. 822 */ 823 if ((mode->hdisplay > native_mode->hdisplay) || 824 (mode->vdisplay > native_mode->vdisplay)) 825 return MODE_PANEL; 826 827 /* if scaling is disabled, block non-native modes */ 828 if (radeon_encoder->rmx_type == RMX_OFF) { 829 if ((mode->hdisplay != native_mode->hdisplay) || 830 (mode->vdisplay != native_mode->vdisplay)) 831 return MODE_PANEL; 832 } 833 } 834 835 return MODE_OK; 836 } 837 838 static enum drm_connector_status 839 radeon_lvds_detect(struct drm_connector *connector, bool force) 840 { 841 struct drm_device *dev = connector->dev; 842 struct radeon_device *rdev = dev->dev_private; 843 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 844 struct drm_encoder *encoder = radeon_best_single_encoder(connector); 845 enum drm_connector_status ret = connector_status_disconnected; 846 int r; 847 848 if (!drm_kms_helper_is_poll_worker()) { 849 r = pm_runtime_get_sync(connector->dev->dev); 850 if (r < 0) { 851 pm_runtime_put_autosuspend(connector->dev->dev); 852 return connector_status_disconnected; 853 } 854 } 855 856 if (encoder) { 857 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 858 struct drm_display_mode *native_mode = &radeon_encoder->native_mode; 859 860 /* check if panel is valid */ 861 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240) 862 ret = connector_status_connected; 863 /* don't fetch the edid from the vbios if ddc fails and runpm is 864 * enabled so we report disconnected. 865 */ 866 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0)) 867 ret = connector_status_disconnected; 868 } 869 870 /* check for edid as well */ 871 radeon_connector_get_edid(connector); 872 if (radeon_connector->edid) 873 ret = connector_status_connected; 874 /* check acpi lid status ??? */ 875 876 radeon_connector_update_scratch_regs(connector, ret); 877 878 if (!drm_kms_helper_is_poll_worker()) { 879 pm_runtime_mark_last_busy(connector->dev->dev); 880 pm_runtime_put_autosuspend(connector->dev->dev); 881 } 882 883 return ret; 884 } 885 886 static void radeon_connector_unregister(struct drm_connector *connector) 887 { 888 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 889 890 if (radeon_connector->ddc_bus && radeon_connector->ddc_bus->has_aux) { 891 drm_dp_aux_unregister(&radeon_connector->ddc_bus->aux); 892 radeon_connector->ddc_bus->has_aux = false; 893 } 894 } 895 896 static void radeon_connector_destroy(struct drm_connector *connector) 897 { 898 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 899 900 radeon_connector_free_edid(connector); 901 kfree(radeon_connector->con_priv); 902 drm_connector_unregister(connector); 903 drm_connector_cleanup(connector); 904 kfree(connector); 905 } 906 907 static int radeon_lvds_set_property(struct drm_connector *connector, 908 struct drm_property *property, 909 uint64_t value) 910 { 911 struct drm_device *dev = connector->dev; 912 struct radeon_encoder *radeon_encoder; 913 enum radeon_rmx_type rmx_type; 914 915 DRM_DEBUG_KMS("\n"); 916 if (property != dev->mode_config.scaling_mode_property) 917 return 0; 918 919 if (connector->encoder) 920 radeon_encoder = to_radeon_encoder(connector->encoder); 921 else { 922 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private; 923 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector)); 924 } 925 926 switch (value) { 927 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break; 928 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break; 929 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break; 930 default: 931 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break; 932 } 933 if (radeon_encoder->rmx_type == rmx_type) 934 return 0; 935 936 radeon_encoder->rmx_type = rmx_type; 937 938 radeon_property_change_mode(&radeon_encoder->base); 939 return 0; 940 } 941 942 943 static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = { 944 .get_modes = radeon_lvds_get_modes, 945 .mode_valid = radeon_lvds_mode_valid, 946 .best_encoder = radeon_best_single_encoder, 947 }; 948 949 static const struct drm_connector_funcs radeon_lvds_connector_funcs = { 950 .dpms = drm_helper_connector_dpms, 951 .detect = radeon_lvds_detect, 952 .fill_modes = drm_helper_probe_single_connector_modes, 953 .early_unregister = radeon_connector_unregister, 954 .destroy = radeon_connector_destroy, 955 .set_property = radeon_lvds_set_property, 956 }; 957 958 static int radeon_vga_get_modes(struct drm_connector *connector) 959 { 960 int ret; 961 962 radeon_connector_get_edid(connector); 963 ret = radeon_ddc_get_modes(connector); 964 965 radeon_get_native_mode(connector); 966 967 return ret; 968 } 969 970 static enum drm_mode_status radeon_vga_mode_valid(struct drm_connector *connector, 971 struct drm_display_mode *mode) 972 { 973 struct drm_device *dev = connector->dev; 974 struct radeon_device *rdev = dev->dev_private; 975 976 /* XXX check mode bandwidth */ 977 978 if ((mode->clock / 10) > rdev->clock.max_pixel_clock) 979 return MODE_CLOCK_HIGH; 980 981 return MODE_OK; 982 } 983 984 static enum drm_connector_status 985 radeon_vga_detect(struct drm_connector *connector, bool force) 986 { 987 struct drm_device *dev = connector->dev; 988 struct radeon_device *rdev = dev->dev_private; 989 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 990 struct drm_encoder *encoder; 991 const struct drm_encoder_helper_funcs *encoder_funcs; 992 bool dret = false; 993 enum drm_connector_status ret = connector_status_disconnected; 994 int r; 995 996 if (!drm_kms_helper_is_poll_worker()) { 997 r = pm_runtime_get_sync(connector->dev->dev); 998 if (r < 0) { 999 pm_runtime_put_autosuspend(connector->dev->dev); 1000 return connector_status_disconnected; 1001 } 1002 } 1003 1004 encoder = radeon_best_single_encoder(connector); 1005 if (!encoder) 1006 ret = connector_status_disconnected; 1007 1008 if (radeon_connector->ddc_bus) 1009 dret = radeon_ddc_probe(radeon_connector, false); 1010 if (dret) { 1011 radeon_connector->detected_by_load = false; 1012 radeon_connector_free_edid(connector); 1013 radeon_connector_get_edid(connector); 1014 1015 if (!radeon_connector->edid) { 1016 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n", 1017 connector->name); 1018 ret = connector_status_connected; 1019 } else { 1020 radeon_connector->use_digital = 1021 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL); 1022 1023 /* some oems have boards with separate digital and analog connectors 1024 * with a shared ddc line (often vga + hdmi) 1025 */ 1026 if (radeon_connector->use_digital && radeon_connector->shared_ddc) { 1027 radeon_connector_free_edid(connector); 1028 ret = connector_status_disconnected; 1029 } else { 1030 ret = connector_status_connected; 1031 } 1032 } 1033 } else { 1034 1035 /* if we aren't forcing don't do destructive polling */ 1036 if (!force) { 1037 /* only return the previous status if we last 1038 * detected a monitor via load. 1039 */ 1040 if (radeon_connector->detected_by_load) 1041 ret = connector->status; 1042 goto out; 1043 } 1044 1045 if (radeon_connector->dac_load_detect && encoder) { 1046 encoder_funcs = encoder->helper_private; 1047 ret = encoder_funcs->detect(encoder, connector); 1048 if (ret != connector_status_disconnected) 1049 radeon_connector->detected_by_load = true; 1050 } 1051 } 1052 1053 if (ret == connector_status_connected) 1054 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true); 1055 1056 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the 1057 * vbios to deal with KVMs. If we have one and are not able to detect a monitor 1058 * by other means, assume the CRT is connected and use that EDID. 1059 */ 1060 if ((!rdev->is_atom_bios) && 1061 (ret == connector_status_disconnected) && 1062 rdev->mode_info.bios_hardcoded_edid) { 1063 ret = connector_status_connected; 1064 } 1065 1066 radeon_connector_update_scratch_regs(connector, ret); 1067 1068 out: 1069 if (!drm_kms_helper_is_poll_worker()) { 1070 pm_runtime_mark_last_busy(connector->dev->dev); 1071 pm_runtime_put_autosuspend(connector->dev->dev); 1072 } 1073 1074 return ret; 1075 } 1076 1077 static const struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = { 1078 .get_modes = radeon_vga_get_modes, 1079 .mode_valid = radeon_vga_mode_valid, 1080 .best_encoder = radeon_best_single_encoder, 1081 }; 1082 1083 static const struct drm_connector_funcs radeon_vga_connector_funcs = { 1084 .dpms = drm_helper_connector_dpms, 1085 .detect = radeon_vga_detect, 1086 .fill_modes = drm_helper_probe_single_connector_modes, 1087 .early_unregister = radeon_connector_unregister, 1088 .destroy = radeon_connector_destroy, 1089 .set_property = radeon_connector_set_property, 1090 }; 1091 1092 static int radeon_tv_get_modes(struct drm_connector *connector) 1093 { 1094 struct drm_device *dev = connector->dev; 1095 struct radeon_device *rdev = dev->dev_private; 1096 struct drm_display_mode *tv_mode; 1097 struct drm_encoder *encoder; 1098 1099 encoder = radeon_best_single_encoder(connector); 1100 if (!encoder) 1101 return 0; 1102 1103 /* avivo chips can scale any mode */ 1104 if (rdev->family >= CHIP_RS600) 1105 /* add scaled modes */ 1106 radeon_add_common_modes(encoder, connector); 1107 else { 1108 /* only 800x600 is supported right now on pre-avivo chips */ 1109 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false); 1110 if (!tv_mode) 1111 return 0; 1112 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; 1113 drm_mode_probed_add(connector, tv_mode); 1114 } 1115 return 1; 1116 } 1117 1118 static enum drm_mode_status radeon_tv_mode_valid(struct drm_connector *connector, 1119 struct drm_display_mode *mode) 1120 { 1121 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768)) 1122 return MODE_CLOCK_RANGE; 1123 return MODE_OK; 1124 } 1125 1126 static enum drm_connector_status 1127 radeon_tv_detect(struct drm_connector *connector, bool force) 1128 { 1129 struct drm_encoder *encoder; 1130 const struct drm_encoder_helper_funcs *encoder_funcs; 1131 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1132 enum drm_connector_status ret = connector_status_disconnected; 1133 int r; 1134 1135 if (!radeon_connector->dac_load_detect) 1136 return ret; 1137 1138 if (!drm_kms_helper_is_poll_worker()) { 1139 r = pm_runtime_get_sync(connector->dev->dev); 1140 if (r < 0) { 1141 pm_runtime_put_autosuspend(connector->dev->dev); 1142 return connector_status_disconnected; 1143 } 1144 } 1145 1146 encoder = radeon_best_single_encoder(connector); 1147 if (!encoder) 1148 ret = connector_status_disconnected; 1149 else { 1150 encoder_funcs = encoder->helper_private; 1151 ret = encoder_funcs->detect(encoder, connector); 1152 } 1153 if (ret == connector_status_connected) 1154 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false); 1155 radeon_connector_update_scratch_regs(connector, ret); 1156 1157 if (!drm_kms_helper_is_poll_worker()) { 1158 pm_runtime_mark_last_busy(connector->dev->dev); 1159 pm_runtime_put_autosuspend(connector->dev->dev); 1160 } 1161 1162 return ret; 1163 } 1164 1165 static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = { 1166 .get_modes = radeon_tv_get_modes, 1167 .mode_valid = radeon_tv_mode_valid, 1168 .best_encoder = radeon_best_single_encoder, 1169 }; 1170 1171 static const struct drm_connector_funcs radeon_tv_connector_funcs = { 1172 .dpms = drm_helper_connector_dpms, 1173 .detect = radeon_tv_detect, 1174 .fill_modes = drm_helper_probe_single_connector_modes, 1175 .early_unregister = radeon_connector_unregister, 1176 .destroy = radeon_connector_destroy, 1177 .set_property = radeon_connector_set_property, 1178 }; 1179 1180 static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector) 1181 { 1182 struct drm_device *dev = connector->dev; 1183 struct radeon_device *rdev = dev->dev_private; 1184 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1185 enum drm_connector_status status; 1186 1187 /* We only trust HPD on R600 and newer ASICS. */ 1188 if (rdev->family >= CHIP_R600 1189 && radeon_connector->hpd.hpd != RADEON_HPD_NONE) { 1190 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) 1191 status = connector_status_connected; 1192 else 1193 status = connector_status_disconnected; 1194 if (connector->status == status) 1195 return true; 1196 } 1197 1198 return false; 1199 } 1200 1201 /* 1202 * DVI is complicated 1203 * Do a DDC probe, if DDC probe passes, get the full EDID so 1204 * we can do analog/digital monitor detection at this point. 1205 * If the monitor is an analog monitor or we got no DDC, 1206 * we need to find the DAC encoder object for this connector. 1207 * If we got no DDC, we do load detection on the DAC encoder object. 1208 * If we got analog DDC or load detection passes on the DAC encoder 1209 * we have to check if this analog encoder is shared with anyone else (TV) 1210 * if its shared we have to set the other connector to disconnected. 1211 */ 1212 static enum drm_connector_status 1213 radeon_dvi_detect(struct drm_connector *connector, bool force) 1214 { 1215 struct drm_device *dev = connector->dev; 1216 struct radeon_device *rdev = dev->dev_private; 1217 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1218 struct drm_encoder *encoder = NULL; 1219 const struct drm_encoder_helper_funcs *encoder_funcs; 1220 int r; 1221 enum drm_connector_status ret = connector_status_disconnected; 1222 bool dret = false, broken_edid = false; 1223 1224 if (!drm_kms_helper_is_poll_worker()) { 1225 r = pm_runtime_get_sync(connector->dev->dev); 1226 if (r < 0) { 1227 pm_runtime_put_autosuspend(connector->dev->dev); 1228 return connector_status_disconnected; 1229 } 1230 } 1231 1232 if (radeon_connector->detected_hpd_without_ddc) { 1233 force = true; 1234 radeon_connector->detected_hpd_without_ddc = false; 1235 } 1236 1237 if (!force && radeon_check_hpd_status_unchanged(connector)) { 1238 ret = connector->status; 1239 goto exit; 1240 } 1241 1242 if (radeon_connector->ddc_bus) { 1243 dret = radeon_ddc_probe(radeon_connector, false); 1244 1245 /* Sometimes the pins required for the DDC probe on DVI 1246 * connectors don't make contact at the same time that the ones 1247 * for HPD do. If the DDC probe fails even though we had an HPD 1248 * signal, try again later */ 1249 if (!dret && !force && 1250 connector->status != connector_status_connected) { 1251 DRM_DEBUG_KMS("hpd detected without ddc, retrying in 1 second\n"); 1252 radeon_connector->detected_hpd_without_ddc = true; 1253 schedule_delayed_work(&rdev->hotplug_work, 1254 msecs_to_jiffies(1000)); 1255 goto exit; 1256 } 1257 } 1258 1259 if (dret && radeon_connector->hpd.hpd != RADEON_HPD_NONE && 1260 !radeon_hpd_sense(rdev, radeon_connector->hpd.hpd) && 1261 connector->connector_type == DRM_MODE_CONNECTOR_HDMIA) { 1262 DRM_DEBUG_KMS("EDID is readable when HPD disconnected\n"); 1263 schedule_delayed_work(&rdev->hotplug_work, msecs_to_jiffies(1000)); 1264 ret = connector_status_disconnected; 1265 goto exit; 1266 } 1267 1268 if (dret) { 1269 radeon_connector->detected_by_load = false; 1270 radeon_connector_free_edid(connector); 1271 radeon_connector_get_edid(connector); 1272 1273 if (!radeon_connector->edid) { 1274 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n", 1275 connector->name); 1276 /* rs690 seems to have a problem with connectors not existing and always 1277 * return a block of 0's. If we see this just stop polling on this output */ 1278 if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) && 1279 radeon_connector->base.null_edid_counter) { 1280 ret = connector_status_disconnected; 1281 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n", 1282 connector->name); 1283 radeon_connector->ddc_bus = NULL; 1284 } else { 1285 ret = connector_status_connected; 1286 broken_edid = true; /* defer use_digital to later */ 1287 } 1288 } else { 1289 radeon_connector->use_digital = 1290 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL); 1291 1292 /* some oems have boards with separate digital and analog connectors 1293 * with a shared ddc line (often vga + hdmi) 1294 */ 1295 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) { 1296 radeon_connector_free_edid(connector); 1297 ret = connector_status_disconnected; 1298 } else { 1299 ret = connector_status_connected; 1300 } 1301 /* This gets complicated. We have boards with VGA + HDMI with a 1302 * shared DDC line and we have boards with DVI-D + HDMI with a shared 1303 * DDC line. The latter is more complex because with DVI<->HDMI adapters 1304 * you don't really know what's connected to which port as both are digital. 1305 */ 1306 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) { 1307 struct drm_connector *list_connector; 1308 struct radeon_connector *list_radeon_connector; 1309 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) { 1310 if (connector == list_connector) 1311 continue; 1312 list_radeon_connector = to_radeon_connector(list_connector); 1313 if (list_radeon_connector->shared_ddc && 1314 (list_radeon_connector->ddc_bus->rec.i2c_id == 1315 radeon_connector->ddc_bus->rec.i2c_id)) { 1316 /* cases where both connectors are digital */ 1317 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) { 1318 /* hpd is our only option in this case */ 1319 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) { 1320 radeon_connector_free_edid(connector); 1321 ret = connector_status_disconnected; 1322 } 1323 } 1324 } 1325 } 1326 } 1327 } 1328 } 1329 1330 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true)) 1331 goto out; 1332 1333 /* DVI-D and HDMI-A are digital only */ 1334 if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) || 1335 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA)) 1336 goto out; 1337 1338 /* if we aren't forcing don't do destructive polling */ 1339 if (!force) { 1340 /* only return the previous status if we last 1341 * detected a monitor via load. 1342 */ 1343 if (radeon_connector->detected_by_load) 1344 ret = connector->status; 1345 goto out; 1346 } 1347 1348 /* find analog encoder */ 1349 if (radeon_connector->dac_load_detect) { 1350 drm_connector_for_each_possible_encoder(connector, encoder) { 1351 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC && 1352 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC) 1353 continue; 1354 1355 encoder_funcs = encoder->helper_private; 1356 if (encoder_funcs->detect) { 1357 if (!broken_edid) { 1358 if (ret != connector_status_connected) { 1359 /* deal with analog monitors without DDC */ 1360 ret = encoder_funcs->detect(encoder, connector); 1361 if (ret == connector_status_connected) { 1362 radeon_connector->use_digital = false; 1363 } 1364 if (ret != connector_status_disconnected) 1365 radeon_connector->detected_by_load = true; 1366 } 1367 } else { 1368 enum drm_connector_status lret; 1369 /* assume digital unless load detected otherwise */ 1370 radeon_connector->use_digital = true; 1371 lret = encoder_funcs->detect(encoder, connector); 1372 DRM_DEBUG_KMS("load_detect %x returned: %x\n", encoder->encoder_type, lret); 1373 if (lret == connector_status_connected) 1374 radeon_connector->use_digital = false; 1375 } 1376 break; 1377 } 1378 } 1379 } 1380 1381 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) && 1382 encoder) { 1383 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true); 1384 } 1385 1386 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the 1387 * vbios to deal with KVMs. If we have one and are not able to detect a monitor 1388 * by other means, assume the DFP is connected and use that EDID. In most 1389 * cases the DVI port is actually a virtual KVM port connected to the service 1390 * processor. 1391 */ 1392 out: 1393 if ((!rdev->is_atom_bios) && 1394 (ret == connector_status_disconnected) && 1395 rdev->mode_info.bios_hardcoded_edid) { 1396 radeon_connector->use_digital = true; 1397 ret = connector_status_connected; 1398 } 1399 1400 /* updated in get modes as well since we need to know if it's analog or digital */ 1401 radeon_connector_update_scratch_regs(connector, ret); 1402 1403 if ((radeon_audio != 0) && radeon_connector->use_digital) { 1404 const struct drm_connector_helper_funcs *connector_funcs = 1405 connector->helper_private; 1406 1407 encoder = connector_funcs->best_encoder(connector); 1408 if (encoder && (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)) { 1409 radeon_connector_get_edid(connector); 1410 radeon_audio_detect(connector, encoder, ret); 1411 } 1412 } 1413 1414 exit: 1415 if (!drm_kms_helper_is_poll_worker()) { 1416 pm_runtime_mark_last_busy(connector->dev->dev); 1417 pm_runtime_put_autosuspend(connector->dev->dev); 1418 } 1419 1420 return ret; 1421 } 1422 1423 /* okay need to be smart in here about which encoder to pick */ 1424 static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector) 1425 { 1426 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1427 struct drm_encoder *encoder; 1428 1429 drm_connector_for_each_possible_encoder(connector, encoder) { 1430 if (radeon_connector->use_digital == true) { 1431 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS) 1432 return encoder; 1433 } else { 1434 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC || 1435 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC) 1436 return encoder; 1437 } 1438 } 1439 1440 /* see if we have a default encoder TODO */ 1441 1442 /* then check use digitial */ 1443 /* pick the first one */ 1444 drm_connector_for_each_possible_encoder(connector, encoder) 1445 return encoder; 1446 1447 return NULL; 1448 } 1449 1450 static void radeon_dvi_force(struct drm_connector *connector) 1451 { 1452 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1453 if (connector->force == DRM_FORCE_ON) 1454 radeon_connector->use_digital = false; 1455 if (connector->force == DRM_FORCE_ON_DIGITAL) 1456 radeon_connector->use_digital = true; 1457 } 1458 1459 static enum drm_mode_status radeon_dvi_mode_valid(struct drm_connector *connector, 1460 struct drm_display_mode *mode) 1461 { 1462 struct drm_device *dev = connector->dev; 1463 struct radeon_device *rdev = dev->dev_private; 1464 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1465 1466 /* XXX check mode bandwidth */ 1467 1468 /* clocks over 135 MHz have heat issues with DVI on RV100 */ 1469 if (radeon_connector->use_digital && 1470 (rdev->family == CHIP_RV100) && 1471 (mode->clock > 135000)) 1472 return MODE_CLOCK_HIGH; 1473 1474 if (radeon_connector->use_digital && (mode->clock > 165000)) { 1475 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) || 1476 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) || 1477 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B)) 1478 return MODE_OK; 1479 else if (ASIC_IS_DCE6(rdev) && connector->display_info.is_hdmi) { 1480 /* HDMI 1.3+ supports max clock of 340 Mhz */ 1481 if (mode->clock > 340000) 1482 return MODE_CLOCK_HIGH; 1483 else 1484 return MODE_OK; 1485 } else { 1486 return MODE_CLOCK_HIGH; 1487 } 1488 } 1489 1490 /* check against the max pixel clock */ 1491 if ((mode->clock / 10) > rdev->clock.max_pixel_clock) 1492 return MODE_CLOCK_HIGH; 1493 1494 return MODE_OK; 1495 } 1496 1497 static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = { 1498 .get_modes = radeon_vga_get_modes, 1499 .mode_valid = radeon_dvi_mode_valid, 1500 .best_encoder = radeon_dvi_encoder, 1501 }; 1502 1503 static const struct drm_connector_funcs radeon_dvi_connector_funcs = { 1504 .dpms = drm_helper_connector_dpms, 1505 .detect = radeon_dvi_detect, 1506 .fill_modes = drm_helper_probe_single_connector_modes, 1507 .set_property = radeon_connector_set_property, 1508 .early_unregister = radeon_connector_unregister, 1509 .destroy = radeon_connector_destroy, 1510 .force = radeon_dvi_force, 1511 }; 1512 1513 static int radeon_dp_get_modes(struct drm_connector *connector) 1514 { 1515 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1516 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv; 1517 struct drm_encoder *encoder = radeon_best_single_encoder(connector); 1518 int ret; 1519 1520 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) || 1521 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) { 1522 struct drm_display_mode *mode; 1523 1524 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) { 1525 if (!radeon_dig_connector->edp_on) 1526 atombios_set_edp_panel_power(connector, 1527 ATOM_TRANSMITTER_ACTION_POWER_ON); 1528 radeon_connector_get_edid(connector); 1529 ret = radeon_ddc_get_modes(connector); 1530 if (!radeon_dig_connector->edp_on) 1531 atombios_set_edp_panel_power(connector, 1532 ATOM_TRANSMITTER_ACTION_POWER_OFF); 1533 } else { 1534 /* need to setup ddc on the bridge */ 1535 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) != 1536 ENCODER_OBJECT_ID_NONE) { 1537 if (encoder) 1538 radeon_atom_ext_encoder_setup_ddc(encoder); 1539 } 1540 radeon_connector_get_edid(connector); 1541 ret = radeon_ddc_get_modes(connector); 1542 } 1543 1544 if (ret > 0) { 1545 if (encoder) { 1546 radeon_fixup_lvds_native_mode(encoder, connector); 1547 /* add scaled modes */ 1548 radeon_add_common_modes(encoder, connector); 1549 } 1550 return ret; 1551 } 1552 1553 if (!encoder) 1554 return 0; 1555 1556 /* we have no EDID modes */ 1557 mode = radeon_fp_native_mode(encoder); 1558 if (mode) { 1559 ret = 1; 1560 drm_mode_probed_add(connector, mode); 1561 /* add the width/height from vbios tables if available */ 1562 connector->display_info.width_mm = mode->width_mm; 1563 connector->display_info.height_mm = mode->height_mm; 1564 /* add scaled modes */ 1565 radeon_add_common_modes(encoder, connector); 1566 } 1567 } else { 1568 /* need to setup ddc on the bridge */ 1569 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) != 1570 ENCODER_OBJECT_ID_NONE) { 1571 if (encoder) 1572 radeon_atom_ext_encoder_setup_ddc(encoder); 1573 } 1574 radeon_connector_get_edid(connector); 1575 ret = radeon_ddc_get_modes(connector); 1576 1577 radeon_get_native_mode(connector); 1578 } 1579 1580 return ret; 1581 } 1582 1583 u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector) 1584 { 1585 struct drm_encoder *encoder; 1586 struct radeon_encoder *radeon_encoder; 1587 1588 drm_connector_for_each_possible_encoder(connector, encoder) { 1589 radeon_encoder = to_radeon_encoder(encoder); 1590 1591 switch (radeon_encoder->encoder_id) { 1592 case ENCODER_OBJECT_ID_TRAVIS: 1593 case ENCODER_OBJECT_ID_NUTMEG: 1594 return radeon_encoder->encoder_id; 1595 default: 1596 break; 1597 } 1598 } 1599 1600 return ENCODER_OBJECT_ID_NONE; 1601 } 1602 1603 static bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector) 1604 { 1605 struct drm_encoder *encoder; 1606 struct radeon_encoder *radeon_encoder; 1607 bool found = false; 1608 1609 drm_connector_for_each_possible_encoder(connector, encoder) { 1610 radeon_encoder = to_radeon_encoder(encoder); 1611 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2) 1612 found = true; 1613 } 1614 1615 return found; 1616 } 1617 1618 bool radeon_connector_is_dp12_capable(struct drm_connector *connector) 1619 { 1620 struct drm_device *dev = connector->dev; 1621 struct radeon_device *rdev = dev->dev_private; 1622 1623 if (ASIC_IS_DCE5(rdev) && 1624 (rdev->clock.default_dispclk >= 53900) && 1625 radeon_connector_encoder_is_hbr2(connector)) { 1626 return true; 1627 } 1628 1629 return false; 1630 } 1631 1632 static enum drm_connector_status 1633 radeon_dp_detect(struct drm_connector *connector, bool force) 1634 { 1635 struct drm_device *dev = connector->dev; 1636 struct radeon_device *rdev = dev->dev_private; 1637 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1638 enum drm_connector_status ret = connector_status_disconnected; 1639 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv; 1640 struct drm_encoder *encoder = radeon_best_single_encoder(connector); 1641 int r; 1642 1643 if (!drm_kms_helper_is_poll_worker()) { 1644 r = pm_runtime_get_sync(connector->dev->dev); 1645 if (r < 0) { 1646 pm_runtime_put_autosuspend(connector->dev->dev); 1647 return connector_status_disconnected; 1648 } 1649 } 1650 1651 if (!force && radeon_check_hpd_status_unchanged(connector)) { 1652 ret = connector->status; 1653 goto out; 1654 } 1655 1656 radeon_connector_free_edid(connector); 1657 1658 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) || 1659 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) { 1660 if (encoder) { 1661 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1662 struct drm_display_mode *native_mode = &radeon_encoder->native_mode; 1663 1664 /* check if panel is valid */ 1665 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240) 1666 ret = connector_status_connected; 1667 /* don't fetch the edid from the vbios if ddc fails and runpm is 1668 * enabled so we report disconnected. 1669 */ 1670 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0)) 1671 ret = connector_status_disconnected; 1672 } 1673 /* eDP is always DP */ 1674 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT; 1675 if (!radeon_dig_connector->edp_on) 1676 atombios_set_edp_panel_power(connector, 1677 ATOM_TRANSMITTER_ACTION_POWER_ON); 1678 if (radeon_dp_getdpcd(radeon_connector)) 1679 ret = connector_status_connected; 1680 if (!radeon_dig_connector->edp_on) 1681 atombios_set_edp_panel_power(connector, 1682 ATOM_TRANSMITTER_ACTION_POWER_OFF); 1683 } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) != 1684 ENCODER_OBJECT_ID_NONE) { 1685 /* DP bridges are always DP */ 1686 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT; 1687 /* get the DPCD from the bridge */ 1688 radeon_dp_getdpcd(radeon_connector); 1689 1690 if (encoder) { 1691 /* setup ddc on the bridge */ 1692 radeon_atom_ext_encoder_setup_ddc(encoder); 1693 /* bridge chips are always aux */ 1694 if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */ 1695 ret = connector_status_connected; 1696 else if (radeon_connector->dac_load_detect) { /* try load detection */ 1697 const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; 1698 ret = encoder_funcs->detect(encoder, connector); 1699 } 1700 } 1701 } else { 1702 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector); 1703 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) { 1704 ret = connector_status_connected; 1705 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) 1706 radeon_dp_getdpcd(radeon_connector); 1707 } else { 1708 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) { 1709 if (radeon_dp_getdpcd(radeon_connector)) 1710 ret = connector_status_connected; 1711 } else { 1712 /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */ 1713 if (radeon_ddc_probe(radeon_connector, false)) 1714 ret = connector_status_connected; 1715 } 1716 } 1717 } 1718 1719 radeon_connector_update_scratch_regs(connector, ret); 1720 1721 if ((radeon_audio != 0) && encoder) { 1722 radeon_connector_get_edid(connector); 1723 radeon_audio_detect(connector, encoder, ret); 1724 } 1725 1726 out: 1727 if (!drm_kms_helper_is_poll_worker()) { 1728 pm_runtime_mark_last_busy(connector->dev->dev); 1729 pm_runtime_put_autosuspend(connector->dev->dev); 1730 } 1731 1732 return ret; 1733 } 1734 1735 static enum drm_mode_status radeon_dp_mode_valid(struct drm_connector *connector, 1736 struct drm_display_mode *mode) 1737 { 1738 struct drm_device *dev = connector->dev; 1739 struct radeon_device *rdev = dev->dev_private; 1740 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1741 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv; 1742 1743 /* XXX check mode bandwidth */ 1744 1745 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) || 1746 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) { 1747 struct drm_encoder *encoder = radeon_best_single_encoder(connector); 1748 1749 if ((mode->hdisplay < 320) || (mode->vdisplay < 240)) 1750 return MODE_PANEL; 1751 1752 if (encoder) { 1753 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1754 struct drm_display_mode *native_mode = &radeon_encoder->native_mode; 1755 1756 /* AVIVO hardware supports downscaling modes larger than the panel 1757 * to the panel size, but I'm not sure this is desirable. 1758 */ 1759 if ((mode->hdisplay > native_mode->hdisplay) || 1760 (mode->vdisplay > native_mode->vdisplay)) 1761 return MODE_PANEL; 1762 1763 /* if scaling is disabled, block non-native modes */ 1764 if (radeon_encoder->rmx_type == RMX_OFF) { 1765 if ((mode->hdisplay != native_mode->hdisplay) || 1766 (mode->vdisplay != native_mode->vdisplay)) 1767 return MODE_PANEL; 1768 } 1769 } 1770 } else { 1771 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) || 1772 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) { 1773 return radeon_dp_mode_valid_helper(connector, mode); 1774 } else { 1775 if (ASIC_IS_DCE6(rdev) && connector->display_info.is_hdmi) { 1776 /* HDMI 1.3+ supports max clock of 340 Mhz */ 1777 if (mode->clock > 340000) 1778 return MODE_CLOCK_HIGH; 1779 } else { 1780 if (mode->clock > 165000) 1781 return MODE_CLOCK_HIGH; 1782 } 1783 } 1784 } 1785 1786 return MODE_OK; 1787 } 1788 1789 static int 1790 radeon_connector_late_register(struct drm_connector *connector) 1791 { 1792 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1793 int r = 0; 1794 1795 if (radeon_connector->ddc_bus->has_aux) { 1796 radeon_connector->ddc_bus->aux.dev = radeon_connector->base.kdev; 1797 r = drm_dp_aux_register(&radeon_connector->ddc_bus->aux); 1798 } 1799 1800 return r; 1801 } 1802 1803 static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = { 1804 .get_modes = radeon_dp_get_modes, 1805 .mode_valid = radeon_dp_mode_valid, 1806 .best_encoder = radeon_dvi_encoder, 1807 }; 1808 1809 static const struct drm_connector_funcs radeon_dp_connector_funcs = { 1810 .dpms = drm_helper_connector_dpms, 1811 .detect = radeon_dp_detect, 1812 .fill_modes = drm_helper_probe_single_connector_modes, 1813 .set_property = radeon_connector_set_property, 1814 .early_unregister = radeon_connector_unregister, 1815 .destroy = radeon_connector_destroy, 1816 .force = radeon_dvi_force, 1817 .late_register = radeon_connector_late_register, 1818 }; 1819 1820 static const struct drm_connector_funcs radeon_edp_connector_funcs = { 1821 .dpms = drm_helper_connector_dpms, 1822 .detect = radeon_dp_detect, 1823 .fill_modes = drm_helper_probe_single_connector_modes, 1824 .set_property = radeon_lvds_set_property, 1825 .early_unregister = radeon_connector_unregister, 1826 .destroy = radeon_connector_destroy, 1827 .force = radeon_dvi_force, 1828 .late_register = radeon_connector_late_register, 1829 }; 1830 1831 static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = { 1832 .dpms = drm_helper_connector_dpms, 1833 .detect = radeon_dp_detect, 1834 .fill_modes = drm_helper_probe_single_connector_modes, 1835 .set_property = radeon_lvds_set_property, 1836 .early_unregister = radeon_connector_unregister, 1837 .destroy = radeon_connector_destroy, 1838 .force = radeon_dvi_force, 1839 .late_register = radeon_connector_late_register, 1840 }; 1841 1842 void 1843 radeon_add_atom_connector(struct drm_device *dev, 1844 uint32_t connector_id, 1845 uint32_t supported_device, 1846 int connector_type, 1847 struct radeon_i2c_bus_rec *i2c_bus, 1848 uint32_t igp_lane_info, 1849 uint16_t connector_object_id, 1850 struct radeon_hpd *hpd, 1851 struct radeon_router *router) 1852 { 1853 struct radeon_device *rdev = dev->dev_private; 1854 struct drm_connector *connector; 1855 struct radeon_connector *radeon_connector; 1856 struct radeon_connector_atom_dig *radeon_dig_connector; 1857 struct drm_encoder *encoder; 1858 struct radeon_encoder *radeon_encoder; 1859 struct i2c_adapter *ddc = NULL; 1860 uint32_t subpixel_order = SubPixelNone; 1861 bool shared_ddc = false; 1862 bool is_dp_bridge = false; 1863 bool has_aux = false; 1864 1865 if (connector_type == DRM_MODE_CONNECTOR_Unknown) 1866 return; 1867 1868 /* if the user selected tv=0 don't try and add the connector */ 1869 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) || 1870 (connector_type == DRM_MODE_CONNECTOR_Composite) || 1871 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) && 1872 (radeon_tv == 0)) 1873 return; 1874 1875 /* see if we already added it */ 1876 list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 1877 radeon_connector = to_radeon_connector(connector); 1878 if (radeon_connector->connector_id == connector_id) { 1879 radeon_connector->devices |= supported_device; 1880 return; 1881 } 1882 if (radeon_connector->ddc_bus && i2c_bus->valid) { 1883 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) { 1884 radeon_connector->shared_ddc = true; 1885 shared_ddc = true; 1886 } 1887 if (radeon_connector->router_bus && router->ddc_valid && 1888 (radeon_connector->router.router_id == router->router_id)) { 1889 radeon_connector->shared_ddc = false; 1890 shared_ddc = false; 1891 } 1892 } 1893 } 1894 1895 /* check if it's a dp bridge */ 1896 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 1897 radeon_encoder = to_radeon_encoder(encoder); 1898 if (radeon_encoder->devices & supported_device) { 1899 switch (radeon_encoder->encoder_id) { 1900 case ENCODER_OBJECT_ID_TRAVIS: 1901 case ENCODER_OBJECT_ID_NUTMEG: 1902 is_dp_bridge = true; 1903 break; 1904 default: 1905 break; 1906 } 1907 } 1908 } 1909 1910 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL); 1911 if (!radeon_connector) 1912 return; 1913 1914 connector = &radeon_connector->base; 1915 1916 radeon_connector->connector_id = connector_id; 1917 radeon_connector->devices = supported_device; 1918 radeon_connector->shared_ddc = shared_ddc; 1919 radeon_connector->connector_object_id = connector_object_id; 1920 radeon_connector->hpd = *hpd; 1921 1922 radeon_connector->router = *router; 1923 if (router->ddc_valid || router->cd_valid) { 1924 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info); 1925 if (!radeon_connector->router_bus) 1926 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n"); 1927 } 1928 1929 if (is_dp_bridge) { 1930 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL); 1931 if (!radeon_dig_connector) 1932 goto failed; 1933 radeon_dig_connector->igp_lane_info = igp_lane_info; 1934 radeon_connector->con_priv = radeon_dig_connector; 1935 if (i2c_bus->valid) { 1936 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 1937 if (radeon_connector->ddc_bus) { 1938 has_aux = true; 1939 ddc = &radeon_connector->ddc_bus->adapter; 1940 } else { 1941 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 1942 } 1943 } 1944 switch (connector_type) { 1945 case DRM_MODE_CONNECTOR_VGA: 1946 case DRM_MODE_CONNECTOR_DVIA: 1947 default: 1948 drm_connector_init_with_ddc(dev, &radeon_connector->base, 1949 &radeon_dp_connector_funcs, 1950 connector_type, 1951 ddc); 1952 drm_connector_helper_add(&radeon_connector->base, 1953 &radeon_dp_connector_helper_funcs); 1954 connector->interlace_allowed = true; 1955 connector->doublescan_allowed = true; 1956 radeon_connector->dac_load_detect = true; 1957 drm_object_attach_property(&radeon_connector->base.base, 1958 rdev->mode_info.load_detect_property, 1959 1); 1960 drm_object_attach_property(&radeon_connector->base.base, 1961 dev->mode_config.scaling_mode_property, 1962 DRM_MODE_SCALE_NONE); 1963 if (ASIC_IS_DCE5(rdev)) 1964 drm_object_attach_property(&radeon_connector->base.base, 1965 rdev->mode_info.output_csc_property, 1966 RADEON_OUTPUT_CSC_BYPASS); 1967 break; 1968 case DRM_MODE_CONNECTOR_DVII: 1969 case DRM_MODE_CONNECTOR_DVID: 1970 case DRM_MODE_CONNECTOR_HDMIA: 1971 case DRM_MODE_CONNECTOR_HDMIB: 1972 case DRM_MODE_CONNECTOR_DisplayPort: 1973 drm_connector_init_with_ddc(dev, &radeon_connector->base, 1974 &radeon_dp_connector_funcs, 1975 connector_type, 1976 ddc); 1977 drm_connector_helper_add(&radeon_connector->base, 1978 &radeon_dp_connector_helper_funcs); 1979 drm_object_attach_property(&radeon_connector->base.base, 1980 rdev->mode_info.underscan_property, 1981 UNDERSCAN_OFF); 1982 drm_object_attach_property(&radeon_connector->base.base, 1983 rdev->mode_info.underscan_hborder_property, 1984 0); 1985 drm_object_attach_property(&radeon_connector->base.base, 1986 rdev->mode_info.underscan_vborder_property, 1987 0); 1988 1989 drm_object_attach_property(&radeon_connector->base.base, 1990 dev->mode_config.scaling_mode_property, 1991 DRM_MODE_SCALE_NONE); 1992 1993 drm_object_attach_property(&radeon_connector->base.base, 1994 rdev->mode_info.dither_property, 1995 RADEON_FMT_DITHER_DISABLE); 1996 1997 if (radeon_audio != 0) { 1998 drm_object_attach_property(&radeon_connector->base.base, 1999 rdev->mode_info.audio_property, 2000 RADEON_AUDIO_AUTO); 2001 radeon_connector->audio = RADEON_AUDIO_AUTO; 2002 } 2003 if (ASIC_IS_DCE5(rdev)) 2004 drm_object_attach_property(&radeon_connector->base.base, 2005 rdev->mode_info.output_csc_property, 2006 RADEON_OUTPUT_CSC_BYPASS); 2007 2008 subpixel_order = SubPixelHorizontalRGB; 2009 connector->interlace_allowed = true; 2010 if (connector_type == DRM_MODE_CONNECTOR_HDMIB) 2011 connector->doublescan_allowed = true; 2012 else 2013 connector->doublescan_allowed = false; 2014 if (connector_type == DRM_MODE_CONNECTOR_DVII) { 2015 radeon_connector->dac_load_detect = true; 2016 drm_object_attach_property(&radeon_connector->base.base, 2017 rdev->mode_info.load_detect_property, 2018 1); 2019 } 2020 break; 2021 case DRM_MODE_CONNECTOR_LVDS: 2022 case DRM_MODE_CONNECTOR_eDP: 2023 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2024 &radeon_lvds_bridge_connector_funcs, 2025 connector_type, 2026 ddc); 2027 drm_connector_helper_add(&radeon_connector->base, 2028 &radeon_dp_connector_helper_funcs); 2029 drm_object_attach_property(&radeon_connector->base.base, 2030 dev->mode_config.scaling_mode_property, 2031 DRM_MODE_SCALE_FULLSCREEN); 2032 subpixel_order = SubPixelHorizontalRGB; 2033 connector->interlace_allowed = false; 2034 connector->doublescan_allowed = false; 2035 break; 2036 } 2037 } else { 2038 switch (connector_type) { 2039 case DRM_MODE_CONNECTOR_VGA: 2040 if (i2c_bus->valid) { 2041 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 2042 if (!radeon_connector->ddc_bus) 2043 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 2044 else 2045 ddc = &radeon_connector->ddc_bus->adapter; 2046 } 2047 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2048 &radeon_vga_connector_funcs, 2049 connector_type, 2050 ddc); 2051 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 2052 radeon_connector->dac_load_detect = true; 2053 drm_object_attach_property(&radeon_connector->base.base, 2054 rdev->mode_info.load_detect_property, 2055 1); 2056 if (ASIC_IS_AVIVO(rdev)) 2057 drm_object_attach_property(&radeon_connector->base.base, 2058 dev->mode_config.scaling_mode_property, 2059 DRM_MODE_SCALE_NONE); 2060 if (ASIC_IS_DCE5(rdev)) 2061 drm_object_attach_property(&radeon_connector->base.base, 2062 rdev->mode_info.output_csc_property, 2063 RADEON_OUTPUT_CSC_BYPASS); 2064 /* no HPD on analog connectors */ 2065 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 2066 connector->interlace_allowed = true; 2067 connector->doublescan_allowed = true; 2068 break; 2069 case DRM_MODE_CONNECTOR_DVIA: 2070 if (i2c_bus->valid) { 2071 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 2072 if (!radeon_connector->ddc_bus) 2073 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 2074 else 2075 ddc = &radeon_connector->ddc_bus->adapter; 2076 } 2077 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2078 &radeon_vga_connector_funcs, 2079 connector_type, 2080 ddc); 2081 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 2082 radeon_connector->dac_load_detect = true; 2083 drm_object_attach_property(&radeon_connector->base.base, 2084 rdev->mode_info.load_detect_property, 2085 1); 2086 if (ASIC_IS_AVIVO(rdev)) 2087 drm_object_attach_property(&radeon_connector->base.base, 2088 dev->mode_config.scaling_mode_property, 2089 DRM_MODE_SCALE_NONE); 2090 if (ASIC_IS_DCE5(rdev)) 2091 drm_object_attach_property(&radeon_connector->base.base, 2092 rdev->mode_info.output_csc_property, 2093 RADEON_OUTPUT_CSC_BYPASS); 2094 /* no HPD on analog connectors */ 2095 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 2096 connector->interlace_allowed = true; 2097 connector->doublescan_allowed = true; 2098 break; 2099 case DRM_MODE_CONNECTOR_DVII: 2100 case DRM_MODE_CONNECTOR_DVID: 2101 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL); 2102 if (!radeon_dig_connector) 2103 goto failed; 2104 radeon_dig_connector->igp_lane_info = igp_lane_info; 2105 radeon_connector->con_priv = radeon_dig_connector; 2106 if (i2c_bus->valid) { 2107 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 2108 if (!radeon_connector->ddc_bus) 2109 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 2110 else 2111 ddc = &radeon_connector->ddc_bus->adapter; 2112 } 2113 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2114 &radeon_dvi_connector_funcs, 2115 connector_type, 2116 ddc); 2117 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 2118 subpixel_order = SubPixelHorizontalRGB; 2119 drm_object_attach_property(&radeon_connector->base.base, 2120 rdev->mode_info.coherent_mode_property, 2121 1); 2122 if (ASIC_IS_AVIVO(rdev)) { 2123 drm_object_attach_property(&radeon_connector->base.base, 2124 rdev->mode_info.underscan_property, 2125 UNDERSCAN_OFF); 2126 drm_object_attach_property(&radeon_connector->base.base, 2127 rdev->mode_info.underscan_hborder_property, 2128 0); 2129 drm_object_attach_property(&radeon_connector->base.base, 2130 rdev->mode_info.underscan_vborder_property, 2131 0); 2132 drm_object_attach_property(&radeon_connector->base.base, 2133 rdev->mode_info.dither_property, 2134 RADEON_FMT_DITHER_DISABLE); 2135 drm_object_attach_property(&radeon_connector->base.base, 2136 dev->mode_config.scaling_mode_property, 2137 DRM_MODE_SCALE_NONE); 2138 } 2139 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) { 2140 drm_object_attach_property(&radeon_connector->base.base, 2141 rdev->mode_info.audio_property, 2142 RADEON_AUDIO_AUTO); 2143 radeon_connector->audio = RADEON_AUDIO_AUTO; 2144 } 2145 if (connector_type == DRM_MODE_CONNECTOR_DVII) { 2146 radeon_connector->dac_load_detect = true; 2147 drm_object_attach_property(&radeon_connector->base.base, 2148 rdev->mode_info.load_detect_property, 2149 1); 2150 } 2151 if (ASIC_IS_DCE5(rdev)) 2152 drm_object_attach_property(&radeon_connector->base.base, 2153 rdev->mode_info.output_csc_property, 2154 RADEON_OUTPUT_CSC_BYPASS); 2155 connector->interlace_allowed = true; 2156 if (connector_type == DRM_MODE_CONNECTOR_DVII) 2157 connector->doublescan_allowed = true; 2158 else 2159 connector->doublescan_allowed = false; 2160 break; 2161 case DRM_MODE_CONNECTOR_HDMIA: 2162 case DRM_MODE_CONNECTOR_HDMIB: 2163 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL); 2164 if (!radeon_dig_connector) 2165 goto failed; 2166 radeon_dig_connector->igp_lane_info = igp_lane_info; 2167 radeon_connector->con_priv = radeon_dig_connector; 2168 if (i2c_bus->valid) { 2169 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 2170 if (!radeon_connector->ddc_bus) 2171 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 2172 else 2173 ddc = &radeon_connector->ddc_bus->adapter; 2174 } 2175 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2176 &radeon_dvi_connector_funcs, 2177 connector_type, 2178 ddc); 2179 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 2180 drm_object_attach_property(&radeon_connector->base.base, 2181 rdev->mode_info.coherent_mode_property, 2182 1); 2183 if (ASIC_IS_AVIVO(rdev)) { 2184 drm_object_attach_property(&radeon_connector->base.base, 2185 rdev->mode_info.underscan_property, 2186 UNDERSCAN_OFF); 2187 drm_object_attach_property(&radeon_connector->base.base, 2188 rdev->mode_info.underscan_hborder_property, 2189 0); 2190 drm_object_attach_property(&radeon_connector->base.base, 2191 rdev->mode_info.underscan_vborder_property, 2192 0); 2193 drm_object_attach_property(&radeon_connector->base.base, 2194 rdev->mode_info.dither_property, 2195 RADEON_FMT_DITHER_DISABLE); 2196 drm_object_attach_property(&radeon_connector->base.base, 2197 dev->mode_config.scaling_mode_property, 2198 DRM_MODE_SCALE_NONE); 2199 } 2200 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) { 2201 drm_object_attach_property(&radeon_connector->base.base, 2202 rdev->mode_info.audio_property, 2203 RADEON_AUDIO_AUTO); 2204 radeon_connector->audio = RADEON_AUDIO_AUTO; 2205 } 2206 if (ASIC_IS_DCE5(rdev)) 2207 drm_object_attach_property(&radeon_connector->base.base, 2208 rdev->mode_info.output_csc_property, 2209 RADEON_OUTPUT_CSC_BYPASS); 2210 subpixel_order = SubPixelHorizontalRGB; 2211 connector->interlace_allowed = true; 2212 if (connector_type == DRM_MODE_CONNECTOR_HDMIB) 2213 connector->doublescan_allowed = true; 2214 else 2215 connector->doublescan_allowed = false; 2216 break; 2217 case DRM_MODE_CONNECTOR_DisplayPort: 2218 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL); 2219 if (!radeon_dig_connector) 2220 goto failed; 2221 radeon_dig_connector->igp_lane_info = igp_lane_info; 2222 radeon_connector->con_priv = radeon_dig_connector; 2223 if (i2c_bus->valid) { 2224 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 2225 if (radeon_connector->ddc_bus) { 2226 has_aux = true; 2227 ddc = &radeon_connector->ddc_bus->adapter; 2228 } else { 2229 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 2230 } 2231 } 2232 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2233 &radeon_dp_connector_funcs, 2234 connector_type, 2235 ddc); 2236 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs); 2237 subpixel_order = SubPixelHorizontalRGB; 2238 drm_object_attach_property(&radeon_connector->base.base, 2239 rdev->mode_info.coherent_mode_property, 2240 1); 2241 if (ASIC_IS_AVIVO(rdev)) { 2242 drm_object_attach_property(&radeon_connector->base.base, 2243 rdev->mode_info.underscan_property, 2244 UNDERSCAN_OFF); 2245 drm_object_attach_property(&radeon_connector->base.base, 2246 rdev->mode_info.underscan_hborder_property, 2247 0); 2248 drm_object_attach_property(&radeon_connector->base.base, 2249 rdev->mode_info.underscan_vborder_property, 2250 0); 2251 drm_object_attach_property(&radeon_connector->base.base, 2252 rdev->mode_info.dither_property, 2253 RADEON_FMT_DITHER_DISABLE); 2254 drm_object_attach_property(&radeon_connector->base.base, 2255 dev->mode_config.scaling_mode_property, 2256 DRM_MODE_SCALE_NONE); 2257 } 2258 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) { 2259 drm_object_attach_property(&radeon_connector->base.base, 2260 rdev->mode_info.audio_property, 2261 RADEON_AUDIO_AUTO); 2262 radeon_connector->audio = RADEON_AUDIO_AUTO; 2263 } 2264 if (ASIC_IS_DCE5(rdev)) 2265 drm_object_attach_property(&radeon_connector->base.base, 2266 rdev->mode_info.output_csc_property, 2267 RADEON_OUTPUT_CSC_BYPASS); 2268 connector->interlace_allowed = true; 2269 /* in theory with a DP to VGA converter... */ 2270 connector->doublescan_allowed = false; 2271 break; 2272 case DRM_MODE_CONNECTOR_eDP: 2273 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL); 2274 if (!radeon_dig_connector) 2275 goto failed; 2276 radeon_dig_connector->igp_lane_info = igp_lane_info; 2277 radeon_connector->con_priv = radeon_dig_connector; 2278 if (i2c_bus->valid) { 2279 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 2280 if (radeon_connector->ddc_bus) { 2281 has_aux = true; 2282 ddc = &radeon_connector->ddc_bus->adapter; 2283 } else { 2284 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 2285 } 2286 } 2287 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2288 &radeon_edp_connector_funcs, 2289 connector_type, 2290 ddc); 2291 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs); 2292 drm_object_attach_property(&radeon_connector->base.base, 2293 dev->mode_config.scaling_mode_property, 2294 DRM_MODE_SCALE_FULLSCREEN); 2295 subpixel_order = SubPixelHorizontalRGB; 2296 connector->interlace_allowed = false; 2297 connector->doublescan_allowed = false; 2298 break; 2299 case DRM_MODE_CONNECTOR_SVIDEO: 2300 case DRM_MODE_CONNECTOR_Composite: 2301 case DRM_MODE_CONNECTOR_9PinDIN: 2302 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2303 &radeon_tv_connector_funcs, 2304 connector_type, 2305 ddc); 2306 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs); 2307 radeon_connector->dac_load_detect = true; 2308 drm_object_attach_property(&radeon_connector->base.base, 2309 rdev->mode_info.load_detect_property, 2310 1); 2311 drm_object_attach_property(&radeon_connector->base.base, 2312 rdev->mode_info.tv_std_property, 2313 radeon_atombios_get_tv_info(rdev)); 2314 /* no HPD on analog connectors */ 2315 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 2316 connector->interlace_allowed = false; 2317 connector->doublescan_allowed = false; 2318 break; 2319 case DRM_MODE_CONNECTOR_LVDS: 2320 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL); 2321 if (!radeon_dig_connector) 2322 goto failed; 2323 radeon_dig_connector->igp_lane_info = igp_lane_info; 2324 radeon_connector->con_priv = radeon_dig_connector; 2325 if (i2c_bus->valid) { 2326 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 2327 if (!radeon_connector->ddc_bus) 2328 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 2329 else 2330 ddc = &radeon_connector->ddc_bus->adapter; 2331 } 2332 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2333 &radeon_lvds_connector_funcs, 2334 connector_type, 2335 ddc); 2336 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs); 2337 drm_object_attach_property(&radeon_connector->base.base, 2338 dev->mode_config.scaling_mode_property, 2339 DRM_MODE_SCALE_FULLSCREEN); 2340 subpixel_order = SubPixelHorizontalRGB; 2341 connector->interlace_allowed = false; 2342 connector->doublescan_allowed = false; 2343 break; 2344 } 2345 } 2346 2347 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) { 2348 if (i2c_bus->valid) { 2349 connector->polled = DRM_CONNECTOR_POLL_CONNECT | 2350 DRM_CONNECTOR_POLL_DISCONNECT; 2351 } 2352 } else 2353 connector->polled = DRM_CONNECTOR_POLL_HPD; 2354 2355 connector->display_info.subpixel_order = subpixel_order; 2356 drm_connector_register(connector); 2357 2358 if (has_aux) 2359 radeon_dp_aux_init(radeon_connector); 2360 2361 return; 2362 2363 failed: 2364 drm_connector_cleanup(connector); 2365 kfree(connector); 2366 } 2367 2368 void 2369 radeon_add_legacy_connector(struct drm_device *dev, 2370 uint32_t connector_id, 2371 uint32_t supported_device, 2372 int connector_type, 2373 struct radeon_i2c_bus_rec *i2c_bus, 2374 uint16_t connector_object_id, 2375 struct radeon_hpd *hpd) 2376 { 2377 struct radeon_device *rdev = dev->dev_private; 2378 struct drm_connector *connector; 2379 struct radeon_connector *radeon_connector; 2380 struct i2c_adapter *ddc = NULL; 2381 uint32_t subpixel_order = SubPixelNone; 2382 2383 if (connector_type == DRM_MODE_CONNECTOR_Unknown) 2384 return; 2385 2386 /* if the user selected tv=0 don't try and add the connector */ 2387 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) || 2388 (connector_type == DRM_MODE_CONNECTOR_Composite) || 2389 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) && 2390 (radeon_tv == 0)) 2391 return; 2392 2393 /* see if we already added it */ 2394 list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 2395 radeon_connector = to_radeon_connector(connector); 2396 if (radeon_connector->connector_id == connector_id) { 2397 radeon_connector->devices |= supported_device; 2398 return; 2399 } 2400 } 2401 2402 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL); 2403 if (!radeon_connector) 2404 return; 2405 2406 connector = &radeon_connector->base; 2407 2408 radeon_connector->connector_id = connector_id; 2409 radeon_connector->devices = supported_device; 2410 radeon_connector->connector_object_id = connector_object_id; 2411 radeon_connector->hpd = *hpd; 2412 2413 switch (connector_type) { 2414 case DRM_MODE_CONNECTOR_VGA: 2415 if (i2c_bus->valid) { 2416 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 2417 if (!radeon_connector->ddc_bus) 2418 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 2419 else 2420 ddc = &radeon_connector->ddc_bus->adapter; 2421 } 2422 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2423 &radeon_vga_connector_funcs, 2424 connector_type, 2425 ddc); 2426 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 2427 radeon_connector->dac_load_detect = true; 2428 drm_object_attach_property(&radeon_connector->base.base, 2429 rdev->mode_info.load_detect_property, 2430 1); 2431 /* no HPD on analog connectors */ 2432 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 2433 connector->interlace_allowed = true; 2434 connector->doublescan_allowed = true; 2435 break; 2436 case DRM_MODE_CONNECTOR_DVIA: 2437 if (i2c_bus->valid) { 2438 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 2439 if (!radeon_connector->ddc_bus) 2440 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 2441 else 2442 ddc = &radeon_connector->ddc_bus->adapter; 2443 } 2444 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2445 &radeon_vga_connector_funcs, 2446 connector_type, 2447 ddc); 2448 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 2449 radeon_connector->dac_load_detect = true; 2450 drm_object_attach_property(&radeon_connector->base.base, 2451 rdev->mode_info.load_detect_property, 2452 1); 2453 /* no HPD on analog connectors */ 2454 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 2455 connector->interlace_allowed = true; 2456 connector->doublescan_allowed = true; 2457 break; 2458 case DRM_MODE_CONNECTOR_DVII: 2459 case DRM_MODE_CONNECTOR_DVID: 2460 if (i2c_bus->valid) { 2461 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 2462 if (!radeon_connector->ddc_bus) 2463 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 2464 else 2465 ddc = &radeon_connector->ddc_bus->adapter; 2466 } 2467 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2468 &radeon_dvi_connector_funcs, 2469 connector_type, 2470 ddc); 2471 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 2472 if (connector_type == DRM_MODE_CONNECTOR_DVII) { 2473 radeon_connector->dac_load_detect = true; 2474 drm_object_attach_property(&radeon_connector->base.base, 2475 rdev->mode_info.load_detect_property, 2476 1); 2477 } 2478 subpixel_order = SubPixelHorizontalRGB; 2479 connector->interlace_allowed = true; 2480 if (connector_type == DRM_MODE_CONNECTOR_DVII) 2481 connector->doublescan_allowed = true; 2482 else 2483 connector->doublescan_allowed = false; 2484 break; 2485 case DRM_MODE_CONNECTOR_SVIDEO: 2486 case DRM_MODE_CONNECTOR_Composite: 2487 case DRM_MODE_CONNECTOR_9PinDIN: 2488 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2489 &radeon_tv_connector_funcs, 2490 connector_type, 2491 ddc); 2492 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs); 2493 radeon_connector->dac_load_detect = true; 2494 /* RS400,RC410,RS480 chipset seems to report a lot 2495 * of false positive on load detect, we haven't yet 2496 * found a way to make load detect reliable on those 2497 * chipset, thus just disable it for TV. 2498 */ 2499 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480) 2500 radeon_connector->dac_load_detect = false; 2501 drm_object_attach_property(&radeon_connector->base.base, 2502 rdev->mode_info.load_detect_property, 2503 radeon_connector->dac_load_detect); 2504 drm_object_attach_property(&radeon_connector->base.base, 2505 rdev->mode_info.tv_std_property, 2506 radeon_combios_get_tv_info(rdev)); 2507 /* no HPD on analog connectors */ 2508 radeon_connector->hpd.hpd = RADEON_HPD_NONE; 2509 connector->interlace_allowed = false; 2510 connector->doublescan_allowed = false; 2511 break; 2512 case DRM_MODE_CONNECTOR_LVDS: 2513 if (i2c_bus->valid) { 2514 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus); 2515 if (!radeon_connector->ddc_bus) 2516 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n"); 2517 else 2518 ddc = &radeon_connector->ddc_bus->adapter; 2519 } 2520 drm_connector_init_with_ddc(dev, &radeon_connector->base, 2521 &radeon_lvds_connector_funcs, 2522 connector_type, 2523 ddc); 2524 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs); 2525 drm_object_attach_property(&radeon_connector->base.base, 2526 dev->mode_config.scaling_mode_property, 2527 DRM_MODE_SCALE_FULLSCREEN); 2528 subpixel_order = SubPixelHorizontalRGB; 2529 connector->interlace_allowed = false; 2530 connector->doublescan_allowed = false; 2531 break; 2532 } 2533 2534 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) { 2535 if (i2c_bus->valid) { 2536 connector->polled = DRM_CONNECTOR_POLL_CONNECT | 2537 DRM_CONNECTOR_POLL_DISCONNECT; 2538 } 2539 } else 2540 connector->polled = DRM_CONNECTOR_POLL_HPD; 2541 2542 connector->display_info.subpixel_order = subpixel_order; 2543 drm_connector_register(connector); 2544 } 2545