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