blob: ee1dccb3fec9792e721c17aae9b0eb81d832c396 [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
Michel Dänzer63ec0112011-03-22 16:30:23 -070043extern void
44radeon_legacy_backlight_init(struct radeon_encoder *radeon_encoder,
45 struct drm_connector *drm_connector);
46
Alex Deucherd4877cf2009-12-04 16:56:37 -050047void radeon_connector_hotplug(struct drm_connector *connector)
48{
49 struct drm_device *dev = connector->dev;
50 struct radeon_device *rdev = dev->dev_private;
51 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
52
Alex Deucher1e85e1d2011-05-20 04:34:29 -040053 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
Alex Deucherd4877cf2009-12-04 16:56:37 -050054
Alex Deucher7c3ed0f2011-05-20 04:34:30 -040055 /* powering up/down the eDP panel generates hpd events which
56 * can interfere with modesetting.
57 */
58 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
59 return;
60
Alex Deucher1e85e1d2011-05-20 04:34:29 -040061 /* pre-r600 did not always have the hpd pins mapped accurately to connectors */
62 if (rdev->family >= CHIP_R600) {
63 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
64 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
65 else
66 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
Alex Deucherd4877cf2009-12-04 16:56:37 -050067 }
Alex Deucherd4877cf2009-12-04 16:56:37 -050068}
69
Dave Airlie445282d2009-09-09 17:40:54 +100070static void radeon_property_change_mode(struct drm_encoder *encoder)
71{
72 struct drm_crtc *crtc = encoder->crtc;
73
74 if (crtc && crtc->enabled) {
75 drm_crtc_helper_set_mode(crtc, &crtc->mode,
76 crtc->x, crtc->y, crtc->fb);
77 }
78}
Jerome Glisse771fe6b2009-06-05 14:42:42 +020079static void
80radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
81{
82 struct drm_device *dev = connector->dev;
83 struct radeon_device *rdev = dev->dev_private;
84 struct drm_encoder *best_encoder = NULL;
85 struct drm_encoder *encoder = NULL;
86 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
87 struct drm_mode_object *obj;
88 bool connected;
89 int i;
90
91 best_encoder = connector_funcs->best_encoder(connector);
92
93 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
94 if (connector->encoder_ids[i] == 0)
95 break;
96
97 obj = drm_mode_object_find(connector->dev,
98 connector->encoder_ids[i],
99 DRM_MODE_OBJECT_ENCODER);
100 if (!obj)
101 continue;
102
103 encoder = obj_to_encoder(obj);
104
105 if ((encoder == best_encoder) && (status == connector_status_connected))
106 connected = true;
107 else
108 connected = false;
109
110 if (rdev->is_atom_bios)
111 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
112 else
113 radeon_combios_connected_scratch_regs(connector, encoder, connected);
114
115 }
116}
117
Dave Airlie445282d2009-09-09 17:40:54 +1000118struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
119{
120 struct drm_mode_object *obj;
121 struct drm_encoder *encoder;
122 int i;
123
124 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
125 if (connector->encoder_ids[i] == 0)
126 break;
127
128 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
129 if (!obj)
130 continue;
131
132 encoder = obj_to_encoder(obj);
133 if (encoder->encoder_type == encoder_type)
134 return encoder;
135 }
136 return NULL;
137}
138
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200139struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
140{
141 int enc_id = connector->encoder_ids[0];
142 struct drm_mode_object *obj;
143 struct drm_encoder *encoder;
144
145 /* pick the encoder ids */
146 if (enc_id) {
147 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
148 if (!obj)
149 return NULL;
150 encoder = obj_to_encoder(obj);
151 return encoder;
152 }
153 return NULL;
154}
155
Dave Airlie4ce001a2009-08-13 16:32:14 +1000156/*
157 * radeon_connector_analog_encoder_conflict_solve
158 * - search for other connectors sharing this encoder
159 * if priority is true, then set them disconnected if this is connected
160 * if priority is false, set us disconnected if they are connected
161 */
162static enum drm_connector_status
163radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
164 struct drm_encoder *encoder,
165 enum drm_connector_status current_status,
166 bool priority)
167{
168 struct drm_device *dev = connector->dev;
169 struct drm_connector *conflict;
Alex Deucher08d07512010-04-15 13:31:12 -0400170 struct radeon_connector *radeon_conflict;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000171 int i;
172
173 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
174 if (conflict == connector)
175 continue;
176
Alex Deucher08d07512010-04-15 13:31:12 -0400177 radeon_conflict = to_radeon_connector(conflict);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000178 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
179 if (conflict->encoder_ids[i] == 0)
180 break;
181
182 /* if the IDs match */
183 if (conflict->encoder_ids[i] == encoder->base.id) {
184 if (conflict->status != connector_status_connected)
185 continue;
186
Alex Deucher08d07512010-04-15 13:31:12 -0400187 if (radeon_conflict->use_digital)
188 continue;
189
Dave Airlie4ce001a2009-08-13 16:32:14 +1000190 if (priority == true) {
Alex Deucherc5d46b42010-10-29 13:49:25 -0400191 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
192 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(connector));
Dave Airlie4ce001a2009-08-13 16:32:14 +1000193 conflict->status = connector_status_disconnected;
194 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
195 } else {
Alex Deucherc5d46b42010-10-29 13:49:25 -0400196 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
197 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(conflict));
Dave Airlie4ce001a2009-08-13 16:32:14 +1000198 current_status = connector_status_disconnected;
199 }
200 break;
201 }
202 }
203 }
204 return current_status;
205
206}
207
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200208static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
209{
210 struct drm_device *dev = encoder->dev;
211 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
212 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400213 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200214
Alex Deucherde2103e2009-10-09 15:14:30 -0400215 if (native_mode->hdisplay != 0 &&
216 native_mode->vdisplay != 0 &&
217 native_mode->clock != 0) {
Alex Deucherfb06ca82009-10-12 11:25:05 -0400218 mode = drm_mode_duplicate(dev, native_mode);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200219 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
220 drm_mode_set_name(mode);
221
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000222 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
Alex Deucherd2efdf62009-12-22 10:06:49 -0500223 } else if (native_mode->hdisplay != 0 &&
224 native_mode->vdisplay != 0) {
225 /* mac laptops without an edid */
226 /* Note that this is not necessarily the exact panel mode,
227 * but an approximation based on the cvt formula. For these
228 * systems we should ideally read the mode info out of the
229 * registers or add a mode table, but this works and is much
230 * simpler.
231 */
232 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
233 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000234 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200235 }
236 return mode;
237}
238
Alex Deucher923f6842009-09-10 17:53:39 -0400239static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
240{
241 struct drm_device *dev = encoder->dev;
242 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
243 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400244 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400245 int i;
246 struct mode_size {
247 int w;
248 int h;
249 } common_modes[17] = {
250 { 640, 480},
251 { 720, 480},
252 { 800, 600},
253 { 848, 480},
254 {1024, 768},
255 {1152, 768},
256 {1280, 720},
257 {1280, 800},
258 {1280, 854},
259 {1280, 960},
260 {1280, 1024},
261 {1440, 900},
262 {1400, 1050},
263 {1680, 1050},
264 {1600, 1200},
265 {1920, 1080},
266 {1920, 1200}
267 };
268
269 for (i = 0; i < 17; i++) {
Alex Deucherdfdd6462009-10-13 12:48:44 -0400270 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
271 if (common_modes[i].w > 1024 ||
272 common_modes[i].h > 768)
273 continue;
274 }
Alex Deucher923f6842009-09-10 17:53:39 -0400275 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400276 if (common_modes[i].w > native_mode->hdisplay ||
277 common_modes[i].h > native_mode->vdisplay ||
278 (common_modes[i].w == native_mode->hdisplay &&
279 common_modes[i].h == native_mode->vdisplay))
Alex Deucher923f6842009-09-10 17:53:39 -0400280 continue;
281 }
282 if (common_modes[i].w < 320 || common_modes[i].h < 200)
283 continue;
284
Dave Airlied50ba252009-09-23 14:44:08 +1000285 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400286 drm_mode_probed_add(connector, mode);
287 }
288}
289
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200290int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
291 uint64_t val)
292{
Dave Airlie445282d2009-09-09 17:40:54 +1000293 struct drm_device *dev = connector->dev;
294 struct radeon_device *rdev = dev->dev_private;
295 struct drm_encoder *encoder;
296 struct radeon_encoder *radeon_encoder;
297
298 if (property == rdev->mode_info.coherent_mode_property) {
299 struct radeon_encoder_atom_dig *dig;
Dave Airliece227c42010-04-09 06:27:00 +0000300 bool new_coherent_mode;
Dave Airlie445282d2009-09-09 17:40:54 +1000301
302 /* need to find digital encoder on connector */
303 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
304 if (!encoder)
305 return 0;
306
307 radeon_encoder = to_radeon_encoder(encoder);
308
309 if (!radeon_encoder->enc_priv)
310 return 0;
311
312 dig = radeon_encoder->enc_priv;
Dave Airliece227c42010-04-09 06:27:00 +0000313 new_coherent_mode = val ? true : false;
314 if (dig->coherent_mode != new_coherent_mode) {
315 dig->coherent_mode = new_coherent_mode;
316 radeon_property_change_mode(&radeon_encoder->base);
317 }
Dave Airlie445282d2009-09-09 17:40:54 +1000318 }
319
Alex Deucher5b1714d2010-08-03 19:59:20 -0400320 if (property == rdev->mode_info.underscan_property) {
321 /* need to find digital encoder on connector */
322 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
323 if (!encoder)
324 return 0;
325
326 radeon_encoder = to_radeon_encoder(encoder);
327
328 if (radeon_encoder->underscan_type != val) {
329 radeon_encoder->underscan_type = val;
330 radeon_property_change_mode(&radeon_encoder->base);
331 }
332 }
333
Marius Gröger5bccf5e2010-09-21 21:30:59 +0200334 if (property == rdev->mode_info.underscan_hborder_property) {
335 /* need to find digital encoder on connector */
336 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
337 if (!encoder)
338 return 0;
339
340 radeon_encoder = to_radeon_encoder(encoder);
341
342 if (radeon_encoder->underscan_hborder != val) {
343 radeon_encoder->underscan_hborder = val;
344 radeon_property_change_mode(&radeon_encoder->base);
345 }
346 }
347
348 if (property == rdev->mode_info.underscan_vborder_property) {
349 /* need to find digital encoder on connector */
350 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
351 if (!encoder)
352 return 0;
353
354 radeon_encoder = to_radeon_encoder(encoder);
355
356 if (radeon_encoder->underscan_vborder != val) {
357 radeon_encoder->underscan_vborder = val;
358 radeon_property_change_mode(&radeon_encoder->base);
359 }
360 }
361
Dave Airlie445282d2009-09-09 17:40:54 +1000362 if (property == rdev->mode_info.tv_std_property) {
363 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
364 if (!encoder) {
365 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
366 }
367
368 if (!encoder)
369 return 0;
370
371 radeon_encoder = to_radeon_encoder(encoder);
372 if (!radeon_encoder->enc_priv)
373 return 0;
Alex Deucher643acac2010-04-05 23:57:52 -0400374 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
Dave Airlie445282d2009-09-09 17:40:54 +1000375 struct radeon_encoder_atom_dac *dac_int;
376 dac_int = radeon_encoder->enc_priv;
377 dac_int->tv_std = val;
378 } else {
379 struct radeon_encoder_tv_dac *dac_int;
380 dac_int = radeon_encoder->enc_priv;
381 dac_int->tv_std = val;
382 }
383 radeon_property_change_mode(&radeon_encoder->base);
384 }
385
386 if (property == rdev->mode_info.load_detect_property) {
387 struct radeon_connector *radeon_connector =
388 to_radeon_connector(connector);
389
390 if (val == 0)
391 radeon_connector->dac_load_detect = false;
392 else
393 radeon_connector->dac_load_detect = true;
394 }
395
396 if (property == rdev->mode_info.tmds_pll_property) {
397 struct radeon_encoder_int_tmds *tmds = NULL;
398 bool ret = false;
399 /* need to find digital encoder on connector */
400 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
401 if (!encoder)
402 return 0;
403
404 radeon_encoder = to_radeon_encoder(encoder);
405
406 tmds = radeon_encoder->enc_priv;
407 if (!tmds)
408 return 0;
409
410 if (val == 0) {
411 if (rdev->is_atom_bios)
412 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
413 else
414 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
415 }
416 if (val == 1 || ret == false) {
417 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
418 }
419 radeon_property_change_mode(&radeon_encoder->base);
420 }
421
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200422 return 0;
423}
424
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200425static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
426 struct drm_connector *connector)
427{
428 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400429 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200430
431 /* Try to get native mode details from EDID if necessary */
Alex Deucherde2103e2009-10-09 15:14:30 -0400432 if (!native_mode->clock) {
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200433 struct drm_display_mode *t, *mode;
434
435 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400436 if (mode->hdisplay == native_mode->hdisplay &&
437 mode->vdisplay == native_mode->vdisplay) {
438 *native_mode = *mode;
439 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
Alex Deucherc5d46b42010-10-29 13:49:25 -0400440 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200441 break;
442 }
443 }
444 }
Alex Deucherde2103e2009-10-09 15:14:30 -0400445 if (!native_mode->clock) {
Alex Deucherc5d46b42010-10-29 13:49:25 -0400446 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200447 radeon_encoder->rmx_type = RMX_OFF;
448 }
449}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200450
451static int radeon_lvds_get_modes(struct drm_connector *connector)
452{
453 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
454 struct drm_encoder *encoder;
455 int ret = 0;
456 struct drm_display_mode *mode;
457
458 if (radeon_connector->ddc_bus) {
459 ret = radeon_ddc_get_modes(radeon_connector);
460 if (ret > 0) {
Alex Deucher7747b712009-09-11 11:15:43 -0400461 encoder = radeon_best_single_encoder(connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200462 if (encoder) {
463 radeon_fixup_lvds_native_mode(encoder, connector);
Alex Deucher7747b712009-09-11 11:15:43 -0400464 /* add scaled modes */
465 radeon_add_common_modes(encoder, connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200466 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200467 return ret;
468 }
469 }
470
471 encoder = radeon_best_single_encoder(connector);
472 if (!encoder)
473 return 0;
474
475 /* we have no EDID modes */
476 mode = radeon_fp_native_mode(encoder);
477 if (mode) {
478 ret = 1;
479 drm_mode_probed_add(connector, mode);
Alex Deucher7a868e12010-12-08 22:13:05 -0500480 /* add the width/height from vbios tables if available */
481 connector->display_info.width_mm = mode->width_mm;
482 connector->display_info.height_mm = mode->height_mm;
Alex Deucher7747b712009-09-11 11:15:43 -0400483 /* add scaled modes */
484 radeon_add_common_modes(encoder, connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200485 }
Alex Deucher923f6842009-09-10 17:53:39 -0400486
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200487 return ret;
488}
489
490static int radeon_lvds_mode_valid(struct drm_connector *connector,
491 struct drm_display_mode *mode)
492{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500493 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
494
495 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
496 return MODE_PANEL;
497
498 if (encoder) {
499 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
500 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
501
502 /* AVIVO hardware supports downscaling modes larger than the panel
503 * to the panel size, but I'm not sure this is desirable.
504 */
505 if ((mode->hdisplay > native_mode->hdisplay) ||
506 (mode->vdisplay > native_mode->vdisplay))
507 return MODE_PANEL;
508
509 /* if scaling is disabled, block non-native modes */
510 if (radeon_encoder->rmx_type == RMX_OFF) {
511 if ((mode->hdisplay != native_mode->hdisplay) ||
512 (mode->vdisplay != native_mode->vdisplay))
513 return MODE_PANEL;
514 }
515 }
516
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200517 return MODE_OK;
518}
519
Chris Wilson7b334fc2010-09-09 23:51:02 +0100520static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100521radeon_lvds_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200522{
Alex Deucher0549a062009-10-09 18:41:19 -0400523 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher2ffb8422009-10-08 13:02:19 -0400524 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Alex Deucher0549a062009-10-09 18:41:19 -0400525 enum drm_connector_status ret = connector_status_disconnected;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400526
527 if (encoder) {
528 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400529 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400530
531 /* check if panel is valid */
Alex Deucherde2103e2009-10-09 15:14:30 -0400532 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
Alex Deucher2ffb8422009-10-08 13:02:19 -0400533 ret = connector_status_connected;
534
535 }
Alex Deucher0549a062009-10-09 18:41:19 -0400536
537 /* check for edid as well */
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400538 if (radeon_connector->edid)
539 ret = connector_status_connected;
540 else {
541 if (radeon_connector->ddc_bus) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400542 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
543 &radeon_connector->ddc_bus->adapter);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400544 if (radeon_connector->edid)
545 ret = connector_status_connected;
546 }
Alex Deucher0549a062009-10-09 18:41:19 -0400547 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200548 /* check acpi lid status ??? */
Alex Deucher2ffb8422009-10-08 13:02:19 -0400549
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200550 radeon_connector_update_scratch_regs(connector, ret);
551 return ret;
552}
553
554static void radeon_connector_destroy(struct drm_connector *connector)
555{
556 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
557
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400558 if (radeon_connector->edid)
559 kfree(radeon_connector->edid);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200560 kfree(radeon_connector->con_priv);
561 drm_sysfs_connector_remove(connector);
562 drm_connector_cleanup(connector);
563 kfree(connector);
564}
565
Dave Airlie445282d2009-09-09 17:40:54 +1000566static int radeon_lvds_set_property(struct drm_connector *connector,
567 struct drm_property *property,
568 uint64_t value)
569{
570 struct drm_device *dev = connector->dev;
571 struct radeon_encoder *radeon_encoder;
572 enum radeon_rmx_type rmx_type;
573
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000574 DRM_DEBUG_KMS("\n");
Dave Airlie445282d2009-09-09 17:40:54 +1000575 if (property != dev->mode_config.scaling_mode_property)
576 return 0;
577
578 if (connector->encoder)
579 radeon_encoder = to_radeon_encoder(connector->encoder);
580 else {
581 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
582 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
583 }
584
585 switch (value) {
586 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
587 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
588 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
589 default:
590 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
591 }
592 if (radeon_encoder->rmx_type == rmx_type)
593 return 0;
594
595 radeon_encoder->rmx_type = rmx_type;
596
597 radeon_property_change_mode(&radeon_encoder->base);
598 return 0;
599}
600
601
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200602struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
603 .get_modes = radeon_lvds_get_modes,
604 .mode_valid = radeon_lvds_mode_valid,
605 .best_encoder = radeon_best_single_encoder,
606};
607
608struct drm_connector_funcs radeon_lvds_connector_funcs = {
609 .dpms = drm_helper_connector_dpms,
610 .detect = radeon_lvds_detect,
611 .fill_modes = drm_helper_probe_single_connector_modes,
612 .destroy = radeon_connector_destroy,
Dave Airlie445282d2009-09-09 17:40:54 +1000613 .set_property = radeon_lvds_set_property,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200614};
615
616static int radeon_vga_get_modes(struct drm_connector *connector)
617{
618 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
619 int ret;
620
621 ret = radeon_ddc_get_modes(radeon_connector);
622
623 return ret;
624}
625
626static int radeon_vga_mode_valid(struct drm_connector *connector,
627 struct drm_display_mode *mode)
628{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500629 /* XXX check mode bandwidth */
630 /* XXX verify against max DAC output frequency */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200631 return MODE_OK;
632}
633
Chris Wilson7b334fc2010-09-09 23:51:02 +0100634static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100635radeon_vga_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200636{
Alex Deucherfafcf942011-03-23 08:10:10 +0000637 struct drm_device *dev = connector->dev;
638 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200639 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
640 struct drm_encoder *encoder;
641 struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000642 bool dret = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200643 enum drm_connector_status ret = connector_status_disconnected;
644
Dave Airlie4ce001a2009-08-13 16:32:14 +1000645 encoder = radeon_best_single_encoder(connector);
646 if (!encoder)
647 ret = connector_status_disconnected;
648
Dave Airlieeb6b6d72010-02-25 13:44:04 +1000649 if (radeon_connector->ddc_bus)
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000650 dret = radeon_ddc_probe(radeon_connector);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400651 if (dret) {
652 if (radeon_connector->edid) {
653 kfree(radeon_connector->edid);
654 radeon_connector->edid = NULL;
655 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400656 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400657
658 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +0100659 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
660 drm_get_connector_name(connector));
661 ret = connector_status_connected;
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400662 } else {
663 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
664
665 /* some oems have boards with separate digital and analog connectors
666 * with a shared ddc line (often vga + hdmi)
667 */
668 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
669 kfree(radeon_connector->edid);
670 radeon_connector->edid = NULL;
671 ret = connector_status_disconnected;
672 } else
673 ret = connector_status_connected;
674 }
675 } else {
Dave Airliec3cceed2010-10-26 12:55:52 +1000676
677 /* if we aren't forcing don't do destructive polling */
678 if (!force)
679 return connector->status;
680
Darren Jenkinsd8a7f792009-12-30 12:22:55 +1100681 if (radeon_connector->dac_load_detect && encoder) {
Dave Airlie445282d2009-09-09 17:40:54 +1000682 encoder_funcs = encoder->helper_private;
683 ret = encoder_funcs->detect(encoder, connector);
684 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200685 }
686
Dave Airlie4ce001a2009-08-13 16:32:14 +1000687 if (ret == connector_status_connected)
688 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
Alex Deucherfafcf942011-03-23 08:10:10 +0000689
690 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
691 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
692 * by other means, assume the CRT is connected and use that EDID.
693 */
694 if ((!rdev->is_atom_bios) &&
695 (ret == connector_status_disconnected) &&
696 rdev->mode_info.bios_hardcoded_edid_size) {
697 ret = connector_status_connected;
698 }
699
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200700 radeon_connector_update_scratch_regs(connector, ret);
701 return ret;
702}
703
704struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
705 .get_modes = radeon_vga_get_modes,
706 .mode_valid = radeon_vga_mode_valid,
707 .best_encoder = radeon_best_single_encoder,
708};
709
710struct drm_connector_funcs radeon_vga_connector_funcs = {
711 .dpms = drm_helper_connector_dpms,
712 .detect = radeon_vga_detect,
713 .fill_modes = drm_helper_probe_single_connector_modes,
714 .destroy = radeon_connector_destroy,
715 .set_property = radeon_connector_set_property,
716};
717
Dave Airlie4ce001a2009-08-13 16:32:14 +1000718static int radeon_tv_get_modes(struct drm_connector *connector)
719{
720 struct drm_device *dev = connector->dev;
Alex Deucher923f6842009-09-10 17:53:39 -0400721 struct radeon_device *rdev = dev->dev_private;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000722 struct drm_display_mode *tv_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400723 struct drm_encoder *encoder;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000724
Alex Deucher923f6842009-09-10 17:53:39 -0400725 encoder = radeon_best_single_encoder(connector);
726 if (!encoder)
727 return 0;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000728
Alex Deucher923f6842009-09-10 17:53:39 -0400729 /* avivo chips can scale any mode */
730 if (rdev->family >= CHIP_RS600)
731 /* add scaled modes */
732 radeon_add_common_modes(encoder, connector);
733 else {
734 /* only 800x600 is supported right now on pre-avivo chips */
Dave Airlied50ba252009-09-23 14:44:08 +1000735 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400736 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
737 drm_mode_probed_add(connector, tv_mode);
738 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000739 return 1;
740}
741
742static int radeon_tv_mode_valid(struct drm_connector *connector,
743 struct drm_display_mode *mode)
744{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500745 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
746 return MODE_CLOCK_RANGE;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000747 return MODE_OK;
748}
749
Chris Wilson7b334fc2010-09-09 23:51:02 +0100750static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100751radeon_tv_detect(struct drm_connector *connector, bool force)
Dave Airlie4ce001a2009-08-13 16:32:14 +1000752{
753 struct drm_encoder *encoder;
754 struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie445282d2009-09-09 17:40:54 +1000755 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
756 enum drm_connector_status ret = connector_status_disconnected;
757
758 if (!radeon_connector->dac_load_detect)
759 return ret;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000760
761 encoder = radeon_best_single_encoder(connector);
762 if (!encoder)
763 ret = connector_status_disconnected;
764 else {
765 encoder_funcs = encoder->helper_private;
766 ret = encoder_funcs->detect(encoder, connector);
767 }
768 if (ret == connector_status_connected)
769 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
770 radeon_connector_update_scratch_regs(connector, ret);
771 return ret;
772}
773
774struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
775 .get_modes = radeon_tv_get_modes,
776 .mode_valid = radeon_tv_mode_valid,
777 .best_encoder = radeon_best_single_encoder,
778};
779
780struct drm_connector_funcs radeon_tv_connector_funcs = {
781 .dpms = drm_helper_connector_dpms,
782 .detect = radeon_tv_detect,
783 .fill_modes = drm_helper_probe_single_connector_modes,
784 .destroy = radeon_connector_destroy,
785 .set_property = radeon_connector_set_property,
786};
787
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200788static int radeon_dvi_get_modes(struct drm_connector *connector)
789{
790 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
791 int ret;
792
793 ret = radeon_ddc_get_modes(radeon_connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200794 return ret;
795}
796
Dave Airlie4ce001a2009-08-13 16:32:14 +1000797/*
798 * DVI is complicated
799 * Do a DDC probe, if DDC probe passes, get the full EDID so
800 * we can do analog/digital monitor detection at this point.
801 * If the monitor is an analog monitor or we got no DDC,
802 * we need to find the DAC encoder object for this connector.
803 * If we got no DDC, we do load detection on the DAC encoder object.
804 * If we got analog DDC or load detection passes on the DAC encoder
805 * we have to check if this analog encoder is shared with anyone else (TV)
806 * if its shared we have to set the other connector to disconnected.
807 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100808static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100809radeon_dvi_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200810{
Alex Deucherfafcf942011-03-23 08:10:10 +0000811 struct drm_device *dev = connector->dev;
812 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200813 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000814 struct drm_encoder *encoder = NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200815 struct drm_encoder_helper_funcs *encoder_funcs;
816 struct drm_mode_object *obj;
817 int i;
818 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000819 bool dret = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200820
Dave Airlieeb6b6d72010-02-25 13:44:04 +1000821 if (radeon_connector->ddc_bus)
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000822 dret = radeon_ddc_probe(radeon_connector);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000823 if (dret) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400824 if (radeon_connector->edid) {
825 kfree(radeon_connector->edid);
826 radeon_connector->edid = NULL;
827 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000828 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200829
Dave Airlie4ce001a2009-08-13 16:32:14 +1000830 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +0100831 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
832 drm_get_connector_name(connector));
Dave Airlie4ce001a2009-08-13 16:32:14 +1000833 } else {
834 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200835
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400836 /* some oems have boards with separate digital and analog connectors
837 * with a shared ddc line (often vga + hdmi)
838 */
839 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
840 kfree(radeon_connector->edid);
841 radeon_connector->edid = NULL;
842 ret = connector_status_disconnected;
843 } else
844 ret = connector_status_connected;
Alex Deucher71407c42009-11-17 15:44:01 -0500845
Alex Deucher42f14c42010-07-20 11:27:54 -0400846 /* This gets complicated. We have boards with VGA + HDMI with a
847 * shared DDC line and we have boards with DVI-D + HDMI with a shared
848 * DDC line. The latter is more complex because with DVI<->HDMI adapters
849 * you don't really know what's connected to which port as both are digital.
Alex Deucher71407c42009-11-17 15:44:01 -0500850 */
Alex Deucherd3932d62010-02-19 02:13:56 -0500851 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
Alex Deucher71407c42009-11-17 15:44:01 -0500852 struct drm_connector *list_connector;
853 struct radeon_connector *list_radeon_connector;
854 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
855 if (connector == list_connector)
856 continue;
857 list_radeon_connector = to_radeon_connector(list_connector);
Alex Deucherb2ea4aa2010-07-01 10:34:56 -0400858 if (list_radeon_connector->shared_ddc &&
859 (list_radeon_connector->ddc_bus->rec.i2c_id ==
860 radeon_connector->ddc_bus->rec.i2c_id)) {
Alex Deucher42f14c42010-07-20 11:27:54 -0400861 /* cases where both connectors are digital */
862 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
863 /* hpd is our only option in this case */
864 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
Alex Deucher71407c42009-11-17 15:44:01 -0500865 kfree(radeon_connector->edid);
866 radeon_connector->edid = NULL;
867 ret = connector_status_disconnected;
868 }
869 }
870 }
871 }
872 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200873 }
874 }
875
Dave Airlie4ce001a2009-08-13 16:32:14 +1000876 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
877 goto out;
878
Dave Airliec3cceed2010-10-26 12:55:52 +1000879 if (!force) {
880 ret = connector->status;
881 goto out;
882 }
883
Dave Airlie4ce001a2009-08-13 16:32:14 +1000884 /* find analog encoder */
Dave Airlie445282d2009-09-09 17:40:54 +1000885 if (radeon_connector->dac_load_detect) {
886 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
887 if (connector->encoder_ids[i] == 0)
888 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000889
Dave Airlie445282d2009-09-09 17:40:54 +1000890 obj = drm_mode_object_find(connector->dev,
891 connector->encoder_ids[i],
892 DRM_MODE_OBJECT_ENCODER);
893 if (!obj)
894 continue;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000895
Dave Airlie445282d2009-09-09 17:40:54 +1000896 encoder = obj_to_encoder(obj);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000897
Dave Airlie445282d2009-09-09 17:40:54 +1000898 encoder_funcs = encoder->helper_private;
899 if (encoder_funcs->detect) {
900 if (ret != connector_status_connected) {
901 ret = encoder_funcs->detect(encoder, connector);
902 if (ret == connector_status_connected) {
903 radeon_connector->use_digital = false;
904 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000905 }
Dave Airlie445282d2009-09-09 17:40:54 +1000906 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000907 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000908 }
909 }
910
911 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
912 encoder) {
913 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
914 }
915
Alex Deucherfafcf942011-03-23 08:10:10 +0000916 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
917 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
918 * by other means, assume the DFP is connected and use that EDID. In most
919 * cases the DVI port is actually a virtual KVM port connected to the service
920 * processor.
921 */
922 if ((!rdev->is_atom_bios) &&
923 (ret == connector_status_disconnected) &&
924 rdev->mode_info.bios_hardcoded_edid_size) {
925 radeon_connector->use_digital = true;
926 ret = connector_status_connected;
927 }
928
Dave Airlie4ce001a2009-08-13 16:32:14 +1000929out:
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200930 /* updated in get modes as well since we need to know if it's analog or digital */
931 radeon_connector_update_scratch_regs(connector, ret);
932 return ret;
933}
934
935/* okay need to be smart in here about which encoder to pick */
936struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
937{
938 int enc_id = connector->encoder_ids[0];
939 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
940 struct drm_mode_object *obj;
941 struct drm_encoder *encoder;
942 int i;
943 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
944 if (connector->encoder_ids[i] == 0)
945 break;
946
947 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
948 if (!obj)
949 continue;
950
951 encoder = obj_to_encoder(obj);
952
Dave Airlie4ce001a2009-08-13 16:32:14 +1000953 if (radeon_connector->use_digital == true) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200954 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
955 return encoder;
956 } else {
957 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
958 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
959 return encoder;
960 }
961 }
962
963 /* see if we have a default encoder TODO */
964
965 /* then check use digitial */
966 /* pick the first one */
967 if (enc_id) {
968 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
969 if (!obj)
970 return NULL;
971 encoder = obj_to_encoder(obj);
972 return encoder;
973 }
974 return NULL;
975}
976
Dave Airlied50ba252009-09-23 14:44:08 +1000977static void radeon_dvi_force(struct drm_connector *connector)
978{
979 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
980 if (connector->force == DRM_FORCE_ON)
981 radeon_connector->use_digital = false;
982 if (connector->force == DRM_FORCE_ON_DIGITAL)
983 radeon_connector->use_digital = true;
984}
985
Alex Deuchera3fa6322009-11-05 11:57:07 -0500986static int radeon_dvi_mode_valid(struct drm_connector *connector,
987 struct drm_display_mode *mode)
988{
Alex Deucher1b242032010-01-11 15:02:31 -0500989 struct drm_device *dev = connector->dev;
990 struct radeon_device *rdev = dev->dev_private;
Alex Deuchera3fa6322009-11-05 11:57:07 -0500991 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
992
993 /* XXX check mode bandwidth */
994
Alex Deucher1b242032010-01-11 15:02:31 -0500995 /* clocks over 135 MHz have heat issues with DVI on RV100 */
996 if (radeon_connector->use_digital &&
997 (rdev->family == CHIP_RV100) &&
998 (mode->clock > 135000))
999 return MODE_CLOCK_HIGH;
1000
Alex Deuchera3fa6322009-11-05 11:57:07 -05001001 if (radeon_connector->use_digital && (mode->clock > 165000)) {
1002 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1003 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1004 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1005 return MODE_OK;
Alex Deuchere1e84012011-03-02 10:21:05 -05001006 else if (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_A) {
1007 if (ASIC_IS_DCE3(rdev)) {
1008 /* HDMI 1.3+ supports max clock of 340 Mhz */
1009 if (mode->clock > 340000)
1010 return MODE_CLOCK_HIGH;
1011 else
1012 return MODE_OK;
1013 } else
1014 return MODE_CLOCK_HIGH;
1015 } else
Alex Deuchera3fa6322009-11-05 11:57:07 -05001016 return MODE_CLOCK_HIGH;
1017 }
1018 return MODE_OK;
1019}
1020
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001021struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
1022 .get_modes = radeon_dvi_get_modes,
Alex Deuchera3fa6322009-11-05 11:57:07 -05001023 .mode_valid = radeon_dvi_mode_valid,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001024 .best_encoder = radeon_dvi_encoder,
1025};
1026
1027struct drm_connector_funcs radeon_dvi_connector_funcs = {
1028 .dpms = drm_helper_connector_dpms,
1029 .detect = radeon_dvi_detect,
1030 .fill_modes = drm_helper_probe_single_connector_modes,
1031 .set_property = radeon_connector_set_property,
1032 .destroy = radeon_connector_destroy,
Dave Airlied50ba252009-09-23 14:44:08 +10001033 .force = radeon_dvi_force,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001034};
1035
Alex Deucherffd09c62009-11-24 16:13:23 -05001036static void radeon_dp_connector_destroy(struct drm_connector *connector)
1037{
1038 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1039 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1040
Alex Deucherffd09c62009-11-24 16:13:23 -05001041 if (radeon_connector->edid)
1042 kfree(radeon_connector->edid);
1043 if (radeon_dig_connector->dp_i2c_bus)
Alex Deucherac1aade2010-03-14 12:22:44 -04001044 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
Alex Deucherffd09c62009-11-24 16:13:23 -05001045 kfree(radeon_connector->con_priv);
1046 drm_sysfs_connector_remove(connector);
1047 drm_connector_cleanup(connector);
1048 kfree(connector);
1049}
1050
Dave Airlie746c1aa2009-12-08 07:07:28 +10001051static int radeon_dp_get_modes(struct drm_connector *connector)
1052{
1053 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher8b834852010-11-17 02:54:42 -05001054 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001055 int ret;
1056
Alex Deucher8b834852010-11-17 02:54:42 -05001057 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
Alex Deucherd2917672011-05-20 04:34:31 -04001058 struct drm_encoder *encoder;
1059 struct drm_display_mode *mode;
1060
Alex Deucher8b834852010-11-17 02:54:42 -05001061 if (!radeon_dig_connector->edp_on)
1062 atombios_set_edp_panel_power(connector,
1063 ATOM_TRANSMITTER_ACTION_POWER_ON);
Alex Deucherd2917672011-05-20 04:34:31 -04001064 ret = radeon_ddc_get_modes(radeon_connector);
Alex Deucher8b834852010-11-17 02:54:42 -05001065 if (!radeon_dig_connector->edp_on)
1066 atombios_set_edp_panel_power(connector,
1067 ATOM_TRANSMITTER_ACTION_POWER_OFF);
Alex Deucherd2917672011-05-20 04:34:31 -04001068
1069 if (ret > 0) {
1070 encoder = radeon_best_single_encoder(connector);
1071 if (encoder) {
1072 radeon_fixup_lvds_native_mode(encoder, connector);
1073 /* add scaled modes */
1074 radeon_add_common_modes(encoder, connector);
1075 }
1076 return ret;
1077 }
1078
1079 encoder = radeon_best_single_encoder(connector);
1080 if (!encoder)
1081 return 0;
1082
1083 /* we have no EDID modes */
1084 mode = radeon_fp_native_mode(encoder);
1085 if (mode) {
1086 ret = 1;
1087 drm_mode_probed_add(connector, mode);
1088 /* add the width/height from vbios tables if available */
1089 connector->display_info.width_mm = mode->width_mm;
1090 connector->display_info.height_mm = mode->height_mm;
1091 /* add scaled modes */
1092 radeon_add_common_modes(encoder, connector);
1093 }
1094 } else
1095 ret = radeon_ddc_get_modes(radeon_connector);
Alex Deucher8b834852010-11-17 02:54:42 -05001096
Dave Airlie746c1aa2009-12-08 07:07:28 +10001097 return ret;
1098}
1099
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001100bool radeon_connector_encoder_is_dp_bridge(struct drm_connector *connector)
1101{
1102 struct drm_mode_object *obj;
1103 struct drm_encoder *encoder;
1104 struct radeon_encoder *radeon_encoder;
1105 int i;
1106 bool found = false;
1107
1108 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1109 if (connector->encoder_ids[i] == 0)
1110 break;
1111
1112 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1113 if (!obj)
1114 continue;
1115
1116 encoder = obj_to_encoder(obj);
1117 radeon_encoder = to_radeon_encoder(encoder);
1118
1119 switch (radeon_encoder->encoder_id) {
1120 case ENCODER_OBJECT_ID_TRAVIS:
1121 case ENCODER_OBJECT_ID_NUTMEG:
1122 found = true;
1123 break;
1124 default:
1125 break;
1126 }
1127 }
1128
1129 return found;
1130}
1131
1132bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
1133{
1134 struct drm_mode_object *obj;
1135 struct drm_encoder *encoder;
1136 struct radeon_encoder *radeon_encoder;
1137 int i;
1138 bool found = false;
1139
1140 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1141 if (connector->encoder_ids[i] == 0)
1142 break;
1143
1144 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1145 if (!obj)
1146 continue;
1147
1148 encoder = obj_to_encoder(obj);
1149 radeon_encoder = to_radeon_encoder(encoder);
1150 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1151 found = true;
1152 }
1153
1154 return found;
1155}
1156
1157bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1158{
1159 struct drm_device *dev = connector->dev;
1160 struct radeon_device *rdev = dev->dev_private;
1161
1162 if (ASIC_IS_DCE5(rdev) &&
1163 (rdev->clock.dp_extclk >= 53900) &&
1164 radeon_connector_encoder_is_hbr2(connector)) {
1165 return true;
1166 }
1167
1168 return false;
1169}
1170
Chris Wilson7b334fc2010-09-09 23:51:02 +01001171static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +01001172radeon_dp_detect(struct drm_connector *connector, bool force)
Dave Airlie746c1aa2009-12-08 07:07:28 +10001173{
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001174 struct drm_device *dev = connector->dev;
1175 struct radeon_device *rdev = dev->dev_private;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001176 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001177 enum drm_connector_status ret = connector_status_disconnected;
Alex Deucher4143e912009-11-23 18:02:35 -05001178 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001179
1180 if (radeon_connector->edid) {
1181 kfree(radeon_connector->edid);
1182 radeon_connector->edid = NULL;
1183 }
1184
Alex Deucher6f50eae2010-08-19 17:29:03 -04001185 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
Alex Deucherd2917672011-05-20 04:34:31 -04001186 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1187 if (encoder) {
1188 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1189 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1190
1191 /* check if panel is valid */
1192 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1193 ret = connector_status_connected;
1194 }
Alex Deucher6f50eae2010-08-19 17:29:03 -04001195 /* eDP is always DP */
1196 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
Alex Deucher8b834852010-11-17 02:54:42 -05001197 if (!radeon_dig_connector->edp_on)
1198 atombios_set_edp_panel_power(connector,
1199 ATOM_TRANSMITTER_ACTION_POWER_ON);
Alex Deucher6f50eae2010-08-19 17:29:03 -04001200 if (radeon_dp_getdpcd(radeon_connector))
Alex Deucher9fa05c92009-11-27 13:01:46 -05001201 ret = connector_status_connected;
Alex Deucher8b834852010-11-17 02:54:42 -05001202 if (!radeon_dig_connector->edp_on)
1203 atombios_set_edp_panel_power(connector,
1204 ATOM_TRANSMITTER_ACTION_POWER_OFF);
Alex Deucher4143e912009-11-23 18:02:35 -05001205 } else {
Alex Deucher6f50eae2010-08-19 17:29:03 -04001206 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001207 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1208 ret = connector_status_connected;
1209 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
1210 radeon_dp_getdpcd(radeon_connector);
Alex Deucher6f50eae2010-08-19 17:29:03 -04001211 } else {
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001212 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1213 if (radeon_dp_getdpcd(radeon_connector))
1214 ret = connector_status_connected;
1215 } else {
1216 if (radeon_ddc_probe(radeon_connector))
1217 ret = connector_status_connected;
1218 }
Alex Deucher4143e912009-11-23 18:02:35 -05001219 }
Dave Airlie746c1aa2009-12-08 07:07:28 +10001220 }
Alex Deucher4143e912009-11-23 18:02:35 -05001221
Alex Deucher30f44372010-08-21 11:09:14 -04001222 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001223 return ret;
1224}
1225
Alex Deucher5801ead2009-11-24 13:32:59 -05001226static int radeon_dp_mode_valid(struct drm_connector *connector,
1227 struct drm_display_mode *mode)
1228{
1229 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1230 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1231
1232 /* XXX check mode bandwidth */
1233
Alex Deucherd2917672011-05-20 04:34:31 -04001234 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1235 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1236
1237 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1238 return MODE_PANEL;
1239
1240 if (encoder) {
1241 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1242 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1243
1244 /* AVIVO hardware supports downscaling modes larger than the panel
1245 * to the panel size, but I'm not sure this is desirable.
1246 */
1247 if ((mode->hdisplay > native_mode->hdisplay) ||
1248 (mode->vdisplay > native_mode->vdisplay))
1249 return MODE_PANEL;
1250
1251 /* if scaling is disabled, block non-native modes */
1252 if (radeon_encoder->rmx_type == RMX_OFF) {
1253 if ((mode->hdisplay != native_mode->hdisplay) ||
1254 (mode->vdisplay != native_mode->vdisplay))
1255 return MODE_PANEL;
1256 }
1257 }
Alex Deucher5801ead2009-11-24 13:32:59 -05001258 return MODE_OK;
Alex Deucherd2917672011-05-20 04:34:31 -04001259 } else {
1260 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1261 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
1262 return radeon_dp_mode_valid_helper(connector, mode);
1263 else
1264 return MODE_OK;
1265 }
Alex Deucher5801ead2009-11-24 13:32:59 -05001266}
1267
Dave Airlie746c1aa2009-12-08 07:07:28 +10001268struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1269 .get_modes = radeon_dp_get_modes,
Alex Deucher5801ead2009-11-24 13:32:59 -05001270 .mode_valid = radeon_dp_mode_valid,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001271 .best_encoder = radeon_dvi_encoder,
1272};
1273
1274struct drm_connector_funcs radeon_dp_connector_funcs = {
1275 .dpms = drm_helper_connector_dpms,
1276 .detect = radeon_dp_detect,
1277 .fill_modes = drm_helper_probe_single_connector_modes,
1278 .set_property = radeon_connector_set_property,
Alex Deucherffd09c62009-11-24 16:13:23 -05001279 .destroy = radeon_dp_connector_destroy,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001280 .force = radeon_dvi_force,
1281};
1282
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001283void
1284radeon_add_atom_connector(struct drm_device *dev,
1285 uint32_t connector_id,
1286 uint32_t supported_device,
1287 int connector_type,
1288 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -05001289 uint32_t igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -05001290 uint16_t connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -04001291 struct radeon_hpd *hpd,
1292 struct radeon_router *router)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001293{
Dave Airlie445282d2009-09-09 17:40:54 +10001294 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001295 struct drm_connector *connector;
1296 struct radeon_connector *radeon_connector;
1297 struct radeon_connector_atom_dig *radeon_dig_connector;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001298 struct drm_encoder *encoder;
1299 struct radeon_encoder *radeon_encoder;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001300 uint32_t subpixel_order = SubPixelNone;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001301 bool shared_ddc = false;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001302 bool is_dp_bridge = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001303
Dave Airlie4ce001a2009-08-13 16:32:14 +10001304 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001305 return;
1306
Alex Deuchercf4c12f2010-09-01 17:15:06 -04001307 /* if the user selected tv=0 don't try and add the connector */
1308 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1309 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1310 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1311 (radeon_tv == 0))
1312 return;
1313
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001314 /* see if we already added it */
1315 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1316 radeon_connector = to_radeon_connector(connector);
1317 if (radeon_connector->connector_id == connector_id) {
1318 radeon_connector->devices |= supported_device;
1319 return;
1320 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001321 if (radeon_connector->ddc_bus && i2c_bus->valid) {
Alex Deucherd3932d62010-02-19 02:13:56 -05001322 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001323 radeon_connector->shared_ddc = true;
1324 shared_ddc = true;
1325 }
Alex Deucherfb939df2010-11-08 16:08:29 +00001326 if (radeon_connector->router_bus && router->ddc_valid &&
Alex Deucher26b5bc92010-08-05 21:21:18 -04001327 (radeon_connector->router.router_id == router->router_id)) {
1328 radeon_connector->shared_ddc = false;
1329 shared_ddc = false;
1330 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001331 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001332 }
1333
Alex Deuchereac4dff2011-05-20 04:34:22 -04001334 /* check if it's a dp bridge */
1335 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1336 radeon_encoder = to_radeon_encoder(encoder);
1337 if (radeon_encoder->devices & supported_device) {
1338 switch (radeon_encoder->encoder_id) {
1339 case ENCODER_OBJECT_ID_TRAVIS:
1340 case ENCODER_OBJECT_ID_NUTMEG:
1341 is_dp_bridge = true;
1342 break;
1343 default:
1344 break;
1345 }
1346 }
1347 }
1348
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001349 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1350 if (!radeon_connector)
1351 return;
1352
1353 connector = &radeon_connector->base;
1354
1355 radeon_connector->connector_id = connector_id;
1356 radeon_connector->devices = supported_device;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001357 radeon_connector->shared_ddc = shared_ddc;
Alex Deucherb75fad02009-11-05 13:16:01 -05001358 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05001359 radeon_connector->hpd = *hpd;
Alex Deucher26b5bc92010-08-05 21:21:18 -04001360 radeon_connector->router = *router;
Alex Deucherfb939df2010-11-08 16:08:29 +00001361 if (router->ddc_valid || router->cd_valid) {
Alex Deucher26b5bc92010-08-05 21:21:18 -04001362 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1363 if (!radeon_connector->router_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04001364 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
Alex Deucher26b5bc92010-08-05 21:21:18 -04001365 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001366
1367 if (is_dp_bridge) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001368 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1369 if (!radeon_dig_connector)
1370 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001371 radeon_dig_connector->igp_lane_info = igp_lane_info;
1372 radeon_connector->con_priv = radeon_dig_connector;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001373 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1374 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001375 if (i2c_bus->valid) {
Alex Deuchereac4dff2011-05-20 04:34:22 -04001376 /* add DP i2c bus */
1377 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1378 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1379 else
1380 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1381 if (!radeon_dig_connector->dp_i2c_bus)
1382 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
Alex Deucherf376b942010-08-05 21:21:16 -04001383 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001384 if (!radeon_connector->ddc_bus)
Alex Deuchereac4dff2011-05-20 04:34:22 -04001385 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001386 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001387 switch (connector_type) {
1388 case DRM_MODE_CONNECTOR_VGA:
1389 case DRM_MODE_CONNECTOR_DVIA:
1390 default:
1391 connector->interlace_allowed = true;
1392 connector->doublescan_allowed = true;
1393 break;
1394 case DRM_MODE_CONNECTOR_DVII:
1395 case DRM_MODE_CONNECTOR_DVID:
1396 case DRM_MODE_CONNECTOR_HDMIA:
1397 case DRM_MODE_CONNECTOR_HDMIB:
1398 case DRM_MODE_CONNECTOR_DisplayPort:
Alex Deucher430f70d2010-08-04 03:45:04 -04001399 drm_connector_attach_property(&radeon_connector->base,
1400 rdev->mode_info.underscan_property,
Alex Deucher56bec7c2011-01-05 11:57:52 -05001401 UNDERSCAN_OFF);
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001402 drm_connector_attach_property(&radeon_connector->base,
1403 rdev->mode_info.underscan_hborder_property,
1404 0);
1405 drm_connector_attach_property(&radeon_connector->base,
1406 rdev->mode_info.underscan_vborder_property,
1407 0);
Alex Deuchereac4dff2011-05-20 04:34:22 -04001408 subpixel_order = SubPixelHorizontalRGB;
1409 connector->interlace_allowed = true;
1410 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1411 connector->doublescan_allowed = true;
1412 else
1413 connector->doublescan_allowed = false;
1414 break;
1415 case DRM_MODE_CONNECTOR_LVDS:
1416 case DRM_MODE_CONNECTOR_eDP:
1417 drm_connector_attach_property(&radeon_connector->base,
1418 dev->mode_config.scaling_mode_property,
1419 DRM_MODE_SCALE_FULLSCREEN);
1420 subpixel_order = SubPixelHorizontalRGB;
1421 connector->interlace_allowed = false;
1422 connector->doublescan_allowed = false;
1423 break;
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001424 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001425 } else {
1426 switch (connector_type) {
1427 case DRM_MODE_CONNECTOR_VGA:
1428 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1429 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1430 if (i2c_bus->valid) {
1431 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1432 if (!radeon_connector->ddc_bus)
1433 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1434 }
Alex Deucher390d0bb2009-12-08 12:48:20 -05001435 radeon_connector->dac_load_detect = true;
1436 drm_connector_attach_property(&radeon_connector->base,
1437 rdev->mode_info.load_detect_property,
1438 1);
Alex Deuchereac4dff2011-05-20 04:34:22 -04001439 /* no HPD on analog connectors */
1440 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1441 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1442 connector->interlace_allowed = true;
Alex Deucherc49948f2010-11-30 15:46:47 -05001443 connector->doublescan_allowed = true;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001444 break;
1445 case DRM_MODE_CONNECTOR_DVIA:
1446 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1447 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1448 if (i2c_bus->valid) {
1449 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1450 if (!radeon_connector->ddc_bus)
1451 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1452 }
1453 radeon_connector->dac_load_detect = true;
Alex Deucher430f70d2010-08-04 03:45:04 -04001454 drm_connector_attach_property(&radeon_connector->base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001455 rdev->mode_info.load_detect_property,
1456 1);
1457 /* no HPD on analog connectors */
1458 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1459 connector->interlace_allowed = true;
Alex Deucherc49948f2010-11-30 15:46:47 -05001460 connector->doublescan_allowed = true;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001461 break;
1462 case DRM_MODE_CONNECTOR_DVII:
1463 case DRM_MODE_CONNECTOR_DVID:
1464 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1465 if (!radeon_dig_connector)
1466 goto failed;
1467 radeon_dig_connector->igp_lane_info = igp_lane_info;
1468 radeon_connector->con_priv = radeon_dig_connector;
1469 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1470 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1471 if (i2c_bus->valid) {
1472 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1473 if (!radeon_connector->ddc_bus)
1474 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1475 }
1476 subpixel_order = SubPixelHorizontalRGB;
1477 drm_connector_attach_property(&radeon_connector->base,
1478 rdev->mode_info.coherent_mode_property,
1479 1);
1480 if (ASIC_IS_AVIVO(rdev)) {
1481 drm_connector_attach_property(&radeon_connector->base,
1482 rdev->mode_info.underscan_property,
1483 UNDERSCAN_OFF);
1484 drm_connector_attach_property(&radeon_connector->base,
1485 rdev->mode_info.underscan_hborder_property,
1486 0);
1487 drm_connector_attach_property(&radeon_connector->base,
1488 rdev->mode_info.underscan_vborder_property,
1489 0);
1490 }
1491 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1492 radeon_connector->dac_load_detect = true;
1493 drm_connector_attach_property(&radeon_connector->base,
1494 rdev->mode_info.load_detect_property,
1495 1);
1496 }
1497 connector->interlace_allowed = true;
1498 if (connector_type == DRM_MODE_CONNECTOR_DVII)
1499 connector->doublescan_allowed = true;
1500 else
1501 connector->doublescan_allowed = false;
1502 break;
1503 case DRM_MODE_CONNECTOR_HDMIA:
1504 case DRM_MODE_CONNECTOR_HDMIB:
1505 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1506 if (!radeon_dig_connector)
1507 goto failed;
1508 radeon_dig_connector->igp_lane_info = igp_lane_info;
1509 radeon_connector->con_priv = radeon_dig_connector;
1510 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1511 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1512 if (i2c_bus->valid) {
1513 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1514 if (!radeon_connector->ddc_bus)
1515 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1516 }
1517 drm_connector_attach_property(&radeon_connector->base,
1518 rdev->mode_info.coherent_mode_property,
1519 1);
1520 if (ASIC_IS_AVIVO(rdev)) {
1521 drm_connector_attach_property(&radeon_connector->base,
1522 rdev->mode_info.underscan_property,
1523 UNDERSCAN_OFF);
1524 drm_connector_attach_property(&radeon_connector->base,
1525 rdev->mode_info.underscan_hborder_property,
1526 0);
1527 drm_connector_attach_property(&radeon_connector->base,
1528 rdev->mode_info.underscan_vborder_property,
1529 0);
1530 }
1531 subpixel_order = SubPixelHorizontalRGB;
1532 connector->interlace_allowed = true;
1533 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1534 connector->doublescan_allowed = true;
1535 else
1536 connector->doublescan_allowed = false;
1537 break;
1538 case DRM_MODE_CONNECTOR_DisplayPort:
1539 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1540 if (!radeon_dig_connector)
1541 goto failed;
1542 radeon_dig_connector->igp_lane_info = igp_lane_info;
1543 radeon_connector->con_priv = radeon_dig_connector;
1544 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1545 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1546 if (i2c_bus->valid) {
1547 /* add DP i2c bus */
1548 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1549 if (!radeon_dig_connector->dp_i2c_bus)
1550 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1551 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1552 if (!radeon_connector->ddc_bus)
1553 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1554 }
1555 subpixel_order = SubPixelHorizontalRGB;
1556 drm_connector_attach_property(&radeon_connector->base,
1557 rdev->mode_info.coherent_mode_property,
1558 1);
1559 if (ASIC_IS_AVIVO(rdev)) {
1560 drm_connector_attach_property(&radeon_connector->base,
1561 rdev->mode_info.underscan_property,
1562 UNDERSCAN_OFF);
1563 drm_connector_attach_property(&radeon_connector->base,
1564 rdev->mode_info.underscan_hborder_property,
1565 0);
1566 drm_connector_attach_property(&radeon_connector->base,
1567 rdev->mode_info.underscan_vborder_property,
1568 0);
1569 }
1570 connector->interlace_allowed = true;
1571 /* in theory with a DP to VGA converter... */
Alex Deucherc49948f2010-11-30 15:46:47 -05001572 connector->doublescan_allowed = false;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001573 break;
1574 case DRM_MODE_CONNECTOR_eDP:
1575 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1576 if (!radeon_dig_connector)
1577 goto failed;
1578 radeon_dig_connector->igp_lane_info = igp_lane_info;
1579 radeon_connector->con_priv = radeon_dig_connector;
1580 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1581 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1582 if (i2c_bus->valid) {
1583 /* add DP i2c bus */
1584 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1585 if (!radeon_dig_connector->dp_i2c_bus)
1586 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1587 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1588 if (!radeon_connector->ddc_bus)
1589 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1590 }
Alex Deucher430f70d2010-08-04 03:45:04 -04001591 drm_connector_attach_property(&radeon_connector->base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001592 dev->mode_config.scaling_mode_property,
1593 DRM_MODE_SCALE_FULLSCREEN);
1594 subpixel_order = SubPixelHorizontalRGB;
1595 connector->interlace_allowed = false;
1596 connector->doublescan_allowed = false;
1597 break;
1598 case DRM_MODE_CONNECTOR_SVIDEO:
1599 case DRM_MODE_CONNECTOR_Composite:
1600 case DRM_MODE_CONNECTOR_9PinDIN:
1601 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1602 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1603 radeon_connector->dac_load_detect = true;
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001604 drm_connector_attach_property(&radeon_connector->base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001605 rdev->mode_info.load_detect_property,
1606 1);
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001607 drm_connector_attach_property(&radeon_connector->base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001608 rdev->mode_info.tv_std_property,
1609 radeon_atombios_get_tv_info(rdev));
1610 /* no HPD on analog connectors */
1611 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1612 connector->interlace_allowed = false;
1613 connector->doublescan_allowed = false;
1614 break;
1615 case DRM_MODE_CONNECTOR_LVDS:
1616 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1617 if (!radeon_dig_connector)
1618 goto failed;
1619 radeon_dig_connector->igp_lane_info = igp_lane_info;
1620 radeon_connector->con_priv = radeon_dig_connector;
1621 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1622 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1623 if (i2c_bus->valid) {
1624 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1625 if (!radeon_connector->ddc_bus)
1626 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1627 }
1628 drm_connector_attach_property(&radeon_connector->base,
1629 dev->mode_config.scaling_mode_property,
1630 DRM_MODE_SCALE_FULLSCREEN);
1631 subpixel_order = SubPixelHorizontalRGB;
1632 connector->interlace_allowed = false;
1633 connector->doublescan_allowed = false;
1634 break;
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001635 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001636 }
1637
Alex Deucher2581afc2010-07-20 03:24:11 -04001638 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001639 if (i2c_bus->valid)
1640 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1641 } else
1642 connector->polled = DRM_CONNECTOR_POLL_HPD;
1643
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001644 connector->display_info.subpixel_order = subpixel_order;
1645 drm_sysfs_connector_add(connector);
1646 return;
1647
1648failed:
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001649 drm_connector_cleanup(connector);
1650 kfree(connector);
1651}
1652
1653void
1654radeon_add_legacy_connector(struct drm_device *dev,
1655 uint32_t connector_id,
1656 uint32_t supported_device,
1657 int connector_type,
Alex Deucherb75fad02009-11-05 13:16:01 -05001658 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -05001659 uint16_t connector_object_id,
1660 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001661{
Dave Airlie445282d2009-09-09 17:40:54 +10001662 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001663 struct drm_connector *connector;
1664 struct radeon_connector *radeon_connector;
1665 uint32_t subpixel_order = SubPixelNone;
1666
Dave Airlie4ce001a2009-08-13 16:32:14 +10001667 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001668 return;
1669
Alex Deuchercf4c12f2010-09-01 17:15:06 -04001670 /* if the user selected tv=0 don't try and add the connector */
1671 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1672 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1673 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1674 (radeon_tv == 0))
1675 return;
1676
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001677 /* see if we already added it */
1678 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1679 radeon_connector = to_radeon_connector(connector);
1680 if (radeon_connector->connector_id == connector_id) {
1681 radeon_connector->devices |= supported_device;
1682 return;
1683 }
1684 }
1685
1686 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1687 if (!radeon_connector)
1688 return;
1689
1690 connector = &radeon_connector->base;
1691
1692 radeon_connector->connector_id = connector_id;
1693 radeon_connector->devices = supported_device;
Alex Deucherb75fad02009-11-05 13:16:01 -05001694 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05001695 radeon_connector->hpd = *hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001696 switch (connector_type) {
1697 case DRM_MODE_CONNECTOR_VGA:
1698 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001699 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001700 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001701 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001702 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04001703 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001704 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001705 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001706 drm_connector_attach_property(&radeon_connector->base,
1707 rdev->mode_info.load_detect_property,
1708 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04001709 /* no HPD on analog connectors */
1710 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001711 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
Alex Deucherc49948f2010-11-30 15:46:47 -05001712 connector->interlace_allowed = true;
1713 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001714 break;
1715 case DRM_MODE_CONNECTOR_DVIA:
1716 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001717 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001718 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001719 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001720 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04001721 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001722 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001723 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001724 drm_connector_attach_property(&radeon_connector->base,
1725 rdev->mode_info.load_detect_property,
1726 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04001727 /* no HPD on analog connectors */
1728 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05001729 connector->interlace_allowed = true;
1730 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001731 break;
1732 case DRM_MODE_CONNECTOR_DVII:
1733 case DRM_MODE_CONNECTOR_DVID:
1734 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001735 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001736 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001737 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001738 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04001739 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Alex Deucher68b3adb2010-04-30 12:37:31 -04001740 }
1741 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001742 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001743 drm_connector_attach_property(&radeon_connector->base,
1744 rdev->mode_info.load_detect_property,
1745 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001746 }
1747 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05001748 connector->interlace_allowed = true;
1749 if (connector_type == DRM_MODE_CONNECTOR_DVII)
1750 connector->doublescan_allowed = true;
1751 else
1752 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001753 break;
1754 case DRM_MODE_CONNECTOR_SVIDEO:
1755 case DRM_MODE_CONNECTOR_Composite:
1756 case DRM_MODE_CONNECTOR_9PinDIN:
Alex Deuchercf4c12f2010-09-01 17:15:06 -04001757 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1758 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1759 radeon_connector->dac_load_detect = true;
1760 /* RS400,RC410,RS480 chipset seems to report a lot
1761 * of false positive on load detect, we haven't yet
1762 * found a way to make load detect reliable on those
1763 * chipset, thus just disable it for TV.
1764 */
1765 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1766 radeon_connector->dac_load_detect = false;
1767 drm_connector_attach_property(&radeon_connector->base,
1768 rdev->mode_info.load_detect_property,
1769 radeon_connector->dac_load_detect);
1770 drm_connector_attach_property(&radeon_connector->base,
1771 rdev->mode_info.tv_std_property,
1772 radeon_combios_get_tv_info(rdev));
1773 /* no HPD on analog connectors */
1774 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05001775 connector->interlace_allowed = false;
1776 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001777 break;
1778 case DRM_MODE_CONNECTOR_LVDS:
1779 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001780 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001781 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001782 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001783 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04001784 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001785 }
Dave Airlie445282d2009-09-09 17:40:54 +10001786 drm_connector_attach_property(&radeon_connector->base,
1787 dev->mode_config.scaling_mode_property,
1788 DRM_MODE_SCALE_FULLSCREEN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001789 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05001790 connector->interlace_allowed = false;
1791 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001792 break;
1793 }
1794
Alex Deucher2581afc2010-07-20 03:24:11 -04001795 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001796 if (i2c_bus->valid)
1797 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1798 } else
1799 connector->polled = DRM_CONNECTOR_POLL_HPD;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001800 connector->display_info.subpixel_order = subpixel_order;
1801 drm_sysfs_connector_add(connector);
Michel Dänzer63ec0112011-03-22 16:30:23 -07001802 if (connector_type == DRM_MODE_CONNECTOR_LVDS) {
1803 struct drm_encoder *drm_encoder;
1804
1805 list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) {
1806 struct radeon_encoder *radeon_encoder;
1807
1808 radeon_encoder = to_radeon_encoder(drm_encoder);
1809 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_LVDS)
1810 radeon_legacy_backlight_init(radeon_encoder, connector);
1811 }
1812 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001813}