9c2929c7e79f9cf3390a8171416eab8d312148fa
[linux-2.6.git] / drivers / gpu / drm / radeon / radeon_connectors.c
1 /*
2  * Copyright 2007-8 Advanced Micro Devices, Inc.
3  * Copyright 2008 Red Hat Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * Authors: Dave Airlie
24  *          Alex Deucher
25  */
26 #include "drmP.h"
27 #include "drm_edid.h"
28 #include "drm_crtc_helper.h"
29 #include "drm_fb_helper.h"
30 #include "radeon_drm.h"
31 #include "radeon.h"
32 #include "atom.h"
33
34 extern void
35 radeon_combios_connected_scratch_regs(struct drm_connector *connector,
36                                       struct drm_encoder *encoder,
37                                       bool connected);
38 extern void
39 radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
40                                        struct drm_encoder *encoder,
41                                        bool connected);
42
43 extern void
44 radeon_legacy_backlight_init(struct radeon_encoder *radeon_encoder,
45                              struct drm_connector *drm_connector);
46
47 void radeon_connector_hotplug(struct drm_connector *connector)
48 {
49         struct drm_device *dev = connector->dev;
50         struct radeon_device *rdev = dev->dev_private;
51         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
52
53         radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
54
55         /* powering up/down the eDP panel generates hpd events which
56          * can interfere with modesetting.
57          */
58         if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
59                 return;
60
61         /* pre-r600 did not always have the hpd pins mapped accurately to connectors */
62         if (rdev->family >= CHIP_R600) {
63                 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
64                         drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
65                 else
66                         drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
67         }
68 }
69
70 static void radeon_property_change_mode(struct drm_encoder *encoder)
71 {
72         struct drm_crtc *crtc = encoder->crtc;
73
74         if (crtc && crtc->enabled) {
75                 drm_crtc_helper_set_mode(crtc, &crtc->mode,
76                                          crtc->x, crtc->y, crtc->fb);
77         }
78 }
79 static void
80 radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
81 {
82         struct drm_device *dev = connector->dev;
83         struct radeon_device *rdev = dev->dev_private;
84         struct drm_encoder *best_encoder = NULL;
85         struct drm_encoder *encoder = NULL;
86         struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
87         struct drm_mode_object *obj;
88         bool connected;
89         int i;
90
91         best_encoder = connector_funcs->best_encoder(connector);
92
93         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
94                 if (connector->encoder_ids[i] == 0)
95                         break;
96
97                 obj = drm_mode_object_find(connector->dev,
98                                            connector->encoder_ids[i],
99                                            DRM_MODE_OBJECT_ENCODER);
100                 if (!obj)
101                         continue;
102
103                 encoder = obj_to_encoder(obj);
104
105                 if ((encoder == best_encoder) && (status == connector_status_connected))
106                         connected = true;
107                 else
108                         connected = false;
109
110                 if (rdev->is_atom_bios)
111                         radeon_atombios_connected_scratch_regs(connector, encoder, connected);
112                 else
113                         radeon_combios_connected_scratch_regs(connector, encoder, connected);
114
115         }
116 }
117
118 struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
119 {
120         struct drm_mode_object *obj;
121         struct drm_encoder *encoder;
122         int i;
123
124         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
125                 if (connector->encoder_ids[i] == 0)
126                         break;
127
128                 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
129                 if (!obj)
130                         continue;
131
132                 encoder = obj_to_encoder(obj);
133                 if (encoder->encoder_type == encoder_type)
134                         return encoder;
135         }
136         return NULL;
137 }
138
139 struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
140 {
141         int enc_id = connector->encoder_ids[0];
142         struct drm_mode_object *obj;
143         struct drm_encoder *encoder;
144
145         /* pick the encoder ids */
146         if (enc_id) {
147                 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
148                 if (!obj)
149                         return NULL;
150                 encoder = obj_to_encoder(obj);
151                 return encoder;
152         }
153         return NULL;
154 }
155
156 /*
157  * radeon_connector_analog_encoder_conflict_solve
158  * - search for other connectors sharing this encoder
159  *   if priority is true, then set them disconnected if this is connected
160  *   if priority is false, set us disconnected if they are connected
161  */
162 static enum drm_connector_status
163 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
164                                                struct drm_encoder *encoder,
165                                                enum drm_connector_status current_status,
166                                                bool priority)
167 {
168         struct drm_device *dev = connector->dev;
169         struct drm_connector *conflict;
170         struct radeon_connector *radeon_conflict;
171         int i;
172
173         list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
174                 if (conflict == connector)
175                         continue;
176
177                 radeon_conflict = to_radeon_connector(conflict);
178                 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
179                         if (conflict->encoder_ids[i] == 0)
180                                 break;
181
182                         /* if the IDs match */
183                         if (conflict->encoder_ids[i] == encoder->base.id) {
184                                 if (conflict->status != connector_status_connected)
185                                         continue;
186
187                                 if (radeon_conflict->use_digital)
188                                         continue;
189
190                                 if (priority == true) {
191                                         DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
192                                         DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(connector));
193                                         conflict->status = connector_status_disconnected;
194                                         radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
195                                 } else {
196                                         DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
197                                         DRM_DEBUG_KMS("in favor of %s\n", drm_get_connector_name(conflict));
198                                         current_status = connector_status_disconnected;
199                                 }
200                                 break;
201                         }
202                 }
203         }
204         return current_status;
205
206 }
207
208 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
209 {
210         struct drm_device *dev = encoder->dev;
211         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
212         struct drm_display_mode *mode = NULL;
213         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
214
215         if (native_mode->hdisplay != 0 &&
216             native_mode->vdisplay != 0 &&
217             native_mode->clock != 0) {
218                 mode = drm_mode_duplicate(dev, native_mode);
219                 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
220                 drm_mode_set_name(mode);
221
222                 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
223         } else if (native_mode->hdisplay != 0 &&
224                    native_mode->vdisplay != 0) {
225                 /* mac laptops without an edid */
226                 /* Note that this is not necessarily the exact panel mode,
227                  * but an approximation based on the cvt formula.  For these
228                  * systems we should ideally read the mode info out of the
229                  * registers or add a mode table, but this works and is much
230                  * simpler.
231                  */
232                 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
233                 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
234                 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
235         }
236         return mode;
237 }
238
239 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
240 {
241         struct drm_device *dev = encoder->dev;
242         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
243         struct drm_display_mode *mode = NULL;
244         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
245         int i;
246         struct mode_size {
247                 int w;
248                 int h;
249         } common_modes[17] = {
250                 { 640,  480},
251                 { 720,  480},
252                 { 800,  600},
253                 { 848,  480},
254                 {1024,  768},
255                 {1152,  768},
256                 {1280,  720},
257                 {1280,  800},
258                 {1280,  854},
259                 {1280,  960},
260                 {1280, 1024},
261                 {1440,  900},
262                 {1400, 1050},
263                 {1680, 1050},
264                 {1600, 1200},
265                 {1920, 1080},
266                 {1920, 1200}
267         };
268
269         for (i = 0; i < 17; i++) {
270                 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
271                         if (common_modes[i].w > 1024 ||
272                             common_modes[i].h > 768)
273                                 continue;
274                 }
275                 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
276                         if (common_modes[i].w > native_mode->hdisplay ||
277                             common_modes[i].h > native_mode->vdisplay ||
278                             (common_modes[i].w == native_mode->hdisplay &&
279                              common_modes[i].h == native_mode->vdisplay))
280                                 continue;
281                 }
282                 if (common_modes[i].w < 320 || common_modes[i].h < 200)
283                         continue;
284
285                 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
286                 drm_mode_probed_add(connector, mode);
287         }
288 }
289
290 int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
291                                   uint64_t val)
292 {
293         struct drm_device *dev = connector->dev;
294         struct radeon_device *rdev = dev->dev_private;
295         struct drm_encoder *encoder;
296         struct radeon_encoder *radeon_encoder;
297
298         if (property == rdev->mode_info.coherent_mode_property) {
299                 struct radeon_encoder_atom_dig *dig;
300                 bool new_coherent_mode;
301
302                 /* need to find digital encoder on connector */
303                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
304                 if (!encoder)
305                         return 0;
306
307                 radeon_encoder = to_radeon_encoder(encoder);
308
309                 if (!radeon_encoder->enc_priv)
310                         return 0;
311
312                 dig = radeon_encoder->enc_priv;
313                 new_coherent_mode = val ? true : false;
314                 if (dig->coherent_mode != new_coherent_mode) {
315                         dig->coherent_mode = new_coherent_mode;
316                         radeon_property_change_mode(&radeon_encoder->base);
317                 }
318         }
319
320         if (property == rdev->mode_info.underscan_property) {
321                 /* need to find digital encoder on connector */
322                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
323                 if (!encoder)
324                         return 0;
325
326                 radeon_encoder = to_radeon_encoder(encoder);
327
328                 if (radeon_encoder->underscan_type != val) {
329                         radeon_encoder->underscan_type = val;
330                         radeon_property_change_mode(&radeon_encoder->base);
331                 }
332         }
333
334         if (property == rdev->mode_info.underscan_hborder_property) {
335                 /* need to find digital encoder on connector */
336                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
337                 if (!encoder)
338                         return 0;
339
340                 radeon_encoder = to_radeon_encoder(encoder);
341
342                 if (radeon_encoder->underscan_hborder != val) {
343                         radeon_encoder->underscan_hborder = val;
344                         radeon_property_change_mode(&radeon_encoder->base);
345                 }
346         }
347
348         if (property == rdev->mode_info.underscan_vborder_property) {
349                 /* need to find digital encoder on connector */
350                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
351                 if (!encoder)
352                         return 0;
353
354                 radeon_encoder = to_radeon_encoder(encoder);
355
356                 if (radeon_encoder->underscan_vborder != val) {
357                         radeon_encoder->underscan_vborder = val;
358                         radeon_property_change_mode(&radeon_encoder->base);
359                 }
360         }
361
362         if (property == rdev->mode_info.tv_std_property) {
363                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
364                 if (!encoder) {
365                         encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
366                 }
367
368                 if (!encoder)
369                         return 0;
370
371                 radeon_encoder = to_radeon_encoder(encoder);
372                 if (!radeon_encoder->enc_priv)
373                         return 0;
374                 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
375                         struct radeon_encoder_atom_dac *dac_int;
376                         dac_int = radeon_encoder->enc_priv;
377                         dac_int->tv_std = val;
378                 } else {
379                         struct radeon_encoder_tv_dac *dac_int;
380                         dac_int = radeon_encoder->enc_priv;
381                         dac_int->tv_std = val;
382                 }
383                 radeon_property_change_mode(&radeon_encoder->base);
384         }
385
386         if (property == rdev->mode_info.load_detect_property) {
387                 struct radeon_connector *radeon_connector =
388                         to_radeon_connector(connector);
389
390                 if (val == 0)
391                         radeon_connector->dac_load_detect = false;
392                 else
393                         radeon_connector->dac_load_detect = true;
394         }
395
396         if (property == rdev->mode_info.tmds_pll_property) {
397                 struct radeon_encoder_int_tmds *tmds = NULL;
398                 bool ret = false;
399                 /* need to find digital encoder on connector */
400                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
401                 if (!encoder)
402                         return 0;
403
404                 radeon_encoder = to_radeon_encoder(encoder);
405
406                 tmds = radeon_encoder->enc_priv;
407                 if (!tmds)
408                         return 0;
409
410                 if (val == 0) {
411                         if (rdev->is_atom_bios)
412                                 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
413                         else
414                                 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
415                 }
416                 if (val == 1 || ret == false) {
417                         radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
418                 }
419                 radeon_property_change_mode(&radeon_encoder->base);
420         }
421
422         return 0;
423 }
424
425 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
426                                           struct drm_connector *connector)
427 {
428         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
429         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
430
431         /* Try to get native mode details from EDID if necessary */
432         if (!native_mode->clock) {
433                 struct drm_display_mode *t, *mode;
434
435                 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
436                         if (mode->hdisplay == native_mode->hdisplay &&
437                             mode->vdisplay == native_mode->vdisplay) {
438                                 *native_mode = *mode;
439                                 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
440                                 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
441                                 break;
442                         }
443                 }
444         }
445         if (!native_mode->clock) {
446                 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
447                 radeon_encoder->rmx_type = RMX_OFF;
448         }
449 }
450
451 static int radeon_lvds_get_modes(struct drm_connector *connector)
452 {
453         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
454         struct drm_encoder *encoder;
455         int ret = 0;
456         struct drm_display_mode *mode;
457
458         if (radeon_connector->ddc_bus) {
459                 ret = radeon_ddc_get_modes(radeon_connector);
460                 if (ret > 0) {
461                         encoder = radeon_best_single_encoder(connector);
462                         if (encoder) {
463                                 radeon_fixup_lvds_native_mode(encoder, connector);
464                                 /* add scaled modes */
465                                 radeon_add_common_modes(encoder, connector);
466                         }
467                         return ret;
468                 }
469         }
470
471         encoder = radeon_best_single_encoder(connector);
472         if (!encoder)
473                 return 0;
474
475         /* we have no EDID modes */
476         mode = radeon_fp_native_mode(encoder);
477         if (mode) {
478                 ret = 1;
479                 drm_mode_probed_add(connector, mode);
480                 /* add the width/height from vbios tables if available */
481                 connector->display_info.width_mm = mode->width_mm;
482                 connector->display_info.height_mm = mode->height_mm;
483                 /* add scaled modes */
484                 radeon_add_common_modes(encoder, connector);
485         }
486
487         return ret;
488 }
489
490 static int radeon_lvds_mode_valid(struct drm_connector *connector,
491                                   struct drm_display_mode *mode)
492 {
493         struct drm_encoder *encoder = radeon_best_single_encoder(connector);
494
495         if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
496                 return MODE_PANEL;
497
498         if (encoder) {
499                 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
500                 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
501
502                 /* AVIVO hardware supports downscaling modes larger than the panel
503                  * to the panel size, but I'm not sure this is desirable.
504                  */
505                 if ((mode->hdisplay > native_mode->hdisplay) ||
506                     (mode->vdisplay > native_mode->vdisplay))
507                         return MODE_PANEL;
508
509                 /* if scaling is disabled, block non-native modes */
510                 if (radeon_encoder->rmx_type == RMX_OFF) {
511                         if ((mode->hdisplay != native_mode->hdisplay) ||
512                             (mode->vdisplay != native_mode->vdisplay))
513                                 return MODE_PANEL;
514                 }
515         }
516
517         return MODE_OK;
518 }
519
520 static enum drm_connector_status
521 radeon_lvds_detect(struct drm_connector *connector, bool force)
522 {
523         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
524         struct drm_encoder *encoder = radeon_best_single_encoder(connector);
525         enum drm_connector_status ret = connector_status_disconnected;
526
527         if (encoder) {
528                 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
529                 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
530
531                 /* check if panel is valid */
532                 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
533                         ret = connector_status_connected;
534
535         }
536
537         /* check for edid as well */
538         if (radeon_connector->edid)
539                 ret = connector_status_connected;
540         else {
541                 if (radeon_connector->ddc_bus) {
542                         radeon_connector->edid = drm_get_edid(&radeon_connector->base,
543                                                               &radeon_connector->ddc_bus->adapter);
544                         if (radeon_connector->edid)
545                                 ret = connector_status_connected;
546                 }
547         }
548         /* check acpi lid status ??? */
549
550         radeon_connector_update_scratch_regs(connector, ret);
551         return ret;
552 }
553
554 static void radeon_connector_destroy(struct drm_connector *connector)
555 {
556         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
557
558         if (radeon_connector->edid)
559                 kfree(radeon_connector->edid);
560         kfree(radeon_connector->con_priv);
561         drm_sysfs_connector_remove(connector);
562         drm_connector_cleanup(connector);
563         kfree(connector);
564 }
565
566 static int radeon_lvds_set_property(struct drm_connector *connector,
567                                     struct drm_property *property,
568                                     uint64_t value)
569 {
570         struct drm_device *dev = connector->dev;
571         struct radeon_encoder *radeon_encoder;
572         enum radeon_rmx_type rmx_type;
573
574         DRM_DEBUG_KMS("\n");
575         if (property != dev->mode_config.scaling_mode_property)
576                 return 0;
577
578         if (connector->encoder)
579                 radeon_encoder = to_radeon_encoder(connector->encoder);
580         else {
581                 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
582                 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
583         }
584
585         switch (value) {
586         case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
587         case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
588         case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
589         default:
590         case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
591         }
592         if (radeon_encoder->rmx_type == rmx_type)
593                 return 0;
594
595         radeon_encoder->rmx_type = rmx_type;
596
597         radeon_property_change_mode(&radeon_encoder->base);
598         return 0;
599 }
600
601
602 struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
603         .get_modes = radeon_lvds_get_modes,
604         .mode_valid = radeon_lvds_mode_valid,
605         .best_encoder = radeon_best_single_encoder,
606 };
607
608 struct drm_connector_funcs radeon_lvds_connector_funcs = {
609         .dpms = drm_helper_connector_dpms,
610         .detect = radeon_lvds_detect,
611         .fill_modes = drm_helper_probe_single_connector_modes,
612         .destroy = radeon_connector_destroy,
613         .set_property = radeon_lvds_set_property,
614 };
615
616 static int radeon_vga_get_modes(struct drm_connector *connector)
617 {
618         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
619         int ret;
620
621         ret = radeon_ddc_get_modes(radeon_connector);
622
623         return ret;
624 }
625
626 static int radeon_vga_mode_valid(struct drm_connector *connector,
627                                   struct drm_display_mode *mode)
628 {
629         struct drm_device *dev = connector->dev;
630         struct radeon_device *rdev = dev->dev_private;
631
632         /* XXX check mode bandwidth */
633
634         if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
635                 return MODE_CLOCK_HIGH;
636
637         return MODE_OK;
638 }
639
640 static enum drm_connector_status
641 radeon_vga_detect(struct drm_connector *connector, bool force)
642 {
643         struct drm_device *dev = connector->dev;
644         struct radeon_device *rdev = dev->dev_private;
645         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
646         struct drm_encoder *encoder;
647         struct drm_encoder_helper_funcs *encoder_funcs;
648         bool dret = false;
649         enum drm_connector_status ret = connector_status_disconnected;
650
651         encoder = radeon_best_single_encoder(connector);
652         if (!encoder)
653                 ret = connector_status_disconnected;
654
655         if (radeon_connector->ddc_bus)
656                 dret = radeon_ddc_probe(radeon_connector);
657         if (dret) {
658                 if (radeon_connector->edid) {
659                         kfree(radeon_connector->edid);
660                         radeon_connector->edid = NULL;
661                 }
662                 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
663
664                 if (!radeon_connector->edid) {
665                         DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
666                                         drm_get_connector_name(connector));
667                         ret = connector_status_connected;
668                 } else {
669                         radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
670
671                         /* some oems have boards with separate digital and analog connectors
672                          * with a shared ddc line (often vga + hdmi)
673                          */
674                         if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
675                                 kfree(radeon_connector->edid);
676                                 radeon_connector->edid = NULL;
677                                 ret = connector_status_disconnected;
678                         } else
679                                 ret = connector_status_connected;
680                 }
681         } else {
682
683                 /* if we aren't forcing don't do destructive polling */
684                 if (!force)
685                         return connector->status;
686
687                 if (radeon_connector->dac_load_detect && encoder) {
688                         encoder_funcs = encoder->helper_private;
689                         ret = encoder_funcs->detect(encoder, connector);
690                 }
691         }
692
693         if (ret == connector_status_connected)
694                 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
695
696         /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
697          * vbios to deal with KVMs. If we have one and are not able to detect a monitor
698          * by other means, assume the CRT is connected and use that EDID.
699          */
700         if ((!rdev->is_atom_bios) &&
701             (ret == connector_status_disconnected) &&
702             rdev->mode_info.bios_hardcoded_edid_size) {
703                 ret = connector_status_connected;
704         }
705
706         radeon_connector_update_scratch_regs(connector, ret);
707         return ret;
708 }
709
710 struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
711         .get_modes = radeon_vga_get_modes,
712         .mode_valid = radeon_vga_mode_valid,
713         .best_encoder = radeon_best_single_encoder,
714 };
715
716 struct drm_connector_funcs radeon_vga_connector_funcs = {
717         .dpms = drm_helper_connector_dpms,
718         .detect = radeon_vga_detect,
719         .fill_modes = drm_helper_probe_single_connector_modes,
720         .destroy = radeon_connector_destroy,
721         .set_property = radeon_connector_set_property,
722 };
723
724 static int radeon_tv_get_modes(struct drm_connector *connector)
725 {
726         struct drm_device *dev = connector->dev;
727         struct radeon_device *rdev = dev->dev_private;
728         struct drm_display_mode *tv_mode;
729         struct drm_encoder *encoder;
730
731         encoder = radeon_best_single_encoder(connector);
732         if (!encoder)
733                 return 0;
734
735         /* avivo chips can scale any mode */
736         if (rdev->family >= CHIP_RS600)
737                 /* add scaled modes */
738                 radeon_add_common_modes(encoder, connector);
739         else {
740                 /* only 800x600 is supported right now on pre-avivo chips */
741                 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
742                 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
743                 drm_mode_probed_add(connector, tv_mode);
744         }
745         return 1;
746 }
747
748 static int radeon_tv_mode_valid(struct drm_connector *connector,
749                                 struct drm_display_mode *mode)
750 {
751         if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
752                 return MODE_CLOCK_RANGE;
753         return MODE_OK;
754 }
755
756 static enum drm_connector_status
757 radeon_tv_detect(struct drm_connector *connector, bool force)
758 {
759         struct drm_encoder *encoder;
760         struct drm_encoder_helper_funcs *encoder_funcs;
761         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
762         enum drm_connector_status ret = connector_status_disconnected;
763
764         if (!radeon_connector->dac_load_detect)
765                 return ret;
766
767         encoder = radeon_best_single_encoder(connector);
768         if (!encoder)
769                 ret = connector_status_disconnected;
770         else {
771                 encoder_funcs = encoder->helper_private;
772                 ret = encoder_funcs->detect(encoder, connector);
773         }
774         if (ret == connector_status_connected)
775                 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
776         radeon_connector_update_scratch_regs(connector, ret);
777         return ret;
778 }
779
780 struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
781         .get_modes = radeon_tv_get_modes,
782         .mode_valid = radeon_tv_mode_valid,
783         .best_encoder = radeon_best_single_encoder,
784 };
785
786 struct drm_connector_funcs radeon_tv_connector_funcs = {
787         .dpms = drm_helper_connector_dpms,
788         .detect = radeon_tv_detect,
789         .fill_modes = drm_helper_probe_single_connector_modes,
790         .destroy = radeon_connector_destroy,
791         .set_property = radeon_connector_set_property,
792 };
793
794 static int radeon_dvi_get_modes(struct drm_connector *connector)
795 {
796         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
797         int ret;
798
799         ret = radeon_ddc_get_modes(radeon_connector);
800         return ret;
801 }
802
803 /*
804  * DVI is complicated
805  * Do a DDC probe, if DDC probe passes, get the full EDID so
806  * we can do analog/digital monitor detection at this point.
807  * If the monitor is an analog monitor or we got no DDC,
808  * we need to find the DAC encoder object for this connector.
809  * If we got no DDC, we do load detection on the DAC encoder object.
810  * If we got analog DDC or load detection passes on the DAC encoder
811  * we have to check if this analog encoder is shared with anyone else (TV)
812  * if its shared we have to set the other connector to disconnected.
813  */
814 static enum drm_connector_status
815 radeon_dvi_detect(struct drm_connector *connector, bool force)
816 {
817         struct drm_device *dev = connector->dev;
818         struct radeon_device *rdev = dev->dev_private;
819         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
820         struct drm_encoder *encoder = NULL;
821         struct drm_encoder_helper_funcs *encoder_funcs;
822         struct drm_mode_object *obj;
823         int i;
824         enum drm_connector_status ret = connector_status_disconnected;
825         bool dret = false;
826
827         if (radeon_connector->ddc_bus)
828                 dret = radeon_ddc_probe(radeon_connector);
829         if (dret) {
830                 if (radeon_connector->edid) {
831                         kfree(radeon_connector->edid);
832                         radeon_connector->edid = NULL;
833                 }
834                 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
835
836                 if (!radeon_connector->edid) {
837                         DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
838                                         drm_get_connector_name(connector));
839                 } else {
840                         radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
841
842                         /* some oems have boards with separate digital and analog connectors
843                          * with a shared ddc line (often vga + hdmi)
844                          */
845                         if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
846                                 kfree(radeon_connector->edid);
847                                 radeon_connector->edid = NULL;
848                                 ret = connector_status_disconnected;
849                         } else
850                                 ret = connector_status_connected;
851
852                         /* This gets complicated.  We have boards with VGA + HDMI with a
853                          * shared DDC line and we have boards with DVI-D + HDMI with a shared
854                          * DDC line.  The latter is more complex because with DVI<->HDMI adapters
855                          * you don't really know what's connected to which port as both are digital.
856                          */
857                         if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
858                                 struct drm_connector *list_connector;
859                                 struct radeon_connector *list_radeon_connector;
860                                 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
861                                         if (connector == list_connector)
862                                                 continue;
863                                         list_radeon_connector = to_radeon_connector(list_connector);
864                                         if (list_radeon_connector->shared_ddc &&
865                                             (list_radeon_connector->ddc_bus->rec.i2c_id ==
866                                              radeon_connector->ddc_bus->rec.i2c_id)) {
867                                                 /* cases where both connectors are digital */
868                                                 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
869                                                         /* hpd is our only option in this case */
870                                                         if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
871                                                                 kfree(radeon_connector->edid);
872                                                                 radeon_connector->edid = NULL;
873                                                                 ret = connector_status_disconnected;
874                                                         }
875                                                 }
876                                         }
877                                 }
878                         }
879                 }
880         }
881
882         if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
883                 goto out;
884
885         if (!force) {
886                 ret = connector->status;
887                 goto out;
888         }
889
890         /* find analog encoder */
891         if (radeon_connector->dac_load_detect) {
892                 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
893                         if (connector->encoder_ids[i] == 0)
894                                 break;
895
896                         obj = drm_mode_object_find(connector->dev,
897                                                    connector->encoder_ids[i],
898                                                    DRM_MODE_OBJECT_ENCODER);
899                         if (!obj)
900                                 continue;
901
902                         encoder = obj_to_encoder(obj);
903
904                         encoder_funcs = encoder->helper_private;
905                         if (encoder_funcs->detect) {
906                                 if (ret != connector_status_connected) {
907                                         ret = encoder_funcs->detect(encoder, connector);
908                                         if (ret == connector_status_connected) {
909                                                 radeon_connector->use_digital = false;
910                                         }
911                                 }
912                                 break;
913                         }
914                 }
915         }
916
917         if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
918             encoder) {
919                 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
920         }
921
922         /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
923          * vbios to deal with KVMs. If we have one and are not able to detect a monitor
924          * by other means, assume the DFP is connected and use that EDID.  In most
925          * cases the DVI port is actually a virtual KVM port connected to the service
926          * processor.
927          */
928         if ((!rdev->is_atom_bios) &&
929             (ret == connector_status_disconnected) &&
930             rdev->mode_info.bios_hardcoded_edid_size) {
931                 radeon_connector->use_digital = true;
932                 ret = connector_status_connected;
933         }
934
935 out:
936         /* updated in get modes as well since we need to know if it's analog or digital */
937         radeon_connector_update_scratch_regs(connector, ret);
938         return ret;
939 }
940
941 /* okay need to be smart in here about which encoder to pick */
942 struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
943 {
944         int enc_id = connector->encoder_ids[0];
945         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
946         struct drm_mode_object *obj;
947         struct drm_encoder *encoder;
948         int i;
949         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
950                 if (connector->encoder_ids[i] == 0)
951                         break;
952
953                 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
954                 if (!obj)
955                         continue;
956
957                 encoder = obj_to_encoder(obj);
958
959                 if (radeon_connector->use_digital == true) {
960                         if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
961                                 return encoder;
962                 } else {
963                         if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
964                             encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
965                                 return encoder;
966                 }
967         }
968
969         /* see if we have a default encoder  TODO */
970
971         /* then check use digitial */
972         /* pick the first one */
973         if (enc_id) {
974                 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
975                 if (!obj)
976                         return NULL;
977                 encoder = obj_to_encoder(obj);
978                 return encoder;
979         }
980         return NULL;
981 }
982
983 static void radeon_dvi_force(struct drm_connector *connector)
984 {
985         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
986         if (connector->force == DRM_FORCE_ON)
987                 radeon_connector->use_digital = false;
988         if (connector->force == DRM_FORCE_ON_DIGITAL)
989                 radeon_connector->use_digital = true;
990 }
991
992 static int radeon_dvi_mode_valid(struct drm_connector *connector,
993                                   struct drm_display_mode *mode)
994 {
995         struct drm_device *dev = connector->dev;
996         struct radeon_device *rdev = dev->dev_private;
997         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
998
999         /* XXX check mode bandwidth */
1000
1001         /* clocks over 135 MHz have heat issues with DVI on RV100 */
1002         if (radeon_connector->use_digital &&
1003             (rdev->family == CHIP_RV100) &&
1004             (mode->clock > 135000))
1005                 return MODE_CLOCK_HIGH;
1006
1007         if (radeon_connector->use_digital && (mode->clock > 165000)) {
1008                 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
1009                     (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
1010                     (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
1011                         return MODE_OK;
1012                 else if (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_A) {
1013                         if (ASIC_IS_DCE3(rdev)) {
1014                                 /* HDMI 1.3+ supports max clock of 340 Mhz */
1015                                 if (mode->clock > 340000)
1016                                         return MODE_CLOCK_HIGH;
1017                                 else
1018                                         return MODE_OK;
1019                         } else
1020                                 return MODE_CLOCK_HIGH;
1021                 } else
1022                         return MODE_CLOCK_HIGH;
1023         }
1024
1025         /* check against the max pixel clock */
1026         if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
1027                 return MODE_CLOCK_HIGH;
1028
1029         return MODE_OK;
1030 }
1031
1032 struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
1033         .get_modes = radeon_dvi_get_modes,
1034         .mode_valid = radeon_dvi_mode_valid,
1035         .best_encoder = radeon_dvi_encoder,
1036 };
1037
1038 struct drm_connector_funcs radeon_dvi_connector_funcs = {
1039         .dpms = drm_helper_connector_dpms,
1040         .detect = radeon_dvi_detect,
1041         .fill_modes = drm_helper_probe_single_connector_modes,
1042         .set_property = radeon_connector_set_property,
1043         .destroy = radeon_connector_destroy,
1044         .force = radeon_dvi_force,
1045 };
1046
1047 static void radeon_dp_connector_destroy(struct drm_connector *connector)
1048 {
1049         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1050         struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1051
1052         if (radeon_connector->edid)
1053                 kfree(radeon_connector->edid);
1054         if (radeon_dig_connector->dp_i2c_bus)
1055                 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
1056         kfree(radeon_connector->con_priv);
1057         drm_sysfs_connector_remove(connector);
1058         drm_connector_cleanup(connector);
1059         kfree(connector);
1060 }
1061
1062 static int radeon_dp_get_modes(struct drm_connector *connector)
1063 {
1064         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1065         struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1066         int ret;
1067
1068         if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1069                 struct drm_encoder *encoder;
1070                 struct drm_display_mode *mode;
1071
1072                 if (!radeon_dig_connector->edp_on)
1073                         atombios_set_edp_panel_power(connector,
1074                                                      ATOM_TRANSMITTER_ACTION_POWER_ON);
1075                 ret = radeon_ddc_get_modes(radeon_connector);
1076                 if (!radeon_dig_connector->edp_on)
1077                         atombios_set_edp_panel_power(connector,
1078                                                      ATOM_TRANSMITTER_ACTION_POWER_OFF);
1079
1080                 if (ret > 0) {
1081                         encoder = radeon_best_single_encoder(connector);
1082                         if (encoder) {
1083                                 radeon_fixup_lvds_native_mode(encoder, connector);
1084                                 /* add scaled modes */
1085                                 radeon_add_common_modes(encoder, connector);
1086                         }
1087                         return ret;
1088                 }
1089
1090                 encoder = radeon_best_single_encoder(connector);
1091                 if (!encoder)
1092                         return 0;
1093
1094                 /* we have no EDID modes */
1095                 mode = radeon_fp_native_mode(encoder);
1096                 if (mode) {
1097                         ret = 1;
1098                         drm_mode_probed_add(connector, mode);
1099                         /* add the width/height from vbios tables if available */
1100                         connector->display_info.width_mm = mode->width_mm;
1101                         connector->display_info.height_mm = mode->height_mm;
1102                         /* add scaled modes */
1103                         radeon_add_common_modes(encoder, connector);
1104                 }
1105         } else
1106                 ret = radeon_ddc_get_modes(radeon_connector);
1107
1108         return ret;
1109 }
1110
1111 bool radeon_connector_encoder_is_dp_bridge(struct drm_connector *connector)
1112 {
1113         struct drm_mode_object *obj;
1114         struct drm_encoder *encoder;
1115         struct radeon_encoder *radeon_encoder;
1116         int i;
1117         bool found = false;
1118
1119         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1120                 if (connector->encoder_ids[i] == 0)
1121                         break;
1122
1123                 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1124                 if (!obj)
1125                         continue;
1126
1127                 encoder = obj_to_encoder(obj);
1128                 radeon_encoder = to_radeon_encoder(encoder);
1129
1130                 switch (radeon_encoder->encoder_id) {
1131                 case ENCODER_OBJECT_ID_TRAVIS:
1132                 case ENCODER_OBJECT_ID_NUTMEG:
1133                         found = true;
1134                         break;
1135                 default:
1136                         break;
1137                 }
1138         }
1139
1140         return found;
1141 }
1142
1143 bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
1144 {
1145         struct drm_mode_object *obj;
1146         struct drm_encoder *encoder;
1147         struct radeon_encoder *radeon_encoder;
1148         int i;
1149         bool found = false;
1150
1151         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1152                 if (connector->encoder_ids[i] == 0)
1153                         break;
1154
1155                 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
1156                 if (!obj)
1157                         continue;
1158
1159                 encoder = obj_to_encoder(obj);
1160                 radeon_encoder = to_radeon_encoder(encoder);
1161                 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
1162                         found = true;
1163         }
1164
1165         return found;
1166 }
1167
1168 bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
1169 {
1170         struct drm_device *dev = connector->dev;
1171         struct radeon_device *rdev = dev->dev_private;
1172
1173         if (ASIC_IS_DCE5(rdev) &&
1174             (rdev->clock.dp_extclk >= 53900) &&
1175             radeon_connector_encoder_is_hbr2(connector)) {
1176                 return true;
1177         }
1178
1179         return false;
1180 }
1181
1182 static enum drm_connector_status
1183 radeon_dp_detect(struct drm_connector *connector, bool force)
1184 {
1185         struct drm_device *dev = connector->dev;
1186         struct radeon_device *rdev = dev->dev_private;
1187         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1188         enum drm_connector_status ret = connector_status_disconnected;
1189         struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1190
1191         if (radeon_connector->edid) {
1192                 kfree(radeon_connector->edid);
1193                 radeon_connector->edid = NULL;
1194         }
1195
1196         if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1197                 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1198                 if (encoder) {
1199                         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1200                         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1201
1202                         /* check if panel is valid */
1203                         if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1204                                 ret = connector_status_connected;
1205                 }
1206                 /* eDP is always DP */
1207                 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1208                 if (!radeon_dig_connector->edp_on)
1209                         atombios_set_edp_panel_power(connector,
1210                                                      ATOM_TRANSMITTER_ACTION_POWER_ON);
1211                 if (radeon_dp_getdpcd(radeon_connector))
1212                         ret = connector_status_connected;
1213                 if (!radeon_dig_connector->edp_on)
1214                         atombios_set_edp_panel_power(connector,
1215                                                      ATOM_TRANSMITTER_ACTION_POWER_OFF);
1216         } else {
1217                 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
1218                 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
1219                         ret = connector_status_connected;
1220                         if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
1221                                 radeon_dp_getdpcd(radeon_connector);
1222                 } else {
1223                         if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
1224                                 if (radeon_dp_getdpcd(radeon_connector))
1225                                         ret = connector_status_connected;
1226                         } else {
1227                                 if (radeon_ddc_probe(radeon_connector))
1228                                         ret = connector_status_connected;
1229                         }
1230                 }
1231         }
1232
1233         radeon_connector_update_scratch_regs(connector, ret);
1234         return ret;
1235 }
1236
1237 static int radeon_dp_mode_valid(struct drm_connector *connector,
1238                                   struct drm_display_mode *mode)
1239 {
1240         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1241         struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1242
1243         /* XXX check mode bandwidth */
1244
1245         if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1246                 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
1247
1248                 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
1249                         return MODE_PANEL;
1250
1251                 if (encoder) {
1252                         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1253                         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
1254
1255                 /* AVIVO hardware supports downscaling modes larger than the panel
1256                          * to the panel size, but I'm not sure this is desirable.
1257                          */
1258                         if ((mode->hdisplay > native_mode->hdisplay) ||
1259                             (mode->vdisplay > native_mode->vdisplay))
1260                                 return MODE_PANEL;
1261
1262                         /* if scaling is disabled, block non-native modes */
1263                         if (radeon_encoder->rmx_type == RMX_OFF) {
1264                                 if ((mode->hdisplay != native_mode->hdisplay) ||
1265                                     (mode->vdisplay != native_mode->vdisplay))
1266                                         return MODE_PANEL;
1267                         }
1268                 }
1269                 return MODE_OK;
1270         } else {
1271                 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1272                     (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
1273                         return radeon_dp_mode_valid_helper(connector, mode);
1274                 else
1275                         return MODE_OK;
1276         }
1277 }
1278
1279 struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1280         .get_modes = radeon_dp_get_modes,
1281         .mode_valid = radeon_dp_mode_valid,
1282         .best_encoder = radeon_dvi_encoder,
1283 };
1284
1285 struct drm_connector_funcs radeon_dp_connector_funcs = {
1286         .dpms = drm_helper_connector_dpms,
1287         .detect = radeon_dp_detect,
1288         .fill_modes = drm_helper_probe_single_connector_modes,
1289         .set_property = radeon_connector_set_property,
1290         .destroy = radeon_dp_connector_destroy,
1291         .force = radeon_dvi_force,
1292 };
1293
1294 void
1295 radeon_add_atom_connector(struct drm_device *dev,
1296                           uint32_t connector_id,
1297                           uint32_t supported_device,
1298                           int connector_type,
1299                           struct radeon_i2c_bus_rec *i2c_bus,
1300                           uint32_t igp_lane_info,
1301                           uint16_t connector_object_id,
1302                           struct radeon_hpd *hpd,
1303                           struct radeon_router *router)
1304 {
1305         struct radeon_device *rdev = dev->dev_private;
1306         struct drm_connector *connector;
1307         struct radeon_connector *radeon_connector;
1308         struct radeon_connector_atom_dig *radeon_dig_connector;
1309         struct drm_encoder *encoder;
1310         struct radeon_encoder *radeon_encoder;
1311         uint32_t subpixel_order = SubPixelNone;
1312         bool shared_ddc = false;
1313         bool is_dp_bridge = false;
1314
1315         if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1316                 return;
1317
1318         /* if the user selected tv=0 don't try and add the connector */
1319         if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1320              (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1321              (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1322             (radeon_tv == 0))
1323                 return;
1324
1325         /* see if we already added it */
1326         list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1327                 radeon_connector = to_radeon_connector(connector);
1328                 if (radeon_connector->connector_id == connector_id) {
1329                         radeon_connector->devices |= supported_device;
1330                         return;
1331                 }
1332                 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1333                         if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1334                                 radeon_connector->shared_ddc = true;
1335                                 shared_ddc = true;
1336                         }
1337                         if (radeon_connector->router_bus && router->ddc_valid &&
1338                             (radeon_connector->router.router_id == router->router_id)) {
1339                                 radeon_connector->shared_ddc = false;
1340                                 shared_ddc = false;
1341                         }
1342                 }
1343         }
1344
1345         /* check if it's a dp bridge */
1346         list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1347                 radeon_encoder = to_radeon_encoder(encoder);
1348                 if (radeon_encoder->devices & supported_device) {
1349                         switch (radeon_encoder->encoder_id) {
1350                         case ENCODER_OBJECT_ID_TRAVIS:
1351                         case ENCODER_OBJECT_ID_NUTMEG:
1352                                 is_dp_bridge = true;
1353                                 break;
1354                         default:
1355                                 break;
1356                         }
1357                 }
1358         }
1359
1360         radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1361         if (!radeon_connector)
1362                 return;
1363
1364         connector = &radeon_connector->base;
1365
1366         radeon_connector->connector_id = connector_id;
1367         radeon_connector->devices = supported_device;
1368         radeon_connector->shared_ddc = shared_ddc;
1369         radeon_connector->connector_object_id = connector_object_id;
1370         radeon_connector->hpd = *hpd;
1371         radeon_connector->router = *router;
1372         if (router->ddc_valid || router->cd_valid) {
1373                 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1374                 if (!radeon_connector->router_bus)
1375                         DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
1376         }
1377
1378         if (is_dp_bridge) {
1379                 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1380                 if (!radeon_dig_connector)
1381                         goto failed;
1382                 radeon_dig_connector->igp_lane_info = igp_lane_info;
1383                 radeon_connector->con_priv = radeon_dig_connector;
1384                 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1385                 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1386                 if (i2c_bus->valid) {
1387                         /* add DP i2c bus */
1388                         if (connector_type == DRM_MODE_CONNECTOR_eDP)
1389                                 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1390                         else
1391                                 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1392                         if (!radeon_dig_connector->dp_i2c_bus)
1393                                 DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1394                         radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1395                         if (!radeon_connector->ddc_bus)
1396                                 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1397                 }
1398                 switch (connector_type) {
1399                 case DRM_MODE_CONNECTOR_VGA:
1400                 case DRM_MODE_CONNECTOR_DVIA:
1401                 default:
1402                         connector->interlace_allowed = true;
1403                         connector->doublescan_allowed = true;
1404                         break;
1405                 case DRM_MODE_CONNECTOR_DVII:
1406                 case DRM_MODE_CONNECTOR_DVID:
1407                 case DRM_MODE_CONNECTOR_HDMIA:
1408                 case DRM_MODE_CONNECTOR_HDMIB:
1409                 case DRM_MODE_CONNECTOR_DisplayPort:
1410                         drm_connector_attach_property(&radeon_connector->base,
1411                                                       rdev->mode_info.underscan_property,
1412                                                       UNDERSCAN_OFF);
1413                         drm_connector_attach_property(&radeon_connector->base,
1414                                                       rdev->mode_info.underscan_hborder_property,
1415                                                       0);
1416                         drm_connector_attach_property(&radeon_connector->base,
1417                                                       rdev->mode_info.underscan_vborder_property,
1418                                                       0);
1419                         subpixel_order = SubPixelHorizontalRGB;
1420                         connector->interlace_allowed = true;
1421                         if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1422                                 connector->doublescan_allowed = true;
1423                         else
1424                                 connector->doublescan_allowed = false;
1425                         break;
1426                 case DRM_MODE_CONNECTOR_LVDS:
1427                 case DRM_MODE_CONNECTOR_eDP:
1428                         drm_connector_attach_property(&radeon_connector->base,
1429                                                       dev->mode_config.scaling_mode_property,
1430                                                       DRM_MODE_SCALE_FULLSCREEN);
1431                         subpixel_order = SubPixelHorizontalRGB;
1432                         connector->interlace_allowed = false;
1433                         connector->doublescan_allowed = false;
1434                         break;
1435                 }
1436         } else {
1437                 switch (connector_type) {
1438                 case DRM_MODE_CONNECTOR_VGA:
1439                         drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1440                         drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1441                         if (i2c_bus->valid) {
1442                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1443                                 if (!radeon_connector->ddc_bus)
1444                                         DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1445                         }
1446                         radeon_connector->dac_load_detect = true;
1447                         drm_connector_attach_property(&radeon_connector->base,
1448                                                       rdev->mode_info.load_detect_property,
1449                                                       1);
1450                         /* no HPD on analog connectors */
1451                         radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1452                         connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1453                         connector->interlace_allowed = true;
1454                         connector->doublescan_allowed = true;
1455                         break;
1456                 case DRM_MODE_CONNECTOR_DVIA:
1457                         drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1458                         drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1459                         if (i2c_bus->valid) {
1460                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1461                                 if (!radeon_connector->ddc_bus)
1462                                         DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1463                         }
1464                         radeon_connector->dac_load_detect = true;
1465                         drm_connector_attach_property(&radeon_connector->base,
1466                                                       rdev->mode_info.load_detect_property,
1467                                                       1);
1468                         /* no HPD on analog connectors */
1469                         radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1470                         connector->interlace_allowed = true;
1471                         connector->doublescan_allowed = true;
1472                         break;
1473                 case DRM_MODE_CONNECTOR_DVII:
1474                 case DRM_MODE_CONNECTOR_DVID:
1475                         radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1476                         if (!radeon_dig_connector)
1477                                 goto failed;
1478                         radeon_dig_connector->igp_lane_info = igp_lane_info;
1479                         radeon_connector->con_priv = radeon_dig_connector;
1480                         drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1481                         drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1482                         if (i2c_bus->valid) {
1483                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1484                                 if (!radeon_connector->ddc_bus)
1485                                         DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1486                         }
1487                         subpixel_order = SubPixelHorizontalRGB;
1488                         drm_connector_attach_property(&radeon_connector->base,
1489                                                       rdev->mode_info.coherent_mode_property,
1490                                                       1);
1491                         if (ASIC_IS_AVIVO(rdev)) {
1492                                 drm_connector_attach_property(&radeon_connector->base,
1493                                                               rdev->mode_info.underscan_property,
1494                                                               UNDERSCAN_OFF);
1495                                 drm_connector_attach_property(&radeon_connector->base,
1496                                                               rdev->mode_info.underscan_hborder_property,
1497                                                               0);
1498                                 drm_connector_attach_property(&radeon_connector->base,
1499                                                               rdev->mode_info.underscan_vborder_property,
1500                                                               0);
1501                         }
1502                         if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1503                                 radeon_connector->dac_load_detect = true;
1504                                 drm_connector_attach_property(&radeon_connector->base,
1505                                                               rdev->mode_info.load_detect_property,
1506                                                               1);
1507                         }
1508                         connector->interlace_allowed = true;
1509                         if (connector_type == DRM_MODE_CONNECTOR_DVII)
1510                                 connector->doublescan_allowed = true;
1511                         else
1512                                 connector->doublescan_allowed = false;
1513                         break;
1514                 case DRM_MODE_CONNECTOR_HDMIA:
1515                 case DRM_MODE_CONNECTOR_HDMIB:
1516                         radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1517                         if (!radeon_dig_connector)
1518                                 goto failed;
1519                         radeon_dig_connector->igp_lane_info = igp_lane_info;
1520                         radeon_connector->con_priv = radeon_dig_connector;
1521                         drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1522                         drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1523                         if (i2c_bus->valid) {
1524                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1525                                 if (!radeon_connector->ddc_bus)
1526                                         DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1527                         }
1528                         drm_connector_attach_property(&radeon_connector->base,
1529                                                       rdev->mode_info.coherent_mode_property,
1530                                                       1);
1531                         if (ASIC_IS_AVIVO(rdev)) {
1532                                 drm_connector_attach_property(&radeon_connector->base,
1533                                                               rdev->mode_info.underscan_property,
1534                                                               UNDERSCAN_OFF);
1535                                 drm_connector_attach_property(&radeon_connector->base,
1536                                                               rdev->mode_info.underscan_hborder_property,
1537                                                               0);
1538                                 drm_connector_attach_property(&radeon_connector->base,
1539                                                               rdev->mode_info.underscan_vborder_property,
1540                                                               0);
1541                         }
1542                         subpixel_order = SubPixelHorizontalRGB;
1543                         connector->interlace_allowed = true;
1544                         if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
1545                                 connector->doublescan_allowed = true;
1546                         else
1547                                 connector->doublescan_allowed = false;
1548                         break;
1549                 case DRM_MODE_CONNECTOR_DisplayPort:
1550                         radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1551                         if (!radeon_dig_connector)
1552                                 goto failed;
1553                         radeon_dig_connector->igp_lane_info = igp_lane_info;
1554                         radeon_connector->con_priv = radeon_dig_connector;
1555                         drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1556                         drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1557                         if (i2c_bus->valid) {
1558                                 /* add DP i2c bus */
1559                                 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1560                                 if (!radeon_dig_connector->dp_i2c_bus)
1561                                         DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1562                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1563                                 if (!radeon_connector->ddc_bus)
1564                                         DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1565                         }
1566                         subpixel_order = SubPixelHorizontalRGB;
1567                         drm_connector_attach_property(&radeon_connector->base,
1568                                                       rdev->mode_info.coherent_mode_property,
1569                                                       1);
1570                         if (ASIC_IS_AVIVO(rdev)) {
1571                                 drm_connector_attach_property(&radeon_connector->base,
1572                                                               rdev->mode_info.underscan_property,
1573                                                               UNDERSCAN_OFF);
1574                                 drm_connector_attach_property(&radeon_connector->base,
1575                                                               rdev->mode_info.underscan_hborder_property,
1576                                                               0);
1577                                 drm_connector_attach_property(&radeon_connector->base,
1578                                                               rdev->mode_info.underscan_vborder_property,
1579                                                               0);
1580                         }
1581                         connector->interlace_allowed = true;
1582                         /* in theory with a DP to VGA converter... */
1583                         connector->doublescan_allowed = false;
1584                         break;
1585                 case DRM_MODE_CONNECTOR_eDP:
1586                         radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1587                         if (!radeon_dig_connector)
1588                                 goto failed;
1589                         radeon_dig_connector->igp_lane_info = igp_lane_info;
1590                         radeon_connector->con_priv = radeon_dig_connector;
1591                         drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1592                         drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1593                         if (i2c_bus->valid) {
1594                                 /* add DP i2c bus */
1595                                 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1596                                 if (!radeon_dig_connector->dp_i2c_bus)
1597                                         DRM_ERROR("DP: Failed to assign dp ddc bus! Check dmesg for i2c errors.\n");
1598                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1599                                 if (!radeon_connector->ddc_bus)
1600                                         DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1601                         }
1602                         drm_connector_attach_property(&radeon_connector->base,
1603                                                       dev->mode_config.scaling_mode_property,
1604                                                       DRM_MODE_SCALE_FULLSCREEN);
1605                         subpixel_order = SubPixelHorizontalRGB;
1606                         connector->interlace_allowed = false;
1607                         connector->doublescan_allowed = false;
1608                         break;
1609                 case DRM_MODE_CONNECTOR_SVIDEO:
1610                 case DRM_MODE_CONNECTOR_Composite:
1611                 case DRM_MODE_CONNECTOR_9PinDIN:
1612                         drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1613                         drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1614                         radeon_connector->dac_load_detect = true;
1615                         drm_connector_attach_property(&radeon_connector->base,
1616                                                       rdev->mode_info.load_detect_property,
1617                                                       1);
1618                         drm_connector_attach_property(&radeon_connector->base,
1619                                                       rdev->mode_info.tv_std_property,
1620                                                       radeon_atombios_get_tv_info(rdev));
1621                         /* no HPD on analog connectors */
1622                         radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1623                         connector->interlace_allowed = false;
1624                         connector->doublescan_allowed = false;
1625                         break;
1626                 case DRM_MODE_CONNECTOR_LVDS:
1627                         radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1628                         if (!radeon_dig_connector)
1629                                 goto failed;
1630                         radeon_dig_connector->igp_lane_info = igp_lane_info;
1631                         radeon_connector->con_priv = radeon_dig_connector;
1632                         drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1633                         drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1634                         if (i2c_bus->valid) {
1635                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1636                                 if (!radeon_connector->ddc_bus)
1637                                         DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1638                         }
1639                         drm_connector_attach_property(&radeon_connector->base,
1640                                                       dev->mode_config.scaling_mode_property,
1641                                                       DRM_MODE_SCALE_FULLSCREEN);
1642                         subpixel_order = SubPixelHorizontalRGB;
1643                         connector->interlace_allowed = false;
1644                         connector->doublescan_allowed = false;
1645                         break;
1646                 }
1647         }
1648
1649         if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
1650                 if (i2c_bus->valid)
1651                         connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1652         } else
1653                 connector->polled = DRM_CONNECTOR_POLL_HPD;
1654
1655         connector->display_info.subpixel_order = subpixel_order;
1656         drm_sysfs_connector_add(connector);
1657         return;
1658
1659 failed:
1660         drm_connector_cleanup(connector);
1661         kfree(connector);
1662 }
1663
1664 void
1665 radeon_add_legacy_connector(struct drm_device *dev,
1666                             uint32_t connector_id,
1667                             uint32_t supported_device,
1668                             int connector_type,
1669                             struct radeon_i2c_bus_rec *i2c_bus,
1670                             uint16_t connector_object_id,
1671                             struct radeon_hpd *hpd)
1672 {
1673         struct radeon_device *rdev = dev->dev_private;
1674         struct drm_connector *connector;
1675         struct radeon_connector *radeon_connector;
1676         uint32_t subpixel_order = SubPixelNone;
1677
1678         if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1679                 return;
1680
1681         /* if the user selected tv=0 don't try and add the connector */
1682         if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
1683              (connector_type == DRM_MODE_CONNECTOR_Composite) ||
1684              (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
1685             (radeon_tv == 0))
1686                 return;
1687
1688         /* see if we already added it */
1689         list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1690                 radeon_connector = to_radeon_connector(connector);
1691                 if (radeon_connector->connector_id == connector_id) {
1692                         radeon_connector->devices |= supported_device;
1693                         return;
1694                 }
1695         }
1696
1697         radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1698         if (!radeon_connector)
1699                 return;
1700
1701         connector = &radeon_connector->base;
1702
1703         radeon_connector->connector_id = connector_id;
1704         radeon_connector->devices = supported_device;
1705         radeon_connector->connector_object_id = connector_object_id;
1706         radeon_connector->hpd = *hpd;
1707         switch (connector_type) {
1708         case DRM_MODE_CONNECTOR_VGA:
1709                 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1710                 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1711                 if (i2c_bus->valid) {
1712                         radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1713                         if (!radeon_connector->ddc_bus)
1714                                 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1715                 }
1716                 radeon_connector->dac_load_detect = true;
1717                 drm_connector_attach_property(&radeon_connector->base,
1718                                               rdev->mode_info.load_detect_property,
1719                                               1);
1720                 /* no HPD on analog connectors */
1721                 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1722                 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1723                 connector->interlace_allowed = true;
1724                 connector->doublescan_allowed = true;
1725                 break;
1726         case DRM_MODE_CONNECTOR_DVIA:
1727                 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1728                 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1729                 if (i2c_bus->valid) {
1730                         radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1731                         if (!radeon_connector->ddc_bus)
1732                                 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1733                 }
1734                 radeon_connector->dac_load_detect = true;
1735                 drm_connector_attach_property(&radeon_connector->base,
1736                                               rdev->mode_info.load_detect_property,
1737                                               1);
1738                 /* no HPD on analog connectors */
1739                 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1740                 connector->interlace_allowed = true;
1741                 connector->doublescan_allowed = true;
1742                 break;
1743         case DRM_MODE_CONNECTOR_DVII:
1744         case DRM_MODE_CONNECTOR_DVID:
1745                 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1746                 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1747                 if (i2c_bus->valid) {
1748                         radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1749                         if (!radeon_connector->ddc_bus)
1750                                 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1751                 }
1752                 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1753                         radeon_connector->dac_load_detect = true;
1754                         drm_connector_attach_property(&radeon_connector->base,
1755                                                       rdev->mode_info.load_detect_property,
1756                                                       1);
1757                 }
1758                 subpixel_order = SubPixelHorizontalRGB;
1759                 connector->interlace_allowed = true;
1760                 if (connector_type == DRM_MODE_CONNECTOR_DVII)
1761                         connector->doublescan_allowed = true;
1762                 else
1763                         connector->doublescan_allowed = false;
1764                 break;
1765         case DRM_MODE_CONNECTOR_SVIDEO:
1766         case DRM_MODE_CONNECTOR_Composite:
1767         case DRM_MODE_CONNECTOR_9PinDIN:
1768                 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1769                 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1770                 radeon_connector->dac_load_detect = true;
1771                 /* RS400,RC410,RS480 chipset seems to report a lot
1772                  * of false positive on load detect, we haven't yet
1773                  * found a way to make load detect reliable on those
1774                  * chipset, thus just disable it for TV.
1775                  */
1776                 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1777                         radeon_connector->dac_load_detect = false;
1778                 drm_connector_attach_property(&radeon_connector->base,
1779                                               rdev->mode_info.load_detect_property,
1780                                               radeon_connector->dac_load_detect);
1781                 drm_connector_attach_property(&radeon_connector->base,
1782                                               rdev->mode_info.tv_std_property,
1783                                               radeon_combios_get_tv_info(rdev));
1784                 /* no HPD on analog connectors */
1785                 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1786                 connector->interlace_allowed = false;
1787                 connector->doublescan_allowed = false;
1788                 break;
1789         case DRM_MODE_CONNECTOR_LVDS:
1790                 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1791                 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1792                 if (i2c_bus->valid) {
1793                         radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1794                         if (!radeon_connector->ddc_bus)
1795                                 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
1796                 }
1797                 drm_connector_attach_property(&radeon_connector->base,
1798                                               dev->mode_config.scaling_mode_property,
1799                                               DRM_MODE_SCALE_FULLSCREEN);
1800                 subpixel_order = SubPixelHorizontalRGB;
1801                 connector->interlace_allowed = false;
1802                 connector->doublescan_allowed = false;
1803                 break;
1804         }
1805
1806         if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
1807                 if (i2c_bus->valid)
1808                         connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1809         } else
1810                 connector->polled = DRM_CONNECTOR_POLL_HPD;
1811         connector->display_info.subpixel_order = subpixel_order;
1812         drm_sysfs_connector_add(connector);
1813         if (connector_type == DRM_MODE_CONNECTOR_LVDS) {
1814                 struct drm_encoder *drm_encoder;
1815
1816                 list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) {
1817                         struct radeon_encoder *radeon_encoder;
1818
1819                         radeon_encoder = to_radeon_encoder(drm_encoder);
1820                         if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_LVDS)
1821                                 radeon_legacy_backlight_init(radeon_encoder, connector);
1822                 }
1823         }
1824 }