mm-only debug patch...
[mmotm.git] / drivers / gpu / drm / radeon / radeon_connectors.c
blob729207a1e83e12c159d59f2879807d8a4f611b28
1 /*
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
24 * Alex Deucher
26 #include "drmP.h"
27 #include "drm_edid.h"
28 #include "drm_crtc_helper.h"
29 #include "drm_fb_helper.h"
30 #include "radeon_drm.h"
31 #include "radeon.h"
32 #include "atom.h"
34 extern void
35 radeon_combios_connected_scratch_regs(struct drm_connector *connector,
36 struct drm_encoder *encoder,
37 bool connected);
38 extern void
39 radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
40 struct drm_encoder *encoder,
41 bool connected);
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);
52 static void
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;
61 bool connected;
62 int i;
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)
68 break;
70 obj = drm_mode_object_find(connector->dev,
71 connector->encoder_ids[i],
72 DRM_MODE_OBJECT_ENCODER);
73 if (!obj)
74 continue;
76 encoder = obj_to_encoder(obj);
78 if ((encoder == best_encoder) && (status == connector_status_connected))
79 connected = true;
80 else
81 connected = false;
83 if (rdev->is_atom_bios)
84 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
85 else
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;
95 int i;
97 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
98 if (connector->encoder_ids[i] == 0)
99 break;
101 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
102 if (!obj)
103 continue;
105 encoder = obj_to_encoder(obj);
106 if (encoder->encoder_type == encoder_type)
107 return encoder;
109 return NULL;
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 */
119 if (enc_id) {
120 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
121 if (!obj)
122 return NULL;
123 encoder = obj_to_encoder(obj);
124 return encoder;
126 return NULL;
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,
139 bool priority)
141 struct drm_device *dev = connector->dev;
142 struct drm_connector *conflict;
143 int i;
145 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
146 if (conflict == connector)
147 continue;
149 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
150 if (conflict->encoder_ids[i] == 0)
151 break;
153 /* if the IDs match */
154 if (conflict->encoder_ids[i] == encoder->base.id) {
155 if (conflict->status != connector_status_connected)
156 continue;
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);
163 } else {
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;
168 break;
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);
192 return mode;
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;
201 int i;
202 struct mode_size {
203 int w;
204 int h;
205 } common_modes[17] = {
206 { 640, 480},
207 { 720, 480},
208 { 800, 600},
209 { 848, 480},
210 {1024, 768},
211 {1152, 768},
212 {1280, 720},
213 {1280, 800},
214 {1280, 854},
215 {1280, 960},
216 {1280, 1024},
217 {1440, 900},
218 {1400, 1050},
219 {1680, 1050},
220 {1600, 1200},
221 {1920, 1080},
222 {1920, 1200}
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))
231 continue;
233 if (common_modes[i].w < 320 || common_modes[i].h < 200)
234 continue;
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,
242 uint64_t val)
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);
254 if (!encoder)
255 return 0;
257 radeon_encoder = to_radeon_encoder(encoder);
259 if (!radeon_encoder->enc_priv)
260 return 0;
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);
269 if (!encoder) {
270 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
273 if (!encoder)
274 return 0;
276 radeon_encoder = to_radeon_encoder(encoder);
277 if (!radeon_encoder->enc_priv)
278 return 0;
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;
283 } else {
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);
295 if (val == 0)
296 radeon_connector->dac_load_detect = false;
297 else
298 radeon_connector->dac_load_detect = true;
301 if (property == rdev->mode_info.tmds_pll_property) {
302 struct radeon_encoder_int_tmds *tmds = NULL;
303 bool ret = false;
304 /* need to find digital encoder on connector */
305 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
306 if (!encoder)
307 return 0;
309 radeon_encoder = to_radeon_encoder(encoder);
311 tmds = radeon_encoder->enc_priv;
312 if (!tmds)
313 return 0;
315 if (val == 0) {
316 if (rdev->is_atom_bios)
317 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
318 else
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);
327 return 0;
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");
346 break;
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;
360 int ret = 0;
361 struct drm_display_mode *mode;
363 if (radeon_connector->ddc_bus) {
364 ret = radeon_ddc_get_modes(radeon_connector);
365 if (ret > 0) {
366 encoder = radeon_best_single_encoder(connector);
367 if (encoder) {
368 radeon_fixup_lvds_native_mode(encoder, connector);
369 /* add scaled modes */
370 radeon_add_common_modes(encoder, connector);
372 return ret;
376 encoder = radeon_best_single_encoder(connector);
377 if (!encoder)
378 return 0;
380 /* we have no EDID modes */
381 mode = radeon_fp_native_mode(encoder);
382 if (mode) {
383 ret = 1;
384 drm_mode_probed_add(connector, mode);
385 /* add scaled modes */
386 radeon_add_common_modes(encoder, connector);
389 return ret;
392 static int radeon_lvds_mode_valid(struct drm_connector *connector,
393 struct drm_display_mode *mode)
395 return MODE_OK;
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;
403 bool dret;
405 if (encoder) {
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);
420 if (dret)
421 ret = connector_status_connected;
423 /* check acpi lid status ??? */
425 radeon_connector_update_scratch_regs(connector, ret);
426 return 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);
438 kfree(connector);
441 static int radeon_lvds_set_property(struct drm_connector *connector,
442 struct drm_property *property,
443 uint64_t value)
445 struct drm_device *dev = connector->dev;
446 struct radeon_encoder *radeon_encoder;
447 enum radeon_rmx_type rmx_type;
449 DRM_DEBUG("\n");
450 if (property != dev->mode_config.scaling_mode_property)
451 return 0;
453 if (connector->encoder)
454 radeon_encoder = to_radeon_encoder(connector->encoder);
455 else {
456 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
457 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
460 switch (value) {
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;
464 default:
465 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
467 if (radeon_encoder->rmx_type == rmx_type)
468 return 0;
470 radeon_encoder->rmx_type = rmx_type;
472 radeon_property_change_mode(&radeon_encoder->base);
473 return 0;
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);
494 int ret;
496 ret = radeon_ddc_get_modes(radeon_connector);
498 return ret;
501 static int radeon_vga_mode_valid(struct drm_connector *connector,
502 struct drm_display_mode *mode)
504 return MODE_OK;
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;
512 bool dret;
513 enum drm_connector_status ret = connector_status_disconnected;
515 encoder = radeon_best_single_encoder(connector);
516 if (!encoder)
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);
522 if (dret)
523 ret = connector_status_connected;
524 else {
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);
534 return 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);
559 if (!encoder)
560 return 0;
562 /* avivo chips can scale any mode */
563 if (rdev->family >= CHIP_RS600)
564 /* add scaled modes */
565 radeon_add_common_modes(encoder, connector);
566 else {
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);
572 return 1;
575 static int radeon_tv_mode_valid(struct drm_connector *connector,
576 struct drm_display_mode *mode)
578 return MODE_OK;
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)
589 return ret;
591 encoder = radeon_best_single_encoder(connector);
592 if (!encoder)
593 ret = connector_status_disconnected;
594 else {
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);
601 return 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);
621 int ret;
623 ret = radeon_ddc_get_modes(radeon_connector);
624 return ret;
628 * DVI is complicated
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;
644 int i;
645 enum drm_connector_status ret = connector_status_disconnected;
646 bool dret;
648 radeon_i2c_do_lock(radeon_connector, 1);
649 dret = radeon_ddc_probe(radeon_connector);
650 radeon_i2c_do_lock(radeon_connector, 0);
651 if (dret) {
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));
659 } else {
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
664 TV conflicts */
665 ret = connector_status_connected;
669 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
670 goto out;
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)
676 break;
678 obj = drm_mode_object_find(connector->dev,
679 connector->encoder_ids[i],
680 DRM_MODE_OBJECT_ENCODER);
681 if (!obj)
682 continue;
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;
694 break;
699 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
700 encoder) {
701 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
704 out:
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);
707 return 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;
717 int i;
718 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
719 if (connector->encoder_ids[i] == 0)
720 break;
722 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
723 if (!obj)
724 continue;
726 encoder = obj_to_encoder(obj);
728 if (radeon_connector->use_digital == true) {
729 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
730 return encoder;
731 } else {
732 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
733 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
734 return encoder;
738 /* see if we have a default encoder TODO */
740 /* then check use digitial */
741 /* pick the first one */
742 if (enc_id) {
743 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
744 if (!obj)
745 return NULL;
746 encoder = obj_to_encoder(obj);
747 return encoder;
749 return NULL;
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,
776 void
777 radeon_add_atom_connector(struct drm_device *dev,
778 uint32_t connector_id,
779 uint32_t supported_device,
780 int connector_type,
781 struct radeon_i2c_bus_rec *i2c_bus,
782 bool linkb,
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;
790 int ret;
792 /* fixme - tv/cv/din */
793 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
794 return;
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;
801 return;
805 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
806 if (!radeon_connector)
807 return;
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);
817 if (ret)
818 goto failed;
819 if (i2c_bus->valid) {
820 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
821 if (!radeon_connector->ddc_bus)
822 goto failed;
824 radeon_connector->dac_load_detect = true;
825 drm_connector_attach_property(&radeon_connector->base,
826 rdev->mode_info.load_detect_property,
828 break;
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);
832 if (ret)
833 goto failed;
834 if (i2c_bus->valid) {
835 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
836 if (!radeon_connector->ddc_bus)
837 goto failed;
839 radeon_connector->dac_load_detect = true;
840 drm_connector_attach_property(&radeon_connector->base,
841 rdev->mode_info.load_detect_property,
843 break;
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)
848 goto failed;
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);
854 if (ret)
855 goto failed;
856 if (i2c_bus->valid) {
857 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
858 if (!radeon_connector->ddc_bus)
859 goto failed;
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,
869 break;
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)
874 goto failed;
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);
880 if (ret)
881 goto failed;
882 if (i2c_bus->valid) {
883 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI");
884 if (!radeon_connector->ddc_bus)
885 goto failed;
887 drm_connector_attach_property(&radeon_connector->base,
888 rdev->mode_info.coherent_mode_property,
890 subpixel_order = SubPixelHorizontalRGB;
891 break;
892 case DRM_MODE_CONNECTOR_DisplayPort:
893 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
894 if (!radeon_dig_connector)
895 goto failed;
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);
901 if (ret)
902 goto failed;
903 if (i2c_bus->valid) {
904 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
905 if (!radeon_connector->ddc_bus)
906 goto failed;
908 subpixel_order = SubPixelHorizontalRGB;
909 break;
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);
916 if (ret)
917 goto failed;
918 radeon_connector->dac_load_detect = true;
919 drm_connector_attach_property(&radeon_connector->base,
920 rdev->mode_info.load_detect_property,
923 break;
924 case DRM_MODE_CONNECTOR_LVDS:
925 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
926 if (!radeon_dig_connector)
927 goto failed;
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);
933 if (ret)
934 goto failed;
935 if (i2c_bus->valid) {
936 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
937 if (!radeon_connector->ddc_bus)
938 goto failed;
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;
945 break;
948 connector->display_info.subpixel_order = subpixel_order;
949 drm_sysfs_connector_add(connector);
950 return;
952 failed:
953 if (radeon_connector->ddc_bus)
954 radeon_i2c_destroy(radeon_connector->ddc_bus);
955 drm_connector_cleanup(connector);
956 kfree(connector);
959 void
960 radeon_add_legacy_connector(struct drm_device *dev,
961 uint32_t connector_id,
962 uint32_t supported_device,
963 int connector_type,
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;
970 int ret;
972 /* fixme - tv/cv/din */
973 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
974 return;
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;
981 return;
985 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
986 if (!radeon_connector)
987 return;
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);
997 if (ret)
998 goto failed;
999 if (i2c_bus->valid) {
1000 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1001 if (!radeon_connector->ddc_bus)
1002 goto failed;
1004 radeon_connector->dac_load_detect = true;
1005 drm_connector_attach_property(&radeon_connector->base,
1006 rdev->mode_info.load_detect_property,
1008 break;
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);
1012 if (ret)
1013 goto failed;
1014 if (i2c_bus->valid) {
1015 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1016 if (!radeon_connector->ddc_bus)
1017 goto failed;
1019 radeon_connector->dac_load_detect = true;
1020 drm_connector_attach_property(&radeon_connector->base,
1021 rdev->mode_info.load_detect_property,
1023 break;
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);
1028 if (ret)
1029 goto failed;
1030 if (i2c_bus->valid) {
1031 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1032 if (!radeon_connector->ddc_bus)
1033 goto failed;
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;
1040 break;
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);
1047 if (ret)
1048 goto failed;
1049 radeon_connector->dac_load_detect = true;
1050 drm_connector_attach_property(&radeon_connector->base,
1051 rdev->mode_info.load_detect_property,
1054 break;
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);
1058 if (ret)
1059 goto failed;
1060 if (i2c_bus->valid) {
1061 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1062 if (!radeon_connector->ddc_bus)
1063 goto failed;
1065 drm_connector_attach_property(&radeon_connector->base,
1066 dev->mode_config.scaling_mode_property,
1067 DRM_MODE_SCALE_FULLSCREEN);
1068 subpixel_order = SubPixelHorizontalRGB;
1069 break;
1072 connector->display_info.subpixel_order = subpixel_order;
1073 drm_sysfs_connector_add(connector);
1074 return;
1076 failed:
1077 if (radeon_connector->ddc_bus)
1078 radeon_i2c_destroy(radeon_connector->ddc_bus);
1079 drm_connector_cleanup(connector);
1080 kfree(connector);