init from v2.6.32.60
[mach-moxart.git] / drivers / gpu / drm / radeon / radeon_connectors.c
blobb1dc1a112aef618da04053ca56cfe81c8e1fef27
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 static void radeon_property_change_mode(struct drm_encoder *encoder)
45 struct drm_crtc *crtc = encoder->crtc;
47 if (crtc && crtc->enabled) {
48 drm_crtc_helper_set_mode(crtc, &crtc->mode,
49 crtc->x, crtc->y, crtc->fb);
52 static void
53 radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
55 struct drm_device *dev = connector->dev;
56 struct radeon_device *rdev = dev->dev_private;
57 struct drm_encoder *best_encoder = NULL;
58 struct drm_encoder *encoder = NULL;
59 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
60 struct drm_mode_object *obj;
61 bool connected;
62 int i;
64 best_encoder = connector_funcs->best_encoder(connector);
66 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
67 if (connector->encoder_ids[i] == 0)
68 break;
70 obj = drm_mode_object_find(connector->dev,
71 connector->encoder_ids[i],
72 DRM_MODE_OBJECT_ENCODER);
73 if (!obj)
74 continue;
76 encoder = obj_to_encoder(obj);
78 if ((encoder == best_encoder) && (status == connector_status_connected))
79 connected = true;
80 else
81 connected = false;
83 if (rdev->is_atom_bios)
84 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
85 else
86 radeon_combios_connected_scratch_regs(connector, encoder, connected);
91 struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
93 struct drm_mode_object *obj;
94 struct drm_encoder *encoder;
95 int i;
97 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
98 if (connector->encoder_ids[i] == 0)
99 break;
101 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
102 if (!obj)
103 continue;
105 encoder = obj_to_encoder(obj);
106 if (encoder->encoder_type == encoder_type)
107 return encoder;
109 return NULL;
112 struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
114 int enc_id = connector->encoder_ids[0];
115 struct drm_mode_object *obj;
116 struct drm_encoder *encoder;
118 /* pick the encoder ids */
119 if (enc_id) {
120 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
121 if (!obj)
122 return NULL;
123 encoder = obj_to_encoder(obj);
124 return encoder;
126 return NULL;
130 * radeon_connector_analog_encoder_conflict_solve
131 * - search for other connectors sharing this encoder
132 * if priority is true, then set them disconnected if this is connected
133 * if priority is false, set us disconnected if they are connected
135 static enum drm_connector_status
136 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
137 struct drm_encoder *encoder,
138 enum drm_connector_status current_status,
139 bool priority)
141 struct drm_device *dev = connector->dev;
142 struct drm_connector *conflict;
143 struct radeon_connector *radeon_conflict;
144 int i;
146 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
147 if (conflict == connector)
148 continue;
150 radeon_conflict = to_radeon_connector(conflict);
151 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
152 if (conflict->encoder_ids[i] == 0)
153 break;
155 /* if the IDs match */
156 if (conflict->encoder_ids[i] == encoder->base.id) {
157 if (conflict->status != connector_status_connected)
158 continue;
160 if (radeon_conflict->use_digital)
161 continue;
163 if (priority == true) {
164 DRM_INFO("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
165 DRM_INFO("in favor of %s\n", drm_get_connector_name(connector));
166 conflict->status = connector_status_disconnected;
167 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
168 } else {
169 DRM_INFO("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
170 DRM_INFO("in favor of %s\n", drm_get_connector_name(conflict));
171 current_status = connector_status_disconnected;
173 break;
177 return current_status;
181 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
183 struct drm_device *dev = encoder->dev;
184 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
185 struct drm_display_mode *mode = NULL;
186 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
188 if (native_mode->hdisplay != 0 &&
189 native_mode->vdisplay != 0 &&
190 native_mode->clock != 0) {
191 mode = drm_mode_duplicate(dev, native_mode);
192 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
193 drm_mode_set_name(mode);
195 DRM_DEBUG("Adding native panel mode %s\n", mode->name);
197 return mode;
200 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
202 struct drm_device *dev = encoder->dev;
203 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
204 struct drm_display_mode *mode = NULL;
205 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
206 int i;
207 struct mode_size {
208 int w;
209 int h;
210 } common_modes[17] = {
211 { 640, 480},
212 { 720, 480},
213 { 800, 600},
214 { 848, 480},
215 {1024, 768},
216 {1152, 768},
217 {1280, 720},
218 {1280, 800},
219 {1280, 854},
220 {1280, 960},
221 {1280, 1024},
222 {1440, 900},
223 {1400, 1050},
224 {1680, 1050},
225 {1600, 1200},
226 {1920, 1080},
227 {1920, 1200}
230 for (i = 0; i < 17; i++) {
231 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
232 if (common_modes[i].w > 1024 ||
233 common_modes[i].h > 768)
234 continue;
236 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
237 if (common_modes[i].w > native_mode->hdisplay ||
238 common_modes[i].h > native_mode->vdisplay ||
239 (common_modes[i].w == native_mode->hdisplay &&
240 common_modes[i].h == native_mode->vdisplay))
241 continue;
243 if (common_modes[i].w < 320 || common_modes[i].h < 200)
244 continue;
246 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
247 drm_mode_probed_add(connector, mode);
251 int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
252 uint64_t val)
254 struct drm_device *dev = connector->dev;
255 struct radeon_device *rdev = dev->dev_private;
256 struct drm_encoder *encoder;
257 struct radeon_encoder *radeon_encoder;
259 if (property == rdev->mode_info.coherent_mode_property) {
260 struct radeon_encoder_atom_dig *dig;
262 /* need to find digital encoder on connector */
263 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
264 if (!encoder)
265 return 0;
267 radeon_encoder = to_radeon_encoder(encoder);
269 if (!radeon_encoder->enc_priv)
270 return 0;
272 dig = radeon_encoder->enc_priv;
273 dig->coherent_mode = val ? true : false;
274 radeon_property_change_mode(&radeon_encoder->base);
277 if (property == rdev->mode_info.tv_std_property) {
278 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
279 if (!encoder) {
280 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
283 if (!encoder)
284 return 0;
286 radeon_encoder = to_radeon_encoder(encoder);
287 if (!radeon_encoder->enc_priv)
288 return 0;
289 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
290 struct radeon_encoder_atom_dac *dac_int;
291 dac_int = radeon_encoder->enc_priv;
292 dac_int->tv_std = val;
293 } else {
294 struct radeon_encoder_tv_dac *dac_int;
295 dac_int = radeon_encoder->enc_priv;
296 dac_int->tv_std = val;
298 radeon_property_change_mode(&radeon_encoder->base);
301 if (property == rdev->mode_info.load_detect_property) {
302 struct radeon_connector *radeon_connector =
303 to_radeon_connector(connector);
305 if (val == 0)
306 radeon_connector->dac_load_detect = false;
307 else
308 radeon_connector->dac_load_detect = true;
311 if (property == rdev->mode_info.tmds_pll_property) {
312 struct radeon_encoder_int_tmds *tmds = NULL;
313 bool ret = false;
314 /* need to find digital encoder on connector */
315 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
316 if (!encoder)
317 return 0;
319 radeon_encoder = to_radeon_encoder(encoder);
321 tmds = radeon_encoder->enc_priv;
322 if (!tmds)
323 return 0;
325 if (val == 0) {
326 if (rdev->is_atom_bios)
327 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
328 else
329 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
331 if (val == 1 || ret == false) {
332 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
334 radeon_property_change_mode(&radeon_encoder->base);
337 return 0;
340 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
341 struct drm_connector *connector)
343 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
344 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
346 /* Try to get native mode details from EDID if necessary */
347 if (!native_mode->clock) {
348 struct drm_display_mode *t, *mode;
350 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
351 if (mode->hdisplay == native_mode->hdisplay &&
352 mode->vdisplay == native_mode->vdisplay) {
353 *native_mode = *mode;
354 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
355 DRM_INFO("Determined LVDS native mode details from EDID\n");
356 break;
360 if (!native_mode->clock) {
361 DRM_INFO("No LVDS native mode details, disabling RMX\n");
362 radeon_encoder->rmx_type = RMX_OFF;
366 static int radeon_lvds_get_modes(struct drm_connector *connector)
368 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
369 struct drm_encoder *encoder;
370 int ret = 0;
371 struct drm_display_mode *mode;
373 if (radeon_connector->ddc_bus) {
374 ret = radeon_ddc_get_modes(radeon_connector);
375 if (ret > 0) {
376 encoder = radeon_best_single_encoder(connector);
377 if (encoder) {
378 radeon_fixup_lvds_native_mode(encoder, connector);
379 /* add scaled modes */
380 radeon_add_common_modes(encoder, connector);
382 return ret;
386 encoder = radeon_best_single_encoder(connector);
387 if (!encoder)
388 return 0;
390 /* we have no EDID modes */
391 mode = radeon_fp_native_mode(encoder);
392 if (mode) {
393 ret = 1;
394 drm_mode_probed_add(connector, mode);
395 /* add scaled modes */
396 radeon_add_common_modes(encoder, connector);
399 return ret;
402 static int radeon_lvds_mode_valid(struct drm_connector *connector,
403 struct drm_display_mode *mode)
405 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
407 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
408 return MODE_PANEL;
410 if (encoder) {
411 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
412 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
414 /* AVIVO hardware supports downscaling modes larger than the panel
415 * to the panel size, but I'm not sure this is desirable.
417 if ((mode->hdisplay > native_mode->hdisplay) ||
418 (mode->vdisplay > native_mode->vdisplay))
419 return MODE_PANEL;
421 /* if scaling is disabled, block non-native modes */
422 if (radeon_encoder->rmx_type == RMX_OFF) {
423 if ((mode->hdisplay != native_mode->hdisplay) ||
424 (mode->vdisplay != native_mode->vdisplay))
425 return MODE_PANEL;
429 return MODE_OK;
432 static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connector)
434 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
435 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
436 enum drm_connector_status ret = connector_status_disconnected;
438 if (encoder) {
439 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
440 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
442 /* check if panel is valid */
443 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
444 ret = connector_status_connected;
448 /* check for edid as well */
449 if (radeon_connector->edid)
450 ret = connector_status_connected;
451 else {
452 if (radeon_connector->ddc_bus) {
453 radeon_i2c_do_lock(radeon_connector, 1);
454 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
455 &radeon_connector->ddc_bus->adapter);
456 radeon_i2c_do_lock(radeon_connector, 0);
457 if (radeon_connector->edid)
458 ret = connector_status_connected;
461 /* check acpi lid status ??? */
463 radeon_connector_update_scratch_regs(connector, ret);
464 return ret;
467 static void radeon_connector_destroy(struct drm_connector *connector)
469 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
471 if (radeon_connector->ddc_bus)
472 radeon_i2c_destroy(radeon_connector->ddc_bus);
473 if (radeon_connector->edid)
474 kfree(radeon_connector->edid);
475 kfree(radeon_connector->con_priv);
476 drm_sysfs_connector_remove(connector);
477 drm_connector_cleanup(connector);
478 kfree(connector);
481 static int radeon_lvds_set_property(struct drm_connector *connector,
482 struct drm_property *property,
483 uint64_t value)
485 struct drm_device *dev = connector->dev;
486 struct radeon_encoder *radeon_encoder;
487 enum radeon_rmx_type rmx_type;
489 DRM_DEBUG("\n");
490 if (property != dev->mode_config.scaling_mode_property)
491 return 0;
493 if (connector->encoder)
494 radeon_encoder = to_radeon_encoder(connector->encoder);
495 else {
496 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
497 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
500 switch (value) {
501 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
502 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
503 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
504 default:
505 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
507 if (radeon_encoder->rmx_type == rmx_type)
508 return 0;
510 radeon_encoder->rmx_type = rmx_type;
512 radeon_property_change_mode(&radeon_encoder->base);
513 return 0;
517 struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
518 .get_modes = radeon_lvds_get_modes,
519 .mode_valid = radeon_lvds_mode_valid,
520 .best_encoder = radeon_best_single_encoder,
523 struct drm_connector_funcs radeon_lvds_connector_funcs = {
524 .dpms = drm_helper_connector_dpms,
525 .detect = radeon_lvds_detect,
526 .fill_modes = drm_helper_probe_single_connector_modes,
527 .destroy = radeon_connector_destroy,
528 .set_property = radeon_lvds_set_property,
531 static int radeon_vga_get_modes(struct drm_connector *connector)
533 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
534 int ret;
536 ret = radeon_ddc_get_modes(radeon_connector);
538 return ret;
541 static int radeon_vga_mode_valid(struct drm_connector *connector,
542 struct drm_display_mode *mode)
544 /* XXX check mode bandwidth */
545 /* XXX verify against max DAC output frequency */
546 return MODE_OK;
549 static enum drm_connector_status radeon_vga_detect(struct drm_connector *connector)
551 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
552 struct drm_encoder *encoder;
553 struct drm_encoder_helper_funcs *encoder_funcs;
554 bool dret;
555 enum drm_connector_status ret = connector_status_disconnected;
557 encoder = radeon_best_single_encoder(connector);
558 if (!encoder)
559 ret = connector_status_disconnected;
561 radeon_i2c_do_lock(radeon_connector, 1);
562 dret = radeon_ddc_probe(radeon_connector);
563 radeon_i2c_do_lock(radeon_connector, 0);
564 if (dret) {
565 if (radeon_connector->edid) {
566 kfree(radeon_connector->edid);
567 radeon_connector->edid = NULL;
569 radeon_i2c_do_lock(radeon_connector, 1);
570 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
571 radeon_i2c_do_lock(radeon_connector, 0);
573 if (!radeon_connector->edid) {
574 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
575 drm_get_connector_name(connector));
576 ret = connector_status_connected;
577 } else {
578 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
580 /* some oems have boards with separate digital and analog connectors
581 * with a shared ddc line (often vga + hdmi)
583 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
584 kfree(radeon_connector->edid);
585 radeon_connector->edid = NULL;
586 ret = connector_status_disconnected;
587 } else
588 ret = connector_status_connected;
590 } else {
591 if (radeon_connector->dac_load_detect) {
592 encoder_funcs = encoder->helper_private;
593 ret = encoder_funcs->detect(encoder, connector);
597 if (ret == connector_status_connected)
598 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
599 radeon_connector_update_scratch_regs(connector, ret);
600 return ret;
603 struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
604 .get_modes = radeon_vga_get_modes,
605 .mode_valid = radeon_vga_mode_valid,
606 .best_encoder = radeon_best_single_encoder,
609 struct drm_connector_funcs radeon_vga_connector_funcs = {
610 .dpms = drm_helper_connector_dpms,
611 .detect = radeon_vga_detect,
612 .fill_modes = drm_helper_probe_single_connector_modes,
613 .destroy = radeon_connector_destroy,
614 .set_property = radeon_connector_set_property,
617 static int radeon_tv_get_modes(struct drm_connector *connector)
619 struct drm_device *dev = connector->dev;
620 struct radeon_device *rdev = dev->dev_private;
621 struct drm_display_mode *tv_mode;
622 struct drm_encoder *encoder;
624 encoder = radeon_best_single_encoder(connector);
625 if (!encoder)
626 return 0;
628 /* avivo chips can scale any mode */
629 if (rdev->family >= CHIP_RS600)
630 /* add scaled modes */
631 radeon_add_common_modes(encoder, connector);
632 else {
633 /* only 800x600 is supported right now on pre-avivo chips */
634 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
635 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
636 drm_mode_probed_add(connector, tv_mode);
638 return 1;
641 static int radeon_tv_mode_valid(struct drm_connector *connector,
642 struct drm_display_mode *mode)
644 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
645 return MODE_CLOCK_RANGE;
646 return MODE_OK;
649 static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector)
651 struct drm_encoder *encoder;
652 struct drm_encoder_helper_funcs *encoder_funcs;
653 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
654 enum drm_connector_status ret = connector_status_disconnected;
656 if (!radeon_connector->dac_load_detect)
657 return ret;
659 encoder = radeon_best_single_encoder(connector);
660 if (!encoder)
661 ret = connector_status_disconnected;
662 else {
663 encoder_funcs = encoder->helper_private;
664 ret = encoder_funcs->detect(encoder, connector);
666 if (ret == connector_status_connected)
667 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
668 radeon_connector_update_scratch_regs(connector, ret);
669 return ret;
672 struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
673 .get_modes = radeon_tv_get_modes,
674 .mode_valid = radeon_tv_mode_valid,
675 .best_encoder = radeon_best_single_encoder,
678 struct drm_connector_funcs radeon_tv_connector_funcs = {
679 .dpms = drm_helper_connector_dpms,
680 .detect = radeon_tv_detect,
681 .fill_modes = drm_helper_probe_single_connector_modes,
682 .destroy = radeon_connector_destroy,
683 .set_property = radeon_connector_set_property,
686 static int radeon_dvi_get_modes(struct drm_connector *connector)
688 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
689 int ret;
691 ret = radeon_ddc_get_modes(radeon_connector);
692 return ret;
696 * DVI is complicated
697 * Do a DDC probe, if DDC probe passes, get the full EDID so
698 * we can do analog/digital monitor detection at this point.
699 * If the monitor is an analog monitor or we got no DDC,
700 * we need to find the DAC encoder object for this connector.
701 * If we got no DDC, we do load detection on the DAC encoder object.
702 * If we got analog DDC or load detection passes on the DAC encoder
703 * we have to check if this analog encoder is shared with anyone else (TV)
704 * if its shared we have to set the other connector to disconnected.
706 static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector)
708 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
709 struct drm_encoder *encoder = NULL;
710 struct drm_encoder_helper_funcs *encoder_funcs;
711 struct drm_mode_object *obj;
712 int i;
713 enum drm_connector_status ret = connector_status_disconnected;
714 bool dret;
716 radeon_i2c_do_lock(radeon_connector, 1);
717 dret = radeon_ddc_probe(radeon_connector);
718 radeon_i2c_do_lock(radeon_connector, 0);
719 if (dret) {
720 if (radeon_connector->edid) {
721 kfree(radeon_connector->edid);
722 radeon_connector->edid = NULL;
724 radeon_i2c_do_lock(radeon_connector, 1);
725 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
726 radeon_i2c_do_lock(radeon_connector, 0);
728 if (!radeon_connector->edid) {
729 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
730 drm_get_connector_name(connector));
731 } else {
732 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
734 /* some oems have boards with separate digital and analog connectors
735 * with a shared ddc line (often vga + hdmi)
737 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
738 kfree(radeon_connector->edid);
739 radeon_connector->edid = NULL;
740 ret = connector_status_disconnected;
741 } else
742 ret = connector_status_connected;
746 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
747 goto out;
749 /* find analog encoder */
750 if (radeon_connector->dac_load_detect) {
751 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
752 if (connector->encoder_ids[i] == 0)
753 break;
755 obj = drm_mode_object_find(connector->dev,
756 connector->encoder_ids[i],
757 DRM_MODE_OBJECT_ENCODER);
758 if (!obj)
759 continue;
761 encoder = obj_to_encoder(obj);
763 encoder_funcs = encoder->helper_private;
764 if (encoder_funcs->detect) {
765 if (ret != connector_status_connected) {
766 ret = encoder_funcs->detect(encoder, connector);
767 if (ret == connector_status_connected) {
768 radeon_connector->use_digital = false;
771 break;
776 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
777 encoder) {
778 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
781 out:
782 /* updated in get modes as well since we need to know if it's analog or digital */
783 radeon_connector_update_scratch_regs(connector, ret);
784 return ret;
787 /* okay need to be smart in here about which encoder to pick */
788 struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
790 int enc_id = connector->encoder_ids[0];
791 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
792 struct drm_mode_object *obj;
793 struct drm_encoder *encoder;
794 int i;
795 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
796 if (connector->encoder_ids[i] == 0)
797 break;
799 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
800 if (!obj)
801 continue;
803 encoder = obj_to_encoder(obj);
805 if (radeon_connector->use_digital == true) {
806 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
807 return encoder;
808 } else {
809 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
810 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
811 return encoder;
815 /* see if we have a default encoder TODO */
817 /* then check use digitial */
818 /* pick the first one */
819 if (enc_id) {
820 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
821 if (!obj)
822 return NULL;
823 encoder = obj_to_encoder(obj);
824 return encoder;
826 return NULL;
829 static void radeon_dvi_force(struct drm_connector *connector)
831 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
832 if (connector->force == DRM_FORCE_ON)
833 radeon_connector->use_digital = false;
834 if (connector->force == DRM_FORCE_ON_DIGITAL)
835 radeon_connector->use_digital = true;
838 static int radeon_dvi_mode_valid(struct drm_connector *connector,
839 struct drm_display_mode *mode)
841 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
843 /* XXX check mode bandwidth */
845 if (radeon_connector->use_digital && (mode->clock > 165000)) {
846 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
847 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
848 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
849 return MODE_OK;
850 else
851 return MODE_CLOCK_HIGH;
853 return MODE_OK;
856 struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
857 .get_modes = radeon_dvi_get_modes,
858 .mode_valid = radeon_dvi_mode_valid,
859 .best_encoder = radeon_dvi_encoder,
862 struct drm_connector_funcs radeon_dvi_connector_funcs = {
863 .dpms = drm_helper_connector_dpms,
864 .detect = radeon_dvi_detect,
865 .fill_modes = drm_helper_probe_single_connector_modes,
866 .set_property = radeon_connector_set_property,
867 .destroy = radeon_connector_destroy,
868 .force = radeon_dvi_force,
871 void
872 radeon_add_atom_connector(struct drm_device *dev,
873 uint32_t connector_id,
874 uint32_t supported_device,
875 int connector_type,
876 struct radeon_i2c_bus_rec *i2c_bus,
877 bool linkb,
878 uint32_t igp_lane_info,
879 uint16_t connector_object_id)
881 struct radeon_device *rdev = dev->dev_private;
882 struct drm_connector *connector;
883 struct radeon_connector *radeon_connector;
884 struct radeon_connector_atom_dig *radeon_dig_connector;
885 uint32_t subpixel_order = SubPixelNone;
886 bool shared_ddc = false;
887 int ret;
889 /* fixme - tv/cv/din */
890 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
891 return;
893 /* see if we already added it */
894 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
895 radeon_connector = to_radeon_connector(connector);
896 if (radeon_connector->connector_id == connector_id) {
897 radeon_connector->devices |= supported_device;
898 return;
900 if (radeon_connector->ddc_bus && i2c_bus->valid) {
901 if (memcmp(&radeon_connector->ddc_bus->rec, i2c_bus,
902 sizeof(struct radeon_i2c_bus_rec)) == 0) {
903 radeon_connector->shared_ddc = true;
904 shared_ddc = true;
909 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
910 if (!radeon_connector)
911 return;
913 connector = &radeon_connector->base;
915 radeon_connector->connector_id = connector_id;
916 radeon_connector->devices = supported_device;
917 radeon_connector->shared_ddc = shared_ddc;
918 radeon_connector->connector_object_id = connector_object_id;
919 switch (connector_type) {
920 case DRM_MODE_CONNECTOR_VGA:
921 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
922 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
923 if (ret)
924 goto failed;
925 if (i2c_bus->valid) {
926 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
927 if (!radeon_connector->ddc_bus)
928 goto failed;
930 radeon_connector->dac_load_detect = true;
931 drm_connector_attach_property(&radeon_connector->base,
932 rdev->mode_info.load_detect_property,
934 break;
935 case DRM_MODE_CONNECTOR_DVIA:
936 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
937 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
938 if (ret)
939 goto failed;
940 if (i2c_bus->valid) {
941 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
942 if (!radeon_connector->ddc_bus)
943 goto failed;
945 radeon_connector->dac_load_detect = true;
946 drm_connector_attach_property(&radeon_connector->base,
947 rdev->mode_info.load_detect_property,
949 break;
950 case DRM_MODE_CONNECTOR_DVII:
951 case DRM_MODE_CONNECTOR_DVID:
952 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
953 if (!radeon_dig_connector)
954 goto failed;
955 radeon_dig_connector->linkb = linkb;
956 radeon_dig_connector->igp_lane_info = igp_lane_info;
957 radeon_connector->con_priv = radeon_dig_connector;
958 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
959 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
960 if (ret)
961 goto failed;
962 if (i2c_bus->valid) {
963 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
964 if (!radeon_connector->ddc_bus)
965 goto failed;
967 subpixel_order = SubPixelHorizontalRGB;
968 drm_connector_attach_property(&radeon_connector->base,
969 rdev->mode_info.coherent_mode_property,
971 radeon_connector->dac_load_detect = true;
972 drm_connector_attach_property(&radeon_connector->base,
973 rdev->mode_info.load_detect_property,
975 break;
976 case DRM_MODE_CONNECTOR_HDMIA:
977 case DRM_MODE_CONNECTOR_HDMIB:
978 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
979 if (!radeon_dig_connector)
980 goto failed;
981 radeon_dig_connector->linkb = linkb;
982 radeon_dig_connector->igp_lane_info = igp_lane_info;
983 radeon_connector->con_priv = radeon_dig_connector;
984 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
985 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
986 if (ret)
987 goto failed;
988 if (i2c_bus->valid) {
989 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI");
990 if (!radeon_connector->ddc_bus)
991 goto failed;
993 drm_connector_attach_property(&radeon_connector->base,
994 rdev->mode_info.coherent_mode_property,
996 subpixel_order = SubPixelHorizontalRGB;
997 break;
998 case DRM_MODE_CONNECTOR_DisplayPort:
999 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1000 if (!radeon_dig_connector)
1001 goto failed;
1002 radeon_dig_connector->linkb = linkb;
1003 radeon_dig_connector->igp_lane_info = igp_lane_info;
1004 radeon_connector->con_priv = radeon_dig_connector;
1005 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1006 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1007 if (ret)
1008 goto failed;
1009 if (i2c_bus->valid) {
1010 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
1011 if (!radeon_connector->ddc_bus)
1012 goto failed;
1014 subpixel_order = SubPixelHorizontalRGB;
1015 break;
1016 case DRM_MODE_CONNECTOR_SVIDEO:
1017 case DRM_MODE_CONNECTOR_Composite:
1018 case DRM_MODE_CONNECTOR_9PinDIN:
1019 if (radeon_tv == 1) {
1020 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1021 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1022 if (ret)
1023 goto failed;
1024 radeon_connector->dac_load_detect = true;
1025 drm_connector_attach_property(&radeon_connector->base,
1026 rdev->mode_info.load_detect_property,
1029 break;
1030 case DRM_MODE_CONNECTOR_LVDS:
1031 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1032 if (!radeon_dig_connector)
1033 goto failed;
1034 radeon_dig_connector->linkb = linkb;
1035 radeon_dig_connector->igp_lane_info = igp_lane_info;
1036 radeon_connector->con_priv = radeon_dig_connector;
1037 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1038 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1039 if (ret)
1040 goto failed;
1041 if (i2c_bus->valid) {
1042 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1043 if (!radeon_connector->ddc_bus)
1044 goto failed;
1046 drm_mode_create_scaling_mode_property(dev);
1047 drm_connector_attach_property(&radeon_connector->base,
1048 dev->mode_config.scaling_mode_property,
1049 DRM_MODE_SCALE_FULLSCREEN);
1050 subpixel_order = SubPixelHorizontalRGB;
1051 break;
1054 connector->display_info.subpixel_order = subpixel_order;
1055 drm_sysfs_connector_add(connector);
1056 return;
1058 failed:
1059 if (radeon_connector->ddc_bus)
1060 radeon_i2c_destroy(radeon_connector->ddc_bus);
1061 drm_connector_cleanup(connector);
1062 kfree(connector);
1065 void
1066 radeon_add_legacy_connector(struct drm_device *dev,
1067 uint32_t connector_id,
1068 uint32_t supported_device,
1069 int connector_type,
1070 struct radeon_i2c_bus_rec *i2c_bus,
1071 uint16_t connector_object_id)
1073 struct radeon_device *rdev = dev->dev_private;
1074 struct drm_connector *connector;
1075 struct radeon_connector *radeon_connector;
1076 uint32_t subpixel_order = SubPixelNone;
1077 int ret;
1079 /* fixme - tv/cv/din */
1080 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1081 return;
1083 /* see if we already added it */
1084 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1085 radeon_connector = to_radeon_connector(connector);
1086 if (radeon_connector->connector_id == connector_id) {
1087 radeon_connector->devices |= supported_device;
1088 return;
1092 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1093 if (!radeon_connector)
1094 return;
1096 connector = &radeon_connector->base;
1098 radeon_connector->connector_id = connector_id;
1099 radeon_connector->devices = supported_device;
1100 radeon_connector->connector_object_id = connector_object_id;
1101 switch (connector_type) {
1102 case DRM_MODE_CONNECTOR_VGA:
1103 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1104 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1105 if (ret)
1106 goto failed;
1107 if (i2c_bus->valid) {
1108 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1109 if (!radeon_connector->ddc_bus)
1110 goto failed;
1112 radeon_connector->dac_load_detect = true;
1113 drm_connector_attach_property(&radeon_connector->base,
1114 rdev->mode_info.load_detect_property,
1116 break;
1117 case DRM_MODE_CONNECTOR_DVIA:
1118 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1119 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1120 if (ret)
1121 goto failed;
1122 if (i2c_bus->valid) {
1123 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1124 if (!radeon_connector->ddc_bus)
1125 goto failed;
1127 radeon_connector->dac_load_detect = true;
1128 drm_connector_attach_property(&radeon_connector->base,
1129 rdev->mode_info.load_detect_property,
1131 break;
1132 case DRM_MODE_CONNECTOR_DVII:
1133 case DRM_MODE_CONNECTOR_DVID:
1134 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1135 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1136 if (ret)
1137 goto failed;
1138 if (i2c_bus->valid) {
1139 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1140 if (!radeon_connector->ddc_bus)
1141 goto failed;
1142 radeon_connector->dac_load_detect = true;
1143 drm_connector_attach_property(&radeon_connector->base,
1144 rdev->mode_info.load_detect_property,
1147 subpixel_order = SubPixelHorizontalRGB;
1148 break;
1149 case DRM_MODE_CONNECTOR_SVIDEO:
1150 case DRM_MODE_CONNECTOR_Composite:
1151 case DRM_MODE_CONNECTOR_9PinDIN:
1152 if (radeon_tv == 1) {
1153 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1154 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1155 if (ret)
1156 goto failed;
1157 radeon_connector->dac_load_detect = true;
1158 /* RS400,RC410,RS480 chipset seems to report a lot
1159 * of false positive on load detect, we haven't yet
1160 * found a way to make load detect reliable on those
1161 * chipset, thus just disable it for TV.
1163 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1164 radeon_connector->dac_load_detect = false;
1165 drm_connector_attach_property(&radeon_connector->base,
1166 rdev->mode_info.load_detect_property,
1169 break;
1170 case DRM_MODE_CONNECTOR_LVDS:
1171 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1172 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1173 if (ret)
1174 goto failed;
1175 if (i2c_bus->valid) {
1176 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1177 if (!radeon_connector->ddc_bus)
1178 goto failed;
1180 drm_connector_attach_property(&radeon_connector->base,
1181 dev->mode_config.scaling_mode_property,
1182 DRM_MODE_SCALE_FULLSCREEN);
1183 subpixel_order = SubPixelHorizontalRGB;
1184 break;
1187 connector->display_info.subpixel_order = subpixel_order;
1188 drm_sysfs_connector_add(connector);
1189 return;
1191 failed:
1192 if (radeon_connector->ddc_bus)
1193 radeon_i2c_destroy(radeon_connector->ddc_bus);
1194 drm_connector_cleanup(connector);
1195 kfree(connector);