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;
254 best_encoder = connector_funcs->best_encoder(connector);
256 drm_connector_for_each_possible_encoder(connector, encoder, i) {
257 if ((encoder == best_encoder) && (status == connector_status_connected))
262 if (rdev->is_atom_bios)
263 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
265 radeon_combios_connected_scratch_regs(connector, encoder, connected);
269 static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
271 struct drm_encoder *encoder;
274 drm_connector_for_each_possible_encoder(connector, encoder, i) {
275 if (encoder->encoder_type == encoder_type)
282 struct edid *radeon_connector_edid(struct drm_connector *connector)
284 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
285 struct drm_property_blob *edid_blob = connector->edid_blob_ptr;
287 if (radeon_connector->edid) {
288 return radeon_connector->edid;
289 } else if (edid_blob) {
290 struct edid *edid = kmemdup(edid_blob->data, edid_blob->length, GFP_KERNEL);
292 radeon_connector->edid = edid;
294 return radeon_connector->edid;
297 static void radeon_connector_get_edid(struct drm_connector *connector)
299 struct drm_device *dev = connector->dev;
300 struct radeon_device *rdev = dev->dev_private;
301 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
303 if (radeon_connector->edid)
306 /* on hw with routers, select right port */
307 if (radeon_connector->router.ddc_valid)
308 radeon_router_select_ddc_port(radeon_connector);
310 if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
311 ENCODER_OBJECT_ID_NONE) &&
312 radeon_connector->ddc_bus->has_aux) {
313 radeon_connector->edid = drm_get_edid(connector,
314 &radeon_connector->ddc_bus->aux.ddc);
315 } else if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
316 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
317 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
319 if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
320 dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) &&
321 radeon_connector->ddc_bus->has_aux)
322 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
323 &radeon_connector->ddc_bus->aux.ddc);
324 else if (radeon_connector->ddc_bus)
325 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
326 &radeon_connector->ddc_bus->adapter);
327 } else if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC &&
328 connector->connector_type == DRM_MODE_CONNECTOR_LVDS &&
329 radeon_connector->ddc_bus) {
330 radeon_connector->edid = drm_get_edid_switcheroo(&radeon_connector->base,
331 &radeon_connector->ddc_bus->adapter);
332 } else if (radeon_connector->ddc_bus) {
333 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
334 &radeon_connector->ddc_bus->adapter);
337 if (!radeon_connector->edid) {
338 /* don't fetch the edid from the vbios if ddc fails and runpm is
339 * enabled so we report disconnected.
341 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
344 if (rdev->is_atom_bios) {
345 /* some laptops provide a hardcoded edid in rom for LCDs */
346 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
347 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)))
348 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
350 /* some servers provide a hardcoded edid in rom for KVMs */
351 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
356 static void radeon_connector_free_edid(struct drm_connector *connector)
358 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
360 if (radeon_connector->edid) {
361 kfree(radeon_connector->edid);
362 radeon_connector->edid = NULL;
366 static int radeon_ddc_get_modes(struct drm_connector *connector)
368 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
371 if (radeon_connector->edid) {
372 drm_connector_update_edid_property(connector, radeon_connector->edid);
373 ret = drm_add_edid_modes(connector, radeon_connector->edid);
376 drm_connector_update_edid_property(connector, NULL);
380 static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
382 struct drm_encoder *encoder;
385 /* pick the first one */
386 drm_connector_for_each_possible_encoder(connector, encoder, i)
392 static void radeon_get_native_mode(struct drm_connector *connector)
394 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
395 struct radeon_encoder *radeon_encoder;
400 radeon_encoder = to_radeon_encoder(encoder);
402 if (!list_empty(&connector->probed_modes)) {
403 struct drm_display_mode *preferred_mode =
404 list_first_entry(&connector->probed_modes,
405 struct drm_display_mode, head);
407 radeon_encoder->native_mode = *preferred_mode;
409 radeon_encoder->native_mode.clock = 0;
414 * radeon_connector_analog_encoder_conflict_solve
415 * - search for other connectors sharing this encoder
416 * if priority is true, then set them disconnected if this is connected
417 * if priority is false, set us disconnected if they are connected
419 static enum drm_connector_status
420 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
421 struct drm_encoder *encoder,
422 enum drm_connector_status current_status,
425 struct drm_device *dev = connector->dev;
426 struct drm_connector *conflict;
427 struct radeon_connector *radeon_conflict;
429 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
430 struct drm_encoder *enc;
433 if (conflict == connector)
436 radeon_conflict = to_radeon_connector(conflict);
438 drm_connector_for_each_possible_encoder(conflict, enc, i) {
439 /* if the IDs match */
440 if (enc == encoder) {
441 if (conflict->status != connector_status_connected)
444 if (radeon_conflict->use_digital)
447 if (priority == true) {
448 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n",
450 DRM_DEBUG_KMS("in favor of %s\n",
452 conflict->status = connector_status_disconnected;
453 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
455 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n",
457 DRM_DEBUG_KMS("in favor of %s\n",
459 current_status = connector_status_disconnected;
465 return current_status;
469 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
471 struct drm_device *dev = encoder->dev;
472 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
473 struct drm_display_mode *mode = NULL;
474 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
476 if (native_mode->hdisplay != 0 &&
477 native_mode->vdisplay != 0 &&
478 native_mode->clock != 0) {
479 mode = drm_mode_duplicate(dev, native_mode);
480 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
481 drm_mode_set_name(mode);
483 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
484 } else if (native_mode->hdisplay != 0 &&
485 native_mode->vdisplay != 0) {
486 /* mac laptops without an edid */
487 /* Note that this is not necessarily the exact panel mode,
488 * but an approximation based on the cvt formula. For these
489 * systems we should ideally read the mode info out of the
490 * registers or add a mode table, but this works and is much
493 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
494 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
495 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
500 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
502 struct drm_device *dev = encoder->dev;
503 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
504 struct drm_display_mode *mode = NULL;
505 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
510 } common_modes[17] = {
530 for (i = 0; i < 17; i++) {
531 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
532 if (common_modes[i].w > 1024 ||
533 common_modes[i].h > 768)
536 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
537 if (common_modes[i].w > native_mode->hdisplay ||
538 common_modes[i].h > native_mode->vdisplay ||
539 (common_modes[i].w == native_mode->hdisplay &&
540 common_modes[i].h == native_mode->vdisplay))
543 if (common_modes[i].w < 320 || common_modes[i].h < 200)
546 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
547 drm_mode_probed_add(connector, mode);
551 static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
554 struct drm_device *dev = connector->dev;
555 struct radeon_device *rdev = dev->dev_private;
556 struct drm_encoder *encoder;
557 struct radeon_encoder *radeon_encoder;
559 if (property == rdev->mode_info.coherent_mode_property) {
560 struct radeon_encoder_atom_dig *dig;
561 bool new_coherent_mode;
563 /* need to find digital encoder on connector */
564 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
568 radeon_encoder = to_radeon_encoder(encoder);
570 if (!radeon_encoder->enc_priv)
573 dig = radeon_encoder->enc_priv;
574 new_coherent_mode = val ? true : false;
575 if (dig->coherent_mode != new_coherent_mode) {
576 dig->coherent_mode = new_coherent_mode;
577 radeon_property_change_mode(&radeon_encoder->base);
581 if (property == rdev->mode_info.audio_property) {
582 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
583 /* need to find digital encoder on connector */
584 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
588 radeon_encoder = to_radeon_encoder(encoder);
590 if (radeon_connector->audio != val) {
591 radeon_connector->audio = val;
592 radeon_property_change_mode(&radeon_encoder->base);
596 if (property == rdev->mode_info.dither_property) {
597 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
598 /* need to find digital encoder on connector */
599 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
603 radeon_encoder = to_radeon_encoder(encoder);
605 if (radeon_connector->dither != val) {
606 radeon_connector->dither = val;
607 radeon_property_change_mode(&radeon_encoder->base);
611 if (property == rdev->mode_info.underscan_property) {
612 /* need to find digital encoder on connector */
613 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
617 radeon_encoder = to_radeon_encoder(encoder);
619 if (radeon_encoder->underscan_type != val) {
620 radeon_encoder->underscan_type = val;
621 radeon_property_change_mode(&radeon_encoder->base);
625 if (property == rdev->mode_info.underscan_hborder_property) {
626 /* need to find digital encoder on connector */
627 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
631 radeon_encoder = to_radeon_encoder(encoder);
633 if (radeon_encoder->underscan_hborder != val) {
634 radeon_encoder->underscan_hborder = val;
635 radeon_property_change_mode(&radeon_encoder->base);
639 if (property == rdev->mode_info.underscan_vborder_property) {
640 /* need to find digital encoder on connector */
641 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
645 radeon_encoder = to_radeon_encoder(encoder);
647 if (radeon_encoder->underscan_vborder != val) {
648 radeon_encoder->underscan_vborder = val;
649 radeon_property_change_mode(&radeon_encoder->base);
653 if (property == rdev->mode_info.tv_std_property) {
654 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
656 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
662 radeon_encoder = to_radeon_encoder(encoder);
663 if (!radeon_encoder->enc_priv)
665 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
666 struct radeon_encoder_atom_dac *dac_int;
667 dac_int = radeon_encoder->enc_priv;
668 dac_int->tv_std = val;
670 struct radeon_encoder_tv_dac *dac_int;
671 dac_int = radeon_encoder->enc_priv;
672 dac_int->tv_std = val;
674 radeon_property_change_mode(&radeon_encoder->base);
677 if (property == rdev->mode_info.load_detect_property) {
678 struct radeon_connector *radeon_connector =
679 to_radeon_connector(connector);
682 radeon_connector->dac_load_detect = false;
684 radeon_connector->dac_load_detect = true;
687 if (property == rdev->mode_info.tmds_pll_property) {
688 struct radeon_encoder_int_tmds *tmds = NULL;
690 /* need to find digital encoder on connector */
691 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
695 radeon_encoder = to_radeon_encoder(encoder);
697 tmds = radeon_encoder->enc_priv;
702 if (rdev->is_atom_bios)
703 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
705 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
707 if (val == 1 || ret == false) {
708 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
710 radeon_property_change_mode(&radeon_encoder->base);
713 if (property == dev->mode_config.scaling_mode_property) {
714 enum radeon_rmx_type rmx_type;
716 if (connector->encoder)
717 radeon_encoder = to_radeon_encoder(connector->encoder);
719 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
720 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
725 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
726 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
727 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
728 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
730 if (radeon_encoder->rmx_type == rmx_type)
733 if ((rmx_type != DRM_MODE_SCALE_NONE) &&
734 (radeon_encoder->native_mode.clock == 0))
737 radeon_encoder->rmx_type = rmx_type;
739 radeon_property_change_mode(&radeon_encoder->base);
742 if (property == rdev->mode_info.output_csc_property) {
743 if (connector->encoder)
744 radeon_encoder = to_radeon_encoder(connector->encoder);
746 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
747 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
750 if (radeon_encoder->output_csc == val)
753 radeon_encoder->output_csc = val;
755 if (connector->encoder && connector->encoder->crtc) {
756 struct drm_crtc *crtc = connector->encoder->crtc;
757 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
759 radeon_crtc->output_csc = radeon_encoder->output_csc;
762 * Our .gamma_set assumes the .gamma_store has been
763 * prefilled and don't care about its arguments.
765 crtc->funcs->gamma_set(crtc, NULL, NULL, NULL, 0, NULL);
772 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
773 struct drm_connector *connector)
775 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
776 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
777 struct drm_display_mode *t, *mode;
779 /* If the EDID preferred mode doesn't match the native mode, use it */
780 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
781 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
782 if (mode->hdisplay != native_mode->hdisplay ||
783 mode->vdisplay != native_mode->vdisplay)
784 memcpy(native_mode, mode, sizeof(*mode));
788 /* Try to get native mode details from EDID if necessary */
789 if (!native_mode->clock) {
790 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
791 if (mode->hdisplay == native_mode->hdisplay &&
792 mode->vdisplay == native_mode->vdisplay) {
793 *native_mode = *mode;
794 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
795 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
801 if (!native_mode->clock) {
802 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
803 radeon_encoder->rmx_type = RMX_OFF;
807 static int radeon_lvds_get_modes(struct drm_connector *connector)
809 struct drm_encoder *encoder;
811 struct drm_display_mode *mode;
813 radeon_connector_get_edid(connector);
814 ret = radeon_ddc_get_modes(connector);
816 encoder = radeon_best_single_encoder(connector);
818 radeon_fixup_lvds_native_mode(encoder, connector);
819 /* add scaled modes */
820 radeon_add_common_modes(encoder, connector);
825 encoder = radeon_best_single_encoder(connector);
829 /* we have no EDID modes */
830 mode = radeon_fp_native_mode(encoder);
833 drm_mode_probed_add(connector, mode);
834 /* add the width/height from vbios tables if available */
835 connector->display_info.width_mm = mode->width_mm;
836 connector->display_info.height_mm = mode->height_mm;
837 /* add scaled modes */
838 radeon_add_common_modes(encoder, connector);
844 static enum drm_mode_status radeon_lvds_mode_valid(struct drm_connector *connector,
845 struct drm_display_mode *mode)
847 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
849 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
853 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
854 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
856 /* AVIVO hardware supports downscaling modes larger than the panel
857 * to the panel size, but I'm not sure this is desirable.
859 if ((mode->hdisplay > native_mode->hdisplay) ||
860 (mode->vdisplay > native_mode->vdisplay))
863 /* if scaling is disabled, block non-native modes */
864 if (radeon_encoder->rmx_type == RMX_OFF) {
865 if ((mode->hdisplay != native_mode->hdisplay) ||
866 (mode->vdisplay != native_mode->vdisplay))
874 static enum drm_connector_status
875 radeon_lvds_detect(struct drm_connector *connector, bool force)
877 struct drm_device *dev = connector->dev;
878 struct radeon_device *rdev = dev->dev_private;
879 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
880 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
881 enum drm_connector_status ret = connector_status_disconnected;
884 if (!drm_kms_helper_is_poll_worker()) {
885 r = pm_runtime_get_sync(connector->dev->dev);
887 return connector_status_disconnected;
891 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
892 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
894 /* check if panel is valid */
895 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
896 ret = connector_status_connected;
897 /* don't fetch the edid from the vbios if ddc fails and runpm is
898 * enabled so we report disconnected.
900 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
901 ret = connector_status_disconnected;
904 /* check for edid as well */
905 radeon_connector_get_edid(connector);
906 if (radeon_connector->edid)
907 ret = connector_status_connected;
908 /* check acpi lid status ??? */
910 radeon_connector_update_scratch_regs(connector, ret);
912 if (!drm_kms_helper_is_poll_worker()) {
913 pm_runtime_mark_last_busy(connector->dev->dev);
914 pm_runtime_put_autosuspend(connector->dev->dev);
920 static void radeon_connector_unregister(struct drm_connector *connector)
922 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
924 if (radeon_connector->ddc_bus && radeon_connector->ddc_bus->has_aux) {
925 drm_dp_aux_unregister(&radeon_connector->ddc_bus->aux);
926 radeon_connector->ddc_bus->has_aux = false;
930 static void radeon_connector_destroy(struct drm_connector *connector)
932 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
934 radeon_connector_free_edid(connector);
935 kfree(radeon_connector->con_priv);
936 drm_connector_unregister(connector);
937 drm_connector_cleanup(connector);
941 static int radeon_lvds_set_property(struct drm_connector *connector,
942 struct drm_property *property,
945 struct drm_device *dev = connector->dev;
946 struct radeon_encoder *radeon_encoder;
947 enum radeon_rmx_type rmx_type;
950 if (property != dev->mode_config.scaling_mode_property)
953 if (connector->encoder)
954 radeon_encoder = to_radeon_encoder(connector->encoder);
956 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
957 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
961 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
962 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
963 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
965 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
967 if (radeon_encoder->rmx_type == rmx_type)
970 radeon_encoder->rmx_type = rmx_type;
972 radeon_property_change_mode(&radeon_encoder->base);
977 static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
978 .get_modes = radeon_lvds_get_modes,
979 .mode_valid = radeon_lvds_mode_valid,
980 .best_encoder = radeon_best_single_encoder,
983 static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
984 .dpms = drm_helper_connector_dpms,
985 .detect = radeon_lvds_detect,
986 .fill_modes = drm_helper_probe_single_connector_modes,
987 .early_unregister = radeon_connector_unregister,
988 .destroy = radeon_connector_destroy,
989 .set_property = radeon_lvds_set_property,
992 static int radeon_vga_get_modes(struct drm_connector *connector)
996 radeon_connector_get_edid(connector);
997 ret = radeon_ddc_get_modes(connector);
999 radeon_get_native_mode(connector);
1004 static enum drm_mode_status radeon_vga_mode_valid(struct drm_connector *connector,
1005 struct drm_display_mode *mode)
1007 struct drm_device *dev = connector->dev;
1008 struct radeon_device *rdev = dev->dev_private;
1010 /* XXX check mode bandwidth */
1012 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1013 return MODE_CLOCK_HIGH;
1018 static enum drm_connector_status
1019 radeon_vga_detect(struct drm_connector *connector, bool force)
1021 struct drm_device *dev = connector->dev;
1022 struct radeon_device *rdev = dev->dev_private;
1023 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1024 struct drm_encoder *encoder;
1025 const struct drm_encoder_helper_funcs *encoder_funcs;
1027 enum drm_connector_status ret = connector_status_disconnected;
1030 if (!drm_kms_helper_is_poll_worker()) {
1031 r = pm_runtime_get_sync(connector->dev->dev);
1033 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 return connector_status_disconnected;
1174 encoder = radeon_best_single_encoder(connector);
1176 ret = connector_status_disconnected;
1178 encoder_funcs = encoder->helper_private;
1179 ret = encoder_funcs->detect(encoder, connector);
1181 if (ret == connector_status_connected)
1182 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
1183 radeon_connector_update_scratch_regs(connector, ret);
1185 if (!drm_kms_helper_is_poll_worker()) {
1186 pm_runtime_mark_last_busy(connector->dev->dev);
1187 pm_runtime_put_autosuspend(connector->dev->dev);
1193 static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
1194 .get_modes = radeon_tv_get_modes,
1195 .mode_valid = radeon_tv_mode_valid,
1196 .best_encoder = radeon_best_single_encoder,
1199 static const struct drm_connector_funcs radeon_tv_connector_funcs = {
1200 .dpms = drm_helper_connector_dpms,
1201 .detect = radeon_tv_detect,
1202 .fill_modes = drm_helper_probe_single_connector_modes,
1203 .early_unregister = radeon_connector_unregister,
1204 .destroy = radeon_connector_destroy,
1205 .set_property = radeon_connector_set_property,
1208 static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector)
1210 struct drm_device *dev = connector->dev;
1211 struct radeon_device *rdev = dev->dev_private;
1212 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1213 enum drm_connector_status status;
1215 /* We only trust HPD on R600 and newer ASICS. */
1216 if (rdev->family >= CHIP_R600
1217 && radeon_connector->hpd.hpd != RADEON_HPD_NONE) {
1218 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
1219 status = connector_status_connected;
1221 status = connector_status_disconnected;
1222 if (connector->status == status)
1230 * DVI is complicated
1231 * Do a DDC probe, if DDC probe passes, get the full EDID so
1232 * we can do analog/digital monitor detection at this point.
1233 * If the monitor is an analog monitor or we got no DDC,
1234 * we need to find the DAC encoder object for this connector.
1235 * If we got no DDC, we do load detection on the DAC encoder object.
1236 * If we got analog DDC or load detection passes on the DAC encoder
1237 * we have to check if this analog encoder is shared with anyone else (TV)
1238 * if its shared we have to set the other connector to disconnected.
1240 static enum drm_connector_status
1241 radeon_dvi_detect(struct drm_connector *connector, bool force)
1243 struct drm_device *dev = connector->dev;
1244 struct radeon_device *rdev = dev->dev_private;
1245 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1246 struct drm_encoder *encoder = NULL;
1247 const struct drm_encoder_helper_funcs *encoder_funcs;
1249 enum drm_connector_status ret = connector_status_disconnected;
1250 bool dret = false, broken_edid = false;
1252 if (!drm_kms_helper_is_poll_worker()) {
1253 r = pm_runtime_get_sync(connector->dev->dev);
1255 return connector_status_disconnected;
1258 if (radeon_connector->detected_hpd_without_ddc) {
1260 radeon_connector->detected_hpd_without_ddc = false;
1263 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1264 ret = connector->status;
1268 if (radeon_connector->ddc_bus) {
1269 dret = radeon_ddc_probe(radeon_connector, false);
1271 /* Sometimes the pins required for the DDC probe on DVI
1272 * connectors don't make contact at the same time that the ones
1273 * for HPD do. If the DDC probe fails even though we had an HPD
1274 * signal, try again later */
1275 if (!dret && !force &&
1276 connector->status != connector_status_connected) {
1277 DRM_DEBUG_KMS("hpd detected without ddc, retrying in 1 second\n");
1278 radeon_connector->detected_hpd_without_ddc = true;
1279 schedule_delayed_work(&rdev->hotplug_work,
1280 msecs_to_jiffies(1000));
1285 radeon_connector->detected_by_load = false;
1286 radeon_connector_free_edid(connector);
1287 radeon_connector_get_edid(connector);
1289 if (!radeon_connector->edid) {
1290 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1292 /* rs690 seems to have a problem with connectors not existing and always
1293 * return a block of 0's. If we see this just stop polling on this output */
1294 if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) &&
1295 radeon_connector->base.null_edid_counter) {
1296 ret = connector_status_disconnected;
1297 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n",
1299 radeon_connector->ddc_bus = NULL;
1301 ret = connector_status_connected;
1302 broken_edid = true; /* defer use_digital to later */
1305 radeon_connector->use_digital =
1306 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
1308 /* some oems have boards with separate digital and analog connectors
1309 * with a shared ddc line (often vga + hdmi)
1311 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
1312 radeon_connector_free_edid(connector);
1313 ret = connector_status_disconnected;
1315 ret = connector_status_connected;
1317 /* This gets complicated. We have boards with VGA + HDMI with a
1318 * shared DDC line and we have boards with DVI-D + HDMI with a shared
1319 * DDC line. The latter is more complex because with DVI<->HDMI adapters
1320 * you don't really know what's connected to which port as both are digital.
1322 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
1323 struct drm_connector *list_connector;
1324 struct radeon_connector *list_radeon_connector;
1325 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
1326 if (connector == list_connector)
1328 list_radeon_connector = to_radeon_connector(list_connector);
1329 if (list_radeon_connector->shared_ddc &&
1330 (list_radeon_connector->ddc_bus->rec.i2c_id ==
1331 radeon_connector->ddc_bus->rec.i2c_id)) {
1332 /* cases where both connectors are digital */
1333 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
1334 /* hpd is our only option in this case */
1335 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1336 radeon_connector_free_edid(connector);
1337 ret = connector_status_disconnected;
1346 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
1349 /* DVI-D and HDMI-A are digital only */
1350 if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
1351 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
1354 /* if we aren't forcing don't do destructive polling */
1356 /* only return the previous status if we last
1357 * detected a monitor via load.
1359 if (radeon_connector->detected_by_load)
1360 ret = connector->status;
1364 /* find analog encoder */
1365 if (radeon_connector->dac_load_detect) {
1368 drm_connector_for_each_possible_encoder(connector, encoder, i) {
1369 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
1370 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
1373 encoder_funcs = encoder->helper_private;
1374 if (encoder_funcs->detect) {
1376 if (ret != connector_status_connected) {
1377 /* deal with analog monitors without DDC */
1378 ret = encoder_funcs->detect(encoder, connector);
1379 if (ret == connector_status_connected) {
1380 radeon_connector->use_digital = false;
1382 if (ret != connector_status_disconnected)
1383 radeon_connector->detected_by_load = true;
1386 enum drm_connector_status lret;
1387 /* assume digital unless load detected otherwise */
1388 radeon_connector->use_digital = true;
1389 lret = encoder_funcs->detect(encoder, connector);
1390 DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
1391 if (lret == connector_status_connected)
1392 radeon_connector->use_digital = false;
1399 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
1401 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1404 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1405 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1406 * by other means, assume the DFP is connected and use that EDID. In most
1407 * cases the DVI port is actually a virtual KVM port connected to the service
1411 if ((!rdev->is_atom_bios) &&
1412 (ret == connector_status_disconnected) &&
1413 rdev->mode_info.bios_hardcoded_edid_size) {
1414 radeon_connector->use_digital = true;
1415 ret = connector_status_connected;
1418 /* updated in get modes as well since we need to know if it's analog or digital */
1419 radeon_connector_update_scratch_regs(connector, ret);
1421 if ((radeon_audio != 0) && radeon_connector->use_digital) {
1422 const struct drm_connector_helper_funcs *connector_funcs =
1423 connector->helper_private;
1425 encoder = connector_funcs->best_encoder(connector);
1426 if (encoder && (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)) {
1427 radeon_connector_get_edid(connector);
1428 radeon_audio_detect(connector, encoder, ret);
1433 if (!drm_kms_helper_is_poll_worker()) {
1434 pm_runtime_mark_last_busy(connector->dev->dev);
1435 pm_runtime_put_autosuspend(connector->dev->dev);
1441 /* okay need to be smart in here about which encoder to pick */
1442 static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
1444 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1445 struct drm_encoder *encoder;
1448 drm_connector_for_each_possible_encoder(connector, encoder, i) {
1449 if (radeon_connector->use_digital == true) {
1450 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
1453 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
1454 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
1459 /* see if we have a default encoder TODO */
1461 /* then check use digitial */
1462 /* pick the first one */
1463 drm_connector_for_each_possible_encoder(connector, encoder, i)
1469 static void radeon_dvi_force(struct drm_connector *connector)
1471 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1472 if (connector->force == DRM_FORCE_ON)
1473 radeon_connector->use_digital = false;
1474 if (connector->force == DRM_FORCE_ON_DIGITAL)
1475 radeon_connector->use_digital = true;
1478 static enum drm_mode_status radeon_dvi_mode_valid(struct drm_connector *connector,
1479 struct drm_display_mode *mode)
1481 struct drm_device *dev = connector->dev;
1482 struct radeon_device *rdev = dev->dev_private;
1483 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1485 /* XXX check mode bandwidth */
1487 /* clocks over 135 MHz have heat issues with DVI on RV100 */
1488 if (radeon_connector->use_digital &&
1489 (rdev->family == CHIP_RV100) &&
1490 (mode->clock > 135000))
1491 return MODE_CLOCK_HIGH;
1493 if (radeon_connector->use_digital && (mode->clock > 165000)) {
1494 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1495 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1496 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1498 else if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
1499 /* HDMI 1.3+ supports max clock of 340 Mhz */
1500 if (mode->clock > 340000)
1501 return MODE_CLOCK_HIGH;
1505 return MODE_CLOCK_HIGH;
1509 /* check against the max pixel clock */
1510 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1511 return MODE_CLOCK_HIGH;
1516 static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
1517 .get_modes = radeon_vga_get_modes,
1518 .mode_valid = radeon_dvi_mode_valid,
1519 .best_encoder = radeon_dvi_encoder,
1522 static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
1523 .dpms = drm_helper_connector_dpms,
1524 .detect = radeon_dvi_detect,
1525 .fill_modes = drm_helper_probe_single_connector_modes,
1526 .set_property = radeon_connector_set_property,
1527 .early_unregister = radeon_connector_unregister,
1528 .destroy = radeon_connector_destroy,
1529 .force = radeon_dvi_force,
1532 static int radeon_dp_get_modes(struct drm_connector *connector)
1534 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1535 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1536 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1539 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1540 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1541 struct drm_display_mode *mode;
1543 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1544 if (!radeon_dig_connector->edp_on)
1545 atombios_set_edp_panel_power(connector,
1546 ATOM_TRANSMITTER_ACTION_POWER_ON);
1547 radeon_connector_get_edid(connector);
1548 ret = radeon_ddc_get_modes(connector);
1549 if (!radeon_dig_connector->edp_on)
1550 atombios_set_edp_panel_power(connector,
1551 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1553 /* need to setup ddc on the bridge */
1554 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1555 ENCODER_OBJECT_ID_NONE) {
1557 radeon_atom_ext_encoder_setup_ddc(encoder);
1559 radeon_connector_get_edid(connector);
1560 ret = radeon_ddc_get_modes(connector);
1565 radeon_fixup_lvds_native_mode(encoder, connector);
1566 /* add scaled modes */
1567 radeon_add_common_modes(encoder, connector);
1575 /* we have no EDID modes */
1576 mode = radeon_fp_native_mode(encoder);
1579 drm_mode_probed_add(connector, mode);
1580 /* add the width/height from vbios tables if available */
1581 connector->display_info.width_mm = mode->width_mm;
1582 connector->display_info.height_mm = mode->height_mm;
1583 /* add scaled modes */
1584 radeon_add_common_modes(encoder, connector);
1587 /* need to setup ddc on the bridge */
1588 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1589 ENCODER_OBJECT_ID_NONE) {
1591 radeon_atom_ext_encoder_setup_ddc(encoder);
1593 radeon_connector_get_edid(connector);
1594 ret = radeon_ddc_get_modes(connector);
1596 radeon_get_native_mode(connector);
1602 u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
1604 struct drm_encoder *encoder;
1605 struct radeon_encoder *radeon_encoder;
1608 drm_connector_for_each_possible_encoder(connector, encoder, i) {
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;
1630 drm_connector_for_each_possible_encoder(connector, encoder, i) {
1631 radeon_encoder = to_radeon_encoder(encoder);
1632 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1639 bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1641 struct drm_device *dev = connector->dev;
1642 struct radeon_device *rdev = dev->dev_private;
1644 if (ASIC_IS_DCE5(rdev) &&
1645 (rdev->clock.default_dispclk >= 53900) &&
1646 radeon_connector_encoder_is_hbr2(connector)) {
1653 static enum drm_connector_status
1654 radeon_dp_detect(struct drm_connector *connector, bool force)
1656 struct drm_device *dev = connector->dev;
1657 struct radeon_device *rdev = dev->dev_private;
1658 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1659 enum drm_connector_status ret = connector_status_disconnected;
1660 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1661 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1664 if (radeon_dig_connector->is_mst)
1665 return connector_status_disconnected;
1667 if (!drm_kms_helper_is_poll_worker()) {
1668 r = pm_runtime_get_sync(connector->dev->dev);
1670 return connector_status_disconnected;
1673 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1674 ret = connector->status;
1678 radeon_connector_free_edid(connector);
1680 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1681 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1683 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1684 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1686 /* check if panel is valid */
1687 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1688 ret = connector_status_connected;
1689 /* don't fetch the edid from the vbios if ddc fails and runpm is
1690 * enabled so we report disconnected.
1692 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
1693 ret = connector_status_disconnected;
1695 /* eDP is always DP */
1696 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1697 if (!radeon_dig_connector->edp_on)
1698 atombios_set_edp_panel_power(connector,
1699 ATOM_TRANSMITTER_ACTION_POWER_ON);
1700 if (radeon_dp_getdpcd(radeon_connector))
1701 ret = connector_status_connected;
1702 if (!radeon_dig_connector->edp_on)
1703 atombios_set_edp_panel_power(connector,
1704 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1705 } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1706 ENCODER_OBJECT_ID_NONE) {
1707 /* DP bridges are always DP */
1708 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1709 /* get the DPCD from the bridge */
1710 radeon_dp_getdpcd(radeon_connector);
1713 /* setup ddc on the bridge */
1714 radeon_atom_ext_encoder_setup_ddc(encoder);
1715 /* bridge chips are always aux */
1716 if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */
1717 ret = connector_status_connected;
1718 else if (radeon_connector->dac_load_detect) { /* try load detection */
1719 const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
1720 ret = encoder_funcs->detect(encoder, connector);
1724 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
1725 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1726 ret = connector_status_connected;
1727 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1728 radeon_dp_getdpcd(radeon_connector);
1729 r = radeon_dp_mst_probe(radeon_connector);
1731 ret = connector_status_disconnected;
1734 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1735 if (radeon_dp_getdpcd(radeon_connector)) {
1736 r = radeon_dp_mst_probe(radeon_connector);
1738 ret = connector_status_disconnected;
1740 ret = connector_status_connected;
1743 /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
1744 if (radeon_ddc_probe(radeon_connector, false))
1745 ret = connector_status_connected;
1750 radeon_connector_update_scratch_regs(connector, ret);
1752 if ((radeon_audio != 0) && encoder) {
1753 radeon_connector_get_edid(connector);
1754 radeon_audio_detect(connector, encoder, ret);
1758 if (!drm_kms_helper_is_poll_worker()) {
1759 pm_runtime_mark_last_busy(connector->dev->dev);
1760 pm_runtime_put_autosuspend(connector->dev->dev);
1766 static enum drm_mode_status radeon_dp_mode_valid(struct drm_connector *connector,
1767 struct drm_display_mode *mode)
1769 struct drm_device *dev = connector->dev;
1770 struct radeon_device *rdev = dev->dev_private;
1771 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1772 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1774 /* XXX check mode bandwidth */
1776 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1777 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1778 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1780 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1784 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1785 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1787 /* AVIVO hardware supports downscaling modes larger than the panel
1788 * to the panel size, but I'm not sure this is desirable.
1790 if ((mode->hdisplay > native_mode->hdisplay) ||
1791 (mode->vdisplay > native_mode->vdisplay))
1794 /* if scaling is disabled, block non-native modes */
1795 if (radeon_encoder->rmx_type == RMX_OFF) {
1796 if ((mode->hdisplay != native_mode->hdisplay) ||
1797 (mode->vdisplay != native_mode->vdisplay))
1802 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1803 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
1804 return radeon_dp_mode_valid_helper(connector, mode);
1806 if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
1807 /* HDMI 1.3+ supports max clock of 340 Mhz */
1808 if (mode->clock > 340000)
1809 return MODE_CLOCK_HIGH;
1811 if (mode->clock > 165000)
1812 return MODE_CLOCK_HIGH;
1820 static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1821 .get_modes = radeon_dp_get_modes,
1822 .mode_valid = radeon_dp_mode_valid,
1823 .best_encoder = radeon_dvi_encoder,
1826 static const struct drm_connector_funcs radeon_dp_connector_funcs = {
1827 .dpms = drm_helper_connector_dpms,
1828 .detect = radeon_dp_detect,
1829 .fill_modes = drm_helper_probe_single_connector_modes,
1830 .set_property = radeon_connector_set_property,
1831 .early_unregister = radeon_connector_unregister,
1832 .destroy = radeon_connector_destroy,
1833 .force = radeon_dvi_force,
1836 static const struct drm_connector_funcs radeon_edp_connector_funcs = {
1837 .dpms = drm_helper_connector_dpms,
1838 .detect = radeon_dp_detect,
1839 .fill_modes = drm_helper_probe_single_connector_modes,
1840 .set_property = radeon_lvds_set_property,
1841 .early_unregister = radeon_connector_unregister,
1842 .destroy = radeon_connector_destroy,
1843 .force = radeon_dvi_force,
1846 static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
1847 .dpms = drm_helper_connector_dpms,
1848 .detect = radeon_dp_detect,
1849 .fill_modes = drm_helper_probe_single_connector_modes,
1850 .set_property = radeon_lvds_set_property,
1851 .early_unregister = radeon_connector_unregister,
1852 .destroy = radeon_connector_destroy,
1853 .force = radeon_dvi_force,
1857 radeon_add_atom_connector(struct drm_device *dev,
1858 uint32_t connector_id,
1859 uint32_t supported_device,
1861 struct radeon_i2c_bus_rec *i2c_bus,
1862 uint32_t igp_lane_info,
1863 uint16_t connector_object_id,
1864 struct radeon_hpd *hpd,
1865 struct radeon_router *router)
1867 struct radeon_device *rdev = dev->dev_private;
1868 struct drm_connector *connector;
1869 struct radeon_connector *radeon_connector;
1870 struct radeon_connector_atom_dig *radeon_dig_connector;
1871 struct drm_encoder *encoder;
1872 struct radeon_encoder *radeon_encoder;
1873 uint32_t subpixel_order = SubPixelNone;
1874 bool shared_ddc = false;
1875 bool is_dp_bridge = false;
1876 bool has_aux = false;
1878 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1881 /* if the user selected tv=0 don't try and add the connector */
1882 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1883 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1884 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1888 /* see if we already added it */
1889 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1890 radeon_connector = to_radeon_connector(connector);
1891 if (radeon_connector->connector_id == connector_id) {
1892 radeon_connector->devices |= supported_device;
1895 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1896 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1897 radeon_connector->shared_ddc = true;
1900 if (radeon_connector->router_bus && router->ddc_valid &&
1901 (radeon_connector->router.router_id == router->router_id)) {
1902 radeon_connector->shared_ddc = false;
1908 /* check if it's a dp bridge */
1909 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1910 radeon_encoder = to_radeon_encoder(encoder);
1911 if (radeon_encoder->devices & supported_device) {
1912 switch (radeon_encoder->encoder_id) {
1913 case ENCODER_OBJECT_ID_TRAVIS:
1914 case ENCODER_OBJECT_ID_NUTMEG:
1915 is_dp_bridge = true;
1923 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1924 if (!radeon_connector)
1927 connector = &radeon_connector->base;
1929 radeon_connector->connector_id = connector_id;
1930 radeon_connector->devices = supported_device;
1931 radeon_connector->shared_ddc = shared_ddc;
1932 radeon_connector->connector_object_id = connector_object_id;
1933 radeon_connector->hpd = *hpd;
1935 radeon_connector->router = *router;
1936 if (router->ddc_valid || router->cd_valid) {
1937 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1938 if (!radeon_connector->router_bus)
1939 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
1943 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1944 if (!radeon_dig_connector)
1946 radeon_dig_connector->igp_lane_info = igp_lane_info;
1947 radeon_connector->con_priv = radeon_dig_connector;
1948 if (i2c_bus->valid) {
1949 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1950 if (radeon_connector->ddc_bus)
1953 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1955 switch (connector_type) {
1956 case DRM_MODE_CONNECTOR_VGA:
1957 case DRM_MODE_CONNECTOR_DVIA:
1959 drm_connector_init(dev, &radeon_connector->base,
1960 &radeon_dp_connector_funcs, connector_type);
1961 drm_connector_helper_add(&radeon_connector->base,
1962 &radeon_dp_connector_helper_funcs);
1963 connector->interlace_allowed = true;
1964 connector->doublescan_allowed = true;
1965 radeon_connector->dac_load_detect = true;
1966 drm_object_attach_property(&radeon_connector->base.base,
1967 rdev->mode_info.load_detect_property,
1969 drm_object_attach_property(&radeon_connector->base.base,
1970 dev->mode_config.scaling_mode_property,
1971 DRM_MODE_SCALE_NONE);
1972 if (ASIC_IS_DCE5(rdev))
1973 drm_object_attach_property(&radeon_connector->base.base,
1974 rdev->mode_info.output_csc_property,
1975 RADEON_OUTPUT_CSC_BYPASS);
1977 case DRM_MODE_CONNECTOR_DVII:
1978 case DRM_MODE_CONNECTOR_DVID:
1979 case DRM_MODE_CONNECTOR_HDMIA:
1980 case DRM_MODE_CONNECTOR_HDMIB:
1981 case DRM_MODE_CONNECTOR_DisplayPort:
1982 drm_connector_init(dev, &radeon_connector->base,
1983 &radeon_dp_connector_funcs, connector_type);
1984 drm_connector_helper_add(&radeon_connector->base,
1985 &radeon_dp_connector_helper_funcs);
1986 drm_object_attach_property(&radeon_connector->base.base,
1987 rdev->mode_info.underscan_property,
1989 drm_object_attach_property(&radeon_connector->base.base,
1990 rdev->mode_info.underscan_hborder_property,
1992 drm_object_attach_property(&radeon_connector->base.base,
1993 rdev->mode_info.underscan_vborder_property,
1996 drm_object_attach_property(&radeon_connector->base.base,
1997 dev->mode_config.scaling_mode_property,
1998 DRM_MODE_SCALE_NONE);
2000 drm_object_attach_property(&radeon_connector->base.base,
2001 rdev->mode_info.dither_property,
2002 RADEON_FMT_DITHER_DISABLE);
2004 if (radeon_audio != 0) {
2005 drm_object_attach_property(&radeon_connector->base.base,
2006 rdev->mode_info.audio_property,
2008 radeon_connector->audio = RADEON_AUDIO_AUTO;
2010 if (ASIC_IS_DCE5(rdev))
2011 drm_object_attach_property(&radeon_connector->base.base,
2012 rdev->mode_info.output_csc_property,
2013 RADEON_OUTPUT_CSC_BYPASS);
2015 subpixel_order = SubPixelHorizontalRGB;
2016 connector->interlace_allowed = true;
2017 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
2018 connector->doublescan_allowed = true;
2020 connector->doublescan_allowed = false;
2021 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2022 radeon_connector->dac_load_detect = true;
2023 drm_object_attach_property(&radeon_connector->base.base,
2024 rdev->mode_info.load_detect_property,
2028 case DRM_MODE_CONNECTOR_LVDS:
2029 case DRM_MODE_CONNECTOR_eDP:
2030 drm_connector_init(dev, &radeon_connector->base,
2031 &radeon_lvds_bridge_connector_funcs, connector_type);
2032 drm_connector_helper_add(&radeon_connector->base,
2033 &radeon_dp_connector_helper_funcs);
2034 drm_object_attach_property(&radeon_connector->base.base,
2035 dev->mode_config.scaling_mode_property,
2036 DRM_MODE_SCALE_FULLSCREEN);
2037 subpixel_order = SubPixelHorizontalRGB;
2038 connector->interlace_allowed = false;
2039 connector->doublescan_allowed = false;
2043 switch (connector_type) {
2044 case DRM_MODE_CONNECTOR_VGA:
2045 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2046 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2047 if (i2c_bus->valid) {
2048 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2049 if (!radeon_connector->ddc_bus)
2050 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2052 radeon_connector->dac_load_detect = true;
2053 drm_object_attach_property(&radeon_connector->base.base,
2054 rdev->mode_info.load_detect_property,
2056 if (ASIC_IS_AVIVO(rdev))
2057 drm_object_attach_property(&radeon_connector->base.base,
2058 dev->mode_config.scaling_mode_property,
2059 DRM_MODE_SCALE_NONE);
2060 if (ASIC_IS_DCE5(rdev))
2061 drm_object_attach_property(&radeon_connector->base.base,
2062 rdev->mode_info.output_csc_property,
2063 RADEON_OUTPUT_CSC_BYPASS);
2064 /* no HPD on analog connectors */
2065 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2066 connector->interlace_allowed = true;
2067 connector->doublescan_allowed = true;
2069 case DRM_MODE_CONNECTOR_DVIA:
2070 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2071 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2072 if (i2c_bus->valid) {
2073 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2074 if (!radeon_connector->ddc_bus)
2075 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2077 radeon_connector->dac_load_detect = true;
2078 drm_object_attach_property(&radeon_connector->base.base,
2079 rdev->mode_info.load_detect_property,
2081 if (ASIC_IS_AVIVO(rdev))
2082 drm_object_attach_property(&radeon_connector->base.base,
2083 dev->mode_config.scaling_mode_property,
2084 DRM_MODE_SCALE_NONE);
2085 if (ASIC_IS_DCE5(rdev))
2086 drm_object_attach_property(&radeon_connector->base.base,
2087 rdev->mode_info.output_csc_property,
2088 RADEON_OUTPUT_CSC_BYPASS);
2089 /* no HPD on analog connectors */
2090 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2091 connector->interlace_allowed = true;
2092 connector->doublescan_allowed = true;
2094 case DRM_MODE_CONNECTOR_DVII:
2095 case DRM_MODE_CONNECTOR_DVID:
2096 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2097 if (!radeon_dig_connector)
2099 radeon_dig_connector->igp_lane_info = igp_lane_info;
2100 radeon_connector->con_priv = radeon_dig_connector;
2101 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
2102 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2103 if (i2c_bus->valid) {
2104 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2105 if (!radeon_connector->ddc_bus)
2106 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2108 subpixel_order = SubPixelHorizontalRGB;
2109 drm_object_attach_property(&radeon_connector->base.base,
2110 rdev->mode_info.coherent_mode_property,
2112 if (ASIC_IS_AVIVO(rdev)) {
2113 drm_object_attach_property(&radeon_connector->base.base,
2114 rdev->mode_info.underscan_property,
2116 drm_object_attach_property(&radeon_connector->base.base,
2117 rdev->mode_info.underscan_hborder_property,
2119 drm_object_attach_property(&radeon_connector->base.base,
2120 rdev->mode_info.underscan_vborder_property,
2122 drm_object_attach_property(&radeon_connector->base.base,
2123 rdev->mode_info.dither_property,
2124 RADEON_FMT_DITHER_DISABLE);
2125 drm_object_attach_property(&radeon_connector->base.base,
2126 dev->mode_config.scaling_mode_property,
2127 DRM_MODE_SCALE_NONE);
2129 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2130 drm_object_attach_property(&radeon_connector->base.base,
2131 rdev->mode_info.audio_property,
2133 radeon_connector->audio = RADEON_AUDIO_AUTO;
2135 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2136 radeon_connector->dac_load_detect = true;
2137 drm_object_attach_property(&radeon_connector->base.base,
2138 rdev->mode_info.load_detect_property,
2141 if (ASIC_IS_DCE5(rdev))
2142 drm_object_attach_property(&radeon_connector->base.base,
2143 rdev->mode_info.output_csc_property,
2144 RADEON_OUTPUT_CSC_BYPASS);
2145 connector->interlace_allowed = true;
2146 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2147 connector->doublescan_allowed = true;
2149 connector->doublescan_allowed = false;
2151 case DRM_MODE_CONNECTOR_HDMIA:
2152 case DRM_MODE_CONNECTOR_HDMIB:
2153 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2154 if (!radeon_dig_connector)
2156 radeon_dig_connector->igp_lane_info = igp_lane_info;
2157 radeon_connector->con_priv = radeon_dig_connector;
2158 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
2159 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2160 if (i2c_bus->valid) {
2161 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2162 if (!radeon_connector->ddc_bus)
2163 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2165 drm_object_attach_property(&radeon_connector->base.base,
2166 rdev->mode_info.coherent_mode_property,
2168 if (ASIC_IS_AVIVO(rdev)) {
2169 drm_object_attach_property(&radeon_connector->base.base,
2170 rdev->mode_info.underscan_property,
2172 drm_object_attach_property(&radeon_connector->base.base,
2173 rdev->mode_info.underscan_hborder_property,
2175 drm_object_attach_property(&radeon_connector->base.base,
2176 rdev->mode_info.underscan_vborder_property,
2178 drm_object_attach_property(&radeon_connector->base.base,
2179 rdev->mode_info.dither_property,
2180 RADEON_FMT_DITHER_DISABLE);
2181 drm_object_attach_property(&radeon_connector->base.base,
2182 dev->mode_config.scaling_mode_property,
2183 DRM_MODE_SCALE_NONE);
2185 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2186 drm_object_attach_property(&radeon_connector->base.base,
2187 rdev->mode_info.audio_property,
2189 radeon_connector->audio = RADEON_AUDIO_AUTO;
2191 if (ASIC_IS_DCE5(rdev))
2192 drm_object_attach_property(&radeon_connector->base.base,
2193 rdev->mode_info.output_csc_property,
2194 RADEON_OUTPUT_CSC_BYPASS);
2195 subpixel_order = SubPixelHorizontalRGB;
2196 connector->interlace_allowed = true;
2197 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
2198 connector->doublescan_allowed = true;
2200 connector->doublescan_allowed = false;
2202 case DRM_MODE_CONNECTOR_DisplayPort:
2203 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2204 if (!radeon_dig_connector)
2206 radeon_dig_connector->igp_lane_info = igp_lane_info;
2207 radeon_connector->con_priv = radeon_dig_connector;
2208 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
2209 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2210 if (i2c_bus->valid) {
2211 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2212 if (radeon_connector->ddc_bus)
2215 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2217 subpixel_order = SubPixelHorizontalRGB;
2218 drm_object_attach_property(&radeon_connector->base.base,
2219 rdev->mode_info.coherent_mode_property,
2221 if (ASIC_IS_AVIVO(rdev)) {
2222 drm_object_attach_property(&radeon_connector->base.base,
2223 rdev->mode_info.underscan_property,
2225 drm_object_attach_property(&radeon_connector->base.base,
2226 rdev->mode_info.underscan_hborder_property,
2228 drm_object_attach_property(&radeon_connector->base.base,
2229 rdev->mode_info.underscan_vborder_property,
2231 drm_object_attach_property(&radeon_connector->base.base,
2232 rdev->mode_info.dither_property,
2233 RADEON_FMT_DITHER_DISABLE);
2234 drm_object_attach_property(&radeon_connector->base.base,
2235 dev->mode_config.scaling_mode_property,
2236 DRM_MODE_SCALE_NONE);
2238 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2239 drm_object_attach_property(&radeon_connector->base.base,
2240 rdev->mode_info.audio_property,
2242 radeon_connector->audio = RADEON_AUDIO_AUTO;
2244 if (ASIC_IS_DCE5(rdev))
2245 drm_object_attach_property(&radeon_connector->base.base,
2246 rdev->mode_info.output_csc_property,
2247 RADEON_OUTPUT_CSC_BYPASS);
2248 connector->interlace_allowed = true;
2249 /* in theory with a DP to VGA converter... */
2250 connector->doublescan_allowed = false;
2252 case DRM_MODE_CONNECTOR_eDP:
2253 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2254 if (!radeon_dig_connector)
2256 radeon_dig_connector->igp_lane_info = igp_lane_info;
2257 radeon_connector->con_priv = radeon_dig_connector;
2258 drm_connector_init(dev, &radeon_connector->base, &radeon_edp_connector_funcs, connector_type);
2259 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2260 if (i2c_bus->valid) {
2261 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2262 if (radeon_connector->ddc_bus)
2265 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2267 drm_object_attach_property(&radeon_connector->base.base,
2268 dev->mode_config.scaling_mode_property,
2269 DRM_MODE_SCALE_FULLSCREEN);
2270 subpixel_order = SubPixelHorizontalRGB;
2271 connector->interlace_allowed = false;
2272 connector->doublescan_allowed = false;
2274 case DRM_MODE_CONNECTOR_SVIDEO:
2275 case DRM_MODE_CONNECTOR_Composite:
2276 case DRM_MODE_CONNECTOR_9PinDIN:
2277 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
2278 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2279 radeon_connector->dac_load_detect = true;
2280 drm_object_attach_property(&radeon_connector->base.base,
2281 rdev->mode_info.load_detect_property,
2283 drm_object_attach_property(&radeon_connector->base.base,
2284 rdev->mode_info.tv_std_property,
2285 radeon_atombios_get_tv_info(rdev));
2286 /* no HPD on analog connectors */
2287 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2288 connector->interlace_allowed = false;
2289 connector->doublescan_allowed = false;
2291 case DRM_MODE_CONNECTOR_LVDS:
2292 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2293 if (!radeon_dig_connector)
2295 radeon_dig_connector->igp_lane_info = igp_lane_info;
2296 radeon_connector->con_priv = radeon_dig_connector;
2297 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
2298 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2299 if (i2c_bus->valid) {
2300 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2301 if (!radeon_connector->ddc_bus)
2302 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2304 drm_object_attach_property(&radeon_connector->base.base,
2305 dev->mode_config.scaling_mode_property,
2306 DRM_MODE_SCALE_FULLSCREEN);
2307 subpixel_order = SubPixelHorizontalRGB;
2308 connector->interlace_allowed = false;
2309 connector->doublescan_allowed = false;
2314 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
2315 if (i2c_bus->valid) {
2316 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2317 DRM_CONNECTOR_POLL_DISCONNECT;
2320 connector->polled = DRM_CONNECTOR_POLL_HPD;
2322 connector->display_info.subpixel_order = subpixel_order;
2323 drm_connector_register(connector);
2326 radeon_dp_aux_init(radeon_connector);
2331 drm_connector_cleanup(connector);
2336 radeon_add_legacy_connector(struct drm_device *dev,
2337 uint32_t connector_id,
2338 uint32_t supported_device,
2340 struct radeon_i2c_bus_rec *i2c_bus,
2341 uint16_t connector_object_id,
2342 struct radeon_hpd *hpd)
2344 struct radeon_device *rdev = dev->dev_private;
2345 struct drm_connector *connector;
2346 struct radeon_connector *radeon_connector;
2347 uint32_t subpixel_order = SubPixelNone;
2349 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
2352 /* if the user selected tv=0 don't try and add the connector */
2353 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
2354 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
2355 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
2359 /* see if we already added it */
2360 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2361 radeon_connector = to_radeon_connector(connector);
2362 if (radeon_connector->connector_id == connector_id) {
2363 radeon_connector->devices |= supported_device;
2368 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
2369 if (!radeon_connector)
2372 connector = &radeon_connector->base;
2374 radeon_connector->connector_id = connector_id;
2375 radeon_connector->devices = supported_device;
2376 radeon_connector->connector_object_id = connector_object_id;
2377 radeon_connector->hpd = *hpd;
2379 switch (connector_type) {
2380 case DRM_MODE_CONNECTOR_VGA:
2381 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2382 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2383 if (i2c_bus->valid) {
2384 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2385 if (!radeon_connector->ddc_bus)
2386 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2388 radeon_connector->dac_load_detect = true;
2389 drm_object_attach_property(&radeon_connector->base.base,
2390 rdev->mode_info.load_detect_property,
2392 /* no HPD on analog connectors */
2393 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2394 connector->interlace_allowed = true;
2395 connector->doublescan_allowed = true;
2397 case DRM_MODE_CONNECTOR_DVIA:
2398 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2399 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2400 if (i2c_bus->valid) {
2401 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2402 if (!radeon_connector->ddc_bus)
2403 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2405 radeon_connector->dac_load_detect = true;
2406 drm_object_attach_property(&radeon_connector->base.base,
2407 rdev->mode_info.load_detect_property,
2409 /* no HPD on analog connectors */
2410 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2411 connector->interlace_allowed = true;
2412 connector->doublescan_allowed = true;
2414 case DRM_MODE_CONNECTOR_DVII:
2415 case DRM_MODE_CONNECTOR_DVID:
2416 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
2417 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2418 if (i2c_bus->valid) {
2419 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2420 if (!radeon_connector->ddc_bus)
2421 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2423 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2424 radeon_connector->dac_load_detect = true;
2425 drm_object_attach_property(&radeon_connector->base.base,
2426 rdev->mode_info.load_detect_property,
2429 subpixel_order = SubPixelHorizontalRGB;
2430 connector->interlace_allowed = true;
2431 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2432 connector->doublescan_allowed = true;
2434 connector->doublescan_allowed = false;
2436 case DRM_MODE_CONNECTOR_SVIDEO:
2437 case DRM_MODE_CONNECTOR_Composite:
2438 case DRM_MODE_CONNECTOR_9PinDIN:
2439 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
2440 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2441 radeon_connector->dac_load_detect = true;
2442 /* RS400,RC410,RS480 chipset seems to report a lot
2443 * of false positive on load detect, we haven't yet
2444 * found a way to make load detect reliable on those
2445 * chipset, thus just disable it for TV.
2447 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
2448 radeon_connector->dac_load_detect = false;
2449 drm_object_attach_property(&radeon_connector->base.base,
2450 rdev->mode_info.load_detect_property,
2451 radeon_connector->dac_load_detect);
2452 drm_object_attach_property(&radeon_connector->base.base,
2453 rdev->mode_info.tv_std_property,
2454 radeon_combios_get_tv_info(rdev));
2455 /* no HPD on analog connectors */
2456 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2457 connector->interlace_allowed = false;
2458 connector->doublescan_allowed = false;
2460 case DRM_MODE_CONNECTOR_LVDS:
2461 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
2462 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2463 if (i2c_bus->valid) {
2464 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2465 if (!radeon_connector->ddc_bus)
2466 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2468 drm_object_attach_property(&radeon_connector->base.base,
2469 dev->mode_config.scaling_mode_property,
2470 DRM_MODE_SCALE_FULLSCREEN);
2471 subpixel_order = SubPixelHorizontalRGB;
2472 connector->interlace_allowed = false;
2473 connector->doublescan_allowed = false;
2477 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
2478 if (i2c_bus->valid) {
2479 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2480 DRM_CONNECTOR_POLL_DISCONNECT;
2483 connector->polled = DRM_CONNECTOR_POLL_HPD;
2485 connector->display_info.subpixel_order = subpixel_order;
2486 drm_connector_register(connector);
2489 void radeon_setup_mst_connector(struct drm_device *dev)
2491 struct radeon_device *rdev = dev->dev_private;
2492 struct drm_connector *connector;
2493 struct radeon_connector *radeon_connector;
2495 if (!ASIC_IS_DCE5(rdev))
2498 if (radeon_mst == 0)
2501 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2504 radeon_connector = to_radeon_connector(connector);
2506 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
2509 ret = radeon_dp_mst_init(radeon_connector);