2 * Copyright (C) 2008 Maarten Maathuis.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include <acpi/button.h>
29 #include <linux/pm_runtime.h>
32 #include <drm/drm_edid.h>
33 #include <drm/drm_crtc_helper.h>
35 #include "nouveau_reg.h"
36 #include "nouveau_drm.h"
37 #include "dispnv04/hw.h"
38 #include "nouveau_acpi.h"
40 #include "nouveau_display.h"
41 #include "nouveau_connector.h"
42 #include "nouveau_encoder.h"
43 #include "nouveau_crtc.h"
45 #include <nvif/class.h>
46 #include <nvif/cl0046.h>
47 #include <nvif/event.h>
49 MODULE_PARM_DESC(tv_disable, "Disable TV-out detection");
50 int nouveau_tv_disable = 0;
51 module_param_named(tv_disable, nouveau_tv_disable, int, 0400);
53 MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status");
54 int nouveau_ignorelid = 0;
55 module_param_named(ignorelid, nouveau_ignorelid, int, 0400);
57 MODULE_PARM_DESC(duallink, "Allow dual-link TMDS (default: enabled)");
58 int nouveau_duallink = 1;
59 module_param_named(duallink, nouveau_duallink, int, 0400);
61 MODULE_PARM_DESC(hdmimhz, "Force a maximum HDMI pixel clock (in MHz)");
62 int nouveau_hdmimhz = 0;
63 module_param_named(hdmimhz, nouveau_hdmimhz, int, 0400);
65 struct nouveau_encoder *
66 find_encoder(struct drm_connector *connector, int type)
68 struct drm_device *dev = connector->dev;
69 struct nouveau_encoder *nv_encoder;
70 struct drm_encoder *enc;
73 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
74 id = connector->encoder_ids[i];
78 enc = drm_encoder_find(dev, id);
81 nv_encoder = nouveau_encoder(enc);
83 if (type == DCB_OUTPUT_ANY ||
84 (nv_encoder->dcb && nv_encoder->dcb->type == type))
91 struct nouveau_connector *
92 nouveau_encoder_connector_get(struct nouveau_encoder *encoder)
94 struct drm_device *dev = to_drm_encoder(encoder)->dev;
95 struct drm_connector *drm_connector;
97 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
98 if (drm_connector->encoder == to_drm_encoder(encoder))
99 return nouveau_connector(drm_connector);
106 nouveau_connector_destroy(struct drm_connector *connector)
108 struct nouveau_connector *nv_connector = nouveau_connector(connector);
109 nvif_notify_fini(&nv_connector->hpd);
110 kfree(nv_connector->edid);
111 drm_connector_unregister(connector);
112 drm_connector_cleanup(connector);
113 if (nv_connector->aux.transfer)
114 drm_dp_aux_unregister(&nv_connector->aux);
118 static struct nouveau_encoder *
119 nouveau_connector_ddc_detect(struct drm_connector *connector)
121 struct drm_device *dev = connector->dev;
122 struct nouveau_connector *nv_connector = nouveau_connector(connector);
123 struct nouveau_drm *drm = nouveau_drm(dev);
124 struct nvkm_gpio *gpio = nvxx_gpio(&drm->device);
125 struct nouveau_encoder *nv_encoder;
126 struct drm_encoder *encoder;
127 int i, panel = -ENODEV;
129 /* eDP panels need powering on by us (if the VBIOS doesn't default it
130 * to on) before doing any AUX channel transactions. LVDS panel power
131 * is handled by the SOR itself, and not required for LVDS DDC.
133 if (nv_connector->type == DCB_CONNECTOR_eDP) {
134 panel = nvkm_gpio_get(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff);
136 nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, 1);
141 for (i = 0; nv_encoder = NULL, i < DRM_CONNECTOR_MAX_ENCODER; i++) {
142 int id = connector->encoder_ids[i];
146 encoder = drm_encoder_find(dev, id);
149 nv_encoder = nouveau_encoder(encoder);
151 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
152 int ret = nouveau_dp_detect(nv_encoder);
156 if (nv_encoder->i2c) {
157 if (nvkm_probe_i2c(nv_encoder->i2c, 0x50))
162 /* eDP panel not detected, restore panel power GPIO to previous
163 * state to avoid confusing the SOR for other output types.
165 if (!nv_encoder && panel == 0)
166 nvkm_gpio_set(gpio, 0, DCB_GPIO_PANEL_POWER, 0xff, panel);
171 static struct nouveau_encoder *
172 nouveau_connector_of_detect(struct drm_connector *connector)
175 struct drm_device *dev = connector->dev;
176 struct nouveau_connector *nv_connector = nouveau_connector(connector);
177 struct nouveau_encoder *nv_encoder;
178 struct device_node *cn, *dn = pci_device_to_OF_node(dev->pdev);
181 !((nv_encoder = find_encoder(connector, DCB_OUTPUT_TMDS)) ||
182 (nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG))))
185 for_each_child_of_node(dn, cn) {
186 const char *name = of_get_property(cn, "name", NULL);
187 const void *edid = of_get_property(cn, "EDID", NULL);
188 int idx = name ? name[strlen(name) - 1] - 'A' : 0;
190 if (nv_encoder->dcb->i2c_index == idx && edid) {
192 kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
202 nouveau_connector_set_encoder(struct drm_connector *connector,
203 struct nouveau_encoder *nv_encoder)
205 struct nouveau_connector *nv_connector = nouveau_connector(connector);
206 struct nouveau_drm *drm = nouveau_drm(connector->dev);
207 struct drm_device *dev = connector->dev;
209 if (nv_connector->detected_encoder == nv_encoder)
211 nv_connector->detected_encoder = nv_encoder;
213 if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
214 connector->interlace_allowed = true;
215 connector->doublescan_allowed = true;
217 if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS ||
218 nv_encoder->dcb->type == DCB_OUTPUT_TMDS) {
219 connector->doublescan_allowed = false;
220 connector->interlace_allowed = false;
222 connector->doublescan_allowed = true;
223 if (drm->device.info.family == NV_DEVICE_INFO_V0_KELVIN ||
224 (drm->device.info.family == NV_DEVICE_INFO_V0_CELSIUS &&
225 (dev->pdev->device & 0x0ff0) != 0x0100 &&
226 (dev->pdev->device & 0x0ff0) != 0x0150))
228 connector->interlace_allowed = false;
230 connector->interlace_allowed = true;
233 if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
234 drm_object_property_set_value(&connector->base,
235 dev->mode_config.dvi_i_subconnector_property,
236 nv_encoder->dcb->type == DCB_OUTPUT_TMDS ?
237 DRM_MODE_SUBCONNECTOR_DVID :
238 DRM_MODE_SUBCONNECTOR_DVIA);
242 static enum drm_connector_status
243 nouveau_connector_detect(struct drm_connector *connector, bool force)
245 struct drm_device *dev = connector->dev;
246 struct nouveau_drm *drm = nouveau_drm(dev);
247 struct nouveau_connector *nv_connector = nouveau_connector(connector);
248 struct nouveau_encoder *nv_encoder = NULL;
249 struct nouveau_encoder *nv_partner;
250 struct i2c_adapter *i2c;
253 enum drm_connector_status conn_status = connector_status_disconnected;
255 /* Cleanup the previous EDID block. */
256 if (nv_connector->edid) {
257 drm_mode_connector_update_edid_property(connector, NULL);
258 kfree(nv_connector->edid);
259 nv_connector->edid = NULL;
262 ret = pm_runtime_get_sync(connector->dev->dev);
263 if (ret < 0 && ret != -EACCES)
266 nv_encoder = nouveau_connector_ddc_detect(connector);
267 if (nv_encoder && (i2c = nv_encoder->i2c) != NULL) {
268 nv_connector->edid = drm_get_edid(connector, i2c);
269 drm_mode_connector_update_edid_property(connector,
271 if (!nv_connector->edid) {
272 NV_ERROR(drm, "DDC responded, but no EDID for %s\n",
277 /* Override encoder type for DVI-I based on whether EDID
278 * says the display is digital or analog, both use the
279 * same i2c channel so the value returned from ddc_detect
280 * isn't necessarily correct.
283 if (nv_encoder->dcb->type == DCB_OUTPUT_TMDS)
284 nv_partner = find_encoder(connector, DCB_OUTPUT_ANALOG);
285 if (nv_encoder->dcb->type == DCB_OUTPUT_ANALOG)
286 nv_partner = find_encoder(connector, DCB_OUTPUT_TMDS);
288 if (nv_partner && ((nv_encoder->dcb->type == DCB_OUTPUT_ANALOG &&
289 nv_partner->dcb->type == DCB_OUTPUT_TMDS) ||
290 (nv_encoder->dcb->type == DCB_OUTPUT_TMDS &&
291 nv_partner->dcb->type == DCB_OUTPUT_ANALOG))) {
292 if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
293 type = DCB_OUTPUT_TMDS;
295 type = DCB_OUTPUT_ANALOG;
297 nv_encoder = find_encoder(connector, type);
300 nouveau_connector_set_encoder(connector, nv_encoder);
301 conn_status = connector_status_connected;
305 nv_encoder = nouveau_connector_of_detect(connector);
307 nouveau_connector_set_encoder(connector, nv_encoder);
308 conn_status = connector_status_connected;
313 nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG);
314 if (!nv_encoder && !nouveau_tv_disable)
315 nv_encoder = find_encoder(connector, DCB_OUTPUT_TV);
316 if (nv_encoder && force) {
317 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
318 const struct drm_encoder_helper_funcs *helper =
319 encoder->helper_private;
321 if (helper->detect(encoder, connector) ==
322 connector_status_connected) {
323 nouveau_connector_set_encoder(connector, nv_encoder);
324 conn_status = connector_status_connected;
332 pm_runtime_mark_last_busy(connector->dev->dev);
333 pm_runtime_put_autosuspend(connector->dev->dev);
338 static enum drm_connector_status
339 nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
341 struct drm_device *dev = connector->dev;
342 struct nouveau_drm *drm = nouveau_drm(dev);
343 struct nouveau_connector *nv_connector = nouveau_connector(connector);
344 struct nouveau_encoder *nv_encoder = NULL;
345 enum drm_connector_status status = connector_status_disconnected;
347 /* Cleanup the previous EDID block. */
348 if (nv_connector->edid) {
349 drm_mode_connector_update_edid_property(connector, NULL);
350 kfree(nv_connector->edid);
351 nv_connector->edid = NULL;
354 nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS);
356 return connector_status_disconnected;
358 /* Try retrieving EDID via DDC */
359 if (!drm->vbios.fp_no_ddc) {
360 status = nouveau_connector_detect(connector, force);
361 if (status == connector_status_connected)
365 /* On some laptops (Sony, i'm looking at you) there appears to
366 * be no direct way of accessing the panel's EDID. The only
367 * option available to us appears to be to ask ACPI for help..
369 * It's important this check's before trying straps, one of the
370 * said manufacturer's laptops are configured in such a way
371 * the nouveau decides an entry in the VBIOS FP mode table is
372 * valid - it's not (rh#613284)
374 if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
375 if ((nv_connector->edid = nouveau_acpi_edid(dev, connector))) {
376 status = connector_status_connected;
381 /* If no EDID found above, and the VBIOS indicates a hardcoded
382 * modeline is avalilable for the panel, set it as the panel's
383 * native mode and exit.
385 if (nouveau_bios_fp_mode(dev, NULL) && (drm->vbios.fp_no_ddc ||
386 nv_encoder->dcb->lvdsconf.use_straps_for_mode)) {
387 status = connector_status_connected;
391 /* Still nothing, some VBIOS images have a hardcoded EDID block
392 * stored for the panel stored in them.
394 if (!drm->vbios.fp_no_ddc) {
396 (struct edid *)nouveau_bios_embedded_edid(dev);
399 kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
400 if (nv_connector->edid)
401 status = connector_status_connected;
406 #if defined(CONFIG_ACPI_BUTTON) || \
407 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
408 if (status == connector_status_connected &&
409 !nouveau_ignorelid && !acpi_lid_open())
410 status = connector_status_unknown;
413 drm_mode_connector_update_edid_property(connector, nv_connector->edid);
414 nouveau_connector_set_encoder(connector, nv_encoder);
419 nouveau_connector_force(struct drm_connector *connector)
421 struct nouveau_drm *drm = nouveau_drm(connector->dev);
422 struct nouveau_connector *nv_connector = nouveau_connector(connector);
423 struct nouveau_encoder *nv_encoder;
426 if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
427 if (connector->force == DRM_FORCE_ON_DIGITAL)
428 type = DCB_OUTPUT_TMDS;
430 type = DCB_OUTPUT_ANALOG;
432 type = DCB_OUTPUT_ANY;
434 nv_encoder = find_encoder(connector, type);
436 NV_ERROR(drm, "can't find encoder to force %s on!\n",
438 connector->status = connector_status_disconnected;
442 nouveau_connector_set_encoder(connector, nv_encoder);
446 nouveau_connector_set_property(struct drm_connector *connector,
447 struct drm_property *property, uint64_t value)
449 struct nouveau_display *disp = nouveau_display(connector->dev);
450 struct nouveau_connector *nv_connector = nouveau_connector(connector);
451 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
452 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
453 struct drm_device *dev = connector->dev;
454 struct nouveau_crtc *nv_crtc;
458 if (connector->encoder && connector->encoder->crtc)
459 nv_crtc = nouveau_crtc(connector->encoder->crtc);
462 if (property == dev->mode_config.scaling_mode_property) {
463 bool modeset = false;
466 case DRM_MODE_SCALE_NONE:
467 /* We allow 'None' for EDID modes, even on a fixed
468 * panel (some exist with support for lower refresh
469 * rates, which people might want to use for power
472 * Non-EDID modes will force the use of GPU scaling
473 * to the native mode regardless of this setting.
475 switch (nv_connector->type) {
476 case DCB_CONNECTOR_LVDS:
477 case DCB_CONNECTOR_LVDS_SPWG:
478 case DCB_CONNECTOR_eDP:
479 /* ... except prior to G80, where the code
480 * doesn't support such things.
482 if (disp->disp.oclass < NV50_DISP)
489 case DRM_MODE_SCALE_FULLSCREEN:
490 case DRM_MODE_SCALE_CENTER:
491 case DRM_MODE_SCALE_ASPECT:
497 /* Changing between GPU and panel scaling requires a full
500 if ((nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) ||
501 (value == DRM_MODE_SCALE_NONE))
503 nv_connector->scaling_mode = value;
508 if (modeset || !nv_crtc->set_scale) {
509 ret = drm_crtc_helper_set_mode(&nv_crtc->base,
512 nv_crtc->base.y, NULL);
516 ret = nv_crtc->set_scale(nv_crtc, true);
525 if (property == disp->underscan_property) {
526 if (nv_connector->underscan != value) {
527 nv_connector->underscan = value;
528 if (!nv_crtc || !nv_crtc->set_scale)
531 return nv_crtc->set_scale(nv_crtc, true);
537 if (property == disp->underscan_hborder_property) {
538 if (nv_connector->underscan_hborder != value) {
539 nv_connector->underscan_hborder = value;
540 if (!nv_crtc || !nv_crtc->set_scale)
543 return nv_crtc->set_scale(nv_crtc, true);
549 if (property == disp->underscan_vborder_property) {
550 if (nv_connector->underscan_vborder != value) {
551 nv_connector->underscan_vborder = value;
552 if (!nv_crtc || !nv_crtc->set_scale)
555 return nv_crtc->set_scale(nv_crtc, true);
562 if (property == disp->dithering_mode) {
563 nv_connector->dithering_mode = value;
564 if (!nv_crtc || !nv_crtc->set_dither)
567 return nv_crtc->set_dither(nv_crtc, true);
570 if (property == disp->dithering_depth) {
571 nv_connector->dithering_depth = value;
572 if (!nv_crtc || !nv_crtc->set_dither)
575 return nv_crtc->set_dither(nv_crtc, true);
578 if (nv_crtc && nv_crtc->set_color_vibrance) {
580 if (property == disp->vibrant_hue_property) {
581 nv_crtc->vibrant_hue = value - 90;
582 return nv_crtc->set_color_vibrance(nv_crtc, true);
585 if (property == disp->color_vibrance_property) {
586 nv_crtc->color_vibrance = value - 100;
587 return nv_crtc->set_color_vibrance(nv_crtc, true);
591 if (nv_encoder && nv_encoder->dcb->type == DCB_OUTPUT_TV)
592 return get_slave_funcs(encoder)->set_property(
593 encoder, connector, property, value);
598 static struct drm_display_mode *
599 nouveau_connector_native_mode(struct drm_connector *connector)
601 const struct drm_connector_helper_funcs *helper = connector->helper_private;
602 struct nouveau_drm *drm = nouveau_drm(connector->dev);
603 struct nouveau_connector *nv_connector = nouveau_connector(connector);
604 struct drm_device *dev = connector->dev;
605 struct drm_display_mode *mode, *largest = NULL;
606 int high_w = 0, high_h = 0, high_v = 0;
608 list_for_each_entry(mode, &nv_connector->base.probed_modes, head) {
609 mode->vrefresh = drm_mode_vrefresh(mode);
610 if (helper->mode_valid(connector, mode) != MODE_OK ||
611 (mode->flags & DRM_MODE_FLAG_INTERLACE))
614 /* Use preferred mode if there is one.. */
615 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
616 NV_DEBUG(drm, "native mode from preferred\n");
617 return drm_mode_duplicate(dev, mode);
620 /* Otherwise, take the resolution with the largest width, then
621 * height, then vertical refresh
623 if (mode->hdisplay < high_w)
626 if (mode->hdisplay == high_w && mode->vdisplay < high_h)
629 if (mode->hdisplay == high_w && mode->vdisplay == high_h &&
630 mode->vrefresh < high_v)
633 high_w = mode->hdisplay;
634 high_h = mode->vdisplay;
635 high_v = mode->vrefresh;
639 NV_DEBUG(drm, "native mode from largest: %dx%d@%d\n",
640 high_w, high_h, high_v);
641 return largest ? drm_mode_duplicate(dev, largest) : NULL;
649 static struct moderec scaler_modes[] = {
668 nouveau_connector_scaler_modes_add(struct drm_connector *connector)
670 struct nouveau_connector *nv_connector = nouveau_connector(connector);
671 struct drm_display_mode *native = nv_connector->native_mode, *m;
672 struct drm_device *dev = connector->dev;
673 struct moderec *mode = &scaler_modes[0];
679 while (mode->hdisplay) {
680 if (mode->hdisplay <= native->hdisplay &&
681 mode->vdisplay <= native->vdisplay &&
682 (mode->hdisplay != native->hdisplay ||
683 mode->vdisplay != native->vdisplay)) {
684 m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay,
685 drm_mode_vrefresh(native), false,
690 drm_mode_probed_add(connector, m);
701 nouveau_connector_detect_depth(struct drm_connector *connector)
703 struct nouveau_drm *drm = nouveau_drm(connector->dev);
704 struct nouveau_connector *nv_connector = nouveau_connector(connector);
705 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
706 struct nvbios *bios = &drm->vbios;
707 struct drm_display_mode *mode = nv_connector->native_mode;
710 /* if the edid is feeling nice enough to provide this info, use it */
711 if (nv_connector->edid && connector->display_info.bpc)
714 /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
715 if (nv_connector->type == DCB_CONNECTOR_eDP) {
716 connector->display_info.bpc = 6;
720 /* we're out of options unless we're LVDS, default to 8bpc */
721 if (nv_encoder->dcb->type != DCB_OUTPUT_LVDS) {
722 connector->display_info.bpc = 8;
726 connector->display_info.bpc = 6;
728 /* LVDS: panel straps */
729 if (bios->fp_no_ddc) {
730 if (bios->fp.if_is_24bit)
731 connector->display_info.bpc = 8;
735 /* LVDS: DDC panel, need to first determine the number of links to
736 * know which if_is_24bit flag to check...
738 if (nv_connector->edid &&
739 nv_connector->type == DCB_CONNECTOR_LVDS_SPWG)
740 duallink = ((u8 *)nv_connector->edid)[121] == 2;
742 duallink = mode->clock >= bios->fp.duallink_transition_clk;
744 if ((!duallink && (bios->fp.strapless_is_24bit & 1)) ||
745 ( duallink && (bios->fp.strapless_is_24bit & 2)))
746 connector->display_info.bpc = 8;
750 nouveau_connector_get_modes(struct drm_connector *connector)
752 struct drm_device *dev = connector->dev;
753 struct nouveau_drm *drm = nouveau_drm(dev);
754 struct nouveau_connector *nv_connector = nouveau_connector(connector);
755 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
756 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
759 /* destroy the native mode, the attached monitor could have changed.
761 if (nv_connector->native_mode) {
762 drm_mode_destroy(dev, nv_connector->native_mode);
763 nv_connector->native_mode = NULL;
766 if (nv_connector->edid)
767 ret = drm_add_edid_modes(connector, nv_connector->edid);
769 if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS &&
770 (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
771 drm->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) {
772 struct drm_display_mode mode;
774 nouveau_bios_fp_mode(dev, &mode);
775 nv_connector->native_mode = drm_mode_duplicate(dev, &mode);
778 /* Determine display colour depth for everything except LVDS now,
779 * DP requires this before mode_valid() is called.
781 if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS)
782 nouveau_connector_detect_depth(connector);
784 /* Find the native mode if this is a digital panel, if we didn't
785 * find any modes through DDC previously add the native mode to
788 if (!nv_connector->native_mode)
789 nv_connector->native_mode =
790 nouveau_connector_native_mode(connector);
791 if (ret == 0 && nv_connector->native_mode) {
792 struct drm_display_mode *mode;
794 mode = drm_mode_duplicate(dev, nv_connector->native_mode);
795 drm_mode_probed_add(connector, mode);
799 /* Determine LVDS colour depth, must happen after determining
800 * "native" mode as some VBIOS tables require us to use the
801 * pixel clock as part of the lookup...
803 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
804 nouveau_connector_detect_depth(connector);
806 if (nv_encoder->dcb->type == DCB_OUTPUT_TV)
807 ret = get_slave_funcs(encoder)->get_modes(encoder, connector);
809 if (nv_connector->type == DCB_CONNECTOR_LVDS ||
810 nv_connector->type == DCB_CONNECTOR_LVDS_SPWG ||
811 nv_connector->type == DCB_CONNECTOR_eDP)
812 ret += nouveau_connector_scaler_modes_add(connector);
818 get_tmds_link_bandwidth(struct drm_connector *connector, bool hdmi)
820 struct nouveau_connector *nv_connector = nouveau_connector(connector);
821 struct nouveau_drm *drm = nouveau_drm(connector->dev);
822 struct dcb_output *dcb = nv_connector->detected_encoder->dcb;
825 if (nouveau_hdmimhz > 0)
826 return nouveau_hdmimhz * 1000;
827 /* Note: these limits are conservative, some Fermi's
828 * can do 297 MHz. Unclear how this can be determined.
830 if (drm->device.info.family >= NV_DEVICE_INFO_V0_KEPLER)
832 if (drm->device.info.family >= NV_DEVICE_INFO_V0_FERMI)
835 if (dcb->location != DCB_LOC_ON_CHIP ||
836 drm->device.info.chipset >= 0x46)
838 else if (drm->device.info.chipset >= 0x40)
840 else if (drm->device.info.chipset >= 0x18)
847 nouveau_connector_mode_valid(struct drm_connector *connector,
848 struct drm_display_mode *mode)
850 struct nouveau_connector *nv_connector = nouveau_connector(connector);
851 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
852 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
853 unsigned min_clock = 25000, max_clock = min_clock;
854 unsigned clock = mode->clock;
857 switch (nv_encoder->dcb->type) {
858 case DCB_OUTPUT_LVDS:
859 if (nv_connector->native_mode &&
860 (mode->hdisplay > nv_connector->native_mode->hdisplay ||
861 mode->vdisplay > nv_connector->native_mode->vdisplay))
867 case DCB_OUTPUT_TMDS:
868 hdmi = drm_detect_hdmi_monitor(nv_connector->edid);
869 max_clock = get_tmds_link_bandwidth(connector, hdmi);
870 if (!hdmi && nouveau_duallink &&
871 nv_encoder->dcb->duallink_possible)
874 case DCB_OUTPUT_ANALOG:
875 max_clock = nv_encoder->dcb->crtconf.maxfreq;
880 return get_slave_funcs(encoder)->mode_valid(encoder, mode);
882 max_clock = nv_encoder->dp.link_nr;
883 max_clock *= nv_encoder->dp.link_bw;
884 clock = clock * (connector->display_info.bpc * 3) / 10;
891 if (clock < min_clock)
892 return MODE_CLOCK_LOW;
894 if (clock > max_clock)
895 return MODE_CLOCK_HIGH;
900 static struct drm_encoder *
901 nouveau_connector_best_encoder(struct drm_connector *connector)
903 struct nouveau_connector *nv_connector = nouveau_connector(connector);
905 if (nv_connector->detected_encoder)
906 return to_drm_encoder(nv_connector->detected_encoder);
911 static const struct drm_connector_helper_funcs
912 nouveau_connector_helper_funcs = {
913 .get_modes = nouveau_connector_get_modes,
914 .mode_valid = nouveau_connector_mode_valid,
915 .best_encoder = nouveau_connector_best_encoder,
918 static const struct drm_connector_funcs
919 nouveau_connector_funcs = {
920 .dpms = drm_helper_connector_dpms,
921 .detect = nouveau_connector_detect,
922 .destroy = nouveau_connector_destroy,
923 .fill_modes = drm_helper_probe_single_connector_modes,
924 .set_property = nouveau_connector_set_property,
925 .force = nouveau_connector_force
928 static const struct drm_connector_funcs
929 nouveau_connector_funcs_lvds = {
930 .dpms = drm_helper_connector_dpms,
931 .detect = nouveau_connector_detect_lvds,
932 .destroy = nouveau_connector_destroy,
933 .fill_modes = drm_helper_probe_single_connector_modes,
934 .set_property = nouveau_connector_set_property,
935 .force = nouveau_connector_force
939 nouveau_connector_dp_dpms(struct drm_connector *connector, int mode)
941 struct nouveau_encoder *nv_encoder = NULL;
943 if (connector->encoder)
944 nv_encoder = nouveau_encoder(connector->encoder);
945 if (nv_encoder && nv_encoder->dcb &&
946 nv_encoder->dcb->type == DCB_OUTPUT_DP) {
947 if (mode == DRM_MODE_DPMS_ON) {
948 u8 data = DP_SET_POWER_D0;
949 nvkm_wraux(nv_encoder->aux, DP_SET_POWER, &data, 1);
950 usleep_range(1000, 2000);
952 u8 data = DP_SET_POWER_D3;
953 nvkm_wraux(nv_encoder->aux, DP_SET_POWER, &data, 1);
957 return drm_helper_connector_dpms(connector, mode);
960 static const struct drm_connector_funcs
961 nouveau_connector_funcs_dp = {
962 .dpms = nouveau_connector_dp_dpms,
963 .detect = nouveau_connector_detect,
964 .destroy = nouveau_connector_destroy,
965 .fill_modes = drm_helper_probe_single_connector_modes,
966 .set_property = nouveau_connector_set_property,
967 .force = nouveau_connector_force
971 nouveau_connector_hotplug(struct nvif_notify *notify)
973 struct nouveau_connector *nv_connector =
974 container_of(notify, typeof(*nv_connector), hpd);
975 struct drm_connector *connector = &nv_connector->base;
976 struct nouveau_drm *drm = nouveau_drm(connector->dev);
977 const struct nvif_notify_conn_rep_v0 *rep = notify->data;
978 const char *name = connector->name;
980 if (rep->mask & NVIF_NOTIFY_CONN_V0_IRQ) {
982 bool plugged = (rep->mask != NVIF_NOTIFY_CONN_V0_UNPLUG);
984 NV_DEBUG(drm, "%splugged %s\n", plugged ? "" : "un", name);
986 mutex_lock(&drm->dev->mode_config.mutex);
988 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
990 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
991 mutex_unlock(&drm->dev->mode_config.mutex);
993 drm_helper_hpd_irq_event(connector->dev);
996 return NVIF_NOTIFY_KEEP;
1000 nouveau_connector_aux_xfer(struct drm_dp_aux *obj, struct drm_dp_aux_msg *msg)
1002 struct nouveau_connector *nv_connector =
1003 container_of(obj, typeof(*nv_connector), aux);
1004 struct nouveau_encoder *nv_encoder;
1005 struct nvkm_i2c_aux *aux;
1008 nv_encoder = find_encoder(&nv_connector->base, DCB_OUTPUT_DP);
1009 if (!nv_encoder || !(aux = nv_encoder->aux))
1011 if (WARN_ON(msg->size > 16))
1016 ret = nvkm_i2c_aux_acquire(aux);
1020 ret = nvkm_i2c_aux_xfer(aux, false, msg->request, msg->address,
1021 msg->buffer, msg->size);
1022 nvkm_i2c_aux_release(aux);
1032 drm_conntype_from_dcb(enum dcb_connector_type dcb)
1035 case DCB_CONNECTOR_VGA : return DRM_MODE_CONNECTOR_VGA;
1036 case DCB_CONNECTOR_TV_0 :
1037 case DCB_CONNECTOR_TV_1 :
1038 case DCB_CONNECTOR_TV_3 : return DRM_MODE_CONNECTOR_TV;
1039 case DCB_CONNECTOR_DMS59_0 :
1040 case DCB_CONNECTOR_DMS59_1 :
1041 case DCB_CONNECTOR_DVI_I : return DRM_MODE_CONNECTOR_DVII;
1042 case DCB_CONNECTOR_DVI_D : return DRM_MODE_CONNECTOR_DVID;
1043 case DCB_CONNECTOR_LVDS :
1044 case DCB_CONNECTOR_LVDS_SPWG: return DRM_MODE_CONNECTOR_LVDS;
1045 case DCB_CONNECTOR_DMS59_DP0:
1046 case DCB_CONNECTOR_DMS59_DP1:
1047 case DCB_CONNECTOR_DP : return DRM_MODE_CONNECTOR_DisplayPort;
1048 case DCB_CONNECTOR_eDP : return DRM_MODE_CONNECTOR_eDP;
1049 case DCB_CONNECTOR_HDMI_0 :
1050 case DCB_CONNECTOR_HDMI_1 :
1051 case DCB_CONNECTOR_HDMI_C : return DRM_MODE_CONNECTOR_HDMIA;
1056 return DRM_MODE_CONNECTOR_Unknown;
1059 struct drm_connector *
1060 nouveau_connector_create(struct drm_device *dev, int index)
1062 const struct drm_connector_funcs *funcs = &nouveau_connector_funcs;
1063 struct nouveau_drm *drm = nouveau_drm(dev);
1064 struct nouveau_display *disp = nouveau_display(dev);
1065 struct nouveau_connector *nv_connector = NULL;
1066 struct drm_connector *connector;
1070 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1071 nv_connector = nouveau_connector(connector);
1072 if (nv_connector->index == index)
1076 nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL);
1078 return ERR_PTR(-ENOMEM);
1080 connector = &nv_connector->base;
1081 nv_connector->index = index;
1083 /* attempt to parse vbios connector type and hotplug gpio */
1084 nv_connector->dcb = olddcb_conn(dev, index);
1085 if (nv_connector->dcb) {
1086 u32 entry = ROM16(nv_connector->dcb[0]);
1087 if (olddcb_conntab(dev)[3] >= 4)
1088 entry |= (u32)ROM16(nv_connector->dcb[2]) << 16;
1090 nv_connector->type = nv_connector->dcb[0];
1091 if (drm_conntype_from_dcb(nv_connector->type) ==
1092 DRM_MODE_CONNECTOR_Unknown) {
1093 NV_WARN(drm, "unknown connector type %02x\n",
1094 nv_connector->type);
1095 nv_connector->type = DCB_CONNECTOR_NONE;
1098 /* Gigabyte NX85T */
1099 if (nv_match_device(dev, 0x0421, 0x1458, 0x344c)) {
1100 if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
1101 nv_connector->type = DCB_CONNECTOR_DVI_I;
1104 /* Gigabyte GV-NX86T512H */
1105 if (nv_match_device(dev, 0x0402, 0x1458, 0x3455)) {
1106 if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
1107 nv_connector->type = DCB_CONNECTOR_DVI_I;
1110 nv_connector->type = DCB_CONNECTOR_NONE;
1113 /* no vbios data, or an unknown dcb connector type - attempt to
1114 * figure out something suitable ourselves
1116 if (nv_connector->type == DCB_CONNECTOR_NONE) {
1117 struct nouveau_drm *drm = nouveau_drm(dev);
1118 struct dcb_table *dcbt = &drm->vbios.dcb;
1122 for (i = 0; i < dcbt->entries; i++) {
1123 if (dcbt->entry[i].connector == nv_connector->index)
1124 encoders |= (1 << dcbt->entry[i].type);
1127 if (encoders & (1 << DCB_OUTPUT_DP)) {
1128 if (encoders & (1 << DCB_OUTPUT_TMDS))
1129 nv_connector->type = DCB_CONNECTOR_DP;
1131 nv_connector->type = DCB_CONNECTOR_eDP;
1133 if (encoders & (1 << DCB_OUTPUT_TMDS)) {
1134 if (encoders & (1 << DCB_OUTPUT_ANALOG))
1135 nv_connector->type = DCB_CONNECTOR_DVI_I;
1137 nv_connector->type = DCB_CONNECTOR_DVI_D;
1139 if (encoders & (1 << DCB_OUTPUT_ANALOG)) {
1140 nv_connector->type = DCB_CONNECTOR_VGA;
1142 if (encoders & (1 << DCB_OUTPUT_LVDS)) {
1143 nv_connector->type = DCB_CONNECTOR_LVDS;
1145 if (encoders & (1 << DCB_OUTPUT_TV)) {
1146 nv_connector->type = DCB_CONNECTOR_TV_0;
1150 switch ((type = drm_conntype_from_dcb(nv_connector->type))) {
1151 case DRM_MODE_CONNECTOR_LVDS:
1152 ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &dummy);
1154 NV_ERROR(drm, "Error parsing LVDS table, disabling\n");
1155 kfree(nv_connector);
1156 return ERR_PTR(ret);
1159 funcs = &nouveau_connector_funcs_lvds;
1161 case DRM_MODE_CONNECTOR_DisplayPort:
1162 case DRM_MODE_CONNECTOR_eDP:
1163 nv_connector->aux.dev = dev->dev;
1164 nv_connector->aux.transfer = nouveau_connector_aux_xfer;
1165 ret = drm_dp_aux_register(&nv_connector->aux);
1167 NV_ERROR(drm, "failed to register aux channel\n");
1168 kfree(nv_connector);
1169 return ERR_PTR(ret);
1172 funcs = &nouveau_connector_funcs_dp;
1175 funcs = &nouveau_connector_funcs;
1179 /* defaults, will get overridden in detect() */
1180 connector->interlace_allowed = false;
1181 connector->doublescan_allowed = false;
1183 drm_connector_init(dev, connector, funcs, type);
1184 drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
1186 /* Init DVI-I specific properties */
1187 if (nv_connector->type == DCB_CONNECTOR_DVI_I)
1188 drm_object_attach_property(&connector->base, dev->mode_config.dvi_i_subconnector_property, 0);
1190 /* Add overscan compensation options to digital outputs */
1191 if (disp->underscan_property &&
1192 (type == DRM_MODE_CONNECTOR_DVID ||
1193 type == DRM_MODE_CONNECTOR_DVII ||
1194 type == DRM_MODE_CONNECTOR_HDMIA ||
1195 type == DRM_MODE_CONNECTOR_DisplayPort)) {
1196 drm_object_attach_property(&connector->base,
1197 disp->underscan_property,
1199 drm_object_attach_property(&connector->base,
1200 disp->underscan_hborder_property,
1202 drm_object_attach_property(&connector->base,
1203 disp->underscan_vborder_property,
1207 /* Add hue and saturation options */
1208 if (disp->vibrant_hue_property)
1209 drm_object_attach_property(&connector->base,
1210 disp->vibrant_hue_property,
1212 if (disp->color_vibrance_property)
1213 drm_object_attach_property(&connector->base,
1214 disp->color_vibrance_property,
1217 /* default scaling mode */
1218 switch (nv_connector->type) {
1219 case DCB_CONNECTOR_LVDS:
1220 case DCB_CONNECTOR_LVDS_SPWG:
1221 case DCB_CONNECTOR_eDP:
1222 /* see note in nouveau_connector_set_property() */
1223 if (disp->disp.oclass < NV50_DISP) {
1224 nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
1227 nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
1230 nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
1234 /* scaling mode property */
1235 switch (nv_connector->type) {
1236 case DCB_CONNECTOR_TV_0:
1237 case DCB_CONNECTOR_TV_1:
1238 case DCB_CONNECTOR_TV_3:
1240 case DCB_CONNECTOR_VGA:
1241 if (disp->disp.oclass < NV50_DISP)
1242 break; /* can only scale on DFPs */
1245 drm_object_attach_property(&connector->base, dev->mode_config.
1246 scaling_mode_property,
1247 nv_connector->scaling_mode);
1251 /* dithering properties */
1252 switch (nv_connector->type) {
1253 case DCB_CONNECTOR_TV_0:
1254 case DCB_CONNECTOR_TV_1:
1255 case DCB_CONNECTOR_TV_3:
1256 case DCB_CONNECTOR_VGA:
1259 if (disp->dithering_mode) {
1260 drm_object_attach_property(&connector->base,
1261 disp->dithering_mode,
1264 nv_connector->dithering_mode = DITHERING_MODE_AUTO;
1266 if (disp->dithering_depth) {
1267 drm_object_attach_property(&connector->base,
1268 disp->dithering_depth,
1271 nv_connector->dithering_depth = DITHERING_DEPTH_AUTO;
1276 ret = nvif_notify_init(&disp->disp, nouveau_connector_hotplug, true,
1277 NV04_DISP_NTFY_CONN,
1278 &(struct nvif_notify_conn_req_v0) {
1279 .mask = NVIF_NOTIFY_CONN_V0_ANY,
1282 sizeof(struct nvif_notify_conn_req_v0),
1283 sizeof(struct nvif_notify_conn_rep_v0),
1284 &nv_connector->hpd);
1286 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1288 connector->polled = DRM_CONNECTOR_POLL_HPD;
1290 drm_connector_register(connector);