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