blob: e376be47a4a0a67e54d2089b4947d562ac4e9fad [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
22 *
23 * Authors: Dave Airlie
24 * Alex Deucher
25 */
26#include "drmP.h"
27#include "drm_edid.h"
28#include "drm_crtc_helper.h"
Dave Airlied50ba252009-09-23 14:44:08 +100029#include "drm_fb_helper.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020030#include "radeon_drm.h"
31#include "radeon.h"
Alex Deucher923f6842009-09-10 17:53:39 -040032#include "atom.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020033
34extern void
35radeon_combios_connected_scratch_regs(struct drm_connector *connector,
36 struct drm_encoder *encoder,
37 bool connected);
38extern void
39radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
40 struct drm_encoder *encoder,
41 bool connected);
42
Dave Airlie445282d2009-09-09 17:40:54 +100043static void radeon_property_change_mode(struct drm_encoder *encoder)
44{
45 struct drm_crtc *crtc = encoder->crtc;
46
47 if (crtc && crtc->enabled) {
48 drm_crtc_helper_set_mode(crtc, &crtc->mode,
49 crtc->x, crtc->y, crtc->fb);
50 }
51}
Jerome Glisse771fe6b2009-06-05 14:42:42 +020052static void
53radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
54{
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;
63
64 best_encoder = connector_funcs->best_encoder(connector);
65
66 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
67 if (connector->encoder_ids[i] == 0)
68 break;
69
70 obj = drm_mode_object_find(connector->dev,
71 connector->encoder_ids[i],
72 DRM_MODE_OBJECT_ENCODER);
73 if (!obj)
74 continue;
75
76 encoder = obj_to_encoder(obj);
77
78 if ((encoder == best_encoder) && (status == connector_status_connected))
79 connected = true;
80 else
81 connected = false;
82
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);
87
88 }
89}
90
Dave Airlie445282d2009-09-09 17:40:54 +100091struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
92{
93 struct drm_mode_object *obj;
94 struct drm_encoder *encoder;
95 int i;
96
97 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
98 if (connector->encoder_ids[i] == 0)
99 break;
100
101 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
102 if (!obj)
103 continue;
104
105 encoder = obj_to_encoder(obj);
106 if (encoder->encoder_type == encoder_type)
107 return encoder;
108 }
109 return NULL;
110}
111
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200112struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
113{
114 int enc_id = connector->encoder_ids[0];
115 struct drm_mode_object *obj;
116 struct drm_encoder *encoder;
117
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;
125 }
126 return NULL;
127}
128
Dave Airlie4ce001a2009-08-13 16:32:14 +1000129/*
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
134 */
135static enum drm_connector_status
136radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
137 struct drm_encoder *encoder,
138 enum drm_connector_status current_status,
139 bool priority)
140{
141 struct drm_device *dev = connector->dev;
142 struct drm_connector *conflict;
143 int i;
144
145 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
146 if (conflict == connector)
147 continue;
148
149 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
150 if (conflict->encoder_ids[i] == 0)
151 break;
152
153 /* if the IDs match */
154 if (conflict->encoder_ids[i] == encoder->base.id) {
155 if (conflict->status != connector_status_connected)
156 continue;
157
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;
167 }
168 break;
169 }
170 }
171 }
172 return current_status;
173
174}
175
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200176static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
177{
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;
182
183 if (native_mode->panel_xres != 0 &&
184 native_mode->panel_yres != 0 &&
185 native_mode->dotclock != 0) {
186 mode = drm_mode_create(dev);
187
188 mode->hdisplay = native_mode->panel_xres;
189 mode->vdisplay = native_mode->panel_yres;
190
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;
199
200 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
201 drm_mode_set_name(mode);
202
203 DRM_DEBUG("Adding native panel mode %s\n", mode->name);
204 }
205 return mode;
206}
207
Alex Deucher923f6842009-09-10 17:53:39 -0400208static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
209{
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}
236 };
237
238 for (i = 0; i < 17; i++) {
239 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
Michel Dänzerfb1fbf82009-09-15 17:09:28 +0200240 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))
Alex Deucher923f6842009-09-10 17:53:39 -0400244 continue;
245 }
246 if (common_modes[i].w < 320 || common_modes[i].h < 200)
247 continue;
248
Dave Airlied50ba252009-09-23 14:44:08 +1000249 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400250 drm_mode_probed_add(connector, mode);
251 }
252}
253
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200254int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
255 uint64_t val)
256{
Dave Airlie445282d2009-09-09 17:40:54 +1000257 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;
261
262 if (property == rdev->mode_info.coherent_mode_property) {
263 struct radeon_encoder_atom_dig *dig;
264
265 /* need to find digital encoder on connector */
266 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
267 if (!encoder)
268 return 0;
269
270 radeon_encoder = to_radeon_encoder(encoder);
271
272 if (!radeon_encoder->enc_priv)
273 return 0;
274
275 dig = radeon_encoder->enc_priv;
276 dig->coherent_mode = val ? true : false;
277 radeon_property_change_mode(&radeon_encoder->base);
278 }
279
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);
284 }
285
286 if (!encoder)
287 return 0;
288
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;
300 }
301 radeon_property_change_mode(&radeon_encoder->base);
302 }
303
304 if (property == rdev->mode_info.load_detect_property) {
305 struct radeon_connector *radeon_connector =
306 to_radeon_connector(connector);
307
308 if (val == 0)
309 radeon_connector->dac_load_detect = false;
310 else
311 radeon_connector->dac_load_detect = true;
312 }
313
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;
321
322 radeon_encoder = to_radeon_encoder(encoder);
323
324 tmds = radeon_encoder->enc_priv;
325 if (!tmds)
326 return 0;
327
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);
333 }
334 if (val == 1 || ret == false) {
335 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
336 }
337 radeon_property_change_mode(&radeon_encoder->base);
338 }
339
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200340 return 0;
341}
342
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200343static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
344 struct drm_connector *connector)
345{
346 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
347 struct radeon_native_mode *native_mode = &radeon_encoder->native_mode;
348
349 /* Try to get native mode details from EDID if necessary */
350 if (!native_mode->dotclock) {
351 struct drm_display_mode *t, *mode;
352
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;
365 }
366 }
367 }
368 if (!native_mode->dotclock) {
369 DRM_INFO("No LVDS native mode details, disabling RMX\n");
370 radeon_encoder->rmx_type = RMX_OFF;
371 }
372}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200373
374static int radeon_lvds_get_modes(struct drm_connector *connector)
375{
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;
380
381 if (radeon_connector->ddc_bus) {
382 ret = radeon_ddc_get_modes(radeon_connector);
383 if (ret > 0) {
Alex Deucher7747b712009-09-11 11:15:43 -0400384 encoder = radeon_best_single_encoder(connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200385 if (encoder) {
386 radeon_fixup_lvds_native_mode(encoder, connector);
Alex Deucher7747b712009-09-11 11:15:43 -0400387 /* add scaled modes */
388 radeon_add_common_modes(encoder, connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200389 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200390 return ret;
391 }
392 }
393
394 encoder = radeon_best_single_encoder(connector);
395 if (!encoder)
396 return 0;
397
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);
Alex Deucher7747b712009-09-11 11:15:43 -0400403 /* add scaled modes */
404 radeon_add_common_modes(encoder, connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200405 }
Alex Deucher923f6842009-09-10 17:53:39 -0400406
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200407 return ret;
408}
409
410static int radeon_lvds_mode_valid(struct drm_connector *connector,
411 struct drm_display_mode *mode)
412{
413 return MODE_OK;
414}
415
416static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connector)
417{
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;
422}
423
424static void radeon_connector_destroy(struct drm_connector *connector)
425{
426 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
427
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);
434}
435
Dave Airlie445282d2009-09-09 17:40:54 +1000436static int radeon_lvds_set_property(struct drm_connector *connector,
437 struct drm_property *property,
438 uint64_t value)
439{
440 struct drm_device *dev = connector->dev;
441 struct radeon_encoder *radeon_encoder;
442 enum radeon_rmx_type rmx_type;
443
444 DRM_DEBUG("\n");
445 if (property != dev->mode_config.scaling_mode_property)
446 return 0;
447
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));
453 }
454
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;
461 }
462 if (radeon_encoder->rmx_type == rmx_type)
463 return 0;
464
465 radeon_encoder->rmx_type = rmx_type;
466
467 radeon_property_change_mode(&radeon_encoder->base);
468 return 0;
469}
470
471
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200472struct 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,
476};
477
478struct 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,
Dave Airlie445282d2009-09-09 17:40:54 +1000483 .set_property = radeon_lvds_set_property,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200484};
485
486static int radeon_vga_get_modes(struct drm_connector *connector)
487{
488 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
489 int ret;
490
491 ret = radeon_ddc_get_modes(radeon_connector);
492
493 return ret;
494}
495
496static int radeon_vga_mode_valid(struct drm_connector *connector,
497 struct drm_display_mode *mode)
498{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200499 return MODE_OK;
500}
501
502static enum drm_connector_status radeon_vga_detect(struct drm_connector *connector)
503{
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;
509
Dave Airlie4ce001a2009-08-13 16:32:14 +1000510 encoder = radeon_best_single_encoder(connector);
511 if (!encoder)
512 ret = connector_status_disconnected;
513
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200514 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 {
Dave Airlie445282d2009-09-09 17:40:54 +1000520 if (radeon_connector->dac_load_detect) {
521 encoder_funcs = encoder->helper_private;
522 ret = encoder_funcs->detect(encoder, connector);
523 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200524 }
525
Dave Airlie4ce001a2009-08-13 16:32:14 +1000526 if (ret == connector_status_connected)
527 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200528 radeon_connector_update_scratch_regs(connector, ret);
529 return ret;
530}
531
532struct 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,
536};
537
538struct 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,
544};
545
Dave Airlie4ce001a2009-08-13 16:32:14 +1000546static int radeon_tv_get_modes(struct drm_connector *connector)
547{
548 struct drm_device *dev = connector->dev;
Alex Deucher923f6842009-09-10 17:53:39 -0400549 struct radeon_device *rdev = dev->dev_private;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000550 struct drm_display_mode *tv_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400551 struct drm_encoder *encoder;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000552
Alex Deucher923f6842009-09-10 17:53:39 -0400553 encoder = radeon_best_single_encoder(connector);
554 if (!encoder)
555 return 0;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000556
Alex Deucher923f6842009-09-10 17:53:39 -0400557 /* 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 */
Dave Airlied50ba252009-09-23 14:44:08 +1000563 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400564 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
565 drm_mode_probed_add(connector, tv_mode);
566 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000567 return 1;
568}
569
570static int radeon_tv_mode_valid(struct drm_connector *connector,
571 struct drm_display_mode *mode)
572{
573 return MODE_OK;
574}
575
576static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector)
577{
578 struct drm_encoder *encoder;
579 struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie445282d2009-09-09 17:40:54 +1000580 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
581 enum drm_connector_status ret = connector_status_disconnected;
582
583 if (!radeon_connector->dac_load_detect)
584 return ret;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000585
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);
592 }
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;
597}
598
599struct 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,
603};
604
605struct 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,
611};
612
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200613static int radeon_dvi_get_modes(struct drm_connector *connector)
614{
615 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
616 int ret;
617
618 ret = radeon_ddc_get_modes(radeon_connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200619 return ret;
620}
621
Dave Airlie4ce001a2009-08-13 16:32:14 +1000622/*
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.
632 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200633static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector)
634{
635 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000636 struct drm_encoder *encoder = NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200637 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;
642
643 radeon_i2c_do_lock(radeon_connector, 1);
644 dret = radeon_ddc_probe(radeon_connector);
645 radeon_i2c_do_lock(radeon_connector, 0);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000646 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);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200650
Dave Airlie4ce001a2009-08-13 16:32:14 +1000651 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);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200656
Dave Airlie4ce001a2009-08-13 16:32:14 +1000657 /* 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;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200661 }
662 }
663
Dave Airlie4ce001a2009-08-13 16:32:14 +1000664 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
665 goto out;
666
667 /* find analog encoder */
Dave Airlie445282d2009-09-09 17:40:54 +1000668 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;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000672
Dave Airlie445282d2009-09-09 17:40:54 +1000673 obj = drm_mode_object_find(connector->dev,
674 connector->encoder_ids[i],
675 DRM_MODE_OBJECT_ENCODER);
676 if (!obj)
677 continue;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000678
Dave Airlie445282d2009-09-09 17:40:54 +1000679 encoder = obj_to_encoder(obj);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000680
Dave Airlie445282d2009-09-09 17:40:54 +1000681 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;
687 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000688 }
Dave Airlie445282d2009-09-09 17:40:54 +1000689 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000690 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000691 }
692 }
693
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);
697 }
698
699out:
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200700 /* 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;
703}
704
705/* okay need to be smart in here about which encoder to pick */
706struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
707{
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;
716
717 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
718 if (!obj)
719 continue;
720
721 encoder = obj_to_encoder(obj);
722
Dave Airlie4ce001a2009-08-13 16:32:14 +1000723 if (radeon_connector->use_digital == true) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200724 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;
730 }
731 }
732
733 /* see if we have a default encoder TODO */
734
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;
743 }
744 return NULL;
745}
746
Dave Airlied50ba252009-09-23 14:44:08 +1000747static void radeon_dvi_force(struct drm_connector *connector)
748{
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;
754}
755
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200756struct 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,
760};
761
762struct 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,
Dave Airlied50ba252009-09-23 14:44:08 +1000768 .force = radeon_dvi_force,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200769};
770
771void
772radeon_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)
779{
Dave Airlie445282d2009-09-09 17:40:54 +1000780 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200781 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;
Dave Airlied50ba252009-09-23 14:44:08 +1000785 int ret;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200786
787 /* fixme - tv/cv/din */
Dave Airlie4ce001a2009-08-13 16:32:14 +1000788 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200789 return;
790
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;
797 }
798 }
799
800 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
801 if (!radeon_connector)
802 return;
803
804 connector = &radeon_connector->base;
805
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);
Dave Airlie74bf2ad2009-09-28 15:31:10 +1000811 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
812 if (ret)
813 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200814 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;
818 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +1000819 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +1000820 drm_connector_attach_property(&radeon_connector->base,
821 rdev->mode_info.load_detect_property,
822 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200823 break;
824 case DRM_MODE_CONNECTOR_DVIA:
825 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +1000826 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
827 if (ret)
828 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200829 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;
833 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +1000834 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +1000835 drm_connector_attach_property(&radeon_connector->base,
836 rdev->mode_info.load_detect_property,
837 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200838 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);
Dave Airlie74bf2ad2009-09-28 15:31:10 +1000848 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
849 if (ret)
850 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200851 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;
855 }
856 subpixel_order = SubPixelHorizontalRGB;
Dave Airlie445282d2009-09-09 17:40:54 +1000857 drm_connector_attach_property(&radeon_connector->base,
858 rdev->mode_info.coherent_mode_property,
859 1);
Dave Airlie35e4b7a2009-09-25 11:56:50 +1000860 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +1000861 drm_connector_attach_property(&radeon_connector->base,
862 rdev->mode_info.load_detect_property,
863 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200864 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);
Dave Airlie74bf2ad2009-09-28 15:31:10 +1000874 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
875 if (ret)
876 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200877 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;
881 }
Dave Airlie445282d2009-09-09 17:40:54 +1000882 drm_connector_attach_property(&radeon_connector->base,
883 rdev->mode_info.coherent_mode_property,
884 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200885 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);
Dave Airlie74bf2ad2009-09-28 15:31:10 +1000895 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
896 if (ret)
897 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200898 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;
902 }
903 subpixel_order = SubPixelHorizontalRGB;
904 break;
905 case DRM_MODE_CONNECTOR_SVIDEO:
906 case DRM_MODE_CONNECTOR_Composite:
907 case DRM_MODE_CONNECTOR_9PinDIN:
Dave Airlie4ce001a2009-08-13 16:32:14 +1000908 if (radeon_tv == 1) {
909 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +1000910 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,
916 1);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000917 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200918 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);
Dave Airlie74bf2ad2009-09-28 15:31:10 +1000927 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
928 if (ret)
929 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200930 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;
934 }
Dave Airlie445282d2009-09-09 17:40:54 +1000935 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);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200939 subpixel_order = SubPixelHorizontalRGB;
940 break;
941 }
942
943 connector->display_info.subpixel_order = subpixel_order;
944 drm_sysfs_connector_add(connector);
945 return;
946
947failed:
948 if (radeon_connector->ddc_bus)
949 radeon_i2c_destroy(radeon_connector->ddc_bus);
950 drm_connector_cleanup(connector);
951 kfree(connector);
952}
953
954void
955radeon_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)
960{
Dave Airlie445282d2009-09-09 17:40:54 +1000961 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200962 struct drm_connector *connector;
963 struct radeon_connector *radeon_connector;
964 uint32_t subpixel_order = SubPixelNone;
Dave Airlied50ba252009-09-23 14:44:08 +1000965 int ret;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200966
967 /* fixme - tv/cv/din */
Dave Airlie4ce001a2009-08-13 16:32:14 +1000968 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200969 return;
970
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;
977 }
978 }
979
980 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
981 if (!radeon_connector)
982 return;
983
984 connector = &radeon_connector->base;
985
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);
Dave Airlie74bf2ad2009-09-28 15:31:10 +1000991 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
992 if (ret)
993 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200994 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;
998 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +1000999 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001000 drm_connector_attach_property(&radeon_connector->base,
1001 rdev->mode_info.load_detect_property,
1002 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001003 break;
1004 case DRM_MODE_CONNECTOR_DVIA:
1005 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001006 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1007 if (ret)
1008 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001009 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;
1013 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001014 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001015 drm_connector_attach_property(&radeon_connector->base,
1016 rdev->mode_info.load_detect_property,
1017 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001018 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);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001022 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1023 if (ret)
1024 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001025 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;
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001029 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001030 drm_connector_attach_property(&radeon_connector->base,
1031 rdev->mode_info.load_detect_property,
1032 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001033 }
1034 subpixel_order = SubPixelHorizontalRGB;
1035 break;
1036 case DRM_MODE_CONNECTOR_SVIDEO:
1037 case DRM_MODE_CONNECTOR_Composite:
1038 case DRM_MODE_CONNECTOR_9PinDIN:
Dave Airlie4ce001a2009-08-13 16:32:14 +10001039 if (radeon_tv == 1) {
1040 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001041 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1042 if (ret)
1043 goto failed;
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001044 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001045 drm_connector_attach_property(&radeon_connector->base,
1046 rdev->mode_info.load_detect_property,
1047 1);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001048 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001049 break;
1050 case DRM_MODE_CONNECTOR_LVDS:
1051 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001052 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1053 if (ret)
1054 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001055 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;
1059 }
Dave Airlie445282d2009-09-09 17:40:54 +10001060 drm_connector_attach_property(&radeon_connector->base,
1061 dev->mode_config.scaling_mode_property,
1062 DRM_MODE_SCALE_FULLSCREEN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001063 subpixel_order = SubPixelHorizontalRGB;
1064 break;
1065 }
1066
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001067 connector->display_info.subpixel_order = subpixel_order;
1068 drm_sysfs_connector_add(connector);
1069 return;
1070
1071failed:
1072 if (radeon_connector->ddc_bus)
1073 radeon_i2c_destroy(radeon_connector->ddc_bus);
1074 drm_connector_cleanup(connector);
1075 kfree(connector);
1076}