blob: d17d251dbd4fe5a1ac99a238fd7aebcf552682ba [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors: Dave Airlie
24 * Alex Deucher
25 */
David Howells760285e2012-10-02 18:01:07 +010026#include <drm/drmP.h>
27#include <drm/drm_edid.h>
28#include <drm/drm_crtc_helper.h>
29#include <drm/drm_fb_helper.h>
Dave Airlie9843ead2015-02-24 09:24:04 +100030#include <drm/drm_dp_mst_helper.h>
David Howells760285e2012-10-02 18:01:07 +010031#include <drm/radeon_drm.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020032#include "radeon.h"
Slava Grigorev1a626b62014-12-01 13:49:39 -050033#include "radeon_audio.h"
Alex Deucher923f6842009-09-10 17:53:39 -040034#include "atom.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020035
Dave Airlie10ebc0b2012-09-17 14:40:31 +100036#include <linux/pm_runtime.h>
37
Dave Airlie9843ead2015-02-24 09:24:04 +100038static int radeon_dp_handle_hpd(struct drm_connector *connector)
39{
40 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
41 int ret;
42
43 ret = radeon_dp_mst_check_status(radeon_connector);
44 if (ret == -EINVAL)
45 return 1;
46 return 0;
47}
Alex Deucherd4877cf2009-12-04 16:56:37 -050048void radeon_connector_hotplug(struct drm_connector *connector)
49{
50 struct drm_device *dev = connector->dev;
51 struct radeon_device *rdev = dev->dev_private;
52 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
53
Dave Airlie9843ead2015-02-24 09:24:04 +100054 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
55 struct radeon_connector_atom_dig *dig_connector =
56 radeon_connector->con_priv;
57
58 if (radeon_connector->is_mst_connector)
59 return;
60 if (dig_connector->is_mst) {
61 radeon_dp_handle_hpd(connector);
62 return;
63 }
64 }
Alex Deuchercbac9542011-07-11 14:49:28 +000065 /* bail if the connector does not have hpd pin, e.g.,
66 * VGA, TV, etc.
67 */
68 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE)
69 return;
70
Alex Deucher1e85e1d2011-05-20 04:34:29 -040071 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
Alex Deucherd4877cf2009-12-04 16:56:37 -050072
Alex Deucher73104b52011-08-09 17:09:06 +000073 /* if the connector is already off, don't turn it back on */
Daniel Vetter6e9f7982014-05-29 23:54:47 +020074 /* FIXME: This access isn't protected by any locks. */
Alex Deucher73104b52011-08-09 17:09:06 +000075 if (connector->dpms != DRM_MODE_DPMS_ON)
76 return;
77
Alex Deucherd5811e82011-08-13 13:36:13 -040078 /* just deal with DP (not eDP) here. */
79 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
Jerome Glisse266dcba2012-07-19 17:15:56 -040080 struct radeon_connector_atom_dig *dig_connector =
81 radeon_connector->con_priv;
Alex Deucher7c3ed0f2011-05-20 04:34:30 -040082
Jerome Glisse266dcba2012-07-19 17:15:56 -040083 /* if existing sink type was not DP no need to retrain */
84 if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT)
85 return;
86
87 /* first get sink type as it may be reset after (un)plug */
88 dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
89 /* don't do anything if sink is not display port, i.e.,
90 * passive dp->(dvi|hdmi) adaptor
91 */
92 if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
93 int saved_dpms = connector->dpms;
94 /* Only turn off the display if it's physically disconnected */
Jerome Glisseca2ccde2012-07-19 17:25:55 -040095 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
Jerome Glisse266dcba2012-07-19 17:15:56 -040096 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
Jerome Glisseca2ccde2012-07-19 17:25:55 -040097 } else if (radeon_dp_needs_link_train(radeon_connector)) {
98 /* set it to OFF so that drm_helper_connector_dpms()
99 * won't return immediately since the current state
100 * is ON at this point.
101 */
102 connector->dpms = DRM_MODE_DPMS_OFF;
Jerome Glisse266dcba2012-07-19 17:15:56 -0400103 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
Jerome Glisseca2ccde2012-07-19 17:25:55 -0400104 }
Jerome Glisse266dcba2012-07-19 17:15:56 -0400105 connector->dpms = saved_dpms;
106 }
Alex Deucherd4877cf2009-12-04 16:56:37 -0500107 }
Alex Deucherd4877cf2009-12-04 16:56:37 -0500108}
109
Dave Airlie445282d2009-09-09 17:40:54 +1000110static void radeon_property_change_mode(struct drm_encoder *encoder)
111{
112 struct drm_crtc *crtc = encoder->crtc;
113
114 if (crtc && crtc->enabled) {
115 drm_crtc_helper_set_mode(crtc, &crtc->mode,
Matt Roperf4510a22014-04-01 15:22:40 -0700116 crtc->x, crtc->y, crtc->primary->fb);
Dave Airlie445282d2009-09-09 17:40:54 +1000117 }
118}
Alex Deuchereccea792012-03-26 15:12:54 -0400119
120int radeon_get_monitor_bpc(struct drm_connector *connector)
121{
122 struct drm_device *dev = connector->dev;
123 struct radeon_device *rdev = dev->dev_private;
124 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
125 struct radeon_connector_atom_dig *dig_connector;
126 int bpc = 8;
Mario Kleinerea292862014-06-05 09:58:24 -0400127 int mode_clock, max_tmds_clock;
Alex Deuchereccea792012-03-26 15:12:54 -0400128
129 switch (connector->connector_type) {
130 case DRM_MODE_CONNECTOR_DVII:
131 case DRM_MODE_CONNECTOR_HDMIB:
132 if (radeon_connector->use_digital) {
Alex Deucher377bd8a2014-07-15 11:00:47 -0400133 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Alex Deuchereccea792012-03-26 15:12:54 -0400134 if (connector->display_info.bpc)
135 bpc = connector->display_info.bpc;
136 }
137 }
138 break;
139 case DRM_MODE_CONNECTOR_DVID:
140 case DRM_MODE_CONNECTOR_HDMIA:
Alex Deucher377bd8a2014-07-15 11:00:47 -0400141 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Alex Deuchereccea792012-03-26 15:12:54 -0400142 if (connector->display_info.bpc)
143 bpc = connector->display_info.bpc;
144 }
145 break;
146 case DRM_MODE_CONNECTOR_DisplayPort:
147 dig_connector = radeon_connector->con_priv;
148 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
149 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) ||
Alex Deucher377bd8a2014-07-15 11:00:47 -0400150 drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Alex Deuchereccea792012-03-26 15:12:54 -0400151 if (connector->display_info.bpc)
152 bpc = connector->display_info.bpc;
153 }
154 break;
155 case DRM_MODE_CONNECTOR_eDP:
156 case DRM_MODE_CONNECTOR_LVDS:
157 if (connector->display_info.bpc)
158 bpc = connector->display_info.bpc;
159 else if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
Jani Nikula319d1e12015-03-11 11:51:02 +0200160 const struct drm_connector_helper_funcs *connector_funcs =
Alex Deuchereccea792012-03-26 15:12:54 -0400161 connector->helper_private;
162 struct drm_encoder *encoder = connector_funcs->best_encoder(connector);
163 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
164 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
165
166 if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR)
167 bpc = 6;
168 else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR)
169 bpc = 8;
170 }
171 break;
172 }
Mario Kleiner89b92332014-05-05 23:03:18 +0200173
Alex Deucher377bd8a2014-07-15 11:00:47 -0400174 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Mario Kleiner89b92332014-05-05 23:03:18 +0200175 /* hdmi deep color only implemented on DCE4+ */
176 if ((bpc > 8) && !ASIC_IS_DCE4(rdev)) {
177 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 8 bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300178 connector->name, bpc);
Mario Kleiner89b92332014-05-05 23:03:18 +0200179 bpc = 8;
180 }
181
182 /*
183 * Pre DCE-8 hw can't handle > 12 bpc, and more than 12 bpc doesn't make
184 * much sense without support for > 12 bpc framebuffers. RGB 4:4:4 at
185 * 12 bpc is always supported on hdmi deep color sinks, as this is
186 * required by the HDMI-1.3 spec. Clamp to a safe 12 bpc maximum.
187 */
188 if (bpc > 12) {
189 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 12 bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300190 connector->name, bpc);
Mario Kleiner89b92332014-05-05 23:03:18 +0200191 bpc = 12;
192 }
Mario Kleinerea292862014-06-05 09:58:24 -0400193
194 /* Any defined maximum tmds clock limit we must not exceed? */
195 if (connector->max_tmds_clock > 0) {
196 /* mode_clock is clock in kHz for mode to be modeset on this connector */
197 mode_clock = radeon_connector->pixelclock_for_modeset;
198
199 /* Maximum allowable input clock in kHz */
200 max_tmds_clock = connector->max_tmds_clock * 1000;
201
202 DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds input clock %d kHz.\n",
203 connector->name, mode_clock, max_tmds_clock);
204
205 /* Check if bpc is within clock limit. Try to degrade gracefully otherwise */
206 if ((bpc == 12) && (mode_clock * 3/2 > max_tmds_clock)) {
207 if ((connector->display_info.edid_hdmi_dc_modes & DRM_EDID_HDMI_DC_30) &&
208 (mode_clock * 5/4 <= max_tmds_clock))
209 bpc = 10;
210 else
211 bpc = 8;
212
213 DRM_DEBUG("%s: HDMI deep color 12 bpc exceeds max tmds clock. Using %d bpc.\n",
214 connector->name, bpc);
215 }
216
217 if ((bpc == 10) && (mode_clock * 5/4 > max_tmds_clock)) {
218 bpc = 8;
219 DRM_DEBUG("%s: HDMI deep color 10 bpc exceeds max tmds clock. Using %d bpc.\n",
220 connector->name, bpc);
221 }
222 }
Mario Kleiner9f51e2e2014-08-05 05:23:11 +0200223 else if (bpc > 8) {
224 /* max_tmds_clock missing, but hdmi spec mandates it for deep color. */
225 DRM_DEBUG("%s: Required max tmds clock for HDMI deep color missing. Using 8 bpc.\n",
226 connector->name);
227 bpc = 8;
228 }
Mario Kleiner89b92332014-05-05 23:03:18 +0200229 }
230
Mario Kleiner9f51e2e2014-08-05 05:23:11 +0200231 if ((radeon_deep_color == 0) && (bpc > 8)) {
232 DRM_DEBUG("%s: Deep color disabled. Set radeon module param deep_color=1 to enable.\n",
233 connector->name);
Alex Deuchera624f422014-07-01 11:23:03 -0400234 bpc = 8;
Mario Kleiner9f51e2e2014-08-05 05:23:11 +0200235 }
Alex Deuchera624f422014-07-01 11:23:03 -0400236
Mario Kleiner89b92332014-05-05 23:03:18 +0200237 DRM_DEBUG("%s: Display bpc=%d, returned bpc=%d\n",
Jani Nikula72082092014-06-03 14:56:19 +0300238 connector->name, connector->display_info.bpc, bpc);
Mario Kleiner89b92332014-05-05 23:03:18 +0200239
Alex Deuchereccea792012-03-26 15:12:54 -0400240 return bpc;
241}
242
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200243static void
244radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
245{
246 struct drm_device *dev = connector->dev;
247 struct radeon_device *rdev = dev->dev_private;
248 struct drm_encoder *best_encoder = NULL;
249 struct drm_encoder *encoder = NULL;
Jani Nikula319d1e12015-03-11 11:51:02 +0200250 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200251 bool connected;
252 int i;
253
254 best_encoder = connector_funcs->best_encoder(connector);
255
256 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
257 if (connector->encoder_ids[i] == 0)
258 break;
259
Rob Clarkb957f452014-07-17 23:30:05 -0400260 encoder = drm_encoder_find(connector->dev,
261 connector->encoder_ids[i]);
262 if (!encoder)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200263 continue;
264
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200265 if ((encoder == best_encoder) && (status == connector_status_connected))
266 connected = true;
267 else
268 connected = false;
269
270 if (rdev->is_atom_bios)
271 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
272 else
273 radeon_combios_connected_scratch_regs(connector, encoder, connected);
274
275 }
276}
277
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400278static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
Dave Airlie445282d2009-09-09 17:40:54 +1000279{
Dave Airlie445282d2009-09-09 17:40:54 +1000280 struct drm_encoder *encoder;
281 int i;
282
283 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
284 if (connector->encoder_ids[i] == 0)
285 break;
286
Rob Clarkb957f452014-07-17 23:30:05 -0400287 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
288 if (!encoder)
Dave Airlie445282d2009-09-09 17:40:54 +1000289 continue;
290
Dave Airlie445282d2009-09-09 17:40:54 +1000291 if (encoder->encoder_type == encoder_type)
292 return encoder;
293 }
294 return NULL;
295}
296
Alex Deucher377bd8a2014-07-15 11:00:47 -0400297struct edid *radeon_connector_edid(struct drm_connector *connector)
298{
299 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
300 struct drm_property_blob *edid_blob = connector->edid_blob_ptr;
301
302 if (radeon_connector->edid) {
303 return radeon_connector->edid;
304 } else if (edid_blob) {
305 struct edid *edid = kmemdup(edid_blob->data, edid_blob->length, GFP_KERNEL);
306 if (edid)
307 radeon_connector->edid = edid;
308 }
309 return radeon_connector->edid;
310}
311
Alex Deucher72a5c972014-07-15 10:38:10 -0400312static void radeon_connector_get_edid(struct drm_connector *connector)
313{
314 struct drm_device *dev = connector->dev;
315 struct radeon_device *rdev = dev->dev_private;
316 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
317
318 if (radeon_connector->edid)
319 return;
320
321 /* on hw with routers, select right port */
322 if (radeon_connector->router.ddc_valid)
323 radeon_router_select_ddc_port(radeon_connector);
324
325 if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
326 ENCODER_OBJECT_ID_NONE) &&
327 radeon_connector->ddc_bus->has_aux) {
328 radeon_connector->edid = drm_get_edid(connector,
329 &radeon_connector->ddc_bus->aux.ddc);
330 } else if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
331 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
332 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
333
334 if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
335 dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) &&
336 radeon_connector->ddc_bus->has_aux)
337 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
338 &radeon_connector->ddc_bus->aux.ddc);
339 else if (radeon_connector->ddc_bus)
340 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
341 &radeon_connector->ddc_bus->adapter);
342 } else if (radeon_connector->ddc_bus) {
343 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
344 &radeon_connector->ddc_bus->adapter);
345 }
346
347 if (!radeon_connector->edid) {
Alex Deucher13485792014-11-14 12:08:34 -0500348 /* don't fetch the edid from the vbios if ddc fails and runpm is
349 * enabled so we report disconnected.
350 */
351 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
352 return;
353
Alex Deucher72a5c972014-07-15 10:38:10 -0400354 if (rdev->is_atom_bios) {
355 /* some laptops provide a hardcoded edid in rom for LCDs */
356 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
357 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)))
358 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
359 } else {
360 /* some servers provide a hardcoded edid in rom for KVMs */
361 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
362 }
363 }
364}
365
366static void radeon_connector_free_edid(struct drm_connector *connector)
367{
368 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
369
370 if (radeon_connector->edid) {
371 kfree(radeon_connector->edid);
372 radeon_connector->edid = NULL;
373 }
374}
375
376static int radeon_ddc_get_modes(struct drm_connector *connector)
377{
378 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
379 int ret;
380
381 if (radeon_connector->edid) {
382 drm_mode_connector_update_edid_property(connector, radeon_connector->edid);
383 ret = drm_add_edid_modes(connector, radeon_connector->edid);
384 drm_edid_to_eld(connector, radeon_connector->edid);
385 return ret;
386 }
387 drm_mode_connector_update_edid_property(connector, NULL);
388 return 0;
389}
390
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400391static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200392{
393 int enc_id = connector->encoder_ids[0];
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200394 /* pick the encoder ids */
Rob Clarkb957f452014-07-17 23:30:05 -0400395 if (enc_id)
396 return drm_encoder_find(connector->dev, enc_id);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200397 return NULL;
398}
399
Alex Deucherda997622014-07-09 13:21:59 -0400400static void radeon_get_native_mode(struct drm_connector *connector)
401{
402 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
403 struct radeon_encoder *radeon_encoder;
404
405 if (encoder == NULL)
406 return;
407
408 radeon_encoder = to_radeon_encoder(encoder);
409
410 if (!list_empty(&connector->probed_modes)) {
411 struct drm_display_mode *preferred_mode =
412 list_first_entry(&connector->probed_modes,
413 struct drm_display_mode, head);
414
415 radeon_encoder->native_mode = *preferred_mode;
416 } else {
417 radeon_encoder->native_mode.clock = 0;
418 }
419}
420
Dave Airlie4ce001a2009-08-13 16:32:14 +1000421/*
422 * radeon_connector_analog_encoder_conflict_solve
423 * - search for other connectors sharing this encoder
424 * if priority is true, then set them disconnected if this is connected
425 * if priority is false, set us disconnected if they are connected
426 */
427static enum drm_connector_status
428radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
429 struct drm_encoder *encoder,
430 enum drm_connector_status current_status,
431 bool priority)
432{
433 struct drm_device *dev = connector->dev;
434 struct drm_connector *conflict;
Alex Deucher08d07512010-04-15 13:31:12 -0400435 struct radeon_connector *radeon_conflict;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000436 int i;
437
438 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
439 if (conflict == connector)
440 continue;
441
Alex Deucher08d07512010-04-15 13:31:12 -0400442 radeon_conflict = to_radeon_connector(conflict);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000443 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
444 if (conflict->encoder_ids[i] == 0)
445 break;
446
447 /* if the IDs match */
448 if (conflict->encoder_ids[i] == encoder->base.id) {
449 if (conflict->status != connector_status_connected)
450 continue;
451
Alex Deucher08d07512010-04-15 13:31:12 -0400452 if (radeon_conflict->use_digital)
453 continue;
454
Dave Airlie4ce001a2009-08-13 16:32:14 +1000455 if (priority == true) {
Jani Nikula72082092014-06-03 14:56:19 +0300456 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n",
457 conflict->name);
458 DRM_DEBUG_KMS("in favor of %s\n",
459 connector->name);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000460 conflict->status = connector_status_disconnected;
461 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
462 } else {
Jani Nikula72082092014-06-03 14:56:19 +0300463 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n",
464 connector->name);
465 DRM_DEBUG_KMS("in favor of %s\n",
466 conflict->name);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000467 current_status = connector_status_disconnected;
468 }
469 break;
470 }
471 }
472 }
473 return current_status;
474
475}
476
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200477static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
478{
479 struct drm_device *dev = encoder->dev;
480 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
481 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400482 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200483
Alex Deucherde2103e2009-10-09 15:14:30 -0400484 if (native_mode->hdisplay != 0 &&
485 native_mode->vdisplay != 0 &&
486 native_mode->clock != 0) {
Alex Deucherfb06ca82009-10-12 11:25:05 -0400487 mode = drm_mode_duplicate(dev, native_mode);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200488 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
489 drm_mode_set_name(mode);
490
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000491 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
Alex Deucherd2efdf62009-12-22 10:06:49 -0500492 } else if (native_mode->hdisplay != 0 &&
493 native_mode->vdisplay != 0) {
494 /* mac laptops without an edid */
495 /* Note that this is not necessarily the exact panel mode,
496 * but an approximation based on the cvt formula. For these
497 * systems we should ideally read the mode info out of the
498 * registers or add a mode table, but this works and is much
499 * simpler.
500 */
501 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
502 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000503 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200504 }
505 return mode;
506}
507
Alex Deucher923f6842009-09-10 17:53:39 -0400508static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
509{
510 struct drm_device *dev = encoder->dev;
511 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
512 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400513 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400514 int i;
515 struct mode_size {
516 int w;
517 int h;
518 } common_modes[17] = {
519 { 640, 480},
520 { 720, 480},
521 { 800, 600},
522 { 848, 480},
523 {1024, 768},
524 {1152, 768},
525 {1280, 720},
526 {1280, 800},
527 {1280, 854},
528 {1280, 960},
529 {1280, 1024},
530 {1440, 900},
531 {1400, 1050},
532 {1680, 1050},
533 {1600, 1200},
534 {1920, 1080},
535 {1920, 1200}
536 };
537
538 for (i = 0; i < 17; i++) {
Alex Deucherdfdd6462009-10-13 12:48:44 -0400539 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
540 if (common_modes[i].w > 1024 ||
541 common_modes[i].h > 768)
542 continue;
543 }
Alex Deucher923f6842009-09-10 17:53:39 -0400544 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400545 if (common_modes[i].w > native_mode->hdisplay ||
546 common_modes[i].h > native_mode->vdisplay ||
547 (common_modes[i].w == native_mode->hdisplay &&
548 common_modes[i].h == native_mode->vdisplay))
Alex Deucher923f6842009-09-10 17:53:39 -0400549 continue;
550 }
551 if (common_modes[i].w < 320 || common_modes[i].h < 200)
552 continue;
553
Dave Airlied50ba252009-09-23 14:44:08 +1000554 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400555 drm_mode_probed_add(connector, mode);
556 }
557}
558
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400559static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200560 uint64_t val)
561{
Dave Airlie445282d2009-09-09 17:40:54 +1000562 struct drm_device *dev = connector->dev;
563 struct radeon_device *rdev = dev->dev_private;
564 struct drm_encoder *encoder;
565 struct radeon_encoder *radeon_encoder;
566
567 if (property == rdev->mode_info.coherent_mode_property) {
568 struct radeon_encoder_atom_dig *dig;
Dave Airliece227c42010-04-09 06:27:00 +0000569 bool new_coherent_mode;
Dave Airlie445282d2009-09-09 17:40:54 +1000570
571 /* need to find digital encoder on connector */
572 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
573 if (!encoder)
574 return 0;
575
576 radeon_encoder = to_radeon_encoder(encoder);
577
578 if (!radeon_encoder->enc_priv)
579 return 0;
580
581 dig = radeon_encoder->enc_priv;
Dave Airliece227c42010-04-09 06:27:00 +0000582 new_coherent_mode = val ? true : false;
583 if (dig->coherent_mode != new_coherent_mode) {
584 dig->coherent_mode = new_coherent_mode;
585 radeon_property_change_mode(&radeon_encoder->base);
586 }
Dave Airlie445282d2009-09-09 17:40:54 +1000587 }
588
Alex Deucher8666c072013-09-03 14:58:44 -0400589 if (property == rdev->mode_info.audio_property) {
590 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
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_connector->audio != val) {
599 radeon_connector->audio = val;
600 radeon_property_change_mode(&radeon_encoder->base);
601 }
602 }
603
Alex Deucher6214bb72013-09-24 17:26:26 -0400604 if (property == rdev->mode_info.dither_property) {
605 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
606 /* need to find digital encoder on connector */
607 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
608 if (!encoder)
609 return 0;
610
611 radeon_encoder = to_radeon_encoder(encoder);
612
613 if (radeon_connector->dither != val) {
614 radeon_connector->dither = val;
615 radeon_property_change_mode(&radeon_encoder->base);
616 }
617 }
618
Alex Deucher5b1714d2010-08-03 19:59:20 -0400619 if (property == rdev->mode_info.underscan_property) {
620 /* need to find digital encoder on connector */
621 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
622 if (!encoder)
623 return 0;
624
625 radeon_encoder = to_radeon_encoder(encoder);
626
627 if (radeon_encoder->underscan_type != val) {
628 radeon_encoder->underscan_type = val;
629 radeon_property_change_mode(&radeon_encoder->base);
630 }
631 }
632
Marius Gröger5bccf5e2010-09-21 21:30:59 +0200633 if (property == rdev->mode_info.underscan_hborder_property) {
634 /* need to find digital encoder on connector */
635 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
636 if (!encoder)
637 return 0;
638
639 radeon_encoder = to_radeon_encoder(encoder);
640
641 if (radeon_encoder->underscan_hborder != val) {
642 radeon_encoder->underscan_hborder = val;
643 radeon_property_change_mode(&radeon_encoder->base);
644 }
645 }
646
647 if (property == rdev->mode_info.underscan_vborder_property) {
648 /* need to find digital encoder on connector */
649 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
650 if (!encoder)
651 return 0;
652
653 radeon_encoder = to_radeon_encoder(encoder);
654
655 if (radeon_encoder->underscan_vborder != val) {
656 radeon_encoder->underscan_vborder = val;
657 radeon_property_change_mode(&radeon_encoder->base);
658 }
659 }
660
Dave Airlie445282d2009-09-09 17:40:54 +1000661 if (property == rdev->mode_info.tv_std_property) {
662 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
663 if (!encoder) {
664 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
665 }
666
667 if (!encoder)
668 return 0;
669
670 radeon_encoder = to_radeon_encoder(encoder);
671 if (!radeon_encoder->enc_priv)
672 return 0;
Alex Deucher643acac2010-04-05 23:57:52 -0400673 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
Dave Airlie445282d2009-09-09 17:40:54 +1000674 struct radeon_encoder_atom_dac *dac_int;
675 dac_int = radeon_encoder->enc_priv;
676 dac_int->tv_std = val;
677 } else {
678 struct radeon_encoder_tv_dac *dac_int;
679 dac_int = radeon_encoder->enc_priv;
680 dac_int->tv_std = val;
681 }
682 radeon_property_change_mode(&radeon_encoder->base);
683 }
684
685 if (property == rdev->mode_info.load_detect_property) {
686 struct radeon_connector *radeon_connector =
687 to_radeon_connector(connector);
688
689 if (val == 0)
690 radeon_connector->dac_load_detect = false;
691 else
692 radeon_connector->dac_load_detect = true;
693 }
694
695 if (property == rdev->mode_info.tmds_pll_property) {
696 struct radeon_encoder_int_tmds *tmds = NULL;
697 bool ret = false;
698 /* need to find digital encoder on connector */
699 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
700 if (!encoder)
701 return 0;
702
703 radeon_encoder = to_radeon_encoder(encoder);
704
705 tmds = radeon_encoder->enc_priv;
706 if (!tmds)
707 return 0;
708
709 if (val == 0) {
710 if (rdev->is_atom_bios)
711 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
712 else
713 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
714 }
715 if (val == 1 || ret == false) {
716 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
717 }
718 radeon_property_change_mode(&radeon_encoder->base);
719 }
720
Alex Deucherda997622014-07-09 13:21:59 -0400721 if (property == dev->mode_config.scaling_mode_property) {
722 enum radeon_rmx_type rmx_type;
723
724 if (connector->encoder)
725 radeon_encoder = to_radeon_encoder(connector->encoder);
726 else {
Jani Nikula319d1e12015-03-11 11:51:02 +0200727 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
Alex Deucherda997622014-07-09 13:21:59 -0400728 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
729 }
730
731 switch (val) {
732 default:
733 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
734 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
735 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
736 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
737 }
738 if (radeon_encoder->rmx_type == rmx_type)
739 return 0;
740
741 if ((rmx_type != DRM_MODE_SCALE_NONE) &&
742 (radeon_encoder->native_mode.clock == 0))
743 return 0;
744
745 radeon_encoder->rmx_type = rmx_type;
746
747 radeon_property_change_mode(&radeon_encoder->base);
748 }
749
Alex Deucher643b1f52015-02-23 10:59:36 -0500750 if (property == rdev->mode_info.output_csc_property) {
751 if (connector->encoder)
752 radeon_encoder = to_radeon_encoder(connector->encoder);
753 else {
Jani Nikula16bb0792015-04-13 11:21:40 +0300754 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
Alex Deucher643b1f52015-02-23 10:59:36 -0500755 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
756 }
757
758 if (radeon_encoder->output_csc == val)
759 return 0;
760
761 radeon_encoder->output_csc = val;
762
763 if (connector->encoder->crtc) {
764 struct drm_crtc *crtc = connector->encoder->crtc;
Jani Nikula16bb0792015-04-13 11:21:40 +0300765 const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
Alex Deucher643b1f52015-02-23 10:59:36 -0500766 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
767
768 radeon_crtc->output_csc = radeon_encoder->output_csc;
769
770 (*crtc_funcs->load_lut)(crtc);
771 }
772 }
773
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200774 return 0;
775}
776
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200777static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
778 struct drm_connector *connector)
779{
780 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400781 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Matthew Garrett13bb9432011-08-08 16:21:15 +0000782 struct drm_display_mode *t, *mode;
783
784 /* If the EDID preferred mode doesn't match the native mode, use it */
785 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
786 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
787 if (mode->hdisplay != native_mode->hdisplay ||
788 mode->vdisplay != native_mode->vdisplay)
789 memcpy(native_mode, mode, sizeof(*mode));
790 }
791 }
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200792
793 /* Try to get native mode details from EDID if necessary */
Alex Deucherde2103e2009-10-09 15:14:30 -0400794 if (!native_mode->clock) {
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200795 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400796 if (mode->hdisplay == native_mode->hdisplay &&
797 mode->vdisplay == native_mode->vdisplay) {
798 *native_mode = *mode;
799 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
Alex Deucherc5d46b42010-10-29 13:49:25 -0400800 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200801 break;
802 }
803 }
804 }
Matthew Garrett13bb9432011-08-08 16:21:15 +0000805
Alex Deucherde2103e2009-10-09 15:14:30 -0400806 if (!native_mode->clock) {
Alex Deucherc5d46b42010-10-29 13:49:25 -0400807 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200808 radeon_encoder->rmx_type = RMX_OFF;
809 }
810}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200811
812static int radeon_lvds_get_modes(struct drm_connector *connector)
813{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200814 struct drm_encoder *encoder;
815 int ret = 0;
816 struct drm_display_mode *mode;
817
Alex Deucher72a5c972014-07-15 10:38:10 -0400818 radeon_connector_get_edid(connector);
819 ret = radeon_ddc_get_modes(connector);
820 if (ret > 0) {
821 encoder = radeon_best_single_encoder(connector);
822 if (encoder) {
823 radeon_fixup_lvds_native_mode(encoder, connector);
824 /* add scaled modes */
825 radeon_add_common_modes(encoder, connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200826 }
Alex Deucher72a5c972014-07-15 10:38:10 -0400827 return ret;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200828 }
829
830 encoder = radeon_best_single_encoder(connector);
831 if (!encoder)
832 return 0;
833
834 /* we have no EDID modes */
835 mode = radeon_fp_native_mode(encoder);
836 if (mode) {
837 ret = 1;
838 drm_mode_probed_add(connector, mode);
Alex Deucher7a868e12010-12-08 22:13:05 -0500839 /* add the width/height from vbios tables if available */
840 connector->display_info.width_mm = mode->width_mm;
841 connector->display_info.height_mm = mode->height_mm;
Alex Deucher7747b712009-09-11 11:15:43 -0400842 /* add scaled modes */
843 radeon_add_common_modes(encoder, connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200844 }
Alex Deucher923f6842009-09-10 17:53:39 -0400845
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200846 return ret;
847}
848
849static int radeon_lvds_mode_valid(struct drm_connector *connector,
850 struct drm_display_mode *mode)
851{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500852 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
853
854 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
855 return MODE_PANEL;
856
857 if (encoder) {
858 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
859 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
860
861 /* AVIVO hardware supports downscaling modes larger than the panel
862 * to the panel size, but I'm not sure this is desirable.
863 */
864 if ((mode->hdisplay > native_mode->hdisplay) ||
865 (mode->vdisplay > native_mode->vdisplay))
866 return MODE_PANEL;
867
868 /* if scaling is disabled, block non-native modes */
869 if (radeon_encoder->rmx_type == RMX_OFF) {
870 if ((mode->hdisplay != native_mode->hdisplay) ||
871 (mode->vdisplay != native_mode->vdisplay))
872 return MODE_PANEL;
873 }
874 }
875
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200876 return MODE_OK;
877}
878
Chris Wilson7b334fc2010-09-09 23:51:02 +0100879static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100880radeon_lvds_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200881{
Alex Deucher13485792014-11-14 12:08:34 -0500882 struct drm_device *dev = connector->dev;
883 struct radeon_device *rdev = dev->dev_private;
Alex Deucher0549a0612009-10-09 18:41:19 -0400884 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher2ffb8422009-10-08 13:02:19 -0400885 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Alex Deucher0549a0612009-10-09 18:41:19 -0400886 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000887 int r;
888
889 r = pm_runtime_get_sync(connector->dev->dev);
890 if (r < 0)
891 return connector_status_disconnected;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400892
893 if (encoder) {
894 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400895 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400896
897 /* check if panel is valid */
Alex Deucherde2103e2009-10-09 15:14:30 -0400898 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
Alex Deucher2ffb8422009-10-08 13:02:19 -0400899 ret = connector_status_connected;
Alex Deucher13485792014-11-14 12:08:34 -0500900 /* don't fetch the edid from the vbios if ddc fails and runpm is
901 * enabled so we report disconnected.
902 */
903 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
904 ret = connector_status_disconnected;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400905 }
Alex Deucher0549a0612009-10-09 18:41:19 -0400906
907 /* check for edid as well */
Alex Deucher72a5c972014-07-15 10:38:10 -0400908 radeon_connector_get_edid(connector);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400909 if (radeon_connector->edid)
910 ret = connector_status_connected;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200911 /* check acpi lid status ??? */
Alex Deucher2ffb8422009-10-08 13:02:19 -0400912
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200913 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000914 pm_runtime_mark_last_busy(connector->dev->dev);
915 pm_runtime_put_autosuspend(connector->dev->dev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200916 return ret;
917}
918
919static void radeon_connector_destroy(struct drm_connector *connector)
920{
921 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
922
Alex Deucher72a5c972014-07-15 10:38:10 -0400923 radeon_connector_free_edid(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200924 kfree(radeon_connector->con_priv);
Thomas Wood34ea3d32014-05-29 16:57:41 +0100925 drm_connector_unregister(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200926 drm_connector_cleanup(connector);
927 kfree(connector);
928}
929
Dave Airlie445282d2009-09-09 17:40:54 +1000930static int radeon_lvds_set_property(struct drm_connector *connector,
931 struct drm_property *property,
932 uint64_t value)
933{
934 struct drm_device *dev = connector->dev;
935 struct radeon_encoder *radeon_encoder;
936 enum radeon_rmx_type rmx_type;
937
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000938 DRM_DEBUG_KMS("\n");
Dave Airlie445282d2009-09-09 17:40:54 +1000939 if (property != dev->mode_config.scaling_mode_property)
940 return 0;
941
942 if (connector->encoder)
943 radeon_encoder = to_radeon_encoder(connector->encoder);
944 else {
Jani Nikula319d1e12015-03-11 11:51:02 +0200945 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
Dave Airlie445282d2009-09-09 17:40:54 +1000946 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
947 }
948
949 switch (value) {
950 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
951 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
952 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
953 default:
954 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
955 }
956 if (radeon_encoder->rmx_type == rmx_type)
957 return 0;
958
959 radeon_encoder->rmx_type = rmx_type;
960
961 radeon_property_change_mode(&radeon_encoder->base);
962 return 0;
963}
964
965
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400966static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200967 .get_modes = radeon_lvds_get_modes,
968 .mode_valid = radeon_lvds_mode_valid,
969 .best_encoder = radeon_best_single_encoder,
970};
971
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400972static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200973 .dpms = drm_helper_connector_dpms,
974 .detect = radeon_lvds_detect,
975 .fill_modes = drm_helper_probe_single_connector_modes,
976 .destroy = radeon_connector_destroy,
Dave Airlie445282d2009-09-09 17:40:54 +1000977 .set_property = radeon_lvds_set_property,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200978};
979
980static int radeon_vga_get_modes(struct drm_connector *connector)
981{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200982 int ret;
983
Alex Deucher72a5c972014-07-15 10:38:10 -0400984 radeon_connector_get_edid(connector);
985 ret = radeon_ddc_get_modes(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200986
Alex Deucherda997622014-07-09 13:21:59 -0400987 radeon_get_native_mode(connector);
988
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200989 return ret;
990}
991
992static int radeon_vga_mode_valid(struct drm_connector *connector,
993 struct drm_display_mode *mode)
994{
Alex Deucherb20f9be2011-06-08 13:01:11 -0400995 struct drm_device *dev = connector->dev;
996 struct radeon_device *rdev = dev->dev_private;
997
Alex Deuchera3fa6322009-11-05 11:57:07 -0500998 /* XXX check mode bandwidth */
Alex Deucherb20f9be2011-06-08 13:01:11 -0400999
1000 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1001 return MODE_CLOCK_HIGH;
1002
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001003 return MODE_OK;
1004}
1005
Chris Wilson7b334fc2010-09-09 23:51:02 +01001006static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +01001007radeon_vga_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001008{
Alex Deucherfafcf942011-03-23 08:10:10 +00001009 struct drm_device *dev = connector->dev;
1010 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001011 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1012 struct drm_encoder *encoder;
Jani Nikula319d1e12015-03-11 11:51:02 +02001013 const struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie4b9d2a22010-02-08 13:16:55 +10001014 bool dret = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001015 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001016 int r;
1017
1018 r = pm_runtime_get_sync(connector->dev->dev);
1019 if (r < 0)
1020 return connector_status_disconnected;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001021
Dave Airlie4ce001a2009-08-13 16:32:14 +10001022 encoder = radeon_best_single_encoder(connector);
1023 if (!encoder)
1024 ret = connector_status_disconnected;
1025
Dave Airlieeb6b6d72010-02-25 13:44:04 +10001026 if (radeon_connector->ddc_bus)
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +01001027 dret = radeon_ddc_probe(radeon_connector, false);
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001028 if (dret) {
Alex Deucherd0d0a222011-10-07 14:23:48 -04001029 radeon_connector->detected_by_load = false;
Alex Deucher72a5c972014-07-15 10:38:10 -04001030 radeon_connector_free_edid(connector);
1031 radeon_connector_get_edid(connector);
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001032
1033 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +01001034 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
Jani Nikula72082092014-06-03 14:56:19 +03001035 connector->name);
Jerome Glissef82f5f32009-11-12 14:13:53 +01001036 ret = connector_status_connected;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001037 } else {
Alex Deucher72a5c972014-07-15 10:38:10 -04001038 radeon_connector->use_digital =
1039 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001040
1041 /* some oems have boards with separate digital and analog connectors
1042 * with a shared ddc line (often vga + hdmi)
1043 */
1044 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
Alex Deucher72a5c972014-07-15 10:38:10 -04001045 radeon_connector_free_edid(connector);
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001046 ret = connector_status_disconnected;
Alex Deucher72a5c972014-07-15 10:38:10 -04001047 } else {
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001048 ret = connector_status_connected;
Alex Deucher72a5c972014-07-15 10:38:10 -04001049 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001050 }
1051 } else {
Dave Airliec3cceed2010-10-26 12:55:52 +10001052
1053 /* if we aren't forcing don't do destructive polling */
Alex Deucherd0d0a222011-10-07 14:23:48 -04001054 if (!force) {
1055 /* only return the previous status if we last
1056 * detected a monitor via load.
1057 */
1058 if (radeon_connector->detected_by_load)
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001059 ret = connector->status;
1060 goto out;
Alex Deucherd0d0a222011-10-07 14:23:48 -04001061 }
Dave Airliec3cceed2010-10-26 12:55:52 +10001062
Darren Jenkinsd8a7f792009-12-30 12:22:55 +11001063 if (radeon_connector->dac_load_detect && encoder) {
Dave Airlie445282d2009-09-09 17:40:54 +10001064 encoder_funcs = encoder->helper_private;
1065 ret = encoder_funcs->detect(encoder, connector);
Jerome Glisse34076442011-10-24 18:16:34 -04001066 if (ret != connector_status_disconnected)
Alex Deucherd0d0a222011-10-07 14:23:48 -04001067 radeon_connector->detected_by_load = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001068 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001069 }
1070
Dave Airlie4ce001a2009-08-13 16:32:14 +10001071 if (ret == connector_status_connected)
1072 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
Alex Deucherfafcf942011-03-23 08:10:10 +00001073
1074 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1075 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1076 * by other means, assume the CRT is connected and use that EDID.
1077 */
1078 if ((!rdev->is_atom_bios) &&
1079 (ret == connector_status_disconnected) &&
1080 rdev->mode_info.bios_hardcoded_edid_size) {
1081 ret = connector_status_connected;
1082 }
1083
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001084 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001085
1086out:
1087 pm_runtime_mark_last_busy(connector->dev->dev);
1088 pm_runtime_put_autosuspend(connector->dev->dev);
1089
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001090 return ret;
1091}
1092
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001093static const struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001094 .get_modes = radeon_vga_get_modes,
1095 .mode_valid = radeon_vga_mode_valid,
1096 .best_encoder = radeon_best_single_encoder,
1097};
1098
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001099static const struct drm_connector_funcs radeon_vga_connector_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001100 .dpms = drm_helper_connector_dpms,
1101 .detect = radeon_vga_detect,
1102 .fill_modes = drm_helper_probe_single_connector_modes,
1103 .destroy = radeon_connector_destroy,
1104 .set_property = radeon_connector_set_property,
1105};
1106
Dave Airlie4ce001a2009-08-13 16:32:14 +10001107static int radeon_tv_get_modes(struct drm_connector *connector)
1108{
1109 struct drm_device *dev = connector->dev;
Alex Deucher923f6842009-09-10 17:53:39 -04001110 struct radeon_device *rdev = dev->dev_private;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001111 struct drm_display_mode *tv_mode;
Alex Deucher923f6842009-09-10 17:53:39 -04001112 struct drm_encoder *encoder;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001113
Alex Deucher923f6842009-09-10 17:53:39 -04001114 encoder = radeon_best_single_encoder(connector);
1115 if (!encoder)
1116 return 0;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001117
Alex Deucher923f6842009-09-10 17:53:39 -04001118 /* 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 */
Dave Airlied50ba252009-09-23 14:44:08 +10001124 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -04001125 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
1126 drm_mode_probed_add(connector, tv_mode);
1127 }
Dave Airlie4ce001a2009-08-13 16:32:14 +10001128 return 1;
1129}
1130
1131static int radeon_tv_mode_valid(struct drm_connector *connector,
1132 struct drm_display_mode *mode)
1133{
Alex Deuchera3fa6322009-11-05 11:57:07 -05001134 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
1135 return MODE_CLOCK_RANGE;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001136 return MODE_OK;
1137}
1138
Chris Wilson7b334fc2010-09-09 23:51:02 +01001139static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +01001140radeon_tv_detect(struct drm_connector *connector, bool force)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001141{
1142 struct drm_encoder *encoder;
Jani Nikula319d1e12015-03-11 11:51:02 +02001143 const struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie445282d2009-09-09 17:40:54 +10001144 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1145 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001146 int r;
Dave Airlie445282d2009-09-09 17:40:54 +10001147
1148 if (!radeon_connector->dac_load_detect)
1149 return ret;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001150
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001151 r = pm_runtime_get_sync(connector->dev->dev);
1152 if (r < 0)
1153 return connector_status_disconnected;
1154
Dave Airlie4ce001a2009-08-13 16:32:14 +10001155 encoder = radeon_best_single_encoder(connector);
1156 if (!encoder)
1157 ret = connector_status_disconnected;
1158 else {
1159 encoder_funcs = encoder->helper_private;
1160 ret = encoder_funcs->detect(encoder, connector);
1161 }
1162 if (ret == connector_status_connected)
1163 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
1164 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001165 pm_runtime_mark_last_busy(connector->dev->dev);
1166 pm_runtime_put_autosuspend(connector->dev->dev);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001167 return ret;
1168}
1169
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001170static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001171 .get_modes = radeon_tv_get_modes,
1172 .mode_valid = radeon_tv_mode_valid,
1173 .best_encoder = radeon_best_single_encoder,
1174};
1175
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001176static const struct drm_connector_funcs radeon_tv_connector_funcs = {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001177 .dpms = drm_helper_connector_dpms,
1178 .detect = radeon_tv_detect,
1179 .fill_modes = drm_helper_probe_single_connector_modes,
1180 .destroy = radeon_connector_destroy,
1181 .set_property = radeon_connector_set_property,
1182};
1183
Tvrtko Ursulin11fe1262012-03-16 12:22:11 -04001184static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector)
1185{
1186 struct drm_device *dev = connector->dev;
1187 struct radeon_device *rdev = dev->dev_private;
1188 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1189 enum drm_connector_status status;
1190
1191 /* We only trust HPD on R600 and newer ASICS. */
1192 if (rdev->family >= CHIP_R600
1193 && radeon_connector->hpd.hpd != RADEON_HPD_NONE) {
1194 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
1195 status = connector_status_connected;
1196 else
1197 status = connector_status_disconnected;
1198 if (connector->status == status)
1199 return true;
1200 }
1201
1202 return false;
1203}
1204
Dave Airlie4ce001a2009-08-13 16:32:14 +10001205/*
1206 * DVI is complicated
1207 * Do a DDC probe, if DDC probe passes, get the full EDID so
1208 * we can do analog/digital monitor detection at this point.
1209 * If the monitor is an analog monitor or we got no DDC,
1210 * we need to find the DAC encoder object for this connector.
1211 * If we got no DDC, we do load detection on the DAC encoder object.
1212 * If we got analog DDC or load detection passes on the DAC encoder
1213 * we have to check if this analog encoder is shared with anyone else (TV)
1214 * if its shared we have to set the other connector to disconnected.
1215 */
Chris Wilson7b334fc2010-09-09 23:51:02 +01001216static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +01001217radeon_dvi_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001218{
Alex Deucherfafcf942011-03-23 08:10:10 +00001219 struct drm_device *dev = connector->dev;
1220 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001221 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001222 struct drm_encoder *encoder = NULL;
Jani Nikula319d1e12015-03-11 11:51:02 +02001223 const struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001224 int i, r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001225 enum drm_connector_status ret = connector_status_disconnected;
Egbert Eichfc87f132012-10-24 18:32:52 +02001226 bool dret = false, broken_edid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001227
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001228 r = pm_runtime_get_sync(connector->dev->dev);
1229 if (r < 0)
1230 return connector_status_disconnected;
1231
1232 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1233 ret = connector->status;
1234 goto exit;
1235 }
Tvrtko Ursulin11fe1262012-03-16 12:22:11 -04001236
Dave Airlieeb6b6d72010-02-25 13:44:04 +10001237 if (radeon_connector->ddc_bus)
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +01001238 dret = radeon_ddc_probe(radeon_connector, false);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001239 if (dret) {
Alex Deucherd0d0a222011-10-07 14:23:48 -04001240 radeon_connector->detected_by_load = false;
Alex Deucher72a5c972014-07-15 10:38:10 -04001241 radeon_connector_free_edid(connector);
1242 radeon_connector_get_edid(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001243
Dave Airlie4ce001a2009-08-13 16:32:14 +10001244 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +01001245 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
Jani Nikula72082092014-06-03 14:56:19 +03001246 connector->name);
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001247 /* rs690 seems to have a problem with connectors not existing and always
1248 * return a block of 0's. If we see this just stop polling on this output */
Alex Deucher72a5c972014-07-15 10:38:10 -04001249 if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) &&
1250 radeon_connector->base.null_edid_counter) {
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001251 ret = connector_status_disconnected;
Jani Nikula72082092014-06-03 14:56:19 +03001252 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n",
1253 connector->name);
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001254 radeon_connector->ddc_bus = NULL;
Egbert Eichfc87f132012-10-24 18:32:52 +02001255 } else {
1256 ret = connector_status_connected;
1257 broken_edid = true; /* defer use_digital to later */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001258 }
Dave Airlie4ce001a2009-08-13 16:32:14 +10001259 } else {
Alex Deucher72a5c972014-07-15 10:38:10 -04001260 radeon_connector->use_digital =
1261 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001262
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001263 /* some oems have boards with separate digital and analog connectors
1264 * with a shared ddc line (often vga + hdmi)
1265 */
1266 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
Alex Deucher72a5c972014-07-15 10:38:10 -04001267 radeon_connector_free_edid(connector);
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001268 ret = connector_status_disconnected;
Alex Deucher72a5c972014-07-15 10:38:10 -04001269 } else {
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001270 ret = connector_status_connected;
Alex Deucher72a5c972014-07-15 10:38:10 -04001271 }
Alex Deucher42f14c42010-07-20 11:27:54 -04001272 /* This gets complicated. We have boards with VGA + HDMI with a
1273 * shared DDC line and we have boards with DVI-D + HDMI with a shared
1274 * DDC line. The latter is more complex because with DVI<->HDMI adapters
1275 * you don't really know what's connected to which port as both are digital.
Alex Deucher71407c42009-11-17 15:44:01 -05001276 */
Alex Deucherd3932d62010-02-19 02:13:56 -05001277 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
Alex Deucher71407c42009-11-17 15:44:01 -05001278 struct drm_connector *list_connector;
1279 struct radeon_connector *list_radeon_connector;
1280 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
1281 if (connector == list_connector)
1282 continue;
1283 list_radeon_connector = to_radeon_connector(list_connector);
Alex Deucherb2ea4aa2010-07-01 10:34:56 -04001284 if (list_radeon_connector->shared_ddc &&
1285 (list_radeon_connector->ddc_bus->rec.i2c_id ==
1286 radeon_connector->ddc_bus->rec.i2c_id)) {
Alex Deucher42f14c42010-07-20 11:27:54 -04001287 /* cases where both connectors are digital */
1288 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
1289 /* hpd is our only option in this case */
1290 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
Alex Deucher72a5c972014-07-15 10:38:10 -04001291 radeon_connector_free_edid(connector);
Alex Deucher71407c42009-11-17 15:44:01 -05001292 ret = connector_status_disconnected;
1293 }
1294 }
1295 }
1296 }
1297 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001298 }
1299 }
1300
Dave Airlie4ce001a2009-08-13 16:32:14 +10001301 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
1302 goto out;
1303
Alex Deucher5f0a2612011-10-07 14:23:47 -04001304 /* DVI-D and HDMI-A are digital only */
1305 if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
1306 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
1307 goto out;
1308
Alex Deucherd0d0a222011-10-07 14:23:48 -04001309 /* if we aren't forcing don't do destructive polling */
Dave Airliec3cceed2010-10-26 12:55:52 +10001310 if (!force) {
Alex Deucherd0d0a222011-10-07 14:23:48 -04001311 /* only return the previous status if we last
1312 * detected a monitor via load.
1313 */
1314 if (radeon_connector->detected_by_load)
1315 ret = connector->status;
Dave Airliec3cceed2010-10-26 12:55:52 +10001316 goto out;
1317 }
1318
Dave Airlie4ce001a2009-08-13 16:32:14 +10001319 /* find analog encoder */
Dave Airlie445282d2009-09-09 17:40:54 +10001320 if (radeon_connector->dac_load_detect) {
1321 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1322 if (connector->encoder_ids[i] == 0)
1323 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001324
Rob Clarkb957f452014-07-17 23:30:05 -04001325 encoder = drm_encoder_find(connector->dev,
1326 connector->encoder_ids[i]);
1327 if (!encoder)
Dave Airlie445282d2009-09-09 17:40:54 +10001328 continue;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001329
Takashi Iwaie3632502012-04-18 15:21:07 +02001330 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
Alex Deuchere00e8b52012-03-16 12:22:09 -04001331 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
1332 continue;
1333
Dave Airlie445282d2009-09-09 17:40:54 +10001334 encoder_funcs = encoder->helper_private;
1335 if (encoder_funcs->detect) {
Egbert Eichfc87f132012-10-24 18:32:52 +02001336 if (!broken_edid) {
1337 if (ret != connector_status_connected) {
1338 /* deal with analog monitors without DDC */
1339 ret = encoder_funcs->detect(encoder, connector);
1340 if (ret == connector_status_connected) {
1341 radeon_connector->use_digital = false;
1342 }
1343 if (ret != connector_status_disconnected)
1344 radeon_connector->detected_by_load = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001345 }
Egbert Eichfc87f132012-10-24 18:32:52 +02001346 } else {
1347 enum drm_connector_status lret;
1348 /* assume digital unless load detected otherwise */
1349 radeon_connector->use_digital = true;
1350 lret = encoder_funcs->detect(encoder, connector);
1351 DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
1352 if (lret == connector_status_connected)
1353 radeon_connector->use_digital = false;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001354 }
Dave Airlie445282d2009-09-09 17:40:54 +10001355 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001356 }
Dave Airlie4ce001a2009-08-13 16:32:14 +10001357 }
1358 }
1359
1360 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
1361 encoder) {
1362 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1363 }
1364
Alex Deucherfafcf942011-03-23 08:10:10 +00001365 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1366 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1367 * by other means, assume the DFP is connected and use that EDID. In most
1368 * cases the DVI port is actually a virtual KVM port connected to the service
1369 * processor.
1370 */
Dave Airliea09d4312012-04-19 15:42:58 +01001371out:
Alex Deucherfafcf942011-03-23 08:10:10 +00001372 if ((!rdev->is_atom_bios) &&
1373 (ret == connector_status_disconnected) &&
1374 rdev->mode_info.bios_hardcoded_edid_size) {
1375 radeon_connector->use_digital = true;
1376 ret = connector_status_connected;
1377 }
1378
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001379 /* updated in get modes as well since we need to know if it's analog or digital */
1380 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001381
Alex Deucher0f55db32015-04-07 09:52:42 -04001382 if (radeon_audio != 0) {
1383 radeon_connector_get_edid(connector);
Slava Grigorev1a626b62014-12-01 13:49:39 -05001384 radeon_audio_detect(connector, ret);
Alex Deucher0f55db32015-04-07 09:52:42 -04001385 }
Slava Grigorev1a626b62014-12-01 13:49:39 -05001386
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001387exit:
1388 pm_runtime_mark_last_busy(connector->dev->dev);
1389 pm_runtime_put_autosuspend(connector->dev->dev);
1390
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001391 return ret;
1392}
1393
1394/* okay need to be smart in here about which encoder to pick */
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001395static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001396{
1397 int enc_id = connector->encoder_ids[0];
1398 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001399 struct drm_encoder *encoder;
1400 int i;
1401 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1402 if (connector->encoder_ids[i] == 0)
1403 break;
1404
Rob Clarkb957f452014-07-17 23:30:05 -04001405 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
1406 if (!encoder)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001407 continue;
1408
Dave Airlie4ce001a2009-08-13 16:32:14 +10001409 if (radeon_connector->use_digital == true) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001410 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
1411 return encoder;
1412 } else {
1413 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
1414 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
1415 return encoder;
1416 }
1417 }
1418
1419 /* see if we have a default encoder TODO */
1420
1421 /* then check use digitial */
1422 /* pick the first one */
Rob Clarkb957f452014-07-17 23:30:05 -04001423 if (enc_id)
1424 return drm_encoder_find(connector->dev, enc_id);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001425 return NULL;
1426}
1427
Dave Airlied50ba252009-09-23 14:44:08 +10001428static void radeon_dvi_force(struct drm_connector *connector)
1429{
1430 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1431 if (connector->force == DRM_FORCE_ON)
1432 radeon_connector->use_digital = false;
1433 if (connector->force == DRM_FORCE_ON_DIGITAL)
1434 radeon_connector->use_digital = true;
1435}
1436
Alex Deuchera3fa6322009-11-05 11:57:07 -05001437static int radeon_dvi_mode_valid(struct drm_connector *connector,
1438 struct drm_display_mode *mode)
1439{
Alex Deucher1b242032010-01-11 15:02:31 -05001440 struct drm_device *dev = connector->dev;
1441 struct radeon_device *rdev = dev->dev_private;
Alex Deuchera3fa6322009-11-05 11:57:07 -05001442 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1443
1444 /* XXX check mode bandwidth */
1445
Alex Deucher1b242032010-01-11 15:02:31 -05001446 /* clocks over 135 MHz have heat issues with DVI on RV100 */
1447 if (radeon_connector->use_digital &&
1448 (rdev->family == CHIP_RV100) &&
1449 (mode->clock > 135000))
1450 return MODE_CLOCK_HIGH;
1451
Alex Deuchera3fa6322009-11-05 11:57:07 -05001452 if (radeon_connector->use_digital && (mode->clock > 165000)) {
1453 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1454 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1455 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1456 return MODE_OK;
Alex Deucher377bd8a2014-07-15 11:00:47 -04001457 else if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Alex Deucherf2263fc2014-06-16 17:46:57 -04001458 /* HDMI 1.3+ supports max clock of 340 Mhz */
1459 if (mode->clock > 340000)
Alex Deuchere1e84012011-03-02 10:21:05 -05001460 return MODE_CLOCK_HIGH;
Alex Deucherf2263fc2014-06-16 17:46:57 -04001461 else
1462 return MODE_OK;
1463 } else {
Alex Deuchera3fa6322009-11-05 11:57:07 -05001464 return MODE_CLOCK_HIGH;
Alex Deucherf2263fc2014-06-16 17:46:57 -04001465 }
Alex Deuchera3fa6322009-11-05 11:57:07 -05001466 }
Alex Deucherb20f9be2011-06-08 13:01:11 -04001467
1468 /* check against the max pixel clock */
1469 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1470 return MODE_CLOCK_HIGH;
1471
Alex Deuchera3fa6322009-11-05 11:57:07 -05001472 return MODE_OK;
1473}
1474
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001475static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
Alex Deucher3e229202014-07-10 13:07:19 -04001476 .get_modes = radeon_vga_get_modes,
Alex Deuchera3fa6322009-11-05 11:57:07 -05001477 .mode_valid = radeon_dvi_mode_valid,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001478 .best_encoder = radeon_dvi_encoder,
1479};
1480
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001481static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001482 .dpms = drm_helper_connector_dpms,
1483 .detect = radeon_dvi_detect,
1484 .fill_modes = drm_helper_probe_single_connector_modes,
1485 .set_property = radeon_connector_set_property,
1486 .destroy = radeon_connector_destroy,
Dave Airlied50ba252009-09-23 14:44:08 +10001487 .force = radeon_dvi_force,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001488};
1489
Dave Airlie746c1aa2009-12-08 07:07:28 +10001490static int radeon_dp_get_modes(struct drm_connector *connector)
1491{
1492 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher8b834852010-11-17 02:54:42 -05001493 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
Alex Deucher591a10e2011-06-13 17:13:34 -04001494 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001495 int ret;
1496
Alex Deucherf89931f2011-06-13 17:13:35 -04001497 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1498 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
Alex Deucherd2917672011-05-20 04:34:31 -04001499 struct drm_display_mode *mode;
1500
Alex Deucher2b69ffb2012-02-28 11:08:22 -05001501 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1502 if (!radeon_dig_connector->edp_on)
1503 atombios_set_edp_panel_power(connector,
1504 ATOM_TRANSMITTER_ACTION_POWER_ON);
Alex Deucher72a5c972014-07-15 10:38:10 -04001505 radeon_connector_get_edid(connector);
1506 ret = radeon_ddc_get_modes(connector);
Alex Deucher2b69ffb2012-02-28 11:08:22 -05001507 if (!radeon_dig_connector->edp_on)
1508 atombios_set_edp_panel_power(connector,
1509 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1510 } else {
1511 /* need to setup ddc on the bridge */
1512 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1513 ENCODER_OBJECT_ID_NONE) {
1514 if (encoder)
1515 radeon_atom_ext_encoder_setup_ddc(encoder);
1516 }
Alex Deucher72a5c972014-07-15 10:38:10 -04001517 radeon_connector_get_edid(connector);
1518 ret = radeon_ddc_get_modes(connector);
Alex Deucher2b69ffb2012-02-28 11:08:22 -05001519 }
Alex Deucherd2917672011-05-20 04:34:31 -04001520
1521 if (ret > 0) {
Alex Deucherd2917672011-05-20 04:34:31 -04001522 if (encoder) {
1523 radeon_fixup_lvds_native_mode(encoder, connector);
1524 /* add scaled modes */
1525 radeon_add_common_modes(encoder, connector);
1526 }
1527 return ret;
1528 }
1529
Alex Deucherd2917672011-05-20 04:34:31 -04001530 if (!encoder)
1531 return 0;
1532
1533 /* we have no EDID modes */
1534 mode = radeon_fp_native_mode(encoder);
1535 if (mode) {
1536 ret = 1;
1537 drm_mode_probed_add(connector, mode);
1538 /* add the width/height from vbios tables if available */
1539 connector->display_info.width_mm = mode->width_mm;
1540 connector->display_info.height_mm = mode->height_mm;
1541 /* add scaled modes */
1542 radeon_add_common_modes(encoder, connector);
1543 }
Alex Deucher591a10e2011-06-13 17:13:34 -04001544 } else {
1545 /* need to setup ddc on the bridge */
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001546 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1547 ENCODER_OBJECT_ID_NONE) {
Alex Deucher591a10e2011-06-13 17:13:34 -04001548 if (encoder)
1549 radeon_atom_ext_encoder_setup_ddc(encoder);
1550 }
Alex Deucher72a5c972014-07-15 10:38:10 -04001551 radeon_connector_get_edid(connector);
1552 ret = radeon_ddc_get_modes(connector);
Alex Deucherda997622014-07-09 13:21:59 -04001553
1554 radeon_get_native_mode(connector);
Alex Deucher591a10e2011-06-13 17:13:34 -04001555 }
Alex Deucher8b834852010-11-17 02:54:42 -05001556
Dave Airlie746c1aa2009-12-08 07:07:28 +10001557 return ret;
1558}
1559
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001560u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001561{
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001562 struct drm_encoder *encoder;
1563 struct radeon_encoder *radeon_encoder;
1564 int i;
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001565
1566 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1567 if (connector->encoder_ids[i] == 0)
1568 break;
1569
Rob Clarkb957f452014-07-17 23:30:05 -04001570 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
1571 if (!encoder)
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001572 continue;
1573
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001574 radeon_encoder = to_radeon_encoder(encoder);
1575
1576 switch (radeon_encoder->encoder_id) {
1577 case ENCODER_OBJECT_ID_TRAVIS:
1578 case ENCODER_OBJECT_ID_NUTMEG:
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001579 return radeon_encoder->encoder_id;
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001580 default:
1581 break;
1582 }
1583 }
1584
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001585 return ENCODER_OBJECT_ID_NONE;
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001586}
1587
Alex Deucherebdea822014-07-24 16:06:57 -04001588static bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001589{
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001590 struct drm_encoder *encoder;
1591 struct radeon_encoder *radeon_encoder;
1592 int i;
1593 bool found = false;
1594
1595 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1596 if (connector->encoder_ids[i] == 0)
1597 break;
1598
Rob Clarkb957f452014-07-17 23:30:05 -04001599 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
1600 if (!encoder)
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001601 continue;
1602
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001603 radeon_encoder = to_radeon_encoder(encoder);
1604 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1605 found = true;
1606 }
1607
1608 return found;
1609}
1610
1611bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1612{
1613 struct drm_device *dev = connector->dev;
1614 struct radeon_device *rdev = dev->dev_private;
1615
1616 if (ASIC_IS_DCE5(rdev) &&
Alex Deucheraf5d3652014-05-27 13:11:36 -04001617 (rdev->clock.default_dispclk >= 53900) &&
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001618 radeon_connector_encoder_is_hbr2(connector)) {
1619 return true;
1620 }
1621
1622 return false;
1623}
1624
Chris Wilson7b334fc2010-09-09 23:51:02 +01001625static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +01001626radeon_dp_detect(struct drm_connector *connector, bool force)
Dave Airlie746c1aa2009-12-08 07:07:28 +10001627{
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001628 struct drm_device *dev = connector->dev;
1629 struct radeon_device *rdev = dev->dev_private;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001630 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001631 enum drm_connector_status ret = connector_status_disconnected;
Alex Deucher4143e912009-11-23 18:02:35 -05001632 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
Alex Deucher591a10e2011-06-13 17:13:34 -04001633 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001634 int r;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001635
Dave Airlie9843ead2015-02-24 09:24:04 +10001636 if (radeon_dig_connector->is_mst)
1637 return connector_status_disconnected;
1638
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001639 r = pm_runtime_get_sync(connector->dev->dev);
1640 if (r < 0)
1641 return connector_status_disconnected;
1642
1643 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1644 ret = connector->status;
1645 goto out;
1646 }
Tvrtko Ursulin11fe1262012-03-16 12:22:11 -04001647
Alex Deucher72a5c972014-07-15 10:38:10 -04001648 radeon_connector_free_edid(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001649
Alex Deucherf89931f2011-06-13 17:13:35 -04001650 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1651 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
Alex Deucherd2917672011-05-20 04:34:31 -04001652 if (encoder) {
1653 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1654 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1655
1656 /* check if panel is valid */
1657 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1658 ret = connector_status_connected;
Alex Deucher13485792014-11-14 12:08:34 -05001659 /* don't fetch the edid from the vbios if ddc fails and runpm is
1660 * enabled so we report disconnected.
1661 */
1662 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
1663 ret = connector_status_disconnected;
Alex Deucherd2917672011-05-20 04:34:31 -04001664 }
Alex Deucher6f50eae2010-08-19 17:29:03 -04001665 /* eDP is always DP */
1666 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
Alex Deucher8b834852010-11-17 02:54:42 -05001667 if (!radeon_dig_connector->edp_on)
1668 atombios_set_edp_panel_power(connector,
1669 ATOM_TRANSMITTER_ACTION_POWER_ON);
Alex Deucher6f50eae2010-08-19 17:29:03 -04001670 if (radeon_dp_getdpcd(radeon_connector))
Alex Deucher9fa05c92009-11-27 13:01:46 -05001671 ret = connector_status_connected;
Alex Deucher8b834852010-11-17 02:54:42 -05001672 if (!radeon_dig_connector->edp_on)
1673 atombios_set_edp_panel_power(connector,
1674 ATOM_TRANSMITTER_ACTION_POWER_OFF);
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001675 } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1676 ENCODER_OBJECT_ID_NONE) {
Alex Deucherb06947b2011-09-02 14:23:09 +00001677 /* DP bridges are always DP */
1678 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1679 /* get the DPCD from the bridge */
1680 radeon_dp_getdpcd(radeon_connector);
1681
Alex Deucher6777a4f2011-10-04 12:23:24 -04001682 if (encoder) {
1683 /* setup ddc on the bridge */
1684 radeon_atom_ext_encoder_setup_ddc(encoder);
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +01001685 /* bridge chips are always aux */
1686 if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */
Alex Deucherb06947b2011-09-02 14:23:09 +00001687 ret = connector_status_connected;
Alex Deucher6777a4f2011-10-04 12:23:24 -04001688 else if (radeon_connector->dac_load_detect) { /* try load detection */
Jani Nikula319d1e12015-03-11 11:51:02 +02001689 const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
Alex Deucherb06947b2011-09-02 14:23:09 +00001690 ret = encoder_funcs->detect(encoder, connector);
1691 }
1692 }
1693 } else {
Alex Deucher6f50eae2010-08-19 17:29:03 -04001694 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001695 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1696 ret = connector_status_connected;
Dave Airlie9843ead2015-02-24 09:24:04 +10001697 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001698 radeon_dp_getdpcd(radeon_connector);
Dave Airlie9843ead2015-02-24 09:24:04 +10001699 r = radeon_dp_mst_probe(radeon_connector);
1700 if (r == 1)
1701 ret = connector_status_disconnected;
1702 }
Alex Deucher6f50eae2010-08-19 17:29:03 -04001703 } else {
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001704 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
Dave Airlie9843ead2015-02-24 09:24:04 +10001705 if (radeon_dp_getdpcd(radeon_connector)) {
1706 r = radeon_dp_mst_probe(radeon_connector);
1707 if (r == 1)
1708 ret = connector_status_disconnected;
1709 else
1710 ret = connector_status_connected;
1711 }
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001712 } else {
Damien Lespiaud592fca2013-09-13 16:37:28 +01001713 /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +01001714 if (radeon_ddc_probe(radeon_connector, false))
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001715 ret = connector_status_connected;
1716 }
Alex Deucher4143e912009-11-23 18:02:35 -05001717 }
Dave Airlie746c1aa2009-12-08 07:07:28 +10001718 }
Alex Deucher4143e912009-11-23 18:02:35 -05001719
Alex Deucher30f44372010-08-21 11:09:14 -04001720 radeon_connector_update_scratch_regs(connector, ret);
Slava Grigorev1a626b62014-12-01 13:49:39 -05001721
Alex Deucher0f55db32015-04-07 09:52:42 -04001722 if (radeon_audio != 0) {
1723 radeon_connector_get_edid(connector);
Slava Grigorev1a626b62014-12-01 13:49:39 -05001724 radeon_audio_detect(connector, ret);
Alex Deucher0f55db32015-04-07 09:52:42 -04001725 }
Slava Grigorev1a626b62014-12-01 13:49:39 -05001726
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001727out:
1728 pm_runtime_mark_last_busy(connector->dev->dev);
1729 pm_runtime_put_autosuspend(connector->dev->dev);
1730
Dave Airlie746c1aa2009-12-08 07:07:28 +10001731 return ret;
1732}
1733
Alex Deucher5801ead2009-11-24 13:32:59 -05001734static int radeon_dp_mode_valid(struct drm_connector *connector,
1735 struct drm_display_mode *mode)
1736{
Alex Deucher6536a3a2014-06-16 17:42:34 -04001737 struct drm_device *dev = connector->dev;
1738 struct radeon_device *rdev = dev->dev_private;
Alex Deucher5801ead2009-11-24 13:32:59 -05001739 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1740 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1741
1742 /* XXX check mode bandwidth */
1743
Alex Deucherf89931f2011-06-13 17:13:35 -04001744 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1745 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
Alex Deucherd2917672011-05-20 04:34:31 -04001746 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1747
1748 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1749 return MODE_PANEL;
1750
1751 if (encoder) {
1752 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1753 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1754
Alex Deucherf89931f2011-06-13 17:13:35 -04001755 /* AVIVO hardware supports downscaling modes larger than the panel
Alex Deucherd2917672011-05-20 04:34:31 -04001756 * to the panel size, but I'm not sure this is desirable.
1757 */
1758 if ((mode->hdisplay > native_mode->hdisplay) ||
1759 (mode->vdisplay > native_mode->vdisplay))
1760 return MODE_PANEL;
1761
1762 /* if scaling is disabled, block non-native modes */
1763 if (radeon_encoder->rmx_type == RMX_OFF) {
1764 if ((mode->hdisplay != native_mode->hdisplay) ||
1765 (mode->vdisplay != native_mode->vdisplay))
1766 return MODE_PANEL;
1767 }
1768 }
Alex Deucherd2917672011-05-20 04:34:31 -04001769 } else {
1770 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
Alex Deucher6536a3a2014-06-16 17:42:34 -04001771 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
Alex Deucherd2917672011-05-20 04:34:31 -04001772 return radeon_dp_mode_valid_helper(connector, mode);
Alex Deucher6536a3a2014-06-16 17:42:34 -04001773 } else {
Alex Deucher377bd8a2014-07-15 11:00:47 -04001774 if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Alex Deucher6536a3a2014-06-16 17:42:34 -04001775 /* HDMI 1.3+ supports max clock of 340 Mhz */
1776 if (mode->clock > 340000)
1777 return MODE_CLOCK_HIGH;
1778 } else {
1779 if (mode->clock > 165000)
1780 return MODE_CLOCK_HIGH;
1781 }
1782 }
Alex Deucherd2917672011-05-20 04:34:31 -04001783 }
Alex Deucher6536a3a2014-06-16 17:42:34 -04001784
1785 return MODE_OK;
Alex Deucher5801ead2009-11-24 13:32:59 -05001786}
1787
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001788static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
Dave Airlie746c1aa2009-12-08 07:07:28 +10001789 .get_modes = radeon_dp_get_modes,
Alex Deucher5801ead2009-11-24 13:32:59 -05001790 .mode_valid = radeon_dp_mode_valid,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001791 .best_encoder = radeon_dvi_encoder,
1792};
1793
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001794static const struct drm_connector_funcs radeon_dp_connector_funcs = {
Dave Airlie746c1aa2009-12-08 07:07:28 +10001795 .dpms = drm_helper_connector_dpms,
1796 .detect = radeon_dp_detect,
1797 .fill_modes = drm_helper_probe_single_connector_modes,
1798 .set_property = radeon_connector_set_property,
Alex Deucher379dfc22014-04-07 10:33:46 -04001799 .destroy = radeon_connector_destroy,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001800 .force = radeon_dvi_force,
1801};
1802
Alex Deucher855f5f12013-09-13 18:33:16 -04001803static const struct drm_connector_funcs radeon_edp_connector_funcs = {
1804 .dpms = drm_helper_connector_dpms,
1805 .detect = radeon_dp_detect,
1806 .fill_modes = drm_helper_probe_single_connector_modes,
1807 .set_property = radeon_lvds_set_property,
Alex Deucher379dfc22014-04-07 10:33:46 -04001808 .destroy = radeon_connector_destroy,
Alex Deucher855f5f12013-09-13 18:33:16 -04001809 .force = radeon_dvi_force,
1810};
1811
1812static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
1813 .dpms = drm_helper_connector_dpms,
1814 .detect = radeon_dp_detect,
1815 .fill_modes = drm_helper_probe_single_connector_modes,
1816 .set_property = radeon_lvds_set_property,
Alex Deucher379dfc22014-04-07 10:33:46 -04001817 .destroy = radeon_connector_destroy,
Alex Deucher855f5f12013-09-13 18:33:16 -04001818 .force = radeon_dvi_force,
1819};
1820
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001821void
1822radeon_add_atom_connector(struct drm_device *dev,
1823 uint32_t connector_id,
1824 uint32_t supported_device,
1825 int connector_type,
1826 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -05001827 uint32_t igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -05001828 uint16_t connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -04001829 struct radeon_hpd *hpd,
1830 struct radeon_router *router)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001831{
Dave Airlie445282d2009-09-09 17:40:54 +10001832 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001833 struct drm_connector *connector;
1834 struct radeon_connector *radeon_connector;
1835 struct radeon_connector_atom_dig *radeon_dig_connector;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001836 struct drm_encoder *encoder;
1837 struct radeon_encoder *radeon_encoder;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001838 uint32_t subpixel_order = SubPixelNone;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001839 bool shared_ddc = false;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001840 bool is_dp_bridge = false;
Alex Deucher496263b2014-03-21 10:34:07 -04001841 bool has_aux = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001842
Dave Airlie4ce001a2009-08-13 16:32:14 +10001843 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001844 return;
1845
Alex Deuchercf4c12f2010-09-01 17:15:06 -04001846 /* if the user selected tv=0 don't try and add the connector */
1847 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1848 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1849 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1850 (radeon_tv == 0))
1851 return;
1852
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001853 /* see if we already added it */
1854 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1855 radeon_connector = to_radeon_connector(connector);
1856 if (radeon_connector->connector_id == connector_id) {
1857 radeon_connector->devices |= supported_device;
1858 return;
1859 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001860 if (radeon_connector->ddc_bus && i2c_bus->valid) {
Alex Deucherd3932d62010-02-19 02:13:56 -05001861 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001862 radeon_connector->shared_ddc = true;
1863 shared_ddc = true;
1864 }
Alex Deucherfb939df2010-11-08 16:08:29 +00001865 if (radeon_connector->router_bus && router->ddc_valid &&
Alex Deucher26b5bc92010-08-05 21:21:18 -04001866 (radeon_connector->router.router_id == router->router_id)) {
1867 radeon_connector->shared_ddc = false;
1868 shared_ddc = false;
1869 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001870 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001871 }
1872
Alex Deuchereac4dff2011-05-20 04:34:22 -04001873 /* check if it's a dp bridge */
1874 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1875 radeon_encoder = to_radeon_encoder(encoder);
1876 if (radeon_encoder->devices & supported_device) {
1877 switch (radeon_encoder->encoder_id) {
1878 case ENCODER_OBJECT_ID_TRAVIS:
1879 case ENCODER_OBJECT_ID_NUTMEG:
1880 is_dp_bridge = true;
1881 break;
1882 default:
1883 break;
1884 }
1885 }
1886 }
1887
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001888 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1889 if (!radeon_connector)
1890 return;
1891
1892 connector = &radeon_connector->base;
1893
1894 radeon_connector->connector_id = connector_id;
1895 radeon_connector->devices = supported_device;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001896 radeon_connector->shared_ddc = shared_ddc;
Alex Deucherb75fad02009-11-05 13:16:01 -05001897 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05001898 radeon_connector->hpd = *hpd;
Alex Deucherbc1c4dc2011-10-30 16:54:27 -04001899
Alex Deucher26b5bc92010-08-05 21:21:18 -04001900 radeon_connector->router = *router;
Alex Deucherfb939df2010-11-08 16:08:29 +00001901 if (router->ddc_valid || router->cd_valid) {
Alex Deucher26b5bc92010-08-05 21:21:18 -04001902 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1903 if (!radeon_connector->router_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04001904 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
Alex Deucher26b5bc92010-08-05 21:21:18 -04001905 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001906
1907 if (is_dp_bridge) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001908 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1909 if (!radeon_dig_connector)
1910 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001911 radeon_dig_connector->igp_lane_info = igp_lane_info;
1912 radeon_connector->con_priv = radeon_dig_connector;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001913 if (i2c_bus->valid) {
Alex Deucher379dfc22014-04-07 10:33:46 -04001914 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1915 if (radeon_connector->ddc_bus)
Alex Deucher496263b2014-03-21 10:34:07 -04001916 has_aux = true;
1917 else
Alex Deuchereac4dff2011-05-20 04:34:22 -04001918 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001919 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001920 switch (connector_type) {
1921 case DRM_MODE_CONNECTOR_VGA:
1922 case DRM_MODE_CONNECTOR_DVIA:
1923 default:
Alex Deucher855f5f12013-09-13 18:33:16 -04001924 drm_connector_init(dev, &radeon_connector->base,
1925 &radeon_dp_connector_funcs, connector_type);
1926 drm_connector_helper_add(&radeon_connector->base,
1927 &radeon_dp_connector_helper_funcs);
Alex Deuchereac4dff2011-05-20 04:34:22 -04001928 connector->interlace_allowed = true;
1929 connector->doublescan_allowed = true;
Alex Deucherd629a3c2011-06-13 17:13:33 -04001930 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05001931 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucherd629a3c2011-06-13 17:13:33 -04001932 rdev->mode_info.load_detect_property,
1933 1);
Alex Deucherda997622014-07-09 13:21:59 -04001934 drm_object_attach_property(&radeon_connector->base.base,
1935 dev->mode_config.scaling_mode_property,
1936 DRM_MODE_SCALE_NONE);
Alex Deucher643b1f52015-02-23 10:59:36 -05001937 if (ASIC_IS_DCE5(rdev))
1938 drm_object_attach_property(&radeon_connector->base.base,
1939 rdev->mode_info.output_csc_property,
1940 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04001941 break;
1942 case DRM_MODE_CONNECTOR_DVII:
1943 case DRM_MODE_CONNECTOR_DVID:
1944 case DRM_MODE_CONNECTOR_HDMIA:
1945 case DRM_MODE_CONNECTOR_HDMIB:
1946 case DRM_MODE_CONNECTOR_DisplayPort:
Alex Deucher855f5f12013-09-13 18:33:16 -04001947 drm_connector_init(dev, &radeon_connector->base,
1948 &radeon_dp_connector_funcs, connector_type);
1949 drm_connector_helper_add(&radeon_connector->base,
1950 &radeon_dp_connector_helper_funcs);
Rob Clarke35755f2012-10-11 20:44:52 -05001951 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher430f70d2010-08-04 03:45:04 -04001952 rdev->mode_info.underscan_property,
Alex Deucher56bec7c2011-01-05 11:57:52 -05001953 UNDERSCAN_OFF);
Rob Clarke35755f2012-10-11 20:44:52 -05001954 drm_object_attach_property(&radeon_connector->base.base,
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001955 rdev->mode_info.underscan_hborder_property,
1956 0);
Rob Clarke35755f2012-10-11 20:44:52 -05001957 drm_object_attach_property(&radeon_connector->base.base,
Marius Gröger5bccf5e2010-09-21 21:30:59 +02001958 rdev->mode_info.underscan_vborder_property,
1959 0);
Dave Airlie91915262013-11-08 16:34:39 +10001960
Alex Deucher6214bb72013-09-24 17:26:26 -04001961 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucherda997622014-07-09 13:21:59 -04001962 dev->mode_config.scaling_mode_property,
1963 DRM_MODE_SCALE_NONE);
1964
1965 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher6214bb72013-09-24 17:26:26 -04001966 rdev->mode_info.dither_property,
1967 RADEON_FMT_DITHER_DISABLE);
Dave Airlie91915262013-11-08 16:34:39 +10001968
Alex Deucher108dc8e2013-10-14 13:17:50 -04001969 if (radeon_audio != 0)
1970 drm_object_attach_property(&radeon_connector->base.base,
1971 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05001972 RADEON_AUDIO_AUTO);
Alex Deucher643b1f52015-02-23 10:59:36 -05001973 if (ASIC_IS_DCE5(rdev))
1974 drm_object_attach_property(&radeon_connector->base.base,
1975 rdev->mode_info.output_csc_property,
1976 RADEON_OUTPUT_CSC_BYPASS);
Dave Airlie91915262013-11-08 16:34:39 +10001977
Alex Deuchereac4dff2011-05-20 04:34:22 -04001978 subpixel_order = SubPixelHorizontalRGB;
1979 connector->interlace_allowed = true;
1980 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1981 connector->doublescan_allowed = true;
1982 else
1983 connector->doublescan_allowed = false;
Alex Deucherd629a3c2011-06-13 17:13:33 -04001984 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1985 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05001986 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucherd629a3c2011-06-13 17:13:33 -04001987 rdev->mode_info.load_detect_property,
1988 1);
1989 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001990 break;
1991 case DRM_MODE_CONNECTOR_LVDS:
1992 case DRM_MODE_CONNECTOR_eDP:
Alex Deucher855f5f12013-09-13 18:33:16 -04001993 drm_connector_init(dev, &radeon_connector->base,
1994 &radeon_lvds_bridge_connector_funcs, connector_type);
1995 drm_connector_helper_add(&radeon_connector->base,
1996 &radeon_dp_connector_helper_funcs);
Rob Clarke35755f2012-10-11 20:44:52 -05001997 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04001998 dev->mode_config.scaling_mode_property,
1999 DRM_MODE_SCALE_FULLSCREEN);
2000 subpixel_order = SubPixelHorizontalRGB;
2001 connector->interlace_allowed = false;
2002 connector->doublescan_allowed = false;
2003 break;
Marius Gröger5bccf5e2010-09-21 21:30:59 +02002004 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04002005 } else {
2006 switch (connector_type) {
2007 case DRM_MODE_CONNECTOR_VGA:
2008 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2009 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2010 if (i2c_bus->valid) {
2011 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2012 if (!radeon_connector->ddc_bus)
2013 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2014 }
Alex Deucher390d0bb2009-12-08 12:48:20 -05002015 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002016 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher390d0bb2009-12-08 12:48:20 -05002017 rdev->mode_info.load_detect_property,
2018 1);
Alex Deucherda997622014-07-09 13:21:59 -04002019 if (ASIC_IS_AVIVO(rdev))
2020 drm_object_attach_property(&radeon_connector->base.base,
2021 dev->mode_config.scaling_mode_property,
2022 DRM_MODE_SCALE_NONE);
Alex Deucher643b1f52015-02-23 10:59:36 -05002023 if (ASIC_IS_DCE5(rdev))
2024 drm_object_attach_property(&radeon_connector->base.base,
2025 rdev->mode_info.output_csc_property,
2026 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002027 /* no HPD on analog connectors */
2028 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2029 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2030 connector->interlace_allowed = true;
Alex Deucherc49948f2010-11-30 15:46:47 -05002031 connector->doublescan_allowed = true;
Alex Deuchereac4dff2011-05-20 04:34:22 -04002032 break;
2033 case DRM_MODE_CONNECTOR_DVIA:
2034 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2035 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2036 if (i2c_bus->valid) {
2037 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2038 if (!radeon_connector->ddc_bus)
2039 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2040 }
2041 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002042 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002043 rdev->mode_info.load_detect_property,
2044 1);
Alex Deucherda997622014-07-09 13:21:59 -04002045 if (ASIC_IS_AVIVO(rdev))
2046 drm_object_attach_property(&radeon_connector->base.base,
2047 dev->mode_config.scaling_mode_property,
2048 DRM_MODE_SCALE_NONE);
Alex Deucher643b1f52015-02-23 10:59:36 -05002049 if (ASIC_IS_DCE5(rdev))
2050 drm_object_attach_property(&radeon_connector->base.base,
2051 rdev->mode_info.output_csc_property,
2052 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002053 /* no HPD on analog connectors */
2054 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2055 connector->interlace_allowed = true;
Alex Deucherc49948f2010-11-30 15:46:47 -05002056 connector->doublescan_allowed = true;
Alex Deuchereac4dff2011-05-20 04:34:22 -04002057 break;
2058 case DRM_MODE_CONNECTOR_DVII:
2059 case DRM_MODE_CONNECTOR_DVID:
2060 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2061 if (!radeon_dig_connector)
2062 goto failed;
2063 radeon_dig_connector->igp_lane_info = igp_lane_info;
2064 radeon_connector->con_priv = radeon_dig_connector;
2065 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
2066 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2067 if (i2c_bus->valid) {
2068 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2069 if (!radeon_connector->ddc_bus)
2070 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2071 }
2072 subpixel_order = SubPixelHorizontalRGB;
Rob Clarke35755f2012-10-11 20:44:52 -05002073 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002074 rdev->mode_info.coherent_mode_property,
2075 1);
2076 if (ASIC_IS_AVIVO(rdev)) {
Rob Clarke35755f2012-10-11 20:44:52 -05002077 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002078 rdev->mode_info.underscan_property,
2079 UNDERSCAN_OFF);
Rob Clarke35755f2012-10-11 20:44:52 -05002080 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002081 rdev->mode_info.underscan_hborder_property,
2082 0);
Rob Clarke35755f2012-10-11 20:44:52 -05002083 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002084 rdev->mode_info.underscan_vborder_property,
2085 0);
Alex Deucherda997622014-07-09 13:21:59 -04002086 drm_object_attach_property(&radeon_connector->base.base,
2087 rdev->mode_info.dither_property,
2088 RADEON_FMT_DITHER_DISABLE);
2089 drm_object_attach_property(&radeon_connector->base.base,
2090 dev->mode_config.scaling_mode_property,
2091 DRM_MODE_SCALE_NONE);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002092 }
Alex Deucher108dc8e2013-10-14 13:17:50 -04002093 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
Alex Deucher8666c072013-09-03 14:58:44 -04002094 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher108dc8e2013-10-14 13:17:50 -04002095 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05002096 RADEON_AUDIO_AUTO);
Alex Deucher8666c072013-09-03 14:58:44 -04002097 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04002098 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2099 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002100 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002101 rdev->mode_info.load_detect_property,
2102 1);
2103 }
Alex Deucher643b1f52015-02-23 10:59:36 -05002104 if (ASIC_IS_DCE5(rdev))
2105 drm_object_attach_property(&radeon_connector->base.base,
2106 rdev->mode_info.output_csc_property,
2107 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002108 connector->interlace_allowed = true;
2109 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2110 connector->doublescan_allowed = true;
2111 else
2112 connector->doublescan_allowed = false;
2113 break;
2114 case DRM_MODE_CONNECTOR_HDMIA:
2115 case DRM_MODE_CONNECTOR_HDMIB:
2116 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2117 if (!radeon_dig_connector)
2118 goto failed;
2119 radeon_dig_connector->igp_lane_info = igp_lane_info;
2120 radeon_connector->con_priv = radeon_dig_connector;
2121 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
2122 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2123 if (i2c_bus->valid) {
2124 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2125 if (!radeon_connector->ddc_bus)
2126 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2127 }
Rob Clarke35755f2012-10-11 20:44:52 -05002128 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002129 rdev->mode_info.coherent_mode_property,
2130 1);
2131 if (ASIC_IS_AVIVO(rdev)) {
Rob Clarke35755f2012-10-11 20:44:52 -05002132 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002133 rdev->mode_info.underscan_property,
2134 UNDERSCAN_OFF);
Rob Clarke35755f2012-10-11 20:44:52 -05002135 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002136 rdev->mode_info.underscan_hborder_property,
2137 0);
Rob Clarke35755f2012-10-11 20:44:52 -05002138 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002139 rdev->mode_info.underscan_vborder_property,
2140 0);
Alex Deucherda997622014-07-09 13:21:59 -04002141 drm_object_attach_property(&radeon_connector->base.base,
2142 rdev->mode_info.dither_property,
2143 RADEON_FMT_DITHER_DISABLE);
2144 drm_object_attach_property(&radeon_connector->base.base,
2145 dev->mode_config.scaling_mode_property,
2146 DRM_MODE_SCALE_NONE);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002147 }
Alex Deucher108dc8e2013-10-14 13:17:50 -04002148 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
Alex Deucher8666c072013-09-03 14:58:44 -04002149 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher108dc8e2013-10-14 13:17:50 -04002150 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05002151 RADEON_AUDIO_AUTO);
Alex Deucher8666c072013-09-03 14:58:44 -04002152 }
Alex Deucher643b1f52015-02-23 10:59:36 -05002153 if (ASIC_IS_DCE5(rdev))
2154 drm_object_attach_property(&radeon_connector->base.base,
2155 rdev->mode_info.output_csc_property,
2156 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002157 subpixel_order = SubPixelHorizontalRGB;
2158 connector->interlace_allowed = true;
2159 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
2160 connector->doublescan_allowed = true;
2161 else
2162 connector->doublescan_allowed = false;
2163 break;
2164 case DRM_MODE_CONNECTOR_DisplayPort:
2165 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2166 if (!radeon_dig_connector)
2167 goto failed;
2168 radeon_dig_connector->igp_lane_info = igp_lane_info;
2169 radeon_connector->con_priv = radeon_dig_connector;
2170 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
2171 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2172 if (i2c_bus->valid) {
Alex Deuchereac4dff2011-05-20 04:34:22 -04002173 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Alex Deucher496263b2014-03-21 10:34:07 -04002174 if (radeon_connector->ddc_bus)
2175 has_aux = true;
2176 else
Alex Deuchereac4dff2011-05-20 04:34:22 -04002177 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2178 }
2179 subpixel_order = SubPixelHorizontalRGB;
Rob Clarke35755f2012-10-11 20:44:52 -05002180 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002181 rdev->mode_info.coherent_mode_property,
2182 1);
2183 if (ASIC_IS_AVIVO(rdev)) {
Rob Clarke35755f2012-10-11 20:44:52 -05002184 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002185 rdev->mode_info.underscan_property,
2186 UNDERSCAN_OFF);
Rob Clarke35755f2012-10-11 20:44:52 -05002187 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002188 rdev->mode_info.underscan_hborder_property,
2189 0);
Rob Clarke35755f2012-10-11 20:44:52 -05002190 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002191 rdev->mode_info.underscan_vborder_property,
2192 0);
Alex Deucherda997622014-07-09 13:21:59 -04002193 drm_object_attach_property(&radeon_connector->base.base,
2194 rdev->mode_info.dither_property,
2195 RADEON_FMT_DITHER_DISABLE);
2196 drm_object_attach_property(&radeon_connector->base.base,
2197 dev->mode_config.scaling_mode_property,
2198 DRM_MODE_SCALE_NONE);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002199 }
Alex Deucher108dc8e2013-10-14 13:17:50 -04002200 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
Alex Deucher8666c072013-09-03 14:58:44 -04002201 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher108dc8e2013-10-14 13:17:50 -04002202 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05002203 RADEON_AUDIO_AUTO);
Alex Deucher8666c072013-09-03 14:58:44 -04002204 }
Alex Deucher643b1f52015-02-23 10:59:36 -05002205 if (ASIC_IS_DCE5(rdev))
2206 drm_object_attach_property(&radeon_connector->base.base,
2207 rdev->mode_info.output_csc_property,
2208 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002209 connector->interlace_allowed = true;
2210 /* in theory with a DP to VGA converter... */
Alex Deucherc49948f2010-11-30 15:46:47 -05002211 connector->doublescan_allowed = false;
Alex Deuchereac4dff2011-05-20 04:34:22 -04002212 break;
2213 case DRM_MODE_CONNECTOR_eDP:
2214 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2215 if (!radeon_dig_connector)
2216 goto failed;
2217 radeon_dig_connector->igp_lane_info = igp_lane_info;
2218 radeon_connector->con_priv = radeon_dig_connector;
Alex Deucher855f5f12013-09-13 18:33:16 -04002219 drm_connector_init(dev, &radeon_connector->base, &radeon_edp_connector_funcs, connector_type);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002220 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2221 if (i2c_bus->valid) {
Alex Deucher379dfc22014-04-07 10:33:46 -04002222 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2223 if (radeon_connector->ddc_bus)
Alex Deucher496263b2014-03-21 10:34:07 -04002224 has_aux = true;
2225 else
Alex Deuchereac4dff2011-05-20 04:34:22 -04002226 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2227 }
Rob Clarke35755f2012-10-11 20:44:52 -05002228 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002229 dev->mode_config.scaling_mode_property,
2230 DRM_MODE_SCALE_FULLSCREEN);
2231 subpixel_order = SubPixelHorizontalRGB;
2232 connector->interlace_allowed = false;
2233 connector->doublescan_allowed = false;
2234 break;
2235 case DRM_MODE_CONNECTOR_SVIDEO:
2236 case DRM_MODE_CONNECTOR_Composite:
2237 case DRM_MODE_CONNECTOR_9PinDIN:
2238 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
2239 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2240 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002241 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002242 rdev->mode_info.load_detect_property,
2243 1);
Rob Clarke35755f2012-10-11 20:44:52 -05002244 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002245 rdev->mode_info.tv_std_property,
2246 radeon_atombios_get_tv_info(rdev));
2247 /* no HPD on analog connectors */
2248 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2249 connector->interlace_allowed = false;
2250 connector->doublescan_allowed = false;
2251 break;
2252 case DRM_MODE_CONNECTOR_LVDS:
2253 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2254 if (!radeon_dig_connector)
2255 goto failed;
2256 radeon_dig_connector->igp_lane_info = igp_lane_info;
2257 radeon_connector->con_priv = radeon_dig_connector;
2258 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
2259 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2260 if (i2c_bus->valid) {
2261 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2262 if (!radeon_connector->ddc_bus)
2263 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2264 }
Rob Clarke35755f2012-10-11 20:44:52 -05002265 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002266 dev->mode_config.scaling_mode_property,
2267 DRM_MODE_SCALE_FULLSCREEN);
2268 subpixel_order = SubPixelHorizontalRGB;
2269 connector->interlace_allowed = false;
2270 connector->doublescan_allowed = false;
2271 break;
Marius Gröger5bccf5e2010-09-21 21:30:59 +02002272 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002273 }
2274
Alex Deucher2581afc2010-07-20 03:24:11 -04002275 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002276 if (i2c_bus->valid)
2277 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2278 } else
2279 connector->polled = DRM_CONNECTOR_POLL_HPD;
2280
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002281 connector->display_info.subpixel_order = subpixel_order;
Thomas Wood34ea3d32014-05-29 16:57:41 +01002282 drm_connector_register(connector);
Alex Deucher496263b2014-03-21 10:34:07 -04002283
2284 if (has_aux)
2285 radeon_dp_aux_init(radeon_connector);
2286
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002287 return;
2288
2289failed:
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002290 drm_connector_cleanup(connector);
2291 kfree(connector);
2292}
2293
2294void
2295radeon_add_legacy_connector(struct drm_device *dev,
2296 uint32_t connector_id,
2297 uint32_t supported_device,
2298 int connector_type,
Alex Deucherb75fad02009-11-05 13:16:01 -05002299 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -05002300 uint16_t connector_object_id,
2301 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002302{
Dave Airlie445282d2009-09-09 17:40:54 +10002303 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002304 struct drm_connector *connector;
2305 struct radeon_connector *radeon_connector;
2306 uint32_t subpixel_order = SubPixelNone;
2307
Dave Airlie4ce001a2009-08-13 16:32:14 +10002308 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002309 return;
2310
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002311 /* if the user selected tv=0 don't try and add the connector */
2312 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
2313 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
2314 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
2315 (radeon_tv == 0))
2316 return;
2317
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002318 /* see if we already added it */
2319 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2320 radeon_connector = to_radeon_connector(connector);
2321 if (radeon_connector->connector_id == connector_id) {
2322 radeon_connector->devices |= supported_device;
2323 return;
2324 }
2325 }
2326
2327 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
2328 if (!radeon_connector)
2329 return;
2330
2331 connector = &radeon_connector->base;
2332
2333 radeon_connector->connector_id = connector_id;
2334 radeon_connector->devices = supported_device;
Alex Deucherb75fad02009-11-05 13:16:01 -05002335 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05002336 radeon_connector->hpd = *hpd;
Alex Deucherbc1c4dc2011-10-30 16:54:27 -04002337
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002338 switch (connector_type) {
2339 case DRM_MODE_CONNECTOR_VGA:
2340 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002341 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002342 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002343 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002344 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002345 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002346 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10002347 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002348 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002349 rdev->mode_info.load_detect_property,
2350 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04002351 /* no HPD on analog connectors */
2352 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002353 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
Alex Deucherc49948f2010-11-30 15:46:47 -05002354 connector->interlace_allowed = true;
2355 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002356 break;
2357 case DRM_MODE_CONNECTOR_DVIA:
2358 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002359 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002360 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002361 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002362 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002363 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002364 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10002365 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002366 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002367 rdev->mode_info.load_detect_property,
2368 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04002369 /* no HPD on analog connectors */
2370 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05002371 connector->interlace_allowed = true;
2372 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002373 break;
2374 case DRM_MODE_CONNECTOR_DVII:
2375 case DRM_MODE_CONNECTOR_DVID:
2376 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002377 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002378 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002379 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002380 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002381 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Alex Deucher68b3adb2010-04-30 12:37:31 -04002382 }
2383 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
Dave Airlie35e4b7a2009-09-25 11:56:50 +10002384 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002385 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002386 rdev->mode_info.load_detect_property,
2387 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002388 }
2389 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05002390 connector->interlace_allowed = true;
2391 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2392 connector->doublescan_allowed = true;
2393 else
2394 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002395 break;
2396 case DRM_MODE_CONNECTOR_SVIDEO:
2397 case DRM_MODE_CONNECTOR_Composite:
2398 case DRM_MODE_CONNECTOR_9PinDIN:
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002399 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
2400 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2401 radeon_connector->dac_load_detect = true;
2402 /* RS400,RC410,RS480 chipset seems to report a lot
2403 * of false positive on load detect, we haven't yet
2404 * found a way to make load detect reliable on those
2405 * chipset, thus just disable it for TV.
2406 */
2407 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
2408 radeon_connector->dac_load_detect = false;
Rob Clarke35755f2012-10-11 20:44:52 -05002409 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002410 rdev->mode_info.load_detect_property,
2411 radeon_connector->dac_load_detect);
Rob Clarke35755f2012-10-11 20:44:52 -05002412 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002413 rdev->mode_info.tv_std_property,
2414 radeon_combios_get_tv_info(rdev));
2415 /* no HPD on analog connectors */
2416 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05002417 connector->interlace_allowed = false;
2418 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002419 break;
2420 case DRM_MODE_CONNECTOR_LVDS:
2421 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002422 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002423 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002424 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002425 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002426 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002427 }
Rob Clarke35755f2012-10-11 20:44:52 -05002428 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002429 dev->mode_config.scaling_mode_property,
2430 DRM_MODE_SCALE_FULLSCREEN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002431 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05002432 connector->interlace_allowed = false;
2433 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002434 break;
2435 }
2436
Alex Deucher2581afc2010-07-20 03:24:11 -04002437 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002438 if (i2c_bus->valid)
2439 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
2440 } else
2441 connector->polled = DRM_CONNECTOR_POLL_HPD;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002442 connector->display_info.subpixel_order = subpixel_order;
Thomas Wood34ea3d32014-05-29 16:57:41 +01002443 drm_connector_register(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002444}
Dave Airlie9843ead2015-02-24 09:24:04 +10002445
2446void radeon_setup_mst_connector(struct drm_device *dev)
2447{
2448 struct radeon_device *rdev = dev->dev_private;
2449 struct drm_connector *connector;
2450 struct radeon_connector *radeon_connector;
2451
2452 if (!ASIC_IS_DCE5(rdev))
2453 return;
2454
2455 if (radeon_mst == 0)
2456 return;
2457
2458 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2459 int ret;
2460
2461 radeon_connector = to_radeon_connector(connector);
2462
2463 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
2464 continue;
2465
2466 ret = radeon_dp_mst_init(radeon_connector);
2467 }
2468}