drm/nouveau: Fallback to analog load detection when the EDID block is invalid.
[linux-2.6-block.git] / drivers / gpu / drm / nouveau / nouveau_connector.c
CommitLineData
6ee73861
BS
1/*
2 * Copyright (C) 2008 Maarten Maathuis.
3 * All Rights Reserved.
4 *
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:
12 *
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.
16 *
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.
24 *
25 */
26
27#include "drmP.h"
28#include "drm_edid.h"
29#include "drm_crtc_helper.h"
30#include "nouveau_reg.h"
31#include "nouveau_drv.h"
32#include "nouveau_encoder.h"
33#include "nouveau_crtc.h"
34#include "nouveau_connector.h"
35#include "nouveau_hw.h"
36
37static inline struct drm_encoder_slave_funcs *
38get_slave_funcs(struct nouveau_encoder *enc)
39{
40 return to_encoder_slave(to_drm_encoder(enc))->slave_funcs;
41}
42
43static struct nouveau_encoder *
44find_encoder_by_type(struct drm_connector *connector, int type)
45{
46 struct drm_device *dev = connector->dev;
47 struct nouveau_encoder *nv_encoder;
48 struct drm_mode_object *obj;
49 int i, id;
50
51 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
52 id = connector->encoder_ids[i];
53 if (!id)
54 break;
55
56 obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
57 if (!obj)
58 continue;
59 nv_encoder = nouveau_encoder(obj_to_encoder(obj));
60
61 if (type == OUTPUT_ANY || nv_encoder->dcb->type == type)
62 return nv_encoder;
63 }
64
65 return NULL;
66}
67
68struct nouveau_connector *
69nouveau_encoder_connector_get(struct nouveau_encoder *encoder)
70{
71 struct drm_device *dev = to_drm_encoder(encoder)->dev;
72 struct drm_connector *drm_connector;
73
74 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
75 if (drm_connector->encoder == to_drm_encoder(encoder))
76 return nouveau_connector(drm_connector);
77 }
78
79 return NULL;
80}
81
82
83static void
84nouveau_connector_destroy(struct drm_connector *drm_connector)
85{
c8ebe275
XC
86 struct nouveau_connector *nv_connector =
87 nouveau_connector(drm_connector);
88 struct drm_device *dev = nv_connector->base.dev;
6ee73861 89
ef2bb506 90 NV_DEBUG_KMS(dev, "\n");
6ee73861 91
c8ebe275 92 if (!nv_connector)
6ee73861
BS
93 return;
94
c8ebe275 95 kfree(nv_connector->edid);
6ee73861
BS
96 drm_sysfs_connector_remove(drm_connector);
97 drm_connector_cleanup(drm_connector);
98 kfree(drm_connector);
99}
100
101static void
102nouveau_connector_ddc_prepare(struct drm_connector *connector, int *flags)
103{
104 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
105
106 if (dev_priv->card_type >= NV_50)
107 return;
108
109 *flags = 0;
110 if (NVLockVgaCrtcs(dev_priv->dev, false))
111 *flags |= 1;
112 if (nv_heads_tied(dev_priv->dev))
113 *flags |= 2;
114
115 if (*flags & 2)
116 NVSetOwner(dev_priv->dev, 0); /* necessary? */
117}
118
119static void
120nouveau_connector_ddc_finish(struct drm_connector *connector, int flags)
121{
122 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
123
124 if (dev_priv->card_type >= NV_50)
125 return;
126
127 if (flags & 2)
128 NVSetOwner(dev_priv->dev, 4);
129 if (flags & 1)
130 NVLockVgaCrtcs(dev_priv->dev, true);
131}
132
133static struct nouveau_i2c_chan *
134nouveau_connector_ddc_detect(struct drm_connector *connector,
135 struct nouveau_encoder **pnv_encoder)
136{
137 struct drm_device *dev = connector->dev;
138 uint8_t out_buf[] = { 0x0, 0x0}, buf[2];
139 int ret, flags, i;
140
141 struct i2c_msg msgs[] = {
142 {
143 .addr = 0x50,
144 .flags = 0,
145 .len = 1,
146 .buf = out_buf,
147 },
148 {
149 .addr = 0x50,
150 .flags = I2C_M_RD,
151 .len = 1,
152 .buf = buf,
153 }
154 };
155
156 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
157 struct nouveau_i2c_chan *i2c = NULL;
158 struct nouveau_encoder *nv_encoder;
159 struct drm_mode_object *obj;
160 int id;
161
162 id = connector->encoder_ids[i];
163 if (!id)
164 break;
165
166 obj = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
167 if (!obj)
168 continue;
169 nv_encoder = nouveau_encoder(obj_to_encoder(obj));
170
171 if (nv_encoder->dcb->i2c_index < 0xf)
172 i2c = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index);
173 if (!i2c)
174 continue;
175
176 nouveau_connector_ddc_prepare(connector, &flags);
177 ret = i2c_transfer(&i2c->adapter, msgs, 2);
178 nouveau_connector_ddc_finish(connector, flags);
179
180 if (ret == 2) {
181 *pnv_encoder = nv_encoder;
182 return i2c;
183 }
184 }
185
186 return NULL;
187}
188
189static void
190nouveau_connector_set_encoder(struct drm_connector *connector,
191 struct nouveau_encoder *nv_encoder)
192{
193 struct nouveau_connector *nv_connector = nouveau_connector(connector);
194 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
195 struct drm_device *dev = connector->dev;
196
197 if (nv_connector->detected_encoder == nv_encoder)
198 return;
199 nv_connector->detected_encoder = nv_encoder;
200
201 if (nv_encoder->dcb->type == OUTPUT_LVDS ||
202 nv_encoder->dcb->type == OUTPUT_TMDS) {
203 connector->doublescan_allowed = false;
204 connector->interlace_allowed = false;
205 } else {
206 connector->doublescan_allowed = true;
207 if (dev_priv->card_type == NV_20 ||
208 (dev_priv->card_type == NV_10 &&
209 (dev->pci_device & 0x0ff0) != 0x0100 &&
210 (dev->pci_device & 0x0ff0) != 0x0150))
211 /* HW is broken */
212 connector->interlace_allowed = false;
213 else
214 connector->interlace_allowed = true;
215 }
216
217 if (connector->connector_type == DRM_MODE_CONNECTOR_DVII) {
218 drm_connector_property_set_value(connector,
219 dev->mode_config.dvi_i_subconnector_property,
220 nv_encoder->dcb->type == OUTPUT_TMDS ?
221 DRM_MODE_SUBCONNECTOR_DVID :
222 DRM_MODE_SUBCONNECTOR_DVIA);
223 }
224}
225
226static enum drm_connector_status
227nouveau_connector_detect(struct drm_connector *connector)
228{
229 struct drm_device *dev = connector->dev;
230 struct nouveau_connector *nv_connector = nouveau_connector(connector);
231 struct nouveau_encoder *nv_encoder = NULL;
232 struct nouveau_i2c_chan *i2c;
233 int type, flags;
234
235 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
236 nv_encoder = find_encoder_by_type(connector, OUTPUT_LVDS);
237 if (nv_encoder && nv_connector->native_mode) {
238 nouveau_connector_set_encoder(connector, nv_encoder);
239 return connector_status_connected;
240 }
241
c8ebe275
XC
242 kfree(nv_connector->edid);
243 nv_connector->edid = NULL;
244
6ee73861
BS
245 i2c = nouveau_connector_ddc_detect(connector, &nv_encoder);
246 if (i2c) {
247 nouveau_connector_ddc_prepare(connector, &flags);
248 nv_connector->edid = drm_get_edid(connector, &i2c->adapter);
249 nouveau_connector_ddc_finish(connector, flags);
250 drm_mode_connector_update_edid_property(connector,
251 nv_connector->edid);
252 if (!nv_connector->edid) {
253 NV_ERROR(dev, "DDC responded, but no EDID for %s\n",
254 drm_get_connector_name(connector));
0ed3165e 255 goto detect_analog;
6ee73861
BS
256 }
257
258 if (nv_encoder->dcb->type == OUTPUT_DP &&
259 !nouveau_dp_detect(to_drm_encoder(nv_encoder))) {
260 NV_ERROR(dev, "Detected %s, but failed init\n",
261 drm_get_connector_name(connector));
262 return connector_status_disconnected;
263 }
264
265 /* Override encoder type for DVI-I based on whether EDID
266 * says the display is digital or analog, both use the
267 * same i2c channel so the value returned from ddc_detect
268 * isn't necessarily correct.
269 */
270 if (connector->connector_type == DRM_MODE_CONNECTOR_DVII) {
271 if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
272 type = OUTPUT_TMDS;
273 else
274 type = OUTPUT_ANALOG;
275
276 nv_encoder = find_encoder_by_type(connector, type);
277 if (!nv_encoder) {
278 NV_ERROR(dev, "Detected %d encoder on %s, "
279 "but no object!\n", type,
280 drm_get_connector_name(connector));
281 return connector_status_disconnected;
282 }
283 }
284
285 nouveau_connector_set_encoder(connector, nv_encoder);
286 return connector_status_connected;
287 }
288
0ed3165e 289detect_analog:
6ee73861
BS
290 nv_encoder = find_encoder_by_type(connector, OUTPUT_ANALOG);
291 if (!nv_encoder)
292 nv_encoder = find_encoder_by_type(connector, OUTPUT_TV);
293 if (nv_encoder) {
294 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
295 struct drm_encoder_helper_funcs *helper =
296 encoder->helper_private;
297
298 if (helper->detect(encoder, connector) ==
299 connector_status_connected) {
300 nouveau_connector_set_encoder(connector, nv_encoder);
301 return connector_status_connected;
302 }
303
304 }
305
306 return connector_status_disconnected;
307}
308
309static void
310nouveau_connector_force(struct drm_connector *connector)
311{
312 struct drm_device *dev = connector->dev;
313 struct nouveau_encoder *nv_encoder;
314 int type;
315
316 if (connector->connector_type == DRM_MODE_CONNECTOR_DVII) {
317 if (connector->force == DRM_FORCE_ON_DIGITAL)
318 type = OUTPUT_TMDS;
319 else
320 type = OUTPUT_ANALOG;
321 } else
322 type = OUTPUT_ANY;
323
324 nv_encoder = find_encoder_by_type(connector, type);
325 if (!nv_encoder) {
326 NV_ERROR(dev, "can't find encoder to force %s on!\n",
327 drm_get_connector_name(connector));
328 connector->status = connector_status_disconnected;
329 return;
330 }
331
332 nouveau_connector_set_encoder(connector, nv_encoder);
333}
334
335static int
336nouveau_connector_set_property(struct drm_connector *connector,
337 struct drm_property *property, uint64_t value)
338{
339 struct nouveau_connector *nv_connector = nouveau_connector(connector);
340 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
341 struct drm_device *dev = connector->dev;
342 int ret;
343
344 /* Scaling mode */
345 if (property == dev->mode_config.scaling_mode_property) {
346 struct nouveau_crtc *nv_crtc = NULL;
347 bool modeset = false;
348
349 switch (value) {
350 case DRM_MODE_SCALE_NONE:
351 case DRM_MODE_SCALE_FULLSCREEN:
352 case DRM_MODE_SCALE_CENTER:
353 case DRM_MODE_SCALE_ASPECT:
354 break;
355 default:
356 return -EINVAL;
357 }
358
359 /* LVDS always needs gpu scaling */
360 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS &&
361 value == DRM_MODE_SCALE_NONE)
362 return -EINVAL;
363
364 /* Changing between GPU and panel scaling requires a full
365 * modeset
366 */
367 if ((nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) ||
368 (value == DRM_MODE_SCALE_NONE))
369 modeset = true;
370 nv_connector->scaling_mode = value;
371
372 if (connector->encoder && connector->encoder->crtc)
373 nv_crtc = nouveau_crtc(connector->encoder->crtc);
374 if (!nv_crtc)
375 return 0;
376
377 if (modeset || !nv_crtc->set_scale) {
378 ret = drm_crtc_helper_set_mode(&nv_crtc->base,
379 &nv_crtc->base.mode,
380 nv_crtc->base.x,
381 nv_crtc->base.y, NULL);
382 if (!ret)
383 return -EINVAL;
384 } else {
385 ret = nv_crtc->set_scale(nv_crtc, value, true);
386 if (ret)
387 return ret;
388 }
389
390 return 0;
391 }
392
393 /* Dithering */
394 if (property == dev->mode_config.dithering_mode_property) {
395 struct nouveau_crtc *nv_crtc = NULL;
396
397 if (value == DRM_MODE_DITHERING_ON)
398 nv_connector->use_dithering = true;
399 else
400 nv_connector->use_dithering = false;
401
402 if (connector->encoder && connector->encoder->crtc)
403 nv_crtc = nouveau_crtc(connector->encoder->crtc);
404
405 if (!nv_crtc || !nv_crtc->set_dither)
406 return 0;
407
408 return nv_crtc->set_dither(nv_crtc, nv_connector->use_dithering,
409 true);
410 }
411
412 if (nv_encoder && nv_encoder->dcb->type == OUTPUT_TV)
413 return get_slave_funcs(nv_encoder)->
414 set_property(to_drm_encoder(nv_encoder), connector, property, value);
415
416 return -EINVAL;
417}
418
419static struct drm_display_mode *
420nouveau_connector_native_mode(struct nouveau_connector *connector)
421{
422 struct drm_device *dev = connector->base.dev;
423 struct drm_display_mode *mode, *largest = NULL;
424 int high_w = 0, high_h = 0, high_v = 0;
425
426 /* Use preferred mode if there is one.. */
427 list_for_each_entry(mode, &connector->base.probed_modes, head) {
428 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
ef2bb506 429 NV_DEBUG_KMS(dev, "native mode from preferred\n");
6ee73861
BS
430 return drm_mode_duplicate(dev, mode);
431 }
432 }
433
434 /* Otherwise, take the resolution with the largest width, then height,
435 * then vertical refresh
436 */
437 list_for_each_entry(mode, &connector->base.probed_modes, head) {
438 if (mode->hdisplay < high_w)
439 continue;
440
441 if (mode->hdisplay == high_w && mode->vdisplay < high_h)
442 continue;
443
444 if (mode->hdisplay == high_w && mode->vdisplay == high_h &&
445 mode->vrefresh < high_v)
446 continue;
447
448 high_w = mode->hdisplay;
449 high_h = mode->vdisplay;
450 high_v = mode->vrefresh;
451 largest = mode;
452 }
453
ef2bb506 454 NV_DEBUG_KMS(dev, "native mode from largest: %dx%d@%d\n",
6ee73861
BS
455 high_w, high_h, high_v);
456 return largest ? drm_mode_duplicate(dev, largest) : NULL;
457}
458
459struct moderec {
460 int hdisplay;
461 int vdisplay;
462};
463
464static struct moderec scaler_modes[] = {
465 { 1920, 1200 },
466 { 1920, 1080 },
467 { 1680, 1050 },
468 { 1600, 1200 },
469 { 1400, 1050 },
470 { 1280, 1024 },
471 { 1280, 960 },
472 { 1152, 864 },
473 { 1024, 768 },
474 { 800, 600 },
475 { 720, 400 },
476 { 640, 480 },
477 { 640, 400 },
478 { 640, 350 },
479 {}
480};
481
482static int
483nouveau_connector_scaler_modes_add(struct drm_connector *connector)
484{
485 struct nouveau_connector *nv_connector = nouveau_connector(connector);
486 struct drm_display_mode *native = nv_connector->native_mode, *m;
487 struct drm_device *dev = connector->dev;
488 struct moderec *mode = &scaler_modes[0];
489 int modes = 0;
490
491 if (!native)
492 return 0;
493
494 while (mode->hdisplay) {
495 if (mode->hdisplay <= native->hdisplay &&
496 mode->vdisplay <= native->vdisplay) {
497 m = drm_cvt_mode(dev, mode->hdisplay, mode->vdisplay,
498 drm_mode_vrefresh(native), false,
499 false, false);
500 if (!m)
501 continue;
502
503 m->type |= DRM_MODE_TYPE_DRIVER;
504
505 drm_mode_probed_add(connector, m);
506 modes++;
507 }
508
509 mode++;
510 }
511
512 return modes;
513}
514
515static int
516nouveau_connector_get_modes(struct drm_connector *connector)
517{
518 struct drm_device *dev = connector->dev;
519 struct nouveau_connector *nv_connector = nouveau_connector(connector);
520 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
521 int ret = 0;
522
523 /* If we're not LVDS, destroy the previous native mode, the attached
524 * monitor could have changed.
525 */
526 if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS &&
527 nv_connector->native_mode) {
528 drm_mode_destroy(dev, nv_connector->native_mode);
529 nv_connector->native_mode = NULL;
530 }
531
532 if (nv_connector->edid)
533 ret = drm_add_edid_modes(connector, nv_connector->edid);
534
535 /* Find the native mode if this is a digital panel, if we didn't
536 * find any modes through DDC previously add the native mode to
537 * the list of modes.
538 */
539 if (!nv_connector->native_mode)
540 nv_connector->native_mode =
541 nouveau_connector_native_mode(nv_connector);
542 if (ret == 0 && nv_connector->native_mode) {
543 struct drm_display_mode *mode;
544
545 mode = drm_mode_duplicate(dev, nv_connector->native_mode);
546 drm_mode_probed_add(connector, mode);
547 ret = 1;
548 }
549
550 if (nv_encoder->dcb->type == OUTPUT_TV)
551 ret = get_slave_funcs(nv_encoder)->
552 get_modes(to_drm_encoder(nv_encoder), connector);
553
554 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
555 ret += nouveau_connector_scaler_modes_add(connector);
556
557 return ret;
558}
559
560static int
561nouveau_connector_mode_valid(struct drm_connector *connector,
562 struct drm_display_mode *mode)
563{
564 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
565 struct nouveau_connector *nv_connector = nouveau_connector(connector);
566 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
567 unsigned min_clock = 25000, max_clock = min_clock;
568 unsigned clock = mode->clock;
569
570 switch (nv_encoder->dcb->type) {
571 case OUTPUT_LVDS:
572 BUG_ON(!nv_connector->native_mode);
573 if (mode->hdisplay > nv_connector->native_mode->hdisplay ||
574 mode->vdisplay > nv_connector->native_mode->vdisplay)
575 return MODE_PANEL;
576
577 min_clock = 0;
578 max_clock = 400000;
579 break;
580 case OUTPUT_TMDS:
581 if ((dev_priv->card_type >= NV_50 && !nouveau_duallink) ||
582 (dev_priv->card_type < NV_50 &&
583 !nv_encoder->dcb->duallink_possible))
584 max_clock = 165000;
585 else
586 max_clock = 330000;
587 break;
588 case OUTPUT_ANALOG:
589 max_clock = nv_encoder->dcb->crtconf.maxfreq;
590 if (!max_clock)
591 max_clock = 350000;
592 break;
593 case OUTPUT_TV:
594 return get_slave_funcs(nv_encoder)->
595 mode_valid(to_drm_encoder(nv_encoder), mode);
596 case OUTPUT_DP:
597 if (nv_encoder->dp.link_bw == DP_LINK_BW_2_7)
598 max_clock = nv_encoder->dp.link_nr * 270000;
599 else
600 max_clock = nv_encoder->dp.link_nr * 162000;
601
602 clock *= 3;
603 break;
604 }
605
606 if (clock < min_clock)
607 return MODE_CLOCK_LOW;
608
609 if (clock > max_clock)
610 return MODE_CLOCK_HIGH;
611
612 return MODE_OK;
613}
614
615static struct drm_encoder *
616nouveau_connector_best_encoder(struct drm_connector *connector)
617{
618 struct nouveau_connector *nv_connector = nouveau_connector(connector);
619
620 if (nv_connector->detected_encoder)
621 return to_drm_encoder(nv_connector->detected_encoder);
622
623 return NULL;
624}
625
626static const struct drm_connector_helper_funcs
627nouveau_connector_helper_funcs = {
628 .get_modes = nouveau_connector_get_modes,
629 .mode_valid = nouveau_connector_mode_valid,
630 .best_encoder = nouveau_connector_best_encoder,
631};
632
633static const struct drm_connector_funcs
634nouveau_connector_funcs = {
635 .dpms = drm_helper_connector_dpms,
636 .save = NULL,
637 .restore = NULL,
638 .detect = nouveau_connector_detect,
639 .destroy = nouveau_connector_destroy,
640 .fill_modes = drm_helper_probe_single_connector_modes,
641 .set_property = nouveau_connector_set_property,
642 .force = nouveau_connector_force
643};
644
645static int
646nouveau_connector_create_lvds(struct drm_device *dev,
647 struct drm_connector *connector)
648{
649 struct nouveau_connector *nv_connector = nouveau_connector(connector);
650 struct drm_nouveau_private *dev_priv = dev->dev_private;
651 struct nouveau_i2c_chan *i2c = NULL;
652 struct nouveau_encoder *nv_encoder;
653 struct drm_display_mode native, *mode, *temp;
654 bool dummy, if_is_24bit = false;
655 int ret, flags;
656
657 nv_encoder = find_encoder_by_type(connector, OUTPUT_LVDS);
658 if (!nv_encoder)
659 return -ENODEV;
660
661 ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &if_is_24bit);
662 if (ret) {
663 NV_ERROR(dev, "Error parsing LVDS table, disabling LVDS\n");
664 return ret;
665 }
666 nv_connector->use_dithering = !if_is_24bit;
667
668 /* Firstly try getting EDID over DDC, if allowed and I2C channel
669 * is available.
670 */
671 if (!dev_priv->VBIOS.pub.fp_no_ddc && nv_encoder->dcb->i2c_index < 0xf)
672 i2c = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index);
673
674 if (i2c) {
675 nouveau_connector_ddc_prepare(connector, &flags);
676 nv_connector->edid = drm_get_edid(connector, &i2c->adapter);
677 nouveau_connector_ddc_finish(connector, flags);
678 }
679
680 /* If no EDID found above, and the VBIOS indicates a hardcoded
681 * modeline is avalilable for the panel, set it as the panel's
682 * native mode and exit.
683 */
684 if (!nv_connector->edid && nouveau_bios_fp_mode(dev, &native) &&
685 (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
686 dev_priv->VBIOS.pub.fp_no_ddc)) {
687 nv_connector->native_mode = drm_mode_duplicate(dev, &native);
688 goto out;
689 }
690
691 /* Still nothing, some VBIOS images have a hardcoded EDID block
692 * stored for the panel stored in them.
693 */
694 if (!nv_connector->edid && !nv_connector->native_mode &&
695 !dev_priv->VBIOS.pub.fp_no_ddc) {
c8ebe275 696 struct edid *edid =
6ee73861 697 (struct edid *)nouveau_bios_embedded_edid(dev);
c8ebe275
XC
698 if (edid) {
699 nv_connector->edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
700 *(nv_connector->edid) = *edid;
701 }
6ee73861
BS
702 }
703
704 if (!nv_connector->edid)
705 goto out;
706
707 /* We didn't find/use a panel mode from the VBIOS, so parse the EDID
708 * block and look for the preferred mode there.
709 */
710 ret = drm_add_edid_modes(connector, nv_connector->edid);
711 if (ret == 0)
712 goto out;
713 nv_connector->detected_encoder = nv_encoder;
714 nv_connector->native_mode = nouveau_connector_native_mode(nv_connector);
715 list_for_each_entry_safe(mode, temp, &connector->probed_modes, head)
716 drm_mode_remove(connector, mode);
717
718out:
719 if (!nv_connector->native_mode) {
720 NV_ERROR(dev, "LVDS present in DCB table, but couldn't "
721 "determine its native mode. Disabling.\n");
722 return -ENODEV;
723 }
724
725 drm_mode_connector_update_edid_property(connector, nv_connector->edid);
726 return 0;
727}
728
729int
730nouveau_connector_create(struct drm_device *dev, int index, int type)
731{
732 struct drm_nouveau_private *dev_priv = dev->dev_private;
733 struct nouveau_connector *nv_connector = NULL;
734 struct drm_connector *connector;
735 struct drm_encoder *encoder;
736 int ret;
737
ef2bb506 738 NV_DEBUG_KMS(dev, "\n");
6ee73861
BS
739
740 nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL);
741 if (!nv_connector)
742 return -ENOMEM;
743 nv_connector->dcb = nouveau_bios_connector_entry(dev, index);
744 connector = &nv_connector->base;
745
746 switch (type) {
747 case DRM_MODE_CONNECTOR_VGA:
748 NV_INFO(dev, "Detected a VGA connector\n");
749 break;
750 case DRM_MODE_CONNECTOR_DVID:
751 NV_INFO(dev, "Detected a DVI-D connector\n");
752 break;
753 case DRM_MODE_CONNECTOR_DVII:
754 NV_INFO(dev, "Detected a DVI-I connector\n");
755 break;
756 case DRM_MODE_CONNECTOR_LVDS:
757 NV_INFO(dev, "Detected a LVDS connector\n");
758 break;
759 case DRM_MODE_CONNECTOR_TV:
760 NV_INFO(dev, "Detected a TV connector\n");
761 break;
762 case DRM_MODE_CONNECTOR_DisplayPort:
763 NV_INFO(dev, "Detected a DisplayPort connector\n");
764 break;
765 default:
766 NV_ERROR(dev, "Unknown connector, this is not good.\n");
767 break;
768 }
769
770 /* defaults, will get overridden in detect() */
771 connector->interlace_allowed = false;
772 connector->doublescan_allowed = false;
773
774 drm_connector_init(dev, connector, &nouveau_connector_funcs, type);
775 drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
776
777 /* Init DVI-I specific properties */
778 if (type == DRM_MODE_CONNECTOR_DVII) {
779 drm_mode_create_dvi_i_properties(dev);
780 drm_connector_attach_property(connector, dev->mode_config.dvi_i_subconnector_property, 0);
781 drm_connector_attach_property(connector, dev->mode_config.dvi_i_select_subconnector_property, 0);
782 }
783
784 if (type != DRM_MODE_CONNECTOR_LVDS)
785 nv_connector->use_dithering = false;
786
787 if (type == DRM_MODE_CONNECTOR_DVID ||
788 type == DRM_MODE_CONNECTOR_DVII ||
789 type == DRM_MODE_CONNECTOR_LVDS ||
790 type == DRM_MODE_CONNECTOR_DisplayPort) {
791 nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
792
793 drm_connector_attach_property(connector, dev->mode_config.scaling_mode_property,
794 nv_connector->scaling_mode);
795 drm_connector_attach_property(connector, dev->mode_config.dithering_mode_property,
796 nv_connector->use_dithering ? DRM_MODE_DITHERING_ON
797 : DRM_MODE_DITHERING_OFF);
798
799 } else {
800 nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
801
802 if (type == DRM_MODE_CONNECTOR_VGA &&
803 dev_priv->card_type >= NV_50) {
804 drm_connector_attach_property(connector,
805 dev->mode_config.scaling_mode_property,
806 nv_connector->scaling_mode);
807 }
808 }
809
810 /* attach encoders */
811 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
812 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
813
814 if (nv_encoder->dcb->connector != index)
815 continue;
816
817 if (get_slave_funcs(nv_encoder))
818 get_slave_funcs(nv_encoder)->create_resources(encoder, connector);
819
820 drm_mode_connector_attach_encoder(connector, encoder);
821 }
822
823 drm_sysfs_connector_add(connector);
824
825 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
826 ret = nouveau_connector_create_lvds(dev, connector);
827 if (ret) {
828 connector->funcs->destroy(connector);
829 return ret;
830 }
831 }
832
833 return 0;
834}