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
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_fb_helper.h>
31 #include <drm/drm_probe_helper.h>
32 #include <drm/radeon_drm.h>
34 #include "radeon_audio.h"
37 #include <linux/pm_runtime.h>
38 #include <linux/vga_switcheroo.h>
40 void radeon_connector_hotplug(struct drm_connector *connector)
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);
46 /* bail if the connector does not have hpd pin, e.g.,
49 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE)
52 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
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)
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;
64 /* if existing sink type was not DP no need to retrain */
65 if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT)
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
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))
80 /* Turn the connector off and back on immediately, which
81 * will trigger link training
83 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
84 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
89 static void radeon_property_change_mode(struct drm_encoder *encoder)
91 struct drm_crtc *crtc = encoder->crtc;
93 if (crtc && crtc->enabled) {
94 drm_crtc_helper_set_mode(crtc, &crtc->mode,
95 crtc->x, crtc->y, crtc->primary->fb);
99 int radeon_get_monitor_bpc(struct drm_connector *connector)
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;
106 int mode_clock, max_tmds_clock;
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 (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
113 if (connector->display_info.bpc)
114 bpc = connector->display_info.bpc;
118 case DRM_MODE_CONNECTOR_DVID:
119 case DRM_MODE_CONNECTOR_HDMIA:
120 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
121 if (connector->display_info.bpc)
122 bpc = connector->display_info.bpc;
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 drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
130 if (connector->display_info.bpc)
131 bpc = connector->display_info.bpc;
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;
145 if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR)
147 else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR)
153 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
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);
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.
168 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 12 bpc.\n",
169 connector->name, bpc);
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;
178 /* Maximum allowable input clock in kHz */
179 max_tmds_clock = connector->display_info.max_tmds_clock;
181 DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds input clock %d kHz.\n",
182 connector->name, mode_clock, max_tmds_clock);
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))
192 DRM_DEBUG("%s: HDMI deep color 12 bpc exceeds max tmds clock. Using %d bpc.\n",
193 connector->name, bpc);
196 if ((bpc == 10) && (mode_clock * 5/4 > max_tmds_clock)) {
198 DRM_DEBUG("%s: HDMI deep color 10 bpc exceeds max tmds clock. Using %d bpc.\n",
199 connector->name, bpc);
203 /* max_tmds_clock missing, but hdmi spec mandates it for deep color. */
204 DRM_DEBUG("%s: Required max tmds clock for HDMI deep color missing. Using 8 bpc.\n",
210 if ((radeon_deep_color == 0) && (bpc > 8)) {
211 DRM_DEBUG("%s: Deep color disabled. Set radeon module param deep_color=1 to enable.\n",
216 DRM_DEBUG("%s: Display bpc=%d, returned bpc=%d\n",
217 connector->name, connector->display_info.bpc, bpc);
223 radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
225 struct drm_device *dev = connector->dev;
226 struct radeon_device *rdev = dev->dev_private;
227 struct drm_encoder *best_encoder;
228 struct drm_encoder *encoder;
229 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
232 best_encoder = connector_funcs->best_encoder(connector);
234 drm_connector_for_each_possible_encoder(connector, encoder) {
235 if ((encoder == best_encoder) && (status == connector_status_connected))
240 if (rdev->is_atom_bios)
241 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
243 radeon_combios_connected_scratch_regs(connector, encoder, connected);
247 static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
249 struct drm_encoder *encoder;
251 drm_connector_for_each_possible_encoder(connector, encoder) {
252 if (encoder->encoder_type == encoder_type)
259 struct edid *radeon_connector_edid(struct drm_connector *connector)
261 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
262 struct drm_property_blob *edid_blob = connector->edid_blob_ptr;
264 if (radeon_connector->edid) {
265 return radeon_connector->edid;
266 } else if (edid_blob) {
267 struct edid *edid = kmemdup(edid_blob->data, edid_blob->length, GFP_KERNEL);
269 radeon_connector->edid = edid;
271 return radeon_connector->edid;
274 static void radeon_connector_get_edid(struct drm_connector *connector)
276 struct drm_device *dev = connector->dev;
277 struct radeon_device *rdev = dev->dev_private;
278 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
280 if (radeon_connector->edid)
283 /* on hw with routers, select right port */
284 if (radeon_connector->router.ddc_valid)
285 radeon_router_select_ddc_port(radeon_connector);
287 if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
288 ENCODER_OBJECT_ID_NONE) &&
289 radeon_connector->ddc_bus->has_aux) {
290 radeon_connector->edid = drm_get_edid(connector,
291 &radeon_connector->ddc_bus->aux.ddc);
292 } else if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
293 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
294 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
296 if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
297 dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) &&
298 radeon_connector->ddc_bus->has_aux)
299 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
300 &radeon_connector->ddc_bus->aux.ddc);
301 else if (radeon_connector->ddc_bus)
302 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
303 &radeon_connector->ddc_bus->adapter);
304 } else if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC &&
305 connector->connector_type == DRM_MODE_CONNECTOR_LVDS &&
306 radeon_connector->ddc_bus) {
307 radeon_connector->edid = drm_get_edid_switcheroo(&radeon_connector->base,
308 &radeon_connector->ddc_bus->adapter);
309 } else if (radeon_connector->ddc_bus) {
310 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
311 &radeon_connector->ddc_bus->adapter);
314 if (!radeon_connector->edid) {
315 /* don't fetch the edid from the vbios if ddc fails and runpm is
316 * enabled so we report disconnected.
318 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
321 if (rdev->is_atom_bios) {
322 /* some laptops provide a hardcoded edid in rom for LCDs */
323 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
324 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)))
325 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
327 /* some servers provide a hardcoded edid in rom for KVMs */
328 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
333 static void radeon_connector_free_edid(struct drm_connector *connector)
335 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
337 if (radeon_connector->edid) {
338 kfree(radeon_connector->edid);
339 radeon_connector->edid = NULL;
343 static int radeon_ddc_get_modes(struct drm_connector *connector)
345 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
348 if (radeon_connector->edid) {
349 drm_connector_update_edid_property(connector, radeon_connector->edid);
350 ret = drm_add_edid_modes(connector, radeon_connector->edid);
353 drm_connector_update_edid_property(connector, NULL);
357 static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
359 struct drm_encoder *encoder;
361 /* pick the first one */
362 drm_connector_for_each_possible_encoder(connector, encoder)
368 static void radeon_get_native_mode(struct drm_connector *connector)
370 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
371 struct radeon_encoder *radeon_encoder;
376 radeon_encoder = to_radeon_encoder(encoder);
378 if (!list_empty(&connector->probed_modes)) {
379 struct drm_display_mode *preferred_mode =
380 list_first_entry(&connector->probed_modes,
381 struct drm_display_mode, head);
383 radeon_encoder->native_mode = *preferred_mode;
385 radeon_encoder->native_mode.clock = 0;
390 * radeon_connector_analog_encoder_conflict_solve
391 * - search for other connectors sharing this encoder
392 * if priority is true, then set them disconnected if this is connected
393 * if priority is false, set us disconnected if they are connected
395 static enum drm_connector_status
396 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
397 struct drm_encoder *encoder,
398 enum drm_connector_status current_status,
401 struct drm_device *dev = connector->dev;
402 struct drm_connector *conflict;
403 struct radeon_connector *radeon_conflict;
405 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
406 struct drm_encoder *enc;
408 if (conflict == connector)
411 radeon_conflict = to_radeon_connector(conflict);
413 drm_connector_for_each_possible_encoder(conflict, enc) {
414 /* if the IDs match */
415 if (enc == encoder) {
416 if (conflict->status != connector_status_connected)
419 if (radeon_conflict->use_digital)
423 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n",
425 DRM_DEBUG_KMS("in favor of %s\n",
427 conflict->status = connector_status_disconnected;
428 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
430 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n",
432 DRM_DEBUG_KMS("in favor of %s\n",
434 current_status = connector_status_disconnected;
440 return current_status;
444 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
446 struct drm_device *dev = encoder->dev;
447 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
448 struct drm_display_mode *mode = NULL;
449 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
451 if (native_mode->hdisplay != 0 &&
452 native_mode->vdisplay != 0 &&
453 native_mode->clock != 0) {
454 mode = drm_mode_duplicate(dev, native_mode);
457 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
458 drm_mode_set_name(mode);
460 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
461 } else if (native_mode->hdisplay != 0 &&
462 native_mode->vdisplay != 0) {
463 /* mac laptops without an edid */
464 /* Note that this is not necessarily the exact panel mode,
465 * but an approximation based on the cvt formula. For these
466 * systems we should ideally read the mode info out of the
467 * registers or add a mode table, but this works and is much
470 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
473 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
474 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
479 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
481 struct drm_device *dev = encoder->dev;
482 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
483 struct drm_display_mode *mode = NULL;
484 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
489 } common_modes[17] = {
509 for (i = 0; i < 17; i++) {
510 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
511 if (common_modes[i].w > 1024 ||
512 common_modes[i].h > 768)
515 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
516 if (common_modes[i].w > native_mode->hdisplay ||
517 common_modes[i].h > native_mode->vdisplay ||
518 (common_modes[i].w == native_mode->hdisplay &&
519 common_modes[i].h == native_mode->vdisplay))
522 if (common_modes[i].w < 320 || common_modes[i].h < 200)
525 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
526 drm_mode_probed_add(connector, mode);
530 static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
533 struct drm_device *dev = connector->dev;
534 struct radeon_device *rdev = dev->dev_private;
535 struct drm_encoder *encoder;
536 struct radeon_encoder *radeon_encoder;
538 if (property == rdev->mode_info.coherent_mode_property) {
539 struct radeon_encoder_atom_dig *dig;
540 bool new_coherent_mode;
542 /* need to find digital encoder on connector */
543 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
547 radeon_encoder = to_radeon_encoder(encoder);
549 if (!radeon_encoder->enc_priv)
552 dig = radeon_encoder->enc_priv;
553 new_coherent_mode = val ? true : false;
554 if (dig->coherent_mode != new_coherent_mode) {
555 dig->coherent_mode = new_coherent_mode;
556 radeon_property_change_mode(&radeon_encoder->base);
560 if (property == rdev->mode_info.audio_property) {
561 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
562 /* need to find digital encoder on connector */
563 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
567 radeon_encoder = to_radeon_encoder(encoder);
569 if (radeon_connector->audio != val) {
570 radeon_connector->audio = val;
571 radeon_property_change_mode(&radeon_encoder->base);
575 if (property == rdev->mode_info.dither_property) {
576 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
577 /* need to find digital encoder on connector */
578 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
582 radeon_encoder = to_radeon_encoder(encoder);
584 if (radeon_connector->dither != val) {
585 radeon_connector->dither = val;
586 radeon_property_change_mode(&radeon_encoder->base);
590 if (property == rdev->mode_info.underscan_property) {
591 /* need to find digital encoder on connector */
592 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
596 radeon_encoder = to_radeon_encoder(encoder);
598 if (radeon_encoder->underscan_type != val) {
599 radeon_encoder->underscan_type = val;
600 radeon_property_change_mode(&radeon_encoder->base);
604 if (property == rdev->mode_info.underscan_hborder_property) {
605 /* need to find digital encoder on connector */
606 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
610 radeon_encoder = to_radeon_encoder(encoder);
612 if (radeon_encoder->underscan_hborder != val) {
613 radeon_encoder->underscan_hborder = val;
614 radeon_property_change_mode(&radeon_encoder->base);
618 if (property == rdev->mode_info.underscan_vborder_property) {
619 /* need to find digital encoder on connector */
620 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
624 radeon_encoder = to_radeon_encoder(encoder);
626 if (radeon_encoder->underscan_vborder != val) {
627 radeon_encoder->underscan_vborder = val;
628 radeon_property_change_mode(&radeon_encoder->base);
632 if (property == rdev->mode_info.tv_std_property) {
633 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
635 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
641 radeon_encoder = to_radeon_encoder(encoder);
642 if (!radeon_encoder->enc_priv)
644 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
645 struct radeon_encoder_atom_dac *dac_int;
646 dac_int = radeon_encoder->enc_priv;
647 dac_int->tv_std = val;
649 struct radeon_encoder_tv_dac *dac_int;
650 dac_int = radeon_encoder->enc_priv;
651 dac_int->tv_std = val;
653 radeon_property_change_mode(&radeon_encoder->base);
656 if (property == rdev->mode_info.load_detect_property) {
657 struct radeon_connector *radeon_connector =
658 to_radeon_connector(connector);
661 radeon_connector->dac_load_detect = false;
663 radeon_connector->dac_load_detect = true;
666 if (property == rdev->mode_info.tmds_pll_property) {
667 struct radeon_encoder_int_tmds *tmds = NULL;
669 /* need to find digital encoder on connector */
670 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
674 radeon_encoder = to_radeon_encoder(encoder);
676 tmds = radeon_encoder->enc_priv;
681 if (rdev->is_atom_bios)
682 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
684 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
686 if (val == 1 || !ret)
687 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
689 radeon_property_change_mode(&radeon_encoder->base);
692 if (property == dev->mode_config.scaling_mode_property) {
693 enum radeon_rmx_type rmx_type;
695 if (connector->encoder)
696 radeon_encoder = to_radeon_encoder(connector->encoder);
698 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
699 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
704 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
705 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
706 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
707 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
709 if (radeon_encoder->rmx_type == rmx_type)
712 if ((rmx_type != DRM_MODE_SCALE_NONE) &&
713 (radeon_encoder->native_mode.clock == 0))
716 radeon_encoder->rmx_type = rmx_type;
718 radeon_property_change_mode(&radeon_encoder->base);
721 if (property == rdev->mode_info.output_csc_property) {
722 if (connector->encoder)
723 radeon_encoder = to_radeon_encoder(connector->encoder);
725 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
726 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
729 if (radeon_encoder->output_csc == val)
732 radeon_encoder->output_csc = val;
734 if (connector->encoder && connector->encoder->crtc) {
735 struct drm_crtc *crtc = connector->encoder->crtc;
736 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
738 radeon_crtc->output_csc = radeon_encoder->output_csc;
741 * Our .gamma_set assumes the .gamma_store has been
742 * prefilled and don't care about its arguments.
744 crtc->funcs->gamma_set(crtc, NULL, NULL, NULL, 0, NULL);
751 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
752 struct drm_connector *connector)
754 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
755 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
756 struct drm_display_mode *t, *mode;
758 /* If the EDID preferred mode doesn't match the native mode, use it */
759 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
760 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
761 if (mode->hdisplay != native_mode->hdisplay ||
762 mode->vdisplay != native_mode->vdisplay)
763 drm_mode_copy(native_mode, mode);
767 /* Try to get native mode details from EDID if necessary */
768 if (!native_mode->clock) {
769 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
770 if (mode->hdisplay == native_mode->hdisplay &&
771 mode->vdisplay == native_mode->vdisplay) {
772 drm_mode_copy(native_mode, mode);
773 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
774 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
780 if (!native_mode->clock) {
781 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
782 radeon_encoder->rmx_type = RMX_OFF;
786 static int radeon_lvds_get_modes(struct drm_connector *connector)
788 struct drm_encoder *encoder;
790 struct drm_display_mode *mode;
792 radeon_connector_get_edid(connector);
793 ret = radeon_ddc_get_modes(connector);
795 encoder = radeon_best_single_encoder(connector);
797 radeon_fixup_lvds_native_mode(encoder, connector);
798 /* add scaled modes */
799 radeon_add_common_modes(encoder, connector);
804 encoder = radeon_best_single_encoder(connector);
808 /* we have no EDID modes */
809 mode = radeon_fp_native_mode(encoder);
812 drm_mode_probed_add(connector, mode);
813 /* add the width/height from vbios tables if available */
814 connector->display_info.width_mm = mode->width_mm;
815 connector->display_info.height_mm = mode->height_mm;
816 /* add scaled modes */
817 radeon_add_common_modes(encoder, connector);
823 static enum drm_mode_status radeon_lvds_mode_valid(struct drm_connector *connector,
824 struct drm_display_mode *mode)
826 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
828 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
832 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
833 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
835 /* AVIVO hardware supports downscaling modes larger than the panel
836 * to the panel size, but I'm not sure this is desirable.
838 if ((mode->hdisplay > native_mode->hdisplay) ||
839 (mode->vdisplay > native_mode->vdisplay))
842 /* if scaling is disabled, block non-native modes */
843 if (radeon_encoder->rmx_type == RMX_OFF) {
844 if ((mode->hdisplay != native_mode->hdisplay) ||
845 (mode->vdisplay != native_mode->vdisplay))
853 static enum drm_connector_status
854 radeon_lvds_detect(struct drm_connector *connector, bool force)
856 struct drm_device *dev = connector->dev;
857 struct radeon_device *rdev = dev->dev_private;
858 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
859 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
860 enum drm_connector_status ret = connector_status_disconnected;
863 if (!drm_kms_helper_is_poll_worker()) {
864 r = pm_runtime_get_sync(connector->dev->dev);
866 pm_runtime_put_autosuspend(connector->dev->dev);
867 return connector_status_disconnected;
872 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
873 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
875 /* check if panel is valid */
876 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
877 ret = connector_status_connected;
878 /* don't fetch the edid from the vbios if ddc fails and runpm is
879 * enabled so we report disconnected.
881 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
882 ret = connector_status_disconnected;
885 /* check for edid as well */
886 radeon_connector_get_edid(connector);
887 if (radeon_connector->edid)
888 ret = connector_status_connected;
889 /* check acpi lid status ??? */
891 radeon_connector_update_scratch_regs(connector, ret);
893 if (!drm_kms_helper_is_poll_worker()) {
894 pm_runtime_mark_last_busy(connector->dev->dev);
895 pm_runtime_put_autosuspend(connector->dev->dev);
901 static void radeon_connector_unregister(struct drm_connector *connector)
903 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
905 if (radeon_connector->ddc_bus && radeon_connector->ddc_bus->has_aux) {
906 drm_dp_aux_unregister(&radeon_connector->ddc_bus->aux);
907 radeon_connector->ddc_bus->has_aux = false;
911 static void radeon_connector_destroy(struct drm_connector *connector)
913 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
915 radeon_connector_free_edid(connector);
916 kfree(radeon_connector->con_priv);
917 drm_connector_unregister(connector);
918 drm_connector_cleanup(connector);
922 static int radeon_lvds_set_property(struct drm_connector *connector,
923 struct drm_property *property,
926 struct drm_device *dev = connector->dev;
927 struct radeon_encoder *radeon_encoder;
928 enum radeon_rmx_type rmx_type;
931 if (property != dev->mode_config.scaling_mode_property)
934 if (connector->encoder)
935 radeon_encoder = to_radeon_encoder(connector->encoder);
937 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
938 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
942 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
943 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
944 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
946 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
948 if (radeon_encoder->rmx_type == rmx_type)
951 radeon_encoder->rmx_type = rmx_type;
953 radeon_property_change_mode(&radeon_encoder->base);
958 static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
959 .get_modes = radeon_lvds_get_modes,
960 .mode_valid = radeon_lvds_mode_valid,
961 .best_encoder = radeon_best_single_encoder,
964 static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
965 .dpms = drm_helper_connector_dpms,
966 .detect = radeon_lvds_detect,
967 .fill_modes = drm_helper_probe_single_connector_modes,
968 .early_unregister = radeon_connector_unregister,
969 .destroy = radeon_connector_destroy,
970 .set_property = radeon_lvds_set_property,
973 static int radeon_vga_get_modes(struct drm_connector *connector)
977 radeon_connector_get_edid(connector);
978 ret = radeon_ddc_get_modes(connector);
980 radeon_get_native_mode(connector);
985 static enum drm_mode_status radeon_vga_mode_valid(struct drm_connector *connector,
986 struct drm_display_mode *mode)
988 struct drm_device *dev = connector->dev;
989 struct radeon_device *rdev = dev->dev_private;
991 /* XXX check mode bandwidth */
993 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
994 return MODE_CLOCK_HIGH;
999 static enum drm_connector_status
1000 radeon_vga_detect(struct drm_connector *connector, bool force)
1002 struct drm_device *dev = connector->dev;
1003 struct radeon_device *rdev = dev->dev_private;
1004 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1005 struct drm_encoder *encoder;
1006 const struct drm_encoder_helper_funcs *encoder_funcs;
1008 enum drm_connector_status ret = connector_status_disconnected;
1011 if (!drm_kms_helper_is_poll_worker()) {
1012 r = pm_runtime_get_sync(connector->dev->dev);
1014 pm_runtime_put_autosuspend(connector->dev->dev);
1015 return connector_status_disconnected;
1019 encoder = radeon_best_single_encoder(connector);
1021 ret = connector_status_disconnected;
1023 if (radeon_connector->ddc_bus)
1024 dret = radeon_ddc_probe(radeon_connector, false);
1026 radeon_connector->detected_by_load = false;
1027 radeon_connector_free_edid(connector);
1028 radeon_connector_get_edid(connector);
1030 if (!radeon_connector->edid) {
1031 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1033 ret = connector_status_connected;
1035 radeon_connector->use_digital =
1036 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
1038 /* some oems have boards with separate digital and analog connectors
1039 * with a shared ddc line (often vga + hdmi)
1041 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
1042 radeon_connector_free_edid(connector);
1043 ret = connector_status_disconnected;
1045 ret = connector_status_connected;
1050 /* if we aren't forcing don't do destructive polling */
1052 /* only return the previous status if we last
1053 * detected a monitor via load.
1055 if (radeon_connector->detected_by_load)
1056 ret = connector->status;
1060 if (radeon_connector->dac_load_detect && encoder) {
1061 encoder_funcs = encoder->helper_private;
1062 ret = encoder_funcs->detect(encoder, connector);
1063 if (ret != connector_status_disconnected)
1064 radeon_connector->detected_by_load = true;
1068 if (ret == connector_status_connected)
1069 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1071 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1072 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1073 * by other means, assume the CRT is connected and use that EDID.
1075 if ((!rdev->is_atom_bios) &&
1076 (ret == connector_status_disconnected) &&
1077 rdev->mode_info.bios_hardcoded_edid_size) {
1078 ret = connector_status_connected;
1081 radeon_connector_update_scratch_regs(connector, ret);
1084 if (!drm_kms_helper_is_poll_worker()) {
1085 pm_runtime_mark_last_busy(connector->dev->dev);
1086 pm_runtime_put_autosuspend(connector->dev->dev);
1092 static const struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
1093 .get_modes = radeon_vga_get_modes,
1094 .mode_valid = radeon_vga_mode_valid,
1095 .best_encoder = radeon_best_single_encoder,
1098 static const struct drm_connector_funcs radeon_vga_connector_funcs = {
1099 .dpms = drm_helper_connector_dpms,
1100 .detect = radeon_vga_detect,
1101 .fill_modes = drm_helper_probe_single_connector_modes,
1102 .early_unregister = radeon_connector_unregister,
1103 .destroy = radeon_connector_destroy,
1104 .set_property = radeon_connector_set_property,
1107 static int radeon_tv_get_modes(struct drm_connector *connector)
1109 struct drm_device *dev = connector->dev;
1110 struct radeon_device *rdev = dev->dev_private;
1111 struct drm_display_mode *tv_mode;
1112 struct drm_encoder *encoder;
1114 encoder = radeon_best_single_encoder(connector);
1118 /* avivo chips can scale any mode */
1119 if (rdev->family >= CHIP_RS600)
1120 /* add scaled modes */
1121 radeon_add_common_modes(encoder, connector);
1123 /* only 800x600 is supported right now on pre-avivo chips */
1124 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
1125 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
1126 drm_mode_probed_add(connector, tv_mode);
1131 static enum drm_mode_status radeon_tv_mode_valid(struct drm_connector *connector,
1132 struct drm_display_mode *mode)
1134 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
1135 return MODE_CLOCK_RANGE;
1139 static enum drm_connector_status
1140 radeon_tv_detect(struct drm_connector *connector, bool force)
1142 struct drm_encoder *encoder;
1143 const struct drm_encoder_helper_funcs *encoder_funcs;
1144 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1145 enum drm_connector_status ret = connector_status_disconnected;
1148 if (!radeon_connector->dac_load_detect)
1151 if (!drm_kms_helper_is_poll_worker()) {
1152 r = pm_runtime_get_sync(connector->dev->dev);
1154 pm_runtime_put_autosuspend(connector->dev->dev);
1155 return connector_status_disconnected;
1159 encoder = radeon_best_single_encoder(connector);
1161 ret = connector_status_disconnected;
1163 encoder_funcs = encoder->helper_private;
1164 ret = encoder_funcs->detect(encoder, connector);
1166 if (ret == connector_status_connected)
1167 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
1168 radeon_connector_update_scratch_regs(connector, ret);
1170 if (!drm_kms_helper_is_poll_worker()) {
1171 pm_runtime_mark_last_busy(connector->dev->dev);
1172 pm_runtime_put_autosuspend(connector->dev->dev);
1178 static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
1179 .get_modes = radeon_tv_get_modes,
1180 .mode_valid = radeon_tv_mode_valid,
1181 .best_encoder = radeon_best_single_encoder,
1184 static const struct drm_connector_funcs radeon_tv_connector_funcs = {
1185 .dpms = drm_helper_connector_dpms,
1186 .detect = radeon_tv_detect,
1187 .fill_modes = drm_helper_probe_single_connector_modes,
1188 .early_unregister = radeon_connector_unregister,
1189 .destroy = radeon_connector_destroy,
1190 .set_property = radeon_connector_set_property,
1193 static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector)
1195 struct drm_device *dev = connector->dev;
1196 struct radeon_device *rdev = dev->dev_private;
1197 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1198 enum drm_connector_status status;
1200 /* We only trust HPD on R600 and newer ASICS. */
1201 if (rdev->family >= CHIP_R600
1202 && radeon_connector->hpd.hpd != RADEON_HPD_NONE) {
1203 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
1204 status = connector_status_connected;
1206 status = connector_status_disconnected;
1207 if (connector->status == status)
1215 * DVI is complicated
1216 * Do a DDC probe, if DDC probe passes, get the full EDID so
1217 * we can do analog/digital monitor detection at this point.
1218 * If the monitor is an analog monitor or we got no DDC,
1219 * we need to find the DAC encoder object for this connector.
1220 * If we got no DDC, we do load detection on the DAC encoder object.
1221 * If we got analog DDC or load detection passes on the DAC encoder
1222 * we have to check if this analog encoder is shared with anyone else (TV)
1223 * if its shared we have to set the other connector to disconnected.
1225 static enum drm_connector_status
1226 radeon_dvi_detect(struct drm_connector *connector, bool force)
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 struct drm_encoder *encoder = NULL;
1232 const struct drm_encoder_helper_funcs *encoder_funcs;
1234 enum drm_connector_status ret = connector_status_disconnected;
1235 bool dret = false, broken_edid = false;
1237 if (!drm_kms_helper_is_poll_worker()) {
1238 r = pm_runtime_get_sync(connector->dev->dev);
1240 pm_runtime_put_autosuspend(connector->dev->dev);
1241 return connector_status_disconnected;
1245 if (radeon_connector->detected_hpd_without_ddc) {
1247 radeon_connector->detected_hpd_without_ddc = false;
1250 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1251 ret = connector->status;
1255 if (radeon_connector->ddc_bus) {
1256 dret = radeon_ddc_probe(radeon_connector, false);
1258 /* Sometimes the pins required for the DDC probe on DVI
1259 * connectors don't make contact at the same time that the ones
1260 * for HPD do. If the DDC probe fails even though we had an HPD
1261 * signal, try again later */
1262 if (!dret && !force &&
1263 connector->status != connector_status_connected) {
1264 DRM_DEBUG_KMS("hpd detected without ddc, retrying in 1 second\n");
1265 radeon_connector->detected_hpd_without_ddc = true;
1266 schedule_delayed_work(&rdev->hotplug_work,
1267 msecs_to_jiffies(1000));
1272 radeon_connector->detected_by_load = false;
1273 radeon_connector_free_edid(connector);
1274 radeon_connector_get_edid(connector);
1276 if (!radeon_connector->edid) {
1277 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1279 /* rs690 seems to have a problem with connectors not existing and always
1280 * return a block of 0's. If we see this just stop polling on this output */
1281 if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) &&
1282 radeon_connector->base.null_edid_counter) {
1283 ret = connector_status_disconnected;
1284 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n",
1286 radeon_connector->ddc_bus = NULL;
1288 ret = connector_status_connected;
1289 broken_edid = true; /* defer use_digital to later */
1292 radeon_connector->use_digital =
1293 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
1295 /* some oems have boards with separate digital and analog connectors
1296 * with a shared ddc line (often vga + hdmi)
1298 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
1299 radeon_connector_free_edid(connector);
1300 ret = connector_status_disconnected;
1302 ret = connector_status_connected;
1304 /* This gets complicated. We have boards with VGA + HDMI with a
1305 * shared DDC line and we have boards with DVI-D + HDMI with a shared
1306 * DDC line. The latter is more complex because with DVI<->HDMI adapters
1307 * you don't really know what's connected to which port as both are digital.
1309 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
1310 struct drm_connector *list_connector;
1311 struct radeon_connector *list_radeon_connector;
1312 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
1313 if (connector == list_connector)
1315 list_radeon_connector = to_radeon_connector(list_connector);
1316 if (list_radeon_connector->shared_ddc &&
1317 (list_radeon_connector->ddc_bus->rec.i2c_id ==
1318 radeon_connector->ddc_bus->rec.i2c_id)) {
1319 /* cases where both connectors are digital */
1320 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
1321 /* hpd is our only option in this case */
1322 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1323 radeon_connector_free_edid(connector);
1324 ret = connector_status_disconnected;
1333 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
1336 /* DVI-D and HDMI-A are digital only */
1337 if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
1338 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
1341 /* if we aren't forcing don't do destructive polling */
1343 /* only return the previous status if we last
1344 * detected a monitor via load.
1346 if (radeon_connector->detected_by_load)
1347 ret = connector->status;
1351 /* find analog encoder */
1352 if (radeon_connector->dac_load_detect) {
1353 drm_connector_for_each_possible_encoder(connector, encoder) {
1354 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
1355 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
1358 encoder_funcs = encoder->helper_private;
1359 if (encoder_funcs->detect) {
1361 if (ret != connector_status_connected) {
1362 /* deal with analog monitors without DDC */
1363 ret = encoder_funcs->detect(encoder, connector);
1364 if (ret == connector_status_connected) {
1365 radeon_connector->use_digital = false;
1367 if (ret != connector_status_disconnected)
1368 radeon_connector->detected_by_load = true;
1371 enum drm_connector_status lret;
1372 /* assume digital unless load detected otherwise */
1373 radeon_connector->use_digital = true;
1374 lret = encoder_funcs->detect(encoder, connector);
1375 DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
1376 if (lret == connector_status_connected)
1377 radeon_connector->use_digital = false;
1384 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
1386 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1389 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1390 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1391 * by other means, assume the DFP is connected and use that EDID. In most
1392 * cases the DVI port is actually a virtual KVM port connected to the service
1396 if ((!rdev->is_atom_bios) &&
1397 (ret == connector_status_disconnected) &&
1398 rdev->mode_info.bios_hardcoded_edid_size) {
1399 radeon_connector->use_digital = true;
1400 ret = connector_status_connected;
1403 /* updated in get modes as well since we need to know if it's analog or digital */
1404 radeon_connector_update_scratch_regs(connector, ret);
1406 if ((radeon_audio != 0) && radeon_connector->use_digital) {
1407 const struct drm_connector_helper_funcs *connector_funcs =
1408 connector->helper_private;
1410 encoder = connector_funcs->best_encoder(connector);
1411 if (encoder && (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)) {
1412 radeon_connector_get_edid(connector);
1413 radeon_audio_detect(connector, encoder, ret);
1418 if (!drm_kms_helper_is_poll_worker()) {
1419 pm_runtime_mark_last_busy(connector->dev->dev);
1420 pm_runtime_put_autosuspend(connector->dev->dev);
1426 /* okay need to be smart in here about which encoder to pick */
1427 static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
1429 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1430 struct drm_encoder *encoder;
1432 drm_connector_for_each_possible_encoder(connector, encoder) {
1433 if (radeon_connector->use_digital == true) {
1434 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
1437 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
1438 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
1443 /* see if we have a default encoder TODO */
1445 /* then check use digitial */
1446 /* pick the first one */
1447 drm_connector_for_each_possible_encoder(connector, encoder)
1453 static void radeon_dvi_force(struct drm_connector *connector)
1455 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1456 if (connector->force == DRM_FORCE_ON)
1457 radeon_connector->use_digital = false;
1458 if (connector->force == DRM_FORCE_ON_DIGITAL)
1459 radeon_connector->use_digital = true;
1462 static enum drm_mode_status radeon_dvi_mode_valid(struct drm_connector *connector,
1463 struct drm_display_mode *mode)
1465 struct drm_device *dev = connector->dev;
1466 struct radeon_device *rdev = dev->dev_private;
1467 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1469 /* XXX check mode bandwidth */
1471 /* clocks over 135 MHz have heat issues with DVI on RV100 */
1472 if (radeon_connector->use_digital &&
1473 (rdev->family == CHIP_RV100) &&
1474 (mode->clock > 135000))
1475 return MODE_CLOCK_HIGH;
1477 if (radeon_connector->use_digital && (mode->clock > 165000)) {
1478 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1479 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1480 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1482 else if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
1483 /* HDMI 1.3+ supports max clock of 340 Mhz */
1484 if (mode->clock > 340000)
1485 return MODE_CLOCK_HIGH;
1489 return MODE_CLOCK_HIGH;
1493 /* check against the max pixel clock */
1494 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1495 return MODE_CLOCK_HIGH;
1500 static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
1501 .get_modes = radeon_vga_get_modes,
1502 .mode_valid = radeon_dvi_mode_valid,
1503 .best_encoder = radeon_dvi_encoder,
1506 static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
1507 .dpms = drm_helper_connector_dpms,
1508 .detect = radeon_dvi_detect,
1509 .fill_modes = drm_helper_probe_single_connector_modes,
1510 .set_property = radeon_connector_set_property,
1511 .early_unregister = radeon_connector_unregister,
1512 .destroy = radeon_connector_destroy,
1513 .force = radeon_dvi_force,
1516 static int radeon_dp_get_modes(struct drm_connector *connector)
1518 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1519 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1520 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1523 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1524 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1525 struct drm_display_mode *mode;
1527 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1528 if (!radeon_dig_connector->edp_on)
1529 atombios_set_edp_panel_power(connector,
1530 ATOM_TRANSMITTER_ACTION_POWER_ON);
1531 radeon_connector_get_edid(connector);
1532 ret = radeon_ddc_get_modes(connector);
1533 if (!radeon_dig_connector->edp_on)
1534 atombios_set_edp_panel_power(connector,
1535 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1537 /* need to setup ddc on the bridge */
1538 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1539 ENCODER_OBJECT_ID_NONE) {
1541 radeon_atom_ext_encoder_setup_ddc(encoder);
1543 radeon_connector_get_edid(connector);
1544 ret = radeon_ddc_get_modes(connector);
1549 radeon_fixup_lvds_native_mode(encoder, connector);
1550 /* add scaled modes */
1551 radeon_add_common_modes(encoder, connector);
1559 /* we have no EDID modes */
1560 mode = radeon_fp_native_mode(encoder);
1563 drm_mode_probed_add(connector, mode);
1564 /* add the width/height from vbios tables if available */
1565 connector->display_info.width_mm = mode->width_mm;
1566 connector->display_info.height_mm = mode->height_mm;
1567 /* add scaled modes */
1568 radeon_add_common_modes(encoder, connector);
1571 /* need to setup ddc on the bridge */
1572 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1573 ENCODER_OBJECT_ID_NONE) {
1575 radeon_atom_ext_encoder_setup_ddc(encoder);
1577 radeon_connector_get_edid(connector);
1578 ret = radeon_ddc_get_modes(connector);
1580 radeon_get_native_mode(connector);
1586 u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
1588 struct drm_encoder *encoder;
1589 struct radeon_encoder *radeon_encoder;
1591 drm_connector_for_each_possible_encoder(connector, encoder) {
1592 radeon_encoder = to_radeon_encoder(encoder);
1594 switch (radeon_encoder->encoder_id) {
1595 case ENCODER_OBJECT_ID_TRAVIS:
1596 case ENCODER_OBJECT_ID_NUTMEG:
1597 return radeon_encoder->encoder_id;
1603 return ENCODER_OBJECT_ID_NONE;
1606 static bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
1608 struct drm_encoder *encoder;
1609 struct radeon_encoder *radeon_encoder;
1612 drm_connector_for_each_possible_encoder(connector, encoder) {
1613 radeon_encoder = to_radeon_encoder(encoder);
1614 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1621 bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1623 struct drm_device *dev = connector->dev;
1624 struct radeon_device *rdev = dev->dev_private;
1626 if (ASIC_IS_DCE5(rdev) &&
1627 (rdev->clock.default_dispclk >= 53900) &&
1628 radeon_connector_encoder_is_hbr2(connector)) {
1635 static enum drm_connector_status
1636 radeon_dp_detect(struct drm_connector *connector, bool force)
1638 struct drm_device *dev = connector->dev;
1639 struct radeon_device *rdev = dev->dev_private;
1640 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1641 enum drm_connector_status ret = connector_status_disconnected;
1642 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1643 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1646 if (!drm_kms_helper_is_poll_worker()) {
1647 r = pm_runtime_get_sync(connector->dev->dev);
1649 pm_runtime_put_autosuspend(connector->dev->dev);
1650 return connector_status_disconnected;
1654 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1655 ret = connector->status;
1659 radeon_connector_free_edid(connector);
1661 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1662 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1664 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1665 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1667 /* check if panel is valid */
1668 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1669 ret = connector_status_connected;
1670 /* don't fetch the edid from the vbios if ddc fails and runpm is
1671 * enabled so we report disconnected.
1673 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
1674 ret = connector_status_disconnected;
1676 /* eDP is always DP */
1677 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1678 if (!radeon_dig_connector->edp_on)
1679 atombios_set_edp_panel_power(connector,
1680 ATOM_TRANSMITTER_ACTION_POWER_ON);
1681 if (radeon_dp_getdpcd(radeon_connector))
1682 ret = connector_status_connected;
1683 if (!radeon_dig_connector->edp_on)
1684 atombios_set_edp_panel_power(connector,
1685 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1686 } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1687 ENCODER_OBJECT_ID_NONE) {
1688 /* DP bridges are always DP */
1689 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1690 /* get the DPCD from the bridge */
1691 radeon_dp_getdpcd(radeon_connector);
1694 /* setup ddc on the bridge */
1695 radeon_atom_ext_encoder_setup_ddc(encoder);
1696 /* bridge chips are always aux */
1697 if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */
1698 ret = connector_status_connected;
1699 else if (radeon_connector->dac_load_detect) { /* try load detection */
1700 const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
1701 ret = encoder_funcs->detect(encoder, connector);
1705 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
1706 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1707 ret = connector_status_connected;
1708 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
1709 radeon_dp_getdpcd(radeon_connector);
1711 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1712 if (radeon_dp_getdpcd(radeon_connector))
1713 ret = connector_status_connected;
1715 /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
1716 if (radeon_ddc_probe(radeon_connector, false))
1717 ret = connector_status_connected;
1722 radeon_connector_update_scratch_regs(connector, ret);
1724 if ((radeon_audio != 0) && encoder) {
1725 radeon_connector_get_edid(connector);
1726 radeon_audio_detect(connector, encoder, ret);
1730 if (!drm_kms_helper_is_poll_worker()) {
1731 pm_runtime_mark_last_busy(connector->dev->dev);
1732 pm_runtime_put_autosuspend(connector->dev->dev);
1738 static enum drm_mode_status radeon_dp_mode_valid(struct drm_connector *connector,
1739 struct drm_display_mode *mode)
1741 struct drm_device *dev = connector->dev;
1742 struct radeon_device *rdev = dev->dev_private;
1743 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1744 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1746 /* XXX check mode bandwidth */
1748 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1749 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1750 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1752 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1756 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1757 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1759 /* AVIVO hardware supports downscaling modes larger than the panel
1760 * to the panel size, but I'm not sure this is desirable.
1762 if ((mode->hdisplay > native_mode->hdisplay) ||
1763 (mode->vdisplay > native_mode->vdisplay))
1766 /* if scaling is disabled, block non-native modes */
1767 if (radeon_encoder->rmx_type == RMX_OFF) {
1768 if ((mode->hdisplay != native_mode->hdisplay) ||
1769 (mode->vdisplay != native_mode->vdisplay))
1774 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1775 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
1776 return radeon_dp_mode_valid_helper(connector, mode);
1778 if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
1779 /* HDMI 1.3+ supports max clock of 340 Mhz */
1780 if (mode->clock > 340000)
1781 return MODE_CLOCK_HIGH;
1783 if (mode->clock > 165000)
1784 return MODE_CLOCK_HIGH;
1792 static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1793 .get_modes = radeon_dp_get_modes,
1794 .mode_valid = radeon_dp_mode_valid,
1795 .best_encoder = radeon_dvi_encoder,
1798 static const struct drm_connector_funcs radeon_dp_connector_funcs = {
1799 .dpms = drm_helper_connector_dpms,
1800 .detect = radeon_dp_detect,
1801 .fill_modes = drm_helper_probe_single_connector_modes,
1802 .set_property = radeon_connector_set_property,
1803 .early_unregister = radeon_connector_unregister,
1804 .destroy = radeon_connector_destroy,
1805 .force = radeon_dvi_force,
1808 static const struct drm_connector_funcs radeon_edp_connector_funcs = {
1809 .dpms = drm_helper_connector_dpms,
1810 .detect = radeon_dp_detect,
1811 .fill_modes = drm_helper_probe_single_connector_modes,
1812 .set_property = radeon_lvds_set_property,
1813 .early_unregister = radeon_connector_unregister,
1814 .destroy = radeon_connector_destroy,
1815 .force = radeon_dvi_force,
1818 static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
1819 .dpms = drm_helper_connector_dpms,
1820 .detect = radeon_dp_detect,
1821 .fill_modes = drm_helper_probe_single_connector_modes,
1822 .set_property = radeon_lvds_set_property,
1823 .early_unregister = radeon_connector_unregister,
1824 .destroy = radeon_connector_destroy,
1825 .force = radeon_dvi_force,
1829 radeon_add_atom_connector(struct drm_device *dev,
1830 uint32_t connector_id,
1831 uint32_t supported_device,
1833 struct radeon_i2c_bus_rec *i2c_bus,
1834 uint32_t igp_lane_info,
1835 uint16_t connector_object_id,
1836 struct radeon_hpd *hpd,
1837 struct radeon_router *router)
1839 struct radeon_device *rdev = dev->dev_private;
1840 struct drm_connector *connector;
1841 struct radeon_connector *radeon_connector;
1842 struct radeon_connector_atom_dig *radeon_dig_connector;
1843 struct drm_encoder *encoder;
1844 struct radeon_encoder *radeon_encoder;
1845 struct i2c_adapter *ddc = NULL;
1846 uint32_t subpixel_order = SubPixelNone;
1847 bool shared_ddc = false;
1848 bool is_dp_bridge = false;
1849 bool has_aux = false;
1851 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1854 /* if the user selected tv=0 don't try and add the connector */
1855 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1856 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1857 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1861 /* see if we already added it */
1862 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1863 radeon_connector = to_radeon_connector(connector);
1864 if (radeon_connector->connector_id == connector_id) {
1865 radeon_connector->devices |= supported_device;
1868 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1869 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1870 radeon_connector->shared_ddc = true;
1873 if (radeon_connector->router_bus && router->ddc_valid &&
1874 (radeon_connector->router.router_id == router->router_id)) {
1875 radeon_connector->shared_ddc = false;
1881 /* check if it's a dp bridge */
1882 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1883 radeon_encoder = to_radeon_encoder(encoder);
1884 if (radeon_encoder->devices & supported_device) {
1885 switch (radeon_encoder->encoder_id) {
1886 case ENCODER_OBJECT_ID_TRAVIS:
1887 case ENCODER_OBJECT_ID_NUTMEG:
1888 is_dp_bridge = true;
1896 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1897 if (!radeon_connector)
1900 connector = &radeon_connector->base;
1902 radeon_connector->connector_id = connector_id;
1903 radeon_connector->devices = supported_device;
1904 radeon_connector->shared_ddc = shared_ddc;
1905 radeon_connector->connector_object_id = connector_object_id;
1906 radeon_connector->hpd = *hpd;
1908 radeon_connector->router = *router;
1909 if (router->ddc_valid || router->cd_valid) {
1910 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1911 if (!radeon_connector->router_bus)
1912 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
1916 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1917 if (!radeon_dig_connector)
1919 radeon_dig_connector->igp_lane_info = igp_lane_info;
1920 radeon_connector->con_priv = radeon_dig_connector;
1921 if (i2c_bus->valid) {
1922 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1923 if (radeon_connector->ddc_bus) {
1925 ddc = &radeon_connector->ddc_bus->adapter;
1927 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1930 switch (connector_type) {
1931 case DRM_MODE_CONNECTOR_VGA:
1932 case DRM_MODE_CONNECTOR_DVIA:
1934 drm_connector_init_with_ddc(dev, &radeon_connector->base,
1935 &radeon_dp_connector_funcs,
1938 drm_connector_helper_add(&radeon_connector->base,
1939 &radeon_dp_connector_helper_funcs);
1940 connector->interlace_allowed = true;
1941 connector->doublescan_allowed = true;
1942 radeon_connector->dac_load_detect = true;
1943 drm_object_attach_property(&radeon_connector->base.base,
1944 rdev->mode_info.load_detect_property,
1946 drm_object_attach_property(&radeon_connector->base.base,
1947 dev->mode_config.scaling_mode_property,
1948 DRM_MODE_SCALE_NONE);
1949 if (ASIC_IS_DCE5(rdev))
1950 drm_object_attach_property(&radeon_connector->base.base,
1951 rdev->mode_info.output_csc_property,
1952 RADEON_OUTPUT_CSC_BYPASS);
1954 case DRM_MODE_CONNECTOR_DVII:
1955 case DRM_MODE_CONNECTOR_DVID:
1956 case DRM_MODE_CONNECTOR_HDMIA:
1957 case DRM_MODE_CONNECTOR_HDMIB:
1958 case DRM_MODE_CONNECTOR_DisplayPort:
1959 drm_connector_init_with_ddc(dev, &radeon_connector->base,
1960 &radeon_dp_connector_funcs,
1963 drm_connector_helper_add(&radeon_connector->base,
1964 &radeon_dp_connector_helper_funcs);
1965 drm_object_attach_property(&radeon_connector->base.base,
1966 rdev->mode_info.underscan_property,
1968 drm_object_attach_property(&radeon_connector->base.base,
1969 rdev->mode_info.underscan_hborder_property,
1971 drm_object_attach_property(&radeon_connector->base.base,
1972 rdev->mode_info.underscan_vborder_property,
1975 drm_object_attach_property(&radeon_connector->base.base,
1976 dev->mode_config.scaling_mode_property,
1977 DRM_MODE_SCALE_NONE);
1979 drm_object_attach_property(&radeon_connector->base.base,
1980 rdev->mode_info.dither_property,
1981 RADEON_FMT_DITHER_DISABLE);
1983 if (radeon_audio != 0) {
1984 drm_object_attach_property(&radeon_connector->base.base,
1985 rdev->mode_info.audio_property,
1987 radeon_connector->audio = RADEON_AUDIO_AUTO;
1989 if (ASIC_IS_DCE5(rdev))
1990 drm_object_attach_property(&radeon_connector->base.base,
1991 rdev->mode_info.output_csc_property,
1992 RADEON_OUTPUT_CSC_BYPASS);
1994 subpixel_order = SubPixelHorizontalRGB;
1995 connector->interlace_allowed = true;
1996 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1997 connector->doublescan_allowed = true;
1999 connector->doublescan_allowed = false;
2000 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2001 radeon_connector->dac_load_detect = true;
2002 drm_object_attach_property(&radeon_connector->base.base,
2003 rdev->mode_info.load_detect_property,
2007 case DRM_MODE_CONNECTOR_LVDS:
2008 case DRM_MODE_CONNECTOR_eDP:
2009 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2010 &radeon_lvds_bridge_connector_funcs,
2013 drm_connector_helper_add(&radeon_connector->base,
2014 &radeon_dp_connector_helper_funcs);
2015 drm_object_attach_property(&radeon_connector->base.base,
2016 dev->mode_config.scaling_mode_property,
2017 DRM_MODE_SCALE_FULLSCREEN);
2018 subpixel_order = SubPixelHorizontalRGB;
2019 connector->interlace_allowed = false;
2020 connector->doublescan_allowed = false;
2024 switch (connector_type) {
2025 case DRM_MODE_CONNECTOR_VGA:
2026 if (i2c_bus->valid) {
2027 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2028 if (!radeon_connector->ddc_bus)
2029 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2031 ddc = &radeon_connector->ddc_bus->adapter;
2033 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2034 &radeon_vga_connector_funcs,
2037 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2038 radeon_connector->dac_load_detect = true;
2039 drm_object_attach_property(&radeon_connector->base.base,
2040 rdev->mode_info.load_detect_property,
2042 if (ASIC_IS_AVIVO(rdev))
2043 drm_object_attach_property(&radeon_connector->base.base,
2044 dev->mode_config.scaling_mode_property,
2045 DRM_MODE_SCALE_NONE);
2046 if (ASIC_IS_DCE5(rdev))
2047 drm_object_attach_property(&radeon_connector->base.base,
2048 rdev->mode_info.output_csc_property,
2049 RADEON_OUTPUT_CSC_BYPASS);
2050 /* no HPD on analog connectors */
2051 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2052 connector->interlace_allowed = true;
2053 connector->doublescan_allowed = true;
2055 case DRM_MODE_CONNECTOR_DVIA:
2056 if (i2c_bus->valid) {
2057 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2058 if (!radeon_connector->ddc_bus)
2059 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2061 ddc = &radeon_connector->ddc_bus->adapter;
2063 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2064 &radeon_vga_connector_funcs,
2067 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2068 radeon_connector->dac_load_detect = true;
2069 drm_object_attach_property(&radeon_connector->base.base,
2070 rdev->mode_info.load_detect_property,
2072 if (ASIC_IS_AVIVO(rdev))
2073 drm_object_attach_property(&radeon_connector->base.base,
2074 dev->mode_config.scaling_mode_property,
2075 DRM_MODE_SCALE_NONE);
2076 if (ASIC_IS_DCE5(rdev))
2077 drm_object_attach_property(&radeon_connector->base.base,
2078 rdev->mode_info.output_csc_property,
2079 RADEON_OUTPUT_CSC_BYPASS);
2080 /* no HPD on analog connectors */
2081 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2082 connector->interlace_allowed = true;
2083 connector->doublescan_allowed = true;
2085 case DRM_MODE_CONNECTOR_DVII:
2086 case DRM_MODE_CONNECTOR_DVID:
2087 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2088 if (!radeon_dig_connector)
2090 radeon_dig_connector->igp_lane_info = igp_lane_info;
2091 radeon_connector->con_priv = radeon_dig_connector;
2092 if (i2c_bus->valid) {
2093 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2094 if (!radeon_connector->ddc_bus)
2095 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2097 ddc = &radeon_connector->ddc_bus->adapter;
2099 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2100 &radeon_dvi_connector_funcs,
2103 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2104 subpixel_order = SubPixelHorizontalRGB;
2105 drm_object_attach_property(&radeon_connector->base.base,
2106 rdev->mode_info.coherent_mode_property,
2108 if (ASIC_IS_AVIVO(rdev)) {
2109 drm_object_attach_property(&radeon_connector->base.base,
2110 rdev->mode_info.underscan_property,
2112 drm_object_attach_property(&radeon_connector->base.base,
2113 rdev->mode_info.underscan_hborder_property,
2115 drm_object_attach_property(&radeon_connector->base.base,
2116 rdev->mode_info.underscan_vborder_property,
2118 drm_object_attach_property(&radeon_connector->base.base,
2119 rdev->mode_info.dither_property,
2120 RADEON_FMT_DITHER_DISABLE);
2121 drm_object_attach_property(&radeon_connector->base.base,
2122 dev->mode_config.scaling_mode_property,
2123 DRM_MODE_SCALE_NONE);
2125 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2126 drm_object_attach_property(&radeon_connector->base.base,
2127 rdev->mode_info.audio_property,
2129 radeon_connector->audio = RADEON_AUDIO_AUTO;
2131 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2132 radeon_connector->dac_load_detect = true;
2133 drm_object_attach_property(&radeon_connector->base.base,
2134 rdev->mode_info.load_detect_property,
2137 if (ASIC_IS_DCE5(rdev))
2138 drm_object_attach_property(&radeon_connector->base.base,
2139 rdev->mode_info.output_csc_property,
2140 RADEON_OUTPUT_CSC_BYPASS);
2141 connector->interlace_allowed = true;
2142 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2143 connector->doublescan_allowed = true;
2145 connector->doublescan_allowed = false;
2147 case DRM_MODE_CONNECTOR_HDMIA:
2148 case DRM_MODE_CONNECTOR_HDMIB:
2149 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2150 if (!radeon_dig_connector)
2152 radeon_dig_connector->igp_lane_info = igp_lane_info;
2153 radeon_connector->con_priv = radeon_dig_connector;
2154 if (i2c_bus->valid) {
2155 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2156 if (!radeon_connector->ddc_bus)
2157 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2159 ddc = &radeon_connector->ddc_bus->adapter;
2161 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2162 &radeon_dvi_connector_funcs,
2165 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2166 drm_object_attach_property(&radeon_connector->base.base,
2167 rdev->mode_info.coherent_mode_property,
2169 if (ASIC_IS_AVIVO(rdev)) {
2170 drm_object_attach_property(&radeon_connector->base.base,
2171 rdev->mode_info.underscan_property,
2173 drm_object_attach_property(&radeon_connector->base.base,
2174 rdev->mode_info.underscan_hborder_property,
2176 drm_object_attach_property(&radeon_connector->base.base,
2177 rdev->mode_info.underscan_vborder_property,
2179 drm_object_attach_property(&radeon_connector->base.base,
2180 rdev->mode_info.dither_property,
2181 RADEON_FMT_DITHER_DISABLE);
2182 drm_object_attach_property(&radeon_connector->base.base,
2183 dev->mode_config.scaling_mode_property,
2184 DRM_MODE_SCALE_NONE);
2186 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2187 drm_object_attach_property(&radeon_connector->base.base,
2188 rdev->mode_info.audio_property,
2190 radeon_connector->audio = RADEON_AUDIO_AUTO;
2192 if (ASIC_IS_DCE5(rdev))
2193 drm_object_attach_property(&radeon_connector->base.base,
2194 rdev->mode_info.output_csc_property,
2195 RADEON_OUTPUT_CSC_BYPASS);
2196 subpixel_order = SubPixelHorizontalRGB;
2197 connector->interlace_allowed = true;
2198 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
2199 connector->doublescan_allowed = true;
2201 connector->doublescan_allowed = false;
2203 case DRM_MODE_CONNECTOR_DisplayPort:
2204 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2205 if (!radeon_dig_connector)
2207 radeon_dig_connector->igp_lane_info = igp_lane_info;
2208 radeon_connector->con_priv = radeon_dig_connector;
2209 if (i2c_bus->valid) {
2210 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2211 if (radeon_connector->ddc_bus) {
2213 ddc = &radeon_connector->ddc_bus->adapter;
2215 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2218 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2219 &radeon_dp_connector_funcs,
2222 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2223 subpixel_order = SubPixelHorizontalRGB;
2224 drm_object_attach_property(&radeon_connector->base.base,
2225 rdev->mode_info.coherent_mode_property,
2227 if (ASIC_IS_AVIVO(rdev)) {
2228 drm_object_attach_property(&radeon_connector->base.base,
2229 rdev->mode_info.underscan_property,
2231 drm_object_attach_property(&radeon_connector->base.base,
2232 rdev->mode_info.underscan_hborder_property,
2234 drm_object_attach_property(&radeon_connector->base.base,
2235 rdev->mode_info.underscan_vborder_property,
2237 drm_object_attach_property(&radeon_connector->base.base,
2238 rdev->mode_info.dither_property,
2239 RADEON_FMT_DITHER_DISABLE);
2240 drm_object_attach_property(&radeon_connector->base.base,
2241 dev->mode_config.scaling_mode_property,
2242 DRM_MODE_SCALE_NONE);
2244 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2245 drm_object_attach_property(&radeon_connector->base.base,
2246 rdev->mode_info.audio_property,
2248 radeon_connector->audio = RADEON_AUDIO_AUTO;
2250 if (ASIC_IS_DCE5(rdev))
2251 drm_object_attach_property(&radeon_connector->base.base,
2252 rdev->mode_info.output_csc_property,
2253 RADEON_OUTPUT_CSC_BYPASS);
2254 connector->interlace_allowed = true;
2255 /* in theory with a DP to VGA converter... */
2256 connector->doublescan_allowed = false;
2258 case DRM_MODE_CONNECTOR_eDP:
2259 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2260 if (!radeon_dig_connector)
2262 radeon_dig_connector->igp_lane_info = igp_lane_info;
2263 radeon_connector->con_priv = radeon_dig_connector;
2264 if (i2c_bus->valid) {
2265 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2266 if (radeon_connector->ddc_bus) {
2268 ddc = &radeon_connector->ddc_bus->adapter;
2270 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2273 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2274 &radeon_edp_connector_funcs,
2277 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2278 drm_object_attach_property(&radeon_connector->base.base,
2279 dev->mode_config.scaling_mode_property,
2280 DRM_MODE_SCALE_FULLSCREEN);
2281 subpixel_order = SubPixelHorizontalRGB;
2282 connector->interlace_allowed = false;
2283 connector->doublescan_allowed = false;
2285 case DRM_MODE_CONNECTOR_SVIDEO:
2286 case DRM_MODE_CONNECTOR_Composite:
2287 case DRM_MODE_CONNECTOR_9PinDIN:
2288 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2289 &radeon_tv_connector_funcs,
2292 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2293 radeon_connector->dac_load_detect = true;
2294 drm_object_attach_property(&radeon_connector->base.base,
2295 rdev->mode_info.load_detect_property,
2297 drm_object_attach_property(&radeon_connector->base.base,
2298 rdev->mode_info.tv_std_property,
2299 radeon_atombios_get_tv_info(rdev));
2300 /* no HPD on analog connectors */
2301 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2302 connector->interlace_allowed = false;
2303 connector->doublescan_allowed = false;
2305 case DRM_MODE_CONNECTOR_LVDS:
2306 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2307 if (!radeon_dig_connector)
2309 radeon_dig_connector->igp_lane_info = igp_lane_info;
2310 radeon_connector->con_priv = radeon_dig_connector;
2311 if (i2c_bus->valid) {
2312 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2313 if (!radeon_connector->ddc_bus)
2314 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2316 ddc = &radeon_connector->ddc_bus->adapter;
2318 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2319 &radeon_lvds_connector_funcs,
2322 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2323 drm_object_attach_property(&radeon_connector->base.base,
2324 dev->mode_config.scaling_mode_property,
2325 DRM_MODE_SCALE_FULLSCREEN);
2326 subpixel_order = SubPixelHorizontalRGB;
2327 connector->interlace_allowed = false;
2328 connector->doublescan_allowed = false;
2333 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
2334 if (i2c_bus->valid) {
2335 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2336 DRM_CONNECTOR_POLL_DISCONNECT;
2339 connector->polled = DRM_CONNECTOR_POLL_HPD;
2341 connector->display_info.subpixel_order = subpixel_order;
2342 drm_connector_register(connector);
2345 radeon_dp_aux_init(radeon_connector);
2350 drm_connector_cleanup(connector);
2355 radeon_add_legacy_connector(struct drm_device *dev,
2356 uint32_t connector_id,
2357 uint32_t supported_device,
2359 struct radeon_i2c_bus_rec *i2c_bus,
2360 uint16_t connector_object_id,
2361 struct radeon_hpd *hpd)
2363 struct radeon_device *rdev = dev->dev_private;
2364 struct drm_connector *connector;
2365 struct radeon_connector *radeon_connector;
2366 struct i2c_adapter *ddc = NULL;
2367 uint32_t subpixel_order = SubPixelNone;
2369 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
2372 /* if the user selected tv=0 don't try and add the connector */
2373 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
2374 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
2375 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
2379 /* see if we already added it */
2380 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2381 radeon_connector = to_radeon_connector(connector);
2382 if (radeon_connector->connector_id == connector_id) {
2383 radeon_connector->devices |= supported_device;
2388 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
2389 if (!radeon_connector)
2392 connector = &radeon_connector->base;
2394 radeon_connector->connector_id = connector_id;
2395 radeon_connector->devices = supported_device;
2396 radeon_connector->connector_object_id = connector_object_id;
2397 radeon_connector->hpd = *hpd;
2399 switch (connector_type) {
2400 case DRM_MODE_CONNECTOR_VGA:
2401 if (i2c_bus->valid) {
2402 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2403 if (!radeon_connector->ddc_bus)
2404 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2406 ddc = &radeon_connector->ddc_bus->adapter;
2408 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2409 &radeon_vga_connector_funcs,
2412 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2413 radeon_connector->dac_load_detect = true;
2414 drm_object_attach_property(&radeon_connector->base.base,
2415 rdev->mode_info.load_detect_property,
2417 /* no HPD on analog connectors */
2418 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2419 connector->interlace_allowed = true;
2420 connector->doublescan_allowed = true;
2422 case DRM_MODE_CONNECTOR_DVIA:
2423 if (i2c_bus->valid) {
2424 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2425 if (!radeon_connector->ddc_bus)
2426 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2428 ddc = &radeon_connector->ddc_bus->adapter;
2430 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2431 &radeon_vga_connector_funcs,
2434 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2435 radeon_connector->dac_load_detect = true;
2436 drm_object_attach_property(&radeon_connector->base.base,
2437 rdev->mode_info.load_detect_property,
2439 /* no HPD on analog connectors */
2440 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2441 connector->interlace_allowed = true;
2442 connector->doublescan_allowed = true;
2444 case DRM_MODE_CONNECTOR_DVII:
2445 case DRM_MODE_CONNECTOR_DVID:
2446 if (i2c_bus->valid) {
2447 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2448 if (!radeon_connector->ddc_bus)
2449 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2451 ddc = &radeon_connector->ddc_bus->adapter;
2453 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2454 &radeon_dvi_connector_funcs,
2457 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2458 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2459 radeon_connector->dac_load_detect = true;
2460 drm_object_attach_property(&radeon_connector->base.base,
2461 rdev->mode_info.load_detect_property,
2464 subpixel_order = SubPixelHorizontalRGB;
2465 connector->interlace_allowed = true;
2466 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2467 connector->doublescan_allowed = true;
2469 connector->doublescan_allowed = false;
2471 case DRM_MODE_CONNECTOR_SVIDEO:
2472 case DRM_MODE_CONNECTOR_Composite:
2473 case DRM_MODE_CONNECTOR_9PinDIN:
2474 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2475 &radeon_tv_connector_funcs,
2478 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2479 radeon_connector->dac_load_detect = true;
2480 /* RS400,RC410,RS480 chipset seems to report a lot
2481 * of false positive on load detect, we haven't yet
2482 * found a way to make load detect reliable on those
2483 * chipset, thus just disable it for TV.
2485 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
2486 radeon_connector->dac_load_detect = false;
2487 drm_object_attach_property(&radeon_connector->base.base,
2488 rdev->mode_info.load_detect_property,
2489 radeon_connector->dac_load_detect);
2490 drm_object_attach_property(&radeon_connector->base.base,
2491 rdev->mode_info.tv_std_property,
2492 radeon_combios_get_tv_info(rdev));
2493 /* no HPD on analog connectors */
2494 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2495 connector->interlace_allowed = false;
2496 connector->doublescan_allowed = false;
2498 case DRM_MODE_CONNECTOR_LVDS:
2499 if (i2c_bus->valid) {
2500 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2501 if (!radeon_connector->ddc_bus)
2502 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2504 ddc = &radeon_connector->ddc_bus->adapter;
2506 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2507 &radeon_lvds_connector_funcs,
2510 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2511 drm_object_attach_property(&radeon_connector->base.base,
2512 dev->mode_config.scaling_mode_property,
2513 DRM_MODE_SCALE_FULLSCREEN);
2514 subpixel_order = SubPixelHorizontalRGB;
2515 connector->interlace_allowed = false;
2516 connector->doublescan_allowed = false;
2520 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
2521 if (i2c_bus->valid) {
2522 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2523 DRM_CONNECTOR_POLL_DISCONNECT;
2526 connector->polled = DRM_CONNECTOR_POLL_HPD;
2528 connector->display_info.subpixel_order = subpixel_order;
2529 drm_connector_register(connector);