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>
30 #include <drm/drm_edid.h>
31 #include <drm/drm_crtc_helper.h>
33 #include "nouveau_reg.h"
34 #include "nouveau_drm.h"
35 #include "dispnv04/hw.h"
36 #include "nouveau_acpi.h"
38 #include "nouveau_display.h"
39 #include "nouveau_connector.h"
40 #include "nouveau_encoder.h"
41 #include "nouveau_crtc.h"
43 #include <subdev/i2c.h>
44 #include <subdev/gpio.h>
46 MODULE_PARM_DESC(tv_disable
, "Disable TV-out detection");
47 static int nouveau_tv_disable
= 0;
48 module_param_named(tv_disable
, nouveau_tv_disable
, int, 0400);
50 MODULE_PARM_DESC(ignorelid
, "Ignore ACPI lid status");
51 static int nouveau_ignorelid
= 0;
52 module_param_named(ignorelid
, nouveau_ignorelid
, int, 0400);
54 MODULE_PARM_DESC(duallink
, "Allow dual-link TMDS (default: enabled)");
55 static int nouveau_duallink
= 1;
56 module_param_named(duallink
, nouveau_duallink
, int, 0400);
58 struct nouveau_encoder
*
59 find_encoder(struct drm_connector
*connector
, int type
)
61 struct drm_device
*dev
= connector
->dev
;
62 struct nouveau_encoder
*nv_encoder
;
63 struct drm_mode_object
*obj
;
66 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
67 id
= connector
->encoder_ids
[i
];
71 obj
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_ENCODER
);
74 nv_encoder
= nouveau_encoder(obj_to_encoder(obj
));
76 if (type
== DCB_OUTPUT_ANY
|| nv_encoder
->dcb
->type
== type
)
83 struct nouveau_connector
*
84 nouveau_encoder_connector_get(struct nouveau_encoder
*encoder
)
86 struct drm_device
*dev
= to_drm_encoder(encoder
)->dev
;
87 struct drm_connector
*drm_connector
;
89 list_for_each_entry(drm_connector
, &dev
->mode_config
.connector_list
, head
) {
90 if (drm_connector
->encoder
== to_drm_encoder(encoder
))
91 return nouveau_connector(drm_connector
);
98 nouveau_connector_destroy(struct drm_connector
*connector
)
100 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
101 kfree(nv_connector
->edid
);
102 drm_sysfs_connector_remove(connector
);
103 drm_connector_cleanup(connector
);
107 static struct nouveau_i2c_port
*
108 nouveau_connector_ddc_detect(struct drm_connector
*connector
,
109 struct nouveau_encoder
**pnv_encoder
)
111 struct drm_device
*dev
= connector
->dev
;
112 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
113 struct nouveau_drm
*drm
= nouveau_drm(dev
);
114 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
115 struct nouveau_i2c_port
*port
= NULL
;
116 int i
, panel
= -ENODEV
;
118 /* eDP panels need powering on by us (if the VBIOS doesn't default it
119 * to on) before doing any AUX channel transactions. LVDS panel power
120 * is handled by the SOR itself, and not required for LVDS DDC.
122 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
123 panel
= gpio
->get(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff);
125 gpio
->set(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff, 1);
130 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
131 struct nouveau_encoder
*nv_encoder
;
132 struct drm_mode_object
*obj
;
135 id
= connector
->encoder_ids
[i
];
139 obj
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_ENCODER
);
142 nv_encoder
= nouveau_encoder(obj_to_encoder(obj
));
144 port
= nv_encoder
->i2c
;
145 if (port
&& nv_probe_i2c(port
, 0x50)) {
146 *pnv_encoder
= nv_encoder
;
153 /* eDP panel not detected, restore panel power GPIO to previous
154 * state to avoid confusing the SOR for other output types.
156 if (!port
&& panel
== 0)
157 gpio
->set(gpio
, 0, DCB_GPIO_PANEL_POWER
, 0xff, panel
);
162 static struct nouveau_encoder
*
163 nouveau_connector_of_detect(struct drm_connector
*connector
)
166 struct drm_device
*dev
= connector
->dev
;
167 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
168 struct nouveau_encoder
*nv_encoder
;
169 struct device_node
*cn
, *dn
= pci_device_to_OF_node(dev
->pdev
);
172 !((nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TMDS
)) ||
173 (nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
))))
176 for_each_child_of_node(dn
, cn
) {
177 const char *name
= of_get_property(cn
, "name", NULL
);
178 const void *edid
= of_get_property(cn
, "EDID", NULL
);
179 int idx
= name
? name
[strlen(name
) - 1] - 'A' : 0;
181 if (nv_encoder
->dcb
->i2c_index
== idx
&& edid
) {
183 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
193 nouveau_connector_set_encoder(struct drm_connector
*connector
,
194 struct nouveau_encoder
*nv_encoder
)
196 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
197 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
198 struct drm_device
*dev
= connector
->dev
;
200 if (nv_connector
->detected_encoder
== nv_encoder
)
202 nv_connector
->detected_encoder
= nv_encoder
;
204 if (nv_device(drm
->device
)->card_type
>= NV_50
) {
205 connector
->interlace_allowed
= true;
206 connector
->doublescan_allowed
= true;
208 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
||
209 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
) {
210 connector
->doublescan_allowed
= false;
211 connector
->interlace_allowed
= false;
213 connector
->doublescan_allowed
= true;
214 if (nv_device(drm
->device
)->card_type
== NV_20
||
215 (nv_device(drm
->device
)->card_type
== NV_10
&&
216 (dev
->pci_device
& 0x0ff0) != 0x0100 &&
217 (dev
->pci_device
& 0x0ff0) != 0x0150))
219 connector
->interlace_allowed
= false;
221 connector
->interlace_allowed
= true;
224 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
225 drm_object_property_set_value(&connector
->base
,
226 dev
->mode_config
.dvi_i_subconnector_property
,
227 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
?
228 DRM_MODE_SUBCONNECTOR_DVID
:
229 DRM_MODE_SUBCONNECTOR_DVIA
);
233 static enum drm_connector_status
234 nouveau_connector_detect(struct drm_connector
*connector
, bool force
)
236 struct drm_device
*dev
= connector
->dev
;
237 struct nouveau_drm
*drm
= nouveau_drm(dev
);
238 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
239 struct nouveau_encoder
*nv_encoder
= NULL
;
240 struct nouveau_encoder
*nv_partner
;
241 struct nouveau_i2c_port
*i2c
;
244 /* Cleanup the previous EDID block. */
245 if (nv_connector
->edid
) {
246 drm_mode_connector_update_edid_property(connector
, NULL
);
247 kfree(nv_connector
->edid
);
248 nv_connector
->edid
= NULL
;
251 i2c
= nouveau_connector_ddc_detect(connector
, &nv_encoder
);
253 nv_connector
->edid
= drm_get_edid(connector
, &i2c
->adapter
);
254 drm_mode_connector_update_edid_property(connector
,
256 if (!nv_connector
->edid
) {
257 NV_ERROR(drm
, "DDC responded, but no EDID for %s\n",
258 drm_get_connector_name(connector
));
262 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
&&
263 !nouveau_dp_detect(to_drm_encoder(nv_encoder
))) {
264 NV_ERROR(drm
, "Detected %s, but failed init\n",
265 drm_get_connector_name(connector
));
266 return connector_status_disconnected
;
269 /* Override encoder type for DVI-I based on whether EDID
270 * says the display is digital or analog, both use the
271 * same i2c channel so the value returned from ddc_detect
272 * isn't necessarily correct.
275 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
)
276 nv_partner
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
277 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
)
278 nv_partner
= find_encoder(connector
, DCB_OUTPUT_TMDS
);
280 if (nv_partner
&& ((nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
&&
281 nv_partner
->dcb
->type
== DCB_OUTPUT_TMDS
) ||
282 (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
&&
283 nv_partner
->dcb
->type
== DCB_OUTPUT_ANALOG
))) {
284 if (nv_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
)
285 type
= DCB_OUTPUT_TMDS
;
287 type
= DCB_OUTPUT_ANALOG
;
289 nv_encoder
= find_encoder(connector
, type
);
292 nouveau_connector_set_encoder(connector
, nv_encoder
);
293 return connector_status_connected
;
296 nv_encoder
= nouveau_connector_of_detect(connector
);
298 nouveau_connector_set_encoder(connector
, nv_encoder
);
299 return connector_status_connected
;
303 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
304 if (!nv_encoder
&& !nouveau_tv_disable
)
305 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TV
);
306 if (nv_encoder
&& force
) {
307 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
308 struct drm_encoder_helper_funcs
*helper
=
309 encoder
->helper_private
;
311 if (helper
->detect(encoder
, connector
) ==
312 connector_status_connected
) {
313 nouveau_connector_set_encoder(connector
, nv_encoder
);
314 return connector_status_connected
;
319 return connector_status_disconnected
;
322 static enum drm_connector_status
323 nouveau_connector_detect_lvds(struct drm_connector
*connector
, bool force
)
325 struct drm_device
*dev
= connector
->dev
;
326 struct nouveau_drm
*drm
= nouveau_drm(dev
);
327 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
328 struct nouveau_encoder
*nv_encoder
= NULL
;
329 enum drm_connector_status status
= connector_status_disconnected
;
331 /* Cleanup the previous EDID block. */
332 if (nv_connector
->edid
) {
333 drm_mode_connector_update_edid_property(connector
, NULL
);
334 kfree(nv_connector
->edid
);
335 nv_connector
->edid
= NULL
;
338 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_LVDS
);
340 return connector_status_disconnected
;
342 /* Try retrieving EDID via DDC */
343 if (!drm
->vbios
.fp_no_ddc
) {
344 status
= nouveau_connector_detect(connector
, force
);
345 if (status
== connector_status_connected
)
349 /* On some laptops (Sony, i'm looking at you) there appears to
350 * be no direct way of accessing the panel's EDID. The only
351 * option available to us appears to be to ask ACPI for help..
353 * It's important this check's before trying straps, one of the
354 * said manufacturer's laptops are configured in such a way
355 * the nouveau decides an entry in the VBIOS FP mode table is
356 * valid - it's not (rh#613284)
358 if (nv_encoder
->dcb
->lvdsconf
.use_acpi_for_edid
) {
359 if ((nv_connector
->edid
= nouveau_acpi_edid(dev
, connector
))) {
360 status
= connector_status_connected
;
365 /* If no EDID found above, and the VBIOS indicates a hardcoded
366 * modeline is avalilable for the panel, set it as the panel's
367 * native mode and exit.
369 if (nouveau_bios_fp_mode(dev
, NULL
) && (drm
->vbios
.fp_no_ddc
||
370 nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
)) {
371 status
= connector_status_connected
;
375 /* Still nothing, some VBIOS images have a hardcoded EDID block
376 * stored for the panel stored in them.
378 if (!drm
->vbios
.fp_no_ddc
) {
380 (struct edid
*)nouveau_bios_embedded_edid(dev
);
383 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
384 if (nv_connector
->edid
)
385 status
= connector_status_connected
;
390 #if defined(CONFIG_ACPI_BUTTON) || \
391 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
392 if (status
== connector_status_connected
&&
393 !nouveau_ignorelid
&& !acpi_lid_open())
394 status
= connector_status_unknown
;
397 drm_mode_connector_update_edid_property(connector
, nv_connector
->edid
);
398 nouveau_connector_set_encoder(connector
, nv_encoder
);
403 nouveau_connector_force(struct drm_connector
*connector
)
405 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
406 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
407 struct nouveau_encoder
*nv_encoder
;
410 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
411 if (connector
->force
== DRM_FORCE_ON_DIGITAL
)
412 type
= DCB_OUTPUT_TMDS
;
414 type
= DCB_OUTPUT_ANALOG
;
416 type
= DCB_OUTPUT_ANY
;
418 nv_encoder
= find_encoder(connector
, type
);
420 NV_ERROR(drm
, "can't find encoder to force %s on!\n",
421 drm_get_connector_name(connector
));
422 connector
->status
= connector_status_disconnected
;
426 nouveau_connector_set_encoder(connector
, nv_encoder
);
430 nouveau_connector_set_property(struct drm_connector
*connector
,
431 struct drm_property
*property
, uint64_t value
)
433 struct nouveau_display
*disp
= nouveau_display(connector
->dev
);
434 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
435 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
436 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
437 struct drm_device
*dev
= connector
->dev
;
438 struct nouveau_crtc
*nv_crtc
;
442 if (connector
->encoder
&& connector
->encoder
->crtc
)
443 nv_crtc
= nouveau_crtc(connector
->encoder
->crtc
);
446 if (property
== dev
->mode_config
.scaling_mode_property
) {
447 bool modeset
= false;
450 case DRM_MODE_SCALE_NONE
:
451 case DRM_MODE_SCALE_FULLSCREEN
:
452 case DRM_MODE_SCALE_CENTER
:
453 case DRM_MODE_SCALE_ASPECT
:
459 /* LVDS always needs gpu scaling */
460 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
&&
461 value
== DRM_MODE_SCALE_NONE
)
464 /* Changing between GPU and panel scaling requires a full
467 if ((nv_connector
->scaling_mode
== DRM_MODE_SCALE_NONE
) ||
468 (value
== DRM_MODE_SCALE_NONE
))
470 nv_connector
->scaling_mode
= value
;
475 if (modeset
|| !nv_crtc
->set_scale
) {
476 ret
= drm_crtc_helper_set_mode(&nv_crtc
->base
,
479 nv_crtc
->base
.y
, NULL
);
483 ret
= nv_crtc
->set_scale(nv_crtc
, true);
492 if (property
== disp
->underscan_property
) {
493 if (nv_connector
->underscan
!= value
) {
494 nv_connector
->underscan
= value
;
495 if (!nv_crtc
|| !nv_crtc
->set_scale
)
498 return nv_crtc
->set_scale(nv_crtc
, true);
504 if (property
== disp
->underscan_hborder_property
) {
505 if (nv_connector
->underscan_hborder
!= value
) {
506 nv_connector
->underscan_hborder
= value
;
507 if (!nv_crtc
|| !nv_crtc
->set_scale
)
510 return nv_crtc
->set_scale(nv_crtc
, true);
516 if (property
== disp
->underscan_vborder_property
) {
517 if (nv_connector
->underscan_vborder
!= value
) {
518 nv_connector
->underscan_vborder
= value
;
519 if (!nv_crtc
|| !nv_crtc
->set_scale
)
522 return nv_crtc
->set_scale(nv_crtc
, true);
529 if (property
== disp
->dithering_mode
) {
530 nv_connector
->dithering_mode
= value
;
531 if (!nv_crtc
|| !nv_crtc
->set_dither
)
534 return nv_crtc
->set_dither(nv_crtc
, true);
537 if (property
== disp
->dithering_depth
) {
538 nv_connector
->dithering_depth
= value
;
539 if (!nv_crtc
|| !nv_crtc
->set_dither
)
542 return nv_crtc
->set_dither(nv_crtc
, true);
545 if (nv_crtc
&& nv_crtc
->set_color_vibrance
) {
547 if (property
== disp
->vibrant_hue_property
) {
548 nv_crtc
->vibrant_hue
= value
- 90;
549 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
552 if (property
== disp
->color_vibrance_property
) {
553 nv_crtc
->color_vibrance
= value
- 100;
554 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
558 if (nv_encoder
&& nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
559 return get_slave_funcs(encoder
)->set_property(
560 encoder
, connector
, property
, value
);
565 static struct drm_display_mode
*
566 nouveau_connector_native_mode(struct drm_connector
*connector
)
568 struct drm_connector_helper_funcs
*helper
= connector
->helper_private
;
569 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
570 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
571 struct drm_device
*dev
= connector
->dev
;
572 struct drm_display_mode
*mode
, *largest
= NULL
;
573 int high_w
= 0, high_h
= 0, high_v
= 0;
575 list_for_each_entry(mode
, &nv_connector
->base
.probed_modes
, head
) {
576 mode
->vrefresh
= drm_mode_vrefresh(mode
);
577 if (helper
->mode_valid(connector
, mode
) != MODE_OK
||
578 (mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
581 /* Use preferred mode if there is one.. */
582 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
) {
583 NV_DEBUG(drm
, "native mode from preferred\n");
584 return drm_mode_duplicate(dev
, mode
);
587 /* Otherwise, take the resolution with the largest width, then
588 * height, then vertical refresh
590 if (mode
->hdisplay
< high_w
)
593 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
< high_h
)
596 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
== high_h
&&
597 mode
->vrefresh
< high_v
)
600 high_w
= mode
->hdisplay
;
601 high_h
= mode
->vdisplay
;
602 high_v
= mode
->vrefresh
;
606 NV_DEBUG(drm
, "native mode from largest: %dx%d@%d\n",
607 high_w
, high_h
, high_v
);
608 return largest
? drm_mode_duplicate(dev
, largest
) : NULL
;
616 static struct moderec scaler_modes
[] = {
635 nouveau_connector_scaler_modes_add(struct drm_connector
*connector
)
637 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
638 struct drm_display_mode
*native
= nv_connector
->native_mode
, *m
;
639 struct drm_device
*dev
= connector
->dev
;
640 struct moderec
*mode
= &scaler_modes
[0];
646 while (mode
->hdisplay
) {
647 if (mode
->hdisplay
<= native
->hdisplay
&&
648 mode
->vdisplay
<= native
->vdisplay
) {
649 m
= drm_cvt_mode(dev
, mode
->hdisplay
, mode
->vdisplay
,
650 drm_mode_vrefresh(native
), false,
655 m
->type
|= DRM_MODE_TYPE_DRIVER
;
657 drm_mode_probed_add(connector
, m
);
668 nouveau_connector_detect_depth(struct drm_connector
*connector
)
670 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
671 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
672 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
673 struct nvbios
*bios
= &drm
->vbios
;
674 struct drm_display_mode
*mode
= nv_connector
->native_mode
;
677 /* if the edid is feeling nice enough to provide this info, use it */
678 if (nv_connector
->edid
&& connector
->display_info
.bpc
)
681 /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
682 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
683 connector
->display_info
.bpc
= 6;
687 /* we're out of options unless we're LVDS, default to 8bpc */
688 if (nv_encoder
->dcb
->type
!= DCB_OUTPUT_LVDS
) {
689 connector
->display_info
.bpc
= 8;
693 connector
->display_info
.bpc
= 6;
695 /* LVDS: panel straps */
696 if (bios
->fp_no_ddc
) {
697 if (bios
->fp
.if_is_24bit
)
698 connector
->display_info
.bpc
= 8;
702 /* LVDS: DDC panel, need to first determine the number of links to
703 * know which if_is_24bit flag to check...
705 if (nv_connector
->edid
&&
706 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
)
707 duallink
= ((u8
*)nv_connector
->edid
)[121] == 2;
709 duallink
= mode
->clock
>= bios
->fp
.duallink_transition_clk
;
711 if ((!duallink
&& (bios
->fp
.strapless_is_24bit
& 1)) ||
712 ( duallink
&& (bios
->fp
.strapless_is_24bit
& 2)))
713 connector
->display_info
.bpc
= 8;
717 nouveau_connector_get_modes(struct drm_connector
*connector
)
719 struct drm_device
*dev
= connector
->dev
;
720 struct nouveau_drm
*drm
= nouveau_drm(dev
);
721 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
722 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
723 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
726 /* destroy the native mode, the attached monitor could have changed.
728 if (nv_connector
->native_mode
) {
729 drm_mode_destroy(dev
, nv_connector
->native_mode
);
730 nv_connector
->native_mode
= NULL
;
733 if (nv_connector
->edid
)
734 ret
= drm_add_edid_modes(connector
, nv_connector
->edid
);
736 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
&&
737 (nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
||
738 drm
->vbios
.fp_no_ddc
) && nouveau_bios_fp_mode(dev
, NULL
)) {
739 struct drm_display_mode mode
;
741 nouveau_bios_fp_mode(dev
, &mode
);
742 nv_connector
->native_mode
= drm_mode_duplicate(dev
, &mode
);
745 /* Determine display colour depth for everything except LVDS now,
746 * DP requires this before mode_valid() is called.
748 if (connector
->connector_type
!= DRM_MODE_CONNECTOR_LVDS
)
749 nouveau_connector_detect_depth(connector
);
751 /* Find the native mode if this is a digital panel, if we didn't
752 * find any modes through DDC previously add the native mode to
755 if (!nv_connector
->native_mode
)
756 nv_connector
->native_mode
=
757 nouveau_connector_native_mode(connector
);
758 if (ret
== 0 && nv_connector
->native_mode
) {
759 struct drm_display_mode
*mode
;
761 mode
= drm_mode_duplicate(dev
, nv_connector
->native_mode
);
762 drm_mode_probed_add(connector
, mode
);
766 /* Determine LVDS colour depth, must happen after determining
767 * "native" mode as some VBIOS tables require us to use the
768 * pixel clock as part of the lookup...
770 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
)
771 nouveau_connector_detect_depth(connector
);
773 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
774 ret
= get_slave_funcs(encoder
)->get_modes(encoder
, connector
);
776 if (nv_connector
->type
== DCB_CONNECTOR_LVDS
||
777 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
||
778 nv_connector
->type
== DCB_CONNECTOR_eDP
)
779 ret
+= nouveau_connector_scaler_modes_add(connector
);
785 get_tmds_link_bandwidth(struct drm_connector
*connector
)
787 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
788 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
789 struct dcb_output
*dcb
= nv_connector
->detected_encoder
->dcb
;
791 if (dcb
->location
!= DCB_LOC_ON_CHIP
||
792 nv_device(drm
->device
)->chipset
>= 0x46)
794 else if (nv_device(drm
->device
)->chipset
>= 0x40)
796 else if (nv_device(drm
->device
)->chipset
>= 0x18)
803 nouveau_connector_mode_valid(struct drm_connector
*connector
,
804 struct drm_display_mode
*mode
)
806 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
807 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
808 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
809 unsigned min_clock
= 25000, max_clock
= min_clock
;
810 unsigned clock
= mode
->clock
;
812 switch (nv_encoder
->dcb
->type
) {
813 case DCB_OUTPUT_LVDS
:
814 if (nv_connector
->native_mode
&&
815 (mode
->hdisplay
> nv_connector
->native_mode
->hdisplay
||
816 mode
->vdisplay
> nv_connector
->native_mode
->vdisplay
))
822 case DCB_OUTPUT_TMDS
:
823 max_clock
= get_tmds_link_bandwidth(connector
);
824 if (nouveau_duallink
&& nv_encoder
->dcb
->duallink_possible
)
827 case DCB_OUTPUT_ANALOG
:
828 max_clock
= nv_encoder
->dcb
->crtconf
.maxfreq
;
833 return get_slave_funcs(encoder
)->mode_valid(encoder
, mode
);
835 max_clock
= nv_encoder
->dp
.link_nr
;
836 max_clock
*= nv_encoder
->dp
.link_bw
;
837 clock
= clock
* (connector
->display_info
.bpc
* 3) / 10;
844 if (clock
< min_clock
)
845 return MODE_CLOCK_LOW
;
847 if (clock
> max_clock
)
848 return MODE_CLOCK_HIGH
;
853 static struct drm_encoder
*
854 nouveau_connector_best_encoder(struct drm_connector
*connector
)
856 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
858 if (nv_connector
->detected_encoder
)
859 return to_drm_encoder(nv_connector
->detected_encoder
);
864 static const struct drm_connector_helper_funcs
865 nouveau_connector_helper_funcs
= {
866 .get_modes
= nouveau_connector_get_modes
,
867 .mode_valid
= nouveau_connector_mode_valid
,
868 .best_encoder
= nouveau_connector_best_encoder
,
871 static const struct drm_connector_funcs
872 nouveau_connector_funcs
= {
873 .dpms
= drm_helper_connector_dpms
,
876 .detect
= nouveau_connector_detect
,
877 .destroy
= nouveau_connector_destroy
,
878 .fill_modes
= drm_helper_probe_single_connector_modes
,
879 .set_property
= nouveau_connector_set_property
,
880 .force
= nouveau_connector_force
883 static const struct drm_connector_funcs
884 nouveau_connector_funcs_lvds
= {
885 .dpms
= drm_helper_connector_dpms
,
888 .detect
= nouveau_connector_detect_lvds
,
889 .destroy
= nouveau_connector_destroy
,
890 .fill_modes
= drm_helper_probe_single_connector_modes
,
891 .set_property
= nouveau_connector_set_property
,
892 .force
= nouveau_connector_force
896 nouveau_connector_hotplug_work(struct work_struct
*work
)
898 struct nouveau_connector
*nv_connector
=
899 container_of(work
, struct nouveau_connector
, hpd_work
);
900 struct drm_connector
*connector
= &nv_connector
->base
;
901 struct drm_device
*dev
= connector
->dev
;
902 struct nouveau_drm
*drm
= nouveau_drm(dev
);
903 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
904 bool plugged
= gpio
->get(gpio
, 0, nv_connector
->hpd
.func
, 0xff);
906 NV_DEBUG(drm
, "%splugged %s\n", plugged
? "" : "un",
907 drm_get_connector_name(connector
));
910 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_ON
);
912 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
914 drm_helper_hpd_irq_event(dev
);
918 nouveau_connector_hotplug(struct nouveau_eventh
*event
, int index
)
920 struct nouveau_connector
*nv_connector
=
921 container_of(event
, struct nouveau_connector
, hpd_func
);
922 schedule_work(&nv_connector
->hpd_work
);
923 return NVKM_EVENT_KEEP
;
927 drm_conntype_from_dcb(enum dcb_connector_type dcb
)
930 case DCB_CONNECTOR_VGA
: return DRM_MODE_CONNECTOR_VGA
;
931 case DCB_CONNECTOR_TV_0
:
932 case DCB_CONNECTOR_TV_1
:
933 case DCB_CONNECTOR_TV_3
: return DRM_MODE_CONNECTOR_TV
;
934 case DCB_CONNECTOR_DMS59_0
:
935 case DCB_CONNECTOR_DMS59_1
:
936 case DCB_CONNECTOR_DVI_I
: return DRM_MODE_CONNECTOR_DVII
;
937 case DCB_CONNECTOR_DVI_D
: return DRM_MODE_CONNECTOR_DVID
;
938 case DCB_CONNECTOR_LVDS
:
939 case DCB_CONNECTOR_LVDS_SPWG
: return DRM_MODE_CONNECTOR_LVDS
;
940 case DCB_CONNECTOR_DMS59_DP0
:
941 case DCB_CONNECTOR_DMS59_DP1
:
942 case DCB_CONNECTOR_DP
: return DRM_MODE_CONNECTOR_DisplayPort
;
943 case DCB_CONNECTOR_eDP
: return DRM_MODE_CONNECTOR_eDP
;
944 case DCB_CONNECTOR_HDMI_0
:
945 case DCB_CONNECTOR_HDMI_1
: return DRM_MODE_CONNECTOR_HDMIA
;
950 return DRM_MODE_CONNECTOR_Unknown
;
953 struct drm_connector
*
954 nouveau_connector_create(struct drm_device
*dev
, int index
)
956 const struct drm_connector_funcs
*funcs
= &nouveau_connector_funcs
;
957 struct nouveau_drm
*drm
= nouveau_drm(dev
);
958 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
959 struct nouveau_display
*disp
= nouveau_display(dev
);
960 struct nouveau_connector
*nv_connector
= NULL
;
961 struct drm_connector
*connector
;
965 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
966 nv_connector
= nouveau_connector(connector
);
967 if (nv_connector
->index
== index
)
971 nv_connector
= kzalloc(sizeof(*nv_connector
), GFP_KERNEL
);
973 return ERR_PTR(-ENOMEM
);
975 connector
= &nv_connector
->base
;
976 INIT_WORK(&nv_connector
->hpd_work
, nouveau_connector_hotplug_work
);
977 nv_connector
->index
= index
;
979 /* attempt to parse vbios connector type and hotplug gpio */
980 nv_connector
->dcb
= olddcb_conn(dev
, index
);
981 if (nv_connector
->dcb
) {
982 static const u8 hpd
[16] = {
983 0xff, 0x07, 0x08, 0xff, 0xff, 0x51, 0x52, 0xff,
984 0xff, 0xff, 0xff, 0xff, 0xff, 0x5e, 0x5f, 0x60,
987 u32 entry
= ROM16(nv_connector
->dcb
[0]);
988 if (olddcb_conntab(dev
)[3] >= 4)
989 entry
|= (u32
)ROM16(nv_connector
->dcb
[2]) << 16;
991 ret
= gpio
->find(gpio
, 0, hpd
[ffs((entry
& 0x07033000) >> 12)],
992 DCB_GPIO_UNUSED
, &nv_connector
->hpd
);
993 nv_connector
->hpd_func
.func
= nouveau_connector_hotplug
;
995 nv_connector
->hpd
.func
= DCB_GPIO_UNUSED
;
997 nv_connector
->type
= nv_connector
->dcb
[0];
998 if (drm_conntype_from_dcb(nv_connector
->type
) ==
999 DRM_MODE_CONNECTOR_Unknown
) {
1000 NV_WARN(drm
, "unknown connector type %02x\n",
1001 nv_connector
->type
);
1002 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1005 /* Gigabyte NX85T */
1006 if (nv_match_device(dev
, 0x0421, 0x1458, 0x344c)) {
1007 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1008 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1011 /* Gigabyte GV-NX86T512H */
1012 if (nv_match_device(dev
, 0x0402, 0x1458, 0x3455)) {
1013 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
1014 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1017 nv_connector
->type
= DCB_CONNECTOR_NONE
;
1018 nv_connector
->hpd
.func
= DCB_GPIO_UNUSED
;
1021 /* no vbios data, or an unknown dcb connector type - attempt to
1022 * figure out something suitable ourselves
1024 if (nv_connector
->type
== DCB_CONNECTOR_NONE
) {
1025 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1026 struct dcb_table
*dcbt
= &drm
->vbios
.dcb
;
1030 for (i
= 0; i
< dcbt
->entries
; i
++) {
1031 if (dcbt
->entry
[i
].connector
== nv_connector
->index
)
1032 encoders
|= (1 << dcbt
->entry
[i
].type
);
1035 if (encoders
& (1 << DCB_OUTPUT_DP
)) {
1036 if (encoders
& (1 << DCB_OUTPUT_TMDS
))
1037 nv_connector
->type
= DCB_CONNECTOR_DP
;
1039 nv_connector
->type
= DCB_CONNECTOR_eDP
;
1041 if (encoders
& (1 << DCB_OUTPUT_TMDS
)) {
1042 if (encoders
& (1 << DCB_OUTPUT_ANALOG
))
1043 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1045 nv_connector
->type
= DCB_CONNECTOR_DVI_D
;
1047 if (encoders
& (1 << DCB_OUTPUT_ANALOG
)) {
1048 nv_connector
->type
= DCB_CONNECTOR_VGA
;
1050 if (encoders
& (1 << DCB_OUTPUT_LVDS
)) {
1051 nv_connector
->type
= DCB_CONNECTOR_LVDS
;
1053 if (encoders
& (1 << DCB_OUTPUT_TV
)) {
1054 nv_connector
->type
= DCB_CONNECTOR_TV_0
;
1058 type
= drm_conntype_from_dcb(nv_connector
->type
);
1059 if (type
== DRM_MODE_CONNECTOR_LVDS
) {
1060 ret
= nouveau_bios_parse_lvds_table(dev
, 0, &dummy
, &dummy
);
1062 NV_ERROR(drm
, "Error parsing LVDS table, disabling\n");
1063 kfree(nv_connector
);
1064 return ERR_PTR(ret
);
1067 funcs
= &nouveau_connector_funcs_lvds
;
1069 funcs
= &nouveau_connector_funcs
;
1072 /* defaults, will get overridden in detect() */
1073 connector
->interlace_allowed
= false;
1074 connector
->doublescan_allowed
= false;
1076 drm_connector_init(dev
, connector
, funcs
, type
);
1077 drm_connector_helper_add(connector
, &nouveau_connector_helper_funcs
);
1079 /* Init DVI-I specific properties */
1080 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
)
1081 drm_object_attach_property(&connector
->base
, dev
->mode_config
.dvi_i_subconnector_property
, 0);
1083 /* Add overscan compensation options to digital outputs */
1084 if (disp
->underscan_property
&&
1085 (type
== DRM_MODE_CONNECTOR_DVID
||
1086 type
== DRM_MODE_CONNECTOR_DVII
||
1087 type
== DRM_MODE_CONNECTOR_HDMIA
||
1088 type
== DRM_MODE_CONNECTOR_DisplayPort
)) {
1089 drm_object_attach_property(&connector
->base
,
1090 disp
->underscan_property
,
1092 drm_object_attach_property(&connector
->base
,
1093 disp
->underscan_hborder_property
,
1095 drm_object_attach_property(&connector
->base
,
1096 disp
->underscan_vborder_property
,
1100 /* Add hue and saturation options */
1101 if (disp
->vibrant_hue_property
)
1102 drm_object_attach_property(&connector
->base
,
1103 disp
->vibrant_hue_property
,
1105 if (disp
->color_vibrance_property
)
1106 drm_object_attach_property(&connector
->base
,
1107 disp
->color_vibrance_property
,
1110 switch (nv_connector
->type
) {
1111 case DCB_CONNECTOR_VGA
:
1112 if (nv_device(drm
->device
)->card_type
>= NV_50
) {
1113 drm_object_attach_property(&connector
->base
,
1114 dev
->mode_config
.scaling_mode_property
,
1115 nv_connector
->scaling_mode
);
1118 case DCB_CONNECTOR_TV_0
:
1119 case DCB_CONNECTOR_TV_1
:
1120 case DCB_CONNECTOR_TV_3
:
1121 nv_connector
->scaling_mode
= DRM_MODE_SCALE_NONE
;
1124 nv_connector
->scaling_mode
= DRM_MODE_SCALE_FULLSCREEN
;
1126 drm_object_attach_property(&connector
->base
,
1127 dev
->mode_config
.scaling_mode_property
,
1128 nv_connector
->scaling_mode
);
1129 if (disp
->dithering_mode
) {
1130 nv_connector
->dithering_mode
= DITHERING_MODE_AUTO
;
1131 drm_object_attach_property(&connector
->base
,
1132 disp
->dithering_mode
,
1133 nv_connector
->dithering_mode
);
1135 if (disp
->dithering_depth
) {
1136 nv_connector
->dithering_depth
= DITHERING_DEPTH_AUTO
;
1137 drm_object_attach_property(&connector
->base
,
1138 disp
->dithering_depth
,
1139 nv_connector
->dithering_depth
);
1144 connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
;
1145 if (nv_connector
->hpd
.func
!= DCB_GPIO_UNUSED
)
1146 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
1148 drm_sysfs_connector_add(connector
);