blob: 8da06e17ff27097fbc41da986e55fb0e2e13f054 [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
Alex Deucherd4877cf2009-12-04 16:56:37 -050043void radeon_connector_hotplug(struct drm_connector *connector)
44{
45 struct drm_device *dev = connector->dev;
46 struct radeon_device *rdev = dev->dev_private;
47 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
48
49 if (radeon_connector->hpd.hpd != RADEON_HPD_NONE)
50 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
51
52 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
53 if (radeon_dp_getsinktype(radeon_connector) == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
54 if (radeon_dp_needs_link_train(radeon_connector)) {
55 if (connector->encoder)
56 dp_link_train(connector->encoder, connector);
57 }
58 }
59 }
60
61}
62
Dave Airlie445282d2009-09-09 17:40:54 +100063static void radeon_property_change_mode(struct drm_encoder *encoder)
64{
65 struct drm_crtc *crtc = encoder->crtc;
66
67 if (crtc && crtc->enabled) {
68 drm_crtc_helper_set_mode(crtc, &crtc->mode,
69 crtc->x, crtc->y, crtc->fb);
70 }
71}
Jerome Glisse771fe6b2009-06-05 14:42:42 +020072static void
73radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
74{
75 struct drm_device *dev = connector->dev;
76 struct radeon_device *rdev = dev->dev_private;
77 struct drm_encoder *best_encoder = NULL;
78 struct drm_encoder *encoder = NULL;
79 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
80 struct drm_mode_object *obj;
81 bool connected;
82 int i;
83
84 best_encoder = connector_funcs->best_encoder(connector);
85
86 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
87 if (connector->encoder_ids[i] == 0)
88 break;
89
90 obj = drm_mode_object_find(connector->dev,
91 connector->encoder_ids[i],
92 DRM_MODE_OBJECT_ENCODER);
93 if (!obj)
94 continue;
95
96 encoder = obj_to_encoder(obj);
97
98 if ((encoder == best_encoder) && (status == connector_status_connected))
99 connected = true;
100 else
101 connected = false;
102
103 if (rdev->is_atom_bios)
104 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
105 else
106 radeon_combios_connected_scratch_regs(connector, encoder, connected);
107
108 }
109}
110
Dave Airlie445282d2009-09-09 17:40:54 +1000111struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
112{
113 struct drm_mode_object *obj;
114 struct drm_encoder *encoder;
115 int i;
116
117 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
118 if (connector->encoder_ids[i] == 0)
119 break;
120
121 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
122 if (!obj)
123 continue;
124
125 encoder = obj_to_encoder(obj);
126 if (encoder->encoder_type == encoder_type)
127 return encoder;
128 }
129 return NULL;
130}
131
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200132struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
133{
134 int enc_id = connector->encoder_ids[0];
135 struct drm_mode_object *obj;
136 struct drm_encoder *encoder;
137
138 /* pick the encoder ids */
139 if (enc_id) {
140 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
141 if (!obj)
142 return NULL;
143 encoder = obj_to_encoder(obj);
144 return encoder;
145 }
146 return NULL;
147}
148
Dave Airlie4ce001a2009-08-13 16:32:14 +1000149/*
150 * radeon_connector_analog_encoder_conflict_solve
151 * - search for other connectors sharing this encoder
152 * if priority is true, then set them disconnected if this is connected
153 * if priority is false, set us disconnected if they are connected
154 */
155static enum drm_connector_status
156radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
157 struct drm_encoder *encoder,
158 enum drm_connector_status current_status,
159 bool priority)
160{
161 struct drm_device *dev = connector->dev;
162 struct drm_connector *conflict;
163 int i;
164
165 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
166 if (conflict == connector)
167 continue;
168
169 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
170 if (conflict->encoder_ids[i] == 0)
171 break;
172
173 /* if the IDs match */
174 if (conflict->encoder_ids[i] == encoder->base.id) {
175 if (conflict->status != connector_status_connected)
176 continue;
177
178 if (priority == true) {
179 DRM_INFO("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
180 DRM_INFO("in favor of %s\n", drm_get_connector_name(connector));
181 conflict->status = connector_status_disconnected;
182 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
183 } else {
184 DRM_INFO("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
185 DRM_INFO("in favor of %s\n", drm_get_connector_name(conflict));
186 current_status = connector_status_disconnected;
187 }
188 break;
189 }
190 }
191 }
192 return current_status;
193
194}
195
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200196static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
197{
198 struct drm_device *dev = encoder->dev;
199 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
200 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400201 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200202
Alex Deucherde2103e2009-10-09 15:14:30 -0400203 if (native_mode->hdisplay != 0 &&
204 native_mode->vdisplay != 0 &&
205 native_mode->clock != 0) {
Alex Deucherfb06ca82009-10-12 11:25:05 -0400206 mode = drm_mode_duplicate(dev, native_mode);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200207 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
208 drm_mode_set_name(mode);
209
210 DRM_DEBUG("Adding native panel mode %s\n", mode->name);
211 }
212 return mode;
213}
214
Alex Deucher923f6842009-09-10 17:53:39 -0400215static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
216{
217 struct drm_device *dev = encoder->dev;
218 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
219 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400220 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400221 int i;
222 struct mode_size {
223 int w;
224 int h;
225 } common_modes[17] = {
226 { 640, 480},
227 { 720, 480},
228 { 800, 600},
229 { 848, 480},
230 {1024, 768},
231 {1152, 768},
232 {1280, 720},
233 {1280, 800},
234 {1280, 854},
235 {1280, 960},
236 {1280, 1024},
237 {1440, 900},
238 {1400, 1050},
239 {1680, 1050},
240 {1600, 1200},
241 {1920, 1080},
242 {1920, 1200}
243 };
244
245 for (i = 0; i < 17; i++) {
Alex Deucherdfdd6462009-10-13 12:48:44 -0400246 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
247 if (common_modes[i].w > 1024 ||
248 common_modes[i].h > 768)
249 continue;
250 }
Alex Deucher923f6842009-09-10 17:53:39 -0400251 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400252 if (common_modes[i].w > native_mode->hdisplay ||
253 common_modes[i].h > native_mode->vdisplay ||
254 (common_modes[i].w == native_mode->hdisplay &&
255 common_modes[i].h == native_mode->vdisplay))
Alex Deucher923f6842009-09-10 17:53:39 -0400256 continue;
257 }
258 if (common_modes[i].w < 320 || common_modes[i].h < 200)
259 continue;
260
Dave Airlied50ba252009-09-23 14:44:08 +1000261 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400262 drm_mode_probed_add(connector, mode);
263 }
264}
265
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200266int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
267 uint64_t val)
268{
Dave Airlie445282d2009-09-09 17:40:54 +1000269 struct drm_device *dev = connector->dev;
270 struct radeon_device *rdev = dev->dev_private;
271 struct drm_encoder *encoder;
272 struct radeon_encoder *radeon_encoder;
273
274 if (property == rdev->mode_info.coherent_mode_property) {
275 struct radeon_encoder_atom_dig *dig;
276
277 /* need to find digital encoder on connector */
278 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
279 if (!encoder)
280 return 0;
281
282 radeon_encoder = to_radeon_encoder(encoder);
283
284 if (!radeon_encoder->enc_priv)
285 return 0;
286
287 dig = radeon_encoder->enc_priv;
288 dig->coherent_mode = val ? true : false;
289 radeon_property_change_mode(&radeon_encoder->base);
290 }
291
292 if (property == rdev->mode_info.tv_std_property) {
293 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
294 if (!encoder) {
295 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
296 }
297
298 if (!encoder)
299 return 0;
300
301 radeon_encoder = to_radeon_encoder(encoder);
302 if (!radeon_encoder->enc_priv)
303 return 0;
304 if (rdev->is_atom_bios) {
305 struct radeon_encoder_atom_dac *dac_int;
306 dac_int = radeon_encoder->enc_priv;
307 dac_int->tv_std = val;
308 } else {
309 struct radeon_encoder_tv_dac *dac_int;
310 dac_int = radeon_encoder->enc_priv;
311 dac_int->tv_std = val;
312 }
313 radeon_property_change_mode(&radeon_encoder->base);
314 }
315
316 if (property == rdev->mode_info.load_detect_property) {
317 struct radeon_connector *radeon_connector =
318 to_radeon_connector(connector);
319
320 if (val == 0)
321 radeon_connector->dac_load_detect = false;
322 else
323 radeon_connector->dac_load_detect = true;
324 }
325
326 if (property == rdev->mode_info.tmds_pll_property) {
327 struct radeon_encoder_int_tmds *tmds = NULL;
328 bool ret = false;
329 /* need to find digital encoder on connector */
330 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
331 if (!encoder)
332 return 0;
333
334 radeon_encoder = to_radeon_encoder(encoder);
335
336 tmds = radeon_encoder->enc_priv;
337 if (!tmds)
338 return 0;
339
340 if (val == 0) {
341 if (rdev->is_atom_bios)
342 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
343 else
344 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
345 }
346 if (val == 1 || ret == false) {
347 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
348 }
349 radeon_property_change_mode(&radeon_encoder->base);
350 }
351
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200352 return 0;
353}
354
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200355static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
356 struct drm_connector *connector)
357{
358 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400359 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200360
361 /* Try to get native mode details from EDID if necessary */
Alex Deucherde2103e2009-10-09 15:14:30 -0400362 if (!native_mode->clock) {
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200363 struct drm_display_mode *t, *mode;
364
365 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400366 if (mode->hdisplay == native_mode->hdisplay &&
367 mode->vdisplay == native_mode->vdisplay) {
368 *native_mode = *mode;
369 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200370 DRM_INFO("Determined LVDS native mode details from EDID\n");
371 break;
372 }
373 }
374 }
Alex Deucherde2103e2009-10-09 15:14:30 -0400375 if (!native_mode->clock) {
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200376 DRM_INFO("No LVDS native mode details, disabling RMX\n");
377 radeon_encoder->rmx_type = RMX_OFF;
378 }
379}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200380
381static int radeon_lvds_get_modes(struct drm_connector *connector)
382{
383 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
384 struct drm_encoder *encoder;
385 int ret = 0;
386 struct drm_display_mode *mode;
387
388 if (radeon_connector->ddc_bus) {
389 ret = radeon_ddc_get_modes(radeon_connector);
390 if (ret > 0) {
Alex Deucher7747b712009-09-11 11:15:43 -0400391 encoder = radeon_best_single_encoder(connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200392 if (encoder) {
393 radeon_fixup_lvds_native_mode(encoder, connector);
Alex Deucher7747b712009-09-11 11:15:43 -0400394 /* add scaled modes */
395 radeon_add_common_modes(encoder, connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200396 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200397 return ret;
398 }
399 }
400
401 encoder = radeon_best_single_encoder(connector);
402 if (!encoder)
403 return 0;
404
405 /* we have no EDID modes */
406 mode = radeon_fp_native_mode(encoder);
407 if (mode) {
408 ret = 1;
409 drm_mode_probed_add(connector, mode);
Alex Deucher7747b712009-09-11 11:15:43 -0400410 /* add scaled modes */
411 radeon_add_common_modes(encoder, connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200412 }
Alex Deucher923f6842009-09-10 17:53:39 -0400413
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200414 return ret;
415}
416
417static int radeon_lvds_mode_valid(struct drm_connector *connector,
418 struct drm_display_mode *mode)
419{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500420 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
421
422 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
423 return MODE_PANEL;
424
425 if (encoder) {
426 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
427 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
428
429 /* AVIVO hardware supports downscaling modes larger than the panel
430 * to the panel size, but I'm not sure this is desirable.
431 */
432 if ((mode->hdisplay > native_mode->hdisplay) ||
433 (mode->vdisplay > native_mode->vdisplay))
434 return MODE_PANEL;
435
436 /* if scaling is disabled, block non-native modes */
437 if (radeon_encoder->rmx_type == RMX_OFF) {
438 if ((mode->hdisplay != native_mode->hdisplay) ||
439 (mode->vdisplay != native_mode->vdisplay))
440 return MODE_PANEL;
441 }
442 }
443
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200444 return MODE_OK;
445}
446
447static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connector)
448{
Alex Deucher0549a0612009-10-09 18:41:19 -0400449 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher2ffb8422009-10-08 13:02:19 -0400450 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Alex Deucher0549a0612009-10-09 18:41:19 -0400451 enum drm_connector_status ret = connector_status_disconnected;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400452
453 if (encoder) {
454 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400455 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400456
457 /* check if panel is valid */
Alex Deucherde2103e2009-10-09 15:14:30 -0400458 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
Alex Deucher2ffb8422009-10-08 13:02:19 -0400459 ret = connector_status_connected;
460
461 }
Alex Deucher0549a0612009-10-09 18:41:19 -0400462
463 /* check for edid as well */
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400464 if (radeon_connector->edid)
465 ret = connector_status_connected;
466 else {
467 if (radeon_connector->ddc_bus) {
Alex Deucherab1e9ea2009-11-05 18:27:30 -0500468 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400469 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
470 &radeon_connector->ddc_bus->adapter);
Alex Deucherab1e9ea2009-11-05 18:27:30 -0500471 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400472 if (radeon_connector->edid)
473 ret = connector_status_connected;
474 }
Alex Deucher0549a0612009-10-09 18:41:19 -0400475 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200476 /* check acpi lid status ??? */
Alex Deucher2ffb8422009-10-08 13:02:19 -0400477
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200478 radeon_connector_update_scratch_regs(connector, ret);
479 return ret;
480}
481
482static void radeon_connector_destroy(struct drm_connector *connector)
483{
484 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
485
486 if (radeon_connector->ddc_bus)
487 radeon_i2c_destroy(radeon_connector->ddc_bus);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400488 if (radeon_connector->edid)
489 kfree(radeon_connector->edid);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200490 kfree(radeon_connector->con_priv);
491 drm_sysfs_connector_remove(connector);
492 drm_connector_cleanup(connector);
493 kfree(connector);
494}
495
Dave Airlie445282d2009-09-09 17:40:54 +1000496static int radeon_lvds_set_property(struct drm_connector *connector,
497 struct drm_property *property,
498 uint64_t value)
499{
500 struct drm_device *dev = connector->dev;
501 struct radeon_encoder *radeon_encoder;
502 enum radeon_rmx_type rmx_type;
503
504 DRM_DEBUG("\n");
505 if (property != dev->mode_config.scaling_mode_property)
506 return 0;
507
508 if (connector->encoder)
509 radeon_encoder = to_radeon_encoder(connector->encoder);
510 else {
511 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
512 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
513 }
514
515 switch (value) {
516 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
517 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
518 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
519 default:
520 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
521 }
522 if (radeon_encoder->rmx_type == rmx_type)
523 return 0;
524
525 radeon_encoder->rmx_type = rmx_type;
526
527 radeon_property_change_mode(&radeon_encoder->base);
528 return 0;
529}
530
531
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200532struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
533 .get_modes = radeon_lvds_get_modes,
534 .mode_valid = radeon_lvds_mode_valid,
535 .best_encoder = radeon_best_single_encoder,
536};
537
538struct drm_connector_funcs radeon_lvds_connector_funcs = {
539 .dpms = drm_helper_connector_dpms,
540 .detect = radeon_lvds_detect,
541 .fill_modes = drm_helper_probe_single_connector_modes,
542 .destroy = radeon_connector_destroy,
Dave Airlie445282d2009-09-09 17:40:54 +1000543 .set_property = radeon_lvds_set_property,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200544};
545
546static int radeon_vga_get_modes(struct drm_connector *connector)
547{
548 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
549 int ret;
550
551 ret = radeon_ddc_get_modes(radeon_connector);
552
553 return ret;
554}
555
556static int radeon_vga_mode_valid(struct drm_connector *connector,
557 struct drm_display_mode *mode)
558{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500559 /* XXX check mode bandwidth */
560 /* XXX verify against max DAC output frequency */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200561 return MODE_OK;
562}
563
564static enum drm_connector_status radeon_vga_detect(struct drm_connector *connector)
565{
566 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
567 struct drm_encoder *encoder;
568 struct drm_encoder_helper_funcs *encoder_funcs;
569 bool dret;
570 enum drm_connector_status ret = connector_status_disconnected;
571
Dave Airlie4ce001a2009-08-13 16:32:14 +1000572 encoder = radeon_best_single_encoder(connector);
573 if (!encoder)
574 ret = connector_status_disconnected;
575
Alex Deucherab1e9ea2009-11-05 18:27:30 -0500576 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200577 dret = radeon_ddc_probe(radeon_connector);
Alex Deucherab1e9ea2009-11-05 18:27:30 -0500578 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400579 if (dret) {
580 if (radeon_connector->edid) {
581 kfree(radeon_connector->edid);
582 radeon_connector->edid = NULL;
583 }
Alex Deucherab1e9ea2009-11-05 18:27:30 -0500584 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400585 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
Alex Deucherab1e9ea2009-11-05 18:27:30 -0500586 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400587
588 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +0100589 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
590 drm_get_connector_name(connector));
591 ret = connector_status_connected;
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400592 } else {
593 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
594
595 /* some oems have boards with separate digital and analog connectors
596 * with a shared ddc line (often vga + hdmi)
597 */
598 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
599 kfree(radeon_connector->edid);
600 radeon_connector->edid = NULL;
601 ret = connector_status_disconnected;
602 } else
603 ret = connector_status_connected;
604 }
605 } else {
Dave Airlie445282d2009-09-09 17:40:54 +1000606 if (radeon_connector->dac_load_detect) {
607 encoder_funcs = encoder->helper_private;
608 ret = encoder_funcs->detect(encoder, connector);
609 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200610 }
611
Dave Airlie4ce001a2009-08-13 16:32:14 +1000612 if (ret == connector_status_connected)
613 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200614 radeon_connector_update_scratch_regs(connector, ret);
615 return ret;
616}
617
618struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
619 .get_modes = radeon_vga_get_modes,
620 .mode_valid = radeon_vga_mode_valid,
621 .best_encoder = radeon_best_single_encoder,
622};
623
624struct drm_connector_funcs radeon_vga_connector_funcs = {
625 .dpms = drm_helper_connector_dpms,
626 .detect = radeon_vga_detect,
627 .fill_modes = drm_helper_probe_single_connector_modes,
628 .destroy = radeon_connector_destroy,
629 .set_property = radeon_connector_set_property,
630};
631
Dave Airlie4ce001a2009-08-13 16:32:14 +1000632static int radeon_tv_get_modes(struct drm_connector *connector)
633{
634 struct drm_device *dev = connector->dev;
Alex Deucher923f6842009-09-10 17:53:39 -0400635 struct radeon_device *rdev = dev->dev_private;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000636 struct drm_display_mode *tv_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400637 struct drm_encoder *encoder;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000638
Alex Deucher923f6842009-09-10 17:53:39 -0400639 encoder = radeon_best_single_encoder(connector);
640 if (!encoder)
641 return 0;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000642
Alex Deucher923f6842009-09-10 17:53:39 -0400643 /* avivo chips can scale any mode */
644 if (rdev->family >= CHIP_RS600)
645 /* add scaled modes */
646 radeon_add_common_modes(encoder, connector);
647 else {
648 /* only 800x600 is supported right now on pre-avivo chips */
Dave Airlied50ba252009-09-23 14:44:08 +1000649 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400650 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
651 drm_mode_probed_add(connector, tv_mode);
652 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000653 return 1;
654}
655
656static int radeon_tv_mode_valid(struct drm_connector *connector,
657 struct drm_display_mode *mode)
658{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500659 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
660 return MODE_CLOCK_RANGE;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000661 return MODE_OK;
662}
663
664static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector)
665{
666 struct drm_encoder *encoder;
667 struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie445282d2009-09-09 17:40:54 +1000668 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
669 enum drm_connector_status ret = connector_status_disconnected;
670
671 if (!radeon_connector->dac_load_detect)
672 return ret;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000673
674 encoder = radeon_best_single_encoder(connector);
675 if (!encoder)
676 ret = connector_status_disconnected;
677 else {
678 encoder_funcs = encoder->helper_private;
679 ret = encoder_funcs->detect(encoder, connector);
680 }
681 if (ret == connector_status_connected)
682 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
683 radeon_connector_update_scratch_regs(connector, ret);
684 return ret;
685}
686
687struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
688 .get_modes = radeon_tv_get_modes,
689 .mode_valid = radeon_tv_mode_valid,
690 .best_encoder = radeon_best_single_encoder,
691};
692
693struct drm_connector_funcs radeon_tv_connector_funcs = {
694 .dpms = drm_helper_connector_dpms,
695 .detect = radeon_tv_detect,
696 .fill_modes = drm_helper_probe_single_connector_modes,
697 .destroy = radeon_connector_destroy,
698 .set_property = radeon_connector_set_property,
699};
700
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200701static int radeon_dvi_get_modes(struct drm_connector *connector)
702{
703 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
704 int ret;
705
706 ret = radeon_ddc_get_modes(radeon_connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200707 return ret;
708}
709
Dave Airlie4ce001a2009-08-13 16:32:14 +1000710/*
711 * DVI is complicated
712 * Do a DDC probe, if DDC probe passes, get the full EDID so
713 * we can do analog/digital monitor detection at this point.
714 * If the monitor is an analog monitor or we got no DDC,
715 * we need to find the DAC encoder object for this connector.
716 * If we got no DDC, we do load detection on the DAC encoder object.
717 * If we got analog DDC or load detection passes on the DAC encoder
718 * we have to check if this analog encoder is shared with anyone else (TV)
719 * if its shared we have to set the other connector to disconnected.
720 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200721static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector)
722{
723 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000724 struct drm_encoder *encoder = NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200725 struct drm_encoder_helper_funcs *encoder_funcs;
726 struct drm_mode_object *obj;
727 int i;
728 enum drm_connector_status ret = connector_status_disconnected;
729 bool dret;
730
Alex Deucherab1e9ea2009-11-05 18:27:30 -0500731 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200732 dret = radeon_ddc_probe(radeon_connector);
Alex Deucherab1e9ea2009-11-05 18:27:30 -0500733 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000734 if (dret) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400735 if (radeon_connector->edid) {
736 kfree(radeon_connector->edid);
737 radeon_connector->edid = NULL;
738 }
Alex Deucherab1e9ea2009-11-05 18:27:30 -0500739 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000740 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
Alex Deucherab1e9ea2009-11-05 18:27:30 -0500741 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200742
Dave Airlie4ce001a2009-08-13 16:32:14 +1000743 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +0100744 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
745 drm_get_connector_name(connector));
Dave Airlie4ce001a2009-08-13 16:32:14 +1000746 } else {
747 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200748
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400749 /* some oems have boards with separate digital and analog connectors
750 * with a shared ddc line (often vga + hdmi)
751 */
752 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
753 kfree(radeon_connector->edid);
754 radeon_connector->edid = NULL;
755 ret = connector_status_disconnected;
756 } else
757 ret = connector_status_connected;
Alex Deucher71407c42009-11-17 15:44:01 -0500758
759 /* multiple connectors on the same encoder with the same ddc line
760 * This tends to be HDMI and DVI on the same encoder with the
761 * same ddc line. If the edid says HDMI, consider the HDMI port
762 * connected and the DVI port disconnected. If the edid doesn't
763 * say HDMI, vice versa.
764 */
765 if (radeon_connector->shared_ddc && connector_status_connected) {
766 struct drm_device *dev = connector->dev;
767 struct drm_connector *list_connector;
768 struct radeon_connector *list_radeon_connector;
769 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
770 if (connector == list_connector)
771 continue;
772 list_radeon_connector = to_radeon_connector(list_connector);
773 if (radeon_connector->devices == list_radeon_connector->devices) {
774 if (drm_detect_hdmi_monitor(radeon_connector->edid)) {
775 if (connector->connector_type == DRM_MODE_CONNECTOR_DVID) {
776 kfree(radeon_connector->edid);
777 radeon_connector->edid = NULL;
778 ret = connector_status_disconnected;
779 }
780 } else {
781 if ((connector->connector_type == DRM_MODE_CONNECTOR_HDMIA) ||
782 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIB)) {
783 kfree(radeon_connector->edid);
784 radeon_connector->edid = NULL;
785 ret = connector_status_disconnected;
786 }
787 }
788 }
789 }
790 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200791 }
792 }
793
Dave Airlie4ce001a2009-08-13 16:32:14 +1000794 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
795 goto out;
796
797 /* find analog encoder */
Dave Airlie445282d2009-09-09 17:40:54 +1000798 if (radeon_connector->dac_load_detect) {
799 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
800 if (connector->encoder_ids[i] == 0)
801 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000802
Dave Airlie445282d2009-09-09 17:40:54 +1000803 obj = drm_mode_object_find(connector->dev,
804 connector->encoder_ids[i],
805 DRM_MODE_OBJECT_ENCODER);
806 if (!obj)
807 continue;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000808
Dave Airlie445282d2009-09-09 17:40:54 +1000809 encoder = obj_to_encoder(obj);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000810
Dave Airlie445282d2009-09-09 17:40:54 +1000811 encoder_funcs = encoder->helper_private;
812 if (encoder_funcs->detect) {
813 if (ret != connector_status_connected) {
814 ret = encoder_funcs->detect(encoder, connector);
815 if (ret == connector_status_connected) {
816 radeon_connector->use_digital = false;
817 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000818 }
Dave Airlie445282d2009-09-09 17:40:54 +1000819 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000820 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000821 }
822 }
823
824 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
825 encoder) {
826 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
827 }
828
829out:
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200830 /* updated in get modes as well since we need to know if it's analog or digital */
831 radeon_connector_update_scratch_regs(connector, ret);
832 return ret;
833}
834
835/* okay need to be smart in here about which encoder to pick */
836struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
837{
838 int enc_id = connector->encoder_ids[0];
839 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
840 struct drm_mode_object *obj;
841 struct drm_encoder *encoder;
842 int i;
843 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
844 if (connector->encoder_ids[i] == 0)
845 break;
846
847 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
848 if (!obj)
849 continue;
850
851 encoder = obj_to_encoder(obj);
852
Dave Airlie4ce001a2009-08-13 16:32:14 +1000853 if (radeon_connector->use_digital == true) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200854 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
855 return encoder;
856 } else {
857 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
858 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
859 return encoder;
860 }
861 }
862
863 /* see if we have a default encoder TODO */
864
865 /* then check use digitial */
866 /* pick the first one */
867 if (enc_id) {
868 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
869 if (!obj)
870 return NULL;
871 encoder = obj_to_encoder(obj);
872 return encoder;
873 }
874 return NULL;
875}
876
Dave Airlied50ba252009-09-23 14:44:08 +1000877static void radeon_dvi_force(struct drm_connector *connector)
878{
879 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
880 if (connector->force == DRM_FORCE_ON)
881 radeon_connector->use_digital = false;
882 if (connector->force == DRM_FORCE_ON_DIGITAL)
883 radeon_connector->use_digital = true;
884}
885
Alex Deuchera3fa6322009-11-05 11:57:07 -0500886static int radeon_dvi_mode_valid(struct drm_connector *connector,
887 struct drm_display_mode *mode)
888{
889 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
890
891 /* XXX check mode bandwidth */
892
893 if (radeon_connector->use_digital && (mode->clock > 165000)) {
894 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
895 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
896 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
897 return MODE_OK;
898 else
899 return MODE_CLOCK_HIGH;
900 }
901 return MODE_OK;
902}
903
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200904struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
905 .get_modes = radeon_dvi_get_modes,
Alex Deuchera3fa6322009-11-05 11:57:07 -0500906 .mode_valid = radeon_dvi_mode_valid,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200907 .best_encoder = radeon_dvi_encoder,
908};
909
910struct drm_connector_funcs radeon_dvi_connector_funcs = {
911 .dpms = drm_helper_connector_dpms,
912 .detect = radeon_dvi_detect,
913 .fill_modes = drm_helper_probe_single_connector_modes,
914 .set_property = radeon_connector_set_property,
915 .destroy = radeon_connector_destroy,
Dave Airlied50ba252009-09-23 14:44:08 +1000916 .force = radeon_dvi_force,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200917};
918
Alex Deucherffd09c62009-11-24 16:13:23 -0500919static void radeon_dp_connector_destroy(struct drm_connector *connector)
920{
921 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
922 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
923
924 if (radeon_connector->ddc_bus)
925 radeon_i2c_destroy(radeon_connector->ddc_bus);
926 if (radeon_connector->edid)
927 kfree(radeon_connector->edid);
928 if (radeon_dig_connector->dp_i2c_bus)
929 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
930 kfree(radeon_connector->con_priv);
931 drm_sysfs_connector_remove(connector);
932 drm_connector_cleanup(connector);
933 kfree(connector);
934}
935
Dave Airlie746c1aa2009-12-08 07:07:28 +1000936static int radeon_dp_get_modes(struct drm_connector *connector)
937{
938 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
939 int ret;
940
941 ret = radeon_ddc_get_modes(radeon_connector);
942 return ret;
943}
944
945static enum drm_connector_status radeon_dp_detect(struct drm_connector *connector)
946{
947 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +1000948 enum drm_connector_status ret = connector_status_disconnected;
Alex Deucher4143e912009-11-23 18:02:35 -0500949 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
950 u8 sink_type;
Dave Airlie746c1aa2009-12-08 07:07:28 +1000951
952 if (radeon_connector->edid) {
953 kfree(radeon_connector->edid);
954 radeon_connector->edid = NULL;
955 }
956
957 sink_type = radeon_dp_getsinktype(radeon_connector);
958 if (sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
Alex Deucher9fa05c92009-11-27 13:01:46 -0500959 if (radeon_dp_getdpcd(radeon_connector)) {
960 radeon_dig_connector->dp_sink_type = sink_type;
961 ret = connector_status_connected;
962 }
Alex Deucher4143e912009-11-23 18:02:35 -0500963 } else {
964 radeon_i2c_do_lock(radeon_connector->ddc_bus, 1);
965 if (radeon_ddc_probe(radeon_connector)) {
966 radeon_dig_connector->dp_sink_type = sink_type;
967 ret = connector_status_connected;
968 }
969 radeon_i2c_do_lock(radeon_connector->ddc_bus, 0);
Dave Airlie746c1aa2009-12-08 07:07:28 +1000970 }
Alex Deucher4143e912009-11-23 18:02:35 -0500971
Dave Airlie746c1aa2009-12-08 07:07:28 +1000972 return ret;
973}
974
Alex Deucher5801ead2009-11-24 13:32:59 -0500975static int radeon_dp_mode_valid(struct drm_connector *connector,
976 struct drm_display_mode *mode)
977{
978 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
979 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
980
981 /* XXX check mode bandwidth */
982
983 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
984 return radeon_dp_mode_valid_helper(radeon_connector, mode);
985 else
986 return MODE_OK;
987}
988
Dave Airlie746c1aa2009-12-08 07:07:28 +1000989struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
990 .get_modes = radeon_dp_get_modes,
Alex Deucher5801ead2009-11-24 13:32:59 -0500991 .mode_valid = radeon_dp_mode_valid,
Dave Airlie746c1aa2009-12-08 07:07:28 +1000992 .best_encoder = radeon_dvi_encoder,
993};
994
995struct drm_connector_funcs radeon_dp_connector_funcs = {
996 .dpms = drm_helper_connector_dpms,
997 .detect = radeon_dp_detect,
998 .fill_modes = drm_helper_probe_single_connector_modes,
999 .set_property = radeon_connector_set_property,
Alex Deucherffd09c62009-11-24 16:13:23 -05001000 .destroy = radeon_dp_connector_destroy,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001001 .force = radeon_dvi_force,
1002};
1003
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001004void
1005radeon_add_atom_connector(struct drm_device *dev,
1006 uint32_t connector_id,
1007 uint32_t supported_device,
1008 int connector_type,
1009 struct radeon_i2c_bus_rec *i2c_bus,
1010 bool linkb,
Alex Deucherb75fad02009-11-05 13:16:01 -05001011 uint32_t igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -05001012 uint16_t connector_object_id,
1013 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001014{
Dave Airlie445282d2009-09-09 17:40:54 +10001015 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001016 struct drm_connector *connector;
1017 struct radeon_connector *radeon_connector;
1018 struct radeon_connector_atom_dig *radeon_dig_connector;
1019 uint32_t subpixel_order = SubPixelNone;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001020 bool shared_ddc = false;
Dave Airlied50ba252009-09-23 14:44:08 +10001021 int ret;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001022
1023 /* fixme - tv/cv/din */
Dave Airlie4ce001a2009-08-13 16:32:14 +10001024 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001025 return;
1026
1027 /* see if we already added it */
1028 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1029 radeon_connector = to_radeon_connector(connector);
1030 if (radeon_connector->connector_id == connector_id) {
1031 radeon_connector->devices |= supported_device;
1032 return;
1033 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001034 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1035 if (memcmp(&radeon_connector->ddc_bus->rec, i2c_bus,
1036 sizeof(struct radeon_i2c_bus_rec)) == 0) {
1037 radeon_connector->shared_ddc = true;
1038 shared_ddc = true;
1039 }
1040 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001041 }
1042
1043 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1044 if (!radeon_connector)
1045 return;
1046
1047 connector = &radeon_connector->base;
1048
1049 radeon_connector->connector_id = connector_id;
1050 radeon_connector->devices = supported_device;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001051 radeon_connector->shared_ddc = shared_ddc;
Alex Deucherb75fad02009-11-05 13:16:01 -05001052 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05001053 radeon_connector->hpd = *hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001054 switch (connector_type) {
1055 case DRM_MODE_CONNECTOR_VGA:
1056 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001057 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1058 if (ret)
1059 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001060 if (i2c_bus->valid) {
1061 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1062 if (!radeon_connector->ddc_bus)
1063 goto failed;
1064 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001065 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001066 drm_connector_attach_property(&radeon_connector->base,
1067 rdev->mode_info.load_detect_property,
1068 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001069 break;
1070 case DRM_MODE_CONNECTOR_DVIA:
1071 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001072 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1073 if (ret)
1074 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001075 if (i2c_bus->valid) {
1076 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1077 if (!radeon_connector->ddc_bus)
1078 goto failed;
1079 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001080 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001081 drm_connector_attach_property(&radeon_connector->base,
1082 rdev->mode_info.load_detect_property,
1083 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001084 break;
1085 case DRM_MODE_CONNECTOR_DVII:
1086 case DRM_MODE_CONNECTOR_DVID:
1087 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1088 if (!radeon_dig_connector)
1089 goto failed;
1090 radeon_dig_connector->linkb = linkb;
1091 radeon_dig_connector->igp_lane_info = igp_lane_info;
1092 radeon_connector->con_priv = radeon_dig_connector;
1093 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001094 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1095 if (ret)
1096 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001097 if (i2c_bus->valid) {
1098 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1099 if (!radeon_connector->ddc_bus)
1100 goto failed;
1101 }
1102 subpixel_order = SubPixelHorizontalRGB;
Dave Airlie445282d2009-09-09 17:40:54 +10001103 drm_connector_attach_property(&radeon_connector->base,
1104 rdev->mode_info.coherent_mode_property,
1105 1);
Alex Deucher390d0bb2009-12-08 12:48:20 -05001106 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1107 radeon_connector->dac_load_detect = true;
1108 drm_connector_attach_property(&radeon_connector->base,
1109 rdev->mode_info.load_detect_property,
1110 1);
1111 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001112 break;
1113 case DRM_MODE_CONNECTOR_HDMIA:
1114 case DRM_MODE_CONNECTOR_HDMIB:
1115 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1116 if (!radeon_dig_connector)
1117 goto failed;
1118 radeon_dig_connector->linkb = linkb;
1119 radeon_dig_connector->igp_lane_info = igp_lane_info;
1120 radeon_connector->con_priv = radeon_dig_connector;
1121 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001122 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1123 if (ret)
1124 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001125 if (i2c_bus->valid) {
1126 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI");
1127 if (!radeon_connector->ddc_bus)
1128 goto failed;
1129 }
Dave Airlie445282d2009-09-09 17:40:54 +10001130 drm_connector_attach_property(&radeon_connector->base,
1131 rdev->mode_info.coherent_mode_property,
1132 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001133 subpixel_order = SubPixelHorizontalRGB;
1134 break;
1135 case DRM_MODE_CONNECTOR_DisplayPort:
1136 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1137 if (!radeon_dig_connector)
1138 goto failed;
1139 radeon_dig_connector->linkb = linkb;
1140 radeon_dig_connector->igp_lane_info = igp_lane_info;
1141 radeon_connector->con_priv = radeon_dig_connector;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001142 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1143 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001144 if (ret)
1145 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001146 if (i2c_bus->valid) {
Alex Deucher390d0bb2009-12-08 12:48:20 -05001147 /* add DP i2c bus */
1148 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1149 if (!radeon_dig_connector->dp_i2c_bus)
1150 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001151 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
1152 if (!radeon_connector->ddc_bus)
1153 goto failed;
1154 }
1155 subpixel_order = SubPixelHorizontalRGB;
Alex Deucher390d0bb2009-12-08 12:48:20 -05001156 drm_connector_attach_property(&radeon_connector->base,
1157 rdev->mode_info.coherent_mode_property,
1158 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001159 break;
1160 case DRM_MODE_CONNECTOR_SVIDEO:
1161 case DRM_MODE_CONNECTOR_Composite:
1162 case DRM_MODE_CONNECTOR_9PinDIN:
Dave Airlie4ce001a2009-08-13 16:32:14 +10001163 if (radeon_tv == 1) {
1164 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001165 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1166 if (ret)
1167 goto failed;
1168 radeon_connector->dac_load_detect = true;
1169 drm_connector_attach_property(&radeon_connector->base,
1170 rdev->mode_info.load_detect_property,
1171 1);
Alex Deuchered160142009-12-01 14:12:14 -05001172 drm_connector_attach_property(&radeon_connector->base,
1173 rdev->mode_info.tv_std_property,
Alex Deucherd79766f2009-12-17 19:00:29 -05001174 radeon_atombios_get_tv_info(rdev));
Dave Airlie4ce001a2009-08-13 16:32:14 +10001175 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001176 break;
1177 case DRM_MODE_CONNECTOR_LVDS:
1178 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1179 if (!radeon_dig_connector)
1180 goto failed;
1181 radeon_dig_connector->linkb = linkb;
1182 radeon_dig_connector->igp_lane_info = igp_lane_info;
1183 radeon_connector->con_priv = radeon_dig_connector;
1184 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001185 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1186 if (ret)
1187 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001188 if (i2c_bus->valid) {
1189 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1190 if (!radeon_connector->ddc_bus)
1191 goto failed;
1192 }
Dave Airlie445282d2009-09-09 17:40:54 +10001193 drm_connector_attach_property(&radeon_connector->base,
1194 dev->mode_config.scaling_mode_property,
1195 DRM_MODE_SCALE_FULLSCREEN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001196 subpixel_order = SubPixelHorizontalRGB;
1197 break;
1198 }
1199
1200 connector->display_info.subpixel_order = subpixel_order;
1201 drm_sysfs_connector_add(connector);
1202 return;
1203
1204failed:
1205 if (radeon_connector->ddc_bus)
1206 radeon_i2c_destroy(radeon_connector->ddc_bus);
1207 drm_connector_cleanup(connector);
1208 kfree(connector);
1209}
1210
1211void
1212radeon_add_legacy_connector(struct drm_device *dev,
1213 uint32_t connector_id,
1214 uint32_t supported_device,
1215 int connector_type,
Alex Deucherb75fad02009-11-05 13:16:01 -05001216 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -05001217 uint16_t connector_object_id,
1218 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001219{
Dave Airlie445282d2009-09-09 17:40:54 +10001220 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001221 struct drm_connector *connector;
1222 struct radeon_connector *radeon_connector;
1223 uint32_t subpixel_order = SubPixelNone;
Dave Airlied50ba252009-09-23 14:44:08 +10001224 int ret;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001225
1226 /* fixme - tv/cv/din */
Dave Airlie4ce001a2009-08-13 16:32:14 +10001227 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001228 return;
1229
1230 /* see if we already added it */
1231 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1232 radeon_connector = to_radeon_connector(connector);
1233 if (radeon_connector->connector_id == connector_id) {
1234 radeon_connector->devices |= supported_device;
1235 return;
1236 }
1237 }
1238
1239 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1240 if (!radeon_connector)
1241 return;
1242
1243 connector = &radeon_connector->base;
1244
1245 radeon_connector->connector_id = connector_id;
1246 radeon_connector->devices = supported_device;
Alex Deucherb75fad02009-11-05 13:16:01 -05001247 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05001248 radeon_connector->hpd = *hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001249 switch (connector_type) {
1250 case DRM_MODE_CONNECTOR_VGA:
1251 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001252 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1253 if (ret)
1254 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001255 if (i2c_bus->valid) {
1256 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1257 if (!radeon_connector->ddc_bus)
1258 goto failed;
1259 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001260 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001261 drm_connector_attach_property(&radeon_connector->base,
1262 rdev->mode_info.load_detect_property,
1263 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001264 break;
1265 case DRM_MODE_CONNECTOR_DVIA:
1266 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001267 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1268 if (ret)
1269 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001270 if (i2c_bus->valid) {
1271 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1272 if (!radeon_connector->ddc_bus)
1273 goto failed;
1274 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001275 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001276 drm_connector_attach_property(&radeon_connector->base,
1277 rdev->mode_info.load_detect_property,
1278 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001279 break;
1280 case DRM_MODE_CONNECTOR_DVII:
1281 case DRM_MODE_CONNECTOR_DVID:
1282 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001283 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1284 if (ret)
1285 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001286 if (i2c_bus->valid) {
1287 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1288 if (!radeon_connector->ddc_bus)
1289 goto failed;
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001290 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001291 drm_connector_attach_property(&radeon_connector->base,
1292 rdev->mode_info.load_detect_property,
1293 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001294 }
1295 subpixel_order = SubPixelHorizontalRGB;
1296 break;
1297 case DRM_MODE_CONNECTOR_SVIDEO:
1298 case DRM_MODE_CONNECTOR_Composite:
1299 case DRM_MODE_CONNECTOR_9PinDIN:
Dave Airlie4ce001a2009-08-13 16:32:14 +10001300 if (radeon_tv == 1) {
1301 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001302 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1303 if (ret)
1304 goto failed;
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001305 radeon_connector->dac_load_detect = true;
Jerome Glisse0beb81a2009-11-13 20:56:35 +01001306 /* RS400,RC410,RS480 chipset seems to report a lot
1307 * of false positive on load detect, we haven't yet
1308 * found a way to make load detect reliable on those
1309 * chipset, thus just disable it for TV.
1310 */
1311 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1312 radeon_connector->dac_load_detect = false;
Dave Airlie445282d2009-09-09 17:40:54 +10001313 drm_connector_attach_property(&radeon_connector->base,
1314 rdev->mode_info.load_detect_property,
1315 1);
Alex Deuchered160142009-12-01 14:12:14 -05001316 drm_connector_attach_property(&radeon_connector->base,
1317 rdev->mode_info.tv_std_property,
Alex Deucherd79766f2009-12-17 19:00:29 -05001318 radeon_combios_get_tv_info(rdev));
Dave Airlie4ce001a2009-08-13 16:32:14 +10001319 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001320 break;
1321 case DRM_MODE_CONNECTOR_LVDS:
1322 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001323 ret = drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1324 if (ret)
1325 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001326 if (i2c_bus->valid) {
1327 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1328 if (!radeon_connector->ddc_bus)
1329 goto failed;
1330 }
Dave Airlie445282d2009-09-09 17:40:54 +10001331 drm_connector_attach_property(&radeon_connector->base,
1332 dev->mode_config.scaling_mode_property,
1333 DRM_MODE_SCALE_FULLSCREEN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001334 subpixel_order = SubPixelHorizontalRGB;
1335 break;
1336 }
1337
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001338 connector->display_info.subpixel_order = subpixel_order;
1339 drm_sysfs_connector_add(connector);
1340 return;
1341
1342failed:
1343 if (radeon_connector->ddc_bus)
1344 radeon_i2c_destroy(radeon_connector->ddc_bus);
1345 drm_connector_cleanup(connector);
1346 kfree(connector);
1347}