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 <subdev/i2c.h>
46 #include <subdev/gpio.h>
47 #include <engine/disp.h>
49 MODULE_PARM_DESC(tv_disable
, "Disable TV-out detection");
50 static int nouveau_tv_disable
= 0;
51 module_param_named(tv_disable
, nouveau_tv_disable
, int, 0400);
53 MODULE_PARM_DESC(ignorelid
, "Ignore ACPI lid status");
54 static int nouveau_ignorelid
= 0;
55 module_param_named(ignorelid
, nouveau_ignorelid
, int, 0400);
57 MODULE_PARM_DESC(duallink
, "Allow dual-link TMDS (default: enabled)");
58 static int nouveau_duallink
= 1;
59 module_param_named(duallink
, nouveau_duallink
, int, 0400);
61 struct nouveau_encoder
*
62 find_encoder(struct drm_connector
*connector
, int type
)
64 struct drm_device
*dev
= connector
->dev
;
65 struct nouveau_encoder
*nv_encoder
;
66 struct drm_mode_object
*obj
;
69 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
70 id
= connector
->encoder_ids
[i
];
74 obj
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_ENCODER
);
77 nv_encoder
= nouveau_encoder(obj_to_encoder(obj
));
79 if (type
== DCB_OUTPUT_ANY
||
80 (nv_encoder
->dcb
&& nv_encoder
->dcb
->type
== type
))
87 struct nouveau_connector
*
88 nouveau_encoder_connector_get(struct nouveau_encoder
*encoder
)
90 struct drm_device
*dev
= to_drm_encoder(encoder
)->dev
;
91 struct drm_connector
*drm_connector
;
93 list_for_each_entry(drm_connector
, &dev
->mode_config
.connector_list
, head
) {
94 if (drm_connector
->encoder
== to_drm_encoder(encoder
))
95 return nouveau_connector(drm_connector
);
102 nouveau_connector_destroy(struct drm_connector
*connector
)
104 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
105 nouveau_event_ref(NULL
, &nv_connector
->hpd
);
106 kfree(nv_connector
->edid
);
107 drm_sysfs_connector_remove(connector
);
108 drm_connector_cleanup(connector
);
109 if (nv_connector
->aux
.transfer
)
110 drm_dp_aux_unregister(&nv_connector
->aux
);
114 static struct nouveau_encoder
*
115 nouveau_connector_ddc_detect(struct drm_connector
*connector
)
117 struct drm_device
*dev
= connector
->dev
;
118 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
119 struct nouveau_drm
*drm
= nouveau_drm(dev
);
120 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
121 struct nouveau_encoder
*nv_encoder
;
122 struct drm_mode_object
*obj
;
123 int i
, panel
= -ENODEV
;
125 /* eDP panels need powering on by us (if the VBIOS doesn't default it
126 * to on) before doing any AUX channel transactions. LVDS panel power
127 * is handled by the SOR itself, and not required for LVDS DDC.
129 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
130 panel
= gpio
->get(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff);
132 gpio
->set(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff, 1);
137 for (i
= 0; nv_encoder
= NULL
, i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
138 int id
= connector
->encoder_ids
[i
];
142 obj
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_ENCODER
);
145 nv_encoder
= nouveau_encoder(obj_to_encoder(obj
));
147 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
) {
148 int ret
= nouveau_dp_detect(nv_encoder
);
152 if (nv_encoder
->i2c
) {
153 if (nv_probe_i2c(nv_encoder
->i2c
, 0x50))
158 /* eDP panel not detected, restore panel power GPIO to previous
159 * state to avoid confusing the SOR for other output types.
161 if (!nv_encoder
&& panel
== 0)
162 gpio
->set(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff, panel
);
167 static struct nouveau_encoder
*
168 nouveau_connector_of_detect(struct drm_connector
*connector
)
171 struct drm_device
*dev
= connector
->dev
;
172 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
173 struct nouveau_encoder
*nv_encoder
;
174 struct device_node
*cn
, *dn
= pci_device_to_OF_node(dev
->pdev
);
177 !((nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TMDS
)) ||
178 (nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
))))
181 for_each_child_of_node(dn
, cn
) {
182 const char *name
= of_get_property(cn
, "name", NULL
);
183 const void *edid
= of_get_property(cn
, "EDID", NULL
);
184 int idx
= name
? name
[strlen(name
) - 1] - 'A' : 0;
186 if (nv_encoder
->dcb
->i2c_index
== idx
&& edid
) {
188 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
198 nouveau_connector_set_encoder(struct drm_connector
*connector
,
199 struct nouveau_encoder
*nv_encoder
)
201 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
202 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
203 struct drm_device
*dev
= connector
->dev
;
205 if (nv_connector
->detected_encoder
== nv_encoder
)
207 nv_connector
->detected_encoder
= nv_encoder
;
209 if (nv_device(drm
->device
)->card_type
>= NV_50
) {
210 connector
->interlace_allowed
= true;
211 connector
->doublescan_allowed
= true;
213 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
||
214 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
) {
215 connector
->doublescan_allowed
= false;
216 connector
->interlace_allowed
= false;
218 connector
->doublescan_allowed
= true;
219 if (nv_device(drm
->device
)->card_type
== NV_20
||
220 ((nv_device(drm
->device
)->card_type
== NV_10
||
221 nv_device(drm
->device
)->card_type
== NV_11
) &&
222 (dev
->pdev
->device
& 0x0ff0) != 0x0100 &&
223 (dev
->pdev
->device
& 0x0ff0) != 0x0150))
225 connector
->interlace_allowed
= false;
227 connector
->interlace_allowed
= true;
230 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
231 drm_object_property_set_value(&connector
->base
,
232 dev
->mode_config
.dvi_i_subconnector_property
,
233 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
?
234 DRM_MODE_SUBCONNECTOR_DVID
:
235 DRM_MODE_SUBCONNECTOR_DVIA
);
239 static enum drm_connector_status
240 nouveau_connector_detect(struct drm_connector
*connector
, bool force
)
242 struct drm_device
*dev
= connector
->dev
;
243 struct nouveau_drm
*drm
= nouveau_drm(dev
);
244 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
245 struct nouveau_encoder
*nv_encoder
= NULL
;
246 struct nouveau_encoder
*nv_partner
;
247 struct nouveau_i2c_port
*i2c
;
250 enum drm_connector_status conn_status
= connector_status_disconnected
;
252 /* Cleanup the previous EDID block. */
253 if (nv_connector
->edid
) {
254 drm_mode_connector_update_edid_property(connector
, NULL
);
255 kfree(nv_connector
->edid
);
256 nv_connector
->edid
= NULL
;
259 ret
= pm_runtime_get_sync(connector
->dev
->dev
);
260 if (ret
< 0 && ret
!= -EACCES
)
263 nv_encoder
= nouveau_connector_ddc_detect(connector
);
264 if (nv_encoder
&& (i2c
= nv_encoder
->i2c
) != NULL
) {
265 nv_connector
->edid
= drm_get_edid(connector
, &i2c
->adapter
);
266 drm_mode_connector_update_edid_property(connector
,
268 if (!nv_connector
->edid
) {
269 NV_ERROR(drm
, "DDC responded, but no EDID for %s\n",
274 /* Override encoder type for DVI-I based on whether EDID
275 * says the display is digital or analog, both use the
276 * same i2c channel so the value returned from ddc_detect
277 * isn't necessarily correct.
280 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
)
281 nv_partner
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
282 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
)
283 nv_partner
= find_encoder(connector
, DCB_OUTPUT_TMDS
);
285 if (nv_partner
&& ((nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
&&
286 nv_partner
->dcb
->type
== DCB_OUTPUT_TMDS
) ||
287 (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
&&
288 nv_partner
->dcb
->type
== DCB_OUTPUT_ANALOG
))) {
289 if (nv_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
)
290 type
= DCB_OUTPUT_TMDS
;
292 type
= DCB_OUTPUT_ANALOG
;
294 nv_encoder
= find_encoder(connector
, type
);
297 nouveau_connector_set_encoder(connector
, nv_encoder
);
298 conn_status
= connector_status_connected
;
302 nv_encoder
= nouveau_connector_of_detect(connector
);
304 nouveau_connector_set_encoder(connector
, nv_encoder
);
305 conn_status
= connector_status_connected
;
310 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
311 if (!nv_encoder
&& !nouveau_tv_disable
)
312 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TV
);
313 if (nv_encoder
&& force
) {
314 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
315 struct drm_encoder_helper_funcs
*helper
=
316 encoder
->helper_private
;
318 if (helper
->detect(encoder
, connector
) ==
319 connector_status_connected
) {
320 nouveau_connector_set_encoder(connector
, nv_encoder
);
321 conn_status
= connector_status_connected
;
329 pm_runtime_mark_last_busy(connector
->dev
->dev
);
330 pm_runtime_put_autosuspend(connector
->dev
->dev
);
335 static enum drm_connector_status
336 nouveau_connector_detect_lvds(struct drm_connector
*connector
, bool force
)
338 struct drm_device
*dev
= connector
->dev
;
339 struct nouveau_drm
*drm
= nouveau_drm(dev
);
340 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
341 struct nouveau_encoder
*nv_encoder
= NULL
;
342 enum drm_connector_status status
= connector_status_disconnected
;
344 /* Cleanup the previous EDID block. */
345 if (nv_connector
->edid
) {
346 drm_mode_connector_update_edid_property(connector
, NULL
);
347 kfree(nv_connector
->edid
);
348 nv_connector
->edid
= NULL
;
351 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_LVDS
);
353 return connector_status_disconnected
;
355 /* Try retrieving EDID via DDC */
356 if (!drm
->vbios
.fp_no_ddc
) {
357 status
= nouveau_connector_detect(connector
, force
);
358 if (status
== connector_status_connected
)
362 /* On some laptops (Sony, i'm looking at you) there appears to
363 * be no direct way of accessing the panel's EDID. The only
364 * option available to us appears to be to ask ACPI for help..
366 * It's important this check's before trying straps, one of the
367 * said manufacturer's laptops are configured in such a way
368 * the nouveau decides an entry in the VBIOS FP mode table is
369 * valid - it's not (rh#613284)
371 if (nv_encoder
->dcb
->lvdsconf
.use_acpi_for_edid
) {
372 if ((nv_connector
->edid
= nouveau_acpi_edid(dev
, connector
))) {
373 status
= connector_status_connected
;
378 /* If no EDID found above, and the VBIOS indicates a hardcoded
379 * modeline is avalilable for the panel, set it as the panel's
380 * native mode and exit.
382 if (nouveau_bios_fp_mode(dev
, NULL
) && (drm
->vbios
.fp_no_ddc
||
383 nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
)) {
384 status
= connector_status_connected
;
388 /* Still nothing, some VBIOS images have a hardcoded EDID block
389 * stored for the panel stored in them.
391 if (!drm
->vbios
.fp_no_ddc
) {
393 (struct edid
*)nouveau_bios_embedded_edid(dev
);
396 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
397 if (nv_connector
->edid
)
398 status
= connector_status_connected
;
403 #if defined(CONFIG_ACPI_BUTTON) || \
404 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
405 if (status
== connector_status_connected
&&
406 !nouveau_ignorelid
&& !acpi_lid_open())
407 status
= connector_status_unknown
;
410 drm_mode_connector_update_edid_property(connector
, nv_connector
->edid
);
411 nouveau_connector_set_encoder(connector
, nv_encoder
);
416 nouveau_connector_force(struct drm_connector
*connector
)
418 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
419 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
420 struct nouveau_encoder
*nv_encoder
;
423 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
424 if (connector
->force
== DRM_FORCE_ON_DIGITAL
)
425 type
= DCB_OUTPUT_TMDS
;
427 type
= DCB_OUTPUT_ANALOG
;
429 type
= DCB_OUTPUT_ANY
;
431 nv_encoder
= find_encoder(connector
, type
);
433 NV_ERROR(drm
, "can't find encoder to force %s on!\n",
435 connector
->status
= connector_status_disconnected
;
439 nouveau_connector_set_encoder(connector
, nv_encoder
);
443 nouveau_connector_set_property(struct drm_connector
*connector
,
444 struct drm_property
*property
, uint64_t value
)
446 struct nouveau_display
*disp
= nouveau_display(connector
->dev
);
447 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
448 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
449 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
450 struct drm_device
*dev
= connector
->dev
;
451 struct nouveau_crtc
*nv_crtc
;
455 if (connector
->encoder
&& connector
->encoder
->crtc
)
456 nv_crtc
= nouveau_crtc(connector
->encoder
->crtc
);
459 if (property
== dev
->mode_config
.scaling_mode_property
) {
460 bool modeset
= false;
463 case DRM_MODE_SCALE_NONE
:
464 case DRM_MODE_SCALE_FULLSCREEN
:
465 case DRM_MODE_SCALE_CENTER
:
466 case DRM_MODE_SCALE_ASPECT
:
472 /* LVDS always needs gpu scaling */
473 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
&&
474 value
== DRM_MODE_SCALE_NONE
)
477 /* Changing between GPU and panel scaling requires a full
480 if ((nv_connector
->scaling_mode
== DRM_MODE_SCALE_NONE
) ||
481 (value
== DRM_MODE_SCALE_NONE
))
483 nv_connector
->scaling_mode
= value
;
488 if (modeset
|| !nv_crtc
->set_scale
) {
489 ret
= drm_crtc_helper_set_mode(&nv_crtc
->base
,
492 nv_crtc
->base
.y
, NULL
);
496 ret
= nv_crtc
->set_scale(nv_crtc
, true);
505 if (property
== disp
->underscan_property
) {
506 if (nv_connector
->underscan
!= value
) {
507 nv_connector
->underscan
= value
;
508 if (!nv_crtc
|| !nv_crtc
->set_scale
)
511 return nv_crtc
->set_scale(nv_crtc
, true);
517 if (property
== disp
->underscan_hborder_property
) {
518 if (nv_connector
->underscan_hborder
!= value
) {
519 nv_connector
->underscan_hborder
= value
;
520 if (!nv_crtc
|| !nv_crtc
->set_scale
)
523 return nv_crtc
->set_scale(nv_crtc
, true);
529 if (property
== disp
->underscan_vborder_property
) {
530 if (nv_connector
->underscan_vborder
!= value
) {
531 nv_connector
->underscan_vborder
= value
;
532 if (!nv_crtc
|| !nv_crtc
->set_scale
)
535 return nv_crtc
->set_scale(nv_crtc
, true);
542 if (property
== disp
->dithering_mode
) {
543 nv_connector
->dithering_mode
= value
;
544 if (!nv_crtc
|| !nv_crtc
->set_dither
)
547 return nv_crtc
->set_dither(nv_crtc
, true);
550 if (property
== disp
->dithering_depth
) {
551 nv_connector
->dithering_depth
= value
;
552 if (!nv_crtc
|| !nv_crtc
->set_dither
)
555 return nv_crtc
->set_dither(nv_crtc
, true);
558 if (nv_crtc
&& nv_crtc
->set_color_vibrance
) {
560 if (property
== disp
->vibrant_hue_property
) {
561 nv_crtc
->vibrant_hue
= value
- 90;
562 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
565 if (property
== disp
->color_vibrance_property
) {
566 nv_crtc
->color_vibrance
= value
- 100;
567 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
571 if (nv_encoder
&& nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
572 return get_slave_funcs(encoder
)->set_property(
573 encoder
, connector
, property
, value
);
578 static struct drm_display_mode
*
579 nouveau_connector_native_mode(struct drm_connector
*connector
)
581 struct drm_connector_helper_funcs
*helper
= connector
->helper_private
;
582 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
583 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
584 struct drm_device
*dev
= connector
->dev
;
585 struct drm_display_mode
*mode
, *largest
= NULL
;
586 int high_w
= 0, high_h
= 0, high_v
= 0;
588 list_for_each_entry(mode
, &nv_connector
->base
.probed_modes
, head
) {
589 mode
->vrefresh
= drm_mode_vrefresh(mode
);
590 if (helper
->mode_valid(connector
, mode
) != MODE_OK
||
591 (mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
594 /* Use preferred mode if there is one.. */
595 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
) {
596 NV_DEBUG(drm
, "native mode from preferred\n");
597 return drm_mode_duplicate(dev
, mode
);
600 /* Otherwise, take the resolution with the largest width, then
601 * height, then vertical refresh
603 if (mode
->hdisplay
< high_w
)
606 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
< high_h
)
609 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
== high_h
&&
610 mode
->vrefresh
< high_v
)
613 high_w
= mode
->hdisplay
;
614 high_h
= mode
->vdisplay
;
615 high_v
= mode
->vrefresh
;
619 NV_DEBUG(drm
, "native mode from largest: %dx%d@%d\n",
620 high_w
, high_h
, high_v
);
621 return largest
? drm_mode_duplicate(dev
, largest
) : NULL
;
629 static struct moderec scaler_modes
[] = {
648 nouveau_connector_scaler_modes_add(struct drm_connector
*connector
)
650 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
651 struct drm_display_mode
*native
= nv_connector
->native_mode
, *m
;
652 struct drm_device
*dev
= connector
->dev
;
653 struct moderec
*mode
= &scaler_modes
[0];
659 while (mode
->hdisplay
) {
660 if (mode
->hdisplay
<= native
->hdisplay
&&
661 mode
->vdisplay
<= native
->vdisplay
) {
662 m
= drm_cvt_mode(dev
, mode
->hdisplay
, mode
->vdisplay
,
663 drm_mode_vrefresh(native
), false,
668 m
->type
|= DRM_MODE_TYPE_DRIVER
;
670 drm_mode_probed_add(connector
, m
);
681 nouveau_connector_detect_depth(struct drm_connector
*connector
)
683 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
684 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
685 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
686 struct nvbios
*bios
= &drm
->vbios
;
687 struct drm_display_mode
*mode
= nv_connector
->native_mode
;
690 /* if the edid is feeling nice enough to provide this info, use it */
691 if (nv_connector
->edid
&& connector
->display_info
.bpc
)
694 /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
695 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
696 connector
->display_info
.bpc
= 6;
700 /* we're out of options unless we're LVDS, default to 8bpc */
701 if (nv_encoder
->dcb
->type
!= DCB_OUTPUT_LVDS
) {
702 connector
->display_info
.bpc
= 8;
706 connector
->display_info
.bpc
= 6;
708 /* LVDS: panel straps */
709 if (bios
->fp_no_ddc
) {
710 if (bios
->fp
.if_is_24bit
)
711 connector
->display_info
.bpc
= 8;
715 /* LVDS: DDC panel, need to first determine the number of links to
716 * know which if_is_24bit flag to check...
718 if (nv_connector
->edid
&&
719 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
)
720 duallink
= ((u8
*)nv_connector
->edid
)[121] == 2;
722 duallink
= mode
->clock
>= bios
->fp
.duallink_transition_clk
;
724 if ((!duallink
&& (bios
->fp
.strapless_is_24bit
& 1)) ||
725 ( duallink
&& (bios
->fp
.strapless_is_24bit
& 2)))
726 connector
->display_info
.bpc
= 8;
730 nouveau_connector_get_modes(struct drm_connector
*connector
)
732 struct drm_device
*dev
= connector
->dev
;
733 struct nouveau_drm
*drm
= nouveau_drm(dev
);
734 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
735 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
736 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
739 /* destroy the native mode, the attached monitor could have changed.
741 if (nv_connector
->native_mode
) {
742 drm_mode_destroy(dev
, nv_connector
->native_mode
);
743 nv_connector
->native_mode
= NULL
;
746 if (nv_connector
->edid
)
747 ret
= drm_add_edid_modes(connector
, nv_connector
->edid
);
749 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
&&
750 (nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
||
751 drm
->vbios
.fp_no_ddc
) && nouveau_bios_fp_mode(dev
, NULL
)) {
752 struct drm_display_mode mode
;
754 nouveau_bios_fp_mode(dev
, &mode
);
755 nv_connector
->native_mode
= drm_mode_duplicate(dev
, &mode
);
758 /* Determine display colour depth for everything except LVDS now,
759 * DP requires this before mode_valid() is called.
761 if (connector
->connector_type
!= DRM_MODE_CONNECTOR_LVDS
)
762 nouveau_connector_detect_depth(connector
);
764 /* Find the native mode if this is a digital panel, if we didn't
765 * find any modes through DDC previously add the native mode to
768 if (!nv_connector
->native_mode
)
769 nv_connector
->native_mode
=
770 nouveau_connector_native_mode(connector
);
771 if (ret
== 0 && nv_connector
->native_mode
) {
772 struct drm_display_mode
*mode
;
774 mode
= drm_mode_duplicate(dev
, nv_connector
->native_mode
);
775 drm_mode_probed_add(connector
, mode
);
779 /* Determine LVDS colour depth, must happen after determining
780 * "native" mode as some VBIOS tables require us to use the
781 * pixel clock as part of the lookup...
783 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
)
784 nouveau_connector_detect_depth(connector
);
786 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
787 ret
= get_slave_funcs(encoder
)->get_modes(encoder
, connector
);
789 if (nv_connector
->type
== DCB_CONNECTOR_LVDS
||
790 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
||
791 nv_connector
->type
== DCB_CONNECTOR_eDP
)
792 ret
+= nouveau_connector_scaler_modes_add(connector
);
798 get_tmds_link_bandwidth(struct drm_connector
*connector
)
800 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
801 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
802 struct dcb_output
*dcb
= nv_connector
->detected_encoder
->dcb
;
804 if (dcb
->location
!= DCB_LOC_ON_CHIP
||
805 nv_device(drm
->device
)->chipset
>= 0x46)
807 else if (nv_device(drm
->device
)->chipset
>= 0x40)
809 else if (nv_device(drm
->device
)->chipset
>= 0x18)
816 nouveau_connector_mode_valid(struct drm_connector
*connector
,
817 struct drm_display_mode
*mode
)
819 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
820 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
821 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
822 unsigned min_clock
= 25000, max_clock
= min_clock
;
823 unsigned clock
= mode
->clock
;
825 switch (nv_encoder
->dcb
->type
) {
826 case DCB_OUTPUT_LVDS
:
827 if (nv_connector
->native_mode
&&
828 (mode
->hdisplay
> nv_connector
->native_mode
->hdisplay
||
829 mode
->vdisplay
> nv_connector
->native_mode
->vdisplay
))
835 case DCB_OUTPUT_TMDS
:
836 max_clock
= get_tmds_link_bandwidth(connector
);
837 if (nouveau_duallink
&& nv_encoder
->dcb
->duallink_possible
)
840 case DCB_OUTPUT_ANALOG
:
841 max_clock
= nv_encoder
->dcb
->crtconf
.maxfreq
;
846 return get_slave_funcs(encoder
)->mode_valid(encoder
, mode
);
848 max_clock
= nv_encoder
->dp
.link_nr
;
849 max_clock
*= nv_encoder
->dp
.link_bw
;
850 clock
= clock
* (connector
->display_info
.bpc
* 3) / 10;
857 if (clock
< min_clock
)
858 return MODE_CLOCK_LOW
;
860 if (clock
> max_clock
)
861 return MODE_CLOCK_HIGH
;
866 static struct drm_encoder
*
867 nouveau_connector_best_encoder(struct drm_connector
*connector
)
869 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
871 if (nv_connector
->detected_encoder
)
872 return to_drm_encoder(nv_connector
->detected_encoder
);
877 static const struct drm_connector_helper_funcs
878 nouveau_connector_helper_funcs
= {
879 .get_modes
= nouveau_connector_get_modes
,
880 .mode_valid
= nouveau_connector_mode_valid
,
881 .best_encoder
= nouveau_connector_best_encoder
,
884 static const struct drm_connector_funcs
885 nouveau_connector_funcs
= {
886 .dpms
= drm_helper_connector_dpms
,
889 .detect
= nouveau_connector_detect
,
890 .destroy
= nouveau_connector_destroy
,
891 .fill_modes
= drm_helper_probe_single_connector_modes
,
892 .set_property
= nouveau_connector_set_property
,
893 .force
= nouveau_connector_force
896 static const struct drm_connector_funcs
897 nouveau_connector_funcs_lvds
= {
898 .dpms
= drm_helper_connector_dpms
,
901 .detect
= nouveau_connector_detect_lvds
,
902 .destroy
= nouveau_connector_destroy
,
903 .fill_modes
= drm_helper_probe_single_connector_modes
,
904 .set_property
= nouveau_connector_set_property
,
905 .force
= nouveau_connector_force
909 nouveau_connector_dp_dpms(struct drm_connector
*connector
, int mode
)
911 struct nouveau_encoder
*nv_encoder
= NULL
;
913 if (connector
->encoder
)
914 nv_encoder
= nouveau_encoder(connector
->encoder
);
915 if (nv_encoder
&& nv_encoder
->dcb
&&
916 nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
) {
917 if (mode
== DRM_MODE_DPMS_ON
) {
918 u8 data
= DP_SET_POWER_D0
;
919 nv_wraux(nv_encoder
->i2c
, DP_SET_POWER
, &data
, 1);
920 usleep_range(1000, 2000);
922 u8 data
= DP_SET_POWER_D3
;
923 nv_wraux(nv_encoder
->i2c
, DP_SET_POWER
, &data
, 1);
927 drm_helper_connector_dpms(connector
, mode
);
930 static const struct drm_connector_funcs
931 nouveau_connector_funcs_dp
= {
932 .dpms
= nouveau_connector_dp_dpms
,
935 .detect
= nouveau_connector_detect
,
936 .destroy
= nouveau_connector_destroy
,
937 .fill_modes
= drm_helper_probe_single_connector_modes
,
938 .set_property
= nouveau_connector_set_property
,
939 .force
= nouveau_connector_force
943 nouveau_connector_hotplug_work(struct work_struct
*work
)
945 struct nouveau_connector
*nv_connector
=
946 container_of(work
, typeof(*nv_connector
), work
);
947 struct drm_connector
*connector
= &nv_connector
->base
;
948 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
949 const char *name
= connector
->name
;
951 if (nv_connector
->status
& NVKM_HPD_IRQ
) {
953 bool plugged
= (nv_connector
->status
!= NVKM_HPD_UNPLUG
);
955 NV_DEBUG(drm
, "%splugged %s\n", plugged
? "" : "un", name
);
958 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_ON
);
960 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
961 drm_helper_hpd_irq_event(connector
->dev
);
964 nouveau_event_get(nv_connector
->hpd
);
968 nouveau_connector_hotplug(void *data
, u32 type
, int index
)
970 struct nouveau_connector
*nv_connector
= data
;
971 nv_connector
->status
= type
;
972 schedule_work(&nv_connector
->work
);
973 return NVKM_EVENT_DROP
;
977 nouveau_connector_aux_xfer(struct drm_dp_aux
*aux
, struct drm_dp_aux_msg
*msg
)
979 struct nouveau_connector
*nv_connector
=
980 container_of(aux
, typeof(*nv_connector
), aux
);
981 struct nouveau_encoder
*nv_encoder
;
982 struct nouveau_i2c_port
*port
;
985 nv_encoder
= find_encoder(&nv_connector
->base
, DCB_OUTPUT_DP
);
986 if (!nv_encoder
|| !(port
= nv_encoder
->i2c
))
988 if (WARN_ON(msg
->size
> 16))
993 ret
= nouveau_i2c(port
)->acquire(port
, 0);
997 ret
= port
->func
->aux(port
, false, msg
->request
, msg
->address
,
998 msg
->buffer
, msg
->size
);
999 nouveau_i2c(port
)->release(port
);
1009 drm_conntype_from_dcb(enum dcb_connector_type dcb
)
1012 case DCB_CONNECTOR_VGA
: return DRM_MODE_CONNECTOR_VGA
;
1013 case DCB_CONNECTOR_TV_0
:
1014 case DCB_CONNECTOR_TV_1
:
1015 case DCB_CONNECTOR_TV_3
: return DRM_MODE_CONNECTOR_TV
;
1016 case DCB_CONNECTOR_DMS59_0
:
1017 case DCB_CONNECTOR_DMS59_1
:
1018 case DCB_CONNECTOR_DVI_I
: return DRM_MODE_CONNECTOR_DVII
;
1019 case DCB_CONNECTOR_DVI_D
: return DRM_MODE_CONNECTOR_DVID
;
1020 case DCB_CONNECTOR_LVDS
:
1021 case DCB_CONNECTOR_LVDS_SPWG
: return DRM_MODE_CONNECTOR_LVDS
;
1022 case DCB_CONNECTOR_DMS59_DP0
:
1023 case DCB_CONNECTOR_DMS59_DP1
:
1024 case DCB_CONNECTOR_DP
: return DRM_MODE_CONNECTOR_DisplayPort
;
1025 case DCB_CONNECTOR_eDP
: return DRM_MODE_CONNECTOR_eDP
;
1026 case DCB_CONNECTOR_HDMI_0
:
1027 case DCB_CONNECTOR_HDMI_1
:
1028 case DCB_CONNECTOR_HDMI_C
: return DRM_MODE_CONNECTOR_HDMIA
;
1033 return DRM_MODE_CONNECTOR_Unknown
;
1036 struct drm_connector
*
1037 nouveau_connector_create(struct drm_device
*dev
, int index
)
1039 const struct drm_connector_funcs
*funcs
= &nouveau_connector_funcs
;
1040 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1041 struct nouveau_display
*disp
= nouveau_display(dev
);
1042 struct nouveau_connector
*nv_connector
= NULL
;
1043 struct nouveau_disp
*pdisp
= nouveau_disp(drm
->device
);
1044 struct drm_connector
*connector
;
1048 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1049 nv_connector
= nouveau_connector(connector
);
1050 if (nv_connector
->index
== index
)
1054 nv_connector
= kzalloc(sizeof(*nv_connector
), GFP_KERNEL
);
1056 return ERR_PTR(-ENOMEM
);
1058 connector
= &nv_connector
->base
;
1059 nv_connector
->index
= index
;
1061 /* attempt to parse vbios connector type and hotplug gpio */
1062 nv_connector
->dcb
= olddcb_conn(dev
, index
);
1063 if (nv_connector
->dcb
) {
1064 u32 entry
= ROM16(nv_connector
->dcb
[0]);
1065 if (olddcb_conntab(dev
)[3] >= 4)
1066 entry
|= (u32
)ROM16(nv_connector
->dcb
[2]) << 16;
1068 nv_connector
->type
= nv_connector
->dcb
[0];
1069 if (drm_conntype_from_dcb(nv_connector
->type
) ==
1070 DRM_MODE_CONNECTOR_Unknown
) {
1071 NV_WARN(drm
, "unknown connector type %02x\n",
1072 nv_connector
->type
);
1073 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1076 /* Gigabyte NX85T */
1077 if (nv_match_device(dev
, 0x0421, 0x1458, 0x344c)) {
1078 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1079 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1082 /* Gigabyte GV-NX86T512H */
1083 if (nv_match_device(dev
, 0x0402, 0x1458, 0x3455)) {
1084 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1085 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1088 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1091 /* no vbios data, or an unknown dcb connector type - attempt to
1092 * figure out something suitable ourselves
1094 if (nv_connector
->type
== DCB_CONNECTOR_NONE
) {
1095 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1096 struct dcb_table
*dcbt
= &drm
->vbios
.dcb
;
1100 for (i
= 0; i
< dcbt
->entries
; i
++) {
1101 if (dcbt
->entry
[i
].connector
== nv_connector
->index
)
1102 encoders
|= (1 << dcbt
->entry
[i
].type
);
1105 if (encoders
& (1 << DCB_OUTPUT_DP
)) {
1106 if (encoders
& (1 << DCB_OUTPUT_TMDS
))
1107 nv_connector
->type
= DCB_CONNECTOR_DP
;
1109 nv_connector
->type
= DCB_CONNECTOR_eDP
;
1111 if (encoders
& (1 << DCB_OUTPUT_TMDS
)) {
1112 if (encoders
& (1 << DCB_OUTPUT_ANALOG
))
1113 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1115 nv_connector
->type
= DCB_CONNECTOR_DVI_D
;
1117 if (encoders
& (1 << DCB_OUTPUT_ANALOG
)) {
1118 nv_connector
->type
= DCB_CONNECTOR_VGA
;
1120 if (encoders
& (1 << DCB_OUTPUT_LVDS
)) {
1121 nv_connector
->type
= DCB_CONNECTOR_LVDS
;
1123 if (encoders
& (1 << DCB_OUTPUT_TV
)) {
1124 nv_connector
->type
= DCB_CONNECTOR_TV_0
;
1128 switch ((type
= drm_conntype_from_dcb(nv_connector
->type
))) {
1129 case DRM_MODE_CONNECTOR_LVDS
:
1130 ret
= nouveau_bios_parse_lvds_table(dev
, 0, &dummy
, &dummy
);
1132 NV_ERROR(drm
, "Error parsing LVDS table, disabling\n");
1133 kfree(nv_connector
);
1134 return ERR_PTR(ret
);
1137 funcs
= &nouveau_connector_funcs_lvds
;
1139 case DRM_MODE_CONNECTOR_DisplayPort
:
1140 case DRM_MODE_CONNECTOR_eDP
:
1141 nv_connector
->aux
.dev
= dev
->dev
;
1142 nv_connector
->aux
.transfer
= nouveau_connector_aux_xfer
;
1143 ret
= drm_dp_aux_register(&nv_connector
->aux
);
1145 NV_ERROR(drm
, "failed to register aux channel\n");
1146 kfree(nv_connector
);
1147 return ERR_PTR(ret
);
1150 funcs
= &nouveau_connector_funcs_dp
;
1153 funcs
= &nouveau_connector_funcs
;
1157 /* defaults, will get overridden in detect() */
1158 connector
->interlace_allowed
= false;
1159 connector
->doublescan_allowed
= false;
1161 drm_connector_init(dev
, connector
, funcs
, type
);
1162 drm_connector_helper_add(connector
, &nouveau_connector_helper_funcs
);
1164 /* Init DVI-I specific properties */
1165 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
)
1166 drm_object_attach_property(&connector
->base
, dev
->mode_config
.dvi_i_subconnector_property
, 0);
1168 /* Add overscan compensation options to digital outputs */
1169 if (disp
->underscan_property
&&
1170 (type
== DRM_MODE_CONNECTOR_DVID
||
1171 type
== DRM_MODE_CONNECTOR_DVII
||
1172 type
== DRM_MODE_CONNECTOR_HDMIA
||
1173 type
== DRM_MODE_CONNECTOR_DisplayPort
)) {
1174 drm_object_attach_property(&connector
->base
,
1175 disp
->underscan_property
,
1177 drm_object_attach_property(&connector
->base
,
1178 disp
->underscan_hborder_property
,
1180 drm_object_attach_property(&connector
->base
,
1181 disp
->underscan_vborder_property
,
1185 /* Add hue and saturation options */
1186 if (disp
->vibrant_hue_property
)
1187 drm_object_attach_property(&connector
->base
,
1188 disp
->vibrant_hue_property
,
1190 if (disp
->color_vibrance_property
)
1191 drm_object_attach_property(&connector
->base
,
1192 disp
->color_vibrance_property
,
1195 switch (nv_connector
->type
) {
1196 case DCB_CONNECTOR_VGA
:
1197 if (nv_device(drm
->device
)->card_type
>= NV_50
) {
1198 drm_object_attach_property(&connector
->base
,
1199 dev
->mode_config
.scaling_mode_property
,
1200 nv_connector
->scaling_mode
);
1203 case DCB_CONNECTOR_TV_0
:
1204 case DCB_CONNECTOR_TV_1
:
1205 case DCB_CONNECTOR_TV_3
:
1206 nv_connector
->scaling_mode
= DRM_MODE_SCALE_NONE
;
1209 nv_connector
->scaling_mode
= DRM_MODE_SCALE_FULLSCREEN
;
1211 drm_object_attach_property(&connector
->base
,
1212 dev
->mode_config
.scaling_mode_property
,
1213 nv_connector
->scaling_mode
);
1214 if (disp
->dithering_mode
) {
1215 nv_connector
->dithering_mode
= DITHERING_MODE_AUTO
;
1216 drm_object_attach_property(&connector
->base
,
1217 disp
->dithering_mode
,
1218 nv_connector
->dithering_mode
);
1220 if (disp
->dithering_depth
) {
1221 nv_connector
->dithering_depth
= DITHERING_DEPTH_AUTO
;
1222 drm_object_attach_property(&connector
->base
,
1223 disp
->dithering_depth
,
1224 nv_connector
->dithering_depth
);
1229 ret
= nouveau_event_new(pdisp
->hpd
, NVKM_HPD
, index
,
1230 nouveau_connector_hotplug
,
1231 nv_connector
, &nv_connector
->hpd
);
1233 connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
;
1235 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
1237 INIT_WORK(&nv_connector
->work
, nouveau_connector_hotplug_work
);
1239 drm_sysfs_connector_add(connector
);