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_LCD_SUPPORT
)) {
227 if (common_modes
[i
].w
> native_mode
->hdisplay
||
228 common_modes
[i
].h
> native_mode
->vdisplay
||
229 (common_modes
[i
].w
== native_mode
->hdisplay
&&
230 common_modes
[i
].h
== native_mode
->vdisplay
))
233 if (common_modes
[i
].w
< 320 || common_modes
[i
].h
< 200)
236 mode
= drm_cvt_mode(dev
, common_modes
[i
].w
, common_modes
[i
].h
, 60, false, false, false);
237 drm_mode_probed_add(connector
, mode
);
241 int radeon_connector_set_property(struct drm_connector
*connector
, struct drm_property
*property
,
244 struct drm_device
*dev
= connector
->dev
;
245 struct radeon_device
*rdev
= dev
->dev_private
;
246 struct drm_encoder
*encoder
;
247 struct radeon_encoder
*radeon_encoder
;
249 if (property
== rdev
->mode_info
.coherent_mode_property
) {
250 struct radeon_encoder_atom_dig
*dig
;
252 /* need to find digital encoder on connector */
253 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_TMDS
);
257 radeon_encoder
= to_radeon_encoder(encoder
);
259 if (!radeon_encoder
->enc_priv
)
262 dig
= radeon_encoder
->enc_priv
;
263 dig
->coherent_mode
= val
? true : false;
264 radeon_property_change_mode(&radeon_encoder
->base
);
267 if (property
== rdev
->mode_info
.tv_std_property
) {
268 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_TVDAC
);
270 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_DAC
);
276 radeon_encoder
= to_radeon_encoder(encoder
);
277 if (!radeon_encoder
->enc_priv
)
279 if (rdev
->is_atom_bios
) {
280 struct radeon_encoder_atom_dac
*dac_int
;
281 dac_int
= radeon_encoder
->enc_priv
;
282 dac_int
->tv_std
= val
;
284 struct radeon_encoder_tv_dac
*dac_int
;
285 dac_int
= radeon_encoder
->enc_priv
;
286 dac_int
->tv_std
= val
;
288 radeon_property_change_mode(&radeon_encoder
->base
);
291 if (property
== rdev
->mode_info
.load_detect_property
) {
292 struct radeon_connector
*radeon_connector
=
293 to_radeon_connector(connector
);
296 radeon_connector
->dac_load_detect
= false;
298 radeon_connector
->dac_load_detect
= true;
301 if (property
== rdev
->mode_info
.tmds_pll_property
) {
302 struct radeon_encoder_int_tmds
*tmds
= NULL
;
304 /* need to find digital encoder on connector */
305 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_TMDS
);
309 radeon_encoder
= to_radeon_encoder(encoder
);
311 tmds
= radeon_encoder
->enc_priv
;
316 if (rdev
->is_atom_bios
)
317 ret
= radeon_atombios_get_tmds_info(radeon_encoder
, tmds
);
319 ret
= radeon_legacy_get_tmds_info_from_combios(radeon_encoder
, tmds
);
321 if (val
== 1 || ret
== false) {
322 radeon_legacy_get_tmds_info_from_table(radeon_encoder
, tmds
);
324 radeon_property_change_mode(&radeon_encoder
->base
);
330 static void radeon_fixup_lvds_native_mode(struct drm_encoder
*encoder
,
331 struct drm_connector
*connector
)
333 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
334 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
336 /* Try to get native mode details from EDID if necessary */
337 if (!native_mode
->clock
) {
338 struct drm_display_mode
*t
, *mode
;
340 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
) {
341 if (mode
->hdisplay
== native_mode
->hdisplay
&&
342 mode
->vdisplay
== native_mode
->vdisplay
) {
343 *native_mode
= *mode
;
344 drm_mode_set_crtcinfo(native_mode
, CRTC_INTERLACE_HALVE_V
);
345 DRM_INFO("Determined LVDS native mode details from EDID\n");
350 if (!native_mode
->clock
) {
351 DRM_INFO("No LVDS native mode details, disabling RMX\n");
352 radeon_encoder
->rmx_type
= RMX_OFF
;
356 static int radeon_lvds_get_modes(struct drm_connector
*connector
)
358 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
359 struct drm_encoder
*encoder
;
361 struct drm_display_mode
*mode
;
363 if (radeon_connector
->ddc_bus
) {
364 ret
= radeon_ddc_get_modes(radeon_connector
);
366 encoder
= radeon_best_single_encoder(connector
);
368 radeon_fixup_lvds_native_mode(encoder
, connector
);
369 /* add scaled modes */
370 radeon_add_common_modes(encoder
, connector
);
376 encoder
= radeon_best_single_encoder(connector
);
380 /* we have no EDID modes */
381 mode
= radeon_fp_native_mode(encoder
);
384 drm_mode_probed_add(connector
, mode
);
385 /* add scaled modes */
386 radeon_add_common_modes(encoder
, connector
);
392 static int radeon_lvds_mode_valid(struct drm_connector
*connector
,
393 struct drm_display_mode
*mode
)
398 static enum drm_connector_status
radeon_lvds_detect(struct drm_connector
*connector
)
400 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
401 struct drm_encoder
*encoder
= radeon_best_single_encoder(connector
);
402 enum drm_connector_status ret
= connector_status_disconnected
;
406 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
407 struct drm_display_mode
*native_mode
= &radeon_encoder
->native_mode
;
409 /* check if panel is valid */
410 if (native_mode
->hdisplay
>= 320 && native_mode
->vdisplay
>= 240)
411 ret
= connector_status_connected
;
415 /* check for edid as well */
416 if (radeon_connector
->ddc_bus
) {
417 radeon_i2c_do_lock(radeon_connector
, 1);
418 dret
= radeon_ddc_probe(radeon_connector
);
419 radeon_i2c_do_lock(radeon_connector
, 0);
421 ret
= connector_status_connected
;
423 /* check acpi lid status ??? */
425 radeon_connector_update_scratch_regs(connector
, ret
);
429 static void radeon_connector_destroy(struct drm_connector
*connector
)
431 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
433 if (radeon_connector
->ddc_bus
)
434 radeon_i2c_destroy(radeon_connector
->ddc_bus
);
435 kfree(radeon_connector
->con_priv
);
436 drm_sysfs_connector_remove(connector
);
437 drm_connector_cleanup(connector
);
441 static int radeon_lvds_set_property(struct drm_connector
*connector
,
442 struct drm_property
*property
,
445 struct drm_device
*dev
= connector
->dev
;
446 struct radeon_encoder
*radeon_encoder
;
447 enum radeon_rmx_type rmx_type
;
450 if (property
!= dev
->mode_config
.scaling_mode_property
)
453 if (connector
->encoder
)
454 radeon_encoder
= to_radeon_encoder(connector
->encoder
);
456 struct drm_connector_helper_funcs
*connector_funcs
= connector
->helper_private
;
457 radeon_encoder
= to_radeon_encoder(connector_funcs
->best_encoder(connector
));
461 case DRM_MODE_SCALE_NONE
: rmx_type
= RMX_OFF
; break;
462 case DRM_MODE_SCALE_CENTER
: rmx_type
= RMX_CENTER
; break;
463 case DRM_MODE_SCALE_ASPECT
: rmx_type
= RMX_ASPECT
; break;
465 case DRM_MODE_SCALE_FULLSCREEN
: rmx_type
= RMX_FULL
; break;
467 if (radeon_encoder
->rmx_type
== rmx_type
)
470 radeon_encoder
->rmx_type
= rmx_type
;
472 radeon_property_change_mode(&radeon_encoder
->base
);
477 struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs
= {
478 .get_modes
= radeon_lvds_get_modes
,
479 .mode_valid
= radeon_lvds_mode_valid
,
480 .best_encoder
= radeon_best_single_encoder
,
483 struct drm_connector_funcs radeon_lvds_connector_funcs
= {
484 .dpms
= drm_helper_connector_dpms
,
485 .detect
= radeon_lvds_detect
,
486 .fill_modes
= drm_helper_probe_single_connector_modes
,
487 .destroy
= radeon_connector_destroy
,
488 .set_property
= radeon_lvds_set_property
,
491 static int radeon_vga_get_modes(struct drm_connector
*connector
)
493 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
496 ret
= radeon_ddc_get_modes(radeon_connector
);
501 static int radeon_vga_mode_valid(struct drm_connector
*connector
,
502 struct drm_display_mode
*mode
)
507 static enum drm_connector_status
radeon_vga_detect(struct drm_connector
*connector
)
509 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
510 struct drm_encoder
*encoder
;
511 struct drm_encoder_helper_funcs
*encoder_funcs
;
513 enum drm_connector_status ret
= connector_status_disconnected
;
515 encoder
= radeon_best_single_encoder(connector
);
517 ret
= connector_status_disconnected
;
519 radeon_i2c_do_lock(radeon_connector
, 1);
520 dret
= radeon_ddc_probe(radeon_connector
);
521 radeon_i2c_do_lock(radeon_connector
, 0);
523 ret
= connector_status_connected
;
525 if (radeon_connector
->dac_load_detect
) {
526 encoder_funcs
= encoder
->helper_private
;
527 ret
= encoder_funcs
->detect(encoder
, connector
);
531 if (ret
== connector_status_connected
)
532 ret
= radeon_connector_analog_encoder_conflict_solve(connector
, encoder
, ret
, true);
533 radeon_connector_update_scratch_regs(connector
, ret
);
537 struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs
= {
538 .get_modes
= radeon_vga_get_modes
,
539 .mode_valid
= radeon_vga_mode_valid
,
540 .best_encoder
= radeon_best_single_encoder
,
543 struct drm_connector_funcs radeon_vga_connector_funcs
= {
544 .dpms
= drm_helper_connector_dpms
,
545 .detect
= radeon_vga_detect
,
546 .fill_modes
= drm_helper_probe_single_connector_modes
,
547 .destroy
= radeon_connector_destroy
,
548 .set_property
= radeon_connector_set_property
,
551 static int radeon_tv_get_modes(struct drm_connector
*connector
)
553 struct drm_device
*dev
= connector
->dev
;
554 struct radeon_device
*rdev
= dev
->dev_private
;
555 struct drm_display_mode
*tv_mode
;
556 struct drm_encoder
*encoder
;
558 encoder
= radeon_best_single_encoder(connector
);
562 /* avivo chips can scale any mode */
563 if (rdev
->family
>= CHIP_RS600
)
564 /* add scaled modes */
565 radeon_add_common_modes(encoder
, connector
);
567 /* only 800x600 is supported right now on pre-avivo chips */
568 tv_mode
= drm_cvt_mode(dev
, 800, 600, 60, false, false, false);
569 tv_mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
570 drm_mode_probed_add(connector
, tv_mode
);
575 static int radeon_tv_mode_valid(struct drm_connector
*connector
,
576 struct drm_display_mode
*mode
)
581 static enum drm_connector_status
radeon_tv_detect(struct drm_connector
*connector
)
583 struct drm_encoder
*encoder
;
584 struct drm_encoder_helper_funcs
*encoder_funcs
;
585 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
586 enum drm_connector_status ret
= connector_status_disconnected
;
588 if (!radeon_connector
->dac_load_detect
)
591 encoder
= radeon_best_single_encoder(connector
);
593 ret
= connector_status_disconnected
;
595 encoder_funcs
= encoder
->helper_private
;
596 ret
= encoder_funcs
->detect(encoder
, connector
);
598 if (ret
== connector_status_connected
)
599 ret
= radeon_connector_analog_encoder_conflict_solve(connector
, encoder
, ret
, false);
600 radeon_connector_update_scratch_regs(connector
, ret
);
604 struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs
= {
605 .get_modes
= radeon_tv_get_modes
,
606 .mode_valid
= radeon_tv_mode_valid
,
607 .best_encoder
= radeon_best_single_encoder
,
610 struct drm_connector_funcs radeon_tv_connector_funcs
= {
611 .dpms
= drm_helper_connector_dpms
,
612 .detect
= radeon_tv_detect
,
613 .fill_modes
= drm_helper_probe_single_connector_modes
,
614 .destroy
= radeon_connector_destroy
,
615 .set_property
= radeon_connector_set_property
,
618 static int radeon_dvi_get_modes(struct drm_connector
*connector
)
620 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
623 ret
= radeon_ddc_get_modes(radeon_connector
);
629 * Do a DDC probe, if DDC probe passes, get the full EDID so
630 * we can do analog/digital monitor detection at this point.
631 * If the monitor is an analog monitor or we got no DDC,
632 * we need to find the DAC encoder object for this connector.
633 * If we got no DDC, we do load detection on the DAC encoder object.
634 * If we got analog DDC or load detection passes on the DAC encoder
635 * we have to check if this analog encoder is shared with anyone else (TV)
636 * if its shared we have to set the other connector to disconnected.
638 static enum drm_connector_status
radeon_dvi_detect(struct drm_connector
*connector
)
640 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
641 struct drm_encoder
*encoder
= NULL
;
642 struct drm_encoder_helper_funcs
*encoder_funcs
;
643 struct drm_mode_object
*obj
;
645 enum drm_connector_status ret
= connector_status_disconnected
;
648 radeon_i2c_do_lock(radeon_connector
, 1);
649 dret
= radeon_ddc_probe(radeon_connector
);
650 radeon_i2c_do_lock(radeon_connector
, 0);
652 radeon_i2c_do_lock(radeon_connector
, 1);
653 radeon_connector
->edid
= drm_get_edid(&radeon_connector
->base
, &radeon_connector
->ddc_bus
->adapter
);
654 radeon_i2c_do_lock(radeon_connector
, 0);
656 if (!radeon_connector
->edid
) {
657 DRM_ERROR("DDC responded but not EDID found for %s\n",
658 drm_get_connector_name(connector
));
660 radeon_connector
->use_digital
= !!(radeon_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
);
662 /* if this isn't a digital monitor
663 then we need to make sure we don't have any
665 ret
= connector_status_connected
;
669 if ((ret
== connector_status_connected
) && (radeon_connector
->use_digital
== true))
672 /* find analog encoder */
673 if (radeon_connector
->dac_load_detect
) {
674 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
675 if (connector
->encoder_ids
[i
] == 0)
678 obj
= drm_mode_object_find(connector
->dev
,
679 connector
->encoder_ids
[i
],
680 DRM_MODE_OBJECT_ENCODER
);
684 encoder
= obj_to_encoder(obj
);
686 encoder_funcs
= encoder
->helper_private
;
687 if (encoder_funcs
->detect
) {
688 if (ret
!= connector_status_connected
) {
689 ret
= encoder_funcs
->detect(encoder
, connector
);
690 if (ret
== connector_status_connected
) {
691 radeon_connector
->use_digital
= false;
699 if ((ret
== connector_status_connected
) && (radeon_connector
->use_digital
== false) &&
701 ret
= radeon_connector_analog_encoder_conflict_solve(connector
, encoder
, ret
, true);
705 /* updated in get modes as well since we need to know if it's analog or digital */
706 radeon_connector_update_scratch_regs(connector
, ret
);
710 /* okay need to be smart in here about which encoder to pick */
711 struct drm_encoder
*radeon_dvi_encoder(struct drm_connector
*connector
)
713 int enc_id
= connector
->encoder_ids
[0];
714 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
715 struct drm_mode_object
*obj
;
716 struct drm_encoder
*encoder
;
718 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
719 if (connector
->encoder_ids
[i
] == 0)
722 obj
= drm_mode_object_find(connector
->dev
, connector
->encoder_ids
[i
], DRM_MODE_OBJECT_ENCODER
);
726 encoder
= obj_to_encoder(obj
);
728 if (radeon_connector
->use_digital
== true) {
729 if (encoder
->encoder_type
== DRM_MODE_ENCODER_TMDS
)
732 if (encoder
->encoder_type
== DRM_MODE_ENCODER_DAC
||
733 encoder
->encoder_type
== DRM_MODE_ENCODER_TVDAC
)
738 /* see if we have a default encoder TODO */
740 /* then check use digitial */
741 /* pick the first one */
743 obj
= drm_mode_object_find(connector
->dev
, enc_id
, DRM_MODE_OBJECT_ENCODER
);
746 encoder
= obj_to_encoder(obj
);
752 static void radeon_dvi_force(struct drm_connector
*connector
)
754 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
755 if (connector
->force
== DRM_FORCE_ON
)
756 radeon_connector
->use_digital
= false;
757 if (connector
->force
== DRM_FORCE_ON_DIGITAL
)
758 radeon_connector
->use_digital
= true;
761 struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs
= {
762 .get_modes
= radeon_dvi_get_modes
,
763 .mode_valid
= radeon_vga_mode_valid
,
764 .best_encoder
= radeon_dvi_encoder
,
767 struct drm_connector_funcs radeon_dvi_connector_funcs
= {
768 .dpms
= drm_helper_connector_dpms
,
769 .detect
= radeon_dvi_detect
,
770 .fill_modes
= drm_helper_probe_single_connector_modes
,
771 .set_property
= radeon_connector_set_property
,
772 .destroy
= radeon_connector_destroy
,
773 .force
= radeon_dvi_force
,
777 radeon_add_atom_connector(struct drm_device
*dev
,
778 uint32_t connector_id
,
779 uint32_t supported_device
,
781 struct radeon_i2c_bus_rec
*i2c_bus
,
783 uint32_t igp_lane_info
)
785 struct radeon_device
*rdev
= dev
->dev_private
;
786 struct drm_connector
*connector
;
787 struct radeon_connector
*radeon_connector
;
788 struct radeon_connector_atom_dig
*radeon_dig_connector
;
789 uint32_t subpixel_order
= SubPixelNone
;
792 /* fixme - tv/cv/din */
793 if (connector_type
== DRM_MODE_CONNECTOR_Unknown
)
796 /* see if we already added it */
797 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
798 radeon_connector
= to_radeon_connector(connector
);
799 if (radeon_connector
->connector_id
== connector_id
) {
800 radeon_connector
->devices
|= supported_device
;
805 radeon_connector
= kzalloc(sizeof(struct radeon_connector
), GFP_KERNEL
);
806 if (!radeon_connector
)
809 connector
= &radeon_connector
->base
;
811 radeon_connector
->connector_id
= connector_id
;
812 radeon_connector
->devices
= supported_device
;
813 switch (connector_type
) {
814 case DRM_MODE_CONNECTOR_VGA
:
815 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
816 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
819 if (i2c_bus
->valid
) {
820 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "VGA");
821 if (!radeon_connector
->ddc_bus
)
824 radeon_connector
->dac_load_detect
= true;
825 drm_connector_attach_property(&radeon_connector
->base
,
826 rdev
->mode_info
.load_detect_property
,
829 case DRM_MODE_CONNECTOR_DVIA
:
830 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
831 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
834 if (i2c_bus
->valid
) {
835 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
836 if (!radeon_connector
->ddc_bus
)
839 radeon_connector
->dac_load_detect
= true;
840 drm_connector_attach_property(&radeon_connector
->base
,
841 rdev
->mode_info
.load_detect_property
,
844 case DRM_MODE_CONNECTOR_DVII
:
845 case DRM_MODE_CONNECTOR_DVID
:
846 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
847 if (!radeon_dig_connector
)
849 radeon_dig_connector
->linkb
= linkb
;
850 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
851 radeon_connector
->con_priv
= radeon_dig_connector
;
852 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
853 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
856 if (i2c_bus
->valid
) {
857 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
858 if (!radeon_connector
->ddc_bus
)
861 subpixel_order
= SubPixelHorizontalRGB
;
862 drm_connector_attach_property(&radeon_connector
->base
,
863 rdev
->mode_info
.coherent_mode_property
,
865 radeon_connector
->dac_load_detect
= true;
866 drm_connector_attach_property(&radeon_connector
->base
,
867 rdev
->mode_info
.load_detect_property
,
870 case DRM_MODE_CONNECTOR_HDMIA
:
871 case DRM_MODE_CONNECTOR_HDMIB
:
872 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
873 if (!radeon_dig_connector
)
875 radeon_dig_connector
->linkb
= linkb
;
876 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
877 radeon_connector
->con_priv
= radeon_dig_connector
;
878 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
879 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
882 if (i2c_bus
->valid
) {
883 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "HDMI");
884 if (!radeon_connector
->ddc_bus
)
887 drm_connector_attach_property(&radeon_connector
->base
,
888 rdev
->mode_info
.coherent_mode_property
,
890 subpixel_order
= SubPixelHorizontalRGB
;
892 case DRM_MODE_CONNECTOR_DisplayPort
:
893 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
894 if (!radeon_dig_connector
)
896 radeon_dig_connector
->linkb
= linkb
;
897 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
898 radeon_connector
->con_priv
= radeon_dig_connector
;
899 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
900 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
903 if (i2c_bus
->valid
) {
904 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DP");
905 if (!radeon_connector
->ddc_bus
)
908 subpixel_order
= SubPixelHorizontalRGB
;
910 case DRM_MODE_CONNECTOR_SVIDEO
:
911 case DRM_MODE_CONNECTOR_Composite
:
912 case DRM_MODE_CONNECTOR_9PinDIN
:
913 if (radeon_tv
== 1) {
914 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_tv_connector_funcs
, connector_type
);
915 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_tv_connector_helper_funcs
);
918 radeon_connector
->dac_load_detect
= true;
919 drm_connector_attach_property(&radeon_connector
->base
,
920 rdev
->mode_info
.load_detect_property
,
924 case DRM_MODE_CONNECTOR_LVDS
:
925 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
926 if (!radeon_dig_connector
)
928 radeon_dig_connector
->linkb
= linkb
;
929 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
930 radeon_connector
->con_priv
= radeon_dig_connector
;
931 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_lvds_connector_funcs
, connector_type
);
932 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_lvds_connector_helper_funcs
);
935 if (i2c_bus
->valid
) {
936 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "LVDS");
937 if (!radeon_connector
->ddc_bus
)
940 drm_mode_create_scaling_mode_property(dev
);
941 drm_connector_attach_property(&radeon_connector
->base
,
942 dev
->mode_config
.scaling_mode_property
,
943 DRM_MODE_SCALE_FULLSCREEN
);
944 subpixel_order
= SubPixelHorizontalRGB
;
948 connector
->display_info
.subpixel_order
= subpixel_order
;
949 drm_sysfs_connector_add(connector
);
953 if (radeon_connector
->ddc_bus
)
954 radeon_i2c_destroy(radeon_connector
->ddc_bus
);
955 drm_connector_cleanup(connector
);
960 radeon_add_legacy_connector(struct drm_device
*dev
,
961 uint32_t connector_id
,
962 uint32_t supported_device
,
964 struct radeon_i2c_bus_rec
*i2c_bus
)
966 struct radeon_device
*rdev
= dev
->dev_private
;
967 struct drm_connector
*connector
;
968 struct radeon_connector
*radeon_connector
;
969 uint32_t subpixel_order
= SubPixelNone
;
972 /* fixme - tv/cv/din */
973 if (connector_type
== DRM_MODE_CONNECTOR_Unknown
)
976 /* see if we already added it */
977 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
978 radeon_connector
= to_radeon_connector(connector
);
979 if (radeon_connector
->connector_id
== connector_id
) {
980 radeon_connector
->devices
|= supported_device
;
985 radeon_connector
= kzalloc(sizeof(struct radeon_connector
), GFP_KERNEL
);
986 if (!radeon_connector
)
989 connector
= &radeon_connector
->base
;
991 radeon_connector
->connector_id
= connector_id
;
992 radeon_connector
->devices
= supported_device
;
993 switch (connector_type
) {
994 case DRM_MODE_CONNECTOR_VGA
:
995 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
996 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
999 if (i2c_bus
->valid
) {
1000 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "VGA");
1001 if (!radeon_connector
->ddc_bus
)
1004 radeon_connector
->dac_load_detect
= true;
1005 drm_connector_attach_property(&radeon_connector
->base
,
1006 rdev
->mode_info
.load_detect_property
,
1009 case DRM_MODE_CONNECTOR_DVIA
:
1010 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
1011 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
1014 if (i2c_bus
->valid
) {
1015 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
1016 if (!radeon_connector
->ddc_bus
)
1019 radeon_connector
->dac_load_detect
= true;
1020 drm_connector_attach_property(&radeon_connector
->base
,
1021 rdev
->mode_info
.load_detect_property
,
1024 case DRM_MODE_CONNECTOR_DVII
:
1025 case DRM_MODE_CONNECTOR_DVID
:
1026 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
1027 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
1030 if (i2c_bus
->valid
) {
1031 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
1032 if (!radeon_connector
->ddc_bus
)
1034 radeon_connector
->dac_load_detect
= true;
1035 drm_connector_attach_property(&radeon_connector
->base
,
1036 rdev
->mode_info
.load_detect_property
,
1039 subpixel_order
= SubPixelHorizontalRGB
;
1041 case DRM_MODE_CONNECTOR_SVIDEO
:
1042 case DRM_MODE_CONNECTOR_Composite
:
1043 case DRM_MODE_CONNECTOR_9PinDIN
:
1044 if (radeon_tv
== 1) {
1045 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_tv_connector_funcs
, connector_type
);
1046 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_tv_connector_helper_funcs
);
1049 radeon_connector
->dac_load_detect
= true;
1050 drm_connector_attach_property(&radeon_connector
->base
,
1051 rdev
->mode_info
.load_detect_property
,
1055 case DRM_MODE_CONNECTOR_LVDS
:
1056 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_lvds_connector_funcs
, connector_type
);
1057 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_lvds_connector_helper_funcs
);
1060 if (i2c_bus
->valid
) {
1061 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "LVDS");
1062 if (!radeon_connector
->ddc_bus
)
1065 drm_connector_attach_property(&radeon_connector
->base
,
1066 dev
->mode_config
.scaling_mode_property
,
1067 DRM_MODE_SCALE_FULLSCREEN
);
1068 subpixel_order
= SubPixelHorizontalRGB
;
1072 connector
->display_info
.subpixel_order
= subpixel_order
;
1073 drm_sysfs_connector_add(connector
);
1077 if (radeon_connector
->ddc_bus
)
1078 radeon_i2c_destroy(radeon_connector
->ddc_bus
);
1079 drm_connector_cleanup(connector
);