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