Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / gpu / drm / radeon / radeon_connectors.c
blob2e2ca3c6b47d374fc6650d15bfab5d7934740a2f
1 /*
2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
23 * Authors: Dave Airlie
24 * Alex Deucher
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"
36 #include <linux/pm_runtime.h>
37 #include <linux/vga_switcheroo.h>
39 static int radeon_dp_handle_hpd(struct drm_connector *connector)
41 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
42 int ret;
44 ret = radeon_dp_mst_check_status(radeon_connector);
45 if (ret == -EINVAL)
46 return 1;
47 return 0;
49 void radeon_connector_hotplug(struct drm_connector *connector)
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);
55 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
56 struct radeon_connector_atom_dig *dig_connector =
57 radeon_connector->con_priv;
59 if (radeon_connector->is_mst_connector)
60 return;
61 if (dig_connector->is_mst) {
62 radeon_dp_handle_hpd(connector);
63 return;
66 /* bail if the connector does not have hpd pin, e.g.,
67 * VGA, TV, etc.
69 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE)
70 return;
72 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
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;
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;
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;
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
93 if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
94 int saved_dpms = connector->dpms;
95 /* Only turn off the display if it's physically disconnected */
96 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
97 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
98 } else if (radeon_dp_needs_link_train(radeon_connector)) {
99 /* Don't try to start link training before we
100 * have the dpcd */
101 if (!radeon_dp_getdpcd(radeon_connector))
102 return;
104 /* set it to OFF so that drm_helper_connector_dpms()
105 * won't return immediately since the current state
106 * is ON at this point.
108 connector->dpms = DRM_MODE_DPMS_OFF;
109 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
111 connector->dpms = saved_dpms;
116 static void radeon_property_change_mode(struct drm_encoder *encoder)
118 struct drm_crtc *crtc = encoder->crtc;
120 if (crtc && crtc->enabled) {
121 drm_crtc_helper_set_mode(crtc, &crtc->mode,
122 crtc->x, crtc->y, crtc->primary->fb);
126 int radeon_get_monitor_bpc(struct drm_connector *connector)
128 struct drm_device *dev = connector->dev;
129 struct radeon_device *rdev = dev->dev_private;
130 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
131 struct radeon_connector_atom_dig *dig_connector;
132 int bpc = 8;
133 int mode_clock, max_tmds_clock;
135 switch (connector->connector_type) {
136 case DRM_MODE_CONNECTOR_DVII:
137 case DRM_MODE_CONNECTOR_HDMIB:
138 if (radeon_connector->use_digital) {
139 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
140 if (connector->display_info.bpc)
141 bpc = connector->display_info.bpc;
144 break;
145 case DRM_MODE_CONNECTOR_DVID:
146 case DRM_MODE_CONNECTOR_HDMIA:
147 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
148 if (connector->display_info.bpc)
149 bpc = connector->display_info.bpc;
151 break;
152 case DRM_MODE_CONNECTOR_DisplayPort:
153 dig_connector = radeon_connector->con_priv;
154 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
155 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) ||
156 drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
157 if (connector->display_info.bpc)
158 bpc = connector->display_info.bpc;
160 break;
161 case DRM_MODE_CONNECTOR_eDP:
162 case DRM_MODE_CONNECTOR_LVDS:
163 if (connector->display_info.bpc)
164 bpc = connector->display_info.bpc;
165 else if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
166 const struct drm_connector_helper_funcs *connector_funcs =
167 connector->helper_private;
168 struct drm_encoder *encoder = connector_funcs->best_encoder(connector);
169 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
170 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
172 if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR)
173 bpc = 6;
174 else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR)
175 bpc = 8;
177 break;
180 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
181 /* hdmi deep color only implemented on DCE4+ */
182 if ((bpc > 8) && !ASIC_IS_DCE4(rdev)) {
183 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 8 bpc.\n",
184 connector->name, bpc);
185 bpc = 8;
189 * Pre DCE-8 hw can't handle > 12 bpc, and more than 12 bpc doesn't make
190 * much sense without support for > 12 bpc framebuffers. RGB 4:4:4 at
191 * 12 bpc is always supported on hdmi deep color sinks, as this is
192 * required by the HDMI-1.3 spec. Clamp to a safe 12 bpc maximum.
194 if (bpc > 12) {
195 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 12 bpc.\n",
196 connector->name, bpc);
197 bpc = 12;
200 /* Any defined maximum tmds clock limit we must not exceed? */
201 if (connector->display_info.max_tmds_clock > 0) {
202 /* mode_clock is clock in kHz for mode to be modeset on this connector */
203 mode_clock = radeon_connector->pixelclock_for_modeset;
205 /* Maximum allowable input clock in kHz */
206 max_tmds_clock = connector->display_info.max_tmds_clock;
208 DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds input clock %d kHz.\n",
209 connector->name, mode_clock, max_tmds_clock);
211 /* Check if bpc is within clock limit. Try to degrade gracefully otherwise */
212 if ((bpc == 12) && (mode_clock * 3/2 > max_tmds_clock)) {
213 if ((connector->display_info.edid_hdmi_dc_modes & DRM_EDID_HDMI_DC_30) &&
214 (mode_clock * 5/4 <= max_tmds_clock))
215 bpc = 10;
216 else
217 bpc = 8;
219 DRM_DEBUG("%s: HDMI deep color 12 bpc exceeds max tmds clock. Using %d bpc.\n",
220 connector->name, bpc);
223 if ((bpc == 10) && (mode_clock * 5/4 > max_tmds_clock)) {
224 bpc = 8;
225 DRM_DEBUG("%s: HDMI deep color 10 bpc exceeds max tmds clock. Using %d bpc.\n",
226 connector->name, bpc);
229 else if (bpc > 8) {
230 /* max_tmds_clock missing, but hdmi spec mandates it for deep color. */
231 DRM_DEBUG("%s: Required max tmds clock for HDMI deep color missing. Using 8 bpc.\n",
232 connector->name);
233 bpc = 8;
237 if ((radeon_deep_color == 0) && (bpc > 8)) {
238 DRM_DEBUG("%s: Deep color disabled. Set radeon module param deep_color=1 to enable.\n",
239 connector->name);
240 bpc = 8;
243 DRM_DEBUG("%s: Display bpc=%d, returned bpc=%d\n",
244 connector->name, connector->display_info.bpc, bpc);
246 return bpc;
249 static void
250 radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
252 struct drm_device *dev = connector->dev;
253 struct radeon_device *rdev = dev->dev_private;
254 struct drm_encoder *best_encoder = NULL;
255 struct drm_encoder *encoder = NULL;
256 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
257 bool connected;
258 int i;
260 best_encoder = connector_funcs->best_encoder(connector);
262 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
263 if (connector->encoder_ids[i] == 0)
264 break;
266 encoder = drm_encoder_find(connector->dev, NULL,
267 connector->encoder_ids[i]);
268 if (!encoder)
269 continue;
271 if ((encoder == best_encoder) && (status == connector_status_connected))
272 connected = true;
273 else
274 connected = false;
276 if (rdev->is_atom_bios)
277 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
278 else
279 radeon_combios_connected_scratch_regs(connector, encoder, connected);
284 static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
286 struct drm_encoder *encoder;
287 int i;
289 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
290 if (connector->encoder_ids[i] == 0)
291 break;
293 encoder = drm_encoder_find(connector->dev, NULL, connector->encoder_ids[i]);
294 if (!encoder)
295 continue;
297 if (encoder->encoder_type == encoder_type)
298 return encoder;
300 return NULL;
303 struct edid *radeon_connector_edid(struct drm_connector *connector)
305 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
306 struct drm_property_blob *edid_blob = connector->edid_blob_ptr;
308 if (radeon_connector->edid) {
309 return radeon_connector->edid;
310 } else if (edid_blob) {
311 struct edid *edid = kmemdup(edid_blob->data, edid_blob->length, GFP_KERNEL);
312 if (edid)
313 radeon_connector->edid = edid;
315 return radeon_connector->edid;
318 static void radeon_connector_get_edid(struct drm_connector *connector)
320 struct drm_device *dev = connector->dev;
321 struct radeon_device *rdev = dev->dev_private;
322 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
324 if (radeon_connector->edid)
325 return;
327 /* on hw with routers, select right port */
328 if (radeon_connector->router.ddc_valid)
329 radeon_router_select_ddc_port(radeon_connector);
331 if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
332 ENCODER_OBJECT_ID_NONE) &&
333 radeon_connector->ddc_bus->has_aux) {
334 radeon_connector->edid = drm_get_edid(connector,
335 &radeon_connector->ddc_bus->aux.ddc);
336 } else if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
337 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
338 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
340 if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
341 dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) &&
342 radeon_connector->ddc_bus->has_aux)
343 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
344 &radeon_connector->ddc_bus->aux.ddc);
345 else if (radeon_connector->ddc_bus)
346 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
347 &radeon_connector->ddc_bus->adapter);
348 } else if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC &&
349 connector->connector_type == DRM_MODE_CONNECTOR_LVDS &&
350 radeon_connector->ddc_bus) {
351 radeon_connector->edid = drm_get_edid_switcheroo(&radeon_connector->base,
352 &radeon_connector->ddc_bus->adapter);
353 } else if (radeon_connector->ddc_bus) {
354 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
355 &radeon_connector->ddc_bus->adapter);
358 if (!radeon_connector->edid) {
359 /* don't fetch the edid from the vbios if ddc fails and runpm is
360 * enabled so we report disconnected.
362 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
363 return;
365 if (rdev->is_atom_bios) {
366 /* some laptops provide a hardcoded edid in rom for LCDs */
367 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
368 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)))
369 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
370 } else {
371 /* some servers provide a hardcoded edid in rom for KVMs */
372 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
377 static void radeon_connector_free_edid(struct drm_connector *connector)
379 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
381 if (radeon_connector->edid) {
382 kfree(radeon_connector->edid);
383 radeon_connector->edid = NULL;
387 static int radeon_ddc_get_modes(struct drm_connector *connector)
389 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
390 int ret;
392 if (radeon_connector->edid) {
393 drm_mode_connector_update_edid_property(connector, radeon_connector->edid);
394 ret = drm_add_edid_modes(connector, radeon_connector->edid);
395 return ret;
397 drm_mode_connector_update_edid_property(connector, NULL);
398 return 0;
401 static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
403 int enc_id = connector->encoder_ids[0];
404 /* pick the encoder ids */
405 if (enc_id)
406 return drm_encoder_find(connector->dev, NULL, enc_id);
407 return NULL;
410 static void radeon_get_native_mode(struct drm_connector *connector)
412 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
413 struct radeon_encoder *radeon_encoder;
415 if (encoder == NULL)
416 return;
418 radeon_encoder = to_radeon_encoder(encoder);
420 if (!list_empty(&connector->probed_modes)) {
421 struct drm_display_mode *preferred_mode =
422 list_first_entry(&connector->probed_modes,
423 struct drm_display_mode, head);
425 radeon_encoder->native_mode = *preferred_mode;
426 } else {
427 radeon_encoder->native_mode.clock = 0;
432 * radeon_connector_analog_encoder_conflict_solve
433 * - search for other connectors sharing this encoder
434 * if priority is true, then set them disconnected if this is connected
435 * if priority is false, set us disconnected if they are connected
437 static enum drm_connector_status
438 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
439 struct drm_encoder *encoder,
440 enum drm_connector_status current_status,
441 bool priority)
443 struct drm_device *dev = connector->dev;
444 struct drm_connector *conflict;
445 struct radeon_connector *radeon_conflict;
446 int i;
448 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
449 if (conflict == connector)
450 continue;
452 radeon_conflict = to_radeon_connector(conflict);
453 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
454 if (conflict->encoder_ids[i] == 0)
455 break;
457 /* if the IDs match */
458 if (conflict->encoder_ids[i] == encoder->base.id) {
459 if (conflict->status != connector_status_connected)
460 continue;
462 if (radeon_conflict->use_digital)
463 continue;
465 if (priority == true) {
466 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n",
467 conflict->name);
468 DRM_DEBUG_KMS("in favor of %s\n",
469 connector->name);
470 conflict->status = connector_status_disconnected;
471 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
472 } else {
473 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n",
474 connector->name);
475 DRM_DEBUG_KMS("in favor of %s\n",
476 conflict->name);
477 current_status = connector_status_disconnected;
479 break;
483 return current_status;
487 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
489 struct drm_device *dev = encoder->dev;
490 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
491 struct drm_display_mode *mode = NULL;
492 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
494 if (native_mode->hdisplay != 0 &&
495 native_mode->vdisplay != 0 &&
496 native_mode->clock != 0) {
497 mode = drm_mode_duplicate(dev, native_mode);
498 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
499 drm_mode_set_name(mode);
501 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
502 } else if (native_mode->hdisplay != 0 &&
503 native_mode->vdisplay != 0) {
504 /* mac laptops without an edid */
505 /* Note that this is not necessarily the exact panel mode,
506 * but an approximation based on the cvt formula. For these
507 * systems we should ideally read the mode info out of the
508 * registers or add a mode table, but this works and is much
509 * simpler.
511 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
512 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
513 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
515 return mode;
518 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
520 struct drm_device *dev = encoder->dev;
521 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
522 struct drm_display_mode *mode = NULL;
523 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
524 int i;
525 struct mode_size {
526 int w;
527 int h;
528 } common_modes[17] = {
529 { 640, 480},
530 { 720, 480},
531 { 800, 600},
532 { 848, 480},
533 {1024, 768},
534 {1152, 768},
535 {1280, 720},
536 {1280, 800},
537 {1280, 854},
538 {1280, 960},
539 {1280, 1024},
540 {1440, 900},
541 {1400, 1050},
542 {1680, 1050},
543 {1600, 1200},
544 {1920, 1080},
545 {1920, 1200}
548 for (i = 0; i < 17; i++) {
549 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
550 if (common_modes[i].w > 1024 ||
551 common_modes[i].h > 768)
552 continue;
554 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
555 if (common_modes[i].w > native_mode->hdisplay ||
556 common_modes[i].h > native_mode->vdisplay ||
557 (common_modes[i].w == native_mode->hdisplay &&
558 common_modes[i].h == native_mode->vdisplay))
559 continue;
561 if (common_modes[i].w < 320 || common_modes[i].h < 200)
562 continue;
564 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
565 drm_mode_probed_add(connector, mode);
569 static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
570 uint64_t val)
572 struct drm_device *dev = connector->dev;
573 struct radeon_device *rdev = dev->dev_private;
574 struct drm_encoder *encoder;
575 struct radeon_encoder *radeon_encoder;
577 if (property == rdev->mode_info.coherent_mode_property) {
578 struct radeon_encoder_atom_dig *dig;
579 bool new_coherent_mode;
581 /* need to find digital encoder on connector */
582 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
583 if (!encoder)
584 return 0;
586 radeon_encoder = to_radeon_encoder(encoder);
588 if (!radeon_encoder->enc_priv)
589 return 0;
591 dig = radeon_encoder->enc_priv;
592 new_coherent_mode = val ? true : false;
593 if (dig->coherent_mode != new_coherent_mode) {
594 dig->coherent_mode = new_coherent_mode;
595 radeon_property_change_mode(&radeon_encoder->base);
599 if (property == rdev->mode_info.audio_property) {
600 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
601 /* need to find digital encoder on connector */
602 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
603 if (!encoder)
604 return 0;
606 radeon_encoder = to_radeon_encoder(encoder);
608 if (radeon_connector->audio != val) {
609 radeon_connector->audio = val;
610 radeon_property_change_mode(&radeon_encoder->base);
614 if (property == rdev->mode_info.dither_property) {
615 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
616 /* need to find digital encoder on connector */
617 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
618 if (!encoder)
619 return 0;
621 radeon_encoder = to_radeon_encoder(encoder);
623 if (radeon_connector->dither != val) {
624 radeon_connector->dither = val;
625 radeon_property_change_mode(&radeon_encoder->base);
629 if (property == rdev->mode_info.underscan_property) {
630 /* need to find digital encoder on connector */
631 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
632 if (!encoder)
633 return 0;
635 radeon_encoder = to_radeon_encoder(encoder);
637 if (radeon_encoder->underscan_type != val) {
638 radeon_encoder->underscan_type = val;
639 radeon_property_change_mode(&radeon_encoder->base);
643 if (property == rdev->mode_info.underscan_hborder_property) {
644 /* need to find digital encoder on connector */
645 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
646 if (!encoder)
647 return 0;
649 radeon_encoder = to_radeon_encoder(encoder);
651 if (radeon_encoder->underscan_hborder != val) {
652 radeon_encoder->underscan_hborder = val;
653 radeon_property_change_mode(&radeon_encoder->base);
657 if (property == rdev->mode_info.underscan_vborder_property) {
658 /* need to find digital encoder on connector */
659 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
660 if (!encoder)
661 return 0;
663 radeon_encoder = to_radeon_encoder(encoder);
665 if (radeon_encoder->underscan_vborder != val) {
666 radeon_encoder->underscan_vborder = val;
667 radeon_property_change_mode(&radeon_encoder->base);
671 if (property == rdev->mode_info.tv_std_property) {
672 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
673 if (!encoder) {
674 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
677 if (!encoder)
678 return 0;
680 radeon_encoder = to_radeon_encoder(encoder);
681 if (!radeon_encoder->enc_priv)
682 return 0;
683 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
684 struct radeon_encoder_atom_dac *dac_int;
685 dac_int = radeon_encoder->enc_priv;
686 dac_int->tv_std = val;
687 } else {
688 struct radeon_encoder_tv_dac *dac_int;
689 dac_int = radeon_encoder->enc_priv;
690 dac_int->tv_std = val;
692 radeon_property_change_mode(&radeon_encoder->base);
695 if (property == rdev->mode_info.load_detect_property) {
696 struct radeon_connector *radeon_connector =
697 to_radeon_connector(connector);
699 if (val == 0)
700 radeon_connector->dac_load_detect = false;
701 else
702 radeon_connector->dac_load_detect = true;
705 if (property == rdev->mode_info.tmds_pll_property) {
706 struct radeon_encoder_int_tmds *tmds = NULL;
707 bool ret = false;
708 /* need to find digital encoder on connector */
709 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
710 if (!encoder)
711 return 0;
713 radeon_encoder = to_radeon_encoder(encoder);
715 tmds = radeon_encoder->enc_priv;
716 if (!tmds)
717 return 0;
719 if (val == 0) {
720 if (rdev->is_atom_bios)
721 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
722 else
723 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
725 if (val == 1 || ret == false) {
726 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
728 radeon_property_change_mode(&radeon_encoder->base);
731 if (property == dev->mode_config.scaling_mode_property) {
732 enum radeon_rmx_type rmx_type;
734 if (connector->encoder)
735 radeon_encoder = to_radeon_encoder(connector->encoder);
736 else {
737 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
738 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
741 switch (val) {
742 default:
743 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
744 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
745 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
746 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
748 if (radeon_encoder->rmx_type == rmx_type)
749 return 0;
751 if ((rmx_type != DRM_MODE_SCALE_NONE) &&
752 (radeon_encoder->native_mode.clock == 0))
753 return 0;
755 radeon_encoder->rmx_type = rmx_type;
757 radeon_property_change_mode(&radeon_encoder->base);
760 if (property == rdev->mode_info.output_csc_property) {
761 if (connector->encoder)
762 radeon_encoder = to_radeon_encoder(connector->encoder);
763 else {
764 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
765 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
768 if (radeon_encoder->output_csc == val)
769 return 0;
771 radeon_encoder->output_csc = val;
773 if (connector->encoder->crtc) {
774 struct drm_crtc *crtc = connector->encoder->crtc;
775 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
777 radeon_crtc->output_csc = radeon_encoder->output_csc;
780 * Our .gamma_set assumes the .gamma_store has been
781 * prefilled and don't care about its arguments.
783 crtc->funcs->gamma_set(crtc, NULL, NULL, NULL, 0, NULL);
787 return 0;
790 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
791 struct drm_connector *connector)
793 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
794 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
795 struct drm_display_mode *t, *mode;
797 /* If the EDID preferred mode doesn't match the native mode, use it */
798 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
799 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
800 if (mode->hdisplay != native_mode->hdisplay ||
801 mode->vdisplay != native_mode->vdisplay)
802 memcpy(native_mode, mode, sizeof(*mode));
806 /* Try to get native mode details from EDID if necessary */
807 if (!native_mode->clock) {
808 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
809 if (mode->hdisplay == native_mode->hdisplay &&
810 mode->vdisplay == native_mode->vdisplay) {
811 *native_mode = *mode;
812 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
813 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
814 break;
819 if (!native_mode->clock) {
820 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
821 radeon_encoder->rmx_type = RMX_OFF;
825 static int radeon_lvds_get_modes(struct drm_connector *connector)
827 struct drm_encoder *encoder;
828 int ret = 0;
829 struct drm_display_mode *mode;
831 radeon_connector_get_edid(connector);
832 ret = radeon_ddc_get_modes(connector);
833 if (ret > 0) {
834 encoder = radeon_best_single_encoder(connector);
835 if (encoder) {
836 radeon_fixup_lvds_native_mode(encoder, connector);
837 /* add scaled modes */
838 radeon_add_common_modes(encoder, connector);
840 return ret;
843 encoder = radeon_best_single_encoder(connector);
844 if (!encoder)
845 return 0;
847 /* we have no EDID modes */
848 mode = radeon_fp_native_mode(encoder);
849 if (mode) {
850 ret = 1;
851 drm_mode_probed_add(connector, mode);
852 /* add the width/height from vbios tables if available */
853 connector->display_info.width_mm = mode->width_mm;
854 connector->display_info.height_mm = mode->height_mm;
855 /* add scaled modes */
856 radeon_add_common_modes(encoder, connector);
859 return ret;
862 static int radeon_lvds_mode_valid(struct drm_connector *connector,
863 struct drm_display_mode *mode)
865 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
867 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
868 return MODE_PANEL;
870 if (encoder) {
871 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
872 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
874 /* AVIVO hardware supports downscaling modes larger than the panel
875 * to the panel size, but I'm not sure this is desirable.
877 if ((mode->hdisplay > native_mode->hdisplay) ||
878 (mode->vdisplay > native_mode->vdisplay))
879 return MODE_PANEL;
881 /* if scaling is disabled, block non-native modes */
882 if (radeon_encoder->rmx_type == RMX_OFF) {
883 if ((mode->hdisplay != native_mode->hdisplay) ||
884 (mode->vdisplay != native_mode->vdisplay))
885 return MODE_PANEL;
889 return MODE_OK;
892 static enum drm_connector_status
893 radeon_lvds_detect(struct drm_connector *connector, bool force)
895 struct drm_device *dev = connector->dev;
896 struct radeon_device *rdev = dev->dev_private;
897 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
898 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
899 enum drm_connector_status ret = connector_status_disconnected;
900 int r;
902 if (!drm_kms_helper_is_poll_worker()) {
903 r = pm_runtime_get_sync(connector->dev->dev);
904 if (r < 0)
905 return connector_status_disconnected;
908 if (encoder) {
909 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
910 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
912 /* check if panel is valid */
913 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
914 ret = connector_status_connected;
915 /* don't fetch the edid from the vbios if ddc fails and runpm is
916 * enabled so we report disconnected.
918 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
919 ret = connector_status_disconnected;
922 /* check for edid as well */
923 radeon_connector_get_edid(connector);
924 if (radeon_connector->edid)
925 ret = connector_status_connected;
926 /* check acpi lid status ??? */
928 radeon_connector_update_scratch_regs(connector, ret);
930 if (!drm_kms_helper_is_poll_worker()) {
931 pm_runtime_mark_last_busy(connector->dev->dev);
932 pm_runtime_put_autosuspend(connector->dev->dev);
935 return ret;
938 static void radeon_connector_unregister(struct drm_connector *connector)
940 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
942 if (radeon_connector->ddc_bus && radeon_connector->ddc_bus->has_aux) {
943 drm_dp_aux_unregister(&radeon_connector->ddc_bus->aux);
944 radeon_connector->ddc_bus->has_aux = false;
948 static void radeon_connector_destroy(struct drm_connector *connector)
950 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
952 radeon_connector_free_edid(connector);
953 kfree(radeon_connector->con_priv);
954 drm_connector_unregister(connector);
955 drm_connector_cleanup(connector);
956 kfree(connector);
959 static int radeon_lvds_set_property(struct drm_connector *connector,
960 struct drm_property *property,
961 uint64_t value)
963 struct drm_device *dev = connector->dev;
964 struct radeon_encoder *radeon_encoder;
965 enum radeon_rmx_type rmx_type;
967 DRM_DEBUG_KMS("\n");
968 if (property != dev->mode_config.scaling_mode_property)
969 return 0;
971 if (connector->encoder)
972 radeon_encoder = to_radeon_encoder(connector->encoder);
973 else {
974 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
975 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
978 switch (value) {
979 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
980 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
981 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
982 default:
983 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
985 if (radeon_encoder->rmx_type == rmx_type)
986 return 0;
988 radeon_encoder->rmx_type = rmx_type;
990 radeon_property_change_mode(&radeon_encoder->base);
991 return 0;
995 static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
996 .get_modes = radeon_lvds_get_modes,
997 .mode_valid = radeon_lvds_mode_valid,
998 .best_encoder = radeon_best_single_encoder,
1001 static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
1002 .dpms = drm_helper_connector_dpms,
1003 .detect = radeon_lvds_detect,
1004 .fill_modes = drm_helper_probe_single_connector_modes,
1005 .early_unregister = radeon_connector_unregister,
1006 .destroy = radeon_connector_destroy,
1007 .set_property = radeon_lvds_set_property,
1010 static int radeon_vga_get_modes(struct drm_connector *connector)
1012 int ret;
1014 radeon_connector_get_edid(connector);
1015 ret = radeon_ddc_get_modes(connector);
1017 radeon_get_native_mode(connector);
1019 return ret;
1022 static int radeon_vga_mode_valid(struct drm_connector *connector,
1023 struct drm_display_mode *mode)
1025 struct drm_device *dev = connector->dev;
1026 struct radeon_device *rdev = dev->dev_private;
1028 /* XXX check mode bandwidth */
1030 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1031 return MODE_CLOCK_HIGH;
1033 return MODE_OK;
1036 static enum drm_connector_status
1037 radeon_vga_detect(struct drm_connector *connector, bool force)
1039 struct drm_device *dev = connector->dev;
1040 struct radeon_device *rdev = dev->dev_private;
1041 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1042 struct drm_encoder *encoder;
1043 const struct drm_encoder_helper_funcs *encoder_funcs;
1044 bool dret = false;
1045 enum drm_connector_status ret = connector_status_disconnected;
1046 int r;
1048 if (!drm_kms_helper_is_poll_worker()) {
1049 r = pm_runtime_get_sync(connector->dev->dev);
1050 if (r < 0)
1051 return connector_status_disconnected;
1054 encoder = radeon_best_single_encoder(connector);
1055 if (!encoder)
1056 ret = connector_status_disconnected;
1058 if (radeon_connector->ddc_bus)
1059 dret = radeon_ddc_probe(radeon_connector, false);
1060 if (dret) {
1061 radeon_connector->detected_by_load = false;
1062 radeon_connector_free_edid(connector);
1063 radeon_connector_get_edid(connector);
1065 if (!radeon_connector->edid) {
1066 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1067 connector->name);
1068 ret = connector_status_connected;
1069 } else {
1070 radeon_connector->use_digital =
1071 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
1073 /* some oems have boards with separate digital and analog connectors
1074 * with a shared ddc line (often vga + hdmi)
1076 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
1077 radeon_connector_free_edid(connector);
1078 ret = connector_status_disconnected;
1079 } else {
1080 ret = connector_status_connected;
1083 } else {
1085 /* if we aren't forcing don't do destructive polling */
1086 if (!force) {
1087 /* only return the previous status if we last
1088 * detected a monitor via load.
1090 if (radeon_connector->detected_by_load)
1091 ret = connector->status;
1092 goto out;
1095 if (radeon_connector->dac_load_detect && encoder) {
1096 encoder_funcs = encoder->helper_private;
1097 ret = encoder_funcs->detect(encoder, connector);
1098 if (ret != connector_status_disconnected)
1099 radeon_connector->detected_by_load = true;
1103 if (ret == connector_status_connected)
1104 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1106 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1107 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1108 * by other means, assume the CRT is connected and use that EDID.
1110 if ((!rdev->is_atom_bios) &&
1111 (ret == connector_status_disconnected) &&
1112 rdev->mode_info.bios_hardcoded_edid_size) {
1113 ret = connector_status_connected;
1116 radeon_connector_update_scratch_regs(connector, ret);
1118 out:
1119 if (!drm_kms_helper_is_poll_worker()) {
1120 pm_runtime_mark_last_busy(connector->dev->dev);
1121 pm_runtime_put_autosuspend(connector->dev->dev);
1124 return ret;
1127 static const struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
1128 .get_modes = radeon_vga_get_modes,
1129 .mode_valid = radeon_vga_mode_valid,
1130 .best_encoder = radeon_best_single_encoder,
1133 static const struct drm_connector_funcs radeon_vga_connector_funcs = {
1134 .dpms = drm_helper_connector_dpms,
1135 .detect = radeon_vga_detect,
1136 .fill_modes = drm_helper_probe_single_connector_modes,
1137 .early_unregister = radeon_connector_unregister,
1138 .destroy = radeon_connector_destroy,
1139 .set_property = radeon_connector_set_property,
1142 static int radeon_tv_get_modes(struct drm_connector *connector)
1144 struct drm_device *dev = connector->dev;
1145 struct radeon_device *rdev = dev->dev_private;
1146 struct drm_display_mode *tv_mode;
1147 struct drm_encoder *encoder;
1149 encoder = radeon_best_single_encoder(connector);
1150 if (!encoder)
1151 return 0;
1153 /* avivo chips can scale any mode */
1154 if (rdev->family >= CHIP_RS600)
1155 /* add scaled modes */
1156 radeon_add_common_modes(encoder, connector);
1157 else {
1158 /* only 800x600 is supported right now on pre-avivo chips */
1159 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
1160 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
1161 drm_mode_probed_add(connector, tv_mode);
1163 return 1;
1166 static int radeon_tv_mode_valid(struct drm_connector *connector,
1167 struct drm_display_mode *mode)
1169 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
1170 return MODE_CLOCK_RANGE;
1171 return MODE_OK;
1174 static enum drm_connector_status
1175 radeon_tv_detect(struct drm_connector *connector, bool force)
1177 struct drm_encoder *encoder;
1178 const struct drm_encoder_helper_funcs *encoder_funcs;
1179 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1180 enum drm_connector_status ret = connector_status_disconnected;
1181 int r;
1183 if (!radeon_connector->dac_load_detect)
1184 return ret;
1186 if (!drm_kms_helper_is_poll_worker()) {
1187 r = pm_runtime_get_sync(connector->dev->dev);
1188 if (r < 0)
1189 return connector_status_disconnected;
1192 encoder = radeon_best_single_encoder(connector);
1193 if (!encoder)
1194 ret = connector_status_disconnected;
1195 else {
1196 encoder_funcs = encoder->helper_private;
1197 ret = encoder_funcs->detect(encoder, connector);
1199 if (ret == connector_status_connected)
1200 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
1201 radeon_connector_update_scratch_regs(connector, ret);
1203 if (!drm_kms_helper_is_poll_worker()) {
1204 pm_runtime_mark_last_busy(connector->dev->dev);
1205 pm_runtime_put_autosuspend(connector->dev->dev);
1208 return ret;
1211 static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
1212 .get_modes = radeon_tv_get_modes,
1213 .mode_valid = radeon_tv_mode_valid,
1214 .best_encoder = radeon_best_single_encoder,
1217 static const struct drm_connector_funcs radeon_tv_connector_funcs = {
1218 .dpms = drm_helper_connector_dpms,
1219 .detect = radeon_tv_detect,
1220 .fill_modes = drm_helper_probe_single_connector_modes,
1221 .early_unregister = radeon_connector_unregister,
1222 .destroy = radeon_connector_destroy,
1223 .set_property = radeon_connector_set_property,
1226 static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector)
1228 struct drm_device *dev = connector->dev;
1229 struct radeon_device *rdev = dev->dev_private;
1230 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1231 enum drm_connector_status status;
1233 /* We only trust HPD on R600 and newer ASICS. */
1234 if (rdev->family >= CHIP_R600
1235 && radeon_connector->hpd.hpd != RADEON_HPD_NONE) {
1236 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
1237 status = connector_status_connected;
1238 else
1239 status = connector_status_disconnected;
1240 if (connector->status == status)
1241 return true;
1244 return false;
1248 * DVI is complicated
1249 * Do a DDC probe, if DDC probe passes, get the full EDID so
1250 * we can do analog/digital monitor detection at this point.
1251 * If the monitor is an analog monitor or we got no DDC,
1252 * we need to find the DAC encoder object for this connector.
1253 * If we got no DDC, we do load detection on the DAC encoder object.
1254 * If we got analog DDC or load detection passes on the DAC encoder
1255 * we have to check if this analog encoder is shared with anyone else (TV)
1256 * if its shared we have to set the other connector to disconnected.
1258 static enum drm_connector_status
1259 radeon_dvi_detect(struct drm_connector *connector, bool force)
1261 struct drm_device *dev = connector->dev;
1262 struct radeon_device *rdev = dev->dev_private;
1263 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1264 struct drm_encoder *encoder = NULL;
1265 const struct drm_encoder_helper_funcs *encoder_funcs;
1266 int i, r;
1267 enum drm_connector_status ret = connector_status_disconnected;
1268 bool dret = false, broken_edid = false;
1270 if (!drm_kms_helper_is_poll_worker()) {
1271 r = pm_runtime_get_sync(connector->dev->dev);
1272 if (r < 0)
1273 return connector_status_disconnected;
1276 if (radeon_connector->detected_hpd_without_ddc) {
1277 force = true;
1278 radeon_connector->detected_hpd_without_ddc = false;
1281 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1282 ret = connector->status;
1283 goto exit;
1286 if (radeon_connector->ddc_bus) {
1287 dret = radeon_ddc_probe(radeon_connector, false);
1289 /* Sometimes the pins required for the DDC probe on DVI
1290 * connectors don't make contact at the same time that the ones
1291 * for HPD do. If the DDC probe fails even though we had an HPD
1292 * signal, try again later */
1293 if (!dret && !force &&
1294 connector->status != connector_status_connected) {
1295 DRM_DEBUG_KMS("hpd detected without ddc, retrying in 1 second\n");
1296 radeon_connector->detected_hpd_without_ddc = true;
1297 schedule_delayed_work(&rdev->hotplug_work,
1298 msecs_to_jiffies(1000));
1299 goto exit;
1302 if (dret) {
1303 radeon_connector->detected_by_load = false;
1304 radeon_connector_free_edid(connector);
1305 radeon_connector_get_edid(connector);
1307 if (!radeon_connector->edid) {
1308 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1309 connector->name);
1310 /* rs690 seems to have a problem with connectors not existing and always
1311 * return a block of 0's. If we see this just stop polling on this output */
1312 if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) &&
1313 radeon_connector->base.null_edid_counter) {
1314 ret = connector_status_disconnected;
1315 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n",
1316 connector->name);
1317 radeon_connector->ddc_bus = NULL;
1318 } else {
1319 ret = connector_status_connected;
1320 broken_edid = true; /* defer use_digital to later */
1322 } else {
1323 radeon_connector->use_digital =
1324 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
1326 /* some oems have boards with separate digital and analog connectors
1327 * with a shared ddc line (often vga + hdmi)
1329 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
1330 radeon_connector_free_edid(connector);
1331 ret = connector_status_disconnected;
1332 } else {
1333 ret = connector_status_connected;
1335 /* This gets complicated. We have boards with VGA + HDMI with a
1336 * shared DDC line and we have boards with DVI-D + HDMI with a shared
1337 * DDC line. The latter is more complex because with DVI<->HDMI adapters
1338 * you don't really know what's connected to which port as both are digital.
1340 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
1341 struct drm_connector *list_connector;
1342 struct radeon_connector *list_radeon_connector;
1343 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
1344 if (connector == list_connector)
1345 continue;
1346 list_radeon_connector = to_radeon_connector(list_connector);
1347 if (list_radeon_connector->shared_ddc &&
1348 (list_radeon_connector->ddc_bus->rec.i2c_id ==
1349 radeon_connector->ddc_bus->rec.i2c_id)) {
1350 /* cases where both connectors are digital */
1351 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
1352 /* hpd is our only option in this case */
1353 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1354 radeon_connector_free_edid(connector);
1355 ret = connector_status_disconnected;
1364 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
1365 goto out;
1367 /* DVI-D and HDMI-A are digital only */
1368 if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
1369 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
1370 goto out;
1372 /* if we aren't forcing don't do destructive polling */
1373 if (!force) {
1374 /* only return the previous status if we last
1375 * detected a monitor via load.
1377 if (radeon_connector->detected_by_load)
1378 ret = connector->status;
1379 goto out;
1382 /* find analog encoder */
1383 if (radeon_connector->dac_load_detect) {
1384 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1385 if (connector->encoder_ids[i] == 0)
1386 break;
1388 encoder = drm_encoder_find(connector->dev, NULL,
1389 connector->encoder_ids[i]);
1390 if (!encoder)
1391 continue;
1393 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
1394 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
1395 continue;
1397 encoder_funcs = encoder->helper_private;
1398 if (encoder_funcs->detect) {
1399 if (!broken_edid) {
1400 if (ret != connector_status_connected) {
1401 /* deal with analog monitors without DDC */
1402 ret = encoder_funcs->detect(encoder, connector);
1403 if (ret == connector_status_connected) {
1404 radeon_connector->use_digital = false;
1406 if (ret != connector_status_disconnected)
1407 radeon_connector->detected_by_load = true;
1409 } else {
1410 enum drm_connector_status lret;
1411 /* assume digital unless load detected otherwise */
1412 radeon_connector->use_digital = true;
1413 lret = encoder_funcs->detect(encoder, connector);
1414 DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
1415 if (lret == connector_status_connected)
1416 radeon_connector->use_digital = false;
1418 break;
1423 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
1424 encoder) {
1425 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1428 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1429 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1430 * by other means, assume the DFP is connected and use that EDID. In most
1431 * cases the DVI port is actually a virtual KVM port connected to the service
1432 * processor.
1434 out:
1435 if ((!rdev->is_atom_bios) &&
1436 (ret == connector_status_disconnected) &&
1437 rdev->mode_info.bios_hardcoded_edid_size) {
1438 radeon_connector->use_digital = true;
1439 ret = connector_status_connected;
1442 /* updated in get modes as well since we need to know if it's analog or digital */
1443 radeon_connector_update_scratch_regs(connector, ret);
1445 if ((radeon_audio != 0) && radeon_connector->use_digital) {
1446 const struct drm_connector_helper_funcs *connector_funcs =
1447 connector->helper_private;
1449 encoder = connector_funcs->best_encoder(connector);
1450 if (encoder && (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)) {
1451 radeon_connector_get_edid(connector);
1452 radeon_audio_detect(connector, encoder, ret);
1456 exit:
1457 if (!drm_kms_helper_is_poll_worker()) {
1458 pm_runtime_mark_last_busy(connector->dev->dev);
1459 pm_runtime_put_autosuspend(connector->dev->dev);
1462 return ret;
1465 /* okay need to be smart in here about which encoder to pick */
1466 static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
1468 int enc_id = connector->encoder_ids[0];
1469 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1470 struct drm_encoder *encoder;
1471 int i;
1472 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1473 if (connector->encoder_ids[i] == 0)
1474 break;
1476 encoder = drm_encoder_find(connector->dev, NULL, connector->encoder_ids[i]);
1477 if (!encoder)
1478 continue;
1480 if (radeon_connector->use_digital == true) {
1481 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
1482 return encoder;
1483 } else {
1484 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
1485 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
1486 return encoder;
1490 /* see if we have a default encoder TODO */
1492 /* then check use digitial */
1493 /* pick the first one */
1494 if (enc_id)
1495 return drm_encoder_find(connector->dev, NULL, enc_id);
1496 return NULL;
1499 static void radeon_dvi_force(struct drm_connector *connector)
1501 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1502 if (connector->force == DRM_FORCE_ON)
1503 radeon_connector->use_digital = false;
1504 if (connector->force == DRM_FORCE_ON_DIGITAL)
1505 radeon_connector->use_digital = true;
1508 static int radeon_dvi_mode_valid(struct drm_connector *connector,
1509 struct drm_display_mode *mode)
1511 struct drm_device *dev = connector->dev;
1512 struct radeon_device *rdev = dev->dev_private;
1513 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1515 /* XXX check mode bandwidth */
1517 /* clocks over 135 MHz have heat issues with DVI on RV100 */
1518 if (radeon_connector->use_digital &&
1519 (rdev->family == CHIP_RV100) &&
1520 (mode->clock > 135000))
1521 return MODE_CLOCK_HIGH;
1523 if (radeon_connector->use_digital && (mode->clock > 165000)) {
1524 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1525 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1526 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1527 return MODE_OK;
1528 else if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
1529 /* HDMI 1.3+ supports max clock of 340 Mhz */
1530 if (mode->clock > 340000)
1531 return MODE_CLOCK_HIGH;
1532 else
1533 return MODE_OK;
1534 } else {
1535 return MODE_CLOCK_HIGH;
1539 /* check against the max pixel clock */
1540 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1541 return MODE_CLOCK_HIGH;
1543 return MODE_OK;
1546 static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
1547 .get_modes = radeon_vga_get_modes,
1548 .mode_valid = radeon_dvi_mode_valid,
1549 .best_encoder = radeon_dvi_encoder,
1552 static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
1553 .dpms = drm_helper_connector_dpms,
1554 .detect = radeon_dvi_detect,
1555 .fill_modes = drm_helper_probe_single_connector_modes,
1556 .set_property = radeon_connector_set_property,
1557 .early_unregister = radeon_connector_unregister,
1558 .destroy = radeon_connector_destroy,
1559 .force = radeon_dvi_force,
1562 static int radeon_dp_get_modes(struct drm_connector *connector)
1564 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1565 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1566 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1567 int ret;
1569 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1570 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1571 struct drm_display_mode *mode;
1573 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1574 if (!radeon_dig_connector->edp_on)
1575 atombios_set_edp_panel_power(connector,
1576 ATOM_TRANSMITTER_ACTION_POWER_ON);
1577 radeon_connector_get_edid(connector);
1578 ret = radeon_ddc_get_modes(connector);
1579 if (!radeon_dig_connector->edp_on)
1580 atombios_set_edp_panel_power(connector,
1581 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1582 } else {
1583 /* need to setup ddc on the bridge */
1584 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1585 ENCODER_OBJECT_ID_NONE) {
1586 if (encoder)
1587 radeon_atom_ext_encoder_setup_ddc(encoder);
1589 radeon_connector_get_edid(connector);
1590 ret = radeon_ddc_get_modes(connector);
1593 if (ret > 0) {
1594 if (encoder) {
1595 radeon_fixup_lvds_native_mode(encoder, connector);
1596 /* add scaled modes */
1597 radeon_add_common_modes(encoder, connector);
1599 return ret;
1602 if (!encoder)
1603 return 0;
1605 /* we have no EDID modes */
1606 mode = radeon_fp_native_mode(encoder);
1607 if (mode) {
1608 ret = 1;
1609 drm_mode_probed_add(connector, mode);
1610 /* add the width/height from vbios tables if available */
1611 connector->display_info.width_mm = mode->width_mm;
1612 connector->display_info.height_mm = mode->height_mm;
1613 /* add scaled modes */
1614 radeon_add_common_modes(encoder, connector);
1616 } else {
1617 /* need to setup ddc on the bridge */
1618 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1619 ENCODER_OBJECT_ID_NONE) {
1620 if (encoder)
1621 radeon_atom_ext_encoder_setup_ddc(encoder);
1623 radeon_connector_get_edid(connector);
1624 ret = radeon_ddc_get_modes(connector);
1626 radeon_get_native_mode(connector);
1629 return ret;
1632 u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
1634 struct drm_encoder *encoder;
1635 struct radeon_encoder *radeon_encoder;
1636 int i;
1638 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1639 if (connector->encoder_ids[i] == 0)
1640 break;
1642 encoder = drm_encoder_find(connector->dev, NULL, connector->encoder_ids[i]);
1643 if (!encoder)
1644 continue;
1646 radeon_encoder = to_radeon_encoder(encoder);
1648 switch (radeon_encoder->encoder_id) {
1649 case ENCODER_OBJECT_ID_TRAVIS:
1650 case ENCODER_OBJECT_ID_NUTMEG:
1651 return radeon_encoder->encoder_id;
1652 default:
1653 break;
1657 return ENCODER_OBJECT_ID_NONE;
1660 static bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
1662 struct drm_encoder *encoder;
1663 struct radeon_encoder *radeon_encoder;
1664 int i;
1665 bool found = false;
1667 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1668 if (connector->encoder_ids[i] == 0)
1669 break;
1671 encoder = drm_encoder_find(connector->dev, NULL, connector->encoder_ids[i]);
1672 if (!encoder)
1673 continue;
1675 radeon_encoder = to_radeon_encoder(encoder);
1676 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1677 found = true;
1680 return found;
1683 bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1685 struct drm_device *dev = connector->dev;
1686 struct radeon_device *rdev = dev->dev_private;
1688 if (ASIC_IS_DCE5(rdev) &&
1689 (rdev->clock.default_dispclk >= 53900) &&
1690 radeon_connector_encoder_is_hbr2(connector)) {
1691 return true;
1694 return false;
1697 static enum drm_connector_status
1698 radeon_dp_detect(struct drm_connector *connector, bool force)
1700 struct drm_device *dev = connector->dev;
1701 struct radeon_device *rdev = dev->dev_private;
1702 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1703 enum drm_connector_status ret = connector_status_disconnected;
1704 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1705 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1706 int r;
1708 if (radeon_dig_connector->is_mst)
1709 return connector_status_disconnected;
1711 if (!drm_kms_helper_is_poll_worker()) {
1712 r = pm_runtime_get_sync(connector->dev->dev);
1713 if (r < 0)
1714 return connector_status_disconnected;
1717 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1718 ret = connector->status;
1719 goto out;
1722 radeon_connector_free_edid(connector);
1724 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1725 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1726 if (encoder) {
1727 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1728 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1730 /* check if panel is valid */
1731 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1732 ret = connector_status_connected;
1733 /* don't fetch the edid from the vbios if ddc fails and runpm is
1734 * enabled so we report disconnected.
1736 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
1737 ret = connector_status_disconnected;
1739 /* eDP is always DP */
1740 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1741 if (!radeon_dig_connector->edp_on)
1742 atombios_set_edp_panel_power(connector,
1743 ATOM_TRANSMITTER_ACTION_POWER_ON);
1744 if (radeon_dp_getdpcd(radeon_connector))
1745 ret = connector_status_connected;
1746 if (!radeon_dig_connector->edp_on)
1747 atombios_set_edp_panel_power(connector,
1748 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1749 } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1750 ENCODER_OBJECT_ID_NONE) {
1751 /* DP bridges are always DP */
1752 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1753 /* get the DPCD from the bridge */
1754 radeon_dp_getdpcd(radeon_connector);
1756 if (encoder) {
1757 /* setup ddc on the bridge */
1758 radeon_atom_ext_encoder_setup_ddc(encoder);
1759 /* bridge chips are always aux */
1760 if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */
1761 ret = connector_status_connected;
1762 else if (radeon_connector->dac_load_detect) { /* try load detection */
1763 const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
1764 ret = encoder_funcs->detect(encoder, connector);
1767 } else {
1768 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
1769 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1770 ret = connector_status_connected;
1771 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1772 radeon_dp_getdpcd(radeon_connector);
1773 r = radeon_dp_mst_probe(radeon_connector);
1774 if (r == 1)
1775 ret = connector_status_disconnected;
1777 } else {
1778 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1779 if (radeon_dp_getdpcd(radeon_connector)) {
1780 r = radeon_dp_mst_probe(radeon_connector);
1781 if (r == 1)
1782 ret = connector_status_disconnected;
1783 else
1784 ret = connector_status_connected;
1786 } else {
1787 /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
1788 if (radeon_ddc_probe(radeon_connector, false))
1789 ret = connector_status_connected;
1794 radeon_connector_update_scratch_regs(connector, ret);
1796 if ((radeon_audio != 0) && encoder) {
1797 radeon_connector_get_edid(connector);
1798 radeon_audio_detect(connector, encoder, ret);
1801 out:
1802 if (!drm_kms_helper_is_poll_worker()) {
1803 pm_runtime_mark_last_busy(connector->dev->dev);
1804 pm_runtime_put_autosuspend(connector->dev->dev);
1807 return ret;
1810 static int radeon_dp_mode_valid(struct drm_connector *connector,
1811 struct drm_display_mode *mode)
1813 struct drm_device *dev = connector->dev;
1814 struct radeon_device *rdev = dev->dev_private;
1815 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1816 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1818 /* XXX check mode bandwidth */
1820 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1821 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1822 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1824 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1825 return MODE_PANEL;
1827 if (encoder) {
1828 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1829 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1831 /* AVIVO hardware supports downscaling modes larger than the panel
1832 * to the panel size, but I'm not sure this is desirable.
1834 if ((mode->hdisplay > native_mode->hdisplay) ||
1835 (mode->vdisplay > native_mode->vdisplay))
1836 return MODE_PANEL;
1838 /* if scaling is disabled, block non-native modes */
1839 if (radeon_encoder->rmx_type == RMX_OFF) {
1840 if ((mode->hdisplay != native_mode->hdisplay) ||
1841 (mode->vdisplay != native_mode->vdisplay))
1842 return MODE_PANEL;
1845 } else {
1846 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1847 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
1848 return radeon_dp_mode_valid_helper(connector, mode);
1849 } else {
1850 if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
1851 /* HDMI 1.3+ supports max clock of 340 Mhz */
1852 if (mode->clock > 340000)
1853 return MODE_CLOCK_HIGH;
1854 } else {
1855 if (mode->clock > 165000)
1856 return MODE_CLOCK_HIGH;
1861 return MODE_OK;
1864 static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1865 .get_modes = radeon_dp_get_modes,
1866 .mode_valid = radeon_dp_mode_valid,
1867 .best_encoder = radeon_dvi_encoder,
1870 static const struct drm_connector_funcs radeon_dp_connector_funcs = {
1871 .dpms = drm_helper_connector_dpms,
1872 .detect = radeon_dp_detect,
1873 .fill_modes = drm_helper_probe_single_connector_modes,
1874 .set_property = radeon_connector_set_property,
1875 .early_unregister = radeon_connector_unregister,
1876 .destroy = radeon_connector_destroy,
1877 .force = radeon_dvi_force,
1880 static const struct drm_connector_funcs radeon_edp_connector_funcs = {
1881 .dpms = drm_helper_connector_dpms,
1882 .detect = radeon_dp_detect,
1883 .fill_modes = drm_helper_probe_single_connector_modes,
1884 .set_property = radeon_lvds_set_property,
1885 .early_unregister = radeon_connector_unregister,
1886 .destroy = radeon_connector_destroy,
1887 .force = radeon_dvi_force,
1890 static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
1891 .dpms = drm_helper_connector_dpms,
1892 .detect = radeon_dp_detect,
1893 .fill_modes = drm_helper_probe_single_connector_modes,
1894 .set_property = radeon_lvds_set_property,
1895 .early_unregister = radeon_connector_unregister,
1896 .destroy = radeon_connector_destroy,
1897 .force = radeon_dvi_force,
1900 void
1901 radeon_add_atom_connector(struct drm_device *dev,
1902 uint32_t connector_id,
1903 uint32_t supported_device,
1904 int connector_type,
1905 struct radeon_i2c_bus_rec *i2c_bus,
1906 uint32_t igp_lane_info,
1907 uint16_t connector_object_id,
1908 struct radeon_hpd *hpd,
1909 struct radeon_router *router)
1911 struct radeon_device *rdev = dev->dev_private;
1912 struct drm_connector *connector;
1913 struct radeon_connector *radeon_connector;
1914 struct radeon_connector_atom_dig *radeon_dig_connector;
1915 struct drm_encoder *encoder;
1916 struct radeon_encoder *radeon_encoder;
1917 uint32_t subpixel_order = SubPixelNone;
1918 bool shared_ddc = false;
1919 bool is_dp_bridge = false;
1920 bool has_aux = false;
1922 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1923 return;
1925 /* if the user selected tv=0 don't try and add the connector */
1926 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1927 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1928 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1929 (radeon_tv == 0))
1930 return;
1932 /* see if we already added it */
1933 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1934 radeon_connector = to_radeon_connector(connector);
1935 if (radeon_connector->connector_id == connector_id) {
1936 radeon_connector->devices |= supported_device;
1937 return;
1939 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1940 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1941 radeon_connector->shared_ddc = true;
1942 shared_ddc = true;
1944 if (radeon_connector->router_bus && router->ddc_valid &&
1945 (radeon_connector->router.router_id == router->router_id)) {
1946 radeon_connector->shared_ddc = false;
1947 shared_ddc = false;
1952 /* check if it's a dp bridge */
1953 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1954 radeon_encoder = to_radeon_encoder(encoder);
1955 if (radeon_encoder->devices & supported_device) {
1956 switch (radeon_encoder->encoder_id) {
1957 case ENCODER_OBJECT_ID_TRAVIS:
1958 case ENCODER_OBJECT_ID_NUTMEG:
1959 is_dp_bridge = true;
1960 break;
1961 default:
1962 break;
1967 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1968 if (!radeon_connector)
1969 return;
1971 connector = &radeon_connector->base;
1973 radeon_connector->connector_id = connector_id;
1974 radeon_connector->devices = supported_device;
1975 radeon_connector->shared_ddc = shared_ddc;
1976 radeon_connector->connector_object_id = connector_object_id;
1977 radeon_connector->hpd = *hpd;
1979 radeon_connector->router = *router;
1980 if (router->ddc_valid || router->cd_valid) {
1981 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1982 if (!radeon_connector->router_bus)
1983 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
1986 if (is_dp_bridge) {
1987 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1988 if (!radeon_dig_connector)
1989 goto failed;
1990 radeon_dig_connector->igp_lane_info = igp_lane_info;
1991 radeon_connector->con_priv = radeon_dig_connector;
1992 if (i2c_bus->valid) {
1993 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1994 if (radeon_connector->ddc_bus)
1995 has_aux = true;
1996 else
1997 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1999 switch (connector_type) {
2000 case DRM_MODE_CONNECTOR_VGA:
2001 case DRM_MODE_CONNECTOR_DVIA:
2002 default:
2003 drm_connector_init(dev, &radeon_connector->base,
2004 &radeon_dp_connector_funcs, connector_type);
2005 drm_connector_helper_add(&radeon_connector->base,
2006 &radeon_dp_connector_helper_funcs);
2007 connector->interlace_allowed = true;
2008 connector->doublescan_allowed = true;
2009 radeon_connector->dac_load_detect = true;
2010 drm_object_attach_property(&radeon_connector->base.base,
2011 rdev->mode_info.load_detect_property,
2013 drm_object_attach_property(&radeon_connector->base.base,
2014 dev->mode_config.scaling_mode_property,
2015 DRM_MODE_SCALE_NONE);
2016 if (ASIC_IS_DCE5(rdev))
2017 drm_object_attach_property(&radeon_connector->base.base,
2018 rdev->mode_info.output_csc_property,
2019 RADEON_OUTPUT_CSC_BYPASS);
2020 break;
2021 case DRM_MODE_CONNECTOR_DVII:
2022 case DRM_MODE_CONNECTOR_DVID:
2023 case DRM_MODE_CONNECTOR_HDMIA:
2024 case DRM_MODE_CONNECTOR_HDMIB:
2025 case DRM_MODE_CONNECTOR_DisplayPort:
2026 drm_connector_init(dev, &radeon_connector->base,
2027 &radeon_dp_connector_funcs, connector_type);
2028 drm_connector_helper_add(&radeon_connector->base,
2029 &radeon_dp_connector_helper_funcs);
2030 drm_object_attach_property(&radeon_connector->base.base,
2031 rdev->mode_info.underscan_property,
2032 UNDERSCAN_OFF);
2033 drm_object_attach_property(&radeon_connector->base.base,
2034 rdev->mode_info.underscan_hborder_property,
2036 drm_object_attach_property(&radeon_connector->base.base,
2037 rdev->mode_info.underscan_vborder_property,
2040 drm_object_attach_property(&radeon_connector->base.base,
2041 dev->mode_config.scaling_mode_property,
2042 DRM_MODE_SCALE_NONE);
2044 drm_object_attach_property(&radeon_connector->base.base,
2045 rdev->mode_info.dither_property,
2046 RADEON_FMT_DITHER_DISABLE);
2048 if (radeon_audio != 0) {
2049 drm_object_attach_property(&radeon_connector->base.base,
2050 rdev->mode_info.audio_property,
2051 RADEON_AUDIO_AUTO);
2052 radeon_connector->audio = RADEON_AUDIO_AUTO;
2054 if (ASIC_IS_DCE5(rdev))
2055 drm_object_attach_property(&radeon_connector->base.base,
2056 rdev->mode_info.output_csc_property,
2057 RADEON_OUTPUT_CSC_BYPASS);
2059 subpixel_order = SubPixelHorizontalRGB;
2060 connector->interlace_allowed = true;
2061 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
2062 connector->doublescan_allowed = true;
2063 else
2064 connector->doublescan_allowed = false;
2065 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2066 radeon_connector->dac_load_detect = true;
2067 drm_object_attach_property(&radeon_connector->base.base,
2068 rdev->mode_info.load_detect_property,
2071 break;
2072 case DRM_MODE_CONNECTOR_LVDS:
2073 case DRM_MODE_CONNECTOR_eDP:
2074 drm_connector_init(dev, &radeon_connector->base,
2075 &radeon_lvds_bridge_connector_funcs, connector_type);
2076 drm_connector_helper_add(&radeon_connector->base,
2077 &radeon_dp_connector_helper_funcs);
2078 drm_object_attach_property(&radeon_connector->base.base,
2079 dev->mode_config.scaling_mode_property,
2080 DRM_MODE_SCALE_FULLSCREEN);
2081 subpixel_order = SubPixelHorizontalRGB;
2082 connector->interlace_allowed = false;
2083 connector->doublescan_allowed = false;
2084 break;
2086 } else {
2087 switch (connector_type) {
2088 case DRM_MODE_CONNECTOR_VGA:
2089 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2090 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2091 if (i2c_bus->valid) {
2092 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2093 if (!radeon_connector->ddc_bus)
2094 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2096 radeon_connector->dac_load_detect = true;
2097 drm_object_attach_property(&radeon_connector->base.base,
2098 rdev->mode_info.load_detect_property,
2100 if (ASIC_IS_AVIVO(rdev))
2101 drm_object_attach_property(&radeon_connector->base.base,
2102 dev->mode_config.scaling_mode_property,
2103 DRM_MODE_SCALE_NONE);
2104 if (ASIC_IS_DCE5(rdev))
2105 drm_object_attach_property(&radeon_connector->base.base,
2106 rdev->mode_info.output_csc_property,
2107 RADEON_OUTPUT_CSC_BYPASS);
2108 /* no HPD on analog connectors */
2109 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2110 connector->interlace_allowed = true;
2111 connector->doublescan_allowed = true;
2112 break;
2113 case DRM_MODE_CONNECTOR_DVIA:
2114 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2115 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2116 if (i2c_bus->valid) {
2117 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2118 if (!radeon_connector->ddc_bus)
2119 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2121 radeon_connector->dac_load_detect = true;
2122 drm_object_attach_property(&radeon_connector->base.base,
2123 rdev->mode_info.load_detect_property,
2125 if (ASIC_IS_AVIVO(rdev))
2126 drm_object_attach_property(&radeon_connector->base.base,
2127 dev->mode_config.scaling_mode_property,
2128 DRM_MODE_SCALE_NONE);
2129 if (ASIC_IS_DCE5(rdev))
2130 drm_object_attach_property(&radeon_connector->base.base,
2131 rdev->mode_info.output_csc_property,
2132 RADEON_OUTPUT_CSC_BYPASS);
2133 /* no HPD on analog connectors */
2134 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2135 connector->interlace_allowed = true;
2136 connector->doublescan_allowed = true;
2137 break;
2138 case DRM_MODE_CONNECTOR_DVII:
2139 case DRM_MODE_CONNECTOR_DVID:
2140 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2141 if (!radeon_dig_connector)
2142 goto failed;
2143 radeon_dig_connector->igp_lane_info = igp_lane_info;
2144 radeon_connector->con_priv = radeon_dig_connector;
2145 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
2146 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2147 if (i2c_bus->valid) {
2148 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2149 if (!radeon_connector->ddc_bus)
2150 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2152 subpixel_order = SubPixelHorizontalRGB;
2153 drm_object_attach_property(&radeon_connector->base.base,
2154 rdev->mode_info.coherent_mode_property,
2156 if (ASIC_IS_AVIVO(rdev)) {
2157 drm_object_attach_property(&radeon_connector->base.base,
2158 rdev->mode_info.underscan_property,
2159 UNDERSCAN_OFF);
2160 drm_object_attach_property(&radeon_connector->base.base,
2161 rdev->mode_info.underscan_hborder_property,
2163 drm_object_attach_property(&radeon_connector->base.base,
2164 rdev->mode_info.underscan_vborder_property,
2166 drm_object_attach_property(&radeon_connector->base.base,
2167 rdev->mode_info.dither_property,
2168 RADEON_FMT_DITHER_DISABLE);
2169 drm_object_attach_property(&radeon_connector->base.base,
2170 dev->mode_config.scaling_mode_property,
2171 DRM_MODE_SCALE_NONE);
2173 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2174 drm_object_attach_property(&radeon_connector->base.base,
2175 rdev->mode_info.audio_property,
2176 RADEON_AUDIO_AUTO);
2177 radeon_connector->audio = RADEON_AUDIO_AUTO;
2179 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2180 radeon_connector->dac_load_detect = true;
2181 drm_object_attach_property(&radeon_connector->base.base,
2182 rdev->mode_info.load_detect_property,
2185 if (ASIC_IS_DCE5(rdev))
2186 drm_object_attach_property(&radeon_connector->base.base,
2187 rdev->mode_info.output_csc_property,
2188 RADEON_OUTPUT_CSC_BYPASS);
2189 connector->interlace_allowed = true;
2190 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2191 connector->doublescan_allowed = true;
2192 else
2193 connector->doublescan_allowed = false;
2194 break;
2195 case DRM_MODE_CONNECTOR_HDMIA:
2196 case DRM_MODE_CONNECTOR_HDMIB:
2197 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2198 if (!radeon_dig_connector)
2199 goto failed;
2200 radeon_dig_connector->igp_lane_info = igp_lane_info;
2201 radeon_connector->con_priv = radeon_dig_connector;
2202 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
2203 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2204 if (i2c_bus->valid) {
2205 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2206 if (!radeon_connector->ddc_bus)
2207 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2209 drm_object_attach_property(&radeon_connector->base.base,
2210 rdev->mode_info.coherent_mode_property,
2212 if (ASIC_IS_AVIVO(rdev)) {
2213 drm_object_attach_property(&radeon_connector->base.base,
2214 rdev->mode_info.underscan_property,
2215 UNDERSCAN_OFF);
2216 drm_object_attach_property(&radeon_connector->base.base,
2217 rdev->mode_info.underscan_hborder_property,
2219 drm_object_attach_property(&radeon_connector->base.base,
2220 rdev->mode_info.underscan_vborder_property,
2222 drm_object_attach_property(&radeon_connector->base.base,
2223 rdev->mode_info.dither_property,
2224 RADEON_FMT_DITHER_DISABLE);
2225 drm_object_attach_property(&radeon_connector->base.base,
2226 dev->mode_config.scaling_mode_property,
2227 DRM_MODE_SCALE_NONE);
2229 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2230 drm_object_attach_property(&radeon_connector->base.base,
2231 rdev->mode_info.audio_property,
2232 RADEON_AUDIO_AUTO);
2233 radeon_connector->audio = RADEON_AUDIO_AUTO;
2235 if (ASIC_IS_DCE5(rdev))
2236 drm_object_attach_property(&radeon_connector->base.base,
2237 rdev->mode_info.output_csc_property,
2238 RADEON_OUTPUT_CSC_BYPASS);
2239 subpixel_order = SubPixelHorizontalRGB;
2240 connector->interlace_allowed = true;
2241 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
2242 connector->doublescan_allowed = true;
2243 else
2244 connector->doublescan_allowed = false;
2245 break;
2246 case DRM_MODE_CONNECTOR_DisplayPort:
2247 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2248 if (!radeon_dig_connector)
2249 goto failed;
2250 radeon_dig_connector->igp_lane_info = igp_lane_info;
2251 radeon_connector->con_priv = radeon_dig_connector;
2252 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
2253 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2254 if (i2c_bus->valid) {
2255 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2256 if (radeon_connector->ddc_bus)
2257 has_aux = true;
2258 else
2259 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2261 subpixel_order = SubPixelHorizontalRGB;
2262 drm_object_attach_property(&radeon_connector->base.base,
2263 rdev->mode_info.coherent_mode_property,
2265 if (ASIC_IS_AVIVO(rdev)) {
2266 drm_object_attach_property(&radeon_connector->base.base,
2267 rdev->mode_info.underscan_property,
2268 UNDERSCAN_OFF);
2269 drm_object_attach_property(&radeon_connector->base.base,
2270 rdev->mode_info.underscan_hborder_property,
2272 drm_object_attach_property(&radeon_connector->base.base,
2273 rdev->mode_info.underscan_vborder_property,
2275 drm_object_attach_property(&radeon_connector->base.base,
2276 rdev->mode_info.dither_property,
2277 RADEON_FMT_DITHER_DISABLE);
2278 drm_object_attach_property(&radeon_connector->base.base,
2279 dev->mode_config.scaling_mode_property,
2280 DRM_MODE_SCALE_NONE);
2282 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2283 drm_object_attach_property(&radeon_connector->base.base,
2284 rdev->mode_info.audio_property,
2285 RADEON_AUDIO_AUTO);
2286 radeon_connector->audio = RADEON_AUDIO_AUTO;
2288 if (ASIC_IS_DCE5(rdev))
2289 drm_object_attach_property(&radeon_connector->base.base,
2290 rdev->mode_info.output_csc_property,
2291 RADEON_OUTPUT_CSC_BYPASS);
2292 connector->interlace_allowed = true;
2293 /* in theory with a DP to VGA converter... */
2294 connector->doublescan_allowed = false;
2295 break;
2296 case DRM_MODE_CONNECTOR_eDP:
2297 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2298 if (!radeon_dig_connector)
2299 goto failed;
2300 radeon_dig_connector->igp_lane_info = igp_lane_info;
2301 radeon_connector->con_priv = radeon_dig_connector;
2302 drm_connector_init(dev, &radeon_connector->base, &radeon_edp_connector_funcs, connector_type);
2303 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2304 if (i2c_bus->valid) {
2305 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2306 if (radeon_connector->ddc_bus)
2307 has_aux = true;
2308 else
2309 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2311 drm_object_attach_property(&radeon_connector->base.base,
2312 dev->mode_config.scaling_mode_property,
2313 DRM_MODE_SCALE_FULLSCREEN);
2314 subpixel_order = SubPixelHorizontalRGB;
2315 connector->interlace_allowed = false;
2316 connector->doublescan_allowed = false;
2317 break;
2318 case DRM_MODE_CONNECTOR_SVIDEO:
2319 case DRM_MODE_CONNECTOR_Composite:
2320 case DRM_MODE_CONNECTOR_9PinDIN:
2321 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
2322 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2323 radeon_connector->dac_load_detect = true;
2324 drm_object_attach_property(&radeon_connector->base.base,
2325 rdev->mode_info.load_detect_property,
2327 drm_object_attach_property(&radeon_connector->base.base,
2328 rdev->mode_info.tv_std_property,
2329 radeon_atombios_get_tv_info(rdev));
2330 /* no HPD on analog connectors */
2331 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2332 connector->interlace_allowed = false;
2333 connector->doublescan_allowed = false;
2334 break;
2335 case DRM_MODE_CONNECTOR_LVDS:
2336 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2337 if (!radeon_dig_connector)
2338 goto failed;
2339 radeon_dig_connector->igp_lane_info = igp_lane_info;
2340 radeon_connector->con_priv = radeon_dig_connector;
2341 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
2342 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2343 if (i2c_bus->valid) {
2344 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2345 if (!radeon_connector->ddc_bus)
2346 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2348 drm_object_attach_property(&radeon_connector->base.base,
2349 dev->mode_config.scaling_mode_property,
2350 DRM_MODE_SCALE_FULLSCREEN);
2351 subpixel_order = SubPixelHorizontalRGB;
2352 connector->interlace_allowed = false;
2353 connector->doublescan_allowed = false;
2354 break;
2358 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
2359 if (i2c_bus->valid) {
2360 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2361 DRM_CONNECTOR_POLL_DISCONNECT;
2363 } else
2364 connector->polled = DRM_CONNECTOR_POLL_HPD;
2366 connector->display_info.subpixel_order = subpixel_order;
2367 drm_connector_register(connector);
2369 if (has_aux)
2370 radeon_dp_aux_init(radeon_connector);
2372 return;
2374 failed:
2375 drm_connector_cleanup(connector);
2376 kfree(connector);
2379 void
2380 radeon_add_legacy_connector(struct drm_device *dev,
2381 uint32_t connector_id,
2382 uint32_t supported_device,
2383 int connector_type,
2384 struct radeon_i2c_bus_rec *i2c_bus,
2385 uint16_t connector_object_id,
2386 struct radeon_hpd *hpd)
2388 struct radeon_device *rdev = dev->dev_private;
2389 struct drm_connector *connector;
2390 struct radeon_connector *radeon_connector;
2391 uint32_t subpixel_order = SubPixelNone;
2393 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
2394 return;
2396 /* if the user selected tv=0 don't try and add the connector */
2397 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
2398 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
2399 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
2400 (radeon_tv == 0))
2401 return;
2403 /* see if we already added it */
2404 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2405 radeon_connector = to_radeon_connector(connector);
2406 if (radeon_connector->connector_id == connector_id) {
2407 radeon_connector->devices |= supported_device;
2408 return;
2412 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
2413 if (!radeon_connector)
2414 return;
2416 connector = &radeon_connector->base;
2418 radeon_connector->connector_id = connector_id;
2419 radeon_connector->devices = supported_device;
2420 radeon_connector->connector_object_id = connector_object_id;
2421 radeon_connector->hpd = *hpd;
2423 switch (connector_type) {
2424 case DRM_MODE_CONNECTOR_VGA:
2425 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2426 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2427 if (i2c_bus->valid) {
2428 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2429 if (!radeon_connector->ddc_bus)
2430 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2432 radeon_connector->dac_load_detect = true;
2433 drm_object_attach_property(&radeon_connector->base.base,
2434 rdev->mode_info.load_detect_property,
2436 /* no HPD on analog connectors */
2437 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2438 connector->interlace_allowed = true;
2439 connector->doublescan_allowed = true;
2440 break;
2441 case DRM_MODE_CONNECTOR_DVIA:
2442 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2443 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2444 if (i2c_bus->valid) {
2445 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2446 if (!radeon_connector->ddc_bus)
2447 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2449 radeon_connector->dac_load_detect = true;
2450 drm_object_attach_property(&radeon_connector->base.base,
2451 rdev->mode_info.load_detect_property,
2453 /* no HPD on analog connectors */
2454 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2455 connector->interlace_allowed = true;
2456 connector->doublescan_allowed = true;
2457 break;
2458 case DRM_MODE_CONNECTOR_DVII:
2459 case DRM_MODE_CONNECTOR_DVID:
2460 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
2461 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2462 if (i2c_bus->valid) {
2463 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2464 if (!radeon_connector->ddc_bus)
2465 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2467 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2468 radeon_connector->dac_load_detect = true;
2469 drm_object_attach_property(&radeon_connector->base.base,
2470 rdev->mode_info.load_detect_property,
2473 subpixel_order = SubPixelHorizontalRGB;
2474 connector->interlace_allowed = true;
2475 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2476 connector->doublescan_allowed = true;
2477 else
2478 connector->doublescan_allowed = false;
2479 break;
2480 case DRM_MODE_CONNECTOR_SVIDEO:
2481 case DRM_MODE_CONNECTOR_Composite:
2482 case DRM_MODE_CONNECTOR_9PinDIN:
2483 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
2484 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2485 radeon_connector->dac_load_detect = true;
2486 /* RS400,RC410,RS480 chipset seems to report a lot
2487 * of false positive on load detect, we haven't yet
2488 * found a way to make load detect reliable on those
2489 * chipset, thus just disable it for TV.
2491 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
2492 radeon_connector->dac_load_detect = false;
2493 drm_object_attach_property(&radeon_connector->base.base,
2494 rdev->mode_info.load_detect_property,
2495 radeon_connector->dac_load_detect);
2496 drm_object_attach_property(&radeon_connector->base.base,
2497 rdev->mode_info.tv_std_property,
2498 radeon_combios_get_tv_info(rdev));
2499 /* no HPD on analog connectors */
2500 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2501 connector->interlace_allowed = false;
2502 connector->doublescan_allowed = false;
2503 break;
2504 case DRM_MODE_CONNECTOR_LVDS:
2505 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
2506 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2507 if (i2c_bus->valid) {
2508 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2509 if (!radeon_connector->ddc_bus)
2510 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2512 drm_object_attach_property(&radeon_connector->base.base,
2513 dev->mode_config.scaling_mode_property,
2514 DRM_MODE_SCALE_FULLSCREEN);
2515 subpixel_order = SubPixelHorizontalRGB;
2516 connector->interlace_allowed = false;
2517 connector->doublescan_allowed = false;
2518 break;
2521 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
2522 if (i2c_bus->valid) {
2523 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2524 DRM_CONNECTOR_POLL_DISCONNECT;
2526 } else
2527 connector->polled = DRM_CONNECTOR_POLL_HPD;
2529 connector->display_info.subpixel_order = subpixel_order;
2530 drm_connector_register(connector);
2533 void radeon_setup_mst_connector(struct drm_device *dev)
2535 struct radeon_device *rdev = dev->dev_private;
2536 struct drm_connector *connector;
2537 struct radeon_connector *radeon_connector;
2539 if (!ASIC_IS_DCE5(rdev))
2540 return;
2542 if (radeon_mst == 0)
2543 return;
2545 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2546 int ret;
2548 radeon_connector = to_radeon_connector(connector);
2550 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
2551 continue;
2553 ret = radeon_dp_mst_init(radeon_connector);