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 radeon_native_mode
*native_mode
= &radeon_encoder
->native_mode
;
183 if (native_mode
->panel_xres
!= 0 &&
184 native_mode
->panel_yres
!= 0 &&
185 native_mode
->dotclock
!= 0) {
186 mode
= drm_mode_create(dev
);
188 mode
->hdisplay
= native_mode
->panel_xres
;
189 mode
->vdisplay
= native_mode
->panel_yres
;
191 mode
->htotal
= mode
->hdisplay
+ native_mode
->hblank
;
192 mode
->hsync_start
= mode
->hdisplay
+ native_mode
->hoverplus
;
193 mode
->hsync_end
= mode
->hsync_start
+ native_mode
->hsync_width
;
194 mode
->vtotal
= mode
->vdisplay
+ native_mode
->vblank
;
195 mode
->vsync_start
= mode
->vdisplay
+ native_mode
->voverplus
;
196 mode
->vsync_end
= mode
->vsync_start
+ native_mode
->vsync_width
;
197 mode
->clock
= native_mode
->dotclock
;
200 mode
->type
= DRM_MODE_TYPE_PREFERRED
| DRM_MODE_TYPE_DRIVER
;
201 drm_mode_set_name(mode
);
203 DRM_DEBUG("Adding native panel mode %s\n", mode
->name
);
208 static void radeon_add_common_modes(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
210 struct drm_device
*dev
= encoder
->dev
;
211 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
212 struct drm_display_mode
*mode
= NULL
;
213 struct radeon_native_mode
*native_mode
= &radeon_encoder
->native_mode
;
218 } common_modes
[17] = {
238 for (i
= 0; i
< 17; i
++) {
239 if (radeon_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
240 if (common_modes
[i
].w
> native_mode
->panel_xres
||
241 common_modes
[i
].h
> native_mode
->panel_yres
||
242 (common_modes
[i
].w
== native_mode
->panel_xres
&&
243 common_modes
[i
].h
== native_mode
->panel_yres
))
246 if (common_modes
[i
].w
< 320 || common_modes
[i
].h
< 200)
249 mode
= drm_cvt_mode(dev
, common_modes
[i
].w
, common_modes
[i
].h
, 60, false, false, false);
250 drm_mode_probed_add(connector
, mode
);
254 int radeon_connector_set_property(struct drm_connector
*connector
, struct drm_property
*property
,
257 struct drm_device
*dev
= connector
->dev
;
258 struct radeon_device
*rdev
= dev
->dev_private
;
259 struct drm_encoder
*encoder
;
260 struct radeon_encoder
*radeon_encoder
;
262 if (property
== rdev
->mode_info
.coherent_mode_property
) {
263 struct radeon_encoder_atom_dig
*dig
;
265 /* need to find digital encoder on connector */
266 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_TMDS
);
270 radeon_encoder
= to_radeon_encoder(encoder
);
272 if (!radeon_encoder
->enc_priv
)
275 dig
= radeon_encoder
->enc_priv
;
276 dig
->coherent_mode
= val
? true : false;
277 radeon_property_change_mode(&radeon_encoder
->base
);
280 if (property
== rdev
->mode_info
.tv_std_property
) {
281 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_TVDAC
);
283 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_DAC
);
289 radeon_encoder
= to_radeon_encoder(encoder
);
290 if (!radeon_encoder
->enc_priv
)
292 if (rdev
->is_atom_bios
) {
293 struct radeon_encoder_atom_dac
*dac_int
;
294 dac_int
= radeon_encoder
->enc_priv
;
295 dac_int
->tv_std
= val
;
297 struct radeon_encoder_tv_dac
*dac_int
;
298 dac_int
= radeon_encoder
->enc_priv
;
299 dac_int
->tv_std
= val
;
301 radeon_property_change_mode(&radeon_encoder
->base
);
304 if (property
== rdev
->mode_info
.load_detect_property
) {
305 struct radeon_connector
*radeon_connector
=
306 to_radeon_connector(connector
);
309 radeon_connector
->dac_load_detect
= false;
311 radeon_connector
->dac_load_detect
= true;
314 if (property
== rdev
->mode_info
.tmds_pll_property
) {
315 struct radeon_encoder_int_tmds
*tmds
= NULL
;
317 /* need to find digital encoder on connector */
318 encoder
= radeon_find_encoder(connector
, DRM_MODE_ENCODER_TMDS
);
322 radeon_encoder
= to_radeon_encoder(encoder
);
324 tmds
= radeon_encoder
->enc_priv
;
329 if (rdev
->is_atom_bios
)
330 ret
= radeon_atombios_get_tmds_info(radeon_encoder
, tmds
);
332 ret
= radeon_legacy_get_tmds_info_from_combios(radeon_encoder
, tmds
);
334 if (val
== 1 || ret
== false) {
335 radeon_legacy_get_tmds_info_from_table(radeon_encoder
, tmds
);
337 radeon_property_change_mode(&radeon_encoder
->base
);
343 static void radeon_fixup_lvds_native_mode(struct drm_encoder
*encoder
,
344 struct drm_connector
*connector
)
346 struct radeon_encoder
*radeon_encoder
= to_radeon_encoder(encoder
);
347 struct radeon_native_mode
*native_mode
= &radeon_encoder
->native_mode
;
349 /* Try to get native mode details from EDID if necessary */
350 if (!native_mode
->dotclock
) {
351 struct drm_display_mode
*t
, *mode
;
353 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
) {
354 if (mode
->hdisplay
== native_mode
->panel_xres
&&
355 mode
->vdisplay
== native_mode
->panel_yres
) {
356 native_mode
->hblank
= mode
->htotal
- mode
->hdisplay
;
357 native_mode
->hoverplus
= mode
->hsync_start
- mode
->hdisplay
;
358 native_mode
->hsync_width
= mode
->hsync_end
- mode
->hsync_start
;
359 native_mode
->vblank
= mode
->vtotal
- mode
->vdisplay
;
360 native_mode
->voverplus
= mode
->vsync_start
- mode
->vdisplay
;
361 native_mode
->vsync_width
= mode
->vsync_end
- mode
->vsync_start
;
362 native_mode
->dotclock
= mode
->clock
;
363 DRM_INFO("Determined LVDS native mode details from EDID\n");
368 if (!native_mode
->dotclock
) {
369 DRM_INFO("No LVDS native mode details, disabling RMX\n");
370 radeon_encoder
->rmx_type
= RMX_OFF
;
374 static int radeon_lvds_get_modes(struct drm_connector
*connector
)
376 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
377 struct drm_encoder
*encoder
;
379 struct drm_display_mode
*mode
;
381 if (radeon_connector
->ddc_bus
) {
382 ret
= radeon_ddc_get_modes(radeon_connector
);
384 encoder
= radeon_best_single_encoder(connector
);
386 radeon_fixup_lvds_native_mode(encoder
, connector
);
387 /* add scaled modes */
388 radeon_add_common_modes(encoder
, connector
);
394 encoder
= radeon_best_single_encoder(connector
);
398 /* we have no EDID modes */
399 mode
= radeon_fp_native_mode(encoder
);
402 drm_mode_probed_add(connector
, mode
);
403 /* add scaled modes */
404 radeon_add_common_modes(encoder
, connector
);
410 static int radeon_lvds_mode_valid(struct drm_connector
*connector
,
411 struct drm_display_mode
*mode
)
416 static enum drm_connector_status
radeon_lvds_detect(struct drm_connector
*connector
)
418 enum drm_connector_status ret
= connector_status_connected
;
419 /* check acpi lid status ??? */
420 radeon_connector_update_scratch_regs(connector
, ret
);
424 static void radeon_connector_destroy(struct drm_connector
*connector
)
426 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
428 if (radeon_connector
->ddc_bus
)
429 radeon_i2c_destroy(radeon_connector
->ddc_bus
);
430 kfree(radeon_connector
->con_priv
);
431 drm_sysfs_connector_remove(connector
);
432 drm_connector_cleanup(connector
);
436 static int radeon_lvds_set_property(struct drm_connector
*connector
,
437 struct drm_property
*property
,
440 struct drm_device
*dev
= connector
->dev
;
441 struct radeon_encoder
*radeon_encoder
;
442 enum radeon_rmx_type rmx_type
;
445 if (property
!= dev
->mode_config
.scaling_mode_property
)
448 if (connector
->encoder
)
449 radeon_encoder
= to_radeon_encoder(connector
->encoder
);
451 struct drm_connector_helper_funcs
*connector_funcs
= connector
->helper_private
;
452 radeon_encoder
= to_radeon_encoder(connector_funcs
->best_encoder(connector
));
456 case DRM_MODE_SCALE_NONE
: rmx_type
= RMX_OFF
; break;
457 case DRM_MODE_SCALE_CENTER
: rmx_type
= RMX_CENTER
; break;
458 case DRM_MODE_SCALE_ASPECT
: rmx_type
= RMX_ASPECT
; break;
460 case DRM_MODE_SCALE_FULLSCREEN
: rmx_type
= RMX_FULL
; break;
462 if (radeon_encoder
->rmx_type
== rmx_type
)
465 radeon_encoder
->rmx_type
= rmx_type
;
467 radeon_property_change_mode(&radeon_encoder
->base
);
472 struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs
= {
473 .get_modes
= radeon_lvds_get_modes
,
474 .mode_valid
= radeon_lvds_mode_valid
,
475 .best_encoder
= radeon_best_single_encoder
,
478 struct drm_connector_funcs radeon_lvds_connector_funcs
= {
479 .dpms
= drm_helper_connector_dpms
,
480 .detect
= radeon_lvds_detect
,
481 .fill_modes
= drm_helper_probe_single_connector_modes
,
482 .destroy
= radeon_connector_destroy
,
483 .set_property
= radeon_lvds_set_property
,
486 static int radeon_vga_get_modes(struct drm_connector
*connector
)
488 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
491 ret
= radeon_ddc_get_modes(radeon_connector
);
496 static int radeon_vga_mode_valid(struct drm_connector
*connector
,
497 struct drm_display_mode
*mode
)
502 static enum drm_connector_status
radeon_vga_detect(struct drm_connector
*connector
)
504 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
505 struct drm_encoder
*encoder
;
506 struct drm_encoder_helper_funcs
*encoder_funcs
;
508 enum drm_connector_status ret
= connector_status_disconnected
;
510 encoder
= radeon_best_single_encoder(connector
);
512 ret
= connector_status_disconnected
;
514 radeon_i2c_do_lock(radeon_connector
, 1);
515 dret
= radeon_ddc_probe(radeon_connector
);
516 radeon_i2c_do_lock(radeon_connector
, 0);
518 ret
= connector_status_connected
;
520 if (radeon_connector
->dac_load_detect
) {
521 encoder_funcs
= encoder
->helper_private
;
522 ret
= encoder_funcs
->detect(encoder
, connector
);
526 if (ret
== connector_status_connected
)
527 ret
= radeon_connector_analog_encoder_conflict_solve(connector
, encoder
, ret
, true);
528 radeon_connector_update_scratch_regs(connector
, ret
);
532 struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs
= {
533 .get_modes
= radeon_vga_get_modes
,
534 .mode_valid
= radeon_vga_mode_valid
,
535 .best_encoder
= radeon_best_single_encoder
,
538 struct drm_connector_funcs radeon_vga_connector_funcs
= {
539 .dpms
= drm_helper_connector_dpms
,
540 .detect
= radeon_vga_detect
,
541 .fill_modes
= drm_helper_probe_single_connector_modes
,
542 .destroy
= radeon_connector_destroy
,
543 .set_property
= radeon_connector_set_property
,
546 static int radeon_tv_get_modes(struct drm_connector
*connector
)
548 struct drm_device
*dev
= connector
->dev
;
549 struct radeon_device
*rdev
= dev
->dev_private
;
550 struct drm_display_mode
*tv_mode
;
551 struct drm_encoder
*encoder
;
553 encoder
= radeon_best_single_encoder(connector
);
557 /* avivo chips can scale any mode */
558 if (rdev
->family
>= CHIP_RS600
)
559 /* add scaled modes */
560 radeon_add_common_modes(encoder
, connector
);
562 /* only 800x600 is supported right now on pre-avivo chips */
563 tv_mode
= drm_cvt_mode(dev
, 800, 600, 60, false, false, false);
564 tv_mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
565 drm_mode_probed_add(connector
, tv_mode
);
570 static int radeon_tv_mode_valid(struct drm_connector
*connector
,
571 struct drm_display_mode
*mode
)
576 static enum drm_connector_status
radeon_tv_detect(struct drm_connector
*connector
)
578 struct drm_encoder
*encoder
;
579 struct drm_encoder_helper_funcs
*encoder_funcs
;
580 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
581 enum drm_connector_status ret
= connector_status_disconnected
;
583 if (!radeon_connector
->dac_load_detect
)
586 encoder
= radeon_best_single_encoder(connector
);
588 ret
= connector_status_disconnected
;
590 encoder_funcs
= encoder
->helper_private
;
591 ret
= encoder_funcs
->detect(encoder
, connector
);
593 if (ret
== connector_status_connected
)
594 ret
= radeon_connector_analog_encoder_conflict_solve(connector
, encoder
, ret
, false);
595 radeon_connector_update_scratch_regs(connector
, ret
);
599 struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs
= {
600 .get_modes
= radeon_tv_get_modes
,
601 .mode_valid
= radeon_tv_mode_valid
,
602 .best_encoder
= radeon_best_single_encoder
,
605 struct drm_connector_funcs radeon_tv_connector_funcs
= {
606 .dpms
= drm_helper_connector_dpms
,
607 .detect
= radeon_tv_detect
,
608 .fill_modes
= drm_helper_probe_single_connector_modes
,
609 .destroy
= radeon_connector_destroy
,
610 .set_property
= radeon_connector_set_property
,
613 static int radeon_dvi_get_modes(struct drm_connector
*connector
)
615 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
618 ret
= radeon_ddc_get_modes(radeon_connector
);
624 * Do a DDC probe, if DDC probe passes, get the full EDID so
625 * we can do analog/digital monitor detection at this point.
626 * If the monitor is an analog monitor or we got no DDC,
627 * we need to find the DAC encoder object for this connector.
628 * If we got no DDC, we do load detection on the DAC encoder object.
629 * If we got analog DDC or load detection passes on the DAC encoder
630 * we have to check if this analog encoder is shared with anyone else (TV)
631 * if its shared we have to set the other connector to disconnected.
633 static enum drm_connector_status
radeon_dvi_detect(struct drm_connector
*connector
)
635 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
636 struct drm_encoder
*encoder
= NULL
;
637 struct drm_encoder_helper_funcs
*encoder_funcs
;
638 struct drm_mode_object
*obj
;
640 enum drm_connector_status ret
= connector_status_disconnected
;
643 radeon_i2c_do_lock(radeon_connector
, 1);
644 dret
= radeon_ddc_probe(radeon_connector
);
645 radeon_i2c_do_lock(radeon_connector
, 0);
647 radeon_i2c_do_lock(radeon_connector
, 1);
648 radeon_connector
->edid
= drm_get_edid(&radeon_connector
->base
, &radeon_connector
->ddc_bus
->adapter
);
649 radeon_i2c_do_lock(radeon_connector
, 0);
651 if (!radeon_connector
->edid
) {
652 DRM_ERROR("DDC responded but not EDID found for %s\n",
653 drm_get_connector_name(connector
));
655 radeon_connector
->use_digital
= !!(radeon_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
);
657 /* if this isn't a digital monitor
658 then we need to make sure we don't have any
660 ret
= connector_status_connected
;
664 if ((ret
== connector_status_connected
) && (radeon_connector
->use_digital
== true))
667 /* find analog encoder */
668 if (radeon_connector
->dac_load_detect
) {
669 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
670 if (connector
->encoder_ids
[i
] == 0)
673 obj
= drm_mode_object_find(connector
->dev
,
674 connector
->encoder_ids
[i
],
675 DRM_MODE_OBJECT_ENCODER
);
679 encoder
= obj_to_encoder(obj
);
681 encoder_funcs
= encoder
->helper_private
;
682 if (encoder_funcs
->detect
) {
683 if (ret
!= connector_status_connected
) {
684 ret
= encoder_funcs
->detect(encoder
, connector
);
685 if (ret
== connector_status_connected
) {
686 radeon_connector
->use_digital
= false;
694 if ((ret
== connector_status_connected
) && (radeon_connector
->use_digital
== false) &&
696 ret
= radeon_connector_analog_encoder_conflict_solve(connector
, encoder
, ret
, true);
700 /* updated in get modes as well since we need to know if it's analog or digital */
701 radeon_connector_update_scratch_regs(connector
, ret
);
705 /* okay need to be smart in here about which encoder to pick */
706 struct drm_encoder
*radeon_dvi_encoder(struct drm_connector
*connector
)
708 int enc_id
= connector
->encoder_ids
[0];
709 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
710 struct drm_mode_object
*obj
;
711 struct drm_encoder
*encoder
;
713 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
714 if (connector
->encoder_ids
[i
] == 0)
717 obj
= drm_mode_object_find(connector
->dev
, connector
->encoder_ids
[i
], DRM_MODE_OBJECT_ENCODER
);
721 encoder
= obj_to_encoder(obj
);
723 if (radeon_connector
->use_digital
== true) {
724 if (encoder
->encoder_type
== DRM_MODE_ENCODER_TMDS
)
727 if (encoder
->encoder_type
== DRM_MODE_ENCODER_DAC
||
728 encoder
->encoder_type
== DRM_MODE_ENCODER_TVDAC
)
733 /* see if we have a default encoder TODO */
735 /* then check use digitial */
736 /* pick the first one */
738 obj
= drm_mode_object_find(connector
->dev
, enc_id
, DRM_MODE_OBJECT_ENCODER
);
741 encoder
= obj_to_encoder(obj
);
747 static void radeon_dvi_force(struct drm_connector
*connector
)
749 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
750 if (connector
->force
== DRM_FORCE_ON
)
751 radeon_connector
->use_digital
= false;
752 if (connector
->force
== DRM_FORCE_ON_DIGITAL
)
753 radeon_connector
->use_digital
= true;
756 struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs
= {
757 .get_modes
= radeon_dvi_get_modes
,
758 .mode_valid
= radeon_vga_mode_valid
,
759 .best_encoder
= radeon_dvi_encoder
,
762 struct drm_connector_funcs radeon_dvi_connector_funcs
= {
763 .dpms
= drm_helper_connector_dpms
,
764 .detect
= radeon_dvi_detect
,
765 .fill_modes
= drm_helper_probe_single_connector_modes
,
766 .set_property
= radeon_connector_set_property
,
767 .destroy
= radeon_connector_destroy
,
768 .force
= radeon_dvi_force
,
772 radeon_add_atom_connector(struct drm_device
*dev
,
773 uint32_t connector_id
,
774 uint32_t supported_device
,
776 struct radeon_i2c_bus_rec
*i2c_bus
,
778 uint32_t igp_lane_info
)
780 struct radeon_device
*rdev
= dev
->dev_private
;
781 struct drm_connector
*connector
;
782 struct radeon_connector
*radeon_connector
;
783 struct radeon_connector_atom_dig
*radeon_dig_connector
;
784 uint32_t subpixel_order
= SubPixelNone
;
787 /* fixme - tv/cv/din */
788 if (connector_type
== DRM_MODE_CONNECTOR_Unknown
)
791 /* see if we already added it */
792 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
793 radeon_connector
= to_radeon_connector(connector
);
794 if (radeon_connector
->connector_id
== connector_id
) {
795 radeon_connector
->devices
|= supported_device
;
800 radeon_connector
= kzalloc(sizeof(struct radeon_connector
), GFP_KERNEL
);
801 if (!radeon_connector
)
804 connector
= &radeon_connector
->base
;
806 radeon_connector
->connector_id
= connector_id
;
807 radeon_connector
->devices
= supported_device
;
808 switch (connector_type
) {
809 case DRM_MODE_CONNECTOR_VGA
:
810 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
811 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
814 if (i2c_bus
->valid
) {
815 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "VGA");
816 if (!radeon_connector
->ddc_bus
)
819 radeon_connector
->dac_load_detect
= true;
820 drm_connector_attach_property(&radeon_connector
->base
,
821 rdev
->mode_info
.load_detect_property
,
824 case DRM_MODE_CONNECTOR_DVIA
:
825 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
826 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
829 if (i2c_bus
->valid
) {
830 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
831 if (!radeon_connector
->ddc_bus
)
834 radeon_connector
->dac_load_detect
= true;
835 drm_connector_attach_property(&radeon_connector
->base
,
836 rdev
->mode_info
.load_detect_property
,
839 case DRM_MODE_CONNECTOR_DVII
:
840 case DRM_MODE_CONNECTOR_DVID
:
841 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
842 if (!radeon_dig_connector
)
844 radeon_dig_connector
->linkb
= linkb
;
845 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
846 radeon_connector
->con_priv
= radeon_dig_connector
;
847 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
848 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
851 if (i2c_bus
->valid
) {
852 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
853 if (!radeon_connector
->ddc_bus
)
856 subpixel_order
= SubPixelHorizontalRGB
;
857 drm_connector_attach_property(&radeon_connector
->base
,
858 rdev
->mode_info
.coherent_mode_property
,
860 radeon_connector
->dac_load_detect
= true;
861 drm_connector_attach_property(&radeon_connector
->base
,
862 rdev
->mode_info
.load_detect_property
,
865 case DRM_MODE_CONNECTOR_HDMIA
:
866 case DRM_MODE_CONNECTOR_HDMIB
:
867 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
868 if (!radeon_dig_connector
)
870 radeon_dig_connector
->linkb
= linkb
;
871 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
872 radeon_connector
->con_priv
= radeon_dig_connector
;
873 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
874 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
877 if (i2c_bus
->valid
) {
878 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "HDMI");
879 if (!radeon_connector
->ddc_bus
)
882 drm_connector_attach_property(&radeon_connector
->base
,
883 rdev
->mode_info
.coherent_mode_property
,
885 subpixel_order
= SubPixelHorizontalRGB
;
887 case DRM_MODE_CONNECTOR_DisplayPort
:
888 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
889 if (!radeon_dig_connector
)
891 radeon_dig_connector
->linkb
= linkb
;
892 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
893 radeon_connector
->con_priv
= radeon_dig_connector
;
894 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
895 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
898 if (i2c_bus
->valid
) {
899 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DP");
900 if (!radeon_connector
->ddc_bus
)
903 subpixel_order
= SubPixelHorizontalRGB
;
905 case DRM_MODE_CONNECTOR_SVIDEO
:
906 case DRM_MODE_CONNECTOR_Composite
:
907 case DRM_MODE_CONNECTOR_9PinDIN
:
908 if (radeon_tv
== 1) {
909 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_tv_connector_funcs
, connector_type
);
910 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_tv_connector_helper_funcs
);
913 radeon_connector
->dac_load_detect
= true;
914 drm_connector_attach_property(&radeon_connector
->base
,
915 rdev
->mode_info
.load_detect_property
,
919 case DRM_MODE_CONNECTOR_LVDS
:
920 radeon_dig_connector
= kzalloc(sizeof(struct radeon_connector_atom_dig
), GFP_KERNEL
);
921 if (!radeon_dig_connector
)
923 radeon_dig_connector
->linkb
= linkb
;
924 radeon_dig_connector
->igp_lane_info
= igp_lane_info
;
925 radeon_connector
->con_priv
= radeon_dig_connector
;
926 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_lvds_connector_funcs
, connector_type
);
927 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_lvds_connector_helper_funcs
);
930 if (i2c_bus
->valid
) {
931 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "LVDS");
932 if (!radeon_connector
->ddc_bus
)
935 drm_mode_create_scaling_mode_property(dev
);
936 drm_connector_attach_property(&radeon_connector
->base
,
937 dev
->mode_config
.scaling_mode_property
,
938 DRM_MODE_SCALE_FULLSCREEN
);
939 subpixel_order
= SubPixelHorizontalRGB
;
943 connector
->display_info
.subpixel_order
= subpixel_order
;
944 drm_sysfs_connector_add(connector
);
948 if (radeon_connector
->ddc_bus
)
949 radeon_i2c_destroy(radeon_connector
->ddc_bus
);
950 drm_connector_cleanup(connector
);
955 radeon_add_legacy_connector(struct drm_device
*dev
,
956 uint32_t connector_id
,
957 uint32_t supported_device
,
959 struct radeon_i2c_bus_rec
*i2c_bus
)
961 struct radeon_device
*rdev
= dev
->dev_private
;
962 struct drm_connector
*connector
;
963 struct radeon_connector
*radeon_connector
;
964 uint32_t subpixel_order
= SubPixelNone
;
967 /* fixme - tv/cv/din */
968 if (connector_type
== DRM_MODE_CONNECTOR_Unknown
)
971 /* see if we already added it */
972 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
973 radeon_connector
= to_radeon_connector(connector
);
974 if (radeon_connector
->connector_id
== connector_id
) {
975 radeon_connector
->devices
|= supported_device
;
980 radeon_connector
= kzalloc(sizeof(struct radeon_connector
), GFP_KERNEL
);
981 if (!radeon_connector
)
984 connector
= &radeon_connector
->base
;
986 radeon_connector
->connector_id
= connector_id
;
987 radeon_connector
->devices
= supported_device
;
988 switch (connector_type
) {
989 case DRM_MODE_CONNECTOR_VGA
:
990 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
991 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
994 if (i2c_bus
->valid
) {
995 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "VGA");
996 if (!radeon_connector
->ddc_bus
)
999 radeon_connector
->dac_load_detect
= true;
1000 drm_connector_attach_property(&radeon_connector
->base
,
1001 rdev
->mode_info
.load_detect_property
,
1004 case DRM_MODE_CONNECTOR_DVIA
:
1005 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_vga_connector_funcs
, connector_type
);
1006 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_vga_connector_helper_funcs
);
1009 if (i2c_bus
->valid
) {
1010 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
1011 if (!radeon_connector
->ddc_bus
)
1014 radeon_connector
->dac_load_detect
= true;
1015 drm_connector_attach_property(&radeon_connector
->base
,
1016 rdev
->mode_info
.load_detect_property
,
1019 case DRM_MODE_CONNECTOR_DVII
:
1020 case DRM_MODE_CONNECTOR_DVID
:
1021 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_dvi_connector_funcs
, connector_type
);
1022 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_dvi_connector_helper_funcs
);
1025 if (i2c_bus
->valid
) {
1026 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "DVI");
1027 if (!radeon_connector
->ddc_bus
)
1029 radeon_connector
->dac_load_detect
= true;
1030 drm_connector_attach_property(&radeon_connector
->base
,
1031 rdev
->mode_info
.load_detect_property
,
1034 subpixel_order
= SubPixelHorizontalRGB
;
1036 case DRM_MODE_CONNECTOR_SVIDEO
:
1037 case DRM_MODE_CONNECTOR_Composite
:
1038 case DRM_MODE_CONNECTOR_9PinDIN
:
1039 if (radeon_tv
== 1) {
1040 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_tv_connector_funcs
, connector_type
);
1041 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_tv_connector_helper_funcs
);
1044 radeon_connector
->dac_load_detect
= true;
1045 drm_connector_attach_property(&radeon_connector
->base
,
1046 rdev
->mode_info
.load_detect_property
,
1050 case DRM_MODE_CONNECTOR_LVDS
:
1051 drm_connector_init(dev
, &radeon_connector
->base
, &radeon_lvds_connector_funcs
, connector_type
);
1052 ret
= drm_connector_helper_add(&radeon_connector
->base
, &radeon_lvds_connector_helper_funcs
);
1055 if (i2c_bus
->valid
) {
1056 radeon_connector
->ddc_bus
= radeon_i2c_create(dev
, i2c_bus
, "LVDS");
1057 if (!radeon_connector
->ddc_bus
)
1060 drm_connector_attach_property(&radeon_connector
->base
,
1061 dev
->mode_config
.scaling_mode_property
,
1062 DRM_MODE_SCALE_FULLSCREEN
);
1063 subpixel_order
= SubPixelHorizontalRGB
;
1067 connector
->display_info
.subpixel_order
= subpixel_order
;
1068 drm_sysfs_connector_add(connector
);
1072 if (radeon_connector
->ddc_bus
)
1073 radeon_i2c_destroy(radeon_connector
->ddc_bus
);
1074 drm_connector_cleanup(connector
);