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