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
28 #include "drm_crtc_helper.h"
29 #include "drm_fb_helper.h"
30 #include "radeon_drm.h"
35 radeon_combios_connected_scratch_regs(struct drm_connector *connector,
36 struct drm_encoder *encoder,
39 radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
40 struct drm_encoder *encoder,
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);
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;
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)
92 obj = drm_mode_object_find(connector->dev,
93 connector->encoder_ids[i],
94 DRM_MODE_OBJECT_ENCODER);
98 encoder = obj_to_encoder(obj);
100 if ((encoder == best_encoder) && (status == connector_status_connected))
105 if (rdev->is_atom_bios)
106 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
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;
119 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
120 if (connector->encoder_ids[i] == 0)
123 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
127 encoder = obj_to_encoder(obj);
128 if (encoder->encoder_type == encoder_type)
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 */
142 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
145 encoder = obj_to_encoder(obj);
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,
163 struct drm_device *dev = connector->dev;
164 struct drm_connector *conflict;
167 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
168 if (conflict == connector)
171 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
172 if (conflict->encoder_ids[i] == 0)
175 /* if the IDs match */
176 if (conflict->encoder_ids[i] == encoder->base.id) {
177 if (conflict->status != connector_status_connected)
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);
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;
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
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);
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;
239 } common_modes[17] = {
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)
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))
272 if (common_modes[i].w < 320 || common_modes[i].h < 200)
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,
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);
296 radeon_encoder = to_radeon_encoder(encoder);
298 if (!radeon_encoder->enc_priv)
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);
309 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
315 radeon_encoder = to_radeon_encoder(encoder);
316 if (!radeon_encoder->enc_priv)
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;
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);
335 radeon_connector->dac_load_detect = false;
337 radeon_connector->dac_load_detect = true;
340 if (property == rdev->mode_info.tmds_pll_property) {
341 struct radeon_encoder_int_tmds *tmds = NULL;
343 /* need to find digital encoder on connector */
344 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
348 radeon_encoder = to_radeon_encoder(encoder);
350 tmds = radeon_encoder->enc_priv;
355 if (rdev->is_atom_bios)
356 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
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);
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");
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;
400 struct drm_display_mode *mode;
402 if (radeon_connector->ddc_bus) {
403 ret = radeon_ddc_get_modes(radeon_connector);
405 encoder = radeon_best_single_encoder(connector);
407 radeon_fixup_lvds_native_mode(encoder, connector);
408 /* add scaled modes */
409 radeon_add_common_modes(encoder, connector);
415 encoder = radeon_best_single_encoder(connector);
419 /* we have no EDID modes */
420 mode = radeon_fp_native_mode(encoder);
423 drm_mode_probed_add(connector, mode);
424 /* add scaled modes */
425 radeon_add_common_modes(encoder, connector);
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))
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))
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))
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;
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;
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);
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);
510 static int radeon_lvds_set_property(struct drm_connector *connector,
511 struct drm_property *property,
514 struct drm_device *dev = connector->dev;
515 struct radeon_encoder *radeon_encoder;
516 enum radeon_rmx_type rmx_type;
519 if (property != dev->mode_config.scaling_mode_property)
522 if (connector->encoder)
523 radeon_encoder = to_radeon_encoder(connector->encoder);
525 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
526 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
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;
534 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
536 if (radeon_encoder->rmx_type == rmx_type)
539 radeon_encoder->rmx_type = rmx_type;
541 radeon_property_change_mode(&radeon_encoder->base);
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);
565 ret = radeon_ddc_get_modes(radeon_connector);
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 */
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;
584 enum drm_connector_status ret = connector_status_disconnected;
586 encoder = radeon_best_single_encoder(connector);
588 ret = connector_status_disconnected;
590 if (radeon_connector->ddc_bus) {
591 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
592 dret = radeon_ddc_probe(radeon_connector);
593 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
596 if (radeon_connector->edid) {
597 kfree(radeon_connector->edid);
598 radeon_connector->edid = NULL;
600 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
601 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
602 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
604 if (!radeon_connector->edid) {
605 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
606 drm_get_connector_name(connector));
607 ret = connector_status_connected;
609 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
611 /* some oems have boards with separate digital and analog connectors
612 * with a shared ddc line (often vga + hdmi)
614 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
615 kfree(radeon_connector->edid);
616 radeon_connector->edid = NULL;
617 ret = connector_status_disconnected;
619 ret = connector_status_connected;
622 if (radeon_connector->dac_load_detect && encoder) {
623 encoder_funcs = encoder->helper_private;
624 ret = encoder_funcs->detect(encoder, connector);
628 if (ret == connector_status_connected)
629 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
630 radeon_connector_update_scratch_regs(connector, ret);
634 struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
635 .get_modes = radeon_vga_get_modes,
636 .mode_valid = radeon_vga_mode_valid,
637 .best_encoder = radeon_best_single_encoder,
640 struct drm_connector_funcs radeon_vga_connector_funcs = {
641 .dpms = drm_helper_connector_dpms,
642 .detect = radeon_vga_detect,
643 .fill_modes = drm_helper_probe_single_connector_modes,
644 .destroy = radeon_connector_destroy,
645 .set_property = radeon_connector_set_property,
648 static int radeon_tv_get_modes(struct drm_connector *connector)
650 struct drm_device *dev = connector->dev;
651 struct radeon_device *rdev = dev->dev_private;
652 struct drm_display_mode *tv_mode;
653 struct drm_encoder *encoder;
655 encoder = radeon_best_single_encoder(connector);
659 /* avivo chips can scale any mode */
660 if (rdev->family >= CHIP_RS600)
661 /* add scaled modes */
662 radeon_add_common_modes(encoder, connector);
664 /* only 800x600 is supported right now on pre-avivo chips */
665 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
666 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
667 drm_mode_probed_add(connector, tv_mode);
672 static int radeon_tv_mode_valid(struct drm_connector *connector,
673 struct drm_display_mode *mode)
675 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
676 return MODE_CLOCK_RANGE;
680 static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector)
682 struct drm_encoder *encoder;
683 struct drm_encoder_helper_funcs *encoder_funcs;
684 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
685 enum drm_connector_status ret = connector_status_disconnected;
687 if (!radeon_connector->dac_load_detect)
690 encoder = radeon_best_single_encoder(connector);
692 ret = connector_status_disconnected;
694 encoder_funcs = encoder->helper_private;
695 ret = encoder_funcs->detect(encoder, connector);
697 if (ret == connector_status_connected)
698 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
699 radeon_connector_update_scratch_regs(connector, ret);
703 struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
704 .get_modes = radeon_tv_get_modes,
705 .mode_valid = radeon_tv_mode_valid,
706 .best_encoder = radeon_best_single_encoder,
709 struct drm_connector_funcs radeon_tv_connector_funcs = {
710 .dpms = drm_helper_connector_dpms,
711 .detect = radeon_tv_detect,
712 .fill_modes = drm_helper_probe_single_connector_modes,
713 .destroy = radeon_connector_destroy,
714 .set_property = radeon_connector_set_property,
717 static int radeon_dvi_get_modes(struct drm_connector *connector)
719 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
722 ret = radeon_ddc_get_modes(radeon_connector);
728 * Do a DDC probe, if DDC probe passes, get the full EDID so
729 * we can do analog/digital monitor detection at this point.
730 * If the monitor is an analog monitor or we got no DDC,
731 * we need to find the DAC encoder object for this connector.
732 * If we got no DDC, we do load detection on the DAC encoder object.
733 * If we got analog DDC or load detection passes on the DAC encoder
734 * we have to check if this analog encoder is shared with anyone else (TV)
735 * if its shared we have to set the other connector to disconnected.
737 static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector)
739 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
740 struct drm_encoder *encoder = NULL;
741 struct drm_encoder_helper_funcs *encoder_funcs;
742 struct drm_mode_object *obj;
744 enum drm_connector_status ret = connector_status_disconnected;
747 if (radeon_connector->ddc_bus) {
748 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
749 dret = radeon_ddc_probe(radeon_connector);
750 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
753 if (radeon_connector->edid) {
754 kfree(radeon_connector->edid);
755 radeon_connector->edid = NULL;
757 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
758 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
759 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
761 if (!radeon_connector->edid) {
762 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
763 drm_get_connector_name(connector));
765 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
767 /* some oems have boards with separate digital and analog connectors
768 * with a shared ddc line (often vga + hdmi)
770 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
771 kfree(radeon_connector->edid);
772 radeon_connector->edid = NULL;
773 ret = connector_status_disconnected;
775 ret = connector_status_connected;
777 /* multiple connectors on the same encoder with the same ddc line
778 * This tends to be HDMI and DVI on the same encoder with the
779 * same ddc line. If the edid says HDMI, consider the HDMI port
780 * connected and the DVI port disconnected. If the edid doesn't
781 * say HDMI, vice versa.
783 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
784 struct drm_device *dev = connector->dev;
785 struct drm_connector *list_connector;
786 struct radeon_connector *list_radeon_connector;
787 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
788 if (connector == list_connector)
790 list_radeon_connector = to_radeon_connector(list_connector);
791 if (radeon_connector->devices == list_radeon_connector->devices) {
792 if (drm_detect_hdmi_monitor(radeon_connector->edid)) {
793 if (connector->connector_type == DRM_MODE_CONNECTOR_DVID) {
794 kfree(radeon_connector->edid);
795 radeon_connector->edid = NULL;
796 ret = connector_status_disconnected;
799 if ((connector->connector_type == DRM_MODE_CONNECTOR_HDMIA) ||
800 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIB)) {
801 kfree(radeon_connector->edid);
802 radeon_connector->edid = NULL;
803 ret = connector_status_disconnected;
812 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
815 /* find analog encoder */
816 if (radeon_connector->dac_load_detect) {
817 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
818 if (connector->encoder_ids[i] == 0)
821 obj = drm_mode_object_find(connector->dev,
822 connector->encoder_ids[i],
823 DRM_MODE_OBJECT_ENCODER);
827 encoder = obj_to_encoder(obj);
829 encoder_funcs = encoder->helper_private;
830 if (encoder_funcs->detect) {
831 if (ret != connector_status_connected) {
832 ret = encoder_funcs->detect(encoder, connector);
833 if (ret == connector_status_connected) {
834 radeon_connector->use_digital = false;
842 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
844 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
848 /* updated in get modes as well since we need to know if it's analog or digital */
849 radeon_connector_update_scratch_regs(connector, ret);
853 /* okay need to be smart in here about which encoder to pick */
854 struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
856 int enc_id = connector->encoder_ids[0];
857 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
858 struct drm_mode_object *obj;
859 struct drm_encoder *encoder;
861 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
862 if (connector->encoder_ids[i] == 0)
865 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
869 encoder = obj_to_encoder(obj);
871 if (radeon_connector->use_digital == true) {
872 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
875 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
876 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
881 /* see if we have a default encoder TODO */
883 /* then check use digitial */
884 /* pick the first one */
886 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
889 encoder = obj_to_encoder(obj);
895 static void radeon_dvi_force(struct drm_connector *connector)
897 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
898 if (connector->force == DRM_FORCE_ON)
899 radeon_connector->use_digital = false;
900 if (connector->force == DRM_FORCE_ON_DIGITAL)
901 radeon_connector->use_digital = true;
904 static int radeon_dvi_mode_valid(struct drm_connector *connector,
905 struct drm_display_mode *mode)
907 struct drm_device *dev = connector->dev;
908 struct radeon_device *rdev = dev->dev_private;
909 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
911 /* XXX check mode bandwidth */
913 /* clocks over 135 MHz have heat issues with DVI on RV100 */
914 if (radeon_connector->use_digital &&
915 (rdev->family == CHIP_RV100) &&
916 (mode->clock > 135000))
917 return MODE_CLOCK_HIGH;
919 if (radeon_connector->use_digital && (mode->clock > 165000)) {
920 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
921 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
922 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
925 return MODE_CLOCK_HIGH;
930 struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
931 .get_modes = radeon_dvi_get_modes,
932 .mode_valid = radeon_dvi_mode_valid,
933 .best_encoder = radeon_dvi_encoder,
936 struct drm_connector_funcs radeon_dvi_connector_funcs = {
937 .dpms = drm_helper_connector_dpms,
938 .detect = radeon_dvi_detect,
939 .fill_modes = drm_helper_probe_single_connector_modes,
940 .set_property = radeon_connector_set_property,
941 .destroy = radeon_connector_destroy,
942 .force = radeon_dvi_force,
945 static void radeon_dp_connector_destroy(struct drm_connector *connector)
947 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
948 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
950 if (radeon_connector->ddc_bus)
951 radeon_i2c_destroy(radeon_connector->ddc_bus);
952 if (radeon_connector->edid)
953 kfree(radeon_connector->edid);
954 if (radeon_dig_connector->dp_i2c_bus)
955 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
956 kfree(radeon_connector->con_priv);
957 drm_sysfs_connector_remove(connector);
958 drm_connector_cleanup(connector);
962 static int radeon_dp_get_modes(struct drm_connector *connector)
964 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
967 ret = radeon_ddc_get_modes(radeon_connector);
971 static enum drm_connector_status radeon_dp_detect(struct drm_connector *connector)
973 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
974 enum drm_connector_status ret = connector_status_disconnected;
975 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
978 if (radeon_connector->edid) {
979 kfree(radeon_connector->edid);
980 radeon_connector->edid = NULL;
983 sink_type = radeon_dp_getsinktype(radeon_connector);
984 if ((sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
985 (sink_type == CONNECTOR_OBJECT_ID_eDP)) {
986 if (radeon_dp_getdpcd(radeon_connector)) {
987 radeon_dig_connector->dp_sink_type = sink_type;
988 ret = connector_status_connected;
991 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
992 if (radeon_ddc_probe(radeon_connector)) {
993 radeon_dig_connector->dp_sink_type = sink_type;
994 ret = connector_status_connected;
996 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
1002 static int radeon_dp_mode_valid(struct drm_connector *connector,
1003 struct drm_display_mode *mode)
1005 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1006 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1008 /* XXX check mode bandwidth */
1010 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1011 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
1012 return radeon_dp_mode_valid_helper(radeon_connector, mode);
1017 struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1018 .get_modes = radeon_dp_get_modes,
1019 .mode_valid = radeon_dp_mode_valid,
1020 .best_encoder = radeon_dvi_encoder,
1023 struct drm_connector_funcs radeon_dp_connector_funcs = {
1024 .dpms = drm_helper_connector_dpms,
1025 .detect = radeon_dp_detect,
1026 .fill_modes = drm_helper_probe_single_connector_modes,
1027 .set_property = radeon_connector_set_property,
1028 .destroy = radeon_dp_connector_destroy,
1029 .force = radeon_dvi_force,
1033 radeon_add_atom_connector(struct drm_device *dev,
1034 uint32_t connector_id,
1035 uint32_t supported_device,
1037 struct radeon_i2c_bus_rec *i2c_bus,
1039 uint32_t igp_lane_info,
1040 uint16_t connector_object_id,
1041 struct radeon_hpd *hpd)
1043 struct radeon_device *rdev = dev->dev_private;
1044 struct drm_connector *connector;
1045 struct radeon_connector *radeon_connector;
1046 struct radeon_connector_atom_dig *radeon_dig_connector;
1047 uint32_t subpixel_order = SubPixelNone;
1048 bool shared_ddc = false;
1051 /* fixme - tv/cv/din */
1052 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1055 /* see if we already added it */
1056 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1057 radeon_connector = to_radeon_connector(connector);
1058 if (radeon_connector->connector_id == connector_id) {
1059 radeon_connector->devices |= supported_device;
1062 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1063 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1064 radeon_connector->shared_ddc = true;
1070 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1071 if (!radeon_connector)
1074 connector = &radeon_connector->base;
1076 radeon_connector->connector_id = connector_id;
1077 radeon_connector->devices = supported_device;
1078 radeon_connector->shared_ddc = shared_ddc;
1079 radeon_connector->connector_object_id = connector_object_id;
1080 radeon_connector->hpd = *hpd;
1081 switch (connector_type) {
1082 case DRM_MODE_CONNECTOR_VGA:
1083 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1084 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1087 if (i2c_bus->valid) {
1088 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1089 if (!radeon_connector->ddc_bus)
1092 radeon_connector->dac_load_detect = true;
1093 drm_connector_attach_property(&radeon_connector->base,
1094 rdev->mode_info.load_detect_property,
1097 case DRM_MODE_CONNECTOR_DVIA:
1098 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1099 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1102 if (i2c_bus->valid) {
1103 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1104 if (!radeon_connector->ddc_bus)
1107 radeon_connector->dac_load_detect = true;
1108 drm_connector_attach_property(&radeon_connector->base,
1109 rdev->mode_info.load_detect_property,
1112 case DRM_MODE_CONNECTOR_DVII:
1113 case DRM_MODE_CONNECTOR_DVID:
1114 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1115 if (!radeon_dig_connector)
1117 radeon_dig_connector->linkb = linkb;
1118 radeon_dig_connector->igp_lane_info = igp_lane_info;
1119 radeon_connector->con_priv = radeon_dig_connector;
1120 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1121 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1124 if (i2c_bus->valid) {
1125 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1126 if (!radeon_connector->ddc_bus)
1129 subpixel_order = SubPixelHorizontalRGB;
1130 drm_connector_attach_property(&radeon_connector->base,
1131 rdev->mode_info.coherent_mode_property,
1133 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1134 radeon_connector->dac_load_detect = true;
1135 drm_connector_attach_property(&radeon_connector->base,
1136 rdev->mode_info.load_detect_property,
1140 case DRM_MODE_CONNECTOR_HDMIA:
1141 case DRM_MODE_CONNECTOR_HDMIB:
1142 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1143 if (!radeon_dig_connector)
1145 radeon_dig_connector->linkb = linkb;
1146 radeon_dig_connector->igp_lane_info = igp_lane_info;
1147 radeon_connector->con_priv = radeon_dig_connector;
1148 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1149 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1152 if (i2c_bus->valid) {
1153 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI");
1154 if (!radeon_connector->ddc_bus)
1157 drm_connector_attach_property(&radeon_connector->base,
1158 rdev->mode_info.coherent_mode_property,
1160 subpixel_order = SubPixelHorizontalRGB;
1162 case DRM_MODE_CONNECTOR_DisplayPort:
1163 case DRM_MODE_CONNECTOR_eDP:
1164 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1165 if (!radeon_dig_connector)
1167 radeon_dig_connector->linkb = linkb;
1168 radeon_dig_connector->igp_lane_info = igp_lane_info;
1169 radeon_connector->con_priv = radeon_dig_connector;
1170 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1171 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1174 if (i2c_bus->valid) {
1175 /* add DP i2c bus */
1176 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1177 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1179 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1180 if (!radeon_dig_connector->dp_i2c_bus)
1182 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1183 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "eDP");
1185 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
1186 if (!radeon_connector->ddc_bus)
1189 subpixel_order = SubPixelHorizontalRGB;
1190 drm_connector_attach_property(&radeon_connector->base,
1191 rdev->mode_info.coherent_mode_property,
1194 case DRM_MODE_CONNECTOR_SVIDEO:
1195 case DRM_MODE_CONNECTOR_Composite:
1196 case DRM_MODE_CONNECTOR_9PinDIN:
1197 if (radeon_tv == 1) {
1198 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1199 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1202 radeon_connector->dac_load_detect = true;
1203 drm_connector_attach_property(&radeon_connector->base,
1204 rdev->mode_info.load_detect_property,
1206 drm_connector_attach_property(&radeon_connector->base,
1207 rdev->mode_info.tv_std_property,
1208 radeon_atombios_get_tv_info(rdev));
1211 case DRM_MODE_CONNECTOR_LVDS:
1212 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1213 if (!radeon_dig_connector)
1215 radeon_dig_connector->linkb = linkb;
1216 radeon_dig_connector->igp_lane_info = igp_lane_info;
1217 radeon_connector->con_priv = radeon_dig_connector;
1218 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1219 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1222 if (i2c_bus->valid) {
1223 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1224 if (!radeon_connector->ddc_bus)
1227 drm_connector_attach_property(&radeon_connector->base,
1228 dev->mode_config.scaling_mode_property,
1229 DRM_MODE_SCALE_FULLSCREEN);
1230 subpixel_order = SubPixelHorizontalRGB;
1234 connector->display_info.subpixel_order = subpixel_order;
1235 drm_sysfs_connector_add(connector);
1239 if (radeon_connector->ddc_bus)
1240 radeon_i2c_destroy(radeon_connector->ddc_bus);
1241 drm_connector_cleanup(connector);
1246 radeon_add_legacy_connector(struct drm_device *dev,
1247 uint32_t connector_id,
1248 uint32_t supported_device,
1250 struct radeon_i2c_bus_rec *i2c_bus,
1251 uint16_t connector_object_id,
1252 struct radeon_hpd *hpd)
1254 struct radeon_device *rdev = dev->dev_private;
1255 struct drm_connector *connector;
1256 struct radeon_connector *radeon_connector;
1257 uint32_t subpixel_order = SubPixelNone;
1260 /* fixme - tv/cv/din */
1261 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1264 /* see if we already added it */
1265 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1266 radeon_connector = to_radeon_connector(connector);
1267 if (radeon_connector->connector_id == connector_id) {
1268 radeon_connector->devices |= supported_device;
1273 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1274 if (!radeon_connector)
1277 connector = &radeon_connector->base;
1279 radeon_connector->connector_id = connector_id;
1280 radeon_connector->devices = supported_device;
1281 radeon_connector->connector_object_id = connector_object_id;
1282 radeon_connector->hpd = *hpd;
1283 switch (connector_type) {
1284 case DRM_MODE_CONNECTOR_VGA:
1285 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1286 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1289 if (i2c_bus->valid) {
1290 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1291 if (!radeon_connector->ddc_bus)
1294 radeon_connector->dac_load_detect = true;
1295 drm_connector_attach_property(&radeon_connector->base,
1296 rdev->mode_info.load_detect_property,
1299 case DRM_MODE_CONNECTOR_DVIA:
1300 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1301 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1304 if (i2c_bus->valid) {
1305 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1306 if (!radeon_connector->ddc_bus)
1309 radeon_connector->dac_load_detect = true;
1310 drm_connector_attach_property(&radeon_connector->base,
1311 rdev->mode_info.load_detect_property,
1314 case DRM_MODE_CONNECTOR_DVII:
1315 case DRM_MODE_CONNECTOR_DVID:
1316 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1317 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1320 if (i2c_bus->valid) {
1321 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1322 if (!radeon_connector->ddc_bus)
1324 radeon_connector->dac_load_detect = true;
1325 drm_connector_attach_property(&radeon_connector->base,
1326 rdev->mode_info.load_detect_property,
1329 subpixel_order = SubPixelHorizontalRGB;
1331 case DRM_MODE_CONNECTOR_SVIDEO:
1332 case DRM_MODE_CONNECTOR_Composite:
1333 case DRM_MODE_CONNECTOR_9PinDIN:
1334 if (radeon_tv == 1) {
1335 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1336 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1339 radeon_connector->dac_load_detect = true;
1340 /* RS400,RC410,RS480 chipset seems to report a lot
1341 * of false positive on load detect, we haven't yet
1342 * found a way to make load detect reliable on those
1343 * chipset, thus just disable it for TV.
1345 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1346 radeon_connector->dac_load_detect = false;
1347 drm_connector_attach_property(&radeon_connector->base,
1348 rdev->mode_info.load_detect_property,
1349 radeon_connector->dac_load_detect);
1350 drm_connector_attach_property(&radeon_connector->base,
1351 rdev->mode_info.tv_std_property,
1352 radeon_combios_get_tv_info(rdev));
1355 case DRM_MODE_CONNECTOR_LVDS:
1356 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1357 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1360 if (i2c_bus->valid) {
1361 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1362 if (!radeon_connector->ddc_bus)
1365 drm_connector_attach_property(&radeon_connector->base,
1366 dev->mode_config.scaling_mode_property,
1367 DRM_MODE_SCALE_FULLSCREEN);
1368 subpixel_order = SubPixelHorizontalRGB;
1372 connector->display_info.subpixel_order = subpixel_order;
1373 drm_sysfs_connector_add(connector);
1377 if (radeon_connector->ddc_bus)
1378 radeon_i2c_destroy(radeon_connector->ddc_bus);
1379 drm_connector_cleanup(connector);