First Support on Ginger and OMAP TI
[linux-ginger.git] / drivers / gpu / drm / radeon / radeon_connectors.c
blobe376be47a4a0a67e54d2089b4947d562ac4e9fad
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 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;
198 mode->flags = 0;
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);
205 return mode;
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;
214 int i;
215 struct mode_size {
216 int w;
217 int h;
218 } common_modes[17] = {
219 { 640, 480},
220 { 720, 480},
221 { 800, 600},
222 { 848, 480},
223 {1024, 768},
224 {1152, 768},
225 {1280, 720},
226 {1280, 800},
227 {1280, 854},
228 {1280, 960},
229 {1280, 1024},
230 {1440, 900},
231 {1400, 1050},
232 {1680, 1050},
233 {1600, 1200},
234 {1920, 1080},
235 {1920, 1200}
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))
244 continue;
246 if (common_modes[i].w < 320 || common_modes[i].h < 200)
247 continue;
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,
255 uint64_t val)
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);
267 if (!encoder)
268 return 0;
270 radeon_encoder = to_radeon_encoder(encoder);
272 if (!radeon_encoder->enc_priv)
273 return 0;
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);
282 if (!encoder) {
283 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
286 if (!encoder)
287 return 0;
289 radeon_encoder = to_radeon_encoder(encoder);
290 if (!radeon_encoder->enc_priv)
291 return 0;
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;
296 } else {
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);
308 if (val == 0)
309 radeon_connector->dac_load_detect = false;
310 else
311 radeon_connector->dac_load_detect = true;
314 if (property == rdev->mode_info.tmds_pll_property) {
315 struct radeon_encoder_int_tmds *tmds = NULL;
316 bool ret = false;
317 /* need to find digital encoder on connector */
318 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
319 if (!encoder)
320 return 0;
322 radeon_encoder = to_radeon_encoder(encoder);
324 tmds = radeon_encoder->enc_priv;
325 if (!tmds)
326 return 0;
328 if (val == 0) {
329 if (rdev->is_atom_bios)
330 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
331 else
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);
340 return 0;
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");
364 break;
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;
378 int ret = 0;
379 struct drm_display_mode *mode;
381 if (radeon_connector->ddc_bus) {
382 ret = radeon_ddc_get_modes(radeon_connector);
383 if (ret > 0) {
384 encoder = radeon_best_single_encoder(connector);
385 if (encoder) {
386 radeon_fixup_lvds_native_mode(encoder, connector);
387 /* add scaled modes */
388 radeon_add_common_modes(encoder, connector);
390 return ret;
394 encoder = radeon_best_single_encoder(connector);
395 if (!encoder)
396 return 0;
398 /* we have no EDID modes */
399 mode = radeon_fp_native_mode(encoder);
400 if (mode) {
401 ret = 1;
402 drm_mode_probed_add(connector, mode);
403 /* add scaled modes */
404 radeon_add_common_modes(encoder, connector);
407 return ret;
410 static int radeon_lvds_mode_valid(struct drm_connector *connector,
411 struct drm_display_mode *mode)
413 return MODE_OK;
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);
421 return 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);
433 kfree(connector);
436 static int radeon_lvds_set_property(struct drm_connector *connector,
437 struct drm_property *property,
438 uint64_t value)
440 struct drm_device *dev = connector->dev;
441 struct radeon_encoder *radeon_encoder;
442 enum radeon_rmx_type rmx_type;
444 DRM_DEBUG("\n");
445 if (property != dev->mode_config.scaling_mode_property)
446 return 0;
448 if (connector->encoder)
449 radeon_encoder = to_radeon_encoder(connector->encoder);
450 else {
451 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
452 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
455 switch (value) {
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;
459 default:
460 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
462 if (radeon_encoder->rmx_type == rmx_type)
463 return 0;
465 radeon_encoder->rmx_type = rmx_type;
467 radeon_property_change_mode(&radeon_encoder->base);
468 return 0;
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);
489 int ret;
491 ret = radeon_ddc_get_modes(radeon_connector);
493 return ret;
496 static int radeon_vga_mode_valid(struct drm_connector *connector,
497 struct drm_display_mode *mode)
499 return MODE_OK;
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;
507 bool dret;
508 enum drm_connector_status ret = connector_status_disconnected;
510 encoder = radeon_best_single_encoder(connector);
511 if (!encoder)
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);
517 if (dret)
518 ret = connector_status_connected;
519 else {
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);
529 return 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);
554 if (!encoder)
555 return 0;
557 /* avivo chips can scale any mode */
558 if (rdev->family >= CHIP_RS600)
559 /* add scaled modes */
560 radeon_add_common_modes(encoder, connector);
561 else {
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);
567 return 1;
570 static int radeon_tv_mode_valid(struct drm_connector *connector,
571 struct drm_display_mode *mode)
573 return MODE_OK;
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)
584 return ret;
586 encoder = radeon_best_single_encoder(connector);
587 if (!encoder)
588 ret = connector_status_disconnected;
589 else {
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);
596 return 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);
616 int ret;
618 ret = radeon_ddc_get_modes(radeon_connector);
619 return ret;
623 * DVI is complicated
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;
639 int i;
640 enum drm_connector_status ret = connector_status_disconnected;
641 bool dret;
643 radeon_i2c_do_lock(radeon_connector, 1);
644 dret = radeon_ddc_probe(radeon_connector);
645 radeon_i2c_do_lock(radeon_connector, 0);
646 if (dret) {
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));
654 } else {
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
659 TV conflicts */
660 ret = connector_status_connected;
664 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
665 goto out;
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)
671 break;
673 obj = drm_mode_object_find(connector->dev,
674 connector->encoder_ids[i],
675 DRM_MODE_OBJECT_ENCODER);
676 if (!obj)
677 continue;
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;
689 break;
694 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
695 encoder) {
696 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
699 out:
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);
702 return 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;
712 int i;
713 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
714 if (connector->encoder_ids[i] == 0)
715 break;
717 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
718 if (!obj)
719 continue;
721 encoder = obj_to_encoder(obj);
723 if (radeon_connector->use_digital == true) {
724 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
725 return encoder;
726 } else {
727 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
728 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
729 return encoder;
733 /* see if we have a default encoder TODO */
735 /* then check use digitial */
736 /* pick the first one */
737 if (enc_id) {
738 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
739 if (!obj)
740 return NULL;
741 encoder = obj_to_encoder(obj);
742 return encoder;
744 return NULL;
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,
771 void
772 radeon_add_atom_connector(struct drm_device *dev,
773 uint32_t connector_id,
774 uint32_t supported_device,
775 int connector_type,
776 struct radeon_i2c_bus_rec *i2c_bus,
777 bool linkb,
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;
785 int ret;
787 /* fixme - tv/cv/din */
788 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
789 return;
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;
796 return;
800 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
801 if (!radeon_connector)
802 return;
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);
812 if (ret)
813 goto failed;
814 if (i2c_bus->valid) {
815 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
816 if (!radeon_connector->ddc_bus)
817 goto failed;
819 radeon_connector->dac_load_detect = true;
820 drm_connector_attach_property(&radeon_connector->base,
821 rdev->mode_info.load_detect_property,
823 break;
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);
827 if (ret)
828 goto failed;
829 if (i2c_bus->valid) {
830 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
831 if (!radeon_connector->ddc_bus)
832 goto failed;
834 radeon_connector->dac_load_detect = true;
835 drm_connector_attach_property(&radeon_connector->base,
836 rdev->mode_info.load_detect_property,
838 break;
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)
843 goto failed;
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);
849 if (ret)
850 goto failed;
851 if (i2c_bus->valid) {
852 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
853 if (!radeon_connector->ddc_bus)
854 goto failed;
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,
864 break;
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)
869 goto failed;
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);
875 if (ret)
876 goto failed;
877 if (i2c_bus->valid) {
878 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI");
879 if (!radeon_connector->ddc_bus)
880 goto failed;
882 drm_connector_attach_property(&radeon_connector->base,
883 rdev->mode_info.coherent_mode_property,
885 subpixel_order = SubPixelHorizontalRGB;
886 break;
887 case DRM_MODE_CONNECTOR_DisplayPort:
888 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
889 if (!radeon_dig_connector)
890 goto failed;
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);
896 if (ret)
897 goto failed;
898 if (i2c_bus->valid) {
899 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
900 if (!radeon_connector->ddc_bus)
901 goto failed;
903 subpixel_order = SubPixelHorizontalRGB;
904 break;
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);
911 if (ret)
912 goto failed;
913 radeon_connector->dac_load_detect = true;
914 drm_connector_attach_property(&radeon_connector->base,
915 rdev->mode_info.load_detect_property,
918 break;
919 case DRM_MODE_CONNECTOR_LVDS:
920 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
921 if (!radeon_dig_connector)
922 goto failed;
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);
928 if (ret)
929 goto failed;
930 if (i2c_bus->valid) {
931 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
932 if (!radeon_connector->ddc_bus)
933 goto failed;
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;
940 break;
943 connector->display_info.subpixel_order = subpixel_order;
944 drm_sysfs_connector_add(connector);
945 return;
947 failed:
948 if (radeon_connector->ddc_bus)
949 radeon_i2c_destroy(radeon_connector->ddc_bus);
950 drm_connector_cleanup(connector);
951 kfree(connector);
954 void
955 radeon_add_legacy_connector(struct drm_device *dev,
956 uint32_t connector_id,
957 uint32_t supported_device,
958 int connector_type,
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;
965 int ret;
967 /* fixme - tv/cv/din */
968 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
969 return;
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;
976 return;
980 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
981 if (!radeon_connector)
982 return;
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);
992 if (ret)
993 goto failed;
994 if (i2c_bus->valid) {
995 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
996 if (!radeon_connector->ddc_bus)
997 goto failed;
999 radeon_connector->dac_load_detect = true;
1000 drm_connector_attach_property(&radeon_connector->base,
1001 rdev->mode_info.load_detect_property,
1003 break;
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);
1007 if (ret)
1008 goto failed;
1009 if (i2c_bus->valid) {
1010 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1011 if (!radeon_connector->ddc_bus)
1012 goto failed;
1014 radeon_connector->dac_load_detect = true;
1015 drm_connector_attach_property(&radeon_connector->base,
1016 rdev->mode_info.load_detect_property,
1018 break;
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);
1023 if (ret)
1024 goto failed;
1025 if (i2c_bus->valid) {
1026 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1027 if (!radeon_connector->ddc_bus)
1028 goto failed;
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;
1035 break;
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);
1042 if (ret)
1043 goto failed;
1044 radeon_connector->dac_load_detect = true;
1045 drm_connector_attach_property(&radeon_connector->base,
1046 rdev->mode_info.load_detect_property,
1049 break;
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);
1053 if (ret)
1054 goto failed;
1055 if (i2c_bus->valid) {
1056 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1057 if (!radeon_connector->ddc_bus)
1058 goto failed;
1060 drm_connector_attach_property(&radeon_connector->base,
1061 dev->mode_config.scaling_mode_property,
1062 DRM_MODE_SCALE_FULLSCREEN);
1063 subpixel_order = SubPixelHorizontalRGB;
1064 break;
1067 connector->display_info.subpixel_order = subpixel_order;
1068 drm_sysfs_connector_add(connector);
1069 return;
1071 failed:
1072 if (radeon_connector->ddc_bus)
1073 radeon_i2c_destroy(radeon_connector->ddc_bus);
1074 drm_connector_cleanup(connector);
1075 kfree(connector);