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"
40 static struct nouveau_encoder *
41 find_encoder_by_type(struct drm_connector *connector, int type)
43 struct drm_device *dev = connector->dev;
44 struct nouveau_encoder *nv_encoder;
45 struct drm_mode_object *obj;
48 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
49 id = connector->encoder_ids[i];
53 obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
56 nv_encoder = nouveau_encoder(obj_to_encoder(obj));
58 if (type == OUTPUT_ANY || nv_encoder->dcb->type == type)
65 struct nouveau_connector *
66 nouveau_encoder_connector_get(struct nouveau_encoder *encoder)
68 struct drm_device *dev = to_drm_encoder(encoder)->dev;
69 struct drm_connector *drm_connector;
71 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
72 if (drm_connector->encoder == to_drm_encoder(encoder))
73 return nouveau_connector(drm_connector);
79 /*TODO: This could use improvement, and learn to handle the fixed
80 * BIOS tables etc. It's fine currently, for its only user.
83 nouveau_connector_bpp(struct drm_connector *connector)
85 struct nouveau_connector *nv_connector = nouveau_connector(connector);
87 if (nv_connector->edid && nv_connector->edid->revision >= 4) {
88 u8 bpc = ((nv_connector->edid->input & 0x70) >> 3) + 4;
97 nouveau_connector_destroy(struct drm_connector *drm_connector)
99 struct nouveau_connector *nv_connector =
100 nouveau_connector(drm_connector);
101 struct drm_device *dev;
106 dev = nv_connector->base.dev;
107 NV_DEBUG_KMS(dev, "\n");
109 kfree(nv_connector->edid);
110 drm_sysfs_connector_remove(drm_connector);
111 drm_connector_cleanup(drm_connector);
112 kfree(drm_connector);
115 static struct nouveau_i2c_chan *
116 nouveau_connector_ddc_detect(struct drm_connector *connector,
117 struct nouveau_encoder **pnv_encoder)
119 struct drm_device *dev = connector->dev;
122 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
123 struct nouveau_i2c_chan *i2c = NULL;
124 struct nouveau_encoder *nv_encoder;
125 struct drm_mode_object *obj;
128 id = connector->encoder_ids[i];
132 obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
135 nv_encoder = nouveau_encoder(obj_to_encoder(obj));
137 if (nv_encoder->dcb->i2c_index < 0xf)
138 i2c = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index);
140 if (i2c && nouveau_probe_i2c_addr(i2c, 0x50)) {
141 *pnv_encoder = nv_encoder;
149 static struct nouveau_encoder *
150 nouveau_connector_of_detect(struct drm_connector *connector)
153 struct drm_device *dev = connector->dev;
154 struct nouveau_connector *nv_connector = nouveau_connector(connector);
155 struct nouveau_encoder *nv_encoder;
156 struct device_node *cn, *dn = pci_device_to_OF_node(dev->pdev);
159 !((nv_encoder = find_encoder_by_type(connector, OUTPUT_TMDS)) ||
160 (nv_encoder = find_encoder_by_type(connector, OUTPUT_ANALOG))))
163 for_each_child_of_node(dn, cn) {
164 const char *name = of_get_property(cn, "name", NULL);
165 const void *edid = of_get_property(cn, "EDID", NULL);
166 int idx = name ? name[strlen(name) - 1] - 'A' : 0;
168 if (nv_encoder->dcb->i2c_index == idx && edid) {
170 kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
180 nouveau_connector_set_encoder(struct drm_connector *connector,
181 struct nouveau_encoder *nv_encoder)
183 struct nouveau_connector *nv_connector = nouveau_connector(connector);
184 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
185 struct drm_device *dev = connector->dev;
187 if (nv_connector->detected_encoder == nv_encoder)
189 nv_connector->detected_encoder = nv_encoder;
191 if (nv_encoder->dcb->type == OUTPUT_LVDS ||
192 nv_encoder->dcb->type == OUTPUT_TMDS) {
193 connector->doublescan_allowed = false;
194 connector->interlace_allowed = false;
196 connector->doublescan_allowed = true;
197 if (dev_priv->card_type == NV_20 ||
198 (dev_priv->card_type == NV_10 &&
199 (dev->pci_device & 0x0ff0) != 0x0100 &&
200 (dev->pci_device & 0x0ff0) != 0x0150))
202 connector->interlace_allowed = false;
204 connector->interlace_allowed = true;
207 if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) {
208 drm_connector_property_set_value(connector,
209 dev->mode_config.dvi_i_subconnector_property,
210 nv_encoder->dcb->type == OUTPUT_TMDS ?
211 DRM_MODE_SUBCONNECTOR_DVID :
212 DRM_MODE_SUBCONNECTOR_DVIA);
217 nouveau_connector_poll_allowed(struct drm_connector *connector)
219 struct drm_device *dev = connector->dev;
220 struct drm_nouveau_private *dev_priv = dev->dev_private;
221 struct drm_crtc *crtc;
222 bool spare_crtc = false;
224 if (dev_priv->card_type >= NV_50) {
227 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
228 spare_crtc |= !crtc->enabled;
234 static enum drm_connector_status
235 nouveau_connector_detect(struct drm_connector *connector, bool force)
237 struct drm_device *dev = connector->dev;
238 struct nouveau_connector *nv_connector = nouveau_connector(connector);
239 struct nouveau_encoder *nv_encoder = NULL;
240 struct nouveau_i2c_chan *i2c;
243 /* Cleanup the previous EDID block. */
244 if (nv_connector->edid) {
245 drm_mode_connector_update_edid_property(connector, NULL);
246 kfree(nv_connector->edid);
247 nv_connector->edid = NULL;
250 i2c = nouveau_connector_ddc_detect(connector, &nv_encoder);
252 nv_connector->edid = drm_get_edid(connector, &i2c->adapter);
253 drm_mode_connector_update_edid_property(connector,
255 if (!nv_connector->edid) {
256 NV_ERROR(dev, "DDC responded, but no EDID for %s\n",
257 drm_get_connector_name(connector));
261 if (nv_encoder->dcb->type == OUTPUT_DP &&
262 !nouveau_dp_detect(to_drm_encoder(nv_encoder))) {
263 NV_ERROR(dev, "Detected %s, but failed init\n",
264 drm_get_connector_name(connector));
265 return connector_status_disconnected;
268 /* Override encoder type for DVI-I based on whether EDID
269 * says the display is digital or analog, both use the
270 * same i2c channel so the value returned from ddc_detect
271 * isn't necessarily correct.
273 if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) {
274 if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
277 type = OUTPUT_ANALOG;
279 nv_encoder = find_encoder_by_type(connector, type);
281 NV_ERROR(dev, "Detected %d encoder on %s, "
282 "but no object!\n", type,
283 drm_get_connector_name(connector));
284 return connector_status_disconnected;
288 nouveau_connector_set_encoder(connector, nv_encoder);
289 return connector_status_connected;
292 nv_encoder = nouveau_connector_of_detect(connector);
294 nouveau_connector_set_encoder(connector, nv_encoder);
295 return connector_status_connected;
299 nv_encoder = find_encoder_by_type(connector, OUTPUT_ANALOG);
300 if (!nv_encoder && !nouveau_tv_disable)
301 nv_encoder = find_encoder_by_type(connector, OUTPUT_TV);
303 (force || nouveau_connector_poll_allowed(connector))) {
304 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
305 struct drm_encoder_helper_funcs *helper =
306 encoder->helper_private;
308 if (helper->detect(encoder, connector) ==
309 connector_status_connected) {
310 nouveau_connector_set_encoder(connector, nv_encoder);
311 return connector_status_connected;
316 return connector_status_disconnected;
319 static enum drm_connector_status
320 nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
322 struct drm_device *dev = connector->dev;
323 struct drm_nouveau_private *dev_priv = dev->dev_private;
324 struct nouveau_connector *nv_connector = nouveau_connector(connector);
325 struct nouveau_encoder *nv_encoder = NULL;
326 enum drm_connector_status status = connector_status_disconnected;
328 /* Cleanup the previous EDID block. */
329 if (nv_connector->edid) {
330 drm_mode_connector_update_edid_property(connector, NULL);
331 kfree(nv_connector->edid);
332 nv_connector->edid = NULL;
335 nv_encoder = find_encoder_by_type(connector, OUTPUT_LVDS);
337 return connector_status_disconnected;
339 /* Try retrieving EDID via DDC */
340 if (!dev_priv->vbios.fp_no_ddc) {
341 status = nouveau_connector_detect(connector, force);
342 if (status == connector_status_connected)
346 /* On some laptops (Sony, i'm looking at you) there appears to
347 * be no direct way of accessing the panel's EDID. The only
348 * option available to us appears to be to ask ACPI for help..
350 * It's important this check's before trying straps, one of the
351 * said manufacturer's laptops are configured in such a way
352 * the nouveau decides an entry in the VBIOS FP mode table is
353 * valid - it's not (rh#613284)
355 if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
356 if (!nouveau_acpi_edid(dev, connector)) {
357 status = connector_status_connected;
362 /* If no EDID found above, and the VBIOS indicates a hardcoded
363 * modeline is avalilable for the panel, set it as the panel's
364 * native mode and exit.
366 if (nouveau_bios_fp_mode(dev, NULL) && (dev_priv->vbios.fp_no_ddc ||
367 nv_encoder->dcb->lvdsconf.use_straps_for_mode)) {
368 status = connector_status_connected;
372 /* Still nothing, some VBIOS images have a hardcoded EDID block
373 * stored for the panel stored in them.
375 if (!dev_priv->vbios.fp_no_ddc) {
377 (struct edid *)nouveau_bios_embedded_edid(dev);
379 nv_connector->edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
380 *(nv_connector->edid) = *edid;
381 status = connector_status_connected;
386 #if defined(CONFIG_ACPI_BUTTON) || \
387 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
388 if (status == connector_status_connected &&
389 !nouveau_ignorelid && !acpi_lid_open())
390 status = connector_status_unknown;
393 drm_mode_connector_update_edid_property(connector, nv_connector->edid);
394 nouveau_connector_set_encoder(connector, nv_encoder);
399 nouveau_connector_force(struct drm_connector *connector)
401 struct nouveau_connector *nv_connector = nouveau_connector(connector);
402 struct nouveau_encoder *nv_encoder;
405 if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) {
406 if (connector->force == DRM_FORCE_ON_DIGITAL)
409 type = OUTPUT_ANALOG;
413 nv_encoder = find_encoder_by_type(connector, type);
415 NV_ERROR(connector->dev, "can't find encoder to force %s on!\n",
416 drm_get_connector_name(connector));
417 connector->status = connector_status_disconnected;
421 nouveau_connector_set_encoder(connector, nv_encoder);
425 nouveau_connector_set_property(struct drm_connector *connector,
426 struct drm_property *property, uint64_t value)
428 struct nouveau_connector *nv_connector = nouveau_connector(connector);
429 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
430 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
431 struct drm_device *dev = connector->dev;
435 if (property == dev->mode_config.scaling_mode_property) {
436 struct nouveau_crtc *nv_crtc = NULL;
437 bool modeset = false;
440 case DRM_MODE_SCALE_NONE:
441 case DRM_MODE_SCALE_FULLSCREEN:
442 case DRM_MODE_SCALE_CENTER:
443 case DRM_MODE_SCALE_ASPECT:
449 /* LVDS always needs gpu scaling */
450 if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS &&
451 value == DRM_MODE_SCALE_NONE)
454 /* Changing between GPU and panel scaling requires a full
457 if ((nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) ||
458 (value == DRM_MODE_SCALE_NONE))
460 nv_connector->scaling_mode = value;
462 if (connector->encoder && connector->encoder->crtc)
463 nv_crtc = nouveau_crtc(connector->encoder->crtc);
467 if (modeset || !nv_crtc->set_scale) {
468 ret = drm_crtc_helper_set_mode(&nv_crtc->base,
471 nv_crtc->base.y, NULL);
475 ret = nv_crtc->set_scale(nv_crtc, value, true);
484 if (property == dev->mode_config.dithering_mode_property) {
485 struct nouveau_crtc *nv_crtc = NULL;
487 if (value == DRM_MODE_DITHERING_ON)
488 nv_connector->use_dithering = true;
490 nv_connector->use_dithering = false;
492 if (connector->encoder && connector->encoder->crtc)
493 nv_crtc = nouveau_crtc(connector->encoder->crtc);
495 if (!nv_crtc || !nv_crtc->set_dither)
498 return nv_crtc->set_dither(nv_crtc, nv_connector->use_dithering,
502 if (nv_encoder && nv_encoder->dcb->type == OUTPUT_TV)
503 return get_slave_funcs(encoder)->set_property(
504 encoder, connector, property, value);
509 static struct drm_display_mode *
510 nouveau_connector_native_mode(struct drm_connector *connector)
512 struct drm_connector_helper_funcs *helper = connector->helper_private;
513 struct nouveau_connector *nv_connector = nouveau_connector(connector);
514 struct drm_device *dev = connector->dev;
515 struct drm_display_mode *mode, *largest = NULL;
516 int high_w = 0, high_h = 0, high_v = 0;
518 list_for_each_entry(mode, &nv_connector->base.probed_modes, head) {
519 if (helper->mode_valid(connector, mode) != MODE_OK ||
520 (mode->flags & DRM_MODE_FLAG_INTERLACE))
523 /* Use preferred mode if there is one.. */
524 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
525 NV_DEBUG_KMS(dev, "native mode from preferred\n");
526 return drm_mode_duplicate(dev, mode);
529 /* Otherwise, take the resolution with the largest width, then
530 * height, then vertical refresh
532 if (mode->hdisplay < high_w)
535 if (mode->hdisplay == high_w && mode->vdisplay < high_h)
538 if (mode->hdisplay == high_w && mode->vdisplay == high_h &&
539 mode->vrefresh < high_v)
542 high_w = mode->hdisplay;
543 high_h = mode->vdisplay;
544 high_v = mode->vrefresh;
548 NV_DEBUG_KMS(dev, "native mode from largest: %dx%d@%d\n",
549 high_w, high_h, high_v);
550 return largest ? drm_mode_duplicate(dev, largest) : NULL;
558 static struct moderec scaler_modes[] = {
577 nouveau_connector_scaler_modes_add(struct drm_connector *connector)
579 struct nouveau_connector *nv_connector = nouveau_connector(connector);
580 struct drm_display_mode *native = nv_connector->native_mode, *m;
581 struct drm_device *dev = connector->dev;
582 struct moderec *mode = &scaler_modes[0];
588 while (mode->hdisplay) {
589 if (mode->hdisplay <= native->hdisplay &&
590 mode->vdisplay <= native->vdisplay) {
591 m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay,
592 drm_mode_vrefresh(native), false,
597 m->type |= DRM_MODE_TYPE_DRIVER;
599 drm_mode_probed_add(connector, m);
610 nouveau_connector_get_modes(struct drm_connector *connector)
612 struct drm_device *dev = connector->dev;
613 struct drm_nouveau_private *dev_priv = dev->dev_private;
614 struct nouveau_connector *nv_connector = nouveau_connector(connector);
615 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
616 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
619 /* destroy the native mode, the attached monitor could have changed.
621 if (nv_connector->native_mode) {
622 drm_mode_destroy(dev, nv_connector->native_mode);
623 nv_connector->native_mode = NULL;
626 if (nv_connector->edid)
627 ret = drm_add_edid_modes(connector, nv_connector->edid);
629 if (nv_encoder->dcb->type == OUTPUT_LVDS &&
630 (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
631 dev_priv->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) {
632 struct drm_display_mode mode;
634 nouveau_bios_fp_mode(dev, &mode);
635 nv_connector->native_mode = drm_mode_duplicate(dev, &mode);
638 /* Find the native mode if this is a digital panel, if we didn't
639 * find any modes through DDC previously add the native mode to
642 if (!nv_connector->native_mode)
643 nv_connector->native_mode =
644 nouveau_connector_native_mode(connector);
645 if (ret == 0 && nv_connector->native_mode) {
646 struct drm_display_mode *mode;
648 mode = drm_mode_duplicate(dev, nv_connector->native_mode);
649 drm_mode_probed_add(connector, mode);
653 if (nv_encoder->dcb->type == OUTPUT_TV)
654 ret = get_slave_funcs(encoder)->get_modes(encoder, connector);
656 if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS ||
657 nv_connector->dcb->type == DCB_CONNECTOR_eDP)
658 ret += nouveau_connector_scaler_modes_add(connector);
664 get_tmds_link_bandwidth(struct drm_connector *connector)
666 struct nouveau_connector *nv_connector = nouveau_connector(connector);
667 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
668 struct dcb_entry *dcb = nv_connector->detected_encoder->dcb;
670 if (dcb->location != DCB_LOC_ON_CHIP ||
671 dev_priv->chipset >= 0x46)
673 else if (dev_priv->chipset >= 0x40)
675 else if (dev_priv->chipset >= 0x18)
682 nouveau_connector_mode_valid(struct drm_connector *connector,
683 struct drm_display_mode *mode)
685 struct nouveau_connector *nv_connector = nouveau_connector(connector);
686 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
687 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
688 unsigned min_clock = 25000, max_clock = min_clock;
689 unsigned clock = mode->clock;
691 switch (nv_encoder->dcb->type) {
693 if (nv_connector->native_mode &&
694 (mode->hdisplay > nv_connector->native_mode->hdisplay ||
695 mode->vdisplay > nv_connector->native_mode->vdisplay))
702 max_clock = get_tmds_link_bandwidth(connector);
703 if (nouveau_duallink && nv_encoder->dcb->duallink_possible)
707 max_clock = nv_encoder->dcb->crtconf.maxfreq;
712 return get_slave_funcs(encoder)->mode_valid(encoder, mode);
714 if (nv_encoder->dp.link_bw == DP_LINK_BW_2_7)
715 max_clock = nv_encoder->dp.link_nr * 270000;
717 max_clock = nv_encoder->dp.link_nr * 162000;
719 clock = clock * nouveau_connector_bpp(connector) / 8;
726 if (clock < min_clock)
727 return MODE_CLOCK_LOW;
729 if (clock > max_clock)
730 return MODE_CLOCK_HIGH;
735 static struct drm_encoder *
736 nouveau_connector_best_encoder(struct drm_connector *connector)
738 struct nouveau_connector *nv_connector = nouveau_connector(connector);
740 if (nv_connector->detected_encoder)
741 return to_drm_encoder(nv_connector->detected_encoder);
746 static const struct drm_connector_helper_funcs
747 nouveau_connector_helper_funcs = {
748 .get_modes = nouveau_connector_get_modes,
749 .mode_valid = nouveau_connector_mode_valid,
750 .best_encoder = nouveau_connector_best_encoder,
753 static const struct drm_connector_funcs
754 nouveau_connector_funcs = {
755 .dpms = drm_helper_connector_dpms,
758 .detect = nouveau_connector_detect,
759 .destroy = nouveau_connector_destroy,
760 .fill_modes = drm_helper_probe_single_connector_modes,
761 .set_property = nouveau_connector_set_property,
762 .force = nouveau_connector_force
765 static const struct drm_connector_funcs
766 nouveau_connector_funcs_lvds = {
767 .dpms = drm_helper_connector_dpms,
770 .detect = nouveau_connector_detect_lvds,
771 .destroy = nouveau_connector_destroy,
772 .fill_modes = drm_helper_probe_single_connector_modes,
773 .set_property = nouveau_connector_set_property,
774 .force = nouveau_connector_force
777 struct drm_connector *
778 nouveau_connector_create(struct drm_device *dev, int index)
780 const struct drm_connector_funcs *funcs = &nouveau_connector_funcs;
781 struct drm_nouveau_private *dev_priv = dev->dev_private;
782 struct nouveau_connector *nv_connector = NULL;
783 struct dcb_connector_table_entry *dcb = NULL;
784 struct drm_connector *connector;
787 NV_DEBUG_KMS(dev, "\n");
789 if (index >= dev_priv->vbios.dcb.connector.entries)
790 return ERR_PTR(-EINVAL);
792 dcb = &dev_priv->vbios.dcb.connector.entry[index];
797 case DCB_CONNECTOR_VGA:
798 type = DRM_MODE_CONNECTOR_VGA;
800 case DCB_CONNECTOR_TV_0:
801 case DCB_CONNECTOR_TV_1:
802 case DCB_CONNECTOR_TV_3:
803 type = DRM_MODE_CONNECTOR_TV;
805 case DCB_CONNECTOR_DVI_I:
806 type = DRM_MODE_CONNECTOR_DVII;
808 case DCB_CONNECTOR_DVI_D:
809 type = DRM_MODE_CONNECTOR_DVID;
811 case DCB_CONNECTOR_HDMI_0:
812 case DCB_CONNECTOR_HDMI_1:
813 type = DRM_MODE_CONNECTOR_HDMIA;
815 case DCB_CONNECTOR_LVDS:
816 type = DRM_MODE_CONNECTOR_LVDS;
817 funcs = &nouveau_connector_funcs_lvds;
819 case DCB_CONNECTOR_DP:
820 type = DRM_MODE_CONNECTOR_DisplayPort;
822 case DCB_CONNECTOR_eDP:
823 type = DRM_MODE_CONNECTOR_eDP;
826 NV_ERROR(dev, "unknown connector type: 0x%02x!!\n", dcb->type);
827 return ERR_PTR(-EINVAL);
830 nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL);
832 return ERR_PTR(-ENOMEM);
833 nv_connector->dcb = dcb;
834 connector = &nv_connector->base;
836 /* defaults, will get overridden in detect() */
837 connector->interlace_allowed = false;
838 connector->doublescan_allowed = false;
840 drm_connector_init(dev, connector, funcs, type);
841 drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
843 /* Check if we need dithering enabled */
844 if (dcb->type == DCB_CONNECTOR_LVDS) {
845 bool dummy, is_24bit = false;
847 ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &is_24bit);
849 NV_ERROR(dev, "Error parsing LVDS table, disabling "
854 nv_connector->use_dithering = !is_24bit;
857 /* Init DVI-I specific properties */
858 if (dcb->type == DCB_CONNECTOR_DVI_I) {
859 drm_mode_create_dvi_i_properties(dev);
860 drm_connector_attach_property(connector, dev->mode_config.dvi_i_subconnector_property, 0);
861 drm_connector_attach_property(connector, dev->mode_config.dvi_i_select_subconnector_property, 0);
865 case DCB_CONNECTOR_VGA:
866 if (dev_priv->card_type >= NV_50) {
867 drm_connector_attach_property(connector,
868 dev->mode_config.scaling_mode_property,
869 nv_connector->scaling_mode);
872 case DCB_CONNECTOR_TV_0:
873 case DCB_CONNECTOR_TV_1:
874 case DCB_CONNECTOR_TV_3:
875 nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
877 if (nv_gf4_disp_arch(dev))
878 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
881 nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
883 drm_connector_attach_property(connector,
884 dev->mode_config.scaling_mode_property,
885 nv_connector->scaling_mode);
886 drm_connector_attach_property(connector,
887 dev->mode_config.dithering_mode_property,
888 nv_connector->use_dithering ?
889 DRM_MODE_DITHERING_ON : DRM_MODE_DITHERING_OFF);
891 if (dcb->type != DCB_CONNECTOR_LVDS) {
892 if (dev_priv->card_type >= NV_50)
893 connector->polled = DRM_CONNECTOR_POLL_HPD;
895 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
900 drm_sysfs_connector_add(connector);
901 dcb->drm = connector;
905 drm_connector_cleanup(connector);