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 | b7bc613 | 2010-10-19 13:05:51 +1000 | [diff] [blame] | 175 | evo = dev_priv->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; |
| 204 | struct drm_crtc *drm_crtc; |
| 205 | int ret, i; |
| 206 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 207 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 208 | |
| 209 | list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) { |
| 210 | struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc); |
| 211 | |
| 212 | nv50_crtc_blank(crtc, true); |
| 213 | } |
| 214 | |
| 215 | ret = RING_SPACE(dev_priv->evo, 2); |
| 216 | if (ret == 0) { |
| 217 | BEGIN_RING(dev_priv->evo, 0, NV50_EVO_UPDATE, 1); |
| 218 | OUT_RING(dev_priv->evo, 0); |
| 219 | } |
| 220 | FIRE_RING(dev_priv->evo); |
| 221 | |
| 222 | /* Almost like ack'ing a vblank interrupt, maybe in the spirit of |
| 223 | * cleaning up? |
| 224 | */ |
| 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); |
| 228 | |
| 229 | if (!crtc->base.enabled) |
| 230 | continue; |
| 231 | |
| 232 | nv_wr32(dev, NV50_PDISPLAY_INTR_1, mask); |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 233 | if (!nv_wait(dev, NV50_PDISPLAY_INTR_1, mask, mask)) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 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)); |
| 238 | } |
| 239 | } |
| 240 | |
Ben Skeggs | b7bc613 | 2010-10-19 13:05:51 +1000 | [diff] [blame] | 241 | nv50_evo_fini(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 242 | |
| 243 | for (i = 0; i < 3; i++) { |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 244 | if (!nv_wait(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i), |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 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))); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | /* disable interrupts. */ |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 253 | nv_wr32(dev, NV50_PDISPLAY_INTR_EN_1, 0x00000000); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 254 | |
| 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); |
| 261 | } |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | int nv50_display_create(struct drm_device *dev) |
| 266 | { |
| 267 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 04a39c5 | 2010-02-24 10:03:05 +1000 | [diff] [blame] | 268 | struct dcb_table *dcb = &dev_priv->vbios.dcb; |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 269 | struct drm_connector *connector, *ct; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 270 | int ret, i; |
| 271 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 272 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 273 | |
| 274 | /* init basic kernel modesetting */ |
| 275 | drm_mode_config_init(dev); |
| 276 | |
| 277 | /* Initialise some optional connector properties. */ |
| 278 | drm_mode_create_scaling_mode_property(dev); |
| 279 | drm_mode_create_dithering_property(dev); |
| 280 | |
| 281 | dev->mode_config.min_width = 0; |
| 282 | dev->mode_config.min_height = 0; |
| 283 | |
| 284 | dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs; |
| 285 | |
| 286 | dev->mode_config.max_width = 8192; |
| 287 | dev->mode_config.max_height = 8192; |
| 288 | |
| 289 | dev->mode_config.fb_base = dev_priv->fb_phys; |
| 290 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 291 | /* Create CRTC objects */ |
| 292 | for (i = 0; i < 2; i++) |
| 293 | nv50_crtc_create(dev, i); |
| 294 | |
| 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]; |
| 298 | |
| 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); |
| 302 | continue; |
| 303 | } |
| 304 | |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 305 | connector = nouveau_connector_create(dev, entry->connector); |
| 306 | if (IS_ERR(connector)) |
| 307 | continue; |
| 308 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 309 | switch (entry->type) { |
| 310 | case OUTPUT_TMDS: |
| 311 | case OUTPUT_LVDS: |
| 312 | case OUTPUT_DP: |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 313 | nv50_sor_create(connector, entry); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 314 | break; |
| 315 | case OUTPUT_ANALOG: |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 316 | nv50_dac_create(connector, entry); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 317 | break; |
| 318 | default: |
| 319 | NV_WARN(dev, "DCB encoder %d unknown\n", entry->type); |
| 320 | continue; |
| 321 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 322 | } |
| 323 | |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 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); |
| 330 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 331 | } |
| 332 | |
Ben Skeggs | 19b7fc7 | 2010-11-03 10:27:27 +1000 | [diff] [blame^] | 333 | INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh); |
| 334 | nouveau_irq_register(dev, 26, nv50_display_isr); |
| 335 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 336 | ret = nv50_display_init(dev); |
Ben Skeggs | a1663ed | 2010-03-25 16:01:04 +1000 | [diff] [blame] | 337 | if (ret) { |
| 338 | nv50_display_destroy(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 339 | return ret; |
Ben Skeggs | a1663ed | 2010-03-25 16:01:04 +1000 | [diff] [blame] | 340 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 345 | void |
| 346 | nv50_display_destroy(struct drm_device *dev) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 347 | { |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 348 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 349 | |
| 350 | drm_mode_config_cleanup(dev); |
| 351 | |
| 352 | nv50_display_disable(dev); |
Ben Skeggs | 19b7fc7 | 2010-11-03 10:27:27 +1000 | [diff] [blame^] | 353 | nouveau_irq_unregister(dev, 26); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 354 | } |
| 355 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 356 | static u16 |
| 357 | nv50_display_script_select(struct drm_device *dev, struct dcb_entry *dcb, |
| 358 | u32 mc, int pxclk) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 359 | { |
| 360 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 75c722d | 2009-12-21 12:16:52 +1000 | [diff] [blame] | 361 | struct nouveau_connector *nv_connector = NULL; |
| 362 | struct drm_encoder *encoder; |
Ben Skeggs | 04a39c5 | 2010-02-24 10:03:05 +1000 | [diff] [blame] | 363 | struct nvbios *bios = &dev_priv->vbios; |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 364 | u32 script = 0, or; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 365 | |
Ben Skeggs | 75c722d | 2009-12-21 12:16:52 +1000 | [diff] [blame] | 366 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 367 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 368 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 369 | if (nv_encoder->dcb != dcb) |
Ben Skeggs | 75c722d | 2009-12-21 12:16:52 +1000 | [diff] [blame] | 370 | continue; |
| 371 | |
| 372 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 373 | break; |
| 374 | } |
| 375 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 376 | or = ffs(dcb->or) - 1; |
| 377 | switch (dcb->type) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 378 | case OUTPUT_LVDS: |
| 379 | script = (mc >> 8) & 0xf; |
Ben Skeggs | 04a39c5 | 2010-02-24 10:03:05 +1000 | [diff] [blame] | 380 | if (bios->fp_no_ddc) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 381 | if (bios->fp.dual_link) |
| 382 | script |= 0x0100; |
| 383 | if (bios->fp.if_is_24bit) |
| 384 | script |= 0x0200; |
| 385 | } else { |
| 386 | if (pxclk >= bios->fp.duallink_transition_clk) { |
| 387 | script |= 0x0100; |
| 388 | if (bios->fp.strapless_is_24bit & 2) |
| 389 | script |= 0x0200; |
| 390 | } else |
| 391 | if (bios->fp.strapless_is_24bit & 1) |
| 392 | script |= 0x0200; |
Ben Skeggs | 75c722d | 2009-12-21 12:16:52 +1000 | [diff] [blame] | 393 | |
| 394 | if (nv_connector && nv_connector->edid && |
| 395 | (nv_connector->edid->revision >= 4) && |
| 396 | (nv_connector->edid->input & 0x70) >= 0x20) |
| 397 | script |= 0x0200; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | if (nouveau_uscript_lvds >= 0) { |
| 401 | NV_INFO(dev, "override script 0x%04x with 0x%04x " |
| 402 | "for output LVDS-%d\n", script, |
| 403 | nouveau_uscript_lvds, or); |
| 404 | script = nouveau_uscript_lvds; |
| 405 | } |
| 406 | break; |
| 407 | case OUTPUT_TMDS: |
| 408 | script = (mc >> 8) & 0xf; |
| 409 | if (pxclk >= 165000) |
| 410 | script |= 0x0100; |
| 411 | |
| 412 | if (nouveau_uscript_tmds >= 0) { |
| 413 | NV_INFO(dev, "override script 0x%04x with 0x%04x " |
| 414 | "for output TMDS-%d\n", script, |
| 415 | nouveau_uscript_tmds, or); |
| 416 | script = nouveau_uscript_tmds; |
| 417 | } |
| 418 | break; |
| 419 | case OUTPUT_DP: |
| 420 | script = (mc >> 8) & 0xf; |
| 421 | break; |
| 422 | case OUTPUT_ANALOG: |
| 423 | script = 0xff; |
| 424 | break; |
| 425 | default: |
| 426 | NV_ERROR(dev, "modeset on unsupported output type!\n"); |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | return script; |
| 431 | } |
| 432 | |
| 433 | static void |
| 434 | nv50_display_vblank_crtc_handler(struct drm_device *dev, int crtc) |
| 435 | { |
| 436 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 437 | struct nouveau_channel *chan, *tmp; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 438 | |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 439 | list_for_each_entry_safe(chan, tmp, &dev_priv->vbl_waiting, |
| 440 | nvsw.vbl_wait) { |
Francisco Jerez | 1f6d2de | 2010-10-24 14:15:58 +0200 | [diff] [blame] | 441 | if (chan->nvsw.vblsem_head != crtc) |
| 442 | continue; |
| 443 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 444 | nouveau_bo_wr32(chan->notifier_bo, chan->nvsw.vblsem_offset, |
| 445 | chan->nvsw.vblsem_rval); |
| 446 | list_del(&chan->nvsw.vbl_wait); |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 447 | drm_vblank_put(dev, crtc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 448 | } |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 449 | |
| 450 | drm_handle_vblank(dev, crtc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | static void |
| 454 | nv50_display_vblank_handler(struct drm_device *dev, uint32_t intr) |
| 455 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 456 | if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_0) |
| 457 | nv50_display_vblank_crtc_handler(dev, 0); |
| 458 | |
| 459 | if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_1) |
| 460 | nv50_display_vblank_crtc_handler(dev, 1); |
| 461 | |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 462 | 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] | 463 | } |
| 464 | |
| 465 | static void |
| 466 | nv50_display_unk10_handler(struct drm_device *dev) |
| 467 | { |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 468 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 469 | u32 unk30 = nv_rd32(dev, 0x610030), mc; |
| 470 | int i, crtc, or, type = OUTPUT_ANY; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 471 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 472 | NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30); |
| 473 | dev_priv->evo_irq.dcb = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 474 | |
| 475 | nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) & ~8); |
| 476 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 477 | /* Determine which CRTC we're dealing with, only 1 ever will be |
| 478 | * signalled at the same time with the current nouveau code. |
| 479 | */ |
| 480 | crtc = ffs((unk30 & 0x00000060) >> 5) - 1; |
| 481 | if (crtc < 0) |
| 482 | goto ack; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 483 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 484 | /* Nothing needs to be done for the encoder */ |
| 485 | crtc = ffs((unk30 & 0x00000180) >> 7) - 1; |
| 486 | if (crtc < 0) |
| 487 | goto ack; |
| 488 | |
| 489 | /* Find which encoder was connected to the CRTC */ |
| 490 | for (i = 0; type == OUTPUT_ANY && i < 3; i++) { |
| 491 | mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_C(i)); |
| 492 | NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc); |
| 493 | if (!(mc & (1 << crtc))) |
| 494 | continue; |
| 495 | |
| 496 | switch ((mc & 0x00000f00) >> 8) { |
| 497 | case 0: type = OUTPUT_ANALOG; break; |
| 498 | case 1: type = OUTPUT_TV; break; |
| 499 | default: |
| 500 | NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc); |
| 501 | goto ack; |
| 502 | } |
| 503 | |
| 504 | or = i; |
| 505 | } |
| 506 | |
Ben Skeggs | 8597a1b | 2010-09-06 11:39:25 +1000 | [diff] [blame] | 507 | for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) { |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 508 | if (dev_priv->chipset < 0x90 || |
| 509 | dev_priv->chipset == 0x92 || |
| 510 | dev_priv->chipset == 0xa0) |
| 511 | mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_C(i)); |
| 512 | else |
| 513 | mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_C(i)); |
| 514 | |
| 515 | NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc); |
| 516 | if (!(mc & (1 << crtc))) |
| 517 | continue; |
| 518 | |
| 519 | switch ((mc & 0x00000f00) >> 8) { |
| 520 | case 0: type = OUTPUT_LVDS; break; |
| 521 | case 1: type = OUTPUT_TMDS; break; |
| 522 | case 2: type = OUTPUT_TMDS; break; |
| 523 | case 5: type = OUTPUT_TMDS; break; |
| 524 | case 8: type = OUTPUT_DP; break; |
| 525 | case 9: type = OUTPUT_DP; break; |
| 526 | default: |
| 527 | NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc); |
| 528 | goto ack; |
| 529 | } |
| 530 | |
| 531 | or = i; |
| 532 | } |
| 533 | |
| 534 | /* There was no encoder to disable */ |
| 535 | if (type == OUTPUT_ANY) |
| 536 | goto ack; |
| 537 | |
| 538 | /* Disable the encoder */ |
| 539 | for (i = 0; i < dev_priv->vbios.dcb.entries; i++) { |
| 540 | struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i]; |
| 541 | |
| 542 | if (dcb->type == type && (dcb->or & (1 << or))) { |
| 543 | nouveau_bios_run_display_table(dev, dcb, 0, -1); |
| 544 | dev_priv->evo_irq.dcb = dcb; |
| 545 | goto ack; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | 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] | 550 | ack: |
| 551 | nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK10); |
| 552 | nv_wr32(dev, 0x610030, 0x80000000); |
| 553 | } |
| 554 | |
| 555 | static void |
Ben Skeggs | afa3b4c | 2010-04-23 08:21:48 +1000 | [diff] [blame] | 556 | nv50_display_unk20_dp_hack(struct drm_device *dev, struct dcb_entry *dcb) |
| 557 | { |
| 558 | int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1); |
| 559 | struct drm_encoder *encoder; |
| 560 | uint32_t tmp, unk0 = 0, unk1 = 0; |
| 561 | |
| 562 | if (dcb->type != OUTPUT_DP) |
| 563 | return; |
| 564 | |
| 565 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 566 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 567 | |
| 568 | if (nv_encoder->dcb == dcb) { |
| 569 | unk0 = nv_encoder->dp.unk0; |
| 570 | unk1 = nv_encoder->dp.unk1; |
| 571 | break; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | if (unk0 || unk1) { |
| 576 | tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link)); |
| 577 | tmp &= 0xfffffe03; |
| 578 | nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp | unk0); |
| 579 | |
| 580 | tmp = nv_rd32(dev, NV50_SOR_DP_UNK128(or, link)); |
| 581 | tmp &= 0xfef080c0; |
| 582 | nv_wr32(dev, NV50_SOR_DP_UNK128(or, link), tmp | unk1); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | static void |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 587 | nv50_display_unk20_handler(struct drm_device *dev) |
| 588 | { |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 589 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 590 | u32 unk30 = nv_rd32(dev, 0x610030), tmp, pclk, script, mc; |
| 591 | struct dcb_entry *dcb; |
| 592 | int i, crtc, or, type = OUTPUT_ANY; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 593 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 594 | NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30); |
| 595 | dcb = dev_priv->evo_irq.dcb; |
| 596 | if (dcb) { |
| 597 | nouveau_bios_run_display_table(dev, dcb, 0, -2); |
| 598 | dev_priv->evo_irq.dcb = NULL; |
| 599 | } |
| 600 | |
| 601 | /* CRTC clock change requested? */ |
| 602 | crtc = ffs((unk30 & 0x00000600) >> 9) - 1; |
| 603 | if (crtc >= 0) { |
| 604 | pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK)); |
| 605 | pclk &= 0x003fffff; |
| 606 | |
| 607 | nv50_crtc_set_clock(dev, crtc, pclk); |
| 608 | |
| 609 | tmp = nv_rd32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc)); |
| 610 | tmp &= ~0x000000f; |
| 611 | nv_wr32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc), tmp); |
| 612 | } |
| 613 | |
| 614 | /* Nothing needs to be done for the encoder */ |
| 615 | crtc = ffs((unk30 & 0x00000180) >> 7) - 1; |
| 616 | if (crtc < 0) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 617 | goto ack; |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 618 | pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK)) & 0x003fffff; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 619 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 620 | /* Find which encoder is connected to the CRTC */ |
| 621 | for (i = 0; type == OUTPUT_ANY && i < 3; i++) { |
| 622 | mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_P(i)); |
| 623 | NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc); |
| 624 | if (!(mc & (1 << crtc))) |
| 625 | continue; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 626 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 627 | switch ((mc & 0x00000f00) >> 8) { |
| 628 | case 0: type = OUTPUT_ANALOG; break; |
| 629 | case 1: type = OUTPUT_TV; break; |
| 630 | default: |
| 631 | NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc); |
| 632 | goto ack; |
| 633 | } |
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 | or = i; |
| 636 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 637 | |
Ben Skeggs | 8597a1b | 2010-09-06 11:39:25 +1000 | [diff] [blame] | 638 | for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) { |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 639 | if (dev_priv->chipset < 0x90 || |
| 640 | dev_priv->chipset == 0x92 || |
| 641 | dev_priv->chipset == 0xa0) |
| 642 | mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_P(i)); |
| 643 | else |
| 644 | mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_P(i)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 645 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 646 | NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc); |
| 647 | if (!(mc & (1 << crtc))) |
| 648 | continue; |
Ben Skeggs | afa3b4c | 2010-04-23 08:21:48 +1000 | [diff] [blame] | 649 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 650 | switch ((mc & 0x00000f00) >> 8) { |
| 651 | case 0: type = OUTPUT_LVDS; break; |
| 652 | case 1: type = OUTPUT_TMDS; break; |
| 653 | case 2: type = OUTPUT_TMDS; break; |
| 654 | case 5: type = OUTPUT_TMDS; break; |
| 655 | case 8: type = OUTPUT_DP; break; |
| 656 | case 9: type = OUTPUT_DP; break; |
| 657 | default: |
| 658 | NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc); |
| 659 | goto ack; |
| 660 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 661 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 662 | or = i; |
| 663 | } |
| 664 | |
| 665 | if (type == OUTPUT_ANY) |
| 666 | goto ack; |
| 667 | |
| 668 | /* Enable the encoder */ |
| 669 | for (i = 0; i < dev_priv->vbios.dcb.entries; i++) { |
| 670 | dcb = &dev_priv->vbios.dcb.entry[i]; |
| 671 | if (dcb->type == type && (dcb->or & (1 << or))) |
| 672 | break; |
| 673 | } |
| 674 | |
| 675 | if (i == dev_priv->vbios.dcb.entries) { |
| 676 | NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc); |
| 677 | goto ack; |
| 678 | } |
| 679 | |
| 680 | script = nv50_display_script_select(dev, dcb, mc, pclk); |
| 681 | nouveau_bios_run_display_table(dev, dcb, script, pclk); |
| 682 | |
| 683 | nv50_display_unk20_dp_hack(dev, dcb); |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 684 | |
| 685 | if (dcb->type != OUTPUT_ANALOG) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 686 | tmp = nv_rd32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or)); |
| 687 | tmp &= ~0x00000f0f; |
| 688 | if (script & 0x0100) |
| 689 | tmp |= 0x00000101; |
| 690 | nv_wr32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or), tmp); |
| 691 | } else { |
| 692 | nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL2(or), 0); |
| 693 | } |
| 694 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 695 | dev_priv->evo_irq.dcb = dcb; |
| 696 | dev_priv->evo_irq.pclk = pclk; |
| 697 | dev_priv->evo_irq.script = script; |
| 698 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 699 | ack: |
| 700 | nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK20); |
| 701 | nv_wr32(dev, 0x610030, 0x80000000); |
| 702 | } |
| 703 | |
Ben Skeggs | 271f29e | 2010-07-09 10:37:42 +1000 | [diff] [blame] | 704 | /* If programming a TMDS output on a SOR that can also be configured for |
| 705 | * DisplayPort, make sure NV50_SOR_DP_CTRL_ENABLE is forced off. |
| 706 | * |
| 707 | * It looks like the VBIOS TMDS scripts make an attempt at this, however, |
| 708 | * the VBIOS scripts on at least one board I have only switch it off on |
| 709 | * link 0, causing a blank display if the output has previously been |
| 710 | * programmed for DisplayPort. |
| 711 | */ |
| 712 | static void |
| 713 | nv50_display_unk40_dp_set_tmds(struct drm_device *dev, struct dcb_entry *dcb) |
| 714 | { |
| 715 | int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1); |
| 716 | struct drm_encoder *encoder; |
| 717 | u32 tmp; |
| 718 | |
| 719 | if (dcb->type != OUTPUT_TMDS) |
| 720 | return; |
| 721 | |
| 722 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 723 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 724 | |
| 725 | if (nv_encoder->dcb->type == OUTPUT_DP && |
| 726 | nv_encoder->dcb->or & (1 << or)) { |
| 727 | tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link)); |
| 728 | tmp &= ~NV50_SOR_DP_CTRL_ENABLED; |
| 729 | nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp); |
| 730 | break; |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 735 | static void |
| 736 | nv50_display_unk40_handler(struct drm_device *dev) |
| 737 | { |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 738 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 739 | struct dcb_entry *dcb = dev_priv->evo_irq.dcb; |
| 740 | u16 script = dev_priv->evo_irq.script; |
| 741 | u32 unk30 = nv_rd32(dev, 0x610030), pclk = dev_priv->evo_irq.pclk; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 742 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 743 | NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30); |
| 744 | dev_priv->evo_irq.dcb = NULL; |
| 745 | if (!dcb) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 746 | goto ack; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 747 | |
Ben Skeggs | 87c0e0e | 2010-07-06 08:54:34 +1000 | [diff] [blame] | 748 | nouveau_bios_run_display_table(dev, dcb, script, -pclk); |
Ben Skeggs | 271f29e | 2010-07-09 10:37:42 +1000 | [diff] [blame] | 749 | nv50_display_unk40_dp_set_tmds(dev, dcb); |
| 750 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 751 | ack: |
| 752 | nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK40); |
| 753 | nv_wr32(dev, 0x610030, 0x80000000); |
| 754 | nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) | 8); |
| 755 | } |
| 756 | |
| 757 | void |
| 758 | nv50_display_irq_handler_bh(struct work_struct *work) |
| 759 | { |
| 760 | struct drm_nouveau_private *dev_priv = |
| 761 | container_of(work, struct drm_nouveau_private, irq_work); |
| 762 | struct drm_device *dev = dev_priv->dev; |
| 763 | |
| 764 | for (;;) { |
| 765 | uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0); |
| 766 | uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1); |
| 767 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 768 | 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] | 769 | |
| 770 | if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK10) |
| 771 | nv50_display_unk10_handler(dev); |
| 772 | else |
| 773 | if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK20) |
| 774 | nv50_display_unk20_handler(dev); |
| 775 | else |
| 776 | if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK40) |
| 777 | nv50_display_unk40_handler(dev); |
| 778 | else |
| 779 | break; |
| 780 | } |
| 781 | |
| 782 | nv_wr32(dev, NV03_PMC_INTR_EN_0, 1); |
| 783 | } |
| 784 | |
| 785 | static void |
| 786 | nv50_display_error_handler(struct drm_device *dev) |
| 787 | { |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 788 | u32 channels = (nv_rd32(dev, NV50_PDISPLAY_INTR_0) & 0x001f0000) >> 16; |
| 789 | u32 addr, data; |
| 790 | int chid; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 791 | |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 792 | for (chid = 0; chid < 5; chid++) { |
| 793 | if (!(channels & (1 << chid))) |
| 794 | continue; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 795 | |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 796 | nv_wr32(dev, NV50_PDISPLAY_INTR_0, 0x00010000 << chid); |
| 797 | addr = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid)); |
| 798 | data = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_DATA(chid)); |
| 799 | NV_ERROR(dev, "EvoCh %d Mthd 0x%04x Data 0x%08x " |
| 800 | "(0x%04x 0x%02x)\n", chid, |
| 801 | addr & 0xffc, data, addr >> 16, (addr >> 12) & 0xf); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 802 | |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 803 | nv_wr32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid), 0x90000000); |
| 804 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 805 | } |
| 806 | |
Ben Skeggs | a5acac6 | 2010-03-30 15:14:41 +1000 | [diff] [blame] | 807 | void |
| 808 | nv50_display_irq_hotplug_bh(struct work_struct *work) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 809 | { |
Ben Skeggs | a5acac6 | 2010-03-30 15:14:41 +1000 | [diff] [blame] | 810 | struct drm_nouveau_private *dev_priv = |
| 811 | container_of(work, struct drm_nouveau_private, hpd_work); |
| 812 | struct drm_device *dev = dev_priv->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 813 | struct drm_connector *connector; |
| 814 | const uint32_t gpio_reg[4] = { 0xe104, 0xe108, 0xe280, 0xe284 }; |
| 815 | uint32_t unplug_mask, plug_mask, change_mask; |
Andy Lutomirski | ab83833 | 2010-11-16 18:40:52 -0500 | [diff] [blame] | 816 | uint32_t hpd0, hpd1; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 817 | |
Andy Lutomirski | ab83833 | 2010-11-16 18:40:52 -0500 | [diff] [blame] | 818 | spin_lock_irq(&dev_priv->hpd_state.lock); |
| 819 | hpd0 = dev_priv->hpd_state.hpd0_bits; |
| 820 | dev_priv->hpd_state.hpd0_bits = 0; |
| 821 | hpd1 = dev_priv->hpd_state.hpd1_bits; |
| 822 | dev_priv->hpd_state.hpd1_bits = 0; |
| 823 | spin_unlock_irq(&dev_priv->hpd_state.lock); |
| 824 | |
| 825 | hpd0 &= nv_rd32(dev, 0xe050); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 826 | if (dev_priv->chipset >= 0x90) |
Andy Lutomirski | ab83833 | 2010-11-16 18:40:52 -0500 | [diff] [blame] | 827 | hpd1 &= nv_rd32(dev, 0xe070); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 828 | |
| 829 | plug_mask = (hpd0 & 0x0000ffff) | (hpd1 << 16); |
| 830 | unplug_mask = (hpd0 >> 16) | (hpd1 & 0xffff0000); |
| 831 | change_mask = plug_mask | unplug_mask; |
| 832 | |
| 833 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 834 | struct drm_encoder_helper_funcs *helper; |
| 835 | struct nouveau_connector *nv_connector = |
| 836 | nouveau_connector(connector); |
| 837 | struct nouveau_encoder *nv_encoder; |
| 838 | struct dcb_gpio_entry *gpio; |
| 839 | uint32_t reg; |
| 840 | bool plugged; |
| 841 | |
| 842 | if (!nv_connector->dcb) |
| 843 | continue; |
| 844 | |
| 845 | gpio = nouveau_bios_gpio_entry(dev, nv_connector->dcb->gpio_tag); |
| 846 | if (!gpio || !(change_mask & (1 << gpio->line))) |
| 847 | continue; |
| 848 | |
| 849 | reg = nv_rd32(dev, gpio_reg[gpio->line >> 3]); |
| 850 | plugged = !!(reg & (4 << ((gpio->line & 7) << 2))); |
| 851 | NV_INFO(dev, "%splugged %s\n", plugged ? "" : "un", |
| 852 | drm_get_connector_name(connector)) ; |
| 853 | |
| 854 | if (!connector->encoder || !connector->encoder->crtc || |
| 855 | !connector->encoder->crtc->enabled) |
| 856 | continue; |
| 857 | nv_encoder = nouveau_encoder(connector->encoder); |
| 858 | helper = connector->encoder->helper_private; |
| 859 | |
| 860 | if (nv_encoder->dcb->type != OUTPUT_DP) |
| 861 | continue; |
| 862 | |
| 863 | if (plugged) |
| 864 | helper->dpms(connector->encoder, DRM_MODE_DPMS_ON); |
| 865 | else |
| 866 | helper->dpms(connector->encoder, DRM_MODE_DPMS_OFF); |
| 867 | } |
| 868 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 869 | drm_helper_hpd_irq_event(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 870 | } |
| 871 | |
Ben Skeggs | 19b7fc7 | 2010-11-03 10:27:27 +1000 | [diff] [blame^] | 872 | static void |
| 873 | nv50_display_isr(struct drm_device *dev) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 874 | { |
| 875 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 876 | uint32_t delayed = 0; |
| 877 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 878 | while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_DISPLAY) { |
| 879 | uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0); |
| 880 | uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1); |
| 881 | uint32_t clock; |
| 882 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 883 | 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] | 884 | |
| 885 | if (!intr0 && !(intr1 & ~delayed)) |
| 886 | break; |
| 887 | |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 888 | if (intr0 & 0x001f0000) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 889 | nv50_display_error_handler(dev); |
Ben Skeggs | 97e2000 | 2010-10-20 14:23:29 +1000 | [diff] [blame] | 890 | intr0 &= ~0x001f0000; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | if (intr1 & NV50_PDISPLAY_INTR_1_VBLANK_CRTC) { |
| 894 | nv50_display_vblank_handler(dev, intr1); |
| 895 | intr1 &= ~NV50_PDISPLAY_INTR_1_VBLANK_CRTC; |
| 896 | } |
| 897 | |
| 898 | clock = (intr1 & (NV50_PDISPLAY_INTR_1_CLK_UNK10 | |
| 899 | NV50_PDISPLAY_INTR_1_CLK_UNK20 | |
| 900 | NV50_PDISPLAY_INTR_1_CLK_UNK40)); |
| 901 | if (clock) { |
| 902 | nv_wr32(dev, NV03_PMC_INTR_EN_0, 0); |
| 903 | if (!work_pending(&dev_priv->irq_work)) |
| 904 | queue_work(dev_priv->wq, &dev_priv->irq_work); |
| 905 | delayed |= clock; |
| 906 | intr1 &= ~clock; |
| 907 | } |
| 908 | |
| 909 | if (intr0) { |
| 910 | NV_ERROR(dev, "unknown PDISPLAY_INTR_0: 0x%08x\n", intr0); |
| 911 | nv_wr32(dev, NV50_PDISPLAY_INTR_0, intr0); |
| 912 | } |
| 913 | |
| 914 | if (intr1) { |
| 915 | NV_ERROR(dev, |
| 916 | "unknown PDISPLAY_INTR_1: 0x%08x\n", intr1); |
| 917 | nv_wr32(dev, NV50_PDISPLAY_INTR_1, intr1); |
| 918 | } |
| 919 | } |
| 920 | } |
| 921 | |