blob: 27affbde058c626eec6ae5b5b77cd9a2d4601ba9 [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>
Lukas Wunner47eb8f72016-01-11 20:09:20 +010037#include <linux/vga_switcheroo.h>
Dave Airlie10ebc0b2012-09-17 14:40:31 +100038
Dave Airlie9843ead2015-02-24 09:24:04 +100039static int radeon_dp_handle_hpd(struct drm_connector *connector)
40{
41 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
42 int ret;
43
44 ret = radeon_dp_mst_check_status(radeon_connector);
45 if (ret == -EINVAL)
46 return 1;
47 return 0;
48}
Alex Deucherd4877cf2009-12-04 16:56:37 -050049void radeon_connector_hotplug(struct drm_connector *connector)
50{
51 struct drm_device *dev = connector->dev;
52 struct radeon_device *rdev = dev->dev_private;
53 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
54
Dave Airlie9843ead2015-02-24 09:24:04 +100055 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
56 struct radeon_connector_atom_dig *dig_connector =
57 radeon_connector->con_priv;
58
59 if (radeon_connector->is_mst_connector)
60 return;
61 if (dig_connector->is_mst) {
62 radeon_dp_handle_hpd(connector);
63 return;
64 }
65 }
Alex Deuchercbac9542011-07-11 14:49:28 +000066 /* bail if the connector does not have hpd pin, e.g.,
67 * VGA, TV, etc.
68 */
69 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE)
70 return;
71
Alex Deucher1e85e1d2011-05-20 04:34:29 -040072 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
Alex Deucherd4877cf2009-12-04 16:56:37 -050073
Alex Deucher73104b52011-08-09 17:09:06 +000074 /* if the connector is already off, don't turn it back on */
Daniel Vetter6e9f7982014-05-29 23:54:47 +020075 /* FIXME: This access isn't protected by any locks. */
Alex Deucher73104b52011-08-09 17:09:06 +000076 if (connector->dpms != DRM_MODE_DPMS_ON)
77 return;
78
Alex Deucherd5811e82011-08-13 13:36:13 -040079 /* just deal with DP (not eDP) here. */
80 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
Jerome Glisse266dcba2012-07-19 17:15:56 -040081 struct radeon_connector_atom_dig *dig_connector =
82 radeon_connector->con_priv;
Alex Deucher7c3ed0f2011-05-20 04:34:30 -040083
Jerome Glisse266dcba2012-07-19 17:15:56 -040084 /* if existing sink type was not DP no need to retrain */
85 if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT)
86 return;
87
88 /* first get sink type as it may be reset after (un)plug */
89 dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
90 /* don't do anything if sink is not display port, i.e.,
91 * passive dp->(dvi|hdmi) adaptor
92 */
93 if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
94 int saved_dpms = connector->dpms;
95 /* Only turn off the display if it's physically disconnected */
Jerome Glisseca2ccde2012-07-19 17:25:55 -040096 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
Jerome Glisse266dcba2012-07-19 17:15:56 -040097 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
Jerome Glisseca2ccde2012-07-19 17:25:55 -040098 } else if (radeon_dp_needs_link_train(radeon_connector)) {
Stephen Chandler Paul924f92b2015-08-21 14:16:12 -040099 /* Don't try to start link training before we
100 * have the dpcd */
101 if (!radeon_dp_getdpcd(radeon_connector))
102 return;
103
Jerome Glisseca2ccde2012-07-19 17:25:55 -0400104 /* set it to OFF so that drm_helper_connector_dpms()
105 * won't return immediately since the current state
106 * is ON at this point.
107 */
108 connector->dpms = DRM_MODE_DPMS_OFF;
Jerome Glisse266dcba2012-07-19 17:15:56 -0400109 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
Jerome Glisseca2ccde2012-07-19 17:25:55 -0400110 }
Jerome Glisse266dcba2012-07-19 17:15:56 -0400111 connector->dpms = saved_dpms;
112 }
Alex Deucherd4877cf2009-12-04 16:56:37 -0500113 }
Alex Deucherd4877cf2009-12-04 16:56:37 -0500114}
115
Dave Airlie445282d2009-09-09 17:40:54 +1000116static void radeon_property_change_mode(struct drm_encoder *encoder)
117{
118 struct drm_crtc *crtc = encoder->crtc;
119
120 if (crtc && crtc->enabled) {
121 drm_crtc_helper_set_mode(crtc, &crtc->mode,
Matt Roperf4510a22014-04-01 15:22:40 -0700122 crtc->x, crtc->y, crtc->primary->fb);
Dave Airlie445282d2009-09-09 17:40:54 +1000123 }
124}
Alex Deuchereccea792012-03-26 15:12:54 -0400125
126int radeon_get_monitor_bpc(struct drm_connector *connector)
127{
128 struct drm_device *dev = connector->dev;
129 struct radeon_device *rdev = dev->dev_private;
130 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
131 struct radeon_connector_atom_dig *dig_connector;
132 int bpc = 8;
Mario Kleinerea292862014-06-05 09:58:24 -0400133 int mode_clock, max_tmds_clock;
Alex Deuchereccea792012-03-26 15:12:54 -0400134
135 switch (connector->connector_type) {
136 case DRM_MODE_CONNECTOR_DVII:
137 case DRM_MODE_CONNECTOR_HDMIB:
138 if (radeon_connector->use_digital) {
Alex Deucher377bd8a2014-07-15 11:00:47 -0400139 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Alex Deuchereccea792012-03-26 15:12:54 -0400140 if (connector->display_info.bpc)
141 bpc = connector->display_info.bpc;
142 }
143 }
144 break;
145 case DRM_MODE_CONNECTOR_DVID:
146 case DRM_MODE_CONNECTOR_HDMIA:
Alex Deucher377bd8a2014-07-15 11:00:47 -0400147 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Alex Deuchereccea792012-03-26 15:12:54 -0400148 if (connector->display_info.bpc)
149 bpc = connector->display_info.bpc;
150 }
151 break;
152 case DRM_MODE_CONNECTOR_DisplayPort:
153 dig_connector = radeon_connector->con_priv;
154 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
155 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) ||
Alex Deucher377bd8a2014-07-15 11:00:47 -0400156 drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Alex Deuchereccea792012-03-26 15:12:54 -0400157 if (connector->display_info.bpc)
158 bpc = connector->display_info.bpc;
159 }
160 break;
161 case DRM_MODE_CONNECTOR_eDP:
162 case DRM_MODE_CONNECTOR_LVDS:
163 if (connector->display_info.bpc)
164 bpc = connector->display_info.bpc;
165 else if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
Jani Nikula319d1e12015-03-11 11:51:02 +0200166 const struct drm_connector_helper_funcs *connector_funcs =
Alex Deuchereccea792012-03-26 15:12:54 -0400167 connector->helper_private;
168 struct drm_encoder *encoder = connector_funcs->best_encoder(connector);
169 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
170 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
171
172 if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR)
173 bpc = 6;
174 else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR)
175 bpc = 8;
176 }
177 break;
178 }
Mario Kleiner89b92332014-05-05 23:03:18 +0200179
Alex Deucher377bd8a2014-07-15 11:00:47 -0400180 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Mario Kleiner89b92332014-05-05 23:03:18 +0200181 /* hdmi deep color only implemented on DCE4+ */
182 if ((bpc > 8) && !ASIC_IS_DCE4(rdev)) {
183 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 8 bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300184 connector->name, bpc);
Mario Kleiner89b92332014-05-05 23:03:18 +0200185 bpc = 8;
186 }
187
188 /*
189 * Pre DCE-8 hw can't handle > 12 bpc, and more than 12 bpc doesn't make
190 * much sense without support for > 12 bpc framebuffers. RGB 4:4:4 at
191 * 12 bpc is always supported on hdmi deep color sinks, as this is
192 * required by the HDMI-1.3 spec. Clamp to a safe 12 bpc maximum.
193 */
194 if (bpc > 12) {
195 DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 12 bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300196 connector->name, bpc);
Mario Kleiner89b92332014-05-05 23:03:18 +0200197 bpc = 12;
198 }
Mario Kleinerea292862014-06-05 09:58:24 -0400199
200 /* Any defined maximum tmds clock limit we must not exceed? */
Ville Syrjälä2a272ca2016-09-28 16:51:37 +0300201 if (connector->display_info.max_tmds_clock > 0) {
Mario Kleinerea292862014-06-05 09:58:24 -0400202 /* mode_clock is clock in kHz for mode to be modeset on this connector */
203 mode_clock = radeon_connector->pixelclock_for_modeset;
204
205 /* Maximum allowable input clock in kHz */
Ville Syrjälä2a272ca2016-09-28 16:51:37 +0300206 max_tmds_clock = connector->display_info.max_tmds_clock;
Mario Kleinerea292862014-06-05 09:58:24 -0400207
208 DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds input clock %d kHz.\n",
209 connector->name, mode_clock, max_tmds_clock);
210
211 /* Check if bpc is within clock limit. Try to degrade gracefully otherwise */
212 if ((bpc == 12) && (mode_clock * 3/2 > max_tmds_clock)) {
213 if ((connector->display_info.edid_hdmi_dc_modes & DRM_EDID_HDMI_DC_30) &&
214 (mode_clock * 5/4 <= max_tmds_clock))
215 bpc = 10;
216 else
217 bpc = 8;
218
219 DRM_DEBUG("%s: HDMI deep color 12 bpc exceeds max tmds clock. Using %d bpc.\n",
220 connector->name, bpc);
221 }
222
223 if ((bpc == 10) && (mode_clock * 5/4 > max_tmds_clock)) {
224 bpc = 8;
225 DRM_DEBUG("%s: HDMI deep color 10 bpc exceeds max tmds clock. Using %d bpc.\n",
226 connector->name, bpc);
227 }
228 }
Mario Kleiner9f51e2e2014-08-05 05:23:11 +0200229 else if (bpc > 8) {
230 /* max_tmds_clock missing, but hdmi spec mandates it for deep color. */
231 DRM_DEBUG("%s: Required max tmds clock for HDMI deep color missing. Using 8 bpc.\n",
232 connector->name);
233 bpc = 8;
234 }
Mario Kleiner89b92332014-05-05 23:03:18 +0200235 }
236
Mario Kleiner9f51e2e2014-08-05 05:23:11 +0200237 if ((radeon_deep_color == 0) && (bpc > 8)) {
238 DRM_DEBUG("%s: Deep color disabled. Set radeon module param deep_color=1 to enable.\n",
239 connector->name);
Alex Deuchera624f422014-07-01 11:23:03 -0400240 bpc = 8;
Mario Kleiner9f51e2e2014-08-05 05:23:11 +0200241 }
Alex Deuchera624f422014-07-01 11:23:03 -0400242
Mario Kleiner89b92332014-05-05 23:03:18 +0200243 DRM_DEBUG("%s: Display bpc=%d, returned bpc=%d\n",
Jani Nikula72082092014-06-03 14:56:19 +0300244 connector->name, connector->display_info.bpc, bpc);
Mario Kleiner89b92332014-05-05 23:03:18 +0200245
Alex Deuchereccea792012-03-26 15:12:54 -0400246 return bpc;
247}
248
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200249static void
250radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
251{
252 struct drm_device *dev = connector->dev;
253 struct radeon_device *rdev = dev->dev_private;
254 struct drm_encoder *best_encoder = NULL;
255 struct drm_encoder *encoder = NULL;
Jani Nikula319d1e12015-03-11 11:51:02 +0200256 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200257 bool connected;
258 int i;
259
260 best_encoder = connector_funcs->best_encoder(connector);
261
262 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
263 if (connector->encoder_ids[i] == 0)
264 break;
265
Rob Clarkb957f452014-07-17 23:30:05 -0400266 encoder = drm_encoder_find(connector->dev,
267 connector->encoder_ids[i]);
268 if (!encoder)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200269 continue;
270
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200271 if ((encoder == best_encoder) && (status == connector_status_connected))
272 connected = true;
273 else
274 connected = false;
275
276 if (rdev->is_atom_bios)
277 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
278 else
279 radeon_combios_connected_scratch_regs(connector, encoder, connected);
280
281 }
282}
283
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400284static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
Dave Airlie445282d2009-09-09 17:40:54 +1000285{
Dave Airlie445282d2009-09-09 17:40:54 +1000286 struct drm_encoder *encoder;
287 int i;
288
289 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
290 if (connector->encoder_ids[i] == 0)
291 break;
292
Rob Clarkb957f452014-07-17 23:30:05 -0400293 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
294 if (!encoder)
Dave Airlie445282d2009-09-09 17:40:54 +1000295 continue;
296
Dave Airlie445282d2009-09-09 17:40:54 +1000297 if (encoder->encoder_type == encoder_type)
298 return encoder;
299 }
300 return NULL;
301}
302
Alex Deucher377bd8a2014-07-15 11:00:47 -0400303struct edid *radeon_connector_edid(struct drm_connector *connector)
304{
305 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
306 struct drm_property_blob *edid_blob = connector->edid_blob_ptr;
307
308 if (radeon_connector->edid) {
309 return radeon_connector->edid;
310 } else if (edid_blob) {
311 struct edid *edid = kmemdup(edid_blob->data, edid_blob->length, GFP_KERNEL);
312 if (edid)
313 radeon_connector->edid = edid;
314 }
315 return radeon_connector->edid;
316}
317
Alex Deucher72a5c972014-07-15 10:38:10 -0400318static void radeon_connector_get_edid(struct drm_connector *connector)
319{
320 struct drm_device *dev = connector->dev;
321 struct radeon_device *rdev = dev->dev_private;
322 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
323
324 if (radeon_connector->edid)
325 return;
326
327 /* on hw with routers, select right port */
328 if (radeon_connector->router.ddc_valid)
329 radeon_router_select_ddc_port(radeon_connector);
330
331 if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
332 ENCODER_OBJECT_ID_NONE) &&
333 radeon_connector->ddc_bus->has_aux) {
334 radeon_connector->edid = drm_get_edid(connector,
335 &radeon_connector->ddc_bus->aux.ddc);
336 } else if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
337 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
338 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
339
340 if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
341 dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) &&
342 radeon_connector->ddc_bus->has_aux)
343 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
344 &radeon_connector->ddc_bus->aux.ddc);
345 else if (radeon_connector->ddc_bus)
346 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
347 &radeon_connector->ddc_bus->adapter);
Lukas Wunner47eb8f72016-01-11 20:09:20 +0100348 } else if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC &&
349 connector->connector_type == DRM_MODE_CONNECTOR_LVDS &&
350 radeon_connector->ddc_bus) {
351 radeon_connector->edid = drm_get_edid_switcheroo(&radeon_connector->base,
352 &radeon_connector->ddc_bus->adapter);
Alex Deucher72a5c972014-07-15 10:38:10 -0400353 } else if (radeon_connector->ddc_bus) {
354 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
355 &radeon_connector->ddc_bus->adapter);
356 }
357
358 if (!radeon_connector->edid) {
Alex Deucher13485792014-11-14 12:08:34 -0500359 /* don't fetch the edid from the vbios if ddc fails and runpm is
360 * enabled so we report disconnected.
361 */
362 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
363 return;
364
Alex Deucher72a5c972014-07-15 10:38:10 -0400365 if (rdev->is_atom_bios) {
366 /* some laptops provide a hardcoded edid in rom for LCDs */
367 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
368 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)))
369 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
370 } else {
371 /* some servers provide a hardcoded edid in rom for KVMs */
372 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
373 }
374 }
375}
376
377static void radeon_connector_free_edid(struct drm_connector *connector)
378{
379 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
380
381 if (radeon_connector->edid) {
382 kfree(radeon_connector->edid);
383 radeon_connector->edid = NULL;
384 }
385}
386
387static int radeon_ddc_get_modes(struct drm_connector *connector)
388{
389 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
390 int ret;
391
392 if (radeon_connector->edid) {
393 drm_mode_connector_update_edid_property(connector, radeon_connector->edid);
394 ret = drm_add_edid_modes(connector, radeon_connector->edid);
395 drm_edid_to_eld(connector, radeon_connector->edid);
396 return ret;
397 }
398 drm_mode_connector_update_edid_property(connector, NULL);
399 return 0;
400}
401
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400402static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200403{
404 int enc_id = connector->encoder_ids[0];
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200405 /* pick the encoder ids */
Rob Clarkb957f452014-07-17 23:30:05 -0400406 if (enc_id)
407 return drm_encoder_find(connector->dev, enc_id);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200408 return NULL;
409}
410
Alex Deucherda997622014-07-09 13:21:59 -0400411static void radeon_get_native_mode(struct drm_connector *connector)
412{
413 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
414 struct radeon_encoder *radeon_encoder;
415
416 if (encoder == NULL)
417 return;
418
419 radeon_encoder = to_radeon_encoder(encoder);
420
421 if (!list_empty(&connector->probed_modes)) {
422 struct drm_display_mode *preferred_mode =
423 list_first_entry(&connector->probed_modes,
424 struct drm_display_mode, head);
425
426 radeon_encoder->native_mode = *preferred_mode;
427 } else {
428 radeon_encoder->native_mode.clock = 0;
429 }
430}
431
Dave Airlie4ce001a2009-08-13 16:32:14 +1000432/*
433 * radeon_connector_analog_encoder_conflict_solve
434 * - search for other connectors sharing this encoder
435 * if priority is true, then set them disconnected if this is connected
436 * if priority is false, set us disconnected if they are connected
437 */
438static enum drm_connector_status
439radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
440 struct drm_encoder *encoder,
441 enum drm_connector_status current_status,
442 bool priority)
443{
444 struct drm_device *dev = connector->dev;
445 struct drm_connector *conflict;
Alex Deucher08d07512010-04-15 13:31:12 -0400446 struct radeon_connector *radeon_conflict;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000447 int i;
448
449 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
450 if (conflict == connector)
451 continue;
452
Alex Deucher08d07512010-04-15 13:31:12 -0400453 radeon_conflict = to_radeon_connector(conflict);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000454 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
455 if (conflict->encoder_ids[i] == 0)
456 break;
457
458 /* if the IDs match */
459 if (conflict->encoder_ids[i] == encoder->base.id) {
460 if (conflict->status != connector_status_connected)
461 continue;
462
Alex Deucher08d07512010-04-15 13:31:12 -0400463 if (radeon_conflict->use_digital)
464 continue;
465
Dave Airlie4ce001a2009-08-13 16:32:14 +1000466 if (priority == true) {
Jani Nikula72082092014-06-03 14:56:19 +0300467 DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n",
468 conflict->name);
469 DRM_DEBUG_KMS("in favor of %s\n",
470 connector->name);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000471 conflict->status = connector_status_disconnected;
472 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
473 } else {
Jani Nikula72082092014-06-03 14:56:19 +0300474 DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n",
475 connector->name);
476 DRM_DEBUG_KMS("in favor of %s\n",
477 conflict->name);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000478 current_status = connector_status_disconnected;
479 }
480 break;
481 }
482 }
483 }
484 return current_status;
485
486}
487
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200488static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
489{
490 struct drm_device *dev = encoder->dev;
491 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
492 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400493 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200494
Alex Deucherde2103e2009-10-09 15:14:30 -0400495 if (native_mode->hdisplay != 0 &&
496 native_mode->vdisplay != 0 &&
497 native_mode->clock != 0) {
Alex Deucherfb06ca82009-10-12 11:25:05 -0400498 mode = drm_mode_duplicate(dev, native_mode);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200499 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
500 drm_mode_set_name(mode);
501
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000502 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
Alex Deucherd2efdf62009-12-22 10:06:49 -0500503 } else if (native_mode->hdisplay != 0 &&
504 native_mode->vdisplay != 0) {
505 /* mac laptops without an edid */
506 /* Note that this is not necessarily the exact panel mode,
507 * but an approximation based on the cvt formula. For these
508 * systems we should ideally read the mode info out of the
509 * registers or add a mode table, but this works and is much
510 * simpler.
511 */
512 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
513 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000514 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200515 }
516 return mode;
517}
518
Alex Deucher923f6842009-09-10 17:53:39 -0400519static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
520{
521 struct drm_device *dev = encoder->dev;
522 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
523 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400524 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400525 int i;
526 struct mode_size {
527 int w;
528 int h;
529 } common_modes[17] = {
530 { 640, 480},
531 { 720, 480},
532 { 800, 600},
533 { 848, 480},
534 {1024, 768},
535 {1152, 768},
536 {1280, 720},
537 {1280, 800},
538 {1280, 854},
539 {1280, 960},
540 {1280, 1024},
541 {1440, 900},
542 {1400, 1050},
543 {1680, 1050},
544 {1600, 1200},
545 {1920, 1080},
546 {1920, 1200}
547 };
548
549 for (i = 0; i < 17; i++) {
Alex Deucherdfdd6462009-10-13 12:48:44 -0400550 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
551 if (common_modes[i].w > 1024 ||
552 common_modes[i].h > 768)
553 continue;
554 }
Alex Deucher923f6842009-09-10 17:53:39 -0400555 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400556 if (common_modes[i].w > native_mode->hdisplay ||
557 common_modes[i].h > native_mode->vdisplay ||
558 (common_modes[i].w == native_mode->hdisplay &&
559 common_modes[i].h == native_mode->vdisplay))
Alex Deucher923f6842009-09-10 17:53:39 -0400560 continue;
561 }
562 if (common_modes[i].w < 320 || common_modes[i].h < 200)
563 continue;
564
Dave Airlied50ba252009-09-23 14:44:08 +1000565 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400566 drm_mode_probed_add(connector, mode);
567 }
568}
569
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400570static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200571 uint64_t val)
572{
Dave Airlie445282d2009-09-09 17:40:54 +1000573 struct drm_device *dev = connector->dev;
574 struct radeon_device *rdev = dev->dev_private;
575 struct drm_encoder *encoder;
576 struct radeon_encoder *radeon_encoder;
577
578 if (property == rdev->mode_info.coherent_mode_property) {
579 struct radeon_encoder_atom_dig *dig;
Dave Airliece227c42010-04-09 06:27:00 +0000580 bool new_coherent_mode;
Dave Airlie445282d2009-09-09 17:40:54 +1000581
582 /* need to find digital encoder on connector */
583 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
584 if (!encoder)
585 return 0;
586
587 radeon_encoder = to_radeon_encoder(encoder);
588
589 if (!radeon_encoder->enc_priv)
590 return 0;
591
592 dig = radeon_encoder->enc_priv;
Dave Airliece227c42010-04-09 06:27:00 +0000593 new_coherent_mode = val ? true : false;
594 if (dig->coherent_mode != new_coherent_mode) {
595 dig->coherent_mode = new_coherent_mode;
596 radeon_property_change_mode(&radeon_encoder->base);
597 }
Dave Airlie445282d2009-09-09 17:40:54 +1000598 }
599
Alex Deucher8666c072013-09-03 14:58:44 -0400600 if (property == rdev->mode_info.audio_property) {
601 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
602 /* need to find digital encoder on connector */
603 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
604 if (!encoder)
605 return 0;
606
607 radeon_encoder = to_radeon_encoder(encoder);
608
609 if (radeon_connector->audio != val) {
610 radeon_connector->audio = val;
611 radeon_property_change_mode(&radeon_encoder->base);
612 }
613 }
614
Alex Deucher6214bb72013-09-24 17:26:26 -0400615 if (property == rdev->mode_info.dither_property) {
616 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
617 /* need to find digital encoder on connector */
618 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
619 if (!encoder)
620 return 0;
621
622 radeon_encoder = to_radeon_encoder(encoder);
623
624 if (radeon_connector->dither != val) {
625 radeon_connector->dither = val;
626 radeon_property_change_mode(&radeon_encoder->base);
627 }
628 }
629
Alex Deucher5b1714d2010-08-03 19:59:20 -0400630 if (property == rdev->mode_info.underscan_property) {
631 /* need to find digital encoder on connector */
632 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
633 if (!encoder)
634 return 0;
635
636 radeon_encoder = to_radeon_encoder(encoder);
637
638 if (radeon_encoder->underscan_type != val) {
639 radeon_encoder->underscan_type = val;
640 radeon_property_change_mode(&radeon_encoder->base);
641 }
642 }
643
Marius Gröger5bccf5e2010-09-21 21:30:59 +0200644 if (property == rdev->mode_info.underscan_hborder_property) {
645 /* need to find digital encoder on connector */
646 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
647 if (!encoder)
648 return 0;
649
650 radeon_encoder = to_radeon_encoder(encoder);
651
652 if (radeon_encoder->underscan_hborder != val) {
653 radeon_encoder->underscan_hborder = val;
654 radeon_property_change_mode(&radeon_encoder->base);
655 }
656 }
657
658 if (property == rdev->mode_info.underscan_vborder_property) {
659 /* need to find digital encoder on connector */
660 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
661 if (!encoder)
662 return 0;
663
664 radeon_encoder = to_radeon_encoder(encoder);
665
666 if (radeon_encoder->underscan_vborder != val) {
667 radeon_encoder->underscan_vborder = val;
668 radeon_property_change_mode(&radeon_encoder->base);
669 }
670 }
671
Dave Airlie445282d2009-09-09 17:40:54 +1000672 if (property == rdev->mode_info.tv_std_property) {
673 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
674 if (!encoder) {
675 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
676 }
677
678 if (!encoder)
679 return 0;
680
681 radeon_encoder = to_radeon_encoder(encoder);
682 if (!radeon_encoder->enc_priv)
683 return 0;
Alex Deucher643acac2010-04-05 23:57:52 -0400684 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
Dave Airlie445282d2009-09-09 17:40:54 +1000685 struct radeon_encoder_atom_dac *dac_int;
686 dac_int = radeon_encoder->enc_priv;
687 dac_int->tv_std = val;
688 } else {
689 struct radeon_encoder_tv_dac *dac_int;
690 dac_int = radeon_encoder->enc_priv;
691 dac_int->tv_std = val;
692 }
693 radeon_property_change_mode(&radeon_encoder->base);
694 }
695
696 if (property == rdev->mode_info.load_detect_property) {
697 struct radeon_connector *radeon_connector =
698 to_radeon_connector(connector);
699
700 if (val == 0)
701 radeon_connector->dac_load_detect = false;
702 else
703 radeon_connector->dac_load_detect = true;
704 }
705
706 if (property == rdev->mode_info.tmds_pll_property) {
707 struct radeon_encoder_int_tmds *tmds = NULL;
708 bool ret = false;
709 /* need to find digital encoder on connector */
710 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
711 if (!encoder)
712 return 0;
713
714 radeon_encoder = to_radeon_encoder(encoder);
715
716 tmds = radeon_encoder->enc_priv;
717 if (!tmds)
718 return 0;
719
720 if (val == 0) {
721 if (rdev->is_atom_bios)
722 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
723 else
724 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
725 }
726 if (val == 1 || ret == false) {
727 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
728 }
729 radeon_property_change_mode(&radeon_encoder->base);
730 }
731
Alex Deucherda997622014-07-09 13:21:59 -0400732 if (property == dev->mode_config.scaling_mode_property) {
733 enum radeon_rmx_type rmx_type;
734
735 if (connector->encoder)
736 radeon_encoder = to_radeon_encoder(connector->encoder);
737 else {
Jani Nikula319d1e12015-03-11 11:51:02 +0200738 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
Alex Deucherda997622014-07-09 13:21:59 -0400739 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
740 }
741
742 switch (val) {
743 default:
744 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
745 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
746 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
747 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
748 }
749 if (radeon_encoder->rmx_type == rmx_type)
750 return 0;
751
752 if ((rmx_type != DRM_MODE_SCALE_NONE) &&
753 (radeon_encoder->native_mode.clock == 0))
754 return 0;
755
756 radeon_encoder->rmx_type = rmx_type;
757
758 radeon_property_change_mode(&radeon_encoder->base);
759 }
760
Alex Deucher643b1f52015-02-23 10:59:36 -0500761 if (property == rdev->mode_info.output_csc_property) {
762 if (connector->encoder)
763 radeon_encoder = to_radeon_encoder(connector->encoder);
764 else {
Jani Nikula16bb0792015-04-13 11:21:40 +0300765 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
Alex Deucher643b1f52015-02-23 10:59:36 -0500766 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
767 }
768
769 if (radeon_encoder->output_csc == val)
770 return 0;
771
772 radeon_encoder->output_csc = val;
773
774 if (connector->encoder->crtc) {
775 struct drm_crtc *crtc = connector->encoder->crtc;
Jani Nikula16bb0792015-04-13 11:21:40 +0300776 const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
Alex Deucher643b1f52015-02-23 10:59:36 -0500777 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
778
779 radeon_crtc->output_csc = radeon_encoder->output_csc;
780
781 (*crtc_funcs->load_lut)(crtc);
782 }
783 }
784
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200785 return 0;
786}
787
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200788static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
789 struct drm_connector *connector)
790{
791 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400792 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Matthew Garrett13bb9432011-08-08 16:21:15 +0000793 struct drm_display_mode *t, *mode;
794
795 /* If the EDID preferred mode doesn't match the native mode, use it */
796 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
797 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
798 if (mode->hdisplay != native_mode->hdisplay ||
799 mode->vdisplay != native_mode->vdisplay)
800 memcpy(native_mode, mode, sizeof(*mode));
801 }
802 }
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200803
804 /* Try to get native mode details from EDID if necessary */
Alex Deucherde2103e2009-10-09 15:14:30 -0400805 if (!native_mode->clock) {
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200806 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400807 if (mode->hdisplay == native_mode->hdisplay &&
808 mode->vdisplay == native_mode->vdisplay) {
809 *native_mode = *mode;
810 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
Alex Deucherc5d46b42010-10-29 13:49:25 -0400811 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200812 break;
813 }
814 }
815 }
Matthew Garrett13bb9432011-08-08 16:21:15 +0000816
Alex Deucherde2103e2009-10-09 15:14:30 -0400817 if (!native_mode->clock) {
Alex Deucherc5d46b42010-10-29 13:49:25 -0400818 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200819 radeon_encoder->rmx_type = RMX_OFF;
820 }
821}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200822
823static int radeon_lvds_get_modes(struct drm_connector *connector)
824{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200825 struct drm_encoder *encoder;
826 int ret = 0;
827 struct drm_display_mode *mode;
828
Alex Deucher72a5c972014-07-15 10:38:10 -0400829 radeon_connector_get_edid(connector);
830 ret = radeon_ddc_get_modes(connector);
831 if (ret > 0) {
832 encoder = radeon_best_single_encoder(connector);
833 if (encoder) {
834 radeon_fixup_lvds_native_mode(encoder, connector);
835 /* add scaled modes */
836 radeon_add_common_modes(encoder, connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200837 }
Alex Deucher72a5c972014-07-15 10:38:10 -0400838 return ret;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200839 }
840
841 encoder = radeon_best_single_encoder(connector);
842 if (!encoder)
843 return 0;
844
845 /* we have no EDID modes */
846 mode = radeon_fp_native_mode(encoder);
847 if (mode) {
848 ret = 1;
849 drm_mode_probed_add(connector, mode);
Alex Deucher7a868e12010-12-08 22:13:05 -0500850 /* add the width/height from vbios tables if available */
851 connector->display_info.width_mm = mode->width_mm;
852 connector->display_info.height_mm = mode->height_mm;
Alex Deucher7747b712009-09-11 11:15:43 -0400853 /* add scaled modes */
854 radeon_add_common_modes(encoder, connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200855 }
Alex Deucher923f6842009-09-10 17:53:39 -0400856
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200857 return ret;
858}
859
860static int radeon_lvds_mode_valid(struct drm_connector *connector,
861 struct drm_display_mode *mode)
862{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500863 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
864
865 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
866 return MODE_PANEL;
867
868 if (encoder) {
869 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
870 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
871
872 /* AVIVO hardware supports downscaling modes larger than the panel
873 * to the panel size, but I'm not sure this is desirable.
874 */
875 if ((mode->hdisplay > native_mode->hdisplay) ||
876 (mode->vdisplay > native_mode->vdisplay))
877 return MODE_PANEL;
878
879 /* if scaling is disabled, block non-native modes */
880 if (radeon_encoder->rmx_type == RMX_OFF) {
881 if ((mode->hdisplay != native_mode->hdisplay) ||
882 (mode->vdisplay != native_mode->vdisplay))
883 return MODE_PANEL;
884 }
885 }
886
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200887 return MODE_OK;
888}
889
Chris Wilson7b334fc2010-09-09 23:51:02 +0100890static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100891radeon_lvds_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200892{
Alex Deucher13485792014-11-14 12:08:34 -0500893 struct drm_device *dev = connector->dev;
894 struct radeon_device *rdev = dev->dev_private;
Alex Deucher0549a0612009-10-09 18:41:19 -0400895 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher2ffb8422009-10-08 13:02:19 -0400896 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Alex Deucher0549a0612009-10-09 18:41:19 -0400897 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000898 int r;
899
900 r = pm_runtime_get_sync(connector->dev->dev);
901 if (r < 0)
902 return connector_status_disconnected;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400903
904 if (encoder) {
905 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400906 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400907
908 /* check if panel is valid */
Alex Deucherde2103e2009-10-09 15:14:30 -0400909 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
Alex Deucher2ffb8422009-10-08 13:02:19 -0400910 ret = connector_status_connected;
Alex Deucher13485792014-11-14 12:08:34 -0500911 /* don't fetch the edid from the vbios if ddc fails and runpm is
912 * enabled so we report disconnected.
913 */
914 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
915 ret = connector_status_disconnected;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400916 }
Alex Deucher0549a0612009-10-09 18:41:19 -0400917
918 /* check for edid as well */
Alex Deucher72a5c972014-07-15 10:38:10 -0400919 radeon_connector_get_edid(connector);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400920 if (radeon_connector->edid)
921 ret = connector_status_connected;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200922 /* check acpi lid status ??? */
Alex Deucher2ffb8422009-10-08 13:02:19 -0400923
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200924 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000925 pm_runtime_mark_last_busy(connector->dev->dev);
926 pm_runtime_put_autosuspend(connector->dev->dev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200927 return ret;
928}
929
Alex Deucherb0c80bd2016-10-11 10:44:24 -0400930static void radeon_connector_unregister(struct drm_connector *connector)
931{
932 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
933
Larry Finger0a6e2102016-10-31 12:19:39 -0400934 if (radeon_connector->ddc_bus && radeon_connector->ddc_bus->has_aux) {
Alex Deucherb0c80bd2016-10-11 10:44:24 -0400935 drm_dp_aux_unregister(&radeon_connector->ddc_bus->aux);
936 radeon_connector->ddc_bus->has_aux = false;
937 }
938}
939
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200940static void radeon_connector_destroy(struct drm_connector *connector)
941{
942 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
943
Alex Deucher72a5c972014-07-15 10:38:10 -0400944 radeon_connector_free_edid(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200945 kfree(radeon_connector->con_priv);
Thomas Wood34ea3d32014-05-29 16:57:41 +0100946 drm_connector_unregister(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200947 drm_connector_cleanup(connector);
948 kfree(connector);
949}
950
Dave Airlie445282d2009-09-09 17:40:54 +1000951static int radeon_lvds_set_property(struct drm_connector *connector,
952 struct drm_property *property,
953 uint64_t value)
954{
955 struct drm_device *dev = connector->dev;
956 struct radeon_encoder *radeon_encoder;
957 enum radeon_rmx_type rmx_type;
958
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000959 DRM_DEBUG_KMS("\n");
Dave Airlie445282d2009-09-09 17:40:54 +1000960 if (property != dev->mode_config.scaling_mode_property)
961 return 0;
962
963 if (connector->encoder)
964 radeon_encoder = to_radeon_encoder(connector->encoder);
965 else {
Jani Nikula319d1e12015-03-11 11:51:02 +0200966 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
Dave Airlie445282d2009-09-09 17:40:54 +1000967 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
968 }
969
970 switch (value) {
971 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
972 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
973 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
974 default:
975 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
976 }
977 if (radeon_encoder->rmx_type == rmx_type)
978 return 0;
979
980 radeon_encoder->rmx_type = rmx_type;
981
982 radeon_property_change_mode(&radeon_encoder->base);
983 return 0;
984}
985
986
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400987static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200988 .get_modes = radeon_lvds_get_modes,
989 .mode_valid = radeon_lvds_mode_valid,
990 .best_encoder = radeon_best_single_encoder,
991};
992
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400993static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200994 .dpms = drm_helper_connector_dpms,
995 .detect = radeon_lvds_detect,
996 .fill_modes = drm_helper_probe_single_connector_modes,
Alex Deucherb0c80bd2016-10-11 10:44:24 -0400997 .early_unregister = radeon_connector_unregister,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200998 .destroy = radeon_connector_destroy,
Dave Airlie445282d2009-09-09 17:40:54 +1000999 .set_property = radeon_lvds_set_property,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001000};
1001
1002static int radeon_vga_get_modes(struct drm_connector *connector)
1003{
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001004 int ret;
1005
Alex Deucher72a5c972014-07-15 10:38:10 -04001006 radeon_connector_get_edid(connector);
1007 ret = radeon_ddc_get_modes(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001008
Alex Deucherda997622014-07-09 13:21:59 -04001009 radeon_get_native_mode(connector);
1010
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001011 return ret;
1012}
1013
1014static int radeon_vga_mode_valid(struct drm_connector *connector,
1015 struct drm_display_mode *mode)
1016{
Alex Deucherb20f9be2011-06-08 13:01:11 -04001017 struct drm_device *dev = connector->dev;
1018 struct radeon_device *rdev = dev->dev_private;
1019
Alex Deuchera3fa6322009-11-05 11:57:07 -05001020 /* XXX check mode bandwidth */
Alex Deucherb20f9be2011-06-08 13:01:11 -04001021
1022 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1023 return MODE_CLOCK_HIGH;
1024
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001025 return MODE_OK;
1026}
1027
Chris Wilson7b334fc2010-09-09 23:51:02 +01001028static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +01001029radeon_vga_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001030{
Alex Deucherfafcf942011-03-23 08:10:10 +00001031 struct drm_device *dev = connector->dev;
1032 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001033 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1034 struct drm_encoder *encoder;
Jani Nikula319d1e12015-03-11 11:51:02 +02001035 const struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie4b9d2a22010-02-08 13:16:55 +10001036 bool dret = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001037 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001038 int r;
1039
1040 r = pm_runtime_get_sync(connector->dev->dev);
1041 if (r < 0)
1042 return connector_status_disconnected;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001043
Dave Airlie4ce001a2009-08-13 16:32:14 +10001044 encoder = radeon_best_single_encoder(connector);
1045 if (!encoder)
1046 ret = connector_status_disconnected;
1047
Dave Airlieeb6b6d72010-02-25 13:44:04 +10001048 if (radeon_connector->ddc_bus)
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +01001049 dret = radeon_ddc_probe(radeon_connector, false);
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001050 if (dret) {
Alex Deucherd0d0a222011-10-07 14:23:48 -04001051 radeon_connector->detected_by_load = false;
Alex Deucher72a5c972014-07-15 10:38:10 -04001052 radeon_connector_free_edid(connector);
1053 radeon_connector_get_edid(connector);
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001054
1055 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +01001056 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
Jani Nikula72082092014-06-03 14:56:19 +03001057 connector->name);
Jerome Glissef82f5f32009-11-12 14:13:53 +01001058 ret = connector_status_connected;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001059 } else {
Alex Deucher72a5c972014-07-15 10:38:10 -04001060 radeon_connector->use_digital =
1061 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001062
1063 /* some oems have boards with separate digital and analog connectors
1064 * with a shared ddc line (often vga + hdmi)
1065 */
1066 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
Alex Deucher72a5c972014-07-15 10:38:10 -04001067 radeon_connector_free_edid(connector);
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001068 ret = connector_status_disconnected;
Alex Deucher72a5c972014-07-15 10:38:10 -04001069 } else {
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001070 ret = connector_status_connected;
Alex Deucher72a5c972014-07-15 10:38:10 -04001071 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001072 }
1073 } else {
Dave Airliec3cceed2010-10-26 12:55:52 +10001074
1075 /* if we aren't forcing don't do destructive polling */
Alex Deucherd0d0a222011-10-07 14:23:48 -04001076 if (!force) {
1077 /* only return the previous status if we last
1078 * detected a monitor via load.
1079 */
1080 if (radeon_connector->detected_by_load)
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001081 ret = connector->status;
1082 goto out;
Alex Deucherd0d0a222011-10-07 14:23:48 -04001083 }
Dave Airliec3cceed2010-10-26 12:55:52 +10001084
Darren Jenkinsd8a7f792009-12-30 12:22:55 +11001085 if (radeon_connector->dac_load_detect && encoder) {
Dave Airlie445282d2009-09-09 17:40:54 +10001086 encoder_funcs = encoder->helper_private;
1087 ret = encoder_funcs->detect(encoder, connector);
Jerome Glisse34076442011-10-24 18:16:34 -04001088 if (ret != connector_status_disconnected)
Alex Deucherd0d0a222011-10-07 14:23:48 -04001089 radeon_connector->detected_by_load = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001090 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001091 }
1092
Dave Airlie4ce001a2009-08-13 16:32:14 +10001093 if (ret == connector_status_connected)
1094 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
Alex Deucherfafcf942011-03-23 08:10:10 +00001095
1096 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1097 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1098 * by other means, assume the CRT is connected and use that EDID.
1099 */
1100 if ((!rdev->is_atom_bios) &&
1101 (ret == connector_status_disconnected) &&
1102 rdev->mode_info.bios_hardcoded_edid_size) {
1103 ret = connector_status_connected;
1104 }
1105
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001106 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001107
1108out:
1109 pm_runtime_mark_last_busy(connector->dev->dev);
1110 pm_runtime_put_autosuspend(connector->dev->dev);
1111
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001112 return ret;
1113}
1114
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001115static const struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001116 .get_modes = radeon_vga_get_modes,
1117 .mode_valid = radeon_vga_mode_valid,
1118 .best_encoder = radeon_best_single_encoder,
1119};
1120
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001121static const struct drm_connector_funcs radeon_vga_connector_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001122 .dpms = drm_helper_connector_dpms,
1123 .detect = radeon_vga_detect,
1124 .fill_modes = drm_helper_probe_single_connector_modes,
Alex Deucherb0c80bd2016-10-11 10:44:24 -04001125 .early_unregister = radeon_connector_unregister,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001126 .destroy = radeon_connector_destroy,
1127 .set_property = radeon_connector_set_property,
1128};
1129
Dave Airlie4ce001a2009-08-13 16:32:14 +10001130static int radeon_tv_get_modes(struct drm_connector *connector)
1131{
1132 struct drm_device *dev = connector->dev;
Alex Deucher923f6842009-09-10 17:53:39 -04001133 struct radeon_device *rdev = dev->dev_private;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001134 struct drm_display_mode *tv_mode;
Alex Deucher923f6842009-09-10 17:53:39 -04001135 struct drm_encoder *encoder;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001136
Alex Deucher923f6842009-09-10 17:53:39 -04001137 encoder = radeon_best_single_encoder(connector);
1138 if (!encoder)
1139 return 0;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001140
Alex Deucher923f6842009-09-10 17:53:39 -04001141 /* avivo chips can scale any mode */
1142 if (rdev->family >= CHIP_RS600)
1143 /* add scaled modes */
1144 radeon_add_common_modes(encoder, connector);
1145 else {
1146 /* only 800x600 is supported right now on pre-avivo chips */
Dave Airlied50ba252009-09-23 14:44:08 +10001147 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -04001148 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
1149 drm_mode_probed_add(connector, tv_mode);
1150 }
Dave Airlie4ce001a2009-08-13 16:32:14 +10001151 return 1;
1152}
1153
1154static int radeon_tv_mode_valid(struct drm_connector *connector,
1155 struct drm_display_mode *mode)
1156{
Alex Deuchera3fa6322009-11-05 11:57:07 -05001157 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
1158 return MODE_CLOCK_RANGE;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001159 return MODE_OK;
1160}
1161
Chris Wilson7b334fc2010-09-09 23:51:02 +01001162static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +01001163radeon_tv_detect(struct drm_connector *connector, bool force)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001164{
1165 struct drm_encoder *encoder;
Jani Nikula319d1e12015-03-11 11:51:02 +02001166 const struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie445282d2009-09-09 17:40:54 +10001167 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1168 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001169 int r;
Dave Airlie445282d2009-09-09 17:40:54 +10001170
1171 if (!radeon_connector->dac_load_detect)
1172 return ret;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001173
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001174 r = pm_runtime_get_sync(connector->dev->dev);
1175 if (r < 0)
1176 return connector_status_disconnected;
1177
Dave Airlie4ce001a2009-08-13 16:32:14 +10001178 encoder = radeon_best_single_encoder(connector);
1179 if (!encoder)
1180 ret = connector_status_disconnected;
1181 else {
1182 encoder_funcs = encoder->helper_private;
1183 ret = encoder_funcs->detect(encoder, connector);
1184 }
1185 if (ret == connector_status_connected)
1186 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
1187 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001188 pm_runtime_mark_last_busy(connector->dev->dev);
1189 pm_runtime_put_autosuspend(connector->dev->dev);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001190 return ret;
1191}
1192
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001193static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001194 .get_modes = radeon_tv_get_modes,
1195 .mode_valid = radeon_tv_mode_valid,
1196 .best_encoder = radeon_best_single_encoder,
1197};
1198
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001199static const struct drm_connector_funcs radeon_tv_connector_funcs = {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001200 .dpms = drm_helper_connector_dpms,
1201 .detect = radeon_tv_detect,
1202 .fill_modes = drm_helper_probe_single_connector_modes,
Alex Deucherb0c80bd2016-10-11 10:44:24 -04001203 .early_unregister = radeon_connector_unregister,
Dave Airlie4ce001a2009-08-13 16:32:14 +10001204 .destroy = radeon_connector_destroy,
1205 .set_property = radeon_connector_set_property,
1206};
1207
Tvrtko Ursulin11fe1262012-03-16 12:22:11 -04001208static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector)
1209{
1210 struct drm_device *dev = connector->dev;
1211 struct radeon_device *rdev = dev->dev_private;
1212 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1213 enum drm_connector_status status;
1214
1215 /* We only trust HPD on R600 and newer ASICS. */
1216 if (rdev->family >= CHIP_R600
1217 && radeon_connector->hpd.hpd != RADEON_HPD_NONE) {
1218 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
1219 status = connector_status_connected;
1220 else
1221 status = connector_status_disconnected;
1222 if (connector->status == status)
1223 return true;
1224 }
1225
1226 return false;
1227}
1228
Dave Airlie4ce001a2009-08-13 16:32:14 +10001229/*
1230 * DVI is complicated
1231 * Do a DDC probe, if DDC probe passes, get the full EDID so
1232 * we can do analog/digital monitor detection at this point.
1233 * If the monitor is an analog monitor or we got no DDC,
1234 * we need to find the DAC encoder object for this connector.
1235 * If we got no DDC, we do load detection on the DAC encoder object.
1236 * If we got analog DDC or load detection passes on the DAC encoder
1237 * we have to check if this analog encoder is shared with anyone else (TV)
1238 * if its shared we have to set the other connector to disconnected.
1239 */
Chris Wilson7b334fc2010-09-09 23:51:02 +01001240static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +01001241radeon_dvi_detect(struct drm_connector *connector, bool force)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001242{
Alex Deucherfafcf942011-03-23 08:10:10 +00001243 struct drm_device *dev = connector->dev;
1244 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001245 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001246 struct drm_encoder *encoder = NULL;
Jani Nikula319d1e12015-03-11 11:51:02 +02001247 const struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001248 int i, r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001249 enum drm_connector_status ret = connector_status_disconnected;
Egbert Eichfc87f132012-10-24 18:32:52 +02001250 bool dret = false, broken_edid = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001251
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001252 r = pm_runtime_get_sync(connector->dev->dev);
1253 if (r < 0)
1254 return connector_status_disconnected;
1255
Lyudecb5d4162015-12-03 18:26:07 -05001256 if (radeon_connector->detected_hpd_without_ddc) {
1257 force = true;
1258 radeon_connector->detected_hpd_without_ddc = false;
1259 }
1260
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001261 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1262 ret = connector->status;
1263 goto exit;
1264 }
Tvrtko Ursulin11fe1262012-03-16 12:22:11 -04001265
Lyudecb5d4162015-12-03 18:26:07 -05001266 if (radeon_connector->ddc_bus) {
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +01001267 dret = radeon_ddc_probe(radeon_connector, false);
Lyudecb5d4162015-12-03 18:26:07 -05001268
1269 /* Sometimes the pins required for the DDC probe on DVI
1270 * connectors don't make contact at the same time that the ones
1271 * for HPD do. If the DDC probe fails even though we had an HPD
1272 * signal, try again later */
1273 if (!dret && !force &&
1274 connector->status != connector_status_connected) {
1275 DRM_DEBUG_KMS("hpd detected without ddc, retrying in 1 second\n");
1276 radeon_connector->detected_hpd_without_ddc = true;
1277 schedule_delayed_work(&rdev->hotplug_work,
1278 msecs_to_jiffies(1000));
1279 goto exit;
1280 }
1281 }
Dave Airlie4ce001a2009-08-13 16:32:14 +10001282 if (dret) {
Alex Deucherd0d0a222011-10-07 14:23:48 -04001283 radeon_connector->detected_by_load = false;
Alex Deucher72a5c972014-07-15 10:38:10 -04001284 radeon_connector_free_edid(connector);
1285 radeon_connector_get_edid(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001286
Dave Airlie4ce001a2009-08-13 16:32:14 +10001287 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +01001288 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
Jani Nikula72082092014-06-03 14:56:19 +03001289 connector->name);
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001290 /* rs690 seems to have a problem with connectors not existing and always
1291 * return a block of 0's. If we see this just stop polling on this output */
Alex Deucher72a5c972014-07-15 10:38:10 -04001292 if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) &&
1293 radeon_connector->base.null_edid_counter) {
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001294 ret = connector_status_disconnected;
Jani Nikula72082092014-06-03 14:56:19 +03001295 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n",
1296 connector->name);
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001297 radeon_connector->ddc_bus = NULL;
Egbert Eichfc87f132012-10-24 18:32:52 +02001298 } else {
1299 ret = connector_status_connected;
1300 broken_edid = true; /* defer use_digital to later */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001301 }
Dave Airlie4ce001a2009-08-13 16:32:14 +10001302 } else {
Alex Deucher72a5c972014-07-15 10:38:10 -04001303 radeon_connector->use_digital =
1304 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001305
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001306 /* some oems have boards with separate digital and analog connectors
1307 * with a shared ddc line (often vga + hdmi)
1308 */
1309 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
Alex Deucher72a5c972014-07-15 10:38:10 -04001310 radeon_connector_free_edid(connector);
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001311 ret = connector_status_disconnected;
Alex Deucher72a5c972014-07-15 10:38:10 -04001312 } else {
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001313 ret = connector_status_connected;
Alex Deucher72a5c972014-07-15 10:38:10 -04001314 }
Alex Deucher42f14c42010-07-20 11:27:54 -04001315 /* This gets complicated. We have boards with VGA + HDMI with a
1316 * shared DDC line and we have boards with DVI-D + HDMI with a shared
1317 * DDC line. The latter is more complex because with DVI<->HDMI adapters
1318 * you don't really know what's connected to which port as both are digital.
Alex Deucher71407c42009-11-17 15:44:01 -05001319 */
Alex Deucherd3932d62010-02-19 02:13:56 -05001320 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
Alex Deucher71407c42009-11-17 15:44:01 -05001321 struct drm_connector *list_connector;
1322 struct radeon_connector *list_radeon_connector;
1323 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
1324 if (connector == list_connector)
1325 continue;
1326 list_radeon_connector = to_radeon_connector(list_connector);
Alex Deucherb2ea4aa2010-07-01 10:34:56 -04001327 if (list_radeon_connector->shared_ddc &&
1328 (list_radeon_connector->ddc_bus->rec.i2c_id ==
1329 radeon_connector->ddc_bus->rec.i2c_id)) {
Alex Deucher42f14c42010-07-20 11:27:54 -04001330 /* cases where both connectors are digital */
1331 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
1332 /* hpd is our only option in this case */
1333 if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
Alex Deucher72a5c972014-07-15 10:38:10 -04001334 radeon_connector_free_edid(connector);
Alex Deucher71407c42009-11-17 15:44:01 -05001335 ret = connector_status_disconnected;
1336 }
1337 }
1338 }
1339 }
1340 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001341 }
1342 }
1343
Dave Airlie4ce001a2009-08-13 16:32:14 +10001344 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
1345 goto out;
1346
Alex Deucher5f0a2612011-10-07 14:23:47 -04001347 /* DVI-D and HDMI-A are digital only */
1348 if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
1349 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
1350 goto out;
1351
Alex Deucherd0d0a222011-10-07 14:23:48 -04001352 /* if we aren't forcing don't do destructive polling */
Dave Airliec3cceed2010-10-26 12:55:52 +10001353 if (!force) {
Alex Deucherd0d0a222011-10-07 14:23:48 -04001354 /* only return the previous status if we last
1355 * detected a monitor via load.
1356 */
1357 if (radeon_connector->detected_by_load)
1358 ret = connector->status;
Dave Airliec3cceed2010-10-26 12:55:52 +10001359 goto out;
1360 }
1361
Dave Airlie4ce001a2009-08-13 16:32:14 +10001362 /* find analog encoder */
Dave Airlie445282d2009-09-09 17:40:54 +10001363 if (radeon_connector->dac_load_detect) {
1364 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1365 if (connector->encoder_ids[i] == 0)
1366 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001367
Rob Clarkb957f452014-07-17 23:30:05 -04001368 encoder = drm_encoder_find(connector->dev,
1369 connector->encoder_ids[i]);
1370 if (!encoder)
Dave Airlie445282d2009-09-09 17:40:54 +10001371 continue;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001372
Takashi Iwaie3632502012-04-18 15:21:07 +02001373 if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
Alex Deuchere00e8b52012-03-16 12:22:09 -04001374 encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
1375 continue;
1376
Dave Airlie445282d2009-09-09 17:40:54 +10001377 encoder_funcs = encoder->helper_private;
1378 if (encoder_funcs->detect) {
Egbert Eichfc87f132012-10-24 18:32:52 +02001379 if (!broken_edid) {
1380 if (ret != connector_status_connected) {
1381 /* deal with analog monitors without DDC */
1382 ret = encoder_funcs->detect(encoder, connector);
1383 if (ret == connector_status_connected) {
1384 radeon_connector->use_digital = false;
1385 }
1386 if (ret != connector_status_disconnected)
1387 radeon_connector->detected_by_load = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001388 }
Egbert Eichfc87f132012-10-24 18:32:52 +02001389 } else {
1390 enum drm_connector_status lret;
1391 /* assume digital unless load detected otherwise */
1392 radeon_connector->use_digital = true;
1393 lret = encoder_funcs->detect(encoder, connector);
1394 DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
1395 if (lret == connector_status_connected)
1396 radeon_connector->use_digital = false;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001397 }
Dave Airlie445282d2009-09-09 17:40:54 +10001398 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001399 }
Dave Airlie4ce001a2009-08-13 16:32:14 +10001400 }
1401 }
1402
1403 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
1404 encoder) {
1405 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
1406 }
1407
Alex Deucherfafcf942011-03-23 08:10:10 +00001408 /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
1409 * vbios to deal with KVMs. If we have one and are not able to detect a monitor
1410 * by other means, assume the DFP is connected and use that EDID. In most
1411 * cases the DVI port is actually a virtual KVM port connected to the service
1412 * processor.
1413 */
Dave Airliea09d4312012-04-19 15:42:58 +01001414out:
Alex Deucherfafcf942011-03-23 08:10:10 +00001415 if ((!rdev->is_atom_bios) &&
1416 (ret == connector_status_disconnected) &&
1417 rdev->mode_info.bios_hardcoded_edid_size) {
1418 radeon_connector->use_digital = true;
1419 ret = connector_status_connected;
1420 }
1421
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001422 /* updated in get modes as well since we need to know if it's analog or digital */
1423 radeon_connector_update_scratch_regs(connector, ret);
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001424
Alex Deucherd0ea3972015-07-23 10:01:09 -04001425 if ((radeon_audio != 0) && radeon_connector->use_digital) {
1426 const struct drm_connector_helper_funcs *connector_funcs =
1427 connector->helper_private;
1428
1429 encoder = connector_funcs->best_encoder(connector);
1430 if (encoder && (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)) {
1431 radeon_connector_get_edid(connector);
1432 radeon_audio_detect(connector, encoder, ret);
1433 }
1434 }
Slava Grigorev1a626b62014-12-01 13:49:39 -05001435
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001436exit:
1437 pm_runtime_mark_last_busy(connector->dev->dev);
1438 pm_runtime_put_autosuspend(connector->dev->dev);
1439
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001440 return ret;
1441}
1442
1443/* okay need to be smart in here about which encoder to pick */
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001444static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001445{
1446 int enc_id = connector->encoder_ids[0];
1447 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001448 struct drm_encoder *encoder;
1449 int i;
1450 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1451 if (connector->encoder_ids[i] == 0)
1452 break;
1453
Rob Clarkb957f452014-07-17 23:30:05 -04001454 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
1455 if (!encoder)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001456 continue;
1457
Dave Airlie4ce001a2009-08-13 16:32:14 +10001458 if (radeon_connector->use_digital == true) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001459 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
1460 return encoder;
1461 } else {
1462 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
1463 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
1464 return encoder;
1465 }
1466 }
1467
1468 /* see if we have a default encoder TODO */
1469
1470 /* then check use digitial */
1471 /* pick the first one */
Rob Clarkb957f452014-07-17 23:30:05 -04001472 if (enc_id)
1473 return drm_encoder_find(connector->dev, enc_id);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001474 return NULL;
1475}
1476
Dave Airlied50ba252009-09-23 14:44:08 +10001477static void radeon_dvi_force(struct drm_connector *connector)
1478{
1479 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1480 if (connector->force == DRM_FORCE_ON)
1481 radeon_connector->use_digital = false;
1482 if (connector->force == DRM_FORCE_ON_DIGITAL)
1483 radeon_connector->use_digital = true;
1484}
1485
Alex Deuchera3fa6322009-11-05 11:57:07 -05001486static int radeon_dvi_mode_valid(struct drm_connector *connector,
1487 struct drm_display_mode *mode)
1488{
Alex Deucher1b242032010-01-11 15:02:31 -05001489 struct drm_device *dev = connector->dev;
1490 struct radeon_device *rdev = dev->dev_private;
Alex Deuchera3fa6322009-11-05 11:57:07 -05001491 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1492
1493 /* XXX check mode bandwidth */
1494
Alex Deucher1b242032010-01-11 15:02:31 -05001495 /* clocks over 135 MHz have heat issues with DVI on RV100 */
1496 if (radeon_connector->use_digital &&
1497 (rdev->family == CHIP_RV100) &&
1498 (mode->clock > 135000))
1499 return MODE_CLOCK_HIGH;
1500
Alex Deuchera3fa6322009-11-05 11:57:07 -05001501 if (radeon_connector->use_digital && (mode->clock > 165000)) {
1502 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1503 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1504 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1505 return MODE_OK;
Alex Deucher377bd8a2014-07-15 11:00:47 -04001506 else if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Alex Deucherf2263fc2014-06-16 17:46:57 -04001507 /* HDMI 1.3+ supports max clock of 340 Mhz */
1508 if (mode->clock > 340000)
Alex Deuchere1e84012011-03-02 10:21:05 -05001509 return MODE_CLOCK_HIGH;
Alex Deucherf2263fc2014-06-16 17:46:57 -04001510 else
1511 return MODE_OK;
1512 } else {
Alex Deuchera3fa6322009-11-05 11:57:07 -05001513 return MODE_CLOCK_HIGH;
Alex Deucherf2263fc2014-06-16 17:46:57 -04001514 }
Alex Deuchera3fa6322009-11-05 11:57:07 -05001515 }
Alex Deucherb20f9be2011-06-08 13:01:11 -04001516
1517 /* check against the max pixel clock */
1518 if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1519 return MODE_CLOCK_HIGH;
1520
Alex Deuchera3fa6322009-11-05 11:57:07 -05001521 return MODE_OK;
1522}
1523
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001524static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
Alex Deucher3e229202014-07-10 13:07:19 -04001525 .get_modes = radeon_vga_get_modes,
Alex Deuchera3fa6322009-11-05 11:57:07 -05001526 .mode_valid = radeon_dvi_mode_valid,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001527 .best_encoder = radeon_dvi_encoder,
1528};
1529
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001530static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001531 .dpms = drm_helper_connector_dpms,
1532 .detect = radeon_dvi_detect,
1533 .fill_modes = drm_helper_probe_single_connector_modes,
1534 .set_property = radeon_connector_set_property,
Alex Deucherb0c80bd2016-10-11 10:44:24 -04001535 .early_unregister = radeon_connector_unregister,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001536 .destroy = radeon_connector_destroy,
Dave Airlied50ba252009-09-23 14:44:08 +10001537 .force = radeon_dvi_force,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001538};
1539
Dave Airlie746c1aa2009-12-08 07:07:28 +10001540static int radeon_dp_get_modes(struct drm_connector *connector)
1541{
1542 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher8b834852010-11-17 02:54:42 -05001543 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
Alex Deucher591a10e2011-06-13 17:13:34 -04001544 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001545 int ret;
1546
Alex Deucherf89931f2011-06-13 17:13:35 -04001547 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1548 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
Alex Deucherd2917672011-05-20 04:34:31 -04001549 struct drm_display_mode *mode;
1550
Alex Deucher2b69ffb2012-02-28 11:08:22 -05001551 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1552 if (!radeon_dig_connector->edp_on)
1553 atombios_set_edp_panel_power(connector,
1554 ATOM_TRANSMITTER_ACTION_POWER_ON);
Alex Deucher72a5c972014-07-15 10:38:10 -04001555 radeon_connector_get_edid(connector);
1556 ret = radeon_ddc_get_modes(connector);
Alex Deucher2b69ffb2012-02-28 11:08:22 -05001557 if (!radeon_dig_connector->edp_on)
1558 atombios_set_edp_panel_power(connector,
1559 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1560 } else {
1561 /* need to setup ddc on the bridge */
1562 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1563 ENCODER_OBJECT_ID_NONE) {
1564 if (encoder)
1565 radeon_atom_ext_encoder_setup_ddc(encoder);
1566 }
Alex Deucher72a5c972014-07-15 10:38:10 -04001567 radeon_connector_get_edid(connector);
1568 ret = radeon_ddc_get_modes(connector);
Alex Deucher2b69ffb2012-02-28 11:08:22 -05001569 }
Alex Deucherd2917672011-05-20 04:34:31 -04001570
1571 if (ret > 0) {
Alex Deucherd2917672011-05-20 04:34:31 -04001572 if (encoder) {
1573 radeon_fixup_lvds_native_mode(encoder, connector);
1574 /* add scaled modes */
1575 radeon_add_common_modes(encoder, connector);
1576 }
1577 return ret;
1578 }
1579
Alex Deucherd2917672011-05-20 04:34:31 -04001580 if (!encoder)
1581 return 0;
1582
1583 /* we have no EDID modes */
1584 mode = radeon_fp_native_mode(encoder);
1585 if (mode) {
1586 ret = 1;
1587 drm_mode_probed_add(connector, mode);
1588 /* add the width/height from vbios tables if available */
1589 connector->display_info.width_mm = mode->width_mm;
1590 connector->display_info.height_mm = mode->height_mm;
1591 /* add scaled modes */
1592 radeon_add_common_modes(encoder, connector);
1593 }
Alex Deucher591a10e2011-06-13 17:13:34 -04001594 } else {
1595 /* need to setup ddc on the bridge */
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001596 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1597 ENCODER_OBJECT_ID_NONE) {
Alex Deucher591a10e2011-06-13 17:13:34 -04001598 if (encoder)
1599 radeon_atom_ext_encoder_setup_ddc(encoder);
1600 }
Alex Deucher72a5c972014-07-15 10:38:10 -04001601 radeon_connector_get_edid(connector);
1602 ret = radeon_ddc_get_modes(connector);
Alex Deucherda997622014-07-09 13:21:59 -04001603
1604 radeon_get_native_mode(connector);
Alex Deucher591a10e2011-06-13 17:13:34 -04001605 }
Alex Deucher8b834852010-11-17 02:54:42 -05001606
Dave Airlie746c1aa2009-12-08 07:07:28 +10001607 return ret;
1608}
1609
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001610u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001611{
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001612 struct drm_encoder *encoder;
1613 struct radeon_encoder *radeon_encoder;
1614 int i;
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001615
1616 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1617 if (connector->encoder_ids[i] == 0)
1618 break;
1619
Rob Clarkb957f452014-07-17 23:30:05 -04001620 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
1621 if (!encoder)
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001622 continue;
1623
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001624 radeon_encoder = to_radeon_encoder(encoder);
1625
1626 switch (radeon_encoder->encoder_id) {
1627 case ENCODER_OBJECT_ID_TRAVIS:
1628 case ENCODER_OBJECT_ID_NUTMEG:
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001629 return radeon_encoder->encoder_id;
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001630 default:
1631 break;
1632 }
1633 }
1634
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001635 return ENCODER_OBJECT_ID_NONE;
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001636}
1637
Alex Deucherebdea822014-07-24 16:06:57 -04001638static bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001639{
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001640 struct drm_encoder *encoder;
1641 struct radeon_encoder *radeon_encoder;
1642 int i;
1643 bool found = false;
1644
1645 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1646 if (connector->encoder_ids[i] == 0)
1647 break;
1648
Rob Clarkb957f452014-07-17 23:30:05 -04001649 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
1650 if (!encoder)
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001651 continue;
1652
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001653 radeon_encoder = to_radeon_encoder(encoder);
1654 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1655 found = true;
1656 }
1657
1658 return found;
1659}
1660
1661bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1662{
1663 struct drm_device *dev = connector->dev;
1664 struct radeon_device *rdev = dev->dev_private;
1665
1666 if (ASIC_IS_DCE5(rdev) &&
Alex Deucheraf5d3652014-05-27 13:11:36 -04001667 (rdev->clock.default_dispclk >= 53900) &&
Alex Deucherd7fa8bb2011-05-20 04:34:21 -04001668 radeon_connector_encoder_is_hbr2(connector)) {
1669 return true;
1670 }
1671
1672 return false;
1673}
1674
Chris Wilson7b334fc2010-09-09 23:51:02 +01001675static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +01001676radeon_dp_detect(struct drm_connector *connector, bool force)
Dave Airlie746c1aa2009-12-08 07:07:28 +10001677{
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001678 struct drm_device *dev = connector->dev;
1679 struct radeon_device *rdev = dev->dev_private;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001680 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001681 enum drm_connector_status ret = connector_status_disconnected;
Alex Deucher4143e912009-11-23 18:02:35 -05001682 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
Alex Deucher591a10e2011-06-13 17:13:34 -04001683 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001684 int r;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001685
Dave Airlie9843ead2015-02-24 09:24:04 +10001686 if (radeon_dig_connector->is_mst)
1687 return connector_status_disconnected;
1688
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001689 r = pm_runtime_get_sync(connector->dev->dev);
1690 if (r < 0)
1691 return connector_status_disconnected;
1692
1693 if (!force && radeon_check_hpd_status_unchanged(connector)) {
1694 ret = connector->status;
1695 goto out;
1696 }
Tvrtko Ursulin11fe1262012-03-16 12:22:11 -04001697
Alex Deucher72a5c972014-07-15 10:38:10 -04001698 radeon_connector_free_edid(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +10001699
Alex Deucherf89931f2011-06-13 17:13:35 -04001700 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1701 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
Alex Deucherd2917672011-05-20 04:34:31 -04001702 if (encoder) {
1703 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1704 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1705
1706 /* check if panel is valid */
1707 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1708 ret = connector_status_connected;
Alex Deucher13485792014-11-14 12:08:34 -05001709 /* don't fetch the edid from the vbios if ddc fails and runpm is
1710 * enabled so we report disconnected.
1711 */
1712 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
1713 ret = connector_status_disconnected;
Alex Deucherd2917672011-05-20 04:34:31 -04001714 }
Alex Deucher6f50eae2010-08-19 17:29:03 -04001715 /* eDP is always DP */
1716 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
Alex Deucher8b834852010-11-17 02:54:42 -05001717 if (!radeon_dig_connector->edp_on)
1718 atombios_set_edp_panel_power(connector,
1719 ATOM_TRANSMITTER_ACTION_POWER_ON);
Alex Deucher6f50eae2010-08-19 17:29:03 -04001720 if (radeon_dp_getdpcd(radeon_connector))
Alex Deucher9fa05c92009-11-27 13:01:46 -05001721 ret = connector_status_connected;
Alex Deucher8b834852010-11-17 02:54:42 -05001722 if (!radeon_dig_connector->edp_on)
1723 atombios_set_edp_panel_power(connector,
1724 ATOM_TRANSMITTER_ACTION_POWER_OFF);
Alex Deucher1d33e1f2011-10-31 08:58:47 -04001725 } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1726 ENCODER_OBJECT_ID_NONE) {
Alex Deucherb06947b2011-09-02 14:23:09 +00001727 /* DP bridges are always DP */
1728 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1729 /* get the DPCD from the bridge */
1730 radeon_dp_getdpcd(radeon_connector);
1731
Alex Deucher6777a4f2011-10-04 12:23:24 -04001732 if (encoder) {
1733 /* setup ddc on the bridge */
1734 radeon_atom_ext_encoder_setup_ddc(encoder);
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +01001735 /* bridge chips are always aux */
1736 if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */
Alex Deucherb06947b2011-09-02 14:23:09 +00001737 ret = connector_status_connected;
Alex Deucher6777a4f2011-10-04 12:23:24 -04001738 else if (radeon_connector->dac_load_detect) { /* try load detection */
Jani Nikula319d1e12015-03-11 11:51:02 +02001739 const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
Alex Deucherb06947b2011-09-02 14:23:09 +00001740 ret = encoder_funcs->detect(encoder, connector);
1741 }
1742 }
1743 } else {
Alex Deucher6f50eae2010-08-19 17:29:03 -04001744 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001745 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1746 ret = connector_status_connected;
Dave Airlie9843ead2015-02-24 09:24:04 +10001747 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001748 radeon_dp_getdpcd(radeon_connector);
Dave Airlie9843ead2015-02-24 09:24:04 +10001749 r = radeon_dp_mst_probe(radeon_connector);
1750 if (r == 1)
1751 ret = connector_status_disconnected;
1752 }
Alex Deucher6f50eae2010-08-19 17:29:03 -04001753 } else {
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001754 if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
Dave Airlie9843ead2015-02-24 09:24:04 +10001755 if (radeon_dp_getdpcd(radeon_connector)) {
1756 r = radeon_dp_mst_probe(radeon_connector);
1757 if (r == 1)
1758 ret = connector_status_disconnected;
1759 else
1760 ret = connector_status_connected;
1761 }
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001762 } else {
Damien Lespiaud592fca2013-09-13 16:37:28 +01001763 /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
Niels Ole Salscheider0a9069d2013-01-03 19:09:28 +01001764 if (radeon_ddc_probe(radeon_connector, false))
Alex Deucherf8d0edd2011-05-20 04:34:23 -04001765 ret = connector_status_connected;
1766 }
Alex Deucher4143e912009-11-23 18:02:35 -05001767 }
Dave Airlie746c1aa2009-12-08 07:07:28 +10001768 }
Alex Deucher4143e912009-11-23 18:02:35 -05001769
Alex Deucher30f44372010-08-21 11:09:14 -04001770 radeon_connector_update_scratch_regs(connector, ret);
Slava Grigorev1a626b62014-12-01 13:49:39 -05001771
Alex Deucherd0ea3972015-07-23 10:01:09 -04001772 if ((radeon_audio != 0) && encoder) {
1773 radeon_connector_get_edid(connector);
1774 radeon_audio_detect(connector, encoder, ret);
1775 }
Slava Grigorev1a626b62014-12-01 13:49:39 -05001776
Dave Airlie10ebc0b2012-09-17 14:40:31 +10001777out:
1778 pm_runtime_mark_last_busy(connector->dev->dev);
1779 pm_runtime_put_autosuspend(connector->dev->dev);
1780
Dave Airlie746c1aa2009-12-08 07:07:28 +10001781 return ret;
1782}
1783
Alex Deucher5801ead2009-11-24 13:32:59 -05001784static int radeon_dp_mode_valid(struct drm_connector *connector,
1785 struct drm_display_mode *mode)
1786{
Alex Deucher6536a3a2014-06-16 17:42:34 -04001787 struct drm_device *dev = connector->dev;
1788 struct radeon_device *rdev = dev->dev_private;
Alex Deucher5801ead2009-11-24 13:32:59 -05001789 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1790 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1791
1792 /* XXX check mode bandwidth */
1793
Alex Deucherf89931f2011-06-13 17:13:35 -04001794 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
1795 (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
Alex Deucherd2917672011-05-20 04:34:31 -04001796 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1797
1798 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1799 return MODE_PANEL;
1800
1801 if (encoder) {
1802 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1803 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1804
Alex Deucherf89931f2011-06-13 17:13:35 -04001805 /* AVIVO hardware supports downscaling modes larger than the panel
Alex Deucherd2917672011-05-20 04:34:31 -04001806 * to the panel size, but I'm not sure this is desirable.
1807 */
1808 if ((mode->hdisplay > native_mode->hdisplay) ||
1809 (mode->vdisplay > native_mode->vdisplay))
1810 return MODE_PANEL;
1811
1812 /* if scaling is disabled, block non-native modes */
1813 if (radeon_encoder->rmx_type == RMX_OFF) {
1814 if ((mode->hdisplay != native_mode->hdisplay) ||
1815 (mode->vdisplay != native_mode->vdisplay))
1816 return MODE_PANEL;
1817 }
1818 }
Alex Deucherd2917672011-05-20 04:34:31 -04001819 } else {
1820 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
Alex Deucher6536a3a2014-06-16 17:42:34 -04001821 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
Alex Deucherd2917672011-05-20 04:34:31 -04001822 return radeon_dp_mode_valid_helper(connector, mode);
Alex Deucher6536a3a2014-06-16 17:42:34 -04001823 } else {
Alex Deucher377bd8a2014-07-15 11:00:47 -04001824 if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
Alex Deucher6536a3a2014-06-16 17:42:34 -04001825 /* HDMI 1.3+ supports max clock of 340 Mhz */
1826 if (mode->clock > 340000)
1827 return MODE_CLOCK_HIGH;
1828 } else {
1829 if (mode->clock > 165000)
1830 return MODE_CLOCK_HIGH;
1831 }
1832 }
Alex Deucherd2917672011-05-20 04:34:31 -04001833 }
Alex Deucher6536a3a2014-06-16 17:42:34 -04001834
1835 return MODE_OK;
Alex Deucher5801ead2009-11-24 13:32:59 -05001836}
1837
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001838static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
Dave Airlie746c1aa2009-12-08 07:07:28 +10001839 .get_modes = radeon_dp_get_modes,
Alex Deucher5801ead2009-11-24 13:32:59 -05001840 .mode_valid = radeon_dp_mode_valid,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001841 .best_encoder = radeon_dvi_encoder,
1842};
1843
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001844static const struct drm_connector_funcs radeon_dp_connector_funcs = {
Dave Airlie746c1aa2009-12-08 07:07:28 +10001845 .dpms = drm_helper_connector_dpms,
1846 .detect = radeon_dp_detect,
1847 .fill_modes = drm_helper_probe_single_connector_modes,
1848 .set_property = radeon_connector_set_property,
Alex Deucherb0c80bd2016-10-11 10:44:24 -04001849 .early_unregister = radeon_connector_unregister,
Alex Deucher379dfc22014-04-07 10:33:46 -04001850 .destroy = radeon_connector_destroy,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001851 .force = radeon_dvi_force,
1852};
1853
Alex Deucher855f5f12013-09-13 18:33:16 -04001854static const struct drm_connector_funcs radeon_edp_connector_funcs = {
1855 .dpms = drm_helper_connector_dpms,
1856 .detect = radeon_dp_detect,
1857 .fill_modes = drm_helper_probe_single_connector_modes,
1858 .set_property = radeon_lvds_set_property,
Alex Deucherb0c80bd2016-10-11 10:44:24 -04001859 .early_unregister = radeon_connector_unregister,
Alex Deucher379dfc22014-04-07 10:33:46 -04001860 .destroy = radeon_connector_destroy,
Alex Deucher855f5f12013-09-13 18:33:16 -04001861 .force = radeon_dvi_force,
1862};
1863
1864static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
1865 .dpms = drm_helper_connector_dpms,
1866 .detect = radeon_dp_detect,
1867 .fill_modes = drm_helper_probe_single_connector_modes,
1868 .set_property = radeon_lvds_set_property,
Alex Deucherb0c80bd2016-10-11 10:44:24 -04001869 .early_unregister = radeon_connector_unregister,
Alex Deucher379dfc22014-04-07 10:33:46 -04001870 .destroy = radeon_connector_destroy,
Alex Deucher855f5f12013-09-13 18:33:16 -04001871 .force = radeon_dvi_force,
1872};
1873
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001874void
1875radeon_add_atom_connector(struct drm_device *dev,
1876 uint32_t connector_id,
1877 uint32_t supported_device,
1878 int connector_type,
1879 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deucherb75fad02009-11-05 13:16:01 -05001880 uint32_t igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -05001881 uint16_t connector_object_id,
Alex Deucher26b5bc92010-08-05 21:21:18 -04001882 struct radeon_hpd *hpd,
1883 struct radeon_router *router)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001884{
Dave Airlie445282d2009-09-09 17:40:54 +10001885 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001886 struct drm_connector *connector;
1887 struct radeon_connector *radeon_connector;
1888 struct radeon_connector_atom_dig *radeon_dig_connector;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001889 struct drm_encoder *encoder;
1890 struct radeon_encoder *radeon_encoder;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001891 uint32_t subpixel_order = SubPixelNone;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001892 bool shared_ddc = false;
Alex Deuchereac4dff2011-05-20 04:34:22 -04001893 bool is_dp_bridge = false;
Alex Deucher496263b2014-03-21 10:34:07 -04001894 bool has_aux = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001895
Dave Airlie4ce001a2009-08-13 16:32:14 +10001896 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001897 return;
1898
Alex Deuchercf4c12f2010-09-01 17:15:06 -04001899 /* if the user selected tv=0 don't try and add the connector */
1900 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1901 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1902 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1903 (radeon_tv == 0))
1904 return;
1905
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001906 /* see if we already added it */
1907 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1908 radeon_connector = to_radeon_connector(connector);
1909 if (radeon_connector->connector_id == connector_id) {
1910 radeon_connector->devices |= supported_device;
1911 return;
1912 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001913 if (radeon_connector->ddc_bus && i2c_bus->valid) {
Alex Deucherd3932d62010-02-19 02:13:56 -05001914 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001915 radeon_connector->shared_ddc = true;
1916 shared_ddc = true;
1917 }
Alex Deucherfb939df2010-11-08 16:08:29 +00001918 if (radeon_connector->router_bus && router->ddc_valid &&
Alex Deucher26b5bc92010-08-05 21:21:18 -04001919 (radeon_connector->router.router_id == router->router_id)) {
1920 radeon_connector->shared_ddc = false;
1921 shared_ddc = false;
1922 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001923 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001924 }
1925
Alex Deuchereac4dff2011-05-20 04:34:22 -04001926 /* check if it's a dp bridge */
1927 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1928 radeon_encoder = to_radeon_encoder(encoder);
1929 if (radeon_encoder->devices & supported_device) {
1930 switch (radeon_encoder->encoder_id) {
1931 case ENCODER_OBJECT_ID_TRAVIS:
1932 case ENCODER_OBJECT_ID_NUTMEG:
1933 is_dp_bridge = true;
1934 break;
1935 default:
1936 break;
1937 }
1938 }
1939 }
1940
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001941 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1942 if (!radeon_connector)
1943 return;
1944
1945 connector = &radeon_connector->base;
1946
1947 radeon_connector->connector_id = connector_id;
1948 radeon_connector->devices = supported_device;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001949 radeon_connector->shared_ddc = shared_ddc;
Alex Deucherb75fad02009-11-05 13:16:01 -05001950 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05001951 radeon_connector->hpd = *hpd;
Alex Deucherbc1c4dc2011-10-30 16:54:27 -04001952
Alex Deucher26b5bc92010-08-05 21:21:18 -04001953 radeon_connector->router = *router;
Alex Deucherfb939df2010-11-08 16:08:29 +00001954 if (router->ddc_valid || router->cd_valid) {
Alex Deucher26b5bc92010-08-05 21:21:18 -04001955 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1956 if (!radeon_connector->router_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04001957 DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
Alex Deucher26b5bc92010-08-05 21:21:18 -04001958 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001959
1960 if (is_dp_bridge) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001961 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1962 if (!radeon_dig_connector)
1963 goto failed;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001964 radeon_dig_connector->igp_lane_info = igp_lane_info;
1965 radeon_connector->con_priv = radeon_dig_connector;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001966 if (i2c_bus->valid) {
Alex Deucher379dfc22014-04-07 10:33:46 -04001967 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1968 if (radeon_connector->ddc_bus)
Alex Deucher496263b2014-03-21 10:34:07 -04001969 has_aux = true;
1970 else
Alex Deuchereac4dff2011-05-20 04:34:22 -04001971 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001972 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04001973 switch (connector_type) {
1974 case DRM_MODE_CONNECTOR_VGA:
1975 case DRM_MODE_CONNECTOR_DVIA:
1976 default:
Alex Deucher855f5f12013-09-13 18:33:16 -04001977 drm_connector_init(dev, &radeon_connector->base,
1978 &radeon_dp_connector_funcs, connector_type);
1979 drm_connector_helper_add(&radeon_connector->base,
1980 &radeon_dp_connector_helper_funcs);
Alex Deuchereac4dff2011-05-20 04:34:22 -04001981 connector->interlace_allowed = true;
1982 connector->doublescan_allowed = true;
Alex Deucherd629a3c2011-06-13 17:13:33 -04001983 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05001984 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucherd629a3c2011-06-13 17:13:33 -04001985 rdev->mode_info.load_detect_property,
1986 1);
Alex Deucherda997622014-07-09 13:21:59 -04001987 drm_object_attach_property(&radeon_connector->base.base,
1988 dev->mode_config.scaling_mode_property,
1989 DRM_MODE_SCALE_NONE);
Alex Deucher643b1f52015-02-23 10:59:36 -05001990 if (ASIC_IS_DCE5(rdev))
1991 drm_object_attach_property(&radeon_connector->base.base,
1992 rdev->mode_info.output_csc_property,
1993 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04001994 break;
1995 case DRM_MODE_CONNECTOR_DVII:
1996 case DRM_MODE_CONNECTOR_DVID:
1997 case DRM_MODE_CONNECTOR_HDMIA:
1998 case DRM_MODE_CONNECTOR_HDMIB:
1999 case DRM_MODE_CONNECTOR_DisplayPort:
Alex Deucher855f5f12013-09-13 18:33:16 -04002000 drm_connector_init(dev, &radeon_connector->base,
2001 &radeon_dp_connector_funcs, connector_type);
2002 drm_connector_helper_add(&radeon_connector->base,
2003 &radeon_dp_connector_helper_funcs);
Rob Clarke35755f2012-10-11 20:44:52 -05002004 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher430f70d2010-08-04 03:45:04 -04002005 rdev->mode_info.underscan_property,
Alex Deucher56bec7c2011-01-05 11:57:52 -05002006 UNDERSCAN_OFF);
Rob Clarke35755f2012-10-11 20:44:52 -05002007 drm_object_attach_property(&radeon_connector->base.base,
Marius Gröger5bccf5e2010-09-21 21:30:59 +02002008 rdev->mode_info.underscan_hborder_property,
2009 0);
Rob Clarke35755f2012-10-11 20:44:52 -05002010 drm_object_attach_property(&radeon_connector->base.base,
Marius Gröger5bccf5e2010-09-21 21:30:59 +02002011 rdev->mode_info.underscan_vborder_property,
2012 0);
Dave Airlie91915262013-11-08 16:34:39 +10002013
Alex Deucher6214bb72013-09-24 17:26:26 -04002014 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucherda997622014-07-09 13:21:59 -04002015 dev->mode_config.scaling_mode_property,
2016 DRM_MODE_SCALE_NONE);
2017
2018 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher6214bb72013-09-24 17:26:26 -04002019 rdev->mode_info.dither_property,
2020 RADEON_FMT_DITHER_DISABLE);
Dave Airlie91915262013-11-08 16:34:39 +10002021
Alex Deucher7403c512016-04-13 12:08:27 -04002022 if (radeon_audio != 0) {
Alex Deucher108dc8e2013-10-14 13:17:50 -04002023 drm_object_attach_property(&radeon_connector->base.base,
2024 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05002025 RADEON_AUDIO_AUTO);
Alex Deucher7403c512016-04-13 12:08:27 -04002026 radeon_connector->audio = RADEON_AUDIO_AUTO;
2027 }
Alex Deucher643b1f52015-02-23 10:59:36 -05002028 if (ASIC_IS_DCE5(rdev))
2029 drm_object_attach_property(&radeon_connector->base.base,
2030 rdev->mode_info.output_csc_property,
2031 RADEON_OUTPUT_CSC_BYPASS);
Dave Airlie91915262013-11-08 16:34:39 +10002032
Alex Deuchereac4dff2011-05-20 04:34:22 -04002033 subpixel_order = SubPixelHorizontalRGB;
2034 connector->interlace_allowed = true;
2035 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
2036 connector->doublescan_allowed = true;
2037 else
2038 connector->doublescan_allowed = false;
Alex Deucherd629a3c2011-06-13 17:13:33 -04002039 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2040 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002041 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucherd629a3c2011-06-13 17:13:33 -04002042 rdev->mode_info.load_detect_property,
2043 1);
2044 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04002045 break;
2046 case DRM_MODE_CONNECTOR_LVDS:
2047 case DRM_MODE_CONNECTOR_eDP:
Alex Deucher855f5f12013-09-13 18:33:16 -04002048 drm_connector_init(dev, &radeon_connector->base,
2049 &radeon_lvds_bridge_connector_funcs, connector_type);
2050 drm_connector_helper_add(&radeon_connector->base,
2051 &radeon_dp_connector_helper_funcs);
Rob Clarke35755f2012-10-11 20:44:52 -05002052 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002053 dev->mode_config.scaling_mode_property,
2054 DRM_MODE_SCALE_FULLSCREEN);
2055 subpixel_order = SubPixelHorizontalRGB;
2056 connector->interlace_allowed = false;
2057 connector->doublescan_allowed = false;
2058 break;
Marius Gröger5bccf5e2010-09-21 21:30:59 +02002059 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04002060 } else {
2061 switch (connector_type) {
2062 case DRM_MODE_CONNECTOR_VGA:
2063 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2064 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2065 if (i2c_bus->valid) {
2066 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2067 if (!radeon_connector->ddc_bus)
2068 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2069 }
Alex Deucher390d0bb2009-12-08 12:48:20 -05002070 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002071 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher390d0bb2009-12-08 12:48:20 -05002072 rdev->mode_info.load_detect_property,
2073 1);
Alex Deucherda997622014-07-09 13:21:59 -04002074 if (ASIC_IS_AVIVO(rdev))
2075 drm_object_attach_property(&radeon_connector->base.base,
2076 dev->mode_config.scaling_mode_property,
2077 DRM_MODE_SCALE_NONE);
Alex Deucher643b1f52015-02-23 10:59:36 -05002078 if (ASIC_IS_DCE5(rdev))
2079 drm_object_attach_property(&radeon_connector->base.base,
2080 rdev->mode_info.output_csc_property,
2081 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002082 /* no HPD on analog connectors */
2083 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deuchereac4dff2011-05-20 04:34:22 -04002084 connector->interlace_allowed = true;
Alex Deucherc49948f2010-11-30 15:46:47 -05002085 connector->doublescan_allowed = true;
Alex Deuchereac4dff2011-05-20 04:34:22 -04002086 break;
2087 case DRM_MODE_CONNECTOR_DVIA:
2088 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
2089 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
2090 if (i2c_bus->valid) {
2091 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2092 if (!radeon_connector->ddc_bus)
2093 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2094 }
2095 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002096 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002097 rdev->mode_info.load_detect_property,
2098 1);
Alex Deucherda997622014-07-09 13:21:59 -04002099 if (ASIC_IS_AVIVO(rdev))
2100 drm_object_attach_property(&radeon_connector->base.base,
2101 dev->mode_config.scaling_mode_property,
2102 DRM_MODE_SCALE_NONE);
Alex Deucher643b1f52015-02-23 10:59:36 -05002103 if (ASIC_IS_DCE5(rdev))
2104 drm_object_attach_property(&radeon_connector->base.base,
2105 rdev->mode_info.output_csc_property,
2106 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002107 /* no HPD on analog connectors */
2108 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2109 connector->interlace_allowed = true;
Alex Deucherc49948f2010-11-30 15:46:47 -05002110 connector->doublescan_allowed = true;
Alex Deuchereac4dff2011-05-20 04:34:22 -04002111 break;
2112 case DRM_MODE_CONNECTOR_DVII:
2113 case DRM_MODE_CONNECTOR_DVID:
2114 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2115 if (!radeon_dig_connector)
2116 goto failed;
2117 radeon_dig_connector->igp_lane_info = igp_lane_info;
2118 radeon_connector->con_priv = radeon_dig_connector;
2119 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
2120 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2121 if (i2c_bus->valid) {
2122 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2123 if (!radeon_connector->ddc_bus)
2124 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2125 }
2126 subpixel_order = SubPixelHorizontalRGB;
Rob Clarke35755f2012-10-11 20:44:52 -05002127 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002128 rdev->mode_info.coherent_mode_property,
2129 1);
2130 if (ASIC_IS_AVIVO(rdev)) {
Rob Clarke35755f2012-10-11 20:44:52 -05002131 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002132 rdev->mode_info.underscan_property,
2133 UNDERSCAN_OFF);
Rob Clarke35755f2012-10-11 20:44:52 -05002134 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002135 rdev->mode_info.underscan_hborder_property,
2136 0);
Rob Clarke35755f2012-10-11 20:44:52 -05002137 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002138 rdev->mode_info.underscan_vborder_property,
2139 0);
Alex Deucherda997622014-07-09 13:21:59 -04002140 drm_object_attach_property(&radeon_connector->base.base,
2141 rdev->mode_info.dither_property,
2142 RADEON_FMT_DITHER_DISABLE);
2143 drm_object_attach_property(&radeon_connector->base.base,
2144 dev->mode_config.scaling_mode_property,
2145 DRM_MODE_SCALE_NONE);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002146 }
Alex Deucher108dc8e2013-10-14 13:17:50 -04002147 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
Alex Deucher8666c072013-09-03 14:58:44 -04002148 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher108dc8e2013-10-14 13:17:50 -04002149 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05002150 RADEON_AUDIO_AUTO);
Alex Deucher7403c512016-04-13 12:08:27 -04002151 radeon_connector->audio = RADEON_AUDIO_AUTO;
Alex Deucher8666c072013-09-03 14:58:44 -04002152 }
Alex Deuchereac4dff2011-05-20 04:34:22 -04002153 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
2154 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002155 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002156 rdev->mode_info.load_detect_property,
2157 1);
2158 }
Alex Deucher643b1f52015-02-23 10:59:36 -05002159 if (ASIC_IS_DCE5(rdev))
2160 drm_object_attach_property(&radeon_connector->base.base,
2161 rdev->mode_info.output_csc_property,
2162 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002163 connector->interlace_allowed = true;
2164 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2165 connector->doublescan_allowed = true;
2166 else
2167 connector->doublescan_allowed = false;
2168 break;
2169 case DRM_MODE_CONNECTOR_HDMIA:
2170 case DRM_MODE_CONNECTOR_HDMIB:
2171 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2172 if (!radeon_dig_connector)
2173 goto failed;
2174 radeon_dig_connector->igp_lane_info = igp_lane_info;
2175 radeon_connector->con_priv = radeon_dig_connector;
2176 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
2177 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
2178 if (i2c_bus->valid) {
2179 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2180 if (!radeon_connector->ddc_bus)
2181 DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2182 }
Rob Clarke35755f2012-10-11 20:44:52 -05002183 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002184 rdev->mode_info.coherent_mode_property,
2185 1);
2186 if (ASIC_IS_AVIVO(rdev)) {
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_property,
2189 UNDERSCAN_OFF);
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_hborder_property,
2192 0);
Rob Clarke35755f2012-10-11 20:44:52 -05002193 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002194 rdev->mode_info.underscan_vborder_property,
2195 0);
Alex Deucherda997622014-07-09 13:21:59 -04002196 drm_object_attach_property(&radeon_connector->base.base,
2197 rdev->mode_info.dither_property,
2198 RADEON_FMT_DITHER_DISABLE);
2199 drm_object_attach_property(&radeon_connector->base.base,
2200 dev->mode_config.scaling_mode_property,
2201 DRM_MODE_SCALE_NONE);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002202 }
Alex Deucher108dc8e2013-10-14 13:17:50 -04002203 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
Alex Deucher8666c072013-09-03 14:58:44 -04002204 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher108dc8e2013-10-14 13:17:50 -04002205 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05002206 RADEON_AUDIO_AUTO);
Alex Deucher7403c512016-04-13 12:08:27 -04002207 radeon_connector->audio = RADEON_AUDIO_AUTO;
Alex Deucher8666c072013-09-03 14:58:44 -04002208 }
Alex Deucher643b1f52015-02-23 10:59:36 -05002209 if (ASIC_IS_DCE5(rdev))
2210 drm_object_attach_property(&radeon_connector->base.base,
2211 rdev->mode_info.output_csc_property,
2212 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002213 subpixel_order = SubPixelHorizontalRGB;
2214 connector->interlace_allowed = true;
2215 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
2216 connector->doublescan_allowed = true;
2217 else
2218 connector->doublescan_allowed = false;
2219 break;
2220 case DRM_MODE_CONNECTOR_DisplayPort:
2221 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2222 if (!radeon_dig_connector)
2223 goto failed;
2224 radeon_dig_connector->igp_lane_info = igp_lane_info;
2225 radeon_connector->con_priv = radeon_dig_connector;
2226 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
2227 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2228 if (i2c_bus->valid) {
Alex Deuchereac4dff2011-05-20 04:34:22 -04002229 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Alex Deucher496263b2014-03-21 10:34:07 -04002230 if (radeon_connector->ddc_bus)
2231 has_aux = true;
2232 else
Alex Deuchereac4dff2011-05-20 04:34:22 -04002233 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2234 }
2235 subpixel_order = SubPixelHorizontalRGB;
Rob Clarke35755f2012-10-11 20:44:52 -05002236 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002237 rdev->mode_info.coherent_mode_property,
2238 1);
2239 if (ASIC_IS_AVIVO(rdev)) {
Rob Clarke35755f2012-10-11 20:44:52 -05002240 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002241 rdev->mode_info.underscan_property,
2242 UNDERSCAN_OFF);
Rob Clarke35755f2012-10-11 20:44:52 -05002243 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002244 rdev->mode_info.underscan_hborder_property,
2245 0);
Rob Clarke35755f2012-10-11 20:44:52 -05002246 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002247 rdev->mode_info.underscan_vborder_property,
2248 0);
Alex Deucherda997622014-07-09 13:21:59 -04002249 drm_object_attach_property(&radeon_connector->base.base,
2250 rdev->mode_info.dither_property,
2251 RADEON_FMT_DITHER_DISABLE);
2252 drm_object_attach_property(&radeon_connector->base.base,
2253 dev->mode_config.scaling_mode_property,
2254 DRM_MODE_SCALE_NONE);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002255 }
Alex Deucher108dc8e2013-10-14 13:17:50 -04002256 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
Alex Deucher8666c072013-09-03 14:58:44 -04002257 drm_object_attach_property(&radeon_connector->base.base,
Alex Deucher108dc8e2013-10-14 13:17:50 -04002258 rdev->mode_info.audio_property,
Alex Deuchere31fadd32013-11-08 13:03:47 -05002259 RADEON_AUDIO_AUTO);
Alex Deucher7403c512016-04-13 12:08:27 -04002260 radeon_connector->audio = RADEON_AUDIO_AUTO;
Alex Deucher8666c072013-09-03 14:58:44 -04002261 }
Alex Deucher643b1f52015-02-23 10:59:36 -05002262 if (ASIC_IS_DCE5(rdev))
2263 drm_object_attach_property(&radeon_connector->base.base,
2264 rdev->mode_info.output_csc_property,
2265 RADEON_OUTPUT_CSC_BYPASS);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002266 connector->interlace_allowed = true;
2267 /* in theory with a DP to VGA converter... */
Alex Deucherc49948f2010-11-30 15:46:47 -05002268 connector->doublescan_allowed = false;
Alex Deuchereac4dff2011-05-20 04:34:22 -04002269 break;
2270 case DRM_MODE_CONNECTOR_eDP:
2271 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2272 if (!radeon_dig_connector)
2273 goto failed;
2274 radeon_dig_connector->igp_lane_info = igp_lane_info;
2275 radeon_connector->con_priv = radeon_dig_connector;
Alex Deucher855f5f12013-09-13 18:33:16 -04002276 drm_connector_init(dev, &radeon_connector->base, &radeon_edp_connector_funcs, connector_type);
Alex Deuchereac4dff2011-05-20 04:34:22 -04002277 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
2278 if (i2c_bus->valid) {
Alex Deucher379dfc22014-04-07 10:33:46 -04002279 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2280 if (radeon_connector->ddc_bus)
Alex Deucher496263b2014-03-21 10:34:07 -04002281 has_aux = true;
2282 else
Alex Deuchereac4dff2011-05-20 04:34:22 -04002283 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2284 }
Rob Clarke35755f2012-10-11 20:44:52 -05002285 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002286 dev->mode_config.scaling_mode_property,
2287 DRM_MODE_SCALE_FULLSCREEN);
2288 subpixel_order = SubPixelHorizontalRGB;
2289 connector->interlace_allowed = false;
2290 connector->doublescan_allowed = false;
2291 break;
2292 case DRM_MODE_CONNECTOR_SVIDEO:
2293 case DRM_MODE_CONNECTOR_Composite:
2294 case DRM_MODE_CONNECTOR_9PinDIN:
2295 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
2296 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2297 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002298 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002299 rdev->mode_info.load_detect_property,
2300 1);
Rob Clarke35755f2012-10-11 20:44:52 -05002301 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002302 rdev->mode_info.tv_std_property,
2303 radeon_atombios_get_tv_info(rdev));
2304 /* no HPD on analog connectors */
2305 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
2306 connector->interlace_allowed = false;
2307 connector->doublescan_allowed = false;
2308 break;
2309 case DRM_MODE_CONNECTOR_LVDS:
2310 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
2311 if (!radeon_dig_connector)
2312 goto failed;
2313 radeon_dig_connector->igp_lane_info = igp_lane_info;
2314 radeon_connector->con_priv = radeon_dig_connector;
2315 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
2316 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
2317 if (i2c_bus->valid) {
2318 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
2319 if (!radeon_connector->ddc_bus)
2320 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
2321 }
Rob Clarke35755f2012-10-11 20:44:52 -05002322 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchereac4dff2011-05-20 04:34:22 -04002323 dev->mode_config.scaling_mode_property,
2324 DRM_MODE_SCALE_FULLSCREEN);
2325 subpixel_order = SubPixelHorizontalRGB;
2326 connector->interlace_allowed = false;
2327 connector->doublescan_allowed = false;
2328 break;
Marius Gröger5bccf5e2010-09-21 21:30:59 +02002329 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002330 }
2331
Alex Deucher2581afc2010-07-20 03:24:11 -04002332 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
Lyude14ff8d42016-06-24 17:54:31 -04002333 if (i2c_bus->valid) {
2334 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2335 DRM_CONNECTOR_POLL_DISCONNECT;
2336 }
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002337 } else
2338 connector->polled = DRM_CONNECTOR_POLL_HPD;
2339
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002340 connector->display_info.subpixel_order = subpixel_order;
Thomas Wood34ea3d32014-05-29 16:57:41 +01002341 drm_connector_register(connector);
Alex Deucher496263b2014-03-21 10:34:07 -04002342
2343 if (has_aux)
2344 radeon_dp_aux_init(radeon_connector);
2345
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002346 return;
2347
2348failed:
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002349 drm_connector_cleanup(connector);
2350 kfree(connector);
2351}
2352
2353void
2354radeon_add_legacy_connector(struct drm_device *dev,
2355 uint32_t connector_id,
2356 uint32_t supported_device,
2357 int connector_type,
Alex Deucherb75fad02009-11-05 13:16:01 -05002358 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -05002359 uint16_t connector_object_id,
2360 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002361{
Dave Airlie445282d2009-09-09 17:40:54 +10002362 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002363 struct drm_connector *connector;
2364 struct radeon_connector *radeon_connector;
2365 uint32_t subpixel_order = SubPixelNone;
2366
Dave Airlie4ce001a2009-08-13 16:32:14 +10002367 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002368 return;
2369
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002370 /* if the user selected tv=0 don't try and add the connector */
2371 if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
2372 (connector_type == DRM_MODE_CONNECTOR_Composite) ||
2373 (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
2374 (radeon_tv == 0))
2375 return;
2376
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002377 /* see if we already added it */
2378 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2379 radeon_connector = to_radeon_connector(connector);
2380 if (radeon_connector->connector_id == connector_id) {
2381 radeon_connector->devices |= supported_device;
2382 return;
2383 }
2384 }
2385
2386 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
2387 if (!radeon_connector)
2388 return;
2389
2390 connector = &radeon_connector->base;
2391
2392 radeon_connector->connector_id = connector_id;
2393 radeon_connector->devices = supported_device;
Alex Deucherb75fad02009-11-05 13:16:01 -05002394 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05002395 radeon_connector->hpd = *hpd;
Alex Deucherbc1c4dc2011-10-30 16:54:27 -04002396
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002397 switch (connector_type) {
2398 case DRM_MODE_CONNECTOR_VGA:
2399 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002400 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002401 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002402 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002403 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002404 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002405 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10002406 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002407 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002408 rdev->mode_info.load_detect_property,
2409 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04002410 /* no HPD on analog connectors */
2411 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05002412 connector->interlace_allowed = true;
2413 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002414 break;
2415 case DRM_MODE_CONNECTOR_DVIA:
2416 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002417 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002418 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002419 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002420 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002421 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002422 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10002423 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002424 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002425 rdev->mode_info.load_detect_property,
2426 1);
Alex Deucher2581afc2010-07-20 03:24:11 -04002427 /* no HPD on analog connectors */
2428 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05002429 connector->interlace_allowed = true;
2430 connector->doublescan_allowed = true;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002431 break;
2432 case DRM_MODE_CONNECTOR_DVII:
2433 case DRM_MODE_CONNECTOR_DVID:
2434 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002435 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002436 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002437 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002438 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002439 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Alex Deucher68b3adb2010-04-30 12:37:31 -04002440 }
2441 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
Dave Airlie35e4b7a2009-09-25 11:56:50 +10002442 radeon_connector->dac_load_detect = true;
Rob Clarke35755f2012-10-11 20:44:52 -05002443 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002444 rdev->mode_info.load_detect_property,
2445 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002446 }
2447 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05002448 connector->interlace_allowed = true;
2449 if (connector_type == DRM_MODE_CONNECTOR_DVII)
2450 connector->doublescan_allowed = true;
2451 else
2452 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002453 break;
2454 case DRM_MODE_CONNECTOR_SVIDEO:
2455 case DRM_MODE_CONNECTOR_Composite:
2456 case DRM_MODE_CONNECTOR_9PinDIN:
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002457 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
2458 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
2459 radeon_connector->dac_load_detect = true;
2460 /* RS400,RC410,RS480 chipset seems to report a lot
2461 * of false positive on load detect, we haven't yet
2462 * found a way to make load detect reliable on those
2463 * chipset, thus just disable it for TV.
2464 */
2465 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
2466 radeon_connector->dac_load_detect = false;
Rob Clarke35755f2012-10-11 20:44:52 -05002467 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002468 rdev->mode_info.load_detect_property,
2469 radeon_connector->dac_load_detect);
Rob Clarke35755f2012-10-11 20:44:52 -05002470 drm_object_attach_property(&radeon_connector->base.base,
Alex Deuchercf4c12f2010-09-01 17:15:06 -04002471 rdev->mode_info.tv_std_property,
2472 radeon_combios_get_tv_info(rdev));
2473 /* no HPD on analog connectors */
2474 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
Alex Deucherc49948f2010-11-30 15:46:47 -05002475 connector->interlace_allowed = false;
2476 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002477 break;
2478 case DRM_MODE_CONNECTOR_LVDS:
2479 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00002480 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002481 if (i2c_bus->valid) {
Alex Deucherf376b942010-08-05 21:21:16 -04002482 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002483 if (!radeon_connector->ddc_bus)
Alex Deuchera70882a2011-04-14 17:24:07 -04002484 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002485 }
Rob Clarke35755f2012-10-11 20:44:52 -05002486 drm_object_attach_property(&radeon_connector->base.base,
Dave Airlie445282d2009-09-09 17:40:54 +10002487 dev->mode_config.scaling_mode_property,
2488 DRM_MODE_SCALE_FULLSCREEN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002489 subpixel_order = SubPixelHorizontalRGB;
Alex Deucherc49948f2010-11-30 15:46:47 -05002490 connector->interlace_allowed = false;
2491 connector->doublescan_allowed = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002492 break;
2493 }
2494
Alex Deucher2581afc2010-07-20 03:24:11 -04002495 if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
Lyude14ff8d42016-06-24 17:54:31 -04002496 if (i2c_bus->valid) {
2497 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
2498 DRM_CONNECTOR_POLL_DISCONNECT;
2499 }
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002500 } else
2501 connector->polled = DRM_CONNECTOR_POLL_HPD;
Lyude14ff8d42016-06-24 17:54:31 -04002502
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002503 connector->display_info.subpixel_order = subpixel_order;
Thomas Wood34ea3d32014-05-29 16:57:41 +01002504 drm_connector_register(connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002505}
Dave Airlie9843ead2015-02-24 09:24:04 +10002506
2507void radeon_setup_mst_connector(struct drm_device *dev)
2508{
2509 struct radeon_device *rdev = dev->dev_private;
2510 struct drm_connector *connector;
2511 struct radeon_connector *radeon_connector;
2512
2513 if (!ASIC_IS_DCE5(rdev))
2514 return;
2515
2516 if (radeon_mst == 0)
2517 return;
2518
2519 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2520 int ret;
2521
2522 radeon_connector = to_radeon_connector(connector);
2523
2524 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
2525 continue;
2526
2527 ret = radeon_dp_mst_init(radeon_connector);
2528 }
2529}