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>
32 #include <drm/drm_edid.h>
33 #include <drm/drm_crtc_helper.h>
35 #include "nouveau_reg.h"
36 #include "nouveau_drm.h"
37 #include "dispnv04/hw.h"
38 #include "nouveau_acpi.h"
40 #include "nouveau_display.h"
41 #include "nouveau_connector.h"
42 #include "nouveau_encoder.h"
43 #include "nouveau_crtc.h"
45 #include <nvif/cl0046.h>
46 #include <nvif/event.h>
48 MODULE_PARM_DESC(tv_disable
, "Disable TV-out detection");
49 int nouveau_tv_disable
= 0;
50 module_param_named(tv_disable
, nouveau_tv_disable
, int, 0400);
52 MODULE_PARM_DESC(ignorelid
, "Ignore ACPI lid status");
53 int nouveau_ignorelid
= 0;
54 module_param_named(ignorelid
, nouveau_ignorelid
, int, 0400);
56 MODULE_PARM_DESC(duallink
, "Allow dual-link TMDS (default: enabled)");
57 int nouveau_duallink
= 1;
58 module_param_named(duallink
, nouveau_duallink
, int, 0400);
60 MODULE_PARM_DESC(hdmimhz
, "Force a maximum HDMI pixel clock (in MHz)");
61 int nouveau_hdmimhz
= 0;
62 module_param_named(hdmimhz
, nouveau_hdmimhz
, int, 0400);
64 struct nouveau_encoder
*
65 find_encoder(struct drm_connector
*connector
, int type
)
67 struct drm_device
*dev
= connector
->dev
;
68 struct nouveau_encoder
*nv_encoder
;
69 struct drm_encoder
*enc
;
72 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
73 id
= connector
->encoder_ids
[i
];
77 enc
= drm_encoder_find(dev
, id
);
80 nv_encoder
= nouveau_encoder(enc
);
82 if (type
== DCB_OUTPUT_ANY
||
83 (nv_encoder
->dcb
&& nv_encoder
->dcb
->type
== type
))
90 struct nouveau_connector
*
91 nouveau_encoder_connector_get(struct nouveau_encoder
*encoder
)
93 struct drm_device
*dev
= to_drm_encoder(encoder
)->dev
;
94 struct drm_connector
*drm_connector
;
96 list_for_each_entry(drm_connector
, &dev
->mode_config
.connector_list
, head
) {
97 if (drm_connector
->encoder
== to_drm_encoder(encoder
))
98 return nouveau_connector(drm_connector
);
105 nouveau_connector_destroy(struct drm_connector
*connector
)
107 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
108 nvif_notify_fini(&nv_connector
->hpd
);
109 kfree(nv_connector
->edid
);
110 drm_connector_unregister(connector
);
111 drm_connector_cleanup(connector
);
112 if (nv_connector
->aux
.transfer
)
113 drm_dp_aux_unregister(&nv_connector
->aux
);
117 static struct nouveau_encoder
*
118 nouveau_connector_ddc_detect(struct drm_connector
*connector
)
120 struct drm_device
*dev
= connector
->dev
;
121 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
122 struct nouveau_drm
*drm
= nouveau_drm(dev
);
123 struct nvkm_gpio
*gpio
= nvxx_gpio(&drm
->device
);
124 struct nouveau_encoder
*nv_encoder
;
125 struct drm_encoder
*encoder
;
126 int i
, panel
= -ENODEV
;
128 /* eDP panels need powering on by us (if the VBIOS doesn't default it
129 * to on) before doing any AUX channel transactions. LVDS panel power
130 * is handled by the SOR itself, and not required for LVDS DDC.
132 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
133 panel
= nvkm_gpio_get(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff);
135 nvkm_gpio_set(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff, 1);
140 for (i
= 0; nv_encoder
= NULL
, i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
141 int id
= connector
->encoder_ids
[i
];
145 encoder
= drm_encoder_find(dev
, id
);
148 nv_encoder
= nouveau_encoder(encoder
);
150 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
) {
151 int ret
= nouveau_dp_detect(nv_encoder
);
155 if (nv_encoder
->i2c
) {
156 if (nvkm_probe_i2c(nv_encoder
->i2c
, 0x50))
161 /* eDP panel not detected, restore panel power GPIO to previous
162 * state to avoid confusing the SOR for other output types.
164 if (!nv_encoder
&& panel
== 0)
165 nvkm_gpio_set(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff, panel
);
170 static struct nouveau_encoder
*
171 nouveau_connector_of_detect(struct drm_connector
*connector
)
174 struct drm_device
*dev
= connector
->dev
;
175 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
176 struct nouveau_encoder
*nv_encoder
;
177 struct device_node
*cn
, *dn
= pci_device_to_OF_node(dev
->pdev
);
180 !((nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TMDS
)) ||
181 (nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
))))
184 for_each_child_of_node(dn
, cn
) {
185 const char *name
= of_get_property(cn
, "name", NULL
);
186 const void *edid
= of_get_property(cn
, "EDID", NULL
);
187 int idx
= name
? name
[strlen(name
) - 1] - 'A' : 0;
189 if (nv_encoder
->dcb
->i2c_index
== idx
&& edid
) {
191 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
201 nouveau_connector_set_encoder(struct drm_connector
*connector
,
202 struct nouveau_encoder
*nv_encoder
)
204 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
205 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
206 struct drm_device
*dev
= connector
->dev
;
208 if (nv_connector
->detected_encoder
== nv_encoder
)
210 nv_connector
->detected_encoder
= nv_encoder
;
212 if (drm
->device
.info
.family
>= NV_DEVICE_INFO_V0_TESLA
) {
213 connector
->interlace_allowed
= true;
214 connector
->doublescan_allowed
= true;
216 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
||
217 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
) {
218 connector
->doublescan_allowed
= false;
219 connector
->interlace_allowed
= false;
221 connector
->doublescan_allowed
= true;
222 if (drm
->device
.info
.family
== NV_DEVICE_INFO_V0_KELVIN
||
223 (drm
->device
.info
.family
== NV_DEVICE_INFO_V0_CELSIUS
&&
224 (dev
->pdev
->device
& 0x0ff0) != 0x0100 &&
225 (dev
->pdev
->device
& 0x0ff0) != 0x0150))
227 connector
->interlace_allowed
= false;
229 connector
->interlace_allowed
= true;
232 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
233 drm_object_property_set_value(&connector
->base
,
234 dev
->mode_config
.dvi_i_subconnector_property
,
235 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
?
236 DRM_MODE_SUBCONNECTOR_DVID
:
237 DRM_MODE_SUBCONNECTOR_DVIA
);
241 static enum drm_connector_status
242 nouveau_connector_detect(struct drm_connector
*connector
, bool force
)
244 struct drm_device
*dev
= connector
->dev
;
245 struct nouveau_drm
*drm
= nouveau_drm(dev
);
246 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
247 struct nouveau_encoder
*nv_encoder
= NULL
;
248 struct nouveau_encoder
*nv_partner
;
249 struct i2c_adapter
*i2c
;
252 enum drm_connector_status conn_status
= connector_status_disconnected
;
254 /* Cleanup the previous EDID block. */
255 if (nv_connector
->edid
) {
256 drm_mode_connector_update_edid_property(connector
, NULL
);
257 kfree(nv_connector
->edid
);
258 nv_connector
->edid
= NULL
;
261 ret
= pm_runtime_get_sync(connector
->dev
->dev
);
262 if (ret
< 0 && ret
!= -EACCES
)
265 nv_encoder
= nouveau_connector_ddc_detect(connector
);
266 if (nv_encoder
&& (i2c
= nv_encoder
->i2c
) != NULL
) {
267 nv_connector
->edid
= drm_get_edid(connector
, i2c
);
268 drm_mode_connector_update_edid_property(connector
,
270 if (!nv_connector
->edid
) {
271 NV_ERROR(drm
, "DDC responded, but no EDID for %s\n",
276 /* Override encoder type for DVI-I based on whether EDID
277 * says the display is digital or analog, both use the
278 * same i2c channel so the value returned from ddc_detect
279 * isn't necessarily correct.
282 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
)
283 nv_partner
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
284 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
)
285 nv_partner
= find_encoder(connector
, DCB_OUTPUT_TMDS
);
287 if (nv_partner
&& ((nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
&&
288 nv_partner
->dcb
->type
== DCB_OUTPUT_TMDS
) ||
289 (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
&&
290 nv_partner
->dcb
->type
== DCB_OUTPUT_ANALOG
))) {
291 if (nv_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
)
292 type
= DCB_OUTPUT_TMDS
;
294 type
= DCB_OUTPUT_ANALOG
;
296 nv_encoder
= find_encoder(connector
, type
);
299 nouveau_connector_set_encoder(connector
, nv_encoder
);
300 conn_status
= connector_status_connected
;
304 nv_encoder
= nouveau_connector_of_detect(connector
);
306 nouveau_connector_set_encoder(connector
, nv_encoder
);
307 conn_status
= connector_status_connected
;
312 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
313 if (!nv_encoder
&& !nouveau_tv_disable
)
314 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TV
);
315 if (nv_encoder
&& force
) {
316 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
317 const struct drm_encoder_helper_funcs
*helper
=
318 encoder
->helper_private
;
320 if (helper
->detect(encoder
, connector
) ==
321 connector_status_connected
) {
322 nouveau_connector_set_encoder(connector
, nv_encoder
);
323 conn_status
= connector_status_connected
;
331 pm_runtime_mark_last_busy(connector
->dev
->dev
);
332 pm_runtime_put_autosuspend(connector
->dev
->dev
);
337 static enum drm_connector_status
338 nouveau_connector_detect_lvds(struct drm_connector
*connector
, bool force
)
340 struct drm_device
*dev
= connector
->dev
;
341 struct nouveau_drm
*drm
= nouveau_drm(dev
);
342 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
343 struct nouveau_encoder
*nv_encoder
= NULL
;
344 enum drm_connector_status status
= connector_status_disconnected
;
346 /* Cleanup the previous EDID block. */
347 if (nv_connector
->edid
) {
348 drm_mode_connector_update_edid_property(connector
, NULL
);
349 kfree(nv_connector
->edid
);
350 nv_connector
->edid
= NULL
;
353 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_LVDS
);
355 return connector_status_disconnected
;
357 /* Try retrieving EDID via DDC */
358 if (!drm
->vbios
.fp_no_ddc
) {
359 status
= nouveau_connector_detect(connector
, force
);
360 if (status
== connector_status_connected
)
364 /* On some laptops (Sony, i'm looking at you) there appears to
365 * be no direct way of accessing the panel's EDID. The only
366 * option available to us appears to be to ask ACPI for help..
368 * It's important this check's before trying straps, one of the
369 * said manufacturer's laptops are configured in such a way
370 * the nouveau decides an entry in the VBIOS FP mode table is
371 * valid - it's not (rh#613284)
373 if (nv_encoder
->dcb
->lvdsconf
.use_acpi_for_edid
) {
374 if ((nv_connector
->edid
= nouveau_acpi_edid(dev
, connector
))) {
375 status
= connector_status_connected
;
380 /* If no EDID found above, and the VBIOS indicates a hardcoded
381 * modeline is avalilable for the panel, set it as the panel's
382 * native mode and exit.
384 if (nouveau_bios_fp_mode(dev
, NULL
) && (drm
->vbios
.fp_no_ddc
||
385 nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
)) {
386 status
= connector_status_connected
;
390 /* Still nothing, some VBIOS images have a hardcoded EDID block
391 * stored for the panel stored in them.
393 if (!drm
->vbios
.fp_no_ddc
) {
395 (struct edid
*)nouveau_bios_embedded_edid(dev
);
398 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
399 if (nv_connector
->edid
)
400 status
= connector_status_connected
;
405 #if defined(CONFIG_ACPI_BUTTON) || \
406 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
407 if (status
== connector_status_connected
&&
408 !nouveau_ignorelid
&& !acpi_lid_open())
409 status
= connector_status_unknown
;
412 drm_mode_connector_update_edid_property(connector
, nv_connector
->edid
);
413 nouveau_connector_set_encoder(connector
, nv_encoder
);
418 nouveau_connector_force(struct drm_connector
*connector
)
420 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
421 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
422 struct nouveau_encoder
*nv_encoder
;
425 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
426 if (connector
->force
== DRM_FORCE_ON_DIGITAL
)
427 type
= DCB_OUTPUT_TMDS
;
429 type
= DCB_OUTPUT_ANALOG
;
431 type
= DCB_OUTPUT_ANY
;
433 nv_encoder
= find_encoder(connector
, type
);
435 NV_ERROR(drm
, "can't find encoder to force %s on!\n",
437 connector
->status
= connector_status_disconnected
;
441 nouveau_connector_set_encoder(connector
, nv_encoder
);
445 nouveau_connector_set_property(struct drm_connector
*connector
,
446 struct drm_property
*property
, uint64_t value
)
448 struct nouveau_display
*disp
= nouveau_display(connector
->dev
);
449 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
450 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
451 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
452 struct drm_device
*dev
= connector
->dev
;
453 struct nouveau_crtc
*nv_crtc
;
457 if (connector
->encoder
&& connector
->encoder
->crtc
)
458 nv_crtc
= nouveau_crtc(connector
->encoder
->crtc
);
461 if (property
== dev
->mode_config
.scaling_mode_property
) {
462 bool modeset
= false;
465 case DRM_MODE_SCALE_NONE
:
466 /* We allow 'None' for EDID modes, even on a fixed
467 * panel (some exist with support for lower refresh
468 * rates, which people might want to use for power
471 * Non-EDID modes will force the use of GPU scaling
472 * to the native mode regardless of this setting.
474 switch (nv_connector
->type
) {
475 case DCB_CONNECTOR_LVDS
:
476 case DCB_CONNECTOR_LVDS_SPWG
:
477 case DCB_CONNECTOR_eDP
:
478 /* ... except prior to G80, where the code
479 * doesn't support such things.
481 if (disp
->disp
.oclass
< NV50_DISP
)
488 case DRM_MODE_SCALE_FULLSCREEN
:
489 case DRM_MODE_SCALE_CENTER
:
490 case DRM_MODE_SCALE_ASPECT
:
496 /* Changing between GPU and panel scaling requires a full
499 if ((nv_connector
->scaling_mode
== DRM_MODE_SCALE_NONE
) ||
500 (value
== DRM_MODE_SCALE_NONE
))
502 nv_connector
->scaling_mode
= value
;
507 if (modeset
|| !nv_crtc
->set_scale
) {
508 ret
= drm_crtc_helper_set_mode(&nv_crtc
->base
,
511 nv_crtc
->base
.y
, NULL
);
515 ret
= nv_crtc
->set_scale(nv_crtc
, true);
524 if (property
== disp
->underscan_property
) {
525 if (nv_connector
->underscan
!= value
) {
526 nv_connector
->underscan
= value
;
527 if (!nv_crtc
|| !nv_crtc
->set_scale
)
530 return nv_crtc
->set_scale(nv_crtc
, true);
536 if (property
== disp
->underscan_hborder_property
) {
537 if (nv_connector
->underscan_hborder
!= value
) {
538 nv_connector
->underscan_hborder
= value
;
539 if (!nv_crtc
|| !nv_crtc
->set_scale
)
542 return nv_crtc
->set_scale(nv_crtc
, true);
548 if (property
== disp
->underscan_vborder_property
) {
549 if (nv_connector
->underscan_vborder
!= value
) {
550 nv_connector
->underscan_vborder
= value
;
551 if (!nv_crtc
|| !nv_crtc
->set_scale
)
554 return nv_crtc
->set_scale(nv_crtc
, true);
561 if (property
== disp
->dithering_mode
) {
562 nv_connector
->dithering_mode
= value
;
563 if (!nv_crtc
|| !nv_crtc
->set_dither
)
566 return nv_crtc
->set_dither(nv_crtc
, true);
569 if (property
== disp
->dithering_depth
) {
570 nv_connector
->dithering_depth
= value
;
571 if (!nv_crtc
|| !nv_crtc
->set_dither
)
574 return nv_crtc
->set_dither(nv_crtc
, true);
577 if (nv_crtc
&& nv_crtc
->set_color_vibrance
) {
579 if (property
== disp
->vibrant_hue_property
) {
580 nv_crtc
->vibrant_hue
= value
- 90;
581 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
584 if (property
== disp
->color_vibrance_property
) {
585 nv_crtc
->color_vibrance
= value
- 100;
586 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
590 if (nv_encoder
&& nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
591 return get_slave_funcs(encoder
)->set_property(
592 encoder
, connector
, property
, value
);
597 static struct drm_display_mode
*
598 nouveau_connector_native_mode(struct drm_connector
*connector
)
600 const struct drm_connector_helper_funcs
*helper
= connector
->helper_private
;
601 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
602 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
603 struct drm_device
*dev
= connector
->dev
;
604 struct drm_display_mode
*mode
, *largest
= NULL
;
605 int high_w
= 0, high_h
= 0, high_v
= 0;
607 list_for_each_entry(mode
, &nv_connector
->base
.probed_modes
, head
) {
608 mode
->vrefresh
= drm_mode_vrefresh(mode
);
609 if (helper
->mode_valid(connector
, mode
) != MODE_OK
||
610 (mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
613 /* Use preferred mode if there is one.. */
614 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
) {
615 NV_DEBUG(drm
, "native mode from preferred\n");
616 return drm_mode_duplicate(dev
, mode
);
619 /* Otherwise, take the resolution with the largest width, then
620 * height, then vertical refresh
622 if (mode
->hdisplay
< high_w
)
625 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
< high_h
)
628 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
== high_h
&&
629 mode
->vrefresh
< high_v
)
632 high_w
= mode
->hdisplay
;
633 high_h
= mode
->vdisplay
;
634 high_v
= mode
->vrefresh
;
638 NV_DEBUG(drm
, "native mode from largest: %dx%d@%d\n",
639 high_w
, high_h
, high_v
);
640 return largest
? drm_mode_duplicate(dev
, largest
) : NULL
;
648 static struct moderec scaler_modes
[] = {
667 nouveau_connector_scaler_modes_add(struct drm_connector
*connector
)
669 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
670 struct drm_display_mode
*native
= nv_connector
->native_mode
, *m
;
671 struct drm_device
*dev
= connector
->dev
;
672 struct moderec
*mode
= &scaler_modes
[0];
678 while (mode
->hdisplay
) {
679 if (mode
->hdisplay
<= native
->hdisplay
&&
680 mode
->vdisplay
<= native
->vdisplay
&&
681 (mode
->hdisplay
!= native
->hdisplay
||
682 mode
->vdisplay
!= native
->vdisplay
)) {
683 m
= drm_cvt_mode(dev
, mode
->hdisplay
, mode
->vdisplay
,
684 drm_mode_vrefresh(native
), false,
689 drm_mode_probed_add(connector
, m
);
700 nouveau_connector_detect_depth(struct drm_connector
*connector
)
702 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
703 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
704 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
705 struct nvbios
*bios
= &drm
->vbios
;
706 struct drm_display_mode
*mode
= nv_connector
->native_mode
;
709 /* if the edid is feeling nice enough to provide this info, use it */
710 if (nv_connector
->edid
&& connector
->display_info
.bpc
)
713 /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
714 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
715 connector
->display_info
.bpc
= 6;
719 /* we're out of options unless we're LVDS, default to 8bpc */
720 if (nv_encoder
->dcb
->type
!= DCB_OUTPUT_LVDS
) {
721 connector
->display_info
.bpc
= 8;
725 connector
->display_info
.bpc
= 6;
727 /* LVDS: panel straps */
728 if (bios
->fp_no_ddc
) {
729 if (bios
->fp
.if_is_24bit
)
730 connector
->display_info
.bpc
= 8;
734 /* LVDS: DDC panel, need to first determine the number of links to
735 * know which if_is_24bit flag to check...
737 if (nv_connector
->edid
&&
738 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
)
739 duallink
= ((u8
*)nv_connector
->edid
)[121] == 2;
741 duallink
= mode
->clock
>= bios
->fp
.duallink_transition_clk
;
743 if ((!duallink
&& (bios
->fp
.strapless_is_24bit
& 1)) ||
744 ( duallink
&& (bios
->fp
.strapless_is_24bit
& 2)))
745 connector
->display_info
.bpc
= 8;
749 nouveau_connector_get_modes(struct drm_connector
*connector
)
751 struct drm_device
*dev
= connector
->dev
;
752 struct nouveau_drm
*drm
= nouveau_drm(dev
);
753 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
754 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
755 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
758 /* destroy the native mode, the attached monitor could have changed.
760 if (nv_connector
->native_mode
) {
761 drm_mode_destroy(dev
, nv_connector
->native_mode
);
762 nv_connector
->native_mode
= NULL
;
765 if (nv_connector
->edid
)
766 ret
= drm_add_edid_modes(connector
, nv_connector
->edid
);
768 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
&&
769 (nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
||
770 drm
->vbios
.fp_no_ddc
) && nouveau_bios_fp_mode(dev
, NULL
)) {
771 struct drm_display_mode mode
;
773 nouveau_bios_fp_mode(dev
, &mode
);
774 nv_connector
->native_mode
= drm_mode_duplicate(dev
, &mode
);
777 /* Determine display colour depth for everything except LVDS now,
778 * DP requires this before mode_valid() is called.
780 if (connector
->connector_type
!= DRM_MODE_CONNECTOR_LVDS
)
781 nouveau_connector_detect_depth(connector
);
783 /* Find the native mode if this is a digital panel, if we didn't
784 * find any modes through DDC previously add the native mode to
787 if (!nv_connector
->native_mode
)
788 nv_connector
->native_mode
=
789 nouveau_connector_native_mode(connector
);
790 if (ret
== 0 && nv_connector
->native_mode
) {
791 struct drm_display_mode
*mode
;
793 mode
= drm_mode_duplicate(dev
, nv_connector
->native_mode
);
794 drm_mode_probed_add(connector
, mode
);
798 /* Determine LVDS colour depth, must happen after determining
799 * "native" mode as some VBIOS tables require us to use the
800 * pixel clock as part of the lookup...
802 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
)
803 nouveau_connector_detect_depth(connector
);
805 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
806 ret
= get_slave_funcs(encoder
)->get_modes(encoder
, connector
);
808 if (nv_connector
->type
== DCB_CONNECTOR_LVDS
||
809 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
||
810 nv_connector
->type
== DCB_CONNECTOR_eDP
)
811 ret
+= nouveau_connector_scaler_modes_add(connector
);
817 get_tmds_link_bandwidth(struct drm_connector
*connector
, bool hdmi
)
819 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
820 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
821 struct dcb_output
*dcb
= nv_connector
->detected_encoder
->dcb
;
824 if (nouveau_hdmimhz
> 0)
825 return nouveau_hdmimhz
* 1000;
826 /* Note: these limits are conservative, some Fermi's
827 * can do 297 MHz. Unclear how this can be determined.
829 if (drm
->device
.info
.family
>= NV_DEVICE_INFO_V0_KEPLER
)
831 if (drm
->device
.info
.family
>= NV_DEVICE_INFO_V0_FERMI
)
834 if (dcb
->location
!= DCB_LOC_ON_CHIP
||
835 drm
->device
.info
.chipset
>= 0x46)
837 else if (drm
->device
.info
.chipset
>= 0x40)
839 else if (drm
->device
.info
.chipset
>= 0x18)
846 nouveau_connector_mode_valid(struct drm_connector
*connector
,
847 struct drm_display_mode
*mode
)
849 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
850 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
851 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
852 unsigned min_clock
= 25000, max_clock
= min_clock
;
853 unsigned clock
= mode
->clock
;
856 switch (nv_encoder
->dcb
->type
) {
857 case DCB_OUTPUT_LVDS
:
858 if (nv_connector
->native_mode
&&
859 (mode
->hdisplay
> nv_connector
->native_mode
->hdisplay
||
860 mode
->vdisplay
> nv_connector
->native_mode
->vdisplay
))
866 case DCB_OUTPUT_TMDS
:
867 hdmi
= drm_detect_hdmi_monitor(nv_connector
->edid
);
868 max_clock
= get_tmds_link_bandwidth(connector
, hdmi
);
869 if (!hdmi
&& nouveau_duallink
&&
870 nv_encoder
->dcb
->duallink_possible
)
873 case DCB_OUTPUT_ANALOG
:
874 max_clock
= nv_encoder
->dcb
->crtconf
.maxfreq
;
879 return get_slave_funcs(encoder
)->mode_valid(encoder
, mode
);
881 max_clock
= nv_encoder
->dp
.link_nr
;
882 max_clock
*= nv_encoder
->dp
.link_bw
;
883 clock
= clock
* (connector
->display_info
.bpc
* 3) / 10;
890 if (clock
< min_clock
)
891 return MODE_CLOCK_LOW
;
893 if (clock
> max_clock
)
894 return MODE_CLOCK_HIGH
;
899 static struct drm_encoder
*
900 nouveau_connector_best_encoder(struct drm_connector
*connector
)
902 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
904 if (nv_connector
->detected_encoder
)
905 return to_drm_encoder(nv_connector
->detected_encoder
);
910 static const struct drm_connector_helper_funcs
911 nouveau_connector_helper_funcs
= {
912 .get_modes
= nouveau_connector_get_modes
,
913 .mode_valid
= nouveau_connector_mode_valid
,
914 .best_encoder
= nouveau_connector_best_encoder
,
917 static const struct drm_connector_funcs
918 nouveau_connector_funcs
= {
919 .dpms
= drm_helper_connector_dpms
,
920 .detect
= nouveau_connector_detect
,
921 .destroy
= nouveau_connector_destroy
,
922 .fill_modes
= drm_helper_probe_single_connector_modes
,
923 .set_property
= nouveau_connector_set_property
,
924 .force
= nouveau_connector_force
927 static const struct drm_connector_funcs
928 nouveau_connector_funcs_lvds
= {
929 .dpms
= drm_helper_connector_dpms
,
930 .detect
= nouveau_connector_detect_lvds
,
931 .destroy
= nouveau_connector_destroy
,
932 .fill_modes
= drm_helper_probe_single_connector_modes
,
933 .set_property
= nouveau_connector_set_property
,
934 .force
= nouveau_connector_force
938 nouveau_connector_dp_dpms(struct drm_connector
*connector
, int mode
)
940 struct nouveau_encoder
*nv_encoder
= NULL
;
942 if (connector
->encoder
)
943 nv_encoder
= nouveau_encoder(connector
->encoder
);
944 if (nv_encoder
&& nv_encoder
->dcb
&&
945 nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
) {
946 if (mode
== DRM_MODE_DPMS_ON
) {
947 u8 data
= DP_SET_POWER_D0
;
948 nvkm_wraux(nv_encoder
->aux
, DP_SET_POWER
, &data
, 1);
949 usleep_range(1000, 2000);
951 u8 data
= DP_SET_POWER_D3
;
952 nvkm_wraux(nv_encoder
->aux
, DP_SET_POWER
, &data
, 1);
956 return drm_helper_connector_dpms(connector
, mode
);
959 static const struct drm_connector_funcs
960 nouveau_connector_funcs_dp
= {
961 .dpms
= nouveau_connector_dp_dpms
,
962 .detect
= nouveau_connector_detect
,
963 .destroy
= nouveau_connector_destroy
,
964 .fill_modes
= drm_helper_probe_single_connector_modes
,
965 .set_property
= nouveau_connector_set_property
,
966 .force
= nouveau_connector_force
970 nouveau_connector_hotplug(struct nvif_notify
*notify
)
972 struct nouveau_connector
*nv_connector
=
973 container_of(notify
, typeof(*nv_connector
), hpd
);
974 struct drm_connector
*connector
= &nv_connector
->base
;
975 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
976 const struct nvif_notify_conn_rep_v0
*rep
= notify
->data
;
977 const char *name
= connector
->name
;
979 if (rep
->mask
& NVIF_NOTIFY_CONN_V0_IRQ
) {
981 bool plugged
= (rep
->mask
!= NVIF_NOTIFY_CONN_V0_UNPLUG
);
983 NV_DEBUG(drm
, "%splugged %s\n", plugged
? "" : "un", name
);
986 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_ON
);
988 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
989 drm_helper_hpd_irq_event(connector
->dev
);
992 return NVIF_NOTIFY_KEEP
;
996 nouveau_connector_aux_xfer(struct drm_dp_aux
*obj
, struct drm_dp_aux_msg
*msg
)
998 struct nouveau_connector
*nv_connector
=
999 container_of(obj
, typeof(*nv_connector
), aux
);
1000 struct nouveau_encoder
*nv_encoder
;
1001 struct nvkm_i2c_aux
*aux
;
1004 nv_encoder
= find_encoder(&nv_connector
->base
, DCB_OUTPUT_DP
);
1005 if (!nv_encoder
|| !(aux
= nv_encoder
->aux
))
1007 if (WARN_ON(msg
->size
> 16))
1012 ret
= nvkm_i2c_aux_acquire(aux
);
1016 ret
= nvkm_i2c_aux_xfer(aux
, false, msg
->request
, msg
->address
,
1017 msg
->buffer
, msg
->size
);
1018 nvkm_i2c_aux_release(aux
);
1028 drm_conntype_from_dcb(enum dcb_connector_type dcb
)
1031 case DCB_CONNECTOR_VGA
: return DRM_MODE_CONNECTOR_VGA
;
1032 case DCB_CONNECTOR_TV_0
:
1033 case DCB_CONNECTOR_TV_1
:
1034 case DCB_CONNECTOR_TV_3
: return DRM_MODE_CONNECTOR_TV
;
1035 case DCB_CONNECTOR_DMS59_0
:
1036 case DCB_CONNECTOR_DMS59_1
:
1037 case DCB_CONNECTOR_DVI_I
: return DRM_MODE_CONNECTOR_DVII
;
1038 case DCB_CONNECTOR_DVI_D
: return DRM_MODE_CONNECTOR_DVID
;
1039 case DCB_CONNECTOR_LVDS
:
1040 case DCB_CONNECTOR_LVDS_SPWG
: return DRM_MODE_CONNECTOR_LVDS
;
1041 case DCB_CONNECTOR_DMS59_DP0
:
1042 case DCB_CONNECTOR_DMS59_DP1
:
1043 case DCB_CONNECTOR_DP
: return DRM_MODE_CONNECTOR_DisplayPort
;
1044 case DCB_CONNECTOR_eDP
: return DRM_MODE_CONNECTOR_eDP
;
1045 case DCB_CONNECTOR_HDMI_0
:
1046 case DCB_CONNECTOR_HDMI_1
:
1047 case DCB_CONNECTOR_HDMI_C
: return DRM_MODE_CONNECTOR_HDMIA
;
1052 return DRM_MODE_CONNECTOR_Unknown
;
1055 struct drm_connector
*
1056 nouveau_connector_create(struct drm_device
*dev
, int index
)
1058 const struct drm_connector_funcs
*funcs
= &nouveau_connector_funcs
;
1059 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1060 struct nouveau_display
*disp
= nouveau_display(dev
);
1061 struct nouveau_connector
*nv_connector
= NULL
;
1062 struct drm_connector
*connector
;
1066 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1067 nv_connector
= nouveau_connector(connector
);
1068 if (nv_connector
->index
== index
)
1072 nv_connector
= kzalloc(sizeof(*nv_connector
), GFP_KERNEL
);
1074 return ERR_PTR(-ENOMEM
);
1076 connector
= &nv_connector
->base
;
1077 nv_connector
->index
= index
;
1079 /* attempt to parse vbios connector type and hotplug gpio */
1080 nv_connector
->dcb
= olddcb_conn(dev
, index
);
1081 if (nv_connector
->dcb
) {
1082 u32 entry
= ROM16(nv_connector
->dcb
[0]);
1083 if (olddcb_conntab(dev
)[3] >= 4)
1084 entry
|= (u32
)ROM16(nv_connector
->dcb
[2]) << 16;
1086 nv_connector
->type
= nv_connector
->dcb
[0];
1087 if (drm_conntype_from_dcb(nv_connector
->type
) ==
1088 DRM_MODE_CONNECTOR_Unknown
) {
1089 NV_WARN(drm
, "unknown connector type %02x\n",
1090 nv_connector
->type
);
1091 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1094 /* Gigabyte NX85T */
1095 if (nv_match_device(dev
, 0x0421, 0x1458, 0x344c)) {
1096 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1097 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1100 /* Gigabyte GV-NX86T512H */
1101 if (nv_match_device(dev
, 0x0402, 0x1458, 0x3455)) {
1102 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1103 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1106 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1109 /* no vbios data, or an unknown dcb connector type - attempt to
1110 * figure out something suitable ourselves
1112 if (nv_connector
->type
== DCB_CONNECTOR_NONE
) {
1113 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1114 struct dcb_table
*dcbt
= &drm
->vbios
.dcb
;
1118 for (i
= 0; i
< dcbt
->entries
; i
++) {
1119 if (dcbt
->entry
[i
].connector
== nv_connector
->index
)
1120 encoders
|= (1 << dcbt
->entry
[i
].type
);
1123 if (encoders
& (1 << DCB_OUTPUT_DP
)) {
1124 if (encoders
& (1 << DCB_OUTPUT_TMDS
))
1125 nv_connector
->type
= DCB_CONNECTOR_DP
;
1127 nv_connector
->type
= DCB_CONNECTOR_eDP
;
1129 if (encoders
& (1 << DCB_OUTPUT_TMDS
)) {
1130 if (encoders
& (1 << DCB_OUTPUT_ANALOG
))
1131 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1133 nv_connector
->type
= DCB_CONNECTOR_DVI_D
;
1135 if (encoders
& (1 << DCB_OUTPUT_ANALOG
)) {
1136 nv_connector
->type
= DCB_CONNECTOR_VGA
;
1138 if (encoders
& (1 << DCB_OUTPUT_LVDS
)) {
1139 nv_connector
->type
= DCB_CONNECTOR_LVDS
;
1141 if (encoders
& (1 << DCB_OUTPUT_TV
)) {
1142 nv_connector
->type
= DCB_CONNECTOR_TV_0
;
1146 switch ((type
= drm_conntype_from_dcb(nv_connector
->type
))) {
1147 case DRM_MODE_CONNECTOR_LVDS
:
1148 ret
= nouveau_bios_parse_lvds_table(dev
, 0, &dummy
, &dummy
);
1150 NV_ERROR(drm
, "Error parsing LVDS table, disabling\n");
1151 kfree(nv_connector
);
1152 return ERR_PTR(ret
);
1155 funcs
= &nouveau_connector_funcs_lvds
;
1157 case DRM_MODE_CONNECTOR_DisplayPort
:
1158 case DRM_MODE_CONNECTOR_eDP
:
1159 nv_connector
->aux
.dev
= dev
->dev
;
1160 nv_connector
->aux
.transfer
= nouveau_connector_aux_xfer
;
1161 ret
= drm_dp_aux_register(&nv_connector
->aux
);
1163 NV_ERROR(drm
, "failed to register aux channel\n");
1164 kfree(nv_connector
);
1165 return ERR_PTR(ret
);
1168 funcs
= &nouveau_connector_funcs_dp
;
1171 funcs
= &nouveau_connector_funcs
;
1175 /* defaults, will get overridden in detect() */
1176 connector
->interlace_allowed
= false;
1177 connector
->doublescan_allowed
= false;
1179 drm_connector_init(dev
, connector
, funcs
, type
);
1180 drm_connector_helper_add(connector
, &nouveau_connector_helper_funcs
);
1182 /* Init DVI-I specific properties */
1183 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
)
1184 drm_object_attach_property(&connector
->base
, dev
->mode_config
.dvi_i_subconnector_property
, 0);
1186 /* Add overscan compensation options to digital outputs */
1187 if (disp
->underscan_property
&&
1188 (type
== DRM_MODE_CONNECTOR_DVID
||
1189 type
== DRM_MODE_CONNECTOR_DVII
||
1190 type
== DRM_MODE_CONNECTOR_HDMIA
||
1191 type
== DRM_MODE_CONNECTOR_DisplayPort
)) {
1192 drm_object_attach_property(&connector
->base
,
1193 disp
->underscan_property
,
1195 drm_object_attach_property(&connector
->base
,
1196 disp
->underscan_hborder_property
,
1198 drm_object_attach_property(&connector
->base
,
1199 disp
->underscan_vborder_property
,
1203 /* Add hue and saturation options */
1204 if (disp
->vibrant_hue_property
)
1205 drm_object_attach_property(&connector
->base
,
1206 disp
->vibrant_hue_property
,
1208 if (disp
->color_vibrance_property
)
1209 drm_object_attach_property(&connector
->base
,
1210 disp
->color_vibrance_property
,
1213 /* default scaling mode */
1214 switch (nv_connector
->type
) {
1215 case DCB_CONNECTOR_LVDS
:
1216 case DCB_CONNECTOR_LVDS_SPWG
:
1217 case DCB_CONNECTOR_eDP
:
1218 /* see note in nouveau_connector_set_property() */
1219 if (disp
->disp
.oclass
< NV50_DISP
) {
1220 nv_connector
->scaling_mode
= DRM_MODE_SCALE_FULLSCREEN
;
1223 nv_connector
->scaling_mode
= DRM_MODE_SCALE_NONE
;
1226 nv_connector
->scaling_mode
= DRM_MODE_SCALE_NONE
;
1230 /* scaling mode property */
1231 switch (nv_connector
->type
) {
1232 case DCB_CONNECTOR_TV_0
:
1233 case DCB_CONNECTOR_TV_1
:
1234 case DCB_CONNECTOR_TV_3
:
1236 case DCB_CONNECTOR_VGA
:
1237 if (disp
->disp
.oclass
< NV50_DISP
)
1238 break; /* can only scale on DFPs */
1241 drm_object_attach_property(&connector
->base
, dev
->mode_config
.
1242 scaling_mode_property
,
1243 nv_connector
->scaling_mode
);
1247 /* dithering properties */
1248 switch (nv_connector
->type
) {
1249 case DCB_CONNECTOR_TV_0
:
1250 case DCB_CONNECTOR_TV_1
:
1251 case DCB_CONNECTOR_TV_3
:
1252 case DCB_CONNECTOR_VGA
:
1255 if (disp
->dithering_mode
) {
1256 drm_object_attach_property(&connector
->base
,
1257 disp
->dithering_mode
,
1260 nv_connector
->dithering_mode
= DITHERING_MODE_AUTO
;
1262 if (disp
->dithering_depth
) {
1263 drm_object_attach_property(&connector
->base
,
1264 disp
->dithering_depth
,
1267 nv_connector
->dithering_depth
= DITHERING_DEPTH_AUTO
;
1272 ret
= nvif_notify_init(&disp
->disp
, nouveau_connector_hotplug
, true,
1273 NV04_DISP_NTFY_CONN
,
1274 &(struct nvif_notify_conn_req_v0
) {
1275 .mask
= NVIF_NOTIFY_CONN_V0_ANY
,
1278 sizeof(struct nvif_notify_conn_req_v0
),
1279 sizeof(struct nvif_notify_conn_rep_v0
),
1280 &nv_connector
->hpd
);
1282 connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
;
1284 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
1286 drm_connector_register(connector
);