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/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/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 static int radeon_dp_handle_hpd(struct drm_connector *connector)
42 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
45 ret = radeon_dp_mst_check_status(radeon_connector);
50 void radeon_connector_hotplug(struct drm_connector *connector)
52 struct drm_device *dev = connector->dev;
53 struct radeon_device *rdev = dev->dev_private;
54 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
56 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
57 struct radeon_connector_atom_dig *dig_connector =
58 radeon_connector->con_priv;
60 if (radeon_connector->is_mst_connector)
62 if (dig_connector->is_mst) {
63 radeon_dp_handle_hpd(connector);
67 /* bail if the connector does not have hpd pin, e.g.,
70 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE)
73 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
75 /* if the connector is already off, don't turn it back on */
76 /* FIXME: This access isn't protected by any locks. */
77 if (connector->dpms != DRM_MODE_DPMS_ON)
80 /* just deal with DP (not eDP) here. */
81 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
82 struct radeon_connector_atom_dig *dig_connector =
83 radeon_connector->con_priv;
85 /* if existing sink type was not DP no need to retrain */
86 if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT)
89 /* first get sink type as it may be reset after (un)plug */
90 dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
91 /* don't do anything if sink is not display port, i.e.,
92 * passive dp->(dvi|hdmi) adaptor
94 if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT &&
95 radeon_hpd_sense(rdev, radeon_connector->hpd.hpd) &&
96 radeon_dp_needs_link_train(radeon_connector)) {
97 /* Don't start link training before we have the DPCD */
98 if (!radeon_dp_getdpcd(radeon_connector))
101 /* Turn the connector off and back on immediately, which
102 * will trigger link training
104 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
105 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
110 static void radeon_property_change_mode(struct drm_encoder *encoder)
112 struct drm_crtc *crtc = encoder->crtc;
114 if (crtc && crtc->enabled) {
115 drm_crtc_helper_set_mode(crtc, &crtc->mode,
116 crtc->x, crtc->y, crtc->primary->fb);
120 int radeon_get_monitor_bpc(struct drm_connector *connector)
122 struct drm_device *dev = connector->dev;
123 struct radeon_device *rdev = dev->dev_private;
124 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
125 struct radeon_connector_atom_dig *dig_connector;
127 int mode_clock, max_tmds_clock;
129 switch (connector->connector_type) {
130 case DRM_MODE_CONNECTOR_DVII:
131 case DRM_MODE_CONNECTOR_HDMIB:
132 if (radeon_connector->use_digital) {
133 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
134 if (connector->display_info.bpc)
135 bpc = connector->display_info.bpc;
139 case DRM_MODE_CONNECTOR_DVID:
140 case DRM_MODE_CONNECTOR_HDMIA:
141 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
142 if (connector->display_info.bpc)
143 bpc = connector->display_info.bpc;
146 case DRM_MODE_CONNECTOR_DisplayPort:
147 dig_connector = radeon_connector->con_priv;
148 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
149 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) ||
150 drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
151 if (connector->display_info.bpc)
152 bpc = connector->display_info.bpc;
155 case DRM_MODE_CONNECTOR_eDP:
156 case DRM_MODE_CONNECTOR_LVDS:
157 if (connector->display_info.bpc)
158 bpc = connector->display_info.bpc;
159 else if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
160 const struct drm_connector_helper_funcs *connector_funcs =
161 connector->helper_private;
162 struct drm_encoder *encoder = connector_funcs->best_encoder(connector);
163 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
164 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
166 if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR)
168 else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR)
174 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
175 /* hdmi deep color only implemented on DCE4+ */
176 if ((bpc > 8) && !ASIC_IS_DCE4(rdev)) {
177 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 8 bpc.\n",
178 connector->name, bpc);
183 * Pre DCE-8 hw can't handle > 12 bpc, and more than 12 bpc doesn't make
184 * much sense without support for > 12 bpc framebuffers. RGB 4:4:4 at
185 * 12 bpc is always supported on hdmi deep color sinks, as this is
186 * required by the HDMI-1.3 spec. Clamp to a safe 12 bpc maximum.
189 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 12 bpc.\n",
190 connector->name, bpc);
194 /* Any defined maximum tmds clock limit we must not exceed? */
195 if (connector->display_info.max_tmds_clock > 0) {
196 /* mode_clock is clock in kHz for mode to be modeset on this connector */
197 mode_clock = radeon_connector->pixelclock_for_modeset;
199 /* Maximum allowable input clock in kHz */
200 max_tmds_clock = connector->display_info.max_tmds_clock;
202 DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds input clock %d kHz.\n",
203 connector->name, mode_clock, max_tmds_clock);
205 /* Check if bpc is within clock limit. Try to degrade gracefully otherwise */
206 if ((bpc == 12) && (mode_clock * 3/2 > max_tmds_clock)) {
207 if ((connector->display_info.edid_hdmi_dc_modes & DRM_EDID_HDMI_DC_30) &&
208 (mode_clock * 5/4 <= max_tmds_clock))
213 DRM_DEBUG("%s: HDMI deep color 12 bpc exceeds max tmds clock. Using %d bpc.\n",
214 connector->name, bpc);
217 if ((bpc == 10) && (mode_clock * 5/4 > max_tmds_clock)) {
219 DRM_DEBUG("%s: HDMI deep color 10 bpc exceeds max tmds clock. Using %d bpc.\n",
220 connector->name, bpc);
224 /* max_tmds_clock missing, but hdmi spec mandates it for deep color. */
225 DRM_DEBUG("%s: Required max tmds clock for HDMI deep color missing. Using 8 bpc.\n",
231 if ((radeon_deep_color == 0) && (bpc > 8)) {
232 DRM_DEBUG("%s: Deep color disabled. Set radeon module param deep_color=1 to enable.\n",
237 DRM_DEBUG("%s: Display bpc=%d, returned bpc=%d\n",
238 connector->name, connector->display_info.bpc, bpc);
244 radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
246 struct drm_device *dev = connector->dev;
247 struct radeon_device *rdev = dev->dev_private;
248 struct drm_encoder *best_encoder;
249 struct drm_encoder *encoder;
250 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
253 best_encoder = connector_funcs->best_encoder(connector);
255 drm_connector_for_each_possible_encoder(connector, encoder) {
256 if ((encoder == best_encoder) && (status == connector_status_connected))
261 if (rdev->is_atom_bios)
262 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
264 radeon_combios_connected_scratch_regs(connector, encoder, connected);
268 static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
270 struct drm_encoder *encoder;
272 drm_connector_for_each_possible_encoder(connector, encoder) {
273 if (encoder->encoder_type == encoder_type)
280 struct edid *radeon_connector_edid(struct drm_connector *connector)
282 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
283 struct drm_property_blob *edid_blob = connector->edid_blob_ptr;
285 if (radeon_connector->edid) {
286 return radeon_connector->edid;
287 } else if (edid_blob) {
288 struct edid *edid = kmemdup(edid_blob->data, edid_blob->length, GFP_KERNEL);
290 radeon_connector->edid = edid;
292 return radeon_connector->edid;
295 static void radeon_connector_get_edid(struct drm_connector *connector)
297 struct drm_device *dev = connector->dev;
298 struct radeon_device *rdev = dev->dev_private;
299 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
301 if (radeon_connector->edid)
304 /* on hw with routers, select right port */
305 if (radeon_connector->router.ddc_valid)
306 radeon_router_select_ddc_port(radeon_connector);
308 if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
309 ENCODER_OBJECT_ID_NONE) &&
310 radeon_connector->ddc_bus->has_aux) {
311 radeon_connector->edid = drm_get_edid(connector,
312 &radeon_connector->ddc_bus->aux.ddc);
313 } else if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
314 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
315 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
317 if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
318 dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) &&
319 radeon_connector->ddc_bus->has_aux)
320 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
321 &radeon_connector->ddc_bus->aux.ddc);
322 else if (radeon_connector->ddc_bus)
323 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
324 &radeon_connector->ddc_bus->adapter);
325 } else if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC &&
326 connector->connector_type == DRM_MODE_CONNECTOR_LVDS &&
327 radeon_connector->ddc_bus) {
328 radeon_connector->edid = drm_get_edid_switcheroo(&radeon_connector->base,
329 &radeon_connector->ddc_bus->adapter);
330 } else if (radeon_connector->ddc_bus) {
331 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
332 &radeon_connector->ddc_bus->adapter);
335 if (!radeon_connector->edid) {
336 /* don't fetch the edid from the vbios if ddc fails and runpm is
337 * enabled so we report disconnected.
339 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
342 if (rdev->is_atom_bios) {
343 /* some laptops provide a hardcoded edid in rom for LCDs */
344 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
345 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)))
346 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
348 /* some servers provide a hardcoded edid in rom for KVMs */
349 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
354 static void radeon_connector_free_edid(struct drm_connector *connector)
356 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
358 if (radeon_connector->edid) {
359 kfree(radeon_connector->edid);
360 radeon_connector->edid = NULL;
364 static int radeon_ddc_get_modes(struct drm_connector *connector)
366 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
369 if (radeon_connector->edid) {
370 drm_connector_update_edid_property(connector, radeon_connector->edid);
371 ret = drm_add_edid_modes(connector, radeon_connector->edid);
374 drm_connector_update_edid_property(connector, NULL);
378 static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
380 struct drm_encoder *encoder;
382 /* pick the first one */
383 drm_connector_for_each_possible_encoder(connector, encoder)
389 static void radeon_get_native_mode(struct drm_connector *connector)
391 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
392 struct radeon_encoder *radeon_encoder;
397 radeon_encoder = to_radeon_encoder(encoder);
399 if (!list_empty(&connector->probed_modes)) {
400 struct drm_display_mode *preferred_mode =
401 list_first_entry(&connector->probed_modes,
402 struct drm_display_mode, head);
404 radeon_encoder->native_mode = *preferred_mode;
406 radeon_encoder->native_mode.clock = 0;
411 * radeon_connector_analog_encoder_conflict_solve
412 * - search for other connectors sharing this encoder
413 * if priority is true, then set them disconnected if this is connected
414 * if priority is false, set us disconnected if they are connected
416 static enum drm_connector_status
417 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
418 struct drm_encoder *encoder,
419 enum drm_connector_status current_status,
422 struct drm_device *dev = connector->dev;
423 struct drm_connector *conflict;
424 struct radeon_connector *radeon_conflict;
426 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
427 struct drm_encoder *enc;
429 if (conflict == connector)
432 radeon_conflict = to_radeon_connector(conflict);
434 drm_connector_for_each_possible_encoder(conflict, enc) {
435 /* if the IDs match */
436 if (enc == encoder) {
437 if (conflict->status != connector_status_connected)
440 if (radeon_conflict->use_digital)
444 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n",
446 DRM_DEBUG_KMS("in favor of %s\n",
448 conflict->status = connector_status_disconnected;
449 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
451 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n",
453 DRM_DEBUG_KMS("in favor of %s\n",
455 current_status = connector_status_disconnected;
461 return current_status;
465 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
467 struct drm_device *dev = encoder->dev;
468 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
469 struct drm_display_mode *mode = NULL;
470 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
472 if (native_mode->hdisplay != 0 &&
473 native_mode->vdisplay != 0 &&
474 native_mode->clock != 0) {
475 mode = drm_mode_duplicate(dev, native_mode);
476 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
477 drm_mode_set_name(mode);
479 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
480 } else if (native_mode->hdisplay != 0 &&
481 native_mode->vdisplay != 0) {
482 /* mac laptops without an edid */
483 /* Note that this is not necessarily the exact panel mode,
484 * but an approximation based on the cvt formula. For these
485 * systems we should ideally read the mode info out of the
486 * registers or add a mode table, but this works and is much
489 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
490 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
491 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
496 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
498 struct drm_device *dev = encoder->dev;
499 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
500 struct drm_display_mode *mode = NULL;
501 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
506 } common_modes[17] = {
526 for (i = 0; i < 17; i++) {
527 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
528 if (common_modes[i].w > 1024 ||
529 common_modes[i].h > 768)
532 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
533 if (common_modes[i].w > native_mode->hdisplay ||
534 common_modes[i].h > native_mode->vdisplay ||
535 (common_modes[i].w == native_mode->hdisplay &&
536 common_modes[i].h == native_mode->vdisplay))
539 if (common_modes[i].w < 320 || common_modes[i].h < 200)
542 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
543 drm_mode_probed_add(connector, mode);
547 static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
550 struct drm_device *dev = connector->dev;
551 struct radeon_device *rdev = dev->dev_private;
552 struct drm_encoder *encoder;
553 struct radeon_encoder *radeon_encoder;
555 if (property == rdev->mode_info.coherent_mode_property) {
556 struct radeon_encoder_atom_dig *dig;
557 bool new_coherent_mode;
559 /* need to find digital encoder on connector */
560 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
564 radeon_encoder = to_radeon_encoder(encoder);
566 if (!radeon_encoder->enc_priv)
569 dig = radeon_encoder->enc_priv;
570 new_coherent_mode = val ? true : false;
571 if (dig->coherent_mode != new_coherent_mode) {
572 dig->coherent_mode = new_coherent_mode;
573 radeon_property_change_mode(&radeon_encoder->base);
577 if (property == rdev->mode_info.audio_property) {
578 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
579 /* need to find digital encoder on connector */
580 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
584 radeon_encoder = to_radeon_encoder(encoder);
586 if (radeon_connector->audio != val) {
587 radeon_connector->audio = val;
588 radeon_property_change_mode(&radeon_encoder->base);
592 if (property == rdev->mode_info.dither_property) {
593 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
594 /* need to find digital encoder on connector */
595 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
599 radeon_encoder = to_radeon_encoder(encoder);
601 if (radeon_connector->dither != val) {
602 radeon_connector->dither = val;
603 radeon_property_change_mode(&radeon_encoder->base);
607 if (property == rdev->mode_info.underscan_property) {
608 /* need to find digital encoder on connector */
609 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
613 radeon_encoder = to_radeon_encoder(encoder);
615 if (radeon_encoder->underscan_type != val) {
616 radeon_encoder->underscan_type = val;
617 radeon_property_change_mode(&radeon_encoder->base);
621 if (property == rdev->mode_info.underscan_hborder_property) {
622 /* need to find digital encoder on connector */
623 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
627 radeon_encoder = to_radeon_encoder(encoder);
629 if (radeon_encoder->underscan_hborder != val) {
630 radeon_encoder->underscan_hborder = val;
631 radeon_property_change_mode(&radeon_encoder->base);
635 if (property == rdev->mode_info.underscan_vborder_property) {
636 /* need to find digital encoder on connector */
637 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
641 radeon_encoder = to_radeon_encoder(encoder);
643 if (radeon_encoder->underscan_vborder != val) {
644 radeon_encoder->underscan_vborder = val;
645 radeon_property_change_mode(&radeon_encoder->base);
649 if (property == rdev->mode_info.tv_std_property) {
650 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
652 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
658 radeon_encoder = to_radeon_encoder(encoder);
659 if (!radeon_encoder->enc_priv)
661 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
662 struct radeon_encoder_atom_dac *dac_int;
663 dac_int = radeon_encoder->enc_priv;
664 dac_int->tv_std = val;
666 struct radeon_encoder_tv_dac *dac_int;
667 dac_int = radeon_encoder->enc_priv;
668 dac_int->tv_std = val;
670 radeon_property_change_mode(&radeon_encoder->base);
673 if (property == rdev->mode_info.load_detect_property) {
674 struct radeon_connector *radeon_connector =
675 to_radeon_connector(connector);
678 radeon_connector->dac_load_detect = false;
680 radeon_connector->dac_load_detect = true;
683 if (property == rdev->mode_info.tmds_pll_property) {
684 struct radeon_encoder_int_tmds *tmds = NULL;
686 /* need to find digital encoder on connector */
687 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
691 radeon_encoder = to_radeon_encoder(encoder);
693 tmds = radeon_encoder->enc_priv;
698 if (rdev->is_atom_bios)
699 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
701 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
703 if (val == 1 || !ret)
704 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
706 radeon_property_change_mode(&radeon_encoder->base);
709 if (property == dev->mode_config.scaling_mode_property) {
710 enum radeon_rmx_type rmx_type;
712 if (connector->encoder)
713 radeon_encoder = to_radeon_encoder(connector->encoder);
715 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
716 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
721 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
722 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
723 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
724 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
726 if (radeon_encoder->rmx_type == rmx_type)
729 if ((rmx_type != DRM_MODE_SCALE_NONE) &&
730 (radeon_encoder->native_mode.clock == 0))
733 radeon_encoder->rmx_type = rmx_type;
735 radeon_property_change_mode(&radeon_encoder->base);
738 if (property == rdev->mode_info.output_csc_property) {
739 if (connector->encoder)
740 radeon_encoder = to_radeon_encoder(connector->encoder);
742 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
743 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
746 if (radeon_encoder->output_csc == val)
749 radeon_encoder->output_csc = val;
751 if (connector->encoder && connector->encoder->crtc) {
752 struct drm_crtc *crtc = connector->encoder->crtc;
753 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
755 radeon_crtc->output_csc = radeon_encoder->output_csc;
758 * Our .gamma_set assumes the .gamma_store has been
759 * prefilled and don't care about its arguments.
761 crtc->funcs->gamma_set(crtc, NULL, NULL, NULL, 0, NULL);
768 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
769 struct drm_connector *connector)
771 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
772 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
773 struct drm_display_mode *t, *mode;
775 /* If the EDID preferred mode doesn't match the native mode, use it */
776 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
777 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
778 if (mode->hdisplay != native_mode->hdisplay ||
779 mode->vdisplay != native_mode->vdisplay)
780 memcpy(native_mode, mode, sizeof(*mode));
784 /* Try to get native mode details from EDID if necessary */
785 if (!native_mode->clock) {
786 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
787 if (mode->hdisplay == native_mode->hdisplay &&
788 mode->vdisplay == native_mode->vdisplay) {
789 *native_mode = *mode;
790 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
791 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
797 if (!native_mode->clock) {
798 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
799 radeon_encoder->rmx_type = RMX_OFF;
803 static int radeon_lvds_get_modes(struct drm_connector *connector)
805 struct drm_encoder *encoder;
807 struct drm_display_mode *mode;
809 radeon_connector_get_edid(connector);
810 ret = radeon_ddc_get_modes(connector);
812 encoder = radeon_best_single_encoder(connector);
814 radeon_fixup_lvds_native_mode(encoder, connector);
815 /* add scaled modes */
816 radeon_add_common_modes(encoder, connector);
821 encoder = radeon_best_single_encoder(connector);
825 /* we have no EDID modes */
826 mode = radeon_fp_native_mode(encoder);
829 drm_mode_probed_add(connector, mode);
830 /* add the width/height from vbios tables if available */
831 connector->display_info.width_mm = mode->width_mm;
832 connector->display_info.height_mm = mode->height_mm;
833 /* add scaled modes */
834 radeon_add_common_modes(encoder, connector);
840 static enum drm_mode_status radeon_lvds_mode_valid(struct drm_connector *connector,
841 struct drm_display_mode *mode)
843 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
845 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
849 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
850 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
852 /* AVIVO hardware supports downscaling modes larger than the panel
853 * to the panel size, but I'm not sure this is desirable.
855 if ((mode->hdisplay > native_mode->hdisplay) ||
856 (mode->vdisplay > native_mode->vdisplay))
859 /* if scaling is disabled, block non-native modes */
860 if (radeon_encoder->rmx_type == RMX_OFF) {
861 if ((mode->hdisplay != native_mode->hdisplay) ||
862 (mode->vdisplay != native_mode->vdisplay))
870 static enum drm_connector_status
871 radeon_lvds_detect(struct drm_connector *connector, bool force)
873 struct drm_device *dev = connector->dev;
874 struct radeon_device *rdev = dev->dev_private;
875 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
876 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
877 enum drm_connector_status ret = connector_status_disconnected;
880 if (!drm_kms_helper_is_poll_worker()) {
881 r = pm_runtime_get_sync(connector->dev->dev);
883 pm_runtime_put_autosuspend(connector->dev->dev);
884 return connector_status_disconnected;
889 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
890 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
892 /* check if panel is valid */
893 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
894 ret = connector_status_connected;
895 /* don't fetch the edid from the vbios if ddc fails and runpm is
896 * enabled so we report disconnected.
898 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
899 ret = connector_status_disconnected;
902 /* check for edid as well */
903 radeon_connector_get_edid(connector);
904 if (radeon_connector->edid)
905 ret = connector_status_connected;
906 /* check acpi lid status ??? */
908 radeon_connector_update_scratch_regs(connector, ret);
910 if (!drm_kms_helper_is_poll_worker()) {
911 pm_runtime_mark_last_busy(connector->dev->dev);
912 pm_runtime_put_autosuspend(connector->dev->dev);
918 static void radeon_connector_unregister(struct drm_connector *connector)
920 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
922 if (radeon_connector->ddc_bus && radeon_connector->ddc_bus->has_aux) {
923 drm_dp_aux_unregister(&radeon_connector->ddc_bus->aux);
924 radeon_connector->ddc_bus->has_aux = false;
928 static void radeon_connector_destroy(struct drm_connector *connector)
930 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
932 radeon_connector_free_edid(connector);
933 kfree(radeon_connector->con_priv);
934 drm_connector_unregister(connector);
935 drm_connector_cleanup(connector);
939 static int radeon_lvds_set_property(struct drm_connector *connector,
940 struct drm_property *property,
943 struct drm_device *dev = connector->dev;
944 struct radeon_encoder *radeon_encoder;
945 enum radeon_rmx_type rmx_type;
948 if (property != dev->mode_config.scaling_mode_property)
951 if (connector->encoder)
952 radeon_encoder = to_radeon_encoder(connector->encoder);
954 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
955 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
959 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
960 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
961 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
963 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
965 if (radeon_encoder->rmx_type == rmx_type)
968 radeon_encoder->rmx_type = rmx_type;
970 radeon_property_change_mode(&radeon_encoder->base);
975 static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
976 .get_modes = radeon_lvds_get_modes,
977 .mode_valid = radeon_lvds_mode_valid,
978 .best_encoder = radeon_best_single_encoder,
981 static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
982 .dpms = drm_helper_connector_dpms,
983 .detect = radeon_lvds_detect,
984 .fill_modes = drm_helper_probe_single_connector_modes,
985 .early_unregister = radeon_connector_unregister,
986 .destroy = radeon_connector_destroy,
987 .set_property = radeon_lvds_set_property,
990 static int radeon_vga_get_modes(struct drm_connector *connector)
994 radeon_connector_get_edid(connector);
995 ret = radeon_ddc_get_modes(connector);
997 radeon_get_native_mode(connector);
1002 static enum drm_mode_status radeon_vga_mode_valid(struct drm_connector *connector,
1003 struct drm_display_mode *mode)
1005 struct drm_device *dev = connector->dev;
1006 struct radeon_device *rdev = dev->dev_private;
1008 /* XXX check mode bandwidth */
1010 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1011 return MODE_CLOCK_HIGH;
1016 static enum drm_connector_status
1017 radeon_vga_detect(struct drm_connector *connector, bool force)
1019 struct drm_device *dev = connector->dev;
1020 struct radeon_device *rdev = dev->dev_private;
1021 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1022 struct drm_encoder *encoder;
1023 const struct drm_encoder_helper_funcs *encoder_funcs;
1025 enum drm_connector_status ret = connector_status_disconnected;
1028 if (!drm_kms_helper_is_poll_worker()) {
1029 r = pm_runtime_get_sync(connector->dev->dev);
1031 pm_runtime_put_autosuspend(connector->dev->dev);
1032 return connector_status_disconnected;
1036 encoder = radeon_best_single_encoder(connector);
1038 ret = connector_status_disconnected;
1040 if (radeon_connector->ddc_bus)
1041 dret = radeon_ddc_probe(radeon_connector, false);
1043 radeon_connector->detected_by_load = false;
1044 radeon_connector_free_edid(connector);
1045 radeon_connector_get_edid(connector);
1047 if (!radeon_connector->edid) {
1048 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1050 ret = connector_status_connected;
1052 radeon_connector->use_digital =
1053 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
1055 /* some oems have boards with separate digital and analog connectors
1056 * with a shared ddc line (often vga + hdmi)
1058 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
1059 radeon_connector_free_edid(connector);
1060 ret = connector_status_disconnected;
1062 ret = connector_status_connected;
1067 /* if we aren't forcing don't do destructive polling */
1069 /* only return the previous status if we last
1070 * detected a monitor via load.
1072 if (radeon_connector->detected_by_load)
1073 ret = connector->status;
1077 if (radeon_connector->dac_load_detect && encoder) {
1078 encoder_funcs = encoder->helper_private;
1079 ret = encoder_funcs->detect(encoder, connector);
1080 if (ret != connector_status_disconnected)
1081 radeon_connector->detected_by_load = true;
1085 if (ret == connector_status_connected)
1086 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1088 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1089 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1090 * by other means, assume the CRT is connected and use that EDID.
1092 if ((!rdev->is_atom_bios) &&
1093 (ret == connector_status_disconnected) &&
1094 rdev->mode_info.bios_hardcoded_edid_size) {
1095 ret = connector_status_connected;
1098 radeon_connector_update_scratch_regs(connector, ret);
1101 if (!drm_kms_helper_is_poll_worker()) {
1102 pm_runtime_mark_last_busy(connector->dev->dev);
1103 pm_runtime_put_autosuspend(connector->dev->dev);
1109 static const struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
1110 .get_modes = radeon_vga_get_modes,
1111 .mode_valid = radeon_vga_mode_valid,
1112 .best_encoder = radeon_best_single_encoder,
1115 static const struct drm_connector_funcs radeon_vga_connector_funcs = {
1116 .dpms = drm_helper_connector_dpms,
1117 .detect = radeon_vga_detect,
1118 .fill_modes = drm_helper_probe_single_connector_modes,
1119 .early_unregister = radeon_connector_unregister,
1120 .destroy = radeon_connector_destroy,
1121 .set_property = radeon_connector_set_property,
1124 static int radeon_tv_get_modes(struct drm_connector *connector)
1126 struct drm_device *dev = connector->dev;
1127 struct radeon_device *rdev = dev->dev_private;
1128 struct drm_display_mode *tv_mode;
1129 struct drm_encoder *encoder;
1131 encoder = radeon_best_single_encoder(connector);
1135 /* avivo chips can scale any mode */
1136 if (rdev->family >= CHIP_RS600)
1137 /* add scaled modes */
1138 radeon_add_common_modes(encoder, connector);
1140 /* only 800x600 is supported right now on pre-avivo chips */
1141 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
1142 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
1143 drm_mode_probed_add(connector, tv_mode);
1148 static enum drm_mode_status radeon_tv_mode_valid(struct drm_connector *connector,
1149 struct drm_display_mode *mode)
1151 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
1152 return MODE_CLOCK_RANGE;
1156 static enum drm_connector_status
1157 radeon_tv_detect(struct drm_connector *connector, bool force)
1159 struct drm_encoder *encoder;
1160 const struct drm_encoder_helper_funcs *encoder_funcs;
1161 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1162 enum drm_connector_status ret = connector_status_disconnected;
1165 if (!radeon_connector->dac_load_detect)
1168 if (!drm_kms_helper_is_poll_worker()) {
1169 r = pm_runtime_get_sync(connector->dev->dev);
1171 pm_runtime_put_autosuspend(connector->dev->dev);
1172 return connector_status_disconnected;
1176 encoder = radeon_best_single_encoder(connector);
1178 ret = connector_status_disconnected;
1180 encoder_funcs = encoder->helper_private;
1181 ret = encoder_funcs->detect(encoder, connector);
1183 if (ret == connector_status_connected)
1184 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
1185 radeon_connector_update_scratch_regs(connector, ret);
1187 if (!drm_kms_helper_is_poll_worker()) {
1188 pm_runtime_mark_last_busy(connector->dev->dev);
1189 pm_runtime_put_autosuspend(connector->dev->dev);
1195 static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
1196 .get_modes = radeon_tv_get_modes,
1197 .mode_valid = radeon_tv_mode_valid,
1198 .best_encoder = radeon_best_single_encoder,
1201 static const struct drm_connector_funcs radeon_tv_connector_funcs = {
1202 .dpms = drm_helper_connector_dpms,
1203 .detect = radeon_tv_detect,
1204 .fill_modes = drm_helper_probe_single_connector_modes,
1205 .early_unregister = radeon_connector_unregister,
1206 .destroy = radeon_connector_destroy,
1207 .set_property = radeon_connector_set_property,
1210 static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector)
1212 struct drm_device *dev = connector->dev;
1213 struct radeon_device *rdev = dev->dev_private;
1214 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1215 enum drm_connector_status status;
1217 /* We only trust HPD on R600 and newer ASICS. */
1218 if (rdev->family >= CHIP_R600
1219 && radeon_connector->hpd.hpd != RADEON_HPD_NONE) {
1220 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
1221 status = connector_status_connected;
1223 status = connector_status_disconnected;
1224 if (connector->status == status)
1232 * DVI is complicated
1233 * Do a DDC probe, if DDC probe passes, get the full EDID so
1234 * we can do analog/digital monitor detection at this point.
1235 * If the monitor is an analog monitor or we got no DDC,
1236 * we need to find the DAC encoder object for this connector.
1237 * If we got no DDC, we do load detection on the DAC encoder object.
1238 * If we got analog DDC or load detection passes on the DAC encoder
1239 * we have to check if this analog encoder is shared with anyone else (TV)
1240 * if its shared we have to set the other connector to disconnected.
1242 static enum drm_connector_status
1243 radeon_dvi_detect(struct drm_connector *connector, bool force)
1245 struct drm_device *dev = connector->dev;
1246 struct radeon_device *rdev = dev->dev_private;
1247 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1248 struct drm_encoder *encoder = NULL;
1249 const struct drm_encoder_helper_funcs *encoder_funcs;
1251 enum drm_connector_status ret = connector_status_disconnected;
1252 bool dret = false, broken_edid = false;
1254 if (!drm_kms_helper_is_poll_worker()) {
1255 r = pm_runtime_get_sync(connector->dev->dev);
1257 pm_runtime_put_autosuspend(connector->dev->dev);
1258 return connector_status_disconnected;
1262 if (radeon_connector->detected_hpd_without_ddc) {
1264 radeon_connector->detected_hpd_without_ddc = false;
1267 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1268 ret = connector->status;
1272 if (radeon_connector->ddc_bus) {
1273 dret = radeon_ddc_probe(radeon_connector, false);
1275 /* Sometimes the pins required for the DDC probe on DVI
1276 * connectors don't make contact at the same time that the ones
1277 * for HPD do. If the DDC probe fails even though we had an HPD
1278 * signal, try again later */
1279 if (!dret && !force &&
1280 connector->status != connector_status_connected) {
1281 DRM_DEBUG_KMS("hpd detected without ddc, retrying in 1 second\n");
1282 radeon_connector->detected_hpd_without_ddc = true;
1283 schedule_delayed_work(&rdev->hotplug_work,
1284 msecs_to_jiffies(1000));
1289 radeon_connector->detected_by_load = false;
1290 radeon_connector_free_edid(connector);
1291 radeon_connector_get_edid(connector);
1293 if (!radeon_connector->edid) {
1294 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1296 /* rs690 seems to have a problem with connectors not existing and always
1297 * return a block of 0's. If we see this just stop polling on this output */
1298 if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) &&
1299 radeon_connector->base.null_edid_counter) {
1300 ret = connector_status_disconnected;
1301 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n",
1303 radeon_connector->ddc_bus = NULL;
1305 ret = connector_status_connected;
1306 broken_edid = true; /* defer use_digital to later */
1309 radeon_connector->use_digital =
1310 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
1312 /* some oems have boards with separate digital and analog connectors
1313 * with a shared ddc line (often vga + hdmi)
1315 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
1316 radeon_connector_free_edid(connector);
1317 ret = connector_status_disconnected;
1319 ret = connector_status_connected;
1321 /* This gets complicated. We have boards with VGA + HDMI with a
1322 * shared DDC line and we have boards with DVI-D + HDMI with a shared
1323 * DDC line. The latter is more complex because with DVI<->HDMI adapters
1324 * you don't really know what's connected to which port as both are digital.
1326 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
1327 struct drm_connector *list_connector;
1328 struct radeon_connector *list_radeon_connector;
1329 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
1330 if (connector == list_connector)
1332 list_radeon_connector = to_radeon_connector(list_connector);
1333 if (list_radeon_connector->shared_ddc &&
1334 (list_radeon_connector->ddc_bus->rec.i2c_id ==
1335 radeon_connector->ddc_bus->rec.i2c_id)) {
1336 /* cases where both connectors are digital */
1337 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
1338 /* hpd is our only option in this case */
1339 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1340 radeon_connector_free_edid(connector);
1341 ret = connector_status_disconnected;
1350 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
1353 /* DVI-D and HDMI-A are digital only */
1354 if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
1355 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
1358 /* if we aren't forcing don't do destructive polling */
1360 /* only return the previous status if we last
1361 * detected a monitor via load.
1363 if (radeon_connector->detected_by_load)
1364 ret = connector->status;
1368 /* find analog encoder */
1369 if (radeon_connector->dac_load_detect) {
1370 drm_connector_for_each_possible_encoder(connector, encoder) {
1371 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
1372 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
1375 encoder_funcs = encoder->helper_private;
1376 if (encoder_funcs->detect) {
1378 if (ret != connector_status_connected) {
1379 /* deal with analog monitors without DDC */
1380 ret = encoder_funcs->detect(encoder, connector);
1381 if (ret == connector_status_connected) {
1382 radeon_connector->use_digital = false;
1384 if (ret != connector_status_disconnected)
1385 radeon_connector->detected_by_load = true;
1388 enum drm_connector_status lret;
1389 /* assume digital unless load detected otherwise */
1390 radeon_connector->use_digital = true;
1391 lret = encoder_funcs->detect(encoder, connector);
1392 DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
1393 if (lret == connector_status_connected)
1394 radeon_connector->use_digital = false;
1401 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
1403 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1406 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1407 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1408 * by other means, assume the DFP is connected and use that EDID. In most
1409 * cases the DVI port is actually a virtual KVM port connected to the service
1413 if ((!rdev->is_atom_bios) &&
1414 (ret == connector_status_disconnected) &&
1415 rdev->mode_info.bios_hardcoded_edid_size) {
1416 radeon_connector->use_digital = true;
1417 ret = connector_status_connected;
1420 /* updated in get modes as well since we need to know if it's analog or digital */
1421 radeon_connector_update_scratch_regs(connector, ret);
1423 if ((radeon_audio != 0) && radeon_connector->use_digital) {
1424 const struct drm_connector_helper_funcs *connector_funcs =
1425 connector->helper_private;
1427 encoder = connector_funcs->best_encoder(connector);
1428 if (encoder && (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)) {
1429 radeon_connector_get_edid(connector);
1430 radeon_audio_detect(connector, encoder, ret);
1435 if (!drm_kms_helper_is_poll_worker()) {
1436 pm_runtime_mark_last_busy(connector->dev->dev);
1437 pm_runtime_put_autosuspend(connector->dev->dev);
1443 /* okay need to be smart in here about which encoder to pick */
1444 static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
1446 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1447 struct drm_encoder *encoder;
1449 drm_connector_for_each_possible_encoder(connector, encoder) {
1450 if (radeon_connector->use_digital == true) {
1451 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
1454 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
1455 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
1460 /* see if we have a default encoder TODO */
1462 /* then check use digitial */
1463 /* pick the first one */
1464 drm_connector_for_each_possible_encoder(connector, encoder)
1470 static void radeon_dvi_force(struct drm_connector *connector)
1472 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1473 if (connector->force == DRM_FORCE_ON)
1474 radeon_connector->use_digital = false;
1475 if (connector->force == DRM_FORCE_ON_DIGITAL)
1476 radeon_connector->use_digital = true;
1479 static enum drm_mode_status radeon_dvi_mode_valid(struct drm_connector *connector,
1480 struct drm_display_mode *mode)
1482 struct drm_device *dev = connector->dev;
1483 struct radeon_device *rdev = dev->dev_private;
1484 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1486 /* XXX check mode bandwidth */
1488 /* clocks over 135 MHz have heat issues with DVI on RV100 */
1489 if (radeon_connector->use_digital &&
1490 (rdev->family == CHIP_RV100) &&
1491 (mode->clock > 135000))
1492 return MODE_CLOCK_HIGH;
1494 if (radeon_connector->use_digital && (mode->clock > 165000)) {
1495 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1496 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1497 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1499 else if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
1500 /* HDMI 1.3+ supports max clock of 340 Mhz */
1501 if (mode->clock > 340000)
1502 return MODE_CLOCK_HIGH;
1506 return MODE_CLOCK_HIGH;
1510 /* check against the max pixel clock */
1511 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1512 return MODE_CLOCK_HIGH;
1517 static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
1518 .get_modes = radeon_vga_get_modes,
1519 .mode_valid = radeon_dvi_mode_valid,
1520 .best_encoder = radeon_dvi_encoder,
1523 static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
1524 .dpms = drm_helper_connector_dpms,
1525 .detect = radeon_dvi_detect,
1526 .fill_modes = drm_helper_probe_single_connector_modes,
1527 .set_property = radeon_connector_set_property,
1528 .early_unregister = radeon_connector_unregister,
1529 .destroy = radeon_connector_destroy,
1530 .force = radeon_dvi_force,
1533 static int radeon_dp_get_modes(struct drm_connector *connector)
1535 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1536 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1537 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1540 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1541 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1542 struct drm_display_mode *mode;
1544 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1545 if (!radeon_dig_connector->edp_on)
1546 atombios_set_edp_panel_power(connector,
1547 ATOM_TRANSMITTER_ACTION_POWER_ON);
1548 radeon_connector_get_edid(connector);
1549 ret = radeon_ddc_get_modes(connector);
1550 if (!radeon_dig_connector->edp_on)
1551 atombios_set_edp_panel_power(connector,
1552 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1554 /* need to setup ddc on the bridge */
1555 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1556 ENCODER_OBJECT_ID_NONE) {
1558 radeon_atom_ext_encoder_setup_ddc(encoder);
1560 radeon_connector_get_edid(connector);
1561 ret = radeon_ddc_get_modes(connector);
1566 radeon_fixup_lvds_native_mode(encoder, connector);
1567 /* add scaled modes */
1568 radeon_add_common_modes(encoder, connector);
1576 /* we have no EDID modes */
1577 mode = radeon_fp_native_mode(encoder);
1580 drm_mode_probed_add(connector, mode);
1581 /* add the width/height from vbios tables if available */
1582 connector->display_info.width_mm = mode->width_mm;
1583 connector->display_info.height_mm = mode->height_mm;
1584 /* add scaled modes */
1585 radeon_add_common_modes(encoder, connector);
1588 /* need to setup ddc on the bridge */
1589 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1590 ENCODER_OBJECT_ID_NONE) {
1592 radeon_atom_ext_encoder_setup_ddc(encoder);
1594 radeon_connector_get_edid(connector);
1595 ret = radeon_ddc_get_modes(connector);
1597 radeon_get_native_mode(connector);
1603 u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
1605 struct drm_encoder *encoder;
1606 struct radeon_encoder *radeon_encoder;
1608 drm_connector_for_each_possible_encoder(connector, encoder) {
1609 radeon_encoder = to_radeon_encoder(encoder);
1611 switch (radeon_encoder->encoder_id) {
1612 case ENCODER_OBJECT_ID_TRAVIS:
1613 case ENCODER_OBJECT_ID_NUTMEG:
1614 return radeon_encoder->encoder_id;
1620 return ENCODER_OBJECT_ID_NONE;
1623 static bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
1625 struct drm_encoder *encoder;
1626 struct radeon_encoder *radeon_encoder;
1629 drm_connector_for_each_possible_encoder(connector, encoder) {
1630 radeon_encoder = to_radeon_encoder(encoder);
1631 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1638 bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1640 struct drm_device *dev = connector->dev;
1641 struct radeon_device *rdev = dev->dev_private;
1643 if (ASIC_IS_DCE5(rdev) &&
1644 (rdev->clock.default_dispclk >= 53900) &&
1645 radeon_connector_encoder_is_hbr2(connector)) {
1652 static enum drm_connector_status
1653 radeon_dp_detect(struct drm_connector *connector, bool force)
1655 struct drm_device *dev = connector->dev;
1656 struct radeon_device *rdev = dev->dev_private;
1657 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1658 enum drm_connector_status ret = connector_status_disconnected;
1659 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1660 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1663 if (radeon_dig_connector->is_mst)
1664 return connector_status_disconnected;
1666 if (!drm_kms_helper_is_poll_worker()) {
1667 r = pm_runtime_get_sync(connector->dev->dev);
1669 pm_runtime_put_autosuspend(connector->dev->dev);
1670 return connector_status_disconnected;
1674 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1675 ret = connector->status;
1679 radeon_connector_free_edid(connector);
1681 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1682 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1684 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1685 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1687 /* check if panel is valid */
1688 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1689 ret = connector_status_connected;
1690 /* don't fetch the edid from the vbios if ddc fails and runpm is
1691 * enabled so we report disconnected.
1693 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
1694 ret = connector_status_disconnected;
1696 /* eDP is always DP */
1697 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1698 if (!radeon_dig_connector->edp_on)
1699 atombios_set_edp_panel_power(connector,
1700 ATOM_TRANSMITTER_ACTION_POWER_ON);
1701 if (radeon_dp_getdpcd(radeon_connector))
1702 ret = connector_status_connected;
1703 if (!radeon_dig_connector->edp_on)
1704 atombios_set_edp_panel_power(connector,
1705 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1706 } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1707 ENCODER_OBJECT_ID_NONE) {
1708 /* DP bridges are always DP */
1709 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1710 /* get the DPCD from the bridge */
1711 radeon_dp_getdpcd(radeon_connector);
1714 /* setup ddc on the bridge */
1715 radeon_atom_ext_encoder_setup_ddc(encoder);
1716 /* bridge chips are always aux */
1717 if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */
1718 ret = connector_status_connected;
1719 else if (radeon_connector->dac_load_detect) { /* try load detection */
1720 const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
1721 ret = encoder_funcs->detect(encoder, connector);
1725 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
1726 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1727 ret = connector_status_connected;
1728 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1729 radeon_dp_getdpcd(radeon_connector);
1730 r = radeon_dp_mst_probe(radeon_connector);
1732 ret = connector_status_disconnected;
1735 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1736 if (radeon_dp_getdpcd(radeon_connector)) {
1737 r = radeon_dp_mst_probe(radeon_connector);
1739 ret = connector_status_disconnected;
1741 ret = connector_status_connected;
1744 /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
1745 if (radeon_ddc_probe(radeon_connector, false))
1746 ret = connector_status_connected;
1751 radeon_connector_update_scratch_regs(connector, ret);
1753 if ((radeon_audio != 0) && encoder) {
1754 radeon_connector_get_edid(connector);
1755 radeon_audio_detect(connector, encoder, ret);
1759 if (!drm_kms_helper_is_poll_worker()) {
1760 pm_runtime_mark_last_busy(connector->dev->dev);
1761 pm_runtime_put_autosuspend(connector->dev->dev);
1767 static enum drm_mode_status radeon_dp_mode_valid(struct drm_connector *connector,
1768 struct drm_display_mode *mode)
1770 struct drm_device *dev = connector->dev;
1771 struct radeon_device *rdev = dev->dev_private;
1772 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1773 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1775 /* XXX check mode bandwidth */
1777 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1778 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1779 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1781 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1785 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1786 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1788 /* AVIVO hardware supports downscaling modes larger than the panel
1789 * to the panel size, but I'm not sure this is desirable.
1791 if ((mode->hdisplay > native_mode->hdisplay) ||
1792 (mode->vdisplay > native_mode->vdisplay))
1795 /* if scaling is disabled, block non-native modes */
1796 if (radeon_encoder->rmx_type == RMX_OFF) {
1797 if ((mode->hdisplay != native_mode->hdisplay) ||
1798 (mode->vdisplay != native_mode->vdisplay))
1803 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1804 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
1805 return radeon_dp_mode_valid_helper(connector, mode);
1807 if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
1808 /* HDMI 1.3+ supports max clock of 340 Mhz */
1809 if (mode->clock > 340000)
1810 return MODE_CLOCK_HIGH;
1812 if (mode->clock > 165000)
1813 return MODE_CLOCK_HIGH;
1821 static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1822 .get_modes = radeon_dp_get_modes,
1823 .mode_valid = radeon_dp_mode_valid,
1824 .best_encoder = radeon_dvi_encoder,
1827 static const struct drm_connector_funcs radeon_dp_connector_funcs = {
1828 .dpms = drm_helper_connector_dpms,
1829 .detect = radeon_dp_detect,
1830 .fill_modes = drm_helper_probe_single_connector_modes,
1831 .set_property = radeon_connector_set_property,
1832 .early_unregister = radeon_connector_unregister,
1833 .destroy = radeon_connector_destroy,
1834 .force = radeon_dvi_force,
1837 static const struct drm_connector_funcs radeon_edp_connector_funcs = {
1838 .dpms = drm_helper_connector_dpms,
1839 .detect = radeon_dp_detect,
1840 .fill_modes = drm_helper_probe_single_connector_modes,
1841 .set_property = radeon_lvds_set_property,
1842 .early_unregister = radeon_connector_unregister,
1843 .destroy = radeon_connector_destroy,
1844 .force = radeon_dvi_force,
1847 static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
1848 .dpms = drm_helper_connector_dpms,
1849 .detect = radeon_dp_detect,
1850 .fill_modes = drm_helper_probe_single_connector_modes,
1851 .set_property = radeon_lvds_set_property,
1852 .early_unregister = radeon_connector_unregister,
1853 .destroy = radeon_connector_destroy,
1854 .force = radeon_dvi_force,
1858 radeon_add_atom_connector(struct drm_device *dev,
1859 uint32_t connector_id,
1860 uint32_t supported_device,
1862 struct radeon_i2c_bus_rec *i2c_bus,
1863 uint32_t igp_lane_info,
1864 uint16_t connector_object_id,
1865 struct radeon_hpd *hpd,
1866 struct radeon_router *router)
1868 struct radeon_device *rdev = dev->dev_private;
1869 struct drm_connector *connector;
1870 struct radeon_connector *radeon_connector;
1871 struct radeon_connector_atom_dig *radeon_dig_connector;
1872 struct drm_encoder *encoder;
1873 struct radeon_encoder *radeon_encoder;
1874 struct i2c_adapter *ddc = NULL;
1875 uint32_t subpixel_order = SubPixelNone;
1876 bool shared_ddc = false;
1877 bool is_dp_bridge = false;
1878 bool has_aux = false;
1880 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1883 /* if the user selected tv=0 don't try and add the connector */
1884 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1885 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1886 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1890 /* see if we already added it */
1891 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1892 radeon_connector = to_radeon_connector(connector);
1893 if (radeon_connector->connector_id == connector_id) {
1894 radeon_connector->devices |= supported_device;
1897 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1898 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1899 radeon_connector->shared_ddc = true;
1902 if (radeon_connector->router_bus && router->ddc_valid &&
1903 (radeon_connector->router.router_id == router->router_id)) {
1904 radeon_connector->shared_ddc = false;
1910 /* check if it's a dp bridge */
1911 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1912 radeon_encoder = to_radeon_encoder(encoder);
1913 if (radeon_encoder->devices & supported_device) {
1914 switch (radeon_encoder->encoder_id) {
1915 case ENCODER_OBJECT_ID_TRAVIS:
1916 case ENCODER_OBJECT_ID_NUTMEG:
1917 is_dp_bridge = true;
1925 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1926 if (!radeon_connector)
1929 connector = &radeon_connector->base;
1931 radeon_connector->connector_id = connector_id;
1932 radeon_connector->devices = supported_device;
1933 radeon_connector->shared_ddc = shared_ddc;
1934 radeon_connector->connector_object_id = connector_object_id;
1935 radeon_connector->hpd = *hpd;
1937 radeon_connector->router = *router;
1938 if (router->ddc_valid || router->cd_valid) {
1939 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1940 if (!radeon_connector->router_bus)
1941 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
1945 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1946 if (!radeon_dig_connector)
1948 radeon_dig_connector->igp_lane_info = igp_lane_info;
1949 radeon_connector->con_priv = radeon_dig_connector;
1950 if (i2c_bus->valid) {
1951 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1952 if (radeon_connector->ddc_bus) {
1954 ddc = &radeon_connector->ddc_bus->adapter;
1956 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1959 switch (connector_type) {
1960 case DRM_MODE_CONNECTOR_VGA:
1961 case DRM_MODE_CONNECTOR_DVIA:
1963 drm_connector_init_with_ddc(dev, &radeon_connector->base,
1964 &radeon_dp_connector_funcs,
1967 drm_connector_helper_add(&radeon_connector->base,
1968 &radeon_dp_connector_helper_funcs);
1969 connector->interlace_allowed = true;
1970 connector->doublescan_allowed = true;
1971 radeon_connector->dac_load_detect = true;
1972 drm_object_attach_property(&radeon_connector->base.base,
1973 rdev->mode_info.load_detect_property,
1975 drm_object_attach_property(&radeon_connector->base.base,
1976 dev->mode_config.scaling_mode_property,
1977 DRM_MODE_SCALE_NONE);
1978 if (ASIC_IS_DCE5(rdev))
1979 drm_object_attach_property(&radeon_connector->base.base,
1980 rdev->mode_info.output_csc_property,
1981 RADEON_OUTPUT_CSC_BYPASS);
1983 case DRM_MODE_CONNECTOR_DVII:
1984 case DRM_MODE_CONNECTOR_DVID:
1985 case DRM_MODE_CONNECTOR_HDMIA:
1986 case DRM_MODE_CONNECTOR_HDMIB:
1987 case DRM_MODE_CONNECTOR_DisplayPort:
1988 drm_connector_init_with_ddc(dev, &radeon_connector->base,
1989 &radeon_dp_connector_funcs,
1992 drm_connector_helper_add(&radeon_connector->base,
1993 &radeon_dp_connector_helper_funcs);
1994 drm_object_attach_property(&radeon_connector->base.base,
1995 rdev->mode_info.underscan_property,
1997 drm_object_attach_property(&radeon_connector->base.base,
1998 rdev->mode_info.underscan_hborder_property,
2000 drm_object_attach_property(&radeon_connector->base.base,
2001 rdev->mode_info.underscan_vborder_property,
2004 drm_object_attach_property(&radeon_connector->base.base,
2005 dev->mode_config.scaling_mode_property,
2006 DRM_MODE_SCALE_NONE);
2008 drm_object_attach_property(&radeon_connector->base.base,
2009 rdev->mode_info.dither_property,
2010 RADEON_FMT_DITHER_DISABLE);
2012 if (radeon_audio != 0) {
2013 drm_object_attach_property(&radeon_connector->base.base,
2014 rdev->mode_info.audio_property,
2016 radeon_connector->audio = RADEON_AUDIO_AUTO;
2018 if (ASIC_IS_DCE5(rdev))
2019 drm_object_attach_property(&radeon_connector->base.base,
2020 rdev->mode_info.output_csc_property,
2021 RADEON_OUTPUT_CSC_BYPASS);
2023 subpixel_order = SubPixelHorizontalRGB;
2024 connector->interlace_allowed = true;
2025 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
2026 connector->doublescan_allowed = true;
2028 connector->doublescan_allowed = false;
2029 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2030 radeon_connector->dac_load_detect = true;
2031 drm_object_attach_property(&radeon_connector->base.base,
2032 rdev->mode_info.load_detect_property,
2036 case DRM_MODE_CONNECTOR_LVDS:
2037 case DRM_MODE_CONNECTOR_eDP:
2038 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2039 &radeon_lvds_bridge_connector_funcs,
2042 drm_connector_helper_add(&radeon_connector->base,
2043 &radeon_dp_connector_helper_funcs);
2044 drm_object_attach_property(&radeon_connector->base.base,
2045 dev->mode_config.scaling_mode_property,
2046 DRM_MODE_SCALE_FULLSCREEN);
2047 subpixel_order = SubPixelHorizontalRGB;
2048 connector->interlace_allowed = false;
2049 connector->doublescan_allowed = false;
2053 switch (connector_type) {
2054 case DRM_MODE_CONNECTOR_VGA:
2055 if (i2c_bus->valid) {
2056 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2057 if (!radeon_connector->ddc_bus)
2058 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2060 ddc = &radeon_connector->ddc_bus->adapter;
2062 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2063 &radeon_vga_connector_funcs,
2066 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2067 radeon_connector->dac_load_detect = true;
2068 drm_object_attach_property(&radeon_connector->base.base,
2069 rdev->mode_info.load_detect_property,
2071 if (ASIC_IS_AVIVO(rdev))
2072 drm_object_attach_property(&radeon_connector->base.base,
2073 dev->mode_config.scaling_mode_property,
2074 DRM_MODE_SCALE_NONE);
2075 if (ASIC_IS_DCE5(rdev))
2076 drm_object_attach_property(&radeon_connector->base.base,
2077 rdev->mode_info.output_csc_property,
2078 RADEON_OUTPUT_CSC_BYPASS);
2079 /* no HPD on analog connectors */
2080 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2081 connector->interlace_allowed = true;
2082 connector->doublescan_allowed = true;
2084 case DRM_MODE_CONNECTOR_DVIA:
2085 if (i2c_bus->valid) {
2086 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2087 if (!radeon_connector->ddc_bus)
2088 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2090 ddc = &radeon_connector->ddc_bus->adapter;
2092 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2093 &radeon_vga_connector_funcs,
2096 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2097 radeon_connector->dac_load_detect = true;
2098 drm_object_attach_property(&radeon_connector->base.base,
2099 rdev->mode_info.load_detect_property,
2101 if (ASIC_IS_AVIVO(rdev))
2102 drm_object_attach_property(&radeon_connector->base.base,
2103 dev->mode_config.scaling_mode_property,
2104 DRM_MODE_SCALE_NONE);
2105 if (ASIC_IS_DCE5(rdev))
2106 drm_object_attach_property(&radeon_connector->base.base,
2107 rdev->mode_info.output_csc_property,
2108 RADEON_OUTPUT_CSC_BYPASS);
2109 /* no HPD on analog connectors */
2110 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2111 connector->interlace_allowed = true;
2112 connector->doublescan_allowed = true;
2114 case DRM_MODE_CONNECTOR_DVII:
2115 case DRM_MODE_CONNECTOR_DVID:
2116 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2117 if (!radeon_dig_connector)
2119 radeon_dig_connector->igp_lane_info = igp_lane_info;
2120 radeon_connector->con_priv = radeon_dig_connector;
2121 if (i2c_bus->valid) {
2122 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2123 if (!radeon_connector->ddc_bus)
2124 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2126 ddc = &radeon_connector->ddc_bus->adapter;
2128 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2129 &radeon_dvi_connector_funcs,
2132 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2133 subpixel_order = SubPixelHorizontalRGB;
2134 drm_object_attach_property(&radeon_connector->base.base,
2135 rdev->mode_info.coherent_mode_property,
2137 if (ASIC_IS_AVIVO(rdev)) {
2138 drm_object_attach_property(&radeon_connector->base.base,
2139 rdev->mode_info.underscan_property,
2141 drm_object_attach_property(&radeon_connector->base.base,
2142 rdev->mode_info.underscan_hborder_property,
2144 drm_object_attach_property(&radeon_connector->base.base,
2145 rdev->mode_info.underscan_vborder_property,
2147 drm_object_attach_property(&radeon_connector->base.base,
2148 rdev->mode_info.dither_property,
2149 RADEON_FMT_DITHER_DISABLE);
2150 drm_object_attach_property(&radeon_connector->base.base,
2151 dev->mode_config.scaling_mode_property,
2152 DRM_MODE_SCALE_NONE);
2154 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2155 drm_object_attach_property(&radeon_connector->base.base,
2156 rdev->mode_info.audio_property,
2158 radeon_connector->audio = RADEON_AUDIO_AUTO;
2160 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2161 radeon_connector->dac_load_detect = true;
2162 drm_object_attach_property(&radeon_connector->base.base,
2163 rdev->mode_info.load_detect_property,
2166 if (ASIC_IS_DCE5(rdev))
2167 drm_object_attach_property(&radeon_connector->base.base,
2168 rdev->mode_info.output_csc_property,
2169 RADEON_OUTPUT_CSC_BYPASS);
2170 connector->interlace_allowed = true;
2171 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2172 connector->doublescan_allowed = true;
2174 connector->doublescan_allowed = false;
2176 case DRM_MODE_CONNECTOR_HDMIA:
2177 case DRM_MODE_CONNECTOR_HDMIB:
2178 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2179 if (!radeon_dig_connector)
2181 radeon_dig_connector->igp_lane_info = igp_lane_info;
2182 radeon_connector->con_priv = radeon_dig_connector;
2183 if (i2c_bus->valid) {
2184 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2185 if (!radeon_connector->ddc_bus)
2186 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2188 ddc = &radeon_connector->ddc_bus->adapter;
2190 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2191 &radeon_dvi_connector_funcs,
2194 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2195 drm_object_attach_property(&radeon_connector->base.base,
2196 rdev->mode_info.coherent_mode_property,
2198 if (ASIC_IS_AVIVO(rdev)) {
2199 drm_object_attach_property(&radeon_connector->base.base,
2200 rdev->mode_info.underscan_property,
2202 drm_object_attach_property(&radeon_connector->base.base,
2203 rdev->mode_info.underscan_hborder_property,
2205 drm_object_attach_property(&radeon_connector->base.base,
2206 rdev->mode_info.underscan_vborder_property,
2208 drm_object_attach_property(&radeon_connector->base.base,
2209 rdev->mode_info.dither_property,
2210 RADEON_FMT_DITHER_DISABLE);
2211 drm_object_attach_property(&radeon_connector->base.base,
2212 dev->mode_config.scaling_mode_property,
2213 DRM_MODE_SCALE_NONE);
2215 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2216 drm_object_attach_property(&radeon_connector->base.base,
2217 rdev->mode_info.audio_property,
2219 radeon_connector->audio = RADEON_AUDIO_AUTO;
2221 if (ASIC_IS_DCE5(rdev))
2222 drm_object_attach_property(&radeon_connector->base.base,
2223 rdev->mode_info.output_csc_property,
2224 RADEON_OUTPUT_CSC_BYPASS);
2225 subpixel_order = SubPixelHorizontalRGB;
2226 connector->interlace_allowed = true;
2227 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
2228 connector->doublescan_allowed = true;
2230 connector->doublescan_allowed = false;
2232 case DRM_MODE_CONNECTOR_DisplayPort:
2233 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2234 if (!radeon_dig_connector)
2236 radeon_dig_connector->igp_lane_info = igp_lane_info;
2237 radeon_connector->con_priv = radeon_dig_connector;
2238 if (i2c_bus->valid) {
2239 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2240 if (radeon_connector->ddc_bus) {
2242 ddc = &radeon_connector->ddc_bus->adapter;
2244 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2247 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2248 &radeon_dp_connector_funcs,
2251 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2252 subpixel_order = SubPixelHorizontalRGB;
2253 drm_object_attach_property(&radeon_connector->base.base,
2254 rdev->mode_info.coherent_mode_property,
2256 if (ASIC_IS_AVIVO(rdev)) {
2257 drm_object_attach_property(&radeon_connector->base.base,
2258 rdev->mode_info.underscan_property,
2260 drm_object_attach_property(&radeon_connector->base.base,
2261 rdev->mode_info.underscan_hborder_property,
2263 drm_object_attach_property(&radeon_connector->base.base,
2264 rdev->mode_info.underscan_vborder_property,
2266 drm_object_attach_property(&radeon_connector->base.base,
2267 rdev->mode_info.dither_property,
2268 RADEON_FMT_DITHER_DISABLE);
2269 drm_object_attach_property(&radeon_connector->base.base,
2270 dev->mode_config.scaling_mode_property,
2271 DRM_MODE_SCALE_NONE);
2273 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2274 drm_object_attach_property(&radeon_connector->base.base,
2275 rdev->mode_info.audio_property,
2277 radeon_connector->audio = RADEON_AUDIO_AUTO;
2279 if (ASIC_IS_DCE5(rdev))
2280 drm_object_attach_property(&radeon_connector->base.base,
2281 rdev->mode_info.output_csc_property,
2282 RADEON_OUTPUT_CSC_BYPASS);
2283 connector->interlace_allowed = true;
2284 /* in theory with a DP to VGA converter... */
2285 connector->doublescan_allowed = false;
2287 case DRM_MODE_CONNECTOR_eDP:
2288 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2289 if (!radeon_dig_connector)
2291 radeon_dig_connector->igp_lane_info = igp_lane_info;
2292 radeon_connector->con_priv = radeon_dig_connector;
2293 if (i2c_bus->valid) {
2294 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2295 if (radeon_connector->ddc_bus) {
2297 ddc = &radeon_connector->ddc_bus->adapter;
2299 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2302 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2303 &radeon_edp_connector_funcs,
2306 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2307 drm_object_attach_property(&radeon_connector->base.base,
2308 dev->mode_config.scaling_mode_property,
2309 DRM_MODE_SCALE_FULLSCREEN);
2310 subpixel_order = SubPixelHorizontalRGB;
2311 connector->interlace_allowed = false;
2312 connector->doublescan_allowed = false;
2314 case DRM_MODE_CONNECTOR_SVIDEO:
2315 case DRM_MODE_CONNECTOR_Composite:
2316 case DRM_MODE_CONNECTOR_9PinDIN:
2317 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2318 &radeon_tv_connector_funcs,
2321 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2322 radeon_connector->dac_load_detect = true;
2323 drm_object_attach_property(&radeon_connector->base.base,
2324 rdev->mode_info.load_detect_property,
2326 drm_object_attach_property(&radeon_connector->base.base,
2327 rdev->mode_info.tv_std_property,
2328 radeon_atombios_get_tv_info(rdev));
2329 /* no HPD on analog connectors */
2330 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2331 connector->interlace_allowed = false;
2332 connector->doublescan_allowed = false;
2334 case DRM_MODE_CONNECTOR_LVDS:
2335 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2336 if (!radeon_dig_connector)
2338 radeon_dig_connector->igp_lane_info = igp_lane_info;
2339 radeon_connector->con_priv = radeon_dig_connector;
2340 if (i2c_bus->valid) {
2341 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2342 if (!radeon_connector->ddc_bus)
2343 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2345 ddc = &radeon_connector->ddc_bus->adapter;
2347 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2348 &radeon_lvds_connector_funcs,
2351 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2352 drm_object_attach_property(&radeon_connector->base.base,
2353 dev->mode_config.scaling_mode_property,
2354 DRM_MODE_SCALE_FULLSCREEN);
2355 subpixel_order = SubPixelHorizontalRGB;
2356 connector->interlace_allowed = false;
2357 connector->doublescan_allowed = false;
2362 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
2363 if (i2c_bus->valid) {
2364 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2365 DRM_CONNECTOR_POLL_DISCONNECT;
2368 connector->polled = DRM_CONNECTOR_POLL_HPD;
2370 connector->display_info.subpixel_order = subpixel_order;
2371 drm_connector_register(connector);
2374 radeon_dp_aux_init(radeon_connector);
2379 drm_connector_cleanup(connector);
2384 radeon_add_legacy_connector(struct drm_device *dev,
2385 uint32_t connector_id,
2386 uint32_t supported_device,
2388 struct radeon_i2c_bus_rec *i2c_bus,
2389 uint16_t connector_object_id,
2390 struct radeon_hpd *hpd)
2392 struct radeon_device *rdev = dev->dev_private;
2393 struct drm_connector *connector;
2394 struct radeon_connector *radeon_connector;
2395 struct i2c_adapter *ddc = NULL;
2396 uint32_t subpixel_order = SubPixelNone;
2398 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
2401 /* if the user selected tv=0 don't try and add the connector */
2402 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
2403 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
2404 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
2408 /* see if we already added it */
2409 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2410 radeon_connector = to_radeon_connector(connector);
2411 if (radeon_connector->connector_id == connector_id) {
2412 radeon_connector->devices |= supported_device;
2417 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
2418 if (!radeon_connector)
2421 connector = &radeon_connector->base;
2423 radeon_connector->connector_id = connector_id;
2424 radeon_connector->devices = supported_device;
2425 radeon_connector->connector_object_id = connector_object_id;
2426 radeon_connector->hpd = *hpd;
2428 switch (connector_type) {
2429 case DRM_MODE_CONNECTOR_VGA:
2430 if (i2c_bus->valid) {
2431 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2432 if (!radeon_connector->ddc_bus)
2433 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2435 ddc = &radeon_connector->ddc_bus->adapter;
2437 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2438 &radeon_vga_connector_funcs,
2441 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2442 radeon_connector->dac_load_detect = true;
2443 drm_object_attach_property(&radeon_connector->base.base,
2444 rdev->mode_info.load_detect_property,
2446 /* no HPD on analog connectors */
2447 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2448 connector->interlace_allowed = true;
2449 connector->doublescan_allowed = true;
2451 case DRM_MODE_CONNECTOR_DVIA:
2452 if (i2c_bus->valid) {
2453 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2454 if (!radeon_connector->ddc_bus)
2455 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2457 ddc = &radeon_connector->ddc_bus->adapter;
2459 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2460 &radeon_vga_connector_funcs,
2463 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2464 radeon_connector->dac_load_detect = true;
2465 drm_object_attach_property(&radeon_connector->base.base,
2466 rdev->mode_info.load_detect_property,
2468 /* no HPD on analog connectors */
2469 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2470 connector->interlace_allowed = true;
2471 connector->doublescan_allowed = true;
2473 case DRM_MODE_CONNECTOR_DVII:
2474 case DRM_MODE_CONNECTOR_DVID:
2475 if (i2c_bus->valid) {
2476 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2477 if (!radeon_connector->ddc_bus)
2478 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2480 ddc = &radeon_connector->ddc_bus->adapter;
2482 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2483 &radeon_dvi_connector_funcs,
2486 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2487 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2488 radeon_connector->dac_load_detect = true;
2489 drm_object_attach_property(&radeon_connector->base.base,
2490 rdev->mode_info.load_detect_property,
2493 subpixel_order = SubPixelHorizontalRGB;
2494 connector->interlace_allowed = true;
2495 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2496 connector->doublescan_allowed = true;
2498 connector->doublescan_allowed = false;
2500 case DRM_MODE_CONNECTOR_SVIDEO:
2501 case DRM_MODE_CONNECTOR_Composite:
2502 case DRM_MODE_CONNECTOR_9PinDIN:
2503 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2504 &radeon_tv_connector_funcs,
2507 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2508 radeon_connector->dac_load_detect = true;
2509 /* RS400,RC410,RS480 chipset seems to report a lot
2510 * of false positive on load detect, we haven't yet
2511 * found a way to make load detect reliable on those
2512 * chipset, thus just disable it for TV.
2514 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
2515 radeon_connector->dac_load_detect = false;
2516 drm_object_attach_property(&radeon_connector->base.base,
2517 rdev->mode_info.load_detect_property,
2518 radeon_connector->dac_load_detect);
2519 drm_object_attach_property(&radeon_connector->base.base,
2520 rdev->mode_info.tv_std_property,
2521 radeon_combios_get_tv_info(rdev));
2522 /* no HPD on analog connectors */
2523 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2524 connector->interlace_allowed = false;
2525 connector->doublescan_allowed = false;
2527 case DRM_MODE_CONNECTOR_LVDS:
2528 if (i2c_bus->valid) {
2529 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2530 if (!radeon_connector->ddc_bus)
2531 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2533 ddc = &radeon_connector->ddc_bus->adapter;
2535 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2536 &radeon_lvds_connector_funcs,
2539 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2540 drm_object_attach_property(&radeon_connector->base.base,
2541 dev->mode_config.scaling_mode_property,
2542 DRM_MODE_SCALE_FULLSCREEN);
2543 subpixel_order = SubPixelHorizontalRGB;
2544 connector->interlace_allowed = false;
2545 connector->doublescan_allowed = false;
2549 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
2550 if (i2c_bus->valid) {
2551 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2552 DRM_CONNECTOR_POLL_DISCONNECT;
2555 connector->polled = DRM_CONNECTOR_POLL_HPD;
2557 connector->display_info.subpixel_order = subpixel_order;
2558 drm_connector_register(connector);
2561 void radeon_setup_mst_connector(struct drm_device *dev)
2563 struct radeon_device *rdev = dev->dev_private;
2564 struct drm_connector *connector;
2565 struct radeon_connector *radeon_connector;
2567 if (!ASIC_IS_DCE5(rdev))
2570 if (radeon_mst == 0)
2573 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2574 radeon_connector = to_radeon_connector(connector);
2576 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
2579 radeon_dp_mst_init(radeon_connector);