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