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