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