Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 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 "nv50_display.h" |
| 28 | #include "nouveau_crtc.h" |
| 29 | #include "nouveau_encoder.h" |
| 30 | #include "nouveau_connector.h" |
| 31 | #include "nouveau_fb.h" |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 32 | #include "nouveau_fbcon.h" |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 33 | #include "nouveau_ramht.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 34 | #include "drm_crtc_helper.h" |
| 35 | |
Ben Skeggs | 19b7fc7 | 2010-11-03 10:27:27 +1000 | [diff] [blame] | 36 | static void nv50_display_isr(struct drm_device *); |
| 37 | |
Ben Skeggs | 8597a1b | 2010-09-06 11:39:25 +1000 | [diff] [blame] | 38 | static inline int |
| 39 | nv50_sor_nr(struct drm_device *dev) |
| 40 | { |
| 41 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 42 | |
| 43 | if (dev_priv->chipset < 0x90 || |
| 44 | dev_priv->chipset == 0x92 || |
| 45 | dev_priv->chipset == 0xa0) |
| 46 | return 2; |
| 47 | |
| 48 | return 4; |
| 49 | } |
| 50 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 51 | int |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 52 | nv50_display_early_init(struct drm_device *dev) |
| 53 | { |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | nv50_display_late_takedown(struct drm_device *dev) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | int |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 63 | nv50_display_init(struct drm_device *dev) |
| 64 | { |
| 65 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 66 | struct nouveau_gpio_engine *pgpio = &dev_priv->engine.gpio; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 67 | struct drm_connector *connector; |
Ben Skeggs | b7bc613 | 2010-10-19 13:05:51 +1000 | [diff] [blame] | 68 | struct nouveau_channel *evo; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 69 | int ret, i; |
Ben Skeggs | cbb4b60 | 2010-10-18 12:34:04 +1000 | [diff] [blame] | 70 | u32 val; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 71 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 72 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 73 | |
| 74 | nv_wr32(dev, 0x00610184, nv_rd32(dev, 0x00614004)); |
Ben Skeggs | 106ddad | 2010-10-19 11:14:17 +1000 | [diff] [blame] | 75 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 76 | /* |
| 77 | * I think the 0x006101XX range is some kind of main control area |
| 78 | * that enables things. |
| 79 | */ |
| 80 | /* CRTC? */ |
| 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); |
| 90 | } |
Ben Skeggs | 106ddad | 2010-10-19 11:14:17 +1000 | [diff] [blame] | 91 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 92 | /* DAC */ |
| 93 | for (i = 0; i < 3; i++) { |
| 94 | val = nv_rd32(dev, 0x0061a000 + (i * 0x800)); |
| 95 | nv_wr32(dev, 0x006101d0 + (i * 0x04), val); |
| 96 | } |
Ben Skeggs | 106ddad | 2010-10-19 11:14:17 +1000 | [diff] [blame] | 97 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 98 | /* SOR */ |
Ben Skeggs | 8597a1b | 2010-09-06 11:39:25 +1000 | [diff] [blame] | 99 | for (i = 0; i < nv50_sor_nr(dev); i++) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 100 | val = nv_rd32(dev, 0x0061c000 + (i * 0x800)); |
| 101 | nv_wr32(dev, 0x006101e0 + (i * 0x04), val); |
| 102 | } |
Ben Skeggs | 106ddad | 2010-10-19 11:14:17 +1000 | [diff] [blame] | 103 | |
Ben Skeggs | 8597a1b | 2010-09-06 11:39:25 +1000 | [diff] [blame] | 104 | /* EXT */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 105 | for (i = 0; i < 3; i++) { |
| 106 | val = nv_rd32(dev, 0x0061e000 + (i * 0x800)); |
| 107 | nv_wr32(dev, 0x006101f0 + (i * 0x04), val); |
| 108 | } |
| 109 | |
| 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); |
| 114 | } |
| 115 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 116 | /* The precise purpose is unknown, i suspect it has something to do |
| 117 | * with text mode. |
| 118 | */ |
| 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); |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 122 | if (!nv_wait(dev, 0x006194e8, 2, 0)) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 123 | NV_ERROR(dev, "timeout: (0x6194e8 & 2) != 0\n"); |
| 124 | NV_ERROR(dev, "0x6194e8 = 0x%08x\n", |
| 125 | nv_rd32(dev, 0x6194e8)); |
| 126 | return -EBUSY; |
| 127 | } |
| 128 | } |
| 129 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 130 | for (i = 0; i < 2; i++) { |
| 131 | nv_wr32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i), 0x2000); |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 132 | if (!nv_wait(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i), |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 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))); |
| 137 | return -EBUSY; |
| 138 | } |
| 139 | |
| 140 | nv_wr32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i), |
| 141 | NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_ON); |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 142 | if (!nv_wait(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i), |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 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))); |
| 149 | return -EBUSY; |
| 150 | } |
| 151 | } |
| 152 | |
Ben Skeggs | 106ddad | 2010-10-19 11:14:17 +1000 | [diff] [blame] | 153 | nv_wr32(dev, NV50_PDISPLAY_PIO_CTRL, 0x00000000); |
Ben Skeggs | 106ddad | 2010-10-19 11:14:17 +1000 | [diff] [blame] | 154 | nv_mask(dev, NV50_PDISPLAY_INTR_0, 0x00000000, 0x00000000); |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 155 | nv_wr32(dev, NV50_PDISPLAY_INTR_EN_0, 0x00000000); |
Ben Skeggs | 106ddad | 2010-10-19 11:14:17 +1000 | [diff] [blame] | 156 | nv_mask(dev, NV50_PDISPLAY_INTR_1, 0x00000000, 0x00000000); |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 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); |
Ben Skeggs | 106ddad | 2010-10-19 11:14:17 +1000 | [diff] [blame] | 161 | |
| 162 | /* enable hotplug interrupts */ |
| 163 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 164 | struct nouveau_connector *conn = nouveau_connector(connector); |
| 165 | |
| 166 | if (conn->dcb->gpio_tag == 0xff) |
| 167 | continue; |
| 168 | |
| 169 | pgpio->irq_enable(dev, conn->dcb->gpio_tag, true); |
| 170 | } |
| 171 | |
Ben Skeggs | b7bc613 | 2010-10-19 13:05:51 +1000 | [diff] [blame] | 172 | ret = nv50_evo_init(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 173 | if (ret) |
| 174 | return ret; |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 175 | evo = nv50_display(dev)->evo; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 176 | |
Ben Skeggs | b7bc613 | 2010-10-19 13:05:51 +1000 | [diff] [blame] | 177 | nv_wr32(dev, NV50_PDISPLAY_OBJECTS, (evo->ramin->vinst >> 8) | 9); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 178 | |
| 179 | ret = RING_SPACE(evo, 11); |
| 180 | if (ret) |
| 181 | return ret; |
| 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); |
| 188 | OUT_RING(evo, 0); |
| 189 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, DISPLAY_START), 1); |
| 190 | OUT_RING(evo, 0); |
| 191 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(0, UNK082C), 1); |
| 192 | OUT_RING(evo, 0); |
| 193 | FIRE_RING(evo); |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 194 | if (!nv_wait(dev, 0x640004, 0xffffffff, evo->dma.put << 2)) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 195 | NV_ERROR(dev, "evo pushbuf stalled\n"); |
| 196 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | static int nv50_display_disable(struct drm_device *dev) |
| 202 | { |
| 203 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 204 | struct nv50_display *disp = nv50_display(dev); |
| 205 | struct nouveau_channel *evo = disp->evo; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 206 | struct drm_crtc *drm_crtc; |
| 207 | int ret, i; |
| 208 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 209 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 210 | |
| 211 | list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) { |
| 212 | struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc); |
| 213 | |
| 214 | nv50_crtc_blank(crtc, true); |
| 215 | } |
| 216 | |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 217 | ret = RING_SPACE(evo, 2); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 218 | if (ret == 0) { |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 219 | BEGIN_RING(evo, 0, NV50_EVO_UPDATE, 1); |
| 220 | OUT_RING(evo, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 221 | } |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 222 | FIRE_RING(evo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 223 | |
| 224 | /* Almost like ack'ing a vblank interrupt, maybe in the spirit of |
| 225 | * cleaning up? |
| 226 | */ |
| 227 | list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) { |
| 228 | struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc); |
| 229 | uint32_t mask = NV50_PDISPLAY_INTR_1_VBLANK_CRTC_(crtc->index); |
| 230 | |
| 231 | if (!crtc->base.enabled) |
| 232 | continue; |
| 233 | |
| 234 | nv_wr32(dev, NV50_PDISPLAY_INTR_1, mask); |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 235 | if (!nv_wait(dev, NV50_PDISPLAY_INTR_1, mask, mask)) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 236 | NV_ERROR(dev, "timeout: (0x610024 & 0x%08x) == " |
| 237 | "0x%08x\n", mask, mask); |
| 238 | NV_ERROR(dev, "0x610024 = 0x%08x\n", |
| 239 | nv_rd32(dev, NV50_PDISPLAY_INTR_1)); |
| 240 | } |
| 241 | } |
| 242 | |
Ben Skeggs | b7bc613 | 2010-10-19 13:05:51 +1000 | [diff] [blame] | 243 | nv50_evo_fini(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 244 | |
| 245 | for (i = 0; i < 3; i++) { |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 246 | if (!nv_wait(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i), |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 247 | NV50_PDISPLAY_SOR_DPMS_STATE_WAIT, 0)) { |
| 248 | NV_ERROR(dev, "timeout: SOR_DPMS_STATE_WAIT(%d) == 0\n", i); |
| 249 | NV_ERROR(dev, "SOR_DPMS_STATE(%d) = 0x%08x\n", i, |
| 250 | nv_rd32(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i))); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /* disable interrupts. */ |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 255 | nv_wr32(dev, NV50_PDISPLAY_INTR_EN_1, 0x00000000); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 256 | |
| 257 | /* disable hotplug interrupts */ |
| 258 | nv_wr32(dev, 0xe054, 0xffffffff); |
| 259 | nv_wr32(dev, 0xe050, 0x00000000); |
| 260 | if (dev_priv->chipset >= 0x90) { |
| 261 | nv_wr32(dev, 0xe074, 0xffffffff); |
| 262 | nv_wr32(dev, 0xe070, 0x00000000); |
| 263 | } |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | int nv50_display_create(struct drm_device *dev) |
| 268 | { |
| 269 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 04a39c5 | 2010-02-24 10:03:05 +1000 | [diff] [blame] | 270 | struct dcb_table *dcb = &dev_priv->vbios.dcb; |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 271 | struct drm_connector *connector, *ct; |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 272 | struct nv50_display *priv; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 273 | int ret, i; |
| 274 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 275 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 276 | |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 277 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 278 | if (!priv) |
| 279 | return -ENOMEM; |
| 280 | dev_priv->engine.display.priv = priv; |
| 281 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 282 | /* init basic kernel modesetting */ |
| 283 | drm_mode_config_init(dev); |
| 284 | |
| 285 | /* Initialise some optional connector properties. */ |
| 286 | drm_mode_create_scaling_mode_property(dev); |
| 287 | drm_mode_create_dithering_property(dev); |
| 288 | |
| 289 | dev->mode_config.min_width = 0; |
| 290 | dev->mode_config.min_height = 0; |
| 291 | |
| 292 | dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs; |
| 293 | |
| 294 | dev->mode_config.max_width = 8192; |
| 295 | dev->mode_config.max_height = 8192; |
| 296 | |
| 297 | dev->mode_config.fb_base = dev_priv->fb_phys; |
| 298 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 299 | /* Create CRTC objects */ |
| 300 | for (i = 0; i < 2; i++) |
| 301 | nv50_crtc_create(dev, i); |
| 302 | |
| 303 | /* We setup the encoders from the BIOS table */ |
| 304 | for (i = 0 ; i < dcb->entries; i++) { |
| 305 | struct dcb_entry *entry = &dcb->entry[i]; |
| 306 | |
| 307 | if (entry->location != DCB_LOC_ON_CHIP) { |
| 308 | NV_WARN(dev, "Off-chip encoder %d/%d unsupported\n", |
| 309 | entry->type, ffs(entry->or) - 1); |
| 310 | continue; |
| 311 | } |
| 312 | |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 313 | connector = nouveau_connector_create(dev, entry->connector); |
| 314 | if (IS_ERR(connector)) |
| 315 | continue; |
| 316 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 317 | switch (entry->type) { |
| 318 | case OUTPUT_TMDS: |
| 319 | case OUTPUT_LVDS: |
| 320 | case OUTPUT_DP: |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 321 | nv50_sor_create(connector, entry); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 322 | break; |
| 323 | case OUTPUT_ANALOG: |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 324 | nv50_dac_create(connector, entry); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 325 | break; |
| 326 | default: |
| 327 | NV_WARN(dev, "DCB encoder %d unknown\n", entry->type); |
| 328 | continue; |
| 329 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 330 | } |
| 331 | |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 332 | list_for_each_entry_safe(connector, ct, |
| 333 | &dev->mode_config.connector_list, head) { |
| 334 | if (!connector->encoder_ids[0]) { |
| 335 | NV_WARN(dev, "%s has no encoders, removing\n", |
| 336 | drm_get_connector_name(connector)); |
| 337 | connector->funcs->destroy(connector); |
| 338 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 339 | } |
| 340 | |
Ben Skeggs | 19b7fc7 | 2010-11-03 10:27:27 +1000 | [diff] [blame] | 341 | INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh); |
| 342 | nouveau_irq_register(dev, 26, nv50_display_isr); |
| 343 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 344 | ret = nv50_display_init(dev); |
Ben Skeggs | a1663ed | 2010-03-25 16:01:04 +1000 | [diff] [blame] | 345 | if (ret) { |
| 346 | nv50_display_destroy(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 347 | return ret; |
Ben Skeggs | a1663ed | 2010-03-25 16:01:04 +1000 | [diff] [blame] | 348 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 353 | void |
| 354 | nv50_display_destroy(struct drm_device *dev) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 355 | { |
Tejun Heo | d82f8e6 | 2011-01-26 17:49:18 +0100 | [diff] [blame] | 356 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 357 | struct nv50_display *disp = nv50_display(dev); |
Tejun Heo | d82f8e6 | 2011-01-26 17:49:18 +0100 | [diff] [blame] | 358 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 359 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 360 | |
| 361 | drm_mode_config_cleanup(dev); |
| 362 | |
| 363 | nv50_display_disable(dev); |
Ben Skeggs | 19b7fc7 | 2010-11-03 10:27:27 +1000 | [diff] [blame] | 364 | nouveau_irq_unregister(dev, 26); |
Tejun Heo | d82f8e6 | 2011-01-26 17:49:18 +0100 | [diff] [blame] | 365 | flush_work_sync(&dev_priv->irq_work); |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 366 | kfree(disp); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 367 | } |
| 368 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 369 | static u16 |
| 370 | nv50_display_script_select(struct drm_device *dev, struct dcb_entry *dcb, |
| 371 | u32 mc, int pxclk) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 372 | { |
| 373 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 75c722d | 2009-12-21 12:16:52 +1000 | [diff] [blame] | 374 | struct nouveau_connector *nv_connector = NULL; |
| 375 | struct drm_encoder *encoder; |
Ben Skeggs | 04a39c5 | 2010-02-24 10:03:05 +1000 | [diff] [blame] | 376 | struct nvbios *bios = &dev_priv->vbios; |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 377 | u32 script = 0, or; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 378 | |
Ben Skeggs | 75c722d | 2009-12-21 12:16:52 +1000 | [diff] [blame] | 379 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 380 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 381 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 382 | if (nv_encoder->dcb != dcb) |
Ben Skeggs | 75c722d | 2009-12-21 12:16:52 +1000 | [diff] [blame] | 383 | continue; |
| 384 | |
| 385 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 386 | break; |
| 387 | } |
| 388 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 389 | or = ffs(dcb->or) - 1; |
| 390 | switch (dcb->type) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 391 | case OUTPUT_LVDS: |
| 392 | script = (mc >> 8) & 0xf; |
Ben Skeggs | 04a39c5 | 2010-02-24 10:03:05 +1000 | [diff] [blame] | 393 | if (bios->fp_no_ddc) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 394 | if (bios->fp.dual_link) |
| 395 | script |= 0x0100; |
| 396 | if (bios->fp.if_is_24bit) |
| 397 | script |= 0x0200; |
| 398 | } else { |
| 399 | if (pxclk >= bios->fp.duallink_transition_clk) { |
| 400 | script |= 0x0100; |
| 401 | if (bios->fp.strapless_is_24bit & 2) |
| 402 | script |= 0x0200; |
| 403 | } else |
| 404 | if (bios->fp.strapless_is_24bit & 1) |
| 405 | script |= 0x0200; |
Ben Skeggs | 75c722d | 2009-12-21 12:16:52 +1000 | [diff] [blame] | 406 | |
| 407 | if (nv_connector && nv_connector->edid && |
| 408 | (nv_connector->edid->revision >= 4) && |
| 409 | (nv_connector->edid->input & 0x70) >= 0x20) |
| 410 | script |= 0x0200; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | if (nouveau_uscript_lvds >= 0) { |
| 414 | NV_INFO(dev, "override script 0x%04x with 0x%04x " |
| 415 | "for output LVDS-%d\n", script, |
| 416 | nouveau_uscript_lvds, or); |
| 417 | script = nouveau_uscript_lvds; |
| 418 | } |
| 419 | break; |
| 420 | case OUTPUT_TMDS: |
| 421 | script = (mc >> 8) & 0xf; |
| 422 | if (pxclk >= 165000) |
| 423 | script |= 0x0100; |
| 424 | |
| 425 | if (nouveau_uscript_tmds >= 0) { |
| 426 | NV_INFO(dev, "override script 0x%04x with 0x%04x " |
| 427 | "for output TMDS-%d\n", script, |
| 428 | nouveau_uscript_tmds, or); |
| 429 | script = nouveau_uscript_tmds; |
| 430 | } |
| 431 | break; |
| 432 | case OUTPUT_DP: |
| 433 | script = (mc >> 8) & 0xf; |
| 434 | break; |
| 435 | case OUTPUT_ANALOG: |
| 436 | script = 0xff; |
| 437 | break; |
| 438 | default: |
| 439 | NV_ERROR(dev, "modeset on unsupported output type!\n"); |
| 440 | break; |
| 441 | } |
| 442 | |
| 443 | return script; |
| 444 | } |
| 445 | |
| 446 | static void |
| 447 | nv50_display_vblank_crtc_handler(struct drm_device *dev, int crtc) |
| 448 | { |
| 449 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 450 | struct nouveau_channel *chan, *tmp; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 451 | |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 452 | list_for_each_entry_safe(chan, tmp, &dev_priv->vbl_waiting, |
| 453 | nvsw.vbl_wait) { |
Francisco Jerez | 1f6d2de | 2010-10-24 14:15:58 +0200 | [diff] [blame] | 454 | if (chan->nvsw.vblsem_head != crtc) |
| 455 | continue; |
| 456 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 457 | nouveau_bo_wr32(chan->notifier_bo, chan->nvsw.vblsem_offset, |
| 458 | chan->nvsw.vblsem_rval); |
| 459 | list_del(&chan->nvsw.vbl_wait); |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 460 | drm_vblank_put(dev, crtc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 461 | } |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 462 | |
| 463 | drm_handle_vblank(dev, crtc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static void |
| 467 | nv50_display_vblank_handler(struct drm_device *dev, uint32_t intr) |
| 468 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 469 | if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_0) |
| 470 | nv50_display_vblank_crtc_handler(dev, 0); |
| 471 | |
| 472 | if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_1) |
| 473 | nv50_display_vblank_crtc_handler(dev, 1); |
| 474 | |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 475 | nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_VBLANK_CRTC); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | static void |
| 479 | nv50_display_unk10_handler(struct drm_device *dev) |
| 480 | { |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 481 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 482 | struct nv50_display *disp = nv50_display(dev); |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 483 | u32 unk30 = nv_rd32(dev, 0x610030), mc; |
| 484 | int i, crtc, or, type = OUTPUT_ANY; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 485 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 486 | NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30); |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 487 | disp->irq.dcb = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 488 | |
| 489 | nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) & ~8); |
| 490 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 491 | /* Determine which CRTC we're dealing with, only 1 ever will be |
| 492 | * signalled at the same time with the current nouveau code. |
| 493 | */ |
| 494 | crtc = ffs((unk30 & 0x00000060) >> 5) - 1; |
| 495 | if (crtc < 0) |
| 496 | goto ack; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 497 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 498 | /* Nothing needs to be done for the encoder */ |
| 499 | crtc = ffs((unk30 & 0x00000180) >> 7) - 1; |
| 500 | if (crtc < 0) |
| 501 | goto ack; |
| 502 | |
| 503 | /* Find which encoder was connected to the CRTC */ |
| 504 | for (i = 0; type == OUTPUT_ANY && i < 3; i++) { |
| 505 | mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_C(i)); |
| 506 | NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc); |
| 507 | if (!(mc & (1 << crtc))) |
| 508 | continue; |
| 509 | |
| 510 | switch ((mc & 0x00000f00) >> 8) { |
| 511 | case 0: type = OUTPUT_ANALOG; break; |
| 512 | case 1: type = OUTPUT_TV; break; |
| 513 | default: |
| 514 | NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc); |
| 515 | goto ack; |
| 516 | } |
| 517 | |
| 518 | or = i; |
| 519 | } |
| 520 | |
Ben Skeggs | 8597a1b | 2010-09-06 11:39:25 +1000 | [diff] [blame] | 521 | for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) { |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 522 | if (dev_priv->chipset < 0x90 || |
| 523 | dev_priv->chipset == 0x92 || |
| 524 | dev_priv->chipset == 0xa0) |
| 525 | mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_C(i)); |
| 526 | else |
| 527 | mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_C(i)); |
| 528 | |
| 529 | NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc); |
| 530 | if (!(mc & (1 << crtc))) |
| 531 | continue; |
| 532 | |
| 533 | switch ((mc & 0x00000f00) >> 8) { |
| 534 | case 0: type = OUTPUT_LVDS; break; |
| 535 | case 1: type = OUTPUT_TMDS; break; |
| 536 | case 2: type = OUTPUT_TMDS; break; |
| 537 | case 5: type = OUTPUT_TMDS; break; |
| 538 | case 8: type = OUTPUT_DP; break; |
| 539 | case 9: type = OUTPUT_DP; break; |
| 540 | default: |
| 541 | NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc); |
| 542 | goto ack; |
| 543 | } |
| 544 | |
| 545 | or = i; |
| 546 | } |
| 547 | |
| 548 | /* There was no encoder to disable */ |
| 549 | if (type == OUTPUT_ANY) |
| 550 | goto ack; |
| 551 | |
| 552 | /* Disable the encoder */ |
| 553 | for (i = 0; i < dev_priv->vbios.dcb.entries; i++) { |
| 554 | struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i]; |
| 555 | |
| 556 | if (dcb->type == type && (dcb->or & (1 << or))) { |
| 557 | nouveau_bios_run_display_table(dev, dcb, 0, -1); |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 558 | disp->irq.dcb = dcb; |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 559 | goto ack; |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 564 | ack: |
| 565 | nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK10); |
| 566 | nv_wr32(dev, 0x610030, 0x80000000); |
| 567 | } |
| 568 | |
| 569 | static void |
Ben Skeggs | afa3b4c | 2010-04-23 08:21:48 +1000 | [diff] [blame] | 570 | nv50_display_unk20_dp_hack(struct drm_device *dev, struct dcb_entry *dcb) |
| 571 | { |
| 572 | int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1); |
| 573 | struct drm_encoder *encoder; |
| 574 | uint32_t tmp, unk0 = 0, unk1 = 0; |
| 575 | |
| 576 | if (dcb->type != OUTPUT_DP) |
| 577 | return; |
| 578 | |
| 579 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 580 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 581 | |
| 582 | if (nv_encoder->dcb == dcb) { |
| 583 | unk0 = nv_encoder->dp.unk0; |
| 584 | unk1 = nv_encoder->dp.unk1; |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | if (unk0 || unk1) { |
| 590 | tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link)); |
| 591 | tmp &= 0xfffffe03; |
| 592 | nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp | unk0); |
| 593 | |
| 594 | tmp = nv_rd32(dev, NV50_SOR_DP_UNK128(or, link)); |
| 595 | tmp &= 0xfef080c0; |
| 596 | nv_wr32(dev, NV50_SOR_DP_UNK128(or, link), tmp | unk1); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | static void |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 601 | nv50_display_unk20_handler(struct drm_device *dev) |
| 602 | { |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 603 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 604 | struct nv50_display *disp = nv50_display(dev); |
Ben Skeggs | ea5f278 | 2011-01-31 08:26:04 +1000 | [diff] [blame] | 605 | u32 unk30 = nv_rd32(dev, 0x610030), tmp, pclk, script, mc = 0; |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 606 | struct dcb_entry *dcb; |
| 607 | int i, crtc, or, type = OUTPUT_ANY; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 608 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 609 | NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30); |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 610 | dcb = disp->irq.dcb; |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 611 | if (dcb) { |
| 612 | nouveau_bios_run_display_table(dev, dcb, 0, -2); |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 613 | disp->irq.dcb = NULL; |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /* CRTC clock change requested? */ |
| 617 | crtc = ffs((unk30 & 0x00000600) >> 9) - 1; |
| 618 | if (crtc >= 0) { |
| 619 | pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK)); |
| 620 | pclk &= 0x003fffff; |
| 621 | |
| 622 | nv50_crtc_set_clock(dev, crtc, pclk); |
| 623 | |
| 624 | tmp = nv_rd32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc)); |
| 625 | tmp &= ~0x000000f; |
| 626 | nv_wr32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc), tmp); |
| 627 | } |
| 628 | |
| 629 | /* Nothing needs to be done for the encoder */ |
| 630 | crtc = ffs((unk30 & 0x00000180) >> 7) - 1; |
| 631 | if (crtc < 0) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 632 | goto ack; |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 633 | pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK)) & 0x003fffff; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 634 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 635 | /* Find which encoder is connected to the CRTC */ |
| 636 | for (i = 0; type == OUTPUT_ANY && i < 3; i++) { |
| 637 | mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_P(i)); |
| 638 | NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc); |
| 639 | if (!(mc & (1 << crtc))) |
| 640 | continue; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 641 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 642 | switch ((mc & 0x00000f00) >> 8) { |
| 643 | case 0: type = OUTPUT_ANALOG; break; |
| 644 | case 1: type = OUTPUT_TV; break; |
| 645 | default: |
| 646 | NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc); |
| 647 | goto ack; |
| 648 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 649 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 650 | or = i; |
| 651 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 652 | |
Ben Skeggs | 8597a1b | 2010-09-06 11:39:25 +1000 | [diff] [blame] | 653 | for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) { |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 654 | if (dev_priv->chipset < 0x90 || |
| 655 | dev_priv->chipset == 0x92 || |
| 656 | dev_priv->chipset == 0xa0) |
| 657 | mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_P(i)); |
| 658 | else |
| 659 | mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_P(i)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 660 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 661 | NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc); |
| 662 | if (!(mc & (1 << crtc))) |
| 663 | continue; |
Ben Skeggs | afa3b4c | 2010-04-23 08:21:48 +1000 | [diff] [blame] | 664 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 665 | switch ((mc & 0x00000f00) >> 8) { |
| 666 | case 0: type = OUTPUT_LVDS; break; |
| 667 | case 1: type = OUTPUT_TMDS; break; |
| 668 | case 2: type = OUTPUT_TMDS; break; |
| 669 | case 5: type = OUTPUT_TMDS; break; |
| 670 | case 8: type = OUTPUT_DP; break; |
| 671 | case 9: type = OUTPUT_DP; break; |
| 672 | default: |
| 673 | NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc); |
| 674 | goto ack; |
| 675 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 676 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 677 | or = i; |
| 678 | } |
| 679 | |
| 680 | if (type == OUTPUT_ANY) |
| 681 | goto ack; |
| 682 | |
| 683 | /* Enable the encoder */ |
| 684 | for (i = 0; i < dev_priv->vbios.dcb.entries; i++) { |
| 685 | dcb = &dev_priv->vbios.dcb.entry[i]; |
| 686 | if (dcb->type == type && (dcb->or & (1 << or))) |
| 687 | break; |
| 688 | } |
| 689 | |
| 690 | if (i == dev_priv->vbios.dcb.entries) { |
| 691 | NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc); |
| 692 | goto ack; |
| 693 | } |
| 694 | |
| 695 | script = nv50_display_script_select(dev, dcb, mc, pclk); |
| 696 | nouveau_bios_run_display_table(dev, dcb, script, pclk); |
| 697 | |
| 698 | nv50_display_unk20_dp_hack(dev, dcb); |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 699 | |
| 700 | if (dcb->type != OUTPUT_ANALOG) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 701 | tmp = nv_rd32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or)); |
| 702 | tmp &= ~0x00000f0f; |
| 703 | if (script & 0x0100) |
| 704 | tmp |= 0x00000101; |
| 705 | nv_wr32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or), tmp); |
| 706 | } else { |
| 707 | nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL2(or), 0); |
| 708 | } |
| 709 | |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 710 | disp->irq.dcb = dcb; |
| 711 | disp->irq.pclk = pclk; |
| 712 | disp->irq.script = script; |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 713 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 714 | ack: |
| 715 | nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK20); |
| 716 | nv_wr32(dev, 0x610030, 0x80000000); |
| 717 | } |
| 718 | |
Ben Skeggs | 271f29e | 2010-07-09 10:37:42 +1000 | [diff] [blame] | 719 | /* If programming a TMDS output on a SOR that can also be configured for |
| 720 | * DisplayPort, make sure NV50_SOR_DP_CTRL_ENABLE is forced off. |
| 721 | * |
| 722 | * It looks like the VBIOS TMDS scripts make an attempt at this, however, |
| 723 | * the VBIOS scripts on at least one board I have only switch it off on |
| 724 | * link 0, causing a blank display if the output has previously been |
| 725 | * programmed for DisplayPort. |
| 726 | */ |
| 727 | static void |
| 728 | nv50_display_unk40_dp_set_tmds(struct drm_device *dev, struct dcb_entry *dcb) |
| 729 | { |
| 730 | int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1); |
| 731 | struct drm_encoder *encoder; |
| 732 | u32 tmp; |
| 733 | |
| 734 | if (dcb->type != OUTPUT_TMDS) |
| 735 | return; |
| 736 | |
| 737 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 738 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 739 | |
| 740 | if (nv_encoder->dcb->type == OUTPUT_DP && |
| 741 | nv_encoder->dcb->or & (1 << or)) { |
| 742 | tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link)); |
| 743 | tmp &= ~NV50_SOR_DP_CTRL_ENABLED; |
| 744 | nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp); |
| 745 | break; |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 750 | static void |
| 751 | nv50_display_unk40_handler(struct drm_device *dev) |
| 752 | { |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 753 | struct nv50_display *disp = nv50_display(dev); |
| 754 | struct dcb_entry *dcb = disp->irq.dcb; |
| 755 | u16 script = disp->irq.script; |
| 756 | u32 unk30 = nv_rd32(dev, 0x610030), pclk = disp->irq.pclk; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 757 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 758 | NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30); |
Ben Skeggs | ef8389a | 2011-02-01 10:07:32 +1000 | [diff] [blame^] | 759 | disp->irq.dcb = NULL; |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 760 | if (!dcb) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 761 | goto ack; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 762 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 763 | nouveau_bios_run_display_table(dev, dcb, script, -pclk); |
Ben Skeggs | 271f29e | 2010-07-09 10:37:42 +1000 | [diff] [blame] | 764 | nv50_display_unk40_dp_set_tmds(dev, dcb); |
| 765 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 766 | ack: |
| 767 | nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK40); |
| 768 | nv_wr32(dev, 0x610030, 0x80000000); |
| 769 | nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) | 8); |
| 770 | } |
| 771 | |
| 772 | void |
| 773 | nv50_display_irq_handler_bh(struct work_struct *work) |
| 774 | { |
| 775 | struct drm_nouveau_private *dev_priv = |
| 776 | container_of(work, struct drm_nouveau_private, irq_work); |
| 777 | struct drm_device *dev = dev_priv->dev; |
| 778 | |
| 779 | for (;;) { |
| 780 | uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0); |
| 781 | uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1); |
| 782 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 783 | NV_DEBUG_KMS(dev, "PDISPLAY_INTR_BH 0x%08x 0x%08x\n", intr0, intr1); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 784 | |
| 785 | if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK10) |
| 786 | nv50_display_unk10_handler(dev); |
| 787 | else |
| 788 | if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK20) |
| 789 | nv50_display_unk20_handler(dev); |
| 790 | else |
| 791 | if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK40) |
| 792 | nv50_display_unk40_handler(dev); |
| 793 | else |
| 794 | break; |
| 795 | } |
| 796 | |
| 797 | nv_wr32(dev, NV03_PMC_INTR_EN_0, 1); |
| 798 | } |
| 799 | |
| 800 | static void |
| 801 | nv50_display_error_handler(struct drm_device *dev) |
| 802 | { |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 803 | u32 channels = (nv_rd32(dev, NV50_PDISPLAY_INTR_0) & 0x001f0000) >> 16; |
| 804 | u32 addr, data; |
| 805 | int chid; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 806 | |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 807 | for (chid = 0; chid < 5; chid++) { |
| 808 | if (!(channels & (1 << chid))) |
| 809 | continue; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 810 | |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 811 | nv_wr32(dev, NV50_PDISPLAY_INTR_0, 0x00010000 << chid); |
| 812 | addr = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid)); |
| 813 | data = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_DATA(chid)); |
| 814 | NV_ERROR(dev, "EvoCh %d Mthd 0x%04x Data 0x%08x " |
| 815 | "(0x%04x 0x%02x)\n", chid, |
| 816 | addr & 0xffc, data, addr >> 16, (addr >> 12) & 0xf); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 817 | |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 818 | nv_wr32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid), 0x90000000); |
| 819 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 820 | } |
| 821 | |
Ben Skeggs | 19b7fc7 | 2010-11-03 10:27:27 +1000 | [diff] [blame] | 822 | static void |
| 823 | nv50_display_isr(struct drm_device *dev) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 824 | { |
| 825 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 826 | uint32_t delayed = 0; |
| 827 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 828 | while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_DISPLAY) { |
| 829 | uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0); |
| 830 | uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1); |
| 831 | uint32_t clock; |
| 832 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 833 | NV_DEBUG_KMS(dev, "PDISPLAY_INTR 0x%08x 0x%08x\n", intr0, intr1); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 834 | |
| 835 | if (!intr0 && !(intr1 & ~delayed)) |
| 836 | break; |
| 837 | |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 838 | if (intr0 & 0x001f0000) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 839 | nv50_display_error_handler(dev); |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 840 | intr0 &= ~0x001f0000; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | if (intr1 & NV50_PDISPLAY_INTR_1_VBLANK_CRTC) { |
| 844 | nv50_display_vblank_handler(dev, intr1); |
| 845 | intr1 &= ~NV50_PDISPLAY_INTR_1_VBLANK_CRTC; |
| 846 | } |
| 847 | |
| 848 | clock = (intr1 & (NV50_PDISPLAY_INTR_1_CLK_UNK10 | |
| 849 | NV50_PDISPLAY_INTR_1_CLK_UNK20 | |
| 850 | NV50_PDISPLAY_INTR_1_CLK_UNK40)); |
| 851 | if (clock) { |
| 852 | nv_wr32(dev, NV03_PMC_INTR_EN_0, 0); |
| 853 | if (!work_pending(&dev_priv->irq_work)) |
Tejun Heo | d82f8e6 | 2011-01-26 17:49:18 +0100 | [diff] [blame] | 854 | schedule_work(&dev_priv->irq_work); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 855 | delayed |= clock; |
| 856 | intr1 &= ~clock; |
| 857 | } |
| 858 | |
| 859 | if (intr0) { |
| 860 | NV_ERROR(dev, "unknown PDISPLAY_INTR_0: 0x%08x\n", intr0); |
| 861 | nv_wr32(dev, NV50_PDISPLAY_INTR_0, intr0); |
| 862 | } |
| 863 | |
| 864 | if (intr1) { |
| 865 | NV_ERROR(dev, |
| 866 | "unknown PDISPLAY_INTR_1: 0x%08x\n", intr1); |
| 867 | nv_wr32(dev, NV50_PDISPLAY_INTR_1, intr1); |
| 868 | } |
| 869 | } |
| 870 | } |