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 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
);
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
;
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)
70 obj
= drm_mode_object_find(connector
->dev
,
71 connector
->encoder_ids
[i
],
72 DRM_MODE_OBJECT_ENCODER
);
76 encoder
= obj_to_encoder(obj
);
78 if ((encoder
== best_encoder
) && (status
== connector_status_connected
))
83 if (rdev
->is_atom_bios
)
84 radeon_atombios_connected_scratch_regs(connector
, encoder
, connected
);
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
;
97 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
98 if (connector
->encoder_ids
[i
] == 0)
101 obj
= drm_mode_object_find(connector
->dev
, connector
->encoder_ids
[i
], DRM_MODE_OBJECT_ENCODER
);
105 encoder
= obj_to_encoder(obj
);
106 if (encoder
->encoder_type
== encoder_type
)
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 */
120 obj
= drm_mode_object_find(connector
->dev
, enc_id
, DRM_MODE_OBJECT_ENCODER
);
123 encoder
= obj_to_encoder(obj
);
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
,
141 struct drm_device
*dev
= connector
->dev
;
142 struct drm_connector
*conflict
;
143 struct radeon_connector
*radeon_conflict
;
146 list_for_each_entry(conflict
, &dev
->mode_config
.connector_list
, head
) {
147 if (conflict
== connector
)
150 radeon_conflict
= to_radeon_connector(conflict
);
151 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
152 if (conflict
->encoder_ids
[i
] == 0)
155 /* if the IDs match */
156 if (conflict
->encoder_ids
[i
] == encoder
->base
.id
) {
157 if (conflict
->status
!= connector_status_connected
)
160 if (radeon_conflict
->use_digital
)
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
);
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
;
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
);
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
;
210 } common_modes
[17] = {
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)
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
))
243 if (common_modes
[i
].w
< 320 || common_modes
[i
].h
< 200)
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
,
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
);
267 radeon_encoder
= to_radeon_encoder(encoder
);
269 if (!radeon_encoder
->enc_priv
)
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
);
280 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_DAC
);
286 radeon_encoder
= to_radeon_encoder(encoder
);
287 if (!radeon_encoder
->enc_priv
)
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
;
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
);
306 radeon_connector
->dac_load_detect
= false;
308 radeon_connector
->dac_load_detect
= true;
311 if (property
== rdev
->mode_info
.tmds_pll_property
) {
312 struct radeon_encoder_int_tmds
*tmds
= NULL
;
314 /* need to find digital encoder on connector */
315 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_TMDS
);
319 radeon_encoder
= to_radeon_encoder(encoder
);
321 tmds
= radeon_encoder
->enc_priv
;
326 if (rdev
->is_atom_bios
)
327 ret
= radeon_atombios_get_tmds_info(radeon_encoder
, tmds
);
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
);
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");
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
;
371 struct drm_display_mode
*mode
;
373 if (radeon_connector
->ddc_bus
) {
374 ret
= radeon_ddc_get_modes(radeon_connector
);
376 encoder
= radeon_best_single_encoder(connector
);
378 radeon_fixup_lvds_native_mode(encoder
, connector
);
379 /* add scaled modes */
380 radeon_add_common_modes(encoder
, connector
);
386 encoder
= radeon_best_single_encoder(connector
);
390 /* we have no EDID modes */
391 mode
= radeon_fp_native_mode(encoder
);
394 drm_mode_probed_add(connector
, mode
);
395 /* add scaled modes */
396 radeon_add_common_modes(encoder
, connector
);
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))
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
))
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
))
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
;
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
;
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
);
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
);
481 static int radeon_lvds_set_property(struct drm_connector
*connector
,
482 struct drm_property
*property
,
485 struct drm_device
*dev
= connector
->dev
;
486 struct radeon_encoder
*radeon_encoder
;
487 enum radeon_rmx_type rmx_type
;
490 if (property
!= dev
->mode_config
.scaling_mode_property
)
493 if (connector
->encoder
)
494 radeon_encoder
= to_radeon_encoder(connector
->encoder
);
496 struct drm_connector_helper_funcs
*connector_funcs
= connector
->helper_private
;
497 radeon_encoder
= to_radeon_encoder(connector_funcs
->best_encoder(connector
));
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;
505 case DRM_MODE_SCALE_FULLSCREEN
: rmx_type
= RMX_FULL
; break;
507 if (radeon_encoder
->rmx_type
== rmx_type
)
510 radeon_encoder
->rmx_type
= rmx_type
;
512 radeon_property_change_mode(&radeon_encoder
->base
);
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
);
536 ret
= radeon_ddc_get_modes(radeon_connector
);
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 */
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
;
555 enum drm_connector_status ret
= connector_status_disconnected
;
557 encoder
= radeon_best_single_encoder(connector
);
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);
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
;
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
;
588 ret
= connector_status_connected
;
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
);
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
);
628 /* avivo chips can scale any mode */
629 if (rdev
->family
>= CHIP_RS600
)
630 /* add scaled modes */
631 radeon_add_common_modes(encoder
, connector
);
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
);
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
;
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
)
659 encoder
= radeon_best_single_encoder(connector
);
661 ret
= connector_status_disconnected
;
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
);
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
);
691 ret
= radeon_ddc_get_modes(radeon_connector
);
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
;
713 enum drm_connector_status ret
= connector_status_disconnected
;
716 radeon_i2c_do_lock(radeon_connector
, 1);
717 dret
= radeon_ddc_probe(radeon_connector
);
718 radeon_i2c_do_lock(radeon_connector
, 0);
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
));
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
;
742 ret
= connector_status_connected
;
746 if ((ret
== connector_status_connected
) && (radeon_connector
->use_digital
== true))
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)
755 obj
= drm_mode_object_find(connector
->dev
,
756 connector
->encoder_ids
[i
],
757 DRM_MODE_OBJECT_ENCODER
);
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;
776 if ((ret
== connector_status_connected
) && (radeon_connector
->use_digital
== false) &&
778 ret
= radeon_connector_analog_encoder_conflict_solve(connector
, encoder
, ret
, true);
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
);
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
;
795 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
796 if (connector
->encoder_ids
[i
] == 0)
799 obj
= drm_mode_object_find(connector
->dev
, connector
->encoder_ids
[i
], DRM_MODE_OBJECT_ENCODER
);
803 encoder
= obj_to_encoder(obj
);
805 if (radeon_connector
->use_digital
== true) {
806 if (encoder
->encoder_type
== DRM_MODE_ENCODER_TMDS
)
809 if (encoder
->encoder_type
== DRM_MODE_ENCODER_DAC
||
810 encoder
->encoder_type
== DRM_MODE_ENCODER_TVDAC
)
815 /* see if we have a default encoder TODO */
817 /* then check use digitial */
818 /* pick the first one */
820 obj
= drm_mode_object_find(connector
->dev
, enc_id
, DRM_MODE_OBJECT_ENCODER
);
823 encoder
= obj_to_encoder(obj
);
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
))
851 return MODE_CLOCK_HIGH
;
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
,
872 radeon_add_atom_connector(struct drm_device
*dev
,
873 uint32_t connector_id
,
874 uint32_t supported_device
,
876 struct radeon_i2c_bus_rec
*i2c_bus
,
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;
889 /* fixme - tv/cv/din */
890 if (connector_type
== DRM_MODE_CONNECTOR_Unknown
)
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
;
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;
909 radeon_connector
= kzalloc(sizeof(struct radeon_connector
), GFP_KERNEL
);
910 if (!radeon_connector
)
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
);
925 if (i2c_bus
->valid
) {
926 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "VGA");
927 if (!radeon_connector
->ddc_bus
)
930 radeon_connector
->dac_load_detect
= true;
931 drm_connector_attach_property(&radeon_connector
->base
,
932 rdev
->mode_info
.load_detect_property
,
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
);
940 if (i2c_bus
->valid
) {
941 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
942 if (!radeon_connector
->ddc_bus
)
945 radeon_connector
->dac_load_detect
= true;
946 drm_connector_attach_property(&radeon_connector
->base
,
947 rdev
->mode_info
.load_detect_property
,
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
)
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
);
962 if (i2c_bus
->valid
) {
963 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
964 if (!radeon_connector
->ddc_bus
)
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
,
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
)
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
);
988 if (i2c_bus
->valid
) {
989 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "HDMI");
990 if (!radeon_connector
->ddc_bus
)
993 drm_connector_attach_property(&radeon_connector
->base
,
994 rdev
->mode_info
.coherent_mode_property
,
996 subpixel_order
= SubPixelHorizontalRGB
;
998 case DRM_MODE_CONNECTOR_DisplayPort
:
999 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
1000 if (!radeon_dig_connector
)
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
);
1009 if (i2c_bus
->valid
) {
1010 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DP");
1011 if (!radeon_connector
->ddc_bus
)
1014 subpixel_order
= SubPixelHorizontalRGB
;
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
);
1024 radeon_connector
->dac_load_detect
= true;
1025 drm_connector_attach_property(&radeon_connector
->base
,
1026 rdev
->mode_info
.load_detect_property
,
1030 case DRM_MODE_CONNECTOR_LVDS
:
1031 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
1032 if (!radeon_dig_connector
)
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
);
1041 if (i2c_bus
->valid
) {
1042 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "LVDS");
1043 if (!radeon_connector
->ddc_bus
)
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
;
1054 connector
->display_info
.subpixel_order
= subpixel_order
;
1055 drm_sysfs_connector_add(connector
);
1059 if (radeon_connector
->ddc_bus
)
1060 radeon_i2c_destroy(radeon_connector
->ddc_bus
);
1061 drm_connector_cleanup(connector
);
1066 radeon_add_legacy_connector(struct drm_device
*dev
,
1067 uint32_t connector_id
,
1068 uint32_t supported_device
,
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
;
1079 /* fixme - tv/cv/din */
1080 if (connector_type
== DRM_MODE_CONNECTOR_Unknown
)
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
;
1092 radeon_connector
= kzalloc(sizeof(struct radeon_connector
), GFP_KERNEL
);
1093 if (!radeon_connector
)
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
);
1107 if (i2c_bus
->valid
) {
1108 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "VGA");
1109 if (!radeon_connector
->ddc_bus
)
1112 radeon_connector
->dac_load_detect
= true;
1113 drm_connector_attach_property(&radeon_connector
->base
,
1114 rdev
->mode_info
.load_detect_property
,
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
);
1122 if (i2c_bus
->valid
) {
1123 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
1124 if (!radeon_connector
->ddc_bus
)
1127 radeon_connector
->dac_load_detect
= true;
1128 drm_connector_attach_property(&radeon_connector
->base
,
1129 rdev
->mode_info
.load_detect_property
,
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
);
1138 if (i2c_bus
->valid
) {
1139 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
1140 if (!radeon_connector
->ddc_bus
)
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
;
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
);
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
,
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
);
1175 if (i2c_bus
->valid
) {
1176 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "LVDS");
1177 if (!radeon_connector
->ddc_bus
)
1180 drm_connector_attach_property(&radeon_connector
->base
,
1181 dev
->mode_config
.scaling_mode_property
,
1182 DRM_MODE_SCALE_FULLSCREEN
);
1183 subpixel_order
= SubPixelHorizontalRGB
;
1187 connector
->display_info
.subpixel_order
= subpixel_order
;
1188 drm_sysfs_connector_add(connector
);
1192 if (radeon_connector
->ddc_bus
)
1193 radeon_i2c_destroy(radeon_connector
->ddc_bus
);
1194 drm_connector_cleanup(connector
);