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