1 /*
2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors: Dave Airlie
24 * Alex Deucher
25 */
26
27 #include <drm/display/drm_dp_mst_helper.h>
28 #include <drm/drm_edid.h>
29 #include <drm/drm_crtc_helper.h>
30 #include <drm/drm_modeset_helper_vtables.h>
31 #include <drm/drm_probe_helper.h>
32 #include <drm/radeon_drm.h>
33 #include "radeon.h"
34 #include "radeon_audio.h"
35 #include "atom.h"
36
37 #include <linux/pm_runtime.h>
38 #include <linux/vga_switcheroo.h>
39
radeon_connector_hotplug(struct drm_connector * connector)40 void radeon_connector_hotplug(struct drm_connector *connector)
41 {
42 struct drm_device *dev = connector->dev;
43 struct radeon_device *rdev = dev->dev_private;
44 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
45
46 /* bail if the connector does not have hpd pin, e.g.,
47 * VGA, TV, etc.
48 */
49 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE)
50 return;
51
52 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
53
54 /* if the connector is already off, don't turn it back on */
55 /* FIXME: This access isn't protected by any locks. */
56 if (connector->dpms != DRM_MODE_DPMS_ON)
57 return;
58
59 /* just deal with DP (not eDP) here. */
60 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
61 struct radeon_connector_atom_dig *dig_connector =
62 radeon_connector->con_priv;
63
64 /* if existing sink type was not DP no need to retrain */
65 if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT)
66 return;
67
68 /* first get sink type as it may be reset after (un)plug */
69 dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
70 /* don't do anything if sink is not display port, i.e.,
71 * passive dp->(dvi|hdmi) adaptor
72 */
73 if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT &&
74 radeon_hpd_sense(rdev, radeon_connector->hpd.hpd) &&
75 radeon_dp_needs_link_train(radeon_connector)) {
76 /* Don't start link training before we have the DPCD */
77 if (!radeon_dp_getdpcd(radeon_connector))
78 return;
79
80 /* Turn the connector off and back on immediately, which
81 * will trigger link training
82 */
83 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
84 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
85 }
86 }
87 }
88
radeon_property_change_mode(struct drm_encoder * encoder)89 static void radeon_property_change_mode(struct drm_encoder *encoder)
90 {
91 struct drm_crtc *crtc = encoder->crtc;
92
93 if (crtc && crtc->enabled) {
94 drm_crtc_helper_set_mode(crtc, &crtc->mode,
95 crtc->x, crtc->y, crtc->primary->fb);
96 }
97 }
98
radeon_get_monitor_bpc(struct drm_connector * connector)99 int radeon_get_monitor_bpc(struct drm_connector *connector)
100 {
101 struct drm_device *dev = connector->dev;
102 struct radeon_device *rdev = dev->dev_private;
103 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
104 struct radeon_connector_atom_dig *dig_connector;
105 int bpc = 8;
106 int mode_clock, max_tmds_clock;
107
108 switch (connector->connector_type) {
109 case DRM_MODE_CONNECTOR_DVII:
110 case DRM_MODE_CONNECTOR_HDMIB:
111 if (radeon_connector->use_digital) {
112 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
113 if (connector->display_info.bpc)
114 bpc = connector->display_info.bpc;
115 }
116 }
117 break;
118 case DRM_MODE_CONNECTOR_DVID:
119 case DRM_MODE_CONNECTOR_HDMIA:
120 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
121 if (connector->display_info.bpc)
122 bpc = connector->display_info.bpc;
123 }
124 break;
125 case DRM_MODE_CONNECTOR_DisplayPort:
126 dig_connector = radeon_connector->con_priv;
127 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
128 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) ||
129 drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
130 if (connector->display_info.bpc)
131 bpc = connector->display_info.bpc;
132 }
133 break;
134 case DRM_MODE_CONNECTOR_eDP:
135 case DRM_MODE_CONNECTOR_LVDS:
136 if (connector->display_info.bpc)
137 bpc = connector->display_info.bpc;
138 else if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
139 const struct drm_connector_helper_funcs *connector_funcs =
140 connector->helper_private;
141 struct drm_encoder *encoder = connector_funcs->best_encoder(connector);
142 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
143 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
144
145 if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR)
146 bpc = 6;
147 else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR)
148 bpc = 8;
149 }
150 break;
151 }
152
153 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
154 /* hdmi deep color only implemented on DCE4+ */
155 if ((bpc > 8) && !ASIC_IS_DCE4(rdev)) {
156 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 8 bpc.\n",
157 connector->name, bpc);
158 bpc = 8;
159 }
160
161 /*
162 * Pre DCE-8 hw can't handle > 12 bpc, and more than 12 bpc doesn't make
163 * much sense without support for > 12 bpc framebuffers. RGB 4:4:4 at
164 * 12 bpc is always supported on hdmi deep color sinks, as this is
165 * required by the HDMI-1.3 spec. Clamp to a safe 12 bpc maximum.
166 */
167 if (bpc > 12) {
168 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 12 bpc.\n",
169 connector->name, bpc);
170 bpc = 12;
171 }
172
173 /* Any defined maximum tmds clock limit we must not exceed? */
174 if (connector->display_info.max_tmds_clock > 0) {
175 /* mode_clock is clock in kHz for mode to be modeset on this connector */
176 mode_clock = radeon_connector->pixelclock_for_modeset;
177
178 /* Maximum allowable input clock in kHz */
179 max_tmds_clock = connector->display_info.max_tmds_clock;
180
181 DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds input clock %d kHz.\n",
182 connector->name, mode_clock, max_tmds_clock);
183
184 /* Check if bpc is within clock limit. Try to degrade gracefully otherwise */
185 if ((bpc == 12) && (mode_clock * 3/2 > max_tmds_clock)) {
186 if ((connector->display_info.edid_hdmi_rgb444_dc_modes & DRM_EDID_HDMI_DC_30) &&
187 (mode_clock * 5/4 <= max_tmds_clock))
188 bpc = 10;
189 else
190 bpc = 8;
191
192 DRM_DEBUG("%s: HDMI deep color 12 bpc exceeds max tmds clock. Using %d bpc.\n",
193 connector->name, bpc);
194 }
195
196 if ((bpc == 10) && (mode_clock * 5/4 > max_tmds_clock)) {
197 bpc = 8;
198 DRM_DEBUG("%s: HDMI deep color 10 bpc exceeds max tmds clock. Using %d bpc.\n",
199 connector->name, bpc);
200 }
201 } else if (bpc > 8) {
202 /* max_tmds_clock missing, but hdmi spec mandates it for deep color. */
203 DRM_DEBUG("%s: Required max tmds clock for HDMI deep color missing. Using 8 bpc.\n",
204 connector->name);
205 bpc = 8;
206 }
207 }
208
209 if ((radeon_deep_color == 0) && (bpc > 8)) {
210 DRM_DEBUG("%s: Deep color disabled. Set radeon module param deep_color=1 to enable.\n",
211 connector->name);
212 bpc = 8;
213 }
214
215 DRM_DEBUG("%s: Display bpc=%d, returned bpc=%d\n",
216 connector->name, connector->display_info.bpc, bpc);
217
218 return bpc;
219 }
220
221 static void
radeon_connector_update_scratch_regs(struct drm_connector * connector,enum drm_connector_status status)222 radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
223 {
224 struct drm_device *dev = connector->dev;
225 struct radeon_device *rdev = dev->dev_private;
226 struct drm_encoder *best_encoder;
227 struct drm_encoder *encoder;
228 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
229 bool connected;
230
231 best_encoder = connector_funcs->best_encoder(connector);
232
233 drm_connector_for_each_possible_encoder(connector, encoder) {
234 if ((encoder == best_encoder) && (status == connector_status_connected))
235 connected = true;
236 else
237 connected = false;
238
239 if (rdev->is_atom_bios)
240 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
241 else
242 radeon_combios_connected_scratch_regs(connector, encoder, connected);
243 }
244 }
245
radeon_find_encoder(struct drm_connector * connector,int encoder_type)246 static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
247 {
248 struct drm_encoder *encoder;
249
250 drm_connector_for_each_possible_encoder(connector, encoder) {
251 if (encoder->encoder_type == encoder_type)
252 return encoder;
253 }
254
255 return NULL;
256 }
257
radeon_connector_edid(struct drm_connector * connector)258 struct edid *radeon_connector_edid(struct drm_connector *connector)
259 {
260 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
261 struct drm_property_blob *edid_blob = connector->edid_blob_ptr;
262
263 if (radeon_connector->edid) {
264 return radeon_connector->edid;
265 } else if (edid_blob) {
266 struct edid *edid = kmemdup(edid_blob->data, edid_blob->length, GFP_KERNEL);
267 if (edid)
268 radeon_connector->edid = edid;
269 }
270 return radeon_connector->edid;
271 }
272
radeon_connector_get_edid(struct drm_connector * connector)273 static void radeon_connector_get_edid(struct drm_connector *connector)
274 {
275 struct drm_device *dev = connector->dev;
276 struct radeon_device *rdev = dev->dev_private;
277 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
278
279 if (radeon_connector->edid)
280 return;
281
282 /* on hw with routers, select right port */
283 if (radeon_connector->router.ddc_valid)
284 radeon_router_select_ddc_port(radeon_connector);
285
286 if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
287 ENCODER_OBJECT_ID_NONE) &&
288 radeon_connector->ddc_bus->has_aux) {
289 radeon_connector->edid = drm_get_edid(connector,
290 &radeon_connector->ddc_bus->aux.ddc);
291 } else if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
292 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
293 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
294
295 if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
296 dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) &&
297 radeon_connector->ddc_bus->has_aux)
298 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
299 &radeon_connector->ddc_bus->aux.ddc);
300 else if (radeon_connector->ddc_bus)
301 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
302 &radeon_connector->ddc_bus->adapter);
303 } else if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC &&
304 connector->connector_type == DRM_MODE_CONNECTOR_LVDS &&
305 radeon_connector->ddc_bus) {
306 radeon_connector->edid = drm_get_edid_switcheroo(&radeon_connector->base,
307 &radeon_connector->ddc_bus->adapter);
308 } else if (radeon_connector->ddc_bus) {
309 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
310 &radeon_connector->ddc_bus->adapter);
311 }
312
313 if (!radeon_connector->edid) {
314 /* don't fetch the edid from the vbios if ddc fails and runpm is
315 * enabled so we report disconnected.
316 */
317 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
318 return;
319
320 if (rdev->is_atom_bios) {
321 /* some laptops provide a hardcoded edid in rom for LCDs */
322 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
323 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)))
324 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
325 } else {
326 /* some servers provide a hardcoded edid in rom for KVMs */
327 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
328 }
329 }
330 }
331
radeon_connector_free_edid(struct drm_connector * connector)332 static void radeon_connector_free_edid(struct drm_connector *connector)
333 {
334 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
335
336 kfree(radeon_connector->edid);
337 radeon_connector->edid = NULL;
338 }
339
radeon_ddc_get_modes(struct drm_connector * connector)340 static int radeon_ddc_get_modes(struct drm_connector *connector)
341 {
342 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
343 int ret;
344
345 if (radeon_connector->edid) {
346 drm_connector_update_edid_property(connector, radeon_connector->edid);
347 ret = drm_add_edid_modes(connector, radeon_connector->edid);
348 return ret;
349 }
350 drm_connector_update_edid_property(connector, NULL);
351 return 0;
352 }
353
radeon_best_single_encoder(struct drm_connector * connector)354 static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
355 {
356 struct drm_encoder *encoder;
357
358 /* pick the first one */
359 drm_connector_for_each_possible_encoder(connector, encoder)
360 return encoder;
361
362 return NULL;
363 }
364
radeon_get_native_mode(struct drm_connector * connector)365 static void radeon_get_native_mode(struct drm_connector *connector)
366 {
367 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
368 struct radeon_encoder *radeon_encoder;
369
370 if (encoder == NULL)
371 return;
372
373 radeon_encoder = to_radeon_encoder(encoder);
374
375 if (!list_empty(&connector->probed_modes)) {
376 struct drm_display_mode *preferred_mode =
377 list_first_entry(&connector->probed_modes,
378 struct drm_display_mode, head);
379
380 radeon_encoder->native_mode = *preferred_mode;
381 } else {
382 radeon_encoder->native_mode.clock = 0;
383 }
384 }
385
386 /*
387 * radeon_connector_analog_encoder_conflict_solve
388 * - search for other connectors sharing this encoder
389 * if priority is true, then set them disconnected if this is connected
390 * if priority is false, set us disconnected if they are connected
391 */
392 static enum drm_connector_status
radeon_connector_analog_encoder_conflict_solve(struct drm_connector * connector,struct drm_encoder * encoder,enum drm_connector_status current_status,bool priority)393 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
394 struct drm_encoder *encoder,
395 enum drm_connector_status current_status,
396 bool priority)
397 {
398 struct drm_device *dev = connector->dev;
399 struct drm_connector *conflict;
400 struct radeon_connector *radeon_conflict;
401
402 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
403 struct drm_encoder *enc;
404
405 if (conflict == connector)
406 continue;
407
408 radeon_conflict = to_radeon_connector(conflict);
409
410 drm_connector_for_each_possible_encoder(conflict, enc) {
411 /* if the IDs match */
412 if (enc == encoder) {
413 if (conflict->status != connector_status_connected)
414 continue;
415
416 if (radeon_conflict->use_digital)
417 continue;
418
419 if (priority) {
420 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n",
421 conflict->name);
422 DRM_DEBUG_KMS("in favor of %s\n",
423 connector->name);
424 conflict->status = connector_status_disconnected;
425 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
426 } else {
427 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n",
428 connector->name);
429 DRM_DEBUG_KMS("in favor of %s\n",
430 conflict->name);
431 current_status = connector_status_disconnected;
432 }
433 break;
434 }
435 }
436 }
437 return current_status;
438
439 }
440
radeon_fp_native_mode(struct drm_encoder * encoder)441 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
442 {
443 struct drm_device *dev = encoder->dev;
444 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
445 struct drm_display_mode *mode = NULL;
446 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
447
448 if (native_mode->hdisplay != 0 &&
449 native_mode->vdisplay != 0 &&
450 native_mode->clock != 0) {
451 mode = drm_mode_duplicate(dev, native_mode);
452 if (!mode)
453 return NULL;
454 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
455 drm_mode_set_name(mode);
456
457 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
458 } else if (native_mode->hdisplay != 0 &&
459 native_mode->vdisplay != 0) {
460 /* mac laptops without an edid */
461 /* Note that this is not necessarily the exact panel mode,
462 * but an approximation based on the cvt formula. For these
463 * systems we should ideally read the mode info out of the
464 * registers or add a mode table, but this works and is much
465 * simpler.
466 */
467 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
468 if (!mode)
469 return NULL;
470 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
471 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
472 }
473 return mode;
474 }
475
radeon_add_common_modes(struct drm_encoder * encoder,struct drm_connector * connector)476 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
477 {
478 struct drm_device *dev = encoder->dev;
479 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
480 struct drm_display_mode *mode = NULL;
481 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
482 int i;
483 struct mode_size {
484 int w;
485 int h;
486 } common_modes[17] = {
487 { 640, 480},
488 { 720, 480},
489 { 800, 600},
490 { 848, 480},
491 {1024, 768},
492 {1152, 768},
493 {1280, 720},
494 {1280, 800},
495 {1280, 854},
496 {1280, 960},
497 {1280, 1024},
498 {1440, 900},
499 {1400, 1050},
500 {1680, 1050},
501 {1600, 1200},
502 {1920, 1080},
503 {1920, 1200}
504 };
505
506 for (i = 0; i < 17; i++) {
507 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
508 if (common_modes[i].w > 1024 ||
509 common_modes[i].h > 768)
510 continue;
511 }
512 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
513 if (common_modes[i].w > native_mode->hdisplay ||
514 common_modes[i].h > native_mode->vdisplay ||
515 (common_modes[i].w == native_mode->hdisplay &&
516 common_modes[i].h == native_mode->vdisplay))
517 continue;
518 }
519 if (common_modes[i].w < 320 || common_modes[i].h < 200)
520 continue;
521
522 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
523 drm_mode_probed_add(connector, mode);
524 }
525 }
526
radeon_connector_set_property(struct drm_connector * connector,struct drm_property * property,uint64_t val)527 static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
528 uint64_t val)
529 {
530 struct drm_device *dev = connector->dev;
531 struct radeon_device *rdev = dev->dev_private;
532 struct drm_encoder *encoder;
533 struct radeon_encoder *radeon_encoder;
534
535 if (property == rdev->mode_info.coherent_mode_property) {
536 struct radeon_encoder_atom_dig *dig;
537 bool new_coherent_mode;
538
539 /* need to find digital encoder on connector */
540 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
541 if (!encoder)
542 return 0;
543
544 radeon_encoder = to_radeon_encoder(encoder);
545
546 if (!radeon_encoder->enc_priv)
547 return 0;
548
549 dig = radeon_encoder->enc_priv;
550 new_coherent_mode = val ? true : false;
551 if (dig->coherent_mode != new_coherent_mode) {
552 dig->coherent_mode = new_coherent_mode;
553 radeon_property_change_mode(&radeon_encoder->base);
554 }
555 }
556
557 if (property == rdev->mode_info.audio_property) {
558 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
559 /* need to find digital encoder on connector */
560 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
561 if (!encoder)
562 return 0;
563
564 radeon_encoder = to_radeon_encoder(encoder);
565
566 if (radeon_connector->audio != val) {
567 radeon_connector->audio = val;
568 radeon_property_change_mode(&radeon_encoder->base);
569 }
570 }
571
572 if (property == rdev->mode_info.dither_property) {
573 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
574 /* need to find digital encoder on connector */
575 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
576 if (!encoder)
577 return 0;
578
579 radeon_encoder = to_radeon_encoder(encoder);
580
581 if (radeon_connector->dither != val) {
582 radeon_connector->dither = val;
583 radeon_property_change_mode(&radeon_encoder->base);
584 }
585 }
586
587 if (property == rdev->mode_info.underscan_property) {
588 /* need to find digital encoder on connector */
589 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
590 if (!encoder)
591 return 0;
592
593 radeon_encoder = to_radeon_encoder(encoder);
594
595 if (radeon_encoder->underscan_type != val) {
596 radeon_encoder->underscan_type = val;
597 radeon_property_change_mode(&radeon_encoder->base);
598 }
599 }
600
601 if (property == rdev->mode_info.underscan_hborder_property) {
602 /* need to find digital encoder on connector */
603 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
604 if (!encoder)
605 return 0;
606
607 radeon_encoder = to_radeon_encoder(encoder);
608
609 if (radeon_encoder->underscan_hborder != val) {
610 radeon_encoder->underscan_hborder = val;
611 radeon_property_change_mode(&radeon_encoder->base);
612 }
613 }
614
615 if (property == rdev->mode_info.underscan_vborder_property) {
616 /* need to find digital encoder on connector */
617 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
618 if (!encoder)
619 return 0;
620
621 radeon_encoder = to_radeon_encoder(encoder);
622
623 if (radeon_encoder->underscan_vborder != val) {
624 radeon_encoder->underscan_vborder = val;
625 radeon_property_change_mode(&radeon_encoder->base);
626 }
627 }
628
629 if (property == rdev->mode_info.tv_std_property) {
630 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
631 if (!encoder) {
632 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
633 }
634
635 if (!encoder)
636 return 0;
637
638 radeon_encoder = to_radeon_encoder(encoder);
639 if (!radeon_encoder->enc_priv)
640 return 0;
641 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
642 struct radeon_encoder_atom_dac *dac_int;
643 dac_int = radeon_encoder->enc_priv;
644 dac_int->tv_std = val;
645 } else {
646 struct radeon_encoder_tv_dac *dac_int;
647 dac_int = radeon_encoder->enc_priv;
648 dac_int->tv_std = val;
649 }
650 radeon_property_change_mode(&radeon_encoder->base);
651 }
652
653 if (property == rdev->mode_info.load_detect_property) {
654 struct radeon_connector *radeon_connector =
655 to_radeon_connector(connector);
656
657 if (val == 0)
658 radeon_connector->dac_load_detect = false;
659 else
660 radeon_connector->dac_load_detect = true;
661 }
662
663 if (property == rdev->mode_info.tmds_pll_property) {
664 struct radeon_encoder_int_tmds *tmds = NULL;
665 bool ret = false;
666 /* need to find digital encoder on connector */
667 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
668 if (!encoder)
669 return 0;
670
671 radeon_encoder = to_radeon_encoder(encoder);
672
673 tmds = radeon_encoder->enc_priv;
674 if (!tmds)
675 return 0;
676
677 if (val == 0) {
678 if (rdev->is_atom_bios)
679 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
680 else
681 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
682 }
683 if (val == 1 || !ret)
684 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
685
686 radeon_property_change_mode(&radeon_encoder->base);
687 }
688
689 if (property == dev->mode_config.scaling_mode_property) {
690 enum radeon_rmx_type rmx_type;
691
692 if (connector->encoder)
693 radeon_encoder = to_radeon_encoder(connector->encoder);
694 else {
695 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
696 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
697 }
698
699 switch (val) {
700 default:
701 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
702 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
703 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
704 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
705 }
706 if (radeon_encoder->rmx_type == rmx_type)
707 return 0;
708
709 if ((rmx_type != DRM_MODE_SCALE_NONE) &&
710 (radeon_encoder->native_mode.clock == 0))
711 return 0;
712
713 radeon_encoder->rmx_type = rmx_type;
714
715 radeon_property_change_mode(&radeon_encoder->base);
716 }
717
718 if (property == rdev->mode_info.output_csc_property) {
719 if (connector->encoder)
720 radeon_encoder = to_radeon_encoder(connector->encoder);
721 else {
722 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
723 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
724 }
725
726 if (radeon_encoder->output_csc == val)
727 return 0;
728
729 radeon_encoder->output_csc = val;
730
731 if (connector->encoder && connector->encoder->crtc) {
732 struct drm_crtc *crtc = connector->encoder->crtc;
733 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
734
735 radeon_crtc->output_csc = radeon_encoder->output_csc;
736
737 /*
738 * Our .gamma_set assumes the .gamma_store has been
739 * prefilled and don't care about its arguments.
740 */
741 crtc->funcs->gamma_set(crtc, NULL, NULL, NULL, 0, NULL);
742 }
743 }
744
745 return 0;
746 }
747
radeon_fixup_lvds_native_mode(struct drm_encoder * encoder,struct drm_connector * connector)748 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
749 struct drm_connector *connector)
750 {
751 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
752 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
753 struct drm_display_mode *t, *mode;
754
755 /* If the EDID preferred mode doesn't match the native mode, use it */
756 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
757 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
758 if (mode->hdisplay != native_mode->hdisplay ||
759 mode->vdisplay != native_mode->vdisplay)
760 drm_mode_copy(native_mode, mode);
761 }
762 }
763
764 /* Try to get native mode details from EDID if necessary */
765 if (!native_mode->clock) {
766 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
767 if (mode->hdisplay == native_mode->hdisplay &&
768 mode->vdisplay == native_mode->vdisplay) {
769 drm_mode_copy(native_mode, mode);
770 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
771 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
772 break;
773 }
774 }
775 }
776
777 if (!native_mode->clock) {
778 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
779 radeon_encoder->rmx_type = RMX_OFF;
780 }
781 }
782
radeon_lvds_get_modes(struct drm_connector * connector)783 static int radeon_lvds_get_modes(struct drm_connector *connector)
784 {
785 struct drm_encoder *encoder;
786 int ret = 0;
787 struct drm_display_mode *mode;
788
789 radeon_connector_get_edid(connector);
790 ret = radeon_ddc_get_modes(connector);
791 if (ret > 0) {
792 encoder = radeon_best_single_encoder(connector);
793 if (encoder) {
794 radeon_fixup_lvds_native_mode(encoder, connector);
795 /* add scaled modes */
796 radeon_add_common_modes(encoder, connector);
797 }
798 return ret;
799 }
800
801 encoder = radeon_best_single_encoder(connector);
802 if (!encoder)
803 return 0;
804
805 /* we have no EDID modes */
806 mode = radeon_fp_native_mode(encoder);
807 if (mode) {
808 ret = 1;
809 drm_mode_probed_add(connector, mode);
810 /* add the width/height from vbios tables if available */
811 connector->display_info.width_mm = mode->width_mm;
812 connector->display_info.height_mm = mode->height_mm;
813 /* add scaled modes */
814 radeon_add_common_modes(encoder, connector);
815 }
816
817 return ret;
818 }
819
radeon_lvds_mode_valid(struct drm_connector * connector,struct drm_display_mode * mode)820 static enum drm_mode_status radeon_lvds_mode_valid(struct drm_connector *connector,
821 struct drm_display_mode *mode)
822 {
823 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
824
825 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
826 return MODE_PANEL;
827
828 if (encoder) {
829 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
830 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
831
832 /* AVIVO hardware supports downscaling modes larger than the panel
833 * to the panel size, but I'm not sure this is desirable.
834 */
835 if ((mode->hdisplay > native_mode->hdisplay) ||
836 (mode->vdisplay > native_mode->vdisplay))
837 return MODE_PANEL;
838
839 /* if scaling is disabled, block non-native modes */
840 if (radeon_encoder->rmx_type == RMX_OFF) {
841 if ((mode->hdisplay != native_mode->hdisplay) ||
842 (mode->vdisplay != native_mode->vdisplay))
843 return MODE_PANEL;
844 }
845 }
846
847 return MODE_OK;
848 }
849
850 static enum drm_connector_status
radeon_lvds_detect(struct drm_connector * connector,bool force)851 radeon_lvds_detect(struct drm_connector *connector, bool force)
852 {
853 struct drm_device *dev = connector->dev;
854 struct radeon_device *rdev = dev->dev_private;
855 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
856 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
857 enum drm_connector_status ret = connector_status_disconnected;
858 int r;
859
860 if (!drm_kms_helper_is_poll_worker()) {
861 r = pm_runtime_get_sync(connector->dev->dev);
862 if (r < 0) {
863 pm_runtime_put_autosuspend(connector->dev->dev);
864 return connector_status_disconnected;
865 }
866 }
867
868 if (encoder) {
869 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
870 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
871
872 /* check if panel is valid */
873 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
874 ret = connector_status_connected;
875 /* don't fetch the edid from the vbios if ddc fails and runpm is
876 * enabled so we report disconnected.
877 */
878 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
879 ret = connector_status_disconnected;
880 }
881
882 /* check for edid as well */
883 radeon_connector_get_edid(connector);
884 if (radeon_connector->edid)
885 ret = connector_status_connected;
886 /* check acpi lid status ??? */
887
888 radeon_connector_update_scratch_regs(connector, ret);
889
890 if (!drm_kms_helper_is_poll_worker()) {
891 pm_runtime_mark_last_busy(connector->dev->dev);
892 pm_runtime_put_autosuspend(connector->dev->dev);
893 }
894
895 return ret;
896 }
897
radeon_connector_unregister(struct drm_connector * connector)898 static void radeon_connector_unregister(struct drm_connector *connector)
899 {
900 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
901
902 if (radeon_connector->ddc_bus && radeon_connector->ddc_bus->has_aux) {
903 drm_dp_aux_unregister(&radeon_connector->ddc_bus->aux);
904 radeon_connector->ddc_bus->has_aux = false;
905 }
906 }
907
radeon_connector_destroy(struct drm_connector * connector)908 static void radeon_connector_destroy(struct drm_connector *connector)
909 {
910 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
911
912 radeon_connector_free_edid(connector);
913 kfree(radeon_connector->con_priv);
914 drm_connector_unregister(connector);
915 drm_connector_cleanup(connector);
916 kfree(connector);
917 }
918
radeon_lvds_set_property(struct drm_connector * connector,struct drm_property * property,uint64_t value)919 static int radeon_lvds_set_property(struct drm_connector *connector,
920 struct drm_property *property,
921 uint64_t value)
922 {
923 struct drm_device *dev = connector->dev;
924 struct radeon_encoder *radeon_encoder;
925 enum radeon_rmx_type rmx_type;
926
927 DRM_DEBUG_KMS("\n");
928 if (property != dev->mode_config.scaling_mode_property)
929 return 0;
930
931 if (connector->encoder)
932 radeon_encoder = to_radeon_encoder(connector->encoder);
933 else {
934 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
935 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
936 }
937
938 switch (value) {
939 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
940 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
941 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
942 default:
943 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
944 }
945 if (radeon_encoder->rmx_type == rmx_type)
946 return 0;
947
948 radeon_encoder->rmx_type = rmx_type;
949
950 radeon_property_change_mode(&radeon_encoder->base);
951 return 0;
952 }
953
954
955 static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
956 .get_modes = radeon_lvds_get_modes,
957 .mode_valid = radeon_lvds_mode_valid,
958 .best_encoder = radeon_best_single_encoder,
959 };
960
961 static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
962 .dpms = drm_helper_connector_dpms,
963 .detect = radeon_lvds_detect,
964 .fill_modes = drm_helper_probe_single_connector_modes,
965 .early_unregister = radeon_connector_unregister,
966 .destroy = radeon_connector_destroy,
967 .set_property = radeon_lvds_set_property,
968 };
969
radeon_vga_get_modes(struct drm_connector * connector)970 static int radeon_vga_get_modes(struct drm_connector *connector)
971 {
972 int ret;
973
974 radeon_connector_get_edid(connector);
975 ret = radeon_ddc_get_modes(connector);
976
977 radeon_get_native_mode(connector);
978
979 return ret;
980 }
981
radeon_vga_mode_valid(struct drm_connector * connector,struct drm_display_mode * mode)982 static enum drm_mode_status radeon_vga_mode_valid(struct drm_connector *connector,
983 struct drm_display_mode *mode)
984 {
985 struct drm_device *dev = connector->dev;
986 struct radeon_device *rdev = dev->dev_private;
987
988 /* XXX check mode bandwidth */
989
990 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
991 return MODE_CLOCK_HIGH;
992
993 return MODE_OK;
994 }
995
996 static enum drm_connector_status
radeon_vga_detect(struct drm_connector * connector,bool force)997 radeon_vga_detect(struct drm_connector *connector, bool force)
998 {
999 struct drm_device *dev = connector->dev;
1000 struct radeon_device *rdev = dev->dev_private;
1001 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1002 struct drm_encoder *encoder;
1003 const struct drm_encoder_helper_funcs *encoder_funcs;
1004 bool dret = false;
1005 enum drm_connector_status ret = connector_status_disconnected;
1006 int r;
1007
1008 if (!drm_kms_helper_is_poll_worker()) {
1009 r = pm_runtime_get_sync(connector->dev->dev);
1010 if (r < 0) {
1011 pm_runtime_put_autosuspend(connector->dev->dev);
1012 return connector_status_disconnected;
1013 }
1014 }
1015
1016 encoder = radeon_best_single_encoder(connector);
1017 if (!encoder)
1018 ret = connector_status_disconnected;
1019
1020 if (radeon_connector->ddc_bus)
1021 dret = radeon_ddc_probe(radeon_connector, false);
1022 if (dret) {
1023 radeon_connector->detected_by_load = false;
1024 radeon_connector_free_edid(connector);
1025 radeon_connector_get_edid(connector);
1026
1027 if (!radeon_connector->edid) {
1028 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1029 connector->name);
1030 ret = connector_status_connected;
1031 } else {
1032 radeon_connector->use_digital =
1033 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
1034
1035 /* some oems have boards with separate digital and analog connectors
1036 * with a shared ddc line (often vga + hdmi)
1037 */
1038 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
1039 radeon_connector_free_edid(connector);
1040 ret = connector_status_disconnected;
1041 } else {
1042 ret = connector_status_connected;
1043 }
1044 }
1045 } else {
1046
1047 /* if we aren't forcing don't do destructive polling */
1048 if (!force) {
1049 /* only return the previous status if we last
1050 * detected a monitor via load.
1051 */
1052 if (radeon_connector->detected_by_load)
1053 ret = connector->status;
1054 goto out;
1055 }
1056
1057 if (radeon_connector->dac_load_detect && encoder) {
1058 encoder_funcs = encoder->helper_private;
1059 ret = encoder_funcs->detect(encoder, connector);
1060 if (ret != connector_status_disconnected)
1061 radeon_connector->detected_by_load = true;
1062 }
1063 }
1064
1065 if (ret == connector_status_connected)
1066 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1067
1068 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1069 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1070 * by other means, assume the CRT is connected and use that EDID.
1071 */
1072 if ((!rdev->is_atom_bios) &&
1073 (ret == connector_status_disconnected) &&
1074 rdev->mode_info.bios_hardcoded_edid_size) {
1075 ret = connector_status_connected;
1076 }
1077
1078 radeon_connector_update_scratch_regs(connector, ret);
1079
1080 out:
1081 if (!drm_kms_helper_is_poll_worker()) {
1082 pm_runtime_mark_last_busy(connector->dev->dev);
1083 pm_runtime_put_autosuspend(connector->dev->dev);
1084 }
1085
1086 return ret;
1087 }
1088
1089 static const struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
1090 .get_modes = radeon_vga_get_modes,
1091 .mode_valid = radeon_vga_mode_valid,
1092 .best_encoder = radeon_best_single_encoder,
1093 };
1094
1095 static const struct drm_connector_funcs radeon_vga_connector_funcs = {
1096 .dpms = drm_helper_connector_dpms,
1097 .detect = radeon_vga_detect,
1098 .fill_modes = drm_helper_probe_single_connector_modes,
1099 .early_unregister = radeon_connector_unregister,
1100 .destroy = radeon_connector_destroy,
1101 .set_property = radeon_connector_set_property,
1102 };
1103
radeon_tv_get_modes(struct drm_connector * connector)1104 static int radeon_tv_get_modes(struct drm_connector *connector)
1105 {
1106 struct drm_device *dev = connector->dev;
1107 struct radeon_device *rdev = dev->dev_private;
1108 struct drm_display_mode *tv_mode;
1109 struct drm_encoder *encoder;
1110
1111 encoder = radeon_best_single_encoder(connector);
1112 if (!encoder)
1113 return 0;
1114
1115 /* avivo chips can scale any mode */
1116 if (rdev->family >= CHIP_RS600)
1117 /* add scaled modes */
1118 radeon_add_common_modes(encoder, connector);
1119 else {
1120 /* only 800x600 is supported right now on pre-avivo chips */
1121 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
1122 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
1123 drm_mode_probed_add(connector, tv_mode);
1124 }
1125 return 1;
1126 }
1127
radeon_tv_mode_valid(struct drm_connector * connector,struct drm_display_mode * mode)1128 static enum drm_mode_status radeon_tv_mode_valid(struct drm_connector *connector,
1129 struct drm_display_mode *mode)
1130 {
1131 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
1132 return MODE_CLOCK_RANGE;
1133 return MODE_OK;
1134 }
1135
1136 static enum drm_connector_status
radeon_tv_detect(struct drm_connector * connector,bool force)1137 radeon_tv_detect(struct drm_connector *connector, bool force)
1138 {
1139 struct drm_encoder *encoder;
1140 const struct drm_encoder_helper_funcs *encoder_funcs;
1141 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1142 enum drm_connector_status ret = connector_status_disconnected;
1143 int r;
1144
1145 if (!radeon_connector->dac_load_detect)
1146 return ret;
1147
1148 if (!drm_kms_helper_is_poll_worker()) {
1149 r = pm_runtime_get_sync(connector->dev->dev);
1150 if (r < 0) {
1151 pm_runtime_put_autosuspend(connector->dev->dev);
1152 return connector_status_disconnected;
1153 }
1154 }
1155
1156 encoder = radeon_best_single_encoder(connector);
1157 if (!encoder)
1158 ret = connector_status_disconnected;
1159 else {
1160 encoder_funcs = encoder->helper_private;
1161 ret = encoder_funcs->detect(encoder, connector);
1162 }
1163 if (ret == connector_status_connected)
1164 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
1165 radeon_connector_update_scratch_regs(connector, ret);
1166
1167 if (!drm_kms_helper_is_poll_worker()) {
1168 pm_runtime_mark_last_busy(connector->dev->dev);
1169 pm_runtime_put_autosuspend(connector->dev->dev);
1170 }
1171
1172 return ret;
1173 }
1174
1175 static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
1176 .get_modes = radeon_tv_get_modes,
1177 .mode_valid = radeon_tv_mode_valid,
1178 .best_encoder = radeon_best_single_encoder,
1179 };
1180
1181 static const struct drm_connector_funcs radeon_tv_connector_funcs = {
1182 .dpms = drm_helper_connector_dpms,
1183 .detect = radeon_tv_detect,
1184 .fill_modes = drm_helper_probe_single_connector_modes,
1185 .early_unregister = radeon_connector_unregister,
1186 .destroy = radeon_connector_destroy,
1187 .set_property = radeon_connector_set_property,
1188 };
1189
radeon_check_hpd_status_unchanged(struct drm_connector * connector)1190 static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector)
1191 {
1192 struct drm_device *dev = connector->dev;
1193 struct radeon_device *rdev = dev->dev_private;
1194 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1195 enum drm_connector_status status;
1196
1197 /* We only trust HPD on R600 and newer ASICS. */
1198 if (rdev->family >= CHIP_R600
1199 && radeon_connector->hpd.hpd != RADEON_HPD_NONE) {
1200 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
1201 status = connector_status_connected;
1202 else
1203 status = connector_status_disconnected;
1204 if (connector->status == status)
1205 return true;
1206 }
1207
1208 return false;
1209 }
1210
1211 /*
1212 * DVI is complicated
1213 * Do a DDC probe, if DDC probe passes, get the full EDID so
1214 * we can do analog/digital monitor detection at this point.
1215 * If the monitor is an analog monitor or we got no DDC,
1216 * we need to find the DAC encoder object for this connector.
1217 * If we got no DDC, we do load detection on the DAC encoder object.
1218 * If we got analog DDC or load detection passes on the DAC encoder
1219 * we have to check if this analog encoder is shared with anyone else (TV)
1220 * if its shared we have to set the other connector to disconnected.
1221 */
1222 static enum drm_connector_status
radeon_dvi_detect(struct drm_connector * connector,bool force)1223 radeon_dvi_detect(struct drm_connector *connector, bool force)
1224 {
1225 struct drm_device *dev = connector->dev;
1226 struct radeon_device *rdev = dev->dev_private;
1227 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1228 struct drm_encoder *encoder = NULL;
1229 const struct drm_encoder_helper_funcs *encoder_funcs;
1230 int r;
1231 enum drm_connector_status ret = connector_status_disconnected;
1232 bool dret = false, broken_edid = false;
1233
1234 if (!drm_kms_helper_is_poll_worker()) {
1235 r = pm_runtime_get_sync(connector->dev->dev);
1236 if (r < 0) {
1237 pm_runtime_put_autosuspend(connector->dev->dev);
1238 return connector_status_disconnected;
1239 }
1240 }
1241
1242 if (radeon_connector->detected_hpd_without_ddc) {
1243 force = true;
1244 radeon_connector->detected_hpd_without_ddc = false;
1245 }
1246
1247 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1248 ret = connector->status;
1249 goto exit;
1250 }
1251
1252 if (radeon_connector->ddc_bus) {
1253 dret = radeon_ddc_probe(radeon_connector, false);
1254
1255 /* Sometimes the pins required for the DDC probe on DVI
1256 * connectors don't make contact at the same time that the ones
1257 * for HPD do. If the DDC probe fails even though we had an HPD
1258 * signal, try again later */
1259 if (!dret && !force &&
1260 connector->status != connector_status_connected) {
1261 DRM_DEBUG_KMS("hpd detected without ddc, retrying in 1 second\n");
1262 radeon_connector->detected_hpd_without_ddc = true;
1263 schedule_delayed_work(&rdev->hotplug_work,
1264 msecs_to_jiffies(1000));
1265 goto exit;
1266 }
1267 }
1268 if (dret) {
1269 radeon_connector->detected_by_load = false;
1270 radeon_connector_free_edid(connector);
1271 radeon_connector_get_edid(connector);
1272
1273 if (!radeon_connector->edid) {
1274 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
1275 connector->name);
1276 /* rs690 seems to have a problem with connectors not existing and always
1277 * return a block of 0's. If we see this just stop polling on this output */
1278 if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) &&
1279 radeon_connector->base.null_edid_counter) {
1280 ret = connector_status_disconnected;
1281 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n",
1282 connector->name);
1283 radeon_connector->ddc_bus = NULL;
1284 } else {
1285 ret = connector_status_connected;
1286 broken_edid = true; /* defer use_digital to later */
1287 }
1288 } else {
1289 radeon_connector->use_digital =
1290 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
1291
1292 /* some oems have boards with separate digital and analog connectors
1293 * with a shared ddc line (often vga + hdmi)
1294 */
1295 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
1296 radeon_connector_free_edid(connector);
1297 ret = connector_status_disconnected;
1298 } else {
1299 ret = connector_status_connected;
1300 }
1301 /* This gets complicated. We have boards with VGA + HDMI with a
1302 * shared DDC line and we have boards with DVI-D + HDMI with a shared
1303 * DDC line. The latter is more complex because with DVI<->HDMI adapters
1304 * you don't really know what's connected to which port as both are digital.
1305 */
1306 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
1307 struct drm_connector *list_connector;
1308 struct radeon_connector *list_radeon_connector;
1309 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
1310 if (connector == list_connector)
1311 continue;
1312 list_radeon_connector = to_radeon_connector(list_connector);
1313 if (list_radeon_connector->shared_ddc &&
1314 (list_radeon_connector->ddc_bus->rec.i2c_id ==
1315 radeon_connector->ddc_bus->rec.i2c_id)) {
1316 /* cases where both connectors are digital */
1317 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
1318 /* hpd is our only option in this case */
1319 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1320 radeon_connector_free_edid(connector);
1321 ret = connector_status_disconnected;
1322 }
1323 }
1324 }
1325 }
1326 }
1327 }
1328 }
1329
1330 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
1331 goto out;
1332
1333 /* DVI-D and HDMI-A are digital only */
1334 if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
1335 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
1336 goto out;
1337
1338 /* if we aren't forcing don't do destructive polling */
1339 if (!force) {
1340 /* only return the previous status if we last
1341 * detected a monitor via load.
1342 */
1343 if (radeon_connector->detected_by_load)
1344 ret = connector->status;
1345 goto out;
1346 }
1347
1348 /* find analog encoder */
1349 if (radeon_connector->dac_load_detect) {
1350 drm_connector_for_each_possible_encoder(connector, encoder) {
1351 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
1352 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
1353 continue;
1354
1355 encoder_funcs = encoder->helper_private;
1356 if (encoder_funcs->detect) {
1357 if (!broken_edid) {
1358 if (ret != connector_status_connected) {
1359 /* deal with analog monitors without DDC */
1360 ret = encoder_funcs->detect(encoder, connector);
1361 if (ret == connector_status_connected) {
1362 radeon_connector->use_digital = false;
1363 }
1364 if (ret != connector_status_disconnected)
1365 radeon_connector->detected_by_load = true;
1366 }
1367 } else {
1368 enum drm_connector_status lret;
1369 /* assume digital unless load detected otherwise */
1370 radeon_connector->use_digital = true;
1371 lret = encoder_funcs->detect(encoder, connector);
1372 DRM_DEBUG_KMS("load_detect %x returned: %x\n", encoder->encoder_type, lret);
1373 if (lret == connector_status_connected)
1374 radeon_connector->use_digital = false;
1375 }
1376 break;
1377 }
1378 }
1379 }
1380
1381 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
1382 encoder) {
1383 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1384 }
1385
1386 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1387 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1388 * by other means, assume the DFP is connected and use that EDID. In most
1389 * cases the DVI port is actually a virtual KVM port connected to the service
1390 * processor.
1391 */
1392 out:
1393 if ((!rdev->is_atom_bios) &&
1394 (ret == connector_status_disconnected) &&
1395 rdev->mode_info.bios_hardcoded_edid_size) {
1396 radeon_connector->use_digital = true;
1397 ret = connector_status_connected;
1398 }
1399
1400 /* updated in get modes as well since we need to know if it's analog or digital */
1401 radeon_connector_update_scratch_regs(connector, ret);
1402
1403 if ((radeon_audio != 0) && radeon_connector->use_digital) {
1404 const struct drm_connector_helper_funcs *connector_funcs =
1405 connector->helper_private;
1406
1407 encoder = connector_funcs->best_encoder(connector);
1408 if (encoder && (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)) {
1409 radeon_connector_get_edid(connector);
1410 radeon_audio_detect(connector, encoder, ret);
1411 }
1412 }
1413
1414 exit:
1415 if (!drm_kms_helper_is_poll_worker()) {
1416 pm_runtime_mark_last_busy(connector->dev->dev);
1417 pm_runtime_put_autosuspend(connector->dev->dev);
1418 }
1419
1420 return ret;
1421 }
1422
1423 /* okay need to be smart in here about which encoder to pick */
radeon_dvi_encoder(struct drm_connector * connector)1424 static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
1425 {
1426 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1427 struct drm_encoder *encoder;
1428
1429 drm_connector_for_each_possible_encoder(connector, encoder) {
1430 if (radeon_connector->use_digital == true) {
1431 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
1432 return encoder;
1433 } else {
1434 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
1435 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
1436 return encoder;
1437 }
1438 }
1439
1440 /* see if we have a default encoder TODO */
1441
1442 /* then check use digitial */
1443 /* pick the first one */
1444 drm_connector_for_each_possible_encoder(connector, encoder)
1445 return encoder;
1446
1447 return NULL;
1448 }
1449
radeon_dvi_force(struct drm_connector * connector)1450 static void radeon_dvi_force(struct drm_connector *connector)
1451 {
1452 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1453 if (connector->force == DRM_FORCE_ON)
1454 radeon_connector->use_digital = false;
1455 if (connector->force == DRM_FORCE_ON_DIGITAL)
1456 radeon_connector->use_digital = true;
1457 }
1458
radeon_dvi_mode_valid(struct drm_connector * connector,struct drm_display_mode * mode)1459 static enum drm_mode_status radeon_dvi_mode_valid(struct drm_connector *connector,
1460 struct drm_display_mode *mode)
1461 {
1462 struct drm_device *dev = connector->dev;
1463 struct radeon_device *rdev = dev->dev_private;
1464 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1465
1466 /* XXX check mode bandwidth */
1467
1468 /* clocks over 135 MHz have heat issues with DVI on RV100 */
1469 if (radeon_connector->use_digital &&
1470 (rdev->family == CHIP_RV100) &&
1471 (mode->clock > 135000))
1472 return MODE_CLOCK_HIGH;
1473
1474 if (radeon_connector->use_digital && (mode->clock > 165000)) {
1475 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1476 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1477 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1478 return MODE_OK;
1479 else if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
1480 /* HDMI 1.3+ supports max clock of 340 Mhz */
1481 if (mode->clock > 340000)
1482 return MODE_CLOCK_HIGH;
1483 else
1484 return MODE_OK;
1485 } else {
1486 return MODE_CLOCK_HIGH;
1487 }
1488 }
1489
1490 /* check against the max pixel clock */
1491 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1492 return MODE_CLOCK_HIGH;
1493
1494 return MODE_OK;
1495 }
1496
1497 static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
1498 .get_modes = radeon_vga_get_modes,
1499 .mode_valid = radeon_dvi_mode_valid,
1500 .best_encoder = radeon_dvi_encoder,
1501 };
1502
1503 static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
1504 .dpms = drm_helper_connector_dpms,
1505 .detect = radeon_dvi_detect,
1506 .fill_modes = drm_helper_probe_single_connector_modes,
1507 .set_property = radeon_connector_set_property,
1508 .early_unregister = radeon_connector_unregister,
1509 .destroy = radeon_connector_destroy,
1510 .force = radeon_dvi_force,
1511 };
1512
radeon_dp_get_modes(struct drm_connector * connector)1513 static int radeon_dp_get_modes(struct drm_connector *connector)
1514 {
1515 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1516 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1517 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1518 int ret;
1519
1520 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1521 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1522 struct drm_display_mode *mode;
1523
1524 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1525 if (!radeon_dig_connector->edp_on)
1526 atombios_set_edp_panel_power(connector,
1527 ATOM_TRANSMITTER_ACTION_POWER_ON);
1528 radeon_connector_get_edid(connector);
1529 ret = radeon_ddc_get_modes(connector);
1530 if (!radeon_dig_connector->edp_on)
1531 atombios_set_edp_panel_power(connector,
1532 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1533 } else {
1534 /* need to setup ddc on the bridge */
1535 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1536 ENCODER_OBJECT_ID_NONE) {
1537 if (encoder)
1538 radeon_atom_ext_encoder_setup_ddc(encoder);
1539 }
1540 radeon_connector_get_edid(connector);
1541 ret = radeon_ddc_get_modes(connector);
1542 }
1543
1544 if (ret > 0) {
1545 if (encoder) {
1546 radeon_fixup_lvds_native_mode(encoder, connector);
1547 /* add scaled modes */
1548 radeon_add_common_modes(encoder, connector);
1549 }
1550 return ret;
1551 }
1552
1553 if (!encoder)
1554 return 0;
1555
1556 /* we have no EDID modes */
1557 mode = radeon_fp_native_mode(encoder);
1558 if (mode) {
1559 ret = 1;
1560 drm_mode_probed_add(connector, mode);
1561 /* add the width/height from vbios tables if available */
1562 connector->display_info.width_mm = mode->width_mm;
1563 connector->display_info.height_mm = mode->height_mm;
1564 /* add scaled modes */
1565 radeon_add_common_modes(encoder, connector);
1566 }
1567 } else {
1568 /* need to setup ddc on the bridge */
1569 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1570 ENCODER_OBJECT_ID_NONE) {
1571 if (encoder)
1572 radeon_atom_ext_encoder_setup_ddc(encoder);
1573 }
1574 radeon_connector_get_edid(connector);
1575 ret = radeon_ddc_get_modes(connector);
1576
1577 radeon_get_native_mode(connector);
1578 }
1579
1580 return ret;
1581 }
1582
radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector * connector)1583 u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
1584 {
1585 struct drm_encoder *encoder;
1586 struct radeon_encoder *radeon_encoder;
1587
1588 drm_connector_for_each_possible_encoder(connector, encoder) {
1589 radeon_encoder = to_radeon_encoder(encoder);
1590
1591 switch (radeon_encoder->encoder_id) {
1592 case ENCODER_OBJECT_ID_TRAVIS:
1593 case ENCODER_OBJECT_ID_NUTMEG:
1594 return radeon_encoder->encoder_id;
1595 default:
1596 break;
1597 }
1598 }
1599
1600 return ENCODER_OBJECT_ID_NONE;
1601 }
1602
radeon_connector_encoder_is_hbr2(struct drm_connector * connector)1603 static bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
1604 {
1605 struct drm_encoder *encoder;
1606 struct radeon_encoder *radeon_encoder;
1607 bool found = false;
1608
1609 drm_connector_for_each_possible_encoder(connector, encoder) {
1610 radeon_encoder = to_radeon_encoder(encoder);
1611 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1612 found = true;
1613 }
1614
1615 return found;
1616 }
1617
radeon_connector_is_dp12_capable(struct drm_connector * connector)1618 bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1619 {
1620 struct drm_device *dev = connector->dev;
1621 struct radeon_device *rdev = dev->dev_private;
1622
1623 if (ASIC_IS_DCE5(rdev) &&
1624 (rdev->clock.default_dispclk >= 53900) &&
1625 radeon_connector_encoder_is_hbr2(connector)) {
1626 return true;
1627 }
1628
1629 return false;
1630 }
1631
1632 static enum drm_connector_status
radeon_dp_detect(struct drm_connector * connector,bool force)1633 radeon_dp_detect(struct drm_connector *connector, bool force)
1634 {
1635 struct drm_device *dev = connector->dev;
1636 struct radeon_device *rdev = dev->dev_private;
1637 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1638 enum drm_connector_status ret = connector_status_disconnected;
1639 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1640 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1641 int r;
1642
1643 if (!drm_kms_helper_is_poll_worker()) {
1644 r = pm_runtime_get_sync(connector->dev->dev);
1645 if (r < 0) {
1646 pm_runtime_put_autosuspend(connector->dev->dev);
1647 return connector_status_disconnected;
1648 }
1649 }
1650
1651 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1652 ret = connector->status;
1653 goto out;
1654 }
1655
1656 radeon_connector_free_edid(connector);
1657
1658 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1659 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1660 if (encoder) {
1661 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1662 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1663
1664 /* check if panel is valid */
1665 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1666 ret = connector_status_connected;
1667 /* don't fetch the edid from the vbios if ddc fails and runpm is
1668 * enabled so we report disconnected.
1669 */
1670 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
1671 ret = connector_status_disconnected;
1672 }
1673 /* eDP is always DP */
1674 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1675 if (!radeon_dig_connector->edp_on)
1676 atombios_set_edp_panel_power(connector,
1677 ATOM_TRANSMITTER_ACTION_POWER_ON);
1678 if (radeon_dp_getdpcd(radeon_connector))
1679 ret = connector_status_connected;
1680 if (!radeon_dig_connector->edp_on)
1681 atombios_set_edp_panel_power(connector,
1682 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1683 } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1684 ENCODER_OBJECT_ID_NONE) {
1685 /* DP bridges are always DP */
1686 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1687 /* get the DPCD from the bridge */
1688 radeon_dp_getdpcd(radeon_connector);
1689
1690 if (encoder) {
1691 /* setup ddc on the bridge */
1692 radeon_atom_ext_encoder_setup_ddc(encoder);
1693 /* bridge chips are always aux */
1694 if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */
1695 ret = connector_status_connected;
1696 else if (radeon_connector->dac_load_detect) { /* try load detection */
1697 const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
1698 ret = encoder_funcs->detect(encoder, connector);
1699 }
1700 }
1701 } else {
1702 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
1703 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1704 ret = connector_status_connected;
1705 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
1706 radeon_dp_getdpcd(radeon_connector);
1707 } else {
1708 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1709 if (radeon_dp_getdpcd(radeon_connector))
1710 ret = connector_status_connected;
1711 } else {
1712 /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
1713 if (radeon_ddc_probe(radeon_connector, false))
1714 ret = connector_status_connected;
1715 }
1716 }
1717 }
1718
1719 radeon_connector_update_scratch_regs(connector, ret);
1720
1721 if ((radeon_audio != 0) && encoder) {
1722 radeon_connector_get_edid(connector);
1723 radeon_audio_detect(connector, encoder, ret);
1724 }
1725
1726 out:
1727 if (!drm_kms_helper_is_poll_worker()) {
1728 pm_runtime_mark_last_busy(connector->dev->dev);
1729 pm_runtime_put_autosuspend(connector->dev->dev);
1730 }
1731
1732 return ret;
1733 }
1734
radeon_dp_mode_valid(struct drm_connector * connector,struct drm_display_mode * mode)1735 static enum drm_mode_status radeon_dp_mode_valid(struct drm_connector *connector,
1736 struct drm_display_mode *mode)
1737 {
1738 struct drm_device *dev = connector->dev;
1739 struct radeon_device *rdev = dev->dev_private;
1740 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1741 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1742
1743 /* XXX check mode bandwidth */
1744
1745 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1746 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
1747 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1748
1749 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1750 return MODE_PANEL;
1751
1752 if (encoder) {
1753 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1754 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1755
1756 /* AVIVO hardware supports downscaling modes larger than the panel
1757 * to the panel size, but I'm not sure this is desirable.
1758 */
1759 if ((mode->hdisplay > native_mode->hdisplay) ||
1760 (mode->vdisplay > native_mode->vdisplay))
1761 return MODE_PANEL;
1762
1763 /* if scaling is disabled, block non-native modes */
1764 if (radeon_encoder->rmx_type == RMX_OFF) {
1765 if ((mode->hdisplay != native_mode->hdisplay) ||
1766 (mode->vdisplay != native_mode->vdisplay))
1767 return MODE_PANEL;
1768 }
1769 }
1770 } else {
1771 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1772 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
1773 return radeon_dp_mode_valid_helper(connector, mode);
1774 } else {
1775 if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
1776 /* HDMI 1.3+ supports max clock of 340 Mhz */
1777 if (mode->clock > 340000)
1778 return MODE_CLOCK_HIGH;
1779 } else {
1780 if (mode->clock > 165000)
1781 return MODE_CLOCK_HIGH;
1782 }
1783 }
1784 }
1785
1786 return MODE_OK;
1787 }
1788
1789 static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1790 .get_modes = radeon_dp_get_modes,
1791 .mode_valid = radeon_dp_mode_valid,
1792 .best_encoder = radeon_dvi_encoder,
1793 };
1794
1795 static const struct drm_connector_funcs radeon_dp_connector_funcs = {
1796 .dpms = drm_helper_connector_dpms,
1797 .detect = radeon_dp_detect,
1798 .fill_modes = drm_helper_probe_single_connector_modes,
1799 .set_property = radeon_connector_set_property,
1800 .early_unregister = radeon_connector_unregister,
1801 .destroy = radeon_connector_destroy,
1802 .force = radeon_dvi_force,
1803 };
1804
1805 static const struct drm_connector_funcs radeon_edp_connector_funcs = {
1806 .dpms = drm_helper_connector_dpms,
1807 .detect = radeon_dp_detect,
1808 .fill_modes = drm_helper_probe_single_connector_modes,
1809 .set_property = radeon_lvds_set_property,
1810 .early_unregister = radeon_connector_unregister,
1811 .destroy = radeon_connector_destroy,
1812 .force = radeon_dvi_force,
1813 };
1814
1815 static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
1816 .dpms = drm_helper_connector_dpms,
1817 .detect = radeon_dp_detect,
1818 .fill_modes = drm_helper_probe_single_connector_modes,
1819 .set_property = radeon_lvds_set_property,
1820 .early_unregister = radeon_connector_unregister,
1821 .destroy = radeon_connector_destroy,
1822 .force = radeon_dvi_force,
1823 };
1824
1825 void
radeon_add_atom_connector(struct drm_device * dev,uint32_t connector_id,uint32_t supported_device,int connector_type,struct radeon_i2c_bus_rec * i2c_bus,uint32_t igp_lane_info,uint16_t connector_object_id,struct radeon_hpd * hpd,struct radeon_router * router)1826 radeon_add_atom_connector(struct drm_device *dev,
1827 uint32_t connector_id,
1828 uint32_t supported_device,
1829 int connector_type,
1830 struct radeon_i2c_bus_rec *i2c_bus,
1831 uint32_t igp_lane_info,
1832 uint16_t connector_object_id,
1833 struct radeon_hpd *hpd,
1834 struct radeon_router *router)
1835 {
1836 struct radeon_device *rdev = dev->dev_private;
1837 struct drm_connector *connector;
1838 struct radeon_connector *radeon_connector;
1839 struct radeon_connector_atom_dig *radeon_dig_connector;
1840 struct drm_encoder *encoder;
1841 struct radeon_encoder *radeon_encoder;
1842 struct i2c_adapter *ddc = NULL;
1843 uint32_t subpixel_order = SubPixelNone;
1844 bool shared_ddc = false;
1845 bool is_dp_bridge = false;
1846 bool has_aux = false;
1847
1848 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1849 return;
1850
1851 /* if the user selected tv=0 don't try and add the connector */
1852 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1853 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1854 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1855 (radeon_tv == 0))
1856 return;
1857
1858 /* see if we already added it */
1859 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1860 radeon_connector = to_radeon_connector(connector);
1861 if (radeon_connector->connector_id == connector_id) {
1862 radeon_connector->devices |= supported_device;
1863 return;
1864 }
1865 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1866 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1867 radeon_connector->shared_ddc = true;
1868 shared_ddc = true;
1869 }
1870 if (radeon_connector->router_bus && router->ddc_valid &&
1871 (radeon_connector->router.router_id == router->router_id)) {
1872 radeon_connector->shared_ddc = false;
1873 shared_ddc = false;
1874 }
1875 }
1876 }
1877
1878 /* check if it's a dp bridge */
1879 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1880 radeon_encoder = to_radeon_encoder(encoder);
1881 if (radeon_encoder->devices & supported_device) {
1882 switch (radeon_encoder->encoder_id) {
1883 case ENCODER_OBJECT_ID_TRAVIS:
1884 case ENCODER_OBJECT_ID_NUTMEG:
1885 is_dp_bridge = true;
1886 break;
1887 default:
1888 break;
1889 }
1890 }
1891 }
1892
1893 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1894 if (!radeon_connector)
1895 return;
1896
1897 connector = &radeon_connector->base;
1898
1899 radeon_connector->connector_id = connector_id;
1900 radeon_connector->devices = supported_device;
1901 radeon_connector->shared_ddc = shared_ddc;
1902 radeon_connector->connector_object_id = connector_object_id;
1903 radeon_connector->hpd = *hpd;
1904
1905 radeon_connector->router = *router;
1906 if (router->ddc_valid || router->cd_valid) {
1907 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1908 if (!radeon_connector->router_bus)
1909 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
1910 }
1911
1912 if (is_dp_bridge) {
1913 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1914 if (!radeon_dig_connector)
1915 goto failed;
1916 radeon_dig_connector->igp_lane_info = igp_lane_info;
1917 radeon_connector->con_priv = radeon_dig_connector;
1918 if (i2c_bus->valid) {
1919 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1920 if (radeon_connector->ddc_bus) {
1921 has_aux = true;
1922 ddc = &radeon_connector->ddc_bus->adapter;
1923 } else {
1924 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1925 }
1926 }
1927 switch (connector_type) {
1928 case DRM_MODE_CONNECTOR_VGA:
1929 case DRM_MODE_CONNECTOR_DVIA:
1930 default:
1931 drm_connector_init_with_ddc(dev, &radeon_connector->base,
1932 &radeon_dp_connector_funcs,
1933 connector_type,
1934 ddc);
1935 drm_connector_helper_add(&radeon_connector->base,
1936 &radeon_dp_connector_helper_funcs);
1937 connector->interlace_allowed = true;
1938 connector->doublescan_allowed = true;
1939 radeon_connector->dac_load_detect = true;
1940 drm_object_attach_property(&radeon_connector->base.base,
1941 rdev->mode_info.load_detect_property,
1942 1);
1943 drm_object_attach_property(&radeon_connector->base.base,
1944 dev->mode_config.scaling_mode_property,
1945 DRM_MODE_SCALE_NONE);
1946 if (ASIC_IS_DCE5(rdev))
1947 drm_object_attach_property(&radeon_connector->base.base,
1948 rdev->mode_info.output_csc_property,
1949 RADEON_OUTPUT_CSC_BYPASS);
1950 break;
1951 case DRM_MODE_CONNECTOR_DVII:
1952 case DRM_MODE_CONNECTOR_DVID:
1953 case DRM_MODE_CONNECTOR_HDMIA:
1954 case DRM_MODE_CONNECTOR_HDMIB:
1955 case DRM_MODE_CONNECTOR_DisplayPort:
1956 drm_connector_init_with_ddc(dev, &radeon_connector->base,
1957 &radeon_dp_connector_funcs,
1958 connector_type,
1959 ddc);
1960 drm_connector_helper_add(&radeon_connector->base,
1961 &radeon_dp_connector_helper_funcs);
1962 drm_object_attach_property(&radeon_connector->base.base,
1963 rdev->mode_info.underscan_property,
1964 UNDERSCAN_OFF);
1965 drm_object_attach_property(&radeon_connector->base.base,
1966 rdev->mode_info.underscan_hborder_property,
1967 0);
1968 drm_object_attach_property(&radeon_connector->base.base,
1969 rdev->mode_info.underscan_vborder_property,
1970 0);
1971
1972 drm_object_attach_property(&radeon_connector->base.base,
1973 dev->mode_config.scaling_mode_property,
1974 DRM_MODE_SCALE_NONE);
1975
1976 drm_object_attach_property(&radeon_connector->base.base,
1977 rdev->mode_info.dither_property,
1978 RADEON_FMT_DITHER_DISABLE);
1979
1980 if (radeon_audio != 0) {
1981 drm_object_attach_property(&radeon_connector->base.base,
1982 rdev->mode_info.audio_property,
1983 RADEON_AUDIO_AUTO);
1984 radeon_connector->audio = RADEON_AUDIO_AUTO;
1985 }
1986 if (ASIC_IS_DCE5(rdev))
1987 drm_object_attach_property(&radeon_connector->base.base,
1988 rdev->mode_info.output_csc_property,
1989 RADEON_OUTPUT_CSC_BYPASS);
1990
1991 subpixel_order = SubPixelHorizontalRGB;
1992 connector->interlace_allowed = true;
1993 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1994 connector->doublescan_allowed = true;
1995 else
1996 connector->doublescan_allowed = false;
1997 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1998 radeon_connector->dac_load_detect = true;
1999 drm_object_attach_property(&radeon_connector->base.base,
2000 rdev->mode_info.load_detect_property,
2001 1);
2002 }
2003 break;
2004 case DRM_MODE_CONNECTOR_LVDS:
2005 case DRM_MODE_CONNECTOR_eDP:
2006 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2007 &radeon_lvds_bridge_connector_funcs,
2008 connector_type,
2009 ddc);
2010 drm_connector_helper_add(&radeon_connector->base,
2011 &radeon_dp_connector_helper_funcs);
2012 drm_object_attach_property(&radeon_connector->base.base,
2013 dev->mode_config.scaling_mode_property,
2014 DRM_MODE_SCALE_FULLSCREEN);
2015 subpixel_order = SubPixelHorizontalRGB;
2016 connector->interlace_allowed = false;
2017 connector->doublescan_allowed = false;
2018 break;
2019 }
2020 } else {
2021 switch (connector_type) {
2022 case DRM_MODE_CONNECTOR_VGA:
2023 if (i2c_bus->valid) {
2024 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2025 if (!radeon_connector->ddc_bus)
2026 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2027 else
2028 ddc = &radeon_connector->ddc_bus->adapter;
2029 }
2030 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2031 &radeon_vga_connector_funcs,
2032 connector_type,
2033 ddc);
2034 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2035 radeon_connector->dac_load_detect = true;
2036 drm_object_attach_property(&radeon_connector->base.base,
2037 rdev->mode_info.load_detect_property,
2038 1);
2039 if (ASIC_IS_AVIVO(rdev))
2040 drm_object_attach_property(&radeon_connector->base.base,
2041 dev->mode_config.scaling_mode_property,
2042 DRM_MODE_SCALE_NONE);
2043 if (ASIC_IS_DCE5(rdev))
2044 drm_object_attach_property(&radeon_connector->base.base,
2045 rdev->mode_info.output_csc_property,
2046 RADEON_OUTPUT_CSC_BYPASS);
2047 /* no HPD on analog connectors */
2048 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2049 connector->interlace_allowed = true;
2050 connector->doublescan_allowed = true;
2051 break;
2052 case DRM_MODE_CONNECTOR_DVIA:
2053 if (i2c_bus->valid) {
2054 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2055 if (!radeon_connector->ddc_bus)
2056 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2057 else
2058 ddc = &radeon_connector->ddc_bus->adapter;
2059 }
2060 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2061 &radeon_vga_connector_funcs,
2062 connector_type,
2063 ddc);
2064 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2065 radeon_connector->dac_load_detect = true;
2066 drm_object_attach_property(&radeon_connector->base.base,
2067 rdev->mode_info.load_detect_property,
2068 1);
2069 if (ASIC_IS_AVIVO(rdev))
2070 drm_object_attach_property(&radeon_connector->base.base,
2071 dev->mode_config.scaling_mode_property,
2072 DRM_MODE_SCALE_NONE);
2073 if (ASIC_IS_DCE5(rdev))
2074 drm_object_attach_property(&radeon_connector->base.base,
2075 rdev->mode_info.output_csc_property,
2076 RADEON_OUTPUT_CSC_BYPASS);
2077 /* no HPD on analog connectors */
2078 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2079 connector->interlace_allowed = true;
2080 connector->doublescan_allowed = true;
2081 break;
2082 case DRM_MODE_CONNECTOR_DVII:
2083 case DRM_MODE_CONNECTOR_DVID:
2084 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2085 if (!radeon_dig_connector)
2086 goto failed;
2087 radeon_dig_connector->igp_lane_info = igp_lane_info;
2088 radeon_connector->con_priv = radeon_dig_connector;
2089 if (i2c_bus->valid) {
2090 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2091 if (!radeon_connector->ddc_bus)
2092 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2093 else
2094 ddc = &radeon_connector->ddc_bus->adapter;
2095 }
2096 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2097 &radeon_dvi_connector_funcs,
2098 connector_type,
2099 ddc);
2100 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2101 subpixel_order = SubPixelHorizontalRGB;
2102 drm_object_attach_property(&radeon_connector->base.base,
2103 rdev->mode_info.coherent_mode_property,
2104 1);
2105 if (ASIC_IS_AVIVO(rdev)) {
2106 drm_object_attach_property(&radeon_connector->base.base,
2107 rdev->mode_info.underscan_property,
2108 UNDERSCAN_OFF);
2109 drm_object_attach_property(&radeon_connector->base.base,
2110 rdev->mode_info.underscan_hborder_property,
2111 0);
2112 drm_object_attach_property(&radeon_connector->base.base,
2113 rdev->mode_info.underscan_vborder_property,
2114 0);
2115 drm_object_attach_property(&radeon_connector->base.base,
2116 rdev->mode_info.dither_property,
2117 RADEON_FMT_DITHER_DISABLE);
2118 drm_object_attach_property(&radeon_connector->base.base,
2119 dev->mode_config.scaling_mode_property,
2120 DRM_MODE_SCALE_NONE);
2121 }
2122 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2123 drm_object_attach_property(&radeon_connector->base.base,
2124 rdev->mode_info.audio_property,
2125 RADEON_AUDIO_AUTO);
2126 radeon_connector->audio = RADEON_AUDIO_AUTO;
2127 }
2128 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2129 radeon_connector->dac_load_detect = true;
2130 drm_object_attach_property(&radeon_connector->base.base,
2131 rdev->mode_info.load_detect_property,
2132 1);
2133 }
2134 if (ASIC_IS_DCE5(rdev))
2135 drm_object_attach_property(&radeon_connector->base.base,
2136 rdev->mode_info.output_csc_property,
2137 RADEON_OUTPUT_CSC_BYPASS);
2138 connector->interlace_allowed = true;
2139 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2140 connector->doublescan_allowed = true;
2141 else
2142 connector->doublescan_allowed = false;
2143 break;
2144 case DRM_MODE_CONNECTOR_HDMIA:
2145 case DRM_MODE_CONNECTOR_HDMIB:
2146 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2147 if (!radeon_dig_connector)
2148 goto failed;
2149 radeon_dig_connector->igp_lane_info = igp_lane_info;
2150 radeon_connector->con_priv = radeon_dig_connector;
2151 if (i2c_bus->valid) {
2152 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2153 if (!radeon_connector->ddc_bus)
2154 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2155 else
2156 ddc = &radeon_connector->ddc_bus->adapter;
2157 }
2158 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2159 &radeon_dvi_connector_funcs,
2160 connector_type,
2161 ddc);
2162 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2163 drm_object_attach_property(&radeon_connector->base.base,
2164 rdev->mode_info.coherent_mode_property,
2165 1);
2166 if (ASIC_IS_AVIVO(rdev)) {
2167 drm_object_attach_property(&radeon_connector->base.base,
2168 rdev->mode_info.underscan_property,
2169 UNDERSCAN_OFF);
2170 drm_object_attach_property(&radeon_connector->base.base,
2171 rdev->mode_info.underscan_hborder_property,
2172 0);
2173 drm_object_attach_property(&radeon_connector->base.base,
2174 rdev->mode_info.underscan_vborder_property,
2175 0);
2176 drm_object_attach_property(&radeon_connector->base.base,
2177 rdev->mode_info.dither_property,
2178 RADEON_FMT_DITHER_DISABLE);
2179 drm_object_attach_property(&radeon_connector->base.base,
2180 dev->mode_config.scaling_mode_property,
2181 DRM_MODE_SCALE_NONE);
2182 }
2183 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2184 drm_object_attach_property(&radeon_connector->base.base,
2185 rdev->mode_info.audio_property,
2186 RADEON_AUDIO_AUTO);
2187 radeon_connector->audio = RADEON_AUDIO_AUTO;
2188 }
2189 if (ASIC_IS_DCE5(rdev))
2190 drm_object_attach_property(&radeon_connector->base.base,
2191 rdev->mode_info.output_csc_property,
2192 RADEON_OUTPUT_CSC_BYPASS);
2193 subpixel_order = SubPixelHorizontalRGB;
2194 connector->interlace_allowed = true;
2195 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
2196 connector->doublescan_allowed = true;
2197 else
2198 connector->doublescan_allowed = false;
2199 break;
2200 case DRM_MODE_CONNECTOR_DisplayPort:
2201 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2202 if (!radeon_dig_connector)
2203 goto failed;
2204 radeon_dig_connector->igp_lane_info = igp_lane_info;
2205 radeon_connector->con_priv = radeon_dig_connector;
2206 if (i2c_bus->valid) {
2207 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2208 if (radeon_connector->ddc_bus) {
2209 has_aux = true;
2210 ddc = &radeon_connector->ddc_bus->adapter;
2211 } else {
2212 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2213 }
2214 }
2215 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2216 &radeon_dp_connector_funcs,
2217 connector_type,
2218 ddc);
2219 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2220 subpixel_order = SubPixelHorizontalRGB;
2221 drm_object_attach_property(&radeon_connector->base.base,
2222 rdev->mode_info.coherent_mode_property,
2223 1);
2224 if (ASIC_IS_AVIVO(rdev)) {
2225 drm_object_attach_property(&radeon_connector->base.base,
2226 rdev->mode_info.underscan_property,
2227 UNDERSCAN_OFF);
2228 drm_object_attach_property(&radeon_connector->base.base,
2229 rdev->mode_info.underscan_hborder_property,
2230 0);
2231 drm_object_attach_property(&radeon_connector->base.base,
2232 rdev->mode_info.underscan_vborder_property,
2233 0);
2234 drm_object_attach_property(&radeon_connector->base.base,
2235 rdev->mode_info.dither_property,
2236 RADEON_FMT_DITHER_DISABLE);
2237 drm_object_attach_property(&radeon_connector->base.base,
2238 dev->mode_config.scaling_mode_property,
2239 DRM_MODE_SCALE_NONE);
2240 }
2241 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
2242 drm_object_attach_property(&radeon_connector->base.base,
2243 rdev->mode_info.audio_property,
2244 RADEON_AUDIO_AUTO);
2245 radeon_connector->audio = RADEON_AUDIO_AUTO;
2246 }
2247 if (ASIC_IS_DCE5(rdev))
2248 drm_object_attach_property(&radeon_connector->base.base,
2249 rdev->mode_info.output_csc_property,
2250 RADEON_OUTPUT_CSC_BYPASS);
2251 connector->interlace_allowed = true;
2252 /* in theory with a DP to VGA converter... */
2253 connector->doublescan_allowed = false;
2254 break;
2255 case DRM_MODE_CONNECTOR_eDP:
2256 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2257 if (!radeon_dig_connector)
2258 goto failed;
2259 radeon_dig_connector->igp_lane_info = igp_lane_info;
2260 radeon_connector->con_priv = radeon_dig_connector;
2261 if (i2c_bus->valid) {
2262 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2263 if (radeon_connector->ddc_bus) {
2264 has_aux = true;
2265 ddc = &radeon_connector->ddc_bus->adapter;
2266 } else {
2267 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2268 }
2269 }
2270 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2271 &radeon_edp_connector_funcs,
2272 connector_type,
2273 ddc);
2274 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2275 drm_object_attach_property(&radeon_connector->base.base,
2276 dev->mode_config.scaling_mode_property,
2277 DRM_MODE_SCALE_FULLSCREEN);
2278 subpixel_order = SubPixelHorizontalRGB;
2279 connector->interlace_allowed = false;
2280 connector->doublescan_allowed = false;
2281 break;
2282 case DRM_MODE_CONNECTOR_SVIDEO:
2283 case DRM_MODE_CONNECTOR_Composite:
2284 case DRM_MODE_CONNECTOR_9PinDIN:
2285 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2286 &radeon_tv_connector_funcs,
2287 connector_type,
2288 ddc);
2289 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2290 radeon_connector->dac_load_detect = true;
2291 drm_object_attach_property(&radeon_connector->base.base,
2292 rdev->mode_info.load_detect_property,
2293 1);
2294 drm_object_attach_property(&radeon_connector->base.base,
2295 rdev->mode_info.tv_std_property,
2296 radeon_atombios_get_tv_info(rdev));
2297 /* no HPD on analog connectors */
2298 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2299 connector->interlace_allowed = false;
2300 connector->doublescan_allowed = false;
2301 break;
2302 case DRM_MODE_CONNECTOR_LVDS:
2303 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2304 if (!radeon_dig_connector)
2305 goto failed;
2306 radeon_dig_connector->igp_lane_info = igp_lane_info;
2307 radeon_connector->con_priv = radeon_dig_connector;
2308 if (i2c_bus->valid) {
2309 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2310 if (!radeon_connector->ddc_bus)
2311 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2312 else
2313 ddc = &radeon_connector->ddc_bus->adapter;
2314 }
2315 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2316 &radeon_lvds_connector_funcs,
2317 connector_type,
2318 ddc);
2319 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2320 drm_object_attach_property(&radeon_connector->base.base,
2321 dev->mode_config.scaling_mode_property,
2322 DRM_MODE_SCALE_FULLSCREEN);
2323 subpixel_order = SubPixelHorizontalRGB;
2324 connector->interlace_allowed = false;
2325 connector->doublescan_allowed = false;
2326 break;
2327 }
2328 }
2329
2330 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
2331 if (i2c_bus->valid) {
2332 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2333 DRM_CONNECTOR_POLL_DISCONNECT;
2334 }
2335 } else
2336 connector->polled = DRM_CONNECTOR_POLL_HPD;
2337
2338 connector->display_info.subpixel_order = subpixel_order;
2339 drm_connector_register(connector);
2340
2341 if (has_aux)
2342 radeon_dp_aux_init(radeon_connector);
2343
2344 return;
2345
2346 failed:
2347 drm_connector_cleanup(connector);
2348 kfree(connector);
2349 }
2350
2351 void
radeon_add_legacy_connector(struct drm_device * dev,uint32_t connector_id,uint32_t supported_device,int connector_type,struct radeon_i2c_bus_rec * i2c_bus,uint16_t connector_object_id,struct radeon_hpd * hpd)2352 radeon_add_legacy_connector(struct drm_device *dev,
2353 uint32_t connector_id,
2354 uint32_t supported_device,
2355 int connector_type,
2356 struct radeon_i2c_bus_rec *i2c_bus,
2357 uint16_t connector_object_id,
2358 struct radeon_hpd *hpd)
2359 {
2360 struct radeon_device *rdev = dev->dev_private;
2361 struct drm_connector *connector;
2362 struct radeon_connector *radeon_connector;
2363 struct i2c_adapter *ddc = NULL;
2364 uint32_t subpixel_order = SubPixelNone;
2365
2366 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
2367 return;
2368
2369 /* if the user selected tv=0 don't try and add the connector */
2370 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
2371 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
2372 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
2373 (radeon_tv == 0))
2374 return;
2375
2376 /* see if we already added it */
2377 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2378 radeon_connector = to_radeon_connector(connector);
2379 if (radeon_connector->connector_id == connector_id) {
2380 radeon_connector->devices |= supported_device;
2381 return;
2382 }
2383 }
2384
2385 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
2386 if (!radeon_connector)
2387 return;
2388
2389 connector = &radeon_connector->base;
2390
2391 radeon_connector->connector_id = connector_id;
2392 radeon_connector->devices = supported_device;
2393 radeon_connector->connector_object_id = connector_object_id;
2394 radeon_connector->hpd = *hpd;
2395
2396 switch (connector_type) {
2397 case DRM_MODE_CONNECTOR_VGA:
2398 if (i2c_bus->valid) {
2399 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2400 if (!radeon_connector->ddc_bus)
2401 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2402 else
2403 ddc = &radeon_connector->ddc_bus->adapter;
2404 }
2405 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2406 &radeon_vga_connector_funcs,
2407 connector_type,
2408 ddc);
2409 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2410 radeon_connector->dac_load_detect = true;
2411 drm_object_attach_property(&radeon_connector->base.base,
2412 rdev->mode_info.load_detect_property,
2413 1);
2414 /* no HPD on analog connectors */
2415 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2416 connector->interlace_allowed = true;
2417 connector->doublescan_allowed = true;
2418 break;
2419 case DRM_MODE_CONNECTOR_DVIA:
2420 if (i2c_bus->valid) {
2421 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2422 if (!radeon_connector->ddc_bus)
2423 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2424 else
2425 ddc = &radeon_connector->ddc_bus->adapter;
2426 }
2427 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2428 &radeon_vga_connector_funcs,
2429 connector_type,
2430 ddc);
2431 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2432 radeon_connector->dac_load_detect = true;
2433 drm_object_attach_property(&radeon_connector->base.base,
2434 rdev->mode_info.load_detect_property,
2435 1);
2436 /* no HPD on analog connectors */
2437 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2438 connector->interlace_allowed = true;
2439 connector->doublescan_allowed = true;
2440 break;
2441 case DRM_MODE_CONNECTOR_DVII:
2442 case DRM_MODE_CONNECTOR_DVID:
2443 if (i2c_bus->valid) {
2444 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2445 if (!radeon_connector->ddc_bus)
2446 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2447 else
2448 ddc = &radeon_connector->ddc_bus->adapter;
2449 }
2450 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2451 &radeon_dvi_connector_funcs,
2452 connector_type,
2453 ddc);
2454 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2455 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2456 radeon_connector->dac_load_detect = true;
2457 drm_object_attach_property(&radeon_connector->base.base,
2458 rdev->mode_info.load_detect_property,
2459 1);
2460 }
2461 subpixel_order = SubPixelHorizontalRGB;
2462 connector->interlace_allowed = true;
2463 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2464 connector->doublescan_allowed = true;
2465 else
2466 connector->doublescan_allowed = false;
2467 break;
2468 case DRM_MODE_CONNECTOR_SVIDEO:
2469 case DRM_MODE_CONNECTOR_Composite:
2470 case DRM_MODE_CONNECTOR_9PinDIN:
2471 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2472 &radeon_tv_connector_funcs,
2473 connector_type,
2474 ddc);
2475 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2476 radeon_connector->dac_load_detect = true;
2477 /* RS400,RC410,RS480 chipset seems to report a lot
2478 * of false positive on load detect, we haven't yet
2479 * found a way to make load detect reliable on those
2480 * chipset, thus just disable it for TV.
2481 */
2482 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
2483 radeon_connector->dac_load_detect = false;
2484 drm_object_attach_property(&radeon_connector->base.base,
2485 rdev->mode_info.load_detect_property,
2486 radeon_connector->dac_load_detect);
2487 drm_object_attach_property(&radeon_connector->base.base,
2488 rdev->mode_info.tv_std_property,
2489 radeon_combios_get_tv_info(rdev));
2490 /* no HPD on analog connectors */
2491 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2492 connector->interlace_allowed = false;
2493 connector->doublescan_allowed = false;
2494 break;
2495 case DRM_MODE_CONNECTOR_LVDS:
2496 if (i2c_bus->valid) {
2497 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2498 if (!radeon_connector->ddc_bus)
2499 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2500 else
2501 ddc = &radeon_connector->ddc_bus->adapter;
2502 }
2503 drm_connector_init_with_ddc(dev, &radeon_connector->base,
2504 &radeon_lvds_connector_funcs,
2505 connector_type,
2506 ddc);
2507 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2508 drm_object_attach_property(&radeon_connector->base.base,
2509 dev->mode_config.scaling_mode_property,
2510 DRM_MODE_SCALE_FULLSCREEN);
2511 subpixel_order = SubPixelHorizontalRGB;
2512 connector->interlace_allowed = false;
2513 connector->doublescan_allowed = false;
2514 break;
2515 }
2516
2517 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
2518 if (i2c_bus->valid) {
2519 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2520 DRM_CONNECTOR_POLL_DISCONNECT;
2521 }
2522 } else
2523 connector->polled = DRM_CONNECTOR_POLL_HPD;
2524
2525 connector->display_info.subpixel_order = subpixel_order;
2526 drm_connector_register(connector);
2527 }
2528