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>
48 MODULE_PARM_DESC(tv_disable
, "Disable TV-out detection");
49 static 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 static 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 static int nouveau_duallink
= 1;
58 module_param_named(duallink
, nouveau_duallink
, int, 0400);
60 struct nouveau_encoder
*
61 find_encoder(struct drm_connector
*connector
, int type
)
63 struct drm_device
*dev
= connector
->dev
;
64 struct nouveau_encoder
*nv_encoder
;
65 struct drm_mode_object
*obj
;
68 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
69 id
= connector
->encoder_ids
[i
];
73 obj
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_ENCODER
);
76 nv_encoder
= nouveau_encoder(obj_to_encoder(obj
));
78 if (type
== DCB_OUTPUT_ANY
|| nv_encoder
->dcb
->type
== type
)
85 struct nouveau_connector
*
86 nouveau_encoder_connector_get(struct nouveau_encoder
*encoder
)
88 struct drm_device
*dev
= to_drm_encoder(encoder
)->dev
;
89 struct drm_connector
*drm_connector
;
91 list_for_each_entry(drm_connector
, &dev
->mode_config
.connector_list
, head
) {
92 if (drm_connector
->encoder
== to_drm_encoder(encoder
))
93 return nouveau_connector(drm_connector
);
100 nouveau_connector_destroy(struct drm_connector
*connector
)
102 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
103 kfree(nv_connector
->edid
);
104 drm_sysfs_connector_remove(connector
);
105 drm_connector_cleanup(connector
);
109 static struct nouveau_i2c_port
*
110 nouveau_connector_ddc_detect(struct drm_connector
*connector
,
111 struct nouveau_encoder
**pnv_encoder
)
113 struct drm_device
*dev
= connector
->dev
;
114 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
115 struct nouveau_drm
*drm
= nouveau_drm(dev
);
116 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
117 struct nouveau_i2c_port
*port
= NULL
;
118 int i
, panel
= -ENODEV
;
120 /* eDP panels need powering on by us (if the VBIOS doesn't default it
121 * to on) before doing any AUX channel transactions. LVDS panel power
122 * is handled by the SOR itself, and not required for LVDS DDC.
124 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
125 panel
= gpio
->get(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff);
127 gpio
->set(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff, 1);
132 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
133 struct nouveau_encoder
*nv_encoder
;
134 struct drm_mode_object
*obj
;
137 id
= connector
->encoder_ids
[i
];
141 obj
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_ENCODER
);
144 nv_encoder
= nouveau_encoder(obj_to_encoder(obj
));
146 port
= nv_encoder
->i2c
;
147 if (port
&& nv_probe_i2c(port
, 0x50)) {
148 *pnv_encoder
= nv_encoder
;
155 /* eDP panel not detected, restore panel power GPIO to previous
156 * state to avoid confusing the SOR for other output types.
158 if (!port
&& panel
== 0)
159 gpio
->set(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff, panel
);
164 static struct nouveau_encoder
*
165 nouveau_connector_of_detect(struct drm_connector
*connector
)
168 struct drm_device
*dev
= connector
->dev
;
169 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
170 struct nouveau_encoder
*nv_encoder
;
171 struct device_node
*cn
, *dn
= pci_device_to_OF_node(dev
->pdev
);
174 !((nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TMDS
)) ||
175 (nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
))))
178 for_each_child_of_node(dn
, cn
) {
179 const char *name
= of_get_property(cn
, "name", NULL
);
180 const void *edid
= of_get_property(cn
, "EDID", NULL
);
181 int idx
= name
? name
[strlen(name
) - 1] - 'A' : 0;
183 if (nv_encoder
->dcb
->i2c_index
== idx
&& edid
) {
185 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
195 nouveau_connector_set_encoder(struct drm_connector
*connector
,
196 struct nouveau_encoder
*nv_encoder
)
198 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
199 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
200 struct drm_device
*dev
= connector
->dev
;
202 if (nv_connector
->detected_encoder
== nv_encoder
)
204 nv_connector
->detected_encoder
= nv_encoder
;
206 if (nv_device(drm
->device
)->card_type
>= NV_50
) {
207 connector
->interlace_allowed
= true;
208 connector
->doublescan_allowed
= true;
210 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
||
211 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
) {
212 connector
->doublescan_allowed
= false;
213 connector
->interlace_allowed
= false;
215 connector
->doublescan_allowed
= true;
216 if (nv_device(drm
->device
)->card_type
== NV_20
||
217 (nv_device(drm
->device
)->card_type
== NV_10
&&
218 (dev
->pci_device
& 0x0ff0) != 0x0100 &&
219 (dev
->pci_device
& 0x0ff0) != 0x0150))
221 connector
->interlace_allowed
= false;
223 connector
->interlace_allowed
= true;
226 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
227 drm_object_property_set_value(&connector
->base
,
228 dev
->mode_config
.dvi_i_subconnector_property
,
229 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
?
230 DRM_MODE_SUBCONNECTOR_DVID
:
231 DRM_MODE_SUBCONNECTOR_DVIA
);
235 static enum drm_connector_status
236 nouveau_connector_detect(struct drm_connector
*connector
, bool force
)
238 struct drm_device
*dev
= connector
->dev
;
239 struct nouveau_drm
*drm
= nouveau_drm(dev
);
240 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
241 struct nouveau_encoder
*nv_encoder
= NULL
;
242 struct nouveau_encoder
*nv_partner
;
243 struct nouveau_i2c_port
*i2c
;
246 enum drm_connector_status conn_status
= connector_status_disconnected
;
248 /* Cleanup the previous EDID block. */
249 if (nv_connector
->edid
) {
250 drm_mode_connector_update_edid_property(connector
, NULL
);
251 kfree(nv_connector
->edid
);
252 nv_connector
->edid
= NULL
;
255 ret
= pm_runtime_get_sync(connector
->dev
->dev
);
259 i2c
= nouveau_connector_ddc_detect(connector
, &nv_encoder
);
261 nv_connector
->edid
= drm_get_edid(connector
, &i2c
->adapter
);
262 drm_mode_connector_update_edid_property(connector
,
264 if (!nv_connector
->edid
) {
265 NV_ERROR(drm
, "DDC responded, but no EDID for %s\n",
266 drm_get_connector_name(connector
));
270 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
&&
271 !nouveau_dp_detect(to_drm_encoder(nv_encoder
))) {
272 NV_ERROR(drm
, "Detected %s, but failed init\n",
273 drm_get_connector_name(connector
));
274 conn_status
= connector_status_disconnected
;
278 /* Override encoder type for DVI-I based on whether EDID
279 * says the display is digital or analog, both use the
280 * same i2c channel so the value returned from ddc_detect
281 * isn't necessarily correct.
284 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
)
285 nv_partner
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
286 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
)
287 nv_partner
= find_encoder(connector
, DCB_OUTPUT_TMDS
);
289 if (nv_partner
&& ((nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
&&
290 nv_partner
->dcb
->type
== DCB_OUTPUT_TMDS
) ||
291 (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
&&
292 nv_partner
->dcb
->type
== DCB_OUTPUT_ANALOG
))) {
293 if (nv_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
)
294 type
= DCB_OUTPUT_TMDS
;
296 type
= DCB_OUTPUT_ANALOG
;
298 nv_encoder
= find_encoder(connector
, type
);
301 nouveau_connector_set_encoder(connector
, nv_encoder
);
302 conn_status
= connector_status_connected
;
306 nv_encoder
= nouveau_connector_of_detect(connector
);
308 nouveau_connector_set_encoder(connector
, nv_encoder
);
309 conn_status
= connector_status_connected
;
314 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
315 if (!nv_encoder
&& !nouveau_tv_disable
)
316 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TV
);
317 if (nv_encoder
&& force
) {
318 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
319 struct drm_encoder_helper_funcs
*helper
=
320 encoder
->helper_private
;
322 if (helper
->detect(encoder
, connector
) ==
323 connector_status_connected
) {
324 nouveau_connector_set_encoder(connector
, nv_encoder
);
325 conn_status
= connector_status_connected
;
333 pm_runtime_mark_last_busy(connector
->dev
->dev
);
334 pm_runtime_put_autosuspend(connector
->dev
->dev
);
339 static enum drm_connector_status
340 nouveau_connector_detect_lvds(struct drm_connector
*connector
, bool force
)
342 struct drm_device
*dev
= connector
->dev
;
343 struct nouveau_drm
*drm
= nouveau_drm(dev
);
344 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
345 struct nouveau_encoder
*nv_encoder
= NULL
;
346 enum drm_connector_status status
= connector_status_disconnected
;
348 /* Cleanup the previous EDID block. */
349 if (nv_connector
->edid
) {
350 drm_mode_connector_update_edid_property(connector
, NULL
);
351 kfree(nv_connector
->edid
);
352 nv_connector
->edid
= NULL
;
355 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_LVDS
);
357 return connector_status_disconnected
;
359 /* Try retrieving EDID via DDC */
360 if (!drm
->vbios
.fp_no_ddc
) {
361 status
= nouveau_connector_detect(connector
, force
);
362 if (status
== connector_status_connected
)
366 /* On some laptops (Sony, i'm looking at you) there appears to
367 * be no direct way of accessing the panel's EDID. The only
368 * option available to us appears to be to ask ACPI for help..
370 * It's important this check's before trying straps, one of the
371 * said manufacturer's laptops are configured in such a way
372 * the nouveau decides an entry in the VBIOS FP mode table is
373 * valid - it's not (rh#613284)
375 if (nv_encoder
->dcb
->lvdsconf
.use_acpi_for_edid
) {
376 if ((nv_connector
->edid
= nouveau_acpi_edid(dev
, connector
))) {
377 status
= connector_status_connected
;
382 /* If no EDID found above, and the VBIOS indicates a hardcoded
383 * modeline is avalilable for the panel, set it as the panel's
384 * native mode and exit.
386 if (nouveau_bios_fp_mode(dev
, NULL
) && (drm
->vbios
.fp_no_ddc
||
387 nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
)) {
388 status
= connector_status_connected
;
392 /* Still nothing, some VBIOS images have a hardcoded EDID block
393 * stored for the panel stored in them.
395 if (!drm
->vbios
.fp_no_ddc
) {
397 (struct edid
*)nouveau_bios_embedded_edid(dev
);
400 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
401 if (nv_connector
->edid
)
402 status
= connector_status_connected
;
407 #if defined(CONFIG_ACPI_BUTTON) || \
408 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
409 if (status
== connector_status_connected
&&
410 !nouveau_ignorelid
&& !acpi_lid_open())
411 status
= connector_status_unknown
;
414 drm_mode_connector_update_edid_property(connector
, nv_connector
->edid
);
415 nouveau_connector_set_encoder(connector
, nv_encoder
);
420 nouveau_connector_force(struct drm_connector
*connector
)
422 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
423 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
424 struct nouveau_encoder
*nv_encoder
;
427 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
428 if (connector
->force
== DRM_FORCE_ON_DIGITAL
)
429 type
= DCB_OUTPUT_TMDS
;
431 type
= DCB_OUTPUT_ANALOG
;
433 type
= DCB_OUTPUT_ANY
;
435 nv_encoder
= find_encoder(connector
, type
);
437 NV_ERROR(drm
, "can't find encoder to force %s on!\n",
438 drm_get_connector_name(connector
));
439 connector
->status
= connector_status_disconnected
;
443 nouveau_connector_set_encoder(connector
, nv_encoder
);
447 nouveau_connector_set_property(struct drm_connector
*connector
,
448 struct drm_property
*property
, uint64_t value
)
450 struct nouveau_display
*disp
= nouveau_display(connector
->dev
);
451 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
452 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
453 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
454 struct drm_device
*dev
= connector
->dev
;
455 struct nouveau_crtc
*nv_crtc
;
459 if (connector
->encoder
&& connector
->encoder
->crtc
)
460 nv_crtc
= nouveau_crtc(connector
->encoder
->crtc
);
463 if (property
== dev
->mode_config
.scaling_mode_property
) {
464 bool modeset
= false;
467 case DRM_MODE_SCALE_NONE
:
468 case DRM_MODE_SCALE_FULLSCREEN
:
469 case DRM_MODE_SCALE_CENTER
:
470 case DRM_MODE_SCALE_ASPECT
:
476 /* LVDS always needs gpu scaling */
477 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
&&
478 value
== DRM_MODE_SCALE_NONE
)
481 /* Changing between GPU and panel scaling requires a full
484 if ((nv_connector
->scaling_mode
== DRM_MODE_SCALE_NONE
) ||
485 (value
== DRM_MODE_SCALE_NONE
))
487 nv_connector
->scaling_mode
= value
;
492 if (modeset
|| !nv_crtc
->set_scale
) {
493 ret
= drm_crtc_helper_set_mode(&nv_crtc
->base
,
496 nv_crtc
->base
.y
, NULL
);
500 ret
= nv_crtc
->set_scale(nv_crtc
, true);
509 if (property
== disp
->underscan_property
) {
510 if (nv_connector
->underscan
!= value
) {
511 nv_connector
->underscan
= value
;
512 if (!nv_crtc
|| !nv_crtc
->set_scale
)
515 return nv_crtc
->set_scale(nv_crtc
, true);
521 if (property
== disp
->underscan_hborder_property
) {
522 if (nv_connector
->underscan_hborder
!= value
) {
523 nv_connector
->underscan_hborder
= value
;
524 if (!nv_crtc
|| !nv_crtc
->set_scale
)
527 return nv_crtc
->set_scale(nv_crtc
, true);
533 if (property
== disp
->underscan_vborder_property
) {
534 if (nv_connector
->underscan_vborder
!= value
) {
535 nv_connector
->underscan_vborder
= value
;
536 if (!nv_crtc
|| !nv_crtc
->set_scale
)
539 return nv_crtc
->set_scale(nv_crtc
, true);
546 if (property
== disp
->dithering_mode
) {
547 nv_connector
->dithering_mode
= value
;
548 if (!nv_crtc
|| !nv_crtc
->set_dither
)
551 return nv_crtc
->set_dither(nv_crtc
, true);
554 if (property
== disp
->dithering_depth
) {
555 nv_connector
->dithering_depth
= value
;
556 if (!nv_crtc
|| !nv_crtc
->set_dither
)
559 return nv_crtc
->set_dither(nv_crtc
, true);
562 if (nv_crtc
&& nv_crtc
->set_color_vibrance
) {
564 if (property
== disp
->vibrant_hue_property
) {
565 nv_crtc
->vibrant_hue
= value
- 90;
566 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
569 if (property
== disp
->color_vibrance_property
) {
570 nv_crtc
->color_vibrance
= value
- 100;
571 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
575 if (nv_encoder
&& nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
576 return get_slave_funcs(encoder
)->set_property(
577 encoder
, connector
, property
, value
);
582 static struct drm_display_mode
*
583 nouveau_connector_native_mode(struct drm_connector
*connector
)
585 struct drm_connector_helper_funcs
*helper
= connector
->helper_private
;
586 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
587 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
588 struct drm_device
*dev
= connector
->dev
;
589 struct drm_display_mode
*mode
, *largest
= NULL
;
590 int high_w
= 0, high_h
= 0, high_v
= 0;
592 list_for_each_entry(mode
, &nv_connector
->base
.probed_modes
, head
) {
593 mode
->vrefresh
= drm_mode_vrefresh(mode
);
594 if (helper
->mode_valid(connector
, mode
) != MODE_OK
||
595 (mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
598 /* Use preferred mode if there is one.. */
599 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
) {
600 NV_DEBUG(drm
, "native mode from preferred\n");
601 return drm_mode_duplicate(dev
, mode
);
604 /* Otherwise, take the resolution with the largest width, then
605 * height, then vertical refresh
607 if (mode
->hdisplay
< high_w
)
610 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
< high_h
)
613 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
== high_h
&&
614 mode
->vrefresh
< high_v
)
617 high_w
= mode
->hdisplay
;
618 high_h
= mode
->vdisplay
;
619 high_v
= mode
->vrefresh
;
623 NV_DEBUG(drm
, "native mode from largest: %dx%d@%d\n",
624 high_w
, high_h
, high_v
);
625 return largest
? drm_mode_duplicate(dev
, largest
) : NULL
;
633 static struct moderec scaler_modes
[] = {
652 nouveau_connector_scaler_modes_add(struct drm_connector
*connector
)
654 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
655 struct drm_display_mode
*native
= nv_connector
->native_mode
, *m
;
656 struct drm_device
*dev
= connector
->dev
;
657 struct moderec
*mode
= &scaler_modes
[0];
663 while (mode
->hdisplay
) {
664 if (mode
->hdisplay
<= native
->hdisplay
&&
665 mode
->vdisplay
<= native
->vdisplay
) {
666 m
= drm_cvt_mode(dev
, mode
->hdisplay
, mode
->vdisplay
,
667 drm_mode_vrefresh(native
), false,
672 m
->type
|= DRM_MODE_TYPE_DRIVER
;
674 drm_mode_probed_add(connector
, m
);
685 nouveau_connector_detect_depth(struct drm_connector
*connector
)
687 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
688 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
689 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
690 struct nvbios
*bios
= &drm
->vbios
;
691 struct drm_display_mode
*mode
= nv_connector
->native_mode
;
694 /* if the edid is feeling nice enough to provide this info, use it */
695 if (nv_connector
->edid
&& connector
->display_info
.bpc
)
698 /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
699 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
700 connector
->display_info
.bpc
= 6;
704 /* we're out of options unless we're LVDS, default to 8bpc */
705 if (nv_encoder
->dcb
->type
!= DCB_OUTPUT_LVDS
) {
706 connector
->display_info
.bpc
= 8;
710 connector
->display_info
.bpc
= 6;
712 /* LVDS: panel straps */
713 if (bios
->fp_no_ddc
) {
714 if (bios
->fp
.if_is_24bit
)
715 connector
->display_info
.bpc
= 8;
719 /* LVDS: DDC panel, need to first determine the number of links to
720 * know which if_is_24bit flag to check...
722 if (nv_connector
->edid
&&
723 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
)
724 duallink
= ((u8
*)nv_connector
->edid
)[121] == 2;
726 duallink
= mode
->clock
>= bios
->fp
.duallink_transition_clk
;
728 if ((!duallink
&& (bios
->fp
.strapless_is_24bit
& 1)) ||
729 ( duallink
&& (bios
->fp
.strapless_is_24bit
& 2)))
730 connector
->display_info
.bpc
= 8;
734 nouveau_connector_get_modes(struct drm_connector
*connector
)
736 struct drm_device
*dev
= connector
->dev
;
737 struct nouveau_drm
*drm
= nouveau_drm(dev
);
738 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
739 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
740 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
743 /* destroy the native mode, the attached monitor could have changed.
745 if (nv_connector
->native_mode
) {
746 drm_mode_destroy(dev
, nv_connector
->native_mode
);
747 nv_connector
->native_mode
= NULL
;
750 if (nv_connector
->edid
)
751 ret
= drm_add_edid_modes(connector
, nv_connector
->edid
);
753 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
&&
754 (nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
||
755 drm
->vbios
.fp_no_ddc
) && nouveau_bios_fp_mode(dev
, NULL
)) {
756 struct drm_display_mode mode
;
758 nouveau_bios_fp_mode(dev
, &mode
);
759 nv_connector
->native_mode
= drm_mode_duplicate(dev
, &mode
);
762 /* Determine display colour depth for everything except LVDS now,
763 * DP requires this before mode_valid() is called.
765 if (connector
->connector_type
!= DRM_MODE_CONNECTOR_LVDS
)
766 nouveau_connector_detect_depth(connector
);
768 /* Find the native mode if this is a digital panel, if we didn't
769 * find any modes through DDC previously add the native mode to
772 if (!nv_connector
->native_mode
)
773 nv_connector
->native_mode
=
774 nouveau_connector_native_mode(connector
);
775 if (ret
== 0 && nv_connector
->native_mode
) {
776 struct drm_display_mode
*mode
;
778 mode
= drm_mode_duplicate(dev
, nv_connector
->native_mode
);
779 drm_mode_probed_add(connector
, mode
);
783 /* Determine LVDS colour depth, must happen after determining
784 * "native" mode as some VBIOS tables require us to use the
785 * pixel clock as part of the lookup...
787 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
)
788 nouveau_connector_detect_depth(connector
);
790 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
791 ret
= get_slave_funcs(encoder
)->get_modes(encoder
, connector
);
793 if (nv_connector
->type
== DCB_CONNECTOR_LVDS
||
794 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
||
795 nv_connector
->type
== DCB_CONNECTOR_eDP
)
796 ret
+= nouveau_connector_scaler_modes_add(connector
);
802 get_tmds_link_bandwidth(struct drm_connector
*connector
)
804 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
805 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
806 struct dcb_output
*dcb
= nv_connector
->detected_encoder
->dcb
;
808 if (dcb
->location
!= DCB_LOC_ON_CHIP
||
809 nv_device(drm
->device
)->chipset
>= 0x46)
811 else if (nv_device(drm
->device
)->chipset
>= 0x40)
813 else if (nv_device(drm
->device
)->chipset
>= 0x18)
820 nouveau_connector_mode_valid(struct drm_connector
*connector
,
821 struct drm_display_mode
*mode
)
823 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
824 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
825 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
826 unsigned min_clock
= 25000, max_clock
= min_clock
;
827 unsigned clock
= mode
->clock
;
829 switch (nv_encoder
->dcb
->type
) {
830 case DCB_OUTPUT_LVDS
:
831 if (nv_connector
->native_mode
&&
832 (mode
->hdisplay
> nv_connector
->native_mode
->hdisplay
||
833 mode
->vdisplay
> nv_connector
->native_mode
->vdisplay
))
839 case DCB_OUTPUT_TMDS
:
840 max_clock
= get_tmds_link_bandwidth(connector
);
841 if (nouveau_duallink
&& nv_encoder
->dcb
->duallink_possible
)
844 case DCB_OUTPUT_ANALOG
:
845 max_clock
= nv_encoder
->dcb
->crtconf
.maxfreq
;
850 return get_slave_funcs(encoder
)->mode_valid(encoder
, mode
);
852 max_clock
= nv_encoder
->dp
.link_nr
;
853 max_clock
*= nv_encoder
->dp
.link_bw
;
854 clock
= clock
* (connector
->display_info
.bpc
* 3) / 10;
861 if (clock
< min_clock
)
862 return MODE_CLOCK_LOW
;
864 if (clock
> max_clock
)
865 return MODE_CLOCK_HIGH
;
870 static struct drm_encoder
*
871 nouveau_connector_best_encoder(struct drm_connector
*connector
)
873 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
875 if (nv_connector
->detected_encoder
)
876 return to_drm_encoder(nv_connector
->detected_encoder
);
881 static const struct drm_connector_helper_funcs
882 nouveau_connector_helper_funcs
= {
883 .get_modes
= nouveau_connector_get_modes
,
884 .mode_valid
= nouveau_connector_mode_valid
,
885 .best_encoder
= nouveau_connector_best_encoder
,
888 static const struct drm_connector_funcs
889 nouveau_connector_funcs
= {
890 .dpms
= drm_helper_connector_dpms
,
893 .detect
= nouveau_connector_detect
,
894 .destroy
= nouveau_connector_destroy
,
895 .fill_modes
= drm_helper_probe_single_connector_modes
,
896 .set_property
= nouveau_connector_set_property
,
897 .force
= nouveau_connector_force
900 static const struct drm_connector_funcs
901 nouveau_connector_funcs_lvds
= {
902 .dpms
= drm_helper_connector_dpms
,
905 .detect
= nouveau_connector_detect_lvds
,
906 .destroy
= nouveau_connector_destroy
,
907 .fill_modes
= drm_helper_probe_single_connector_modes
,
908 .set_property
= nouveau_connector_set_property
,
909 .force
= nouveau_connector_force
913 nouveau_connector_hotplug_work(struct work_struct
*work
)
915 struct nouveau_connector
*nv_connector
=
916 container_of(work
, struct nouveau_connector
, hpd_work
);
917 struct drm_connector
*connector
= &nv_connector
->base
;
918 struct drm_device
*dev
= connector
->dev
;
919 struct nouveau_drm
*drm
= nouveau_drm(dev
);
920 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
921 bool plugged
= gpio
->get(gpio
, 0, nv_connector
->hpd
.func
, 0xff);
923 NV_DEBUG(drm
, "%splugged %s\n", plugged
? "" : "un",
924 drm_get_connector_name(connector
));
927 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_ON
);
929 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
931 drm_helper_hpd_irq_event(dev
);
935 nouveau_connector_hotplug(struct nouveau_eventh
*event
, int index
)
937 struct nouveau_connector
*nv_connector
=
938 container_of(event
, struct nouveau_connector
, hpd_func
);
939 schedule_work(&nv_connector
->hpd_work
);
940 return NVKM_EVENT_KEEP
;
944 drm_conntype_from_dcb(enum dcb_connector_type dcb
)
947 case DCB_CONNECTOR_VGA
: return DRM_MODE_CONNECTOR_VGA
;
948 case DCB_CONNECTOR_TV_0
:
949 case DCB_CONNECTOR_TV_1
:
950 case DCB_CONNECTOR_TV_3
: return DRM_MODE_CONNECTOR_TV
;
951 case DCB_CONNECTOR_DMS59_0
:
952 case DCB_CONNECTOR_DMS59_1
:
953 case DCB_CONNECTOR_DVI_I
: return DRM_MODE_CONNECTOR_DVII
;
954 case DCB_CONNECTOR_DVI_D
: return DRM_MODE_CONNECTOR_DVID
;
955 case DCB_CONNECTOR_LVDS
:
956 case DCB_CONNECTOR_LVDS_SPWG
: return DRM_MODE_CONNECTOR_LVDS
;
957 case DCB_CONNECTOR_DMS59_DP0
:
958 case DCB_CONNECTOR_DMS59_DP1
:
959 case DCB_CONNECTOR_DP
: return DRM_MODE_CONNECTOR_DisplayPort
;
960 case DCB_CONNECTOR_eDP
: return DRM_MODE_CONNECTOR_eDP
;
961 case DCB_CONNECTOR_HDMI_0
:
962 case DCB_CONNECTOR_HDMI_1
: return DRM_MODE_CONNECTOR_HDMIA
;
967 return DRM_MODE_CONNECTOR_Unknown
;
970 struct drm_connector
*
971 nouveau_connector_create(struct drm_device
*dev
, int index
)
973 const struct drm_connector_funcs
*funcs
= &nouveau_connector_funcs
;
974 struct nouveau_drm
*drm
= nouveau_drm(dev
);
975 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
976 struct nouveau_display
*disp
= nouveau_display(dev
);
977 struct nouveau_connector
*nv_connector
= NULL
;
978 struct drm_connector
*connector
;
982 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
983 nv_connector
= nouveau_connector(connector
);
984 if (nv_connector
->index
== index
)
988 nv_connector
= kzalloc(sizeof(*nv_connector
), GFP_KERNEL
);
990 return ERR_PTR(-ENOMEM
);
992 connector
= &nv_connector
->base
;
993 INIT_WORK(&nv_connector
->hpd_work
, nouveau_connector_hotplug_work
);
994 nv_connector
->index
= index
;
996 /* attempt to parse vbios connector type and hotplug gpio */
997 nv_connector
->dcb
= olddcb_conn(dev
, index
);
998 if (nv_connector
->dcb
) {
999 static const u8 hpd
[16] = {
1000 0xff, 0x07, 0x08, 0xff, 0xff, 0x51, 0x52, 0xff,
1001 0xff, 0xff, 0xff, 0xff, 0xff, 0x5e, 0x5f, 0x60,
1004 u32 entry
= ROM16(nv_connector
->dcb
[0]);
1005 if (olddcb_conntab(dev
)[3] >= 4)
1006 entry
|= (u32
)ROM16(nv_connector
->dcb
[2]) << 16;
1008 ret
= gpio
->find(gpio
, 0, hpd
[ffs((entry
& 0x07033000) >> 12)],
1009 DCB_GPIO_UNUSED
, &nv_connector
->hpd
);
1010 nv_connector
->hpd_func
.func
= nouveau_connector_hotplug
;
1012 nv_connector
->hpd
.func
= DCB_GPIO_UNUSED
;
1014 nv_connector
->type
= nv_connector
->dcb
[0];
1015 if (drm_conntype_from_dcb(nv_connector
->type
) ==
1016 DRM_MODE_CONNECTOR_Unknown
) {
1017 NV_WARN(drm
, "unknown connector type %02x\n",
1018 nv_connector
->type
);
1019 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1022 /* Gigabyte NX85T */
1023 if (nv_match_device(dev
, 0x0421, 0x1458, 0x344c)) {
1024 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1025 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1028 /* Gigabyte GV-NX86T512H */
1029 if (nv_match_device(dev
, 0x0402, 0x1458, 0x3455)) {
1030 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1031 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1034 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1035 nv_connector
->hpd
.func
= DCB_GPIO_UNUSED
;
1038 /* no vbios data, or an unknown dcb connector type - attempt to
1039 * figure out something suitable ourselves
1041 if (nv_connector
->type
== DCB_CONNECTOR_NONE
) {
1042 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1043 struct dcb_table
*dcbt
= &drm
->vbios
.dcb
;
1047 for (i
= 0; i
< dcbt
->entries
; i
++) {
1048 if (dcbt
->entry
[i
].connector
== nv_connector
->index
)
1049 encoders
|= (1 << dcbt
->entry
[i
].type
);
1052 if (encoders
& (1 << DCB_OUTPUT_DP
)) {
1053 if (encoders
& (1 << DCB_OUTPUT_TMDS
))
1054 nv_connector
->type
= DCB_CONNECTOR_DP
;
1056 nv_connector
->type
= DCB_CONNECTOR_eDP
;
1058 if (encoders
& (1 << DCB_OUTPUT_TMDS
)) {
1059 if (encoders
& (1 << DCB_OUTPUT_ANALOG
))
1060 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1062 nv_connector
->type
= DCB_CONNECTOR_DVI_D
;
1064 if (encoders
& (1 << DCB_OUTPUT_ANALOG
)) {
1065 nv_connector
->type
= DCB_CONNECTOR_VGA
;
1067 if (encoders
& (1 << DCB_OUTPUT_LVDS
)) {
1068 nv_connector
->type
= DCB_CONNECTOR_LVDS
;
1070 if (encoders
& (1 << DCB_OUTPUT_TV
)) {
1071 nv_connector
->type
= DCB_CONNECTOR_TV_0
;
1075 type
= drm_conntype_from_dcb(nv_connector
->type
);
1076 if (type
== DRM_MODE_CONNECTOR_LVDS
) {
1077 ret
= nouveau_bios_parse_lvds_table(dev
, 0, &dummy
, &dummy
);
1079 NV_ERROR(drm
, "Error parsing LVDS table, disabling\n");
1080 kfree(nv_connector
);
1081 return ERR_PTR(ret
);
1084 funcs
= &nouveau_connector_funcs_lvds
;
1086 funcs
= &nouveau_connector_funcs
;
1089 /* defaults, will get overridden in detect() */
1090 connector
->interlace_allowed
= false;
1091 connector
->doublescan_allowed
= false;
1093 drm_connector_init(dev
, connector
, funcs
, type
);
1094 drm_connector_helper_add(connector
, &nouveau_connector_helper_funcs
);
1096 /* Init DVI-I specific properties */
1097 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
)
1098 drm_object_attach_property(&connector
->base
, dev
->mode_config
.dvi_i_subconnector_property
, 0);
1100 /* Add overscan compensation options to digital outputs */
1101 if (disp
->underscan_property
&&
1102 (type
== DRM_MODE_CONNECTOR_DVID
||
1103 type
== DRM_MODE_CONNECTOR_DVII
||
1104 type
== DRM_MODE_CONNECTOR_HDMIA
||
1105 type
== DRM_MODE_CONNECTOR_DisplayPort
)) {
1106 drm_object_attach_property(&connector
->base
,
1107 disp
->underscan_property
,
1109 drm_object_attach_property(&connector
->base
,
1110 disp
->underscan_hborder_property
,
1112 drm_object_attach_property(&connector
->base
,
1113 disp
->underscan_vborder_property
,
1117 /* Add hue and saturation options */
1118 if (disp
->vibrant_hue_property
)
1119 drm_object_attach_property(&connector
->base
,
1120 disp
->vibrant_hue_property
,
1122 if (disp
->color_vibrance_property
)
1123 drm_object_attach_property(&connector
->base
,
1124 disp
->color_vibrance_property
,
1127 switch (nv_connector
->type
) {
1128 case DCB_CONNECTOR_VGA
:
1129 if (nv_device(drm
->device
)->card_type
>= NV_50
) {
1130 drm_object_attach_property(&connector
->base
,
1131 dev
->mode_config
.scaling_mode_property
,
1132 nv_connector
->scaling_mode
);
1135 case DCB_CONNECTOR_TV_0
:
1136 case DCB_CONNECTOR_TV_1
:
1137 case DCB_CONNECTOR_TV_3
:
1138 nv_connector
->scaling_mode
= DRM_MODE_SCALE_NONE
;
1141 nv_connector
->scaling_mode
= DRM_MODE_SCALE_FULLSCREEN
;
1143 drm_object_attach_property(&connector
->base
,
1144 dev
->mode_config
.scaling_mode_property
,
1145 nv_connector
->scaling_mode
);
1146 if (disp
->dithering_mode
) {
1147 nv_connector
->dithering_mode
= DITHERING_MODE_AUTO
;
1148 drm_object_attach_property(&connector
->base
,
1149 disp
->dithering_mode
,
1150 nv_connector
->dithering_mode
);
1152 if (disp
->dithering_depth
) {
1153 nv_connector
->dithering_depth
= DITHERING_DEPTH_AUTO
;
1154 drm_object_attach_property(&connector
->base
,
1155 disp
->dithering_depth
,
1156 nv_connector
->dithering_depth
);
1161 connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
;
1162 if (nv_connector
->hpd
.func
!= DCB_GPIO_UNUSED
)
1163 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
1165 drm_sysfs_connector_add(connector
);