MIPS: Yosemite, Emma: Fix off-by-two in arcs_cmdline buffer size check
[linux-2.6/linux-mips.git] / drivers / gpu / drm / radeon / radeon_connectors.c
blobdec6cbe6a0a6a4ef5a1b59be5b63e037521870a4
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 "drmP.h"
27 #include "drm_edid.h"
28 #include "drm_crtc_helper.h"
29 #include "drm_fb_helper.h"
30 #include "radeon_drm.h"
31 #include "radeon.h"
32 #include "atom.h"
34 extern void
35 radeon_combios_connected_scratch_regs(struct drm_connector *connector,
36 struct drm_encoder *encoder,
37 bool connected);
38 extern void
39 radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
40 struct drm_encoder *encoder,
41 bool connected);
43 extern void
44 radeon_legacy_backlight_init(struct radeon_encoder *radeon_encoder,
45 struct drm_connector *drm_connector);
47 bool radeon_connector_encoder_is_dp_bridge(struct drm_connector *connector);
49 void radeon_connector_hotplug(struct drm_connector *connector)
51 struct drm_device *dev = connector->dev;
52 struct radeon_device *rdev = dev->dev_private;
53 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
55 /* bail if the connector does not have hpd pin, e.g.,
56 * VGA, TV, etc.
58 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE)
59 return;
61 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
63 /* if the connector is already off, don't turn it back on */
64 if (connector->dpms != DRM_MODE_DPMS_ON)
65 return;
67 /* just deal with DP (not eDP) here. */
68 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
69 int saved_dpms = connector->dpms;
71 /* Only turn off the display it it's physically disconnected */
72 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
73 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
74 else if (radeon_dp_needs_link_train(radeon_connector))
75 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
76 connector->dpms = saved_dpms;
80 static void radeon_property_change_mode(struct drm_encoder *encoder)
82 struct drm_crtc *crtc = encoder->crtc;
84 if (crtc && crtc->enabled) {
85 drm_crtc_helper_set_mode(crtc, &crtc->mode,
86 crtc->x, crtc->y, crtc->fb);
89 static void
90 radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
92 struct drm_device *dev = connector->dev;
93 struct radeon_device *rdev = dev->dev_private;
94 struct drm_encoder *best_encoder = NULL;
95 struct drm_encoder *encoder = NULL;
96 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
97 struct drm_mode_object *obj;
98 bool connected;
99 int i;
101 best_encoder = connector_funcs->best_encoder(connector);
103 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
104 if (connector->encoder_ids[i] == 0)
105 break;
107 obj = drm_mode_object_find(connector->dev,
108 connector->encoder_ids[i],
109 DRM_MODE_OBJECT_ENCODER);
110 if (!obj)
111 continue;
113 encoder = obj_to_encoder(obj);
115 if ((encoder == best_encoder) && (status == connector_status_connected))
116 connected = true;
117 else
118 connected = false;
120 if (rdev->is_atom_bios)
121 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
122 else
123 radeon_combios_connected_scratch_regs(connector, encoder, connected);
128 struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
130 struct drm_mode_object *obj;
131 struct drm_encoder *encoder;
132 int i;
134 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
135 if (connector->encoder_ids[i] == 0)
136 break;
138 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
139 if (!obj)
140 continue;
142 encoder = obj_to_encoder(obj);
143 if (encoder->encoder_type == encoder_type)
144 return encoder;
146 return NULL;
149 struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
151 int enc_id = connector->encoder_ids[0];
152 struct drm_mode_object *obj;
153 struct drm_encoder *encoder;
155 /* pick the encoder ids */
156 if (enc_id) {
157 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
158 if (!obj)
159 return NULL;
160 encoder = obj_to_encoder(obj);
161 return encoder;
163 return NULL;
167 * radeon_connector_analog_encoder_conflict_solve
168 * - search for other connectors sharing this encoder
169 * if priority is true, then set them disconnected if this is connected
170 * if priority is false, set us disconnected if they are connected
172 static enum drm_connector_status
173 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
174 struct drm_encoder *encoder,
175 enum drm_connector_status current_status,
176 bool priority)
178 struct drm_device *dev = connector->dev;
179 struct drm_connector *conflict;
180 struct radeon_connector *radeon_conflict;
181 int i;
183 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
184 if (conflict == connector)
185 continue;
187 radeon_conflict = to_radeon_connector(conflict);
188 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
189 if (conflict->encoder_ids[i] == 0)
190 break;
192 /* if the IDs match */
193 if (conflict->encoder_ids[i] == encoder->base.id) {
194 if (conflict->status != connector_status_connected)
195 continue;
197 if (radeon_conflict->use_digital)
198 continue;
200 if (priority == true) {
201 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
202 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(connector));
203 conflict->status = connector_status_disconnected;
204 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
205 } else {
206 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
207 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(conflict));
208 current_status = connector_status_disconnected;
210 break;
214 return current_status;
218 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
220 struct drm_device *dev = encoder->dev;
221 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
222 struct drm_display_mode *mode = NULL;
223 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
225 if (native_mode->hdisplay != 0 &&
226 native_mode->vdisplay != 0 &&
227 native_mode->clock != 0) {
228 mode = drm_mode_duplicate(dev, native_mode);
229 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
230 drm_mode_set_name(mode);
232 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
233 } else if (native_mode->hdisplay != 0 &&
234 native_mode->vdisplay != 0) {
235 /* mac laptops without an edid */
236 /* Note that this is not necessarily the exact panel mode,
237 * but an approximation based on the cvt formula. For these
238 * systems we should ideally read the mode info out of the
239 * registers or add a mode table, but this works and is much
240 * simpler.
242 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
243 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
244 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
246 return mode;
249 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
251 struct drm_device *dev = encoder->dev;
252 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
253 struct drm_display_mode *mode = NULL;
254 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
255 int i;
256 struct mode_size {
257 int w;
258 int h;
259 } common_modes[17] = {
260 { 640, 480},
261 { 720, 480},
262 { 800, 600},
263 { 848, 480},
264 {1024, 768},
265 {1152, 768},
266 {1280, 720},
267 {1280, 800},
268 {1280, 854},
269 {1280, 960},
270 {1280, 1024},
271 {1440, 900},
272 {1400, 1050},
273 {1680, 1050},
274 {1600, 1200},
275 {1920, 1080},
276 {1920, 1200}
279 for (i = 0; i < 17; i++) {
280 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
281 if (common_modes[i].w > 1024 ||
282 common_modes[i].h > 768)
283 continue;
285 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
286 if (common_modes[i].w > native_mode->hdisplay ||
287 common_modes[i].h > native_mode->vdisplay ||
288 (common_modes[i].w == native_mode->hdisplay &&
289 common_modes[i].h == native_mode->vdisplay))
290 continue;
292 if (common_modes[i].w < 320 || common_modes[i].h < 200)
293 continue;
295 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
296 drm_mode_probed_add(connector, mode);
300 int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
301 uint64_t val)
303 struct drm_device *dev = connector->dev;
304 struct radeon_device *rdev = dev->dev_private;
305 struct drm_encoder *encoder;
306 struct radeon_encoder *radeon_encoder;
308 if (property == rdev->mode_info.coherent_mode_property) {
309 struct radeon_encoder_atom_dig *dig;
310 bool new_coherent_mode;
312 /* need to find digital encoder on connector */
313 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
314 if (!encoder)
315 return 0;
317 radeon_encoder = to_radeon_encoder(encoder);
319 if (!radeon_encoder->enc_priv)
320 return 0;
322 dig = radeon_encoder->enc_priv;
323 new_coherent_mode = val ? true : false;
324 if (dig->coherent_mode != new_coherent_mode) {
325 dig->coherent_mode = new_coherent_mode;
326 radeon_property_change_mode(&radeon_encoder->base);
330 if (property == rdev->mode_info.underscan_property) {
331 /* need to find digital encoder on connector */
332 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
333 if (!encoder)
334 return 0;
336 radeon_encoder = to_radeon_encoder(encoder);
338 if (radeon_encoder->underscan_type != val) {
339 radeon_encoder->underscan_type = val;
340 radeon_property_change_mode(&radeon_encoder->base);
344 if (property == rdev->mode_info.underscan_hborder_property) {
345 /* need to find digital encoder on connector */
346 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
347 if (!encoder)
348 return 0;
350 radeon_encoder = to_radeon_encoder(encoder);
352 if (radeon_encoder->underscan_hborder != val) {
353 radeon_encoder->underscan_hborder = val;
354 radeon_property_change_mode(&radeon_encoder->base);
358 if (property == rdev->mode_info.underscan_vborder_property) {
359 /* need to find digital encoder on connector */
360 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
361 if (!encoder)
362 return 0;
364 radeon_encoder = to_radeon_encoder(encoder);
366 if (radeon_encoder->underscan_vborder != val) {
367 radeon_encoder->underscan_vborder = val;
368 radeon_property_change_mode(&radeon_encoder->base);
372 if (property == rdev->mode_info.tv_std_property) {
373 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
374 if (!encoder) {
375 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
378 if (!encoder)
379 return 0;
381 radeon_encoder = to_radeon_encoder(encoder);
382 if (!radeon_encoder->enc_priv)
383 return 0;
384 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
385 struct radeon_encoder_atom_dac *dac_int;
386 dac_int = radeon_encoder->enc_priv;
387 dac_int->tv_std = val;
388 } else {
389 struct radeon_encoder_tv_dac *dac_int;
390 dac_int = radeon_encoder->enc_priv;
391 dac_int->tv_std = val;
393 radeon_property_change_mode(&radeon_encoder->base);
396 if (property == rdev->mode_info.load_detect_property) {
397 struct radeon_connector *radeon_connector =
398 to_radeon_connector(connector);
400 if (val == 0)
401 radeon_connector->dac_load_detect = false;
402 else
403 radeon_connector->dac_load_detect = true;
406 if (property == rdev->mode_info.tmds_pll_property) {
407 struct radeon_encoder_int_tmds *tmds = NULL;
408 bool ret = false;
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 tmds = radeon_encoder->enc_priv;
417 if (!tmds)
418 return 0;
420 if (val == 0) {
421 if (rdev->is_atom_bios)
422 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
423 else
424 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
426 if (val == 1 || ret == false) {
427 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
429 radeon_property_change_mode(&radeon_encoder->base);
432 return 0;
436 * Some integrated ATI Radeon chipset implementations (e. g.
437 * Asus M2A-VM HDMI) may indicate the availability of a DDC,
438 * even when there's no monitor connected. For these connectors
439 * following DDC probe extension will be applied: check also for the
440 * availability of EDID with at least a correct EDID header. Only then,
441 * DDC is assumed to be available. This prevents drm_get_edid() and
442 * drm_edid_block_valid() from periodically dumping data and kernel
443 * errors into the logs and onto the terminal.
445 static bool radeon_connector_needs_extended_probe(struct radeon_device *dev,
446 uint32_t supported_device,
447 int connector_type)
449 /* Asus M2A-VM HDMI board sends data to i2c bus even,
450 * if HDMI add-on card is not plugged in or HDMI is disabled in
451 * BIOS. Valid DDC can only be assumed, if also a valid EDID header
452 * can be retrieved via i2c bus during DDC probe */
453 if ((dev->pdev->device == 0x791e) &&
454 (dev->pdev->subsystem_vendor == 0x1043) &&
455 (dev->pdev->subsystem_device == 0x826d)) {
456 if ((connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
457 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
458 return true;
460 /* ECS A740GM-M with ATI RADEON 2100 sends data to i2c bus
461 * for a DVI connector that is not implemented */
462 if ((dev->pdev->device == 0x796e) &&
463 (dev->pdev->subsystem_vendor == 0x1019) &&
464 (dev->pdev->subsystem_device == 0x2615)) {
465 if ((connector_type == DRM_MODE_CONNECTOR_DVID) &&
466 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
467 return true;
469 /* TOSHIBA Satellite L300D with ATI Mobility Radeon x1100
470 * (RS690M) sends data to i2c bus for a HDMI connector that
471 * is not implemented */
472 if ((dev->pdev->device == 0x791f) &&
473 (dev->pdev->subsystem_vendor == 0x1179) &&
474 (dev->pdev->subsystem_device == 0xff68)) {
475 if ((connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
476 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
477 return true;
480 /* Default: no EDID header probe required for DDC probing */
481 return false;
484 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
485 struct drm_connector *connector)
487 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
488 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
489 struct drm_display_mode *t, *mode;
491 /* If the EDID preferred mode doesn't match the native mode, use it */
492 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
493 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
494 if (mode->hdisplay != native_mode->hdisplay ||
495 mode->vdisplay != native_mode->vdisplay)
496 memcpy(native_mode, mode, sizeof(*mode));
500 /* Try to get native mode details from EDID if necessary */
501 if (!native_mode->clock) {
502 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
503 if (mode->hdisplay == native_mode->hdisplay &&
504 mode->vdisplay == native_mode->vdisplay) {
505 *native_mode = *mode;
506 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
507 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
508 break;
513 if (!native_mode->clock) {
514 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
515 radeon_encoder->rmx_type = RMX_OFF;
519 static int radeon_lvds_get_modes(struct drm_connector *connector)
521 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
522 struct drm_encoder *encoder;
523 int ret = 0;
524 struct drm_display_mode *mode;
526 if (radeon_connector->ddc_bus) {
527 ret = radeon_ddc_get_modes(radeon_connector);
528 if (ret > 0) {
529 encoder = radeon_best_single_encoder(connector);
530 if (encoder) {
531 radeon_fixup_lvds_native_mode(encoder, connector);
532 /* add scaled modes */
533 radeon_add_common_modes(encoder, connector);
535 return ret;
539 encoder = radeon_best_single_encoder(connector);
540 if (!encoder)
541 return 0;
543 /* we have no EDID modes */
544 mode = radeon_fp_native_mode(encoder);
545 if (mode) {
546 ret = 1;
547 drm_mode_probed_add(connector, mode);
548 /* add the width/height from vbios tables if available */
549 connector->display_info.width_mm = mode->width_mm;
550 connector->display_info.height_mm = mode->height_mm;
551 /* add scaled modes */
552 radeon_add_common_modes(encoder, connector);
555 return ret;
558 static int radeon_lvds_mode_valid(struct drm_connector *connector,
559 struct drm_display_mode *mode)
561 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
563 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
564 return MODE_PANEL;
566 if (encoder) {
567 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
568 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
570 /* AVIVO hardware supports downscaling modes larger than the panel
571 * to the panel size, but I'm not sure this is desirable.
573 if ((mode->hdisplay > native_mode->hdisplay) ||
574 (mode->vdisplay > native_mode->vdisplay))
575 return MODE_PANEL;
577 /* if scaling is disabled, block non-native modes */
578 if (radeon_encoder->rmx_type == RMX_OFF) {
579 if ((mode->hdisplay != native_mode->hdisplay) ||
580 (mode->vdisplay != native_mode->vdisplay))
581 return MODE_PANEL;
585 return MODE_OK;
588 static enum drm_connector_status
589 radeon_lvds_detect(struct drm_connector *connector, bool force)
591 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
592 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
593 enum drm_connector_status ret = connector_status_disconnected;
595 if (encoder) {
596 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
597 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
599 /* check if panel is valid */
600 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
601 ret = connector_status_connected;
605 /* check for edid as well */
606 if (radeon_connector->edid)
607 ret = connector_status_connected;
608 else {
609 if (radeon_connector->ddc_bus) {
610 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
611 &radeon_connector->ddc_bus->adapter);
612 if (radeon_connector->edid)
613 ret = connector_status_connected;
616 /* check acpi lid status ??? */
618 radeon_connector_update_scratch_regs(connector, ret);
619 return ret;
622 static void radeon_connector_destroy(struct drm_connector *connector)
624 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
626 if (radeon_connector->edid)
627 kfree(radeon_connector->edid);
628 kfree(radeon_connector->con_priv);
629 drm_sysfs_connector_remove(connector);
630 drm_connector_cleanup(connector);
631 kfree(connector);
634 static int radeon_lvds_set_property(struct drm_connector *connector,
635 struct drm_property *property,
636 uint64_t value)
638 struct drm_device *dev = connector->dev;
639 struct radeon_encoder *radeon_encoder;
640 enum radeon_rmx_type rmx_type;
642 DRM_DEBUG_KMS("\n");
643 if (property != dev->mode_config.scaling_mode_property)
644 return 0;
646 if (connector->encoder)
647 radeon_encoder = to_radeon_encoder(connector->encoder);
648 else {
649 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
650 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
653 switch (value) {
654 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
655 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
656 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
657 default:
658 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
660 if (radeon_encoder->rmx_type == rmx_type)
661 return 0;
663 radeon_encoder->rmx_type = rmx_type;
665 radeon_property_change_mode(&radeon_encoder->base);
666 return 0;
670 struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
671 .get_modes = radeon_lvds_get_modes,
672 .mode_valid = radeon_lvds_mode_valid,
673 .best_encoder = radeon_best_single_encoder,
676 struct drm_connector_funcs radeon_lvds_connector_funcs = {
677 .dpms = drm_helper_connector_dpms,
678 .detect = radeon_lvds_detect,
679 .fill_modes = drm_helper_probe_single_connector_modes,
680 .destroy = radeon_connector_destroy,
681 .set_property = radeon_lvds_set_property,
684 static int radeon_vga_get_modes(struct drm_connector *connector)
686 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
687 int ret;
689 ret = radeon_ddc_get_modes(radeon_connector);
691 return ret;
694 static int radeon_vga_mode_valid(struct drm_connector *connector,
695 struct drm_display_mode *mode)
697 struct drm_device *dev = connector->dev;
698 struct radeon_device *rdev = dev->dev_private;
700 /* XXX check mode bandwidth */
702 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
703 return MODE_CLOCK_HIGH;
705 return MODE_OK;
708 static enum drm_connector_status
709 radeon_vga_detect(struct drm_connector *connector, bool force)
711 struct drm_device *dev = connector->dev;
712 struct radeon_device *rdev = dev->dev_private;
713 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
714 struct drm_encoder *encoder;
715 struct drm_encoder_helper_funcs *encoder_funcs;
716 bool dret = false;
717 enum drm_connector_status ret = connector_status_disconnected;
719 encoder = radeon_best_single_encoder(connector);
720 if (!encoder)
721 ret = connector_status_disconnected;
723 if (radeon_connector->ddc_bus)
724 dret = radeon_ddc_probe(radeon_connector,
725 radeon_connector->requires_extended_probe);
726 if (dret) {
727 radeon_connector->detected_by_load = false;
728 if (radeon_connector->edid) {
729 kfree(radeon_connector->edid);
730 radeon_connector->edid = NULL;
732 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
734 if (!radeon_connector->edid) {
735 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
736 drm_get_connector_name(connector));
737 ret = connector_status_connected;
738 } else {
739 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
741 /* some oems have boards with separate digital and analog connectors
742 * with a shared ddc line (often vga + hdmi)
744 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
745 kfree(radeon_connector->edid);
746 radeon_connector->edid = NULL;
747 ret = connector_status_disconnected;
748 } else
749 ret = connector_status_connected;
751 } else {
753 /* if we aren't forcing don't do destructive polling */
754 if (!force) {
755 /* only return the previous status if we last
756 * detected a monitor via load.
758 if (radeon_connector->detected_by_load)
759 return connector->status;
760 else
761 return ret;
764 if (radeon_connector->dac_load_detect && encoder) {
765 encoder_funcs = encoder->helper_private;
766 ret = encoder_funcs->detect(encoder, connector);
767 if (ret == connector_status_connected)
768 radeon_connector->detected_by_load = true;
772 if (ret == connector_status_connected)
773 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
775 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
776 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
777 * by other means, assume the CRT is connected and use that EDID.
779 if ((!rdev->is_atom_bios) &&
780 (ret == connector_status_disconnected) &&
781 rdev->mode_info.bios_hardcoded_edid_size) {
782 ret = connector_status_connected;
785 radeon_connector_update_scratch_regs(connector, ret);
786 return ret;
789 struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
790 .get_modes = radeon_vga_get_modes,
791 .mode_valid = radeon_vga_mode_valid,
792 .best_encoder = radeon_best_single_encoder,
795 struct drm_connector_funcs radeon_vga_connector_funcs = {
796 .dpms = drm_helper_connector_dpms,
797 .detect = radeon_vga_detect,
798 .fill_modes = drm_helper_probe_single_connector_modes,
799 .destroy = radeon_connector_destroy,
800 .set_property = radeon_connector_set_property,
803 static int radeon_tv_get_modes(struct drm_connector *connector)
805 struct drm_device *dev = connector->dev;
806 struct radeon_device *rdev = dev->dev_private;
807 struct drm_display_mode *tv_mode;
808 struct drm_encoder *encoder;
810 encoder = radeon_best_single_encoder(connector);
811 if (!encoder)
812 return 0;
814 /* avivo chips can scale any mode */
815 if (rdev->family >= CHIP_RS600)
816 /* add scaled modes */
817 radeon_add_common_modes(encoder, connector);
818 else {
819 /* only 800x600 is supported right now on pre-avivo chips */
820 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
821 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
822 drm_mode_probed_add(connector, tv_mode);
824 return 1;
827 static int radeon_tv_mode_valid(struct drm_connector *connector,
828 struct drm_display_mode *mode)
830 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
831 return MODE_CLOCK_RANGE;
832 return MODE_OK;
835 static enum drm_connector_status
836 radeon_tv_detect(struct drm_connector *connector, bool force)
838 struct drm_encoder *encoder;
839 struct drm_encoder_helper_funcs *encoder_funcs;
840 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
841 enum drm_connector_status ret = connector_status_disconnected;
843 if (!radeon_connector->dac_load_detect)
844 return ret;
846 encoder = radeon_best_single_encoder(connector);
847 if (!encoder)
848 ret = connector_status_disconnected;
849 else {
850 encoder_funcs = encoder->helper_private;
851 ret = encoder_funcs->detect(encoder, connector);
853 if (ret == connector_status_connected)
854 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
855 radeon_connector_update_scratch_regs(connector, ret);
856 return ret;
859 struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
860 .get_modes = radeon_tv_get_modes,
861 .mode_valid = radeon_tv_mode_valid,
862 .best_encoder = radeon_best_single_encoder,
865 struct drm_connector_funcs radeon_tv_connector_funcs = {
866 .dpms = drm_helper_connector_dpms,
867 .detect = radeon_tv_detect,
868 .fill_modes = drm_helper_probe_single_connector_modes,
869 .destroy = radeon_connector_destroy,
870 .set_property = radeon_connector_set_property,
873 static int radeon_dvi_get_modes(struct drm_connector *connector)
875 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
876 int ret;
878 ret = radeon_ddc_get_modes(radeon_connector);
879 return ret;
883 * DVI is complicated
884 * Do a DDC probe, if DDC probe passes, get the full EDID so
885 * we can do analog/digital monitor detection at this point.
886 * If the monitor is an analog monitor or we got no DDC,
887 * we need to find the DAC encoder object for this connector.
888 * If we got no DDC, we do load detection on the DAC encoder object.
889 * If we got analog DDC or load detection passes on the DAC encoder
890 * we have to check if this analog encoder is shared with anyone else (TV)
891 * if its shared we have to set the other connector to disconnected.
893 static enum drm_connector_status
894 radeon_dvi_detect(struct drm_connector *connector, bool force)
896 struct drm_device *dev = connector->dev;
897 struct radeon_device *rdev = dev->dev_private;
898 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
899 struct drm_encoder *encoder = NULL;
900 struct drm_encoder_helper_funcs *encoder_funcs;
901 struct drm_mode_object *obj;
902 int i;
903 enum drm_connector_status ret = connector_status_disconnected;
904 bool dret = false;
906 if (radeon_connector->ddc_bus)
907 dret = radeon_ddc_probe(radeon_connector,
908 radeon_connector->requires_extended_probe);
909 if (dret) {
910 radeon_connector->detected_by_load = false;
911 if (radeon_connector->edid) {
912 kfree(radeon_connector->edid);
913 radeon_connector->edid = NULL;
915 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
917 if (!radeon_connector->edid) {
918 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
919 drm_get_connector_name(connector));
920 /* rs690 seems to have a problem with connectors not existing and always
921 * return a block of 0's. If we see this just stop polling on this output */
922 if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) && radeon_connector->base.null_edid_counter) {
923 ret = connector_status_disconnected;
924 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n", drm_get_connector_name(connector));
925 radeon_connector->ddc_bus = NULL;
927 } else {
928 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
930 /* some oems have boards with separate digital and analog connectors
931 * with a shared ddc line (often vga + hdmi)
933 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
934 kfree(radeon_connector->edid);
935 radeon_connector->edid = NULL;
936 ret = connector_status_disconnected;
937 } else
938 ret = connector_status_connected;
940 /* This gets complicated. We have boards with VGA + HDMI with a
941 * shared DDC line and we have boards with DVI-D + HDMI with a shared
942 * DDC line. The latter is more complex because with DVI<->HDMI adapters
943 * you don't really know what's connected to which port as both are digital.
945 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
946 struct drm_connector *list_connector;
947 struct radeon_connector *list_radeon_connector;
948 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
949 if (connector == list_connector)
950 continue;
951 list_radeon_connector = to_radeon_connector(list_connector);
952 if (list_radeon_connector->shared_ddc &&
953 (list_radeon_connector->ddc_bus->rec.i2c_id ==
954 radeon_connector->ddc_bus->rec.i2c_id)) {
955 /* cases where both connectors are digital */
956 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
957 /* hpd is our only option in this case */
958 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
959 kfree(radeon_connector->edid);
960 radeon_connector->edid = NULL;
961 ret = connector_status_disconnected;
970 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
971 goto out;
973 /* DVI-D and HDMI-A are digital only */
974 if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
975 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
976 goto out;
978 /* if we aren't forcing don't do destructive polling */
979 if (!force) {
980 /* only return the previous status if we last
981 * detected a monitor via load.
983 if (radeon_connector->detected_by_load)
984 ret = connector->status;
985 goto out;
988 /* find analog encoder */
989 if (radeon_connector->dac_load_detect) {
990 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
991 if (connector->encoder_ids[i] == 0)
992 break;
994 obj = drm_mode_object_find(connector->dev,
995 connector->encoder_ids[i],
996 DRM_MODE_OBJECT_ENCODER);
997 if (!obj)
998 continue;
1000 encoder = obj_to_encoder(obj);
1002 encoder_funcs = encoder->helper_private;
1003 if (encoder_funcs->detect) {
1004 if (ret != connector_status_connected) {
1005 ret = encoder_funcs->detect(encoder, connector);
1006 if (ret == connector_status_connected) {
1007 radeon_connector->use_digital = false;
1008 radeon_connector->detected_by_load = true;
1011 break;
1016 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
1017 encoder) {
1018 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1021 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1022 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1023 * by other means, assume the DFP is connected and use that EDID. In most
1024 * cases the DVI port is actually a virtual KVM port connected to the service
1025 * processor.
1027 if ((!rdev->is_atom_bios) &&
1028 (ret == connector_status_disconnected) &&
1029 rdev->mode_info.bios_hardcoded_edid_size) {
1030 radeon_connector->use_digital = true;
1031 ret = connector_status_connected;
1034 out:
1035 /* updated in get modes as well since we need to know if it's analog or digital */
1036 radeon_connector_update_scratch_regs(connector, ret);
1037 return ret;
1040 /* okay need to be smart in here about which encoder to pick */
1041 struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
1043 int enc_id = connector->encoder_ids[0];
1044 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1045 struct drm_mode_object *obj;
1046 struct drm_encoder *encoder;
1047 int i;
1048 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1049 if (connector->encoder_ids[i] == 0)
1050 break;
1052 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1053 if (!obj)
1054 continue;
1056 encoder = obj_to_encoder(obj);
1058 if (radeon_connector->use_digital == true) {
1059 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
1060 return encoder;
1061 } else {
1062 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
1063 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
1064 return encoder;
1068 /* see if we have a default encoder TODO */
1070 /* then check use digitial */
1071 /* pick the first one */
1072 if (enc_id) {
1073 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
1074 if (!obj)
1075 return NULL;
1076 encoder = obj_to_encoder(obj);
1077 return encoder;
1079 return NULL;
1082 static void radeon_dvi_force(struct drm_connector *connector)
1084 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1085 if (connector->force == DRM_FORCE_ON)
1086 radeon_connector->use_digital = false;
1087 if (connector->force == DRM_FORCE_ON_DIGITAL)
1088 radeon_connector->use_digital = true;
1091 static int radeon_dvi_mode_valid(struct drm_connector *connector,
1092 struct drm_display_mode *mode)
1094 struct drm_device *dev = connector->dev;
1095 struct radeon_device *rdev = dev->dev_private;
1096 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1098 /* XXX check mode bandwidth */
1100 /* clocks over 135 MHz have heat issues with DVI on RV100 */
1101 if (radeon_connector->use_digital &&
1102 (rdev->family == CHIP_RV100) &&
1103 (mode->clock > 135000))
1104 return MODE_CLOCK_HIGH;
1106 if (radeon_connector->use_digital && (mode->clock > 165000)) {
1107 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1108 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1109 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1110 return MODE_OK;
1111 else if (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_A) {
1112 if (ASIC_IS_DCE3(rdev)) {
1113 /* HDMI 1.3+ supports max clock of 340 Mhz */
1114 if (mode->clock > 340000)
1115 return MODE_CLOCK_HIGH;
1116 else
1117 return MODE_OK;
1118 } else
1119 return MODE_CLOCK_HIGH;
1120 } else
1121 return MODE_CLOCK_HIGH;
1124 /* check against the max pixel clock */
1125 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1126 return MODE_CLOCK_HIGH;
1128 return MODE_OK;
1131 struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
1132 .get_modes = radeon_dvi_get_modes,
1133 .mode_valid = radeon_dvi_mode_valid,
1134 .best_encoder = radeon_dvi_encoder,
1137 struct drm_connector_funcs radeon_dvi_connector_funcs = {
1138 .dpms = drm_helper_connector_dpms,
1139 .detect = radeon_dvi_detect,
1140 .fill_modes = drm_helper_probe_single_connector_modes,
1141 .set_property = radeon_connector_set_property,
1142 .destroy = radeon_connector_destroy,
1143 .force = radeon_dvi_force,
1146 static void radeon_dp_connector_destroy(struct drm_connector *connector)
1148 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1149 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1151 if (radeon_connector->edid)
1152 kfree(radeon_connector->edid);
1153 if (radeon_dig_connector->dp_i2c_bus)
1154 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
1155 kfree(radeon_connector->con_priv);
1156 drm_sysfs_connector_remove(connector);
1157 drm_connector_cleanup(connector);
1158 kfree(connector);
1161 static int radeon_dp_get_modes(struct drm_connector *connector)
1163 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1164 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1165 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1166 int ret;
1168 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1169 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1170 struct drm_display_mode *mode;
1172 if (!radeon_dig_connector->edp_on)
1173 atombios_set_edp_panel_power(connector,
1174 ATOM_TRANSMITTER_ACTION_POWER_ON);
1175 ret = radeon_ddc_get_modes(radeon_connector);
1176 if (!radeon_dig_connector->edp_on)
1177 atombios_set_edp_panel_power(connector,
1178 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1180 if (ret > 0) {
1181 if (encoder) {
1182 radeon_fixup_lvds_native_mode(encoder, connector);
1183 /* add scaled modes */
1184 radeon_add_common_modes(encoder, connector);
1186 return ret;
1189 encoder = radeon_best_single_encoder(connector);
1190 if (!encoder)
1191 return 0;
1193 /* we have no EDID modes */
1194 mode = radeon_fp_native_mode(encoder);
1195 if (mode) {
1196 ret = 1;
1197 drm_mode_probed_add(connector, mode);
1198 /* add the width/height from vbios tables if available */
1199 connector->display_info.width_mm = mode->width_mm;
1200 connector->display_info.height_mm = mode->height_mm;
1201 /* add scaled modes */
1202 radeon_add_common_modes(encoder, connector);
1204 } else {
1205 /* need to setup ddc on the bridge */
1206 if (radeon_connector_encoder_is_dp_bridge(connector)) {
1207 if (encoder)
1208 radeon_atom_ext_encoder_setup_ddc(encoder);
1210 ret = radeon_ddc_get_modes(radeon_connector);
1213 return ret;
1216 bool radeon_connector_encoder_is_dp_bridge(struct drm_connector *connector)
1218 struct drm_mode_object *obj;
1219 struct drm_encoder *encoder;
1220 struct radeon_encoder *radeon_encoder;
1221 int i;
1222 bool found = false;
1224 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1225 if (connector->encoder_ids[i] == 0)
1226 break;
1228 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1229 if (!obj)
1230 continue;
1232 encoder = obj_to_encoder(obj);
1233 radeon_encoder = to_radeon_encoder(encoder);
1235 switch (radeon_encoder->encoder_id) {
1236 case ENCODER_OBJECT_ID_TRAVIS:
1237 case ENCODER_OBJECT_ID_NUTMEG:
1238 found = true;
1239 break;
1240 default:
1241 break;
1245 return found;
1248 bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
1250 struct drm_mode_object *obj;
1251 struct drm_encoder *encoder;
1252 struct radeon_encoder *radeon_encoder;
1253 int i;
1254 bool found = false;
1256 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1257 if (connector->encoder_ids[i] == 0)
1258 break;
1260 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1261 if (!obj)
1262 continue;
1264 encoder = obj_to_encoder(obj);
1265 radeon_encoder = to_radeon_encoder(encoder);
1266 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1267 found = true;
1270 return found;
1273 bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1275 struct drm_device *dev = connector->dev;
1276 struct radeon_device *rdev = dev->dev_private;
1278 if (ASIC_IS_DCE5(rdev) &&
1279 (rdev->clock.dp_extclk >= 53900) &&
1280 radeon_connector_encoder_is_hbr2(connector)) {
1281 return true;
1284 return false;
1287 static enum drm_connector_status
1288 radeon_dp_detect(struct drm_connector *connector, bool force)
1290 struct drm_device *dev = connector->dev;
1291 struct radeon_device *rdev = dev->dev_private;
1292 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1293 enum drm_connector_status ret = connector_status_disconnected;
1294 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1295 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1297 if (radeon_connector->edid) {
1298 kfree(radeon_connector->edid);
1299 radeon_connector->edid = NULL;
1302 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1303 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1304 if (encoder) {
1305 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1306 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1308 /* check if panel is valid */
1309 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1310 ret = connector_status_connected;
1312 /* eDP is always DP */
1313 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1314 if (!radeon_dig_connector->edp_on)
1315 atombios_set_edp_panel_power(connector,
1316 ATOM_TRANSMITTER_ACTION_POWER_ON);
1317 if (radeon_dp_getdpcd(radeon_connector))
1318 ret = connector_status_connected;
1319 if (!radeon_dig_connector->edp_on)
1320 atombios_set_edp_panel_power(connector,
1321 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1322 } else if (radeon_connector_encoder_is_dp_bridge(connector)) {
1323 /* DP bridges are always DP */
1324 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1325 /* get the DPCD from the bridge */
1326 radeon_dp_getdpcd(radeon_connector);
1328 if (encoder) {
1329 /* setup ddc on the bridge */
1330 radeon_atom_ext_encoder_setup_ddc(encoder);
1331 if (radeon_ddc_probe(radeon_connector,
1332 radeon_connector->requires_extended_probe)) /* try DDC */
1333 ret = connector_status_connected;
1334 else if (radeon_connector->dac_load_detect) { /* try load detection */
1335 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
1336 ret = encoder_funcs->detect(encoder, connector);
1339 } else {
1340 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
1341 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1342 ret = connector_status_connected;
1343 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
1344 radeon_dp_getdpcd(radeon_connector);
1345 } else {
1346 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1347 if (radeon_dp_getdpcd(radeon_connector))
1348 ret = connector_status_connected;
1349 } else {
1350 if (radeon_ddc_probe(radeon_connector,
1351 radeon_connector->requires_extended_probe))
1352 ret = connector_status_connected;
1357 radeon_connector_update_scratch_regs(connector, ret);
1358 return ret;
1361 static int radeon_dp_mode_valid(struct drm_connector *connector,
1362 struct drm_display_mode *mode)
1364 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1365 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1367 /* XXX check mode bandwidth */
1369 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1370 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1371 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1373 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1374 return MODE_PANEL;
1376 if (encoder) {
1377 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1378 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1380 /* AVIVO hardware supports downscaling modes larger than the panel
1381 * to the panel size, but I'm not sure this is desirable.
1383 if ((mode->hdisplay > native_mode->hdisplay) ||
1384 (mode->vdisplay > native_mode->vdisplay))
1385 return MODE_PANEL;
1387 /* if scaling is disabled, block non-native modes */
1388 if (radeon_encoder->rmx_type == RMX_OFF) {
1389 if ((mode->hdisplay != native_mode->hdisplay) ||
1390 (mode->vdisplay != native_mode->vdisplay))
1391 return MODE_PANEL;
1394 return MODE_OK;
1395 } else {
1396 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1397 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
1398 return radeon_dp_mode_valid_helper(connector, mode);
1399 else
1400 return MODE_OK;
1404 struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1405 .get_modes = radeon_dp_get_modes,
1406 .mode_valid = radeon_dp_mode_valid,
1407 .best_encoder = radeon_dvi_encoder,
1410 struct drm_connector_funcs radeon_dp_connector_funcs = {
1411 .dpms = drm_helper_connector_dpms,
1412 .detect = radeon_dp_detect,
1413 .fill_modes = drm_helper_probe_single_connector_modes,
1414 .set_property = radeon_connector_set_property,
1415 .destroy = radeon_dp_connector_destroy,
1416 .force = radeon_dvi_force,
1419 void
1420 radeon_add_atom_connector(struct drm_device *dev,
1421 uint32_t connector_id,
1422 uint32_t supported_device,
1423 int connector_type,
1424 struct radeon_i2c_bus_rec *i2c_bus,
1425 uint32_t igp_lane_info,
1426 uint16_t connector_object_id,
1427 struct radeon_hpd *hpd,
1428 struct radeon_router *router)
1430 struct radeon_device *rdev = dev->dev_private;
1431 struct drm_connector *connector;
1432 struct radeon_connector *radeon_connector;
1433 struct radeon_connector_atom_dig *radeon_dig_connector;
1434 struct drm_encoder *encoder;
1435 struct radeon_encoder *radeon_encoder;
1436 uint32_t subpixel_order = SubPixelNone;
1437 bool shared_ddc = false;
1438 bool is_dp_bridge = false;
1440 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1441 return;
1443 /* if the user selected tv=0 don't try and add the connector */
1444 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1445 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1446 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1447 (radeon_tv == 0))
1448 return;
1450 /* see if we already added it */
1451 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1452 radeon_connector = to_radeon_connector(connector);
1453 if (radeon_connector->connector_id == connector_id) {
1454 radeon_connector->devices |= supported_device;
1455 return;
1457 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1458 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1459 radeon_connector->shared_ddc = true;
1460 shared_ddc = true;
1462 if (radeon_connector->router_bus && router->ddc_valid &&
1463 (radeon_connector->router.router_id == router->router_id)) {
1464 radeon_connector->shared_ddc = false;
1465 shared_ddc = false;
1470 /* check if it's a dp bridge */
1471 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1472 radeon_encoder = to_radeon_encoder(encoder);
1473 if (radeon_encoder->devices & supported_device) {
1474 switch (radeon_encoder->encoder_id) {
1475 case ENCODER_OBJECT_ID_TRAVIS:
1476 case ENCODER_OBJECT_ID_NUTMEG:
1477 is_dp_bridge = true;
1478 break;
1479 default:
1480 break;
1485 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1486 if (!radeon_connector)
1487 return;
1489 connector = &radeon_connector->base;
1491 radeon_connector->connector_id = connector_id;
1492 radeon_connector->devices = supported_device;
1493 radeon_connector->shared_ddc = shared_ddc;
1494 radeon_connector->connector_object_id = connector_object_id;
1495 radeon_connector->hpd = *hpd;
1496 radeon_connector->requires_extended_probe =
1497 radeon_connector_needs_extended_probe(rdev, supported_device,
1498 connector_type);
1499 radeon_connector->router = *router;
1500 if (router->ddc_valid || router->cd_valid) {
1501 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1502 if (!radeon_connector->router_bus)
1503 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
1506 if (is_dp_bridge) {
1507 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1508 if (!radeon_dig_connector)
1509 goto failed;
1510 radeon_dig_connector->igp_lane_info = igp_lane_info;
1511 radeon_connector->con_priv = radeon_dig_connector;
1512 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1513 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1514 if (i2c_bus->valid) {
1515 /* add DP i2c bus */
1516 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1517 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1518 else
1519 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1520 if (!radeon_dig_connector->dp_i2c_bus)
1521 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1522 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1523 if (!radeon_connector->ddc_bus)
1524 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1526 switch (connector_type) {
1527 case DRM_MODE_CONNECTOR_VGA:
1528 case DRM_MODE_CONNECTOR_DVIA:
1529 default:
1530 connector->interlace_allowed = true;
1531 connector->doublescan_allowed = true;
1532 radeon_connector->dac_load_detect = true;
1533 drm_connector_attach_property(&radeon_connector->base,
1534 rdev->mode_info.load_detect_property,
1536 break;
1537 case DRM_MODE_CONNECTOR_DVII:
1538 case DRM_MODE_CONNECTOR_DVID:
1539 case DRM_MODE_CONNECTOR_HDMIA:
1540 case DRM_MODE_CONNECTOR_HDMIB:
1541 case DRM_MODE_CONNECTOR_DisplayPort:
1542 drm_connector_attach_property(&radeon_connector->base,
1543 rdev->mode_info.underscan_property,
1544 UNDERSCAN_OFF);
1545 drm_connector_attach_property(&radeon_connector->base,
1546 rdev->mode_info.underscan_hborder_property,
1548 drm_connector_attach_property(&radeon_connector->base,
1549 rdev->mode_info.underscan_vborder_property,
1551 subpixel_order = SubPixelHorizontalRGB;
1552 connector->interlace_allowed = true;
1553 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1554 connector->doublescan_allowed = true;
1555 else
1556 connector->doublescan_allowed = false;
1557 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1558 radeon_connector->dac_load_detect = true;
1559 drm_connector_attach_property(&radeon_connector->base,
1560 rdev->mode_info.load_detect_property,
1563 break;
1564 case DRM_MODE_CONNECTOR_LVDS:
1565 case DRM_MODE_CONNECTOR_eDP:
1566 drm_connector_attach_property(&radeon_connector->base,
1567 dev->mode_config.scaling_mode_property,
1568 DRM_MODE_SCALE_FULLSCREEN);
1569 subpixel_order = SubPixelHorizontalRGB;
1570 connector->interlace_allowed = false;
1571 connector->doublescan_allowed = false;
1572 break;
1574 } else {
1575 switch (connector_type) {
1576 case DRM_MODE_CONNECTOR_VGA:
1577 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1578 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1579 if (i2c_bus->valid) {
1580 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1581 if (!radeon_connector->ddc_bus)
1582 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1584 radeon_connector->dac_load_detect = true;
1585 drm_connector_attach_property(&radeon_connector->base,
1586 rdev->mode_info.load_detect_property,
1588 /* no HPD on analog connectors */
1589 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1590 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1591 connector->interlace_allowed = true;
1592 connector->doublescan_allowed = true;
1593 break;
1594 case DRM_MODE_CONNECTOR_DVIA:
1595 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1596 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1597 if (i2c_bus->valid) {
1598 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1599 if (!radeon_connector->ddc_bus)
1600 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1602 radeon_connector->dac_load_detect = true;
1603 drm_connector_attach_property(&radeon_connector->base,
1604 rdev->mode_info.load_detect_property,
1606 /* no HPD on analog connectors */
1607 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1608 connector->interlace_allowed = true;
1609 connector->doublescan_allowed = true;
1610 break;
1611 case DRM_MODE_CONNECTOR_DVII:
1612 case DRM_MODE_CONNECTOR_DVID:
1613 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1614 if (!radeon_dig_connector)
1615 goto failed;
1616 radeon_dig_connector->igp_lane_info = igp_lane_info;
1617 radeon_connector->con_priv = radeon_dig_connector;
1618 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1619 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1620 if (i2c_bus->valid) {
1621 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1622 if (!radeon_connector->ddc_bus)
1623 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1625 subpixel_order = SubPixelHorizontalRGB;
1626 drm_connector_attach_property(&radeon_connector->base,
1627 rdev->mode_info.coherent_mode_property,
1629 if (ASIC_IS_AVIVO(rdev)) {
1630 drm_connector_attach_property(&radeon_connector->base,
1631 rdev->mode_info.underscan_property,
1632 UNDERSCAN_OFF);
1633 drm_connector_attach_property(&radeon_connector->base,
1634 rdev->mode_info.underscan_hborder_property,
1636 drm_connector_attach_property(&radeon_connector->base,
1637 rdev->mode_info.underscan_vborder_property,
1640 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1641 radeon_connector->dac_load_detect = true;
1642 drm_connector_attach_property(&radeon_connector->base,
1643 rdev->mode_info.load_detect_property,
1646 connector->interlace_allowed = true;
1647 if (connector_type == DRM_MODE_CONNECTOR_DVII)
1648 connector->doublescan_allowed = true;
1649 else
1650 connector->doublescan_allowed = false;
1651 break;
1652 case DRM_MODE_CONNECTOR_HDMIA:
1653 case DRM_MODE_CONNECTOR_HDMIB:
1654 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1655 if (!radeon_dig_connector)
1656 goto failed;
1657 radeon_dig_connector->igp_lane_info = igp_lane_info;
1658 radeon_connector->con_priv = radeon_dig_connector;
1659 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1660 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1661 if (i2c_bus->valid) {
1662 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1663 if (!radeon_connector->ddc_bus)
1664 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1666 drm_connector_attach_property(&radeon_connector->base,
1667 rdev->mode_info.coherent_mode_property,
1669 if (ASIC_IS_AVIVO(rdev)) {
1670 drm_connector_attach_property(&radeon_connector->base,
1671 rdev->mode_info.underscan_property,
1672 UNDERSCAN_OFF);
1673 drm_connector_attach_property(&radeon_connector->base,
1674 rdev->mode_info.underscan_hborder_property,
1676 drm_connector_attach_property(&radeon_connector->base,
1677 rdev->mode_info.underscan_vborder_property,
1680 subpixel_order = SubPixelHorizontalRGB;
1681 connector->interlace_allowed = true;
1682 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1683 connector->doublescan_allowed = true;
1684 else
1685 connector->doublescan_allowed = false;
1686 break;
1687 case DRM_MODE_CONNECTOR_DisplayPort:
1688 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1689 if (!radeon_dig_connector)
1690 goto failed;
1691 radeon_dig_connector->igp_lane_info = igp_lane_info;
1692 radeon_connector->con_priv = radeon_dig_connector;
1693 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1694 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1695 if (i2c_bus->valid) {
1696 /* add DP i2c bus */
1697 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1698 if (!radeon_dig_connector->dp_i2c_bus)
1699 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1700 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1701 if (!radeon_connector->ddc_bus)
1702 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1704 subpixel_order = SubPixelHorizontalRGB;
1705 drm_connector_attach_property(&radeon_connector->base,
1706 rdev->mode_info.coherent_mode_property,
1708 if (ASIC_IS_AVIVO(rdev)) {
1709 drm_connector_attach_property(&radeon_connector->base,
1710 rdev->mode_info.underscan_property,
1711 UNDERSCAN_OFF);
1712 drm_connector_attach_property(&radeon_connector->base,
1713 rdev->mode_info.underscan_hborder_property,
1715 drm_connector_attach_property(&radeon_connector->base,
1716 rdev->mode_info.underscan_vborder_property,
1719 connector->interlace_allowed = true;
1720 /* in theory with a DP to VGA converter... */
1721 connector->doublescan_allowed = false;
1722 break;
1723 case DRM_MODE_CONNECTOR_eDP:
1724 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1725 if (!radeon_dig_connector)
1726 goto failed;
1727 radeon_dig_connector->igp_lane_info = igp_lane_info;
1728 radeon_connector->con_priv = radeon_dig_connector;
1729 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1730 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1731 if (i2c_bus->valid) {
1732 /* add DP i2c bus */
1733 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1734 if (!radeon_dig_connector->dp_i2c_bus)
1735 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1736 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1737 if (!radeon_connector->ddc_bus)
1738 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1740 drm_connector_attach_property(&radeon_connector->base,
1741 dev->mode_config.scaling_mode_property,
1742 DRM_MODE_SCALE_FULLSCREEN);
1743 subpixel_order = SubPixelHorizontalRGB;
1744 connector->interlace_allowed = false;
1745 connector->doublescan_allowed = false;
1746 break;
1747 case DRM_MODE_CONNECTOR_SVIDEO:
1748 case DRM_MODE_CONNECTOR_Composite:
1749 case DRM_MODE_CONNECTOR_9PinDIN:
1750 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1751 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1752 radeon_connector->dac_load_detect = true;
1753 drm_connector_attach_property(&radeon_connector->base,
1754 rdev->mode_info.load_detect_property,
1756 drm_connector_attach_property(&radeon_connector->base,
1757 rdev->mode_info.tv_std_property,
1758 radeon_atombios_get_tv_info(rdev));
1759 /* no HPD on analog connectors */
1760 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1761 connector->interlace_allowed = false;
1762 connector->doublescan_allowed = false;
1763 break;
1764 case DRM_MODE_CONNECTOR_LVDS:
1765 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1766 if (!radeon_dig_connector)
1767 goto failed;
1768 radeon_dig_connector->igp_lane_info = igp_lane_info;
1769 radeon_connector->con_priv = radeon_dig_connector;
1770 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1771 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1772 if (i2c_bus->valid) {
1773 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1774 if (!radeon_connector->ddc_bus)
1775 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1777 drm_connector_attach_property(&radeon_connector->base,
1778 dev->mode_config.scaling_mode_property,
1779 DRM_MODE_SCALE_FULLSCREEN);
1780 subpixel_order = SubPixelHorizontalRGB;
1781 connector->interlace_allowed = false;
1782 connector->doublescan_allowed = false;
1783 break;
1787 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
1788 if (i2c_bus->valid)
1789 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1790 } else
1791 connector->polled = DRM_CONNECTOR_POLL_HPD;
1793 connector->display_info.subpixel_order = subpixel_order;
1794 drm_sysfs_connector_add(connector);
1795 return;
1797 failed:
1798 drm_connector_cleanup(connector);
1799 kfree(connector);
1802 void
1803 radeon_add_legacy_connector(struct drm_device *dev,
1804 uint32_t connector_id,
1805 uint32_t supported_device,
1806 int connector_type,
1807 struct radeon_i2c_bus_rec *i2c_bus,
1808 uint16_t connector_object_id,
1809 struct radeon_hpd *hpd)
1811 struct radeon_device *rdev = dev->dev_private;
1812 struct drm_connector *connector;
1813 struct radeon_connector *radeon_connector;
1814 uint32_t subpixel_order = SubPixelNone;
1816 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1817 return;
1819 /* if the user selected tv=0 don't try and add the connector */
1820 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1821 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1822 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1823 (radeon_tv == 0))
1824 return;
1826 /* see if we already added it */
1827 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1828 radeon_connector = to_radeon_connector(connector);
1829 if (radeon_connector->connector_id == connector_id) {
1830 radeon_connector->devices |= supported_device;
1831 return;
1835 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1836 if (!radeon_connector)
1837 return;
1839 connector = &radeon_connector->base;
1841 radeon_connector->connector_id = connector_id;
1842 radeon_connector->devices = supported_device;
1843 radeon_connector->connector_object_id = connector_object_id;
1844 radeon_connector->hpd = *hpd;
1845 radeon_connector->requires_extended_probe =
1846 radeon_connector_needs_extended_probe(rdev, supported_device,
1847 connector_type);
1848 switch (connector_type) {
1849 case DRM_MODE_CONNECTOR_VGA:
1850 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1851 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1852 if (i2c_bus->valid) {
1853 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1854 if (!radeon_connector->ddc_bus)
1855 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1857 radeon_connector->dac_load_detect = true;
1858 drm_connector_attach_property(&radeon_connector->base,
1859 rdev->mode_info.load_detect_property,
1861 /* no HPD on analog connectors */
1862 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1863 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1864 connector->interlace_allowed = true;
1865 connector->doublescan_allowed = true;
1866 break;
1867 case DRM_MODE_CONNECTOR_DVIA:
1868 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1869 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1870 if (i2c_bus->valid) {
1871 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1872 if (!radeon_connector->ddc_bus)
1873 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1875 radeon_connector->dac_load_detect = true;
1876 drm_connector_attach_property(&radeon_connector->base,
1877 rdev->mode_info.load_detect_property,
1879 /* no HPD on analog connectors */
1880 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1881 connector->interlace_allowed = true;
1882 connector->doublescan_allowed = true;
1883 break;
1884 case DRM_MODE_CONNECTOR_DVII:
1885 case DRM_MODE_CONNECTOR_DVID:
1886 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1887 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1888 if (i2c_bus->valid) {
1889 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1890 if (!radeon_connector->ddc_bus)
1891 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1893 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1894 radeon_connector->dac_load_detect = true;
1895 drm_connector_attach_property(&radeon_connector->base,
1896 rdev->mode_info.load_detect_property,
1899 subpixel_order = SubPixelHorizontalRGB;
1900 connector->interlace_allowed = true;
1901 if (connector_type == DRM_MODE_CONNECTOR_DVII)
1902 connector->doublescan_allowed = true;
1903 else
1904 connector->doublescan_allowed = false;
1905 break;
1906 case DRM_MODE_CONNECTOR_SVIDEO:
1907 case DRM_MODE_CONNECTOR_Composite:
1908 case DRM_MODE_CONNECTOR_9PinDIN:
1909 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1910 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1911 radeon_connector->dac_load_detect = true;
1912 /* RS400,RC410,RS480 chipset seems to report a lot
1913 * of false positive on load detect, we haven't yet
1914 * found a way to make load detect reliable on those
1915 * chipset, thus just disable it for TV.
1917 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1918 radeon_connector->dac_load_detect = false;
1919 drm_connector_attach_property(&radeon_connector->base,
1920 rdev->mode_info.load_detect_property,
1921 radeon_connector->dac_load_detect);
1922 drm_connector_attach_property(&radeon_connector->base,
1923 rdev->mode_info.tv_std_property,
1924 radeon_combios_get_tv_info(rdev));
1925 /* no HPD on analog connectors */
1926 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1927 connector->interlace_allowed = false;
1928 connector->doublescan_allowed = false;
1929 break;
1930 case DRM_MODE_CONNECTOR_LVDS:
1931 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1932 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1933 if (i2c_bus->valid) {
1934 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1935 if (!radeon_connector->ddc_bus)
1936 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1938 drm_connector_attach_property(&radeon_connector->base,
1939 dev->mode_config.scaling_mode_property,
1940 DRM_MODE_SCALE_FULLSCREEN);
1941 subpixel_order = SubPixelHorizontalRGB;
1942 connector->interlace_allowed = false;
1943 connector->doublescan_allowed = false;
1944 break;
1947 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
1948 if (i2c_bus->valid)
1949 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1950 } else
1951 connector->polled = DRM_CONNECTOR_POLL_HPD;
1952 connector->display_info.subpixel_order = subpixel_order;
1953 drm_sysfs_connector_add(connector);
1954 if (connector_type == DRM_MODE_CONNECTOR_LVDS) {
1955 struct drm_encoder *drm_encoder;
1957 list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) {
1958 struct radeon_encoder *radeon_encoder;
1960 radeon_encoder = to_radeon_encoder(drm_encoder);
1961 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_LVDS)
1962 radeon_legacy_backlight_init(radeon_encoder, connector);