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 "nouveau_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 static void nouveau_connector_hotplug(void *, int);
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 struct nouveau_gpio
*gpio
;
104 struct nouveau_drm
*drm
;
105 struct drm_device
*dev
;
110 dev
= nv_connector
->base
.dev
;
111 drm
= nouveau_drm(dev
);
112 gpio
= nouveau_gpio(drm
->device
);
115 if (gpio
&& nv_connector
->hpd
!= DCB_GPIO_UNUSED
) {
116 gpio
->isr_del(gpio
, 0, nv_connector
->hpd
, 0xff,
117 nouveau_connector_hotplug
, connector
);
120 kfree(nv_connector
->edid
);
121 drm_sysfs_connector_remove(connector
);
122 drm_connector_cleanup(connector
);
126 static struct nouveau_i2c_port
*
127 nouveau_connector_ddc_detect(struct drm_connector
*connector
,
128 struct nouveau_encoder
**pnv_encoder
)
130 struct drm_device
*dev
= connector
->dev
;
131 struct nouveau_drm
*drm
= nouveau_drm(dev
);
132 struct nouveau_i2c
*i2c
= nouveau_i2c(drm
->device
);
135 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
136 struct nouveau_i2c_port
*port
= NULL
;
137 struct nouveau_encoder
*nv_encoder
;
138 struct drm_mode_object
*obj
;
141 id
= connector
->encoder_ids
[i
];
145 obj
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_ENCODER
);
148 nv_encoder
= nouveau_encoder(obj_to_encoder(obj
));
150 if (nv_encoder
->dcb
->i2c_index
< 0xf)
151 port
= i2c
->find(i2c
, nv_encoder
->dcb
->i2c_index
);
152 if (port
&& nv_probe_i2c(port
, 0x50)) {
153 *pnv_encoder
= nv_encoder
;
161 static struct nouveau_encoder
*
162 nouveau_connector_of_detect(struct drm_connector
*connector
)
165 struct drm_device
*dev
= connector
->dev
;
166 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
167 struct nouveau_encoder
*nv_encoder
;
168 struct device_node
*cn
, *dn
= pci_device_to_OF_node(dev
->pdev
);
171 !((nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TMDS
)) ||
172 (nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
))))
175 for_each_child_of_node(dn
, cn
) {
176 const char *name
= of_get_property(cn
, "name", NULL
);
177 const void *edid
= of_get_property(cn
, "EDID", NULL
);
178 int idx
= name
? name
[strlen(name
) - 1] - 'A' : 0;
180 if (nv_encoder
->dcb
->i2c_index
== idx
&& edid
) {
182 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
192 nouveau_connector_set_encoder(struct drm_connector
*connector
,
193 struct nouveau_encoder
*nv_encoder
)
195 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
196 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
197 struct drm_device
*dev
= connector
->dev
;
199 if (nv_connector
->detected_encoder
== nv_encoder
)
201 nv_connector
->detected_encoder
= nv_encoder
;
203 if (nv_device(drm
->device
)->card_type
>= NV_50
) {
204 connector
->interlace_allowed
= true;
205 connector
->doublescan_allowed
= true;
207 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
||
208 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
) {
209 connector
->doublescan_allowed
= false;
210 connector
->interlace_allowed
= false;
212 connector
->doublescan_allowed
= true;
213 if (nv_device(drm
->device
)->card_type
== NV_20
||
214 (nv_device(drm
->device
)->card_type
== NV_10
&&
215 (dev
->pci_device
& 0x0ff0) != 0x0100 &&
216 (dev
->pci_device
& 0x0ff0) != 0x0150))
218 connector
->interlace_allowed
= false;
220 connector
->interlace_allowed
= true;
223 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
224 drm_connector_property_set_value(connector
,
225 dev
->mode_config
.dvi_i_subconnector_property
,
226 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
?
227 DRM_MODE_SUBCONNECTOR_DVID
:
228 DRM_MODE_SUBCONNECTOR_DVIA
);
232 static enum drm_connector_status
233 nouveau_connector_detect(struct drm_connector
*connector
, bool force
)
235 struct drm_device
*dev
= connector
->dev
;
236 struct nouveau_drm
*drm
= nouveau_drm(dev
);
237 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
238 struct nouveau_encoder
*nv_encoder
= NULL
;
239 struct nouveau_encoder
*nv_partner
;
240 struct nouveau_i2c_port
*i2c
;
243 /* Cleanup the previous EDID block. */
244 if (nv_connector
->edid
) {
245 drm_mode_connector_update_edid_property(connector
, NULL
);
246 kfree(nv_connector
->edid
);
247 nv_connector
->edid
= NULL
;
250 i2c
= nouveau_connector_ddc_detect(connector
, &nv_encoder
);
252 nv_connector
->edid
= drm_get_edid(connector
, &i2c
->adapter
);
253 drm_mode_connector_update_edid_property(connector
,
255 if (!nv_connector
->edid
) {
256 NV_ERROR(drm
, "DDC responded, but no EDID for %s\n",
257 drm_get_connector_name(connector
));
261 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
&&
262 !nouveau_dp_detect(to_drm_encoder(nv_encoder
))) {
263 NV_ERROR(drm
, "Detected %s, but failed init\n",
264 drm_get_connector_name(connector
));
265 return connector_status_disconnected
;
268 /* Override encoder type for DVI-I based on whether EDID
269 * says the display is digital or analog, both use the
270 * same i2c channel so the value returned from ddc_detect
271 * isn't necessarily correct.
274 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
)
275 nv_partner
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
276 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
)
277 nv_partner
= find_encoder(connector
, DCB_OUTPUT_TMDS
);
279 if (nv_partner
&& ((nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
&&
280 nv_partner
->dcb
->type
== DCB_OUTPUT_TMDS
) ||
281 (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
&&
282 nv_partner
->dcb
->type
== DCB_OUTPUT_ANALOG
))) {
283 if (nv_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
)
284 type
= DCB_OUTPUT_TMDS
;
286 type
= DCB_OUTPUT_ANALOG
;
288 nv_encoder
= find_encoder(connector
, type
);
291 nouveau_connector_set_encoder(connector
, nv_encoder
);
292 return connector_status_connected
;
295 nv_encoder
= nouveau_connector_of_detect(connector
);
297 nouveau_connector_set_encoder(connector
, nv_encoder
);
298 return connector_status_connected
;
302 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
303 if (!nv_encoder
&& !nouveau_tv_disable
)
304 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TV
);
305 if (nv_encoder
&& force
) {
306 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
307 struct drm_encoder_helper_funcs
*helper
=
308 encoder
->helper_private
;
310 if (helper
->detect(encoder
, connector
) ==
311 connector_status_connected
) {
312 nouveau_connector_set_encoder(connector
, nv_encoder
);
313 return connector_status_connected
;
318 return connector_status_disconnected
;
321 static enum drm_connector_status
322 nouveau_connector_detect_lvds(struct drm_connector
*connector
, bool force
)
324 struct drm_device
*dev
= connector
->dev
;
325 struct nouveau_drm
*drm
= nouveau_drm(dev
);
326 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
327 struct nouveau_encoder
*nv_encoder
= NULL
;
328 enum drm_connector_status status
= connector_status_disconnected
;
330 /* Cleanup the previous EDID block. */
331 if (nv_connector
->edid
) {
332 drm_mode_connector_update_edid_property(connector
, NULL
);
333 kfree(nv_connector
->edid
);
334 nv_connector
->edid
= NULL
;
337 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_LVDS
);
339 return connector_status_disconnected
;
341 /* Try retrieving EDID via DDC */
342 if (!drm
->vbios
.fp_no_ddc
) {
343 status
= nouveau_connector_detect(connector
, force
);
344 if (status
== connector_status_connected
)
348 /* On some laptops (Sony, i'm looking at you) there appears to
349 * be no direct way of accessing the panel's EDID. The only
350 * option available to us appears to be to ask ACPI for help..
352 * It's important this check's before trying straps, one of the
353 * said manufacturer's laptops are configured in such a way
354 * the nouveau decides an entry in the VBIOS FP mode table is
355 * valid - it's not (rh#613284)
357 if (nv_encoder
->dcb
->lvdsconf
.use_acpi_for_edid
) {
358 if ((nv_connector
->edid
= nouveau_acpi_edid(dev
, connector
))) {
359 status
= connector_status_connected
;
364 /* If no EDID found above, and the VBIOS indicates a hardcoded
365 * modeline is avalilable for the panel, set it as the panel's
366 * native mode and exit.
368 if (nouveau_bios_fp_mode(dev
, NULL
) && (drm
->vbios
.fp_no_ddc
||
369 nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
)) {
370 status
= connector_status_connected
;
374 /* Still nothing, some VBIOS images have a hardcoded EDID block
375 * stored for the panel stored in them.
377 if (!drm
->vbios
.fp_no_ddc
) {
379 (struct edid
*)nouveau_bios_embedded_edid(dev
);
381 nv_connector
->edid
= kmalloc(EDID_LENGTH
, GFP_KERNEL
);
382 *(nv_connector
->edid
) = *edid
;
383 status
= connector_status_connected
;
388 #if defined(CONFIG_ACPI_BUTTON) || \
389 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
390 if (status
== connector_status_connected
&&
391 !nouveau_ignorelid
&& !acpi_lid_open())
392 status
= connector_status_unknown
;
395 drm_mode_connector_update_edid_property(connector
, nv_connector
->edid
);
396 nouveau_connector_set_encoder(connector
, nv_encoder
);
401 nouveau_connector_force(struct drm_connector
*connector
)
403 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
404 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
405 struct nouveau_encoder
*nv_encoder
;
408 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
409 if (connector
->force
== DRM_FORCE_ON_DIGITAL
)
410 type
= DCB_OUTPUT_TMDS
;
412 type
= DCB_OUTPUT_ANALOG
;
414 type
= DCB_OUTPUT_ANY
;
416 nv_encoder
= find_encoder(connector
, type
);
418 NV_ERROR(drm
, "can't find encoder to force %s on!\n",
419 drm_get_connector_name(connector
));
420 connector
->status
= connector_status_disconnected
;
424 nouveau_connector_set_encoder(connector
, nv_encoder
);
428 nouveau_connector_set_property(struct drm_connector
*connector
,
429 struct drm_property
*property
, uint64_t value
)
431 struct nouveau_display
*disp
= nouveau_display(connector
->dev
);
432 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
433 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
434 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
435 struct drm_device
*dev
= connector
->dev
;
436 struct nouveau_crtc
*nv_crtc
;
440 if (connector
->encoder
&& connector
->encoder
->crtc
)
441 nv_crtc
= nouveau_crtc(connector
->encoder
->crtc
);
444 if (property
== dev
->mode_config
.scaling_mode_property
) {
445 bool modeset
= false;
448 case DRM_MODE_SCALE_NONE
:
449 case DRM_MODE_SCALE_FULLSCREEN
:
450 case DRM_MODE_SCALE_CENTER
:
451 case DRM_MODE_SCALE_ASPECT
:
457 /* LVDS always needs gpu scaling */
458 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
&&
459 value
== DRM_MODE_SCALE_NONE
)
462 /* Changing between GPU and panel scaling requires a full
465 if ((nv_connector
->scaling_mode
== DRM_MODE_SCALE_NONE
) ||
466 (value
== DRM_MODE_SCALE_NONE
))
468 nv_connector
->scaling_mode
= value
;
473 if (modeset
|| !nv_crtc
->set_scale
) {
474 ret
= drm_crtc_helper_set_mode(&nv_crtc
->base
,
477 nv_crtc
->base
.y
, NULL
);
481 ret
= nv_crtc
->set_scale(nv_crtc
, true);
490 if (property
== disp
->underscan_property
) {
491 if (nv_connector
->underscan
!= value
) {
492 nv_connector
->underscan
= value
;
493 if (!nv_crtc
|| !nv_crtc
->set_scale
)
496 return nv_crtc
->set_scale(nv_crtc
, true);
502 if (property
== disp
->underscan_hborder_property
) {
503 if (nv_connector
->underscan_hborder
!= value
) {
504 nv_connector
->underscan_hborder
= value
;
505 if (!nv_crtc
|| !nv_crtc
->set_scale
)
508 return nv_crtc
->set_scale(nv_crtc
, true);
514 if (property
== disp
->underscan_vborder_property
) {
515 if (nv_connector
->underscan_vborder
!= value
) {
516 nv_connector
->underscan_vborder
= value
;
517 if (!nv_crtc
|| !nv_crtc
->set_scale
)
520 return nv_crtc
->set_scale(nv_crtc
, true);
527 if (property
== disp
->dithering_mode
) {
528 nv_connector
->dithering_mode
= value
;
529 if (!nv_crtc
|| !nv_crtc
->set_dither
)
532 return nv_crtc
->set_dither(nv_crtc
, true);
535 if (property
== disp
->dithering_depth
) {
536 nv_connector
->dithering_depth
= value
;
537 if (!nv_crtc
|| !nv_crtc
->set_dither
)
540 return nv_crtc
->set_dither(nv_crtc
, true);
543 if (nv_crtc
&& nv_crtc
->set_color_vibrance
) {
545 if (property
== disp
->vibrant_hue_property
) {
546 nv_crtc
->vibrant_hue
= value
- 90;
547 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
550 if (property
== disp
->color_vibrance_property
) {
551 nv_crtc
->color_vibrance
= value
- 100;
552 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
556 if (nv_encoder
&& nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
557 return get_slave_funcs(encoder
)->set_property(
558 encoder
, connector
, property
, value
);
563 static struct drm_display_mode
*
564 nouveau_connector_native_mode(struct drm_connector
*connector
)
566 struct drm_connector_helper_funcs
*helper
= connector
->helper_private
;
567 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
568 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
569 struct drm_device
*dev
= connector
->dev
;
570 struct drm_display_mode
*mode
, *largest
= NULL
;
571 int high_w
= 0, high_h
= 0, high_v
= 0;
573 list_for_each_entry(mode
, &nv_connector
->base
.probed_modes
, head
) {
574 mode
->vrefresh
= drm_mode_vrefresh(mode
);
575 if (helper
->mode_valid(connector
, mode
) != MODE_OK
||
576 (mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
579 /* Use preferred mode if there is one.. */
580 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
) {
581 NV_DEBUG(drm
, "native mode from preferred\n");
582 return drm_mode_duplicate(dev
, mode
);
585 /* Otherwise, take the resolution with the largest width, then
586 * height, then vertical refresh
588 if (mode
->hdisplay
< high_w
)
591 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
< high_h
)
594 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
== high_h
&&
595 mode
->vrefresh
< high_v
)
598 high_w
= mode
->hdisplay
;
599 high_h
= mode
->vdisplay
;
600 high_v
= mode
->vrefresh
;
604 NV_DEBUG(drm
, "native mode from largest: %dx%d@%d\n",
605 high_w
, high_h
, high_v
);
606 return largest
? drm_mode_duplicate(dev
, largest
) : NULL
;
614 static struct moderec scaler_modes
[] = {
633 nouveau_connector_scaler_modes_add(struct drm_connector
*connector
)
635 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
636 struct drm_display_mode
*native
= nv_connector
->native_mode
, *m
;
637 struct drm_device
*dev
= connector
->dev
;
638 struct moderec
*mode
= &scaler_modes
[0];
644 while (mode
->hdisplay
) {
645 if (mode
->hdisplay
<= native
->hdisplay
&&
646 mode
->vdisplay
<= native
->vdisplay
) {
647 m
= drm_cvt_mode(dev
, mode
->hdisplay
, mode
->vdisplay
,
648 drm_mode_vrefresh(native
), false,
653 m
->type
|= DRM_MODE_TYPE_DRIVER
;
655 drm_mode_probed_add(connector
, m
);
666 nouveau_connector_detect_depth(struct drm_connector
*connector
)
668 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
669 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
670 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
671 struct nvbios
*bios
= &drm
->vbios
;
672 struct drm_display_mode
*mode
= nv_connector
->native_mode
;
675 /* if the edid is feeling nice enough to provide this info, use it */
676 if (nv_connector
->edid
&& connector
->display_info
.bpc
)
679 /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
680 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
681 connector
->display_info
.bpc
= 6;
685 /* we're out of options unless we're LVDS, default to 8bpc */
686 if (nv_encoder
->dcb
->type
!= DCB_OUTPUT_LVDS
) {
687 connector
->display_info
.bpc
= 8;
691 connector
->display_info
.bpc
= 6;
693 /* LVDS: panel straps */
694 if (bios
->fp_no_ddc
) {
695 if (bios
->fp
.if_is_24bit
)
696 connector
->display_info
.bpc
= 8;
700 /* LVDS: DDC panel, need to first determine the number of links to
701 * know which if_is_24bit flag to check...
703 if (nv_connector
->edid
&&
704 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
)
705 duallink
= ((u8
*)nv_connector
->edid
)[121] == 2;
707 duallink
= mode
->clock
>= bios
->fp
.duallink_transition_clk
;
709 if ((!duallink
&& (bios
->fp
.strapless_is_24bit
& 1)) ||
710 ( duallink
&& (bios
->fp
.strapless_is_24bit
& 2)))
711 connector
->display_info
.bpc
= 8;
715 nouveau_connector_get_modes(struct drm_connector
*connector
)
717 struct drm_device
*dev
= connector
->dev
;
718 struct nouveau_drm
*drm
= nouveau_drm(dev
);
719 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
720 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
721 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
724 /* destroy the native mode, the attached monitor could have changed.
726 if (nv_connector
->native_mode
) {
727 drm_mode_destroy(dev
, nv_connector
->native_mode
);
728 nv_connector
->native_mode
= NULL
;
731 if (nv_connector
->edid
)
732 ret
= drm_add_edid_modes(connector
, nv_connector
->edid
);
734 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
&&
735 (nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
||
736 drm
->vbios
.fp_no_ddc
) && nouveau_bios_fp_mode(dev
, NULL
)) {
737 struct drm_display_mode mode
;
739 nouveau_bios_fp_mode(dev
, &mode
);
740 nv_connector
->native_mode
= drm_mode_duplicate(dev
, &mode
);
743 /* Determine display colour depth for everything except LVDS now,
744 * DP requires this before mode_valid() is called.
746 if (connector
->connector_type
!= DRM_MODE_CONNECTOR_LVDS
)
747 nouveau_connector_detect_depth(connector
);
749 /* Find the native mode if this is a digital panel, if we didn't
750 * find any modes through DDC previously add the native mode to
753 if (!nv_connector
->native_mode
)
754 nv_connector
->native_mode
=
755 nouveau_connector_native_mode(connector
);
756 if (ret
== 0 && nv_connector
->native_mode
) {
757 struct drm_display_mode
*mode
;
759 mode
= drm_mode_duplicate(dev
, nv_connector
->native_mode
);
760 drm_mode_probed_add(connector
, mode
);
764 /* Determine LVDS colour depth, must happen after determining
765 * "native" mode as some VBIOS tables require us to use the
766 * pixel clock as part of the lookup...
768 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
)
769 nouveau_connector_detect_depth(connector
);
771 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
772 ret
= get_slave_funcs(encoder
)->get_modes(encoder
, connector
);
774 if (nv_connector
->type
== DCB_CONNECTOR_LVDS
||
775 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
||
776 nv_connector
->type
== DCB_CONNECTOR_eDP
)
777 ret
+= nouveau_connector_scaler_modes_add(connector
);
783 get_tmds_link_bandwidth(struct drm_connector
*connector
)
785 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
786 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
787 struct dcb_output
*dcb
= nv_connector
->detected_encoder
->dcb
;
789 if (dcb
->location
!= DCB_LOC_ON_CHIP
||
790 nv_device(drm
->device
)->chipset
>= 0x46)
792 else if (nv_device(drm
->device
)->chipset
>= 0x40)
794 else if (nv_device(drm
->device
)->chipset
>= 0x18)
801 nouveau_connector_mode_valid(struct drm_connector
*connector
,
802 struct drm_display_mode
*mode
)
804 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
805 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
806 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
807 unsigned min_clock
= 25000, max_clock
= min_clock
;
808 unsigned clock
= mode
->clock
;
810 switch (nv_encoder
->dcb
->type
) {
811 case DCB_OUTPUT_LVDS
:
812 if (nv_connector
->native_mode
&&
813 (mode
->hdisplay
> nv_connector
->native_mode
->hdisplay
||
814 mode
->vdisplay
> nv_connector
->native_mode
->vdisplay
))
820 case DCB_OUTPUT_TMDS
:
821 max_clock
= get_tmds_link_bandwidth(connector
);
822 if (nouveau_duallink
&& nv_encoder
->dcb
->duallink_possible
)
825 case DCB_OUTPUT_ANALOG
:
826 max_clock
= nv_encoder
->dcb
->crtconf
.maxfreq
;
831 return get_slave_funcs(encoder
)->mode_valid(encoder
, mode
);
833 max_clock
= nv_encoder
->dp
.link_nr
;
834 max_clock
*= nv_encoder
->dp
.link_bw
;
835 clock
= clock
* (connector
->display_info
.bpc
* 3) / 10;
842 if (clock
< min_clock
)
843 return MODE_CLOCK_LOW
;
845 if (clock
> max_clock
)
846 return MODE_CLOCK_HIGH
;
851 static struct drm_encoder
*
852 nouveau_connector_best_encoder(struct drm_connector
*connector
)
854 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
856 if (nv_connector
->detected_encoder
)
857 return to_drm_encoder(nv_connector
->detected_encoder
);
862 static const struct drm_connector_helper_funcs
863 nouveau_connector_helper_funcs
= {
864 .get_modes
= nouveau_connector_get_modes
,
865 .mode_valid
= nouveau_connector_mode_valid
,
866 .best_encoder
= nouveau_connector_best_encoder
,
869 static const struct drm_connector_funcs
870 nouveau_connector_funcs
= {
871 .dpms
= drm_helper_connector_dpms
,
874 .detect
= nouveau_connector_detect
,
875 .destroy
= nouveau_connector_destroy
,
876 .fill_modes
= drm_helper_probe_single_connector_modes
,
877 .set_property
= nouveau_connector_set_property
,
878 .force
= nouveau_connector_force
881 static const struct drm_connector_funcs
882 nouveau_connector_funcs_lvds
= {
883 .dpms
= drm_helper_connector_dpms
,
886 .detect
= nouveau_connector_detect_lvds
,
887 .destroy
= nouveau_connector_destroy
,
888 .fill_modes
= drm_helper_probe_single_connector_modes
,
889 .set_property
= nouveau_connector_set_property
,
890 .force
= nouveau_connector_force
894 drm_conntype_from_dcb(enum dcb_connector_type dcb
)
897 case DCB_CONNECTOR_VGA
: return DRM_MODE_CONNECTOR_VGA
;
898 case DCB_CONNECTOR_TV_0
:
899 case DCB_CONNECTOR_TV_1
:
900 case DCB_CONNECTOR_TV_3
: return DRM_MODE_CONNECTOR_TV
;
901 case DCB_CONNECTOR_DMS59_0
:
902 case DCB_CONNECTOR_DMS59_1
:
903 case DCB_CONNECTOR_DVI_I
: return DRM_MODE_CONNECTOR_DVII
;
904 case DCB_CONNECTOR_DVI_D
: return DRM_MODE_CONNECTOR_DVID
;
905 case DCB_CONNECTOR_LVDS
:
906 case DCB_CONNECTOR_LVDS_SPWG
: return DRM_MODE_CONNECTOR_LVDS
;
907 case DCB_CONNECTOR_DMS59_DP0
:
908 case DCB_CONNECTOR_DMS59_DP1
:
909 case DCB_CONNECTOR_DP
: return DRM_MODE_CONNECTOR_DisplayPort
;
910 case DCB_CONNECTOR_eDP
: return DRM_MODE_CONNECTOR_eDP
;
911 case DCB_CONNECTOR_HDMI_0
:
912 case DCB_CONNECTOR_HDMI_1
: return DRM_MODE_CONNECTOR_HDMIA
;
917 return DRM_MODE_CONNECTOR_Unknown
;
920 struct drm_connector
*
921 nouveau_connector_create(struct drm_device
*dev
, int index
)
923 const struct drm_connector_funcs
*funcs
= &nouveau_connector_funcs
;
924 struct nouveau_drm
*drm
= nouveau_drm(dev
);
925 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
926 struct nouveau_display
*disp
= nouveau_display(dev
);
927 struct nouveau_connector
*nv_connector
= NULL
;
928 struct drm_connector
*connector
;
934 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
935 nv_connector
= nouveau_connector(connector
);
936 if (nv_connector
->index
== index
)
940 nv_connector
= kzalloc(sizeof(*nv_connector
), GFP_KERNEL
);
942 return ERR_PTR(-ENOMEM
);
944 connector
= &nv_connector
->base
;
945 nv_connector
->index
= index
;
947 /* attempt to parse vbios connector type and hotplug gpio */
948 nv_connector
->dcb
= olddcb_conn(dev
, index
);
949 if (nv_connector
->dcb
) {
950 static const u8 hpd
[16] = {
951 0xff, 0x07, 0x08, 0xff, 0xff, 0x51, 0x52, 0xff,
952 0xff, 0xff, 0xff, 0xff, 0xff, 0x5e, 0x5f, 0x60,
955 u32 entry
= ROM16(nv_connector
->dcb
[0]);
956 if (olddcb_conntab(dev
)[3] >= 4)
957 entry
|= (u32
)ROM16(nv_connector
->dcb
[2]) << 16;
959 nv_connector
->hpd
= ffs((entry
& 0x07033000) >> 12);
960 nv_connector
->hpd
= hpd
[nv_connector
->hpd
];
962 nv_connector
->type
= nv_connector
->dcb
[0];
963 if (drm_conntype_from_dcb(nv_connector
->type
) ==
964 DRM_MODE_CONNECTOR_Unknown
) {
965 NV_WARN(drm
, "unknown connector type %02x\n",
967 nv_connector
->type
= DCB_CONNECTOR_NONE
;
971 if (nv_match_device(dev
, 0x0421, 0x1458, 0x344c)) {
972 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
973 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
976 /* Gigabyte GV-NX86T512H */
977 if (nv_match_device(dev
, 0x0402, 0x1458, 0x3455)) {
978 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
979 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
982 nv_connector
->type
= DCB_CONNECTOR_NONE
;
983 nv_connector
->hpd
= DCB_GPIO_UNUSED
;
986 /* no vbios data, or an unknown dcb connector type - attempt to
987 * figure out something suitable ourselves
989 if (nv_connector
->type
== DCB_CONNECTOR_NONE
) {
990 struct nouveau_drm
*drm
= nouveau_drm(dev
);
991 struct dcb_table
*dcbt
= &drm
->vbios
.dcb
;
995 for (i
= 0; i
< dcbt
->entries
; i
++) {
996 if (dcbt
->entry
[i
].connector
== nv_connector
->index
)
997 encoders
|= (1 << dcbt
->entry
[i
].type
);
1000 if (encoders
& (1 << DCB_OUTPUT_DP
)) {
1001 if (encoders
& (1 << DCB_OUTPUT_TMDS
))
1002 nv_connector
->type
= DCB_CONNECTOR_DP
;
1004 nv_connector
->type
= DCB_CONNECTOR_eDP
;
1006 if (encoders
& (1 << DCB_OUTPUT_TMDS
)) {
1007 if (encoders
& (1 << DCB_OUTPUT_ANALOG
))
1008 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1010 nv_connector
->type
= DCB_CONNECTOR_DVI_D
;
1012 if (encoders
& (1 << DCB_OUTPUT_ANALOG
)) {
1013 nv_connector
->type
= DCB_CONNECTOR_VGA
;
1015 if (encoders
& (1 << DCB_OUTPUT_LVDS
)) {
1016 nv_connector
->type
= DCB_CONNECTOR_LVDS
;
1018 if (encoders
& (1 << DCB_OUTPUT_TV
)) {
1019 nv_connector
->type
= DCB_CONNECTOR_TV_0
;
1023 type
= drm_conntype_from_dcb(nv_connector
->type
);
1024 if (type
== DRM_MODE_CONNECTOR_LVDS
) {
1025 ret
= nouveau_bios_parse_lvds_table(dev
, 0, &dummy
, &dummy
);
1027 NV_ERROR(drm
, "Error parsing LVDS table, disabling\n");
1028 kfree(nv_connector
);
1029 return ERR_PTR(ret
);
1032 funcs
= &nouveau_connector_funcs_lvds
;
1034 funcs
= &nouveau_connector_funcs
;
1037 /* defaults, will get overridden in detect() */
1038 connector
->interlace_allowed
= false;
1039 connector
->doublescan_allowed
= false;
1041 drm_connector_init(dev
, connector
, funcs
, type
);
1042 drm_connector_helper_add(connector
, &nouveau_connector_helper_funcs
);
1044 /* Init DVI-I specific properties */
1045 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
)
1046 drm_connector_attach_property(connector
, dev
->mode_config
.dvi_i_subconnector_property
, 0);
1048 /* Add overscan compensation options to digital outputs */
1049 if (disp
->underscan_property
&&
1050 (type
== DRM_MODE_CONNECTOR_DVID
||
1051 type
== DRM_MODE_CONNECTOR_DVII
||
1052 type
== DRM_MODE_CONNECTOR_HDMIA
||
1053 type
== DRM_MODE_CONNECTOR_DisplayPort
)) {
1054 drm_connector_attach_property(connector
,
1055 disp
->underscan_property
,
1057 drm_connector_attach_property(connector
,
1058 disp
->underscan_hborder_property
,
1060 drm_connector_attach_property(connector
,
1061 disp
->underscan_vborder_property
,
1065 /* Add hue and saturation options */
1066 if (disp
->vibrant_hue_property
)
1067 drm_connector_attach_property(connector
,
1068 disp
->vibrant_hue_property
,
1070 if (disp
->color_vibrance_property
)
1071 drm_connector_attach_property(connector
,
1072 disp
->color_vibrance_property
,
1075 switch (nv_connector
->type
) {
1076 case DCB_CONNECTOR_VGA
:
1077 if (nv_device(drm
->device
)->card_type
>= NV_50
) {
1078 drm_connector_attach_property(connector
,
1079 dev
->mode_config
.scaling_mode_property
,
1080 nv_connector
->scaling_mode
);
1083 case DCB_CONNECTOR_TV_0
:
1084 case DCB_CONNECTOR_TV_1
:
1085 case DCB_CONNECTOR_TV_3
:
1086 nv_connector
->scaling_mode
= DRM_MODE_SCALE_NONE
;
1089 nv_connector
->scaling_mode
= DRM_MODE_SCALE_FULLSCREEN
;
1091 drm_connector_attach_property(connector
,
1092 dev
->mode_config
.scaling_mode_property
,
1093 nv_connector
->scaling_mode
);
1094 if (disp
->dithering_mode
) {
1095 nv_connector
->dithering_mode
= DITHERING_MODE_AUTO
;
1096 drm_connector_attach_property(connector
,
1097 disp
->dithering_mode
,
1098 nv_connector
->dithering_mode
);
1100 if (disp
->dithering_depth
) {
1101 nv_connector
->dithering_depth
= DITHERING_DEPTH_AUTO
;
1102 drm_connector_attach_property(connector
,
1103 disp
->dithering_depth
,
1104 nv_connector
->dithering_depth
);
1109 connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
;
1110 if (gpio
&& nv_connector
->hpd
!= DCB_GPIO_UNUSED
) {
1111 ret
= gpio
->isr_add(gpio
, 0, nv_connector
->hpd
, 0xff,
1112 nouveau_connector_hotplug
, connector
);
1114 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
1117 drm_sysfs_connector_add(connector
);
1122 nouveau_connector_hotplug(void *data
, int plugged
)
1124 struct drm_connector
*connector
= data
;
1125 struct drm_device
*dev
= connector
->dev
;
1126 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1128 NV_DEBUG(drm
, "%splugged %s\n", plugged
? "" : "un",
1129 drm_get_connector_name(connector
));
1132 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_ON
);
1134 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
1136 drm_helper_hpd_irq_event(dev
);