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
;
145 list_for_each_entry(conflict
, &dev
->mode_config
.connector_list
, head
) {
146 if (conflict
== connector
)
149 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
150 if (conflict
->encoder_ids
[i
] == 0)
153 /* if the IDs match */
154 if (conflict
->encoder_ids
[i
] == encoder
->base
.id
) {
155 if (conflict
->status
!= connector_status_connected
)
158 if (priority
== true) {
159 DRM_INFO("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict
));
160 DRM_INFO("in favor of %s\n", drm_get_connector_name(connector
));
161 conflict
->status
= connector_status_disconnected
;
162 radeon_connector_update_scratch_regs(conflict
, connector_status_disconnected
);
164 DRM_INFO("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector
));
165 DRM_INFO("in favor of %s\n", drm_get_connector_name(conflict
));
166 current_status
= connector_status_disconnected
;
172 return current_status
;
176 static struct drm_display_mode
*radeon_fp_native_mode(struct drm_encoder
*encoder
)
178 struct drm_device
*dev
= encoder
->dev
;
179 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
180 struct drm_display_mode
*mode
= NULL
;
181 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
183 if (native_mode
->hdisplay
!= 0 &&
184 native_mode
->vdisplay
!= 0 &&
185 native_mode
->clock
!= 0) {
186 mode
= drm_mode_duplicate(dev
, native_mode
);
187 mode
->type
= DRM_MODE_TYPE_PREFERRED
| DRM_MODE_TYPE_DRIVER
;
188 drm_mode_set_name(mode
);
190 DRM_DEBUG("Adding native panel mode %s\n", mode
->name
);
195 static void radeon_add_common_modes(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
197 struct drm_device
*dev
= encoder
->dev
;
198 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
199 struct drm_display_mode
*mode
= NULL
;
200 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
205 } common_modes
[17] = {
225 for (i
= 0; i
< 17; i
++) {
226 if (radeon_encoder
->devices
& (ATOM_DEVICE_TV_SUPPORT
)) {
227 if (common_modes
[i
].w
> 1024 ||
228 common_modes
[i
].h
> 768)
231 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
232 if (common_modes
[i
].w
> native_mode
->hdisplay
||
233 common_modes
[i
].h
> native_mode
->vdisplay
||
234 (common_modes
[i
].w
== native_mode
->hdisplay
&&
235 common_modes
[i
].h
== native_mode
->vdisplay
))
238 if (common_modes
[i
].w
< 320 || common_modes
[i
].h
< 200)
241 mode
= drm_cvt_mode(dev
, common_modes
[i
].w
, common_modes
[i
].h
, 60, false, false, false);
242 drm_mode_probed_add(connector
, mode
);
246 int radeon_connector_set_property(struct drm_connector
*connector
, struct drm_property
*property
,
249 struct drm_device
*dev
= connector
->dev
;
250 struct radeon_device
*rdev
= dev
->dev_private
;
251 struct drm_encoder
*encoder
;
252 struct radeon_encoder
*radeon_encoder
;
254 if (property
== rdev
->mode_info
.coherent_mode_property
) {
255 struct radeon_encoder_atom_dig
*dig
;
257 /* need to find digital encoder on connector */
258 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_TMDS
);
262 radeon_encoder
= to_radeon_encoder(encoder
);
264 if (!radeon_encoder
->enc_priv
)
267 dig
= radeon_encoder
->enc_priv
;
268 dig
->coherent_mode
= val
? true : false;
269 radeon_property_change_mode(&radeon_encoder
->base
);
272 if (property
== rdev
->mode_info
.tv_std_property
) {
273 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_TVDAC
);
275 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_DAC
);
281 radeon_encoder
= to_radeon_encoder(encoder
);
282 if (!radeon_encoder
->enc_priv
)
284 if (rdev
->is_atom_bios
) {
285 struct radeon_encoder_atom_dac
*dac_int
;
286 dac_int
= radeon_encoder
->enc_priv
;
287 dac_int
->tv_std
= val
;
289 struct radeon_encoder_tv_dac
*dac_int
;
290 dac_int
= radeon_encoder
->enc_priv
;
291 dac_int
->tv_std
= val
;
293 radeon_property_change_mode(&radeon_encoder
->base
);
296 if (property
== rdev
->mode_info
.load_detect_property
) {
297 struct radeon_connector
*radeon_connector
=
298 to_radeon_connector(connector
);
301 radeon_connector
->dac_load_detect
= false;
303 radeon_connector
->dac_load_detect
= true;
306 if (property
== rdev
->mode_info
.tmds_pll_property
) {
307 struct radeon_encoder_int_tmds
*tmds
= NULL
;
309 /* need to find digital encoder on connector */
310 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_TMDS
);
314 radeon_encoder
= to_radeon_encoder(encoder
);
316 tmds
= radeon_encoder
->enc_priv
;
321 if (rdev
->is_atom_bios
)
322 ret
= radeon_atombios_get_tmds_info(radeon_encoder
, tmds
);
324 ret
= radeon_legacy_get_tmds_info_from_combios(radeon_encoder
, tmds
);
326 if (val
== 1 || ret
== false) {
327 radeon_legacy_get_tmds_info_from_table(radeon_encoder
, tmds
);
329 radeon_property_change_mode(&radeon_encoder
->base
);
335 static void radeon_fixup_lvds_native_mode(struct drm_encoder
*encoder
,
336 struct drm_connector
*connector
)
338 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
339 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
341 /* Try to get native mode details from EDID if necessary */
342 if (!native_mode
->clock
) {
343 struct drm_display_mode
*t
, *mode
;
345 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
) {
346 if (mode
->hdisplay
== native_mode
->hdisplay
&&
347 mode
->vdisplay
== native_mode
->vdisplay
) {
348 *native_mode
= *mode
;
349 drm_mode_set_crtcinfo(native_mode
, CRTC_INTERLACE_HALVE_V
);
350 DRM_INFO("Determined LVDS native mode details from EDID\n");
355 if (!native_mode
->clock
) {
356 DRM_INFO("No LVDS native mode details, disabling RMX\n");
357 radeon_encoder
->rmx_type
= RMX_OFF
;
361 static int radeon_lvds_get_modes(struct drm_connector
*connector
)
363 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
364 struct drm_encoder
*encoder
;
366 struct drm_display_mode
*mode
;
368 if (radeon_connector
->ddc_bus
) {
369 ret
= radeon_ddc_get_modes(radeon_connector
);
371 encoder
= radeon_best_single_encoder(connector
);
373 radeon_fixup_lvds_native_mode(encoder
, connector
);
374 /* add scaled modes */
375 radeon_add_common_modes(encoder
, connector
);
381 encoder
= radeon_best_single_encoder(connector
);
385 /* we have no EDID modes */
386 mode
= radeon_fp_native_mode(encoder
);
389 drm_mode_probed_add(connector
, mode
);
390 /* add scaled modes */
391 radeon_add_common_modes(encoder
, connector
);
397 static int radeon_lvds_mode_valid(struct drm_connector
*connector
,
398 struct drm_display_mode
*mode
)
400 struct drm_encoder
*encoder
= radeon_best_single_encoder(connector
);
402 if ((mode
->hdisplay
< 320) || (mode
->vdisplay
< 240))
406 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
407 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
409 /* AVIVO hardware supports downscaling modes larger than the panel
410 * to the panel size, but I'm not sure this is desirable.
412 if ((mode
->hdisplay
> native_mode
->hdisplay
) ||
413 (mode
->vdisplay
> native_mode
->vdisplay
))
416 /* if scaling is disabled, block non-native modes */
417 if (radeon_encoder
->rmx_type
== RMX_OFF
) {
418 if ((mode
->hdisplay
!= native_mode
->hdisplay
) ||
419 (mode
->vdisplay
!= native_mode
->vdisplay
))
427 static enum drm_connector_status
radeon_lvds_detect(struct drm_connector
*connector
)
429 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
430 struct drm_encoder
*encoder
= radeon_best_single_encoder(connector
);
431 enum drm_connector_status ret
= connector_status_disconnected
;
434 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
435 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
437 /* check if panel is valid */
438 if (native_mode
->hdisplay
>= 320 && native_mode
->vdisplay
>= 240)
439 ret
= connector_status_connected
;
443 /* check for edid as well */
444 if (radeon_connector
->edid
)
445 ret
= connector_status_connected
;
447 if (radeon_connector
->ddc_bus
) {
448 radeon_i2c_do_lock(radeon_connector
, 1);
449 radeon_connector
->edid
= drm_get_edid(&radeon_connector
->base
,
450 &radeon_connector
->ddc_bus
->adapter
);
451 radeon_i2c_do_lock(radeon_connector
, 0);
452 if (radeon_connector
->edid
)
453 ret
= connector_status_connected
;
456 /* check acpi lid status ??? */
458 radeon_connector_update_scratch_regs(connector
, ret
);
462 static void radeon_connector_destroy(struct drm_connector
*connector
)
464 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
466 if (radeon_connector
->ddc_bus
)
467 radeon_i2c_destroy(radeon_connector
->ddc_bus
);
468 if (radeon_connector
->edid
)
469 kfree(radeon_connector
->edid
);
470 kfree(radeon_connector
->con_priv
);
471 drm_sysfs_connector_remove(connector
);
472 drm_connector_cleanup(connector
);
476 static int radeon_lvds_set_property(struct drm_connector
*connector
,
477 struct drm_property
*property
,
480 struct drm_device
*dev
= connector
->dev
;
481 struct radeon_encoder
*radeon_encoder
;
482 enum radeon_rmx_type rmx_type
;
485 if (property
!= dev
->mode_config
.scaling_mode_property
)
488 if (connector
->encoder
)
489 radeon_encoder
= to_radeon_encoder(connector
->encoder
);
491 struct drm_connector_helper_funcs
*connector_funcs
= connector
->helper_private
;
492 radeon_encoder
= to_radeon_encoder(connector_funcs
->best_encoder(connector
));
496 case DRM_MODE_SCALE_NONE
: rmx_type
= RMX_OFF
; break;
497 case DRM_MODE_SCALE_CENTER
: rmx_type
= RMX_CENTER
; break;
498 case DRM_MODE_SCALE_ASPECT
: rmx_type
= RMX_ASPECT
; break;
500 case DRM_MODE_SCALE_FULLSCREEN
: rmx_type
= RMX_FULL
; break;
502 if (radeon_encoder
->rmx_type
== rmx_type
)
505 radeon_encoder
->rmx_type
= rmx_type
;
507 radeon_property_change_mode(&radeon_encoder
->base
);
512 struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs
= {
513 .get_modes
= radeon_lvds_get_modes
,
514 .mode_valid
= radeon_lvds_mode_valid
,
515 .best_encoder
= radeon_best_single_encoder
,
518 struct drm_connector_funcs radeon_lvds_connector_funcs
= {
519 .dpms
= drm_helper_connector_dpms
,
520 .detect
= radeon_lvds_detect
,
521 .fill_modes
= drm_helper_probe_single_connector_modes
,
522 .destroy
= radeon_connector_destroy
,
523 .set_property
= radeon_lvds_set_property
,
526 static int radeon_vga_get_modes(struct drm_connector
*connector
)
528 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
531 ret
= radeon_ddc_get_modes(radeon_connector
);
536 static int radeon_vga_mode_valid(struct drm_connector
*connector
,
537 struct drm_display_mode
*mode
)
539 /* XXX check mode bandwidth */
540 /* XXX verify against max DAC output frequency */
544 static enum drm_connector_status
radeon_vga_detect(struct drm_connector
*connector
)
546 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
547 struct drm_encoder
*encoder
;
548 struct drm_encoder_helper_funcs
*encoder_funcs
;
550 enum drm_connector_status ret
= connector_status_disconnected
;
552 encoder
= radeon_best_single_encoder(connector
);
554 ret
= connector_status_disconnected
;
556 radeon_i2c_do_lock(radeon_connector
, 1);
557 dret
= radeon_ddc_probe(radeon_connector
);
558 radeon_i2c_do_lock(radeon_connector
, 0);
560 if (radeon_connector
->edid
) {
561 kfree(radeon_connector
->edid
);
562 radeon_connector
->edid
= NULL
;
564 radeon_i2c_do_lock(radeon_connector
, 1);
565 radeon_connector
->edid
= drm_get_edid(&radeon_connector
->base
, &radeon_connector
->ddc_bus
->adapter
);
566 radeon_i2c_do_lock(radeon_connector
, 0);
568 if (!radeon_connector
->edid
) {
569 DRM_ERROR("DDC responded but not EDID found for %s\n",
570 drm_get_connector_name(connector
));
572 radeon_connector
->use_digital
= !!(radeon_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
);
574 /* some oems have boards with separate digital and analog connectors
575 * with a shared ddc line (often vga + hdmi)
577 if (radeon_connector
->use_digital
&& radeon_connector
->shared_ddc
) {
578 kfree(radeon_connector
->edid
);
579 radeon_connector
->edid
= NULL
;
580 ret
= connector_status_disconnected
;
582 ret
= connector_status_connected
;
585 if (radeon_connector
->dac_load_detect
) {
586 encoder_funcs
= encoder
->helper_private
;
587 ret
= encoder_funcs
->detect(encoder
, connector
);
591 if (ret
== connector_status_connected
)
592 ret
= radeon_connector_analog_encoder_conflict_solve(connector
, encoder
, ret
, true);
593 radeon_connector_update_scratch_regs(connector
, ret
);
597 struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs
= {
598 .get_modes
= radeon_vga_get_modes
,
599 .mode_valid
= radeon_vga_mode_valid
,
600 .best_encoder
= radeon_best_single_encoder
,
603 struct drm_connector_funcs radeon_vga_connector_funcs
= {
604 .dpms
= drm_helper_connector_dpms
,
605 .detect
= radeon_vga_detect
,
606 .fill_modes
= drm_helper_probe_single_connector_modes
,
607 .destroy
= radeon_connector_destroy
,
608 .set_property
= radeon_connector_set_property
,
611 static int radeon_tv_get_modes(struct drm_connector
*connector
)
613 struct drm_device
*dev
= connector
->dev
;
614 struct radeon_device
*rdev
= dev
->dev_private
;
615 struct drm_display_mode
*tv_mode
;
616 struct drm_encoder
*encoder
;
618 encoder
= radeon_best_single_encoder(connector
);
622 /* avivo chips can scale any mode */
623 if (rdev
->family
>= CHIP_RS600
)
624 /* add scaled modes */
625 radeon_add_common_modes(encoder
, connector
);
627 /* only 800x600 is supported right now on pre-avivo chips */
628 tv_mode
= drm_cvt_mode(dev
, 800, 600, 60, false, false, false);
629 tv_mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
630 drm_mode_probed_add(connector
, tv_mode
);
635 static int radeon_tv_mode_valid(struct drm_connector
*connector
,
636 struct drm_display_mode
*mode
)
638 if ((mode
->hdisplay
> 1024) || (mode
->vdisplay
> 768))
639 return MODE_CLOCK_RANGE
;
643 static enum drm_connector_status
radeon_tv_detect(struct drm_connector
*connector
)
645 struct drm_encoder
*encoder
;
646 struct drm_encoder_helper_funcs
*encoder_funcs
;
647 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
648 enum drm_connector_status ret
= connector_status_disconnected
;
650 if (!radeon_connector
->dac_load_detect
)
653 encoder
= radeon_best_single_encoder(connector
);
655 ret
= connector_status_disconnected
;
657 encoder_funcs
= encoder
->helper_private
;
658 ret
= encoder_funcs
->detect(encoder
, connector
);
660 if (ret
== connector_status_connected
)
661 ret
= radeon_connector_analog_encoder_conflict_solve(connector
, encoder
, ret
, false);
662 radeon_connector_update_scratch_regs(connector
, ret
);
666 struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs
= {
667 .get_modes
= radeon_tv_get_modes
,
668 .mode_valid
= radeon_tv_mode_valid
,
669 .best_encoder
= radeon_best_single_encoder
,
672 struct drm_connector_funcs radeon_tv_connector_funcs
= {
673 .dpms
= drm_helper_connector_dpms
,
674 .detect
= radeon_tv_detect
,
675 .fill_modes
= drm_helper_probe_single_connector_modes
,
676 .destroy
= radeon_connector_destroy
,
677 .set_property
= radeon_connector_set_property
,
680 static int radeon_dvi_get_modes(struct drm_connector
*connector
)
682 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
685 ret
= radeon_ddc_get_modes(radeon_connector
);
691 * Do a DDC probe, if DDC probe passes, get the full EDID so
692 * we can do analog/digital monitor detection at this point.
693 * If the monitor is an analog monitor or we got no DDC,
694 * we need to find the DAC encoder object for this connector.
695 * If we got no DDC, we do load detection on the DAC encoder object.
696 * If we got analog DDC or load detection passes on the DAC encoder
697 * we have to check if this analog encoder is shared with anyone else (TV)
698 * if its shared we have to set the other connector to disconnected.
700 static enum drm_connector_status
radeon_dvi_detect(struct drm_connector
*connector
)
702 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
703 struct drm_encoder
*encoder
= NULL
;
704 struct drm_encoder_helper_funcs
*encoder_funcs
;
705 struct drm_mode_object
*obj
;
707 enum drm_connector_status ret
= connector_status_disconnected
;
710 radeon_i2c_do_lock(radeon_connector
, 1);
711 dret
= radeon_ddc_probe(radeon_connector
);
712 radeon_i2c_do_lock(radeon_connector
, 0);
714 if (radeon_connector
->edid
) {
715 kfree(radeon_connector
->edid
);
716 radeon_connector
->edid
= NULL
;
718 radeon_i2c_do_lock(radeon_connector
, 1);
719 radeon_connector
->edid
= drm_get_edid(&radeon_connector
->base
, &radeon_connector
->ddc_bus
->adapter
);
720 radeon_i2c_do_lock(radeon_connector
, 0);
722 if (!radeon_connector
->edid
) {
723 DRM_ERROR("DDC responded but not EDID found for %s\n",
724 drm_get_connector_name(connector
));
726 radeon_connector
->use_digital
= !!(radeon_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
);
728 /* some oems have boards with separate digital and analog connectors
729 * with a shared ddc line (often vga + hdmi)
731 if ((!radeon_connector
->use_digital
) && radeon_connector
->shared_ddc
) {
732 kfree(radeon_connector
->edid
);
733 radeon_connector
->edid
= NULL
;
734 ret
= connector_status_disconnected
;
736 ret
= connector_status_connected
;
740 if ((ret
== connector_status_connected
) && (radeon_connector
->use_digital
== true))
743 /* find analog encoder */
744 if (radeon_connector
->dac_load_detect
) {
745 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
746 if (connector
->encoder_ids
[i
] == 0)
749 obj
= drm_mode_object_find(connector
->dev
,
750 connector
->encoder_ids
[i
],
751 DRM_MODE_OBJECT_ENCODER
);
755 encoder
= obj_to_encoder(obj
);
757 encoder_funcs
= encoder
->helper_private
;
758 if (encoder_funcs
->detect
) {
759 if (ret
!= connector_status_connected
) {
760 ret
= encoder_funcs
->detect(encoder
, connector
);
761 if (ret
== connector_status_connected
) {
762 radeon_connector
->use_digital
= false;
770 if ((ret
== connector_status_connected
) && (radeon_connector
->use_digital
== false) &&
772 ret
= radeon_connector_analog_encoder_conflict_solve(connector
, encoder
, ret
, true);
776 /* updated in get modes as well since we need to know if it's analog or digital */
777 radeon_connector_update_scratch_regs(connector
, ret
);
781 /* okay need to be smart in here about which encoder to pick */
782 struct drm_encoder
*radeon_dvi_encoder(struct drm_connector
*connector
)
784 int enc_id
= connector
->encoder_ids
[0];
785 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
786 struct drm_mode_object
*obj
;
787 struct drm_encoder
*encoder
;
789 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
790 if (connector
->encoder_ids
[i
] == 0)
793 obj
= drm_mode_object_find(connector
->dev
, connector
->encoder_ids
[i
], DRM_MODE_OBJECT_ENCODER
);
797 encoder
= obj_to_encoder(obj
);
799 if (radeon_connector
->use_digital
== true) {
800 if (encoder
->encoder_type
== DRM_MODE_ENCODER_TMDS
)
803 if (encoder
->encoder_type
== DRM_MODE_ENCODER_DAC
||
804 encoder
->encoder_type
== DRM_MODE_ENCODER_TVDAC
)
809 /* see if we have a default encoder TODO */
811 /* then check use digitial */
812 /* pick the first one */
814 obj
= drm_mode_object_find(connector
->dev
, enc_id
, DRM_MODE_OBJECT_ENCODER
);
817 encoder
= obj_to_encoder(obj
);
823 static void radeon_dvi_force(struct drm_connector
*connector
)
825 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
826 if (connector
->force
== DRM_FORCE_ON
)
827 radeon_connector
->use_digital
= false;
828 if (connector
->force
== DRM_FORCE_ON_DIGITAL
)
829 radeon_connector
->use_digital
= true;
832 static int radeon_dvi_mode_valid(struct drm_connector
*connector
,
833 struct drm_display_mode
*mode
)
835 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
837 /* XXX check mode bandwidth */
839 if (radeon_connector
->use_digital
&& (mode
->clock
> 165000)) {
840 if ((radeon_connector
->connector_object_id
== CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I
) ||
841 (radeon_connector
->connector_object_id
== CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D
) ||
842 (radeon_connector
->connector_object_id
== CONNECTOR_OBJECT_ID_HDMI_TYPE_B
))
845 return MODE_CLOCK_HIGH
;
850 struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs
= {
851 .get_modes
= radeon_dvi_get_modes
,
852 .mode_valid
= radeon_dvi_mode_valid
,
853 .best_encoder
= radeon_dvi_encoder
,
856 struct drm_connector_funcs radeon_dvi_connector_funcs
= {
857 .dpms
= drm_helper_connector_dpms
,
858 .detect
= radeon_dvi_detect
,
859 .fill_modes
= drm_helper_probe_single_connector_modes
,
860 .set_property
= radeon_connector_set_property
,
861 .destroy
= radeon_connector_destroy
,
862 .force
= radeon_dvi_force
,
866 radeon_add_atom_connector(struct drm_device
*dev
,
867 uint32_t connector_id
,
868 uint32_t supported_device
,
870 struct radeon_i2c_bus_rec
*i2c_bus
,
872 uint32_t igp_lane_info
,
873 uint16_t connector_object_id
)
875 struct radeon_device
*rdev
= dev
->dev_private
;
876 struct drm_connector
*connector
;
877 struct radeon_connector
*radeon_connector
;
878 struct radeon_connector_atom_dig
*radeon_dig_connector
;
879 uint32_t subpixel_order
= SubPixelNone
;
880 bool shared_ddc
= false;
883 /* fixme - tv/cv/din */
884 if (connector_type
== DRM_MODE_CONNECTOR_Unknown
)
887 /* see if we already added it */
888 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
889 radeon_connector
= to_radeon_connector(connector
);
890 if (radeon_connector
->connector_id
== connector_id
) {
891 radeon_connector
->devices
|= supported_device
;
894 if (radeon_connector
->ddc_bus
&& i2c_bus
->valid
) {
895 if (memcmp(&radeon_connector
->ddc_bus
->rec
, i2c_bus
,
896 sizeof(struct radeon_i2c_bus_rec
)) == 0) {
897 radeon_connector
->shared_ddc
= true;
903 radeon_connector
= kzalloc(sizeof(struct radeon_connector
), GFP_KERNEL
);
904 if (!radeon_connector
)
907 connector
= &radeon_connector
->base
;
909 radeon_connector
->connector_id
= connector_id
;
910 radeon_connector
->devices
= supported_device
;
911 radeon_connector
->shared_ddc
= shared_ddc
;
912 radeon_connector
->connector_object_id
= connector_object_id
;
913 switch (connector_type
) {
914 case DRM_MODE_CONNECTOR_VGA
:
915 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
916 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
919 if (i2c_bus
->valid
) {
920 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "VGA");
921 if (!radeon_connector
->ddc_bus
)
924 radeon_connector
->dac_load_detect
= true;
925 drm_connector_attach_property(&radeon_connector
->base
,
926 rdev
->mode_info
.load_detect_property
,
929 case DRM_MODE_CONNECTOR_DVIA
:
930 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
931 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
934 if (i2c_bus
->valid
) {
935 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
936 if (!radeon_connector
->ddc_bus
)
939 radeon_connector
->dac_load_detect
= true;
940 drm_connector_attach_property(&radeon_connector
->base
,
941 rdev
->mode_info
.load_detect_property
,
944 case DRM_MODE_CONNECTOR_DVII
:
945 case DRM_MODE_CONNECTOR_DVID
:
946 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
947 if (!radeon_dig_connector
)
949 radeon_dig_connector
->linkb
= linkb
;
950 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
951 radeon_connector
->con_priv
= radeon_dig_connector
;
952 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
953 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
956 if (i2c_bus
->valid
) {
957 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
958 if (!radeon_connector
->ddc_bus
)
961 subpixel_order
= SubPixelHorizontalRGB
;
962 drm_connector_attach_property(&radeon_connector
->base
,
963 rdev
->mode_info
.coherent_mode_property
,
965 radeon_connector
->dac_load_detect
= true;
966 drm_connector_attach_property(&radeon_connector
->base
,
967 rdev
->mode_info
.load_detect_property
,
970 case DRM_MODE_CONNECTOR_HDMIA
:
971 case DRM_MODE_CONNECTOR_HDMIB
:
972 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
973 if (!radeon_dig_connector
)
975 radeon_dig_connector
->linkb
= linkb
;
976 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
977 radeon_connector
->con_priv
= radeon_dig_connector
;
978 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
979 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
982 if (i2c_bus
->valid
) {
983 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "HDMI");
984 if (!radeon_connector
->ddc_bus
)
987 drm_connector_attach_property(&radeon_connector
->base
,
988 rdev
->mode_info
.coherent_mode_property
,
990 subpixel_order
= SubPixelHorizontalRGB
;
992 case DRM_MODE_CONNECTOR_DisplayPort
:
993 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
994 if (!radeon_dig_connector
)
996 radeon_dig_connector
->linkb
= linkb
;
997 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
998 radeon_connector
->con_priv
= radeon_dig_connector
;
999 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
1000 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
1003 if (i2c_bus
->valid
) {
1004 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DP");
1005 if (!radeon_connector
->ddc_bus
)
1008 subpixel_order
= SubPixelHorizontalRGB
;
1010 case DRM_MODE_CONNECTOR_SVIDEO
:
1011 case DRM_MODE_CONNECTOR_Composite
:
1012 case DRM_MODE_CONNECTOR_9PinDIN
:
1013 if (radeon_tv
== 1) {
1014 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_tv_connector_funcs
, connector_type
);
1015 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_tv_connector_helper_funcs
);
1018 radeon_connector
->dac_load_detect
= true;
1019 drm_connector_attach_property(&radeon_connector
->base
,
1020 rdev
->mode_info
.load_detect_property
,
1024 case DRM_MODE_CONNECTOR_LVDS
:
1025 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
1026 if (!radeon_dig_connector
)
1028 radeon_dig_connector
->linkb
= linkb
;
1029 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
1030 radeon_connector
->con_priv
= radeon_dig_connector
;
1031 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_lvds_connector_funcs
, connector_type
);
1032 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_lvds_connector_helper_funcs
);
1035 if (i2c_bus
->valid
) {
1036 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "LVDS");
1037 if (!radeon_connector
->ddc_bus
)
1040 drm_mode_create_scaling_mode_property(dev
);
1041 drm_connector_attach_property(&radeon_connector
->base
,
1042 dev
->mode_config
.scaling_mode_property
,
1043 DRM_MODE_SCALE_FULLSCREEN
);
1044 subpixel_order
= SubPixelHorizontalRGB
;
1048 connector
->display_info
.subpixel_order
= subpixel_order
;
1049 drm_sysfs_connector_add(connector
);
1053 if (radeon_connector
->ddc_bus
)
1054 radeon_i2c_destroy(radeon_connector
->ddc_bus
);
1055 drm_connector_cleanup(connector
);
1060 radeon_add_legacy_connector(struct drm_device
*dev
,
1061 uint32_t connector_id
,
1062 uint32_t supported_device
,
1064 struct radeon_i2c_bus_rec
*i2c_bus
,
1065 uint16_t connector_object_id
)
1067 struct radeon_device
*rdev
= dev
->dev_private
;
1068 struct drm_connector
*connector
;
1069 struct radeon_connector
*radeon_connector
;
1070 uint32_t subpixel_order
= SubPixelNone
;
1073 /* fixme - tv/cv/din */
1074 if (connector_type
== DRM_MODE_CONNECTOR_Unknown
)
1077 /* see if we already added it */
1078 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1079 radeon_connector
= to_radeon_connector(connector
);
1080 if (radeon_connector
->connector_id
== connector_id
) {
1081 radeon_connector
->devices
|= supported_device
;
1086 radeon_connector
= kzalloc(sizeof(struct radeon_connector
), GFP_KERNEL
);
1087 if (!radeon_connector
)
1090 connector
= &radeon_connector
->base
;
1092 radeon_connector
->connector_id
= connector_id
;
1093 radeon_connector
->devices
= supported_device
;
1094 radeon_connector
->connector_object_id
= connector_object_id
;
1095 switch (connector_type
) {
1096 case DRM_MODE_CONNECTOR_VGA
:
1097 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
1098 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
1101 if (i2c_bus
->valid
) {
1102 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "VGA");
1103 if (!radeon_connector
->ddc_bus
)
1106 radeon_connector
->dac_load_detect
= true;
1107 drm_connector_attach_property(&radeon_connector
->base
,
1108 rdev
->mode_info
.load_detect_property
,
1111 case DRM_MODE_CONNECTOR_DVIA
:
1112 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
1113 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
1116 if (i2c_bus
->valid
) {
1117 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
1118 if (!radeon_connector
->ddc_bus
)
1121 radeon_connector
->dac_load_detect
= true;
1122 drm_connector_attach_property(&radeon_connector
->base
,
1123 rdev
->mode_info
.load_detect_property
,
1126 case DRM_MODE_CONNECTOR_DVII
:
1127 case DRM_MODE_CONNECTOR_DVID
:
1128 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
1129 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
1132 if (i2c_bus
->valid
) {
1133 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
1134 if (!radeon_connector
->ddc_bus
)
1136 radeon_connector
->dac_load_detect
= true;
1137 drm_connector_attach_property(&radeon_connector
->base
,
1138 rdev
->mode_info
.load_detect_property
,
1141 subpixel_order
= SubPixelHorizontalRGB
;
1143 case DRM_MODE_CONNECTOR_SVIDEO
:
1144 case DRM_MODE_CONNECTOR_Composite
:
1145 case DRM_MODE_CONNECTOR_9PinDIN
:
1146 if (radeon_tv
== 1) {
1147 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_tv_connector_funcs
, connector_type
);
1148 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_tv_connector_helper_funcs
);
1151 radeon_connector
->dac_load_detect
= true;
1152 drm_connector_attach_property(&radeon_connector
->base
,
1153 rdev
->mode_info
.load_detect_property
,
1157 case DRM_MODE_CONNECTOR_LVDS
:
1158 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_lvds_connector_funcs
, connector_type
);
1159 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_lvds_connector_helper_funcs
);
1162 if (i2c_bus
->valid
) {
1163 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "LVDS");
1164 if (!radeon_connector
->ddc_bus
)
1167 drm_connector_attach_property(&radeon_connector
->base
,
1168 dev
->mode_config
.scaling_mode_property
,
1169 DRM_MODE_SCALE_FULLSCREEN
);
1170 subpixel_order
= SubPixelHorizontalRGB
;
1174 connector
->display_info
.subpixel_order
= subpixel_order
;
1175 drm_sysfs_connector_add(connector
);
1179 if (radeon_connector
->ddc_bus
)
1180 radeon_i2c_destroy(radeon_connector
->ddc_bus
);
1181 drm_connector_cleanup(connector
);