Linux 2.6.33-rc6
[cris-mirror.git] / drivers / gpu / drm / radeon / radeon_connectors.c
blob55266416fa478821db5f1b6360e285aa8138ca1c
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 void radeon_connector_hotplug(struct drm_connector *connector)
45 struct drm_device *dev = connector->dev;
46 struct radeon_device *rdev = dev->dev_private;
47 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
49 if (radeon_connector->hpd.hpd != RADEON_HPD_NONE)
50 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
52 if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
53 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
54 if ((radeon_dp_getsinktype(radeon_connector) == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
55 (radeon_dp_getsinktype(radeon_connector) == CONNECTOR_OBJECT_ID_eDP)) {
56 if (radeon_dp_needs_link_train(radeon_connector)) {
57 if (connector->encoder)
58 dp_link_train(connector->encoder, connector);
65 static void radeon_property_change_mode(struct drm_encoder *encoder)
67 struct drm_crtc *crtc = encoder->crtc;
69 if (crtc && crtc->enabled) {
70 drm_crtc_helper_set_mode(crtc, &crtc->mode,
71 crtc->x, crtc->y, crtc->fb);
74 static void
75 radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
77 struct drm_device *dev = connector->dev;
78 struct radeon_device *rdev = dev->dev_private;
79 struct drm_encoder *best_encoder = NULL;
80 struct drm_encoder *encoder = NULL;
81 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
82 struct drm_mode_object *obj;
83 bool connected;
84 int i;
86 best_encoder = connector_funcs->best_encoder(connector);
88 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
89 if (connector->encoder_ids[i] == 0)
90 break;
92 obj = drm_mode_object_find(connector->dev,
93 connector->encoder_ids[i],
94 DRM_MODE_OBJECT_ENCODER);
95 if (!obj)
96 continue;
98 encoder = obj_to_encoder(obj);
100 if ((encoder == best_encoder) && (status == connector_status_connected))
101 connected = true;
102 else
103 connected = false;
105 if (rdev->is_atom_bios)
106 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
107 else
108 radeon_combios_connected_scratch_regs(connector, encoder, connected);
113 struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
115 struct drm_mode_object *obj;
116 struct drm_encoder *encoder;
117 int i;
119 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
120 if (connector->encoder_ids[i] == 0)
121 break;
123 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
124 if (!obj)
125 continue;
127 encoder = obj_to_encoder(obj);
128 if (encoder->encoder_type == encoder_type)
129 return encoder;
131 return NULL;
134 struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
136 int enc_id = connector->encoder_ids[0];
137 struct drm_mode_object *obj;
138 struct drm_encoder *encoder;
140 /* pick the encoder ids */
141 if (enc_id) {
142 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
143 if (!obj)
144 return NULL;
145 encoder = obj_to_encoder(obj);
146 return encoder;
148 return NULL;
152 * radeon_connector_analog_encoder_conflict_solve
153 * - search for other connectors sharing this encoder
154 * if priority is true, then set them disconnected if this is connected
155 * if priority is false, set us disconnected if they are connected
157 static enum drm_connector_status
158 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
159 struct drm_encoder *encoder,
160 enum drm_connector_status current_status,
161 bool priority)
163 struct drm_device *dev = connector->dev;
164 struct drm_connector *conflict;
165 int i;
167 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
168 if (conflict == connector)
169 continue;
171 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
172 if (conflict->encoder_ids[i] == 0)
173 break;
175 /* if the IDs match */
176 if (conflict->encoder_ids[i] == encoder->base.id) {
177 if (conflict->status != connector_status_connected)
178 continue;
180 if (priority == true) {
181 DRM_INFO("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
182 DRM_INFO("in favor of %s\n", drm_get_connector_name(connector));
183 conflict->status = connector_status_disconnected;
184 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
185 } else {
186 DRM_INFO("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
187 DRM_INFO("in favor of %s\n", drm_get_connector_name(conflict));
188 current_status = connector_status_disconnected;
190 break;
194 return current_status;
198 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
200 struct drm_device *dev = encoder->dev;
201 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
202 struct drm_display_mode *mode = NULL;
203 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
205 if (native_mode->hdisplay != 0 &&
206 native_mode->vdisplay != 0 &&
207 native_mode->clock != 0) {
208 mode = drm_mode_duplicate(dev, native_mode);
209 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
210 drm_mode_set_name(mode);
212 DRM_DEBUG("Adding native panel mode %s\n", mode->name);
213 } else if (native_mode->hdisplay != 0 &&
214 native_mode->vdisplay != 0) {
215 /* mac laptops without an edid */
216 /* Note that this is not necessarily the exact panel mode,
217 * but an approximation based on the cvt formula. For these
218 * systems we should ideally read the mode info out of the
219 * registers or add a mode table, but this works and is much
220 * simpler.
222 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
223 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
224 DRM_DEBUG("Adding cvt approximation of native panel mode %s\n", mode->name);
226 return mode;
229 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
231 struct drm_device *dev = encoder->dev;
232 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
233 struct drm_display_mode *mode = NULL;
234 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
235 int i;
236 struct mode_size {
237 int w;
238 int h;
239 } common_modes[17] = {
240 { 640, 480},
241 { 720, 480},
242 { 800, 600},
243 { 848, 480},
244 {1024, 768},
245 {1152, 768},
246 {1280, 720},
247 {1280, 800},
248 {1280, 854},
249 {1280, 960},
250 {1280, 1024},
251 {1440, 900},
252 {1400, 1050},
253 {1680, 1050},
254 {1600, 1200},
255 {1920, 1080},
256 {1920, 1200}
259 for (i = 0; i < 17; i++) {
260 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
261 if (common_modes[i].w > 1024 ||
262 common_modes[i].h > 768)
263 continue;
265 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
266 if (common_modes[i].w > native_mode->hdisplay ||
267 common_modes[i].h > native_mode->vdisplay ||
268 (common_modes[i].w == native_mode->hdisplay &&
269 common_modes[i].h == native_mode->vdisplay))
270 continue;
272 if (common_modes[i].w < 320 || common_modes[i].h < 200)
273 continue;
275 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
276 drm_mode_probed_add(connector, mode);
280 int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
281 uint64_t val)
283 struct drm_device *dev = connector->dev;
284 struct radeon_device *rdev = dev->dev_private;
285 struct drm_encoder *encoder;
286 struct radeon_encoder *radeon_encoder;
288 if (property == rdev->mode_info.coherent_mode_property) {
289 struct radeon_encoder_atom_dig *dig;
291 /* need to find digital encoder on connector */
292 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
293 if (!encoder)
294 return 0;
296 radeon_encoder = to_radeon_encoder(encoder);
298 if (!radeon_encoder->enc_priv)
299 return 0;
301 dig = radeon_encoder->enc_priv;
302 dig->coherent_mode = val ? true : false;
303 radeon_property_change_mode(&radeon_encoder->base);
306 if (property == rdev->mode_info.tv_std_property) {
307 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
308 if (!encoder) {
309 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
312 if (!encoder)
313 return 0;
315 radeon_encoder = to_radeon_encoder(encoder);
316 if (!radeon_encoder->enc_priv)
317 return 0;
318 if (rdev->is_atom_bios) {
319 struct radeon_encoder_atom_dac *dac_int;
320 dac_int = radeon_encoder->enc_priv;
321 dac_int->tv_std = val;
322 } else {
323 struct radeon_encoder_tv_dac *dac_int;
324 dac_int = radeon_encoder->enc_priv;
325 dac_int->tv_std = val;
327 radeon_property_change_mode(&radeon_encoder->base);
330 if (property == rdev->mode_info.load_detect_property) {
331 struct radeon_connector *radeon_connector =
332 to_radeon_connector(connector);
334 if (val == 0)
335 radeon_connector->dac_load_detect = false;
336 else
337 radeon_connector->dac_load_detect = true;
340 if (property == rdev->mode_info.tmds_pll_property) {
341 struct radeon_encoder_int_tmds *tmds = NULL;
342 bool ret = false;
343 /* need to find digital encoder on connector */
344 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
345 if (!encoder)
346 return 0;
348 radeon_encoder = to_radeon_encoder(encoder);
350 tmds = radeon_encoder->enc_priv;
351 if (!tmds)
352 return 0;
354 if (val == 0) {
355 if (rdev->is_atom_bios)
356 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
357 else
358 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
360 if (val == 1 || ret == false) {
361 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
363 radeon_property_change_mode(&radeon_encoder->base);
366 return 0;
369 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
370 struct drm_connector *connector)
372 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
373 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
375 /* Try to get native mode details from EDID if necessary */
376 if (!native_mode->clock) {
377 struct drm_display_mode *t, *mode;
379 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
380 if (mode->hdisplay == native_mode->hdisplay &&
381 mode->vdisplay == native_mode->vdisplay) {
382 *native_mode = *mode;
383 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
384 DRM_INFO("Determined LVDS native mode details from EDID\n");
385 break;
389 if (!native_mode->clock) {
390 DRM_INFO("No LVDS native mode details, disabling RMX\n");
391 radeon_encoder->rmx_type = RMX_OFF;
395 static int radeon_lvds_get_modes(struct drm_connector *connector)
397 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
398 struct drm_encoder *encoder;
399 int ret = 0;
400 struct drm_display_mode *mode;
402 if (radeon_connector->ddc_bus) {
403 ret = radeon_ddc_get_modes(radeon_connector);
404 if (ret > 0) {
405 encoder = radeon_best_single_encoder(connector);
406 if (encoder) {
407 radeon_fixup_lvds_native_mode(encoder, connector);
408 /* add scaled modes */
409 radeon_add_common_modes(encoder, connector);
411 return ret;
415 encoder = radeon_best_single_encoder(connector);
416 if (!encoder)
417 return 0;
419 /* we have no EDID modes */
420 mode = radeon_fp_native_mode(encoder);
421 if (mode) {
422 ret = 1;
423 drm_mode_probed_add(connector, mode);
424 /* add scaled modes */
425 radeon_add_common_modes(encoder, connector);
428 return ret;
431 static int radeon_lvds_mode_valid(struct drm_connector *connector,
432 struct drm_display_mode *mode)
434 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
436 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
437 return MODE_PANEL;
439 if (encoder) {
440 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
441 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
443 /* AVIVO hardware supports downscaling modes larger than the panel
444 * to the panel size, but I'm not sure this is desirable.
446 if ((mode->hdisplay > native_mode->hdisplay) ||
447 (mode->vdisplay > native_mode->vdisplay))
448 return MODE_PANEL;
450 /* if scaling is disabled, block non-native modes */
451 if (radeon_encoder->rmx_type == RMX_OFF) {
452 if ((mode->hdisplay != native_mode->hdisplay) ||
453 (mode->vdisplay != native_mode->vdisplay))
454 return MODE_PANEL;
458 return MODE_OK;
461 static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connector)
463 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
464 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
465 enum drm_connector_status ret = connector_status_disconnected;
467 if (encoder) {
468 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
469 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
471 /* check if panel is valid */
472 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
473 ret = connector_status_connected;
477 /* check for edid as well */
478 if (radeon_connector->edid)
479 ret = connector_status_connected;
480 else {
481 if (radeon_connector->ddc_bus) {
482 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
483 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
484 &radeon_connector->ddc_bus->adapter);
485 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
486 if (radeon_connector->edid)
487 ret = connector_status_connected;
490 /* check acpi lid status ??? */
492 radeon_connector_update_scratch_regs(connector, ret);
493 return ret;
496 static void radeon_connector_destroy(struct drm_connector *connector)
498 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
500 if (radeon_connector->ddc_bus)
501 radeon_i2c_destroy(radeon_connector->ddc_bus);
502 if (radeon_connector->edid)
503 kfree(radeon_connector->edid);
504 kfree(radeon_connector->con_priv);
505 drm_sysfs_connector_remove(connector);
506 drm_connector_cleanup(connector);
507 kfree(connector);
510 static int radeon_lvds_set_property(struct drm_connector *connector,
511 struct drm_property *property,
512 uint64_t value)
514 struct drm_device *dev = connector->dev;
515 struct radeon_encoder *radeon_encoder;
516 enum radeon_rmx_type rmx_type;
518 DRM_DEBUG("\n");
519 if (property != dev->mode_config.scaling_mode_property)
520 return 0;
522 if (connector->encoder)
523 radeon_encoder = to_radeon_encoder(connector->encoder);
524 else {
525 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
526 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
529 switch (value) {
530 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
531 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
532 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
533 default:
534 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
536 if (radeon_encoder->rmx_type == rmx_type)
537 return 0;
539 radeon_encoder->rmx_type = rmx_type;
541 radeon_property_change_mode(&radeon_encoder->base);
542 return 0;
546 struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
547 .get_modes = radeon_lvds_get_modes,
548 .mode_valid = radeon_lvds_mode_valid,
549 .best_encoder = radeon_best_single_encoder,
552 struct drm_connector_funcs radeon_lvds_connector_funcs = {
553 .dpms = drm_helper_connector_dpms,
554 .detect = radeon_lvds_detect,
555 .fill_modes = drm_helper_probe_single_connector_modes,
556 .destroy = radeon_connector_destroy,
557 .set_property = radeon_lvds_set_property,
560 static int radeon_vga_get_modes(struct drm_connector *connector)
562 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
563 int ret;
565 ret = radeon_ddc_get_modes(radeon_connector);
567 return ret;
570 static int radeon_vga_mode_valid(struct drm_connector *connector,
571 struct drm_display_mode *mode)
573 /* XXX check mode bandwidth */
574 /* XXX verify against max DAC output frequency */
575 return MODE_OK;
578 static enum drm_connector_status radeon_vga_detect(struct drm_connector *connector)
580 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
581 struct drm_encoder *encoder;
582 struct drm_encoder_helper_funcs *encoder_funcs;
583 bool dret;
584 enum drm_connector_status ret = connector_status_disconnected;
586 encoder = radeon_best_single_encoder(connector);
587 if (!encoder)
588 ret = connector_status_disconnected;
590 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
591 dret = radeon_ddc_probe(radeon_connector);
592 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
593 if (dret) {
594 if (radeon_connector->edid) {
595 kfree(radeon_connector->edid);
596 radeon_connector->edid = NULL;
598 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
599 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
600 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
602 if (!radeon_connector->edid) {
603 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
604 drm_get_connector_name(connector));
605 ret = connector_status_connected;
606 } else {
607 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
609 /* some oems have boards with separate digital and analog connectors
610 * with a shared ddc line (often vga + hdmi)
612 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
613 kfree(radeon_connector->edid);
614 radeon_connector->edid = NULL;
615 ret = connector_status_disconnected;
616 } else
617 ret = connector_status_connected;
619 } else {
620 if (radeon_connector->dac_load_detect && encoder) {
621 encoder_funcs = encoder->helper_private;
622 ret = encoder_funcs->detect(encoder, connector);
626 if (ret == connector_status_connected)
627 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
628 radeon_connector_update_scratch_regs(connector, ret);
629 return ret;
632 struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
633 .get_modes = radeon_vga_get_modes,
634 .mode_valid = radeon_vga_mode_valid,
635 .best_encoder = radeon_best_single_encoder,
638 struct drm_connector_funcs radeon_vga_connector_funcs = {
639 .dpms = drm_helper_connector_dpms,
640 .detect = radeon_vga_detect,
641 .fill_modes = drm_helper_probe_single_connector_modes,
642 .destroy = radeon_connector_destroy,
643 .set_property = radeon_connector_set_property,
646 static int radeon_tv_get_modes(struct drm_connector *connector)
648 struct drm_device *dev = connector->dev;
649 struct radeon_device *rdev = dev->dev_private;
650 struct drm_display_mode *tv_mode;
651 struct drm_encoder *encoder;
653 encoder = radeon_best_single_encoder(connector);
654 if (!encoder)
655 return 0;
657 /* avivo chips can scale any mode */
658 if (rdev->family >= CHIP_RS600)
659 /* add scaled modes */
660 radeon_add_common_modes(encoder, connector);
661 else {
662 /* only 800x600 is supported right now on pre-avivo chips */
663 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
664 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
665 drm_mode_probed_add(connector, tv_mode);
667 return 1;
670 static int radeon_tv_mode_valid(struct drm_connector *connector,
671 struct drm_display_mode *mode)
673 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
674 return MODE_CLOCK_RANGE;
675 return MODE_OK;
678 static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector)
680 struct drm_encoder *encoder;
681 struct drm_encoder_helper_funcs *encoder_funcs;
682 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
683 enum drm_connector_status ret = connector_status_disconnected;
685 if (!radeon_connector->dac_load_detect)
686 return ret;
688 encoder = radeon_best_single_encoder(connector);
689 if (!encoder)
690 ret = connector_status_disconnected;
691 else {
692 encoder_funcs = encoder->helper_private;
693 ret = encoder_funcs->detect(encoder, connector);
695 if (ret == connector_status_connected)
696 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
697 radeon_connector_update_scratch_regs(connector, ret);
698 return ret;
701 struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
702 .get_modes = radeon_tv_get_modes,
703 .mode_valid = radeon_tv_mode_valid,
704 .best_encoder = radeon_best_single_encoder,
707 struct drm_connector_funcs radeon_tv_connector_funcs = {
708 .dpms = drm_helper_connector_dpms,
709 .detect = radeon_tv_detect,
710 .fill_modes = drm_helper_probe_single_connector_modes,
711 .destroy = radeon_connector_destroy,
712 .set_property = radeon_connector_set_property,
715 static int radeon_dvi_get_modes(struct drm_connector *connector)
717 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
718 int ret;
720 ret = radeon_ddc_get_modes(radeon_connector);
721 return ret;
725 * DVI is complicated
726 * Do a DDC probe, if DDC probe passes, get the full EDID so
727 * we can do analog/digital monitor detection at this point.
728 * If the monitor is an analog monitor or we got no DDC,
729 * we need to find the DAC encoder object for this connector.
730 * If we got no DDC, we do load detection on the DAC encoder object.
731 * If we got analog DDC or load detection passes on the DAC encoder
732 * we have to check if this analog encoder is shared with anyone else (TV)
733 * if its shared we have to set the other connector to disconnected.
735 static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector)
737 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
738 struct drm_encoder *encoder = NULL;
739 struct drm_encoder_helper_funcs *encoder_funcs;
740 struct drm_mode_object *obj;
741 int i;
742 enum drm_connector_status ret = connector_status_disconnected;
743 bool dret;
745 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
746 dret = radeon_ddc_probe(radeon_connector);
747 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
748 if (dret) {
749 if (radeon_connector->edid) {
750 kfree(radeon_connector->edid);
751 radeon_connector->edid = NULL;
753 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
754 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
755 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
757 if (!radeon_connector->edid) {
758 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
759 drm_get_connector_name(connector));
760 } else {
761 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
763 /* some oems have boards with separate digital and analog connectors
764 * with a shared ddc line (often vga + hdmi)
766 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
767 kfree(radeon_connector->edid);
768 radeon_connector->edid = NULL;
769 ret = connector_status_disconnected;
770 } else
771 ret = connector_status_connected;
773 /* multiple connectors on the same encoder with the same ddc line
774 * This tends to be HDMI and DVI on the same encoder with the
775 * same ddc line. If the edid says HDMI, consider the HDMI port
776 * connected and the DVI port disconnected. If the edid doesn't
777 * say HDMI, vice versa.
779 if (radeon_connector->shared_ddc && connector_status_connected) {
780 struct drm_device *dev = connector->dev;
781 struct drm_connector *list_connector;
782 struct radeon_connector *list_radeon_connector;
783 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
784 if (connector == list_connector)
785 continue;
786 list_radeon_connector = to_radeon_connector(list_connector);
787 if (radeon_connector->devices == list_radeon_connector->devices) {
788 if (drm_detect_hdmi_monitor(radeon_connector->edid)) {
789 if (connector->connector_type == DRM_MODE_CONNECTOR_DVID) {
790 kfree(radeon_connector->edid);
791 radeon_connector->edid = NULL;
792 ret = connector_status_disconnected;
794 } else {
795 if ((connector->connector_type == DRM_MODE_CONNECTOR_HDMIA) ||
796 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIB)) {
797 kfree(radeon_connector->edid);
798 radeon_connector->edid = NULL;
799 ret = connector_status_disconnected;
808 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
809 goto out;
811 /* find analog encoder */
812 if (radeon_connector->dac_load_detect) {
813 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
814 if (connector->encoder_ids[i] == 0)
815 break;
817 obj = drm_mode_object_find(connector->dev,
818 connector->encoder_ids[i],
819 DRM_MODE_OBJECT_ENCODER);
820 if (!obj)
821 continue;
823 encoder = obj_to_encoder(obj);
825 encoder_funcs = encoder->helper_private;
826 if (encoder_funcs->detect) {
827 if (ret != connector_status_connected) {
828 ret = encoder_funcs->detect(encoder, connector);
829 if (ret == connector_status_connected) {
830 radeon_connector->use_digital = false;
833 break;
838 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
839 encoder) {
840 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
843 out:
844 /* updated in get modes as well since we need to know if it's analog or digital */
845 radeon_connector_update_scratch_regs(connector, ret);
846 return ret;
849 /* okay need to be smart in here about which encoder to pick */
850 struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
852 int enc_id = connector->encoder_ids[0];
853 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
854 struct drm_mode_object *obj;
855 struct drm_encoder *encoder;
856 int i;
857 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
858 if (connector->encoder_ids[i] == 0)
859 break;
861 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
862 if (!obj)
863 continue;
865 encoder = obj_to_encoder(obj);
867 if (radeon_connector->use_digital == true) {
868 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
869 return encoder;
870 } else {
871 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
872 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
873 return encoder;
877 /* see if we have a default encoder TODO */
879 /* then check use digitial */
880 /* pick the first one */
881 if (enc_id) {
882 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
883 if (!obj)
884 return NULL;
885 encoder = obj_to_encoder(obj);
886 return encoder;
888 return NULL;
891 static void radeon_dvi_force(struct drm_connector *connector)
893 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
894 if (connector->force == DRM_FORCE_ON)
895 radeon_connector->use_digital = false;
896 if (connector->force == DRM_FORCE_ON_DIGITAL)
897 radeon_connector->use_digital = true;
900 static int radeon_dvi_mode_valid(struct drm_connector *connector,
901 struct drm_display_mode *mode)
903 struct drm_device *dev = connector->dev;
904 struct radeon_device *rdev = dev->dev_private;
905 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
907 /* XXX check mode bandwidth */
909 /* clocks over 135 MHz have heat issues with DVI on RV100 */
910 if (radeon_connector->use_digital &&
911 (rdev->family == CHIP_RV100) &&
912 (mode->clock > 135000))
913 return MODE_CLOCK_HIGH;
915 if (radeon_connector->use_digital && (mode->clock > 165000)) {
916 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
917 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
918 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
919 return MODE_OK;
920 else
921 return MODE_CLOCK_HIGH;
923 return MODE_OK;
926 struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
927 .get_modes = radeon_dvi_get_modes,
928 .mode_valid = radeon_dvi_mode_valid,
929 .best_encoder = radeon_dvi_encoder,
932 struct drm_connector_funcs radeon_dvi_connector_funcs = {
933 .dpms = drm_helper_connector_dpms,
934 .detect = radeon_dvi_detect,
935 .fill_modes = drm_helper_probe_single_connector_modes,
936 .set_property = radeon_connector_set_property,
937 .destroy = radeon_connector_destroy,
938 .force = radeon_dvi_force,
941 static void radeon_dp_connector_destroy(struct drm_connector *connector)
943 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
944 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
946 if (radeon_connector->ddc_bus)
947 radeon_i2c_destroy(radeon_connector->ddc_bus);
948 if (radeon_connector->edid)
949 kfree(radeon_connector->edid);
950 if (radeon_dig_connector->dp_i2c_bus)
951 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
952 kfree(radeon_connector->con_priv);
953 drm_sysfs_connector_remove(connector);
954 drm_connector_cleanup(connector);
955 kfree(connector);
958 static int radeon_dp_get_modes(struct drm_connector *connector)
960 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
961 int ret;
963 ret = radeon_ddc_get_modes(radeon_connector);
964 return ret;
967 static enum drm_connector_status radeon_dp_detect(struct drm_connector *connector)
969 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
970 enum drm_connector_status ret = connector_status_disconnected;
971 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
972 u8 sink_type;
974 if (radeon_connector->edid) {
975 kfree(radeon_connector->edid);
976 radeon_connector->edid = NULL;
979 sink_type = radeon_dp_getsinktype(radeon_connector);
980 if ((sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
981 (sink_type == CONNECTOR_OBJECT_ID_eDP)) {
982 if (radeon_dp_getdpcd(radeon_connector)) {
983 radeon_dig_connector->dp_sink_type = sink_type;
984 ret = connector_status_connected;
986 } else {
987 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
988 if (radeon_ddc_probe(radeon_connector)) {
989 radeon_dig_connector->dp_sink_type = sink_type;
990 ret = connector_status_connected;
992 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
995 return ret;
998 static int radeon_dp_mode_valid(struct drm_connector *connector,
999 struct drm_display_mode *mode)
1001 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1002 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1004 /* XXX check mode bandwidth */
1006 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1007 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
1008 return radeon_dp_mode_valid_helper(radeon_connector, mode);
1009 else
1010 return MODE_OK;
1013 struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1014 .get_modes = radeon_dp_get_modes,
1015 .mode_valid = radeon_dp_mode_valid,
1016 .best_encoder = radeon_dvi_encoder,
1019 struct drm_connector_funcs radeon_dp_connector_funcs = {
1020 .dpms = drm_helper_connector_dpms,
1021 .detect = radeon_dp_detect,
1022 .fill_modes = drm_helper_probe_single_connector_modes,
1023 .set_property = radeon_connector_set_property,
1024 .destroy = radeon_dp_connector_destroy,
1025 .force = radeon_dvi_force,
1028 void
1029 radeon_add_atom_connector(struct drm_device *dev,
1030 uint32_t connector_id,
1031 uint32_t supported_device,
1032 int connector_type,
1033 struct radeon_i2c_bus_rec *i2c_bus,
1034 bool linkb,
1035 uint32_t igp_lane_info,
1036 uint16_t connector_object_id,
1037 struct radeon_hpd *hpd)
1039 struct radeon_device *rdev = dev->dev_private;
1040 struct drm_connector *connector;
1041 struct radeon_connector *radeon_connector;
1042 struct radeon_connector_atom_dig *radeon_dig_connector;
1043 uint32_t subpixel_order = SubPixelNone;
1044 bool shared_ddc = false;
1045 int ret;
1047 /* fixme - tv/cv/din */
1048 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1049 return;
1051 /* see if we already added it */
1052 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1053 radeon_connector = to_radeon_connector(connector);
1054 if (radeon_connector->connector_id == connector_id) {
1055 radeon_connector->devices |= supported_device;
1056 return;
1058 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1059 if (memcmp(&radeon_connector->ddc_bus->rec, i2c_bus,
1060 sizeof(struct radeon_i2c_bus_rec)) == 0) {
1061 radeon_connector->shared_ddc = true;
1062 shared_ddc = true;
1067 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1068 if (!radeon_connector)
1069 return;
1071 connector = &radeon_connector->base;
1073 radeon_connector->connector_id = connector_id;
1074 radeon_connector->devices = supported_device;
1075 radeon_connector->shared_ddc = shared_ddc;
1076 radeon_connector->connector_object_id = connector_object_id;
1077 radeon_connector->hpd = *hpd;
1078 switch (connector_type) {
1079 case DRM_MODE_CONNECTOR_VGA:
1080 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1081 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1082 if (ret)
1083 goto failed;
1084 if (i2c_bus->valid) {
1085 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1086 if (!radeon_connector->ddc_bus)
1087 goto failed;
1089 radeon_connector->dac_load_detect = true;
1090 drm_connector_attach_property(&radeon_connector->base,
1091 rdev->mode_info.load_detect_property,
1093 break;
1094 case DRM_MODE_CONNECTOR_DVIA:
1095 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1096 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1097 if (ret)
1098 goto failed;
1099 if (i2c_bus->valid) {
1100 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1101 if (!radeon_connector->ddc_bus)
1102 goto failed;
1104 radeon_connector->dac_load_detect = true;
1105 drm_connector_attach_property(&radeon_connector->base,
1106 rdev->mode_info.load_detect_property,
1108 break;
1109 case DRM_MODE_CONNECTOR_DVII:
1110 case DRM_MODE_CONNECTOR_DVID:
1111 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1112 if (!radeon_dig_connector)
1113 goto failed;
1114 radeon_dig_connector->linkb = linkb;
1115 radeon_dig_connector->igp_lane_info = igp_lane_info;
1116 radeon_connector->con_priv = radeon_dig_connector;
1117 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1118 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1119 if (ret)
1120 goto failed;
1121 if (i2c_bus->valid) {
1122 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1123 if (!radeon_connector->ddc_bus)
1124 goto failed;
1126 subpixel_order = SubPixelHorizontalRGB;
1127 drm_connector_attach_property(&radeon_connector->base,
1128 rdev->mode_info.coherent_mode_property,
1130 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1131 radeon_connector->dac_load_detect = true;
1132 drm_connector_attach_property(&radeon_connector->base,
1133 rdev->mode_info.load_detect_property,
1136 break;
1137 case DRM_MODE_CONNECTOR_HDMIA:
1138 case DRM_MODE_CONNECTOR_HDMIB:
1139 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1140 if (!radeon_dig_connector)
1141 goto failed;
1142 radeon_dig_connector->linkb = linkb;
1143 radeon_dig_connector->igp_lane_info = igp_lane_info;
1144 radeon_connector->con_priv = radeon_dig_connector;
1145 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1146 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1147 if (ret)
1148 goto failed;
1149 if (i2c_bus->valid) {
1150 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI");
1151 if (!radeon_connector->ddc_bus)
1152 goto failed;
1154 drm_connector_attach_property(&radeon_connector->base,
1155 rdev->mode_info.coherent_mode_property,
1157 subpixel_order = SubPixelHorizontalRGB;
1158 break;
1159 case DRM_MODE_CONNECTOR_DisplayPort:
1160 case DRM_MODE_CONNECTOR_eDP:
1161 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1162 if (!radeon_dig_connector)
1163 goto failed;
1164 radeon_dig_connector->linkb = linkb;
1165 radeon_dig_connector->igp_lane_info = igp_lane_info;
1166 radeon_connector->con_priv = radeon_dig_connector;
1167 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1168 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1169 if (ret)
1170 goto failed;
1171 if (i2c_bus->valid) {
1172 /* add DP i2c bus */
1173 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1174 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1175 else
1176 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1177 if (!radeon_dig_connector->dp_i2c_bus)
1178 goto failed;
1179 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1180 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "eDP");
1181 else
1182 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
1183 if (!radeon_connector->ddc_bus)
1184 goto failed;
1186 subpixel_order = SubPixelHorizontalRGB;
1187 drm_connector_attach_property(&radeon_connector->base,
1188 rdev->mode_info.coherent_mode_property,
1190 break;
1191 case DRM_MODE_CONNECTOR_SVIDEO:
1192 case DRM_MODE_CONNECTOR_Composite:
1193 case DRM_MODE_CONNECTOR_9PinDIN:
1194 if (radeon_tv == 1) {
1195 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1196 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1197 if (ret)
1198 goto failed;
1199 radeon_connector->dac_load_detect = true;
1200 drm_connector_attach_property(&radeon_connector->base,
1201 rdev->mode_info.load_detect_property,
1203 drm_connector_attach_property(&radeon_connector->base,
1204 rdev->mode_info.tv_std_property,
1205 radeon_atombios_get_tv_info(rdev));
1207 break;
1208 case DRM_MODE_CONNECTOR_LVDS:
1209 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1210 if (!radeon_dig_connector)
1211 goto failed;
1212 radeon_dig_connector->linkb = linkb;
1213 radeon_dig_connector->igp_lane_info = igp_lane_info;
1214 radeon_connector->con_priv = radeon_dig_connector;
1215 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1216 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1217 if (ret)
1218 goto failed;
1219 if (i2c_bus->valid) {
1220 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1221 if (!radeon_connector->ddc_bus)
1222 goto failed;
1224 drm_connector_attach_property(&radeon_connector->base,
1225 dev->mode_config.scaling_mode_property,
1226 DRM_MODE_SCALE_FULLSCREEN);
1227 subpixel_order = SubPixelHorizontalRGB;
1228 break;
1231 connector->display_info.subpixel_order = subpixel_order;
1232 drm_sysfs_connector_add(connector);
1233 return;
1235 failed:
1236 if (radeon_connector->ddc_bus)
1237 radeon_i2c_destroy(radeon_connector->ddc_bus);
1238 drm_connector_cleanup(connector);
1239 kfree(connector);
1242 void
1243 radeon_add_legacy_connector(struct drm_device *dev,
1244 uint32_t connector_id,
1245 uint32_t supported_device,
1246 int connector_type,
1247 struct radeon_i2c_bus_rec *i2c_bus,
1248 uint16_t connector_object_id,
1249 struct radeon_hpd *hpd)
1251 struct radeon_device *rdev = dev->dev_private;
1252 struct drm_connector *connector;
1253 struct radeon_connector *radeon_connector;
1254 uint32_t subpixel_order = SubPixelNone;
1255 int ret;
1257 /* fixme - tv/cv/din */
1258 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1259 return;
1261 /* see if we already added it */
1262 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1263 radeon_connector = to_radeon_connector(connector);
1264 if (radeon_connector->connector_id == connector_id) {
1265 radeon_connector->devices |= supported_device;
1266 return;
1270 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1271 if (!radeon_connector)
1272 return;
1274 connector = &radeon_connector->base;
1276 radeon_connector->connector_id = connector_id;
1277 radeon_connector->devices = supported_device;
1278 radeon_connector->connector_object_id = connector_object_id;
1279 radeon_connector->hpd = *hpd;
1280 switch (connector_type) {
1281 case DRM_MODE_CONNECTOR_VGA:
1282 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1283 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1284 if (ret)
1285 goto failed;
1286 if (i2c_bus->valid) {
1287 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1288 if (!radeon_connector->ddc_bus)
1289 goto failed;
1291 radeon_connector->dac_load_detect = true;
1292 drm_connector_attach_property(&radeon_connector->base,
1293 rdev->mode_info.load_detect_property,
1295 break;
1296 case DRM_MODE_CONNECTOR_DVIA:
1297 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1298 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1299 if (ret)
1300 goto failed;
1301 if (i2c_bus->valid) {
1302 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1303 if (!radeon_connector->ddc_bus)
1304 goto failed;
1306 radeon_connector->dac_load_detect = true;
1307 drm_connector_attach_property(&radeon_connector->base,
1308 rdev->mode_info.load_detect_property,
1310 break;
1311 case DRM_MODE_CONNECTOR_DVII:
1312 case DRM_MODE_CONNECTOR_DVID:
1313 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1314 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1315 if (ret)
1316 goto failed;
1317 if (i2c_bus->valid) {
1318 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1319 if (!radeon_connector->ddc_bus)
1320 goto failed;
1321 radeon_connector->dac_load_detect = true;
1322 drm_connector_attach_property(&radeon_connector->base,
1323 rdev->mode_info.load_detect_property,
1326 subpixel_order = SubPixelHorizontalRGB;
1327 break;
1328 case DRM_MODE_CONNECTOR_SVIDEO:
1329 case DRM_MODE_CONNECTOR_Composite:
1330 case DRM_MODE_CONNECTOR_9PinDIN:
1331 if (radeon_tv == 1) {
1332 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1333 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1334 if (ret)
1335 goto failed;
1336 radeon_connector->dac_load_detect = true;
1337 /* RS400,RC410,RS480 chipset seems to report a lot
1338 * of false positive on load detect, we haven't yet
1339 * found a way to make load detect reliable on those
1340 * chipset, thus just disable it for TV.
1342 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1343 radeon_connector->dac_load_detect = false;
1344 drm_connector_attach_property(&radeon_connector->base,
1345 rdev->mode_info.load_detect_property,
1347 drm_connector_attach_property(&radeon_connector->base,
1348 rdev->mode_info.tv_std_property,
1349 radeon_combios_get_tv_info(rdev));
1351 break;
1352 case DRM_MODE_CONNECTOR_LVDS:
1353 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1354 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1355 if (ret)
1356 goto failed;
1357 if (i2c_bus->valid) {
1358 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1359 if (!radeon_connector->ddc_bus)
1360 goto failed;
1362 drm_connector_attach_property(&radeon_connector->base,
1363 dev->mode_config.scaling_mode_property,
1364 DRM_MODE_SCALE_FULLSCREEN);
1365 subpixel_order = SubPixelHorizontalRGB;
1366 break;
1369 connector->display_info.subpixel_order = subpixel_order;
1370 drm_sysfs_connector_add(connector);
1371 return;
1373 failed:
1374 if (radeon_connector->ddc_bus)
1375 radeon_i2c_destroy(radeon_connector->ddc_bus);
1376 drm_connector_cleanup(connector);
1377 kfree(connector);