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