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 "nv50_display.h"
28 #include "nouveau_crtc.h"
29 #include "nouveau_encoder.h"
30 #include "nouveau_connector.h"
31 #include "nouveau_fb.h"
32 #include "nouveau_fbcon.h"
33 #include "nouveau_ramht.h"
34 #include "drm_crtc_helper.h"
36 static void nv50_display_isr(struct drm_device *);
39 nv50_sor_nr(struct drm_device *dev)
41 struct drm_nouveau_private *dev_priv = dev->dev_private;
43 if (dev_priv->chipset < 0x90 ||
44 dev_priv->chipset == 0x92 ||
45 dev_priv->chipset == 0xa0)
52 nv50_display_early_init(struct drm_device *dev)
58 nv50_display_late_takedown(struct drm_device *dev)
63 nv50_display_init(struct drm_device *dev)
65 struct drm_nouveau_private *dev_priv = dev->dev_private;
66 struct nouveau_gpio_engine *pgpio = &dev_priv->engine.gpio;
67 struct drm_connector *connector;
68 struct nouveau_channel *evo;
72 NV_DEBUG_KMS(dev, "\n");
74 nv_wr32(dev, 0x00610184, nv_rd32(dev, 0x00614004));
77 * I think the 0x006101XX range is some kind of main control area
78 * that enables things.
81 for (i = 0; i < 2; i++) {
82 val = nv_rd32(dev, 0x00616100 + (i * 0x800));
83 nv_wr32(dev, 0x00610190 + (i * 0x10), val);
84 val = nv_rd32(dev, 0x00616104 + (i * 0x800));
85 nv_wr32(dev, 0x00610194 + (i * 0x10), val);
86 val = nv_rd32(dev, 0x00616108 + (i * 0x800));
87 nv_wr32(dev, 0x00610198 + (i * 0x10), val);
88 val = nv_rd32(dev, 0x0061610c + (i * 0x800));
89 nv_wr32(dev, 0x0061019c + (i * 0x10), val);
93 for (i = 0; i < 3; i++) {
94 val = nv_rd32(dev, 0x0061a000 + (i * 0x800));
95 nv_wr32(dev, 0x006101d0 + (i * 0x04), val);
99 for (i = 0; i < nv50_sor_nr(dev); i++) {
100 val = nv_rd32(dev, 0x0061c000 + (i * 0x800));
101 nv_wr32(dev, 0x006101e0 + (i * 0x04), val);
105 for (i = 0; i < 3; i++) {
106 val = nv_rd32(dev, 0x0061e000 + (i * 0x800));
107 nv_wr32(dev, 0x006101f0 + (i * 0x04), val);
110 for (i = 0; i < 3; i++) {
111 nv_wr32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(i), 0x00550000 |
112 NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING);
113 nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL1(i), 0x00000001);
116 /* The precise purpose is unknown, i suspect it has something to do
119 if (nv_rd32(dev, NV50_PDISPLAY_INTR_1) & 0x100) {
120 nv_wr32(dev, NV50_PDISPLAY_INTR_1, 0x100);
121 nv_wr32(dev, 0x006194e8, nv_rd32(dev, 0x006194e8) & ~1);
122 if (!nv_wait(dev, 0x006194e8, 2, 0)) {
123 NV_ERROR(dev, "timeout: (0x6194e8 & 2) != 0\n");
124 NV_ERROR(dev, "0x6194e8 = 0x%08x\n",
125 nv_rd32(dev, 0x6194e8));
130 for (i = 0; i < 2; i++) {
131 nv_wr32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i), 0x2000);
132 if (!nv_wait(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
133 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS, 0)) {
134 NV_ERROR(dev, "timeout: CURSOR_CTRL2_STATUS == 0\n");
135 NV_ERROR(dev, "CURSOR_CTRL2 = 0x%08x\n",
136 nv_rd32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i)));
140 nv_wr32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
141 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_ON);
142 if (!nv_wait(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
143 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS,
144 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_ACTIVE)) {
145 NV_ERROR(dev, "timeout: "
146 "CURSOR_CTRL2_STATUS_ACTIVE(%d)\n", i);
147 NV_ERROR(dev, "CURSOR_CTRL2(%d) = 0x%08x\n", i,
148 nv_rd32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i)));
153 nv_wr32(dev, NV50_PDISPLAY_PIO_CTRL, 0x00000000);
154 nv_mask(dev, NV50_PDISPLAY_INTR_0, 0x00000000, 0x00000000);
155 nv_wr32(dev, NV50_PDISPLAY_INTR_EN_0, 0x00000000);
156 nv_mask(dev, NV50_PDISPLAY_INTR_1, 0x00000000, 0x00000000);
157 nv_wr32(dev, NV50_PDISPLAY_INTR_EN_1,
158 NV50_PDISPLAY_INTR_EN_1_CLK_UNK10 |
159 NV50_PDISPLAY_INTR_EN_1_CLK_UNK20 |
160 NV50_PDISPLAY_INTR_EN_1_CLK_UNK40);
162 /* enable hotplug interrupts */
163 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
164 struct nouveau_connector *conn = nouveau_connector(connector);
166 if (conn->dcb->gpio_tag == 0xff)
169 pgpio->irq_enable(dev, conn->dcb->gpio_tag, true);
172 ret = nv50_evo_init(dev);
177 nv_wr32(dev, NV50_PDISPLAY_OBJECTS, (evo->ramin->vinst >> 8) | 9);
179 ret = RING_SPACE(evo, 11);
182 BEGIN_RING(evo, 0, NV50_EVO_UNK84, 2);
183 OUT_RING(evo, NV50_EVO_UNK84_NOTIFY_DISABLED);
184 OUT_RING(evo, NV50_EVO_DMA_NOTIFY_HANDLE_NONE);
185 BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, FB_DMA), 1);
186 OUT_RING(evo, NV50_EVO_CRTC_FB_DMA_HANDLE_NONE);
187 BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, UNK0800), 1);
189 BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, DISPLAY_START), 1);
191 BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, UNK082C), 1);
194 if (!nv_wait(dev, 0x640004, 0xffffffff, evo->dma.put << 2))
195 NV_ERROR(dev, "evo pushbuf stalled\n");
201 static int nv50_display_disable(struct drm_device *dev)
203 struct drm_nouveau_private *dev_priv = dev->dev_private;
204 struct drm_crtc *drm_crtc;
207 NV_DEBUG_KMS(dev, "\n");
209 list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) {
210 struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc);
212 nv50_crtc_blank(crtc, true);
215 ret = RING_SPACE(dev_priv->evo, 2);
217 BEGIN_RING(dev_priv->evo, 0, NV50_EVO_UPDATE, 1);
218 OUT_RING(dev_priv->evo, 0);
220 FIRE_RING(dev_priv->evo);
222 /* Almost like ack'ing a vblank interrupt, maybe in the spirit of
225 list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) {
226 struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc);
227 uint32_t mask = NV50_PDISPLAY_INTR_1_VBLANK_CRTC_(crtc->index);
229 if (!crtc->base.enabled)
232 nv_wr32(dev, NV50_PDISPLAY_INTR_1, mask);
233 if (!nv_wait(dev, NV50_PDISPLAY_INTR_1, mask, mask)) {
234 NV_ERROR(dev, "timeout: (0x610024 & 0x%08x) == "
235 "0x%08x\n", mask, mask);
236 NV_ERROR(dev, "0x610024 = 0x%08x\n",
237 nv_rd32(dev, NV50_PDISPLAY_INTR_1));
243 for (i = 0; i < 3; i++) {
244 if (!nv_wait(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i),
245 NV50_PDISPLAY_SOR_DPMS_STATE_WAIT, 0)) {
246 NV_ERROR(dev, "timeout: SOR_DPMS_STATE_WAIT(%d) == 0\n", i);
247 NV_ERROR(dev, "SOR_DPMS_STATE(%d) = 0x%08x\n", i,
248 nv_rd32(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i)));
252 /* disable interrupts. */
253 nv_wr32(dev, NV50_PDISPLAY_INTR_EN_1, 0x00000000);
255 /* disable hotplug interrupts */
256 nv_wr32(dev, 0xe054, 0xffffffff);
257 nv_wr32(dev, 0xe050, 0x00000000);
258 if (dev_priv->chipset >= 0x90) {
259 nv_wr32(dev, 0xe074, 0xffffffff);
260 nv_wr32(dev, 0xe070, 0x00000000);
265 int nv50_display_create(struct drm_device *dev)
267 struct drm_nouveau_private *dev_priv = dev->dev_private;
268 struct dcb_table *dcb = &dev_priv->vbios.dcb;
269 struct drm_connector *connector, *ct;
272 NV_DEBUG_KMS(dev, "\n");
274 /* init basic kernel modesetting */
275 drm_mode_config_init(dev);
277 /* Initialise some optional connector properties. */
278 drm_mode_create_scaling_mode_property(dev);
279 drm_mode_create_dithering_property(dev);
281 dev->mode_config.min_width = 0;
282 dev->mode_config.min_height = 0;
284 dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
286 dev->mode_config.max_width = 8192;
287 dev->mode_config.max_height = 8192;
289 dev->mode_config.fb_base = dev_priv->fb_phys;
291 /* Create CRTC objects */
292 for (i = 0; i < 2; i++)
293 nv50_crtc_create(dev, i);
295 /* We setup the encoders from the BIOS table */
296 for (i = 0 ; i < dcb->entries; i++) {
297 struct dcb_entry *entry = &dcb->entry[i];
299 if (entry->location != DCB_LOC_ON_CHIP) {
300 NV_WARN(dev, "Off-chip encoder %d/%d unsupported\n",
301 entry->type, ffs(entry->or) - 1);
305 connector = nouveau_connector_create(dev, entry->connector);
306 if (IS_ERR(connector))
309 switch (entry->type) {
313 nv50_sor_create(connector, entry);
316 nv50_dac_create(connector, entry);
319 NV_WARN(dev, "DCB encoder %d unknown\n", entry->type);
324 list_for_each_entry_safe(connector, ct,
325 &dev->mode_config.connector_list, head) {
326 if (!connector->encoder_ids[0]) {
327 NV_WARN(dev, "%s has no encoders, removing\n",
328 drm_get_connector_name(connector));
329 connector->funcs->destroy(connector);
333 INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh);
334 nouveau_irq_register(dev, 26, nv50_display_isr);
336 ret = nv50_display_init(dev);
338 nv50_display_destroy(dev);
346 nv50_display_destroy(struct drm_device *dev)
348 struct drm_nouveau_private *dev_priv = dev->dev_private;
350 NV_DEBUG_KMS(dev, "\n");
352 drm_mode_config_cleanup(dev);
354 nv50_display_disable(dev);
355 nouveau_irq_unregister(dev, 26);
356 flush_work_sync(&dev_priv->irq_work);
360 nv50_display_script_select(struct drm_device *dev, struct dcb_entry *dcb,
363 struct drm_nouveau_private *dev_priv = dev->dev_private;
364 struct nouveau_connector *nv_connector = NULL;
365 struct drm_encoder *encoder;
366 struct nvbios *bios = &dev_priv->vbios;
369 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
370 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
372 if (nv_encoder->dcb != dcb)
375 nv_connector = nouveau_encoder_connector_get(nv_encoder);
379 or = ffs(dcb->or) - 1;
382 script = (mc >> 8) & 0xf;
383 if (bios->fp_no_ddc) {
384 if (bios->fp.dual_link)
386 if (bios->fp.if_is_24bit)
389 if (pxclk >= bios->fp.duallink_transition_clk) {
391 if (bios->fp.strapless_is_24bit & 2)
394 if (bios->fp.strapless_is_24bit & 1)
397 if (nv_connector && nv_connector->edid &&
398 (nv_connector->edid->revision >= 4) &&
399 (nv_connector->edid->input & 0x70) >= 0x20)
403 if (nouveau_uscript_lvds >= 0) {
404 NV_INFO(dev, "override script 0x%04x with 0x%04x "
405 "for output LVDS-%d\n", script,
406 nouveau_uscript_lvds, or);
407 script = nouveau_uscript_lvds;
411 script = (mc >> 8) & 0xf;
415 if (nouveau_uscript_tmds >= 0) {
416 NV_INFO(dev, "override script 0x%04x with 0x%04x "
417 "for output TMDS-%d\n", script,
418 nouveau_uscript_tmds, or);
419 script = nouveau_uscript_tmds;
423 script = (mc >> 8) & 0xf;
429 NV_ERROR(dev, "modeset on unsupported output type!\n");
437 nv50_display_vblank_crtc_handler(struct drm_device *dev, int crtc)
439 struct drm_nouveau_private *dev_priv = dev->dev_private;
440 struct nouveau_channel *chan, *tmp;
442 list_for_each_entry_safe(chan, tmp, &dev_priv->vbl_waiting,
444 if (chan->nvsw.vblsem_head != crtc)
447 nouveau_bo_wr32(chan->notifier_bo, chan->nvsw.vblsem_offset,
448 chan->nvsw.vblsem_rval);
449 list_del(&chan->nvsw.vbl_wait);
450 drm_vblank_put(dev, crtc);
453 drm_handle_vblank(dev, crtc);
457 nv50_display_vblank_handler(struct drm_device *dev, uint32_t intr)
459 if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_0)
460 nv50_display_vblank_crtc_handler(dev, 0);
462 if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_1)
463 nv50_display_vblank_crtc_handler(dev, 1);
465 nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_VBLANK_CRTC);
469 nv50_display_unk10_handler(struct drm_device *dev)
471 struct drm_nouveau_private *dev_priv = dev->dev_private;
472 u32 unk30 = nv_rd32(dev, 0x610030), mc;
473 int i, crtc, or, type = OUTPUT_ANY;
475 NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
476 dev_priv->evo_irq.dcb = NULL;
478 nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) & ~8);
480 /* Determine which CRTC we're dealing with, only 1 ever will be
481 * signalled at the same time with the current nouveau code.
483 crtc = ffs((unk30 & 0x00000060) >> 5) - 1;
487 /* Nothing needs to be done for the encoder */
488 crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
492 /* Find which encoder was connected to the CRTC */
493 for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
494 mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_C(i));
495 NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
496 if (!(mc & (1 << crtc)))
499 switch ((mc & 0x00000f00) >> 8) {
500 case 0: type = OUTPUT_ANALOG; break;
501 case 1: type = OUTPUT_TV; break;
503 NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
510 for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) {
511 if (dev_priv->chipset < 0x90 ||
512 dev_priv->chipset == 0x92 ||
513 dev_priv->chipset == 0xa0)
514 mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_C(i));
516 mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_C(i));
518 NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
519 if (!(mc & (1 << crtc)))
522 switch ((mc & 0x00000f00) >> 8) {
523 case 0: type = OUTPUT_LVDS; break;
524 case 1: type = OUTPUT_TMDS; break;
525 case 2: type = OUTPUT_TMDS; break;
526 case 5: type = OUTPUT_TMDS; break;
527 case 8: type = OUTPUT_DP; break;
528 case 9: type = OUTPUT_DP; break;
530 NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
537 /* There was no encoder to disable */
538 if (type == OUTPUT_ANY)
541 /* Disable the encoder */
542 for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
543 struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i];
545 if (dcb->type == type && (dcb->or & (1 << or))) {
546 nouveau_bios_run_display_table(dev, dcb, 0, -1);
547 dev_priv->evo_irq.dcb = dcb;
552 NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
554 nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK10);
555 nv_wr32(dev, 0x610030, 0x80000000);
559 nv50_display_unk20_dp_hack(struct drm_device *dev, struct dcb_entry *dcb)
561 int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1);
562 struct drm_encoder *encoder;
563 uint32_t tmp, unk0 = 0, unk1 = 0;
565 if (dcb->type != OUTPUT_DP)
568 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
569 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
571 if (nv_encoder->dcb == dcb) {
572 unk0 = nv_encoder->dp.unk0;
573 unk1 = nv_encoder->dp.unk1;
579 tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
581 nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp | unk0);
583 tmp = nv_rd32(dev, NV50_SOR_DP_UNK128(or, link));
585 nv_wr32(dev, NV50_SOR_DP_UNK128(or, link), tmp | unk1);
590 nv50_display_unk20_handler(struct drm_device *dev)
592 struct drm_nouveau_private *dev_priv = dev->dev_private;
593 u32 unk30 = nv_rd32(dev, 0x610030), tmp, pclk, script, mc = 0;
594 struct dcb_entry *dcb;
595 int i, crtc, or, type = OUTPUT_ANY;
597 NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
598 dcb = dev_priv->evo_irq.dcb;
600 nouveau_bios_run_display_table(dev, dcb, 0, -2);
601 dev_priv->evo_irq.dcb = NULL;
604 /* CRTC clock change requested? */
605 crtc = ffs((unk30 & 0x00000600) >> 9) - 1;
607 pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK));
610 nv50_crtc_set_clock(dev, crtc, pclk);
612 tmp = nv_rd32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc));
614 nv_wr32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc), tmp);
617 /* Nothing needs to be done for the encoder */
618 crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
621 pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK)) & 0x003fffff;
623 /* Find which encoder is connected to the CRTC */
624 for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
625 mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_P(i));
626 NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
627 if (!(mc & (1 << crtc)))
630 switch ((mc & 0x00000f00) >> 8) {
631 case 0: type = OUTPUT_ANALOG; break;
632 case 1: type = OUTPUT_TV; break;
634 NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
641 for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) {
642 if (dev_priv->chipset < 0x90 ||
643 dev_priv->chipset == 0x92 ||
644 dev_priv->chipset == 0xa0)
645 mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_P(i));
647 mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_P(i));
649 NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
650 if (!(mc & (1 << crtc)))
653 switch ((mc & 0x00000f00) >> 8) {
654 case 0: type = OUTPUT_LVDS; break;
655 case 1: type = OUTPUT_TMDS; break;
656 case 2: type = OUTPUT_TMDS; break;
657 case 5: type = OUTPUT_TMDS; break;
658 case 8: type = OUTPUT_DP; break;
659 case 9: type = OUTPUT_DP; break;
661 NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
668 if (type == OUTPUT_ANY)
671 /* Enable the encoder */
672 for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
673 dcb = &dev_priv->vbios.dcb.entry[i];
674 if (dcb->type == type && (dcb->or & (1 << or)))
678 if (i == dev_priv->vbios.dcb.entries) {
679 NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
683 script = nv50_display_script_select(dev, dcb, mc, pclk);
684 nouveau_bios_run_display_table(dev, dcb, script, pclk);
686 nv50_display_unk20_dp_hack(dev, dcb);
688 if (dcb->type != OUTPUT_ANALOG) {
689 tmp = nv_rd32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or));
693 nv_wr32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or), tmp);
695 nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL2(or), 0);
698 dev_priv->evo_irq.dcb = dcb;
699 dev_priv->evo_irq.pclk = pclk;
700 dev_priv->evo_irq.script = script;
703 nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK20);
704 nv_wr32(dev, 0x610030, 0x80000000);
707 /* If programming a TMDS output on a SOR that can also be configured for
708 * DisplayPort, make sure NV50_SOR_DP_CTRL_ENABLE is forced off.
710 * It looks like the VBIOS TMDS scripts make an attempt at this, however,
711 * the VBIOS scripts on at least one board I have only switch it off on
712 * link 0, causing a blank display if the output has previously been
713 * programmed for DisplayPort.
716 nv50_display_unk40_dp_set_tmds(struct drm_device *dev, struct dcb_entry *dcb)
718 int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1);
719 struct drm_encoder *encoder;
722 if (dcb->type != OUTPUT_TMDS)
725 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
726 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
728 if (nv_encoder->dcb->type == OUTPUT_DP &&
729 nv_encoder->dcb->or & (1 << or)) {
730 tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
731 tmp &= ~NV50_SOR_DP_CTRL_ENABLED;
732 nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp);
739 nv50_display_unk40_handler(struct drm_device *dev)
741 struct drm_nouveau_private *dev_priv = dev->dev_private;
742 struct dcb_entry *dcb = dev_priv->evo_irq.dcb;
743 u16 script = dev_priv->evo_irq.script;
744 u32 unk30 = nv_rd32(dev, 0x610030), pclk = dev_priv->evo_irq.pclk;
746 NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
747 dev_priv->evo_irq.dcb = NULL;
751 nouveau_bios_run_display_table(dev, dcb, script, -pclk);
752 nv50_display_unk40_dp_set_tmds(dev, dcb);
755 nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK40);
756 nv_wr32(dev, 0x610030, 0x80000000);
757 nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) | 8);
761 nv50_display_irq_handler_bh(struct work_struct *work)
763 struct drm_nouveau_private *dev_priv =
764 container_of(work, struct drm_nouveau_private, irq_work);
765 struct drm_device *dev = dev_priv->dev;
768 uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
769 uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
771 NV_DEBUG_KMS(dev, "PDISPLAY_INTR_BH 0x%08x 0x%08x\n", intr0, intr1);
773 if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK10)
774 nv50_display_unk10_handler(dev);
776 if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK20)
777 nv50_display_unk20_handler(dev);
779 if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK40)
780 nv50_display_unk40_handler(dev);
785 nv_wr32(dev, NV03_PMC_INTR_EN_0, 1);
789 nv50_display_error_handler(struct drm_device *dev)
791 u32 channels = (nv_rd32(dev, NV50_PDISPLAY_INTR_0) & 0x001f0000) >> 16;
795 for (chid = 0; chid < 5; chid++) {
796 if (!(channels & (1 << chid)))
799 nv_wr32(dev, NV50_PDISPLAY_INTR_0, 0x00010000 << chid);
800 addr = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid));
801 data = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_DATA(chid));
802 NV_ERROR(dev, "EvoCh %d Mthd 0x%04x Data 0x%08x "
803 "(0x%04x 0x%02x)\n", chid,
804 addr & 0xffc, data, addr >> 16, (addr >> 12) & 0xf);
806 nv_wr32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid), 0x90000000);
811 nv50_display_isr(struct drm_device *dev)
813 struct drm_nouveau_private *dev_priv = dev->dev_private;
814 uint32_t delayed = 0;
816 while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_DISPLAY) {
817 uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
818 uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
821 NV_DEBUG_KMS(dev, "PDISPLAY_INTR 0x%08x 0x%08x\n", intr0, intr1);
823 if (!intr0 && !(intr1 & ~delayed))
826 if (intr0 & 0x001f0000) {
827 nv50_display_error_handler(dev);
828 intr0 &= ~0x001f0000;
831 if (intr1 & NV50_PDISPLAY_INTR_1_VBLANK_CRTC) {
832 nv50_display_vblank_handler(dev, intr1);
833 intr1 &= ~NV50_PDISPLAY_INTR_1_VBLANK_CRTC;
836 clock = (intr1 & (NV50_PDISPLAY_INTR_1_CLK_UNK10 |
837 NV50_PDISPLAY_INTR_1_CLK_UNK20 |
838 NV50_PDISPLAY_INTR_1_CLK_UNK40));
840 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
841 if (!work_pending(&dev_priv->irq_work))
842 schedule_work(&dev_priv->irq_work);
848 NV_ERROR(dev, "unknown PDISPLAY_INTR_0: 0x%08x\n", intr0);
849 nv_wr32(dev, NV50_PDISPLAY_INTR_0, intr0);
854 "unknown PDISPLAY_INTR_1: 0x%08x\n", intr1);
855 nv_wr32(dev, NV50_PDISPLAY_INTR_1, intr1);