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
);
114 if (gpio
&& nv_connector
->hpd
!= DCB_GPIO_UNUSED
) {
115 gpio
->isr_del(gpio
, 0, nv_connector
->hpd
, 0xff,
116 nouveau_connector_hotplug
, connector
);
119 kfree(nv_connector
->edid
);
120 drm_sysfs_connector_remove(connector
);
121 drm_connector_cleanup(connector
);
125 static struct nouveau_i2c_port
*
126 nouveau_connector_ddc_detect(struct drm_connector
*connector
,
127 struct nouveau_encoder
**pnv_encoder
)
129 struct drm_device
*dev
= connector
->dev
;
130 struct nouveau_drm
*drm
= nouveau_drm(dev
);
131 struct nouveau_i2c
*i2c
= nouveau_i2c(drm
->device
);
134 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
135 struct nouveau_i2c_port
*port
= NULL
;
136 struct nouveau_encoder
*nv_encoder
;
137 struct drm_mode_object
*obj
;
140 id
= connector
->encoder_ids
[i
];
144 obj
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_ENCODER
);
147 nv_encoder
= nouveau_encoder(obj_to_encoder(obj
));
149 if (nv_encoder
->dcb
->i2c_index
< 0xf)
150 port
= i2c
->find(i2c
, nv_encoder
->dcb
->i2c_index
);
151 if (port
&& nv_probe_i2c(port
, 0x50)) {
152 *pnv_encoder
= nv_encoder
;
160 static struct nouveau_encoder
*
161 nouveau_connector_of_detect(struct drm_connector
*connector
)
164 struct drm_device
*dev
= connector
->dev
;
165 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
166 struct nouveau_encoder
*nv_encoder
;
167 struct device_node
*cn
, *dn
= pci_device_to_OF_node(dev
->pdev
);
170 !((nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TMDS
)) ||
171 (nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
))))
174 for_each_child_of_node(dn
, cn
) {
175 const char *name
= of_get_property(cn
, "name", NULL
);
176 const void *edid
= of_get_property(cn
, "EDID", NULL
);
177 int idx
= name
? name
[strlen(name
) - 1] - 'A' : 0;
179 if (nv_encoder
->dcb
->i2c_index
== idx
&& edid
) {
181 kmemdup(edid
, EDID_LENGTH
, GFP_KERNEL
);
191 nouveau_connector_set_encoder(struct drm_connector
*connector
,
192 struct nouveau_encoder
*nv_encoder
)
194 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
195 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
196 struct drm_device
*dev
= connector
->dev
;
198 if (nv_connector
->detected_encoder
== nv_encoder
)
200 nv_connector
->detected_encoder
= nv_encoder
;
202 if (nv_device(drm
->device
)->card_type
>= NV_50
) {
203 connector
->interlace_allowed
= true;
204 connector
->doublescan_allowed
= true;
206 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
||
207 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
) {
208 connector
->doublescan_allowed
= false;
209 connector
->interlace_allowed
= false;
211 connector
->doublescan_allowed
= true;
212 if (nv_device(drm
->device
)->card_type
== NV_20
||
213 (nv_device(drm
->device
)->card_type
== NV_10
&&
214 (dev
->pci_device
& 0x0ff0) != 0x0100 &&
215 (dev
->pci_device
& 0x0ff0) != 0x0150))
217 connector
->interlace_allowed
= false;
219 connector
->interlace_allowed
= true;
222 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
223 drm_object_property_set_value(&connector
->base
,
224 dev
->mode_config
.dvi_i_subconnector_property
,
225 nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
?
226 DRM_MODE_SUBCONNECTOR_DVID
:
227 DRM_MODE_SUBCONNECTOR_DVIA
);
231 static enum drm_connector_status
232 nouveau_connector_detect(struct drm_connector
*connector
, bool force
)
234 struct drm_device
*dev
= connector
->dev
;
235 struct nouveau_drm
*drm
= nouveau_drm(dev
);
236 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
237 struct nouveau_encoder
*nv_encoder
= NULL
;
238 struct nouveau_encoder
*nv_partner
;
239 struct nouveau_i2c_port
*i2c
;
242 /* Cleanup the previous EDID block. */
243 if (nv_connector
->edid
) {
244 drm_mode_connector_update_edid_property(connector
, NULL
);
245 kfree(nv_connector
->edid
);
246 nv_connector
->edid
= NULL
;
249 i2c
= nouveau_connector_ddc_detect(connector
, &nv_encoder
);
251 nv_connector
->edid
= drm_get_edid(connector
, &i2c
->adapter
);
252 drm_mode_connector_update_edid_property(connector
,
254 if (!nv_connector
->edid
) {
255 NV_ERROR(drm
, "DDC responded, but no EDID for %s\n",
256 drm_get_connector_name(connector
));
260 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
&&
261 !nouveau_dp_detect(to_drm_encoder(nv_encoder
))) {
262 NV_ERROR(drm
, "Detected %s, but failed init\n",
263 drm_get_connector_name(connector
));
264 return connector_status_disconnected
;
267 /* Override encoder type for DVI-I based on whether EDID
268 * says the display is digital or analog, both use the
269 * same i2c channel so the value returned from ddc_detect
270 * isn't necessarily correct.
273 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
)
274 nv_partner
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
275 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
)
276 nv_partner
= find_encoder(connector
, DCB_OUTPUT_TMDS
);
278 if (nv_partner
&& ((nv_encoder
->dcb
->type
== DCB_OUTPUT_ANALOG
&&
279 nv_partner
->dcb
->type
== DCB_OUTPUT_TMDS
) ||
280 (nv_encoder
->dcb
->type
== DCB_OUTPUT_TMDS
&&
281 nv_partner
->dcb
->type
== DCB_OUTPUT_ANALOG
))) {
282 if (nv_connector
->edid
->input
& DRM_EDID_INPUT_DIGITAL
)
283 type
= DCB_OUTPUT_TMDS
;
285 type
= DCB_OUTPUT_ANALOG
;
287 nv_encoder
= find_encoder(connector
, type
);
290 nouveau_connector_set_encoder(connector
, nv_encoder
);
291 return connector_status_connected
;
294 nv_encoder
= nouveau_connector_of_detect(connector
);
296 nouveau_connector_set_encoder(connector
, nv_encoder
);
297 return connector_status_connected
;
301 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_ANALOG
);
302 if (!nv_encoder
&& !nouveau_tv_disable
)
303 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_TV
);
304 if (nv_encoder
&& force
) {
305 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
306 struct drm_encoder_helper_funcs
*helper
=
307 encoder
->helper_private
;
309 if (helper
->detect(encoder
, connector
) ==
310 connector_status_connected
) {
311 nouveau_connector_set_encoder(connector
, nv_encoder
);
312 return connector_status_connected
;
317 return connector_status_disconnected
;
320 static enum drm_connector_status
321 nouveau_connector_detect_lvds(struct drm_connector
*connector
, bool force
)
323 struct drm_device
*dev
= connector
->dev
;
324 struct nouveau_drm
*drm
= nouveau_drm(dev
);
325 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
326 struct nouveau_encoder
*nv_encoder
= NULL
;
327 enum drm_connector_status status
= connector_status_disconnected
;
329 /* Cleanup the previous EDID block. */
330 if (nv_connector
->edid
) {
331 drm_mode_connector_update_edid_property(connector
, NULL
);
332 kfree(nv_connector
->edid
);
333 nv_connector
->edid
= NULL
;
336 nv_encoder
= find_encoder(connector
, DCB_OUTPUT_LVDS
);
338 return connector_status_disconnected
;
340 /* Try retrieving EDID via DDC */
341 if (!drm
->vbios
.fp_no_ddc
) {
342 status
= nouveau_connector_detect(connector
, force
);
343 if (status
== connector_status_connected
)
347 /* On some laptops (Sony, i'm looking at you) there appears to
348 * be no direct way of accessing the panel's EDID. The only
349 * option available to us appears to be to ask ACPI for help..
351 * It's important this check's before trying straps, one of the
352 * said manufacturer's laptops are configured in such a way
353 * the nouveau decides an entry in the VBIOS FP mode table is
354 * valid - it's not (rh#613284)
356 if (nv_encoder
->dcb
->lvdsconf
.use_acpi_for_edid
) {
357 if ((nv_connector
->edid
= nouveau_acpi_edid(dev
, connector
))) {
358 status
= connector_status_connected
;
363 /* If no EDID found above, and the VBIOS indicates a hardcoded
364 * modeline is avalilable for the panel, set it as the panel's
365 * native mode and exit.
367 if (nouveau_bios_fp_mode(dev
, NULL
) && (drm
->vbios
.fp_no_ddc
||
368 nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
)) {
369 status
= connector_status_connected
;
373 /* Still nothing, some VBIOS images have a hardcoded EDID block
374 * stored for the panel stored in them.
376 if (!drm
->vbios
.fp_no_ddc
) {
378 (struct edid
*)nouveau_bios_embedded_edid(dev
);
380 nv_connector
->edid
= kmalloc(EDID_LENGTH
, GFP_KERNEL
);
381 *(nv_connector
->edid
) = *edid
;
382 status
= connector_status_connected
;
387 #if defined(CONFIG_ACPI_BUTTON) || \
388 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
389 if (status
== connector_status_connected
&&
390 !nouveau_ignorelid
&& !acpi_lid_open())
391 status
= connector_status_unknown
;
394 drm_mode_connector_update_edid_property(connector
, nv_connector
->edid
);
395 nouveau_connector_set_encoder(connector
, nv_encoder
);
400 nouveau_connector_force(struct drm_connector
*connector
)
402 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
403 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
404 struct nouveau_encoder
*nv_encoder
;
407 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
) {
408 if (connector
->force
== DRM_FORCE_ON_DIGITAL
)
409 type
= DCB_OUTPUT_TMDS
;
411 type
= DCB_OUTPUT_ANALOG
;
413 type
= DCB_OUTPUT_ANY
;
415 nv_encoder
= find_encoder(connector
, type
);
417 NV_ERROR(drm
, "can't find encoder to force %s on!\n",
418 drm_get_connector_name(connector
));
419 connector
->status
= connector_status_disconnected
;
423 nouveau_connector_set_encoder(connector
, nv_encoder
);
427 nouveau_connector_set_property(struct drm_connector
*connector
,
428 struct drm_property
*property
, uint64_t value
)
430 struct nouveau_display
*disp
= nouveau_display(connector
->dev
);
431 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
432 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
433 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
434 struct drm_device
*dev
= connector
->dev
;
435 struct nouveau_crtc
*nv_crtc
;
439 if (connector
->encoder
&& connector
->encoder
->crtc
)
440 nv_crtc
= nouveau_crtc(connector
->encoder
->crtc
);
443 if (property
== dev
->mode_config
.scaling_mode_property
) {
444 bool modeset
= false;
447 case DRM_MODE_SCALE_NONE
:
448 case DRM_MODE_SCALE_FULLSCREEN
:
449 case DRM_MODE_SCALE_CENTER
:
450 case DRM_MODE_SCALE_ASPECT
:
456 /* LVDS always needs gpu scaling */
457 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
&&
458 value
== DRM_MODE_SCALE_NONE
)
461 /* Changing between GPU and panel scaling requires a full
464 if ((nv_connector
->scaling_mode
== DRM_MODE_SCALE_NONE
) ||
465 (value
== DRM_MODE_SCALE_NONE
))
467 nv_connector
->scaling_mode
= value
;
472 if (modeset
|| !nv_crtc
->set_scale
) {
473 ret
= drm_crtc_helper_set_mode(&nv_crtc
->base
,
476 nv_crtc
->base
.y
, NULL
);
480 ret
= nv_crtc
->set_scale(nv_crtc
, true);
489 if (property
== disp
->underscan_property
) {
490 if (nv_connector
->underscan
!= value
) {
491 nv_connector
->underscan
= value
;
492 if (!nv_crtc
|| !nv_crtc
->set_scale
)
495 return nv_crtc
->set_scale(nv_crtc
, true);
501 if (property
== disp
->underscan_hborder_property
) {
502 if (nv_connector
->underscan_hborder
!= value
) {
503 nv_connector
->underscan_hborder
= value
;
504 if (!nv_crtc
|| !nv_crtc
->set_scale
)
507 return nv_crtc
->set_scale(nv_crtc
, true);
513 if (property
== disp
->underscan_vborder_property
) {
514 if (nv_connector
->underscan_vborder
!= value
) {
515 nv_connector
->underscan_vborder
= value
;
516 if (!nv_crtc
|| !nv_crtc
->set_scale
)
519 return nv_crtc
->set_scale(nv_crtc
, true);
526 if (property
== disp
->dithering_mode
) {
527 nv_connector
->dithering_mode
= value
;
528 if (!nv_crtc
|| !nv_crtc
->set_dither
)
531 return nv_crtc
->set_dither(nv_crtc
, true);
534 if (property
== disp
->dithering_depth
) {
535 nv_connector
->dithering_depth
= value
;
536 if (!nv_crtc
|| !nv_crtc
->set_dither
)
539 return nv_crtc
->set_dither(nv_crtc
, true);
542 if (nv_crtc
&& nv_crtc
->set_color_vibrance
) {
544 if (property
== disp
->vibrant_hue_property
) {
545 nv_crtc
->vibrant_hue
= value
- 90;
546 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
549 if (property
== disp
->color_vibrance_property
) {
550 nv_crtc
->color_vibrance
= value
- 100;
551 return nv_crtc
->set_color_vibrance(nv_crtc
, true);
555 if (nv_encoder
&& nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
556 return get_slave_funcs(encoder
)->set_property(
557 encoder
, connector
, property
, value
);
562 static struct drm_display_mode
*
563 nouveau_connector_native_mode(struct drm_connector
*connector
)
565 struct drm_connector_helper_funcs
*helper
= connector
->helper_private
;
566 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
567 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
568 struct drm_device
*dev
= connector
->dev
;
569 struct drm_display_mode
*mode
, *largest
= NULL
;
570 int high_w
= 0, high_h
= 0, high_v
= 0;
572 list_for_each_entry(mode
, &nv_connector
->base
.probed_modes
, head
) {
573 mode
->vrefresh
= drm_mode_vrefresh(mode
);
574 if (helper
->mode_valid(connector
, mode
) != MODE_OK
||
575 (mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
578 /* Use preferred mode if there is one.. */
579 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
) {
580 NV_DEBUG(drm
, "native mode from preferred\n");
581 return drm_mode_duplicate(dev
, mode
);
584 /* Otherwise, take the resolution with the largest width, then
585 * height, then vertical refresh
587 if (mode
->hdisplay
< high_w
)
590 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
< high_h
)
593 if (mode
->hdisplay
== high_w
&& mode
->vdisplay
== high_h
&&
594 mode
->vrefresh
< high_v
)
597 high_w
= mode
->hdisplay
;
598 high_h
= mode
->vdisplay
;
599 high_v
= mode
->vrefresh
;
603 NV_DEBUG(drm
, "native mode from largest: %dx%d@%d\n",
604 high_w
, high_h
, high_v
);
605 return largest
? drm_mode_duplicate(dev
, largest
) : NULL
;
613 static struct moderec scaler_modes
[] = {
632 nouveau_connector_scaler_modes_add(struct drm_connector
*connector
)
634 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
635 struct drm_display_mode
*native
= nv_connector
->native_mode
, *m
;
636 struct drm_device
*dev
= connector
->dev
;
637 struct moderec
*mode
= &scaler_modes
[0];
643 while (mode
->hdisplay
) {
644 if (mode
->hdisplay
<= native
->hdisplay
&&
645 mode
->vdisplay
<= native
->vdisplay
) {
646 m
= drm_cvt_mode(dev
, mode
->hdisplay
, mode
->vdisplay
,
647 drm_mode_vrefresh(native
), false,
652 m
->type
|= DRM_MODE_TYPE_DRIVER
;
654 drm_mode_probed_add(connector
, m
);
665 nouveau_connector_detect_depth(struct drm_connector
*connector
)
667 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
668 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
669 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
670 struct nvbios
*bios
= &drm
->vbios
;
671 struct drm_display_mode
*mode
= nv_connector
->native_mode
;
674 /* if the edid is feeling nice enough to provide this info, use it */
675 if (nv_connector
->edid
&& connector
->display_info
.bpc
)
678 /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
679 if (nv_connector
->type
== DCB_CONNECTOR_eDP
) {
680 connector
->display_info
.bpc
= 6;
684 /* we're out of options unless we're LVDS, default to 8bpc */
685 if (nv_encoder
->dcb
->type
!= DCB_OUTPUT_LVDS
) {
686 connector
->display_info
.bpc
= 8;
690 connector
->display_info
.bpc
= 6;
692 /* LVDS: panel straps */
693 if (bios
->fp_no_ddc
) {
694 if (bios
->fp
.if_is_24bit
)
695 connector
->display_info
.bpc
= 8;
699 /* LVDS: DDC panel, need to first determine the number of links to
700 * know which if_is_24bit flag to check...
702 if (nv_connector
->edid
&&
703 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
)
704 duallink
= ((u8
*)nv_connector
->edid
)[121] == 2;
706 duallink
= mode
->clock
>= bios
->fp
.duallink_transition_clk
;
708 if ((!duallink
&& (bios
->fp
.strapless_is_24bit
& 1)) ||
709 ( duallink
&& (bios
->fp
.strapless_is_24bit
& 2)))
710 connector
->display_info
.bpc
= 8;
714 nouveau_connector_get_modes(struct drm_connector
*connector
)
716 struct drm_device
*dev
= connector
->dev
;
717 struct nouveau_drm
*drm
= nouveau_drm(dev
);
718 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
719 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
720 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
723 /* destroy the native mode, the attached monitor could have changed.
725 if (nv_connector
->native_mode
) {
726 drm_mode_destroy(dev
, nv_connector
->native_mode
);
727 nv_connector
->native_mode
= NULL
;
730 if (nv_connector
->edid
)
731 ret
= drm_add_edid_modes(connector
, nv_connector
->edid
);
733 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_LVDS
&&
734 (nv_encoder
->dcb
->lvdsconf
.use_straps_for_mode
||
735 drm
->vbios
.fp_no_ddc
) && nouveau_bios_fp_mode(dev
, NULL
)) {
736 struct drm_display_mode mode
;
738 nouveau_bios_fp_mode(dev
, &mode
);
739 nv_connector
->native_mode
= drm_mode_duplicate(dev
, &mode
);
742 /* Determine display colour depth for everything except LVDS now,
743 * DP requires this before mode_valid() is called.
745 if (connector
->connector_type
!= DRM_MODE_CONNECTOR_LVDS
)
746 nouveau_connector_detect_depth(connector
);
748 /* Find the native mode if this is a digital panel, if we didn't
749 * find any modes through DDC previously add the native mode to
752 if (!nv_connector
->native_mode
)
753 nv_connector
->native_mode
=
754 nouveau_connector_native_mode(connector
);
755 if (ret
== 0 && nv_connector
->native_mode
) {
756 struct drm_display_mode
*mode
;
758 mode
= drm_mode_duplicate(dev
, nv_connector
->native_mode
);
759 drm_mode_probed_add(connector
, mode
);
763 /* Determine LVDS colour depth, must happen after determining
764 * "native" mode as some VBIOS tables require us to use the
765 * pixel clock as part of the lookup...
767 if (connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
)
768 nouveau_connector_detect_depth(connector
);
770 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_TV
)
771 ret
= get_slave_funcs(encoder
)->get_modes(encoder
, connector
);
773 if (nv_connector
->type
== DCB_CONNECTOR_LVDS
||
774 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
||
775 nv_connector
->type
== DCB_CONNECTOR_eDP
)
776 ret
+= nouveau_connector_scaler_modes_add(connector
);
782 get_tmds_link_bandwidth(struct drm_connector
*connector
)
784 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
785 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
786 struct dcb_output
*dcb
= nv_connector
->detected_encoder
->dcb
;
788 if (dcb
->location
!= DCB_LOC_ON_CHIP
||
789 nv_device(drm
->device
)->chipset
>= 0x46)
791 else if (nv_device(drm
->device
)->chipset
>= 0x40)
793 else if (nv_device(drm
->device
)->chipset
>= 0x18)
800 nouveau_connector_mode_valid(struct drm_connector
*connector
,
801 struct drm_display_mode
*mode
)
803 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
804 struct nouveau_encoder
*nv_encoder
= nv_connector
->detected_encoder
;
805 struct drm_encoder
*encoder
= to_drm_encoder(nv_encoder
);
806 unsigned min_clock
= 25000, max_clock
= min_clock
;
807 unsigned clock
= mode
->clock
;
809 switch (nv_encoder
->dcb
->type
) {
810 case DCB_OUTPUT_LVDS
:
811 if (nv_connector
->native_mode
&&
812 (mode
->hdisplay
> nv_connector
->native_mode
->hdisplay
||
813 mode
->vdisplay
> nv_connector
->native_mode
->vdisplay
))
819 case DCB_OUTPUT_TMDS
:
820 max_clock
= get_tmds_link_bandwidth(connector
);
821 if (nouveau_duallink
&& nv_encoder
->dcb
->duallink_possible
)
824 case DCB_OUTPUT_ANALOG
:
825 max_clock
= nv_encoder
->dcb
->crtconf
.maxfreq
;
830 return get_slave_funcs(encoder
)->mode_valid(encoder
, mode
);
832 max_clock
= nv_encoder
->dp
.link_nr
;
833 max_clock
*= nv_encoder
->dp
.link_bw
;
834 clock
= clock
* (connector
->display_info
.bpc
* 3) / 10;
841 if (clock
< min_clock
)
842 return MODE_CLOCK_LOW
;
844 if (clock
> max_clock
)
845 return MODE_CLOCK_HIGH
;
850 static struct drm_encoder
*
851 nouveau_connector_best_encoder(struct drm_connector
*connector
)
853 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
855 if (nv_connector
->detected_encoder
)
856 return to_drm_encoder(nv_connector
->detected_encoder
);
861 static const struct drm_connector_helper_funcs
862 nouveau_connector_helper_funcs
= {
863 .get_modes
= nouveau_connector_get_modes
,
864 .mode_valid
= nouveau_connector_mode_valid
,
865 .best_encoder
= nouveau_connector_best_encoder
,
868 static const struct drm_connector_funcs
869 nouveau_connector_funcs
= {
870 .dpms
= drm_helper_connector_dpms
,
873 .detect
= nouveau_connector_detect
,
874 .destroy
= nouveau_connector_destroy
,
875 .fill_modes
= drm_helper_probe_single_connector_modes
,
876 .set_property
= nouveau_connector_set_property
,
877 .force
= nouveau_connector_force
880 static const struct drm_connector_funcs
881 nouveau_connector_funcs_lvds
= {
882 .dpms
= drm_helper_connector_dpms
,
885 .detect
= nouveau_connector_detect_lvds
,
886 .destroy
= nouveau_connector_destroy
,
887 .fill_modes
= drm_helper_probe_single_connector_modes
,
888 .set_property
= nouveau_connector_set_property
,
889 .force
= nouveau_connector_force
893 drm_conntype_from_dcb(enum dcb_connector_type dcb
)
896 case DCB_CONNECTOR_VGA
: return DRM_MODE_CONNECTOR_VGA
;
897 case DCB_CONNECTOR_TV_0
:
898 case DCB_CONNECTOR_TV_1
:
899 case DCB_CONNECTOR_TV_3
: return DRM_MODE_CONNECTOR_TV
;
900 case DCB_CONNECTOR_DMS59_0
:
901 case DCB_CONNECTOR_DMS59_1
:
902 case DCB_CONNECTOR_DVI_I
: return DRM_MODE_CONNECTOR_DVII
;
903 case DCB_CONNECTOR_DVI_D
: return DRM_MODE_CONNECTOR_DVID
;
904 case DCB_CONNECTOR_LVDS
:
905 case DCB_CONNECTOR_LVDS_SPWG
: return DRM_MODE_CONNECTOR_LVDS
;
906 case DCB_CONNECTOR_DMS59_DP0
:
907 case DCB_CONNECTOR_DMS59_DP1
:
908 case DCB_CONNECTOR_DP
: return DRM_MODE_CONNECTOR_DisplayPort
;
909 case DCB_CONNECTOR_eDP
: return DRM_MODE_CONNECTOR_eDP
;
910 case DCB_CONNECTOR_HDMI_0
:
911 case DCB_CONNECTOR_HDMI_1
: return DRM_MODE_CONNECTOR_HDMIA
;
916 return DRM_MODE_CONNECTOR_Unknown
;
919 struct drm_connector
*
920 nouveau_connector_create(struct drm_device
*dev
, int index
)
922 const struct drm_connector_funcs
*funcs
= &nouveau_connector_funcs
;
923 struct nouveau_drm
*drm
= nouveau_drm(dev
);
924 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
925 struct nouveau_display
*disp
= nouveau_display(dev
);
926 struct nouveau_connector
*nv_connector
= NULL
;
927 struct drm_connector
*connector
;
931 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
932 nv_connector
= nouveau_connector(connector
);
933 if (nv_connector
->index
== index
)
937 nv_connector
= kzalloc(sizeof(*nv_connector
), GFP_KERNEL
);
939 return ERR_PTR(-ENOMEM
);
941 connector
= &nv_connector
->base
;
942 nv_connector
->index
= index
;
944 /* attempt to parse vbios connector type and hotplug gpio */
945 nv_connector
->dcb
= olddcb_conn(dev
, index
);
946 if (nv_connector
->dcb
) {
947 static const u8 hpd
[16] = {
948 0xff, 0x07, 0x08, 0xff, 0xff, 0x51, 0x52, 0xff,
949 0xff, 0xff, 0xff, 0xff, 0xff, 0x5e, 0x5f, 0x60,
952 u32 entry
= ROM16(nv_connector
->dcb
[0]);
953 if (olddcb_conntab(dev
)[3] >= 4)
954 entry
|= (u32
)ROM16(nv_connector
->dcb
[2]) << 16;
956 nv_connector
->hpd
= ffs((entry
& 0x07033000) >> 12);
957 nv_connector
->hpd
= hpd
[nv_connector
->hpd
];
959 nv_connector
->type
= nv_connector
->dcb
[0];
960 if (drm_conntype_from_dcb(nv_connector
->type
) ==
961 DRM_MODE_CONNECTOR_Unknown
) {
962 NV_WARN(drm
, "unknown connector type %02x\n",
964 nv_connector
->type
= DCB_CONNECTOR_NONE
;
968 if (nv_match_device(dev
, 0x0421, 0x1458, 0x344c)) {
969 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
970 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
973 /* Gigabyte GV-NX86T512H */
974 if (nv_match_device(dev
, 0x0402, 0x1458, 0x3455)) {
975 if (nv_connector
->type
== DCB_CONNECTOR_HDMI_1
)
976 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
979 nv_connector
->type
= DCB_CONNECTOR_NONE
;
980 nv_connector
->hpd
= DCB_GPIO_UNUSED
;
983 /* no vbios data, or an unknown dcb connector type - attempt to
984 * figure out something suitable ourselves
986 if (nv_connector
->type
== DCB_CONNECTOR_NONE
) {
987 struct nouveau_drm
*drm
= nouveau_drm(dev
);
988 struct dcb_table
*dcbt
= &drm
->vbios
.dcb
;
992 for (i
= 0; i
< dcbt
->entries
; i
++) {
993 if (dcbt
->entry
[i
].connector
== nv_connector
->index
)
994 encoders
|= (1 << dcbt
->entry
[i
].type
);
997 if (encoders
& (1 << DCB_OUTPUT_DP
)) {
998 if (encoders
& (1 << DCB_OUTPUT_TMDS
))
999 nv_connector
->type
= DCB_CONNECTOR_DP
;
1001 nv_connector
->type
= DCB_CONNECTOR_eDP
;
1003 if (encoders
& (1 << DCB_OUTPUT_TMDS
)) {
1004 if (encoders
& (1 << DCB_OUTPUT_ANALOG
))
1005 nv_connector
->type
= DCB_CONNECTOR_DVI_I
;
1007 nv_connector
->type
= DCB_CONNECTOR_DVI_D
;
1009 if (encoders
& (1 << DCB_OUTPUT_ANALOG
)) {
1010 nv_connector
->type
= DCB_CONNECTOR_VGA
;
1012 if (encoders
& (1 << DCB_OUTPUT_LVDS
)) {
1013 nv_connector
->type
= DCB_CONNECTOR_LVDS
;
1015 if (encoders
& (1 << DCB_OUTPUT_TV
)) {
1016 nv_connector
->type
= DCB_CONNECTOR_TV_0
;
1020 type
= drm_conntype_from_dcb(nv_connector
->type
);
1021 if (type
== DRM_MODE_CONNECTOR_LVDS
) {
1022 ret
= nouveau_bios_parse_lvds_table(dev
, 0, &dummy
, &dummy
);
1024 NV_ERROR(drm
, "Error parsing LVDS table, disabling\n");
1025 kfree(nv_connector
);
1026 return ERR_PTR(ret
);
1029 funcs
= &nouveau_connector_funcs_lvds
;
1031 funcs
= &nouveau_connector_funcs
;
1034 /* defaults, will get overridden in detect() */
1035 connector
->interlace_allowed
= false;
1036 connector
->doublescan_allowed
= false;
1038 drm_connector_init(dev
, connector
, funcs
, type
);
1039 drm_connector_helper_add(connector
, &nouveau_connector_helper_funcs
);
1041 /* Init DVI-I specific properties */
1042 if (nv_connector
->type
== DCB_CONNECTOR_DVI_I
)
1043 drm_object_attach_property(&connector
->base
, dev
->mode_config
.dvi_i_subconnector_property
, 0);
1045 /* Add overscan compensation options to digital outputs */
1046 if (disp
->underscan_property
&&
1047 (type
== DRM_MODE_CONNECTOR_DVID
||
1048 type
== DRM_MODE_CONNECTOR_DVII
||
1049 type
== DRM_MODE_CONNECTOR_HDMIA
||
1050 type
== DRM_MODE_CONNECTOR_DisplayPort
)) {
1051 drm_object_attach_property(&connector
->base
,
1052 disp
->underscan_property
,
1054 drm_object_attach_property(&connector
->base
,
1055 disp
->underscan_hborder_property
,
1057 drm_object_attach_property(&connector
->base
,
1058 disp
->underscan_vborder_property
,
1062 /* Add hue and saturation options */
1063 if (disp
->vibrant_hue_property
)
1064 drm_object_attach_property(&connector
->base
,
1065 disp
->vibrant_hue_property
,
1067 if (disp
->color_vibrance_property
)
1068 drm_object_attach_property(&connector
->base
,
1069 disp
->color_vibrance_property
,
1072 switch (nv_connector
->type
) {
1073 case DCB_CONNECTOR_VGA
:
1074 if (nv_device(drm
->device
)->card_type
>= NV_50
) {
1075 drm_object_attach_property(&connector
->base
,
1076 dev
->mode_config
.scaling_mode_property
,
1077 nv_connector
->scaling_mode
);
1080 case DCB_CONNECTOR_TV_0
:
1081 case DCB_CONNECTOR_TV_1
:
1082 case DCB_CONNECTOR_TV_3
:
1083 nv_connector
->scaling_mode
= DRM_MODE_SCALE_NONE
;
1086 nv_connector
->scaling_mode
= DRM_MODE_SCALE_FULLSCREEN
;
1088 drm_object_attach_property(&connector
->base
,
1089 dev
->mode_config
.scaling_mode_property
,
1090 nv_connector
->scaling_mode
);
1091 if (disp
->dithering_mode
) {
1092 nv_connector
->dithering_mode
= DITHERING_MODE_AUTO
;
1093 drm_object_attach_property(&connector
->base
,
1094 disp
->dithering_mode
,
1095 nv_connector
->dithering_mode
);
1097 if (disp
->dithering_depth
) {
1098 nv_connector
->dithering_depth
= DITHERING_DEPTH_AUTO
;
1099 drm_object_attach_property(&connector
->base
,
1100 disp
->dithering_depth
,
1101 nv_connector
->dithering_depth
);
1106 connector
->polled
= DRM_CONNECTOR_POLL_CONNECT
;
1107 if (gpio
&& nv_connector
->hpd
!= DCB_GPIO_UNUSED
) {
1108 ret
= gpio
->isr_add(gpio
, 0, nv_connector
->hpd
, 0xff,
1109 nouveau_connector_hotplug
, connector
);
1111 connector
->polled
= DRM_CONNECTOR_POLL_HPD
;
1114 drm_sysfs_connector_add(connector
);
1119 nouveau_connector_hotplug(void *data
, int plugged
)
1121 struct drm_connector
*connector
= data
;
1122 struct drm_device
*dev
= connector
->dev
;
1123 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1125 NV_DEBUG(drm
, "%splugged %s\n", plugged
? "" : "un",
1126 drm_get_connector_name(connector
));
1129 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_ON
);
1131 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
1133 drm_helper_hpd_irq_event(dev
);