blob: 47bd98521becfe606ce3caa46a029aa82d50088c [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 */
26#include "drmP.h"
27#include "drm_edid.h"
28#include "drm_crtc_helper.h"
Dave Airlied50ba252009-09-23 14:44:08 +100029#include "drm_fb_helper.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020030#include "radeon_drm.h"
31#include "radeon.h"
Alex Deucher923f6842009-09-10 17:53:39 -040032#include "atom.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020033
34extern void
35radeon_combios_connected_scratch_regs(struct drm_connector *connector,
36 struct drm_encoder *encoder,
37 bool connected);
38extern void
39radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
40 struct drm_encoder *encoder,
41 bool connected);
42
Alex Deucherd4877cf2009-12-04 16:56:37 -050043void radeon_connector_hotplug(struct drm_connector *connector)
44{
45 struct drm_device *dev = connector->dev;
46 struct radeon_device *rdev = dev->dev_private;
47 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
48
49 if (radeon_connector->hpd.hpd != RADEON_HPD_NONE)
50 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
51
Alex Deucher196c58d2010-01-07 14:22:32 -050052 if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
53 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
54 if ((radeon_dp_getsinktype(radeon_connector) == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
55 (radeon_dp_getsinktype(radeon_connector) == CONNECTOR_OBJECT_ID_eDP)) {
Alex Deucherd4877cf2009-12-04 16:56:37 -050056 if (radeon_dp_needs_link_train(radeon_connector)) {
57 if (connector->encoder)
58 dp_link_train(connector->encoder, connector);
59 }
60 }
61 }
62
63}
64
Dave Airlie445282d2009-09-09 17:40:54 +100065static void radeon_property_change_mode(struct drm_encoder *encoder)
66{
67 struct drm_crtc *crtc = encoder->crtc;
68
69 if (crtc && crtc->enabled) {
70 drm_crtc_helper_set_mode(crtc, &crtc->mode,
71 crtc->x, crtc->y, crtc->fb);
72 }
73}
Jerome Glisse771fe6b2009-06-05 14:42:42 +020074static void
75radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
76{
77 struct drm_device *dev = connector->dev;
78 struct radeon_device *rdev = dev->dev_private;
79 struct drm_encoder *best_encoder = NULL;
80 struct drm_encoder *encoder = NULL;
81 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
82 struct drm_mode_object *obj;
83 bool connected;
84 int i;
85
86 best_encoder = connector_funcs->best_encoder(connector);
87
88 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
89 if (connector->encoder_ids[i] == 0)
90 break;
91
92 obj = drm_mode_object_find(connector->dev,
93 connector->encoder_ids[i],
94 DRM_MODE_OBJECT_ENCODER);
95 if (!obj)
96 continue;
97
98 encoder = obj_to_encoder(obj);
99
100 if ((encoder == best_encoder) && (status == connector_status_connected))
101 connected = true;
102 else
103 connected = false;
104
105 if (rdev->is_atom_bios)
106 radeon_atombios_connected_scratch_regs(connector, encoder, connected);
107 else
108 radeon_combios_connected_scratch_regs(connector, encoder, connected);
109
110 }
111}
112
Dave Airlie445282d2009-09-09 17:40:54 +1000113struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
114{
115 struct drm_mode_object *obj;
116 struct drm_encoder *encoder;
117 int i;
118
119 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
120 if (connector->encoder_ids[i] == 0)
121 break;
122
123 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
124 if (!obj)
125 continue;
126
127 encoder = obj_to_encoder(obj);
128 if (encoder->encoder_type == encoder_type)
129 return encoder;
130 }
131 return NULL;
132}
133
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200134struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
135{
136 int enc_id = connector->encoder_ids[0];
137 struct drm_mode_object *obj;
138 struct drm_encoder *encoder;
139
140 /* pick the encoder ids */
141 if (enc_id) {
142 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
143 if (!obj)
144 return NULL;
145 encoder = obj_to_encoder(obj);
146 return encoder;
147 }
148 return NULL;
149}
150
Dave Airlie4ce001a2009-08-13 16:32:14 +1000151/*
152 * radeon_connector_analog_encoder_conflict_solve
153 * - search for other connectors sharing this encoder
154 * if priority is true, then set them disconnected if this is connected
155 * if priority is false, set us disconnected if they are connected
156 */
157static enum drm_connector_status
158radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
159 struct drm_encoder *encoder,
160 enum drm_connector_status current_status,
161 bool priority)
162{
163 struct drm_device *dev = connector->dev;
164 struct drm_connector *conflict;
165 int i;
166
167 list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
168 if (conflict == connector)
169 continue;
170
171 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
172 if (conflict->encoder_ids[i] == 0)
173 break;
174
175 /* if the IDs match */
176 if (conflict->encoder_ids[i] == encoder->base.id) {
177 if (conflict->status != connector_status_connected)
178 continue;
179
180 if (priority == true) {
181 DRM_INFO("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
182 DRM_INFO("in favor of %s\n", drm_get_connector_name(connector));
183 conflict->status = connector_status_disconnected;
184 radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
185 } else {
186 DRM_INFO("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
187 DRM_INFO("in favor of %s\n", drm_get_connector_name(conflict));
188 current_status = connector_status_disconnected;
189 }
190 break;
191 }
192 }
193 }
194 return current_status;
195
196}
197
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200198static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
199{
200 struct drm_device *dev = encoder->dev;
201 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
202 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400203 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200204
Alex Deucherde2103e2009-10-09 15:14:30 -0400205 if (native_mode->hdisplay != 0 &&
206 native_mode->vdisplay != 0 &&
207 native_mode->clock != 0) {
Alex Deucherfb06ca82009-10-12 11:25:05 -0400208 mode = drm_mode_duplicate(dev, native_mode);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200209 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
210 drm_mode_set_name(mode);
211
212 DRM_DEBUG("Adding native panel mode %s\n", mode->name);
Alex Deucherd2efdf62009-12-22 10:06:49 -0500213 } else if (native_mode->hdisplay != 0 &&
214 native_mode->vdisplay != 0) {
215 /* mac laptops without an edid */
216 /* Note that this is not necessarily the exact panel mode,
217 * but an approximation based on the cvt formula. For these
218 * systems we should ideally read the mode info out of the
219 * registers or add a mode table, but this works and is much
220 * simpler.
221 */
222 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
223 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
224 DRM_DEBUG("Adding cvt approximation of native panel mode %s\n", mode->name);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200225 }
226 return mode;
227}
228
Alex Deucher923f6842009-09-10 17:53:39 -0400229static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
230{
231 struct drm_device *dev = encoder->dev;
232 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
233 struct drm_display_mode *mode = NULL;
Alex Deucherde2103e2009-10-09 15:14:30 -0400234 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400235 int i;
236 struct mode_size {
237 int w;
238 int h;
239 } common_modes[17] = {
240 { 640, 480},
241 { 720, 480},
242 { 800, 600},
243 { 848, 480},
244 {1024, 768},
245 {1152, 768},
246 {1280, 720},
247 {1280, 800},
248 {1280, 854},
249 {1280, 960},
250 {1280, 1024},
251 {1440, 900},
252 {1400, 1050},
253 {1680, 1050},
254 {1600, 1200},
255 {1920, 1080},
256 {1920, 1200}
257 };
258
259 for (i = 0; i < 17; i++) {
Alex Deucherdfdd6462009-10-13 12:48:44 -0400260 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
261 if (common_modes[i].w > 1024 ||
262 common_modes[i].h > 768)
263 continue;
264 }
Alex Deucher923f6842009-09-10 17:53:39 -0400265 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400266 if (common_modes[i].w > native_mode->hdisplay ||
267 common_modes[i].h > native_mode->vdisplay ||
268 (common_modes[i].w == native_mode->hdisplay &&
269 common_modes[i].h == native_mode->vdisplay))
Alex Deucher923f6842009-09-10 17:53:39 -0400270 continue;
271 }
272 if (common_modes[i].w < 320 || common_modes[i].h < 200)
273 continue;
274
Dave Airlied50ba252009-09-23 14:44:08 +1000275 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400276 drm_mode_probed_add(connector, mode);
277 }
278}
279
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200280int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
281 uint64_t val)
282{
Dave Airlie445282d2009-09-09 17:40:54 +1000283 struct drm_device *dev = connector->dev;
284 struct radeon_device *rdev = dev->dev_private;
285 struct drm_encoder *encoder;
286 struct radeon_encoder *radeon_encoder;
287
288 if (property == rdev->mode_info.coherent_mode_property) {
289 struct radeon_encoder_atom_dig *dig;
290
291 /* need to find digital encoder on connector */
292 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
293 if (!encoder)
294 return 0;
295
296 radeon_encoder = to_radeon_encoder(encoder);
297
298 if (!radeon_encoder->enc_priv)
299 return 0;
300
301 dig = radeon_encoder->enc_priv;
302 dig->coherent_mode = val ? true : false;
303 radeon_property_change_mode(&radeon_encoder->base);
304 }
305
306 if (property == rdev->mode_info.tv_std_property) {
307 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
308 if (!encoder) {
309 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
310 }
311
312 if (!encoder)
313 return 0;
314
315 radeon_encoder = to_radeon_encoder(encoder);
316 if (!radeon_encoder->enc_priv)
317 return 0;
Alex Deucher643acac2010-04-05 23:57:52 -0400318 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
Dave Airlie445282d2009-09-09 17:40:54 +1000319 struct radeon_encoder_atom_dac *dac_int;
320 dac_int = radeon_encoder->enc_priv;
321 dac_int->tv_std = val;
322 } else {
323 struct radeon_encoder_tv_dac *dac_int;
324 dac_int = radeon_encoder->enc_priv;
325 dac_int->tv_std = val;
326 }
327 radeon_property_change_mode(&radeon_encoder->base);
328 }
329
330 if (property == rdev->mode_info.load_detect_property) {
331 struct radeon_connector *radeon_connector =
332 to_radeon_connector(connector);
333
334 if (val == 0)
335 radeon_connector->dac_load_detect = false;
336 else
337 radeon_connector->dac_load_detect = true;
338 }
339
340 if (property == rdev->mode_info.tmds_pll_property) {
341 struct radeon_encoder_int_tmds *tmds = NULL;
342 bool ret = false;
343 /* need to find digital encoder on connector */
344 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
345 if (!encoder)
346 return 0;
347
348 radeon_encoder = to_radeon_encoder(encoder);
349
350 tmds = radeon_encoder->enc_priv;
351 if (!tmds)
352 return 0;
353
354 if (val == 0) {
355 if (rdev->is_atom_bios)
356 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
357 else
358 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
359 }
360 if (val == 1 || ret == false) {
361 radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
362 }
363 radeon_property_change_mode(&radeon_encoder->base);
364 }
365
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200366 return 0;
367}
368
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200369static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
370 struct drm_connector *connector)
371{
372 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400373 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200374
375 /* Try to get native mode details from EDID if necessary */
Alex Deucherde2103e2009-10-09 15:14:30 -0400376 if (!native_mode->clock) {
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200377 struct drm_display_mode *t, *mode;
378
379 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
Alex Deucherde2103e2009-10-09 15:14:30 -0400380 if (mode->hdisplay == native_mode->hdisplay &&
381 mode->vdisplay == native_mode->vdisplay) {
382 *native_mode = *mode;
383 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200384 DRM_INFO("Determined LVDS native mode details from EDID\n");
385 break;
386 }
387 }
388 }
Alex Deucherde2103e2009-10-09 15:14:30 -0400389 if (!native_mode->clock) {
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200390 DRM_INFO("No LVDS native mode details, disabling RMX\n");
391 radeon_encoder->rmx_type = RMX_OFF;
392 }
393}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200394
395static int radeon_lvds_get_modes(struct drm_connector *connector)
396{
397 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
398 struct drm_encoder *encoder;
399 int ret = 0;
400 struct drm_display_mode *mode;
401
402 if (radeon_connector->ddc_bus) {
403 ret = radeon_ddc_get_modes(radeon_connector);
404 if (ret > 0) {
Alex Deucher7747b712009-09-11 11:15:43 -0400405 encoder = radeon_best_single_encoder(connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200406 if (encoder) {
407 radeon_fixup_lvds_native_mode(encoder, connector);
Alex Deucher7747b712009-09-11 11:15:43 -0400408 /* add scaled modes */
409 radeon_add_common_modes(encoder, connector);
Michel Dänzer8dfaa8a2009-09-15 17:09:27 +0200410 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200411 return ret;
412 }
413 }
414
415 encoder = radeon_best_single_encoder(connector);
416 if (!encoder)
417 return 0;
418
419 /* we have no EDID modes */
420 mode = radeon_fp_native_mode(encoder);
421 if (mode) {
422 ret = 1;
423 drm_mode_probed_add(connector, mode);
Alex Deucher7747b712009-09-11 11:15:43 -0400424 /* add scaled modes */
425 radeon_add_common_modes(encoder, connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200426 }
Alex Deucher923f6842009-09-10 17:53:39 -0400427
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200428 return ret;
429}
430
431static int radeon_lvds_mode_valid(struct drm_connector *connector,
432 struct drm_display_mode *mode)
433{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500434 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
435
436 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
437 return MODE_PANEL;
438
439 if (encoder) {
440 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
441 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
442
443 /* AVIVO hardware supports downscaling modes larger than the panel
444 * to the panel size, but I'm not sure this is desirable.
445 */
446 if ((mode->hdisplay > native_mode->hdisplay) ||
447 (mode->vdisplay > native_mode->vdisplay))
448 return MODE_PANEL;
449
450 /* if scaling is disabled, block non-native modes */
451 if (radeon_encoder->rmx_type == RMX_OFF) {
452 if ((mode->hdisplay != native_mode->hdisplay) ||
453 (mode->vdisplay != native_mode->vdisplay))
454 return MODE_PANEL;
455 }
456 }
457
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200458 return MODE_OK;
459}
460
461static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connector)
462{
Alex Deucher0549a0612009-10-09 18:41:19 -0400463 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher2ffb8422009-10-08 13:02:19 -0400464 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
Alex Deucher0549a0612009-10-09 18:41:19 -0400465 enum drm_connector_status ret = connector_status_disconnected;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400466
467 if (encoder) {
468 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherde2103e2009-10-09 15:14:30 -0400469 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
Alex Deucher2ffb8422009-10-08 13:02:19 -0400470
471 /* check if panel is valid */
Alex Deucherde2103e2009-10-09 15:14:30 -0400472 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
Alex Deucher2ffb8422009-10-08 13:02:19 -0400473 ret = connector_status_connected;
474
475 }
Alex Deucher0549a0612009-10-09 18:41:19 -0400476
477 /* check for edid as well */
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400478 if (radeon_connector->edid)
479 ret = connector_status_connected;
480 else {
481 if (radeon_connector->ddc_bus) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400482 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
483 &radeon_connector->ddc_bus->adapter);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400484 if (radeon_connector->edid)
485 ret = connector_status_connected;
486 }
Alex Deucher0549a0612009-10-09 18:41:19 -0400487 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200488 /* check acpi lid status ??? */
Alex Deucher2ffb8422009-10-08 13:02:19 -0400489
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200490 radeon_connector_update_scratch_regs(connector, ret);
491 return ret;
492}
493
494static void radeon_connector_destroy(struct drm_connector *connector)
495{
496 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
497
498 if (radeon_connector->ddc_bus)
499 radeon_i2c_destroy(radeon_connector->ddc_bus);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400500 if (radeon_connector->edid)
501 kfree(radeon_connector->edid);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200502 kfree(radeon_connector->con_priv);
503 drm_sysfs_connector_remove(connector);
504 drm_connector_cleanup(connector);
505 kfree(connector);
506}
507
Dave Airlie445282d2009-09-09 17:40:54 +1000508static int radeon_lvds_set_property(struct drm_connector *connector,
509 struct drm_property *property,
510 uint64_t value)
511{
512 struct drm_device *dev = connector->dev;
513 struct radeon_encoder *radeon_encoder;
514 enum radeon_rmx_type rmx_type;
515
516 DRM_DEBUG("\n");
517 if (property != dev->mode_config.scaling_mode_property)
518 return 0;
519
520 if (connector->encoder)
521 radeon_encoder = to_radeon_encoder(connector->encoder);
522 else {
523 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
524 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
525 }
526
527 switch (value) {
528 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
529 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
530 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
531 default:
532 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
533 }
534 if (radeon_encoder->rmx_type == rmx_type)
535 return 0;
536
537 radeon_encoder->rmx_type = rmx_type;
538
539 radeon_property_change_mode(&radeon_encoder->base);
540 return 0;
541}
542
543
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200544struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
545 .get_modes = radeon_lvds_get_modes,
546 .mode_valid = radeon_lvds_mode_valid,
547 .best_encoder = radeon_best_single_encoder,
548};
549
550struct drm_connector_funcs radeon_lvds_connector_funcs = {
551 .dpms = drm_helper_connector_dpms,
552 .detect = radeon_lvds_detect,
553 .fill_modes = drm_helper_probe_single_connector_modes,
554 .destroy = radeon_connector_destroy,
Dave Airlie445282d2009-09-09 17:40:54 +1000555 .set_property = radeon_lvds_set_property,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200556};
557
558static int radeon_vga_get_modes(struct drm_connector *connector)
559{
560 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
561 int ret;
562
563 ret = radeon_ddc_get_modes(radeon_connector);
564
565 return ret;
566}
567
568static int radeon_vga_mode_valid(struct drm_connector *connector,
569 struct drm_display_mode *mode)
570{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500571 /* XXX check mode bandwidth */
572 /* XXX verify against max DAC output frequency */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200573 return MODE_OK;
574}
575
576static enum drm_connector_status radeon_vga_detect(struct drm_connector *connector)
577{
578 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
579 struct drm_encoder *encoder;
580 struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000581 bool dret = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200582 enum drm_connector_status ret = connector_status_disconnected;
583
Dave Airlie4ce001a2009-08-13 16:32:14 +1000584 encoder = radeon_best_single_encoder(connector);
585 if (!encoder)
586 ret = connector_status_disconnected;
587
Dave Airlieeb6b6d72010-02-25 13:44:04 +1000588 if (radeon_connector->ddc_bus)
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000589 dret = radeon_ddc_probe(radeon_connector);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400590 if (dret) {
591 if (radeon_connector->edid) {
592 kfree(radeon_connector->edid);
593 radeon_connector->edid = NULL;
594 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400595 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400596
597 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +0100598 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
599 drm_get_connector_name(connector));
600 ret = connector_status_connected;
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400601 } else {
602 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
603
604 /* some oems have boards with separate digital and analog connectors
605 * with a shared ddc line (often vga + hdmi)
606 */
607 if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
608 kfree(radeon_connector->edid);
609 radeon_connector->edid = NULL;
610 ret = connector_status_disconnected;
611 } else
612 ret = connector_status_connected;
613 }
614 } else {
Darren Jenkinsd8a7f792009-12-30 12:22:55 +1100615 if (radeon_connector->dac_load_detect && encoder) {
Dave Airlie445282d2009-09-09 17:40:54 +1000616 encoder_funcs = encoder->helper_private;
617 ret = encoder_funcs->detect(encoder, connector);
618 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200619 }
620
Dave Airlie4ce001a2009-08-13 16:32:14 +1000621 if (ret == connector_status_connected)
622 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200623 radeon_connector_update_scratch_regs(connector, ret);
624 return ret;
625}
626
627struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
628 .get_modes = radeon_vga_get_modes,
629 .mode_valid = radeon_vga_mode_valid,
630 .best_encoder = radeon_best_single_encoder,
631};
632
633struct drm_connector_funcs radeon_vga_connector_funcs = {
634 .dpms = drm_helper_connector_dpms,
635 .detect = radeon_vga_detect,
636 .fill_modes = drm_helper_probe_single_connector_modes,
637 .destroy = radeon_connector_destroy,
638 .set_property = radeon_connector_set_property,
639};
640
Dave Airlie4ce001a2009-08-13 16:32:14 +1000641static int radeon_tv_get_modes(struct drm_connector *connector)
642{
643 struct drm_device *dev = connector->dev;
Alex Deucher923f6842009-09-10 17:53:39 -0400644 struct radeon_device *rdev = dev->dev_private;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000645 struct drm_display_mode *tv_mode;
Alex Deucher923f6842009-09-10 17:53:39 -0400646 struct drm_encoder *encoder;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000647
Alex Deucher923f6842009-09-10 17:53:39 -0400648 encoder = radeon_best_single_encoder(connector);
649 if (!encoder)
650 return 0;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000651
Alex Deucher923f6842009-09-10 17:53:39 -0400652 /* avivo chips can scale any mode */
653 if (rdev->family >= CHIP_RS600)
654 /* add scaled modes */
655 radeon_add_common_modes(encoder, connector);
656 else {
657 /* only 800x600 is supported right now on pre-avivo chips */
Dave Airlied50ba252009-09-23 14:44:08 +1000658 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
Alex Deucher923f6842009-09-10 17:53:39 -0400659 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
660 drm_mode_probed_add(connector, tv_mode);
661 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000662 return 1;
663}
664
665static int radeon_tv_mode_valid(struct drm_connector *connector,
666 struct drm_display_mode *mode)
667{
Alex Deuchera3fa6322009-11-05 11:57:07 -0500668 if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
669 return MODE_CLOCK_RANGE;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000670 return MODE_OK;
671}
672
673static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector)
674{
675 struct drm_encoder *encoder;
676 struct drm_encoder_helper_funcs *encoder_funcs;
Dave Airlie445282d2009-09-09 17:40:54 +1000677 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
678 enum drm_connector_status ret = connector_status_disconnected;
679
680 if (!radeon_connector->dac_load_detect)
681 return ret;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000682
683 encoder = radeon_best_single_encoder(connector);
684 if (!encoder)
685 ret = connector_status_disconnected;
686 else {
687 encoder_funcs = encoder->helper_private;
688 ret = encoder_funcs->detect(encoder, connector);
689 }
690 if (ret == connector_status_connected)
691 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
692 radeon_connector_update_scratch_regs(connector, ret);
693 return ret;
694}
695
696struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
697 .get_modes = radeon_tv_get_modes,
698 .mode_valid = radeon_tv_mode_valid,
699 .best_encoder = radeon_best_single_encoder,
700};
701
702struct drm_connector_funcs radeon_tv_connector_funcs = {
703 .dpms = drm_helper_connector_dpms,
704 .detect = radeon_tv_detect,
705 .fill_modes = drm_helper_probe_single_connector_modes,
706 .destroy = radeon_connector_destroy,
707 .set_property = radeon_connector_set_property,
708};
709
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200710static int radeon_dvi_get_modes(struct drm_connector *connector)
711{
712 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
713 int ret;
714
715 ret = radeon_ddc_get_modes(radeon_connector);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200716 return ret;
717}
718
Dave Airlie4ce001a2009-08-13 16:32:14 +1000719/*
720 * DVI is complicated
721 * Do a DDC probe, if DDC probe passes, get the full EDID so
722 * we can do analog/digital monitor detection at this point.
723 * If the monitor is an analog monitor or we got no DDC,
724 * we need to find the DAC encoder object for this connector.
725 * If we got no DDC, we do load detection on the DAC encoder object.
726 * If we got analog DDC or load detection passes on the DAC encoder
727 * we have to check if this analog encoder is shared with anyone else (TV)
728 * if its shared we have to set the other connector to disconnected.
729 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200730static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector)
731{
732 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000733 struct drm_encoder *encoder = NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200734 struct drm_encoder_helper_funcs *encoder_funcs;
735 struct drm_mode_object *obj;
736 int i;
737 enum drm_connector_status ret = connector_status_disconnected;
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000738 bool dret = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200739
Dave Airlieeb6b6d72010-02-25 13:44:04 +1000740 if (radeon_connector->ddc_bus)
Dave Airlie4b9d2a22010-02-08 13:16:55 +1000741 dret = radeon_ddc_probe(radeon_connector);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000742 if (dret) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400743 if (radeon_connector->edid) {
744 kfree(radeon_connector->edid);
745 radeon_connector->edid = NULL;
746 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000747 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200748
Dave Airlie4ce001a2009-08-13 16:32:14 +1000749 if (!radeon_connector->edid) {
Jerome Glissef82f5f32009-11-12 14:13:53 +0100750 DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
751 drm_get_connector_name(connector));
Dave Airlie4ce001a2009-08-13 16:32:14 +1000752 } else {
753 radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200754
Alex Deucher0294cf4f2009-10-15 16:16:35 -0400755 /* some oems have boards with separate digital and analog connectors
756 * with a shared ddc line (often vga + hdmi)
757 */
758 if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
759 kfree(radeon_connector->edid);
760 radeon_connector->edid = NULL;
761 ret = connector_status_disconnected;
762 } else
763 ret = connector_status_connected;
Alex Deucher71407c42009-11-17 15:44:01 -0500764
765 /* multiple connectors on the same encoder with the same ddc line
766 * This tends to be HDMI and DVI on the same encoder with the
767 * same ddc line. If the edid says HDMI, consider the HDMI port
768 * connected and the DVI port disconnected. If the edid doesn't
769 * say HDMI, vice versa.
770 */
Alex Deucherd3932d62010-02-19 02:13:56 -0500771 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
Alex Deucher71407c42009-11-17 15:44:01 -0500772 struct drm_device *dev = connector->dev;
773 struct drm_connector *list_connector;
774 struct radeon_connector *list_radeon_connector;
775 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
776 if (connector == list_connector)
777 continue;
778 list_radeon_connector = to_radeon_connector(list_connector);
779 if (radeon_connector->devices == list_radeon_connector->devices) {
780 if (drm_detect_hdmi_monitor(radeon_connector->edid)) {
781 if (connector->connector_type == DRM_MODE_CONNECTOR_DVID) {
782 kfree(radeon_connector->edid);
783 radeon_connector->edid = NULL;
784 ret = connector_status_disconnected;
785 }
786 } else {
787 if ((connector->connector_type == DRM_MODE_CONNECTOR_HDMIA) ||
788 (connector->connector_type == DRM_MODE_CONNECTOR_HDMIB)) {
789 kfree(radeon_connector->edid);
790 radeon_connector->edid = NULL;
791 ret = connector_status_disconnected;
792 }
793 }
794 }
795 }
796 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200797 }
798 }
799
Dave Airlie4ce001a2009-08-13 16:32:14 +1000800 if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
801 goto out;
802
803 /* find analog encoder */
Dave Airlie445282d2009-09-09 17:40:54 +1000804 if (radeon_connector->dac_load_detect) {
805 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
806 if (connector->encoder_ids[i] == 0)
807 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000808
Dave Airlie445282d2009-09-09 17:40:54 +1000809 obj = drm_mode_object_find(connector->dev,
810 connector->encoder_ids[i],
811 DRM_MODE_OBJECT_ENCODER);
812 if (!obj)
813 continue;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000814
Dave Airlie445282d2009-09-09 17:40:54 +1000815 encoder = obj_to_encoder(obj);
Dave Airlie4ce001a2009-08-13 16:32:14 +1000816
Dave Airlie445282d2009-09-09 17:40:54 +1000817 encoder_funcs = encoder->helper_private;
818 if (encoder_funcs->detect) {
819 if (ret != connector_status_connected) {
820 ret = encoder_funcs->detect(encoder, connector);
821 if (ret == connector_status_connected) {
822 radeon_connector->use_digital = false;
823 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000824 }
Dave Airlie445282d2009-09-09 17:40:54 +1000825 break;
Dave Airlie4ce001a2009-08-13 16:32:14 +1000826 }
Dave Airlie4ce001a2009-08-13 16:32:14 +1000827 }
828 }
829
830 if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
831 encoder) {
832 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
833 }
834
835out:
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200836 /* updated in get modes as well since we need to know if it's analog or digital */
837 radeon_connector_update_scratch_regs(connector, ret);
838 return ret;
839}
840
841/* okay need to be smart in here about which encoder to pick */
842struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
843{
844 int enc_id = connector->encoder_ids[0];
845 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
846 struct drm_mode_object *obj;
847 struct drm_encoder *encoder;
848 int i;
849 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
850 if (connector->encoder_ids[i] == 0)
851 break;
852
853 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
854 if (!obj)
855 continue;
856
857 encoder = obj_to_encoder(obj);
858
Dave Airlie4ce001a2009-08-13 16:32:14 +1000859 if (radeon_connector->use_digital == true) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200860 if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
861 return encoder;
862 } else {
863 if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
864 encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
865 return encoder;
866 }
867 }
868
869 /* see if we have a default encoder TODO */
870
871 /* then check use digitial */
872 /* pick the first one */
873 if (enc_id) {
874 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
875 if (!obj)
876 return NULL;
877 encoder = obj_to_encoder(obj);
878 return encoder;
879 }
880 return NULL;
881}
882
Dave Airlied50ba252009-09-23 14:44:08 +1000883static void radeon_dvi_force(struct drm_connector *connector)
884{
885 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
886 if (connector->force == DRM_FORCE_ON)
887 radeon_connector->use_digital = false;
888 if (connector->force == DRM_FORCE_ON_DIGITAL)
889 radeon_connector->use_digital = true;
890}
891
Alex Deuchera3fa6322009-11-05 11:57:07 -0500892static int radeon_dvi_mode_valid(struct drm_connector *connector,
893 struct drm_display_mode *mode)
894{
Alex Deucher1b242032010-01-11 15:02:31 -0500895 struct drm_device *dev = connector->dev;
896 struct radeon_device *rdev = dev->dev_private;
Alex Deuchera3fa6322009-11-05 11:57:07 -0500897 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
898
899 /* XXX check mode bandwidth */
900
Alex Deucher1b242032010-01-11 15:02:31 -0500901 /* clocks over 135 MHz have heat issues with DVI on RV100 */
902 if (radeon_connector->use_digital &&
903 (rdev->family == CHIP_RV100) &&
904 (mode->clock > 135000))
905 return MODE_CLOCK_HIGH;
906
Alex Deuchera3fa6322009-11-05 11:57:07 -0500907 if (radeon_connector->use_digital && (mode->clock > 165000)) {
908 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
909 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
910 (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
911 return MODE_OK;
912 else
913 return MODE_CLOCK_HIGH;
914 }
915 return MODE_OK;
916}
917
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200918struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
919 .get_modes = radeon_dvi_get_modes,
Alex Deuchera3fa6322009-11-05 11:57:07 -0500920 .mode_valid = radeon_dvi_mode_valid,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200921 .best_encoder = radeon_dvi_encoder,
922};
923
924struct drm_connector_funcs radeon_dvi_connector_funcs = {
925 .dpms = drm_helper_connector_dpms,
926 .detect = radeon_dvi_detect,
927 .fill_modes = drm_helper_probe_single_connector_modes,
928 .set_property = radeon_connector_set_property,
929 .destroy = radeon_connector_destroy,
Dave Airlied50ba252009-09-23 14:44:08 +1000930 .force = radeon_dvi_force,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200931};
932
Alex Deucherffd09c62009-11-24 16:13:23 -0500933static void radeon_dp_connector_destroy(struct drm_connector *connector)
934{
935 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
936 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
937
938 if (radeon_connector->ddc_bus)
939 radeon_i2c_destroy(radeon_connector->ddc_bus);
940 if (radeon_connector->edid)
941 kfree(radeon_connector->edid);
942 if (radeon_dig_connector->dp_i2c_bus)
Alex Deucherac1aade2010-03-14 12:22:44 -0400943 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
Alex Deucherffd09c62009-11-24 16:13:23 -0500944 kfree(radeon_connector->con_priv);
945 drm_sysfs_connector_remove(connector);
946 drm_connector_cleanup(connector);
947 kfree(connector);
948}
949
Dave Airlie746c1aa2009-12-08 07:07:28 +1000950static int radeon_dp_get_modes(struct drm_connector *connector)
951{
952 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
953 int ret;
954
955 ret = radeon_ddc_get_modes(radeon_connector);
956 return ret;
957}
958
959static enum drm_connector_status radeon_dp_detect(struct drm_connector *connector)
960{
961 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Dave Airlie746c1aa2009-12-08 07:07:28 +1000962 enum drm_connector_status ret = connector_status_disconnected;
Alex Deucher4143e912009-11-23 18:02:35 -0500963 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
964 u8 sink_type;
Dave Airlie746c1aa2009-12-08 07:07:28 +1000965
966 if (radeon_connector->edid) {
967 kfree(radeon_connector->edid);
968 radeon_connector->edid = NULL;
969 }
970
971 sink_type = radeon_dp_getsinktype(radeon_connector);
Alex Deucher196c58d2010-01-07 14:22:32 -0500972 if ((sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
973 (sink_type == CONNECTOR_OBJECT_ID_eDP)) {
Alex Deucher9fa05c92009-11-27 13:01:46 -0500974 if (radeon_dp_getdpcd(radeon_connector)) {
975 radeon_dig_connector->dp_sink_type = sink_type;
976 ret = connector_status_connected;
977 }
Alex Deucher4143e912009-11-23 18:02:35 -0500978 } else {
Alex Deucher4143e912009-11-23 18:02:35 -0500979 if (radeon_ddc_probe(radeon_connector)) {
980 radeon_dig_connector->dp_sink_type = sink_type;
981 ret = connector_status_connected;
982 }
Dave Airlie746c1aa2009-12-08 07:07:28 +1000983 }
Alex Deucher4143e912009-11-23 18:02:35 -0500984
Dave Airlie746c1aa2009-12-08 07:07:28 +1000985 return ret;
986}
987
Alex Deucher5801ead2009-11-24 13:32:59 -0500988static int radeon_dp_mode_valid(struct drm_connector *connector,
989 struct drm_display_mode *mode)
990{
991 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
992 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
993
994 /* XXX check mode bandwidth */
995
Alex Deucher196c58d2010-01-07 14:22:32 -0500996 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
997 (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
Alex Deucher5801ead2009-11-24 13:32:59 -0500998 return radeon_dp_mode_valid_helper(radeon_connector, mode);
999 else
1000 return MODE_OK;
1001}
1002
Dave Airlie746c1aa2009-12-08 07:07:28 +10001003struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1004 .get_modes = radeon_dp_get_modes,
Alex Deucher5801ead2009-11-24 13:32:59 -05001005 .mode_valid = radeon_dp_mode_valid,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001006 .best_encoder = radeon_dvi_encoder,
1007};
1008
1009struct drm_connector_funcs radeon_dp_connector_funcs = {
1010 .dpms = drm_helper_connector_dpms,
1011 .detect = radeon_dp_detect,
1012 .fill_modes = drm_helper_probe_single_connector_modes,
1013 .set_property = radeon_connector_set_property,
Alex Deucherffd09c62009-11-24 16:13:23 -05001014 .destroy = radeon_dp_connector_destroy,
Dave Airlie746c1aa2009-12-08 07:07:28 +10001015 .force = radeon_dvi_force,
1016};
1017
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001018void
1019radeon_add_atom_connector(struct drm_device *dev,
1020 uint32_t connector_id,
1021 uint32_t supported_device,
1022 int connector_type,
1023 struct radeon_i2c_bus_rec *i2c_bus,
1024 bool linkb,
Alex Deucherb75fad02009-11-05 13:16:01 -05001025 uint32_t igp_lane_info,
Alex Deuchereed45b32009-12-04 14:45:27 -05001026 uint16_t connector_object_id,
1027 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001028{
Dave Airlie445282d2009-09-09 17:40:54 +10001029 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001030 struct drm_connector *connector;
1031 struct radeon_connector *radeon_connector;
1032 struct radeon_connector_atom_dig *radeon_dig_connector;
1033 uint32_t subpixel_order = SubPixelNone;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001034 bool shared_ddc = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001035
1036 /* fixme - tv/cv/din */
Dave Airlie4ce001a2009-08-13 16:32:14 +10001037 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001038 return;
1039
1040 /* see if we already added it */
1041 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1042 radeon_connector = to_radeon_connector(connector);
1043 if (radeon_connector->connector_id == connector_id) {
1044 radeon_connector->devices |= supported_device;
1045 return;
1046 }
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001047 if (radeon_connector->ddc_bus && i2c_bus->valid) {
Alex Deucherd3932d62010-02-19 02:13:56 -05001048 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001049 radeon_connector->shared_ddc = true;
1050 shared_ddc = true;
1051 }
1052 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001053 }
1054
1055 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1056 if (!radeon_connector)
1057 return;
1058
1059 connector = &radeon_connector->base;
1060
1061 radeon_connector->connector_id = connector_id;
1062 radeon_connector->devices = supported_device;
Alex Deucher0294cf4f2009-10-15 16:16:35 -04001063 radeon_connector->shared_ddc = shared_ddc;
Alex Deucherb75fad02009-11-05 13:16:01 -05001064 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05001065 radeon_connector->hpd = *hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001066 switch (connector_type) {
1067 case DRM_MODE_CONNECTOR_VGA:
1068 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001069 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001070 if (i2c_bus->valid) {
1071 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1072 if (!radeon_connector->ddc_bus)
1073 goto failed;
1074 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001075 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001076 drm_connector_attach_property(&radeon_connector->base,
1077 rdev->mode_info.load_detect_property,
1078 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001079 break;
1080 case DRM_MODE_CONNECTOR_DVIA:
1081 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001082 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001083 if (i2c_bus->valid) {
1084 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1085 if (!radeon_connector->ddc_bus)
1086 goto failed;
1087 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001088 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001089 drm_connector_attach_property(&radeon_connector->base,
1090 rdev->mode_info.load_detect_property,
1091 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001092 break;
1093 case DRM_MODE_CONNECTOR_DVII:
1094 case DRM_MODE_CONNECTOR_DVID:
1095 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1096 if (!radeon_dig_connector)
1097 goto failed;
1098 radeon_dig_connector->linkb = linkb;
1099 radeon_dig_connector->igp_lane_info = igp_lane_info;
1100 radeon_connector->con_priv = radeon_dig_connector;
1101 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001102 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001103 if (i2c_bus->valid) {
1104 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1105 if (!radeon_connector->ddc_bus)
1106 goto failed;
1107 }
1108 subpixel_order = SubPixelHorizontalRGB;
Dave Airlie445282d2009-09-09 17:40:54 +10001109 drm_connector_attach_property(&radeon_connector->base,
1110 rdev->mode_info.coherent_mode_property,
1111 1);
Alex Deucher390d0bb2009-12-08 12:48:20 -05001112 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1113 radeon_connector->dac_load_detect = true;
1114 drm_connector_attach_property(&radeon_connector->base,
1115 rdev->mode_info.load_detect_property,
1116 1);
1117 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001118 break;
1119 case DRM_MODE_CONNECTOR_HDMIA:
1120 case DRM_MODE_CONNECTOR_HDMIB:
1121 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1122 if (!radeon_dig_connector)
1123 goto failed;
1124 radeon_dig_connector->linkb = linkb;
1125 radeon_dig_connector->igp_lane_info = igp_lane_info;
1126 radeon_connector->con_priv = radeon_dig_connector;
1127 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001128 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001129 if (i2c_bus->valid) {
1130 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI");
1131 if (!radeon_connector->ddc_bus)
1132 goto failed;
1133 }
Dave Airlie445282d2009-09-09 17:40:54 +10001134 drm_connector_attach_property(&radeon_connector->base,
1135 rdev->mode_info.coherent_mode_property,
1136 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001137 subpixel_order = SubPixelHorizontalRGB;
1138 break;
1139 case DRM_MODE_CONNECTOR_DisplayPort:
Alex Deucher196c58d2010-01-07 14:22:32 -05001140 case DRM_MODE_CONNECTOR_eDP:
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001141 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1142 if (!radeon_dig_connector)
1143 goto failed;
1144 radeon_dig_connector->linkb = linkb;
1145 radeon_dig_connector->igp_lane_info = igp_lane_info;
1146 radeon_connector->con_priv = radeon_dig_connector;
Dave Airlie746c1aa2009-12-08 07:07:28 +10001147 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001148 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001149 if (i2c_bus->valid) {
Alex Deucher390d0bb2009-12-08 12:48:20 -05001150 /* add DP i2c bus */
Alex Deucher196c58d2010-01-07 14:22:32 -05001151 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1152 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1153 else
1154 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
Alex Deucher390d0bb2009-12-08 12:48:20 -05001155 if (!radeon_dig_connector->dp_i2c_bus)
1156 goto failed;
Alex Deucher196c58d2010-01-07 14:22:32 -05001157 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1158 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "eDP");
1159 else
1160 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001161 if (!radeon_connector->ddc_bus)
1162 goto failed;
1163 }
1164 subpixel_order = SubPixelHorizontalRGB;
Alex Deucher390d0bb2009-12-08 12:48:20 -05001165 drm_connector_attach_property(&radeon_connector->base,
1166 rdev->mode_info.coherent_mode_property,
1167 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001168 break;
1169 case DRM_MODE_CONNECTOR_SVIDEO:
1170 case DRM_MODE_CONNECTOR_Composite:
1171 case DRM_MODE_CONNECTOR_9PinDIN:
Dave Airlie4ce001a2009-08-13 16:32:14 +10001172 if (radeon_tv == 1) {
1173 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001174 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
Dave Airlie74bf2ad2009-09-28 15:31:10 +10001175 radeon_connector->dac_load_detect = true;
1176 drm_connector_attach_property(&radeon_connector->base,
1177 rdev->mode_info.load_detect_property,
1178 1);
Alex Deuchered160142009-12-01 14:12:14 -05001179 drm_connector_attach_property(&radeon_connector->base,
1180 rdev->mode_info.tv_std_property,
Alex Deucherd79766f2009-12-17 19:00:29 -05001181 radeon_atombios_get_tv_info(rdev));
Dave Airlie4ce001a2009-08-13 16:32:14 +10001182 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001183 break;
1184 case DRM_MODE_CONNECTOR_LVDS:
1185 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1186 if (!radeon_dig_connector)
1187 goto failed;
1188 radeon_dig_connector->linkb = linkb;
1189 radeon_dig_connector->igp_lane_info = igp_lane_info;
1190 radeon_connector->con_priv = radeon_dig_connector;
1191 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001192 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001193 if (i2c_bus->valid) {
1194 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1195 if (!radeon_connector->ddc_bus)
1196 goto failed;
1197 }
Dave Airlie445282d2009-09-09 17:40:54 +10001198 drm_connector_attach_property(&radeon_connector->base,
1199 dev->mode_config.scaling_mode_property,
1200 DRM_MODE_SCALE_FULLSCREEN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001201 subpixel_order = SubPixelHorizontalRGB;
1202 break;
1203 }
1204
1205 connector->display_info.subpixel_order = subpixel_order;
1206 drm_sysfs_connector_add(connector);
1207 return;
1208
1209failed:
1210 if (radeon_connector->ddc_bus)
1211 radeon_i2c_destroy(radeon_connector->ddc_bus);
1212 drm_connector_cleanup(connector);
1213 kfree(connector);
1214}
1215
1216void
1217radeon_add_legacy_connector(struct drm_device *dev,
1218 uint32_t connector_id,
1219 uint32_t supported_device,
1220 int connector_type,
Alex Deucherb75fad02009-11-05 13:16:01 -05001221 struct radeon_i2c_bus_rec *i2c_bus,
Alex Deuchereed45b32009-12-04 14:45:27 -05001222 uint16_t connector_object_id,
1223 struct radeon_hpd *hpd)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001224{
Dave Airlie445282d2009-09-09 17:40:54 +10001225 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001226 struct drm_connector *connector;
1227 struct radeon_connector *radeon_connector;
1228 uint32_t subpixel_order = SubPixelNone;
1229
1230 /* fixme - tv/cv/din */
Dave Airlie4ce001a2009-08-13 16:32:14 +10001231 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001232 return;
1233
1234 /* see if we already added it */
1235 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1236 radeon_connector = to_radeon_connector(connector);
1237 if (radeon_connector->connector_id == connector_id) {
1238 radeon_connector->devices |= supported_device;
1239 return;
1240 }
1241 }
1242
1243 radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1244 if (!radeon_connector)
1245 return;
1246
1247 connector = &radeon_connector->base;
1248
1249 radeon_connector->connector_id = connector_id;
1250 radeon_connector->devices = supported_device;
Alex Deucherb75fad02009-11-05 13:16:01 -05001251 radeon_connector->connector_object_id = connector_object_id;
Alex Deuchereed45b32009-12-04 14:45:27 -05001252 radeon_connector->hpd = *hpd;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001253 switch (connector_type) {
1254 case DRM_MODE_CONNECTOR_VGA:
1255 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001256 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001257 if (i2c_bus->valid) {
1258 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1259 if (!radeon_connector->ddc_bus)
1260 goto failed;
1261 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001262 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001263 drm_connector_attach_property(&radeon_connector->base,
1264 rdev->mode_info.load_detect_property,
1265 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001266 break;
1267 case DRM_MODE_CONNECTOR_DVIA:
1268 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001269 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001270 if (i2c_bus->valid) {
1271 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1272 if (!radeon_connector->ddc_bus)
1273 goto failed;
1274 }
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001275 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001276 drm_connector_attach_property(&radeon_connector->base,
1277 rdev->mode_info.load_detect_property,
1278 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001279 break;
1280 case DRM_MODE_CONNECTOR_DVII:
1281 case DRM_MODE_CONNECTOR_DVID:
1282 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001283 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001284 if (i2c_bus->valid) {
1285 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1286 if (!radeon_connector->ddc_bus)
1287 goto failed;
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001288 radeon_connector->dac_load_detect = true;
Dave Airlie445282d2009-09-09 17:40:54 +10001289 drm_connector_attach_property(&radeon_connector->base,
1290 rdev->mode_info.load_detect_property,
1291 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001292 }
1293 subpixel_order = SubPixelHorizontalRGB;
1294 break;
1295 case DRM_MODE_CONNECTOR_SVIDEO:
1296 case DRM_MODE_CONNECTOR_Composite:
1297 case DRM_MODE_CONNECTOR_9PinDIN:
Dave Airlie4ce001a2009-08-13 16:32:14 +10001298 if (radeon_tv == 1) {
1299 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001300 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
Dave Airlie35e4b7a2009-09-25 11:56:50 +10001301 radeon_connector->dac_load_detect = true;
Jerome Glisse0beb81a2009-11-13 20:56:35 +01001302 /* RS400,RC410,RS480 chipset seems to report a lot
1303 * of false positive on load detect, we haven't yet
1304 * found a way to make load detect reliable on those
1305 * chipset, thus just disable it for TV.
1306 */
1307 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1308 radeon_connector->dac_load_detect = false;
Dave Airlie445282d2009-09-09 17:40:54 +10001309 drm_connector_attach_property(&radeon_connector->base,
1310 rdev->mode_info.load_detect_property,
Dave Airlie624ab4f2010-01-27 16:07:15 +10001311 radeon_connector->dac_load_detect);
Alex Deuchered160142009-12-01 14:12:14 -05001312 drm_connector_attach_property(&radeon_connector->base,
1313 rdev->mode_info.tv_std_property,
Alex Deucherd79766f2009-12-17 19:00:29 -05001314 radeon_combios_get_tv_info(rdev));
Dave Airlie4ce001a2009-08-13 16:32:14 +10001315 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001316 break;
1317 case DRM_MODE_CONNECTOR_LVDS:
1318 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
Dave Airlie0b4c0f32010-03-30 05:34:15 +00001319 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001320 if (i2c_bus->valid) {
1321 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1322 if (!radeon_connector->ddc_bus)
1323 goto failed;
1324 }
Dave Airlie445282d2009-09-09 17:40:54 +10001325 drm_connector_attach_property(&radeon_connector->base,
1326 dev->mode_config.scaling_mode_property,
1327 DRM_MODE_SCALE_FULLSCREEN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001328 subpixel_order = SubPixelHorizontalRGB;
1329 break;
1330 }
1331
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001332 connector->display_info.subpixel_order = subpixel_order;
1333 drm_sysfs_connector_add(connector);
1334 return;
1335
1336failed:
1337 if (radeon_connector->ddc_bus)
1338 radeon_i2c_destroy(radeon_connector->ddc_bus);
1339 drm_connector_cleanup(connector);
1340 kfree(connector);
1341}