blob: c566b486ca08a79d72256dd3696b0992c07b481f [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 */
David Howells760285e2012-10-02 18:01:07 +010026#include <drm/drmP.h>
27#include <drm/drm_edid.h>
28#include <drm/drm_crtc_helper.h>
29#include <drm/drm_fb_helper.h>
30#include <drm/radeon_drm.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020031#include "radeon.h"
Alex Deucher923f6842009-09-10 17:53:39 -040032#include "atom.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020033
Dave Airlie10ebc0b2012-09-17 14:40:31 +100034#include <linux/pm_runtime.h>
35
Alex Deucherd4877cf2009-12-04 16:56:37 -050036void radeon_connector_hotplug(struct drm_connector *connector)
37{
38 struct drm_device *dev = connector->dev;
39 struct radeon_device *rdev = dev->dev_private;
40 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
41
Alex Deuchercbac9542011-07-11 14:49:28 +000042 /* bail if the connector does not have hpd pin, e.g.,
43 * VGA, TV, etc.
44 */
45 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE)
46 return;
47
Alex Deucher1e85e1d2011-05-20 04:34:29 -040048 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
Alex Deucherd4877cf2009-12-04 16:56:37 -050049
Alex Deucher73104b52011-08-09 17:09:06 +000050 /* if the connector is already off, don't turn it back on */
51 if (connector->dpms != DRM_MODE_DPMS_ON)
52 return;
53
Alex Deucherd5811e82011-08-13 13:36:13 -040054 /* just deal with DP (not eDP) here. */
55 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
Jerome Glisse266dcba2012-07-19 17:15:56 -040056 struct radeon_connector_atom_dig *dig_connector =
57 radeon_connector->con_priv;
Alex Deucher7c3ed0f2011-05-20 04:34:30 -040058
Jerome Glisse266dcba2012-07-19 17:15:56 -040059 /* if existing sink type was not DP no need to retrain */
60 if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT)
61 return;
62
63 /* first get sink type as it may be reset after (un)plug */
64 dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
65 /* don't do anything if sink is not display port, i.e.,
66 * passive dp->(dvi|hdmi) adaptor
67 */
68 if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
69 int saved_dpms = connector->dpms;
70 /* Only turn off the display if it's physically disconnected */
Jerome Glisseca2ccde2012-07-19 17:25:55 -040071 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
Jerome Glisse266dcba2012-07-19 17:15:56 -040072 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
Jerome Glisseca2ccde2012-07-19 17:25:55 -040073 } else if (radeon_dp_needs_link_train(radeon_connector)) {
74 /* set it to OFF so that drm_helper_connector_dpms()
75 * won't return immediately since the current state
76 * is ON at this point.
77 */
78 connector->dpms = DRM_MODE_DPMS_OFF;
Jerome Glisse266dcba2012-07-19 17:15:56 -040079 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
Jerome Glisseca2ccde2012-07-19 17:25:55 -040080 }
Jerome Glisse266dcba2012-07-19 17:15:56 -040081 connector->dpms = saved_dpms;
82 }
Alex Deucherd4877cf2009-12-04 16:56:37 -050083 }
Alex Deucherd4877cf2009-12-04 16:56:37 -050084}
85
Dave Airlie445282d2009-09-09 17:40:54 +100086static void radeon_property_change_mode(struct drm_encoder *encoder)
87{
88 struct drm_crtc *crtc = encoder->crtc;
89
90 if (crtc && crtc->enabled) {
91 drm_crtc_helper_set_mode(crtc, &crtc->mode,
Matt Roperf4510a22014-04-01 15:22:40 -070092 crtc->x, crtc->y, crtc->primary->fb);
Dave Airlie445282d2009-09-09 17:40:54 +100093 }
94}
Alex Deuchereccea792012-03-26 15:12:54 -040095
96int radeon_get_monitor_bpc(struct drm_connector *connector)
97{
98 struct drm_device *dev = connector->dev;
99 struct radeon_device *rdev = dev->dev_private;
100 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
101 struct radeon_connector_atom_dig *dig_connector;
102 int bpc = 8;
103
104 switch (connector->connector_type) {
105 case DRM_MODE_CONNECTOR_DVII:
106 case DRM_MODE_CONNECTOR_HDMIB:
107 if (radeon_connector->use_digital) {
108 if (drm_detect_hdmi_monitor(radeon_connector->edid)) {
109 if (connector->display_info.bpc)
110 bpc = connector->display_info.bpc;
111 }
112 }
113 break;
114 case DRM_MODE_CONNECTOR_DVID:
115 case DRM_MODE_CONNECTOR_HDMIA:
116 if (drm_detect_hdmi_monitor(radeon_connector->edid)) {
117 if (connector->display_info.bpc)
118 bpc = connector->display_info.bpc;
119 }
120 break;
121 case DRM_MODE_CONNECTOR_DisplayPort:
122 dig_connector = radeon_connector->con_priv;
123 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
124 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) ||
125 drm_detect_hdmi_monitor(radeon_connector->edid)) {
126 if (connector->display_info.bpc)
127 bpc = connector->display_info.bpc;
128 }
129 break;
130 case DRM_MODE_CONNECTOR_eDP:
131 case DRM_MODE_CONNECTOR_LVDS:
132 if (connector->display_info.bpc)
133 bpc = connector->display_info.bpc;
134 else if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
135 struct drm_connector_helper_funcs *connector_funcs =
136 connector->helper_private;
137 struct drm_encoder *encoder = connector_funcs->best_encoder(connector);
138 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
139 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
140
141 if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR)
142 bpc = 6;
143 else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR)
144 bpc = 8;
145 }
146 break;
147 }
148 return bpc;
149}
150
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200151static void
152radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
153{
154 struct drm_device *dev = connector->dev;
155 struct radeon_device *rdev = dev->dev_private;
156 struct drm_encoder *best_encoder = NULL;
157 struct drm_encoder *encoder = NULL;
158 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
159 struct drm_mode_object *obj;
160 bool connected;
161 int i;
162
163 best_encoder = connector_funcs->best_encoder(connector);
164
165 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
166 if (connector->encoder_ids[i] == 0)
167 break;
168
169 obj = drm_mode_object_find(connector->dev,
170 connector->encoder_ids[i],
171 DRM_MODE_OBJECT_ENCODER);
172 if (!obj)
173 continue;
174
175 encoder = obj_to_encoder(obj);
176
177 if ((encoder == best_encoder) && (status == connector_status_connected))
178 connected = true;
179 else
180 connected = false;
181
182 if (rdev->is_atom_bios)
183 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
184 else
185 radeon_combios_connected_scratch_regs(connector, encoder, connected);
186
187 }
188}
189
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400190static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
Dave Airlie445282d2009-09-09 17:40:54 +1000191{
192 struct drm_mode_object *obj;
193 struct drm_encoder *encoder;
194 int i;
195
196 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
197 if (connector->encoder_ids[i] == 0)
198 break;
199
200 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
201 if (!obj)
202 continue;
203
204 encoder = obj_to_encoder(obj);
205 if (encoder->encoder_type == encoder_type)
206 return encoder;
207 }
208 return NULL;
209}
210
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400211static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200212{
213 int enc_id = connector->encoder_ids[0];
214 struct drm_mode_object *obj;
215 struct drm_encoder *encoder;
216
217 /* pick the encoder ids */
218 if (enc_id) {
219 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
220 if (!obj)
221 return NULL;
222 encoder = obj_to_encoder(obj);
223 return encoder;
224 }
225 return NULL;
226}
227
Dave Airlie4ce001a2009-08-13 16:32:14 +1000228/*
229 * radeon_connector_analog_encoder_conflict_solve
230 * - search for other connectors sharing this encoder
231 * if priority is true, then set them disconnected if this is connected
232 * if priority is false, set us disconnected if they are connected
233 */
234static enum drm_connector_status
235radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
236 struct drm_encoder *encoder,
237 enum drm_connector_status current_status,
238 bool priority)
239{
240 struct drm_device *dev = connector->dev;
241 struct drm_connector *conflict;
Alex Deucher08d07512010-04-15 13:31:12 -0400242 struct radeon_connector *radeon_conflict;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000243 int i;
244
245 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
246 if (conflict == connector)
247 continue;
248
Alex Deucher08d07512010-04-15 13:31:12 -0400249 radeon_conflict = to_radeon_connector(conflict);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000250 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
251 if (conflict->encoder_ids[i] == 0)
252 break;
253
254 /* if the IDs match */
255 if (conflict->encoder_ids[i] == encoder->base.id) {
256 if (conflict->status != connector_status_connected)
257 continue;
258
Alex Deucher08d07512010-04-15 13:31:12 -0400259 if (radeon_conflict->use_digital)
260 continue;
261
Dave Airlie4ce001a2009-08-13 16:32:14 +1000262 if (priority == true) {
Alex Deucherc5d46b42010-10-29 13:49:25 -0400263 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
264 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(connector));
Dave Airlie4ce001a2009-08-13 16:32:14 +1000265 conflict->status = connector_status_disconnected;
266 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
267 } else {
Alex Deucherc5d46b42010-10-29 13:49:25 -0400268 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
269 DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(conflict));
Dave Airlie4ce001a2009-08-13 16:32:14 +1000270 current_status = connector_status_disconnected;
271 }
272 break;
273 }
274 }
275 }
276 return current_status;
277
278}
279
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200280static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
281{
282 struct drm_device *dev = encoder->dev;
283 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
284 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400285 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200286
Alex Deucherde2103e2009-10-09 15:14:30 -0400287 if (native_mode->hdisplay != 0 &&
288 native_mode->vdisplay != 0 &&
289 native_mode->clock != 0) {
Alex Deucherfb06ca82009-10-12 11:25:05 -0400290 mode = drm_mode_duplicate(dev, native_mode);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200291 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
292 drm_mode_set_name(mode);
293
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000294 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
Alex Deucherd2efdf62009-12-22 10:06:49 -0500295 } else if (native_mode->hdisplay != 0 &&
296 native_mode->vdisplay != 0) {
297 /* mac laptops without an edid */
298 /* Note that this is not necessarily the exact panel mode,
299 * but an approximation based on the cvt formula. For these
300 * systems we should ideally read the mode info out of the
301 * registers or add a mode table, but this works and is much
302 * simpler.
303 */
304 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
305 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000306 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200307 }
308 return mode;
309}
310
Alex Deucher923f6842009-09-10 17:53:39 -0400311static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
312{
313 struct drm_device *dev = encoder->dev;
314 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
315 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400316 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400317 int i;
318 struct mode_size {
319 int w;
320 int h;
321 } common_modes[17] = {
322 { 640, 480},
323 { 720, 480},
324 { 800, 600},
325 { 848, 480},
326 {1024, 768},
327 {1152, 768},
328 {1280, 720},
329 {1280, 800},
330 {1280, 854},
331 {1280, 960},
332 {1280, 1024},
333 {1440, 900},
334 {1400, 1050},
335 {1680, 1050},
336 {1600, 1200},
337 {1920, 1080},
338 {1920, 1200}
339 };
340
341 for (i = 0; i < 17; i++) {
Alex Deucherdfdd6462009-10-13 12:48:44 -0400342 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
343 if (common_modes[i].w > 1024 ||
344 common_modes[i].h > 768)
345 continue;
346 }
Alex Deucher923f6842009-09-10 17:53:39 -0400347 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400348 if (common_modes[i].w > native_mode->hdisplay ||
349 common_modes[i].h > native_mode->vdisplay ||
350 (common_modes[i].w == native_mode->hdisplay &&
351 common_modes[i].h == native_mode->vdisplay))
Alex Deucher923f6842009-09-10 17:53:39 -0400352 continue;
353 }
354 if (common_modes[i].w < 320 || common_modes[i].h < 200)
355 continue;
356
Dave Airlied50ba252009-09-23 14:44:08 +1000357 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400358 drm_mode_probed_add(connector, mode);
359 }
360}
361
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400362static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200363 uint64_t val)
364{
Dave Airlie445282d2009-09-09 17:40:54 +1000365 struct drm_device *dev = connector->dev;
366 struct radeon_device *rdev = dev->dev_private;
367 struct drm_encoder *encoder;
368 struct radeon_encoder *radeon_encoder;
369
370 if (property == rdev->mode_info.coherent_mode_property) {
371 struct radeon_encoder_atom_dig *dig;
Dave Airliece227c42010-04-09 06:27:00 +0000372 bool new_coherent_mode;
Dave Airlie445282d2009-09-09 17:40:54 +1000373
374 /* need to find digital encoder on connector */
375 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
376 if (!encoder)
377 return 0;
378
379 radeon_encoder = to_radeon_encoder(encoder);
380
381 if (!radeon_encoder->enc_priv)
382 return 0;
383
384 dig = radeon_encoder->enc_priv;
Dave Airliece227c42010-04-09 06:27:00 +0000385 new_coherent_mode = val ? true : false;
386 if (dig->coherent_mode != new_coherent_mode) {
387 dig->coherent_mode = new_coherent_mode;
388 radeon_property_change_mode(&radeon_encoder->base);
389 }
Dave Airlie445282d2009-09-09 17:40:54 +1000390 }
391
Alex Deucher8666c072013-09-03 14:58:44 -0400392 if (property == rdev->mode_info.audio_property) {
393 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
394 /* need to find digital encoder on connector */
395 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
396 if (!encoder)
397 return 0;
398
399 radeon_encoder = to_radeon_encoder(encoder);
400
401 if (radeon_connector->audio != val) {
402 radeon_connector->audio = val;
403 radeon_property_change_mode(&radeon_encoder->base);
404 }
405 }
406
Alex Deucher6214bb72013-09-24 17:26:26 -0400407 if (property == rdev->mode_info.dither_property) {
408 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
409 /* need to find digital encoder on connector */
410 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
411 if (!encoder)
412 return 0;
413
414 radeon_encoder = to_radeon_encoder(encoder);
415
416 if (radeon_connector->dither != val) {
417 radeon_connector->dither = val;
418 radeon_property_change_mode(&radeon_encoder->base);
419 }
420 }
421
Alex Deucher5b1714d2010-08-03 19:59:20 -0400422 if (property == rdev->mode_info.underscan_property) {
423 /* need to find digital encoder on connector */
424 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
425 if (!encoder)
426 return 0;
427
428 radeon_encoder = to_radeon_encoder(encoder);
429
430 if (radeon_encoder->underscan_type != val) {
431 radeon_encoder->underscan_type = val;
432 radeon_property_change_mode(&radeon_encoder->base);
433 }
434 }
435
Marius Gröger5bccf5e2010-09-21 21:30:59 +0200436 if (property == rdev->mode_info.underscan_hborder_property) {
437 /* need to find digital encoder on connector */
438 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
439 if (!encoder)
440 return 0;
441
442 radeon_encoder = to_radeon_encoder(encoder);
443
444 if (radeon_encoder->underscan_hborder != val) {
445 radeon_encoder->underscan_hborder = val;
446 radeon_property_change_mode(&radeon_encoder->base);
447 }
448 }
449
450 if (property == rdev->mode_info.underscan_vborder_property) {
451 /* need to find digital encoder on connector */
452 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
453 if (!encoder)
454 return 0;
455
456 radeon_encoder = to_radeon_encoder(encoder);
457
458 if (radeon_encoder->underscan_vborder != val) {
459 radeon_encoder->underscan_vborder = val;
460 radeon_property_change_mode(&radeon_encoder->base);
461 }
462 }
463
Dave Airlie445282d2009-09-09 17:40:54 +1000464 if (property == rdev->mode_info.tv_std_property) {
465 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
466 if (!encoder) {
467 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
468 }
469
470 if (!encoder)
471 return 0;
472
473 radeon_encoder = to_radeon_encoder(encoder);
474 if (!radeon_encoder->enc_priv)
475 return 0;
Alex Deucher643acac2010-04-05 23:57:52 -0400476 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
Dave Airlie445282d2009-09-09 17:40:54 +1000477 struct radeon_encoder_atom_dac *dac_int;
478 dac_int = radeon_encoder->enc_priv;
479 dac_int->tv_std = val;
480 } else {
481 struct radeon_encoder_tv_dac *dac_int;
482 dac_int = radeon_encoder->enc_priv;
483 dac_int->tv_std = val;
484 }
485 radeon_property_change_mode(&radeon_encoder->base);
486 }
487
488 if (property == rdev->mode_info.load_detect_property) {
489 struct radeon_connector *radeon_connector =
490 to_radeon_connector(connector);
491
492 if (val == 0)
493 radeon_connector->dac_load_detect = false;
494 else
495 radeon_connector->dac_load_detect = true;
496 }
497
498 if (property == rdev->mode_info.tmds_pll_property) {
499 struct radeon_encoder_int_tmds *tmds = NULL;
500 bool ret = false;
501 /* need to find digital encoder on connector */
502 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
503 if (!encoder)
504 return 0;
505
506 radeon_encoder = to_radeon_encoder(encoder);
507
508 tmds = radeon_encoder->enc_priv;
509 if (!tmds)
510 return 0;
511
512 if (val == 0) {
513 if (rdev->is_atom_bios)
514 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
515 else
516 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
517 }
518 if (val == 1 || ret == false) {
519 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
520 }
521 radeon_property_change_mode(&radeon_encoder->base);
522 }
523
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200524 return 0;
525}
526
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200527static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
528 struct drm_connector *connector)
529{
530 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400531 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Matthew Garrett13bb9432011-08-08 16:21:15 +0000532 struct drm_display_mode *t, *mode;
533
534 /* If the EDID preferred mode doesn't match the native mode, use it */
535 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
536 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
537 if (mode->hdisplay != native_mode->hdisplay ||
538 mode->vdisplay != native_mode->vdisplay)
539 memcpy(native_mode, mode, sizeof(*mode));
540 }
541 }
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200542
543 /* Try to get native mode details from EDID if necessary */
Alex Deucherde2103e2009-10-09 15:14:30 -0400544 if (!native_mode->clock) {
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200545 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400546 if (mode->hdisplay == native_mode->hdisplay &&
547 mode->vdisplay == native_mode->vdisplay) {
548 *native_mode = *mode;
549 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
Alex Deucherc5d46b42010-10-29 13:49:25 -0400550 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200551 break;
552 }
553 }
554 }
Matthew Garrett13bb9432011-08-08 16:21:15 +0000555
Alex Deucherde2103e2009-10-09 15:14:30 -0400556 if (!native_mode->clock) {
Alex Deucherc5d46b42010-10-29 13:49:25 -0400557 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200558 radeon_encoder->rmx_type = RMX_OFF;
559 }
560}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200561
562static int radeon_lvds_get_modes(struct drm_connector *connector)
563{
564 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
565 struct drm_encoder *encoder;
566 int ret = 0;
567 struct drm_display_mode *mode;
568
569 if (radeon_connector->ddc_bus) {
570 ret = radeon_ddc_get_modes(radeon_connector);
571 if (ret > 0) {
Alex Deucher7747b712009-09-11 11:15:43 -0400572 encoder = radeon_best_single_encoder(connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200573 if (encoder) {
574 radeon_fixup_lvds_native_mode(encoder, connector);
Alex Deucher7747b712009-09-11 11:15:43 -0400575 /* add scaled modes */
576 radeon_add_common_modes(encoder, connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200577 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200578 return ret;
579 }
580 }
581
582 encoder = radeon_best_single_encoder(connector);
583 if (!encoder)
584 return 0;
585
586 /* we have no EDID modes */
587 mode = radeon_fp_native_mode(encoder);
588 if (mode) {
589 ret = 1;
590 drm_mode_probed_add(connector, mode);
Alex Deucher7a868e12010-12-08 22:13:05 -0500591 /* add the width/height from vbios tables if available */
592 connector->display_info.width_mm = mode->width_mm;
593 connector->display_info.height_mm = mode->height_mm;
Alex Deucher7747b712009-09-11 11:15:43 -0400594 /* add scaled modes */
595 radeon_add_common_modes(encoder, connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200596 }
Alex Deucher923f6842009-09-10 17:53:39 -0400597
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200598 return ret;
599}
600
601static int radeon_lvds_mode_valid(struct drm_connector *connector,
602 struct drm_display_mode *mode)
603{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500604 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
605
606 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
607 return MODE_PANEL;
608
609 if (encoder) {
610 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
611 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
612
613 /* AVIVO hardware supports downscaling modes larger than the panel
614 * to the panel size, but I'm not sure this is desirable.
615 */
616 if ((mode->hdisplay > native_mode->hdisplay) ||
617 (mode->vdisplay > native_mode->vdisplay))
618 return MODE_PANEL;
619
620 /* if scaling is disabled, block non-native modes */
621 if (radeon_encoder->rmx_type == RMX_OFF) {
622 if ((mode->hdisplay != native_mode->hdisplay) ||
623 (mode->vdisplay != native_mode->vdisplay))
624 return MODE_PANEL;
625 }
626 }
627
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200628 return MODE_OK;
629}
630
Chris Wilson7b334fc2010-09-09 23:51:02 +0100631static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100632radeon_lvds_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200633{
Alex Deucher0549a0612009-10-09 18:41:19 -0400634 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher2ffb8422009-10-08 13:02:19 -0400635 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Alex Deucher0549a0612009-10-09 18:41:19 -0400636 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000637 int r;
638
639 r = pm_runtime_get_sync(connector->dev->dev);
640 if (r < 0)
641 return connector_status_disconnected;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400642
643 if (encoder) {
644 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400645 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400646
647 /* check if panel is valid */
Alex Deucherde2103e2009-10-09 15:14:30 -0400648 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
Alex Deucher2ffb8422009-10-08 13:02:19 -0400649 ret = connector_status_connected;
650
651 }
Alex Deucher0549a0612009-10-09 18:41:19 -0400652
653 /* check for edid as well */
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400654 if (radeon_connector->edid)
655 ret = connector_status_connected;
656 else {
657 if (radeon_connector->ddc_bus) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400658 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
659 &radeon_connector->ddc_bus->adapter);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400660 if (radeon_connector->edid)
661 ret = connector_status_connected;
662 }
Alex Deucher0549a0612009-10-09 18:41:19 -0400663 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200664 /* check acpi lid status ??? */
Alex Deucher2ffb8422009-10-08 13:02:19 -0400665
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200666 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000667 pm_runtime_mark_last_busy(connector->dev->dev);
668 pm_runtime_put_autosuspend(connector->dev->dev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200669 return ret;
670}
671
672static void radeon_connector_destroy(struct drm_connector *connector)
673{
674 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
675
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400676 if (radeon_connector->edid)
677 kfree(radeon_connector->edid);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200678 kfree(radeon_connector->con_priv);
679 drm_sysfs_connector_remove(connector);
680 drm_connector_cleanup(connector);
681 kfree(connector);
682}
683
Dave Airlie445282d2009-09-09 17:40:54 +1000684static int radeon_lvds_set_property(struct drm_connector *connector,
685 struct drm_property *property,
686 uint64_t value)
687{
688 struct drm_device *dev = connector->dev;
689 struct radeon_encoder *radeon_encoder;
690 enum radeon_rmx_type rmx_type;
691
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000692 DRM_DEBUG_KMS("\n");
Dave Airlie445282d2009-09-09 17:40:54 +1000693 if (property != dev->mode_config.scaling_mode_property)
694 return 0;
695
696 if (connector->encoder)
697 radeon_encoder = to_radeon_encoder(connector->encoder);
698 else {
699 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
700 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
701 }
702
703 switch (value) {
704 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
705 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
706 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
707 default:
708 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
709 }
710 if (radeon_encoder->rmx_type == rmx_type)
711 return 0;
712
713 radeon_encoder->rmx_type = rmx_type;
714
715 radeon_property_change_mode(&radeon_encoder->base);
716 return 0;
717}
718
719
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400720static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200721 .get_modes = radeon_lvds_get_modes,
722 .mode_valid = radeon_lvds_mode_valid,
723 .best_encoder = radeon_best_single_encoder,
724};
725
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400726static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200727 .dpms = drm_helper_connector_dpms,
728 .detect = radeon_lvds_detect,
729 .fill_modes = drm_helper_probe_single_connector_modes,
730 .destroy = radeon_connector_destroy,
Dave Airlie445282d2009-09-09 17:40:54 +1000731 .set_property = radeon_lvds_set_property,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200732};
733
734static int radeon_vga_get_modes(struct drm_connector *connector)
735{
736 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
737 int ret;
738
739 ret = radeon_ddc_get_modes(radeon_connector);
740
741 return ret;
742}
743
744static int radeon_vga_mode_valid(struct drm_connector *connector,
745 struct drm_display_mode *mode)
746{
Alex Deucherb20f9be2011-06-08 13:01:11 -0400747 struct drm_device *dev = connector->dev;
748 struct radeon_device *rdev = dev->dev_private;
749
Alex Deuchera3fa6322009-11-05 11:57:07 -0500750 /* XXX check mode bandwidth */
Alex Deucherb20f9be2011-06-08 13:01:11 -0400751
752 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
753 return MODE_CLOCK_HIGH;
754
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200755 return MODE_OK;
756}
757
Chris Wilson7b334fc2010-09-09 23:51:02 +0100758static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100759radeon_vga_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200760{
Alex Deucherfafcf942011-03-23 08:10:10 +0000761 struct drm_device *dev = connector->dev;
762 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200763 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
764 struct drm_encoder *encoder;
765 struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000766 bool dret = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200767 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000768 int r;
769
770 r = pm_runtime_get_sync(connector->dev->dev);
771 if (r < 0)
772 return connector_status_disconnected;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200773
Dave Airlie4ce001a2009-08-13 16:32:14 +1000774 encoder = radeon_best_single_encoder(connector);
775 if (!encoder)
776 ret = connector_status_disconnected;
777
Dave Airlieeb6b6d72010-02-25 13:44:04 +1000778 if (radeon_connector->ddc_bus)
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +0100779 dret = radeon_ddc_probe(radeon_connector, false);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400780 if (dret) {
Alex Deucherd0d0a222011-10-07 14:23:48 -0400781 radeon_connector->detected_by_load = false;
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400782 if (radeon_connector->edid) {
783 kfree(radeon_connector->edid);
784 radeon_connector->edid = NULL;
785 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400786 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400787
788 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +0100789 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
790 drm_get_connector_name(connector));
791 ret = connector_status_connected;
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400792 } else {
793 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
794
795 /* some oems have boards with separate digital and analog connectors
796 * with a shared ddc line (often vga + hdmi)
797 */
798 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
799 kfree(radeon_connector->edid);
800 radeon_connector->edid = NULL;
801 ret = connector_status_disconnected;
802 } else
803 ret = connector_status_connected;
804 }
805 } else {
Dave Airliec3cceed2010-10-26 12:55:52 +1000806
807 /* if we aren't forcing don't do destructive polling */
Alex Deucherd0d0a222011-10-07 14:23:48 -0400808 if (!force) {
809 /* only return the previous status if we last
810 * detected a monitor via load.
811 */
812 if (radeon_connector->detected_by_load)
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000813 ret = connector->status;
814 goto out;
Alex Deucherd0d0a222011-10-07 14:23:48 -0400815 }
Dave Airliec3cceed2010-10-26 12:55:52 +1000816
Darren Jenkinsd8a7f792009-12-30 12:22:55 +1100817 if (radeon_connector->dac_load_detect && encoder) {
Dave Airlie445282d2009-09-09 17:40:54 +1000818 encoder_funcs = encoder->helper_private;
819 ret = encoder_funcs->detect(encoder, connector);
Jerome Glisse34076442011-10-24 18:16:34 -0400820 if (ret != connector_status_disconnected)
Alex Deucherd0d0a222011-10-07 14:23:48 -0400821 radeon_connector->detected_by_load = true;
Dave Airlie445282d2009-09-09 17:40:54 +1000822 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200823 }
824
Dave Airlie4ce001a2009-08-13 16:32:14 +1000825 if (ret == connector_status_connected)
826 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
Alex Deucherfafcf942011-03-23 08:10:10 +0000827
828 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
829 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
830 * by other means, assume the CRT is connected and use that EDID.
831 */
832 if ((!rdev->is_atom_bios) &&
833 (ret == connector_status_disconnected) &&
834 rdev->mode_info.bios_hardcoded_edid_size) {
835 ret = connector_status_connected;
836 }
837
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200838 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000839
840out:
841 pm_runtime_mark_last_busy(connector->dev->dev);
842 pm_runtime_put_autosuspend(connector->dev->dev);
843
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200844 return ret;
845}
846
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400847static const struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200848 .get_modes = radeon_vga_get_modes,
849 .mode_valid = radeon_vga_mode_valid,
850 .best_encoder = radeon_best_single_encoder,
851};
852
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400853static const struct drm_connector_funcs radeon_vga_connector_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200854 .dpms = drm_helper_connector_dpms,
855 .detect = radeon_vga_detect,
856 .fill_modes = drm_helper_probe_single_connector_modes,
857 .destroy = radeon_connector_destroy,
858 .set_property = radeon_connector_set_property,
859};
860
Dave Airlie4ce001a2009-08-13 16:32:14 +1000861static int radeon_tv_get_modes(struct drm_connector *connector)
862{
863 struct drm_device *dev = connector->dev;
Alex Deucher923f6842009-09-10 17:53:39 -0400864 struct radeon_device *rdev = dev->dev_private;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000865 struct drm_display_mode *tv_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400866 struct drm_encoder *encoder;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000867
Alex Deucher923f6842009-09-10 17:53:39 -0400868 encoder = radeon_best_single_encoder(connector);
869 if (!encoder)
870 return 0;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000871
Alex Deucher923f6842009-09-10 17:53:39 -0400872 /* avivo chips can scale any mode */
873 if (rdev->family >= CHIP_RS600)
874 /* add scaled modes */
875 radeon_add_common_modes(encoder, connector);
876 else {
877 /* only 800x600 is supported right now on pre-avivo chips */
Dave Airlied50ba252009-09-23 14:44:08 +1000878 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400879 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
880 drm_mode_probed_add(connector, tv_mode);
881 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000882 return 1;
883}
884
885static int radeon_tv_mode_valid(struct drm_connector *connector,
886 struct drm_display_mode *mode)
887{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500888 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
889 return MODE_CLOCK_RANGE;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000890 return MODE_OK;
891}
892
Chris Wilson7b334fc2010-09-09 23:51:02 +0100893static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100894radeon_tv_detect(struct drm_connector *connector, bool force)
Dave Airlie4ce001a2009-08-13 16:32:14 +1000895{
896 struct drm_encoder *encoder;
897 struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie445282d2009-09-09 17:40:54 +1000898 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
899 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000900 int r;
Dave Airlie445282d2009-09-09 17:40:54 +1000901
902 if (!radeon_connector->dac_load_detect)
903 return ret;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000904
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000905 r = pm_runtime_get_sync(connector->dev->dev);
906 if (r < 0)
907 return connector_status_disconnected;
908
Dave Airlie4ce001a2009-08-13 16:32:14 +1000909 encoder = radeon_best_single_encoder(connector);
910 if (!encoder)
911 ret = connector_status_disconnected;
912 else {
913 encoder_funcs = encoder->helper_private;
914 ret = encoder_funcs->detect(encoder, connector);
915 }
916 if (ret == connector_status_connected)
917 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
918 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000919 pm_runtime_mark_last_busy(connector->dev->dev);
920 pm_runtime_put_autosuspend(connector->dev->dev);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000921 return ret;
922}
923
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400924static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
Dave Airlie4ce001a2009-08-13 16:32:14 +1000925 .get_modes = radeon_tv_get_modes,
926 .mode_valid = radeon_tv_mode_valid,
927 .best_encoder = radeon_best_single_encoder,
928};
929
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400930static const struct drm_connector_funcs radeon_tv_connector_funcs = {
Dave Airlie4ce001a2009-08-13 16:32:14 +1000931 .dpms = drm_helper_connector_dpms,
932 .detect = radeon_tv_detect,
933 .fill_modes = drm_helper_probe_single_connector_modes,
934 .destroy = radeon_connector_destroy,
935 .set_property = radeon_connector_set_property,
936};
937
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200938static int radeon_dvi_get_modes(struct drm_connector *connector)
939{
940 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
941 int ret;
942
943 ret = radeon_ddc_get_modes(radeon_connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200944 return ret;
945}
946
Tvrtko Ursulin11fe1262012-03-16 12:22:11 -0400947static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector)
948{
949 struct drm_device *dev = connector->dev;
950 struct radeon_device *rdev = dev->dev_private;
951 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
952 enum drm_connector_status status;
953
954 /* We only trust HPD on R600 and newer ASICS. */
955 if (rdev->family >= CHIP_R600
956 && radeon_connector->hpd.hpd != RADEON_HPD_NONE) {
957 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
958 status = connector_status_connected;
959 else
960 status = connector_status_disconnected;
961 if (connector->status == status)
962 return true;
963 }
964
965 return false;
966}
967
Dave Airlie4ce001a2009-08-13 16:32:14 +1000968/*
969 * DVI is complicated
970 * Do a DDC probe, if DDC probe passes, get the full EDID so
971 * we can do analog/digital monitor detection at this point.
972 * If the monitor is an analog monitor or we got no DDC,
973 * we need to find the DAC encoder object for this connector.
974 * If we got no DDC, we do load detection on the DAC encoder object.
975 * If we got analog DDC or load detection passes on the DAC encoder
976 * we have to check if this analog encoder is shared with anyone else (TV)
977 * if its shared we have to set the other connector to disconnected.
978 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100979static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100980radeon_dvi_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200981{
Alex Deucherfafcf942011-03-23 08:10:10 +0000982 struct drm_device *dev = connector->dev;
983 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200984 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000985 struct drm_encoder *encoder = NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200986 struct drm_encoder_helper_funcs *encoder_funcs;
987 struct drm_mode_object *obj;
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000988 int i, r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200989 enum drm_connector_status ret = connector_status_disconnected;
Egbert Eichfc87f132012-10-24 18:32:52 +0200990 bool dret = false, broken_edid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200991
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000992 r = pm_runtime_get_sync(connector->dev->dev);
993 if (r < 0)
994 return connector_status_disconnected;
995
996 if (!force && radeon_check_hpd_status_unchanged(connector)) {
997 ret = connector->status;
998 goto exit;
999 }
Tvrtko Ursulin11fe1262012-03-16 12:22:11 -04001000
Dave Airlieeb6b6d72010-02-25 13:44:04 +10001001 if (radeon_connector->ddc_bus)
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +01001002 dret = radeon_ddc_probe(radeon_connector, false);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001003 if (dret) {
Alex Deucherd0d0a222011-10-07 14:23:48 -04001004 radeon_connector->detected_by_load = false;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001005 if (radeon_connector->edid) {
1006 kfree(radeon_connector->edid);
1007 radeon_connector->edid = NULL;
1008 }
Dave Airlie4ce001a2009-08-13 16:32:14 +10001009 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001010
Dave Airlie4ce001a2009-08-13 16:32:14 +10001011 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +01001012 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1013 drm_get_connector_name(connector));
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001014 /* rs690 seems to have a problem with connectors not existing and always
1015 * return a block of 0's. If we see this just stop polling on this output */
1016 if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) && radeon_connector->base.null_edid_counter) {
1017 ret = connector_status_disconnected;
1018 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n", drm_get_connector_name(connector));
1019 radeon_connector->ddc_bus = NULL;
Egbert Eichfc87f132012-10-24 18:32:52 +02001020 } else {
1021 ret = connector_status_connected;
1022 broken_edid = true; /* defer use_digital to later */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001023 }
Dave Airlie4ce001a2009-08-13 16:32:14 +10001024 } else {
1025 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001026
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001027 /* some oems have boards with separate digital and analog connectors
1028 * with a shared ddc line (often vga + hdmi)
1029 */
1030 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
1031 kfree(radeon_connector->edid);
1032 radeon_connector->edid = NULL;
1033 ret = connector_status_disconnected;
1034 } else
1035 ret = connector_status_connected;
Alex Deucher71407c42009-11-17 15:44:01 -05001036
Alex Deucher42f14c42010-07-20 11:27:54 -04001037 /* This gets complicated. We have boards with VGA + HDMI with a
1038 * shared DDC line and we have boards with DVI-D + HDMI with a shared
1039 * DDC line. The latter is more complex because with DVI<->HDMI adapters
1040 * you don't really know what's connected to which port as both are digital.
Alex Deucher71407c42009-11-17 15:44:01 -05001041 */
Alex Deucherd3932d62010-02-19 02:13:56 -05001042 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
Alex Deucher71407c42009-11-17 15:44:01 -05001043 struct drm_connector *list_connector;
1044 struct radeon_connector *list_radeon_connector;
1045 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
1046 if (connector == list_connector)
1047 continue;
1048 list_radeon_connector = to_radeon_connector(list_connector);
Alex Deucherb2ea4aa2010-07-01 10:34:56 -04001049 if (list_radeon_connector->shared_ddc &&
1050 (list_radeon_connector->ddc_bus->rec.i2c_id ==
1051 radeon_connector->ddc_bus->rec.i2c_id)) {
Alex Deucher42f14c42010-07-20 11:27:54 -04001052 /* cases where both connectors are digital */
1053 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
1054 /* hpd is our only option in this case */
1055 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
Alex Deucher71407c42009-11-17 15:44:01 -05001056 kfree(radeon_connector->edid);
1057 radeon_connector->edid = NULL;
1058 ret = connector_status_disconnected;
1059 }
1060 }
1061 }
1062 }
1063 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001064 }
1065 }
1066
Dave Airlie4ce001a2009-08-13 16:32:14 +10001067 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
1068 goto out;
1069
Alex Deucher5f0a2612011-10-07 14:23:47 -04001070 /* DVI-D and HDMI-A are digital only */
1071 if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
1072 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
1073 goto out;
1074
Alex Deucherd0d0a222011-10-07 14:23:48 -04001075 /* if we aren't forcing don't do destructive polling */
Dave Airliec3cceed2010-10-26 12:55:52 +10001076 if (!force) {
Alex Deucherd0d0a222011-10-07 14:23:48 -04001077 /* only return the previous status if we last
1078 * detected a monitor via load.
1079 */
1080 if (radeon_connector->detected_by_load)
1081 ret = connector->status;
Dave Airliec3cceed2010-10-26 12:55:52 +10001082 goto out;
1083 }
1084
Dave Airlie4ce001a2009-08-13 16:32:14 +10001085 /* find analog encoder */
Dave Airlie445282d2009-09-09 17:40:54 +10001086 if (radeon_connector->dac_load_detect) {
1087 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1088 if (connector->encoder_ids[i] == 0)
1089 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001090
Dave Airlie445282d2009-09-09 17:40:54 +10001091 obj = drm_mode_object_find(connector->dev,
1092 connector->encoder_ids[i],
1093 DRM_MODE_OBJECT_ENCODER);
1094 if (!obj)
1095 continue;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001096
Dave Airlie445282d2009-09-09 17:40:54 +10001097 encoder = obj_to_encoder(obj);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001098
Takashi Iwaie3632502012-04-18 15:21:07 +02001099 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
Alex Deuchere00e8b52012-03-16 12:22:09 -04001100 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
1101 continue;
1102
Dave Airlie445282d2009-09-09 17:40:54 +10001103 encoder_funcs = encoder->helper_private;
1104 if (encoder_funcs->detect) {
Egbert Eichfc87f132012-10-24 18:32:52 +02001105 if (!broken_edid) {
1106 if (ret != connector_status_connected) {
1107 /* deal with analog monitors without DDC */
1108 ret = encoder_funcs->detect(encoder, connector);
1109 if (ret == connector_status_connected) {
1110 radeon_connector->use_digital = false;
1111 }
1112 if (ret != connector_status_disconnected)
1113 radeon_connector->detected_by_load = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001114 }
Egbert Eichfc87f132012-10-24 18:32:52 +02001115 } else {
1116 enum drm_connector_status lret;
1117 /* assume digital unless load detected otherwise */
1118 radeon_connector->use_digital = true;
1119 lret = encoder_funcs->detect(encoder, connector);
1120 DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
1121 if (lret == connector_status_connected)
1122 radeon_connector->use_digital = false;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001123 }
Dave Airlie445282d2009-09-09 17:40:54 +10001124 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001125 }
Dave Airlie4ce001a2009-08-13 16:32:14 +10001126 }
1127 }
1128
1129 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
1130 encoder) {
1131 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1132 }
1133
Alex Deucherfafcf942011-03-23 08:10:10 +00001134 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1135 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1136 * by other means, assume the DFP is connected and use that EDID. In most
1137 * cases the DVI port is actually a virtual KVM port connected to the service
1138 * processor.
1139 */
Dave Airliea09d4312012-04-19 15:42:58 +01001140out:
Alex Deucherfafcf942011-03-23 08:10:10 +00001141 if ((!rdev->is_atom_bios) &&
1142 (ret == connector_status_disconnected) &&
1143 rdev->mode_info.bios_hardcoded_edid_size) {
1144 radeon_connector->use_digital = true;
1145 ret = connector_status_connected;
1146 }
1147
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001148 /* updated in get modes as well since we need to know if it's analog or digital */
1149 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001150
1151exit:
1152 pm_runtime_mark_last_busy(connector->dev->dev);
1153 pm_runtime_put_autosuspend(connector->dev->dev);
1154
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001155 return ret;
1156}
1157
1158/* okay need to be smart in here about which encoder to pick */
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001159static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001160{
1161 int enc_id = connector->encoder_ids[0];
1162 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1163 struct drm_mode_object *obj;
1164 struct drm_encoder *encoder;
1165 int i;
1166 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1167 if (connector->encoder_ids[i] == 0)
1168 break;
1169
1170 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1171 if (!obj)
1172 continue;
1173
1174 encoder = obj_to_encoder(obj);
1175
Dave Airlie4ce001a2009-08-13 16:32:14 +10001176 if (radeon_connector->use_digital == true) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001177 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
1178 return encoder;
1179 } else {
1180 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
1181 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
1182 return encoder;
1183 }
1184 }
1185
1186 /* see if we have a default encoder TODO */
1187
1188 /* then check use digitial */
1189 /* pick the first one */
1190 if (enc_id) {
1191 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
1192 if (!obj)
1193 return NULL;
1194 encoder = obj_to_encoder(obj);
1195 return encoder;
1196 }
1197 return NULL;
1198}
1199
Dave Airlied50ba252009-09-23 14:44:08 +10001200static void radeon_dvi_force(struct drm_connector *connector)
1201{
1202 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1203 if (connector->force == DRM_FORCE_ON)
1204 radeon_connector->use_digital = false;
1205 if (connector->force == DRM_FORCE_ON_DIGITAL)
1206 radeon_connector->use_digital = true;
1207}
1208
Alex Deuchera3fa6322009-11-05 11:57:07 -05001209static int radeon_dvi_mode_valid(struct drm_connector *connector,
1210 struct drm_display_mode *mode)
1211{
Alex Deucher1b242032010-01-11 15:02:31 -05001212 struct drm_device *dev = connector->dev;
1213 struct radeon_device *rdev = dev->dev_private;
Alex Deuchera3fa6322009-11-05 11:57:07 -05001214 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1215
1216 /* XXX check mode bandwidth */
1217
Alex Deucher1b242032010-01-11 15:02:31 -05001218 /* clocks over 135 MHz have heat issues with DVI on RV100 */
1219 if (radeon_connector->use_digital &&
1220 (rdev->family == CHIP_RV100) &&
1221 (mode->clock > 135000))
1222 return MODE_CLOCK_HIGH;
1223
Alex Deuchera3fa6322009-11-05 11:57:07 -05001224 if (radeon_connector->use_digital && (mode->clock > 165000)) {
1225 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1226 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1227 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1228 return MODE_OK;
Alex Deuchere1e84012011-03-02 10:21:05 -05001229 else if (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_A) {
Alex Deucher1b2681b2012-03-20 17:18:42 -04001230 if (ASIC_IS_DCE6(rdev)) {
Alex Deuchere1e84012011-03-02 10:21:05 -05001231 /* HDMI 1.3+ supports max clock of 340 Mhz */
1232 if (mode->clock > 340000)
1233 return MODE_CLOCK_HIGH;
1234 else
1235 return MODE_OK;
1236 } else
1237 return MODE_CLOCK_HIGH;
1238 } else
Alex Deuchera3fa6322009-11-05 11:57:07 -05001239 return MODE_CLOCK_HIGH;
1240 }
Alex Deucherb20f9be2011-06-08 13:01:11 -04001241
1242 /* check against the max pixel clock */
1243 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1244 return MODE_CLOCK_HIGH;
1245
Alex Deuchera3fa6322009-11-05 11:57:07 -05001246 return MODE_OK;
1247}
1248
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001249static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001250 .get_modes = radeon_dvi_get_modes,
Alex Deuchera3fa6322009-11-05 11:57:07 -05001251 .mode_valid = radeon_dvi_mode_valid,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001252 .best_encoder = radeon_dvi_encoder,
1253};
1254
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001255static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001256 .dpms = drm_helper_connector_dpms,
1257 .detect = radeon_dvi_detect,
1258 .fill_modes = drm_helper_probe_single_connector_modes,
1259 .set_property = radeon_connector_set_property,
1260 .destroy = radeon_connector_destroy,
Dave Airlied50ba252009-09-23 14:44:08 +10001261 .force = radeon_dvi_force,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001262};
1263
Alex Deucherffd09c62009-11-24 16:13:23 -05001264static void radeon_dp_connector_destroy(struct drm_connector *connector)
1265{
1266 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1267 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1268
Alex Deucherffd09c62009-11-24 16:13:23 -05001269 if (radeon_connector->edid)
1270 kfree(radeon_connector->edid);
1271 if (radeon_dig_connector->dp_i2c_bus)
Alex Deucherac1aade2010-03-14 12:22:44 -04001272 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
Alex Deucherffd09c62009-11-24 16:13:23 -05001273 kfree(radeon_connector->con_priv);
1274 drm_sysfs_connector_remove(connector);
1275 drm_connector_cleanup(connector);
1276 kfree(connector);
1277}
1278
Dave Airlie746c1aa2009-12-08 07:07:28 +10001279static int radeon_dp_get_modes(struct drm_connector *connector)
1280{
1281 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher8b834852010-11-17 02:54:42 -05001282 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
Alex Deucher591a10e2011-06-13 17:13:34 -04001283 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001284 int ret;
1285
Alex Deucherf89931f2011-06-13 17:13:35 -04001286 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1287 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
Alex Deucherd2917672011-05-20 04:34:31 -04001288 struct drm_display_mode *mode;
1289
Alex Deucher2b69ffb2012-02-28 11:08:22 -05001290 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1291 if (!radeon_dig_connector->edp_on)
1292 atombios_set_edp_panel_power(connector,
1293 ATOM_TRANSMITTER_ACTION_POWER_ON);
1294 ret = radeon_ddc_get_modes(radeon_connector);
1295 if (!radeon_dig_connector->edp_on)
1296 atombios_set_edp_panel_power(connector,
1297 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1298 } else {
1299 /* need to setup ddc on the bridge */
1300 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1301 ENCODER_OBJECT_ID_NONE) {
1302 if (encoder)
1303 radeon_atom_ext_encoder_setup_ddc(encoder);
1304 }
1305 ret = radeon_ddc_get_modes(radeon_connector);
1306 }
Alex Deucherd2917672011-05-20 04:34:31 -04001307
1308 if (ret > 0) {
Alex Deucherd2917672011-05-20 04:34:31 -04001309 if (encoder) {
1310 radeon_fixup_lvds_native_mode(encoder, connector);
1311 /* add scaled modes */
1312 radeon_add_common_modes(encoder, connector);
1313 }
1314 return ret;
1315 }
1316
Alex Deucherd2917672011-05-20 04:34:31 -04001317 if (!encoder)
1318 return 0;
1319
1320 /* we have no EDID modes */
1321 mode = radeon_fp_native_mode(encoder);
1322 if (mode) {
1323 ret = 1;
1324 drm_mode_probed_add(connector, mode);
1325 /* add the width/height from vbios tables if available */
1326 connector->display_info.width_mm = mode->width_mm;
1327 connector->display_info.height_mm = mode->height_mm;
1328 /* add scaled modes */
1329 radeon_add_common_modes(encoder, connector);
1330 }
Alex Deucher591a10e2011-06-13 17:13:34 -04001331 } else {
1332 /* need to setup ddc on the bridge */
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001333 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1334 ENCODER_OBJECT_ID_NONE) {
Alex Deucher591a10e2011-06-13 17:13:34 -04001335 if (encoder)
1336 radeon_atom_ext_encoder_setup_ddc(encoder);
1337 }
Alex Deucherd2917672011-05-20 04:34:31 -04001338 ret = radeon_ddc_get_modes(radeon_connector);
Alex Deucher591a10e2011-06-13 17:13:34 -04001339 }
Alex Deucher8b834852010-11-17 02:54:42 -05001340
Dave Airlie746c1aa2009-12-08 07:07:28 +10001341 return ret;
1342}
1343
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001344u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001345{
1346 struct drm_mode_object *obj;
1347 struct drm_encoder *encoder;
1348 struct radeon_encoder *radeon_encoder;
1349 int i;
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001350
1351 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1352 if (connector->encoder_ids[i] == 0)
1353 break;
1354
1355 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1356 if (!obj)
1357 continue;
1358
1359 encoder = obj_to_encoder(obj);
1360 radeon_encoder = to_radeon_encoder(encoder);
1361
1362 switch (radeon_encoder->encoder_id) {
1363 case ENCODER_OBJECT_ID_TRAVIS:
1364 case ENCODER_OBJECT_ID_NUTMEG:
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001365 return radeon_encoder->encoder_id;
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001366 default:
1367 break;
1368 }
1369 }
1370
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001371 return ENCODER_OBJECT_ID_NONE;
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001372}
1373
1374bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
1375{
1376 struct drm_mode_object *obj;
1377 struct drm_encoder *encoder;
1378 struct radeon_encoder *radeon_encoder;
1379 int i;
1380 bool found = false;
1381
1382 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1383 if (connector->encoder_ids[i] == 0)
1384 break;
1385
1386 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1387 if (!obj)
1388 continue;
1389
1390 encoder = obj_to_encoder(obj);
1391 radeon_encoder = to_radeon_encoder(encoder);
1392 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1393 found = true;
1394 }
1395
1396 return found;
1397}
1398
1399bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1400{
1401 struct drm_device *dev = connector->dev;
1402 struct radeon_device *rdev = dev->dev_private;
1403
1404 if (ASIC_IS_DCE5(rdev) &&
1405 (rdev->clock.dp_extclk >= 53900) &&
1406 radeon_connector_encoder_is_hbr2(connector)) {
1407 return true;
1408 }
1409
1410 return false;
1411}
1412
Chris Wilson7b334fc2010-09-09 23:51:02 +01001413static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +01001414radeon_dp_detect(struct drm_connector *connector, bool force)
Dave Airlie746c1aa2009-12-08 07:07:28 +10001415{
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001416 struct drm_device *dev = connector->dev;
1417 struct radeon_device *rdev = dev->dev_private;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001418 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001419 enum drm_connector_status ret = connector_status_disconnected;
Alex Deucher4143e912009-11-23 18:02:35 -05001420 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
Alex Deucher591a10e2011-06-13 17:13:34 -04001421 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001422 int r;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001423
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001424 r = pm_runtime_get_sync(connector->dev->dev);
1425 if (r < 0)
1426 return connector_status_disconnected;
1427
1428 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1429 ret = connector->status;
1430 goto out;
1431 }
Tvrtko Ursulin11fe1262012-03-16 12:22:11 -04001432
Dave Airlie746c1aa2009-12-08 07:07:28 +10001433 if (radeon_connector->edid) {
1434 kfree(radeon_connector->edid);
1435 radeon_connector->edid = NULL;
1436 }
1437
Alex Deucherf89931f2011-06-13 17:13:35 -04001438 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1439 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
Alex Deucherd2917672011-05-20 04:34:31 -04001440 if (encoder) {
1441 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1442 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1443
1444 /* check if panel is valid */
1445 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1446 ret = connector_status_connected;
1447 }
Alex Deucher6f50eae2010-08-19 17:29:03 -04001448 /* eDP is always DP */
1449 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
Alex Deucher8b834852010-11-17 02:54:42 -05001450 if (!radeon_dig_connector->edp_on)
1451 atombios_set_edp_panel_power(connector,
1452 ATOM_TRANSMITTER_ACTION_POWER_ON);
Alex Deucher6f50eae2010-08-19 17:29:03 -04001453 if (radeon_dp_getdpcd(radeon_connector))
Alex Deucher9fa05c92009-11-27 13:01:46 -05001454 ret = connector_status_connected;
Alex Deucher8b834852010-11-17 02:54:42 -05001455 if (!radeon_dig_connector->edp_on)
1456 atombios_set_edp_panel_power(connector,
1457 ATOM_TRANSMITTER_ACTION_POWER_OFF);
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001458 } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1459 ENCODER_OBJECT_ID_NONE) {
Alex Deucherb06947b2011-09-02 14:23:09 +00001460 /* DP bridges are always DP */
1461 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1462 /* get the DPCD from the bridge */
1463 radeon_dp_getdpcd(radeon_connector);
1464
Alex Deucher6777a4f2011-10-04 12:23:24 -04001465 if (encoder) {
1466 /* setup ddc on the bridge */
1467 radeon_atom_ext_encoder_setup_ddc(encoder);
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +01001468 /* bridge chips are always aux */
1469 if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */
Alex Deucherb06947b2011-09-02 14:23:09 +00001470 ret = connector_status_connected;
Alex Deucher6777a4f2011-10-04 12:23:24 -04001471 else if (radeon_connector->dac_load_detect) { /* try load detection */
1472 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
Alex Deucherb06947b2011-09-02 14:23:09 +00001473 ret = encoder_funcs->detect(encoder, connector);
1474 }
1475 }
1476 } else {
Alex Deucher6f50eae2010-08-19 17:29:03 -04001477 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001478 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1479 ret = connector_status_connected;
1480 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
1481 radeon_dp_getdpcd(radeon_connector);
Alex Deucher6f50eae2010-08-19 17:29:03 -04001482 } else {
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001483 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1484 if (radeon_dp_getdpcd(radeon_connector))
1485 ret = connector_status_connected;
1486 } else {
Damien Lespiaud592fca2013-09-13 16:37:28 +01001487 /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +01001488 if (radeon_ddc_probe(radeon_connector, false))
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001489 ret = connector_status_connected;
1490 }
Alex Deucher4143e912009-11-23 18:02:35 -05001491 }
Dave Airlie746c1aa2009-12-08 07:07:28 +10001492 }
Alex Deucher4143e912009-11-23 18:02:35 -05001493
Alex Deucher30f44372010-08-21 11:09:14 -04001494 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001495out:
1496 pm_runtime_mark_last_busy(connector->dev->dev);
1497 pm_runtime_put_autosuspend(connector->dev->dev);
1498
Dave Airlie746c1aa2009-12-08 07:07:28 +10001499 return ret;
1500}
1501
Alex Deucher5801ead2009-11-24 13:32:59 -05001502static int radeon_dp_mode_valid(struct drm_connector *connector,
1503 struct drm_display_mode *mode)
1504{
1505 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1506 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1507
1508 /* XXX check mode bandwidth */
1509
Alex Deucherf89931f2011-06-13 17:13:35 -04001510 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1511 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
Alex Deucherd2917672011-05-20 04:34:31 -04001512 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1513
1514 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1515 return MODE_PANEL;
1516
1517 if (encoder) {
1518 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1519 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1520
Alex Deucherf89931f2011-06-13 17:13:35 -04001521 /* AVIVO hardware supports downscaling modes larger than the panel
Alex Deucherd2917672011-05-20 04:34:31 -04001522 * to the panel size, but I'm not sure this is desirable.
1523 */
1524 if ((mode->hdisplay > native_mode->hdisplay) ||
1525 (mode->vdisplay > native_mode->vdisplay))
1526 return MODE_PANEL;
1527
1528 /* if scaling is disabled, block non-native modes */
1529 if (radeon_encoder->rmx_type == RMX_OFF) {
1530 if ((mode->hdisplay != native_mode->hdisplay) ||
1531 (mode->vdisplay != native_mode->vdisplay))
1532 return MODE_PANEL;
1533 }
1534 }
Alex Deucher5801ead2009-11-24 13:32:59 -05001535 return MODE_OK;
Alex Deucherd2917672011-05-20 04:34:31 -04001536 } else {
1537 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1538 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
1539 return radeon_dp_mode_valid_helper(connector, mode);
1540 else
1541 return MODE_OK;
1542 }
Alex Deucher5801ead2009-11-24 13:32:59 -05001543}
1544
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001545static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
Dave Airlie746c1aa2009-12-08 07:07:28 +10001546 .get_modes = radeon_dp_get_modes,
Alex Deucher5801ead2009-11-24 13:32:59 -05001547 .mode_valid = radeon_dp_mode_valid,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001548 .best_encoder = radeon_dvi_encoder,
1549};
1550
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001551static const struct drm_connector_funcs radeon_dp_connector_funcs = {
Dave Airlie746c1aa2009-12-08 07:07:28 +10001552 .dpms = drm_helper_connector_dpms,
1553 .detect = radeon_dp_detect,
1554 .fill_modes = drm_helper_probe_single_connector_modes,
1555 .set_property = radeon_connector_set_property,
Alex Deucherffd09c62009-11-24 16:13:23 -05001556 .destroy = radeon_dp_connector_destroy,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001557 .force = radeon_dvi_force,
1558};
1559
Alex Deucher855f5f12013-09-13 18:33:16 -04001560static const struct drm_connector_funcs radeon_edp_connector_funcs = {
1561 .dpms = drm_helper_connector_dpms,
1562 .detect = radeon_dp_detect,
1563 .fill_modes = drm_helper_probe_single_connector_modes,
1564 .set_property = radeon_lvds_set_property,
1565 .destroy = radeon_dp_connector_destroy,
1566 .force = radeon_dvi_force,
1567};
1568
1569static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
1570 .dpms = drm_helper_connector_dpms,
1571 .detect = radeon_dp_detect,
1572 .fill_modes = drm_helper_probe_single_connector_modes,
1573 .set_property = radeon_lvds_set_property,
1574 .destroy = radeon_dp_connector_destroy,
1575 .force = radeon_dvi_force,
1576};
1577
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001578void
1579radeon_add_atom_connector(struct drm_device *dev,
1580 uint32_t connector_id,
1581 uint32_t supported_device,
1582 int connector_type,
1583 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -05001584 uint32_t igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -05001585 uint16_t connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -04001586 struct radeon_hpd *hpd,
1587 struct radeon_router *router)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001588{
Dave Airlie445282d2009-09-09 17:40:54 +10001589 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001590 struct drm_connector *connector;
1591 struct radeon_connector *radeon_connector;
1592 struct radeon_connector_atom_dig *radeon_dig_connector;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001593 struct drm_encoder *encoder;
1594 struct radeon_encoder *radeon_encoder;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001595 uint32_t subpixel_order = SubPixelNone;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001596 bool shared_ddc = false;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001597 bool is_dp_bridge = false;
Alex Deucher496263b2014-03-21 10:34:07 -04001598 bool has_aux = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001599
Dave Airlie4ce001a2009-08-13 16:32:14 +10001600 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001601 return;
1602
Alex Deuchercf4c12f2010-09-01 17:15:06 -04001603 /* if the user selected tv=0 don't try and add the connector */
1604 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1605 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1606 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1607 (radeon_tv == 0))
1608 return;
1609
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001610 /* see if we already added it */
1611 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1612 radeon_connector = to_radeon_connector(connector);
1613 if (radeon_connector->connector_id == connector_id) {
1614 radeon_connector->devices |= supported_device;
1615 return;
1616 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001617 if (radeon_connector->ddc_bus && i2c_bus->valid) {
Alex Deucherd3932d62010-02-19 02:13:56 -05001618 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001619 radeon_connector->shared_ddc = true;
1620 shared_ddc = true;
1621 }
Alex Deucherfb939df2010-11-08 16:08:29 +00001622 if (radeon_connector->router_bus && router->ddc_valid &&
Alex Deucher26b5bc92010-08-05 21:21:18 -04001623 (radeon_connector->router.router_id == router->router_id)) {
1624 radeon_connector->shared_ddc = false;
1625 shared_ddc = false;
1626 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001627 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001628 }
1629
Alex Deuchereac4dff2011-05-20 04:34:22 -04001630 /* check if it's a dp bridge */
1631 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1632 radeon_encoder = to_radeon_encoder(encoder);
1633 if (radeon_encoder->devices & supported_device) {
1634 switch (radeon_encoder->encoder_id) {
1635 case ENCODER_OBJECT_ID_TRAVIS:
1636 case ENCODER_OBJECT_ID_NUTMEG:
1637 is_dp_bridge = true;
1638 break;
1639 default:
1640 break;
1641 }
1642 }
1643 }
1644
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001645 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1646 if (!radeon_connector)
1647 return;
1648
1649 connector = &radeon_connector->base;
1650
1651 radeon_connector->connector_id = connector_id;
1652 radeon_connector->devices = supported_device;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001653 radeon_connector->shared_ddc = shared_ddc;
Alex Deucherb75fad02009-11-05 13:16:01 -05001654 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05001655 radeon_connector->hpd = *hpd;
Alex Deucherbc1c4dc2011-10-30 16:54:27 -04001656
Alex Deucher26b5bc92010-08-05 21:21:18 -04001657 radeon_connector->router = *router;
Alex Deucherfb939df2010-11-08 16:08:29 +00001658 if (router->ddc_valid || router->cd_valid) {
Alex Deucher26b5bc92010-08-05 21:21:18 -04001659 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1660 if (!radeon_connector->router_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04001661 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
Alex Deucher26b5bc92010-08-05 21:21:18 -04001662 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001663
1664 if (is_dp_bridge) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001665 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1666 if (!radeon_dig_connector)
1667 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001668 radeon_dig_connector->igp_lane_info = igp_lane_info;
1669 radeon_connector->con_priv = radeon_dig_connector;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001670 if (i2c_bus->valid) {
Alex Deuchereac4dff2011-05-20 04:34:22 -04001671 /* add DP i2c bus */
1672 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1673 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1674 else
1675 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
Alex Deucher496263b2014-03-21 10:34:07 -04001676 if (radeon_dig_connector->dp_i2c_bus)
1677 has_aux = true;
1678 else
Alex Deuchereac4dff2011-05-20 04:34:22 -04001679 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
Alex Deucherf376b942010-08-05 21:21:16 -04001680 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001681 if (!radeon_connector->ddc_bus)
Alex Deuchereac4dff2011-05-20 04:34:22 -04001682 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001683 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001684 switch (connector_type) {
1685 case DRM_MODE_CONNECTOR_VGA:
1686 case DRM_MODE_CONNECTOR_DVIA:
1687 default:
Alex Deucher855f5f12013-09-13 18:33:16 -04001688 drm_connector_init(dev, &radeon_connector->base,
1689 &radeon_dp_connector_funcs, connector_type);
1690 drm_connector_helper_add(&radeon_connector->base,
1691 &radeon_dp_connector_helper_funcs);
Alex Deuchereac4dff2011-05-20 04:34:22 -04001692 connector->interlace_allowed = true;
1693 connector->doublescan_allowed = true;
Alex Deucherd629a3c2011-06-13 17:13:33 -04001694 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05001695 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucherd629a3c2011-06-13 17:13:33 -04001696 rdev->mode_info.load_detect_property,
1697 1);
Alex Deuchereac4dff2011-05-20 04:34:22 -04001698 break;
1699 case DRM_MODE_CONNECTOR_DVII:
1700 case DRM_MODE_CONNECTOR_DVID:
1701 case DRM_MODE_CONNECTOR_HDMIA:
1702 case DRM_MODE_CONNECTOR_HDMIB:
1703 case DRM_MODE_CONNECTOR_DisplayPort:
Alex Deucher855f5f12013-09-13 18:33:16 -04001704 drm_connector_init(dev, &radeon_connector->base,
1705 &radeon_dp_connector_funcs, connector_type);
1706 drm_connector_helper_add(&radeon_connector->base,
1707 &radeon_dp_connector_helper_funcs);
Rob Clarke35755f2012-10-11 20:44:52 -05001708 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher430f70d2010-08-04 03:45:04 -04001709 rdev->mode_info.underscan_property,
Alex Deucher56bec7c2011-01-05 11:57:52 -05001710 UNDERSCAN_OFF);
Rob Clarke35755f2012-10-11 20:44:52 -05001711 drm_object_attach_property(&radeon_connector->base.base,
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001712 rdev->mode_info.underscan_hborder_property,
1713 0);
Rob Clarke35755f2012-10-11 20:44:52 -05001714 drm_object_attach_property(&radeon_connector->base.base,
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001715 rdev->mode_info.underscan_vborder_property,
1716 0);
Dave Airlie91915262013-11-08 16:34:39 +10001717
Alex Deucher6214bb72013-09-24 17:26:26 -04001718 drm_object_attach_property(&radeon_connector->base.base,
1719 rdev->mode_info.dither_property,
1720 RADEON_FMT_DITHER_DISABLE);
Dave Airlie91915262013-11-08 16:34:39 +10001721
Alex Deucher108dc8e2013-10-14 13:17:50 -04001722 if (radeon_audio != 0)
1723 drm_object_attach_property(&radeon_connector->base.base,
1724 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05001725 RADEON_AUDIO_AUTO);
Dave Airlie91915262013-11-08 16:34:39 +10001726
Alex Deuchereac4dff2011-05-20 04:34:22 -04001727 subpixel_order = SubPixelHorizontalRGB;
1728 connector->interlace_allowed = true;
1729 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1730 connector->doublescan_allowed = true;
1731 else
1732 connector->doublescan_allowed = false;
Alex Deucherd629a3c2011-06-13 17:13:33 -04001733 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1734 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05001735 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucherd629a3c2011-06-13 17:13:33 -04001736 rdev->mode_info.load_detect_property,
1737 1);
1738 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001739 break;
1740 case DRM_MODE_CONNECTOR_LVDS:
1741 case DRM_MODE_CONNECTOR_eDP:
Alex Deucher855f5f12013-09-13 18:33:16 -04001742 drm_connector_init(dev, &radeon_connector->base,
1743 &radeon_lvds_bridge_connector_funcs, connector_type);
1744 drm_connector_helper_add(&radeon_connector->base,
1745 &radeon_dp_connector_helper_funcs);
Rob Clarke35755f2012-10-11 20:44:52 -05001746 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001747 dev->mode_config.scaling_mode_property,
1748 DRM_MODE_SCALE_FULLSCREEN);
1749 subpixel_order = SubPixelHorizontalRGB;
1750 connector->interlace_allowed = false;
1751 connector->doublescan_allowed = false;
1752 break;
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001753 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001754 } else {
1755 switch (connector_type) {
1756 case DRM_MODE_CONNECTOR_VGA:
1757 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1758 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1759 if (i2c_bus->valid) {
1760 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1761 if (!radeon_connector->ddc_bus)
1762 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1763 }
Alex Deucher390d0bb2009-12-08 12:48:20 -05001764 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05001765 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher390d0bb2009-12-08 12:48:20 -05001766 rdev->mode_info.load_detect_property,
1767 1);
Alex Deuchereac4dff2011-05-20 04:34:22 -04001768 /* no HPD on analog connectors */
1769 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1770 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1771 connector->interlace_allowed = true;
Alex Deucherc49948f2010-11-30 15:46:47 -05001772 connector->doublescan_allowed = true;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001773 break;
1774 case DRM_MODE_CONNECTOR_DVIA:
1775 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1776 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1777 if (i2c_bus->valid) {
1778 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1779 if (!radeon_connector->ddc_bus)
1780 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1781 }
1782 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05001783 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001784 rdev->mode_info.load_detect_property,
1785 1);
1786 /* no HPD on analog connectors */
1787 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1788 connector->interlace_allowed = true;
Alex Deucherc49948f2010-11-30 15:46:47 -05001789 connector->doublescan_allowed = true;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001790 break;
1791 case DRM_MODE_CONNECTOR_DVII:
1792 case DRM_MODE_CONNECTOR_DVID:
1793 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1794 if (!radeon_dig_connector)
1795 goto failed;
1796 radeon_dig_connector->igp_lane_info = igp_lane_info;
1797 radeon_connector->con_priv = radeon_dig_connector;
1798 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1799 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1800 if (i2c_bus->valid) {
1801 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1802 if (!radeon_connector->ddc_bus)
1803 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1804 }
1805 subpixel_order = SubPixelHorizontalRGB;
Rob Clarke35755f2012-10-11 20:44:52 -05001806 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001807 rdev->mode_info.coherent_mode_property,
1808 1);
1809 if (ASIC_IS_AVIVO(rdev)) {
Rob Clarke35755f2012-10-11 20:44:52 -05001810 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001811 rdev->mode_info.underscan_property,
1812 UNDERSCAN_OFF);
Rob Clarke35755f2012-10-11 20:44:52 -05001813 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001814 rdev->mode_info.underscan_hborder_property,
1815 0);
Rob Clarke35755f2012-10-11 20:44:52 -05001816 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001817 rdev->mode_info.underscan_vborder_property,
1818 0);
1819 }
Alex Deucher108dc8e2013-10-14 13:17:50 -04001820 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
Alex Deucher8666c072013-09-03 14:58:44 -04001821 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher108dc8e2013-10-14 13:17:50 -04001822 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05001823 RADEON_AUDIO_AUTO);
Alex Deucher8666c072013-09-03 14:58:44 -04001824 }
Alex Deucher6214bb72013-09-24 17:26:26 -04001825 if (ASIC_IS_AVIVO(rdev)) {
1826 drm_object_attach_property(&radeon_connector->base.base,
1827 rdev->mode_info.dither_property,
1828 RADEON_FMT_DITHER_DISABLE);
1829 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001830 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1831 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05001832 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001833 rdev->mode_info.load_detect_property,
1834 1);
1835 }
1836 connector->interlace_allowed = true;
1837 if (connector_type == DRM_MODE_CONNECTOR_DVII)
1838 connector->doublescan_allowed = true;
1839 else
1840 connector->doublescan_allowed = false;
1841 break;
1842 case DRM_MODE_CONNECTOR_HDMIA:
1843 case DRM_MODE_CONNECTOR_HDMIB:
1844 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1845 if (!radeon_dig_connector)
1846 goto failed;
1847 radeon_dig_connector->igp_lane_info = igp_lane_info;
1848 radeon_connector->con_priv = radeon_dig_connector;
1849 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1850 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1851 if (i2c_bus->valid) {
1852 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1853 if (!radeon_connector->ddc_bus)
1854 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1855 }
Rob Clarke35755f2012-10-11 20:44:52 -05001856 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001857 rdev->mode_info.coherent_mode_property,
1858 1);
1859 if (ASIC_IS_AVIVO(rdev)) {
Rob Clarke35755f2012-10-11 20:44:52 -05001860 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001861 rdev->mode_info.underscan_property,
1862 UNDERSCAN_OFF);
Rob Clarke35755f2012-10-11 20:44:52 -05001863 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001864 rdev->mode_info.underscan_hborder_property,
1865 0);
Rob Clarke35755f2012-10-11 20:44:52 -05001866 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001867 rdev->mode_info.underscan_vborder_property,
1868 0);
1869 }
Alex Deucher108dc8e2013-10-14 13:17:50 -04001870 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
Alex Deucher8666c072013-09-03 14:58:44 -04001871 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher108dc8e2013-10-14 13:17:50 -04001872 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05001873 RADEON_AUDIO_AUTO);
Alex Deucher8666c072013-09-03 14:58:44 -04001874 }
Alex Deucher6214bb72013-09-24 17:26:26 -04001875 if (ASIC_IS_AVIVO(rdev)) {
1876 drm_object_attach_property(&radeon_connector->base.base,
1877 rdev->mode_info.dither_property,
1878 RADEON_FMT_DITHER_DISABLE);
1879 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001880 subpixel_order = SubPixelHorizontalRGB;
1881 connector->interlace_allowed = true;
1882 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1883 connector->doublescan_allowed = true;
1884 else
1885 connector->doublescan_allowed = false;
1886 break;
1887 case DRM_MODE_CONNECTOR_DisplayPort:
1888 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1889 if (!radeon_dig_connector)
1890 goto failed;
1891 radeon_dig_connector->igp_lane_info = igp_lane_info;
1892 radeon_connector->con_priv = radeon_dig_connector;
1893 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1894 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1895 if (i2c_bus->valid) {
1896 /* add DP i2c bus */
1897 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1898 if (!radeon_dig_connector->dp_i2c_bus)
1899 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1900 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Alex Deucher496263b2014-03-21 10:34:07 -04001901 if (radeon_connector->ddc_bus)
1902 has_aux = true;
1903 else
Alex Deuchereac4dff2011-05-20 04:34:22 -04001904 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1905 }
1906 subpixel_order = SubPixelHorizontalRGB;
Rob Clarke35755f2012-10-11 20:44:52 -05001907 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001908 rdev->mode_info.coherent_mode_property,
1909 1);
1910 if (ASIC_IS_AVIVO(rdev)) {
Rob Clarke35755f2012-10-11 20:44:52 -05001911 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001912 rdev->mode_info.underscan_property,
1913 UNDERSCAN_OFF);
Rob Clarke35755f2012-10-11 20:44:52 -05001914 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001915 rdev->mode_info.underscan_hborder_property,
1916 0);
Rob Clarke35755f2012-10-11 20:44:52 -05001917 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001918 rdev->mode_info.underscan_vborder_property,
1919 0);
1920 }
Alex Deucher108dc8e2013-10-14 13:17:50 -04001921 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
Alex Deucher8666c072013-09-03 14:58:44 -04001922 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher108dc8e2013-10-14 13:17:50 -04001923 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05001924 RADEON_AUDIO_AUTO);
Alex Deucher8666c072013-09-03 14:58:44 -04001925 }
Alex Deucher6214bb72013-09-24 17:26:26 -04001926 if (ASIC_IS_AVIVO(rdev)) {
1927 drm_object_attach_property(&radeon_connector->base.base,
1928 rdev->mode_info.dither_property,
1929 RADEON_FMT_DITHER_DISABLE);
Dave Airlie91915262013-11-08 16:34:39 +10001930
Alex Deucher6214bb72013-09-24 17:26:26 -04001931 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001932 connector->interlace_allowed = true;
1933 /* in theory with a DP to VGA converter... */
Alex Deucherc49948f2010-11-30 15:46:47 -05001934 connector->doublescan_allowed = false;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001935 break;
1936 case DRM_MODE_CONNECTOR_eDP:
1937 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1938 if (!radeon_dig_connector)
1939 goto failed;
1940 radeon_dig_connector->igp_lane_info = igp_lane_info;
1941 radeon_connector->con_priv = radeon_dig_connector;
Alex Deucher855f5f12013-09-13 18:33:16 -04001942 drm_connector_init(dev, &radeon_connector->base, &radeon_edp_connector_funcs, connector_type);
Alex Deuchereac4dff2011-05-20 04:34:22 -04001943 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1944 if (i2c_bus->valid) {
1945 /* add DP i2c bus */
1946 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
Alex Deucher496263b2014-03-21 10:34:07 -04001947 if (radeon_dig_connector->dp_i2c_bus)
1948 has_aux = true;
1949 else
Alex Deuchereac4dff2011-05-20 04:34:22 -04001950 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1951 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1952 if (!radeon_connector->ddc_bus)
1953 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1954 }
Rob Clarke35755f2012-10-11 20:44:52 -05001955 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001956 dev->mode_config.scaling_mode_property,
1957 DRM_MODE_SCALE_FULLSCREEN);
1958 subpixel_order = SubPixelHorizontalRGB;
1959 connector->interlace_allowed = false;
1960 connector->doublescan_allowed = false;
1961 break;
1962 case DRM_MODE_CONNECTOR_SVIDEO:
1963 case DRM_MODE_CONNECTOR_Composite:
1964 case DRM_MODE_CONNECTOR_9PinDIN:
1965 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1966 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1967 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05001968 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001969 rdev->mode_info.load_detect_property,
1970 1);
Rob Clarke35755f2012-10-11 20:44:52 -05001971 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001972 rdev->mode_info.tv_std_property,
1973 radeon_atombios_get_tv_info(rdev));
1974 /* no HPD on analog connectors */
1975 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1976 connector->interlace_allowed = false;
1977 connector->doublescan_allowed = false;
1978 break;
1979 case DRM_MODE_CONNECTOR_LVDS:
1980 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1981 if (!radeon_dig_connector)
1982 goto failed;
1983 radeon_dig_connector->igp_lane_info = igp_lane_info;
1984 radeon_connector->con_priv = radeon_dig_connector;
1985 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1986 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1987 if (i2c_bus->valid) {
1988 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1989 if (!radeon_connector->ddc_bus)
1990 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1991 }
Rob Clarke35755f2012-10-11 20:44:52 -05001992 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001993 dev->mode_config.scaling_mode_property,
1994 DRM_MODE_SCALE_FULLSCREEN);
1995 subpixel_order = SubPixelHorizontalRGB;
1996 connector->interlace_allowed = false;
1997 connector->doublescan_allowed = false;
1998 break;
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001999 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002000 }
2001
Alex Deucher2581afc2010-07-20 03:24:11 -04002002 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002003 if (i2c_bus->valid)
2004 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2005 } else
2006 connector->polled = DRM_CONNECTOR_POLL_HPD;
2007
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002008 connector->display_info.subpixel_order = subpixel_order;
2009 drm_sysfs_connector_add(connector);
Alex Deucher496263b2014-03-21 10:34:07 -04002010
2011 if (has_aux)
2012 radeon_dp_aux_init(radeon_connector);
2013
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002014 return;
2015
2016failed:
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002017 drm_connector_cleanup(connector);
2018 kfree(connector);
2019}
2020
2021void
2022radeon_add_legacy_connector(struct drm_device *dev,
2023 uint32_t connector_id,
2024 uint32_t supported_device,
2025 int connector_type,
Alex Deucherb75fad02009-11-05 13:16:01 -05002026 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -05002027 uint16_t connector_object_id,
2028 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002029{
Dave Airlie445282d2009-09-09 17:40:54 +10002030 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002031 struct drm_connector *connector;
2032 struct radeon_connector *radeon_connector;
2033 uint32_t subpixel_order = SubPixelNone;
2034
Dave Airlie4ce001a2009-08-13 16:32:14 +10002035 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002036 return;
2037
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002038 /* if the user selected tv=0 don't try and add the connector */
2039 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
2040 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
2041 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
2042 (radeon_tv == 0))
2043 return;
2044
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002045 /* see if we already added it */
2046 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2047 radeon_connector = to_radeon_connector(connector);
2048 if (radeon_connector->connector_id == connector_id) {
2049 radeon_connector->devices |= supported_device;
2050 return;
2051 }
2052 }
2053
2054 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
2055 if (!radeon_connector)
2056 return;
2057
2058 connector = &radeon_connector->base;
2059
2060 radeon_connector->connector_id = connector_id;
2061 radeon_connector->devices = supported_device;
Alex Deucherb75fad02009-11-05 13:16:01 -05002062 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05002063 radeon_connector->hpd = *hpd;
Alex Deucherbc1c4dc2011-10-30 16:54:27 -04002064
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002065 switch (connector_type) {
2066 case DRM_MODE_CONNECTOR_VGA:
2067 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002068 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002069 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002070 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002071 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002072 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002073 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10002074 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002075 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002076 rdev->mode_info.load_detect_property,
2077 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04002078 /* no HPD on analog connectors */
2079 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002080 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
Alex Deucherc49948f2010-11-30 15:46:47 -05002081 connector->interlace_allowed = true;
2082 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002083 break;
2084 case DRM_MODE_CONNECTOR_DVIA:
2085 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002086 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002087 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002088 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002089 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002090 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002091 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10002092 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002093 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002094 rdev->mode_info.load_detect_property,
2095 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04002096 /* no HPD on analog connectors */
2097 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05002098 connector->interlace_allowed = true;
2099 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002100 break;
2101 case DRM_MODE_CONNECTOR_DVII:
2102 case DRM_MODE_CONNECTOR_DVID:
2103 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002104 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002105 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002106 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002107 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002108 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Alex Deucher68b3adb2010-04-30 12:37:31 -04002109 }
2110 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
Dave Airlie35e4b7a2009-09-25 11:56:50 +10002111 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002112 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002113 rdev->mode_info.load_detect_property,
2114 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002115 }
2116 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05002117 connector->interlace_allowed = true;
2118 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2119 connector->doublescan_allowed = true;
2120 else
2121 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002122 break;
2123 case DRM_MODE_CONNECTOR_SVIDEO:
2124 case DRM_MODE_CONNECTOR_Composite:
2125 case DRM_MODE_CONNECTOR_9PinDIN:
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002126 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
2127 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2128 radeon_connector->dac_load_detect = true;
2129 /* RS400,RC410,RS480 chipset seems to report a lot
2130 * of false positive on load detect, we haven't yet
2131 * found a way to make load detect reliable on those
2132 * chipset, thus just disable it for TV.
2133 */
2134 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
2135 radeon_connector->dac_load_detect = false;
Rob Clarke35755f2012-10-11 20:44:52 -05002136 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002137 rdev->mode_info.load_detect_property,
2138 radeon_connector->dac_load_detect);
Rob Clarke35755f2012-10-11 20:44:52 -05002139 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002140 rdev->mode_info.tv_std_property,
2141 radeon_combios_get_tv_info(rdev));
2142 /* no HPD on analog connectors */
2143 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05002144 connector->interlace_allowed = false;
2145 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002146 break;
2147 case DRM_MODE_CONNECTOR_LVDS:
2148 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002149 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002150 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002151 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002152 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002153 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002154 }
Rob Clarke35755f2012-10-11 20:44:52 -05002155 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002156 dev->mode_config.scaling_mode_property,
2157 DRM_MODE_SCALE_FULLSCREEN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002158 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05002159 connector->interlace_allowed = false;
2160 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002161 break;
2162 }
2163
Alex Deucher2581afc2010-07-20 03:24:11 -04002164 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002165 if (i2c_bus->valid)
2166 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2167 } else
2168 connector->polled = DRM_CONNECTOR_POLL_HPD;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002169 connector->display_info.subpixel_order = subpixel_order;
2170 drm_sysfs_connector_add(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002171}