Subversion Repositories Kolibri OS

Rev

Rev 1268 | Rev 1321 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1123 serge 1
/*
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"
1126 serge 27
#include "drm_edid.h"
1123 serge 28
#include "drm_crtc_helper.h"
1221 serge 29
#include "drm_fb_helper.h"
1123 serge 30
#include "radeon_drm.h"
31
#include "radeon.h"
1179 serge 32
#include "atom.h"
1123 serge 33
 
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);
42
 
1179 serge 43
static 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
}
1123 serge 52
static void
53
radeon_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
 
1179 serge 91
struct 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
 
1123 serge 112
struct 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
 
1179 serge 129
/*
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
 */
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)
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
 
1123 serge 176
static 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;
1268 serge 181
	struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1123 serge 182
 
1268 serge 183
	if (native_mode->hdisplay != 0 &&
184
	    native_mode->vdisplay != 0 &&
185
	    native_mode->clock != 0) {
186
		mode = drm_mode_duplicate(dev, native_mode);
1123 serge 187
		mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
188
		drm_mode_set_name(mode);
189
 
190
		DRM_DEBUG("Adding native panel mode %s\n", mode->name);
191
	}
192
	return mode;
193
}
194
 
1179 serge 195
static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
196
{
197
	struct drm_device *dev = encoder->dev;
198
	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
199
	struct drm_display_mode *mode = NULL;
1268 serge 200
	struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1179 serge 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}
223
	};
224
 
225
	for (i = 0; i < 17; i++) {
1268 serge 226
		if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
227
			if (common_modes[i].w > 1024 ||
228
			    common_modes[i].h > 768)
229
				continue;
230
		}
1179 serge 231
		if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1268 serge 232
			if (common_modes[i].w > native_mode->hdisplay ||
233
			    common_modes[i].h > native_mode->vdisplay ||
234
			    (common_modes[i].w == native_mode->hdisplay &&
235
			     common_modes[i].h == native_mode->vdisplay))
1179 serge 236
				continue;
237
		}
238
		if (common_modes[i].w < 320 || common_modes[i].h < 200)
239
			continue;
240
 
1221 serge 241
		mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
1179 serge 242
		drm_mode_probed_add(connector, mode);
243
	}
244
}
245
 
1123 serge 246
int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
247
				  uint64_t val)
248
{
1179 serge 249
	struct drm_device *dev = connector->dev;
250
	struct radeon_device *rdev = dev->dev_private;
251
	struct drm_encoder *encoder;
252
	struct radeon_encoder *radeon_encoder;
253
 
254
	if (property == rdev->mode_info.coherent_mode_property) {
255
		struct radeon_encoder_atom_dig *dig;
256
 
257
		/* need to find digital encoder on connector */
258
		encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
259
		if (!encoder)
260
			return 0;
261
 
262
		radeon_encoder = to_radeon_encoder(encoder);
263
 
264
		if (!radeon_encoder->enc_priv)
265
			return 0;
266
 
267
		dig = radeon_encoder->enc_priv;
268
		dig->coherent_mode = val ? true : false;
269
		radeon_property_change_mode(&radeon_encoder->base);
270
	}
271
 
272
	if (property == rdev->mode_info.tv_std_property) {
273
		encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
274
		if (!encoder) {
275
			encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
276
		}
277
 
278
		if (!encoder)
279
			return 0;
280
 
281
		radeon_encoder = to_radeon_encoder(encoder);
282
		if (!radeon_encoder->enc_priv)
283
			return 0;
284
		if (rdev->is_atom_bios) {
285
			struct radeon_encoder_atom_dac *dac_int;
286
			dac_int = radeon_encoder->enc_priv;
287
			dac_int->tv_std = val;
288
		} else {
289
			struct radeon_encoder_tv_dac *dac_int;
290
			dac_int = radeon_encoder->enc_priv;
291
			dac_int->tv_std = val;
292
		}
293
		radeon_property_change_mode(&radeon_encoder->base);
294
	}
295
 
296
	if (property == rdev->mode_info.load_detect_property) {
297
		struct radeon_connector *radeon_connector =
298
			to_radeon_connector(connector);
299
 
300
		if (val == 0)
301
			radeon_connector->dac_load_detect = false;
302
		else
303
			radeon_connector->dac_load_detect = true;
304
	}
305
 
306
	if (property == rdev->mode_info.tmds_pll_property) {
307
		struct radeon_encoder_int_tmds *tmds = NULL;
308
		bool ret = false;
309
		/* need to find digital encoder on connector */
310
		encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
311
		if (!encoder)
312
			return 0;
313
 
314
		radeon_encoder = to_radeon_encoder(encoder);
315
 
316
		tmds = radeon_encoder->enc_priv;
317
		if (!tmds)
318
			return 0;
319
 
320
		if (val == 0) {
321
			if (rdev->is_atom_bios)
322
				ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
323
			else
324
				ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
325
		}
326
		if (val == 1 || ret == false) {
327
			radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
328
		}
329
		radeon_property_change_mode(&radeon_encoder->base);
330
	}
331
 
1123 serge 332
	return 0;
333
}
334
 
1179 serge 335
static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
336
					  struct drm_connector *connector)
337
{
338
	struct radeon_encoder *radeon_encoder =	to_radeon_encoder(encoder);
1268 serge 339
	struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1123 serge 340
 
1179 serge 341
	/* Try to get native mode details from EDID if necessary */
1268 serge 342
	if (!native_mode->clock) {
1179 serge 343
		struct drm_display_mode *t, *mode;
344
 
345
		list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
1268 serge 346
			if (mode->hdisplay == native_mode->hdisplay &&
347
			    mode->vdisplay == native_mode->vdisplay) {
348
				*native_mode = *mode;
349
				drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
1179 serge 350
				DRM_INFO("Determined LVDS native mode details from EDID\n");
351
				break;
352
			}
353
		}
354
	}
1268 serge 355
	if (!native_mode->clock) {
1179 serge 356
		DRM_INFO("No LVDS native mode details, disabling RMX\n");
357
		radeon_encoder->rmx_type = RMX_OFF;
358
	}
359
}
360
 
1123 serge 361
static int radeon_lvds_get_modes(struct drm_connector *connector)
362
{
363
	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
364
	struct drm_encoder *encoder;
365
	int ret = 0;
366
	struct drm_display_mode *mode;
367
 
368
	if (radeon_connector->ddc_bus) {
369
		ret = radeon_ddc_get_modes(radeon_connector);
370
		if (ret > 0) {
1179 serge 371
			encoder = radeon_best_single_encoder(connector);
372
			if (encoder) {
373
				radeon_fixup_lvds_native_mode(encoder, connector);
374
				/* add scaled modes */
375
				radeon_add_common_modes(encoder, connector);
376
			}
1123 serge 377
			return ret;
378
		}
379
	}
380
 
381
	encoder = radeon_best_single_encoder(connector);
382
	if (!encoder)
383
		return 0;
384
 
385
	/* we have no EDID modes */
386
	mode = radeon_fp_native_mode(encoder);
387
	if (mode) {
388
		ret = 1;
389
		drm_mode_probed_add(connector, mode);
1179 serge 390
		/* add scaled modes */
391
		radeon_add_common_modes(encoder, connector);
1123 serge 392
	}
1179 serge 393
 
1123 serge 394
	return ret;
395
}
396
 
397
static int radeon_lvds_mode_valid(struct drm_connector *connector,
398
				  struct drm_display_mode *mode)
399
{
1268 serge 400
	struct drm_encoder *encoder = radeon_best_single_encoder(connector);
401
 
402
	if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
403
		return MODE_PANEL;
404
 
405
	if (encoder) {
406
		struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
407
		struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
408
 
409
		/* AVIVO hardware supports downscaling modes larger than the panel
410
		 * to the panel size, but I'm not sure this is desirable.
411
		 */
412
		if ((mode->hdisplay > native_mode->hdisplay) ||
413
		    (mode->vdisplay > native_mode->vdisplay))
414
			return MODE_PANEL;
415
 
416
		/* if scaling is disabled, block non-native modes */
417
		if (radeon_encoder->rmx_type == RMX_OFF) {
418
			if ((mode->hdisplay != native_mode->hdisplay) ||
419
			    (mode->vdisplay != native_mode->vdisplay))
420
				return MODE_PANEL;
421
		}
422
	}
423
 
1123 serge 424
	return MODE_OK;
425
}
426
 
427
static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connector)
428
{
1268 serge 429
	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
430
	struct drm_encoder *encoder = radeon_best_single_encoder(connector);
431
	enum drm_connector_status ret = connector_status_disconnected;
432
 
433
	if (encoder) {
434
		struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
435
		struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
436
 
437
		/* check if panel is valid */
438
		if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
439
			ret = connector_status_connected;
440
 
441
	}
442
 
443
	/* check for edid as well */
444
	if (radeon_connector->edid)
445
		ret = connector_status_connected;
446
	else {
447
		if (radeon_connector->ddc_bus) {
448
			radeon_i2c_do_lock(radeon_connector, 1);
449
			radeon_connector->edid = drm_get_edid(&radeon_connector->base,
450
							      &radeon_connector->ddc_bus->adapter);
451
			radeon_i2c_do_lock(radeon_connector, 0);
452
			if (radeon_connector->edid)
453
				ret = connector_status_connected;
454
		}
455
	}
1123 serge 456
	/* check acpi lid status ??? */
1268 serge 457
 
1123 serge 458
	radeon_connector_update_scratch_regs(connector, ret);
459
	return ret;
460
}
461
 
462
static void radeon_connector_destroy(struct drm_connector *connector)
463
{
464
	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
465
 
466
	if (radeon_connector->ddc_bus)
467
		radeon_i2c_destroy(radeon_connector->ddc_bus);
1268 serge 468
	if (radeon_connector->edid)
469
		kfree(radeon_connector->edid);
1123 serge 470
	kfree(radeon_connector->con_priv);
1233 serge 471
	drm_sysfs_connector_remove(connector);
1123 serge 472
	drm_connector_cleanup(connector);
473
	kfree(connector);
474
}
475
 
1179 serge 476
static int radeon_lvds_set_property(struct drm_connector *connector,
477
				    struct drm_property *property,
478
				    uint64_t value)
479
{
480
	struct drm_device *dev = connector->dev;
481
	struct radeon_encoder *radeon_encoder;
482
	enum radeon_rmx_type rmx_type;
483
 
484
	DRM_DEBUG("\n");
485
	if (property != dev->mode_config.scaling_mode_property)
486
		return 0;
487
 
488
	if (connector->encoder)
489
		radeon_encoder = to_radeon_encoder(connector->encoder);
490
	else {
491
		struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
492
		radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
493
	}
494
 
495
	switch (value) {
496
	case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
497
	case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
498
	case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
499
	default:
500
	case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
501
	}
502
	if (radeon_encoder->rmx_type == rmx_type)
503
		return 0;
504
 
505
	radeon_encoder->rmx_type = rmx_type;
506
 
507
	radeon_property_change_mode(&radeon_encoder->base);
508
	return 0;
509
}
510
 
511
 
1123 serge 512
struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
513
	.get_modes = radeon_lvds_get_modes,
514
	.mode_valid = radeon_lvds_mode_valid,
515
	.best_encoder = radeon_best_single_encoder,
516
};
517
 
518
struct drm_connector_funcs radeon_lvds_connector_funcs = {
519
	.dpms = drm_helper_connector_dpms,
520
	.detect = radeon_lvds_detect,
521
	.fill_modes = drm_helper_probe_single_connector_modes,
522
	.destroy = radeon_connector_destroy,
1179 serge 523
	.set_property = radeon_lvds_set_property,
1123 serge 524
};
525
 
526
static int radeon_vga_get_modes(struct drm_connector *connector)
527
{
528
	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
529
	int ret;
530
 
531
	ret = radeon_ddc_get_modes(radeon_connector);
532
 
533
	return ret;
534
}
535
 
536
static int radeon_vga_mode_valid(struct drm_connector *connector,
537
				  struct drm_display_mode *mode)
538
{
1268 serge 539
	/* XXX check mode bandwidth */
540
	/* XXX verify against max DAC output frequency */
1123 serge 541
	return MODE_OK;
542
}
543
 
544
static enum drm_connector_status radeon_vga_detect(struct drm_connector *connector)
545
{
546
	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
547
	struct drm_encoder *encoder;
548
	struct drm_encoder_helper_funcs *encoder_funcs;
549
	bool dret;
550
	enum drm_connector_status ret = connector_status_disconnected;
551
 
1179 serge 552
	encoder = radeon_best_single_encoder(connector);
553
	if (!encoder)
554
		ret = connector_status_disconnected;
555
 
1123 serge 556
	radeon_i2c_do_lock(radeon_connector, 1);
557
	dret = radeon_ddc_probe(radeon_connector);
558
	radeon_i2c_do_lock(radeon_connector, 0);
1268 serge 559
	if (dret) {
560
		if (radeon_connector->edid) {
561
			kfree(radeon_connector->edid);
562
			radeon_connector->edid = NULL;
563
		}
564
		radeon_i2c_do_lock(radeon_connector, 1);
565
		radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
566
		radeon_i2c_do_lock(radeon_connector, 0);
567
 
568
		if (!radeon_connector->edid) {
1313 serge 569
			DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1268 serge 570
				  drm_get_connector_name(connector));
1313 serge 571
			ret = connector_status_connected;
1268 serge 572
		} else {
573
			radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
574
 
575
			/* some oems have boards with separate digital and analog connectors
576
			 * with a shared ddc line (often vga + hdmi)
577
			 */
578
			if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
579
				kfree(radeon_connector->edid);
580
				radeon_connector->edid = NULL;
581
				ret = connector_status_disconnected;
582
			} else
1123 serge 583
		ret = connector_status_connected;
1268 serge 584
		}
585
	} else {
1179 serge 586
		if (radeon_connector->dac_load_detect) {
1123 serge 587
			encoder_funcs = encoder->helper_private;
588
			ret = encoder_funcs->detect(encoder, connector);
589
		}
590
	}
591
 
1179 serge 592
	if (ret == connector_status_connected)
593
		ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1123 serge 594
	radeon_connector_update_scratch_regs(connector, ret);
595
	return ret;
596
}
597
 
598
struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
599
	.get_modes = radeon_vga_get_modes,
600
	.mode_valid = radeon_vga_mode_valid,
601
	.best_encoder = radeon_best_single_encoder,
602
};
603
 
604
struct drm_connector_funcs radeon_vga_connector_funcs = {
605
	.dpms = drm_helper_connector_dpms,
606
	.detect = radeon_vga_detect,
607
	.fill_modes = drm_helper_probe_single_connector_modes,
608
	.destroy = radeon_connector_destroy,
609
	.set_property = radeon_connector_set_property,
610
};
611
 
1179 serge 612
static int radeon_tv_get_modes(struct drm_connector *connector)
613
{
614
	struct drm_device *dev = connector->dev;
615
	struct radeon_device *rdev = dev->dev_private;
616
	struct drm_display_mode *tv_mode;
617
	struct drm_encoder *encoder;
618
 
619
	encoder = radeon_best_single_encoder(connector);
620
	if (!encoder)
621
		return 0;
622
 
623
	/* avivo chips can scale any mode */
624
	if (rdev->family >= CHIP_RS600)
625
		/* add scaled modes */
626
		radeon_add_common_modes(encoder, connector);
627
	else {
628
		/* only 800x600 is supported right now on pre-avivo chips */
1221 serge 629
		tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
1179 serge 630
		tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
631
		drm_mode_probed_add(connector, tv_mode);
632
	}
633
	return 1;
634
}
635
 
636
static int radeon_tv_mode_valid(struct drm_connector *connector,
637
				struct drm_display_mode *mode)
638
{
1268 serge 639
	if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
640
		return MODE_CLOCK_RANGE;
1179 serge 641
	return MODE_OK;
642
}
643
 
644
static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector)
645
{
646
	struct drm_encoder *encoder;
647
	struct drm_encoder_helper_funcs *encoder_funcs;
648
	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
649
	enum drm_connector_status ret = connector_status_disconnected;
650
 
651
	if (!radeon_connector->dac_load_detect)
652
		return ret;
653
 
654
	encoder = radeon_best_single_encoder(connector);
655
	if (!encoder)
656
		ret = connector_status_disconnected;
657
	else {
658
		encoder_funcs = encoder->helper_private;
659
		ret = encoder_funcs->detect(encoder, connector);
660
	}
661
	if (ret == connector_status_connected)
662
		ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
663
	radeon_connector_update_scratch_regs(connector, ret);
664
	return ret;
665
}
666
 
667
struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
668
	.get_modes = radeon_tv_get_modes,
669
	.mode_valid = radeon_tv_mode_valid,
670
	.best_encoder = radeon_best_single_encoder,
671
};
672
 
673
struct drm_connector_funcs radeon_tv_connector_funcs = {
674
	.dpms = drm_helper_connector_dpms,
675
	.detect = radeon_tv_detect,
676
	.fill_modes = drm_helper_probe_single_connector_modes,
677
	.destroy = radeon_connector_destroy,
678
	.set_property = radeon_connector_set_property,
679
};
680
 
1123 serge 681
static int radeon_dvi_get_modes(struct drm_connector *connector)
682
{
683
	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
684
	int ret;
685
 
686
	ret = radeon_ddc_get_modes(radeon_connector);
687
	return ret;
688
}
689
 
1179 serge 690
/*
691
 * DVI is complicated
692
 * Do a DDC probe, if DDC probe passes, get the full EDID so
693
 * we can do analog/digital monitor detection at this point.
694
 * If the monitor is an analog monitor or we got no DDC,
695
 * we need to find the DAC encoder object for this connector.
696
 * If we got no DDC, we do load detection on the DAC encoder object.
697
 * If we got analog DDC or load detection passes on the DAC encoder
698
 * we have to check if this analog encoder is shared with anyone else (TV)
699
 * if its shared we have to set the other connector to disconnected.
700
 */
1123 serge 701
static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector)
702
{
703
	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1179 serge 704
	struct drm_encoder *encoder = NULL;
1123 serge 705
	struct drm_encoder_helper_funcs *encoder_funcs;
706
	struct drm_mode_object *obj;
707
	int i;
708
	enum drm_connector_status ret = connector_status_disconnected;
709
	bool dret;
710
 
711
	radeon_i2c_do_lock(radeon_connector, 1);
712
	dret = radeon_ddc_probe(radeon_connector);
713
	radeon_i2c_do_lock(radeon_connector, 0);
1179 serge 714
	if (dret) {
1268 serge 715
		if (radeon_connector->edid) {
716
			kfree(radeon_connector->edid);
717
			radeon_connector->edid = NULL;
718
		}
1179 serge 719
		radeon_i2c_do_lock(radeon_connector, 1);
720
		radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
721
		radeon_i2c_do_lock(radeon_connector, 0);
722
 
723
		if (!radeon_connector->edid) {
1313 serge 724
			DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1179 serge 725
				  drm_get_connector_name(connector));
726
		} else {
727
			radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
728
 
1268 serge 729
			/* some oems have boards with separate digital and analog connectors
730
			 * with a shared ddc line (often vga + hdmi)
731
			 */
732
			if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
733
				kfree(radeon_connector->edid);
734
				radeon_connector->edid = NULL;
735
				ret = connector_status_disconnected;
736
			} else
1123 serge 737
		ret = connector_status_connected;
1179 serge 738
		}
739
	}
740
 
741
	if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
742
		goto out;
743
 
744
	/* find analog encoder */
745
	if (radeon_connector->dac_load_detect) {
1123 serge 746
		for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
747
			if (connector->encoder_ids[i] == 0)
748
				break;
749
 
750
			obj = drm_mode_object_find(connector->dev,
751
						   connector->encoder_ids[i],
752
						   DRM_MODE_OBJECT_ENCODER);
753
			if (!obj)
754
				continue;
755
 
756
			encoder = obj_to_encoder(obj);
757
 
758
			encoder_funcs = encoder->helper_private;
759
			if (encoder_funcs->detect) {
1179 serge 760
				if (ret != connector_status_connected) {
1123 serge 761
				ret = encoder_funcs->detect(encoder, connector);
762
				if (ret == connector_status_connected) {
1179 serge 763
						radeon_connector->use_digital = false;
764
					}
765
				}
1123 serge 766
					break;
767
				}
768
			}
769
		}
1179 serge 770
 
771
	if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
772
	    encoder) {
773
		ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1123 serge 774
	}
775
 
1179 serge 776
out:
1123 serge 777
	/* updated in get modes as well since we need to know if it's analog or digital */
778
	radeon_connector_update_scratch_regs(connector, ret);
779
	return ret;
780
}
781
 
782
/* okay need to be smart in here about which encoder to pick */
783
struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
784
{
785
	int enc_id = connector->encoder_ids[0];
786
	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
787
	struct drm_mode_object *obj;
788
	struct drm_encoder *encoder;
789
	int i;
790
	for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
791
		if (connector->encoder_ids[i] == 0)
792
			break;
793
 
794
		obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
795
		if (!obj)
796
			continue;
797
 
798
		encoder = obj_to_encoder(obj);
799
 
1179 serge 800
		if (radeon_connector->use_digital == true) {
1123 serge 801
			if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
802
				return encoder;
803
		} else {
804
			if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
805
			    encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
806
				return encoder;
807
		}
808
	}
809
 
810
	/* see if we have a default encoder  TODO */
811
 
812
	/* then check use digitial */
813
	/* pick the first one */
814
	if (enc_id) {
815
		obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
816
		if (!obj)
817
			return NULL;
818
		encoder = obj_to_encoder(obj);
819
		return encoder;
820
	}
821
	return NULL;
822
}
823
 
1221 serge 824
static void radeon_dvi_force(struct drm_connector *connector)
825
{
826
	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
827
	if (connector->force == DRM_FORCE_ON)
828
		radeon_connector->use_digital = false;
829
	if (connector->force == DRM_FORCE_ON_DIGITAL)
830
		radeon_connector->use_digital = true;
831
}
832
 
1268 serge 833
static int radeon_dvi_mode_valid(struct drm_connector *connector,
834
				  struct drm_display_mode *mode)
835
{
836
	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
837
 
838
	/* XXX check mode bandwidth */
839
 
840
	if (radeon_connector->use_digital && (mode->clock > 165000)) {
841
		if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
842
		    (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
843
		    (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
844
			return MODE_OK;
845
		else
846
			return MODE_CLOCK_HIGH;
847
	}
848
	return MODE_OK;
849
}
850
 
1123 serge 851
struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
852
	.get_modes = radeon_dvi_get_modes,
1268 serge 853
	.mode_valid = radeon_dvi_mode_valid,
1123 serge 854
	.best_encoder = radeon_dvi_encoder,
855
};
856
 
857
struct drm_connector_funcs radeon_dvi_connector_funcs = {
858
	.dpms = drm_helper_connector_dpms,
859
	.detect = radeon_dvi_detect,
860
	.fill_modes = drm_helper_probe_single_connector_modes,
861
	.set_property = radeon_connector_set_property,
862
	.destroy = radeon_connector_destroy,
1221 serge 863
	.force = radeon_dvi_force,
1123 serge 864
};
865
 
866
void
867
radeon_add_atom_connector(struct drm_device *dev,
868
			  uint32_t connector_id,
869
			  uint32_t supported_device,
870
			  int connector_type,
871
			  struct radeon_i2c_bus_rec *i2c_bus,
872
			  bool linkb,
1268 serge 873
			  uint32_t igp_lane_info,
874
			  uint16_t connector_object_id)
1123 serge 875
{
1179 serge 876
	struct radeon_device *rdev = dev->dev_private;
1123 serge 877
	struct drm_connector *connector;
878
	struct radeon_connector *radeon_connector;
879
	struct radeon_connector_atom_dig *radeon_dig_connector;
880
	uint32_t subpixel_order = SubPixelNone;
1268 serge 881
	bool shared_ddc = false;
1221 serge 882
	int ret;
1123 serge 883
 
884
	/* fixme - tv/cv/din */
1179 serge 885
	if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1123 serge 886
		return;
887
 
888
	/* see if we already added it */
889
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
890
		radeon_connector = to_radeon_connector(connector);
891
		if (radeon_connector->connector_id == connector_id) {
892
			radeon_connector->devices |= supported_device;
893
			return;
894
		}
1268 serge 895
		if (radeon_connector->ddc_bus && i2c_bus->valid) {
896
			if (memcmp(&radeon_connector->ddc_bus->rec, i2c_bus,
897
				    sizeof(struct radeon_i2c_bus_rec)) == 0) {
898
				radeon_connector->shared_ddc = true;
899
				shared_ddc = true;
900
			}
901
		}
1123 serge 902
	}
903
 
904
	radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
905
	if (!radeon_connector)
906
		return;
907
 
908
	connector = &radeon_connector->base;
909
 
910
	radeon_connector->connector_id = connector_id;
911
	radeon_connector->devices = supported_device;
1268 serge 912
	radeon_connector->shared_ddc = shared_ddc;
913
	radeon_connector->connector_object_id = connector_object_id;
1123 serge 914
	switch (connector_type) {
915
	case DRM_MODE_CONNECTOR_VGA:
916
		drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1221 serge 917
		ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
918
		if (ret)
919
			goto failed;
1123 serge 920
		if (i2c_bus->valid) {
921
			radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
922
			if (!radeon_connector->ddc_bus)
923
				goto failed;
924
		}
1221 serge 925
		radeon_connector->dac_load_detect = true;
1179 serge 926
		drm_connector_attach_property(&radeon_connector->base,
927
					      rdev->mode_info.load_detect_property,
928
					      1);
1123 serge 929
		break;
930
	case DRM_MODE_CONNECTOR_DVIA:
931
		drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1221 serge 932
		ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
933
		if (ret)
934
			goto failed;
1123 serge 935
		if (i2c_bus->valid) {
936
			radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
937
			if (!radeon_connector->ddc_bus)
938
				goto failed;
939
		}
1221 serge 940
		radeon_connector->dac_load_detect = true;
1179 serge 941
		drm_connector_attach_property(&radeon_connector->base,
942
					      rdev->mode_info.load_detect_property,
943
					      1);
1123 serge 944
		break;
945
	case DRM_MODE_CONNECTOR_DVII:
946
	case DRM_MODE_CONNECTOR_DVID:
947
		radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
948
		if (!radeon_dig_connector)
949
			goto failed;
950
		radeon_dig_connector->linkb = linkb;
951
		radeon_dig_connector->igp_lane_info = igp_lane_info;
952
		radeon_connector->con_priv = radeon_dig_connector;
953
		drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1221 serge 954
		ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
955
		if (ret)
956
			goto failed;
1123 serge 957
		if (i2c_bus->valid) {
958
			radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
959
			if (!radeon_connector->ddc_bus)
960
				goto failed;
961
		}
962
		subpixel_order = SubPixelHorizontalRGB;
1179 serge 963
		drm_connector_attach_property(&radeon_connector->base,
964
					      rdev->mode_info.coherent_mode_property,
965
					      1);
1221 serge 966
		radeon_connector->dac_load_detect = true;
1179 serge 967
		drm_connector_attach_property(&radeon_connector->base,
968
					      rdev->mode_info.load_detect_property,
969
					      1);
1123 serge 970
		break;
971
	case DRM_MODE_CONNECTOR_HDMIA:
972
	case DRM_MODE_CONNECTOR_HDMIB:
973
		radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
974
		if (!radeon_dig_connector)
975
			goto failed;
976
		radeon_dig_connector->linkb = linkb;
977
		radeon_dig_connector->igp_lane_info = igp_lane_info;
978
		radeon_connector->con_priv = radeon_dig_connector;
979
		drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1221 serge 980
		ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
981
		if (ret)
982
			goto failed;
1123 serge 983
		if (i2c_bus->valid) {
984
			radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI");
985
			if (!radeon_connector->ddc_bus)
986
				goto failed;
987
		}
1179 serge 988
		drm_connector_attach_property(&radeon_connector->base,
989
					      rdev->mode_info.coherent_mode_property,
990
					      1);
1123 serge 991
		subpixel_order = SubPixelHorizontalRGB;
992
		break;
993
	case DRM_MODE_CONNECTOR_DisplayPort:
994
		radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
995
		if (!radeon_dig_connector)
996
			goto failed;
997
		radeon_dig_connector->linkb = linkb;
998
		radeon_dig_connector->igp_lane_info = igp_lane_info;
999
		radeon_connector->con_priv = radeon_dig_connector;
1000
		drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1221 serge 1001
		ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1002
		if (ret)
1003
			goto failed;
1123 serge 1004
		if (i2c_bus->valid) {
1005
			radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
1006
			if (!radeon_connector->ddc_bus)
1007
				goto failed;
1008
		}
1009
		subpixel_order = SubPixelHorizontalRGB;
1010
		break;
1011
	case DRM_MODE_CONNECTOR_SVIDEO:
1012
	case DRM_MODE_CONNECTOR_Composite:
1013
	case DRM_MODE_CONNECTOR_9PinDIN:
1179 serge 1014
		if (radeon_tv == 1) {
1015
			drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1221 serge 1016
			ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1017
			if (ret)
1018
				goto failed;
1019
			radeon_connector->dac_load_detect = true;
1179 serge 1020
		drm_connector_attach_property(&radeon_connector->base,
1021
					      rdev->mode_info.load_detect_property,
1022
					      1);
1221 serge 1023
		}
1123 serge 1024
		break;
1025
	case DRM_MODE_CONNECTOR_LVDS:
1026
		radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1027
		if (!radeon_dig_connector)
1028
			goto failed;
1029
		radeon_dig_connector->linkb = linkb;
1030
		radeon_dig_connector->igp_lane_info = igp_lane_info;
1031
		radeon_connector->con_priv = radeon_dig_connector;
1032
		drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1221 serge 1033
		ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1034
		if (ret)
1035
			goto failed;
1123 serge 1036
		if (i2c_bus->valid) {
1037
			radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1038
			if (!radeon_connector->ddc_bus)
1039
				goto failed;
1040
		}
1179 serge 1041
		drm_mode_create_scaling_mode_property(dev);
1042
		drm_connector_attach_property(&radeon_connector->base,
1043
					      dev->mode_config.scaling_mode_property,
1044
					      DRM_MODE_SCALE_FULLSCREEN);
1123 serge 1045
		subpixel_order = SubPixelHorizontalRGB;
1046
		break;
1047
	}
1048
 
1049
	connector->display_info.subpixel_order = subpixel_order;
1233 serge 1050
	drm_sysfs_connector_add(connector);
1123 serge 1051
	return;
1052
 
1053
failed:
1054
	if (radeon_connector->ddc_bus)
1055
		radeon_i2c_destroy(radeon_connector->ddc_bus);
1056
	drm_connector_cleanup(connector);
1057
	kfree(connector);
1058
}
1059
 
1060
void
1061
radeon_add_legacy_connector(struct drm_device *dev,
1062
			    uint32_t connector_id,
1063
			    uint32_t supported_device,
1064
			    int connector_type,
1268 serge 1065
			    struct radeon_i2c_bus_rec *i2c_bus,
1066
			    uint16_t connector_object_id)
1123 serge 1067
{
1179 serge 1068
	struct radeon_device *rdev = dev->dev_private;
1123 serge 1069
	struct drm_connector *connector;
1070
	struct radeon_connector *radeon_connector;
1071
	uint32_t subpixel_order = SubPixelNone;
1221 serge 1072
	int ret;
1123 serge 1073
 
1074
	/* fixme - tv/cv/din */
1179 serge 1075
	if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1123 serge 1076
		return;
1077
 
1078
	/* see if we already added it */
1079
	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1080
		radeon_connector = to_radeon_connector(connector);
1081
		if (radeon_connector->connector_id == connector_id) {
1082
			radeon_connector->devices |= supported_device;
1083
			return;
1084
		}
1085
	}
1086
 
1087
	radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1088
	if (!radeon_connector)
1089
		return;
1090
 
1091
	connector = &radeon_connector->base;
1092
 
1093
	radeon_connector->connector_id = connector_id;
1094
	radeon_connector->devices = supported_device;
1268 serge 1095
	radeon_connector->connector_object_id = connector_object_id;
1123 serge 1096
	switch (connector_type) {
1097
	case DRM_MODE_CONNECTOR_VGA:
1098
		drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1221 serge 1099
		ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1100
		if (ret)
1101
			goto failed;
1123 serge 1102
		if (i2c_bus->valid) {
1103
			radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1104
			if (!radeon_connector->ddc_bus)
1105
				goto failed;
1106
		}
1221 serge 1107
		radeon_connector->dac_load_detect = true;
1179 serge 1108
		drm_connector_attach_property(&radeon_connector->base,
1109
					      rdev->mode_info.load_detect_property,
1110
					      1);
1123 serge 1111
		break;
1112
	case DRM_MODE_CONNECTOR_DVIA:
1113
		drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1221 serge 1114
		ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1115
		if (ret)
1116
			goto failed;
1123 serge 1117
		if (i2c_bus->valid) {
1118
			radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1119
			if (!radeon_connector->ddc_bus)
1120
				goto failed;
1121
		}
1221 serge 1122
		radeon_connector->dac_load_detect = true;
1179 serge 1123
		drm_connector_attach_property(&radeon_connector->base,
1124
					      rdev->mode_info.load_detect_property,
1125
					      1);
1123 serge 1126
		break;
1127
	case DRM_MODE_CONNECTOR_DVII:
1128
	case DRM_MODE_CONNECTOR_DVID:
1129
		drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1221 serge 1130
		ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1131
		if (ret)
1132
			goto failed;
1123 serge 1133
		if (i2c_bus->valid) {
1134
			radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1135
			if (!radeon_connector->ddc_bus)
1136
				goto failed;
1221 serge 1137
			radeon_connector->dac_load_detect = true;
1179 serge 1138
			drm_connector_attach_property(&radeon_connector->base,
1139
						      rdev->mode_info.load_detect_property,
1140
						      1);
1123 serge 1141
		}
1142
		subpixel_order = SubPixelHorizontalRGB;
1143
		break;
1144
	case DRM_MODE_CONNECTOR_SVIDEO:
1145
	case DRM_MODE_CONNECTOR_Composite:
1146
	case DRM_MODE_CONNECTOR_9PinDIN:
1179 serge 1147
		if (radeon_tv == 1) {
1148
			drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1221 serge 1149
			ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1150
			if (ret)
1151
				goto failed;
1152
			radeon_connector->dac_load_detect = true;
1313 serge 1153
			/* RS400,RC410,RS480 chipset seems to report a lot
1154
			 * of false positive on load detect, we haven't yet
1155
			 * found a way to make load detect reliable on those
1156
			 * chipset, thus just disable it for TV.
1157
			 */
1158
			if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1159
				radeon_connector->dac_load_detect = false;
1179 serge 1160
			drm_connector_attach_property(&radeon_connector->base,
1161
						      rdev->mode_info.load_detect_property,
1162
						      1);
1163
		}
1123 serge 1164
		break;
1165
	case DRM_MODE_CONNECTOR_LVDS:
1166
		drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1221 serge 1167
		ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1168
		if (ret)
1169
			goto failed;
1123 serge 1170
		if (i2c_bus->valid) {
1171
			radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1172
			if (!radeon_connector->ddc_bus)
1173
				goto failed;
1174
		}
1179 serge 1175
		drm_connector_attach_property(&radeon_connector->base,
1176
					      dev->mode_config.scaling_mode_property,
1177
					      DRM_MODE_SCALE_FULLSCREEN);
1123 serge 1178
		subpixel_order = SubPixelHorizontalRGB;
1179
		break;
1180
	}
1181
 
1182
	connector->display_info.subpixel_order = subpixel_order;
1233 serge 1183
	drm_sysfs_connector_add(connector);
1123 serge 1184
	return;
1185
 
1186
failed:
1187
	if (radeon_connector->ddc_bus)
1188
		radeon_i2c_destroy(radeon_connector->ddc_bus);
1189
	drm_connector_cleanup(connector);
1190
	kfree(connector);
1191
}