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