Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 Red Hat Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | * Authors: Ben Skeggs |
| 23 | */ |
| 24 | |
| 25 | #include "drmP.h" |
| 26 | #include "nouveau_drv.h" |
Ben Skeggs | 02a841d | 2012-07-04 23:44:54 +1000 | [diff] [blame] | 27 | #include <nouveau_bios.h> |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 28 | #include "nouveau_hw.h" |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 29 | #include "nouveau_pm.h" |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 30 | #include "nouveau_hwsq.h" |
Ben Skeggs | e495d0d | 2012-01-23 13:22:58 +1000 | [diff] [blame] | 31 | #include "nv50_display.h" |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 32 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 33 | enum clk_src { |
| 34 | clk_src_crystal, |
| 35 | clk_src_href, |
| 36 | clk_src_hclk, |
| 37 | clk_src_hclkm3, |
| 38 | clk_src_hclkm3d2, |
| 39 | clk_src_host, |
| 40 | clk_src_nvclk, |
| 41 | clk_src_sclk, |
| 42 | clk_src_mclk, |
| 43 | clk_src_vdec, |
| 44 | clk_src_dom6 |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 45 | }; |
| 46 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 47 | static u32 read_clk(struct drm_device *, enum clk_src); |
| 48 | |
| 49 | static u32 |
| 50 | read_div(struct drm_device *dev) |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 51 | { |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 52 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 53 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 54 | switch (dev_priv->chipset) { |
| 55 | case 0x50: /* it exists, but only has bit 31, not the dividers.. */ |
| 56 | case 0x84: |
| 57 | case 0x86: |
| 58 | case 0x98: |
| 59 | case 0xa0: |
| 60 | return nv_rd32(dev, 0x004700); |
| 61 | case 0x92: |
| 62 | case 0x94: |
| 63 | case 0x96: |
| 64 | return nv_rd32(dev, 0x004800); |
| 65 | default: |
| 66 | return 0x00000000; |
| 67 | } |
| 68 | } |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 69 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 70 | static u32 |
Ben Skeggs | 463464e | 2011-10-30 23:10:55 +1000 | [diff] [blame] | 71 | read_pll_src(struct drm_device *dev, u32 base) |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 72 | { |
| 73 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 74 | u32 coef, ref = read_clk(dev, clk_src_crystal); |
| 75 | u32 rsel = nv_rd32(dev, 0x00e18c); |
| 76 | int P, N, M, id; |
Emil Velikov | 619d4f7 | 2011-04-11 20:43:23 +0100 | [diff] [blame] | 77 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 78 | switch (dev_priv->chipset) { |
| 79 | case 0x50: |
| 80 | case 0xa0: |
| 81 | switch (base) { |
| 82 | case 0x4020: |
| 83 | case 0x4028: id = !!(rsel & 0x00000004); break; |
| 84 | case 0x4008: id = !!(rsel & 0x00000008); break; |
| 85 | case 0x4030: id = 0; break; |
| 86 | default: |
| 87 | NV_ERROR(dev, "ref: bad pll 0x%06x\n", base); |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | coef = nv_rd32(dev, 0x00e81c + (id * 0x0c)); |
| 92 | ref *= (coef & 0x01000000) ? 2 : 4; |
| 93 | P = (coef & 0x00070000) >> 16; |
| 94 | N = ((coef & 0x0000ff00) >> 8) + 1; |
| 95 | M = ((coef & 0x000000ff) >> 0) + 1; |
| 96 | break; |
| 97 | case 0x84: |
| 98 | case 0x86: |
| 99 | case 0x92: |
| 100 | coef = nv_rd32(dev, 0x00e81c); |
| 101 | P = (coef & 0x00070000) >> 16; |
| 102 | N = (coef & 0x0000ff00) >> 8; |
| 103 | M = (coef & 0x000000ff) >> 0; |
| 104 | break; |
| 105 | case 0x94: |
| 106 | case 0x96: |
| 107 | case 0x98: |
| 108 | rsel = nv_rd32(dev, 0x00c050); |
| 109 | switch (base) { |
| 110 | case 0x4020: rsel = (rsel & 0x00000003) >> 0; break; |
| 111 | case 0x4008: rsel = (rsel & 0x0000000c) >> 2; break; |
| 112 | case 0x4028: rsel = (rsel & 0x00001800) >> 11; break; |
| 113 | case 0x4030: rsel = 3; break; |
| 114 | default: |
| 115 | NV_ERROR(dev, "ref: bad pll 0x%06x\n", base); |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | switch (rsel) { |
| 120 | case 0: id = 1; break; |
| 121 | case 1: return read_clk(dev, clk_src_crystal); |
| 122 | case 2: return read_clk(dev, clk_src_href); |
| 123 | case 3: id = 0; break; |
| 124 | } |
| 125 | |
| 126 | coef = nv_rd32(dev, 0x00e81c + (id * 0x28)); |
| 127 | P = (nv_rd32(dev, 0x00e824 + (id * 0x28)) >> 16) & 7; |
| 128 | P += (coef & 0x00070000) >> 16; |
| 129 | N = (coef & 0x0000ff00) >> 8; |
| 130 | M = (coef & 0x000000ff) >> 0; |
| 131 | break; |
| 132 | default: |
| 133 | BUG_ON(1); |
| 134 | } |
| 135 | |
| 136 | if (M) |
| 137 | return (ref * N / M) >> P; |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static u32 |
Ben Skeggs | 463464e | 2011-10-30 23:10:55 +1000 | [diff] [blame] | 142 | read_pll_ref(struct drm_device *dev, u32 base) |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 143 | { |
Ben Skeggs | 463464e | 2011-10-30 23:10:55 +1000 | [diff] [blame] | 144 | u32 src, mast = nv_rd32(dev, 0x00c040); |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 145 | |
| 146 | switch (base) { |
| 147 | case 0x004028: |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 148 | src = !!(mast & 0x00200000); |
| 149 | break; |
| 150 | case 0x004020: |
| 151 | src = !!(mast & 0x00400000); |
| 152 | break; |
| 153 | case 0x004008: |
| 154 | src = !!(mast & 0x00010000); |
| 155 | break; |
| 156 | case 0x004030: |
| 157 | src = !!(mast & 0x02000000); |
| 158 | break; |
| 159 | case 0x00e810: |
Ben Skeggs | 463464e | 2011-10-30 23:10:55 +1000 | [diff] [blame] | 160 | return read_clk(dev, clk_src_crystal); |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 161 | default: |
| 162 | NV_ERROR(dev, "bad pll 0x%06x\n", base); |
| 163 | return 0; |
| 164 | } |
| 165 | |
Ben Skeggs | 463464e | 2011-10-30 23:10:55 +1000 | [diff] [blame] | 166 | if (src) |
| 167 | return read_clk(dev, clk_src_href); |
| 168 | return read_pll_src(dev, base); |
| 169 | } |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 170 | |
Ben Skeggs | 463464e | 2011-10-30 23:10:55 +1000 | [diff] [blame] | 171 | static u32 |
| 172 | read_pll(struct drm_device *dev, u32 base) |
| 173 | { |
| 174 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 175 | u32 mast = nv_rd32(dev, 0x00c040); |
| 176 | u32 ctrl = nv_rd32(dev, base + 0); |
| 177 | u32 coef = nv_rd32(dev, base + 4); |
| 178 | u32 ref = read_pll_ref(dev, base); |
| 179 | u32 clk = 0; |
| 180 | int N1, N2, M1, M2; |
| 181 | |
| 182 | if (base == 0x004028 && (mast & 0x00100000)) { |
| 183 | /* wtf, appears to only disable post-divider on nva0 */ |
| 184 | if (dev_priv->chipset != 0xa0) |
| 185 | return read_clk(dev, clk_src_dom6); |
| 186 | } |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 187 | |
| 188 | N2 = (coef & 0xff000000) >> 24; |
| 189 | M2 = (coef & 0x00ff0000) >> 16; |
| 190 | N1 = (coef & 0x0000ff00) >> 8; |
| 191 | M1 = (coef & 0x000000ff); |
| 192 | if ((ctrl & 0x80000000) && M1) { |
| 193 | clk = ref * N1 / M1; |
| 194 | if ((ctrl & 0x40000100) == 0x40000000) { |
| 195 | if (M2) |
| 196 | clk = clk * N2 / M2; |
| 197 | else |
| 198 | clk = 0; |
Emil Velikov | 619d4f7 | 2011-04-11 20:43:23 +0100 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 202 | return clk; |
| 203 | } |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 204 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 205 | static u32 |
| 206 | read_clk(struct drm_device *dev, enum clk_src src) |
| 207 | { |
| 208 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 209 | u32 mast = nv_rd32(dev, 0x00c040); |
| 210 | u32 P = 0; |
| 211 | |
| 212 | switch (src) { |
| 213 | case clk_src_crystal: |
| 214 | return dev_priv->crystal; |
| 215 | case clk_src_href: |
| 216 | return 100000; /* PCIE reference clock */ |
| 217 | case clk_src_hclk: |
| 218 | return read_clk(dev, clk_src_href) * 27778 / 10000; |
| 219 | case clk_src_hclkm3: |
| 220 | return read_clk(dev, clk_src_hclk) * 3; |
| 221 | case clk_src_hclkm3d2: |
| 222 | return read_clk(dev, clk_src_hclk) * 3 / 2; |
| 223 | case clk_src_host: |
| 224 | switch (mast & 0x30000000) { |
| 225 | case 0x00000000: return read_clk(dev, clk_src_href); |
| 226 | case 0x10000000: break; |
| 227 | case 0x20000000: /* !0x50 */ |
| 228 | case 0x30000000: return read_clk(dev, clk_src_hclk); |
| 229 | } |
| 230 | break; |
| 231 | case clk_src_nvclk: |
| 232 | if (!(mast & 0x00100000)) |
| 233 | P = (nv_rd32(dev, 0x004028) & 0x00070000) >> 16; |
| 234 | switch (mast & 0x00000003) { |
| 235 | case 0x00000000: return read_clk(dev, clk_src_crystal) >> P; |
| 236 | case 0x00000001: return read_clk(dev, clk_src_dom6); |
| 237 | case 0x00000002: return read_pll(dev, 0x004020) >> P; |
| 238 | case 0x00000003: return read_pll(dev, 0x004028) >> P; |
| 239 | } |
| 240 | break; |
| 241 | case clk_src_sclk: |
| 242 | P = (nv_rd32(dev, 0x004020) & 0x00070000) >> 16; |
| 243 | switch (mast & 0x00000030) { |
| 244 | case 0x00000000: |
| 245 | if (mast & 0x00000080) |
| 246 | return read_clk(dev, clk_src_host) >> P; |
| 247 | return read_clk(dev, clk_src_crystal) >> P; |
| 248 | case 0x00000010: break; |
| 249 | case 0x00000020: return read_pll(dev, 0x004028) >> P; |
| 250 | case 0x00000030: return read_pll(dev, 0x004020) >> P; |
| 251 | } |
| 252 | break; |
| 253 | case clk_src_mclk: |
| 254 | P = (nv_rd32(dev, 0x004008) & 0x00070000) >> 16; |
| 255 | if (nv_rd32(dev, 0x004008) & 0x00000200) { |
| 256 | switch (mast & 0x0000c000) { |
| 257 | case 0x00000000: |
| 258 | return read_clk(dev, clk_src_crystal) >> P; |
| 259 | case 0x00008000: |
| 260 | case 0x0000c000: |
| 261 | return read_clk(dev, clk_src_href) >> P; |
| 262 | } |
| 263 | } else { |
| 264 | return read_pll(dev, 0x004008) >> P; |
| 265 | } |
| 266 | break; |
| 267 | case clk_src_vdec: |
| 268 | P = (read_div(dev) & 0x00000700) >> 8; |
| 269 | switch (dev_priv->chipset) { |
| 270 | case 0x84: |
| 271 | case 0x86: |
| 272 | case 0x92: |
| 273 | case 0x94: |
| 274 | case 0x96: |
| 275 | case 0xa0: |
| 276 | switch (mast & 0x00000c00) { |
| 277 | case 0x00000000: |
| 278 | if (dev_priv->chipset == 0xa0) /* wtf?? */ |
| 279 | return read_clk(dev, clk_src_nvclk) >> P; |
| 280 | return read_clk(dev, clk_src_crystal) >> P; |
| 281 | case 0x00000400: |
| 282 | return 0; |
| 283 | case 0x00000800: |
| 284 | if (mast & 0x01000000) |
| 285 | return read_pll(dev, 0x004028) >> P; |
| 286 | return read_pll(dev, 0x004030) >> P; |
| 287 | case 0x00000c00: |
| 288 | return read_clk(dev, clk_src_nvclk) >> P; |
| 289 | } |
| 290 | break; |
| 291 | case 0x98: |
| 292 | switch (mast & 0x00000c00) { |
| 293 | case 0x00000000: |
| 294 | return read_clk(dev, clk_src_nvclk) >> P; |
| 295 | case 0x00000400: |
| 296 | return 0; |
| 297 | case 0x00000800: |
| 298 | return read_clk(dev, clk_src_hclkm3d2) >> P; |
| 299 | case 0x00000c00: |
Martin Peres | d467646 | 2011-11-01 11:38:16 +0100 | [diff] [blame] | 300 | return read_clk(dev, clk_src_mclk) >> P; |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 301 | } |
| 302 | break; |
| 303 | } |
| 304 | break; |
| 305 | case clk_src_dom6: |
| 306 | switch (dev_priv->chipset) { |
| 307 | case 0x50: |
| 308 | case 0xa0: |
| 309 | return read_pll(dev, 0x00e810) >> 2; |
| 310 | case 0x84: |
| 311 | case 0x86: |
| 312 | case 0x92: |
| 313 | case 0x94: |
| 314 | case 0x96: |
| 315 | case 0x98: |
| 316 | P = (read_div(dev) & 0x00000007) >> 0; |
| 317 | switch (mast & 0x0c000000) { |
| 318 | case 0x00000000: return read_clk(dev, clk_src_href); |
| 319 | case 0x04000000: break; |
| 320 | case 0x08000000: return read_clk(dev, clk_src_hclk); |
| 321 | case 0x0c000000: |
| 322 | return read_clk(dev, clk_src_hclkm3) >> P; |
| 323 | } |
| 324 | break; |
| 325 | default: |
| 326 | break; |
| 327 | } |
| 328 | default: |
| 329 | break; |
| 330 | } |
| 331 | |
| 332 | NV_DEBUG(dev, "unknown clock source %d 0x%08x\n", src, mast); |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | int |
| 337 | nv50_pm_clocks_get(struct drm_device *dev, struct nouveau_pm_level *perflvl) |
| 338 | { |
| 339 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 340 | if (dev_priv->chipset == 0xaa || |
| 341 | dev_priv->chipset == 0xac) |
| 342 | return 0; |
| 343 | |
| 344 | perflvl->core = read_clk(dev, clk_src_nvclk); |
| 345 | perflvl->shader = read_clk(dev, clk_src_sclk); |
| 346 | perflvl->memory = read_clk(dev, clk_src_mclk); |
| 347 | if (dev_priv->chipset != 0x50) { |
| 348 | perflvl->vdec = read_clk(dev, clk_src_vdec); |
| 349 | perflvl->dom6 = read_clk(dev, clk_src_dom6); |
| 350 | } |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | struct nv50_pm_state { |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 356 | struct nouveau_pm_level *perflvl; |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 357 | struct hwsq_ucode eclk_hwsq; |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 358 | struct hwsq_ucode mclk_hwsq; |
| 359 | u32 mscript; |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 360 | u32 mmast; |
| 361 | u32 mctrl; |
| 362 | u32 mcoef; |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 363 | }; |
| 364 | |
| 365 | static u32 |
Ben Skeggs | 70790f4 | 2012-07-10 17:26:46 +1000 | [diff] [blame] | 366 | calc_pll(struct drm_device *dev, u32 reg, struct nvbios_pll *pll, |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 367 | u32 clk, int *N1, int *M1, int *log2P) |
| 368 | { |
| 369 | struct nouveau_pll_vals coef; |
| 370 | int ret; |
| 371 | |
| 372 | ret = get_pll_limits(dev, reg, pll); |
| 373 | if (ret) |
| 374 | return 0; |
| 375 | |
Ben Skeggs | 70790f4 | 2012-07-10 17:26:46 +1000 | [diff] [blame] | 376 | pll->vco2.max_freq = 0; |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 377 | pll->refclk = read_pll_ref(dev, reg); |
| 378 | if (!pll->refclk) |
| 379 | return 0; |
| 380 | |
| 381 | ret = nouveau_calc_pll_mnp(dev, pll, clk, &coef); |
| 382 | if (ret == 0) |
| 383 | return 0; |
| 384 | |
| 385 | *N1 = coef.N1; |
| 386 | *M1 = coef.M1; |
| 387 | *log2P = coef.log2P; |
| 388 | return ret; |
| 389 | } |
| 390 | |
| 391 | static inline u32 |
| 392 | calc_div(u32 src, u32 target, int *div) |
| 393 | { |
| 394 | u32 clk0 = src, clk1 = src; |
| 395 | for (*div = 0; *div <= 7; (*div)++) { |
| 396 | if (clk0 <= target) { |
| 397 | clk1 = clk0 << (*div ? 1 : 0); |
| 398 | break; |
| 399 | } |
| 400 | clk0 >>= 1; |
| 401 | } |
| 402 | |
| 403 | if (target - clk0 <= clk1 - target) |
| 404 | return clk0; |
| 405 | (*div)--; |
| 406 | return clk1; |
| 407 | } |
| 408 | |
| 409 | static inline u32 |
| 410 | clk_same(u32 a, u32 b) |
| 411 | { |
| 412 | return ((a / 1000) == (b / 1000)); |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 413 | } |
| 414 | |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 415 | static void |
| 416 | mclk_precharge(struct nouveau_mem_exec_func *exec) |
| 417 | { |
| 418 | struct nv50_pm_state *info = exec->priv; |
| 419 | struct hwsq_ucode *hwsq = &info->mclk_hwsq; |
| 420 | |
| 421 | hwsq_wr32(hwsq, 0x1002d4, 0x00000001); |
| 422 | } |
| 423 | |
| 424 | static void |
| 425 | mclk_refresh(struct nouveau_mem_exec_func *exec) |
| 426 | { |
| 427 | struct nv50_pm_state *info = exec->priv; |
| 428 | struct hwsq_ucode *hwsq = &info->mclk_hwsq; |
| 429 | |
| 430 | hwsq_wr32(hwsq, 0x1002d0, 0x00000001); |
| 431 | } |
| 432 | |
| 433 | static void |
| 434 | mclk_refresh_auto(struct nouveau_mem_exec_func *exec, bool enable) |
| 435 | { |
| 436 | struct nv50_pm_state *info = exec->priv; |
| 437 | struct hwsq_ucode *hwsq = &info->mclk_hwsq; |
| 438 | |
| 439 | hwsq_wr32(hwsq, 0x100210, enable ? 0x80000000 : 0x00000000); |
| 440 | } |
| 441 | |
| 442 | static void |
| 443 | mclk_refresh_self(struct nouveau_mem_exec_func *exec, bool enable) |
| 444 | { |
| 445 | struct nv50_pm_state *info = exec->priv; |
| 446 | struct hwsq_ucode *hwsq = &info->mclk_hwsq; |
| 447 | |
| 448 | hwsq_wr32(hwsq, 0x1002dc, enable ? 0x00000001 : 0x00000000); |
| 449 | } |
| 450 | |
| 451 | static void |
| 452 | mclk_wait(struct nouveau_mem_exec_func *exec, u32 nsec) |
| 453 | { |
| 454 | struct nv50_pm_state *info = exec->priv; |
| 455 | struct hwsq_ucode *hwsq = &info->mclk_hwsq; |
| 456 | |
| 457 | if (nsec > 1000) |
| 458 | hwsq_usec(hwsq, (nsec + 500) / 1000); |
| 459 | } |
| 460 | |
| 461 | static u32 |
| 462 | mclk_mrg(struct nouveau_mem_exec_func *exec, int mr) |
| 463 | { |
| 464 | if (mr <= 1) |
| 465 | return nv_rd32(exec->dev, 0x1002c0 + ((mr - 0) * 4)); |
| 466 | if (mr <= 3) |
| 467 | return nv_rd32(exec->dev, 0x1002e0 + ((mr - 2) * 4)); |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | static void |
| 472 | mclk_mrs(struct nouveau_mem_exec_func *exec, int mr, u32 data) |
| 473 | { |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 474 | struct nv50_pm_state *info = exec->priv; |
| 475 | struct hwsq_ucode *hwsq = &info->mclk_hwsq; |
| 476 | |
| 477 | if (mr <= 1) { |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame] | 478 | if (nvfb_vram_rank_B(exec->dev)) |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 479 | hwsq_wr32(hwsq, 0x1002c8 + ((mr - 0) * 4), data); |
| 480 | hwsq_wr32(hwsq, 0x1002c0 + ((mr - 0) * 4), data); |
| 481 | } else |
| 482 | if (mr <= 3) { |
Ben Skeggs | 861d210 | 2012-07-11 19:05:01 +1000 | [diff] [blame] | 483 | if (nvfb_vram_rank_B(exec->dev)) |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 484 | hwsq_wr32(hwsq, 0x1002e8 + ((mr - 2) * 4), data); |
| 485 | hwsq_wr32(hwsq, 0x1002e0 + ((mr - 2) * 4), data); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | static void |
| 490 | mclk_clock_set(struct nouveau_mem_exec_func *exec) |
| 491 | { |
| 492 | struct nv50_pm_state *info = exec->priv; |
| 493 | struct hwsq_ucode *hwsq = &info->mclk_hwsq; |
| 494 | u32 ctrl = nv_rd32(exec->dev, 0x004008); |
| 495 | |
| 496 | info->mmast = nv_rd32(exec->dev, 0x00c040); |
| 497 | info->mmast &= ~0xc0000000; /* get MCLK_2 from HREF */ |
| 498 | info->mmast |= 0x0000c000; /* use MCLK_2 as MPLL_BYPASS clock */ |
| 499 | |
| 500 | hwsq_wr32(hwsq, 0xc040, info->mmast); |
| 501 | hwsq_wr32(hwsq, 0x4008, ctrl | 0x00000200); /* bypass MPLL */ |
| 502 | if (info->mctrl & 0x80000000) |
| 503 | hwsq_wr32(hwsq, 0x400c, info->mcoef); |
| 504 | hwsq_wr32(hwsq, 0x4008, info->mctrl); |
| 505 | } |
| 506 | |
| 507 | static void |
| 508 | mclk_timing_set(struct nouveau_mem_exec_func *exec) |
| 509 | { |
| 510 | struct drm_device *dev = exec->dev; |
| 511 | struct nv50_pm_state *info = exec->priv; |
| 512 | struct nouveau_pm_level *perflvl = info->perflvl; |
| 513 | struct hwsq_ucode *hwsq = &info->mclk_hwsq; |
| 514 | int i; |
| 515 | |
| 516 | for (i = 0; i < 9; i++) { |
| 517 | u32 reg = 0x100220 + (i * 4); |
| 518 | u32 val = nv_rd32(dev, reg); |
| 519 | if (val != perflvl->timing.reg[i]) |
| 520 | hwsq_wr32(hwsq, reg, perflvl->timing.reg[i]); |
| 521 | } |
| 522 | } |
| 523 | |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 524 | static int |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 525 | calc_mclk(struct drm_device *dev, struct nouveau_pm_level *perflvl, |
| 526 | struct nv50_pm_state *info) |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 527 | { |
| 528 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | e495d0d | 2012-01-23 13:22:58 +1000 | [diff] [blame] | 529 | u32 crtc_mask = nv50_display_active_crtcs(dev); |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 530 | struct nouveau_mem_exec_func exec = { |
| 531 | .dev = dev, |
| 532 | .precharge = mclk_precharge, |
| 533 | .refresh = mclk_refresh, |
| 534 | .refresh_auto = mclk_refresh_auto, |
| 535 | .refresh_self = mclk_refresh_self, |
| 536 | .wait = mclk_wait, |
| 537 | .mrg = mclk_mrg, |
| 538 | .mrs = mclk_mrs, |
| 539 | .clock_set = mclk_clock_set, |
| 540 | .timing_set = mclk_timing_set, |
| 541 | .priv = info |
| 542 | }; |
| 543 | struct hwsq_ucode *hwsq = &info->mclk_hwsq; |
Ben Skeggs | 70790f4 | 2012-07-10 17:26:46 +1000 | [diff] [blame] | 544 | struct nvbios_pll pll; |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 545 | int N, M, P; |
Ben Skeggs | e495d0d | 2012-01-23 13:22:58 +1000 | [diff] [blame] | 546 | int ret; |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 547 | |
| 548 | /* use pcie refclock if possible, otherwise use mpll */ |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 549 | info->mctrl = nv_rd32(dev, 0x004008); |
| 550 | info->mctrl &= ~0x81ff0200; |
| 551 | if (clk_same(perflvl->memory, read_clk(dev, clk_src_href))) { |
Ben Skeggs | 70790f4 | 2012-07-10 17:26:46 +1000 | [diff] [blame] | 552 | info->mctrl |= 0x00000200 | (pll.bias_p << 19); |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 553 | } else { |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 554 | ret = calc_pll(dev, 0x4008, &pll, perflvl->memory, &N, &M, &P); |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 555 | if (ret == 0) |
| 556 | return -EINVAL; |
| 557 | |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 558 | info->mctrl |= 0x80000000 | (P << 22) | (P << 16); |
Ben Skeggs | 70790f4 | 2012-07-10 17:26:46 +1000 | [diff] [blame] | 559 | info->mctrl |= pll.bias_p << 19; |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 560 | info->mcoef = (N << 8) | M; |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 561 | } |
| 562 | |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 563 | /* build the ucode which will reclock the memory for us */ |
| 564 | hwsq_init(hwsq); |
| 565 | if (crtc_mask) { |
| 566 | hwsq_op5f(hwsq, crtc_mask, 0x00); /* wait for scanout */ |
| 567 | hwsq_op5f(hwsq, crtc_mask, 0x01); /* wait for vblank */ |
| 568 | } |
| 569 | if (dev_priv->chipset >= 0x92) |
| 570 | hwsq_wr32(hwsq, 0x611200, 0x00003300); /* disable scanout */ |
Ben Skeggs | c8b9641 | 2011-11-09 20:22:25 +1000 | [diff] [blame] | 571 | hwsq_setf(hwsq, 0x10, 0); /* disable bus access */ |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 572 | hwsq_op5f(hwsq, 0x00, 0x01); /* no idea :s */ |
| 573 | |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 574 | ret = nouveau_mem_exec(&exec, perflvl); |
| 575 | if (ret) |
| 576 | return ret; |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 577 | |
Ben Skeggs | c8b9641 | 2011-11-09 20:22:25 +1000 | [diff] [blame] | 578 | hwsq_setf(hwsq, 0x10, 1); /* enable bus access */ |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 579 | hwsq_op5f(hwsq, 0x00, 0x00); /* no idea, reverse of 0x00, 0x01? */ |
| 580 | if (dev_priv->chipset >= 0x92) |
| 581 | hwsq_wr32(hwsq, 0x611200, 0x00003330); /* enable scanout */ |
| 582 | hwsq_fini(hwsq); |
| 583 | return 0; |
| 584 | } |
| 585 | |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 586 | void * |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 587 | nv50_pm_clocks_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl) |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 588 | { |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 589 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 590 | struct nv50_pm_state *info; |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 591 | struct hwsq_ucode *hwsq; |
Ben Skeggs | 70790f4 | 2012-07-10 17:26:46 +1000 | [diff] [blame] | 592 | struct nvbios_pll pll; |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 593 | u32 out, mast, divs, ctrl; |
Dan Carpenter | a9d9938 | 2012-01-04 10:20:47 +0300 | [diff] [blame] | 594 | int clk, ret = -EINVAL; |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 595 | int N, M, P1, P2; |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 596 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 597 | if (dev_priv->chipset == 0xaa || |
| 598 | dev_priv->chipset == 0xac) |
| 599 | return ERR_PTR(-ENODEV); |
| 600 | |
| 601 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
| 602 | if (!info) |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 603 | return ERR_PTR(-ENOMEM); |
Ben Skeggs | 6bdf68c | 2012-01-23 13:17:11 +1000 | [diff] [blame] | 604 | info->perflvl = perflvl; |
| 605 | |
| 606 | /* memory: build hwsq ucode which we'll use to reclock memory. |
| 607 | * use pcie refclock if possible, otherwise use mpll */ |
| 608 | info->mclk_hwsq.len = 0; |
| 609 | if (perflvl->memory) { |
| 610 | ret = calc_mclk(dev, perflvl, info); |
| 611 | if (ret) |
| 612 | goto error; |
| 613 | info->mscript = perflvl->memscript; |
| 614 | } |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 615 | |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 616 | divs = read_div(dev); |
| 617 | mast = info->mmast; |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 618 | |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 619 | /* start building HWSQ script for engine reclocking */ |
| 620 | hwsq = &info->eclk_hwsq; |
| 621 | hwsq_init(hwsq); |
| 622 | hwsq_setf(hwsq, 0x10, 0); /* disable bus access */ |
| 623 | hwsq_op5f(hwsq, 0x00, 0x01); /* wait for access disabled? */ |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 624 | |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 625 | /* vdec/dom6: switch to "safe" clocks temporarily */ |
| 626 | if (perflvl->vdec) { |
| 627 | mast &= ~0x00000c00; |
| 628 | divs &= ~0x00000700; |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 629 | } |
| 630 | |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 631 | if (perflvl->dom6) { |
| 632 | mast &= ~0x0c000000; |
| 633 | divs &= ~0x00000007; |
| 634 | } |
| 635 | |
| 636 | hwsq_wr32(hwsq, 0x00c040, mast); |
| 637 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 638 | /* vdec: avoid modifying xpll until we know exactly how the other |
| 639 | * clock domains work, i suspect at least some of them can also be |
| 640 | * tied to xpll... |
| 641 | */ |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 642 | if (perflvl->vdec) { |
| 643 | /* see how close we can get using nvclk as a source */ |
| 644 | clk = calc_div(perflvl->core, perflvl->vdec, &P1); |
| 645 | |
| 646 | /* see how close we can get using xpll/hclk as a source */ |
| 647 | if (dev_priv->chipset != 0x98) |
| 648 | out = read_pll(dev, 0x004030); |
| 649 | else |
| 650 | out = read_clk(dev, clk_src_hclkm3d2); |
| 651 | out = calc_div(out, perflvl->vdec, &P2); |
| 652 | |
| 653 | /* select whichever gets us closest */ |
| 654 | if (abs((int)perflvl->vdec - clk) <= |
| 655 | abs((int)perflvl->vdec - out)) { |
| 656 | if (dev_priv->chipset != 0x98) |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 657 | mast |= 0x00000c00; |
| 658 | divs |= P1 << 8; |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 659 | } else { |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 660 | mast |= 0x00000800; |
| 661 | divs |= P2 << 8; |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
| 665 | /* dom6: nfi what this is, but we're limited to various combinations |
| 666 | * of the host clock frequency |
| 667 | */ |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 668 | if (perflvl->dom6) { |
Ben Skeggs | 973e861 | 2011-10-31 10:52:33 +1000 | [diff] [blame] | 669 | if (clk_same(perflvl->dom6, read_clk(dev, clk_src_href))) { |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 670 | mast |= 0x00000000; |
Ben Skeggs | 973e861 | 2011-10-31 10:52:33 +1000 | [diff] [blame] | 671 | } else |
| 672 | if (clk_same(perflvl->dom6, read_clk(dev, clk_src_hclk))) { |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 673 | mast |= 0x08000000; |
Ben Skeggs | 973e861 | 2011-10-31 10:52:33 +1000 | [diff] [blame] | 674 | } else { |
| 675 | clk = read_clk(dev, clk_src_hclk) * 3; |
| 676 | clk = calc_div(clk, perflvl->dom6, &P1); |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 677 | |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 678 | mast |= 0x0c000000; |
| 679 | divs |= P1; |
Ben Skeggs | 973e861 | 2011-10-31 10:52:33 +1000 | [diff] [blame] | 680 | } |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 681 | } |
| 682 | |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 683 | /* vdec/dom6: complete switch to new clocks */ |
| 684 | switch (dev_priv->chipset) { |
| 685 | case 0x92: |
| 686 | case 0x94: |
| 687 | case 0x96: |
| 688 | hwsq_wr32(hwsq, 0x004800, divs); |
| 689 | break; |
| 690 | default: |
| 691 | hwsq_wr32(hwsq, 0x004700, divs); |
| 692 | break; |
| 693 | } |
| 694 | |
| 695 | hwsq_wr32(hwsq, 0x00c040, mast); |
| 696 | |
| 697 | /* core/shader: make sure sclk/nvclk are disconnected from their |
| 698 | * PLLs (nvclk to dom6, sclk to hclk) |
| 699 | */ |
| 700 | if (dev_priv->chipset < 0x92) |
| 701 | mast = (mast & ~0x001000b0) | 0x00100080; |
| 702 | else |
| 703 | mast = (mast & ~0x000000b3) | 0x00000081; |
| 704 | |
| 705 | hwsq_wr32(hwsq, 0x00c040, mast); |
| 706 | |
| 707 | /* core: for the moment at least, always use nvpll */ |
| 708 | clk = calc_pll(dev, 0x4028, &pll, perflvl->core, &N, &M, &P1); |
| 709 | if (clk == 0) |
| 710 | goto error; |
| 711 | |
| 712 | ctrl = nv_rd32(dev, 0x004028) & ~0xc03f0100; |
| 713 | mast &= ~0x00100000; |
| 714 | mast |= 3; |
| 715 | |
| 716 | hwsq_wr32(hwsq, 0x004028, 0x80000000 | (P1 << 19) | (P1 << 16) | ctrl); |
| 717 | hwsq_wr32(hwsq, 0x00402c, (N << 8) | M); |
| 718 | |
| 719 | /* shader: tie to nvclk if possible, otherwise use spll. have to be |
| 720 | * very careful that the shader clock is at least twice the core, or |
| 721 | * some chipsets will be very unhappy. i expect most or all of these |
| 722 | * cases will be handled by tying to nvclk, but it's possible there's |
| 723 | * corners |
| 724 | */ |
| 725 | ctrl = nv_rd32(dev, 0x004020) & ~0xc03f0100; |
| 726 | |
| 727 | if (P1-- && perflvl->shader == (perflvl->core << 1)) { |
| 728 | hwsq_wr32(hwsq, 0x004020, (P1 << 19) | (P1 << 16) | ctrl); |
| 729 | hwsq_wr32(hwsq, 0x00c040, 0x00000020 | mast); |
| 730 | } else { |
| 731 | clk = calc_pll(dev, 0x4020, &pll, perflvl->shader, &N, &M, &P1); |
| 732 | if (clk == 0) |
| 733 | goto error; |
| 734 | ctrl |= 0x80000000; |
| 735 | |
| 736 | hwsq_wr32(hwsq, 0x004020, (P1 << 19) | (P1 << 16) | ctrl); |
| 737 | hwsq_wr32(hwsq, 0x004024, (N << 8) | M); |
| 738 | hwsq_wr32(hwsq, 0x00c040, 0x00000030 | mast); |
| 739 | } |
| 740 | |
| 741 | hwsq_setf(hwsq, 0x10, 1); /* enable bus access */ |
| 742 | hwsq_op5f(hwsq, 0x00, 0x00); /* wait for access enabled? */ |
| 743 | hwsq_fini(hwsq); |
| 744 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 745 | return info; |
| 746 | error: |
| 747 | kfree(info); |
| 748 | return ERR_PTR(ret); |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 749 | } |
| 750 | |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 751 | static int |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 752 | prog_hwsq(struct drm_device *dev, struct hwsq_ucode *hwsq) |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 753 | { |
| 754 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 755 | u32 hwsq_data, hwsq_kick; |
| 756 | int i; |
| 757 | |
Martin Peres | e436d1b | 2012-03-09 00:15:01 +0100 | [diff] [blame] | 758 | if (dev_priv->chipset < 0x94) { |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 759 | hwsq_data = 0x001400; |
| 760 | hwsq_kick = 0x00000003; |
| 761 | } else { |
| 762 | hwsq_data = 0x080000; |
| 763 | hwsq_kick = 0x00000001; |
| 764 | } |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 765 | /* upload hwsq ucode */ |
| 766 | nv_mask(dev, 0x001098, 0x00000008, 0x00000000); |
| 767 | nv_wr32(dev, 0x001304, 0x00000000); |
Martin Peres | e436d1b | 2012-03-09 00:15:01 +0100 | [diff] [blame] | 768 | if (dev_priv->chipset >= 0x92) |
| 769 | nv_wr32(dev, 0x001318, 0x00000000); |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 770 | for (i = 0; i < hwsq->len / 4; i++) |
| 771 | nv_wr32(dev, hwsq_data + (i * 4), hwsq->ptr.u32[i]); |
| 772 | nv_mask(dev, 0x001098, 0x00000018, 0x00000018); |
| 773 | |
| 774 | /* launch, and wait for completion */ |
| 775 | nv_wr32(dev, 0x00130c, hwsq_kick); |
| 776 | if (!nv_wait(dev, 0x001308, 0x00000100, 0x00000000)) { |
| 777 | NV_ERROR(dev, "hwsq ucode exec timed out\n"); |
| 778 | NV_ERROR(dev, "0x001308: 0x%08x\n", nv_rd32(dev, 0x001308)); |
| 779 | for (i = 0; i < hwsq->len / 4; i++) { |
| 780 | NV_ERROR(dev, "0x%06x: 0x%08x\n", 0x1400 + (i * 4), |
| 781 | nv_rd32(dev, 0x001400 + (i * 4))); |
| 782 | } |
| 783 | |
| 784 | return -EIO; |
| 785 | } |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 790 | int |
| 791 | nv50_pm_clocks_set(struct drm_device *dev, void *data) |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 792 | { |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 793 | struct nv50_pm_state *info = data; |
| 794 | struct bit_entry M; |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 795 | int ret = -EBUSY; |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 796 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 797 | /* halt and idle execution engines */ |
| 798 | nv_mask(dev, 0x002504, 0x00000001, 0x00000001); |
| 799 | if (!nv_wait(dev, 0x002504, 0x00000010, 0x00000010)) |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 800 | goto resume; |
Martin Peres | c57ebf5e | 2012-01-09 15:23:10 +1000 | [diff] [blame] | 801 | if (!nv_wait(dev, 0x00251c, 0x0000003f, 0x0000003f)) |
| 802 | goto resume; |
Ben Skeggs | aee582d | 2010-09-27 10:13:23 +1000 | [diff] [blame] | 803 | |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 804 | /* program memory clock, if necessary - must come before engine clock |
| 805 | * reprogramming due to how we construct the hwsq scripts in pre() |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 806 | */ |
| 807 | if (info->mclk_hwsq.len) { |
| 808 | /* execute some scripts that do ??? from the vbios.. */ |
| 809 | if (!bit_table(dev, 'M', &M) && M.version == 1) { |
| 810 | if (M.length >= 6) |
| 811 | nouveau_bios_init_exec(dev, ROM16(M.data[5])); |
| 812 | if (M.length >= 8) |
| 813 | nouveau_bios_init_exec(dev, ROM16(M.data[7])); |
| 814 | if (M.length >= 10) |
| 815 | nouveau_bios_init_exec(dev, ROM16(M.data[9])); |
| 816 | nouveau_bios_init_exec(dev, info->mscript); |
| 817 | } |
| 818 | |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 819 | ret = prog_hwsq(dev, &info->mclk_hwsq); |
Martin Peres | eeb7a50 | 2011-11-07 23:38:50 +0100 | [diff] [blame] | 820 | if (ret) |
| 821 | goto resume; |
| 822 | } |
| 823 | |
Ben Skeggs | 496a73b | 2012-01-24 09:47:04 +1000 | [diff] [blame] | 824 | /* program engine clocks */ |
| 825 | ret = prog_hwsq(dev, &info->eclk_hwsq); |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 826 | |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 827 | resume: |
| 828 | nv_mask(dev, 0x002504, 0x00000001, 0x00000000); |
Ben Skeggs | 19fa224 | 2011-10-28 22:10:15 +1000 | [diff] [blame] | 829 | kfree(info); |
Ben Skeggs | f3fbaf3 | 2011-10-26 09:11:02 +1000 | [diff] [blame] | 830 | return ret; |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 831 | } |
| 832 | |
Ben Skeggs | cb9fa62 | 2011-08-14 12:43:47 +1000 | [diff] [blame] | 833 | static int |
Ben Skeggs | 675aac0 | 2011-11-21 21:28:28 +1000 | [diff] [blame] | 834 | pwm_info(struct drm_device *dev, int *line, int *ctrl, int *indx) |
Ben Skeggs | cb9fa62 | 2011-08-14 12:43:47 +1000 | [diff] [blame] | 835 | { |
Ben Skeggs | 675aac0 | 2011-11-21 21:28:28 +1000 | [diff] [blame] | 836 | if (*line == 0x04) { |
Ben Skeggs | 5a4267a | 2011-09-17 02:01:24 +1000 | [diff] [blame] | 837 | *ctrl = 0x00e100; |
| 838 | *line = 4; |
| 839 | *indx = 0; |
| 840 | } else |
Ben Skeggs | 675aac0 | 2011-11-21 21:28:28 +1000 | [diff] [blame] | 841 | if (*line == 0x09) { |
Ben Skeggs | 5a4267a | 2011-09-17 02:01:24 +1000 | [diff] [blame] | 842 | *ctrl = 0x00e100; |
| 843 | *line = 9; |
| 844 | *indx = 1; |
| 845 | } else |
Ben Skeggs | 675aac0 | 2011-11-21 21:28:28 +1000 | [diff] [blame] | 846 | if (*line == 0x10) { |
Ben Skeggs | 5a4267a | 2011-09-17 02:01:24 +1000 | [diff] [blame] | 847 | *ctrl = 0x00e28c; |
| 848 | *line = 0; |
| 849 | *indx = 0; |
| 850 | } else { |
Ben Skeggs | 675aac0 | 2011-11-21 21:28:28 +1000 | [diff] [blame] | 851 | NV_ERROR(dev, "unknown pwm ctrl for gpio %d\n", *line); |
Ben Skeggs | 5a4267a | 2011-09-17 02:01:24 +1000 | [diff] [blame] | 852 | return -ENODEV; |
Ben Skeggs | cb9fa62 | 2011-08-14 12:43:47 +1000 | [diff] [blame] | 853 | } |
| 854 | |
Ben Skeggs | 5a4267a | 2011-09-17 02:01:24 +1000 | [diff] [blame] | 855 | return 0; |
Ben Skeggs | cb9fa62 | 2011-08-14 12:43:47 +1000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | int |
Ben Skeggs | 675aac0 | 2011-11-21 21:28:28 +1000 | [diff] [blame] | 859 | nv50_pm_pwm_get(struct drm_device *dev, int line, u32 *divs, u32 *duty) |
Ben Skeggs | cb9fa62 | 2011-08-14 12:43:47 +1000 | [diff] [blame] | 860 | { |
Ben Skeggs | 675aac0 | 2011-11-21 21:28:28 +1000 | [diff] [blame] | 861 | int ctrl, id, ret = pwm_info(dev, &line, &ctrl, &id); |
Ben Skeggs | cb9fa62 | 2011-08-14 12:43:47 +1000 | [diff] [blame] | 862 | if (ret) |
| 863 | return ret; |
| 864 | |
Ben Skeggs | 5a4267a | 2011-09-17 02:01:24 +1000 | [diff] [blame] | 865 | if (nv_rd32(dev, ctrl) & (1 << line)) { |
| 866 | *divs = nv_rd32(dev, 0x00e114 + (id * 8)); |
| 867 | *duty = nv_rd32(dev, 0x00e118 + (id * 8)); |
Ben Skeggs | cb9fa62 | 2011-08-14 12:43:47 +1000 | [diff] [blame] | 868 | return 0; |
| 869 | } |
| 870 | |
Ben Skeggs | 5a4267a | 2011-09-17 02:01:24 +1000 | [diff] [blame] | 871 | return -EINVAL; |
Ben Skeggs | cb9fa62 | 2011-08-14 12:43:47 +1000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | int |
Ben Skeggs | 675aac0 | 2011-11-21 21:28:28 +1000 | [diff] [blame] | 875 | nv50_pm_pwm_set(struct drm_device *dev, int line, u32 divs, u32 duty) |
Ben Skeggs | cb9fa62 | 2011-08-14 12:43:47 +1000 | [diff] [blame] | 876 | { |
Ben Skeggs | 675aac0 | 2011-11-21 21:28:28 +1000 | [diff] [blame] | 877 | int ctrl, id, ret = pwm_info(dev, &line, &ctrl, &id); |
Ben Skeggs | cb9fa62 | 2011-08-14 12:43:47 +1000 | [diff] [blame] | 878 | if (ret) |
| 879 | return ret; |
| 880 | |
Ben Skeggs | 5a4267a | 2011-09-17 02:01:24 +1000 | [diff] [blame] | 881 | nv_mask(dev, ctrl, 0x00010001 << line, 0x00000001 << line); |
| 882 | nv_wr32(dev, 0x00e114 + (id * 8), divs); |
| 883 | nv_wr32(dev, 0x00e118 + (id * 8), duty | 0x80000000); |
Ben Skeggs | cb9fa62 | 2011-08-14 12:43:47 +1000 | [diff] [blame] | 884 | return 0; |
| 885 | } |