blob: 28c7961cd19bc986540dd0b0413dba2f5bc94ffe [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
53 if (radeon_connector->hpd.hpd != RADEON_HPD_NONE)
54 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
55
Alex Deucher196c58d2010-01-07 14:22:32 -050056 if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
57 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
58 if ((radeon_dp_getsinktype(radeon_connector) == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
59 (radeon_dp_getsinktype(radeon_connector) == CONNECTOR_OBJECT_ID_eDP)) {
Alex Deucherd4877cf2009-12-04 16:56:37 -050060 if (radeon_dp_needs_link_train(radeon_connector)) {
61 if (connector->encoder)
62 dp_link_train(connector->encoder, connector);
63 }
64 }
65 }
66
67}
68
Dave Airlie445282d2009-09-09 17:40:54 +100069static void radeon_property_change_mode(struct drm_encoder *encoder)
70{
71 struct drm_crtc *crtc = encoder->crtc;
72
73 if (crtc && crtc->enabled) {
74 drm_crtc_helper_set_mode(crtc, &crtc->mode,
75 crtc->x, crtc->y, crtc->fb);
76 }
77}
Jerome Glisse771fe6b2009-06-05 14:42:42 +020078static void
79radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
80{
81 struct drm_device *dev = connector->dev;
82 struct radeon_device *rdev = dev->dev_private;
83 struct drm_encoder *best_encoder = NULL;
84 struct drm_encoder *encoder = NULL;
85 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
86 struct drm_mode_object *obj;
87 bool connected;
88 int i;
89
90 best_encoder = connector_funcs->best_encoder(connector);
91
92 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
93 if (connector->encoder_ids[i] == 0)
94 break;
95
96 obj = drm_mode_object_find(connector->dev,
97 connector->encoder_ids[i],
98 DRM_MODE_OBJECT_ENCODER);
99 if (!obj)
100 continue;
101
102 encoder = obj_to_encoder(obj);
103
104 if ((encoder == best_encoder) && (status == connector_status_connected))
105 connected = true;
106 else
107 connected = false;
108
109 if (rdev->is_atom_bios)
110 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
111 else
112 radeon_combios_connected_scratch_regs(connector, encoder, connected);
113
114 }
115}
116
Dave Airlie445282d2009-09-09 17:40:54 +1000117struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
118{
119 struct drm_mode_object *obj;
120 struct drm_encoder *encoder;
121 int i;
122
123 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
124 if (connector->encoder_ids[i] == 0)
125 break;
126
127 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
128 if (!obj)
129 continue;
130
131 encoder = obj_to_encoder(obj);
132 if (encoder->encoder_type == encoder_type)
133 return encoder;
134 }
135 return NULL;
136}
137
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200138struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
139{
140 int enc_id = connector->encoder_ids[0];
141 struct drm_mode_object *obj;
142 struct drm_encoder *encoder;
143
144 /* pick the encoder ids */
145 if (enc_id) {
146 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
147 if (!obj)
148 return NULL;
149 encoder = obj_to_encoder(obj);
150 return encoder;
151 }
152 return NULL;
153}
154
Dave Airlie4ce001a2009-08-13 16:32:14 +1000155/*
156 * radeon_connector_analog_encoder_conflict_solve
157 * - search for other connectors sharing this encoder
158 * if priority is true, then set them disconnected if this is connected
159 * if priority is false, set us disconnected if they are connected
160 */
161static enum drm_connector_status
162radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
163 struct drm_encoder *encoder,
164 enum drm_connector_status current_status,
165 bool priority)
166{
167 struct drm_device *dev = connector->dev;
168 struct drm_connector *conflict;
Alex Deucher08d07512010-04-15 13:31:12 -0400169 struct radeon_connector *radeon_conflict;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000170 int i;
171
172 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
173 if (conflict == connector)
174 continue;
175
Alex Deucher08d07512010-04-15 13:31:12 -0400176 radeon_conflict = to_radeon_connector(conflict);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000177 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
178 if (conflict->encoder_ids[i] == 0)
179 break;
180
181 /* if the IDs match */
182 if (conflict->encoder_ids[i] == encoder->base.id) {
183 if (conflict->status != connector_status_connected)
184 continue;
185
Alex Deucher08d07512010-04-15 13:31:12 -0400186 if (radeon_conflict->use_digital)
187 continue;
188
Dave Airlie4ce001a2009-08-13 16:32:14 +1000189 if (priority == true) {
Alex Deucherc5d46b42010-10-29 13:49:25 -0400190 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
191 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(connector));
Dave Airlie4ce001a2009-08-13 16:32:14 +1000192 conflict->status = connector_status_disconnected;
193 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
194 } else {
Alex Deucherc5d46b42010-10-29 13:49:25 -0400195 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
196 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(conflict));
Dave Airlie4ce001a2009-08-13 16:32:14 +1000197 current_status = connector_status_disconnected;
198 }
199 break;
200 }
201 }
202 }
203 return current_status;
204
205}
206
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200207static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
208{
209 struct drm_device *dev = encoder->dev;
210 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
211 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400212 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200213
Alex Deucherde2103e2009-10-09 15:14:30 -0400214 if (native_mode->hdisplay != 0 &&
215 native_mode->vdisplay != 0 &&
216 native_mode->clock != 0) {
Alex Deucherfb06ca8f2009-10-12 11:25:05 -0400217 mode = drm_mode_duplicate(dev, native_mode);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200218 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
219 drm_mode_set_name(mode);
220
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000221 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
Alex Deucherd2efdf62009-12-22 10:06:49 -0500222 } else if (native_mode->hdisplay != 0 &&
223 native_mode->vdisplay != 0) {
224 /* mac laptops without an edid */
225 /* Note that this is not necessarily the exact panel mode,
226 * but an approximation based on the cvt formula. For these
227 * systems we should ideally read the mode info out of the
228 * registers or add a mode table, but this works and is much
229 * simpler.
230 */
231 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
232 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000233 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200234 }
235 return mode;
236}
237
Alex Deucher923f6842009-09-10 17:53:39 -0400238static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
239{
240 struct drm_device *dev = encoder->dev;
241 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
242 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400243 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400244 int i;
245 struct mode_size {
246 int w;
247 int h;
248 } common_modes[17] = {
249 { 640, 480},
250 { 720, 480},
251 { 800, 600},
252 { 848, 480},
253 {1024, 768},
254 {1152, 768},
255 {1280, 720},
256 {1280, 800},
257 {1280, 854},
258 {1280, 960},
259 {1280, 1024},
260 {1440, 900},
261 {1400, 1050},
262 {1680, 1050},
263 {1600, 1200},
264 {1920, 1080},
265 {1920, 1200}
266 };
267
268 for (i = 0; i < 17; i++) {
Alex Deucherdfdd6462009-10-13 12:48:44 -0400269 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
270 if (common_modes[i].w > 1024 ||
271 common_modes[i].h > 768)
272 continue;
273 }
Alex Deucher923f6842009-09-10 17:53:39 -0400274 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400275 if (common_modes[i].w > native_mode->hdisplay ||
276 common_modes[i].h > native_mode->vdisplay ||
277 (common_modes[i].w == native_mode->hdisplay &&
278 common_modes[i].h == native_mode->vdisplay))
Alex Deucher923f6842009-09-10 17:53:39 -0400279 continue;
280 }
281 if (common_modes[i].w < 320 || common_modes[i].h < 200)
282 continue;
283
Dave Airlied50ba252009-09-23 14:44:08 +1000284 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400285 drm_mode_probed_add(connector, mode);
286 }
287}
288
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200289int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
290 uint64_t val)
291{
Dave Airlie445282d2009-09-09 17:40:54 +1000292 struct drm_device *dev = connector->dev;
293 struct radeon_device *rdev = dev->dev_private;
294 struct drm_encoder *encoder;
295 struct radeon_encoder *radeon_encoder;
296
297 if (property == rdev->mode_info.coherent_mode_property) {
298 struct radeon_encoder_atom_dig *dig;
Dave Airliece227c42010-04-09 06:27:00 +0000299 bool new_coherent_mode;
Dave Airlie445282d2009-09-09 17:40:54 +1000300
301 /* need to find digital encoder on connector */
302 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
303 if (!encoder)
304 return 0;
305
306 radeon_encoder = to_radeon_encoder(encoder);
307
308 if (!radeon_encoder->enc_priv)
309 return 0;
310
311 dig = radeon_encoder->enc_priv;
Dave Airliece227c42010-04-09 06:27:00 +0000312 new_coherent_mode = val ? true : false;
313 if (dig->coherent_mode != new_coherent_mode) {
314 dig->coherent_mode = new_coherent_mode;
315 radeon_property_change_mode(&radeon_encoder->base);
316 }
Dave Airlie445282d2009-09-09 17:40:54 +1000317 }
318
Alex Deucher5b1714d2010-08-03 19:59:20 -0400319 if (property == rdev->mode_info.underscan_property) {
320 /* need to find digital encoder on connector */
321 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
322 if (!encoder)
323 return 0;
324
325 radeon_encoder = to_radeon_encoder(encoder);
326
327 if (radeon_encoder->underscan_type != val) {
328 radeon_encoder->underscan_type = val;
329 radeon_property_change_mode(&radeon_encoder->base);
330 }
331 }
332
Marius Gröger5bccf5e2010-09-21 21:30:59 +0200333 if (property == rdev->mode_info.underscan_hborder_property) {
334 /* need to find digital encoder on connector */
335 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
336 if (!encoder)
337 return 0;
338
339 radeon_encoder = to_radeon_encoder(encoder);
340
341 if (radeon_encoder->underscan_hborder != val) {
342 radeon_encoder->underscan_hborder = val;
343 radeon_property_change_mode(&radeon_encoder->base);
344 }
345 }
346
347 if (property == rdev->mode_info.underscan_vborder_property) {
348 /* need to find digital encoder on connector */
349 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
350 if (!encoder)
351 return 0;
352
353 radeon_encoder = to_radeon_encoder(encoder);
354
355 if (radeon_encoder->underscan_vborder != val) {
356 radeon_encoder->underscan_vborder = val;
357 radeon_property_change_mode(&radeon_encoder->base);
358 }
359 }
360
Dave Airlie445282d2009-09-09 17:40:54 +1000361 if (property == rdev->mode_info.tv_std_property) {
362 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
363 if (!encoder) {
364 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
365 }
366
367 if (!encoder)
368 return 0;
369
370 radeon_encoder = to_radeon_encoder(encoder);
371 if (!radeon_encoder->enc_priv)
372 return 0;
Alex Deucher643acac2010-04-05 23:57:52 -0400373 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
Dave Airlie445282d2009-09-09 17:40:54 +1000374 struct radeon_encoder_atom_dac *dac_int;
375 dac_int = radeon_encoder->enc_priv;
376 dac_int->tv_std = val;
377 } else {
378 struct radeon_encoder_tv_dac *dac_int;
379 dac_int = radeon_encoder->enc_priv;
380 dac_int->tv_std = val;
381 }
382 radeon_property_change_mode(&radeon_encoder->base);
383 }
384
385 if (property == rdev->mode_info.load_detect_property) {
386 struct radeon_connector *radeon_connector =
387 to_radeon_connector(connector);
388
389 if (val == 0)
390 radeon_connector->dac_load_detect = false;
391 else
392 radeon_connector->dac_load_detect = true;
393 }
394
395 if (property == rdev->mode_info.tmds_pll_property) {
396 struct radeon_encoder_int_tmds *tmds = NULL;
397 bool ret = false;
398 /* need to find digital encoder on connector */
399 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
400 if (!encoder)
401 return 0;
402
403 radeon_encoder = to_radeon_encoder(encoder);
404
405 tmds = radeon_encoder->enc_priv;
406 if (!tmds)
407 return 0;
408
409 if (val == 0) {
410 if (rdev->is_atom_bios)
411 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
412 else
413 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
414 }
415 if (val == 1 || ret == false) {
416 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
417 }
418 radeon_property_change_mode(&radeon_encoder->base);
419 }
420
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200421 return 0;
422}
423
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200424static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
425 struct drm_connector *connector)
426{
427 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400428 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200429
430 /* Try to get native mode details from EDID if necessary */
Alex Deucherde2103e2009-10-09 15:14:30 -0400431 if (!native_mode->clock) {
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200432 struct drm_display_mode *t, *mode;
433
434 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400435 if (mode->hdisplay == native_mode->hdisplay &&
436 mode->vdisplay == native_mode->vdisplay) {
437 *native_mode = *mode;
438 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
Alex Deucherc5d46b42010-10-29 13:49:25 -0400439 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200440 break;
441 }
442 }
443 }
Alex Deucherde2103e2009-10-09 15:14:30 -0400444 if (!native_mode->clock) {
Alex Deucherc5d46b42010-10-29 13:49:25 -0400445 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200446 radeon_encoder->rmx_type = RMX_OFF;
447 }
448}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200449
450static int radeon_lvds_get_modes(struct drm_connector *connector)
451{
452 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
453 struct drm_encoder *encoder;
454 int ret = 0;
455 struct drm_display_mode *mode;
456
457 if (radeon_connector->ddc_bus) {
458 ret = radeon_ddc_get_modes(radeon_connector);
459 if (ret > 0) {
Alex Deucher7747b712009-09-11 11:15:43 -0400460 encoder = radeon_best_single_encoder(connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200461 if (encoder) {
462 radeon_fixup_lvds_native_mode(encoder, connector);
Alex Deucher7747b712009-09-11 11:15:43 -0400463 /* add scaled modes */
464 radeon_add_common_modes(encoder, connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200465 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200466 return ret;
467 }
468 }
469
470 encoder = radeon_best_single_encoder(connector);
471 if (!encoder)
472 return 0;
473
474 /* we have no EDID modes */
475 mode = radeon_fp_native_mode(encoder);
476 if (mode) {
477 ret = 1;
478 drm_mode_probed_add(connector, mode);
Alex Deucher7a868e12010-12-08 22:13:05 -0500479 /* add the width/height from vbios tables if available */
480 connector->display_info.width_mm = mode->width_mm;
481 connector->display_info.height_mm = mode->height_mm;
Alex Deucher7747b712009-09-11 11:15:43 -0400482 /* add scaled modes */
483 radeon_add_common_modes(encoder, connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200484 }
Alex Deucher923f6842009-09-10 17:53:39 -0400485
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200486 return ret;
487}
488
489static int radeon_lvds_mode_valid(struct drm_connector *connector,
490 struct drm_display_mode *mode)
491{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500492 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
493
494 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
495 return MODE_PANEL;
496
497 if (encoder) {
498 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
499 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
500
501 /* AVIVO hardware supports downscaling modes larger than the panel
502 * to the panel size, but I'm not sure this is desirable.
503 */
504 if ((mode->hdisplay > native_mode->hdisplay) ||
505 (mode->vdisplay > native_mode->vdisplay))
506 return MODE_PANEL;
507
508 /* if scaling is disabled, block non-native modes */
509 if (radeon_encoder->rmx_type == RMX_OFF) {
510 if ((mode->hdisplay != native_mode->hdisplay) ||
511 (mode->vdisplay != native_mode->vdisplay))
512 return MODE_PANEL;
513 }
514 }
515
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200516 return MODE_OK;
517}
518
Chris Wilson7b334fc2010-09-09 23:51:02 +0100519static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100520radeon_lvds_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200521{
Alex Deucher0549a0612009-10-09 18:41:19 -0400522 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher2ffb8422009-10-08 13:02:19 -0400523 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Alex Deucher0549a0612009-10-09 18:41:19 -0400524 enum drm_connector_status ret = connector_status_disconnected;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400525
526 if (encoder) {
527 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400528 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400529
530 /* check if panel is valid */
Alex Deucherde2103e2009-10-09 15:14:30 -0400531 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
Alex Deucher2ffb8422009-10-08 13:02:19 -0400532 ret = connector_status_connected;
533
534 }
Alex Deucher0549a0612009-10-09 18:41:19 -0400535
536 /* check for edid as well */
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400537 if (radeon_connector->edid)
538 ret = connector_status_connected;
539 else {
540 if (radeon_connector->ddc_bus) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400541 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
542 &radeon_connector->ddc_bus->adapter);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400543 if (radeon_connector->edid)
544 ret = connector_status_connected;
545 }
Alex Deucher0549a0612009-10-09 18:41:19 -0400546 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200547 /* check acpi lid status ??? */
Alex Deucher2ffb8422009-10-08 13:02:19 -0400548
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200549 radeon_connector_update_scratch_regs(connector, ret);
550 return ret;
551}
552
553static void radeon_connector_destroy(struct drm_connector *connector)
554{
555 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
556
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400557 if (radeon_connector->edid)
558 kfree(radeon_connector->edid);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200559 kfree(radeon_connector->con_priv);
560 drm_sysfs_connector_remove(connector);
561 drm_connector_cleanup(connector);
562 kfree(connector);
563}
564
Dave Airlie445282d2009-09-09 17:40:54 +1000565static int radeon_lvds_set_property(struct drm_connector *connector,
566 struct drm_property *property,
567 uint64_t value)
568{
569 struct drm_device *dev = connector->dev;
570 struct radeon_encoder *radeon_encoder;
571 enum radeon_rmx_type rmx_type;
572
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000573 DRM_DEBUG_KMS("\n");
Dave Airlie445282d2009-09-09 17:40:54 +1000574 if (property != dev->mode_config.scaling_mode_property)
575 return 0;
576
577 if (connector->encoder)
578 radeon_encoder = to_radeon_encoder(connector->encoder);
579 else {
580 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
581 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
582 }
583
584 switch (value) {
585 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
586 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
587 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
588 default:
589 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
590 }
591 if (radeon_encoder->rmx_type == rmx_type)
592 return 0;
593
594 radeon_encoder->rmx_type = rmx_type;
595
596 radeon_property_change_mode(&radeon_encoder->base);
597 return 0;
598}
599
600
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200601struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
602 .get_modes = radeon_lvds_get_modes,
603 .mode_valid = radeon_lvds_mode_valid,
604 .best_encoder = radeon_best_single_encoder,
605};
606
607struct drm_connector_funcs radeon_lvds_connector_funcs = {
608 .dpms = drm_helper_connector_dpms,
609 .detect = radeon_lvds_detect,
610 .fill_modes = drm_helper_probe_single_connector_modes,
611 .destroy = radeon_connector_destroy,
Dave Airlie445282d2009-09-09 17:40:54 +1000612 .set_property = radeon_lvds_set_property,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200613};
614
615static int radeon_vga_get_modes(struct drm_connector *connector)
616{
617 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
618 int ret;
619
620 ret = radeon_ddc_get_modes(radeon_connector);
621
622 return ret;
623}
624
625static int radeon_vga_mode_valid(struct drm_connector *connector,
626 struct drm_display_mode *mode)
627{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500628 /* XXX check mode bandwidth */
629 /* XXX verify against max DAC output frequency */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200630 return MODE_OK;
631}
632
Chris Wilson7b334fc2010-09-09 23:51:02 +0100633static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100634radeon_vga_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200635{
636 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
637 struct drm_encoder *encoder;
638 struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000639 bool dret = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200640 enum drm_connector_status ret = connector_status_disconnected;
641
Dave Airlie4ce001a2009-08-13 16:32:14 +1000642 encoder = radeon_best_single_encoder(connector);
643 if (!encoder)
644 ret = connector_status_disconnected;
645
Dave Airlieeb6b6d72010-02-25 13:44:04 +1000646 if (radeon_connector->ddc_bus)
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000647 dret = radeon_ddc_probe(radeon_connector);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400648 if (dret) {
649 if (radeon_connector->edid) {
650 kfree(radeon_connector->edid);
651 radeon_connector->edid = NULL;
652 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400653 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400654
655 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +0100656 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
657 drm_get_connector_name(connector));
658 ret = connector_status_connected;
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400659 } else {
660 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
661
662 /* some oems have boards with separate digital and analog connectors
663 * with a shared ddc line (often vga + hdmi)
664 */
665 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
666 kfree(radeon_connector->edid);
667 radeon_connector->edid = NULL;
668 ret = connector_status_disconnected;
669 } else
670 ret = connector_status_connected;
671 }
672 } else {
Dave Airliec3cceed2010-10-26 12:55:52 +1000673
674 /* if we aren't forcing don't do destructive polling */
675 if (!force)
676 return connector->status;
677
Darren Jenkinsd8a7f792009-12-30 12:22:55 +1100678 if (radeon_connector->dac_load_detect && encoder) {
Dave Airlie445282d2009-09-09 17:40:54 +1000679 encoder_funcs = encoder->helper_private;
680 ret = encoder_funcs->detect(encoder, connector);
681 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200682 }
683
Dave Airlie4ce001a2009-08-13 16:32:14 +1000684 if (ret == connector_status_connected)
685 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200686 radeon_connector_update_scratch_regs(connector, ret);
687 return ret;
688}
689
690struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
691 .get_modes = radeon_vga_get_modes,
692 .mode_valid = radeon_vga_mode_valid,
693 .best_encoder = radeon_best_single_encoder,
694};
695
696struct drm_connector_funcs radeon_vga_connector_funcs = {
697 .dpms = drm_helper_connector_dpms,
698 .detect = radeon_vga_detect,
699 .fill_modes = drm_helper_probe_single_connector_modes,
700 .destroy = radeon_connector_destroy,
701 .set_property = radeon_connector_set_property,
702};
703
Dave Airlie4ce001a2009-08-13 16:32:14 +1000704static int radeon_tv_get_modes(struct drm_connector *connector)
705{
706 struct drm_device *dev = connector->dev;
Alex Deucher923f6842009-09-10 17:53:39 -0400707 struct radeon_device *rdev = dev->dev_private;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000708 struct drm_display_mode *tv_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400709 struct drm_encoder *encoder;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000710
Alex Deucher923f6842009-09-10 17:53:39 -0400711 encoder = radeon_best_single_encoder(connector);
712 if (!encoder)
713 return 0;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000714
Alex Deucher923f6842009-09-10 17:53:39 -0400715 /* avivo chips can scale any mode */
716 if (rdev->family >= CHIP_RS600)
717 /* add scaled modes */
718 radeon_add_common_modes(encoder, connector);
719 else {
720 /* only 800x600 is supported right now on pre-avivo chips */
Dave Airlied50ba252009-09-23 14:44:08 +1000721 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400722 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
723 drm_mode_probed_add(connector, tv_mode);
724 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000725 return 1;
726}
727
728static int radeon_tv_mode_valid(struct drm_connector *connector,
729 struct drm_display_mode *mode)
730{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500731 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
732 return MODE_CLOCK_RANGE;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000733 return MODE_OK;
734}
735
Chris Wilson7b334fc2010-09-09 23:51:02 +0100736static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100737radeon_tv_detect(struct drm_connector *connector, bool force)
Dave Airlie4ce001a2009-08-13 16:32:14 +1000738{
739 struct drm_encoder *encoder;
740 struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie445282d2009-09-09 17:40:54 +1000741 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
742 enum drm_connector_status ret = connector_status_disconnected;
743
744 if (!radeon_connector->dac_load_detect)
745 return ret;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000746
747 encoder = radeon_best_single_encoder(connector);
748 if (!encoder)
749 ret = connector_status_disconnected;
750 else {
751 encoder_funcs = encoder->helper_private;
752 ret = encoder_funcs->detect(encoder, connector);
753 }
754 if (ret == connector_status_connected)
755 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
756 radeon_connector_update_scratch_regs(connector, ret);
757 return ret;
758}
759
760struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
761 .get_modes = radeon_tv_get_modes,
762 .mode_valid = radeon_tv_mode_valid,
763 .best_encoder = radeon_best_single_encoder,
764};
765
766struct drm_connector_funcs radeon_tv_connector_funcs = {
767 .dpms = drm_helper_connector_dpms,
768 .detect = radeon_tv_detect,
769 .fill_modes = drm_helper_probe_single_connector_modes,
770 .destroy = radeon_connector_destroy,
771 .set_property = radeon_connector_set_property,
772};
773
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200774static int radeon_dvi_get_modes(struct drm_connector *connector)
775{
776 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
777 int ret;
778
779 ret = radeon_ddc_get_modes(radeon_connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200780 return ret;
781}
782
Dave Airlie4ce001a2009-08-13 16:32:14 +1000783/*
784 * DVI is complicated
785 * Do a DDC probe, if DDC probe passes, get the full EDID so
786 * we can do analog/digital monitor detection at this point.
787 * If the monitor is an analog monitor or we got no DDC,
788 * we need to find the DAC encoder object for this connector.
789 * If we got no DDC, we do load detection on the DAC encoder object.
790 * If we got analog DDC or load detection passes on the DAC encoder
791 * we have to check if this analog encoder is shared with anyone else (TV)
792 * if its shared we have to set the other connector to disconnected.
793 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100794static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100795radeon_dvi_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200796{
797 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000798 struct drm_encoder *encoder = NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200799 struct drm_encoder_helper_funcs *encoder_funcs;
800 struct drm_mode_object *obj;
801 int i;
802 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000803 bool dret = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200804
Dave Airlieeb6b6d72010-02-25 13:44:04 +1000805 if (radeon_connector->ddc_bus)
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000806 dret = radeon_ddc_probe(radeon_connector);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000807 if (dret) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400808 if (radeon_connector->edid) {
809 kfree(radeon_connector->edid);
810 radeon_connector->edid = NULL;
811 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000812 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200813
Dave Airlie4ce001a2009-08-13 16:32:14 +1000814 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +0100815 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
816 drm_get_connector_name(connector));
Dave Airlie4ce001a2009-08-13 16:32:14 +1000817 } else {
818 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200819
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400820 /* some oems have boards with separate digital and analog connectors
821 * with a shared ddc line (often vga + hdmi)
822 */
823 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
824 kfree(radeon_connector->edid);
825 radeon_connector->edid = NULL;
826 ret = connector_status_disconnected;
827 } else
828 ret = connector_status_connected;
Alex Deucher71407c42009-11-17 15:44:01 -0500829
Alex Deucher42f14c42010-07-20 11:27:54 -0400830 /* This gets complicated. We have boards with VGA + HDMI with a
831 * shared DDC line and we have boards with DVI-D + HDMI with a shared
832 * DDC line. The latter is more complex because with DVI<->HDMI adapters
833 * you don't really know what's connected to which port as both are digital.
Alex Deucher71407c42009-11-17 15:44:01 -0500834 */
Alex Deucherd3932d62010-02-19 02:13:56 -0500835 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
Alex Deucher71407c42009-11-17 15:44:01 -0500836 struct drm_device *dev = connector->dev;
Alex Deucher42f14c42010-07-20 11:27:54 -0400837 struct radeon_device *rdev = dev->dev_private;
Alex Deucher71407c42009-11-17 15:44:01 -0500838 struct drm_connector *list_connector;
839 struct radeon_connector *list_radeon_connector;
840 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
841 if (connector == list_connector)
842 continue;
843 list_radeon_connector = to_radeon_connector(list_connector);
Alex Deucherb2ea4aa2010-07-01 10:34:56 -0400844 if (list_radeon_connector->shared_ddc &&
845 (list_radeon_connector->ddc_bus->rec.i2c_id ==
846 radeon_connector->ddc_bus->rec.i2c_id)) {
Alex Deucher42f14c42010-07-20 11:27:54 -0400847 /* cases where both connectors are digital */
848 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
849 /* hpd is our only option in this case */
850 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
Alex Deucher71407c42009-11-17 15:44:01 -0500851 kfree(radeon_connector->edid);
852 radeon_connector->edid = NULL;
853 ret = connector_status_disconnected;
854 }
855 }
856 }
857 }
858 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200859 }
860 }
861
Dave Airlie4ce001a2009-08-13 16:32:14 +1000862 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
863 goto out;
864
Dave Airliec3cceed2010-10-26 12:55:52 +1000865 if (!force) {
866 ret = connector->status;
867 goto out;
868 }
869
Dave Airlie4ce001a2009-08-13 16:32:14 +1000870 /* find analog encoder */
Dave Airlie445282d2009-09-09 17:40:54 +1000871 if (radeon_connector->dac_load_detect) {
872 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
873 if (connector->encoder_ids[i] == 0)
874 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000875
Dave Airlie445282d2009-09-09 17:40:54 +1000876 obj = drm_mode_object_find(connector->dev,
877 connector->encoder_ids[i],
878 DRM_MODE_OBJECT_ENCODER);
879 if (!obj)
880 continue;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000881
Dave Airlie445282d2009-09-09 17:40:54 +1000882 encoder = obj_to_encoder(obj);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000883
Dave Airlie445282d2009-09-09 17:40:54 +1000884 encoder_funcs = encoder->helper_private;
885 if (encoder_funcs->detect) {
886 if (ret != connector_status_connected) {
887 ret = encoder_funcs->detect(encoder, connector);
888 if (ret == connector_status_connected) {
889 radeon_connector->use_digital = false;
890 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000891 }
Dave Airlie445282d2009-09-09 17:40:54 +1000892 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000893 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000894 }
895 }
896
897 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
898 encoder) {
899 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
900 }
901
902out:
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200903 /* updated in get modes as well since we need to know if it's analog or digital */
904 radeon_connector_update_scratch_regs(connector, ret);
905 return ret;
906}
907
908/* okay need to be smart in here about which encoder to pick */
909struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
910{
911 int enc_id = connector->encoder_ids[0];
912 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
913 struct drm_mode_object *obj;
914 struct drm_encoder *encoder;
915 int i;
916 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
917 if (connector->encoder_ids[i] == 0)
918 break;
919
920 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
921 if (!obj)
922 continue;
923
924 encoder = obj_to_encoder(obj);
925
Dave Airlie4ce001a2009-08-13 16:32:14 +1000926 if (radeon_connector->use_digital == true) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200927 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
928 return encoder;
929 } else {
930 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
931 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
932 return encoder;
933 }
934 }
935
936 /* see if we have a default encoder TODO */
937
938 /* then check use digitial */
939 /* pick the first one */
940 if (enc_id) {
941 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
942 if (!obj)
943 return NULL;
944 encoder = obj_to_encoder(obj);
945 return encoder;
946 }
947 return NULL;
948}
949
Dave Airlied50ba252009-09-23 14:44:08 +1000950static void radeon_dvi_force(struct drm_connector *connector)
951{
952 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
953 if (connector->force == DRM_FORCE_ON)
954 radeon_connector->use_digital = false;
955 if (connector->force == DRM_FORCE_ON_DIGITAL)
956 radeon_connector->use_digital = true;
957}
958
Alex Deuchera3fa6322009-11-05 11:57:07 -0500959static int radeon_dvi_mode_valid(struct drm_connector *connector,
960 struct drm_display_mode *mode)
961{
Alex Deucher1b242032010-01-11 15:02:31 -0500962 struct drm_device *dev = connector->dev;
963 struct radeon_device *rdev = dev->dev_private;
Alex Deuchera3fa6322009-11-05 11:57:07 -0500964 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
965
966 /* XXX check mode bandwidth */
967
Alex Deucher1b242032010-01-11 15:02:31 -0500968 /* clocks over 135 MHz have heat issues with DVI on RV100 */
969 if (radeon_connector->use_digital &&
970 (rdev->family == CHIP_RV100) &&
971 (mode->clock > 135000))
972 return MODE_CLOCK_HIGH;
973
Alex Deuchera3fa6322009-11-05 11:57:07 -0500974 if (radeon_connector->use_digital && (mode->clock > 165000)) {
975 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
976 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
977 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
978 return MODE_OK;
Alex Deuchere1e84012011-03-02 10:21:05 -0500979 else if (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_A) {
980 if (ASIC_IS_DCE3(rdev)) {
981 /* HDMI 1.3+ supports max clock of 340 Mhz */
982 if (mode->clock > 340000)
983 return MODE_CLOCK_HIGH;
984 else
985 return MODE_OK;
986 } else
987 return MODE_CLOCK_HIGH;
988 } else
Alex Deuchera3fa6322009-11-05 11:57:07 -0500989 return MODE_CLOCK_HIGH;
990 }
991 return MODE_OK;
992}
993
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200994struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
995 .get_modes = radeon_dvi_get_modes,
Alex Deuchera3fa6322009-11-05 11:57:07 -0500996 .mode_valid = radeon_dvi_mode_valid,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200997 .best_encoder = radeon_dvi_encoder,
998};
999
1000struct drm_connector_funcs radeon_dvi_connector_funcs = {
1001 .dpms = drm_helper_connector_dpms,
1002 .detect = radeon_dvi_detect,
1003 .fill_modes = drm_helper_probe_single_connector_modes,
1004 .set_property = radeon_connector_set_property,
1005 .destroy = radeon_connector_destroy,
Dave Airlied50ba252009-09-23 14:44:08 +10001006 .force = radeon_dvi_force,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001007};
1008
Alex Deucherffd09c62009-11-24 16:13:23 -05001009static void radeon_dp_connector_destroy(struct drm_connector *connector)
1010{
1011 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1012 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1013
Alex Deucherffd09c62009-11-24 16:13:23 -05001014 if (radeon_connector->edid)
1015 kfree(radeon_connector->edid);
1016 if (radeon_dig_connector->dp_i2c_bus)
Alex Deucherac1aade2010-03-14 12:22:44 -04001017 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
Alex Deucherffd09c62009-11-24 16:13:23 -05001018 kfree(radeon_connector->con_priv);
1019 drm_sysfs_connector_remove(connector);
1020 drm_connector_cleanup(connector);
1021 kfree(connector);
1022}
1023
Dave Airlie746c1aa2009-12-08 07:07:28 +10001024static int radeon_dp_get_modes(struct drm_connector *connector)
1025{
1026 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher8b834852010-11-17 02:54:42 -05001027 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001028 int ret;
1029
Alex Deucher8b834852010-11-17 02:54:42 -05001030 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1031 if (!radeon_dig_connector->edp_on)
1032 atombios_set_edp_panel_power(connector,
1033 ATOM_TRANSMITTER_ACTION_POWER_ON);
1034 }
Dave Airlie746c1aa2009-12-08 07:07:28 +10001035 ret = radeon_ddc_get_modes(radeon_connector);
Alex Deucher8b834852010-11-17 02:54:42 -05001036 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1037 if (!radeon_dig_connector->edp_on)
1038 atombios_set_edp_panel_power(connector,
1039 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1040 }
1041
Dave Airlie746c1aa2009-12-08 07:07:28 +10001042 return ret;
1043}
1044
Chris Wilson7b334fc2010-09-09 23:51:02 +01001045static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +01001046radeon_dp_detect(struct drm_connector *connector, bool force)
Dave Airlie746c1aa2009-12-08 07:07:28 +10001047{
1048 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001049 enum drm_connector_status ret = connector_status_disconnected;
Alex Deucher4143e912009-11-23 18:02:35 -05001050 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001051
1052 if (radeon_connector->edid) {
1053 kfree(radeon_connector->edid);
1054 radeon_connector->edid = NULL;
1055 }
1056
Alex Deucher6f50eae2010-08-19 17:29:03 -04001057 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1058 /* eDP is always DP */
1059 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
Alex Deucher8b834852010-11-17 02:54:42 -05001060 if (!radeon_dig_connector->edp_on)
1061 atombios_set_edp_panel_power(connector,
1062 ATOM_TRANSMITTER_ACTION_POWER_ON);
Alex Deucher6f50eae2010-08-19 17:29:03 -04001063 if (radeon_dp_getdpcd(radeon_connector))
Alex Deucher9fa05c92009-11-27 13:01:46 -05001064 ret = connector_status_connected;
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 Deucher4143e912009-11-23 18:02:35 -05001068 } else {
Alex Deucher6f50eae2010-08-19 17:29:03 -04001069 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
1070 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1071 if (radeon_dp_getdpcd(radeon_connector))
1072 ret = connector_status_connected;
1073 } else {
1074 if (radeon_ddc_probe(radeon_connector))
1075 ret = connector_status_connected;
Alex Deucher4143e912009-11-23 18:02:35 -05001076 }
Dave Airlie746c1aa2009-12-08 07:07:28 +10001077 }
Alex Deucher4143e912009-11-23 18:02:35 -05001078
Alex Deucher30f44372010-08-21 11:09:14 -04001079 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001080 return ret;
1081}
1082
Alex Deucher5801ead2009-11-24 13:32:59 -05001083static int radeon_dp_mode_valid(struct drm_connector *connector,
1084 struct drm_display_mode *mode)
1085{
1086 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1087 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1088
1089 /* XXX check mode bandwidth */
1090
Alex Deucher196c58d2010-01-07 14:22:32 -05001091 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1092 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
Alex Deucher5801ead2009-11-24 13:32:59 -05001093 return radeon_dp_mode_valid_helper(radeon_connector, mode);
1094 else
1095 return MODE_OK;
1096}
1097
Dave Airlie746c1aa2009-12-08 07:07:28 +10001098struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1099 .get_modes = radeon_dp_get_modes,
Alex Deucher5801ead2009-11-24 13:32:59 -05001100 .mode_valid = radeon_dp_mode_valid,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001101 .best_encoder = radeon_dvi_encoder,
1102};
1103
1104struct drm_connector_funcs radeon_dp_connector_funcs = {
1105 .dpms = drm_helper_connector_dpms,
1106 .detect = radeon_dp_detect,
1107 .fill_modes = drm_helper_probe_single_connector_modes,
1108 .set_property = radeon_connector_set_property,
Alex Deucherffd09c62009-11-24 16:13:23 -05001109 .destroy = radeon_dp_connector_destroy,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001110 .force = radeon_dvi_force,
1111};
1112
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001113void
1114radeon_add_atom_connector(struct drm_device *dev,
1115 uint32_t connector_id,
1116 uint32_t supported_device,
1117 int connector_type,
1118 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -05001119 uint32_t igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -05001120 uint16_t connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -04001121 struct radeon_hpd *hpd,
1122 struct radeon_router *router)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001123{
Dave Airlie445282d2009-09-09 17:40:54 +10001124 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001125 struct drm_connector *connector;
1126 struct radeon_connector *radeon_connector;
1127 struct radeon_connector_atom_dig *radeon_dig_connector;
1128 uint32_t subpixel_order = SubPixelNone;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001129 bool shared_ddc = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001130
Dave Airlie4ce001a2009-08-13 16:32:14 +10001131 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001132 return;
1133
Alex Deuchercf4c12f2010-09-01 17:15:06 -04001134 /* if the user selected tv=0 don't try and add the connector */
1135 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1136 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1137 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1138 (radeon_tv == 0))
1139 return;
1140
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001141 /* see if we already added it */
1142 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1143 radeon_connector = to_radeon_connector(connector);
1144 if (radeon_connector->connector_id == connector_id) {
1145 radeon_connector->devices |= supported_device;
1146 return;
1147 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001148 if (radeon_connector->ddc_bus && i2c_bus->valid) {
Alex Deucherd3932d62010-02-19 02:13:56 -05001149 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001150 radeon_connector->shared_ddc = true;
1151 shared_ddc = true;
1152 }
Alex Deucherfb939df2010-11-08 16:08:29 +00001153 if (radeon_connector->router_bus && router->ddc_valid &&
Alex Deucher26b5bc92010-08-05 21:21:18 -04001154 (radeon_connector->router.router_id == router->router_id)) {
1155 radeon_connector->shared_ddc = false;
1156 shared_ddc = false;
1157 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001158 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001159 }
1160
1161 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1162 if (!radeon_connector)
1163 return;
1164
1165 connector = &radeon_connector->base;
1166
1167 radeon_connector->connector_id = connector_id;
1168 radeon_connector->devices = supported_device;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001169 radeon_connector->shared_ddc = shared_ddc;
Alex Deucherb75fad02009-11-05 13:16:01 -05001170 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05001171 radeon_connector->hpd = *hpd;
Alex Deucher26b5bc92010-08-05 21:21:18 -04001172 radeon_connector->router = *router;
Alex Deucherfb939df2010-11-08 16:08:29 +00001173 if (router->ddc_valid || router->cd_valid) {
Alex Deucher26b5bc92010-08-05 21:21:18 -04001174 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1175 if (!radeon_connector->router_bus)
1176 goto failed;
1177 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001178 switch (connector_type) {
1179 case DRM_MODE_CONNECTOR_VGA:
1180 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001181 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001182 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001183 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001184 if (!radeon_connector->ddc_bus)
1185 goto failed;
1186 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001187 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001188 drm_connector_attach_property(&radeon_connector->base,
1189 rdev->mode_info.load_detect_property,
1190 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04001191 /* no HPD on analog connectors */
1192 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001193 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
Alex Deucherc49948f2010-11-30 15:46:47 -05001194 connector->interlace_allowed = true;
1195 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001196 break;
1197 case DRM_MODE_CONNECTOR_DVIA:
1198 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001199 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001200 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001201 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001202 if (!radeon_connector->ddc_bus)
1203 goto failed;
1204 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001205 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001206 drm_connector_attach_property(&radeon_connector->base,
1207 rdev->mode_info.load_detect_property,
1208 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04001209 /* no HPD on analog connectors */
1210 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05001211 connector->interlace_allowed = true;
1212 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001213 break;
1214 case DRM_MODE_CONNECTOR_DVII:
1215 case DRM_MODE_CONNECTOR_DVID:
1216 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1217 if (!radeon_dig_connector)
1218 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001219 radeon_dig_connector->igp_lane_info = igp_lane_info;
1220 radeon_connector->con_priv = radeon_dig_connector;
1221 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001222 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001223 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001224 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001225 if (!radeon_connector->ddc_bus)
1226 goto failed;
1227 }
1228 subpixel_order = SubPixelHorizontalRGB;
Dave Airlie445282d2009-09-09 17:40:54 +10001229 drm_connector_attach_property(&radeon_connector->base,
1230 rdev->mode_info.coherent_mode_property,
1231 1);
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001232 if (ASIC_IS_AVIVO(rdev)) {
Alex Deucher430f70d2010-08-04 03:45:04 -04001233 drm_connector_attach_property(&radeon_connector->base,
1234 rdev->mode_info.underscan_property,
Alex Deucher56bec7c2011-01-05 11:57:52 -05001235 UNDERSCAN_OFF);
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001236 drm_connector_attach_property(&radeon_connector->base,
1237 rdev->mode_info.underscan_hborder_property,
1238 0);
1239 drm_connector_attach_property(&radeon_connector->base,
1240 rdev->mode_info.underscan_vborder_property,
1241 0);
1242 }
Alex Deucher390d0bb2009-12-08 12:48:20 -05001243 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1244 radeon_connector->dac_load_detect = true;
1245 drm_connector_attach_property(&radeon_connector->base,
1246 rdev->mode_info.load_detect_property,
1247 1);
1248 }
Alex Deucherc49948f2010-11-30 15:46:47 -05001249 connector->interlace_allowed = true;
1250 if (connector_type == DRM_MODE_CONNECTOR_DVII)
1251 connector->doublescan_allowed = true;
1252 else
1253 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001254 break;
1255 case DRM_MODE_CONNECTOR_HDMIA:
1256 case DRM_MODE_CONNECTOR_HDMIB:
1257 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1258 if (!radeon_dig_connector)
1259 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001260 radeon_dig_connector->igp_lane_info = igp_lane_info;
1261 radeon_connector->con_priv = radeon_dig_connector;
1262 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001263 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001264 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001265 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001266 if (!radeon_connector->ddc_bus)
1267 goto failed;
1268 }
Dave Airlie445282d2009-09-09 17:40:54 +10001269 drm_connector_attach_property(&radeon_connector->base,
1270 rdev->mode_info.coherent_mode_property,
1271 1);
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001272 if (ASIC_IS_AVIVO(rdev)) {
Alex Deucher430f70d2010-08-04 03:45:04 -04001273 drm_connector_attach_property(&radeon_connector->base,
1274 rdev->mode_info.underscan_property,
Alex Deucher56bec7c2011-01-05 11:57:52 -05001275 UNDERSCAN_OFF);
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001276 drm_connector_attach_property(&radeon_connector->base,
1277 rdev->mode_info.underscan_hborder_property,
1278 0);
1279 drm_connector_attach_property(&radeon_connector->base,
1280 rdev->mode_info.underscan_vborder_property,
1281 0);
1282 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001283 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05001284 connector->interlace_allowed = true;
1285 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1286 connector->doublescan_allowed = true;
1287 else
1288 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001289 break;
1290 case DRM_MODE_CONNECTOR_DisplayPort:
Alex Deucher196c58d2010-01-07 14:22:32 -05001291 case DRM_MODE_CONNECTOR_eDP:
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001292 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1293 if (!radeon_dig_connector)
1294 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001295 radeon_dig_connector->igp_lane_info = igp_lane_info;
1296 radeon_connector->con_priv = radeon_dig_connector;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001297 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001298 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001299 if (i2c_bus->valid) {
Alex Deucher390d0bb2009-12-08 12:48:20 -05001300 /* add DP i2c bus */
Alex Deucher196c58d2010-01-07 14:22:32 -05001301 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1302 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1303 else
1304 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
Alex Deucher390d0bb2009-12-08 12:48:20 -05001305 if (!radeon_dig_connector->dp_i2c_bus)
1306 goto failed;
Alex Deucherf376b942010-08-05 21:21:16 -04001307 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001308 if (!radeon_connector->ddc_bus)
1309 goto failed;
1310 }
1311 subpixel_order = SubPixelHorizontalRGB;
Alex Deucher390d0bb2009-12-08 12:48:20 -05001312 drm_connector_attach_property(&radeon_connector->base,
1313 rdev->mode_info.coherent_mode_property,
1314 1);
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001315 if (ASIC_IS_AVIVO(rdev)) {
Alex Deucher430f70d2010-08-04 03:45:04 -04001316 drm_connector_attach_property(&radeon_connector->base,
1317 rdev->mode_info.underscan_property,
Alex Deucher56bec7c2011-01-05 11:57:52 -05001318 UNDERSCAN_OFF);
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001319 drm_connector_attach_property(&radeon_connector->base,
1320 rdev->mode_info.underscan_hborder_property,
1321 0);
1322 drm_connector_attach_property(&radeon_connector->base,
1323 rdev->mode_info.underscan_vborder_property,
1324 0);
1325 }
Alex Deucherc49948f2010-11-30 15:46:47 -05001326 connector->interlace_allowed = true;
1327 /* in theory with a DP to VGA converter... */
1328 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001329 break;
1330 case DRM_MODE_CONNECTOR_SVIDEO:
1331 case DRM_MODE_CONNECTOR_Composite:
1332 case DRM_MODE_CONNECTOR_9PinDIN:
Alex Deuchercf4c12f2010-09-01 17:15:06 -04001333 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1334 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1335 radeon_connector->dac_load_detect = true;
1336 drm_connector_attach_property(&radeon_connector->base,
1337 rdev->mode_info.load_detect_property,
1338 1);
1339 drm_connector_attach_property(&radeon_connector->base,
1340 rdev->mode_info.tv_std_property,
1341 radeon_atombios_get_tv_info(rdev));
1342 /* no HPD on analog connectors */
1343 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05001344 connector->interlace_allowed = false;
1345 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001346 break;
1347 case DRM_MODE_CONNECTOR_LVDS:
1348 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1349 if (!radeon_dig_connector)
1350 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001351 radeon_dig_connector->igp_lane_info = igp_lane_info;
1352 radeon_connector->con_priv = radeon_dig_connector;
1353 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001354 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001355 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001356 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001357 if (!radeon_connector->ddc_bus)
1358 goto failed;
1359 }
Dave Airlie445282d2009-09-09 17:40:54 +10001360 drm_connector_attach_property(&radeon_connector->base,
1361 dev->mode_config.scaling_mode_property,
1362 DRM_MODE_SCALE_FULLSCREEN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001363 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05001364 connector->interlace_allowed = false;
1365 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001366 break;
1367 }
1368
Alex Deucher2581afc2010-07-20 03:24:11 -04001369 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001370 if (i2c_bus->valid)
1371 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1372 } else
1373 connector->polled = DRM_CONNECTOR_POLL_HPD;
1374
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001375 connector->display_info.subpixel_order = subpixel_order;
1376 drm_sysfs_connector_add(connector);
1377 return;
1378
1379failed:
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001380 drm_connector_cleanup(connector);
1381 kfree(connector);
1382}
1383
1384void
1385radeon_add_legacy_connector(struct drm_device *dev,
1386 uint32_t connector_id,
1387 uint32_t supported_device,
1388 int connector_type,
Alex Deucherb75fad02009-11-05 13:16:01 -05001389 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -05001390 uint16_t connector_object_id,
1391 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001392{
Dave Airlie445282d2009-09-09 17:40:54 +10001393 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001394 struct drm_connector *connector;
1395 struct radeon_connector *radeon_connector;
1396 uint32_t subpixel_order = SubPixelNone;
1397
Dave Airlie4ce001a2009-08-13 16:32:14 +10001398 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001399 return;
1400
Alex Deuchercf4c12f2010-09-01 17:15:06 -04001401 /* if the user selected tv=0 don't try and add the connector */
1402 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1403 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1404 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1405 (radeon_tv == 0))
1406 return;
1407
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001408 /* see if we already added it */
1409 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1410 radeon_connector = to_radeon_connector(connector);
1411 if (radeon_connector->connector_id == connector_id) {
1412 radeon_connector->devices |= supported_device;
1413 return;
1414 }
1415 }
1416
1417 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1418 if (!radeon_connector)
1419 return;
1420
1421 connector = &radeon_connector->base;
1422
1423 radeon_connector->connector_id = connector_id;
1424 radeon_connector->devices = supported_device;
Alex Deucherb75fad02009-11-05 13:16:01 -05001425 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05001426 radeon_connector->hpd = *hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001427 switch (connector_type) {
1428 case DRM_MODE_CONNECTOR_VGA:
1429 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001430 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001431 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001432 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001433 if (!radeon_connector->ddc_bus)
1434 goto failed;
1435 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001436 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001437 drm_connector_attach_property(&radeon_connector->base,
1438 rdev->mode_info.load_detect_property,
1439 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04001440 /* no HPD on analog connectors */
1441 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001442 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
Alex Deucherc49948f2010-11-30 15:46:47 -05001443 connector->interlace_allowed = true;
1444 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001445 break;
1446 case DRM_MODE_CONNECTOR_DVIA:
1447 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001448 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001449 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001450 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001451 if (!radeon_connector->ddc_bus)
1452 goto failed;
1453 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001454 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001455 drm_connector_attach_property(&radeon_connector->base,
1456 rdev->mode_info.load_detect_property,
1457 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04001458 /* no HPD on analog connectors */
1459 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05001460 connector->interlace_allowed = true;
1461 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001462 break;
1463 case DRM_MODE_CONNECTOR_DVII:
1464 case DRM_MODE_CONNECTOR_DVID:
1465 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001466 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001467 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001468 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001469 if (!radeon_connector->ddc_bus)
1470 goto failed;
Alex Deucher68b3adb2010-04-30 12:37:31 -04001471 }
1472 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001473 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001474 drm_connector_attach_property(&radeon_connector->base,
1475 rdev->mode_info.load_detect_property,
1476 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001477 }
1478 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05001479 connector->interlace_allowed = true;
1480 if (connector_type == DRM_MODE_CONNECTOR_DVII)
1481 connector->doublescan_allowed = true;
1482 else
1483 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001484 break;
1485 case DRM_MODE_CONNECTOR_SVIDEO:
1486 case DRM_MODE_CONNECTOR_Composite:
1487 case DRM_MODE_CONNECTOR_9PinDIN:
Alex Deuchercf4c12f2010-09-01 17:15:06 -04001488 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1489 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1490 radeon_connector->dac_load_detect = true;
1491 /* RS400,RC410,RS480 chipset seems to report a lot
1492 * of false positive on load detect, we haven't yet
1493 * found a way to make load detect reliable on those
1494 * chipset, thus just disable it for TV.
1495 */
1496 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1497 radeon_connector->dac_load_detect = false;
1498 drm_connector_attach_property(&radeon_connector->base,
1499 rdev->mode_info.load_detect_property,
1500 radeon_connector->dac_load_detect);
1501 drm_connector_attach_property(&radeon_connector->base,
1502 rdev->mode_info.tv_std_property,
1503 radeon_combios_get_tv_info(rdev));
1504 /* no HPD on analog connectors */
1505 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05001506 connector->interlace_allowed = false;
1507 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001508 break;
1509 case DRM_MODE_CONNECTOR_LVDS:
1510 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001511 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001512 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04001513 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001514 if (!radeon_connector->ddc_bus)
1515 goto failed;
1516 }
Dave Airlie445282d2009-09-09 17:40:54 +10001517 drm_connector_attach_property(&radeon_connector->base,
1518 dev->mode_config.scaling_mode_property,
1519 DRM_MODE_SCALE_FULLSCREEN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001520 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05001521 connector->interlace_allowed = false;
1522 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001523 break;
1524 }
1525
Alex Deucher2581afc2010-07-20 03:24:11 -04001526 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001527 if (i2c_bus->valid)
1528 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1529 } else
1530 connector->polled = DRM_CONNECTOR_POLL_HPD;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001531 connector->display_info.subpixel_order = subpixel_order;
1532 drm_sysfs_connector_add(connector);
Michel Dänzer63ec0112011-03-22 16:30:23 -07001533 if (connector_type == DRM_MODE_CONNECTOR_LVDS) {
1534 struct drm_encoder *drm_encoder;
1535
1536 list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) {
1537 struct radeon_encoder *radeon_encoder;
1538
1539 radeon_encoder = to_radeon_encoder(drm_encoder);
1540 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_LVDS)
1541 radeon_legacy_backlight_init(radeon_encoder, connector);
1542 }
1543 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001544 return;
1545
1546failed:
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001547 drm_connector_cleanup(connector);
1548 kfree(connector);
1549}