GNU Linux-libre 4.4.285-gnu1
[releases.git] / drivers / gpu / drm / nouveau / nouveau_connector.c
1 /*
2  * Copyright (C) 2008 Maarten Maathuis.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial
15  * portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  */
26
27 #include <acpi/button.h>
28
29 #include <linux/pm_runtime.h>
30
31 #include <drm/drmP.h>
32 #include <drm/drm_edid.h>
33 #include <drm/drm_crtc_helper.h>
34
35 #include "nouveau_reg.h"
36 #include "nouveau_drm.h"
37 #include "dispnv04/hw.h"
38 #include "nouveau_acpi.h"
39
40 #include "nouveau_display.h"
41 #include "nouveau_connector.h"
42 #include "nouveau_encoder.h"
43 #include "nouveau_crtc.h"
44
45 #include <nvif/event.h>
46
47 MODULE_PARM_DESC(tv_disable, "Disable TV-out detection");
48 int nouveau_tv_disable = 0;
49 module_param_named(tv_disable, nouveau_tv_disable, int, 0400);
50
51 MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status");
52 int nouveau_ignorelid = 0;
53 module_param_named(ignorelid, nouveau_ignorelid, int, 0400);
54
55 MODULE_PARM_DESC(duallink, "Allow dual-link TMDS (default: enabled)");
56 int nouveau_duallink = 1;
57 module_param_named(duallink, nouveau_duallink, int, 0400);
58
59 struct nouveau_encoder *
60 find_encoder(struct drm_connector *connector, int type)
61 {
62         struct drm_device *dev = connector->dev;
63         struct nouveau_encoder *nv_encoder;
64         struct drm_encoder *enc;
65         int i, id;
66
67         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
68                 id = connector->encoder_ids[i];
69                 if (!id)
70                         break;
71
72                 enc = drm_encoder_find(dev, id);
73                 if (!enc)
74                         continue;
75                 nv_encoder = nouveau_encoder(enc);
76
77                 if (type == DCB_OUTPUT_ANY ||
78                     (nv_encoder->dcb && nv_encoder->dcb->type == type))
79                         return nv_encoder;
80         }
81
82         return NULL;
83 }
84
85 struct nouveau_connector *
86 nouveau_encoder_connector_get(struct nouveau_encoder *encoder)
87 {
88         struct drm_device *dev = to_drm_encoder(encoder)->dev;
89         struct drm_connector *drm_connector;
90
91         list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
92                 if (drm_connector->encoder == to_drm_encoder(encoder))
93                         return nouveau_connector(drm_connector);
94         }
95
96         return NULL;
97 }
98
99 static void
100 nouveau_connector_destroy(struct drm_connector *connector)
101 {
102         struct nouveau_connector *nv_connector = nouveau_connector(connector);
103         nvif_notify_fini(&nv_connector->hpd);
104         kfree(nv_connector->edid);
105         drm_connector_unregister(connector);
106         drm_connector_cleanup(connector);
107         if (nv_connector->aux.transfer)
108                 drm_dp_aux_unregister(&nv_connector->aux);
109         kfree(connector);
110 }
111
112 static struct nouveau_encoder *
113 nouveau_connector_ddc_detect(struct drm_connector *connector)
114 {
115         struct drm_device *dev = connector->dev;
116         struct nouveau_connector *nv_connector = nouveau_connector(connector);
117         struct nouveau_drm *drm = nouveau_drm(dev);
118         struct nvkm_gpio *gpio = nvxx_gpio(&drm->device);
119         struct nouveau_encoder *nv_encoder;
120         struct drm_encoder *encoder;
121         int i, panel = -ENODEV;
122
123         /* eDP panels need powering on by us (if the VBIOS doesn't default it
124          * to on) before doing any AUX channel transactions.  LVDS panel power
125          * is handled by the SOR itself, and not required for LVDS DDC.
126          */
127         if (nv_connector->type == DCB_CONNECTOR_eDP) {
128                 panel = nvkm_gpio_get(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff);
129                 if (panel == 0) {
130                         nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, 1);
131                         msleep(300);
132                 }
133         }
134
135         for (i = 0; nv_encoder = NULL, i < DRM_CONNECTOR_MAX_ENCODER; i++) {
136                 int id = connector->encoder_ids[i];
137                 if (id == 0)
138                         break;
139
140                 encoder = drm_encoder_find(dev, id);
141                 if (!encoder)
142                         continue;
143                 nv_encoder = nouveau_encoder(encoder);
144
145                 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
146                         int ret = nouveau_dp_detect(nv_encoder);
147                         if (ret == 0)
148                                 break;
149                 } else
150                 if (nv_encoder->i2c) {
151                         if (nvkm_probe_i2c(nv_encoder->i2c, 0x50))
152                                 break;
153                 }
154         }
155
156         /* eDP panel not detected, restore panel power GPIO to previous
157          * state to avoid confusing the SOR for other output types.
158          */
159         if (!nv_encoder && panel == 0)
160                 nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, panel);
161
162         return nv_encoder;
163 }
164
165 static struct nouveau_encoder *
166 nouveau_connector_of_detect(struct drm_connector *connector)
167 {
168 #ifdef __powerpc__
169         struct drm_device *dev = connector->dev;
170         struct nouveau_connector *nv_connector = nouveau_connector(connector);
171         struct nouveau_encoder *nv_encoder;
172         struct device_node *cn, *dn = pci_device_to_OF_node(dev->pdev);
173
174         if (!dn ||
175             !((nv_encoder = find_encoder(connector, DCB_OUTPUT_TMDS)) ||
176               (nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG))))
177                 return NULL;
178
179         for_each_child_of_node(dn, cn) {
180                 const char *name = of_get_property(cn, "name", NULL);
181                 const void *edid = of_get_property(cn, "EDID", NULL);
182                 int idx = name ? name[strlen(name) - 1] - 'A' : 0;
183
184                 if (nv_encoder->dcb->i2c_index == idx && edid) {
185                         nv_connector->edid =
186                                 kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
187                         of_node_put(cn);
188                         return nv_encoder;
189                 }
190         }
191 #endif
192         return NULL;
193 }
194
195 static void
196 nouveau_connector_set_encoder(struct drm_connector *connector,
197                               struct nouveau_encoder *nv_encoder)
198 {
199         struct nouveau_connector *nv_connector = nouveau_connector(connector);
200         struct nouveau_drm *drm = nouveau_drm(connector->dev);
201         struct drm_device *dev = connector->dev;
202
203         if (nv_connector->detected_encoder == nv_encoder)
204                 return;
205         nv_connector->detected_encoder = nv_encoder;
206
207         if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
208                 connector->interlace_allowed = true;
209                 connector->doublescan_allowed = true;
210         } else
211         if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS ||
212             nv_encoder->dcb->type == DCB_OUTPUT_TMDS) {
213                 connector->doublescan_allowed = false;
214                 connector->interlace_allowed = false;
215         } else {
216                 connector->doublescan_allowed = true;
217                 if (drm->device.info.family == NV_DEVICE_INFO_V0_KELVIN ||
218                     (drm->device.info.family == NV_DEVICE_INFO_V0_CELSIUS &&
219                      (dev->pdev->device & 0x0ff0) != 0x0100 &&
220                      (dev->pdev->device & 0x0ff0) != 0x0150))
221                         /* HW is broken */
222                         connector->interlace_allowed = false;
223                 else
224                         connector->interlace_allowed = true;
225         }
226
227         if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
228                 drm_object_property_set_value(&connector->base,
229                         dev->mode_config.dvi_i_subconnector_property,
230                         nv_encoder->dcb->type == DCB_OUTPUT_TMDS ?
231                         DRM_MODE_SUBCONNECTOR_DVID :
232                         DRM_MODE_SUBCONNECTOR_DVIA);
233         }
234 }
235
236 static enum drm_connector_status
237 nouveau_connector_detect(struct drm_connector *connector, bool force)
238 {
239         struct drm_device *dev = connector->dev;
240         struct nouveau_drm *drm = nouveau_drm(dev);
241         struct nouveau_connector *nv_connector = nouveau_connector(connector);
242         struct nouveau_encoder *nv_encoder = NULL;
243         struct nouveau_encoder *nv_partner;
244         struct i2c_adapter *i2c;
245         int type;
246         int ret;
247         enum drm_connector_status conn_status = connector_status_disconnected;
248
249         /* Cleanup the previous EDID block. */
250         if (nv_connector->edid) {
251                 drm_mode_connector_update_edid_property(connector, NULL);
252                 kfree(nv_connector->edid);
253                 nv_connector->edid = NULL;
254         }
255
256         /* Outputs are only polled while runtime active, so resuming the
257          * device here is unnecessary (and would deadlock upon runtime suspend
258          * because it waits for polling to finish). We do however, want to
259          * prevent the autosuspend timer from elapsing during this operation
260          * if possible.
261          */
262         if (drm_kms_helper_is_poll_worker()) {
263                 pm_runtime_get_noresume(dev->dev);
264         } else {
265                 ret = pm_runtime_get_sync(dev->dev);
266                 if (ret < 0 && ret != -EACCES) {
267                         pm_runtime_put_autosuspend(dev->dev);
268                         return conn_status;
269                 }
270         }
271
272         nv_encoder = nouveau_connector_ddc_detect(connector);
273         if (nv_encoder && (i2c = nv_encoder->i2c) != NULL) {
274                 nv_connector->edid = drm_get_edid(connector, i2c);
275                 drm_mode_connector_update_edid_property(connector,
276                                                         nv_connector->edid);
277                 if (!nv_connector->edid) {
278                         NV_ERROR(drm, "DDC responded, but no EDID for %s\n",
279                                  connector->name);
280                         goto detect_analog;
281                 }
282
283                 /* Override encoder type for DVI-I based on whether EDID
284                  * says the display is digital or analog, both use the
285                  * same i2c channel so the value returned from ddc_detect
286                  * isn't necessarily correct.
287                  */
288                 nv_partner = NULL;
289                 if (nv_encoder->dcb->type == DCB_OUTPUT_TMDS)
290                         nv_partner = find_encoder(connector, DCB_OUTPUT_ANALOG);
291                 if (nv_encoder->dcb->type == DCB_OUTPUT_ANALOG)
292                         nv_partner = find_encoder(connector, DCB_OUTPUT_TMDS);
293
294                 if (nv_partner && ((nv_encoder->dcb->type == DCB_OUTPUT_ANALOG &&
295                                     nv_partner->dcb->type == DCB_OUTPUT_TMDS) ||
296                                    (nv_encoder->dcb->type == DCB_OUTPUT_TMDS &&
297                                     nv_partner->dcb->type == DCB_OUTPUT_ANALOG))) {
298                         if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
299                                 type = DCB_OUTPUT_TMDS;
300                         else
301                                 type = DCB_OUTPUT_ANALOG;
302
303                         nv_encoder = find_encoder(connector, type);
304                 }
305
306                 nouveau_connector_set_encoder(connector, nv_encoder);
307                 conn_status = connector_status_connected;
308                 goto out;
309         }
310
311         nv_encoder = nouveau_connector_of_detect(connector);
312         if (nv_encoder) {
313                 nouveau_connector_set_encoder(connector, nv_encoder);
314                 conn_status = connector_status_connected;
315                 goto out;
316         }
317
318 detect_analog:
319         nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG);
320         if (!nv_encoder && !nouveau_tv_disable)
321                 nv_encoder = find_encoder(connector, DCB_OUTPUT_TV);
322         if (nv_encoder && force) {
323                 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
324                 const struct drm_encoder_helper_funcs *helper =
325                                                 encoder->helper_private;
326
327                 if (helper->detect(encoder, connector) ==
328                                                 connector_status_connected) {
329                         nouveau_connector_set_encoder(connector, nv_encoder);
330                         conn_status = connector_status_connected;
331                         goto out;
332                 }
333
334         }
335
336  out:
337
338         pm_runtime_mark_last_busy(dev->dev);
339         pm_runtime_put_autosuspend(dev->dev);
340
341         return conn_status;
342 }
343
344 static enum drm_connector_status
345 nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
346 {
347         struct drm_device *dev = connector->dev;
348         struct nouveau_drm *drm = nouveau_drm(dev);
349         struct nouveau_connector *nv_connector = nouveau_connector(connector);
350         struct nouveau_encoder *nv_encoder = NULL;
351         enum drm_connector_status status = connector_status_disconnected;
352
353         /* Cleanup the previous EDID block. */
354         if (nv_connector->edid) {
355                 drm_mode_connector_update_edid_property(connector, NULL);
356                 kfree(nv_connector->edid);
357                 nv_connector->edid = NULL;
358         }
359
360         nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS);
361         if (!nv_encoder)
362                 return connector_status_disconnected;
363
364         /* Try retrieving EDID via DDC */
365         if (!drm->vbios.fp_no_ddc) {
366                 status = nouveau_connector_detect(connector, force);
367                 if (status == connector_status_connected)
368                         goto out;
369         }
370
371         /* On some laptops (Sony, i'm looking at you) there appears to
372          * be no direct way of accessing the panel's EDID.  The only
373          * option available to us appears to be to ask ACPI for help..
374          *
375          * It's important this check's before trying straps, one of the
376          * said manufacturer's laptops are configured in such a way
377          * the nouveau decides an entry in the VBIOS FP mode table is
378          * valid - it's not (rh#613284)
379          */
380         if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
381                 if ((nv_connector->edid = nouveau_acpi_edid(dev, connector))) {
382                         status = connector_status_connected;
383                         goto out;
384                 }
385         }
386
387         /* If no EDID found above, and the VBIOS indicates a hardcoded
388          * modeline is avalilable for the panel, set it as the panel's
389          * native mode and exit.
390          */
391         if (nouveau_bios_fp_mode(dev, NULL) && (drm->vbios.fp_no_ddc ||
392             nv_encoder->dcb->lvdsconf.use_straps_for_mode)) {
393                 status = connector_status_connected;
394                 goto out;
395         }
396
397         /* Still nothing, some VBIOS images have a hardcoded EDID block
398          * stored for the panel stored in them.
399          */
400         if (!drm->vbios.fp_no_ddc) {
401                 struct edid *edid =
402                         (struct edid *)nouveau_bios_embedded_edid(dev);
403                 if (edid) {
404                         nv_connector->edid =
405                                         kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
406                         if (nv_connector->edid)
407                                 status = connector_status_connected;
408                 }
409         }
410
411 out:
412 #if defined(CONFIG_ACPI_BUTTON) || \
413         (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
414         if (status == connector_status_connected &&
415             !nouveau_ignorelid && !acpi_lid_open())
416                 status = connector_status_unknown;
417 #endif
418
419         drm_mode_connector_update_edid_property(connector, nv_connector->edid);
420         nouveau_connector_set_encoder(connector, nv_encoder);
421         return status;
422 }
423
424 static void
425 nouveau_connector_force(struct drm_connector *connector)
426 {
427         struct nouveau_drm *drm = nouveau_drm(connector->dev);
428         struct nouveau_connector *nv_connector = nouveau_connector(connector);
429         struct nouveau_encoder *nv_encoder;
430         int type;
431
432         if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
433                 if (connector->force == DRM_FORCE_ON_DIGITAL)
434                         type = DCB_OUTPUT_TMDS;
435                 else
436                         type = DCB_OUTPUT_ANALOG;
437         } else
438                 type = DCB_OUTPUT_ANY;
439
440         nv_encoder = find_encoder(connector, type);
441         if (!nv_encoder) {
442                 NV_ERROR(drm, "can't find encoder to force %s on!\n",
443                          connector->name);
444                 connector->status = connector_status_disconnected;
445                 return;
446         }
447
448         nouveau_connector_set_encoder(connector, nv_encoder);
449 }
450
451 static int
452 nouveau_connector_set_property(struct drm_connector *connector,
453                                struct drm_property *property, uint64_t value)
454 {
455         struct nouveau_display *disp = nouveau_display(connector->dev);
456         struct nouveau_connector *nv_connector = nouveau_connector(connector);
457         struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
458         struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
459         struct drm_device *dev = connector->dev;
460         struct nouveau_crtc *nv_crtc;
461         int ret;
462
463         nv_crtc = NULL;
464         if (connector->encoder && connector->encoder->crtc)
465                 nv_crtc = nouveau_crtc(connector->encoder->crtc);
466
467         /* Scaling mode */
468         if (property == dev->mode_config.scaling_mode_property) {
469                 bool modeset = false;
470
471                 switch (value) {
472                 case DRM_MODE_SCALE_NONE:
473                         /* We allow 'None' for EDID modes, even on a fixed
474                          * panel (some exist with support for lower refresh
475                          * rates, which people might want to use for power
476                          * saving purposes).
477                          *
478                          * Non-EDID modes will force the use of GPU scaling
479                          * to the native mode regardless of this setting.
480                          */
481                         switch (nv_connector->type) {
482                         case DCB_CONNECTOR_LVDS:
483                         case DCB_CONNECTOR_LVDS_SPWG:
484                         case DCB_CONNECTOR_eDP:
485                                 /* ... except prior to G80, where the code
486                                  * doesn't support such things.
487                                  */
488                                 if (disp->disp.oclass < NV50_DISP)
489                                         return -EINVAL;
490                                 break;
491                         default:
492                                 break;
493                         }
494                         break;
495                 case DRM_MODE_SCALE_FULLSCREEN:
496                 case DRM_MODE_SCALE_CENTER:
497                 case DRM_MODE_SCALE_ASPECT:
498                         break;
499                 default:
500                         return -EINVAL;
501                 }
502
503                 /* Changing between GPU and panel scaling requires a full
504                  * modeset
505                  */
506                 if ((nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) ||
507                     (value == DRM_MODE_SCALE_NONE))
508                         modeset = true;
509                 nv_connector->scaling_mode = value;
510
511                 if (!nv_crtc)
512                         return 0;
513
514                 if (modeset || !nv_crtc->set_scale) {
515                         ret = drm_crtc_helper_set_mode(&nv_crtc->base,
516                                                         &nv_crtc->base.mode,
517                                                         nv_crtc->base.x,
518                                                         nv_crtc->base.y, NULL);
519                         if (!ret)
520                                 return -EINVAL;
521                 } else {
522                         ret = nv_crtc->set_scale(nv_crtc, true);
523                         if (ret)
524                                 return ret;
525                 }
526
527                 return 0;
528         }
529
530         /* Underscan */
531         if (property == disp->underscan_property) {
532                 if (nv_connector->underscan != value) {
533                         nv_connector->underscan = value;
534                         if (!nv_crtc || !nv_crtc->set_scale)
535                                 return 0;
536
537                         return nv_crtc->set_scale(nv_crtc, true);
538                 }
539
540                 return 0;
541         }
542
543         if (property == disp->underscan_hborder_property) {
544                 if (nv_connector->underscan_hborder != value) {
545                         nv_connector->underscan_hborder = value;
546                         if (!nv_crtc || !nv_crtc->set_scale)
547                                 return 0;
548
549                         return nv_crtc->set_scale(nv_crtc, true);
550                 }
551
552                 return 0;
553         }
554
555         if (property == disp->underscan_vborder_property) {
556                 if (nv_connector->underscan_vborder != value) {
557                         nv_connector->underscan_vborder = value;
558                         if (!nv_crtc || !nv_crtc->set_scale)
559                                 return 0;
560
561                         return nv_crtc->set_scale(nv_crtc, true);
562                 }
563
564                 return 0;
565         }
566
567         /* Dithering */
568         if (property == disp->dithering_mode) {
569                 nv_connector->dithering_mode = value;
570                 if (!nv_crtc || !nv_crtc->set_dither)
571                         return 0;
572
573                 return nv_crtc->set_dither(nv_crtc, true);
574         }
575
576         if (property == disp->dithering_depth) {
577                 nv_connector->dithering_depth = value;
578                 if (!nv_crtc || !nv_crtc->set_dither)
579                         return 0;
580
581                 return nv_crtc->set_dither(nv_crtc, true);
582         }
583
584         if (nv_crtc && nv_crtc->set_color_vibrance) {
585                 /* Hue */
586                 if (property == disp->vibrant_hue_property) {
587                         nv_crtc->vibrant_hue = value - 90;
588                         return nv_crtc->set_color_vibrance(nv_crtc, true);
589                 }
590                 /* Saturation */
591                 if (property == disp->color_vibrance_property) {
592                         nv_crtc->color_vibrance = value - 100;
593                         return nv_crtc->set_color_vibrance(nv_crtc, true);
594                 }
595         }
596
597         if (nv_encoder && nv_encoder->dcb->type == DCB_OUTPUT_TV)
598                 return get_slave_funcs(encoder)->set_property(
599                         encoder, connector, property, value);
600
601         return -EINVAL;
602 }
603
604 static struct drm_display_mode *
605 nouveau_connector_native_mode(struct drm_connector *connector)
606 {
607         const struct drm_connector_helper_funcs *helper = connector->helper_private;
608         struct nouveau_drm *drm = nouveau_drm(connector->dev);
609         struct nouveau_connector *nv_connector = nouveau_connector(connector);
610         struct drm_device *dev = connector->dev;
611         struct drm_display_mode *mode, *largest = NULL;
612         int high_w = 0, high_h = 0, high_v = 0;
613
614         list_for_each_entry(mode, &nv_connector->base.probed_modes, head) {
615                 mode->vrefresh = drm_mode_vrefresh(mode);
616                 if (helper->mode_valid(connector, mode) != MODE_OK ||
617                     (mode->flags & DRM_MODE_FLAG_INTERLACE))
618                         continue;
619
620                 /* Use preferred mode if there is one.. */
621                 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
622                         NV_DEBUG(drm, "native mode from preferred\n");
623                         return drm_mode_duplicate(dev, mode);
624                 }
625
626                 /* Otherwise, take the resolution with the largest width, then
627                  * height, then vertical refresh
628                  */
629                 if (mode->hdisplay < high_w)
630                         continue;
631
632                 if (mode->hdisplay == high_w && mode->vdisplay < high_h)
633                         continue;
634
635                 if (mode->hdisplay == high_w && mode->vdisplay == high_h &&
636                     mode->vrefresh < high_v)
637                         continue;
638
639                 high_w = mode->hdisplay;
640                 high_h = mode->vdisplay;
641                 high_v = mode->vrefresh;
642                 largest = mode;
643         }
644
645         NV_DEBUG(drm, "native mode from largest: %dx%d@%d\n",
646                       high_w, high_h, high_v);
647         return largest ? drm_mode_duplicate(dev, largest) : NULL;
648 }
649
650 struct moderec {
651         int hdisplay;
652         int vdisplay;
653 };
654
655 static struct moderec scaler_modes[] = {
656         { 1920, 1200 },
657         { 1920, 1080 },
658         { 1680, 1050 },
659         { 1600, 1200 },
660         { 1400, 1050 },
661         { 1280, 1024 },
662         { 1280, 960 },
663         { 1152, 864 },
664         { 1024, 768 },
665         { 800, 600 },
666         { 720, 400 },
667         { 640, 480 },
668         { 640, 400 },
669         { 640, 350 },
670         {}
671 };
672
673 static int
674 nouveau_connector_scaler_modes_add(struct drm_connector *connector)
675 {
676         struct nouveau_connector *nv_connector = nouveau_connector(connector);
677         struct drm_display_mode *native = nv_connector->native_mode, *m;
678         struct drm_device *dev = connector->dev;
679         struct moderec *mode = &scaler_modes[0];
680         int modes = 0;
681
682         if (!native)
683                 return 0;
684
685         while (mode->hdisplay) {
686                 if (mode->hdisplay <= native->hdisplay &&
687                     mode->vdisplay <= native->vdisplay &&
688                     (mode->hdisplay != native->hdisplay ||
689                      mode->vdisplay != native->vdisplay)) {
690                         m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay,
691                                          drm_mode_vrefresh(native), false,
692                                          false, false);
693                         if (!m)
694                                 continue;
695
696                         drm_mode_probed_add(connector, m);
697                         modes++;
698                 }
699
700                 mode++;
701         }
702
703         return modes;
704 }
705
706 static void
707 nouveau_connector_detect_depth(struct drm_connector *connector)
708 {
709         struct nouveau_drm *drm = nouveau_drm(connector->dev);
710         struct nouveau_connector *nv_connector = nouveau_connector(connector);
711         struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
712         struct nvbios *bios = &drm->vbios;
713         struct drm_display_mode *mode = nv_connector->native_mode;
714         bool duallink;
715
716         /* if the edid is feeling nice enough to provide this info, use it */
717         if (nv_connector->edid && connector->display_info.bpc)
718                 return;
719
720         /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
721         if (nv_connector->type == DCB_CONNECTOR_eDP) {
722                 connector->display_info.bpc = 6;
723                 return;
724         }
725
726         /* we're out of options unless we're LVDS, default to 8bpc */
727         if (nv_encoder->dcb->type != DCB_OUTPUT_LVDS) {
728                 connector->display_info.bpc = 8;
729                 return;
730         }
731
732         connector->display_info.bpc = 6;
733
734         /* LVDS: panel straps */
735         if (bios->fp_no_ddc) {
736                 if (bios->fp.if_is_24bit)
737                         connector->display_info.bpc = 8;
738                 return;
739         }
740
741         /* LVDS: DDC panel, need to first determine the number of links to
742          * know which if_is_24bit flag to check...
743          */
744         if (nv_connector->edid &&
745             nv_connector->type == DCB_CONNECTOR_LVDS_SPWG)
746                 duallink = ((u8 *)nv_connector->edid)[121] == 2;
747         else
748                 duallink = mode->clock >= bios->fp.duallink_transition_clk;
749
750         if ((!duallink && (bios->fp.strapless_is_24bit & 1)) ||
751             ( duallink && (bios->fp.strapless_is_24bit & 2)))
752                 connector->display_info.bpc = 8;
753 }
754
755 static int
756 nouveau_connector_get_modes(struct drm_connector *connector)
757 {
758         struct drm_device *dev = connector->dev;
759         struct nouveau_drm *drm = nouveau_drm(dev);
760         struct nouveau_connector *nv_connector = nouveau_connector(connector);
761         struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
762         struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
763         int ret = 0;
764
765         /* destroy the native mode, the attached monitor could have changed.
766          */
767         if (nv_connector->native_mode) {
768                 drm_mode_destroy(dev, nv_connector->native_mode);
769                 nv_connector->native_mode = NULL;
770         }
771
772         if (nv_connector->edid)
773                 ret = drm_add_edid_modes(connector, nv_connector->edid);
774         else
775         if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS &&
776             (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
777              drm->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) {
778                 struct drm_display_mode mode;
779
780                 nouveau_bios_fp_mode(dev, &mode);
781                 nv_connector->native_mode = drm_mode_duplicate(dev, &mode);
782         }
783
784         /* Determine display colour depth for everything except LVDS now,
785          * DP requires this before mode_valid() is called.
786          */
787         if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS)
788                 nouveau_connector_detect_depth(connector);
789
790         /* Find the native mode if this is a digital panel, if we didn't
791          * find any modes through DDC previously add the native mode to
792          * the list of modes.
793          */
794         if (!nv_connector->native_mode)
795                 nv_connector->native_mode =
796                         nouveau_connector_native_mode(connector);
797         if (ret == 0 && nv_connector->native_mode) {
798                 struct drm_display_mode *mode;
799
800                 mode = drm_mode_duplicate(dev, nv_connector->native_mode);
801                 drm_mode_probed_add(connector, mode);
802                 ret = 1;
803         }
804
805         /* Determine LVDS colour depth, must happen after determining
806          * "native" mode as some VBIOS tables require us to use the
807          * pixel clock as part of the lookup...
808          */
809         if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
810                 nouveau_connector_detect_depth(connector);
811
812         if (nv_encoder->dcb->type == DCB_OUTPUT_TV)
813                 ret = get_slave_funcs(encoder)->get_modes(encoder, connector);
814
815         if (nv_connector->type == DCB_CONNECTOR_LVDS ||
816             nv_connector->type == DCB_CONNECTOR_LVDS_SPWG ||
817             nv_connector->type == DCB_CONNECTOR_eDP)
818                 ret += nouveau_connector_scaler_modes_add(connector);
819
820         return ret;
821 }
822
823 static unsigned
824 get_tmds_link_bandwidth(struct drm_connector *connector)
825 {
826         struct nouveau_connector *nv_connector = nouveau_connector(connector);
827         struct nouveau_drm *drm = nouveau_drm(connector->dev);
828         struct dcb_output *dcb = nv_connector->detected_encoder->dcb;
829
830         if (dcb->location != DCB_LOC_ON_CHIP ||
831             drm->device.info.chipset >= 0x46)
832                 return 165000;
833         else if (drm->device.info.chipset >= 0x40)
834                 return 155000;
835         else if (drm->device.info.chipset >= 0x18)
836                 return 135000;
837         else
838                 return 112000;
839 }
840
841 static int
842 nouveau_connector_mode_valid(struct drm_connector *connector,
843                              struct drm_display_mode *mode)
844 {
845         struct nouveau_connector *nv_connector = nouveau_connector(connector);
846         struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
847         struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
848         unsigned min_clock = 25000, max_clock = min_clock;
849         unsigned clock = mode->clock;
850
851         switch (nv_encoder->dcb->type) {
852         case DCB_OUTPUT_LVDS:
853                 if (nv_connector->native_mode &&
854                     (mode->hdisplay > nv_connector->native_mode->hdisplay ||
855                      mode->vdisplay > nv_connector->native_mode->vdisplay))
856                         return MODE_PANEL;
857
858                 min_clock = 0;
859                 max_clock = 400000;
860                 break;
861         case DCB_OUTPUT_TMDS:
862                 max_clock = get_tmds_link_bandwidth(connector);
863                 if (nouveau_duallink && nv_encoder->dcb->duallink_possible)
864                         max_clock *= 2;
865                 break;
866         case DCB_OUTPUT_ANALOG:
867                 max_clock = nv_encoder->dcb->crtconf.maxfreq;
868                 if (!max_clock)
869                         max_clock = 350000;
870                 break;
871         case DCB_OUTPUT_TV:
872                 return get_slave_funcs(encoder)->mode_valid(encoder, mode);
873         case DCB_OUTPUT_DP:
874                 max_clock  = nv_encoder->dp.link_nr;
875                 max_clock *= nv_encoder->dp.link_bw;
876                 clock = clock * (connector->display_info.bpc * 3) / 10;
877                 break;
878         default:
879                 BUG_ON(1);
880                 return MODE_BAD;
881         }
882
883         if (clock < min_clock)
884                 return MODE_CLOCK_LOW;
885
886         if (clock > max_clock)
887                 return MODE_CLOCK_HIGH;
888
889         return MODE_OK;
890 }
891
892 static struct drm_encoder *
893 nouveau_connector_best_encoder(struct drm_connector *connector)
894 {
895         struct nouveau_connector *nv_connector = nouveau_connector(connector);
896
897         if (nv_connector->detected_encoder)
898                 return to_drm_encoder(nv_connector->detected_encoder);
899
900         return NULL;
901 }
902
903 static const struct drm_connector_helper_funcs
904 nouveau_connector_helper_funcs = {
905         .get_modes = nouveau_connector_get_modes,
906         .mode_valid = nouveau_connector_mode_valid,
907         .best_encoder = nouveau_connector_best_encoder,
908 };
909
910 static const struct drm_connector_funcs
911 nouveau_connector_funcs = {
912         .dpms = drm_helper_connector_dpms,
913         .save = NULL,
914         .restore = NULL,
915         .detect = nouveau_connector_detect,
916         .destroy = nouveau_connector_destroy,
917         .fill_modes = drm_helper_probe_single_connector_modes,
918         .set_property = nouveau_connector_set_property,
919         .force = nouveau_connector_force
920 };
921
922 static const struct drm_connector_funcs
923 nouveau_connector_funcs_lvds = {
924         .dpms = drm_helper_connector_dpms,
925         .save = NULL,
926         .restore = NULL,
927         .detect = nouveau_connector_detect_lvds,
928         .destroy = nouveau_connector_destroy,
929         .fill_modes = drm_helper_probe_single_connector_modes,
930         .set_property = nouveau_connector_set_property,
931         .force = nouveau_connector_force
932 };
933
934 static int
935 nouveau_connector_dp_dpms(struct drm_connector *connector, int mode)
936 {
937         struct nouveau_encoder *nv_encoder = NULL;
938
939         if (connector->encoder)
940                 nv_encoder = nouveau_encoder(connector->encoder);
941         if (nv_encoder && nv_encoder->dcb &&
942             nv_encoder->dcb->type == DCB_OUTPUT_DP) {
943                 if (mode == DRM_MODE_DPMS_ON) {
944                         u8 data = DP_SET_POWER_D0;
945                         nvkm_wraux(nv_encoder->aux, DP_SET_POWER, &data, 1);
946                         usleep_range(1000, 2000);
947                 } else {
948                         u8 data = DP_SET_POWER_D3;
949                         nvkm_wraux(nv_encoder->aux, DP_SET_POWER, &data, 1);
950                 }
951         }
952
953         return drm_helper_connector_dpms(connector, mode);
954 }
955
956 static const struct drm_connector_funcs
957 nouveau_connector_funcs_dp = {
958         .dpms = nouveau_connector_dp_dpms,
959         .save = NULL,
960         .restore = NULL,
961         .detect = nouveau_connector_detect,
962         .destroy = nouveau_connector_destroy,
963         .fill_modes = drm_helper_probe_single_connector_modes,
964         .set_property = nouveau_connector_set_property,
965         .force = nouveau_connector_force
966 };
967
968 static int
969 nouveau_connector_hotplug(struct nvif_notify *notify)
970 {
971         struct nouveau_connector *nv_connector =
972                 container_of(notify, typeof(*nv_connector), hpd);
973         struct drm_connector *connector = &nv_connector->base;
974         struct nouveau_drm *drm = nouveau_drm(connector->dev);
975         const struct nvif_notify_conn_rep_v0 *rep = notify->data;
976         const char *name = connector->name;
977
978         if (rep->mask & NVIF_NOTIFY_CONN_V0_IRQ) {
979         } else {
980                 bool plugged = (rep->mask != NVIF_NOTIFY_CONN_V0_UNPLUG);
981
982                 NV_DEBUG(drm, "%splugged %s\n", plugged ? "" : "un", name);
983
984                 mutex_lock(&drm->dev->mode_config.mutex);
985                 if (plugged)
986                         drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
987                 else
988                         drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
989                 mutex_unlock(&drm->dev->mode_config.mutex);
990
991                 drm_helper_hpd_irq_event(connector->dev);
992         }
993
994         return NVIF_NOTIFY_KEEP;
995 }
996
997 static ssize_t
998 nouveau_connector_aux_xfer(struct drm_dp_aux *obj, struct drm_dp_aux_msg *msg)
999 {
1000         struct nouveau_connector *nv_connector =
1001                 container_of(obj, typeof(*nv_connector), aux);
1002         struct nouveau_encoder *nv_encoder;
1003         struct nvkm_i2c_aux *aux;
1004         int ret;
1005
1006         nv_encoder = find_encoder(&nv_connector->base, DCB_OUTPUT_DP);
1007         if (!nv_encoder || !(aux = nv_encoder->aux))
1008                 return -ENODEV;
1009         if (WARN_ON(msg->size > 16))
1010                 return -E2BIG;
1011         if (msg->size == 0)
1012                 return msg->size;
1013
1014         ret = nvkm_i2c_aux_acquire(aux);
1015         if (ret)
1016                 return ret;
1017
1018         ret = nvkm_i2c_aux_xfer(aux, false, msg->request, msg->address,
1019                                 msg->buffer, msg->size);
1020         nvkm_i2c_aux_release(aux);
1021         if (ret >= 0) {
1022                 msg->reply = ret;
1023                 return msg->size;
1024         }
1025
1026         return ret;
1027 }
1028
1029 static int
1030 drm_conntype_from_dcb(enum dcb_connector_type dcb)
1031 {
1032         switch (dcb) {
1033         case DCB_CONNECTOR_VGA      : return DRM_MODE_CONNECTOR_VGA;
1034         case DCB_CONNECTOR_TV_0     :
1035         case DCB_CONNECTOR_TV_1     :
1036         case DCB_CONNECTOR_TV_3     : return DRM_MODE_CONNECTOR_TV;
1037         case DCB_CONNECTOR_DMS59_0  :
1038         case DCB_CONNECTOR_DMS59_1  :
1039         case DCB_CONNECTOR_DVI_I    : return DRM_MODE_CONNECTOR_DVII;
1040         case DCB_CONNECTOR_DVI_D    : return DRM_MODE_CONNECTOR_DVID;
1041         case DCB_CONNECTOR_LVDS     :
1042         case DCB_CONNECTOR_LVDS_SPWG: return DRM_MODE_CONNECTOR_LVDS;
1043         case DCB_CONNECTOR_DMS59_DP0:
1044         case DCB_CONNECTOR_DMS59_DP1:
1045         case DCB_CONNECTOR_DP       : return DRM_MODE_CONNECTOR_DisplayPort;
1046         case DCB_CONNECTOR_eDP      : return DRM_MODE_CONNECTOR_eDP;
1047         case DCB_CONNECTOR_HDMI_0   :
1048         case DCB_CONNECTOR_HDMI_1   :
1049         case DCB_CONNECTOR_HDMI_C   : return DRM_MODE_CONNECTOR_HDMIA;
1050         default:
1051                 break;
1052         }
1053
1054         return DRM_MODE_CONNECTOR_Unknown;
1055 }
1056
1057 struct drm_connector *
1058 nouveau_connector_create(struct drm_device *dev, int index)
1059 {
1060         const struct drm_connector_funcs *funcs = &nouveau_connector_funcs;
1061         struct nouveau_drm *drm = nouveau_drm(dev);
1062         struct nouveau_display *disp = nouveau_display(dev);
1063         struct nouveau_connector *nv_connector = NULL;
1064         struct drm_connector *connector;
1065         int type, ret = 0;
1066         bool dummy;
1067
1068         list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1069                 nv_connector = nouveau_connector(connector);
1070                 if (nv_connector->index == index)
1071                         return connector;
1072         }
1073
1074         nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL);
1075         if (!nv_connector)
1076                 return ERR_PTR(-ENOMEM);
1077
1078         connector = &nv_connector->base;
1079         nv_connector->index = index;
1080
1081         /* attempt to parse vbios connector type and hotplug gpio */
1082         nv_connector->dcb = olddcb_conn(dev, index);
1083         if (nv_connector->dcb) {
1084                 u32 entry = ROM16(nv_connector->dcb[0]);
1085                 if (olddcb_conntab(dev)[3] >= 4)
1086                         entry |= (u32)ROM16(nv_connector->dcb[2]) << 16;
1087
1088                 nv_connector->type = nv_connector->dcb[0];
1089                 if (drm_conntype_from_dcb(nv_connector->type) ==
1090                                           DRM_MODE_CONNECTOR_Unknown) {
1091                         NV_WARN(drm, "unknown connector type %02x\n",
1092                                 nv_connector->type);
1093                         nv_connector->type = DCB_CONNECTOR_NONE;
1094                 }
1095
1096                 /* Gigabyte NX85T */
1097                 if (nv_match_device(dev, 0x0421, 0x1458, 0x344c)) {
1098                         if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
1099                                 nv_connector->type = DCB_CONNECTOR_DVI_I;
1100                 }
1101
1102                 /* Gigabyte GV-NX86T512H */
1103                 if (nv_match_device(dev, 0x0402, 0x1458, 0x3455)) {
1104                         if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
1105                                 nv_connector->type = DCB_CONNECTOR_DVI_I;
1106                 }
1107         } else {
1108                 nv_connector->type = DCB_CONNECTOR_NONE;
1109         }
1110
1111         /* no vbios data, or an unknown dcb connector type - attempt to
1112          * figure out something suitable ourselves
1113          */
1114         if (nv_connector->type == DCB_CONNECTOR_NONE) {
1115                 struct nouveau_drm *drm = nouveau_drm(dev);
1116                 struct dcb_table *dcbt = &drm->vbios.dcb;
1117                 u32 encoders = 0;
1118                 int i;
1119
1120                 for (i = 0; i < dcbt->entries; i++) {
1121                         if (dcbt->entry[i].connector == nv_connector->index)
1122                                 encoders |= (1 << dcbt->entry[i].type);
1123                 }
1124
1125                 if (encoders & (1 << DCB_OUTPUT_DP)) {
1126                         if (encoders & (1 << DCB_OUTPUT_TMDS))
1127                                 nv_connector->type = DCB_CONNECTOR_DP;
1128                         else
1129                                 nv_connector->type = DCB_CONNECTOR_eDP;
1130                 } else
1131                 if (encoders & (1 << DCB_OUTPUT_TMDS)) {
1132                         if (encoders & (1 << DCB_OUTPUT_ANALOG))
1133                                 nv_connector->type = DCB_CONNECTOR_DVI_I;
1134                         else
1135                                 nv_connector->type = DCB_CONNECTOR_DVI_D;
1136                 } else
1137                 if (encoders & (1 << DCB_OUTPUT_ANALOG)) {
1138                         nv_connector->type = DCB_CONNECTOR_VGA;
1139                 } else
1140                 if (encoders & (1 << DCB_OUTPUT_LVDS)) {
1141                         nv_connector->type = DCB_CONNECTOR_LVDS;
1142                 } else
1143                 if (encoders & (1 << DCB_OUTPUT_TV)) {
1144                         nv_connector->type = DCB_CONNECTOR_TV_0;
1145                 }
1146         }
1147
1148         switch ((type = drm_conntype_from_dcb(nv_connector->type))) {
1149         case DRM_MODE_CONNECTOR_LVDS:
1150                 ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &dummy);
1151                 if (ret) {
1152                         NV_ERROR(drm, "Error parsing LVDS table, disabling\n");
1153                         kfree(nv_connector);
1154                         return ERR_PTR(ret);
1155                 }
1156
1157                 funcs = &nouveau_connector_funcs_lvds;
1158                 break;
1159         case DRM_MODE_CONNECTOR_DisplayPort:
1160         case DRM_MODE_CONNECTOR_eDP:
1161                 nv_connector->aux.dev = dev->dev;
1162                 nv_connector->aux.transfer = nouveau_connector_aux_xfer;
1163                 ret = drm_dp_aux_register(&nv_connector->aux);
1164                 if (ret) {
1165                         NV_ERROR(drm, "failed to register aux channel\n");
1166                         kfree(nv_connector);
1167                         return ERR_PTR(ret);
1168                 }
1169
1170                 funcs = &nouveau_connector_funcs_dp;
1171                 break;
1172         default:
1173                 funcs = &nouveau_connector_funcs;
1174                 break;
1175         }
1176
1177         /* defaults, will get overridden in detect() */
1178         connector->interlace_allowed = false;
1179         connector->doublescan_allowed = false;
1180
1181         drm_connector_init(dev, connector, funcs, type);
1182         drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
1183
1184         /* Init DVI-I specific properties */
1185         if (nv_connector->type == DCB_CONNECTOR_DVI_I)
1186                 drm_object_attach_property(&connector->base, dev->mode_config.dvi_i_subconnector_property, 0);
1187
1188         /* Add overscan compensation options to digital outputs */
1189         if (disp->underscan_property &&
1190             (type == DRM_MODE_CONNECTOR_DVID ||
1191              type == DRM_MODE_CONNECTOR_DVII ||
1192              type == DRM_MODE_CONNECTOR_HDMIA ||
1193              type == DRM_MODE_CONNECTOR_DisplayPort)) {
1194                 drm_object_attach_property(&connector->base,
1195                                               disp->underscan_property,
1196                                               UNDERSCAN_OFF);
1197                 drm_object_attach_property(&connector->base,
1198                                               disp->underscan_hborder_property,
1199                                               0);
1200                 drm_object_attach_property(&connector->base,
1201                                               disp->underscan_vborder_property,
1202                                               0);
1203         }
1204
1205         /* Add hue and saturation options */
1206         if (disp->vibrant_hue_property)
1207                 drm_object_attach_property(&connector->base,
1208                                               disp->vibrant_hue_property,
1209                                               90);
1210         if (disp->color_vibrance_property)
1211                 drm_object_attach_property(&connector->base,
1212                                               disp->color_vibrance_property,
1213                                               150);
1214
1215         /* default scaling mode */
1216         switch (nv_connector->type) {
1217         case DCB_CONNECTOR_LVDS:
1218         case DCB_CONNECTOR_LVDS_SPWG:
1219         case DCB_CONNECTOR_eDP:
1220                 /* see note in nouveau_connector_set_property() */
1221                 if (disp->disp.oclass < NV50_DISP) {
1222                         nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
1223                         break;
1224                 }
1225                 nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
1226                 break;
1227         default:
1228                 nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
1229                 break;
1230         }
1231
1232         /* scaling mode property */
1233         switch (nv_connector->type) {
1234         case DCB_CONNECTOR_TV_0:
1235         case DCB_CONNECTOR_TV_1:
1236         case DCB_CONNECTOR_TV_3:
1237                 break;
1238         case DCB_CONNECTOR_VGA:
1239                 if (disp->disp.oclass < NV50_DISP)
1240                         break; /* can only scale on DFPs */
1241                 /* fall-through */
1242         default:
1243                 drm_object_attach_property(&connector->base, dev->mode_config.
1244                                            scaling_mode_property,
1245                                            nv_connector->scaling_mode);
1246                 break;
1247         }
1248
1249         /* dithering properties */
1250         switch (nv_connector->type) {
1251         case DCB_CONNECTOR_TV_0:
1252         case DCB_CONNECTOR_TV_1:
1253         case DCB_CONNECTOR_TV_3:
1254         case DCB_CONNECTOR_VGA:
1255                 break;
1256         default:
1257                 if (disp->dithering_mode) {
1258                         drm_object_attach_property(&connector->base,
1259                                                    disp->dithering_mode,
1260                                                    nv_connector->
1261                                                    dithering_mode);
1262                         nv_connector->dithering_mode = DITHERING_MODE_AUTO;
1263                 }
1264                 if (disp->dithering_depth) {
1265                         drm_object_attach_property(&connector->base,
1266                                                    disp->dithering_depth,
1267                                                    nv_connector->
1268                                                    dithering_depth);
1269                         nv_connector->dithering_depth = DITHERING_DEPTH_AUTO;
1270                 }
1271                 break;
1272         }
1273
1274         ret = nvif_notify_init(&disp->disp, nouveau_connector_hotplug, true,
1275                                NV04_DISP_NTFY_CONN,
1276                                &(struct nvif_notify_conn_req_v0) {
1277                                 .mask = NVIF_NOTIFY_CONN_V0_ANY,
1278                                 .conn = index,
1279                                },
1280                                sizeof(struct nvif_notify_conn_req_v0),
1281                                sizeof(struct nvif_notify_conn_rep_v0),
1282                                &nv_connector->hpd);
1283         if (ret)
1284                 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1285         else
1286                 connector->polled = DRM_CONNECTOR_POLL_HPD;
1287
1288         drm_connector_register(connector);
1289         return connector;
1290 }