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 "drmP.h" |
| 28 | #include "drm_mode.h" |
| 29 | #include "drm_crtc_helper.h" |
| 30 | |
| 31 | #define NOUVEAU_DMA_DEBUG (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO) |
| 32 | #include "nouveau_reg.h" |
| 33 | #include "nouveau_drv.h" |
| 34 | #include "nouveau_hw.h" |
| 35 | #include "nouveau_encoder.h" |
| 36 | #include "nouveau_crtc.h" |
| 37 | #include "nouveau_fb.h" |
| 38 | #include "nouveau_connector.h" |
| 39 | #include "nv50_display.h" |
| 40 | |
Ben Skeggs | 549cd87 | 2011-10-06 11:51:45 +1000 | [diff] [blame] | 41 | static int |
| 42 | nv50_crtc_wait_complete(struct drm_crtc *crtc) |
| 43 | { |
| 44 | struct drm_device *dev = crtc->dev; |
| 45 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 46 | struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer; |
| 47 | struct nv50_display *disp = nv50_display(dev); |
| 48 | struct nouveau_channel *evo = disp->master; |
| 49 | u64 start; |
| 50 | int ret; |
| 51 | |
| 52 | ret = RING_SPACE(evo, 6); |
| 53 | if (ret) |
| 54 | return ret; |
| 55 | BEGIN_RING(evo, 0, 0x0084, 1); |
| 56 | OUT_RING (evo, 0x80000000); |
| 57 | BEGIN_RING(evo, 0, 0x0080, 1); |
| 58 | OUT_RING (evo, 0); |
| 59 | BEGIN_RING(evo, 0, 0x0084, 1); |
| 60 | OUT_RING (evo, 0x00000000); |
| 61 | |
| 62 | nv_wo32(disp->ntfy, 0x000, 0x00000000); |
| 63 | FIRE_RING (evo); |
| 64 | |
| 65 | start = ptimer->read(dev); |
| 66 | do { |
| 67 | if (nv_ro32(disp->ntfy, 0x000)) |
| 68 | return 0; |
| 69 | } while (ptimer->read(dev) - start < 2000000000ULL); |
| 70 | |
| 71 | return -EBUSY; |
| 72 | } |
| 73 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 74 | static void |
| 75 | nv50_crtc_lut_load(struct drm_crtc *crtc) |
| 76 | { |
| 77 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 78 | void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo); |
| 79 | int i; |
| 80 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 81 | NV_DEBUG_KMS(crtc->dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 82 | |
| 83 | for (i = 0; i < 256; i++) { |
| 84 | writew(nv_crtc->lut.r[i] >> 2, lut + 8*i + 0); |
| 85 | writew(nv_crtc->lut.g[i] >> 2, lut + 8*i + 2); |
| 86 | writew(nv_crtc->lut.b[i] >> 2, lut + 8*i + 4); |
| 87 | } |
| 88 | |
| 89 | if (nv_crtc->lut.depth == 30) { |
| 90 | writew(nv_crtc->lut.r[i - 1] >> 2, lut + 8*i + 0); |
| 91 | writew(nv_crtc->lut.g[i - 1] >> 2, lut + 8*i + 2); |
| 92 | writew(nv_crtc->lut.b[i - 1] >> 2, lut + 8*i + 4); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | int |
| 97 | nv50_crtc_blank(struct nouveau_crtc *nv_crtc, bool blanked) |
| 98 | { |
| 99 | struct drm_device *dev = nv_crtc->base.dev; |
| 100 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 101 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 102 | int index = nv_crtc->index, ret; |
| 103 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 104 | NV_DEBUG_KMS(dev, "index %d\n", nv_crtc->index); |
| 105 | NV_DEBUG_KMS(dev, "%s\n", blanked ? "blanked" : "unblanked"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 106 | |
| 107 | if (blanked) { |
| 108 | nv_crtc->cursor.hide(nv_crtc, false); |
| 109 | |
| 110 | ret = RING_SPACE(evo, dev_priv->chipset != 0x50 ? 7 : 5); |
| 111 | if (ret) { |
| 112 | NV_ERROR(dev, "no space while blanking crtc\n"); |
| 113 | return ret; |
| 114 | } |
| 115 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(index, CLUT_MODE), 2); |
| 116 | OUT_RING(evo, NV50_EVO_CRTC_CLUT_MODE_BLANK); |
| 117 | OUT_RING(evo, 0); |
| 118 | if (dev_priv->chipset != 0x50) { |
| 119 | BEGIN_RING(evo, 0, NV84_EVO_CRTC(index, CLUT_DMA), 1); |
| 120 | OUT_RING(evo, NV84_EVO_CRTC_CLUT_DMA_HANDLE_NONE); |
| 121 | } |
| 122 | |
| 123 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(index, FB_DMA), 1); |
| 124 | OUT_RING(evo, NV50_EVO_CRTC_FB_DMA_HANDLE_NONE); |
| 125 | } else { |
| 126 | if (nv_crtc->cursor.visible) |
| 127 | nv_crtc->cursor.show(nv_crtc, false); |
| 128 | else |
| 129 | nv_crtc->cursor.hide(nv_crtc, false); |
| 130 | |
| 131 | ret = RING_SPACE(evo, dev_priv->chipset != 0x50 ? 10 : 8); |
| 132 | if (ret) { |
| 133 | NV_ERROR(dev, "no space while unblanking crtc\n"); |
| 134 | return ret; |
| 135 | } |
| 136 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(index, CLUT_MODE), 2); |
| 137 | OUT_RING(evo, nv_crtc->lut.depth == 8 ? |
| 138 | NV50_EVO_CRTC_CLUT_MODE_OFF : |
| 139 | NV50_EVO_CRTC_CLUT_MODE_ON); |
Ben Skeggs | 180cc30 | 2011-06-07 11:24:14 +1000 | [diff] [blame] | 140 | OUT_RING(evo, nv_crtc->lut.nvbo->bo.offset >> 8); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 141 | if (dev_priv->chipset != 0x50) { |
| 142 | BEGIN_RING(evo, 0, NV84_EVO_CRTC(index, CLUT_DMA), 1); |
| 143 | OUT_RING(evo, NvEvoVRAM); |
| 144 | } |
| 145 | |
| 146 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(index, FB_OFFSET), 2); |
| 147 | OUT_RING(evo, nv_crtc->fb.offset >> 8); |
| 148 | OUT_RING(evo, 0); |
| 149 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(index, FB_DMA), 1); |
| 150 | if (dev_priv->chipset != 0x50) |
Ben Skeggs | 6d86951 | 2010-12-08 11:19:30 +1000 | [diff] [blame] | 151 | if (nv_crtc->fb.tile_flags == 0x7a00 || |
| 152 | nv_crtc->fb.tile_flags == 0xfe00) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 153 | OUT_RING(evo, NvEvoFB32); |
| 154 | else |
| 155 | if (nv_crtc->fb.tile_flags == 0x7000) |
| 156 | OUT_RING(evo, NvEvoFB16); |
| 157 | else |
Ben Skeggs | 6d86951 | 2010-12-08 11:19:30 +1000 | [diff] [blame] | 158 | OUT_RING(evo, NvEvoVRAM_LP); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 159 | else |
Ben Skeggs | 6d86951 | 2010-12-08 11:19:30 +1000 | [diff] [blame] | 160 | OUT_RING(evo, NvEvoVRAM_LP); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | nv_crtc->fb.blanked = blanked; |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static int |
| 168 | nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool on, bool update) |
| 169 | { |
| 170 | struct drm_device *dev = nv_crtc->base.dev; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 171 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 172 | int ret; |
| 173 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 174 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 175 | |
| 176 | ret = RING_SPACE(evo, 2 + (update ? 2 : 0)); |
| 177 | if (ret) { |
| 178 | NV_ERROR(dev, "no space while setting dither\n"); |
| 179 | return ret; |
| 180 | } |
| 181 | |
| 182 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, DITHER_CTRL), 1); |
| 183 | if (on) |
| 184 | OUT_RING(evo, NV50_EVO_CRTC_DITHER_CTRL_ON); |
| 185 | else |
| 186 | OUT_RING(evo, NV50_EVO_CRTC_DITHER_CTRL_OFF); |
| 187 | |
| 188 | if (update) { |
| 189 | BEGIN_RING(evo, 0, NV50_EVO_UPDATE, 1); |
| 190 | OUT_RING(evo, 0); |
| 191 | FIRE_RING(evo); |
| 192 | } |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | struct nouveau_connector * |
| 198 | nouveau_crtc_connector_get(struct nouveau_crtc *nv_crtc) |
| 199 | { |
| 200 | struct drm_device *dev = nv_crtc->base.dev; |
| 201 | struct drm_connector *connector; |
| 202 | struct drm_crtc *crtc = to_drm_crtc(nv_crtc); |
| 203 | |
| 204 | /* The safest approach is to find an encoder with the right crtc, that |
| 205 | * is also linked to a connector. */ |
| 206 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 207 | if (connector->encoder) |
| 208 | if (connector->encoder->crtc == crtc) |
| 209 | return nouveau_connector(connector); |
| 210 | } |
| 211 | |
| 212 | return NULL; |
| 213 | } |
| 214 | |
| 215 | static int |
| 216 | nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, int scaling_mode, bool update) |
| 217 | { |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 218 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 549cd87 | 2011-10-06 11:51:45 +1000 | [diff] [blame] | 219 | struct drm_crtc *crtc = &nv_crtc->base; |
| 220 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 221 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Ben Skeggs | 549cd87 | 2011-10-06 11:51:45 +1000 | [diff] [blame] | 222 | struct drm_display_mode *mode = &crtc->mode; |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 223 | u32 ctrl = 0, oX, oY; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 224 | int ret; |
| 225 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 226 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 227 | |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 228 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
| 229 | if (!nv_connector || !nv_connector->native_mode) { |
| 230 | NV_ERROR(dev, "no native mode, forcing panel scaling\n"); |
| 231 | scaling_mode = DRM_MODE_SCALE_NONE; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 232 | } |
| 233 | |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 234 | /* start off at the resolution we programmed the crtc for, this |
| 235 | * effectively handles NONE/FULL scaling |
| 236 | */ |
| 237 | if (scaling_mode != DRM_MODE_SCALE_NONE) { |
| 238 | oX = nv_connector->native_mode->hdisplay; |
| 239 | oY = nv_connector->native_mode->vdisplay; |
| 240 | } else { |
| 241 | oX = mode->hdisplay; |
| 242 | oY = mode->vdisplay; |
| 243 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 244 | |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 245 | /* add overscan compensation if necessary, will keep the aspect |
| 246 | * ratio the same as the backend mode unless overridden by the |
| 247 | * user setting both hborder and vborder properties. |
| 248 | */ |
| 249 | if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON || |
| 250 | (nv_connector->underscan == UNDERSCAN_AUTO && |
| 251 | nv_connector->edid && |
| 252 | drm_detect_hdmi_monitor(nv_connector->edid)))) { |
| 253 | u32 bX = nv_connector->underscan_hborder; |
| 254 | u32 bY = nv_connector->underscan_vborder; |
| 255 | u32 aspect = (oY << 19) / oX; |
| 256 | |
| 257 | if (bX) { |
| 258 | oX -= (bX * 2); |
| 259 | if (bY) oY -= (bY * 2); |
| 260 | else oY = ((oX * aspect) + (aspect / 2)) >> 19; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 261 | } else { |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 262 | oX -= (oX >> 4) + 32; |
| 263 | if (bY) oY -= (bY * 2); |
| 264 | else oY = ((oX * aspect) + (aspect / 2)) >> 19; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 265 | } |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /* handle CENTER/ASPECT scaling, taking into account the areas |
| 269 | * removed already for overscan compensation |
| 270 | */ |
| 271 | switch (scaling_mode) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 272 | case DRM_MODE_SCALE_CENTER: |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 273 | oX = min((u32)mode->hdisplay, oX); |
| 274 | oY = min((u32)mode->vdisplay, oY); |
| 275 | /* fall-through */ |
| 276 | case DRM_MODE_SCALE_ASPECT: |
| 277 | if (oY < oX) { |
| 278 | u32 aspect = (mode->hdisplay << 19) / mode->vdisplay; |
| 279 | oX = ((oY * aspect) + (aspect / 2)) >> 19; |
| 280 | } else { |
| 281 | u32 aspect = (mode->vdisplay << 19) / mode->hdisplay; |
| 282 | oY = ((oX * aspect) + (aspect / 2)) >> 19; |
| 283 | } |
| 284 | break; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 285 | default: |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 286 | break; |
| 287 | } |
| 288 | |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 289 | if (mode->hdisplay != oX || mode->vdisplay != oY || |
| 290 | mode->flags & DRM_MODE_FLAG_INTERLACE || |
| 291 | mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 292 | ctrl |= NV50_EVO_CRTC_SCALE_CTRL_ACTIVE; |
| 293 | |
Ben Skeggs | 549cd87 | 2011-10-06 11:51:45 +1000 | [diff] [blame] | 294 | ret = RING_SPACE(evo, 5); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 295 | if (ret) |
| 296 | return ret; |
| 297 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 298 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, SCALE_CTRL), 1); |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 299 | OUT_RING (evo, ctrl); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 300 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, SCALE_RES1), 2); |
Ben Skeggs | b29caa5 | 2011-10-06 13:29:05 +1000 | [diff] [blame] | 301 | OUT_RING (evo, oY << 16 | oX); |
| 302 | OUT_RING (evo, oY << 16 | oX); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 303 | |
| 304 | if (update) { |
Ben Skeggs | 549cd87 | 2011-10-06 11:51:45 +1000 | [diff] [blame] | 305 | nv50_display_flip_stop(crtc); |
| 306 | nv50_crtc_wait_complete(crtc); |
| 307 | nv50_display_flip_next(crtc, crtc->fb, NULL); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | int |
| 314 | nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk) |
| 315 | { |
Ben Skeggs | 1ac7b52 | 2010-08-04 22:08:03 +1000 | [diff] [blame] | 316 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 317 | struct pll_lims pll; |
Ben Skeggs | 5b32165 | 2010-09-24 09:17:02 +1000 | [diff] [blame] | 318 | uint32_t reg1, reg2; |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 319 | int ret, N1, M1, N2, M2, P; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 320 | |
Ben Skeggs | 5b32165 | 2010-09-24 09:17:02 +1000 | [diff] [blame] | 321 | ret = get_pll_limits(dev, PLL_VPLL0 + head, &pll); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 322 | if (ret) |
| 323 | return ret; |
| 324 | |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 325 | if (pll.vco2.maxfreq) { |
| 326 | ret = nv50_calc_pll(dev, &pll, pclk, &N1, &M1, &N2, &M2, &P); |
| 327 | if (ret <= 0) |
| 328 | return 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 329 | |
Ben Skeggs | 17b96cc | 2010-04-23 03:53:42 +1000 | [diff] [blame] | 330 | NV_DEBUG(dev, "pclk %d out %d NM1 %d %d NM2 %d %d P %d\n", |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 331 | pclk, ret, N1, M1, N2, M2, P); |
Ben Skeggs | 17b96cc | 2010-04-23 03:53:42 +1000 | [diff] [blame] | 332 | |
Ben Skeggs | 5b32165 | 2010-09-24 09:17:02 +1000 | [diff] [blame] | 333 | reg1 = nv_rd32(dev, pll.reg + 4) & 0xff00ff00; |
| 334 | reg2 = nv_rd32(dev, pll.reg + 8) & 0x8000ff00; |
| 335 | nv_wr32(dev, pll.reg + 0, 0x10000611); |
| 336 | nv_wr32(dev, pll.reg + 4, reg1 | (M1 << 16) | N1); |
| 337 | nv_wr32(dev, pll.reg + 8, reg2 | (P << 28) | (M2 << 16) | N2); |
Ben Skeggs | 1ac7b52 | 2010-08-04 22:08:03 +1000 | [diff] [blame] | 338 | } else |
| 339 | if (dev_priv->chipset < NV_C0) { |
Ben Skeggs | 52eba8d | 2011-04-28 02:34:21 +1000 | [diff] [blame] | 340 | ret = nva3_calc_pll(dev, &pll, pclk, &N1, &N2, &M1, &P); |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 341 | if (ret <= 0) |
| 342 | return 0; |
Ben Skeggs | 17b96cc | 2010-04-23 03:53:42 +1000 | [diff] [blame] | 343 | |
Ben Skeggs | e9ebb68 | 2010-04-28 14:07:06 +1000 | [diff] [blame] | 344 | NV_DEBUG(dev, "pclk %d out %d N %d fN 0x%04x M %d P %d\n", |
| 345 | pclk, ret, N1, N2, M1, P); |
| 346 | |
Ben Skeggs | 5b32165 | 2010-09-24 09:17:02 +1000 | [diff] [blame] | 347 | reg1 = nv_rd32(dev, pll.reg + 4) & 0xffc00000; |
| 348 | nv_wr32(dev, pll.reg + 0, 0x50000610); |
| 349 | nv_wr32(dev, pll.reg + 4, reg1 | (P << 16) | (M1 << 8) | N1); |
| 350 | nv_wr32(dev, pll.reg + 8, N2); |
Ben Skeggs | 1ac7b52 | 2010-08-04 22:08:03 +1000 | [diff] [blame] | 351 | } else { |
Ben Skeggs | 52eba8d | 2011-04-28 02:34:21 +1000 | [diff] [blame] | 352 | ret = nva3_calc_pll(dev, &pll, pclk, &N1, &N2, &M1, &P); |
Ben Skeggs | 1ac7b52 | 2010-08-04 22:08:03 +1000 | [diff] [blame] | 353 | if (ret <= 0) |
| 354 | return 0; |
| 355 | |
| 356 | NV_DEBUG(dev, "pclk %d out %d N %d fN 0x%04x M %d P %d\n", |
| 357 | pclk, ret, N1, N2, M1, P); |
| 358 | |
Ben Skeggs | 5b32165 | 2010-09-24 09:17:02 +1000 | [diff] [blame] | 359 | nv_mask(dev, pll.reg + 0x0c, 0x00000000, 0x00000100); |
| 360 | nv_wr32(dev, pll.reg + 0x04, (P << 16) | (N1 << 8) | M1); |
| 361 | nv_wr32(dev, pll.reg + 0x10, N2 << 16); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static void |
| 368 | nv50_crtc_destroy(struct drm_crtc *crtc) |
| 369 | { |
Marcin Slusarz | dd19e44 | 2010-01-30 15:41:00 +0100 | [diff] [blame] | 370 | struct drm_device *dev; |
| 371 | struct nouveau_crtc *nv_crtc; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 372 | |
| 373 | if (!crtc) |
| 374 | return; |
| 375 | |
Marcin Slusarz | dd19e44 | 2010-01-30 15:41:00 +0100 | [diff] [blame] | 376 | dev = crtc->dev; |
| 377 | nv_crtc = nouveau_crtc(crtc); |
| 378 | |
| 379 | NV_DEBUG_KMS(dev, "\n"); |
| 380 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 381 | drm_crtc_cleanup(&nv_crtc->base); |
| 382 | |
Ben Skeggs | 9d59e8a | 2010-08-27 13:04:41 +1000 | [diff] [blame] | 383 | nouveau_bo_unmap(nv_crtc->lut.nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 384 | nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo); |
Ben Skeggs | 9d59e8a | 2010-08-27 13:04:41 +1000 | [diff] [blame] | 385 | nouveau_bo_unmap(nv_crtc->cursor.nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 386 | nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo); |
| 387 | kfree(nv_crtc->mode); |
| 388 | kfree(nv_crtc); |
| 389 | } |
| 390 | |
| 391 | int |
| 392 | nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, |
| 393 | uint32_t buffer_handle, uint32_t width, uint32_t height) |
| 394 | { |
| 395 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 396 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 397 | struct nouveau_bo *cursor = NULL; |
| 398 | struct drm_gem_object *gem; |
| 399 | int ret = 0, i; |
| 400 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 401 | if (!buffer_handle) { |
| 402 | nv_crtc->cursor.hide(nv_crtc, true); |
| 403 | return 0; |
| 404 | } |
| 405 | |
Marcin Slusarz | b4fa9d0 | 2011-05-01 23:49:04 +0200 | [diff] [blame] | 406 | if (width != 64 || height != 64) |
| 407 | return -EINVAL; |
| 408 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 409 | gem = drm_gem_object_lookup(dev, file_priv, buffer_handle); |
| 410 | if (!gem) |
Chris Wilson | bf79cb9 | 2010-08-04 14:19:46 +0100 | [diff] [blame] | 411 | return -ENOENT; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 412 | cursor = nouveau_gem_object(gem); |
| 413 | |
| 414 | ret = nouveau_bo_map(cursor); |
| 415 | if (ret) |
| 416 | goto out; |
| 417 | |
| 418 | /* The simple will do for now. */ |
| 419 | for (i = 0; i < 64 * 64; i++) |
| 420 | nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, nouveau_bo_rd32(cursor, i)); |
| 421 | |
| 422 | nouveau_bo_unmap(cursor); |
| 423 | |
Ben Skeggs | 180cc30 | 2011-06-07 11:24:14 +1000 | [diff] [blame] | 424 | nv_crtc->cursor.set_offset(nv_crtc, nv_crtc->cursor.nvbo->bo.offset); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 425 | nv_crtc->cursor.show(nv_crtc, true); |
| 426 | |
| 427 | out: |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 428 | drm_gem_object_unreference_unlocked(gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 429 | return ret; |
| 430 | } |
| 431 | |
| 432 | int |
| 433 | nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
| 434 | { |
| 435 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 436 | |
| 437 | nv_crtc->cursor.set_pos(nv_crtc, x, y); |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | static void |
| 442 | nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 443 | uint32_t start, uint32_t size) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 444 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 445 | int end = (start + size > 256) ? 256 : start + size, i; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 446 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 447 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 448 | for (i = start; i < end; i++) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 449 | nv_crtc->lut.r[i] = r[i]; |
| 450 | nv_crtc->lut.g[i] = g[i]; |
| 451 | nv_crtc->lut.b[i] = b[i]; |
| 452 | } |
| 453 | |
| 454 | /* We need to know the depth before we upload, but it's possible to |
| 455 | * get called before a framebuffer is bound. If this is the case, |
| 456 | * mark the lut values as dirty by setting depth==0, and it'll be |
| 457 | * uploaded on the first mode_set_base() |
| 458 | */ |
| 459 | if (!nv_crtc->base.fb) { |
| 460 | nv_crtc->lut.depth = 0; |
| 461 | return; |
| 462 | } |
| 463 | |
| 464 | nv50_crtc_lut_load(crtc); |
| 465 | } |
| 466 | |
| 467 | static void |
| 468 | nv50_crtc_save(struct drm_crtc *crtc) |
| 469 | { |
| 470 | NV_ERROR(crtc->dev, "!!\n"); |
| 471 | } |
| 472 | |
| 473 | static void |
| 474 | nv50_crtc_restore(struct drm_crtc *crtc) |
| 475 | { |
| 476 | NV_ERROR(crtc->dev, "!!\n"); |
| 477 | } |
| 478 | |
| 479 | static const struct drm_crtc_funcs nv50_crtc_funcs = { |
| 480 | .save = nv50_crtc_save, |
| 481 | .restore = nv50_crtc_restore, |
| 482 | .cursor_set = nv50_crtc_cursor_set, |
| 483 | .cursor_move = nv50_crtc_cursor_move, |
| 484 | .gamma_set = nv50_crtc_gamma_set, |
| 485 | .set_config = drm_crtc_helper_set_config, |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 486 | .page_flip = nouveau_crtc_page_flip, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 487 | .destroy = nv50_crtc_destroy, |
| 488 | }; |
| 489 | |
| 490 | static void |
| 491 | nv50_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 492 | { |
| 493 | } |
| 494 | |
| 495 | static void |
| 496 | nv50_crtc_prepare(struct drm_crtc *crtc) |
| 497 | { |
| 498 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 499 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 500 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 501 | NV_DEBUG_KMS(dev, "index %d\n", nv_crtc->index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 502 | |
Ben Skeggs | 1d3fac0 | 2011-02-07 14:18:37 +1000 | [diff] [blame] | 503 | nv50_display_flip_stop(crtc); |
Francisco Jerez | 1c180fa | 2010-10-25 03:30:34 +0200 | [diff] [blame] | 504 | drm_vblank_pre_modeset(dev, nv_crtc->index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 505 | nv50_crtc_blank(nv_crtc, true); |
| 506 | } |
| 507 | |
| 508 | static void |
| 509 | nv50_crtc_commit(struct drm_crtc *crtc) |
| 510 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 511 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 512 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 513 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 514 | NV_DEBUG_KMS(dev, "index %d\n", nv_crtc->index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 515 | |
| 516 | nv50_crtc_blank(nv_crtc, false); |
Francisco Jerez | 1c180fa | 2010-10-25 03:30:34 +0200 | [diff] [blame] | 517 | drm_vblank_post_modeset(dev, nv_crtc->index); |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 518 | nv50_crtc_wait_complete(crtc); |
Ben Skeggs | 1d3fac0 | 2011-02-07 14:18:37 +1000 | [diff] [blame] | 519 | nv50_display_flip_next(crtc, crtc->fb, NULL); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static bool |
| 523 | nv50_crtc_mode_fixup(struct drm_crtc *crtc, struct drm_display_mode *mode, |
| 524 | struct drm_display_mode *adjusted_mode) |
| 525 | { |
| 526 | return true; |
| 527 | } |
| 528 | |
| 529 | static int |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 530 | nv50_crtc_do_mode_set_base(struct drm_crtc *crtc, |
| 531 | struct drm_framebuffer *passed_fb, |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 532 | int x, int y, bool atomic) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 533 | { |
| 534 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 535 | struct drm_device *dev = nv_crtc->base.dev; |
| 536 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 537 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Emil Velikov | ffbc559 | 2011-08-21 22:48:12 +0100 | [diff] [blame] | 538 | struct drm_framebuffer *drm_fb; |
| 539 | struct nouveau_framebuffer *fb; |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 540 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 541 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 542 | NV_DEBUG_KMS(dev, "index %d\n", nv_crtc->index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 543 | |
Emil Velikov | ffbc559 | 2011-08-21 22:48:12 +0100 | [diff] [blame] | 544 | /* no fb bound */ |
| 545 | if (!atomic && !crtc->fb) { |
| 546 | NV_DEBUG_KMS(dev, "No FB bound\n"); |
| 547 | return 0; |
| 548 | } |
| 549 | |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 550 | /* If atomic, we want to switch to the fb we were passed, so |
| 551 | * now we update pointers to do that. (We don't pin; just |
| 552 | * assume we're already pinned and update the base address.) |
| 553 | */ |
| 554 | if (atomic) { |
| 555 | drm_fb = passed_fb; |
| 556 | fb = nouveau_framebuffer(passed_fb); |
Emil Velikov | f9ec8f6 | 2011-03-19 23:31:53 +0000 | [diff] [blame] | 557 | } else { |
Emil Velikov | ffbc559 | 2011-08-21 22:48:12 +0100 | [diff] [blame] | 558 | drm_fb = crtc->fb; |
| 559 | fb = nouveau_framebuffer(crtc->fb); |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 560 | /* If not atomic, we can go ahead and pin, and unpin the |
| 561 | * old fb we were passed. |
| 562 | */ |
| 563 | ret = nouveau_bo_pin(fb->nvbo, TTM_PL_FLAG_VRAM); |
| 564 | if (ret) |
| 565 | return ret; |
| 566 | |
| 567 | if (passed_fb) { |
| 568 | struct nouveau_framebuffer *ofb = nouveau_framebuffer(passed_fb); |
| 569 | nouveau_bo_unpin(ofb->nvbo); |
| 570 | } |
| 571 | } |
| 572 | |
Ben Skeggs | 180cc30 | 2011-06-07 11:24:14 +1000 | [diff] [blame] | 573 | nv_crtc->fb.offset = fb->nvbo->bo.offset; |
Francisco Jerez | f13b326 | 2010-10-10 06:01:08 +0200 | [diff] [blame] | 574 | nv_crtc->fb.tile_flags = nouveau_bo_tile_layout(fb->nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 575 | nv_crtc->fb.cpp = drm_fb->bits_per_pixel / 8; |
| 576 | if (!nv_crtc->fb.blanked && dev_priv->chipset != 0x50) { |
| 577 | ret = RING_SPACE(evo, 2); |
| 578 | if (ret) |
| 579 | return ret; |
| 580 | |
| 581 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, FB_DMA), 1); |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 582 | OUT_RING (evo, fb->r_dma); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | ret = RING_SPACE(evo, 12); |
| 586 | if (ret) |
| 587 | return ret; |
| 588 | |
| 589 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, FB_OFFSET), 5); |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 590 | OUT_RING (evo, nv_crtc->fb.offset >> 8); |
| 591 | OUT_RING (evo, 0); |
| 592 | OUT_RING (evo, (drm_fb->height << 16) | drm_fb->width); |
| 593 | OUT_RING (evo, fb->r_pitch); |
| 594 | OUT_RING (evo, fb->r_format); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 595 | |
| 596 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CLUT_MODE), 1); |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 597 | OUT_RING (evo, fb->base.depth == 8 ? |
| 598 | NV50_EVO_CRTC_CLUT_MODE_OFF : NV50_EVO_CRTC_CLUT_MODE_ON); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 599 | |
| 600 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, COLOR_CTRL), 1); |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 601 | OUT_RING (evo, NV50_EVO_CRTC_COLOR_CTRL_COLOR); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 602 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, FB_POS), 1); |
Ben Skeggs | 45c4e0a | 2011-02-09 11:57:45 +1000 | [diff] [blame] | 603 | OUT_RING (evo, (y << 16) | x); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 604 | |
| 605 | if (nv_crtc->lut.depth != fb->base.depth) { |
| 606 | nv_crtc->lut.depth = fb->base.depth; |
| 607 | nv50_crtc_lut_load(crtc); |
| 608 | } |
| 609 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | static int |
| 614 | nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode, |
| 615 | struct drm_display_mode *adjusted_mode, int x, int y, |
| 616 | struct drm_framebuffer *old_fb) |
| 617 | { |
| 618 | struct drm_device *dev = crtc->dev; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 619 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 620 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 621 | struct nouveau_connector *nv_connector = NULL; |
| 622 | uint32_t hsync_dur, vsync_dur, hsync_start_to_end, vsync_start_to_end; |
| 623 | uint32_t hunk1, vunk1, vunk2a, vunk2b; |
| 624 | int ret; |
| 625 | |
| 626 | /* Find the connector attached to this CRTC */ |
| 627 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
| 628 | |
| 629 | *nv_crtc->mode = *adjusted_mode; |
| 630 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 631 | NV_DEBUG_KMS(dev, "index %d\n", nv_crtc->index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 632 | |
| 633 | hsync_dur = adjusted_mode->hsync_end - adjusted_mode->hsync_start; |
| 634 | vsync_dur = adjusted_mode->vsync_end - adjusted_mode->vsync_start; |
| 635 | hsync_start_to_end = adjusted_mode->htotal - adjusted_mode->hsync_start; |
| 636 | vsync_start_to_end = adjusted_mode->vtotal - adjusted_mode->vsync_start; |
| 637 | /* I can't give this a proper name, anyone else can? */ |
| 638 | hunk1 = adjusted_mode->htotal - |
| 639 | adjusted_mode->hsync_start + adjusted_mode->hdisplay; |
| 640 | vunk1 = adjusted_mode->vtotal - |
| 641 | adjusted_mode->vsync_start + adjusted_mode->vdisplay; |
| 642 | /* Another strange value, this time only for interlaced adjusted_modes. */ |
| 643 | vunk2a = 2 * adjusted_mode->vtotal - |
| 644 | adjusted_mode->vsync_start + adjusted_mode->vdisplay; |
| 645 | vunk2b = adjusted_mode->vtotal - |
| 646 | adjusted_mode->vsync_start + adjusted_mode->vtotal; |
| 647 | |
| 648 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 649 | vsync_dur /= 2; |
| 650 | vsync_start_to_end /= 2; |
| 651 | vunk1 /= 2; |
| 652 | vunk2a /= 2; |
| 653 | vunk2b /= 2; |
| 654 | /* magic */ |
| 655 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN) { |
| 656 | vsync_start_to_end -= 1; |
| 657 | vunk1 -= 1; |
| 658 | vunk2a -= 1; |
| 659 | vunk2b -= 1; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | ret = RING_SPACE(evo, 17); |
| 664 | if (ret) |
| 665 | return ret; |
| 666 | |
| 667 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CLOCK), 2); |
| 668 | OUT_RING(evo, adjusted_mode->clock | 0x800000); |
| 669 | OUT_RING(evo, (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 0); |
| 670 | |
| 671 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, DISPLAY_START), 5); |
| 672 | OUT_RING(evo, 0); |
| 673 | OUT_RING(evo, (adjusted_mode->vtotal << 16) | adjusted_mode->htotal); |
| 674 | OUT_RING(evo, (vsync_dur - 1) << 16 | (hsync_dur - 1)); |
| 675 | OUT_RING(evo, (vsync_start_to_end - 1) << 16 | |
| 676 | (hsync_start_to_end - 1)); |
| 677 | OUT_RING(evo, (vunk1 - 1) << 16 | (hunk1 - 1)); |
| 678 | |
| 679 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 680 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, UNK0824), 1); |
| 681 | OUT_RING(evo, (vunk2b - 1) << 16 | (vunk2a - 1)); |
| 682 | } else { |
| 683 | OUT_RING(evo, 0); |
| 684 | OUT_RING(evo, 0); |
| 685 | } |
| 686 | |
| 687 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, UNK082C), 1); |
| 688 | OUT_RING(evo, 0); |
| 689 | |
| 690 | /* This is the actual resolution of the mode. */ |
| 691 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, REAL_RES), 1); |
| 692 | OUT_RING(evo, (mode->vdisplay << 16) | mode->hdisplay); |
| 693 | BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, SCALE_CENTER_OFFSET), 1); |
| 694 | OUT_RING(evo, NV50_EVO_CRTC_SCALE_CENTER_OFFSET_VAL(0, 0)); |
| 695 | |
| 696 | nv_crtc->set_dither(nv_crtc, nv_connector->use_dithering, false); |
| 697 | nv_crtc->set_scale(nv_crtc, nv_connector->scaling_mode, false); |
| 698 | |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 699 | return nv50_crtc_do_mode_set_base(crtc, old_fb, x, y, false); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | static int |
| 703 | nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
| 704 | struct drm_framebuffer *old_fb) |
| 705 | { |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 706 | int ret; |
| 707 | |
Ben Skeggs | 1d3fac0 | 2011-02-07 14:18:37 +1000 | [diff] [blame] | 708 | nv50_display_flip_stop(crtc); |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 709 | ret = nv50_crtc_do_mode_set_base(crtc, old_fb, x, y, false); |
| 710 | if (ret) |
| 711 | return ret; |
| 712 | |
Ben Skeggs | 1d3fac0 | 2011-02-07 14:18:37 +1000 | [diff] [blame] | 713 | ret = nv50_crtc_wait_complete(crtc); |
| 714 | if (ret) |
| 715 | return ret; |
| 716 | |
| 717 | return nv50_display_flip_next(crtc, crtc->fb, NULL); |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | static int |
| 721 | nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc, |
| 722 | struct drm_framebuffer *fb, |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 723 | int x, int y, enum mode_set_atomic state) |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 724 | { |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 725 | int ret; |
| 726 | |
Ben Skeggs | 1d3fac0 | 2011-02-07 14:18:37 +1000 | [diff] [blame] | 727 | nv50_display_flip_stop(crtc); |
Ben Skeggs | 60f60bf | 2011-02-03 15:46:14 +1000 | [diff] [blame] | 728 | ret = nv50_crtc_do_mode_set_base(crtc, fb, x, y, true); |
| 729 | if (ret) |
| 730 | return ret; |
| 731 | |
| 732 | return nv50_crtc_wait_complete(crtc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | static const struct drm_crtc_helper_funcs nv50_crtc_helper_funcs = { |
| 736 | .dpms = nv50_crtc_dpms, |
| 737 | .prepare = nv50_crtc_prepare, |
| 738 | .commit = nv50_crtc_commit, |
| 739 | .mode_fixup = nv50_crtc_mode_fixup, |
| 740 | .mode_set = nv50_crtc_mode_set, |
| 741 | .mode_set_base = nv50_crtc_mode_set_base, |
Chris Ball | be64c2bb | 2010-09-26 06:47:24 -0500 | [diff] [blame] | 742 | .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 743 | .load_lut = nv50_crtc_lut_load, |
| 744 | }; |
| 745 | |
| 746 | int |
| 747 | nv50_crtc_create(struct drm_device *dev, int index) |
| 748 | { |
| 749 | struct nouveau_crtc *nv_crtc = NULL; |
| 750 | int ret, i; |
| 751 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 752 | NV_DEBUG_KMS(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 753 | |
| 754 | nv_crtc = kzalloc(sizeof(*nv_crtc), GFP_KERNEL); |
| 755 | if (!nv_crtc) |
| 756 | return -ENOMEM; |
| 757 | |
| 758 | nv_crtc->mode = kzalloc(sizeof(*nv_crtc->mode), GFP_KERNEL); |
| 759 | if (!nv_crtc->mode) { |
| 760 | kfree(nv_crtc); |
| 761 | return -ENOMEM; |
| 762 | } |
| 763 | |
| 764 | /* Default CLUT parameters, will be activated on the hw upon |
| 765 | * first mode set. |
| 766 | */ |
| 767 | for (i = 0; i < 256; i++) { |
| 768 | nv_crtc->lut.r[i] = i << 8; |
| 769 | nv_crtc->lut.g[i] = i << 8; |
| 770 | nv_crtc->lut.b[i] = i << 8; |
| 771 | } |
| 772 | nv_crtc->lut.depth = 0; |
| 773 | |
Ben Skeggs | 7375c95 | 2011-06-07 14:21:29 +1000 | [diff] [blame] | 774 | ret = nouveau_bo_new(dev, 4096, 0x100, TTM_PL_FLAG_VRAM, |
Ben Skeggs | d550c41 | 2011-02-16 08:41:56 +1000 | [diff] [blame] | 775 | 0, 0x0000, &nv_crtc->lut.nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 776 | if (!ret) { |
| 777 | ret = nouveau_bo_pin(nv_crtc->lut.nvbo, TTM_PL_FLAG_VRAM); |
| 778 | if (!ret) |
| 779 | ret = nouveau_bo_map(nv_crtc->lut.nvbo); |
| 780 | if (ret) |
| 781 | nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo); |
| 782 | } |
| 783 | |
| 784 | if (ret) { |
| 785 | kfree(nv_crtc->mode); |
| 786 | kfree(nv_crtc); |
| 787 | return ret; |
| 788 | } |
| 789 | |
| 790 | nv_crtc->index = index; |
| 791 | |
| 792 | /* set function pointers */ |
| 793 | nv_crtc->set_dither = nv50_crtc_set_dither; |
| 794 | nv_crtc->set_scale = nv50_crtc_set_scale; |
| 795 | |
| 796 | drm_crtc_init(dev, &nv_crtc->base, &nv50_crtc_funcs); |
| 797 | drm_crtc_helper_add(&nv_crtc->base, &nv50_crtc_helper_funcs); |
| 798 | drm_mode_crtc_set_gamma_size(&nv_crtc->base, 256); |
| 799 | |
Ben Skeggs | 7375c95 | 2011-06-07 14:21:29 +1000 | [diff] [blame] | 800 | ret = nouveau_bo_new(dev, 64*64*4, 0x100, TTM_PL_FLAG_VRAM, |
Ben Skeggs | d550c41 | 2011-02-16 08:41:56 +1000 | [diff] [blame] | 801 | 0, 0x0000, &nv_crtc->cursor.nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 802 | if (!ret) { |
| 803 | ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM); |
| 804 | if (!ret) |
| 805 | ret = nouveau_bo_map(nv_crtc->cursor.nvbo); |
| 806 | if (ret) |
| 807 | nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo); |
| 808 | } |
| 809 | |
| 810 | nv50_cursor_init(nv_crtc); |
| 811 | return 0; |
| 812 | } |