drm/radeon/kms: only change mode when coherent value changes.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / gpu / drm / radeon / radeon_connectors.c
blob3bc20406d45b73c8c55c5c2a1505504880ca2ee7
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;
290 bool new_coherent_mode;
292 /* need to find digital encoder on connector */
293 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
294 if (!encoder)
295 return 0;
297 radeon_encoder = to_radeon_encoder(encoder);
299 if (!radeon_encoder->enc_priv)
300 return 0;
302 dig = radeon_encoder->enc_priv;
303 new_coherent_mode = val ? true : false;
304 if (dig->coherent_mode != new_coherent_mode) {
305 dig->coherent_mode = new_coherent_mode;
306 radeon_property_change_mode(&radeon_encoder->base);
310 if (property == rdev->mode_info.tv_std_property) {
311 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
312 if (!encoder) {
313 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
316 if (!encoder)
317 return 0;
319 radeon_encoder = to_radeon_encoder(encoder);
320 if (!radeon_encoder->enc_priv)
321 return 0;
322 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
323 struct radeon_encoder_atom_dac *dac_int;
324 dac_int = radeon_encoder->enc_priv;
325 dac_int->tv_std = val;
326 } else {
327 struct radeon_encoder_tv_dac *dac_int;
328 dac_int = radeon_encoder->enc_priv;
329 dac_int->tv_std = val;
331 radeon_property_change_mode(&radeon_encoder->base);
334 if (property == rdev->mode_info.load_detect_property) {
335 struct radeon_connector *radeon_connector =
336 to_radeon_connector(connector);
338 if (val == 0)
339 radeon_connector->dac_load_detect = false;
340 else
341 radeon_connector->dac_load_detect = true;
344 if (property == rdev->mode_info.tmds_pll_property) {
345 struct radeon_encoder_int_tmds *tmds = NULL;
346 bool ret = false;
347 /* need to find digital encoder on connector */
348 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
349 if (!encoder)
350 return 0;
352 radeon_encoder = to_radeon_encoder(encoder);
354 tmds = radeon_encoder->enc_priv;
355 if (!tmds)
356 return 0;
358 if (val == 0) {
359 if (rdev->is_atom_bios)
360 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
361 else
362 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
364 if (val == 1 || ret == false) {
365 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
367 radeon_property_change_mode(&radeon_encoder->base);
370 return 0;
373 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
374 struct drm_connector *connector)
376 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
377 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
379 /* Try to get native mode details from EDID if necessary */
380 if (!native_mode->clock) {
381 struct drm_display_mode *t, *mode;
383 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
384 if (mode->hdisplay == native_mode->hdisplay &&
385 mode->vdisplay == native_mode->vdisplay) {
386 *native_mode = *mode;
387 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
388 DRM_INFO("Determined LVDS native mode details from EDID\n");
389 break;
393 if (!native_mode->clock) {
394 DRM_INFO("No LVDS native mode details, disabling RMX\n");
395 radeon_encoder->rmx_type = RMX_OFF;
399 static int radeon_lvds_get_modes(struct drm_connector *connector)
401 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
402 struct drm_encoder *encoder;
403 int ret = 0;
404 struct drm_display_mode *mode;
406 if (radeon_connector->ddc_bus) {
407 ret = radeon_ddc_get_modes(radeon_connector);
408 if (ret > 0) {
409 encoder = radeon_best_single_encoder(connector);
410 if (encoder) {
411 radeon_fixup_lvds_native_mode(encoder, connector);
412 /* add scaled modes */
413 radeon_add_common_modes(encoder, connector);
415 return ret;
419 encoder = radeon_best_single_encoder(connector);
420 if (!encoder)
421 return 0;
423 /* we have no EDID modes */
424 mode = radeon_fp_native_mode(encoder);
425 if (mode) {
426 ret = 1;
427 drm_mode_probed_add(connector, mode);
428 /* add scaled modes */
429 radeon_add_common_modes(encoder, connector);
432 return ret;
435 static int radeon_lvds_mode_valid(struct drm_connector *connector,
436 struct drm_display_mode *mode)
438 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
440 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
441 return MODE_PANEL;
443 if (encoder) {
444 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
445 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
447 /* AVIVO hardware supports downscaling modes larger than the panel
448 * to the panel size, but I'm not sure this is desirable.
450 if ((mode->hdisplay > native_mode->hdisplay) ||
451 (mode->vdisplay > native_mode->vdisplay))
452 return MODE_PANEL;
454 /* if scaling is disabled, block non-native modes */
455 if (radeon_encoder->rmx_type == RMX_OFF) {
456 if ((mode->hdisplay != native_mode->hdisplay) ||
457 (mode->vdisplay != native_mode->vdisplay))
458 return MODE_PANEL;
462 return MODE_OK;
465 static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connector)
467 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
468 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
469 enum drm_connector_status ret = connector_status_disconnected;
471 if (encoder) {
472 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
473 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
475 /* check if panel is valid */
476 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
477 ret = connector_status_connected;
481 /* check for edid as well */
482 if (radeon_connector->edid)
483 ret = connector_status_connected;
484 else {
485 if (radeon_connector->ddc_bus) {
486 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
487 &radeon_connector->ddc_bus->adapter);
488 if (radeon_connector->edid)
489 ret = connector_status_connected;
492 /* check acpi lid status ??? */
494 radeon_connector_update_scratch_regs(connector, ret);
495 return ret;
498 static void radeon_connector_destroy(struct drm_connector *connector)
500 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
502 if (radeon_connector->ddc_bus)
503 radeon_i2c_destroy(radeon_connector->ddc_bus);
504 if (radeon_connector->edid)
505 kfree(radeon_connector->edid);
506 kfree(radeon_connector->con_priv);
507 drm_sysfs_connector_remove(connector);
508 drm_connector_cleanup(connector);
509 kfree(connector);
512 static int radeon_lvds_set_property(struct drm_connector *connector,
513 struct drm_property *property,
514 uint64_t value)
516 struct drm_device *dev = connector->dev;
517 struct radeon_encoder *radeon_encoder;
518 enum radeon_rmx_type rmx_type;
520 DRM_DEBUG("\n");
521 if (property != dev->mode_config.scaling_mode_property)
522 return 0;
524 if (connector->encoder)
525 radeon_encoder = to_radeon_encoder(connector->encoder);
526 else {
527 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
528 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
531 switch (value) {
532 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
533 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
534 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
535 default:
536 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
538 if (radeon_encoder->rmx_type == rmx_type)
539 return 0;
541 radeon_encoder->rmx_type = rmx_type;
543 radeon_property_change_mode(&radeon_encoder->base);
544 return 0;
548 struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
549 .get_modes = radeon_lvds_get_modes,
550 .mode_valid = radeon_lvds_mode_valid,
551 .best_encoder = radeon_best_single_encoder,
554 struct drm_connector_funcs radeon_lvds_connector_funcs = {
555 .dpms = drm_helper_connector_dpms,
556 .detect = radeon_lvds_detect,
557 .fill_modes = drm_helper_probe_single_connector_modes,
558 .destroy = radeon_connector_destroy,
559 .set_property = radeon_lvds_set_property,
562 static int radeon_vga_get_modes(struct drm_connector *connector)
564 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
565 int ret;
567 ret = radeon_ddc_get_modes(radeon_connector);
569 return ret;
572 static int radeon_vga_mode_valid(struct drm_connector *connector,
573 struct drm_display_mode *mode)
575 /* XXX check mode bandwidth */
576 /* XXX verify against max DAC output frequency */
577 return MODE_OK;
580 static enum drm_connector_status radeon_vga_detect(struct drm_connector *connector)
582 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
583 struct drm_encoder *encoder;
584 struct drm_encoder_helper_funcs *encoder_funcs;
585 bool dret = false;
586 enum drm_connector_status ret = connector_status_disconnected;
588 encoder = radeon_best_single_encoder(connector);
589 if (!encoder)
590 ret = connector_status_disconnected;
592 if (radeon_connector->ddc_bus)
593 dret = radeon_ddc_probe(radeon_connector);
594 if (dret) {
595 if (radeon_connector->edid) {
596 kfree(radeon_connector->edid);
597 radeon_connector->edid = NULL;
599 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
601 if (!radeon_connector->edid) {
602 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
603 drm_get_connector_name(connector));
604 ret = connector_status_connected;
605 } else {
606 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
608 /* some oems have boards with separate digital and analog connectors
609 * with a shared ddc line (often vga + hdmi)
611 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
612 kfree(radeon_connector->edid);
613 radeon_connector->edid = NULL;
614 ret = connector_status_disconnected;
615 } else
616 ret = connector_status_connected;
618 } else {
619 if (radeon_connector->dac_load_detect && encoder) {
620 encoder_funcs = encoder->helper_private;
621 ret = encoder_funcs->detect(encoder, connector);
625 if (ret == connector_status_connected)
626 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
627 radeon_connector_update_scratch_regs(connector, ret);
628 return ret;
631 struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
632 .get_modes = radeon_vga_get_modes,
633 .mode_valid = radeon_vga_mode_valid,
634 .best_encoder = radeon_best_single_encoder,
637 struct drm_connector_funcs radeon_vga_connector_funcs = {
638 .dpms = drm_helper_connector_dpms,
639 .detect = radeon_vga_detect,
640 .fill_modes = drm_helper_probe_single_connector_modes,
641 .destroy = radeon_connector_destroy,
642 .set_property = radeon_connector_set_property,
645 static int radeon_tv_get_modes(struct drm_connector *connector)
647 struct drm_device *dev = connector->dev;
648 struct radeon_device *rdev = dev->dev_private;
649 struct drm_display_mode *tv_mode;
650 struct drm_encoder *encoder;
652 encoder = radeon_best_single_encoder(connector);
653 if (!encoder)
654 return 0;
656 /* avivo chips can scale any mode */
657 if (rdev->family >= CHIP_RS600)
658 /* add scaled modes */
659 radeon_add_common_modes(encoder, connector);
660 else {
661 /* only 800x600 is supported right now on pre-avivo chips */
662 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
663 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
664 drm_mode_probed_add(connector, tv_mode);
666 return 1;
669 static int radeon_tv_mode_valid(struct drm_connector *connector,
670 struct drm_display_mode *mode)
672 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
673 return MODE_CLOCK_RANGE;
674 return MODE_OK;
677 static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector)
679 struct drm_encoder *encoder;
680 struct drm_encoder_helper_funcs *encoder_funcs;
681 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
682 enum drm_connector_status ret = connector_status_disconnected;
684 if (!radeon_connector->dac_load_detect)
685 return ret;
687 encoder = radeon_best_single_encoder(connector);
688 if (!encoder)
689 ret = connector_status_disconnected;
690 else {
691 encoder_funcs = encoder->helper_private;
692 ret = encoder_funcs->detect(encoder, connector);
694 if (ret == connector_status_connected)
695 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
696 radeon_connector_update_scratch_regs(connector, ret);
697 return ret;
700 struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
701 .get_modes = radeon_tv_get_modes,
702 .mode_valid = radeon_tv_mode_valid,
703 .best_encoder = radeon_best_single_encoder,
706 struct drm_connector_funcs radeon_tv_connector_funcs = {
707 .dpms = drm_helper_connector_dpms,
708 .detect = radeon_tv_detect,
709 .fill_modes = drm_helper_probe_single_connector_modes,
710 .destroy = radeon_connector_destroy,
711 .set_property = radeon_connector_set_property,
714 static int radeon_dvi_get_modes(struct drm_connector *connector)
716 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
717 int ret;
719 ret = radeon_ddc_get_modes(radeon_connector);
720 return ret;
724 * DVI is complicated
725 * Do a DDC probe, if DDC probe passes, get the full EDID so
726 * we can do analog/digital monitor detection at this point.
727 * If the monitor is an analog monitor or we got no DDC,
728 * we need to find the DAC encoder object for this connector.
729 * If we got no DDC, we do load detection on the DAC encoder object.
730 * If we got analog DDC or load detection passes on the DAC encoder
731 * we have to check if this analog encoder is shared with anyone else (TV)
732 * if its shared we have to set the other connector to disconnected.
734 static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector)
736 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
737 struct drm_encoder *encoder = NULL;
738 struct drm_encoder_helper_funcs *encoder_funcs;
739 struct drm_mode_object *obj;
740 int i;
741 enum drm_connector_status ret = connector_status_disconnected;
742 bool dret = false;
744 if (radeon_connector->ddc_bus)
745 dret = radeon_ddc_probe(radeon_connector);
746 if (dret) {
747 if (radeon_connector->edid) {
748 kfree(radeon_connector->edid);
749 radeon_connector->edid = NULL;
751 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
753 if (!radeon_connector->edid) {
754 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
755 drm_get_connector_name(connector));
756 } else {
757 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
759 /* some oems have boards with separate digital and analog connectors
760 * with a shared ddc line (often vga + hdmi)
762 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
763 kfree(radeon_connector->edid);
764 radeon_connector->edid = NULL;
765 ret = connector_status_disconnected;
766 } else
767 ret = connector_status_connected;
769 /* multiple connectors on the same encoder with the same ddc line
770 * This tends to be HDMI and DVI on the same encoder with the
771 * same ddc line. If the edid says HDMI, consider the HDMI port
772 * connected and the DVI port disconnected. If the edid doesn't
773 * say HDMI, vice versa.
775 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
776 struct drm_device *dev = connector->dev;
777 struct drm_connector *list_connector;
778 struct radeon_connector *list_radeon_connector;
779 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
780 if (connector == list_connector)
781 continue;
782 list_radeon_connector = to_radeon_connector(list_connector);
783 if (radeon_connector->devices == list_radeon_connector->devices) {
784 if (drm_detect_hdmi_monitor(radeon_connector->edid)) {
785 if (connector->connector_type == DRM_MODE_CONNECTOR_DVID) {
786 kfree(radeon_connector->edid);
787 radeon_connector->edid = NULL;
788 ret = connector_status_disconnected;
790 } else {
791 if ((connector->connector_type == DRM_MODE_CONNECTOR_HDMIA) ||
792 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIB)) {
793 kfree(radeon_connector->edid);
794 radeon_connector->edid = NULL;
795 ret = connector_status_disconnected;
804 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
805 goto out;
807 /* find analog encoder */
808 if (radeon_connector->dac_load_detect) {
809 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
810 if (connector->encoder_ids[i] == 0)
811 break;
813 obj = drm_mode_object_find(connector->dev,
814 connector->encoder_ids[i],
815 DRM_MODE_OBJECT_ENCODER);
816 if (!obj)
817 continue;
819 encoder = obj_to_encoder(obj);
821 encoder_funcs = encoder->helper_private;
822 if (encoder_funcs->detect) {
823 if (ret != connector_status_connected) {
824 ret = encoder_funcs->detect(encoder, connector);
825 if (ret == connector_status_connected) {
826 radeon_connector->use_digital = false;
829 break;
834 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
835 encoder) {
836 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
839 out:
840 /* updated in get modes as well since we need to know if it's analog or digital */
841 radeon_connector_update_scratch_regs(connector, ret);
842 return ret;
845 /* okay need to be smart in here about which encoder to pick */
846 struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
848 int enc_id = connector->encoder_ids[0];
849 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
850 struct drm_mode_object *obj;
851 struct drm_encoder *encoder;
852 int i;
853 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
854 if (connector->encoder_ids[i] == 0)
855 break;
857 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
858 if (!obj)
859 continue;
861 encoder = obj_to_encoder(obj);
863 if (radeon_connector->use_digital == true) {
864 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
865 return encoder;
866 } else {
867 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
868 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
869 return encoder;
873 /* see if we have a default encoder TODO */
875 /* then check use digitial */
876 /* pick the first one */
877 if (enc_id) {
878 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
879 if (!obj)
880 return NULL;
881 encoder = obj_to_encoder(obj);
882 return encoder;
884 return NULL;
887 static void radeon_dvi_force(struct drm_connector *connector)
889 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
890 if (connector->force == DRM_FORCE_ON)
891 radeon_connector->use_digital = false;
892 if (connector->force == DRM_FORCE_ON_DIGITAL)
893 radeon_connector->use_digital = true;
896 static int radeon_dvi_mode_valid(struct drm_connector *connector,
897 struct drm_display_mode *mode)
899 struct drm_device *dev = connector->dev;
900 struct radeon_device *rdev = dev->dev_private;
901 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
903 /* XXX check mode bandwidth */
905 /* clocks over 135 MHz have heat issues with DVI on RV100 */
906 if (radeon_connector->use_digital &&
907 (rdev->family == CHIP_RV100) &&
908 (mode->clock > 135000))
909 return MODE_CLOCK_HIGH;
911 if (radeon_connector->use_digital && (mode->clock > 165000)) {
912 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
913 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
914 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
915 return MODE_OK;
916 else
917 return MODE_CLOCK_HIGH;
919 return MODE_OK;
922 struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
923 .get_modes = radeon_dvi_get_modes,
924 .mode_valid = radeon_dvi_mode_valid,
925 .best_encoder = radeon_dvi_encoder,
928 struct drm_connector_funcs radeon_dvi_connector_funcs = {
929 .dpms = drm_helper_connector_dpms,
930 .detect = radeon_dvi_detect,
931 .fill_modes = drm_helper_probe_single_connector_modes,
932 .set_property = radeon_connector_set_property,
933 .destroy = radeon_connector_destroy,
934 .force = radeon_dvi_force,
937 static void radeon_dp_connector_destroy(struct drm_connector *connector)
939 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
940 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
942 if (radeon_connector->ddc_bus)
943 radeon_i2c_destroy(radeon_connector->ddc_bus);
944 if (radeon_connector->edid)
945 kfree(radeon_connector->edid);
946 if (radeon_dig_connector->dp_i2c_bus)
947 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
948 kfree(radeon_connector->con_priv);
949 drm_sysfs_connector_remove(connector);
950 drm_connector_cleanup(connector);
951 kfree(connector);
954 static int radeon_dp_get_modes(struct drm_connector *connector)
956 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
957 int ret;
959 ret = radeon_ddc_get_modes(radeon_connector);
960 return ret;
963 static enum drm_connector_status radeon_dp_detect(struct drm_connector *connector)
965 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
966 enum drm_connector_status ret = connector_status_disconnected;
967 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
968 u8 sink_type;
970 if (radeon_connector->edid) {
971 kfree(radeon_connector->edid);
972 radeon_connector->edid = NULL;
975 sink_type = radeon_dp_getsinktype(radeon_connector);
976 if ((sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
977 (sink_type == CONNECTOR_OBJECT_ID_eDP)) {
978 if (radeon_dp_getdpcd(radeon_connector)) {
979 radeon_dig_connector->dp_sink_type = sink_type;
980 ret = connector_status_connected;
982 } else {
983 if (radeon_ddc_probe(radeon_connector)) {
984 radeon_dig_connector->dp_sink_type = sink_type;
985 ret = connector_status_connected;
989 return ret;
992 static int radeon_dp_mode_valid(struct drm_connector *connector,
993 struct drm_display_mode *mode)
995 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
996 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
998 /* XXX check mode bandwidth */
1000 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1001 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
1002 return radeon_dp_mode_valid_helper(radeon_connector, mode);
1003 else
1004 return MODE_OK;
1007 struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1008 .get_modes = radeon_dp_get_modes,
1009 .mode_valid = radeon_dp_mode_valid,
1010 .best_encoder = radeon_dvi_encoder,
1013 struct drm_connector_funcs radeon_dp_connector_funcs = {
1014 .dpms = drm_helper_connector_dpms,
1015 .detect = radeon_dp_detect,
1016 .fill_modes = drm_helper_probe_single_connector_modes,
1017 .set_property = radeon_connector_set_property,
1018 .destroy = radeon_dp_connector_destroy,
1019 .force = radeon_dvi_force,
1022 void
1023 radeon_add_atom_connector(struct drm_device *dev,
1024 uint32_t connector_id,
1025 uint32_t supported_device,
1026 int connector_type,
1027 struct radeon_i2c_bus_rec *i2c_bus,
1028 bool linkb,
1029 uint32_t igp_lane_info,
1030 uint16_t connector_object_id,
1031 struct radeon_hpd *hpd)
1033 struct radeon_device *rdev = dev->dev_private;
1034 struct drm_connector *connector;
1035 struct radeon_connector *radeon_connector;
1036 struct radeon_connector_atom_dig *radeon_dig_connector;
1037 uint32_t subpixel_order = SubPixelNone;
1038 bool shared_ddc = false;
1039 int ret;
1041 /* fixme - tv/cv/din */
1042 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1043 return;
1045 /* see if we already added it */
1046 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1047 radeon_connector = to_radeon_connector(connector);
1048 if (radeon_connector->connector_id == connector_id) {
1049 radeon_connector->devices |= supported_device;
1050 return;
1052 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1053 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1054 radeon_connector->shared_ddc = true;
1055 shared_ddc = true;
1060 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1061 if (!radeon_connector)
1062 return;
1064 connector = &radeon_connector->base;
1066 radeon_connector->connector_id = connector_id;
1067 radeon_connector->devices = supported_device;
1068 radeon_connector->shared_ddc = shared_ddc;
1069 radeon_connector->connector_object_id = connector_object_id;
1070 radeon_connector->hpd = *hpd;
1071 switch (connector_type) {
1072 case DRM_MODE_CONNECTOR_VGA:
1073 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1074 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1075 if (ret)
1076 goto failed;
1077 if (i2c_bus->valid) {
1078 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1079 if (!radeon_connector->ddc_bus)
1080 goto failed;
1082 radeon_connector->dac_load_detect = true;
1083 drm_connector_attach_property(&radeon_connector->base,
1084 rdev->mode_info.load_detect_property,
1086 break;
1087 case DRM_MODE_CONNECTOR_DVIA:
1088 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1089 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1090 if (ret)
1091 goto failed;
1092 if (i2c_bus->valid) {
1093 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1094 if (!radeon_connector->ddc_bus)
1095 goto failed;
1097 radeon_connector->dac_load_detect = true;
1098 drm_connector_attach_property(&radeon_connector->base,
1099 rdev->mode_info.load_detect_property,
1101 break;
1102 case DRM_MODE_CONNECTOR_DVII:
1103 case DRM_MODE_CONNECTOR_DVID:
1104 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1105 if (!radeon_dig_connector)
1106 goto failed;
1107 radeon_dig_connector->linkb = linkb;
1108 radeon_dig_connector->igp_lane_info = igp_lane_info;
1109 radeon_connector->con_priv = radeon_dig_connector;
1110 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1111 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1112 if (ret)
1113 goto failed;
1114 if (i2c_bus->valid) {
1115 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1116 if (!radeon_connector->ddc_bus)
1117 goto failed;
1119 subpixel_order = SubPixelHorizontalRGB;
1120 drm_connector_attach_property(&radeon_connector->base,
1121 rdev->mode_info.coherent_mode_property,
1123 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1124 radeon_connector->dac_load_detect = true;
1125 drm_connector_attach_property(&radeon_connector->base,
1126 rdev->mode_info.load_detect_property,
1129 break;
1130 case DRM_MODE_CONNECTOR_HDMIA:
1131 case DRM_MODE_CONNECTOR_HDMIB:
1132 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1133 if (!radeon_dig_connector)
1134 goto failed;
1135 radeon_dig_connector->linkb = linkb;
1136 radeon_dig_connector->igp_lane_info = igp_lane_info;
1137 radeon_connector->con_priv = radeon_dig_connector;
1138 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1139 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1140 if (ret)
1141 goto failed;
1142 if (i2c_bus->valid) {
1143 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI");
1144 if (!radeon_connector->ddc_bus)
1145 goto failed;
1147 drm_connector_attach_property(&radeon_connector->base,
1148 rdev->mode_info.coherent_mode_property,
1150 subpixel_order = SubPixelHorizontalRGB;
1151 break;
1152 case DRM_MODE_CONNECTOR_DisplayPort:
1153 case DRM_MODE_CONNECTOR_eDP:
1154 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1155 if (!radeon_dig_connector)
1156 goto failed;
1157 radeon_dig_connector->linkb = linkb;
1158 radeon_dig_connector->igp_lane_info = igp_lane_info;
1159 radeon_connector->con_priv = radeon_dig_connector;
1160 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1161 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1162 if (ret)
1163 goto failed;
1164 if (i2c_bus->valid) {
1165 /* add DP i2c bus */
1166 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1167 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1168 else
1169 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1170 if (!radeon_dig_connector->dp_i2c_bus)
1171 goto failed;
1172 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1173 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "eDP");
1174 else
1175 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
1176 if (!radeon_connector->ddc_bus)
1177 goto failed;
1179 subpixel_order = SubPixelHorizontalRGB;
1180 drm_connector_attach_property(&radeon_connector->base,
1181 rdev->mode_info.coherent_mode_property,
1183 break;
1184 case DRM_MODE_CONNECTOR_SVIDEO:
1185 case DRM_MODE_CONNECTOR_Composite:
1186 case DRM_MODE_CONNECTOR_9PinDIN:
1187 if (radeon_tv == 1) {
1188 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1189 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1190 if (ret)
1191 goto failed;
1192 radeon_connector->dac_load_detect = true;
1193 drm_connector_attach_property(&radeon_connector->base,
1194 rdev->mode_info.load_detect_property,
1196 drm_connector_attach_property(&radeon_connector->base,
1197 rdev->mode_info.tv_std_property,
1198 radeon_atombios_get_tv_info(rdev));
1200 break;
1201 case DRM_MODE_CONNECTOR_LVDS:
1202 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1203 if (!radeon_dig_connector)
1204 goto failed;
1205 radeon_dig_connector->linkb = linkb;
1206 radeon_dig_connector->igp_lane_info = igp_lane_info;
1207 radeon_connector->con_priv = radeon_dig_connector;
1208 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1209 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1210 if (ret)
1211 goto failed;
1212 if (i2c_bus->valid) {
1213 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1214 if (!radeon_connector->ddc_bus)
1215 goto failed;
1217 drm_connector_attach_property(&radeon_connector->base,
1218 dev->mode_config.scaling_mode_property,
1219 DRM_MODE_SCALE_FULLSCREEN);
1220 subpixel_order = SubPixelHorizontalRGB;
1221 break;
1224 connector->display_info.subpixel_order = subpixel_order;
1225 drm_sysfs_connector_add(connector);
1226 return;
1228 failed:
1229 if (radeon_connector->ddc_bus)
1230 radeon_i2c_destroy(radeon_connector->ddc_bus);
1231 drm_connector_cleanup(connector);
1232 kfree(connector);
1235 void
1236 radeon_add_legacy_connector(struct drm_device *dev,
1237 uint32_t connector_id,
1238 uint32_t supported_device,
1239 int connector_type,
1240 struct radeon_i2c_bus_rec *i2c_bus,
1241 uint16_t connector_object_id,
1242 struct radeon_hpd *hpd)
1244 struct radeon_device *rdev = dev->dev_private;
1245 struct drm_connector *connector;
1246 struct radeon_connector *radeon_connector;
1247 uint32_t subpixel_order = SubPixelNone;
1248 int ret;
1250 /* fixme - tv/cv/din */
1251 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1252 return;
1254 /* see if we already added it */
1255 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1256 radeon_connector = to_radeon_connector(connector);
1257 if (radeon_connector->connector_id == connector_id) {
1258 radeon_connector->devices |= supported_device;
1259 return;
1263 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1264 if (!radeon_connector)
1265 return;
1267 connector = &radeon_connector->base;
1269 radeon_connector->connector_id = connector_id;
1270 radeon_connector->devices = supported_device;
1271 radeon_connector->connector_object_id = connector_object_id;
1272 radeon_connector->hpd = *hpd;
1273 switch (connector_type) {
1274 case DRM_MODE_CONNECTOR_VGA:
1275 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1276 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1277 if (ret)
1278 goto failed;
1279 if (i2c_bus->valid) {
1280 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1281 if (!radeon_connector->ddc_bus)
1282 goto failed;
1284 radeon_connector->dac_load_detect = true;
1285 drm_connector_attach_property(&radeon_connector->base,
1286 rdev->mode_info.load_detect_property,
1288 break;
1289 case DRM_MODE_CONNECTOR_DVIA:
1290 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1291 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1292 if (ret)
1293 goto failed;
1294 if (i2c_bus->valid) {
1295 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1296 if (!radeon_connector->ddc_bus)
1297 goto failed;
1299 radeon_connector->dac_load_detect = true;
1300 drm_connector_attach_property(&radeon_connector->base,
1301 rdev->mode_info.load_detect_property,
1303 break;
1304 case DRM_MODE_CONNECTOR_DVII:
1305 case DRM_MODE_CONNECTOR_DVID:
1306 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1307 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1308 if (ret)
1309 goto failed;
1310 if (i2c_bus->valid) {
1311 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1312 if (!radeon_connector->ddc_bus)
1313 goto failed;
1314 radeon_connector->dac_load_detect = true;
1315 drm_connector_attach_property(&radeon_connector->base,
1316 rdev->mode_info.load_detect_property,
1319 subpixel_order = SubPixelHorizontalRGB;
1320 break;
1321 case DRM_MODE_CONNECTOR_SVIDEO:
1322 case DRM_MODE_CONNECTOR_Composite:
1323 case DRM_MODE_CONNECTOR_9PinDIN:
1324 if (radeon_tv == 1) {
1325 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1326 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1327 if (ret)
1328 goto failed;
1329 radeon_connector->dac_load_detect = true;
1330 /* RS400,RC410,RS480 chipset seems to report a lot
1331 * of false positive on load detect, we haven't yet
1332 * found a way to make load detect reliable on those
1333 * chipset, thus just disable it for TV.
1335 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1336 radeon_connector->dac_load_detect = false;
1337 drm_connector_attach_property(&radeon_connector->base,
1338 rdev->mode_info.load_detect_property,
1339 radeon_connector->dac_load_detect);
1340 drm_connector_attach_property(&radeon_connector->base,
1341 rdev->mode_info.tv_std_property,
1342 radeon_combios_get_tv_info(rdev));
1344 break;
1345 case DRM_MODE_CONNECTOR_LVDS:
1346 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1347 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1348 if (ret)
1349 goto failed;
1350 if (i2c_bus->valid) {
1351 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1352 if (!radeon_connector->ddc_bus)
1353 goto failed;
1355 drm_connector_attach_property(&radeon_connector->base,
1356 dev->mode_config.scaling_mode_property,
1357 DRM_MODE_SCALE_FULLSCREEN);
1358 subpixel_order = SubPixelHorizontalRGB;
1359 break;
1362 connector->display_info.subpixel_order = subpixel_order;
1363 drm_sysfs_connector_add(connector);
1364 return;
1366 failed:
1367 if (radeon_connector->ddc_bus)
1368 radeon_i2c_destroy(radeon_connector->ddc_bus);
1369 drm_connector_cleanup(connector);
1370 kfree(connector);