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/event.h>
47 MODULE_PARM_DESC(tv_disable
, "Disable TV-out detection");
48 int nouveau_tv_disable
= 0;
49 module_param_named(tv_disable
, nouveau_tv_disable
, int, 0400);
51 MODULE_PARM_DESC(ignorelid
, "Ignore ACPI lid status");
52 int nouveau_ignorelid
= 0;
53 module_param_named(ignorelid
, nouveau_ignorelid
, int, 0400);
55 MODULE_PARM_DESC(duallink
, "Allow dual-link TMDS (default: enabled)");
56 int nouveau_duallink
= 1;
57 module_param_named(duallink
, nouveau_duallink
, int, 0400);
59 MODULE_PARM_DESC(hdmimhz
, "Force a maximum HDMI pixel clock (in MHz)");
60 int nouveau_hdmimhz
= 0;
61 module_param_named(hdmimhz
, nouveau_hdmimhz
, int, 0400);
63 struct nouveau_encoder
*
64 find_encoder(struct drm_connector
*connector
, int type
)
66 struct drm_device
*dev
= connector
->dev
;
67 struct nouveau_encoder
*nv_encoder
;
68 struct drm_encoder
*enc
;
71 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
72 id
= connector
->encoder_ids
[i
];
76 enc
= drm_encoder_find(dev
, id
);
79 nv_encoder
= nouveau_encoder(enc
);
81 if (type
== DCB_OUTPUT_ANY
||
82 (nv_encoder
->dcb
&& nv_encoder
->dcb
->type
== type
))
89 struct nouveau_connector
*
90 nouveau_encoder_connector_get(struct nouveau_encoder
*encoder
)
92 struct drm_device
*dev
= to_drm_encoder(encoder
)->dev
;
93 struct drm_connector
*drm_connector
;
95 list_for_each_entry(drm_connector
, &dev
->mode_config
.connector_list
, head
) {
96 if (drm_connector
->encoder
== to_drm_encoder(encoder
))
97 return nouveau_connector(drm_connector
);
104 nouveau_connector_destroy(struct drm_connector
*connector
)
106 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
107 nvif_notify_fini(&nv_connector
->hpd
);
108 kfree(nv_connector
->edid
);
109 drm_connector_unregister(connector
);
110 drm_connector_cleanup(connector
);
111 if (nv_connector
->aux
.transfer
)
112 drm_dp_aux_unregister(&nv_connector
->aux
);
116 static struct nouveau_encoder
*
117 nouveau_connector_ddc_detect(struct drm_connector
*connector
)
119 struct drm_device
*dev
= connector
->dev
;
120 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
121 struct nouveau_drm
*drm
= nouveau_drm(dev
);
122 struct nvkm_gpio
*gpio
= nvxx_gpio(&drm
->device
);
123 struct nouveau_encoder
*nv_encoder
;
124 struct drm_encoder
*encoder
;
125 int i
, panel
= -ENODEV
;
127 /* eDP panels need powering on by us (if the VBIOS doesn't default it
128 * to on) before doing any AUX channel transactions. LVDS panel power
129 * is handled by the SOR itself, and not required for LVDS DDC.
131 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
132 panel
= nvkm_gpio_get(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff);
134 nvkm_gpio_set(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff, 1);
139 for (i
= 0; nv_encoder
= NULL
, i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
140 int id
= connector
->encoder_ids
[i
];
144 encoder
= drm_encoder_find(dev
, id
);
147 nv_encoder
= nouveau_encoder(encoder
);
149 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
) {
150 int ret
= nouveau_dp_detect(nv_encoder
);
154 if (nv_encoder
->i2c
) {
155 if (nvkm_probe_i2c(nv_encoder
->i2c
, 0x50))
160 /* eDP panel not detected, restore panel power GPIO to previous
161 * state to avoid confusing the SOR for other output types.
163 if (!nv_encoder
&& panel
== 0)
164 nvkm_gpio_set(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff, panel
);
169 static struct nouveau_encoder
*
170 nouveau_connector_of_detect(struct drm_connector
*connector
)
173 struct drm_device
*dev
= connector
->dev
;
174 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
175 struct nouveau_encoder
*nv_encoder
;
176 struct device_node
*cn
, *dn
= pci_device_to_OF_node(dev
->pdev
);
179 !((nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TMDS
)) ||
180 (nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
))))
183 for_each_child_of_node(dn
, cn
) {
184 const char *name
= of_get_property(cn
, "name", NULL
);
185 const void *edid
= of_get_property(cn
, "EDID", NULL
);
186 int idx
= name
? name
[strlen(name
) - 1] - 'A' : 0;
188 if (nv_encoder
->dcb
->i2c_index
== idx
&& edid
) {
190 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
200 nouveau_connector_set_encoder(struct drm_connector
*connector
,
201 struct nouveau_encoder
*nv_encoder
)
203 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
204 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
205 struct drm_device
*dev
= connector
->dev
;
207 if (nv_connector
->detected_encoder
== nv_encoder
)
209 nv_connector
->detected_encoder
= nv_encoder
;
211 if (drm
->device
.info
.family
>= NV_DEVICE_INFO_V0_TESLA
) {
212 connector
->interlace_allowed
= true;
213 connector
->doublescan_allowed
= true;
215 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
||
216 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
) {
217 connector
->doublescan_allowed
= false;
218 connector
->interlace_allowed
= false;
220 connector
->doublescan_allowed
= true;
221 if (drm
->device
.info
.family
== NV_DEVICE_INFO_V0_KELVIN
||
222 (drm
->device
.info
.family
== NV_DEVICE_INFO_V0_CELSIUS
&&
223 (dev
->pdev
->device
& 0x0ff0) != 0x0100 &&
224 (dev
->pdev
->device
& 0x0ff0) != 0x0150))
226 connector
->interlace_allowed
= false;
228 connector
->interlace_allowed
= true;
231 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
232 drm_object_property_set_value(&connector
->base
,
233 dev
->mode_config
.dvi_i_subconnector_property
,
234 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
?
235 DRM_MODE_SUBCONNECTOR_DVID
:
236 DRM_MODE_SUBCONNECTOR_DVIA
);
240 static enum drm_connector_status
241 nouveau_connector_detect(struct drm_connector
*connector
, bool force
)
243 struct drm_device
*dev
= connector
->dev
;
244 struct nouveau_drm
*drm
= nouveau_drm(dev
);
245 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
246 struct nouveau_encoder
*nv_encoder
= NULL
;
247 struct nouveau_encoder
*nv_partner
;
248 struct i2c_adapter
*i2c
;
251 enum drm_connector_status conn_status
= connector_status_disconnected
;
253 /* Cleanup the previous EDID block. */
254 if (nv_connector
->edid
) {
255 drm_mode_connector_update_edid_property(connector
, NULL
);
256 kfree(nv_connector
->edid
);
257 nv_connector
->edid
= NULL
;
260 ret
= pm_runtime_get_sync(connector
->dev
->dev
);
261 if (ret
< 0 && ret
!= -EACCES
)
264 nv_encoder
= nouveau_connector_ddc_detect(connector
);
265 if (nv_encoder
&& (i2c
= nv_encoder
->i2c
) != NULL
) {
266 nv_connector
->edid
= drm_get_edid(connector
, i2c
);
267 drm_mode_connector_update_edid_property(connector
,
269 if (!nv_connector
->edid
) {
270 NV_ERROR(drm
, "DDC responded, but no EDID for %s\n",
275 /* Override encoder type for DVI-I based on whether EDID
276 * says the display is digital or analog, both use the
277 * same i2c channel so the value returned from ddc_detect
278 * isn't necessarily correct.
281 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
)
282 nv_partner
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
283 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
)
284 nv_partner
= find_encoder(connector
, DCB_OUTPUT_TMDS
);
286 if (nv_partner
&& ((nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
&&
287 nv_partner
->dcb
->type
== DCB_OUTPUT_TMDS
) ||
288 (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
&&
289 nv_partner
->dcb
->type
== DCB_OUTPUT_ANALOG
))) {
290 if (nv_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
)
291 type
= DCB_OUTPUT_TMDS
;
293 type
= DCB_OUTPUT_ANALOG
;
295 nv_encoder
= find_encoder(connector
, type
);
298 nouveau_connector_set_encoder(connector
, nv_encoder
);
299 conn_status
= connector_status_connected
;
303 nv_encoder
= nouveau_connector_of_detect(connector
);
305 nouveau_connector_set_encoder(connector
, nv_encoder
);
306 conn_status
= connector_status_connected
;
311 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
312 if (!nv_encoder
&& !nouveau_tv_disable
)
313 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TV
);
314 if (nv_encoder
&& force
) {
315 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
316 const struct drm_encoder_helper_funcs
*helper
=
317 encoder
->helper_private
;
319 if (helper
->detect(encoder
, connector
) ==
320 connector_status_connected
) {
321 nouveau_connector_set_encoder(connector
, nv_encoder
);
322 conn_status
= connector_status_connected
;
330 pm_runtime_mark_last_busy(connector
->dev
->dev
);
331 pm_runtime_put_autosuspend(connector
->dev
->dev
);
336 static enum drm_connector_status
337 nouveau_connector_detect_lvds(struct drm_connector
*connector
, bool force
)
339 struct drm_device
*dev
= connector
->dev
;
340 struct nouveau_drm
*drm
= nouveau_drm(dev
);
341 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
342 struct nouveau_encoder
*nv_encoder
= NULL
;
343 enum drm_connector_status status
= connector_status_disconnected
;
345 /* Cleanup the previous EDID block. */
346 if (nv_connector
->edid
) {
347 drm_mode_connector_update_edid_property(connector
, NULL
);
348 kfree(nv_connector
->edid
);
349 nv_connector
->edid
= NULL
;
352 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_LVDS
);
354 return connector_status_disconnected
;
356 /* Try retrieving EDID via DDC */
357 if (!drm
->vbios
.fp_no_ddc
) {
358 status
= nouveau_connector_detect(connector
, force
);
359 if (status
== connector_status_connected
)
363 /* On some laptops (Sony, i'm looking at you) there appears to
364 * be no direct way of accessing the panel's EDID. The only
365 * option available to us appears to be to ask ACPI for help..
367 * It's important this check's before trying straps, one of the
368 * said manufacturer's laptops are configured in such a way
369 * the nouveau decides an entry in the VBIOS FP mode table is
370 * valid - it's not (rh#613284)
372 if (nv_encoder
->dcb
->lvdsconf
.use_acpi_for_edid
) {
373 if ((nv_connector
->edid
= nouveau_acpi_edid(dev
, connector
))) {
374 status
= connector_status_connected
;
379 /* If no EDID found above, and the VBIOS indicates a hardcoded
380 * modeline is avalilable for the panel, set it as the panel's
381 * native mode and exit.
383 if (nouveau_bios_fp_mode(dev
, NULL
) && (drm
->vbios
.fp_no_ddc
||
384 nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
)) {
385 status
= connector_status_connected
;
389 /* Still nothing, some VBIOS images have a hardcoded EDID block
390 * stored for the panel stored in them.
392 if (!drm
->vbios
.fp_no_ddc
) {
394 (struct edid
*)nouveau_bios_embedded_edid(dev
);
397 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
398 if (nv_connector
->edid
)
399 status
= connector_status_connected
;
404 #if defined(CONFIG_ACPI_BUTTON) || \
405 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
406 if (status
== connector_status_connected
&&
407 !nouveau_ignorelid
&& !acpi_lid_open())
408 status
= connector_status_unknown
;
411 drm_mode_connector_update_edid_property(connector
, nv_connector
->edid
);
412 nouveau_connector_set_encoder(connector
, nv_encoder
);
417 nouveau_connector_force(struct drm_connector
*connector
)
419 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
420 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
421 struct nouveau_encoder
*nv_encoder
;
424 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
425 if (connector
->force
== DRM_FORCE_ON_DIGITAL
)
426 type
= DCB_OUTPUT_TMDS
;
428 type
= DCB_OUTPUT_ANALOG
;
430 type
= DCB_OUTPUT_ANY
;
432 nv_encoder
= find_encoder(connector
, type
);
434 NV_ERROR(drm
, "can't find encoder to force %s on!\n",
436 connector
->status
= connector_status_disconnected
;
440 nouveau_connector_set_encoder(connector
, nv_encoder
);
444 nouveau_connector_set_property(struct drm_connector
*connector
,
445 struct drm_property
*property
, uint64_t value
)
447 struct nouveau_display
*disp
= nouveau_display(connector
->dev
);
448 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
449 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
450 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
451 struct drm_device
*dev
= connector
->dev
;
452 struct nouveau_crtc
*nv_crtc
;
456 if (connector
->encoder
&& connector
->encoder
->crtc
)
457 nv_crtc
= nouveau_crtc(connector
->encoder
->crtc
);
460 if (property
== dev
->mode_config
.scaling_mode_property
) {
461 bool modeset
= false;
464 case DRM_MODE_SCALE_NONE
:
465 /* We allow 'None' for EDID modes, even on a fixed
466 * panel (some exist with support for lower refresh
467 * rates, which people might want to use for power
470 * Non-EDID modes will force the use of GPU scaling
471 * to the native mode regardless of this setting.
473 switch (nv_connector
->type
) {
474 case DCB_CONNECTOR_LVDS
:
475 case DCB_CONNECTOR_LVDS_SPWG
:
476 case DCB_CONNECTOR_eDP
:
477 /* ... except prior to G80, where the code
478 * doesn't support such things.
480 if (disp
->disp
.oclass
< NV50_DISP
)
487 case DRM_MODE_SCALE_FULLSCREEN
:
488 case DRM_MODE_SCALE_CENTER
:
489 case DRM_MODE_SCALE_ASPECT
:
495 /* Changing between GPU and panel scaling requires a full
498 if ((nv_connector
->scaling_mode
== DRM_MODE_SCALE_NONE
) ||
499 (value
== DRM_MODE_SCALE_NONE
))
501 nv_connector
->scaling_mode
= value
;
506 if (modeset
|| !nv_crtc
->set_scale
) {
507 ret
= drm_crtc_helper_set_mode(&nv_crtc
->base
,
510 nv_crtc
->base
.y
, NULL
);
514 ret
= nv_crtc
->set_scale(nv_crtc
, true);
523 if (property
== disp
->underscan_property
) {
524 if (nv_connector
->underscan
!= value
) {
525 nv_connector
->underscan
= value
;
526 if (!nv_crtc
|| !nv_crtc
->set_scale
)
529 return nv_crtc
->set_scale(nv_crtc
, true);
535 if (property
== disp
->underscan_hborder_property
) {
536 if (nv_connector
->underscan_hborder
!= value
) {
537 nv_connector
->underscan_hborder
= value
;
538 if (!nv_crtc
|| !nv_crtc
->set_scale
)
541 return nv_crtc
->set_scale(nv_crtc
, true);
547 if (property
== disp
->underscan_vborder_property
) {
548 if (nv_connector
->underscan_vborder
!= value
) {
549 nv_connector
->underscan_vborder
= value
;
550 if (!nv_crtc
|| !nv_crtc
->set_scale
)
553 return nv_crtc
->set_scale(nv_crtc
, true);
560 if (property
== disp
->dithering_mode
) {
561 nv_connector
->dithering_mode
= value
;
562 if (!nv_crtc
|| !nv_crtc
->set_dither
)
565 return nv_crtc
->set_dither(nv_crtc
, true);
568 if (property
== disp
->dithering_depth
) {
569 nv_connector
->dithering_depth
= value
;
570 if (!nv_crtc
|| !nv_crtc
->set_dither
)
573 return nv_crtc
->set_dither(nv_crtc
, true);
576 if (nv_crtc
&& nv_crtc
->set_color_vibrance
) {
578 if (property
== disp
->vibrant_hue_property
) {
579 nv_crtc
->vibrant_hue
= value
- 90;
580 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
583 if (property
== disp
->color_vibrance_property
) {
584 nv_crtc
->color_vibrance
= value
- 100;
585 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
589 if (nv_encoder
&& nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
590 return get_slave_funcs(encoder
)->set_property(
591 encoder
, connector
, property
, value
);
596 static struct drm_display_mode
*
597 nouveau_connector_native_mode(struct drm_connector
*connector
)
599 const struct drm_connector_helper_funcs
*helper
= connector
->helper_private
;
600 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
601 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
602 struct drm_device
*dev
= connector
->dev
;
603 struct drm_display_mode
*mode
, *largest
= NULL
;
604 int high_w
= 0, high_h
= 0, high_v
= 0;
606 list_for_each_entry(mode
, &nv_connector
->base
.probed_modes
, head
) {
607 mode
->vrefresh
= drm_mode_vrefresh(mode
);
608 if (helper
->mode_valid(connector
, mode
) != MODE_OK
||
609 (mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
612 /* Use preferred mode if there is one.. */
613 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
) {
614 NV_DEBUG(drm
, "native mode from preferred\n");
615 return drm_mode_duplicate(dev
, mode
);
618 /* Otherwise, take the resolution with the largest width, then
619 * height, then vertical refresh
621 if (mode
->hdisplay
< high_w
)
624 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
< high_h
)
627 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
== high_h
&&
628 mode
->vrefresh
< high_v
)
631 high_w
= mode
->hdisplay
;
632 high_h
= mode
->vdisplay
;
633 high_v
= mode
->vrefresh
;
637 NV_DEBUG(drm
, "native mode from largest: %dx%d@%d\n",
638 high_w
, high_h
, high_v
);
639 return largest
? drm_mode_duplicate(dev
, largest
) : NULL
;
647 static struct moderec scaler_modes
[] = {
666 nouveau_connector_scaler_modes_add(struct drm_connector
*connector
)
668 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
669 struct drm_display_mode
*native
= nv_connector
->native_mode
, *m
;
670 struct drm_device
*dev
= connector
->dev
;
671 struct moderec
*mode
= &scaler_modes
[0];
677 while (mode
->hdisplay
) {
678 if (mode
->hdisplay
<= native
->hdisplay
&&
679 mode
->vdisplay
<= native
->vdisplay
&&
680 (mode
->hdisplay
!= native
->hdisplay
||
681 mode
->vdisplay
!= native
->vdisplay
)) {
682 m
= drm_cvt_mode(dev
, mode
->hdisplay
, mode
->vdisplay
,
683 drm_mode_vrefresh(native
), false,
688 drm_mode_probed_add(connector
, m
);
699 nouveau_connector_detect_depth(struct drm_connector
*connector
)
701 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
702 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
703 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
704 struct nvbios
*bios
= &drm
->vbios
;
705 struct drm_display_mode
*mode
= nv_connector
->native_mode
;
708 /* if the edid is feeling nice enough to provide this info, use it */
709 if (nv_connector
->edid
&& connector
->display_info
.bpc
)
712 /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
713 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
714 connector
->display_info
.bpc
= 6;
718 /* we're out of options unless we're LVDS, default to 8bpc */
719 if (nv_encoder
->dcb
->type
!= DCB_OUTPUT_LVDS
) {
720 connector
->display_info
.bpc
= 8;
724 connector
->display_info
.bpc
= 6;
726 /* LVDS: panel straps */
727 if (bios
->fp_no_ddc
) {
728 if (bios
->fp
.if_is_24bit
)
729 connector
->display_info
.bpc
= 8;
733 /* LVDS: DDC panel, need to first determine the number of links to
734 * know which if_is_24bit flag to check...
736 if (nv_connector
->edid
&&
737 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
)
738 duallink
= ((u8
*)nv_connector
->edid
)[121] == 2;
740 duallink
= mode
->clock
>= bios
->fp
.duallink_transition_clk
;
742 if ((!duallink
&& (bios
->fp
.strapless_is_24bit
& 1)) ||
743 ( duallink
&& (bios
->fp
.strapless_is_24bit
& 2)))
744 connector
->display_info
.bpc
= 8;
748 nouveau_connector_get_modes(struct drm_connector
*connector
)
750 struct drm_device
*dev
= connector
->dev
;
751 struct nouveau_drm
*drm
= nouveau_drm(dev
);
752 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
753 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
754 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
757 /* destroy the native mode, the attached monitor could have changed.
759 if (nv_connector
->native_mode
) {
760 drm_mode_destroy(dev
, nv_connector
->native_mode
);
761 nv_connector
->native_mode
= NULL
;
764 if (nv_connector
->edid
)
765 ret
= drm_add_edid_modes(connector
, nv_connector
->edid
);
767 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
&&
768 (nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
||
769 drm
->vbios
.fp_no_ddc
) && nouveau_bios_fp_mode(dev
, NULL
)) {
770 struct drm_display_mode mode
;
772 nouveau_bios_fp_mode(dev
, &mode
);
773 nv_connector
->native_mode
= drm_mode_duplicate(dev
, &mode
);
776 /* Determine display colour depth for everything except LVDS now,
777 * DP requires this before mode_valid() is called.
779 if (connector
->connector_type
!= DRM_MODE_CONNECTOR_LVDS
)
780 nouveau_connector_detect_depth(connector
);
782 /* Find the native mode if this is a digital panel, if we didn't
783 * find any modes through DDC previously add the native mode to
786 if (!nv_connector
->native_mode
)
787 nv_connector
->native_mode
=
788 nouveau_connector_native_mode(connector
);
789 if (ret
== 0 && nv_connector
->native_mode
) {
790 struct drm_display_mode
*mode
;
792 mode
= drm_mode_duplicate(dev
, nv_connector
->native_mode
);
793 drm_mode_probed_add(connector
, mode
);
797 /* Determine LVDS colour depth, must happen after determining
798 * "native" mode as some VBIOS tables require us to use the
799 * pixel clock as part of the lookup...
801 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
)
802 nouveau_connector_detect_depth(connector
);
804 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
805 ret
= get_slave_funcs(encoder
)->get_modes(encoder
, connector
);
807 if (nv_connector
->type
== DCB_CONNECTOR_LVDS
||
808 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
||
809 nv_connector
->type
== DCB_CONNECTOR_eDP
)
810 ret
+= nouveau_connector_scaler_modes_add(connector
);
816 get_tmds_link_bandwidth(struct drm_connector
*connector
, bool hdmi
)
818 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
819 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
820 struct dcb_output
*dcb
= nv_connector
->detected_encoder
->dcb
;
823 if (nouveau_hdmimhz
> 0)
824 return nouveau_hdmimhz
* 1000;
825 /* Note: these limits are conservative, some Fermi's
826 * can do 297 MHz. Unclear how this can be determined.
828 if (drm
->device
.info
.family
>= NV_DEVICE_INFO_V0_KEPLER
)
830 if (drm
->device
.info
.family
>= NV_DEVICE_INFO_V0_FERMI
)
833 if (dcb
->location
!= DCB_LOC_ON_CHIP
||
834 drm
->device
.info
.chipset
>= 0x46)
836 else if (drm
->device
.info
.chipset
>= 0x40)
838 else if (drm
->device
.info
.chipset
>= 0x18)
845 nouveau_connector_mode_valid(struct drm_connector
*connector
,
846 struct drm_display_mode
*mode
)
848 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
849 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
850 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
851 unsigned min_clock
= 25000, max_clock
= min_clock
;
852 unsigned clock
= mode
->clock
;
855 switch (nv_encoder
->dcb
->type
) {
856 case DCB_OUTPUT_LVDS
:
857 if (nv_connector
->native_mode
&&
858 (mode
->hdisplay
> nv_connector
->native_mode
->hdisplay
||
859 mode
->vdisplay
> nv_connector
->native_mode
->vdisplay
))
865 case DCB_OUTPUT_TMDS
:
866 hdmi
= drm_detect_hdmi_monitor(nv_connector
->edid
);
867 max_clock
= get_tmds_link_bandwidth(connector
, hdmi
);
868 if (!hdmi
&& nouveau_duallink
&&
869 nv_encoder
->dcb
->duallink_possible
)
872 case DCB_OUTPUT_ANALOG
:
873 max_clock
= nv_encoder
->dcb
->crtconf
.maxfreq
;
878 return get_slave_funcs(encoder
)->mode_valid(encoder
, mode
);
880 max_clock
= nv_encoder
->dp
.link_nr
;
881 max_clock
*= nv_encoder
->dp
.link_bw
;
882 clock
= clock
* (connector
->display_info
.bpc
* 3) / 10;
889 if (clock
< min_clock
)
890 return MODE_CLOCK_LOW
;
892 if (clock
> max_clock
)
893 return MODE_CLOCK_HIGH
;
898 static struct drm_encoder
*
899 nouveau_connector_best_encoder(struct drm_connector
*connector
)
901 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
903 if (nv_connector
->detected_encoder
)
904 return to_drm_encoder(nv_connector
->detected_encoder
);
909 static const struct drm_connector_helper_funcs
910 nouveau_connector_helper_funcs
= {
911 .get_modes
= nouveau_connector_get_modes
,
912 .mode_valid
= nouveau_connector_mode_valid
,
913 .best_encoder
= nouveau_connector_best_encoder
,
916 static const struct drm_connector_funcs
917 nouveau_connector_funcs
= {
918 .dpms
= drm_helper_connector_dpms
,
919 .detect
= nouveau_connector_detect
,
920 .destroy
= nouveau_connector_destroy
,
921 .fill_modes
= drm_helper_probe_single_connector_modes
,
922 .set_property
= nouveau_connector_set_property
,
923 .force
= nouveau_connector_force
926 static const struct drm_connector_funcs
927 nouveau_connector_funcs_lvds
= {
928 .dpms
= drm_helper_connector_dpms
,
929 .detect
= nouveau_connector_detect_lvds
,
930 .destroy
= nouveau_connector_destroy
,
931 .fill_modes
= drm_helper_probe_single_connector_modes
,
932 .set_property
= nouveau_connector_set_property
,
933 .force
= nouveau_connector_force
937 nouveau_connector_dp_dpms(struct drm_connector
*connector
, int mode
)
939 struct nouveau_encoder
*nv_encoder
= NULL
;
941 if (connector
->encoder
)
942 nv_encoder
= nouveau_encoder(connector
->encoder
);
943 if (nv_encoder
&& nv_encoder
->dcb
&&
944 nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
) {
945 if (mode
== DRM_MODE_DPMS_ON
) {
946 u8 data
= DP_SET_POWER_D0
;
947 nvkm_wraux(nv_encoder
->aux
, DP_SET_POWER
, &data
, 1);
948 usleep_range(1000, 2000);
950 u8 data
= DP_SET_POWER_D3
;
951 nvkm_wraux(nv_encoder
->aux
, DP_SET_POWER
, &data
, 1);
955 return drm_helper_connector_dpms(connector
, mode
);
958 static const struct drm_connector_funcs
959 nouveau_connector_funcs_dp
= {
960 .dpms
= nouveau_connector_dp_dpms
,
961 .detect
= nouveau_connector_detect
,
962 .destroy
= nouveau_connector_destroy
,
963 .fill_modes
= drm_helper_probe_single_connector_modes
,
964 .set_property
= nouveau_connector_set_property
,
965 .force
= nouveau_connector_force
969 nouveau_connector_hotplug(struct nvif_notify
*notify
)
971 struct nouveau_connector
*nv_connector
=
972 container_of(notify
, typeof(*nv_connector
), hpd
);
973 struct drm_connector
*connector
= &nv_connector
->base
;
974 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
975 const struct nvif_notify_conn_rep_v0
*rep
= notify
->data
;
976 const char *name
= connector
->name
;
978 if (rep
->mask
& NVIF_NOTIFY_CONN_V0_IRQ
) {
980 bool plugged
= (rep
->mask
!= NVIF_NOTIFY_CONN_V0_UNPLUG
);
982 NV_DEBUG(drm
, "%splugged %s\n", plugged
? "" : "un", name
);
985 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_ON
);
987 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
988 drm_helper_hpd_irq_event(connector
->dev
);
991 return NVIF_NOTIFY_KEEP
;
995 nouveau_connector_aux_xfer(struct drm_dp_aux
*obj
, struct drm_dp_aux_msg
*msg
)
997 struct nouveau_connector
*nv_connector
=
998 container_of(obj
, typeof(*nv_connector
), aux
);
999 struct nouveau_encoder
*nv_encoder
;
1000 struct nvkm_i2c_aux
*aux
;
1003 nv_encoder
= find_encoder(&nv_connector
->base
, DCB_OUTPUT_DP
);
1004 if (!nv_encoder
|| !(aux
= nv_encoder
->aux
))
1006 if (WARN_ON(msg
->size
> 16))
1011 ret
= nvkm_i2c_aux_acquire(aux
);
1015 ret
= nvkm_i2c_aux_xfer(aux
, false, msg
->request
, msg
->address
,
1016 msg
->buffer
, msg
->size
);
1017 nvkm_i2c_aux_release(aux
);
1027 drm_conntype_from_dcb(enum dcb_connector_type dcb
)
1030 case DCB_CONNECTOR_VGA
: return DRM_MODE_CONNECTOR_VGA
;
1031 case DCB_CONNECTOR_TV_0
:
1032 case DCB_CONNECTOR_TV_1
:
1033 case DCB_CONNECTOR_TV_3
: return DRM_MODE_CONNECTOR_TV
;
1034 case DCB_CONNECTOR_DMS59_0
:
1035 case DCB_CONNECTOR_DMS59_1
:
1036 case DCB_CONNECTOR_DVI_I
: return DRM_MODE_CONNECTOR_DVII
;
1037 case DCB_CONNECTOR_DVI_D
: return DRM_MODE_CONNECTOR_DVID
;
1038 case DCB_CONNECTOR_LVDS
:
1039 case DCB_CONNECTOR_LVDS_SPWG
: return DRM_MODE_CONNECTOR_LVDS
;
1040 case DCB_CONNECTOR_DMS59_DP0
:
1041 case DCB_CONNECTOR_DMS59_DP1
:
1042 case DCB_CONNECTOR_DP
: return DRM_MODE_CONNECTOR_DisplayPort
;
1043 case DCB_CONNECTOR_eDP
: return DRM_MODE_CONNECTOR_eDP
;
1044 case DCB_CONNECTOR_HDMI_0
:
1045 case DCB_CONNECTOR_HDMI_1
:
1046 case DCB_CONNECTOR_HDMI_C
: return DRM_MODE_CONNECTOR_HDMIA
;
1051 return DRM_MODE_CONNECTOR_Unknown
;
1054 struct drm_connector
*
1055 nouveau_connector_create(struct drm_device
*dev
, int index
)
1057 const struct drm_connector_funcs
*funcs
= &nouveau_connector_funcs
;
1058 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1059 struct nouveau_display
*disp
= nouveau_display(dev
);
1060 struct nouveau_connector
*nv_connector
= NULL
;
1061 struct drm_connector
*connector
;
1065 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1066 nv_connector
= nouveau_connector(connector
);
1067 if (nv_connector
->index
== index
)
1071 nv_connector
= kzalloc(sizeof(*nv_connector
), GFP_KERNEL
);
1073 return ERR_PTR(-ENOMEM
);
1075 connector
= &nv_connector
->base
;
1076 nv_connector
->index
= index
;
1078 /* attempt to parse vbios connector type and hotplug gpio */
1079 nv_connector
->dcb
= olddcb_conn(dev
, index
);
1080 if (nv_connector
->dcb
) {
1081 u32 entry
= ROM16(nv_connector
->dcb
[0]);
1082 if (olddcb_conntab(dev
)[3] >= 4)
1083 entry
|= (u32
)ROM16(nv_connector
->dcb
[2]) << 16;
1085 nv_connector
->type
= nv_connector
->dcb
[0];
1086 if (drm_conntype_from_dcb(nv_connector
->type
) ==
1087 DRM_MODE_CONNECTOR_Unknown
) {
1088 NV_WARN(drm
, "unknown connector type %02x\n",
1089 nv_connector
->type
);
1090 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1093 /* Gigabyte NX85T */
1094 if (nv_match_device(dev
, 0x0421, 0x1458, 0x344c)) {
1095 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1096 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1099 /* Gigabyte GV-NX86T512H */
1100 if (nv_match_device(dev
, 0x0402, 0x1458, 0x3455)) {
1101 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1102 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1105 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1108 /* no vbios data, or an unknown dcb connector type - attempt to
1109 * figure out something suitable ourselves
1111 if (nv_connector
->type
== DCB_CONNECTOR_NONE
) {
1112 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1113 struct dcb_table
*dcbt
= &drm
->vbios
.dcb
;
1117 for (i
= 0; i
< dcbt
->entries
; i
++) {
1118 if (dcbt
->entry
[i
].connector
== nv_connector
->index
)
1119 encoders
|= (1 << dcbt
->entry
[i
].type
);
1122 if (encoders
& (1 << DCB_OUTPUT_DP
)) {
1123 if (encoders
& (1 << DCB_OUTPUT_TMDS
))
1124 nv_connector
->type
= DCB_CONNECTOR_DP
;
1126 nv_connector
->type
= DCB_CONNECTOR_eDP
;
1128 if (encoders
& (1 << DCB_OUTPUT_TMDS
)) {
1129 if (encoders
& (1 << DCB_OUTPUT_ANALOG
))
1130 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1132 nv_connector
->type
= DCB_CONNECTOR_DVI_D
;
1134 if (encoders
& (1 << DCB_OUTPUT_ANALOG
)) {
1135 nv_connector
->type
= DCB_CONNECTOR_VGA
;
1137 if (encoders
& (1 << DCB_OUTPUT_LVDS
)) {
1138 nv_connector
->type
= DCB_CONNECTOR_LVDS
;
1140 if (encoders
& (1 << DCB_OUTPUT_TV
)) {
1141 nv_connector
->type
= DCB_CONNECTOR_TV_0
;
1145 switch ((type
= drm_conntype_from_dcb(nv_connector
->type
))) {
1146 case DRM_MODE_CONNECTOR_LVDS
:
1147 ret
= nouveau_bios_parse_lvds_table(dev
, 0, &dummy
, &dummy
);
1149 NV_ERROR(drm
, "Error parsing LVDS table, disabling\n");
1150 kfree(nv_connector
);
1151 return ERR_PTR(ret
);
1154 funcs
= &nouveau_connector_funcs_lvds
;
1156 case DRM_MODE_CONNECTOR_DisplayPort
:
1157 case DRM_MODE_CONNECTOR_eDP
:
1158 nv_connector
->aux
.dev
= dev
->dev
;
1159 nv_connector
->aux
.transfer
= nouveau_connector_aux_xfer
;
1160 ret
= drm_dp_aux_register(&nv_connector
->aux
);
1162 NV_ERROR(drm
, "failed to register aux channel\n");
1163 kfree(nv_connector
);
1164 return ERR_PTR(ret
);
1167 funcs
= &nouveau_connector_funcs_dp
;
1170 funcs
= &nouveau_connector_funcs
;
1174 /* defaults, will get overridden in detect() */
1175 connector
->interlace_allowed
= false;
1176 connector
->doublescan_allowed
= false;
1178 drm_connector_init(dev
, connector
, funcs
, type
);
1179 drm_connector_helper_add(connector
, &nouveau_connector_helper_funcs
);
1181 /* Init DVI-I specific properties */
1182 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
)
1183 drm_object_attach_property(&connector
->base
, dev
->mode_config
.dvi_i_subconnector_property
, 0);
1185 /* Add overscan compensation options to digital outputs */
1186 if (disp
->underscan_property
&&
1187 (type
== DRM_MODE_CONNECTOR_DVID
||
1188 type
== DRM_MODE_CONNECTOR_DVII
||
1189 type
== DRM_MODE_CONNECTOR_HDMIA
||
1190 type
== DRM_MODE_CONNECTOR_DisplayPort
)) {
1191 drm_object_attach_property(&connector
->base
,
1192 disp
->underscan_property
,
1194 drm_object_attach_property(&connector
->base
,
1195 disp
->underscan_hborder_property
,
1197 drm_object_attach_property(&connector
->base
,
1198 disp
->underscan_vborder_property
,
1202 /* Add hue and saturation options */
1203 if (disp
->vibrant_hue_property
)
1204 drm_object_attach_property(&connector
->base
,
1205 disp
->vibrant_hue_property
,
1207 if (disp
->color_vibrance_property
)
1208 drm_object_attach_property(&connector
->base
,
1209 disp
->color_vibrance_property
,
1212 /* default scaling mode */
1213 switch (nv_connector
->type
) {
1214 case DCB_CONNECTOR_LVDS
:
1215 case DCB_CONNECTOR_LVDS_SPWG
:
1216 case DCB_CONNECTOR_eDP
:
1217 /* see note in nouveau_connector_set_property() */
1218 if (disp
->disp
.oclass
< NV50_DISP
) {
1219 nv_connector
->scaling_mode
= DRM_MODE_SCALE_FULLSCREEN
;
1222 nv_connector
->scaling_mode
= DRM_MODE_SCALE_NONE
;
1225 nv_connector
->scaling_mode
= DRM_MODE_SCALE_NONE
;
1229 /* scaling mode property */
1230 switch (nv_connector
->type
) {
1231 case DCB_CONNECTOR_TV_0
:
1232 case DCB_CONNECTOR_TV_1
:
1233 case DCB_CONNECTOR_TV_3
:
1235 case DCB_CONNECTOR_VGA
:
1236 if (disp
->disp
.oclass
< NV50_DISP
)
1237 break; /* can only scale on DFPs */
1240 drm_object_attach_property(&connector
->base
, dev
->mode_config
.
1241 scaling_mode_property
,
1242 nv_connector
->scaling_mode
);
1246 /* dithering properties */
1247 switch (nv_connector
->type
) {
1248 case DCB_CONNECTOR_TV_0
:
1249 case DCB_CONNECTOR_TV_1
:
1250 case DCB_CONNECTOR_TV_3
:
1251 case DCB_CONNECTOR_VGA
:
1254 if (disp
->dithering_mode
) {
1255 drm_object_attach_property(&connector
->base
,
1256 disp
->dithering_mode
,
1259 nv_connector
->dithering_mode
= DITHERING_MODE_AUTO
;
1261 if (disp
->dithering_depth
) {
1262 drm_object_attach_property(&connector
->base
,
1263 disp
->dithering_depth
,
1266 nv_connector
->dithering_depth
= DITHERING_DEPTH_AUTO
;
1271 ret
= nvif_notify_init(&disp
->disp
, nouveau_connector_hotplug
, true,
1272 NV04_DISP_NTFY_CONN
,
1273 &(struct nvif_notify_conn_req_v0
) {
1274 .mask
= NVIF_NOTIFY_CONN_V0_ANY
,
1277 sizeof(struct nvif_notify_conn_req_v0
),
1278 sizeof(struct nvif_notify_conn_rep_v0
),
1279 &nv_connector
->hpd
);
1281 connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
;
1283 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
1285 drm_connector_register(connector
);