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