]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/gpu/drm/radeon/radeon_connectors.c
drm/radeon/kms: enable underscan option for digital connectors
[net-next-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 void radeon_connector_hotplug(struct drm_connector *connector)
44 {
45         struct drm_device *dev = connector->dev;
46         struct radeon_device *rdev = dev->dev_private;
47         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
48
49         if (radeon_connector->hpd.hpd != RADEON_HPD_NONE)
50                 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
51
52         if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
53             (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
54                 if ((radeon_dp_getsinktype(radeon_connector) == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
55                     (radeon_dp_getsinktype(radeon_connector) == CONNECTOR_OBJECT_ID_eDP)) {
56                         if (radeon_dp_needs_link_train(radeon_connector)) {
57                                 if (connector->encoder)
58                                         dp_link_train(connector->encoder, connector);
59                         }
60                 }
61         }
62
63 }
64
65 static void radeon_property_change_mode(struct drm_encoder *encoder)
66 {
67         struct drm_crtc *crtc = encoder->crtc;
68
69         if (crtc && crtc->enabled) {
70                 drm_crtc_helper_set_mode(crtc, &crtc->mode,
71                                          crtc->x, crtc->y, crtc->fb);
72         }
73 }
74 static void
75 radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
76 {
77         struct drm_device *dev = connector->dev;
78         struct radeon_device *rdev = dev->dev_private;
79         struct drm_encoder *best_encoder = NULL;
80         struct drm_encoder *encoder = NULL;
81         struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
82         struct drm_mode_object *obj;
83         bool connected;
84         int i;
85
86         best_encoder = connector_funcs->best_encoder(connector);
87
88         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
89                 if (connector->encoder_ids[i] == 0)
90                         break;
91
92                 obj = drm_mode_object_find(connector->dev,
93                                            connector->encoder_ids[i],
94                                            DRM_MODE_OBJECT_ENCODER);
95                 if (!obj)
96                         continue;
97
98                 encoder = obj_to_encoder(obj);
99
100                 if ((encoder == best_encoder) && (status == connector_status_connected))
101                         connected = true;
102                 else
103                         connected = false;
104
105                 if (rdev->is_atom_bios)
106                         radeon_atombios_connected_scratch_regs(connector, encoder, connected);
107                 else
108                         radeon_combios_connected_scratch_regs(connector, encoder, connected);
109
110         }
111 }
112
113 struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
114 {
115         struct drm_mode_object *obj;
116         struct drm_encoder *encoder;
117         int i;
118
119         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
120                 if (connector->encoder_ids[i] == 0)
121                         break;
122
123                 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
124                 if (!obj)
125                         continue;
126
127                 encoder = obj_to_encoder(obj);
128                 if (encoder->encoder_type == encoder_type)
129                         return encoder;
130         }
131         return NULL;
132 }
133
134 struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
135 {
136         int enc_id = connector->encoder_ids[0];
137         struct drm_mode_object *obj;
138         struct drm_encoder *encoder;
139
140         /* pick the encoder ids */
141         if (enc_id) {
142                 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
143                 if (!obj)
144                         return NULL;
145                 encoder = obj_to_encoder(obj);
146                 return encoder;
147         }
148         return NULL;
149 }
150
151 /*
152  * radeon_connector_analog_encoder_conflict_solve
153  * - search for other connectors sharing this encoder
154  *   if priority is true, then set them disconnected if this is connected
155  *   if priority is false, set us disconnected if they are connected
156  */
157 static enum drm_connector_status
158 radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
159                                                struct drm_encoder *encoder,
160                                                enum drm_connector_status current_status,
161                                                bool priority)
162 {
163         struct drm_device *dev = connector->dev;
164         struct drm_connector *conflict;
165         struct radeon_connector *radeon_conflict;
166         int i;
167
168         list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
169                 if (conflict == connector)
170                         continue;
171
172                 radeon_conflict = to_radeon_connector(conflict);
173                 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
174                         if (conflict->encoder_ids[i] == 0)
175                                 break;
176
177                         /* if the IDs match */
178                         if (conflict->encoder_ids[i] == encoder->base.id) {
179                                 if (conflict->status != connector_status_connected)
180                                         continue;
181
182                                 if (radeon_conflict->use_digital)
183                                         continue;
184
185                                 if (priority == true) {
186                                         DRM_INFO("1: conflicting encoders switching off %s\n", drm_get_connector_name(conflict));
187                                         DRM_INFO("in favor of %s\n", drm_get_connector_name(connector));
188                                         conflict->status = connector_status_disconnected;
189                                         radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
190                                 } else {
191                                         DRM_INFO("2: conflicting encoders switching off %s\n", drm_get_connector_name(connector));
192                                         DRM_INFO("in favor of %s\n", drm_get_connector_name(conflict));
193                                         current_status = connector_status_disconnected;
194                                 }
195                                 break;
196                         }
197                 }
198         }
199         return current_status;
200
201 }
202
203 static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
204 {
205         struct drm_device *dev = encoder->dev;
206         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
207         struct drm_display_mode *mode = NULL;
208         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
209
210         if (native_mode->hdisplay != 0 &&
211             native_mode->vdisplay != 0 &&
212             native_mode->clock != 0) {
213                 mode = drm_mode_duplicate(dev, native_mode);
214                 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
215                 drm_mode_set_name(mode);
216
217                 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
218         } else if (native_mode->hdisplay != 0 &&
219                    native_mode->vdisplay != 0) {
220                 /* mac laptops without an edid */
221                 /* Note that this is not necessarily the exact panel mode,
222                  * but an approximation based on the cvt formula.  For these
223                  * systems we should ideally read the mode info out of the
224                  * registers or add a mode table, but this works and is much
225                  * simpler.
226                  */
227                 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
228                 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
229                 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
230         }
231         return mode;
232 }
233
234 static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
235 {
236         struct drm_device *dev = encoder->dev;
237         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
238         struct drm_display_mode *mode = NULL;
239         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
240         int i;
241         struct mode_size {
242                 int w;
243                 int h;
244         } common_modes[17] = {
245                 { 640,  480},
246                 { 720,  480},
247                 { 800,  600},
248                 { 848,  480},
249                 {1024,  768},
250                 {1152,  768},
251                 {1280,  720},
252                 {1280,  800},
253                 {1280,  854},
254                 {1280,  960},
255                 {1280, 1024},
256                 {1440,  900},
257                 {1400, 1050},
258                 {1680, 1050},
259                 {1600, 1200},
260                 {1920, 1080},
261                 {1920, 1200}
262         };
263
264         for (i = 0; i < 17; i++) {
265                 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
266                         if (common_modes[i].w > 1024 ||
267                             common_modes[i].h > 768)
268                                 continue;
269                 }
270                 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
271                         if (common_modes[i].w > native_mode->hdisplay ||
272                             common_modes[i].h > native_mode->vdisplay ||
273                             (common_modes[i].w == native_mode->hdisplay &&
274                              common_modes[i].h == native_mode->vdisplay))
275                                 continue;
276                 }
277                 if (common_modes[i].w < 320 || common_modes[i].h < 200)
278                         continue;
279
280                 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
281                 drm_mode_probed_add(connector, mode);
282         }
283 }
284
285 int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
286                                   uint64_t val)
287 {
288         struct drm_device *dev = connector->dev;
289         struct radeon_device *rdev = dev->dev_private;
290         struct drm_encoder *encoder;
291         struct radeon_encoder *radeon_encoder;
292
293         if (property == rdev->mode_info.coherent_mode_property) {
294                 struct radeon_encoder_atom_dig *dig;
295                 bool new_coherent_mode;
296
297                 /* need to find digital encoder on connector */
298                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
299                 if (!encoder)
300                         return 0;
301
302                 radeon_encoder = to_radeon_encoder(encoder);
303
304                 if (!radeon_encoder->enc_priv)
305                         return 0;
306
307                 dig = radeon_encoder->enc_priv;
308                 new_coherent_mode = val ? true : false;
309                 if (dig->coherent_mode != new_coherent_mode) {
310                         dig->coherent_mode = new_coherent_mode;
311                         radeon_property_change_mode(&radeon_encoder->base);
312                 }
313         }
314
315         if (property == rdev->mode_info.underscan_property) {
316                 /* need to find digital encoder on connector */
317                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
318                 if (!encoder)
319                         return 0;
320
321                 radeon_encoder = to_radeon_encoder(encoder);
322
323                 if (radeon_encoder->underscan_type != val) {
324                         radeon_encoder->underscan_type = val;
325                         radeon_property_change_mode(&radeon_encoder->base);
326                 }
327         }
328
329         if (property == rdev->mode_info.tv_std_property) {
330                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
331                 if (!encoder) {
332                         encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
333                 }
334
335                 if (!encoder)
336                         return 0;
337
338                 radeon_encoder = to_radeon_encoder(encoder);
339                 if (!radeon_encoder->enc_priv)
340                         return 0;
341                 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
342                         struct radeon_encoder_atom_dac *dac_int;
343                         dac_int = radeon_encoder->enc_priv;
344                         dac_int->tv_std = val;
345                 } else {
346                         struct radeon_encoder_tv_dac *dac_int;
347                         dac_int = radeon_encoder->enc_priv;
348                         dac_int->tv_std = val;
349                 }
350                 radeon_property_change_mode(&radeon_encoder->base);
351         }
352
353         if (property == rdev->mode_info.load_detect_property) {
354                 struct radeon_connector *radeon_connector =
355                         to_radeon_connector(connector);
356
357                 if (val == 0)
358                         radeon_connector->dac_load_detect = false;
359                 else
360                         radeon_connector->dac_load_detect = true;
361         }
362
363         if (property == rdev->mode_info.tmds_pll_property) {
364                 struct radeon_encoder_int_tmds *tmds = NULL;
365                 bool ret = false;
366                 /* need to find digital encoder on connector */
367                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
368                 if (!encoder)
369                         return 0;
370
371                 radeon_encoder = to_radeon_encoder(encoder);
372
373                 tmds = radeon_encoder->enc_priv;
374                 if (!tmds)
375                         return 0;
376
377                 if (val == 0) {
378                         if (rdev->is_atom_bios)
379                                 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
380                         else
381                                 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
382                 }
383                 if (val == 1 || ret == false) {
384                         radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
385                 }
386                 radeon_property_change_mode(&radeon_encoder->base);
387         }
388
389         return 0;
390 }
391
392 static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
393                                           struct drm_connector *connector)
394 {
395         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
396         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
397
398         /* Try to get native mode details from EDID if necessary */
399         if (!native_mode->clock) {
400                 struct drm_display_mode *t, *mode;
401
402                 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
403                         if (mode->hdisplay == native_mode->hdisplay &&
404                             mode->vdisplay == native_mode->vdisplay) {
405                                 *native_mode = *mode;
406                                 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
407                                 DRM_INFO("Determined LVDS native mode details from EDID\n");
408                                 break;
409                         }
410                 }
411         }
412         if (!native_mode->clock) {
413                 DRM_INFO("No LVDS native mode details, disabling RMX\n");
414                 radeon_encoder->rmx_type = RMX_OFF;
415         }
416 }
417
418 static int radeon_lvds_get_modes(struct drm_connector *connector)
419 {
420         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
421         struct drm_encoder *encoder;
422         int ret = 0;
423         struct drm_display_mode *mode;
424
425         if (radeon_connector->ddc_bus) {
426                 ret = radeon_ddc_get_modes(radeon_connector);
427                 if (ret > 0) {
428                         encoder = radeon_best_single_encoder(connector);
429                         if (encoder) {
430                                 radeon_fixup_lvds_native_mode(encoder, connector);
431                                 /* add scaled modes */
432                                 radeon_add_common_modes(encoder, connector);
433                         }
434                         return ret;
435                 }
436         }
437
438         encoder = radeon_best_single_encoder(connector);
439         if (!encoder)
440                 return 0;
441
442         /* we have no EDID modes */
443         mode = radeon_fp_native_mode(encoder);
444         if (mode) {
445                 ret = 1;
446                 drm_mode_probed_add(connector, mode);
447                 /* add scaled modes */
448                 radeon_add_common_modes(encoder, connector);
449         }
450
451         return ret;
452 }
453
454 static int radeon_lvds_mode_valid(struct drm_connector *connector,
455                                   struct drm_display_mode *mode)
456 {
457         struct drm_encoder *encoder = radeon_best_single_encoder(connector);
458
459         if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
460                 return MODE_PANEL;
461
462         if (encoder) {
463                 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
464                 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
465
466                 /* AVIVO hardware supports downscaling modes larger than the panel
467                  * to the panel size, but I'm not sure this is desirable.
468                  */
469                 if ((mode->hdisplay > native_mode->hdisplay) ||
470                     (mode->vdisplay > native_mode->vdisplay))
471                         return MODE_PANEL;
472
473                 /* if scaling is disabled, block non-native modes */
474                 if (radeon_encoder->rmx_type == RMX_OFF) {
475                         if ((mode->hdisplay != native_mode->hdisplay) ||
476                             (mode->vdisplay != native_mode->vdisplay))
477                                 return MODE_PANEL;
478                 }
479         }
480
481         return MODE_OK;
482 }
483
484 static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connector)
485 {
486         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
487         struct drm_encoder *encoder = radeon_best_single_encoder(connector);
488         enum drm_connector_status ret = connector_status_disconnected;
489
490         if (encoder) {
491                 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
492                 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
493
494                 /* check if panel is valid */
495                 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
496                         ret = connector_status_connected;
497
498         }
499
500         /* check for edid as well */
501         if (radeon_connector->edid)
502                 ret = connector_status_connected;
503         else {
504                 if (radeon_connector->ddc_bus) {
505                         radeon_connector->edid = drm_get_edid(&radeon_connector->base,
506                                                               &radeon_connector->ddc_bus->adapter);
507                         if (radeon_connector->edid)
508                                 ret = connector_status_connected;
509                 }
510         }
511         /* check acpi lid status ??? */
512
513         radeon_connector_update_scratch_regs(connector, ret);
514         return ret;
515 }
516
517 static void radeon_connector_destroy(struct drm_connector *connector)
518 {
519         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
520
521         if (radeon_connector->ddc_bus)
522                 radeon_i2c_destroy(radeon_connector->ddc_bus);
523         if (radeon_connector->edid)
524                 kfree(radeon_connector->edid);
525         kfree(radeon_connector->con_priv);
526         drm_sysfs_connector_remove(connector);
527         drm_connector_cleanup(connector);
528         kfree(connector);
529 }
530
531 static int radeon_lvds_set_property(struct drm_connector *connector,
532                                     struct drm_property *property,
533                                     uint64_t value)
534 {
535         struct drm_device *dev = connector->dev;
536         struct radeon_encoder *radeon_encoder;
537         enum radeon_rmx_type rmx_type;
538
539         DRM_DEBUG_KMS("\n");
540         if (property != dev->mode_config.scaling_mode_property)
541                 return 0;
542
543         if (connector->encoder)
544                 radeon_encoder = to_radeon_encoder(connector->encoder);
545         else {
546                 struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
547                 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
548         }
549
550         switch (value) {
551         case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
552         case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
553         case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
554         default:
555         case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
556         }
557         if (radeon_encoder->rmx_type == rmx_type)
558                 return 0;
559
560         radeon_encoder->rmx_type = rmx_type;
561
562         radeon_property_change_mode(&radeon_encoder->base);
563         return 0;
564 }
565
566
567 struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
568         .get_modes = radeon_lvds_get_modes,
569         .mode_valid = radeon_lvds_mode_valid,
570         .best_encoder = radeon_best_single_encoder,
571 };
572
573 struct drm_connector_funcs radeon_lvds_connector_funcs = {
574         .dpms = drm_helper_connector_dpms,
575         .detect = radeon_lvds_detect,
576         .fill_modes = drm_helper_probe_single_connector_modes,
577         .destroy = radeon_connector_destroy,
578         .set_property = radeon_lvds_set_property,
579 };
580
581 static int radeon_vga_get_modes(struct drm_connector *connector)
582 {
583         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
584         int ret;
585
586         ret = radeon_ddc_get_modes(radeon_connector);
587
588         return ret;
589 }
590
591 static int radeon_vga_mode_valid(struct drm_connector *connector,
592                                   struct drm_display_mode *mode)
593 {
594         /* XXX check mode bandwidth */
595         /* XXX verify against max DAC output frequency */
596         return MODE_OK;
597 }
598
599 static enum drm_connector_status radeon_vga_detect(struct drm_connector *connector)
600 {
601         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
602         struct drm_encoder *encoder;
603         struct drm_encoder_helper_funcs *encoder_funcs;
604         bool dret = false;
605         enum drm_connector_status ret = connector_status_disconnected;
606
607         encoder = radeon_best_single_encoder(connector);
608         if (!encoder)
609                 ret = connector_status_disconnected;
610
611         if (radeon_connector->ddc_bus)
612                 dret = radeon_ddc_probe(radeon_connector);
613         if (dret) {
614                 if (radeon_connector->edid) {
615                         kfree(radeon_connector->edid);
616                         radeon_connector->edid = NULL;
617                 }
618                 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
619
620                 if (!radeon_connector->edid) {
621                         DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
622                                         drm_get_connector_name(connector));
623                         ret = connector_status_connected;
624                 } else {
625                         radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
626
627                         /* some oems have boards with separate digital and analog connectors
628                          * with a shared ddc line (often vga + hdmi)
629                          */
630                         if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
631                                 kfree(radeon_connector->edid);
632                                 radeon_connector->edid = NULL;
633                                 ret = connector_status_disconnected;
634                         } else
635                                 ret = connector_status_connected;
636                 }
637         } else {
638                 if (radeon_connector->dac_load_detect && encoder) {
639                         encoder_funcs = encoder->helper_private;
640                         ret = encoder_funcs->detect(encoder, connector);
641                 }
642         }
643
644         if (ret == connector_status_connected)
645                 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
646         radeon_connector_update_scratch_regs(connector, ret);
647         return ret;
648 }
649
650 struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
651         .get_modes = radeon_vga_get_modes,
652         .mode_valid = radeon_vga_mode_valid,
653         .best_encoder = radeon_best_single_encoder,
654 };
655
656 struct drm_connector_funcs radeon_vga_connector_funcs = {
657         .dpms = drm_helper_connector_dpms,
658         .detect = radeon_vga_detect,
659         .fill_modes = drm_helper_probe_single_connector_modes,
660         .destroy = radeon_connector_destroy,
661         .set_property = radeon_connector_set_property,
662 };
663
664 static int radeon_tv_get_modes(struct drm_connector *connector)
665 {
666         struct drm_device *dev = connector->dev;
667         struct radeon_device *rdev = dev->dev_private;
668         struct drm_display_mode *tv_mode;
669         struct drm_encoder *encoder;
670
671         encoder = radeon_best_single_encoder(connector);
672         if (!encoder)
673                 return 0;
674
675         /* avivo chips can scale any mode */
676         if (rdev->family >= CHIP_RS600)
677                 /* add scaled modes */
678                 radeon_add_common_modes(encoder, connector);
679         else {
680                 /* only 800x600 is supported right now on pre-avivo chips */
681                 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
682                 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
683                 drm_mode_probed_add(connector, tv_mode);
684         }
685         return 1;
686 }
687
688 static int radeon_tv_mode_valid(struct drm_connector *connector,
689                                 struct drm_display_mode *mode)
690 {
691         if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
692                 return MODE_CLOCK_RANGE;
693         return MODE_OK;
694 }
695
696 static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector)
697 {
698         struct drm_encoder *encoder;
699         struct drm_encoder_helper_funcs *encoder_funcs;
700         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
701         enum drm_connector_status ret = connector_status_disconnected;
702
703         if (!radeon_connector->dac_load_detect)
704                 return ret;
705
706         encoder = radeon_best_single_encoder(connector);
707         if (!encoder)
708                 ret = connector_status_disconnected;
709         else {
710                 encoder_funcs = encoder->helper_private;
711                 ret = encoder_funcs->detect(encoder, connector);
712         }
713         if (ret == connector_status_connected)
714                 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
715         radeon_connector_update_scratch_regs(connector, ret);
716         return ret;
717 }
718
719 struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
720         .get_modes = radeon_tv_get_modes,
721         .mode_valid = radeon_tv_mode_valid,
722         .best_encoder = radeon_best_single_encoder,
723 };
724
725 struct drm_connector_funcs radeon_tv_connector_funcs = {
726         .dpms = drm_helper_connector_dpms,
727         .detect = radeon_tv_detect,
728         .fill_modes = drm_helper_probe_single_connector_modes,
729         .destroy = radeon_connector_destroy,
730         .set_property = radeon_connector_set_property,
731 };
732
733 static int radeon_dvi_get_modes(struct drm_connector *connector)
734 {
735         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
736         int ret;
737
738         ret = radeon_ddc_get_modes(radeon_connector);
739         return ret;
740 }
741
742 /*
743  * DVI is complicated
744  * Do a DDC probe, if DDC probe passes, get the full EDID so
745  * we can do analog/digital monitor detection at this point.
746  * If the monitor is an analog monitor or we got no DDC,
747  * we need to find the DAC encoder object for this connector.
748  * If we got no DDC, we do load detection on the DAC encoder object.
749  * If we got analog DDC or load detection passes on the DAC encoder
750  * we have to check if this analog encoder is shared with anyone else (TV)
751  * if its shared we have to set the other connector to disconnected.
752  */
753 static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector)
754 {
755         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
756         struct drm_encoder *encoder = NULL;
757         struct drm_encoder_helper_funcs *encoder_funcs;
758         struct drm_mode_object *obj;
759         int i;
760         enum drm_connector_status ret = connector_status_disconnected;
761         bool dret = false;
762
763         if (radeon_connector->ddc_bus)
764                 dret = radeon_ddc_probe(radeon_connector);
765         if (dret) {
766                 if (radeon_connector->edid) {
767                         kfree(radeon_connector->edid);
768                         radeon_connector->edid = NULL;
769                 }
770                 radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
771
772                 if (!radeon_connector->edid) {
773                         DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
774                                         drm_get_connector_name(connector));
775                 } else {
776                         radeon_connector->use_digital = !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
777
778                         /* some oems have boards with separate digital and analog connectors
779                          * with a shared ddc line (often vga + hdmi)
780                          */
781                         if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
782                                 kfree(radeon_connector->edid);
783                                 radeon_connector->edid = NULL;
784                                 ret = connector_status_disconnected;
785                         } else
786                                 ret = connector_status_connected;
787
788                         /* This gets complicated.  We have boards with VGA + HDMI with a
789                          * shared DDC line and we have boards with DVI-D + HDMI with a shared
790                          * DDC line.  The latter is more complex because with DVI<->HDMI adapters
791                          * you don't really know what's connected to which port as both are digital.
792                          */
793                         if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
794                                 struct drm_device *dev = connector->dev;
795                                 struct radeon_device *rdev = dev->dev_private;
796                                 struct drm_connector *list_connector;
797                                 struct radeon_connector *list_radeon_connector;
798                                 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
799                                         if (connector == list_connector)
800                                                 continue;
801                                         list_radeon_connector = to_radeon_connector(list_connector);
802                                         if (list_radeon_connector->shared_ddc &&
803                                             (list_radeon_connector->ddc_bus->rec.i2c_id ==
804                                              radeon_connector->ddc_bus->rec.i2c_id)) {
805                                                 /* cases where both connectors are digital */
806                                                 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
807                                                         /* hpd is our only option in this case */
808                                                         if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
809                                                                 kfree(radeon_connector->edid);
810                                                                 radeon_connector->edid = NULL;
811                                                                 ret = connector_status_disconnected;
812                                                         }
813                                                 }
814                                         }
815                                 }
816                         }
817                 }
818         }
819
820         if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
821                 goto out;
822
823         /* find analog encoder */
824         if (radeon_connector->dac_load_detect) {
825                 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
826                         if (connector->encoder_ids[i] == 0)
827                                 break;
828
829                         obj = drm_mode_object_find(connector->dev,
830                                                    connector->encoder_ids[i],
831                                                    DRM_MODE_OBJECT_ENCODER);
832                         if (!obj)
833                                 continue;
834
835                         encoder = obj_to_encoder(obj);
836
837                         encoder_funcs = encoder->helper_private;
838                         if (encoder_funcs->detect) {
839                                 if (ret != connector_status_connected) {
840                                         ret = encoder_funcs->detect(encoder, connector);
841                                         if (ret == connector_status_connected) {
842                                                 radeon_connector->use_digital = false;
843                                         }
844                                 }
845                                 break;
846                         }
847                 }
848         }
849
850         if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
851             encoder) {
852                 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
853         }
854
855 out:
856         /* updated in get modes as well since we need to know if it's analog or digital */
857         radeon_connector_update_scratch_regs(connector, ret);
858         return ret;
859 }
860
861 /* okay need to be smart in here about which encoder to pick */
862 struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
863 {
864         int enc_id = connector->encoder_ids[0];
865         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
866         struct drm_mode_object *obj;
867         struct drm_encoder *encoder;
868         int i;
869         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
870                 if (connector->encoder_ids[i] == 0)
871                         break;
872
873                 obj = drm_mode_object_find(connector->dev, connector->encoder_ids[i], DRM_MODE_OBJECT_ENCODER);
874                 if (!obj)
875                         continue;
876
877                 encoder = obj_to_encoder(obj);
878
879                 if (radeon_connector->use_digital == true) {
880                         if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
881                                 return encoder;
882                 } else {
883                         if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
884                             encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
885                                 return encoder;
886                 }
887         }
888
889         /* see if we have a default encoder  TODO */
890
891         /* then check use digitial */
892         /* pick the first one */
893         if (enc_id) {
894                 obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
895                 if (!obj)
896                         return NULL;
897                 encoder = obj_to_encoder(obj);
898                 return encoder;
899         }
900         return NULL;
901 }
902
903 static void radeon_dvi_force(struct drm_connector *connector)
904 {
905         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
906         if (connector->force == DRM_FORCE_ON)
907                 radeon_connector->use_digital = false;
908         if (connector->force == DRM_FORCE_ON_DIGITAL)
909                 radeon_connector->use_digital = true;
910 }
911
912 static int radeon_dvi_mode_valid(struct drm_connector *connector,
913                                   struct drm_display_mode *mode)
914 {
915         struct drm_device *dev = connector->dev;
916         struct radeon_device *rdev = dev->dev_private;
917         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
918
919         /* XXX check mode bandwidth */
920
921         /* clocks over 135 MHz have heat issues with DVI on RV100 */
922         if (radeon_connector->use_digital &&
923             (rdev->family == CHIP_RV100) &&
924             (mode->clock > 135000))
925                 return MODE_CLOCK_HIGH;
926
927         if (radeon_connector->use_digital && (mode->clock > 165000)) {
928                 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
929                     (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
930                     (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
931                         return MODE_OK;
932                 else
933                         return MODE_CLOCK_HIGH;
934         }
935         return MODE_OK;
936 }
937
938 struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
939         .get_modes = radeon_dvi_get_modes,
940         .mode_valid = radeon_dvi_mode_valid,
941         .best_encoder = radeon_dvi_encoder,
942 };
943
944 struct drm_connector_funcs radeon_dvi_connector_funcs = {
945         .dpms = drm_helper_connector_dpms,
946         .detect = radeon_dvi_detect,
947         .fill_modes = drm_helper_probe_single_connector_modes,
948         .set_property = radeon_connector_set_property,
949         .destroy = radeon_connector_destroy,
950         .force = radeon_dvi_force,
951 };
952
953 static void radeon_dp_connector_destroy(struct drm_connector *connector)
954 {
955         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
956         struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
957
958         if (radeon_connector->ddc_bus)
959                 radeon_i2c_destroy(radeon_connector->ddc_bus);
960         if (radeon_connector->edid)
961                 kfree(radeon_connector->edid);
962         if (radeon_dig_connector->dp_i2c_bus)
963                 radeon_i2c_destroy(radeon_dig_connector->dp_i2c_bus);
964         kfree(radeon_connector->con_priv);
965         drm_sysfs_connector_remove(connector);
966         drm_connector_cleanup(connector);
967         kfree(connector);
968 }
969
970 static int radeon_dp_get_modes(struct drm_connector *connector)
971 {
972         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
973         int ret;
974
975         ret = radeon_ddc_get_modes(radeon_connector);
976         return ret;
977 }
978
979 static enum drm_connector_status radeon_dp_detect(struct drm_connector *connector)
980 {
981         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
982         enum drm_connector_status ret = connector_status_disconnected;
983         struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
984         u8 sink_type;
985
986         if (radeon_connector->edid) {
987                 kfree(radeon_connector->edid);
988                 radeon_connector->edid = NULL;
989         }
990
991         sink_type = radeon_dp_getsinktype(radeon_connector);
992         if ((sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
993             (sink_type == CONNECTOR_OBJECT_ID_eDP)) {
994                 if (radeon_dp_getdpcd(radeon_connector)) {
995                         radeon_dig_connector->dp_sink_type = sink_type;
996                         ret = connector_status_connected;
997                 }
998         } else {
999                 if (radeon_ddc_probe(radeon_connector)) {
1000                         radeon_dig_connector->dp_sink_type = sink_type;
1001                         ret = connector_status_connected;
1002                 }
1003         }
1004
1005         return ret;
1006 }
1007
1008 static int radeon_dp_mode_valid(struct drm_connector *connector,
1009                                   struct drm_display_mode *mode)
1010 {
1011         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1012         struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
1013
1014         /* XXX check mode bandwidth */
1015
1016         if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
1017             (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
1018                 return radeon_dp_mode_valid_helper(radeon_connector, mode);
1019         else
1020                 return MODE_OK;
1021 }
1022
1023 struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
1024         .get_modes = radeon_dp_get_modes,
1025         .mode_valid = radeon_dp_mode_valid,
1026         .best_encoder = radeon_dvi_encoder,
1027 };
1028
1029 struct drm_connector_funcs radeon_dp_connector_funcs = {
1030         .dpms = drm_helper_connector_dpms,
1031         .detect = radeon_dp_detect,
1032         .fill_modes = drm_helper_probe_single_connector_modes,
1033         .set_property = radeon_connector_set_property,
1034         .destroy = radeon_dp_connector_destroy,
1035         .force = radeon_dvi_force,
1036 };
1037
1038 void
1039 radeon_add_atom_connector(struct drm_device *dev,
1040                           uint32_t connector_id,
1041                           uint32_t supported_device,
1042                           int connector_type,
1043                           struct radeon_i2c_bus_rec *i2c_bus,
1044                           bool linkb,
1045                           uint32_t igp_lane_info,
1046                           uint16_t connector_object_id,
1047                           struct radeon_hpd *hpd)
1048 {
1049         struct radeon_device *rdev = dev->dev_private;
1050         struct drm_connector *connector;
1051         struct radeon_connector *radeon_connector;
1052         struct radeon_connector_atom_dig *radeon_dig_connector;
1053         uint32_t subpixel_order = SubPixelNone;
1054         bool shared_ddc = false;
1055
1056         /* fixme - tv/cv/din */
1057         if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1058                 return;
1059
1060         /* see if we already added it */
1061         list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1062                 radeon_connector = to_radeon_connector(connector);
1063                 if (radeon_connector->connector_id == connector_id) {
1064                         radeon_connector->devices |= supported_device;
1065                         return;
1066                 }
1067                 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1068                         if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1069                                 radeon_connector->shared_ddc = true;
1070                                 shared_ddc = true;
1071                         }
1072                 }
1073         }
1074
1075         radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1076         if (!radeon_connector)
1077                 return;
1078
1079         connector = &radeon_connector->base;
1080
1081         radeon_connector->connector_id = connector_id;
1082         radeon_connector->devices = supported_device;
1083         radeon_connector->shared_ddc = shared_ddc;
1084         radeon_connector->connector_object_id = connector_object_id;
1085         radeon_connector->hpd = *hpd;
1086         switch (connector_type) {
1087         case DRM_MODE_CONNECTOR_VGA:
1088                 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1089                 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1090                 if (i2c_bus->valid) {
1091                         radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1092                         if (!radeon_connector->ddc_bus)
1093                                 goto failed;
1094                 }
1095                 radeon_connector->dac_load_detect = true;
1096                 drm_connector_attach_property(&radeon_connector->base,
1097                                               rdev->mode_info.load_detect_property,
1098                                               1);
1099                 /* no HPD on analog connectors */
1100                 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1101                 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1102                 break;
1103         case DRM_MODE_CONNECTOR_DVIA:
1104                 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1105                 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1106                 if (i2c_bus->valid) {
1107                         radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1108                         if (!radeon_connector->ddc_bus)
1109                                 goto failed;
1110                 }
1111                 radeon_connector->dac_load_detect = true;
1112                 drm_connector_attach_property(&radeon_connector->base,
1113                                               rdev->mode_info.load_detect_property,
1114                                               1);
1115                 /* no HPD on analog connectors */
1116                 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1117                 break;
1118         case DRM_MODE_CONNECTOR_DVII:
1119         case DRM_MODE_CONNECTOR_DVID:
1120                 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1121                 if (!radeon_dig_connector)
1122                         goto failed;
1123                 radeon_dig_connector->linkb = linkb;
1124                 radeon_dig_connector->igp_lane_info = igp_lane_info;
1125                 radeon_connector->con_priv = radeon_dig_connector;
1126                 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1127                 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1128                 if (i2c_bus->valid) {
1129                         radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1130                         if (!radeon_connector->ddc_bus)
1131                                 goto failed;
1132                 }
1133                 subpixel_order = SubPixelHorizontalRGB;
1134                 drm_connector_attach_property(&radeon_connector->base,
1135                                               rdev->mode_info.coherent_mode_property,
1136                                               1);
1137                 drm_connector_attach_property(&radeon_connector->base,
1138                                               rdev->mode_info.underscan_property,
1139                                               UNDERSCAN_AUTO);
1140                 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1141                         radeon_connector->dac_load_detect = true;
1142                         drm_connector_attach_property(&radeon_connector->base,
1143                                                       rdev->mode_info.load_detect_property,
1144                                                       1);
1145                 }
1146                 break;
1147         case DRM_MODE_CONNECTOR_HDMIA:
1148         case DRM_MODE_CONNECTOR_HDMIB:
1149                 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1150                 if (!radeon_dig_connector)
1151                         goto failed;
1152                 radeon_dig_connector->linkb = linkb;
1153                 radeon_dig_connector->igp_lane_info = igp_lane_info;
1154                 radeon_connector->con_priv = radeon_dig_connector;
1155                 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1156                 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1157                 if (i2c_bus->valid) {
1158                         radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI");
1159                         if (!radeon_connector->ddc_bus)
1160                                 goto failed;
1161                 }
1162                 drm_connector_attach_property(&radeon_connector->base,
1163                                               rdev->mode_info.coherent_mode_property,
1164                                               1);
1165                 drm_connector_attach_property(&radeon_connector->base,
1166                                               rdev->mode_info.underscan_property,
1167                                               UNDERSCAN_AUTO);
1168                 subpixel_order = SubPixelHorizontalRGB;
1169                 break;
1170         case DRM_MODE_CONNECTOR_DisplayPort:
1171         case DRM_MODE_CONNECTOR_eDP:
1172                 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1173                 if (!radeon_dig_connector)
1174                         goto failed;
1175                 radeon_dig_connector->linkb = linkb;
1176                 radeon_dig_connector->igp_lane_info = igp_lane_info;
1177                 radeon_connector->con_priv = radeon_dig_connector;
1178                 drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
1179                 drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
1180                 if (i2c_bus->valid) {
1181                         /* add DP i2c bus */
1182                         if (connector_type == DRM_MODE_CONNECTOR_eDP)
1183                                 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "eDP-auxch");
1184                         else
1185                                 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1186                         if (!radeon_dig_connector->dp_i2c_bus)
1187                                 goto failed;
1188                         if (connector_type == DRM_MODE_CONNECTOR_eDP)
1189                                 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "eDP");
1190                         else
1191                                 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
1192                         if (!radeon_connector->ddc_bus)
1193                                 goto failed;
1194                 }
1195                 subpixel_order = SubPixelHorizontalRGB;
1196                 drm_connector_attach_property(&radeon_connector->base,
1197                                               rdev->mode_info.coherent_mode_property,
1198                                               1);
1199                 drm_connector_attach_property(&radeon_connector->base,
1200                                               rdev->mode_info.underscan_property,
1201                                               UNDERSCAN_AUTO);
1202                 break;
1203         case DRM_MODE_CONNECTOR_SVIDEO:
1204         case DRM_MODE_CONNECTOR_Composite:
1205         case DRM_MODE_CONNECTOR_9PinDIN:
1206                 if (radeon_tv == 1) {
1207                         drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1208                         drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1209                         radeon_connector->dac_load_detect = true;
1210                         drm_connector_attach_property(&radeon_connector->base,
1211                                                       rdev->mode_info.load_detect_property,
1212                                                       1);
1213                         drm_connector_attach_property(&radeon_connector->base,
1214                                                       rdev->mode_info.tv_std_property,
1215                                                       radeon_atombios_get_tv_info(rdev));
1216                         /* no HPD on analog connectors */
1217                         radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1218                 }
1219                 break;
1220         case DRM_MODE_CONNECTOR_LVDS:
1221                 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
1222                 if (!radeon_dig_connector)
1223                         goto failed;
1224                 radeon_dig_connector->linkb = linkb;
1225                 radeon_dig_connector->igp_lane_info = igp_lane_info;
1226                 radeon_connector->con_priv = radeon_dig_connector;
1227                 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1228                 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1229                 if (i2c_bus->valid) {
1230                         radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1231                         if (!radeon_connector->ddc_bus)
1232                                 goto failed;
1233                 }
1234                 drm_connector_attach_property(&radeon_connector->base,
1235                                               dev->mode_config.scaling_mode_property,
1236                                               DRM_MODE_SCALE_FULLSCREEN);
1237                 subpixel_order = SubPixelHorizontalRGB;
1238                 break;
1239         }
1240
1241         if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
1242                 if (i2c_bus->valid)
1243                         connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1244         } else
1245                 connector->polled = DRM_CONNECTOR_POLL_HPD;
1246
1247         connector->display_info.subpixel_order = subpixel_order;
1248         drm_sysfs_connector_add(connector);
1249         return;
1250
1251 failed:
1252         if (radeon_connector->ddc_bus)
1253                 radeon_i2c_destroy(radeon_connector->ddc_bus);
1254         drm_connector_cleanup(connector);
1255         kfree(connector);
1256 }
1257
1258 void
1259 radeon_add_legacy_connector(struct drm_device *dev,
1260                             uint32_t connector_id,
1261                             uint32_t supported_device,
1262                             int connector_type,
1263                             struct radeon_i2c_bus_rec *i2c_bus,
1264                             uint16_t connector_object_id,
1265                             struct radeon_hpd *hpd)
1266 {
1267         struct radeon_device *rdev = dev->dev_private;
1268         struct drm_connector *connector;
1269         struct radeon_connector *radeon_connector;
1270         uint32_t subpixel_order = SubPixelNone;
1271
1272         /* fixme - tv/cv/din */
1273         if (connector_type == DRM_MODE_CONNECTOR_Unknown)
1274                 return;
1275
1276         /* see if we already added it */
1277         list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1278                 radeon_connector = to_radeon_connector(connector);
1279                 if (radeon_connector->connector_id == connector_id) {
1280                         radeon_connector->devices |= supported_device;
1281                         return;
1282                 }
1283         }
1284
1285         radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
1286         if (!radeon_connector)
1287                 return;
1288
1289         connector = &radeon_connector->base;
1290
1291         radeon_connector->connector_id = connector_id;
1292         radeon_connector->devices = supported_device;
1293         radeon_connector->connector_object_id = connector_object_id;
1294         radeon_connector->hpd = *hpd;
1295         switch (connector_type) {
1296         case DRM_MODE_CONNECTOR_VGA:
1297                 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1298                 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1299                 if (i2c_bus->valid) {
1300                         radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA");
1301                         if (!radeon_connector->ddc_bus)
1302                                 goto failed;
1303                 }
1304                 radeon_connector->dac_load_detect = true;
1305                 drm_connector_attach_property(&radeon_connector->base,
1306                                               rdev->mode_info.load_detect_property,
1307                                               1);
1308                 /* no HPD on analog connectors */
1309                 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1310                 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1311                 break;
1312         case DRM_MODE_CONNECTOR_DVIA:
1313                 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1314                 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1315                 if (i2c_bus->valid) {
1316                         radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1317                         if (!radeon_connector->ddc_bus)
1318                                 goto failed;
1319                 }
1320                 radeon_connector->dac_load_detect = true;
1321                 drm_connector_attach_property(&radeon_connector->base,
1322                                               rdev->mode_info.load_detect_property,
1323                                               1);
1324                 /* no HPD on analog connectors */
1325                 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1326                 break;
1327         case DRM_MODE_CONNECTOR_DVII:
1328         case DRM_MODE_CONNECTOR_DVID:
1329                 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1330                 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1331                 if (i2c_bus->valid) {
1332                         radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI");
1333                         if (!radeon_connector->ddc_bus)
1334                                 goto failed;
1335                 }
1336                 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1337                         radeon_connector->dac_load_detect = true;
1338                         drm_connector_attach_property(&radeon_connector->base,
1339                                                       rdev->mode_info.load_detect_property,
1340                                                       1);
1341                 }
1342                 subpixel_order = SubPixelHorizontalRGB;
1343                 break;
1344         case DRM_MODE_CONNECTOR_SVIDEO:
1345         case DRM_MODE_CONNECTOR_Composite:
1346         case DRM_MODE_CONNECTOR_9PinDIN:
1347                 if (radeon_tv == 1) {
1348                         drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
1349                         drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
1350                         radeon_connector->dac_load_detect = true;
1351                         /* RS400,RC410,RS480 chipset seems to report a lot
1352                          * of false positive on load detect, we haven't yet
1353                          * found a way to make load detect reliable on those
1354                          * chipset, thus just disable it for TV.
1355                          */
1356                         if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
1357                                 radeon_connector->dac_load_detect = false;
1358                         drm_connector_attach_property(&radeon_connector->base,
1359                                                       rdev->mode_info.load_detect_property,
1360                                                       radeon_connector->dac_load_detect);
1361                         drm_connector_attach_property(&radeon_connector->base,
1362                                                       rdev->mode_info.tv_std_property,
1363                                                       radeon_combios_get_tv_info(rdev));
1364                         /* no HPD on analog connectors */
1365                         radeon_connector->hpd.hpd = RADEON_HPD_NONE;
1366                 }
1367                 break;
1368         case DRM_MODE_CONNECTOR_LVDS:
1369                 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1370                 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1371                 if (i2c_bus->valid) {
1372                         radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS");
1373                         if (!radeon_connector->ddc_bus)
1374                                 goto failed;
1375                 }
1376                 drm_connector_attach_property(&radeon_connector->base,
1377                                               dev->mode_config.scaling_mode_property,
1378                                               DRM_MODE_SCALE_FULLSCREEN);
1379                 subpixel_order = SubPixelHorizontalRGB;
1380                 break;
1381         }
1382
1383         if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
1384                 if (i2c_bus->valid)
1385                         connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1386         } else
1387                 connector->polled = DRM_CONNECTOR_POLL_HPD;
1388         connector->display_info.subpixel_order = subpixel_order;
1389         drm_sysfs_connector_add(connector);
1390         return;
1391
1392 failed:
1393         if (radeon_connector->ddc_bus)
1394                 radeon_i2c_destroy(radeon_connector->ddc_bus);
1395         drm_connector_cleanup(connector);
1396         kfree(connector);
1397 }