PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / gpu / drm / radeon / radeon_connectors.c
blob82d4f865546ed9024b4078d67bfdd947f08a1060
1 /*
2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 * Authors: Dave Airlie
24 * Alex Deucher
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/radeon_drm.h>
31 #include "radeon.h"
32 #include "atom.h"
34 #include <linux/pm_runtime.h>
36 void radeon_connector_hotplug(struct drm_connector *connector)
38 struct drm_device *dev = connector->dev;
39 struct radeon_device *rdev = dev->dev_private;
40 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
42 /* bail if the connector does not have hpd pin, e.g.,
43 * VGA, TV, etc.
45 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE)
46 return;
48 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
50 /* if the connector is already off, don't turn it back on */
51 if (connector->dpms != DRM_MODE_DPMS_ON)
52 return;
54 /* just deal with DP (not eDP) here. */
55 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
56 struct radeon_connector_atom_dig *dig_connector =
57 radeon_connector->con_priv;
59 /* if existing sink type was not DP no need to retrain */
60 if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT)
61 return;
63 /* first get sink type as it may be reset after (un)plug */
64 dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
65 /* don't do anything if sink is not display port, i.e.,
66 * passive dp->(dvi|hdmi) adaptor
68 if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
69 int saved_dpms = connector->dpms;
70 /* Only turn off the display if it's physically disconnected */
71 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
72 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
73 } else if (radeon_dp_needs_link_train(radeon_connector)) {
74 /* set it to OFF so that drm_helper_connector_dpms()
75 * won't return immediately since the current state
76 * is ON at this point.
78 connector->dpms = DRM_MODE_DPMS_OFF;
79 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
81 connector->dpms = saved_dpms;
86 static void radeon_property_change_mode(struct drm_encoder *encoder)
88 struct drm_crtc *crtc = encoder->crtc;
90 if (crtc && crtc->enabled) {
91 drm_crtc_helper_set_mode(crtc, &crtc->mode,
92 crtc->x, crtc->y, crtc->fb);
96 int radeon_get_monitor_bpc(struct drm_connector *connector)
98 struct drm_device *dev = connector->dev;
99 struct radeon_device *rdev = dev->dev_private;
100 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
101 struct radeon_connector_atom_dig *dig_connector;
102 int bpc = 8;
104 switch (connector->connector_type) {
105 case DRM_MODE_CONNECTOR_DVII:
106 case DRM_MODE_CONNECTOR_HDMIB:
107 if (radeon_connector->use_digital) {
108 if (drm_detect_hdmi_monitor(radeon_connector->edid)) {
109 if (connector->display_info.bpc)
110 bpc = connector->display_info.bpc;
113 break;
114 case DRM_MODE_CONNECTOR_DVID:
115 case DRM_MODE_CONNECTOR_HDMIA:
116 if (drm_detect_hdmi_monitor(radeon_connector->edid)) {
117 if (connector->display_info.bpc)
118 bpc = connector->display_info.bpc;
120 break;
121 case DRM_MODE_CONNECTOR_DisplayPort:
122 dig_connector = radeon_connector->con_priv;
123 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
124 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) ||
125 drm_detect_hdmi_monitor(radeon_connector->edid)) {
126 if (connector->display_info.bpc)
127 bpc = connector->display_info.bpc;
129 break;
130 case DRM_MODE_CONNECTOR_eDP:
131 case DRM_MODE_CONNECTOR_LVDS:
132 if (connector->display_info.bpc)
133 bpc = connector->display_info.bpc;
134 else if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
135 struct drm_connector_helper_funcs *connector_funcs =
136 connector->helper_private;
137 struct drm_encoder *encoder = connector_funcs->best_encoder(connector);
138 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
139 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
141 if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR)
142 bpc = 6;
143 else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR)
144 bpc = 8;
146 break;
148 return bpc;
151 static void
152 radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
154 struct drm_device *dev = connector->dev;
155 struct radeon_device *rdev = dev->dev_private;
156 struct drm_encoder *best_encoder = NULL;
157 struct drm_encoder *encoder = NULL;
158 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
159 struct drm_mode_object *obj;
160 bool connected;
161 int i;
163 best_encoder = connector_funcs->best_encoder(connector);
165 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
166 if (connector->encoder_ids[i] == 0)
167 break;
169 obj = drm_mode_object_find(connector->dev,
170 connector->encoder_ids[i],
171 DRM_MODE_OBJECT_ENCODER);
172 if (!obj)
173 continue;
175 encoder = obj_to_encoder(obj);
177 if ((encoder == best_encoder) && (status == connector_status_connected))
178 connected = true;
179 else
180 connected = false;
182 if (rdev->is_atom_bios)
183 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
184 else
185 radeon_combios_connected_scratch_regs(connector, encoder, connected);
190 static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
192 struct drm_mode_object *obj;
193 struct drm_encoder *encoder;
194 int i;
196 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
197 if (connector->encoder_ids[i] == 0)
198 break;
200 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
201 if (!obj)
202 continue;
204 encoder = obj_to_encoder(obj);
205 if (encoder->encoder_type == encoder_type)
206 return encoder;
208 return NULL;
211 static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
213 int enc_id = connector->encoder_ids[0];
214 struct drm_mode_object *obj;
215 struct drm_encoder *encoder;
217 /* pick the encoder ids */
218 if (enc_id) {
219 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
220 if (!obj)
221 return NULL;
222 encoder = obj_to_encoder(obj);
223 return encoder;
225 return NULL;
229 * radeon_connector_analog_encoder_conflict_solve
230 * - search for other connectors sharing this encoder
231 * if priority is true, then set them disconnected if this is connected
232 * if priority is false, set us disconnected if they are connected
234 static enum drm_connector_status
235 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
236 struct drm_encoder *encoder,
237 enum drm_connector_status current_status,
238 bool priority)
240 struct drm_device *dev = connector->dev;
241 struct drm_connector *conflict;
242 struct radeon_connector *radeon_conflict;
243 int i;
245 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
246 if (conflict == connector)
247 continue;
249 radeon_conflict = to_radeon_connector(conflict);
250 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
251 if (conflict->encoder_ids[i] == 0)
252 break;
254 /* if the IDs match */
255 if (conflict->encoder_ids[i] == encoder->base.id) {
256 if (conflict->status != connector_status_connected)
257 continue;
259 if (radeon_conflict->use_digital)
260 continue;
262 if (priority == true) {
263 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
264 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(connector));
265 conflict->status = connector_status_disconnected;
266 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
267 } else {
268 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
269 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(conflict));
270 current_status = connector_status_disconnected;
272 break;
276 return current_status;
280 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
282 struct drm_device *dev = encoder->dev;
283 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
284 struct drm_display_mode *mode = NULL;
285 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
287 if (native_mode->hdisplay != 0 &&
288 native_mode->vdisplay != 0 &&
289 native_mode->clock != 0) {
290 mode = drm_mode_duplicate(dev, native_mode);
291 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
292 drm_mode_set_name(mode);
294 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
295 } else if (native_mode->hdisplay != 0 &&
296 native_mode->vdisplay != 0) {
297 /* mac laptops without an edid */
298 /* Note that this is not necessarily the exact panel mode,
299 * but an approximation based on the cvt formula. For these
300 * systems we should ideally read the mode info out of the
301 * registers or add a mode table, but this works and is much
302 * simpler.
304 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
305 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
306 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
308 return mode;
311 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
313 struct drm_device *dev = encoder->dev;
314 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
315 struct drm_display_mode *mode = NULL;
316 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
317 int i;
318 struct mode_size {
319 int w;
320 int h;
321 } common_modes[17] = {
322 { 640, 480},
323 { 720, 480},
324 { 800, 600},
325 { 848, 480},
326 {1024, 768},
327 {1152, 768},
328 {1280, 720},
329 {1280, 800},
330 {1280, 854},
331 {1280, 960},
332 {1280, 1024},
333 {1440, 900},
334 {1400, 1050},
335 {1680, 1050},
336 {1600, 1200},
337 {1920, 1080},
338 {1920, 1200}
341 for (i = 0; i < 17; i++) {
342 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
343 if (common_modes[i].w > 1024 ||
344 common_modes[i].h > 768)
345 continue;
347 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
348 if (common_modes[i].w > native_mode->hdisplay ||
349 common_modes[i].h > native_mode->vdisplay ||
350 (common_modes[i].w == native_mode->hdisplay &&
351 common_modes[i].h == native_mode->vdisplay))
352 continue;
354 if (common_modes[i].w < 320 || common_modes[i].h < 200)
355 continue;
357 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
358 drm_mode_probed_add(connector, mode);
362 static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
363 uint64_t val)
365 struct drm_device *dev = connector->dev;
366 struct radeon_device *rdev = dev->dev_private;
367 struct drm_encoder *encoder;
368 struct radeon_encoder *radeon_encoder;
370 if (property == rdev->mode_info.coherent_mode_property) {
371 struct radeon_encoder_atom_dig *dig;
372 bool new_coherent_mode;
374 /* need to find digital encoder on connector */
375 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
376 if (!encoder)
377 return 0;
379 radeon_encoder = to_radeon_encoder(encoder);
381 if (!radeon_encoder->enc_priv)
382 return 0;
384 dig = radeon_encoder->enc_priv;
385 new_coherent_mode = val ? true : false;
386 if (dig->coherent_mode != new_coherent_mode) {
387 dig->coherent_mode = new_coherent_mode;
388 radeon_property_change_mode(&radeon_encoder->base);
392 if (property == rdev->mode_info.audio_property) {
393 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
394 /* need to find digital encoder on connector */
395 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
396 if (!encoder)
397 return 0;
399 radeon_encoder = to_radeon_encoder(encoder);
401 if (radeon_connector->audio != val) {
402 radeon_connector->audio = val;
403 radeon_property_change_mode(&radeon_encoder->base);
407 if (property == rdev->mode_info.dither_property) {
408 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
409 /* need to find digital encoder on connector */
410 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
411 if (!encoder)
412 return 0;
414 radeon_encoder = to_radeon_encoder(encoder);
416 if (radeon_connector->dither != val) {
417 radeon_connector->dither = val;
418 radeon_property_change_mode(&radeon_encoder->base);
422 if (property == rdev->mode_info.underscan_property) {
423 /* need to find digital encoder on connector */
424 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
425 if (!encoder)
426 return 0;
428 radeon_encoder = to_radeon_encoder(encoder);
430 if (radeon_encoder->underscan_type != val) {
431 radeon_encoder->underscan_type = val;
432 radeon_property_change_mode(&radeon_encoder->base);
436 if (property == rdev->mode_info.underscan_hborder_property) {
437 /* need to find digital encoder on connector */
438 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
439 if (!encoder)
440 return 0;
442 radeon_encoder = to_radeon_encoder(encoder);
444 if (radeon_encoder->underscan_hborder != val) {
445 radeon_encoder->underscan_hborder = val;
446 radeon_property_change_mode(&radeon_encoder->base);
450 if (property == rdev->mode_info.underscan_vborder_property) {
451 /* need to find digital encoder on connector */
452 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
453 if (!encoder)
454 return 0;
456 radeon_encoder = to_radeon_encoder(encoder);
458 if (radeon_encoder->underscan_vborder != val) {
459 radeon_encoder->underscan_vborder = val;
460 radeon_property_change_mode(&radeon_encoder->base);
464 if (property == rdev->mode_info.tv_std_property) {
465 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
466 if (!encoder) {
467 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
470 if (!encoder)
471 return 0;
473 radeon_encoder = to_radeon_encoder(encoder);
474 if (!radeon_encoder->enc_priv)
475 return 0;
476 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
477 struct radeon_encoder_atom_dac *dac_int;
478 dac_int = radeon_encoder->enc_priv;
479 dac_int->tv_std = val;
480 } else {
481 struct radeon_encoder_tv_dac *dac_int;
482 dac_int = radeon_encoder->enc_priv;
483 dac_int->tv_std = val;
485 radeon_property_change_mode(&radeon_encoder->base);
488 if (property == rdev->mode_info.load_detect_property) {
489 struct radeon_connector *radeon_connector =
490 to_radeon_connector(connector);
492 if (val == 0)
493 radeon_connector->dac_load_detect = false;
494 else
495 radeon_connector->dac_load_detect = true;
498 if (property == rdev->mode_info.tmds_pll_property) {
499 struct radeon_encoder_int_tmds *tmds = NULL;
500 bool ret = false;
501 /* need to find digital encoder on connector */
502 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
503 if (!encoder)
504 return 0;
506 radeon_encoder = to_radeon_encoder(encoder);
508 tmds = radeon_encoder->enc_priv;
509 if (!tmds)
510 return 0;
512 if (val == 0) {
513 if (rdev->is_atom_bios)
514 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
515 else
516 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
518 if (val == 1 || ret == false) {
519 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
521 radeon_property_change_mode(&radeon_encoder->base);
524 return 0;
527 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
528 struct drm_connector *connector)
530 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
531 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
532 struct drm_display_mode *t, *mode;
534 /* If the EDID preferred mode doesn't match the native mode, use it */
535 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
536 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
537 if (mode->hdisplay != native_mode->hdisplay ||
538 mode->vdisplay != native_mode->vdisplay)
539 memcpy(native_mode, mode, sizeof(*mode));
543 /* Try to get native mode details from EDID if necessary */
544 if (!native_mode->clock) {
545 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
546 if (mode->hdisplay == native_mode->hdisplay &&
547 mode->vdisplay == native_mode->vdisplay) {
548 *native_mode = *mode;
549 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
550 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
551 break;
556 if (!native_mode->clock) {
557 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
558 radeon_encoder->rmx_type = RMX_OFF;
562 static int radeon_lvds_get_modes(struct drm_connector *connector)
564 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
565 struct drm_encoder *encoder;
566 int ret = 0;
567 struct drm_display_mode *mode;
569 if (radeon_connector->ddc_bus) {
570 ret = radeon_ddc_get_modes(radeon_connector);
571 if (ret > 0) {
572 encoder = radeon_best_single_encoder(connector);
573 if (encoder) {
574 radeon_fixup_lvds_native_mode(encoder, connector);
575 /* add scaled modes */
576 radeon_add_common_modes(encoder, connector);
578 return ret;
582 encoder = radeon_best_single_encoder(connector);
583 if (!encoder)
584 return 0;
586 /* we have no EDID modes */
587 mode = radeon_fp_native_mode(encoder);
588 if (mode) {
589 ret = 1;
590 drm_mode_probed_add(connector, mode);
591 /* add the width/height from vbios tables if available */
592 connector->display_info.width_mm = mode->width_mm;
593 connector->display_info.height_mm = mode->height_mm;
594 /* add scaled modes */
595 radeon_add_common_modes(encoder, connector);
598 return ret;
601 static int radeon_lvds_mode_valid(struct drm_connector *connector,
602 struct drm_display_mode *mode)
604 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
606 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
607 return MODE_PANEL;
609 if (encoder) {
610 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
611 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
613 /* AVIVO hardware supports downscaling modes larger than the panel
614 * to the panel size, but I'm not sure this is desirable.
616 if ((mode->hdisplay > native_mode->hdisplay) ||
617 (mode->vdisplay > native_mode->vdisplay))
618 return MODE_PANEL;
620 /* if scaling is disabled, block non-native modes */
621 if (radeon_encoder->rmx_type == RMX_OFF) {
622 if ((mode->hdisplay != native_mode->hdisplay) ||
623 (mode->vdisplay != native_mode->vdisplay))
624 return MODE_PANEL;
628 return MODE_OK;
631 static enum drm_connector_status
632 radeon_lvds_detect(struct drm_connector *connector, bool force)
634 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
635 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
636 enum drm_connector_status ret = connector_status_disconnected;
637 int r;
639 r = pm_runtime_get_sync(connector->dev->dev);
640 if (r < 0)
641 return connector_status_disconnected;
643 if (encoder) {
644 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
645 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
647 /* check if panel is valid */
648 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
649 ret = connector_status_connected;
653 /* check for edid as well */
654 if (radeon_connector->edid)
655 ret = connector_status_connected;
656 else {
657 if (radeon_connector->ddc_bus) {
658 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
659 &radeon_connector->ddc_bus->adapter);
660 if (radeon_connector->edid)
661 ret = connector_status_connected;
664 /* check acpi lid status ??? */
666 radeon_connector_update_scratch_regs(connector, ret);
667 pm_runtime_mark_last_busy(connector->dev->dev);
668 pm_runtime_put_autosuspend(connector->dev->dev);
669 return ret;
672 static void radeon_connector_destroy(struct drm_connector *connector)
674 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
676 if (radeon_connector->edid)
677 kfree(radeon_connector->edid);
678 kfree(radeon_connector->con_priv);
679 drm_sysfs_connector_remove(connector);
680 drm_connector_cleanup(connector);
681 kfree(connector);
684 static int radeon_lvds_set_property(struct drm_connector *connector,
685 struct drm_property *property,
686 uint64_t value)
688 struct drm_device *dev = connector->dev;
689 struct radeon_encoder *radeon_encoder;
690 enum radeon_rmx_type rmx_type;
692 DRM_DEBUG_KMS("\n");
693 if (property != dev->mode_config.scaling_mode_property)
694 return 0;
696 if (connector->encoder)
697 radeon_encoder = to_radeon_encoder(connector->encoder);
698 else {
699 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
700 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
703 switch (value) {
704 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
705 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
706 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
707 default:
708 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
710 if (radeon_encoder->rmx_type == rmx_type)
711 return 0;
713 radeon_encoder->rmx_type = rmx_type;
715 radeon_property_change_mode(&radeon_encoder->base);
716 return 0;
720 static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
721 .get_modes = radeon_lvds_get_modes,
722 .mode_valid = radeon_lvds_mode_valid,
723 .best_encoder = radeon_best_single_encoder,
726 static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
727 .dpms = drm_helper_connector_dpms,
728 .detect = radeon_lvds_detect,
729 .fill_modes = drm_helper_probe_single_connector_modes,
730 .destroy = radeon_connector_destroy,
731 .set_property = radeon_lvds_set_property,
734 static int radeon_vga_get_modes(struct drm_connector *connector)
736 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
737 int ret;
739 ret = radeon_ddc_get_modes(radeon_connector);
741 return ret;
744 static int radeon_vga_mode_valid(struct drm_connector *connector,
745 struct drm_display_mode *mode)
747 struct drm_device *dev = connector->dev;
748 struct radeon_device *rdev = dev->dev_private;
750 /* XXX check mode bandwidth */
752 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
753 return MODE_CLOCK_HIGH;
755 return MODE_OK;
758 static enum drm_connector_status
759 radeon_vga_detect(struct drm_connector *connector, bool force)
761 struct drm_device *dev = connector->dev;
762 struct radeon_device *rdev = dev->dev_private;
763 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
764 struct drm_encoder *encoder;
765 struct drm_encoder_helper_funcs *encoder_funcs;
766 bool dret = false;
767 enum drm_connector_status ret = connector_status_disconnected;
768 int r;
770 r = pm_runtime_get_sync(connector->dev->dev);
771 if (r < 0)
772 return connector_status_disconnected;
774 encoder = radeon_best_single_encoder(connector);
775 if (!encoder)
776 ret = connector_status_disconnected;
778 if (radeon_connector->ddc_bus)
779 dret = radeon_ddc_probe(radeon_connector, false);
780 if (dret) {
781 radeon_connector->detected_by_load = false;
782 if (radeon_connector->edid) {
783 kfree(radeon_connector->edid);
784 radeon_connector->edid = NULL;
786 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
788 if (!radeon_connector->edid) {
789 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
790 drm_get_connector_name(connector));
791 ret = connector_status_connected;
792 } else {
793 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
795 /* some oems have boards with separate digital and analog connectors
796 * with a shared ddc line (often vga + hdmi)
798 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
799 kfree(radeon_connector->edid);
800 radeon_connector->edid = NULL;
801 ret = connector_status_disconnected;
802 } else
803 ret = connector_status_connected;
805 } else {
807 /* if we aren't forcing don't do destructive polling */
808 if (!force) {
809 /* only return the previous status if we last
810 * detected a monitor via load.
812 if (radeon_connector->detected_by_load)
813 ret = connector->status;
814 goto out;
817 if (radeon_connector->dac_load_detect && encoder) {
818 encoder_funcs = encoder->helper_private;
819 ret = encoder_funcs->detect(encoder, connector);
820 if (ret != connector_status_disconnected)
821 radeon_connector->detected_by_load = true;
825 if (ret == connector_status_connected)
826 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
828 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
829 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
830 * by other means, assume the CRT is connected and use that EDID.
832 if ((!rdev->is_atom_bios) &&
833 (ret == connector_status_disconnected) &&
834 rdev->mode_info.bios_hardcoded_edid_size) {
835 ret = connector_status_connected;
838 radeon_connector_update_scratch_regs(connector, ret);
840 out:
841 pm_runtime_mark_last_busy(connector->dev->dev);
842 pm_runtime_put_autosuspend(connector->dev->dev);
844 return ret;
847 static const struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
848 .get_modes = radeon_vga_get_modes,
849 .mode_valid = radeon_vga_mode_valid,
850 .best_encoder = radeon_best_single_encoder,
853 static const struct drm_connector_funcs radeon_vga_connector_funcs = {
854 .dpms = drm_helper_connector_dpms,
855 .detect = radeon_vga_detect,
856 .fill_modes = drm_helper_probe_single_connector_modes,
857 .destroy = radeon_connector_destroy,
858 .set_property = radeon_connector_set_property,
861 static int radeon_tv_get_modes(struct drm_connector *connector)
863 struct drm_device *dev = connector->dev;
864 struct radeon_device *rdev = dev->dev_private;
865 struct drm_display_mode *tv_mode;
866 struct drm_encoder *encoder;
868 encoder = radeon_best_single_encoder(connector);
869 if (!encoder)
870 return 0;
872 /* avivo chips can scale any mode */
873 if (rdev->family >= CHIP_RS600)
874 /* add scaled modes */
875 radeon_add_common_modes(encoder, connector);
876 else {
877 /* only 800x600 is supported right now on pre-avivo chips */
878 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
879 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
880 drm_mode_probed_add(connector, tv_mode);
882 return 1;
885 static int radeon_tv_mode_valid(struct drm_connector *connector,
886 struct drm_display_mode *mode)
888 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
889 return MODE_CLOCK_RANGE;
890 return MODE_OK;
893 static enum drm_connector_status
894 radeon_tv_detect(struct drm_connector *connector, bool force)
896 struct drm_encoder *encoder;
897 struct drm_encoder_helper_funcs *encoder_funcs;
898 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
899 enum drm_connector_status ret = connector_status_disconnected;
900 int r;
902 if (!radeon_connector->dac_load_detect)
903 return ret;
905 r = pm_runtime_get_sync(connector->dev->dev);
906 if (r < 0)
907 return connector_status_disconnected;
909 encoder = radeon_best_single_encoder(connector);
910 if (!encoder)
911 ret = connector_status_disconnected;
912 else {
913 encoder_funcs = encoder->helper_private;
914 ret = encoder_funcs->detect(encoder, connector);
916 if (ret == connector_status_connected)
917 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
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;
924 static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
925 .get_modes = radeon_tv_get_modes,
926 .mode_valid = radeon_tv_mode_valid,
927 .best_encoder = radeon_best_single_encoder,
930 static const struct drm_connector_funcs radeon_tv_connector_funcs = {
931 .dpms = drm_helper_connector_dpms,
932 .detect = radeon_tv_detect,
933 .fill_modes = drm_helper_probe_single_connector_modes,
934 .destroy = radeon_connector_destroy,
935 .set_property = radeon_connector_set_property,
938 static int radeon_dvi_get_modes(struct drm_connector *connector)
940 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
941 int ret;
943 ret = radeon_ddc_get_modes(radeon_connector);
944 return ret;
947 static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector)
949 struct drm_device *dev = connector->dev;
950 struct radeon_device *rdev = dev->dev_private;
951 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
952 enum drm_connector_status status;
954 /* We only trust HPD on R600 and newer ASICS. */
955 if (rdev->family >= CHIP_R600
956 && radeon_connector->hpd.hpd != RADEON_HPD_NONE) {
957 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
958 status = connector_status_connected;
959 else
960 status = connector_status_disconnected;
961 if (connector->status == status)
962 return true;
965 return false;
969 * DVI is complicated
970 * Do a DDC probe, if DDC probe passes, get the full EDID so
971 * we can do analog/digital monitor detection at this point.
972 * If the monitor is an analog monitor or we got no DDC,
973 * we need to find the DAC encoder object for this connector.
974 * If we got no DDC, we do load detection on the DAC encoder object.
975 * If we got analog DDC or load detection passes on the DAC encoder
976 * we have to check if this analog encoder is shared with anyone else (TV)
977 * if its shared we have to set the other connector to disconnected.
979 static enum drm_connector_status
980 radeon_dvi_detect(struct drm_connector *connector, bool force)
982 struct drm_device *dev = connector->dev;
983 struct radeon_device *rdev = dev->dev_private;
984 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
985 struct drm_encoder *encoder = NULL;
986 struct drm_encoder_helper_funcs *encoder_funcs;
987 struct drm_mode_object *obj;
988 int i, r;
989 enum drm_connector_status ret = connector_status_disconnected;
990 bool dret = false, broken_edid = false;
992 r = pm_runtime_get_sync(connector->dev->dev);
993 if (r < 0)
994 return connector_status_disconnected;
996 if (!force && radeon_check_hpd_status_unchanged(connector)) {
997 ret = connector->status;
998 goto exit;
1001 if (radeon_connector->ddc_bus)
1002 dret = radeon_ddc_probe(radeon_connector, false);
1003 if (dret) {
1004 radeon_connector->detected_by_load = false;
1005 if (radeon_connector->edid) {
1006 kfree(radeon_connector->edid);
1007 radeon_connector->edid = NULL;
1009 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
1011 if (!radeon_connector->edid) {
1012 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1013 drm_get_connector_name(connector));
1014 /* rs690 seems to have a problem with connectors not existing and always
1015 * return a block of 0's. If we see this just stop polling on this output */
1016 if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) && radeon_connector->base.null_edid_counter) {
1017 ret = connector_status_disconnected;
1018 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n", drm_get_connector_name(connector));
1019 radeon_connector->ddc_bus = NULL;
1020 } else {
1021 ret = connector_status_connected;
1022 broken_edid = true; /* defer use_digital to later */
1024 } else {
1025 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
1027 /* some oems have boards with separate digital and analog connectors
1028 * with a shared ddc line (often vga + hdmi)
1030 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
1031 kfree(radeon_connector->edid);
1032 radeon_connector->edid = NULL;
1033 ret = connector_status_disconnected;
1034 } else
1035 ret = connector_status_connected;
1037 /* This gets complicated. We have boards with VGA + HDMI with a
1038 * shared DDC line and we have boards with DVI-D + HDMI with a shared
1039 * DDC line. The latter is more complex because with DVI<->HDMI adapters
1040 * you don't really know what's connected to which port as both are digital.
1042 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
1043 struct drm_connector *list_connector;
1044 struct radeon_connector *list_radeon_connector;
1045 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
1046 if (connector == list_connector)
1047 continue;
1048 list_radeon_connector = to_radeon_connector(list_connector);
1049 if (list_radeon_connector->shared_ddc &&
1050 (list_radeon_connector->ddc_bus->rec.i2c_id ==
1051 radeon_connector->ddc_bus->rec.i2c_id)) {
1052 /* cases where both connectors are digital */
1053 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
1054 /* hpd is our only option in this case */
1055 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1056 kfree(radeon_connector->edid);
1057 radeon_connector->edid = NULL;
1058 ret = connector_status_disconnected;
1067 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
1068 goto out;
1070 /* DVI-D and HDMI-A are digital only */
1071 if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
1072 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
1073 goto out;
1075 /* if we aren't forcing don't do destructive polling */
1076 if (!force) {
1077 /* only return the previous status if we last
1078 * detected a monitor via load.
1080 if (radeon_connector->detected_by_load)
1081 ret = connector->status;
1082 goto out;
1085 /* find analog encoder */
1086 if (radeon_connector->dac_load_detect) {
1087 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1088 if (connector->encoder_ids[i] == 0)
1089 break;
1091 obj = drm_mode_object_find(connector->dev,
1092 connector->encoder_ids[i],
1093 DRM_MODE_OBJECT_ENCODER);
1094 if (!obj)
1095 continue;
1097 encoder = obj_to_encoder(obj);
1099 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
1100 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
1101 continue;
1103 encoder_funcs = encoder->helper_private;
1104 if (encoder_funcs->detect) {
1105 if (!broken_edid) {
1106 if (ret != connector_status_connected) {
1107 /* deal with analog monitors without DDC */
1108 ret = encoder_funcs->detect(encoder, connector);
1109 if (ret == connector_status_connected) {
1110 radeon_connector->use_digital = false;
1112 if (ret != connector_status_disconnected)
1113 radeon_connector->detected_by_load = true;
1115 } else {
1116 enum drm_connector_status lret;
1117 /* assume digital unless load detected otherwise */
1118 radeon_connector->use_digital = true;
1119 lret = encoder_funcs->detect(encoder, connector);
1120 DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
1121 if (lret == connector_status_connected)
1122 radeon_connector->use_digital = false;
1124 break;
1129 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
1130 encoder) {
1131 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1134 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1135 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1136 * by other means, assume the DFP is connected and use that EDID. In most
1137 * cases the DVI port is actually a virtual KVM port connected to the service
1138 * processor.
1140 out:
1141 if ((!rdev->is_atom_bios) &&
1142 (ret == connector_status_disconnected) &&
1143 rdev->mode_info.bios_hardcoded_edid_size) {
1144 radeon_connector->use_digital = true;
1145 ret = connector_status_connected;
1148 /* updated in get modes as well since we need to know if it's analog or digital */
1149 radeon_connector_update_scratch_regs(connector, ret);
1151 exit:
1152 pm_runtime_mark_last_busy(connector->dev->dev);
1153 pm_runtime_put_autosuspend(connector->dev->dev);
1155 return ret;
1158 /* okay need to be smart in here about which encoder to pick */
1159 static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
1161 int enc_id = connector->encoder_ids[0];
1162 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1163 struct drm_mode_object *obj;
1164 struct drm_encoder *encoder;
1165 int i;
1166 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1167 if (connector->encoder_ids[i] == 0)
1168 break;
1170 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1171 if (!obj)
1172 continue;
1174 encoder = obj_to_encoder(obj);
1176 if (radeon_connector->use_digital == true) {
1177 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
1178 return encoder;
1179 } else {
1180 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
1181 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
1182 return encoder;
1186 /* see if we have a default encoder TODO */
1188 /* then check use digitial */
1189 /* pick the first one */
1190 if (enc_id) {
1191 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
1192 if (!obj)
1193 return NULL;
1194 encoder = obj_to_encoder(obj);
1195 return encoder;
1197 return NULL;
1200 static void radeon_dvi_force(struct drm_connector *connector)
1202 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1203 if (connector->force == DRM_FORCE_ON)
1204 radeon_connector->use_digital = false;
1205 if (connector->force == DRM_FORCE_ON_DIGITAL)
1206 radeon_connector->use_digital = true;
1209 static int radeon_dvi_mode_valid(struct drm_connector *connector,
1210 struct drm_display_mode *mode)
1212 struct drm_device *dev = connector->dev;
1213 struct radeon_device *rdev = dev->dev_private;
1214 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1216 /* XXX check mode bandwidth */
1218 /* clocks over 135 MHz have heat issues with DVI on RV100 */
1219 if (radeon_connector->use_digital &&
1220 (rdev->family == CHIP_RV100) &&
1221 (mode->clock > 135000))
1222 return MODE_CLOCK_HIGH;
1224 if (radeon_connector->use_digital && (mode->clock > 165000)) {
1225 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1226 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1227 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1228 return MODE_OK;
1229 else if (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_A) {
1230 if (ASIC_IS_DCE6(rdev)) {
1231 /* HDMI 1.3+ supports max clock of 340 Mhz */
1232 if (mode->clock > 340000)
1233 return MODE_CLOCK_HIGH;
1234 else
1235 return MODE_OK;
1236 } else
1237 return MODE_CLOCK_HIGH;
1238 } else
1239 return MODE_CLOCK_HIGH;
1242 /* check against the max pixel clock */
1243 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1244 return MODE_CLOCK_HIGH;
1246 return MODE_OK;
1249 static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
1250 .get_modes = radeon_dvi_get_modes,
1251 .mode_valid = radeon_dvi_mode_valid,
1252 .best_encoder = radeon_dvi_encoder,
1255 static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
1256 .dpms = drm_helper_connector_dpms,
1257 .detect = radeon_dvi_detect,
1258 .fill_modes = drm_helper_probe_single_connector_modes,
1259 .set_property = radeon_connector_set_property,
1260 .destroy = radeon_connector_destroy,
1261 .force = radeon_dvi_force,
1264 static void radeon_dp_connector_destroy(struct drm_connector *connector)
1266 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1267 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1269 if (radeon_connector->edid)
1270 kfree(radeon_connector->edid);
1271 if (radeon_dig_connector->dp_i2c_bus)
1272 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
1273 kfree(radeon_connector->con_priv);
1274 drm_sysfs_connector_remove(connector);
1275 drm_connector_cleanup(connector);
1276 kfree(connector);
1279 static int radeon_dp_get_modes(struct drm_connector *connector)
1281 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1282 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1283 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1284 int ret;
1286 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1287 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1288 struct drm_display_mode *mode;
1290 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1291 if (!radeon_dig_connector->edp_on)
1292 atombios_set_edp_panel_power(connector,
1293 ATOM_TRANSMITTER_ACTION_POWER_ON);
1294 ret = radeon_ddc_get_modes(radeon_connector);
1295 if (!radeon_dig_connector->edp_on)
1296 atombios_set_edp_panel_power(connector,
1297 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1298 } else {
1299 /* need to setup ddc on the bridge */
1300 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1301 ENCODER_OBJECT_ID_NONE) {
1302 if (encoder)
1303 radeon_atom_ext_encoder_setup_ddc(encoder);
1305 ret = radeon_ddc_get_modes(radeon_connector);
1308 if (ret > 0) {
1309 if (encoder) {
1310 radeon_fixup_lvds_native_mode(encoder, connector);
1311 /* add scaled modes */
1312 radeon_add_common_modes(encoder, connector);
1314 return ret;
1317 if (!encoder)
1318 return 0;
1320 /* we have no EDID modes */
1321 mode = radeon_fp_native_mode(encoder);
1322 if (mode) {
1323 ret = 1;
1324 drm_mode_probed_add(connector, mode);
1325 /* add the width/height from vbios tables if available */
1326 connector->display_info.width_mm = mode->width_mm;
1327 connector->display_info.height_mm = mode->height_mm;
1328 /* add scaled modes */
1329 radeon_add_common_modes(encoder, connector);
1331 } else {
1332 /* need to setup ddc on the bridge */
1333 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1334 ENCODER_OBJECT_ID_NONE) {
1335 if (encoder)
1336 radeon_atom_ext_encoder_setup_ddc(encoder);
1338 ret = radeon_ddc_get_modes(radeon_connector);
1341 return ret;
1344 u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
1346 struct drm_mode_object *obj;
1347 struct drm_encoder *encoder;
1348 struct radeon_encoder *radeon_encoder;
1349 int i;
1351 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1352 if (connector->encoder_ids[i] == 0)
1353 break;
1355 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1356 if (!obj)
1357 continue;
1359 encoder = obj_to_encoder(obj);
1360 radeon_encoder = to_radeon_encoder(encoder);
1362 switch (radeon_encoder->encoder_id) {
1363 case ENCODER_OBJECT_ID_TRAVIS:
1364 case ENCODER_OBJECT_ID_NUTMEG:
1365 return radeon_encoder->encoder_id;
1366 default:
1367 break;
1371 return ENCODER_OBJECT_ID_NONE;
1374 bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
1376 struct drm_mode_object *obj;
1377 struct drm_encoder *encoder;
1378 struct radeon_encoder *radeon_encoder;
1379 int i;
1380 bool found = false;
1382 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1383 if (connector->encoder_ids[i] == 0)
1384 break;
1386 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1387 if (!obj)
1388 continue;
1390 encoder = obj_to_encoder(obj);
1391 radeon_encoder = to_radeon_encoder(encoder);
1392 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1393 found = true;
1396 return found;
1399 bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1401 struct drm_device *dev = connector->dev;
1402 struct radeon_device *rdev = dev->dev_private;
1404 if (ASIC_IS_DCE5(rdev) &&
1405 (rdev->clock.dp_extclk >= 53900) &&
1406 radeon_connector_encoder_is_hbr2(connector)) {
1407 return true;
1410 return false;
1413 static enum drm_connector_status
1414 radeon_dp_detect(struct drm_connector *connector, bool force)
1416 struct drm_device *dev = connector->dev;
1417 struct radeon_device *rdev = dev->dev_private;
1418 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1419 enum drm_connector_status ret = connector_status_disconnected;
1420 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1421 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1422 int r;
1424 r = pm_runtime_get_sync(connector->dev->dev);
1425 if (r < 0)
1426 return connector_status_disconnected;
1428 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1429 ret = connector->status;
1430 goto out;
1433 if (radeon_connector->edid) {
1434 kfree(radeon_connector->edid);
1435 radeon_connector->edid = NULL;
1438 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1439 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1440 if (encoder) {
1441 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1442 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1444 /* check if panel is valid */
1445 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1446 ret = connector_status_connected;
1448 /* eDP is always DP */
1449 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1450 if (!radeon_dig_connector->edp_on)
1451 atombios_set_edp_panel_power(connector,
1452 ATOM_TRANSMITTER_ACTION_POWER_ON);
1453 if (radeon_dp_getdpcd(radeon_connector))
1454 ret = connector_status_connected;
1455 if (!radeon_dig_connector->edp_on)
1456 atombios_set_edp_panel_power(connector,
1457 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1458 } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1459 ENCODER_OBJECT_ID_NONE) {
1460 /* DP bridges are always DP */
1461 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1462 /* get the DPCD from the bridge */
1463 radeon_dp_getdpcd(radeon_connector);
1465 if (encoder) {
1466 /* setup ddc on the bridge */
1467 radeon_atom_ext_encoder_setup_ddc(encoder);
1468 /* bridge chips are always aux */
1469 if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */
1470 ret = connector_status_connected;
1471 else if (radeon_connector->dac_load_detect) { /* try load detection */
1472 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
1473 ret = encoder_funcs->detect(encoder, connector);
1476 } else {
1477 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
1478 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1479 ret = connector_status_connected;
1480 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
1481 radeon_dp_getdpcd(radeon_connector);
1482 } else {
1483 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1484 if (radeon_dp_getdpcd(radeon_connector))
1485 ret = connector_status_connected;
1486 } else {
1487 /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
1488 if (radeon_ddc_probe(radeon_connector, false))
1489 ret = connector_status_connected;
1494 radeon_connector_update_scratch_regs(connector, ret);
1495 out:
1496 pm_runtime_mark_last_busy(connector->dev->dev);
1497 pm_runtime_put_autosuspend(connector->dev->dev);
1499 return ret;
1502 static int radeon_dp_mode_valid(struct drm_connector *connector,
1503 struct drm_display_mode *mode)
1505 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1506 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1508 /* XXX check mode bandwidth */
1510 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1511 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1512 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1514 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1515 return MODE_PANEL;
1517 if (encoder) {
1518 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1519 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1521 /* AVIVO hardware supports downscaling modes larger than the panel
1522 * to the panel size, but I'm not sure this is desirable.
1524 if ((mode->hdisplay > native_mode->hdisplay) ||
1525 (mode->vdisplay > native_mode->vdisplay))
1526 return MODE_PANEL;
1528 /* if scaling is disabled, block non-native modes */
1529 if (radeon_encoder->rmx_type == RMX_OFF) {
1530 if ((mode->hdisplay != native_mode->hdisplay) ||
1531 (mode->vdisplay != native_mode->vdisplay))
1532 return MODE_PANEL;
1535 return MODE_OK;
1536 } else {
1537 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1538 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
1539 return radeon_dp_mode_valid_helper(connector, mode);
1540 else
1541 return MODE_OK;
1545 static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1546 .get_modes = radeon_dp_get_modes,
1547 .mode_valid = radeon_dp_mode_valid,
1548 .best_encoder = radeon_dvi_encoder,
1551 static const struct drm_connector_funcs radeon_dp_connector_funcs = {
1552 .dpms = drm_helper_connector_dpms,
1553 .detect = radeon_dp_detect,
1554 .fill_modes = drm_helper_probe_single_connector_modes,
1555 .set_property = radeon_connector_set_property,
1556 .destroy = radeon_dp_connector_destroy,
1557 .force = radeon_dvi_force,
1560 static const struct drm_connector_funcs radeon_edp_connector_funcs = {
1561 .dpms = drm_helper_connector_dpms,
1562 .detect = radeon_dp_detect,
1563 .fill_modes = drm_helper_probe_single_connector_modes,
1564 .set_property = radeon_lvds_set_property,
1565 .destroy = radeon_dp_connector_destroy,
1566 .force = radeon_dvi_force,
1569 static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
1570 .dpms = drm_helper_connector_dpms,
1571 .detect = radeon_dp_detect,
1572 .fill_modes = drm_helper_probe_single_connector_modes,
1573 .set_property = radeon_lvds_set_property,
1574 .destroy = radeon_dp_connector_destroy,
1575 .force = radeon_dvi_force,
1578 void
1579 radeon_add_atom_connector(struct drm_device *dev,
1580 uint32_t connector_id,
1581 uint32_t supported_device,
1582 int connector_type,
1583 struct radeon_i2c_bus_rec *i2c_bus,
1584 uint32_t igp_lane_info,
1585 uint16_t connector_object_id,
1586 struct radeon_hpd *hpd,
1587 struct radeon_router *router)
1589 struct radeon_device *rdev = dev->dev_private;
1590 struct drm_connector *connector;
1591 struct radeon_connector *radeon_connector;
1592 struct radeon_connector_atom_dig *radeon_dig_connector;
1593 struct drm_encoder *encoder;
1594 struct radeon_encoder *radeon_encoder;
1595 uint32_t subpixel_order = SubPixelNone;
1596 bool shared_ddc = false;
1597 bool is_dp_bridge = false;
1599 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1600 return;
1602 /* if the user selected tv=0 don't try and add the connector */
1603 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1604 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1605 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1606 (radeon_tv == 0))
1607 return;
1609 /* see if we already added it */
1610 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1611 radeon_connector = to_radeon_connector(connector);
1612 if (radeon_connector->connector_id == connector_id) {
1613 radeon_connector->devices |= supported_device;
1614 return;
1616 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1617 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1618 radeon_connector->shared_ddc = true;
1619 shared_ddc = true;
1621 if (radeon_connector->router_bus && router->ddc_valid &&
1622 (radeon_connector->router.router_id == router->router_id)) {
1623 radeon_connector->shared_ddc = false;
1624 shared_ddc = false;
1629 /* check if it's a dp bridge */
1630 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1631 radeon_encoder = to_radeon_encoder(encoder);
1632 if (radeon_encoder->devices & supported_device) {
1633 switch (radeon_encoder->encoder_id) {
1634 case ENCODER_OBJECT_ID_TRAVIS:
1635 case ENCODER_OBJECT_ID_NUTMEG:
1636 is_dp_bridge = true;
1637 break;
1638 default:
1639 break;
1644 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1645 if (!radeon_connector)
1646 return;
1648 connector = &radeon_connector->base;
1650 radeon_connector->connector_id = connector_id;
1651 radeon_connector->devices = supported_device;
1652 radeon_connector->shared_ddc = shared_ddc;
1653 radeon_connector->connector_object_id = connector_object_id;
1654 radeon_connector->hpd = *hpd;
1656 radeon_connector->router = *router;
1657 if (router->ddc_valid || router->cd_valid) {
1658 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1659 if (!radeon_connector->router_bus)
1660 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
1663 if (is_dp_bridge) {
1664 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1665 if (!radeon_dig_connector)
1666 goto failed;
1667 radeon_dig_connector->igp_lane_info = igp_lane_info;
1668 radeon_connector->con_priv = radeon_dig_connector;
1669 if (i2c_bus->valid) {
1670 /* add DP i2c bus */
1671 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1672 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1673 else
1674 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1675 if (!radeon_dig_connector->dp_i2c_bus)
1676 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1677 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1678 if (!radeon_connector->ddc_bus)
1679 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1681 switch (connector_type) {
1682 case DRM_MODE_CONNECTOR_VGA:
1683 case DRM_MODE_CONNECTOR_DVIA:
1684 default:
1685 drm_connector_init(dev, &radeon_connector->base,
1686 &radeon_dp_connector_funcs, connector_type);
1687 drm_connector_helper_add(&radeon_connector->base,
1688 &radeon_dp_connector_helper_funcs);
1689 connector->interlace_allowed = true;
1690 connector->doublescan_allowed = true;
1691 radeon_connector->dac_load_detect = true;
1692 drm_object_attach_property(&radeon_connector->base.base,
1693 rdev->mode_info.load_detect_property,
1695 break;
1696 case DRM_MODE_CONNECTOR_DVII:
1697 case DRM_MODE_CONNECTOR_DVID:
1698 case DRM_MODE_CONNECTOR_HDMIA:
1699 case DRM_MODE_CONNECTOR_HDMIB:
1700 case DRM_MODE_CONNECTOR_DisplayPort:
1701 drm_connector_init(dev, &radeon_connector->base,
1702 &radeon_dp_connector_funcs, connector_type);
1703 drm_connector_helper_add(&radeon_connector->base,
1704 &radeon_dp_connector_helper_funcs);
1705 drm_object_attach_property(&radeon_connector->base.base,
1706 rdev->mode_info.underscan_property,
1707 UNDERSCAN_OFF);
1708 drm_object_attach_property(&radeon_connector->base.base,
1709 rdev->mode_info.underscan_hborder_property,
1711 drm_object_attach_property(&radeon_connector->base.base,
1712 rdev->mode_info.underscan_vborder_property,
1715 drm_object_attach_property(&radeon_connector->base.base,
1716 rdev->mode_info.dither_property,
1717 RADEON_FMT_DITHER_DISABLE);
1719 if (radeon_audio != 0)
1720 drm_object_attach_property(&radeon_connector->base.base,
1721 rdev->mode_info.audio_property,
1722 RADEON_AUDIO_AUTO);
1724 subpixel_order = SubPixelHorizontalRGB;
1725 connector->interlace_allowed = true;
1726 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1727 connector->doublescan_allowed = true;
1728 else
1729 connector->doublescan_allowed = false;
1730 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1731 radeon_connector->dac_load_detect = true;
1732 drm_object_attach_property(&radeon_connector->base.base,
1733 rdev->mode_info.load_detect_property,
1736 break;
1737 case DRM_MODE_CONNECTOR_LVDS:
1738 case DRM_MODE_CONNECTOR_eDP:
1739 drm_connector_init(dev, &radeon_connector->base,
1740 &radeon_lvds_bridge_connector_funcs, connector_type);
1741 drm_connector_helper_add(&radeon_connector->base,
1742 &radeon_dp_connector_helper_funcs);
1743 drm_object_attach_property(&radeon_connector->base.base,
1744 dev->mode_config.scaling_mode_property,
1745 DRM_MODE_SCALE_FULLSCREEN);
1746 subpixel_order = SubPixelHorizontalRGB;
1747 connector->interlace_allowed = false;
1748 connector->doublescan_allowed = false;
1749 break;
1751 } else {
1752 switch (connector_type) {
1753 case DRM_MODE_CONNECTOR_VGA:
1754 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1755 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1756 if (i2c_bus->valid) {
1757 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1758 if (!radeon_connector->ddc_bus)
1759 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1761 radeon_connector->dac_load_detect = true;
1762 drm_object_attach_property(&radeon_connector->base.base,
1763 rdev->mode_info.load_detect_property,
1765 /* no HPD on analog connectors */
1766 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1767 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1768 connector->interlace_allowed = true;
1769 connector->doublescan_allowed = true;
1770 break;
1771 case DRM_MODE_CONNECTOR_DVIA:
1772 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1773 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1774 if (i2c_bus->valid) {
1775 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1776 if (!radeon_connector->ddc_bus)
1777 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1779 radeon_connector->dac_load_detect = true;
1780 drm_object_attach_property(&radeon_connector->base.base,
1781 rdev->mode_info.load_detect_property,
1783 /* no HPD on analog connectors */
1784 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1785 connector->interlace_allowed = true;
1786 connector->doublescan_allowed = true;
1787 break;
1788 case DRM_MODE_CONNECTOR_DVII:
1789 case DRM_MODE_CONNECTOR_DVID:
1790 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1791 if (!radeon_dig_connector)
1792 goto failed;
1793 radeon_dig_connector->igp_lane_info = igp_lane_info;
1794 radeon_connector->con_priv = radeon_dig_connector;
1795 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1796 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1797 if (i2c_bus->valid) {
1798 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1799 if (!radeon_connector->ddc_bus)
1800 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1802 subpixel_order = SubPixelHorizontalRGB;
1803 drm_object_attach_property(&radeon_connector->base.base,
1804 rdev->mode_info.coherent_mode_property,
1806 if (ASIC_IS_AVIVO(rdev)) {
1807 drm_object_attach_property(&radeon_connector->base.base,
1808 rdev->mode_info.underscan_property,
1809 UNDERSCAN_OFF);
1810 drm_object_attach_property(&radeon_connector->base.base,
1811 rdev->mode_info.underscan_hborder_property,
1813 drm_object_attach_property(&radeon_connector->base.base,
1814 rdev->mode_info.underscan_vborder_property,
1817 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
1818 drm_object_attach_property(&radeon_connector->base.base,
1819 rdev->mode_info.audio_property,
1820 RADEON_AUDIO_AUTO);
1822 if (ASIC_IS_AVIVO(rdev)) {
1823 drm_object_attach_property(&radeon_connector->base.base,
1824 rdev->mode_info.dither_property,
1825 RADEON_FMT_DITHER_DISABLE);
1827 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1828 radeon_connector->dac_load_detect = true;
1829 drm_object_attach_property(&radeon_connector->base.base,
1830 rdev->mode_info.load_detect_property,
1833 connector->interlace_allowed = true;
1834 if (connector_type == DRM_MODE_CONNECTOR_DVII)
1835 connector->doublescan_allowed = true;
1836 else
1837 connector->doublescan_allowed = false;
1838 break;
1839 case DRM_MODE_CONNECTOR_HDMIA:
1840 case DRM_MODE_CONNECTOR_HDMIB:
1841 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1842 if (!radeon_dig_connector)
1843 goto failed;
1844 radeon_dig_connector->igp_lane_info = igp_lane_info;
1845 radeon_connector->con_priv = radeon_dig_connector;
1846 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1847 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1848 if (i2c_bus->valid) {
1849 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1850 if (!radeon_connector->ddc_bus)
1851 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1853 drm_object_attach_property(&radeon_connector->base.base,
1854 rdev->mode_info.coherent_mode_property,
1856 if (ASIC_IS_AVIVO(rdev)) {
1857 drm_object_attach_property(&radeon_connector->base.base,
1858 rdev->mode_info.underscan_property,
1859 UNDERSCAN_OFF);
1860 drm_object_attach_property(&radeon_connector->base.base,
1861 rdev->mode_info.underscan_hborder_property,
1863 drm_object_attach_property(&radeon_connector->base.base,
1864 rdev->mode_info.underscan_vborder_property,
1867 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
1868 drm_object_attach_property(&radeon_connector->base.base,
1869 rdev->mode_info.audio_property,
1870 RADEON_AUDIO_AUTO);
1872 if (ASIC_IS_AVIVO(rdev)) {
1873 drm_object_attach_property(&radeon_connector->base.base,
1874 rdev->mode_info.dither_property,
1875 RADEON_FMT_DITHER_DISABLE);
1877 subpixel_order = SubPixelHorizontalRGB;
1878 connector->interlace_allowed = true;
1879 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1880 connector->doublescan_allowed = true;
1881 else
1882 connector->doublescan_allowed = false;
1883 break;
1884 case DRM_MODE_CONNECTOR_DisplayPort:
1885 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1886 if (!radeon_dig_connector)
1887 goto failed;
1888 radeon_dig_connector->igp_lane_info = igp_lane_info;
1889 radeon_connector->con_priv = radeon_dig_connector;
1890 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1891 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1892 if (i2c_bus->valid) {
1893 /* add DP i2c bus */
1894 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1895 if (!radeon_dig_connector->dp_i2c_bus)
1896 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1897 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1898 if (!radeon_connector->ddc_bus)
1899 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1901 subpixel_order = SubPixelHorizontalRGB;
1902 drm_object_attach_property(&radeon_connector->base.base,
1903 rdev->mode_info.coherent_mode_property,
1905 if (ASIC_IS_AVIVO(rdev)) {
1906 drm_object_attach_property(&radeon_connector->base.base,
1907 rdev->mode_info.underscan_property,
1908 UNDERSCAN_OFF);
1909 drm_object_attach_property(&radeon_connector->base.base,
1910 rdev->mode_info.underscan_hborder_property,
1912 drm_object_attach_property(&radeon_connector->base.base,
1913 rdev->mode_info.underscan_vborder_property,
1916 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
1917 drm_object_attach_property(&radeon_connector->base.base,
1918 rdev->mode_info.audio_property,
1919 RADEON_AUDIO_AUTO);
1921 if (ASIC_IS_AVIVO(rdev)) {
1922 drm_object_attach_property(&radeon_connector->base.base,
1923 rdev->mode_info.dither_property,
1924 RADEON_FMT_DITHER_DISABLE);
1927 connector->interlace_allowed = true;
1928 /* in theory with a DP to VGA converter... */
1929 connector->doublescan_allowed = false;
1930 break;
1931 case DRM_MODE_CONNECTOR_eDP:
1932 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1933 if (!radeon_dig_connector)
1934 goto failed;
1935 radeon_dig_connector->igp_lane_info = igp_lane_info;
1936 radeon_connector->con_priv = radeon_dig_connector;
1937 drm_connector_init(dev, &radeon_connector->base, &radeon_edp_connector_funcs, connector_type);
1938 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1939 if (i2c_bus->valid) {
1940 /* add DP i2c bus */
1941 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1942 if (!radeon_dig_connector->dp_i2c_bus)
1943 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1944 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1945 if (!radeon_connector->ddc_bus)
1946 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1948 drm_object_attach_property(&radeon_connector->base.base,
1949 dev->mode_config.scaling_mode_property,
1950 DRM_MODE_SCALE_FULLSCREEN);
1951 subpixel_order = SubPixelHorizontalRGB;
1952 connector->interlace_allowed = false;
1953 connector->doublescan_allowed = false;
1954 break;
1955 case DRM_MODE_CONNECTOR_SVIDEO:
1956 case DRM_MODE_CONNECTOR_Composite:
1957 case DRM_MODE_CONNECTOR_9PinDIN:
1958 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1959 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1960 radeon_connector->dac_load_detect = true;
1961 drm_object_attach_property(&radeon_connector->base.base,
1962 rdev->mode_info.load_detect_property,
1964 drm_object_attach_property(&radeon_connector->base.base,
1965 rdev->mode_info.tv_std_property,
1966 radeon_atombios_get_tv_info(rdev));
1967 /* no HPD on analog connectors */
1968 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1969 connector->interlace_allowed = false;
1970 connector->doublescan_allowed = false;
1971 break;
1972 case DRM_MODE_CONNECTOR_LVDS:
1973 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1974 if (!radeon_dig_connector)
1975 goto failed;
1976 radeon_dig_connector->igp_lane_info = igp_lane_info;
1977 radeon_connector->con_priv = radeon_dig_connector;
1978 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1979 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1980 if (i2c_bus->valid) {
1981 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1982 if (!radeon_connector->ddc_bus)
1983 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1985 drm_object_attach_property(&radeon_connector->base.base,
1986 dev->mode_config.scaling_mode_property,
1987 DRM_MODE_SCALE_FULLSCREEN);
1988 subpixel_order = SubPixelHorizontalRGB;
1989 connector->interlace_allowed = false;
1990 connector->doublescan_allowed = false;
1991 break;
1995 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
1996 if (i2c_bus->valid)
1997 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1998 } else
1999 connector->polled = DRM_CONNECTOR_POLL_HPD;
2001 connector->display_info.subpixel_order = subpixel_order;
2002 drm_sysfs_connector_add(connector);
2003 return;
2005 failed:
2006 drm_connector_cleanup(connector);
2007 kfree(connector);
2010 void
2011 radeon_add_legacy_connector(struct drm_device *dev,
2012 uint32_t connector_id,
2013 uint32_t supported_device,
2014 int connector_type,
2015 struct radeon_i2c_bus_rec *i2c_bus,
2016 uint16_t connector_object_id,
2017 struct radeon_hpd *hpd)
2019 struct radeon_device *rdev = dev->dev_private;
2020 struct drm_connector *connector;
2021 struct radeon_connector *radeon_connector;
2022 uint32_t subpixel_order = SubPixelNone;
2024 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
2025 return;
2027 /* if the user selected tv=0 don't try and add the connector */
2028 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
2029 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
2030 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
2031 (radeon_tv == 0))
2032 return;
2034 /* see if we already added it */
2035 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2036 radeon_connector = to_radeon_connector(connector);
2037 if (radeon_connector->connector_id == connector_id) {
2038 radeon_connector->devices |= supported_device;
2039 return;
2043 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
2044 if (!radeon_connector)
2045 return;
2047 connector = &radeon_connector->base;
2049 radeon_connector->connector_id = connector_id;
2050 radeon_connector->devices = supported_device;
2051 radeon_connector->connector_object_id = connector_object_id;
2052 radeon_connector->hpd = *hpd;
2054 switch (connector_type) {
2055 case DRM_MODE_CONNECTOR_VGA:
2056 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2057 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2058 if (i2c_bus->valid) {
2059 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2060 if (!radeon_connector->ddc_bus)
2061 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2063 radeon_connector->dac_load_detect = true;
2064 drm_object_attach_property(&radeon_connector->base.base,
2065 rdev->mode_info.load_detect_property,
2067 /* no HPD on analog connectors */
2068 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2069 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2070 connector->interlace_allowed = true;
2071 connector->doublescan_allowed = true;
2072 break;
2073 case DRM_MODE_CONNECTOR_DVIA:
2074 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2075 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2076 if (i2c_bus->valid) {
2077 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2078 if (!radeon_connector->ddc_bus)
2079 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2081 radeon_connector->dac_load_detect = true;
2082 drm_object_attach_property(&radeon_connector->base.base,
2083 rdev->mode_info.load_detect_property,
2085 /* no HPD on analog connectors */
2086 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2087 connector->interlace_allowed = true;
2088 connector->doublescan_allowed = true;
2089 break;
2090 case DRM_MODE_CONNECTOR_DVII:
2091 case DRM_MODE_CONNECTOR_DVID:
2092 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
2093 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2094 if (i2c_bus->valid) {
2095 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2096 if (!radeon_connector->ddc_bus)
2097 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2099 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2100 radeon_connector->dac_load_detect = true;
2101 drm_object_attach_property(&radeon_connector->base.base,
2102 rdev->mode_info.load_detect_property,
2105 subpixel_order = SubPixelHorizontalRGB;
2106 connector->interlace_allowed = true;
2107 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2108 connector->doublescan_allowed = true;
2109 else
2110 connector->doublescan_allowed = false;
2111 break;
2112 case DRM_MODE_CONNECTOR_SVIDEO:
2113 case DRM_MODE_CONNECTOR_Composite:
2114 case DRM_MODE_CONNECTOR_9PinDIN:
2115 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
2116 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2117 radeon_connector->dac_load_detect = true;
2118 /* RS400,RC410,RS480 chipset seems to report a lot
2119 * of false positive on load detect, we haven't yet
2120 * found a way to make load detect reliable on those
2121 * chipset, thus just disable it for TV.
2123 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
2124 radeon_connector->dac_load_detect = false;
2125 drm_object_attach_property(&radeon_connector->base.base,
2126 rdev->mode_info.load_detect_property,
2127 radeon_connector->dac_load_detect);
2128 drm_object_attach_property(&radeon_connector->base.base,
2129 rdev->mode_info.tv_std_property,
2130 radeon_combios_get_tv_info(rdev));
2131 /* no HPD on analog connectors */
2132 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2133 connector->interlace_allowed = false;
2134 connector->doublescan_allowed = false;
2135 break;
2136 case DRM_MODE_CONNECTOR_LVDS:
2137 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
2138 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2139 if (i2c_bus->valid) {
2140 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2141 if (!radeon_connector->ddc_bus)
2142 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2144 drm_object_attach_property(&radeon_connector->base.base,
2145 dev->mode_config.scaling_mode_property,
2146 DRM_MODE_SCALE_FULLSCREEN);
2147 subpixel_order = SubPixelHorizontalRGB;
2148 connector->interlace_allowed = false;
2149 connector->doublescan_allowed = false;
2150 break;
2153 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
2154 if (i2c_bus->valid)
2155 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2156 } else
2157 connector->polled = DRM_CONNECTOR_POLL_HPD;
2158 connector->display_info.subpixel_order = subpixel_order;
2159 drm_sysfs_connector_add(connector);