drm/nouveau: fix panels using straps-based mode detection
[linux-2.6/btrfs-unstable.git] / drivers / gpu / drm / nouveau / nouveau_connector.c
blobfc737037f751c3690dfb09239e3439df1fa4191c
1 /*
2 * Copyright (C) 2008 Maarten Maathuis.
3 * All Rights Reserved.
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 "drmP.h"
30 #include "drm_edid.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;
46 int i, id;
48 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
49 id = connector->encoder_ids[i];
50 if (!id)
51 break;
53 obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
54 if (!obj)
55 continue;
56 nv_encoder = nouveau_encoder(obj_to_encoder(obj));
58 if (type == OUTPUT_ANY || nv_encoder->dcb->type == type)
59 return nv_encoder;
62 return NULL;
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);
76 return NULL;
80 static void
81 nouveau_connector_destroy(struct drm_connector *drm_connector)
83 struct nouveau_connector *nv_connector =
84 nouveau_connector(drm_connector);
85 struct drm_device *dev;
87 if (!nv_connector)
88 return;
90 dev = nv_connector->base.dev;
91 NV_DEBUG_KMS(dev, "\n");
93 kfree(nv_connector->edid);
94 drm_sysfs_connector_remove(drm_connector);
95 drm_connector_cleanup(drm_connector);
96 kfree(drm_connector);
99 static struct nouveau_i2c_chan *
100 nouveau_connector_ddc_detect(struct drm_connector *connector,
101 struct nouveau_encoder **pnv_encoder)
103 struct drm_device *dev = connector->dev;
104 int i;
106 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
107 struct nouveau_i2c_chan *i2c = NULL;
108 struct nouveau_encoder *nv_encoder;
109 struct drm_mode_object *obj;
110 int id;
112 id = connector->encoder_ids[i];
113 if (!id)
114 break;
116 obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
117 if (!obj)
118 continue;
119 nv_encoder = nouveau_encoder(obj_to_encoder(obj));
121 if (nv_encoder->dcb->i2c_index < 0xf)
122 i2c = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index);
124 if (i2c && nouveau_probe_i2c_addr(i2c, 0x50)) {
125 *pnv_encoder = nv_encoder;
126 return i2c;
130 return NULL;
133 static void
134 nouveau_connector_set_encoder(struct drm_connector *connector,
135 struct nouveau_encoder *nv_encoder)
137 struct nouveau_connector *nv_connector = nouveau_connector(connector);
138 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
139 struct drm_device *dev = connector->dev;
141 if (nv_connector->detected_encoder == nv_encoder)
142 return;
143 nv_connector->detected_encoder = nv_encoder;
145 if (nv_encoder->dcb->type == OUTPUT_LVDS ||
146 nv_encoder->dcb->type == OUTPUT_TMDS) {
147 connector->doublescan_allowed = false;
148 connector->interlace_allowed = false;
149 } else {
150 connector->doublescan_allowed = true;
151 if (dev_priv->card_type == NV_20 ||
152 (dev_priv->card_type == NV_10 &&
153 (dev->pci_device & 0x0ff0) != 0x0100 &&
154 (dev->pci_device & 0x0ff0) != 0x0150))
155 /* HW is broken */
156 connector->interlace_allowed = false;
157 else
158 connector->interlace_allowed = true;
161 if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) {
162 drm_connector_property_set_value(connector,
163 dev->mode_config.dvi_i_subconnector_property,
164 nv_encoder->dcb->type == OUTPUT_TMDS ?
165 DRM_MODE_SUBCONNECTOR_DVID :
166 DRM_MODE_SUBCONNECTOR_DVIA);
170 static enum drm_connector_status
171 nouveau_connector_detect(struct drm_connector *connector, bool force)
173 struct drm_device *dev = connector->dev;
174 struct nouveau_connector *nv_connector = nouveau_connector(connector);
175 struct nouveau_encoder *nv_encoder = NULL;
176 struct nouveau_i2c_chan *i2c;
177 int type;
179 /* Cleanup the previous EDID block. */
180 if (nv_connector->edid) {
181 drm_mode_connector_update_edid_property(connector, NULL);
182 kfree(nv_connector->edid);
183 nv_connector->edid = NULL;
186 i2c = nouveau_connector_ddc_detect(connector, &nv_encoder);
187 if (i2c) {
188 nv_connector->edid = drm_get_edid(connector, &i2c->adapter);
189 drm_mode_connector_update_edid_property(connector,
190 nv_connector->edid);
191 if (!nv_connector->edid) {
192 NV_ERROR(dev, "DDC responded, but no EDID for %s\n",
193 drm_get_connector_name(connector));
194 goto detect_analog;
197 if (nv_encoder->dcb->type == OUTPUT_DP &&
198 !nouveau_dp_detect(to_drm_encoder(nv_encoder))) {
199 NV_ERROR(dev, "Detected %s, but failed init\n",
200 drm_get_connector_name(connector));
201 return connector_status_disconnected;
204 /* Override encoder type for DVI-I based on whether EDID
205 * says the display is digital or analog, both use the
206 * same i2c channel so the value returned from ddc_detect
207 * isn't necessarily correct.
209 if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) {
210 if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
211 type = OUTPUT_TMDS;
212 else
213 type = OUTPUT_ANALOG;
215 nv_encoder = find_encoder_by_type(connector, type);
216 if (!nv_encoder) {
217 NV_ERROR(dev, "Detected %d encoder on %s, "
218 "but no object!\n", type,
219 drm_get_connector_name(connector));
220 return connector_status_disconnected;
224 nouveau_connector_set_encoder(connector, nv_encoder);
225 return connector_status_connected;
228 detect_analog:
229 nv_encoder = find_encoder_by_type(connector, OUTPUT_ANALOG);
230 if (!nv_encoder && !nouveau_tv_disable)
231 nv_encoder = find_encoder_by_type(connector, OUTPUT_TV);
232 if (nv_encoder) {
233 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
234 struct drm_encoder_helper_funcs *helper =
235 encoder->helper_private;
237 if (helper->detect(encoder, connector) ==
238 connector_status_connected) {
239 nouveau_connector_set_encoder(connector, nv_encoder);
240 return connector_status_connected;
245 return connector_status_disconnected;
248 static enum drm_connector_status
249 nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
251 struct drm_device *dev = connector->dev;
252 struct drm_nouveau_private *dev_priv = dev->dev_private;
253 struct nouveau_connector *nv_connector = nouveau_connector(connector);
254 struct nouveau_encoder *nv_encoder = NULL;
255 enum drm_connector_status status = connector_status_disconnected;
257 /* Cleanup the previous EDID block. */
258 if (nv_connector->edid) {
259 drm_mode_connector_update_edid_property(connector, NULL);
260 kfree(nv_connector->edid);
261 nv_connector->edid = NULL;
264 nv_encoder = find_encoder_by_type(connector, OUTPUT_LVDS);
265 if (!nv_encoder)
266 return connector_status_disconnected;
268 /* Try retrieving EDID via DDC */
269 if (!dev_priv->vbios.fp_no_ddc) {
270 status = nouveau_connector_detect(connector, force);
271 if (status == connector_status_connected)
272 goto out;
275 /* On some laptops (Sony, i'm looking at you) there appears to
276 * be no direct way of accessing the panel's EDID. The only
277 * option available to us appears to be to ask ACPI for help..
279 * It's important this check's before trying straps, one of the
280 * said manufacturer's laptops are configured in such a way
281 * the nouveau decides an entry in the VBIOS FP mode table is
282 * valid - it's not (rh#613284)
284 if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
285 if (!nouveau_acpi_edid(dev, connector)) {
286 status = connector_status_connected;
287 goto out;
291 /* If no EDID found above, and the VBIOS indicates a hardcoded
292 * modeline is avalilable for the panel, set it as the panel's
293 * native mode and exit.
295 if (nouveau_bios_fp_mode(dev, NULL) && (dev_priv->vbios.fp_no_ddc ||
296 nv_encoder->dcb->lvdsconf.use_straps_for_mode)) {
297 status = connector_status_connected;
298 goto out;
301 /* Still nothing, some VBIOS images have a hardcoded EDID block
302 * stored for the panel stored in them.
304 if (!dev_priv->vbios.fp_no_ddc) {
305 struct edid *edid =
306 (struct edid *)nouveau_bios_embedded_edid(dev);
307 if (edid) {
308 nv_connector->edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
309 *(nv_connector->edid) = *edid;
310 status = connector_status_connected;
314 out:
315 #if defined(CONFIG_ACPI_BUTTON) || \
316 (defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE))
317 if (status == connector_status_connected &&
318 !nouveau_ignorelid && !acpi_lid_open())
319 status = connector_status_unknown;
320 #endif
322 drm_mode_connector_update_edid_property(connector, nv_connector->edid);
323 nouveau_connector_set_encoder(connector, nv_encoder);
324 return status;
327 static void
328 nouveau_connector_force(struct drm_connector *connector)
330 struct nouveau_connector *nv_connector = nouveau_connector(connector);
331 struct nouveau_encoder *nv_encoder;
332 int type;
334 if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) {
335 if (connector->force == DRM_FORCE_ON_DIGITAL)
336 type = OUTPUT_TMDS;
337 else
338 type = OUTPUT_ANALOG;
339 } else
340 type = OUTPUT_ANY;
342 nv_encoder = find_encoder_by_type(connector, type);
343 if (!nv_encoder) {
344 NV_ERROR(connector->dev, "can't find encoder to force %s on!\n",
345 drm_get_connector_name(connector));
346 connector->status = connector_status_disconnected;
347 return;
350 nouveau_connector_set_encoder(connector, nv_encoder);
353 static int
354 nouveau_connector_set_property(struct drm_connector *connector,
355 struct drm_property *property, uint64_t value)
357 struct nouveau_connector *nv_connector = nouveau_connector(connector);
358 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
359 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
360 struct drm_device *dev = connector->dev;
361 int ret;
363 /* Scaling mode */
364 if (property == dev->mode_config.scaling_mode_property) {
365 struct nouveau_crtc *nv_crtc = NULL;
366 bool modeset = false;
368 switch (value) {
369 case DRM_MODE_SCALE_NONE:
370 case DRM_MODE_SCALE_FULLSCREEN:
371 case DRM_MODE_SCALE_CENTER:
372 case DRM_MODE_SCALE_ASPECT:
373 break;
374 default:
375 return -EINVAL;
378 /* LVDS always needs gpu scaling */
379 if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS &&
380 value == DRM_MODE_SCALE_NONE)
381 return -EINVAL;
383 /* Changing between GPU and panel scaling requires a full
384 * modeset
386 if ((nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) ||
387 (value == DRM_MODE_SCALE_NONE))
388 modeset = true;
389 nv_connector->scaling_mode = value;
391 if (connector->encoder && connector->encoder->crtc)
392 nv_crtc = nouveau_crtc(connector->encoder->crtc);
393 if (!nv_crtc)
394 return 0;
396 if (modeset || !nv_crtc->set_scale) {
397 ret = drm_crtc_helper_set_mode(&nv_crtc->base,
398 &nv_crtc->base.mode,
399 nv_crtc->base.x,
400 nv_crtc->base.y, NULL);
401 if (!ret)
402 return -EINVAL;
403 } else {
404 ret = nv_crtc->set_scale(nv_crtc, value, true);
405 if (ret)
406 return ret;
409 return 0;
412 /* Dithering */
413 if (property == dev->mode_config.dithering_mode_property) {
414 struct nouveau_crtc *nv_crtc = NULL;
416 if (value == DRM_MODE_DITHERING_ON)
417 nv_connector->use_dithering = true;
418 else
419 nv_connector->use_dithering = false;
421 if (connector->encoder && connector->encoder->crtc)
422 nv_crtc = nouveau_crtc(connector->encoder->crtc);
424 if (!nv_crtc || !nv_crtc->set_dither)
425 return 0;
427 return nv_crtc->set_dither(nv_crtc, nv_connector->use_dithering,
428 true);
431 if (nv_encoder && nv_encoder->dcb->type == OUTPUT_TV)
432 return get_slave_funcs(encoder)->set_property(
433 encoder, connector, property, value);
435 return -EINVAL;
438 static struct drm_display_mode *
439 nouveau_connector_native_mode(struct drm_connector *connector)
441 struct drm_connector_helper_funcs *helper = connector->helper_private;
442 struct nouveau_connector *nv_connector = nouveau_connector(connector);
443 struct drm_device *dev = connector->dev;
444 struct drm_display_mode *mode, *largest = NULL;
445 int high_w = 0, high_h = 0, high_v = 0;
447 list_for_each_entry(mode, &nv_connector->base.probed_modes, head) {
448 if (helper->mode_valid(connector, mode) != MODE_OK ||
449 (mode->flags & DRM_MODE_FLAG_INTERLACE))
450 continue;
452 /* Use preferred mode if there is one.. */
453 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
454 NV_DEBUG_KMS(dev, "native mode from preferred\n");
455 return drm_mode_duplicate(dev, mode);
458 /* Otherwise, take the resolution with the largest width, then
459 * height, then vertical refresh
461 if (mode->hdisplay < high_w)
462 continue;
464 if (mode->hdisplay == high_w && mode->vdisplay < high_h)
465 continue;
467 if (mode->hdisplay == high_w && mode->vdisplay == high_h &&
468 mode->vrefresh < high_v)
469 continue;
471 high_w = mode->hdisplay;
472 high_h = mode->vdisplay;
473 high_v = mode->vrefresh;
474 largest = mode;
477 NV_DEBUG_KMS(dev, "native mode from largest: %dx%d@%d\n",
478 high_w, high_h, high_v);
479 return largest ? drm_mode_duplicate(dev, largest) : NULL;
482 struct moderec {
483 int hdisplay;
484 int vdisplay;
487 static struct moderec scaler_modes[] = {
488 { 1920, 1200 },
489 { 1920, 1080 },
490 { 1680, 1050 },
491 { 1600, 1200 },
492 { 1400, 1050 },
493 { 1280, 1024 },
494 { 1280, 960 },
495 { 1152, 864 },
496 { 1024, 768 },
497 { 800, 600 },
498 { 720, 400 },
499 { 640, 480 },
500 { 640, 400 },
501 { 640, 350 },
505 static int
506 nouveau_connector_scaler_modes_add(struct drm_connector *connector)
508 struct nouveau_connector *nv_connector = nouveau_connector(connector);
509 struct drm_display_mode *native = nv_connector->native_mode, *m;
510 struct drm_device *dev = connector->dev;
511 struct moderec *mode = &scaler_modes[0];
512 int modes = 0;
514 if (!native)
515 return 0;
517 while (mode->hdisplay) {
518 if (mode->hdisplay <= native->hdisplay &&
519 mode->vdisplay <= native->vdisplay) {
520 m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay,
521 drm_mode_vrefresh(native), false,
522 false, false);
523 if (!m)
524 continue;
526 m->type |= DRM_MODE_TYPE_DRIVER;
528 drm_mode_probed_add(connector, m);
529 modes++;
532 mode++;
535 return modes;
538 static int
539 nouveau_connector_get_modes(struct drm_connector *connector)
541 struct drm_device *dev = connector->dev;
542 struct drm_nouveau_private *dev_priv = dev->dev_private;
543 struct nouveau_connector *nv_connector = nouveau_connector(connector);
544 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
545 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
546 int ret = 0;
548 /* destroy the native mode, the attached monitor could have changed.
550 if (nv_connector->native_mode) {
551 drm_mode_destroy(dev, nv_connector->native_mode);
552 nv_connector->native_mode = NULL;
555 if (nv_connector->edid)
556 ret = drm_add_edid_modes(connector, nv_connector->edid);
557 else
558 if (nv_encoder->dcb->type == OUTPUT_LVDS &&
559 (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
560 dev_priv->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) {
561 struct drm_display_mode mode;
563 nouveau_bios_fp_mode(dev, &mode);
564 nv_connector->native_mode = drm_mode_duplicate(dev, &mode);
567 /* Find the native mode if this is a digital panel, if we didn't
568 * find any modes through DDC previously add the native mode to
569 * the list of modes.
571 if (!nv_connector->native_mode)
572 nv_connector->native_mode =
573 nouveau_connector_native_mode(connector);
574 if (ret == 0 && nv_connector->native_mode) {
575 struct drm_display_mode *mode;
577 mode = drm_mode_duplicate(dev, nv_connector->native_mode);
578 drm_mode_probed_add(connector, mode);
579 ret = 1;
582 if (nv_encoder->dcb->type == OUTPUT_TV)
583 ret = get_slave_funcs(encoder)->get_modes(encoder, connector);
585 if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS ||
586 nv_connector->dcb->type == DCB_CONNECTOR_eDP)
587 ret += nouveau_connector_scaler_modes_add(connector);
589 return ret;
592 static int
593 nouveau_connector_mode_valid(struct drm_connector *connector,
594 struct drm_display_mode *mode)
596 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
597 struct nouveau_connector *nv_connector = nouveau_connector(connector);
598 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
599 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
600 unsigned min_clock = 25000, max_clock = min_clock;
601 unsigned clock = mode->clock;
603 switch (nv_encoder->dcb->type) {
604 case OUTPUT_LVDS:
605 if (nv_connector->native_mode &&
606 (mode->hdisplay > nv_connector->native_mode->hdisplay ||
607 mode->vdisplay > nv_connector->native_mode->vdisplay))
608 return MODE_PANEL;
610 min_clock = 0;
611 max_clock = 400000;
612 break;
613 case OUTPUT_TMDS:
614 if ((dev_priv->card_type >= NV_50 && !nouveau_duallink) ||
615 !nv_encoder->dcb->duallink_possible)
616 max_clock = 165000;
617 else
618 max_clock = 330000;
619 break;
620 case OUTPUT_ANALOG:
621 max_clock = nv_encoder->dcb->crtconf.maxfreq;
622 if (!max_clock)
623 max_clock = 350000;
624 break;
625 case OUTPUT_TV:
626 return get_slave_funcs(encoder)->mode_valid(encoder, mode);
627 case OUTPUT_DP:
628 if (nv_encoder->dp.link_bw == DP_LINK_BW_2_7)
629 max_clock = nv_encoder->dp.link_nr * 270000;
630 else
631 max_clock = nv_encoder->dp.link_nr * 162000;
633 clock *= 3;
634 break;
635 default:
636 BUG_ON(1);
637 return MODE_BAD;
640 if (clock < min_clock)
641 return MODE_CLOCK_LOW;
643 if (clock > max_clock)
644 return MODE_CLOCK_HIGH;
646 return MODE_OK;
649 static struct drm_encoder *
650 nouveau_connector_best_encoder(struct drm_connector *connector)
652 struct nouveau_connector *nv_connector = nouveau_connector(connector);
654 if (nv_connector->detected_encoder)
655 return to_drm_encoder(nv_connector->detected_encoder);
657 return NULL;
660 void
661 nouveau_connector_set_polling(struct drm_connector *connector)
663 struct drm_device *dev = connector->dev;
664 struct drm_nouveau_private *dev_priv = dev->dev_private;
665 struct drm_crtc *crtc;
666 bool spare_crtc = false;
668 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
669 spare_crtc |= !crtc->enabled;
671 connector->polled = 0;
673 switch (connector->connector_type) {
674 case DRM_MODE_CONNECTOR_VGA:
675 case DRM_MODE_CONNECTOR_TV:
676 if (dev_priv->card_type >= NV_50 ||
677 (nv_gf4_disp_arch(dev) && spare_crtc))
678 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
679 break;
681 case DRM_MODE_CONNECTOR_DVII:
682 case DRM_MODE_CONNECTOR_DVID:
683 case DRM_MODE_CONNECTOR_HDMIA:
684 case DRM_MODE_CONNECTOR_DisplayPort:
685 case DRM_MODE_CONNECTOR_eDP:
686 if (dev_priv->card_type >= NV_50)
687 connector->polled = DRM_CONNECTOR_POLL_HPD;
688 else if (connector->connector_type == DRM_MODE_CONNECTOR_DVID ||
689 spare_crtc)
690 connector->polled = DRM_CONNECTOR_POLL_CONNECT;
691 break;
693 default:
694 break;
698 static const struct drm_connector_helper_funcs
699 nouveau_connector_helper_funcs = {
700 .get_modes = nouveau_connector_get_modes,
701 .mode_valid = nouveau_connector_mode_valid,
702 .best_encoder = nouveau_connector_best_encoder,
705 static const struct drm_connector_funcs
706 nouveau_connector_funcs = {
707 .dpms = drm_helper_connector_dpms,
708 .save = NULL,
709 .restore = NULL,
710 .detect = nouveau_connector_detect,
711 .destroy = nouveau_connector_destroy,
712 .fill_modes = drm_helper_probe_single_connector_modes,
713 .set_property = nouveau_connector_set_property,
714 .force = nouveau_connector_force
717 static const struct drm_connector_funcs
718 nouveau_connector_funcs_lvds = {
719 .dpms = drm_helper_connector_dpms,
720 .save = NULL,
721 .restore = NULL,
722 .detect = nouveau_connector_detect_lvds,
723 .destroy = nouveau_connector_destroy,
724 .fill_modes = drm_helper_probe_single_connector_modes,
725 .set_property = nouveau_connector_set_property,
726 .force = nouveau_connector_force
729 struct drm_connector *
730 nouveau_connector_create(struct drm_device *dev, int index)
732 const struct drm_connector_funcs *funcs = &nouveau_connector_funcs;
733 struct drm_nouveau_private *dev_priv = dev->dev_private;
734 struct nouveau_connector *nv_connector = NULL;
735 struct dcb_connector_table_entry *dcb = NULL;
736 struct drm_connector *connector;
737 int type, ret = 0;
739 NV_DEBUG_KMS(dev, "\n");
741 if (index >= dev_priv->vbios.dcb.connector.entries)
742 return ERR_PTR(-EINVAL);
744 dcb = &dev_priv->vbios.dcb.connector.entry[index];
745 if (dcb->drm)
746 return dcb->drm;
748 switch (dcb->type) {
749 case DCB_CONNECTOR_VGA:
750 type = DRM_MODE_CONNECTOR_VGA;
751 break;
752 case DCB_CONNECTOR_TV_0:
753 case DCB_CONNECTOR_TV_1:
754 case DCB_CONNECTOR_TV_3:
755 type = DRM_MODE_CONNECTOR_TV;
756 break;
757 case DCB_CONNECTOR_DVI_I:
758 type = DRM_MODE_CONNECTOR_DVII;
759 break;
760 case DCB_CONNECTOR_DVI_D:
761 type = DRM_MODE_CONNECTOR_DVID;
762 break;
763 case DCB_CONNECTOR_HDMI_0:
764 case DCB_CONNECTOR_HDMI_1:
765 type = DRM_MODE_CONNECTOR_HDMIA;
766 break;
767 case DCB_CONNECTOR_LVDS:
768 type = DRM_MODE_CONNECTOR_LVDS;
769 funcs = &nouveau_connector_funcs_lvds;
770 break;
771 case DCB_CONNECTOR_DP:
772 type = DRM_MODE_CONNECTOR_DisplayPort;
773 break;
774 case DCB_CONNECTOR_eDP:
775 type = DRM_MODE_CONNECTOR_eDP;
776 break;
777 default:
778 NV_ERROR(dev, "unknown connector type: 0x%02x!!\n", dcb->type);
779 return ERR_PTR(-EINVAL);
782 nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL);
783 if (!nv_connector)
784 return ERR_PTR(-ENOMEM);
785 nv_connector->dcb = dcb;
786 connector = &nv_connector->base;
788 /* defaults, will get overridden in detect() */
789 connector->interlace_allowed = false;
790 connector->doublescan_allowed = false;
792 drm_connector_init(dev, connector, funcs, type);
793 drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
795 /* Check if we need dithering enabled */
796 if (dcb->type == DCB_CONNECTOR_LVDS) {
797 bool dummy, is_24bit = false;
799 ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &is_24bit);
800 if (ret) {
801 NV_ERROR(dev, "Error parsing LVDS table, disabling "
802 "LVDS\n");
803 goto fail;
806 nv_connector->use_dithering = !is_24bit;
809 /* Init DVI-I specific properties */
810 if (dcb->type == DCB_CONNECTOR_DVI_I) {
811 drm_mode_create_dvi_i_properties(dev);
812 drm_connector_attach_property(connector, dev->mode_config.dvi_i_subconnector_property, 0);
813 drm_connector_attach_property(connector, dev->mode_config.dvi_i_select_subconnector_property, 0);
816 switch (dcb->type) {
817 case DCB_CONNECTOR_VGA:
818 if (dev_priv->card_type >= NV_50) {
819 drm_connector_attach_property(connector,
820 dev->mode_config.scaling_mode_property,
821 nv_connector->scaling_mode);
823 /* fall-through */
824 case DCB_CONNECTOR_TV_0:
825 case DCB_CONNECTOR_TV_1:
826 case DCB_CONNECTOR_TV_3:
827 nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
828 break;
829 default:
830 nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
832 drm_connector_attach_property(connector,
833 dev->mode_config.scaling_mode_property,
834 nv_connector->scaling_mode);
835 drm_connector_attach_property(connector,
836 dev->mode_config.dithering_mode_property,
837 nv_connector->use_dithering ?
838 DRM_MODE_DITHERING_ON : DRM_MODE_DITHERING_OFF);
839 break;
842 nouveau_connector_set_polling(connector);
844 drm_sysfs_connector_add(connector);
845 dcb->drm = connector;
846 return dcb->drm;
848 fail:
849 drm_connector_cleanup(connector);
850 kfree(connector);
851 return ERR_PTR(ret);