2 * Copyright (C) 2008 Maarten Maathuis.
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:
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.
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.
27 #include <acpi/button.h>
29 #include <linux/pm_runtime.h>
30 #include <linux/vga_switcheroo.h>
33 #include <drm/drm_atomic_helper.h>
34 #include <drm/drm_edid.h>
35 #include <drm/drm_crtc_helper.h>
36 #include <drm/drm_probe_helper.h>
37 #include <drm/drm_atomic.h>
39 #include "nouveau_reg.h"
40 #include "nouveau_drv.h"
41 #include "dispnv04/hw.h"
42 #include "nouveau_acpi.h"
44 #include "nouveau_display.h"
45 #include "nouveau_connector.h"
46 #include "nouveau_encoder.h"
47 #include "nouveau_crtc.h"
49 #include <nvif/class.h>
50 #include <nvif/cl0046.h>
51 #include <nvif/event.h>
53 struct drm_display_mode
*
54 nouveau_conn_native_mode(struct drm_connector
*connector
)
56 const struct drm_connector_helper_funcs
*helper
= connector
->helper_private
;
57 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
58 struct drm_device
*dev
= connector
->dev
;
59 struct drm_display_mode
*mode
, *largest
= NULL
;
60 int high_w
= 0, high_h
= 0, high_v
= 0;
62 list_for_each_entry(mode
, &connector
->probed_modes
, head
) {
63 mode
->vrefresh
= drm_mode_vrefresh(mode
);
64 if (helper
->mode_valid(connector
, mode
) != MODE_OK
||
65 (mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
68 /* Use preferred mode if there is one.. */
69 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
) {
70 NV_DEBUG(drm
, "native mode from preferred\n");
71 return drm_mode_duplicate(dev
, mode
);
74 /* Otherwise, take the resolution with the largest width, then
75 * height, then vertical refresh
77 if (mode
->hdisplay
< high_w
)
80 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
< high_h
)
83 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
== high_h
&&
84 mode
->vrefresh
< high_v
)
87 high_w
= mode
->hdisplay
;
88 high_h
= mode
->vdisplay
;
89 high_v
= mode
->vrefresh
;
93 NV_DEBUG(drm
, "native mode from largest: %dx%d@%d\n",
94 high_w
, high_h
, high_v
);
95 return largest
? drm_mode_duplicate(dev
, largest
) : NULL
;
99 nouveau_conn_atomic_get_property(struct drm_connector
*connector
,
100 const struct drm_connector_state
*state
,
101 struct drm_property
*property
, u64
*val
)
103 struct nouveau_conn_atom
*asyc
= nouveau_conn_atom(state
);
104 struct nouveau_display
*disp
= nouveau_display(connector
->dev
);
105 struct drm_device
*dev
= connector
->dev
;
107 if (property
== dev
->mode_config
.scaling_mode_property
)
108 *val
= asyc
->scaler
.mode
;
109 else if (property
== disp
->underscan_property
)
110 *val
= asyc
->scaler
.underscan
.mode
;
111 else if (property
== disp
->underscan_hborder_property
)
112 *val
= asyc
->scaler
.underscan
.hborder
;
113 else if (property
== disp
->underscan_vborder_property
)
114 *val
= asyc
->scaler
.underscan
.vborder
;
115 else if (property
== disp
->dithering_mode
)
116 *val
= asyc
->dither
.mode
;
117 else if (property
== disp
->dithering_depth
)
118 *val
= asyc
->dither
.depth
;
119 else if (property
== disp
->vibrant_hue_property
)
120 *val
= asyc
->procamp
.vibrant_hue
;
121 else if (property
== disp
->color_vibrance_property
)
122 *val
= asyc
->procamp
.color_vibrance
;
130 nouveau_conn_atomic_set_property(struct drm_connector
*connector
,
131 struct drm_connector_state
*state
,
132 struct drm_property
*property
, u64 val
)
134 struct drm_device
*dev
= connector
->dev
;
135 struct nouveau_conn_atom
*asyc
= nouveau_conn_atom(state
);
136 struct nouveau_display
*disp
= nouveau_display(dev
);
138 if (property
== dev
->mode_config
.scaling_mode_property
) {
140 case DRM_MODE_SCALE_NONE
:
141 /* We allow 'None' for EDID modes, even on a fixed
142 * panel (some exist with support for lower refresh
143 * rates, which people might want to use for power-
146 * Non-EDID modes will force the use of GPU scaling
147 * to the native mode regardless of this setting.
149 switch (connector
->connector_type
) {
150 case DRM_MODE_CONNECTOR_LVDS
:
151 case DRM_MODE_CONNECTOR_eDP
:
152 /* ... except prior to G80, where the code
153 * doesn't support such things.
155 if (disp
->disp
.object
.oclass
< NV50_DISP
)
161 case DRM_MODE_SCALE_FULLSCREEN
:
162 case DRM_MODE_SCALE_CENTER
:
163 case DRM_MODE_SCALE_ASPECT
:
169 if (asyc
->scaler
.mode
!= val
) {
170 asyc
->scaler
.mode
= val
;
171 asyc
->set
.scaler
= true;
174 if (property
== disp
->underscan_property
) {
175 if (asyc
->scaler
.underscan
.mode
!= val
) {
176 asyc
->scaler
.underscan
.mode
= val
;
177 asyc
->set
.scaler
= true;
180 if (property
== disp
->underscan_hborder_property
) {
181 if (asyc
->scaler
.underscan
.hborder
!= val
) {
182 asyc
->scaler
.underscan
.hborder
= val
;
183 asyc
->set
.scaler
= true;
186 if (property
== disp
->underscan_vborder_property
) {
187 if (asyc
->scaler
.underscan
.vborder
!= val
) {
188 asyc
->scaler
.underscan
.vborder
= val
;
189 asyc
->set
.scaler
= true;
192 if (property
== disp
->dithering_mode
) {
193 if (asyc
->dither
.mode
!= val
) {
194 asyc
->dither
.mode
= val
;
195 asyc
->set
.dither
= true;
198 if (property
== disp
->dithering_depth
) {
199 if (asyc
->dither
.mode
!= val
) {
200 asyc
->dither
.depth
= val
;
201 asyc
->set
.dither
= true;
204 if (property
== disp
->vibrant_hue_property
) {
205 if (asyc
->procamp
.vibrant_hue
!= val
) {
206 asyc
->procamp
.vibrant_hue
= val
;
207 asyc
->set
.procamp
= true;
210 if (property
== disp
->color_vibrance_property
) {
211 if (asyc
->procamp
.color_vibrance
!= val
) {
212 asyc
->procamp
.color_vibrance
= val
;
213 asyc
->set
.procamp
= true;
223 nouveau_conn_atomic_destroy_state(struct drm_connector
*connector
,
224 struct drm_connector_state
*state
)
226 struct nouveau_conn_atom
*asyc
= nouveau_conn_atom(state
);
227 __drm_atomic_helper_connector_destroy_state(&asyc
->state
);
231 struct drm_connector_state
*
232 nouveau_conn_atomic_duplicate_state(struct drm_connector
*connector
)
234 struct nouveau_conn_atom
*armc
= nouveau_conn_atom(connector
->state
);
235 struct nouveau_conn_atom
*asyc
;
236 if (!(asyc
= kmalloc(sizeof(*asyc
), GFP_KERNEL
)))
238 __drm_atomic_helper_connector_duplicate_state(connector
, &asyc
->state
);
239 asyc
->dither
= armc
->dither
;
240 asyc
->scaler
= armc
->scaler
;
241 asyc
->procamp
= armc
->procamp
;
247 nouveau_conn_reset(struct drm_connector
*connector
)
249 struct nouveau_conn_atom
*asyc
;
251 if (WARN_ON(!(asyc
= kzalloc(sizeof(*asyc
), GFP_KERNEL
))))
254 if (connector
->state
)
255 __drm_atomic_helper_connector_destroy_state(connector
->state
);
256 __drm_atomic_helper_connector_reset(connector
, &asyc
->state
);
257 asyc
->dither
.mode
= DITHERING_MODE_AUTO
;
258 asyc
->dither
.depth
= DITHERING_DEPTH_AUTO
;
259 asyc
->scaler
.mode
= DRM_MODE_SCALE_NONE
;
260 asyc
->scaler
.underscan
.mode
= UNDERSCAN_OFF
;
261 asyc
->procamp
.color_vibrance
= 150;
262 asyc
->procamp
.vibrant_hue
= 90;
264 if (nouveau_display(connector
->dev
)->disp
.object
.oclass
< NV50_DISP
) {
265 switch (connector
->connector_type
) {
266 case DRM_MODE_CONNECTOR_LVDS
:
267 /* See note in nouveau_conn_atomic_set_property(). */
268 asyc
->scaler
.mode
= DRM_MODE_SCALE_FULLSCREEN
;
277 nouveau_conn_attach_properties(struct drm_connector
*connector
)
279 struct drm_device
*dev
= connector
->dev
;
280 struct nouveau_conn_atom
*armc
= nouveau_conn_atom(connector
->state
);
281 struct nouveau_display
*disp
= nouveau_display(dev
);
283 /* Init DVI-I specific properties. */
284 if (connector
->connector_type
== DRM_MODE_CONNECTOR_DVII
)
285 drm_object_attach_property(&connector
->base
, dev
->mode_config
.
286 dvi_i_subconnector_property
, 0);
288 /* Add overscan compensation options to digital outputs. */
289 if (disp
->underscan_property
&&
290 (connector
->connector_type
== DRM_MODE_CONNECTOR_DVID
||
291 connector
->connector_type
== DRM_MODE_CONNECTOR_DVII
||
292 connector
->connector_type
== DRM_MODE_CONNECTOR_HDMIA
||
293 connector
->connector_type
== DRM_MODE_CONNECTOR_DisplayPort
)) {
294 drm_object_attach_property(&connector
->base
,
295 disp
->underscan_property
,
297 drm_object_attach_property(&connector
->base
,
298 disp
->underscan_hborder_property
, 0);
299 drm_object_attach_property(&connector
->base
,
300 disp
->underscan_vborder_property
, 0);
303 /* Add hue and saturation options. */
304 if (disp
->vibrant_hue_property
)
305 drm_object_attach_property(&connector
->base
,
306 disp
->vibrant_hue_property
,
307 armc
->procamp
.vibrant_hue
);
308 if (disp
->color_vibrance_property
)
309 drm_object_attach_property(&connector
->base
,
310 disp
->color_vibrance_property
,
311 armc
->procamp
.color_vibrance
);
313 /* Scaling mode property. */
314 switch (connector
->connector_type
) {
315 case DRM_MODE_CONNECTOR_TV
:
317 case DRM_MODE_CONNECTOR_VGA
:
318 if (disp
->disp
.object
.oclass
< NV50_DISP
)
319 break; /* Can only scale on DFPs. */
322 drm_object_attach_property(&connector
->base
, dev
->mode_config
.
323 scaling_mode_property
,
328 /* Dithering properties. */
329 switch (connector
->connector_type
) {
330 case DRM_MODE_CONNECTOR_TV
:
331 case DRM_MODE_CONNECTOR_VGA
:
334 if (disp
->dithering_mode
) {
335 drm_object_attach_property(&connector
->base
,
336 disp
->dithering_mode
,
339 if (disp
->dithering_depth
) {
340 drm_object_attach_property(&connector
->base
,
341 disp
->dithering_depth
,
348 MODULE_PARM_DESC(tv_disable
, "Disable TV-out detection");
349 int nouveau_tv_disable
= 0;
350 module_param_named(tv_disable
, nouveau_tv_disable
, int, 0400);
352 MODULE_PARM_DESC(ignorelid
, "Ignore ACPI lid status");
353 int nouveau_ignorelid
= 0;
354 module_param_named(ignorelid
, nouveau_ignorelid
, int, 0400);
356 MODULE_PARM_DESC(duallink
, "Allow dual-link TMDS (default: enabled)");
357 int nouveau_duallink
= 1;
358 module_param_named(duallink
, nouveau_duallink
, int, 0400);
360 MODULE_PARM_DESC(hdmimhz
, "Force a maximum HDMI pixel clock (in MHz)");
361 int nouveau_hdmimhz
= 0;
362 module_param_named(hdmimhz
, nouveau_hdmimhz
, int, 0400);
364 struct nouveau_encoder
*
365 find_encoder(struct drm_connector
*connector
, int type
)
367 struct nouveau_encoder
*nv_encoder
;
368 struct drm_encoder
*enc
;
371 drm_connector_for_each_possible_encoder(connector
, enc
, i
) {
372 nv_encoder
= nouveau_encoder(enc
);
374 if (type
== DCB_OUTPUT_ANY
||
375 (nv_encoder
->dcb
&& nv_encoder
->dcb
->type
== type
))
382 struct nouveau_connector
*
383 nouveau_encoder_connector_get(struct nouveau_encoder
*encoder
)
385 struct drm_device
*dev
= to_drm_encoder(encoder
)->dev
;
386 struct drm_connector
*drm_connector
;
388 list_for_each_entry(drm_connector
, &dev
->mode_config
.connector_list
, head
) {
389 if (drm_connector
->encoder
== to_drm_encoder(encoder
))
390 return nouveau_connector(drm_connector
);
397 nouveau_connector_destroy(struct drm_connector
*connector
)
399 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
400 nvif_notify_fini(&nv_connector
->hpd
);
401 kfree(nv_connector
->edid
);
402 drm_connector_unregister(connector
);
403 drm_connector_cleanup(connector
);
404 if (nv_connector
->aux
.transfer
) {
405 drm_dp_cec_unregister_connector(&nv_connector
->aux
);
406 drm_dp_aux_unregister(&nv_connector
->aux
);
407 kfree(nv_connector
->aux
.name
);
412 static struct nouveau_encoder
*
413 nouveau_connector_ddc_detect(struct drm_connector
*connector
)
415 struct drm_device
*dev
= connector
->dev
;
416 struct nouveau_encoder
*nv_encoder
= NULL
, *found
= NULL
;
417 struct drm_encoder
*encoder
;
419 bool switcheroo_ddc
= false;
421 drm_connector_for_each_possible_encoder(connector
, encoder
, i
) {
422 nv_encoder
= nouveau_encoder(encoder
);
424 switch (nv_encoder
->dcb
->type
) {
426 ret
= nouveau_dp_detect(nv_encoder
);
427 if (ret
== NOUVEAU_DP_MST
)
429 else if (ret
== NOUVEAU_DP_SST
)
433 case DCB_OUTPUT_LVDS
:
434 switcheroo_ddc
= !!(vga_switcheroo_handler_flags() &
435 VGA_SWITCHEROO_CAN_SWITCH_DDC
);
438 if (!nv_encoder
->i2c
)
442 vga_switcheroo_lock_ddc(dev
->pdev
);
443 if (nvkm_probe_i2c(nv_encoder
->i2c
, 0x50))
446 vga_switcheroo_unlock_ddc(dev
->pdev
);
457 static struct nouveau_encoder
*
458 nouveau_connector_of_detect(struct drm_connector
*connector
)
461 struct drm_device
*dev
= connector
->dev
;
462 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
463 struct nouveau_encoder
*nv_encoder
;
464 struct device_node
*cn
, *dn
= pci_device_to_OF_node(dev
->pdev
);
467 !((nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TMDS
)) ||
468 (nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
))))
471 for_each_child_of_node(dn
, cn
) {
472 const char *name
= of_get_property(cn
, "name", NULL
);
473 const void *edid
= of_get_property(cn
, "EDID", NULL
);
474 int idx
= name
? name
[strlen(name
) - 1] - 'A' : 0;
476 if (nv_encoder
->dcb
->i2c_index
== idx
&& edid
) {
478 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
488 nouveau_connector_set_encoder(struct drm_connector
*connector
,
489 struct nouveau_encoder
*nv_encoder
)
491 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
492 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
493 struct drm_device
*dev
= connector
->dev
;
495 if (nv_connector
->detected_encoder
== nv_encoder
)
497 nv_connector
->detected_encoder
= nv_encoder
;
499 if (drm
->client
.device
.info
.family
>= NV_DEVICE_INFO_V0_TESLA
) {
500 connector
->interlace_allowed
= true;
501 connector
->doublescan_allowed
= true;
503 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
||
504 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
) {
505 connector
->doublescan_allowed
= false;
506 connector
->interlace_allowed
= false;
508 connector
->doublescan_allowed
= true;
509 if (drm
->client
.device
.info
.family
== NV_DEVICE_INFO_V0_KELVIN
||
510 (drm
->client
.device
.info
.family
== NV_DEVICE_INFO_V0_CELSIUS
&&
511 (dev
->pdev
->device
& 0x0ff0) != 0x0100 &&
512 (dev
->pdev
->device
& 0x0ff0) != 0x0150))
514 connector
->interlace_allowed
= false;
516 connector
->interlace_allowed
= true;
519 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
520 drm_object_property_set_value(&connector
->base
,
521 dev
->mode_config
.dvi_i_subconnector_property
,
522 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
?
523 DRM_MODE_SUBCONNECTOR_DVID
:
524 DRM_MODE_SUBCONNECTOR_DVIA
);
528 static enum drm_connector_status
529 nouveau_connector_detect(struct drm_connector
*connector
, bool force
)
531 struct drm_device
*dev
= connector
->dev
;
532 struct nouveau_drm
*drm
= nouveau_drm(dev
);
533 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
534 struct nouveau_encoder
*nv_encoder
= NULL
;
535 struct nouveau_encoder
*nv_partner
;
536 struct i2c_adapter
*i2c
;
539 enum drm_connector_status conn_status
= connector_status_disconnected
;
541 /* Cleanup the previous EDID block. */
542 if (nv_connector
->edid
) {
543 drm_connector_update_edid_property(connector
, NULL
);
544 kfree(nv_connector
->edid
);
545 nv_connector
->edid
= NULL
;
548 /* Outputs are only polled while runtime active, so resuming the
549 * device here is unnecessary (and would deadlock upon runtime suspend
550 * because it waits for polling to finish). We do however, want to
551 * prevent the autosuspend timer from elapsing during this operation
554 if (drm_kms_helper_is_poll_worker()) {
555 pm_runtime_get_noresume(dev
->dev
);
557 ret
= pm_runtime_get_sync(dev
->dev
);
558 if (ret
< 0 && ret
!= -EACCES
)
562 nv_encoder
= nouveau_connector_ddc_detect(connector
);
563 if (nv_encoder
&& (i2c
= nv_encoder
->i2c
) != NULL
) {
564 if ((vga_switcheroo_handler_flags() &
565 VGA_SWITCHEROO_CAN_SWITCH_DDC
) &&
566 nv_connector
->type
== DCB_CONNECTOR_LVDS
)
567 nv_connector
->edid
= drm_get_edid_switcheroo(connector
,
570 nv_connector
->edid
= drm_get_edid(connector
, i2c
);
572 drm_connector_update_edid_property(connector
,
574 if (!nv_connector
->edid
) {
575 NV_ERROR(drm
, "DDC responded, but no EDID for %s\n",
580 /* Override encoder type for DVI-I based on whether EDID
581 * says the display is digital or analog, both use the
582 * same i2c channel so the value returned from ddc_detect
583 * isn't necessarily correct.
586 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
)
587 nv_partner
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
588 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
)
589 nv_partner
= find_encoder(connector
, DCB_OUTPUT_TMDS
);
591 if (nv_partner
&& ((nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
&&
592 nv_partner
->dcb
->type
== DCB_OUTPUT_TMDS
) ||
593 (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
&&
594 nv_partner
->dcb
->type
== DCB_OUTPUT_ANALOG
))) {
595 if (nv_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
)
596 type
= DCB_OUTPUT_TMDS
;
598 type
= DCB_OUTPUT_ANALOG
;
600 nv_encoder
= find_encoder(connector
, type
);
603 nouveau_connector_set_encoder(connector
, nv_encoder
);
604 conn_status
= connector_status_connected
;
605 drm_dp_cec_set_edid(&nv_connector
->aux
, nv_connector
->edid
);
609 nv_encoder
= nouveau_connector_of_detect(connector
);
611 nouveau_connector_set_encoder(connector
, nv_encoder
);
612 conn_status
= connector_status_connected
;
617 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
618 if (!nv_encoder
&& !nouveau_tv_disable
)
619 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TV
);
620 if (nv_encoder
&& force
) {
621 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
622 const struct drm_encoder_helper_funcs
*helper
=
623 encoder
->helper_private
;
625 if (helper
->detect(encoder
, connector
) ==
626 connector_status_connected
) {
627 nouveau_connector_set_encoder(connector
, nv_encoder
);
628 conn_status
= connector_status_connected
;
636 pm_runtime_mark_last_busy(dev
->dev
);
637 pm_runtime_put_autosuspend(dev
->dev
);
642 static enum drm_connector_status
643 nouveau_connector_detect_lvds(struct drm_connector
*connector
, bool force
)
645 struct drm_device
*dev
= connector
->dev
;
646 struct nouveau_drm
*drm
= nouveau_drm(dev
);
647 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
648 struct nouveau_encoder
*nv_encoder
= NULL
;
649 enum drm_connector_status status
= connector_status_disconnected
;
651 /* Cleanup the previous EDID block. */
652 if (nv_connector
->edid
) {
653 drm_connector_update_edid_property(connector
, NULL
);
654 kfree(nv_connector
->edid
);
655 nv_connector
->edid
= NULL
;
658 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_LVDS
);
660 return connector_status_disconnected
;
662 /* Try retrieving EDID via DDC */
663 if (!drm
->vbios
.fp_no_ddc
) {
664 status
= nouveau_connector_detect(connector
, force
);
665 if (status
== connector_status_connected
)
669 /* On some laptops (Sony, i'm looking at you) there appears to
670 * be no direct way of accessing the panel's EDID. The only
671 * option available to us appears to be to ask ACPI for help..
673 * It's important this check's before trying straps, one of the
674 * said manufacturer's laptops are configured in such a way
675 * the nouveau decides an entry in the VBIOS FP mode table is
676 * valid - it's not (rh#613284)
678 if (nv_encoder
->dcb
->lvdsconf
.use_acpi_for_edid
) {
679 if ((nv_connector
->edid
= nouveau_acpi_edid(dev
, connector
))) {
680 status
= connector_status_connected
;
685 /* If no EDID found above, and the VBIOS indicates a hardcoded
686 * modeline is avalilable for the panel, set it as the panel's
687 * native mode and exit.
689 if (nouveau_bios_fp_mode(dev
, NULL
) && (drm
->vbios
.fp_no_ddc
||
690 nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
)) {
691 status
= connector_status_connected
;
695 /* Still nothing, some VBIOS images have a hardcoded EDID block
696 * stored for the panel stored in them.
698 if (!drm
->vbios
.fp_no_ddc
) {
700 (struct edid
*)nouveau_bios_embedded_edid(dev
);
703 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
704 if (nv_connector
->edid
)
705 status
= connector_status_connected
;
710 #if defined(CONFIG_ACPI_BUTTON) || \
711 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
712 if (status
== connector_status_connected
&&
713 !nouveau_ignorelid
&& !acpi_lid_open())
714 status
= connector_status_unknown
;
717 drm_connector_update_edid_property(connector
, nv_connector
->edid
);
718 nouveau_connector_set_encoder(connector
, nv_encoder
);
723 nouveau_connector_force(struct drm_connector
*connector
)
725 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
726 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
727 struct nouveau_encoder
*nv_encoder
;
730 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
731 if (connector
->force
== DRM_FORCE_ON_DIGITAL
)
732 type
= DCB_OUTPUT_TMDS
;
734 type
= DCB_OUTPUT_ANALOG
;
736 type
= DCB_OUTPUT_ANY
;
738 nv_encoder
= find_encoder(connector
, type
);
740 NV_ERROR(drm
, "can't find encoder to force %s on!\n",
742 connector
->status
= connector_status_disconnected
;
746 nouveau_connector_set_encoder(connector
, nv_encoder
);
750 nouveau_connector_set_property(struct drm_connector
*connector
,
751 struct drm_property
*property
, uint64_t value
)
753 struct nouveau_conn_atom
*asyc
= nouveau_conn_atom(connector
->state
);
754 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
755 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
756 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
759 ret
= connector
->funcs
->atomic_set_property(&nv_connector
->base
,
763 if (nv_encoder
&& nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
764 return get_slave_funcs(encoder
)->set_property(
765 encoder
, connector
, property
, value
);
769 nv_connector
->scaling_mode
= asyc
->scaler
.mode
;
770 nv_connector
->dithering_mode
= asyc
->dither
.mode
;
772 if (connector
->encoder
&& connector
->encoder
->crtc
) {
773 ret
= drm_crtc_helper_set_mode(connector
->encoder
->crtc
,
774 &connector
->encoder
->crtc
->mode
,
775 connector
->encoder
->crtc
->x
,
776 connector
->encoder
->crtc
->y
,
790 static struct moderec scaler_modes
[] = {
809 nouveau_connector_scaler_modes_add(struct drm_connector
*connector
)
811 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
812 struct drm_display_mode
*native
= nv_connector
->native_mode
, *m
;
813 struct drm_device
*dev
= connector
->dev
;
814 struct moderec
*mode
= &scaler_modes
[0];
820 while (mode
->hdisplay
) {
821 if (mode
->hdisplay
<= native
->hdisplay
&&
822 mode
->vdisplay
<= native
->vdisplay
&&
823 (mode
->hdisplay
!= native
->hdisplay
||
824 mode
->vdisplay
!= native
->vdisplay
)) {
825 m
= drm_cvt_mode(dev
, mode
->hdisplay
, mode
->vdisplay
,
826 drm_mode_vrefresh(native
), false,
831 drm_mode_probed_add(connector
, m
);
842 nouveau_connector_detect_depth(struct drm_connector
*connector
)
844 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
845 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
846 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
847 struct nvbios
*bios
= &drm
->vbios
;
848 struct drm_display_mode
*mode
= nv_connector
->native_mode
;
851 /* if the edid is feeling nice enough to provide this info, use it */
852 if (nv_connector
->edid
&& connector
->display_info
.bpc
)
855 /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
856 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
857 connector
->display_info
.bpc
= 6;
861 /* we're out of options unless we're LVDS, default to 8bpc */
862 if (nv_encoder
->dcb
->type
!= DCB_OUTPUT_LVDS
) {
863 connector
->display_info
.bpc
= 8;
867 connector
->display_info
.bpc
= 6;
869 /* LVDS: panel straps */
870 if (bios
->fp_no_ddc
) {
871 if (bios
->fp
.if_is_24bit
)
872 connector
->display_info
.bpc
= 8;
876 /* LVDS: DDC panel, need to first determine the number of links to
877 * know which if_is_24bit flag to check...
879 if (nv_connector
->edid
&&
880 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
)
881 duallink
= ((u8
*)nv_connector
->edid
)[121] == 2;
883 duallink
= mode
->clock
>= bios
->fp
.duallink_transition_clk
;
885 if ((!duallink
&& (bios
->fp
.strapless_is_24bit
& 1)) ||
886 ( duallink
&& (bios
->fp
.strapless_is_24bit
& 2)))
887 connector
->display_info
.bpc
= 8;
891 nouveau_connector_late_register(struct drm_connector
*connector
)
895 ret
= nouveau_backlight_init(connector
);
901 nouveau_connector_early_unregister(struct drm_connector
*connector
)
903 nouveau_backlight_fini(connector
);
907 nouveau_connector_get_modes(struct drm_connector
*connector
)
909 struct drm_device
*dev
= connector
->dev
;
910 struct nouveau_drm
*drm
= nouveau_drm(dev
);
911 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
912 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
913 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
916 /* destroy the native mode, the attached monitor could have changed.
918 if (nv_connector
->native_mode
) {
919 drm_mode_destroy(dev
, nv_connector
->native_mode
);
920 nv_connector
->native_mode
= NULL
;
923 if (nv_connector
->edid
)
924 ret
= drm_add_edid_modes(connector
, nv_connector
->edid
);
926 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
&&
927 (nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
||
928 drm
->vbios
.fp_no_ddc
) && nouveau_bios_fp_mode(dev
, NULL
)) {
929 struct drm_display_mode mode
;
931 nouveau_bios_fp_mode(dev
, &mode
);
932 nv_connector
->native_mode
= drm_mode_duplicate(dev
, &mode
);
935 /* Determine display colour depth for everything except LVDS now,
936 * DP requires this before mode_valid() is called.
938 if (connector
->connector_type
!= DRM_MODE_CONNECTOR_LVDS
)
939 nouveau_connector_detect_depth(connector
);
941 /* Find the native mode if this is a digital panel, if we didn't
942 * find any modes through DDC previously add the native mode to
945 if (!nv_connector
->native_mode
)
946 nv_connector
->native_mode
= nouveau_conn_native_mode(connector
);
947 if (ret
== 0 && nv_connector
->native_mode
) {
948 struct drm_display_mode
*mode
;
950 mode
= drm_mode_duplicate(dev
, nv_connector
->native_mode
);
951 drm_mode_probed_add(connector
, mode
);
955 /* Determine LVDS colour depth, must happen after determining
956 * "native" mode as some VBIOS tables require us to use the
957 * pixel clock as part of the lookup...
959 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
)
960 nouveau_connector_detect_depth(connector
);
962 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
963 ret
= get_slave_funcs(encoder
)->get_modes(encoder
, connector
);
965 if (nv_connector
->type
== DCB_CONNECTOR_LVDS
||
966 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
||
967 nv_connector
->type
== DCB_CONNECTOR_eDP
)
968 ret
+= nouveau_connector_scaler_modes_add(connector
);
974 get_tmds_link_bandwidth(struct drm_connector
*connector
)
976 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
977 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
978 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
979 struct dcb_output
*dcb
= nv_connector
->detected_encoder
->dcb
;
980 struct drm_display_info
*info
= NULL
;
981 const unsigned duallink_scale
=
982 nouveau_duallink
&& nv_encoder
->dcb
->duallink_possible
? 2 : 1;
984 if (drm_detect_hdmi_monitor(nv_connector
->edid
))
985 info
= &nv_connector
->base
.display_info
;
988 if (nouveau_hdmimhz
> 0)
989 return nouveau_hdmimhz
* 1000;
990 /* Note: these limits are conservative, some Fermi's
991 * can do 297 MHz. Unclear how this can be determined.
993 if (drm
->client
.device
.info
.chipset
>= 0x120) {
994 const int max_tmds_clock
=
995 info
->hdmi
.scdc
.scrambling
.supported
?
997 return info
->max_tmds_clock
?
998 min(info
->max_tmds_clock
, max_tmds_clock
) :
1001 if (drm
->client
.device
.info
.family
>= NV_DEVICE_INFO_V0_KEPLER
)
1003 if (drm
->client
.device
.info
.family
>= NV_DEVICE_INFO_V0_FERMI
)
1006 if (dcb
->location
!= DCB_LOC_ON_CHIP
||
1007 drm
->client
.device
.info
.chipset
>= 0x46)
1008 return 165000 * duallink_scale
;
1009 else if (drm
->client
.device
.info
.chipset
>= 0x40)
1010 return 155000 * duallink_scale
;
1011 else if (drm
->client
.device
.info
.chipset
>= 0x18)
1012 return 135000 * duallink_scale
;
1014 return 112000 * duallink_scale
;
1017 static enum drm_mode_status
1018 nouveau_connector_mode_valid(struct drm_connector
*connector
,
1019 struct drm_display_mode
*mode
)
1021 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
1022 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
1023 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
1024 unsigned min_clock
= 25000, max_clock
= min_clock
;
1025 unsigned clock
= mode
->clock
;
1027 switch (nv_encoder
->dcb
->type
) {
1028 case DCB_OUTPUT_LVDS
:
1029 if (nv_connector
->native_mode
&&
1030 (mode
->hdisplay
> nv_connector
->native_mode
->hdisplay
||
1031 mode
->vdisplay
> nv_connector
->native_mode
->vdisplay
))
1037 case DCB_OUTPUT_TMDS
:
1038 max_clock
= get_tmds_link_bandwidth(connector
);
1040 case DCB_OUTPUT_ANALOG
:
1041 max_clock
= nv_encoder
->dcb
->crtconf
.maxfreq
;
1046 return get_slave_funcs(encoder
)->mode_valid(encoder
, mode
);
1048 max_clock
= nv_encoder
->dp
.link_nr
;
1049 max_clock
*= nv_encoder
->dp
.link_bw
;
1050 clock
= clock
* (connector
->display_info
.bpc
* 3) / 10;
1057 if ((mode
->flags
& DRM_MODE_FLAG_3D_MASK
) == DRM_MODE_FLAG_3D_FRAME_PACKING
)
1060 if (clock
< min_clock
)
1061 return MODE_CLOCK_LOW
;
1063 if (clock
> max_clock
)
1064 return MODE_CLOCK_HIGH
;
1069 static struct drm_encoder
*
1070 nouveau_connector_best_encoder(struct drm_connector
*connector
)
1072 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
1074 if (nv_connector
->detected_encoder
)
1075 return to_drm_encoder(nv_connector
->detected_encoder
);
1080 static const struct drm_connector_helper_funcs
1081 nouveau_connector_helper_funcs
= {
1082 .get_modes
= nouveau_connector_get_modes
,
1083 .mode_valid
= nouveau_connector_mode_valid
,
1084 .best_encoder
= nouveau_connector_best_encoder
,
1087 static const struct drm_connector_funcs
1088 nouveau_connector_funcs
= {
1089 .dpms
= drm_helper_connector_dpms
,
1090 .reset
= nouveau_conn_reset
,
1091 .detect
= nouveau_connector_detect
,
1092 .force
= nouveau_connector_force
,
1093 .fill_modes
= drm_helper_probe_single_connector_modes
,
1094 .set_property
= nouveau_connector_set_property
,
1095 .destroy
= nouveau_connector_destroy
,
1096 .atomic_duplicate_state
= nouveau_conn_atomic_duplicate_state
,
1097 .atomic_destroy_state
= nouveau_conn_atomic_destroy_state
,
1098 .atomic_set_property
= nouveau_conn_atomic_set_property
,
1099 .atomic_get_property
= nouveau_conn_atomic_get_property
,
1100 .late_register
= nouveau_connector_late_register
,
1101 .early_unregister
= nouveau_connector_early_unregister
,
1104 static const struct drm_connector_funcs
1105 nouveau_connector_funcs_lvds
= {
1106 .dpms
= drm_helper_connector_dpms
,
1107 .reset
= nouveau_conn_reset
,
1108 .detect
= nouveau_connector_detect_lvds
,
1109 .force
= nouveau_connector_force
,
1110 .fill_modes
= drm_helper_probe_single_connector_modes
,
1111 .set_property
= nouveau_connector_set_property
,
1112 .destroy
= nouveau_connector_destroy
,
1113 .atomic_duplicate_state
= nouveau_conn_atomic_duplicate_state
,
1114 .atomic_destroy_state
= nouveau_conn_atomic_destroy_state
,
1115 .atomic_set_property
= nouveau_conn_atomic_set_property
,
1116 .atomic_get_property
= nouveau_conn_atomic_get_property
,
1117 .late_register
= nouveau_connector_late_register
,
1118 .early_unregister
= nouveau_connector_early_unregister
,
1122 nouveau_connector_hotplug(struct nvif_notify
*notify
)
1124 struct nouveau_connector
*nv_connector
=
1125 container_of(notify
, typeof(*nv_connector
), hpd
);
1126 struct drm_connector
*connector
= &nv_connector
->base
;
1127 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
1128 const struct nvif_notify_conn_rep_v0
*rep
= notify
->data
;
1129 const char *name
= connector
->name
;
1130 struct nouveau_encoder
*nv_encoder
;
1133 ret
= pm_runtime_get(drm
->dev
->dev
);
1135 /* We can't block here if there's a pending PM request
1136 * running, as we'll deadlock nouveau_display_fini() when it
1137 * calls nvif_put() on our nvif_notify struct. So, simply
1138 * defer the hotplug event until the device finishes resuming
1140 NV_DEBUG(drm
, "Deferring HPD on %s until runtime resume\n",
1142 schedule_work(&drm
->hpd_work
);
1144 pm_runtime_put_noidle(drm
->dev
->dev
);
1145 return NVIF_NOTIFY_KEEP
;
1146 } else if (ret
!= 1 && ret
!= -EACCES
) {
1147 NV_WARN(drm
, "HPD on %s dropped due to RPM failure: %d\n",
1149 return NVIF_NOTIFY_DROP
;
1152 if (rep
->mask
& NVIF_NOTIFY_CONN_V0_IRQ
) {
1153 NV_DEBUG(drm
, "service %s\n", name
);
1154 drm_dp_cec_irq(&nv_connector
->aux
);
1155 if ((nv_encoder
= find_encoder(connector
, DCB_OUTPUT_DP
)))
1156 nv50_mstm_service(nv_encoder
->dp
.mstm
);
1158 bool plugged
= (rep
->mask
!= NVIF_NOTIFY_CONN_V0_UNPLUG
);
1161 drm_dp_cec_unset_edid(&nv_connector
->aux
);
1162 NV_DEBUG(drm
, "%splugged %s\n", plugged
? "" : "un", name
);
1163 if ((nv_encoder
= find_encoder(connector
, DCB_OUTPUT_DP
))) {
1165 nv50_mstm_remove(nv_encoder
->dp
.mstm
);
1168 drm_helper_hpd_irq_event(connector
->dev
);
1171 pm_runtime_mark_last_busy(drm
->dev
->dev
);
1172 pm_runtime_put_autosuspend(drm
->dev
->dev
);
1173 return NVIF_NOTIFY_KEEP
;
1177 nouveau_connector_aux_xfer(struct drm_dp_aux
*obj
, struct drm_dp_aux_msg
*msg
)
1179 struct nouveau_connector
*nv_connector
=
1180 container_of(obj
, typeof(*nv_connector
), aux
);
1181 struct nouveau_encoder
*nv_encoder
;
1182 struct nvkm_i2c_aux
*aux
;
1183 u8 size
= msg
->size
;
1186 nv_encoder
= find_encoder(&nv_connector
->base
, DCB_OUTPUT_DP
);
1187 if (!nv_encoder
|| !(aux
= nv_encoder
->aux
))
1189 if (WARN_ON(msg
->size
> 16))
1192 ret
= nvkm_i2c_aux_acquire(aux
);
1196 ret
= nvkm_i2c_aux_xfer(aux
, false, msg
->request
, msg
->address
,
1197 msg
->buffer
, &size
);
1198 nvkm_i2c_aux_release(aux
);
1208 drm_conntype_from_dcb(enum dcb_connector_type dcb
)
1211 case DCB_CONNECTOR_VGA
: return DRM_MODE_CONNECTOR_VGA
;
1212 case DCB_CONNECTOR_TV_0
:
1213 case DCB_CONNECTOR_TV_1
:
1214 case DCB_CONNECTOR_TV_3
: return DRM_MODE_CONNECTOR_TV
;
1215 case DCB_CONNECTOR_DMS59_0
:
1216 case DCB_CONNECTOR_DMS59_1
:
1217 case DCB_CONNECTOR_DVI_I
: return DRM_MODE_CONNECTOR_DVII
;
1218 case DCB_CONNECTOR_DVI_D
: return DRM_MODE_CONNECTOR_DVID
;
1219 case DCB_CONNECTOR_LVDS
:
1220 case DCB_CONNECTOR_LVDS_SPWG
: return DRM_MODE_CONNECTOR_LVDS
;
1221 case DCB_CONNECTOR_DMS59_DP0
:
1222 case DCB_CONNECTOR_DMS59_DP1
:
1223 case DCB_CONNECTOR_DP
:
1224 case DCB_CONNECTOR_USB_C
: return DRM_MODE_CONNECTOR_DisplayPort
;
1225 case DCB_CONNECTOR_eDP
: return DRM_MODE_CONNECTOR_eDP
;
1226 case DCB_CONNECTOR_HDMI_0
:
1227 case DCB_CONNECTOR_HDMI_1
:
1228 case DCB_CONNECTOR_HDMI_C
: return DRM_MODE_CONNECTOR_HDMIA
;
1229 case DCB_CONNECTOR_WFD
: return DRM_MODE_CONNECTOR_VIRTUAL
;
1234 return DRM_MODE_CONNECTOR_Unknown
;
1237 struct drm_connector
*
1238 nouveau_connector_create(struct drm_device
*dev
,
1239 const struct dcb_output
*dcbe
)
1241 const struct drm_connector_funcs
*funcs
= &nouveau_connector_funcs
;
1242 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1243 struct nouveau_display
*disp
= nouveau_display(dev
);
1244 struct nouveau_connector
*nv_connector
= NULL
;
1245 struct drm_connector
*connector
;
1246 struct drm_connector_list_iter conn_iter
;
1247 char aux_name
[48] = {0};
1248 int index
= dcbe
->connector
;
1252 drm_connector_list_iter_begin(dev
, &conn_iter
);
1253 nouveau_for_each_non_mst_connector_iter(connector
, &conn_iter
) {
1254 nv_connector
= nouveau_connector(connector
);
1255 if (nv_connector
->index
== index
) {
1256 drm_connector_list_iter_end(&conn_iter
);
1260 drm_connector_list_iter_end(&conn_iter
);
1262 nv_connector
= kzalloc(sizeof(*nv_connector
), GFP_KERNEL
);
1264 return ERR_PTR(-ENOMEM
);
1266 connector
= &nv_connector
->base
;
1267 nv_connector
->index
= index
;
1269 /* attempt to parse vbios connector type and hotplug gpio */
1270 nv_connector
->dcb
= olddcb_conn(dev
, index
);
1271 if (nv_connector
->dcb
) {
1272 u32 entry
= ROM16(nv_connector
->dcb
[0]);
1273 if (olddcb_conntab(dev
)[3] >= 4)
1274 entry
|= (u32
)ROM16(nv_connector
->dcb
[2]) << 16;
1276 nv_connector
->type
= nv_connector
->dcb
[0];
1277 if (drm_conntype_from_dcb(nv_connector
->type
) ==
1278 DRM_MODE_CONNECTOR_Unknown
) {
1279 NV_WARN(drm
, "unknown connector type %02x\n",
1280 nv_connector
->type
);
1281 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1284 /* Gigabyte NX85T */
1285 if (nv_match_device(dev
, 0x0421, 0x1458, 0x344c)) {
1286 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1287 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1290 /* Gigabyte GV-NX86T512H */
1291 if (nv_match_device(dev
, 0x0402, 0x1458, 0x3455)) {
1292 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1293 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1296 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1299 /* no vbios data, or an unknown dcb connector type - attempt to
1300 * figure out something suitable ourselves
1302 if (nv_connector
->type
== DCB_CONNECTOR_NONE
) {
1303 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1304 struct dcb_table
*dcbt
= &drm
->vbios
.dcb
;
1308 for (i
= 0; i
< dcbt
->entries
; i
++) {
1309 if (dcbt
->entry
[i
].connector
== nv_connector
->index
)
1310 encoders
|= (1 << dcbt
->entry
[i
].type
);
1313 if (encoders
& (1 << DCB_OUTPUT_DP
)) {
1314 if (encoders
& (1 << DCB_OUTPUT_TMDS
))
1315 nv_connector
->type
= DCB_CONNECTOR_DP
;
1317 nv_connector
->type
= DCB_CONNECTOR_eDP
;
1319 if (encoders
& (1 << DCB_OUTPUT_TMDS
)) {
1320 if (encoders
& (1 << DCB_OUTPUT_ANALOG
))
1321 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1323 nv_connector
->type
= DCB_CONNECTOR_DVI_D
;
1325 if (encoders
& (1 << DCB_OUTPUT_ANALOG
)) {
1326 nv_connector
->type
= DCB_CONNECTOR_VGA
;
1328 if (encoders
& (1 << DCB_OUTPUT_LVDS
)) {
1329 nv_connector
->type
= DCB_CONNECTOR_LVDS
;
1331 if (encoders
& (1 << DCB_OUTPUT_TV
)) {
1332 nv_connector
->type
= DCB_CONNECTOR_TV_0
;
1336 switch ((type
= drm_conntype_from_dcb(nv_connector
->type
))) {
1337 case DRM_MODE_CONNECTOR_LVDS
:
1338 ret
= nouveau_bios_parse_lvds_table(dev
, 0, &dummy
, &dummy
);
1340 NV_ERROR(drm
, "Error parsing LVDS table, disabling\n");
1341 kfree(nv_connector
);
1342 return ERR_PTR(ret
);
1345 funcs
= &nouveau_connector_funcs_lvds
;
1347 case DRM_MODE_CONNECTOR_DisplayPort
:
1348 case DRM_MODE_CONNECTOR_eDP
:
1349 nv_connector
->aux
.dev
= dev
->dev
;
1350 nv_connector
->aux
.transfer
= nouveau_connector_aux_xfer
;
1351 snprintf(aux_name
, sizeof(aux_name
), "sor-%04x-%04x",
1352 dcbe
->hasht
, dcbe
->hashm
);
1353 nv_connector
->aux
.name
= kstrdup(aux_name
, GFP_KERNEL
);
1354 ret
= drm_dp_aux_register(&nv_connector
->aux
);
1356 NV_ERROR(drm
, "failed to register aux channel\n");
1357 kfree(nv_connector
);
1358 return ERR_PTR(ret
);
1360 funcs
= &nouveau_connector_funcs
;
1363 funcs
= &nouveau_connector_funcs
;
1367 /* HDMI 3D support */
1368 if ((disp
->disp
.object
.oclass
>= G82_DISP
)
1369 && ((type
== DRM_MODE_CONNECTOR_DisplayPort
)
1370 || (type
== DRM_MODE_CONNECTOR_eDP
)
1371 || (type
== DRM_MODE_CONNECTOR_HDMIA
)))
1372 connector
->stereo_allowed
= true;
1374 /* defaults, will get overridden in detect() */
1375 connector
->interlace_allowed
= false;
1376 connector
->doublescan_allowed
= false;
1378 drm_connector_init(dev
, connector
, funcs
, type
);
1379 drm_connector_helper_add(connector
, &nouveau_connector_helper_funcs
);
1381 connector
->funcs
->reset(connector
);
1382 nouveau_conn_attach_properties(connector
);
1384 /* Default scaling mode */
1385 switch (nv_connector
->type
) {
1386 case DCB_CONNECTOR_LVDS
:
1387 case DCB_CONNECTOR_LVDS_SPWG
:
1388 case DCB_CONNECTOR_eDP
:
1389 /* see note in nouveau_connector_set_property() */
1390 if (disp
->disp
.object
.oclass
< NV50_DISP
) {
1391 nv_connector
->scaling_mode
= DRM_MODE_SCALE_FULLSCREEN
;
1394 nv_connector
->scaling_mode
= DRM_MODE_SCALE_NONE
;
1397 nv_connector
->scaling_mode
= DRM_MODE_SCALE_NONE
;
1401 /* dithering properties */
1402 switch (nv_connector
->type
) {
1403 case DCB_CONNECTOR_TV_0
:
1404 case DCB_CONNECTOR_TV_1
:
1405 case DCB_CONNECTOR_TV_3
:
1406 case DCB_CONNECTOR_VGA
:
1409 nv_connector
->dithering_mode
= DITHERING_MODE_AUTO
;
1414 case DRM_MODE_CONNECTOR_DisplayPort
:
1415 case DRM_MODE_CONNECTOR_eDP
:
1416 drm_dp_cec_register_connector(&nv_connector
->aux
,
1417 connector
->name
, dev
->dev
);
1421 ret
= nvif_notify_init(&disp
->disp
.object
, nouveau_connector_hotplug
,
1422 true, NV04_DISP_NTFY_CONN
,
1423 &(struct nvif_notify_conn_req_v0
) {
1424 .mask
= NVIF_NOTIFY_CONN_V0_ANY
,
1427 sizeof(struct nvif_notify_conn_req_v0
),
1428 sizeof(struct nvif_notify_conn_rep_v0
),
1429 &nv_connector
->hpd
);
1431 connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
;
1433 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
1435 drm_connector_register(connector
);