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