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>
31 #include "drm_crtc_helper.h"
33 #include "nouveau_reg.h"
34 #include "nouveau_drv.h"
35 #include "nouveau_encoder.h"
36 #include "nouveau_crtc.h"
37 #include "nouveau_connector.h"
38 #include "nouveau_hw.h"
39 #include "nouveau_acpi.h"
41 #include <subdev/bios/gpio.h>
43 static void nouveau_connector_hotplug(void *, int);
45 struct nouveau_encoder *
46 find_encoder(struct drm_connector *connector, int type)
48 struct drm_device *dev = connector->dev;
49 struct nouveau_encoder *nv_encoder;
50 struct drm_mode_object *obj;
53 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
54 id = connector->encoder_ids[i];
58 obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
61 nv_encoder = nouveau_encoder(obj_to_encoder(obj));
63 if (type == DCB_OUTPUT_ANY || nv_encoder->dcb->type == type)
70 struct nouveau_connector *
71 nouveau_encoder_connector_get(struct nouveau_encoder *encoder)
73 struct drm_device *dev = to_drm_encoder(encoder)->dev;
74 struct drm_connector *drm_connector;
76 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
77 if (drm_connector->encoder == to_drm_encoder(encoder))
78 return nouveau_connector(drm_connector);
85 nouveau_connector_destroy(struct drm_connector *connector)
87 struct nouveau_connector *nv_connector = nouveau_connector(connector);
88 struct drm_nouveau_private *dev_priv;
89 struct drm_device *dev;
94 dev = nv_connector->base.dev;
95 dev_priv = dev->dev_private;
96 NV_DEBUG_KMS(dev, "\n");
98 if (nv_connector->hpd != DCB_GPIO_UNUSED) {
99 nouveau_gpio_isr_del(dev, 0, nv_connector->hpd, 0xff,
100 nouveau_connector_hotplug, connector);
103 kfree(nv_connector->edid);
104 drm_sysfs_connector_remove(connector);
105 drm_connector_cleanup(connector);
109 static struct nouveau_i2c_port *
110 nouveau_connector_ddc_detect(struct drm_connector *connector,
111 struct nouveau_encoder **pnv_encoder)
113 struct drm_device *dev = connector->dev;
116 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
117 struct nouveau_i2c_port *i2c = NULL;
118 struct nouveau_encoder *nv_encoder;
119 struct drm_mode_object *obj;
122 id = connector->encoder_ids[i];
126 obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
129 nv_encoder = nouveau_encoder(obj_to_encoder(obj));
131 if (nv_encoder->dcb->i2c_index < 0xf)
132 i2c = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index);
134 if (i2c && nouveau_probe_i2c_addr(i2c, 0x50)) {
135 *pnv_encoder = nv_encoder;
143 static struct nouveau_encoder *
144 nouveau_connector_of_detect(struct drm_connector *connector)
147 struct drm_device *dev = connector->dev;
148 struct nouveau_connector *nv_connector = nouveau_connector(connector);
149 struct nouveau_encoder *nv_encoder;
150 struct device_node *cn, *dn = pci_device_to_OF_node(dev->pdev);
153 !((nv_encoder = find_encoder(connector, DCB_OUTPUT_TMDS)) ||
154 (nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG))))
157 for_each_child_of_node(dn, cn) {
158 const char *name = of_get_property(cn, "name", NULL);
159 const void *edid = of_get_property(cn, "EDID", NULL);
160 int idx = name ? name[strlen(name) - 1] - 'A' : 0;
162 if (nv_encoder->dcb->i2c_index == idx && edid) {
164 kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
174 nouveau_connector_set_encoder(struct drm_connector *connector,
175 struct nouveau_encoder *nv_encoder)
177 struct nouveau_connector *nv_connector = nouveau_connector(connector);
178 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
179 struct drm_device *dev = connector->dev;
181 if (nv_connector->detected_encoder == nv_encoder)
183 nv_connector->detected_encoder = nv_encoder;
185 if (dev_priv->card_type >= NV_50) {
186 connector->interlace_allowed = true;
187 connector->doublescan_allowed = true;
189 if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS ||
190 nv_encoder->dcb->type == DCB_OUTPUT_TMDS) {
191 connector->doublescan_allowed = false;
192 connector->interlace_allowed = false;
194 connector->doublescan_allowed = true;
195 if (dev_priv->card_type == NV_20 ||
196 (dev_priv->card_type == NV_10 &&
197 (dev->pci_device & 0x0ff0) != 0x0100 &&
198 (dev->pci_device & 0x0ff0) != 0x0150))
200 connector->interlace_allowed = false;
202 connector->interlace_allowed = true;
205 if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
206 drm_connector_property_set_value(connector,
207 dev->mode_config.dvi_i_subconnector_property,
208 nv_encoder->dcb->type == DCB_OUTPUT_TMDS ?
209 DRM_MODE_SUBCONNECTOR_DVID :
210 DRM_MODE_SUBCONNECTOR_DVIA);
214 static enum drm_connector_status
215 nouveau_connector_detect(struct drm_connector *connector, bool force)
217 struct drm_device *dev = connector->dev;
218 struct nouveau_connector *nv_connector = nouveau_connector(connector);
219 struct nouveau_encoder *nv_encoder = NULL;
220 struct nouveau_encoder *nv_partner;
221 struct nouveau_i2c_port *i2c;
224 /* Cleanup the previous EDID block. */
225 if (nv_connector->edid) {
226 drm_mode_connector_update_edid_property(connector, NULL);
227 kfree(nv_connector->edid);
228 nv_connector->edid = NULL;
231 i2c = nouveau_connector_ddc_detect(connector, &nv_encoder);
233 nv_connector->edid = drm_get_edid(connector, nouveau_i2c_adapter(i2c));
234 drm_mode_connector_update_edid_property(connector,
236 if (!nv_connector->edid) {
237 NV_ERROR(dev, "DDC responded, but no EDID for %s\n",
238 drm_get_connector_name(connector));
242 if (nv_encoder->dcb->type == DCB_OUTPUT_DP &&
243 !nouveau_dp_detect(to_drm_encoder(nv_encoder))) {
244 NV_ERROR(dev, "Detected %s, but failed init\n",
245 drm_get_connector_name(connector));
246 return connector_status_disconnected;
249 /* Override encoder type for DVI-I based on whether EDID
250 * says the display is digital or analog, both use the
251 * same i2c channel so the value returned from ddc_detect
252 * isn't necessarily correct.
255 if (nv_encoder->dcb->type == DCB_OUTPUT_TMDS)
256 nv_partner = find_encoder(connector, DCB_OUTPUT_ANALOG);
257 if (nv_encoder->dcb->type == DCB_OUTPUT_ANALOG)
258 nv_partner = find_encoder(connector, DCB_OUTPUT_TMDS);
260 if (nv_partner && ((nv_encoder->dcb->type == DCB_OUTPUT_ANALOG &&
261 nv_partner->dcb->type == DCB_OUTPUT_TMDS) ||
262 (nv_encoder->dcb->type == DCB_OUTPUT_TMDS &&
263 nv_partner->dcb->type == DCB_OUTPUT_ANALOG))) {
264 if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
265 type = DCB_OUTPUT_TMDS;
267 type = DCB_OUTPUT_ANALOG;
269 nv_encoder = find_encoder(connector, type);
272 nouveau_connector_set_encoder(connector, nv_encoder);
273 return connector_status_connected;
276 nv_encoder = nouveau_connector_of_detect(connector);
278 nouveau_connector_set_encoder(connector, nv_encoder);
279 return connector_status_connected;
283 nv_encoder = find_encoder(connector, DCB_OUTPUT_ANALOG);
284 if (!nv_encoder && !nouveau_tv_disable)
285 nv_encoder = find_encoder(connector, DCB_OUTPUT_TV);
286 if (nv_encoder && force) {
287 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
288 struct drm_encoder_helper_funcs *helper =
289 encoder->helper_private;
291 if (helper->detect(encoder, connector) ==
292 connector_status_connected) {
293 nouveau_connector_set_encoder(connector, nv_encoder);
294 return connector_status_connected;
299 return connector_status_disconnected;
302 static enum drm_connector_status
303 nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
305 struct drm_device *dev = connector->dev;
306 struct drm_nouveau_private *dev_priv = dev->dev_private;
307 struct nouveau_connector *nv_connector = nouveau_connector(connector);
308 struct nouveau_encoder *nv_encoder = NULL;
309 enum drm_connector_status status = connector_status_disconnected;
311 /* Cleanup the previous EDID block. */
312 if (nv_connector->edid) {
313 drm_mode_connector_update_edid_property(connector, NULL);
314 kfree(nv_connector->edid);
315 nv_connector->edid = NULL;
318 nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS);
320 return connector_status_disconnected;
322 /* Try retrieving EDID via DDC */
323 if (!dev_priv->vbios.fp_no_ddc) {
324 status = nouveau_connector_detect(connector, force);
325 if (status == connector_status_connected)
329 /* On some laptops (Sony, i'm looking at you) there appears to
330 * be no direct way of accessing the panel's EDID. The only
331 * option available to us appears to be to ask ACPI for help..
333 * It's important this check's before trying straps, one of the
334 * said manufacturer's laptops are configured in such a way
335 * the nouveau decides an entry in the VBIOS FP mode table is
336 * valid - it's not (rh#613284)
338 if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
339 if (!(nv_connector->edid = nouveau_acpi_edid(dev, connector))) {
340 status = connector_status_connected;
345 /* If no EDID found above, and the VBIOS indicates a hardcoded
346 * modeline is avalilable for the panel, set it as the panel's
347 * native mode and exit.
349 if (nouveau_bios_fp_mode(dev, NULL) && (dev_priv->vbios.fp_no_ddc ||
350 nv_encoder->dcb->lvdsconf.use_straps_for_mode)) {
351 status = connector_status_connected;
355 /* Still nothing, some VBIOS images have a hardcoded EDID block
356 * stored for the panel stored in them.
358 if (!dev_priv->vbios.fp_no_ddc) {
360 (struct edid *)nouveau_bios_embedded_edid(dev);
362 nv_connector->edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
363 *(nv_connector->edid) = *edid;
364 status = connector_status_connected;
369 #if defined(CONFIG_ACPI_BUTTON) || \
370 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
371 if (status == connector_status_connected &&
372 !nouveau_ignorelid && !acpi_lid_open())
373 status = connector_status_unknown;
376 drm_mode_connector_update_edid_property(connector, nv_connector->edid);
377 nouveau_connector_set_encoder(connector, nv_encoder);
382 nouveau_connector_force(struct drm_connector *connector)
384 struct nouveau_connector *nv_connector = nouveau_connector(connector);
385 struct nouveau_encoder *nv_encoder;
388 if (nv_connector->type == DCB_CONNECTOR_DVI_I) {
389 if (connector->force == DRM_FORCE_ON_DIGITAL)
390 type = DCB_OUTPUT_TMDS;
392 type = DCB_OUTPUT_ANALOG;
394 type = DCB_OUTPUT_ANY;
396 nv_encoder = find_encoder(connector, type);
398 NV_ERROR(connector->dev, "can't find encoder to force %s on!\n",
399 drm_get_connector_name(connector));
400 connector->status = connector_status_disconnected;
404 nouveau_connector_set_encoder(connector, nv_encoder);
408 nouveau_connector_set_property(struct drm_connector *connector,
409 struct drm_property *property, uint64_t value)
411 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
412 struct nouveau_display_engine *disp = &dev_priv->engine.display;
413 struct nouveau_connector *nv_connector = nouveau_connector(connector);
414 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
415 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
416 struct drm_device *dev = connector->dev;
417 struct nouveau_crtc *nv_crtc;
421 if (connector->encoder && connector->encoder->crtc)
422 nv_crtc = nouveau_crtc(connector->encoder->crtc);
425 if (property == dev->mode_config.scaling_mode_property) {
426 bool modeset = false;
429 case DRM_MODE_SCALE_NONE:
430 case DRM_MODE_SCALE_FULLSCREEN:
431 case DRM_MODE_SCALE_CENTER:
432 case DRM_MODE_SCALE_ASPECT:
438 /* LVDS always needs gpu scaling */
439 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS &&
440 value == DRM_MODE_SCALE_NONE)
443 /* Changing between GPU and panel scaling requires a full
446 if ((nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) ||
447 (value == DRM_MODE_SCALE_NONE))
449 nv_connector->scaling_mode = value;
454 if (modeset || !nv_crtc->set_scale) {
455 ret = drm_crtc_helper_set_mode(&nv_crtc->base,
458 nv_crtc->base.y, NULL);
462 ret = nv_crtc->set_scale(nv_crtc, true);
471 if (property == disp->underscan_property) {
472 if (nv_connector->underscan != value) {
473 nv_connector->underscan = value;
474 if (!nv_crtc || !nv_crtc->set_scale)
477 return nv_crtc->set_scale(nv_crtc, true);
483 if (property == disp->underscan_hborder_property) {
484 if (nv_connector->underscan_hborder != value) {
485 nv_connector->underscan_hborder = value;
486 if (!nv_crtc || !nv_crtc->set_scale)
489 return nv_crtc->set_scale(nv_crtc, true);
495 if (property == disp->underscan_vborder_property) {
496 if (nv_connector->underscan_vborder != value) {
497 nv_connector->underscan_vborder = value;
498 if (!nv_crtc || !nv_crtc->set_scale)
501 return nv_crtc->set_scale(nv_crtc, true);
508 if (property == disp->dithering_mode) {
509 nv_connector->dithering_mode = value;
510 if (!nv_crtc || !nv_crtc->set_dither)
513 return nv_crtc->set_dither(nv_crtc, true);
516 if (property == disp->dithering_depth) {
517 nv_connector->dithering_depth = value;
518 if (!nv_crtc || !nv_crtc->set_dither)
521 return nv_crtc->set_dither(nv_crtc, true);
524 if (nv_crtc && nv_crtc->set_color_vibrance) {
526 if (property == disp->vibrant_hue_property) {
527 nv_crtc->vibrant_hue = value - 90;
528 return nv_crtc->set_color_vibrance(nv_crtc, true);
531 if (property == disp->color_vibrance_property) {
532 nv_crtc->color_vibrance = value - 100;
533 return nv_crtc->set_color_vibrance(nv_crtc, true);
537 if (nv_encoder && nv_encoder->dcb->type == DCB_OUTPUT_TV)
538 return get_slave_funcs(encoder)->set_property(
539 encoder, connector, property, value);
544 static struct drm_display_mode *
545 nouveau_connector_native_mode(struct drm_connector *connector)
547 struct drm_connector_helper_funcs *helper = connector->helper_private;
548 struct nouveau_connector *nv_connector = nouveau_connector(connector);
549 struct drm_device *dev = connector->dev;
550 struct drm_display_mode *mode, *largest = NULL;
551 int high_w = 0, high_h = 0, high_v = 0;
553 list_for_each_entry(mode, &nv_connector->base.probed_modes, head) {
554 mode->vrefresh = drm_mode_vrefresh(mode);
555 if (helper->mode_valid(connector, mode) != MODE_OK ||
556 (mode->flags & DRM_MODE_FLAG_INTERLACE))
559 /* Use preferred mode if there is one.. */
560 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
561 NV_DEBUG_KMS(dev, "native mode from preferred\n");
562 return drm_mode_duplicate(dev, mode);
565 /* Otherwise, take the resolution with the largest width, then
566 * height, then vertical refresh
568 if (mode->hdisplay < high_w)
571 if (mode->hdisplay == high_w && mode->vdisplay < high_h)
574 if (mode->hdisplay == high_w && mode->vdisplay == high_h &&
575 mode->vrefresh < high_v)
578 high_w = mode->hdisplay;
579 high_h = mode->vdisplay;
580 high_v = mode->vrefresh;
584 NV_DEBUG_KMS(dev, "native mode from largest: %dx%d@%d\n",
585 high_w, high_h, high_v);
586 return largest ? drm_mode_duplicate(dev, largest) : NULL;
594 static struct moderec scaler_modes[] = {
613 nouveau_connector_scaler_modes_add(struct drm_connector *connector)
615 struct nouveau_connector *nv_connector = nouveau_connector(connector);
616 struct drm_display_mode *native = nv_connector->native_mode, *m;
617 struct drm_device *dev = connector->dev;
618 struct moderec *mode = &scaler_modes[0];
624 while (mode->hdisplay) {
625 if (mode->hdisplay <= native->hdisplay &&
626 mode->vdisplay <= native->vdisplay) {
627 m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay,
628 drm_mode_vrefresh(native), false,
633 m->type |= DRM_MODE_TYPE_DRIVER;
635 drm_mode_probed_add(connector, m);
646 nouveau_connector_detect_depth(struct drm_connector *connector)
648 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
649 struct nouveau_connector *nv_connector = nouveau_connector(connector);
650 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
651 struct nvbios *bios = &dev_priv->vbios;
652 struct drm_display_mode *mode = nv_connector->native_mode;
655 /* if the edid is feeling nice enough to provide this info, use it */
656 if (nv_connector->edid && connector->display_info.bpc)
659 /* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */
660 if (nv_connector->type == DCB_CONNECTOR_eDP) {
661 connector->display_info.bpc = 6;
665 /* we're out of options unless we're LVDS, default to 8bpc */
666 if (nv_encoder->dcb->type != DCB_OUTPUT_LVDS) {
667 connector->display_info.bpc = 8;
671 connector->display_info.bpc = 6;
673 /* LVDS: panel straps */
674 if (bios->fp_no_ddc) {
675 if (bios->fp.if_is_24bit)
676 connector->display_info.bpc = 8;
680 /* LVDS: DDC panel, need to first determine the number of links to
681 * know which if_is_24bit flag to check...
683 if (nv_connector->edid &&
684 nv_connector->type == DCB_CONNECTOR_LVDS_SPWG)
685 duallink = ((u8 *)nv_connector->edid)[121] == 2;
687 duallink = mode->clock >= bios->fp.duallink_transition_clk;
689 if ((!duallink && (bios->fp.strapless_is_24bit & 1)) ||
690 ( duallink && (bios->fp.strapless_is_24bit & 2)))
691 connector->display_info.bpc = 8;
695 nouveau_connector_get_modes(struct drm_connector *connector)
697 struct drm_device *dev = connector->dev;
698 struct drm_nouveau_private *dev_priv = dev->dev_private;
699 struct nouveau_connector *nv_connector = nouveau_connector(connector);
700 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
701 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
704 /* destroy the native mode, the attached monitor could have changed.
706 if (nv_connector->native_mode) {
707 drm_mode_destroy(dev, nv_connector->native_mode);
708 nv_connector->native_mode = NULL;
711 if (nv_connector->edid)
712 ret = drm_add_edid_modes(connector, nv_connector->edid);
714 if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS &&
715 (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
716 dev_priv->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) {
717 struct drm_display_mode mode;
719 nouveau_bios_fp_mode(dev, &mode);
720 nv_connector->native_mode = drm_mode_duplicate(dev, &mode);
723 /* Determine display colour depth for everything except LVDS now,
724 * DP requires this before mode_valid() is called.
726 if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS)
727 nouveau_connector_detect_depth(connector);
729 /* Find the native mode if this is a digital panel, if we didn't
730 * find any modes through DDC previously add the native mode to
733 if (!nv_connector->native_mode)
734 nv_connector->native_mode =
735 nouveau_connector_native_mode(connector);
736 if (ret == 0 && nv_connector->native_mode) {
737 struct drm_display_mode *mode;
739 mode = drm_mode_duplicate(dev, nv_connector->native_mode);
740 drm_mode_probed_add(connector, mode);
744 /* Determine LVDS colour depth, must happen after determining
745 * "native" mode as some VBIOS tables require us to use the
746 * pixel clock as part of the lookup...
748 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
749 nouveau_connector_detect_depth(connector);
751 if (nv_encoder->dcb->type == DCB_OUTPUT_TV)
752 ret = get_slave_funcs(encoder)->get_modes(encoder, connector);
754 if (nv_connector->type == DCB_CONNECTOR_LVDS ||
755 nv_connector->type == DCB_CONNECTOR_LVDS_SPWG ||
756 nv_connector->type == DCB_CONNECTOR_eDP)
757 ret += nouveau_connector_scaler_modes_add(connector);
763 get_tmds_link_bandwidth(struct drm_connector *connector)
765 struct nouveau_connector *nv_connector = nouveau_connector(connector);
766 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
767 struct dcb_output *dcb = nv_connector->detected_encoder->dcb;
769 if (dcb->location != DCB_LOC_ON_CHIP ||
770 dev_priv->chipset >= 0x46)
772 else if (dev_priv->chipset >= 0x40)
774 else if (dev_priv->chipset >= 0x18)
781 nouveau_connector_mode_valid(struct drm_connector *connector,
782 struct drm_display_mode *mode)
784 struct nouveau_connector *nv_connector = nouveau_connector(connector);
785 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
786 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
787 unsigned min_clock = 25000, max_clock = min_clock;
788 unsigned clock = mode->clock;
790 switch (nv_encoder->dcb->type) {
791 case DCB_OUTPUT_LVDS:
792 if (nv_connector->native_mode &&
793 (mode->hdisplay > nv_connector->native_mode->hdisplay ||
794 mode->vdisplay > nv_connector->native_mode->vdisplay))
800 case DCB_OUTPUT_TMDS:
801 max_clock = get_tmds_link_bandwidth(connector);
802 if (nouveau_duallink && nv_encoder->dcb->duallink_possible)
805 case DCB_OUTPUT_ANALOG:
806 max_clock = nv_encoder->dcb->crtconf.maxfreq;
811 return get_slave_funcs(encoder)->mode_valid(encoder, mode);
813 max_clock = nv_encoder->dp.link_nr;
814 max_clock *= nv_encoder->dp.link_bw;
815 clock = clock * (connector->display_info.bpc * 3) / 10;
822 if (clock < min_clock)
823 return MODE_CLOCK_LOW;
825 if (clock > max_clock)
826 return MODE_CLOCK_HIGH;
831 static struct drm_encoder *
832 nouveau_connector_best_encoder(struct drm_connector *connector)
834 struct nouveau_connector *nv_connector = nouveau_connector(connector);
836 if (nv_connector->detected_encoder)
837 return to_drm_encoder(nv_connector->detected_encoder);
842 static const struct drm_connector_helper_funcs
843 nouveau_connector_helper_funcs = {
844 .get_modes = nouveau_connector_get_modes,
845 .mode_valid = nouveau_connector_mode_valid,
846 .best_encoder = nouveau_connector_best_encoder,
849 static const struct drm_connector_funcs
850 nouveau_connector_funcs = {
851 .dpms = drm_helper_connector_dpms,
854 .detect = nouveau_connector_detect,
855 .destroy = nouveau_connector_destroy,
856 .fill_modes = drm_helper_probe_single_connector_modes,
857 .set_property = nouveau_connector_set_property,
858 .force = nouveau_connector_force
861 static const struct drm_connector_funcs
862 nouveau_connector_funcs_lvds = {
863 .dpms = drm_helper_connector_dpms,
866 .detect = nouveau_connector_detect_lvds,
867 .destroy = nouveau_connector_destroy,
868 .fill_modes = drm_helper_probe_single_connector_modes,
869 .set_property = nouveau_connector_set_property,
870 .force = nouveau_connector_force
874 drm_conntype_from_dcb(enum dcb_connector_type dcb)
877 case DCB_CONNECTOR_VGA : return DRM_MODE_CONNECTOR_VGA;
878 case DCB_CONNECTOR_TV_0 :
879 case DCB_CONNECTOR_TV_1 :
880 case DCB_CONNECTOR_TV_3 : return DRM_MODE_CONNECTOR_TV;
881 case DCB_CONNECTOR_DMS59_0 :
882 case DCB_CONNECTOR_DMS59_1 :
883 case DCB_CONNECTOR_DVI_I : return DRM_MODE_CONNECTOR_DVII;
884 case DCB_CONNECTOR_DVI_D : return DRM_MODE_CONNECTOR_DVID;
885 case DCB_CONNECTOR_LVDS :
886 case DCB_CONNECTOR_LVDS_SPWG: return DRM_MODE_CONNECTOR_LVDS;
887 case DCB_CONNECTOR_DMS59_DP0:
888 case DCB_CONNECTOR_DMS59_DP1:
889 case DCB_CONNECTOR_DP : return DRM_MODE_CONNECTOR_DisplayPort;
890 case DCB_CONNECTOR_eDP : return DRM_MODE_CONNECTOR_eDP;
891 case DCB_CONNECTOR_HDMI_0 :
892 case DCB_CONNECTOR_HDMI_1 : return DRM_MODE_CONNECTOR_HDMIA;
897 return DRM_MODE_CONNECTOR_Unknown;
900 struct drm_connector *
901 nouveau_connector_create(struct drm_device *dev, int index)
903 const struct drm_connector_funcs *funcs = &nouveau_connector_funcs;
904 struct drm_nouveau_private *dev_priv = dev->dev_private;
905 struct nouveau_display_engine *disp = &dev_priv->engine.display;
906 struct nouveau_connector *nv_connector = NULL;
907 struct drm_connector *connector;
911 NV_DEBUG_KMS(dev, "\n");
913 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
914 nv_connector = nouveau_connector(connector);
915 if (nv_connector->index == index)
919 nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL);
921 return ERR_PTR(-ENOMEM);
923 connector = &nv_connector->base;
924 nv_connector->index = index;
926 /* attempt to parse vbios connector type and hotplug gpio */
927 nv_connector->dcb = olddcb_conn(dev, index);
928 if (nv_connector->dcb) {
929 static const u8 hpd[16] = {
930 0xff, 0x07, 0x08, 0xff, 0xff, 0x51, 0x52, 0xff,
931 0xff, 0xff, 0xff, 0xff, 0xff, 0x5e, 0x5f, 0x60,
934 u32 entry = ROM16(nv_connector->dcb[0]);
935 if (olddcb_conntab(dev)[3] >= 4)
936 entry |= (u32)ROM16(nv_connector->dcb[2]) << 16;
938 nv_connector->hpd = ffs((entry & 0x07033000) >> 12);
939 nv_connector->hpd = hpd[nv_connector->hpd];
941 nv_connector->type = nv_connector->dcb[0];
942 if (drm_conntype_from_dcb(nv_connector->type) ==
943 DRM_MODE_CONNECTOR_Unknown) {
944 NV_WARN(dev, "unknown connector type %02x\n",
946 nv_connector->type = DCB_CONNECTOR_NONE;
950 if (nv_match_device(dev, 0x0421, 0x1458, 0x344c)) {
951 if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
952 nv_connector->type = DCB_CONNECTOR_DVI_I;
955 /* Gigabyte GV-NX86T512H */
956 if (nv_match_device(dev, 0x0402, 0x1458, 0x3455)) {
957 if (nv_connector->type == DCB_CONNECTOR_HDMI_1)
958 nv_connector->type = DCB_CONNECTOR_DVI_I;
961 nv_connector->type = DCB_CONNECTOR_NONE;
962 nv_connector->hpd = DCB_GPIO_UNUSED;
965 /* no vbios data, or an unknown dcb connector type - attempt to
966 * figure out something suitable ourselves
968 if (nv_connector->type == DCB_CONNECTOR_NONE) {
969 struct drm_nouveau_private *dev_priv = dev->dev_private;
970 struct dcb_table *dcbt = &dev_priv->vbios.dcb;
974 for (i = 0; i < dcbt->entries; i++) {
975 if (dcbt->entry[i].connector == nv_connector->index)
976 encoders |= (1 << dcbt->entry[i].type);
979 if (encoders & (1 << DCB_OUTPUT_DP)) {
980 if (encoders & (1 << DCB_OUTPUT_TMDS))
981 nv_connector->type = DCB_CONNECTOR_DP;
983 nv_connector->type = DCB_CONNECTOR_eDP;
985 if (encoders & (1 << DCB_OUTPUT_TMDS)) {
986 if (encoders & (1 << DCB_OUTPUT_ANALOG))
987 nv_connector->type = DCB_CONNECTOR_DVI_I;
989 nv_connector->type = DCB_CONNECTOR_DVI_D;
991 if (encoders & (1 << DCB_OUTPUT_ANALOG)) {
992 nv_connector->type = DCB_CONNECTOR_VGA;
994 if (encoders & (1 << DCB_OUTPUT_LVDS)) {
995 nv_connector->type = DCB_CONNECTOR_LVDS;
997 if (encoders & (1 << DCB_OUTPUT_TV)) {
998 nv_connector->type = DCB_CONNECTOR_TV_0;
1002 type = drm_conntype_from_dcb(nv_connector->type);
1003 if (type == DRM_MODE_CONNECTOR_LVDS) {
1004 ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &dummy);
1006 NV_ERROR(dev, "Error parsing LVDS table, disabling\n");
1007 kfree(nv_connector);
1008 return ERR_PTR(ret);
1011 funcs = &nouveau_connector_funcs_lvds;
1013 funcs = &nouveau_connector_funcs;
1016 /* defaults, will get overridden in detect() */
1017 connector->interlace_allowed = false;
1018 connector->doublescan_allowed = false;
1020 drm_connector_init(dev, connector, funcs, type);
1021 drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
1023 /* Init DVI-I specific properties */
1024 if (nv_connector->type == DCB_CONNECTOR_DVI_I)
1025 drm_connector_attach_property(connector, dev->mode_config.dvi_i_subconnector_property, 0);
1027 /* Add overscan compensation options to digital outputs */
1028 if (disp->underscan_property &&
1029 (type == DRM_MODE_CONNECTOR_DVID ||
1030 type == DRM_MODE_CONNECTOR_DVII ||
1031 type == DRM_MODE_CONNECTOR_HDMIA ||
1032 type == DRM_MODE_CONNECTOR_DisplayPort)) {
1033 drm_connector_attach_property(connector,
1034 disp->underscan_property,
1036 drm_connector_attach_property(connector,
1037 disp->underscan_hborder_property,
1039 drm_connector_attach_property(connector,
1040 disp->underscan_vborder_property,
1044 /* Add hue and saturation options */
1045 if (disp->vibrant_hue_property)
1046 drm_connector_attach_property(connector,
1047 disp->vibrant_hue_property,
1049 if (disp->color_vibrance_property)
1050 drm_connector_attach_property(connector,
1051 disp->color_vibrance_property,
1054 switch (nv_connector->type) {
1055 case DCB_CONNECTOR_VGA:
1056 if (dev_priv->card_type >= NV_50) {
1057 drm_connector_attach_property(connector,
1058 dev->mode_config.scaling_mode_property,
1059 nv_connector->scaling_mode);
1062 case DCB_CONNECTOR_TV_0:
1063 case DCB_CONNECTOR_TV_1:
1064 case DCB_CONNECTOR_TV_3:
1065 nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
1068 nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
1070 drm_connector_attach_property(connector,
1071 dev->mode_config.scaling_mode_property,
1072 nv_connector->scaling_mode);
1073 if (disp->dithering_mode) {
1074 nv_connector->dithering_mode = DITHERING_MODE_AUTO;
1075 drm_connector_attach_property(connector,
1076 disp->dithering_mode,
1077 nv_connector->dithering_mode);
1079 if (disp->dithering_depth) {
1080 nv_connector->dithering_depth = DITHERING_DEPTH_AUTO;
1081 drm_connector_attach_property(connector,
1082 disp->dithering_depth,
1083 nv_connector->dithering_depth);
1088 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1089 if (nv_connector->hpd != DCB_GPIO_UNUSED) {
1090 ret = nouveau_gpio_isr_add(dev, 0, nv_connector->hpd, 0xff,
1091 nouveau_connector_hotplug,
1094 connector->polled = DRM_CONNECTOR_POLL_HPD;
1097 drm_sysfs_connector_add(connector);
1102 nouveau_connector_hotplug(void *data, int plugged)
1104 struct drm_connector *connector = data;
1105 struct drm_device *dev = connector->dev;
1107 NV_DEBUG(dev, "%splugged %s\n", plugged ? "" : "un",
1108 drm_get_connector_name(connector));
1111 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
1113 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
1115 drm_helper_hpd_irq_event(dev);