nva3_pm.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. #include "drmP.h"
  25. #include "nouveau_drv.h"
  26. #include <nouveau_bios.h>
  27. #include "nouveau_pm.h"
  28. static u32 read_clk(struct drm_device *, int, bool);
  29. static u32 read_pll(struct drm_device *, int, u32);
  30. static u32
  31. read_vco(struct drm_device *dev, int clk)
  32. {
  33. u32 sctl = nv_rd32(dev, 0x4120 + (clk * 4));
  34. if ((sctl & 0x00000030) != 0x00000030)
  35. return read_pll(dev, 0x41, 0x00e820);
  36. return read_pll(dev, 0x42, 0x00e8a0);
  37. }
  38. static u32
  39. read_clk(struct drm_device *dev, int clk, bool ignore_en)
  40. {
  41. struct drm_nouveau_private *dev_priv = dev->dev_private;
  42. u32 sctl, sdiv, sclk;
  43. /* refclk for the 0xe8xx plls is a fixed frequency */
  44. if (clk >= 0x40) {
  45. if (dev_priv->chipset == 0xaf) {
  46. /* no joke.. seriously.. sigh.. */
  47. return nv_rd32(dev, 0x00471c) * 1000;
  48. }
  49. return dev_priv->crystal;
  50. }
  51. sctl = nv_rd32(dev, 0x4120 + (clk * 4));
  52. if (!ignore_en && !(sctl & 0x00000100))
  53. return 0;
  54. switch (sctl & 0x00003000) {
  55. case 0x00000000:
  56. return dev_priv->crystal;
  57. case 0x00002000:
  58. if (sctl & 0x00000040)
  59. return 108000;
  60. return 100000;
  61. case 0x00003000:
  62. sclk = read_vco(dev, clk);
  63. sdiv = ((sctl & 0x003f0000) >> 16) + 2;
  64. return (sclk * 2) / sdiv;
  65. default:
  66. return 0;
  67. }
  68. }
  69. static u32
  70. read_pll(struct drm_device *dev, int clk, u32 pll)
  71. {
  72. u32 ctrl = nv_rd32(dev, pll + 0);
  73. u32 sclk = 0, P = 1, N = 1, M = 1;
  74. if (!(ctrl & 0x00000008)) {
  75. if (ctrl & 0x00000001) {
  76. u32 coef = nv_rd32(dev, pll + 4);
  77. M = (coef & 0x000000ff) >> 0;
  78. N = (coef & 0x0000ff00) >> 8;
  79. P = (coef & 0x003f0000) >> 16;
  80. /* no post-divider on these.. */
  81. if ((pll & 0x00ff00) == 0x00e800)
  82. P = 1;
  83. sclk = read_clk(dev, 0x00 + clk, false);
  84. }
  85. } else {
  86. sclk = read_clk(dev, 0x10 + clk, false);
  87. }
  88. if (M * P)
  89. return sclk * N / (M * P);
  90. return 0;
  91. }
  92. struct creg {
  93. u32 clk;
  94. u32 pll;
  95. };
  96. static int
  97. calc_clk(struct drm_device *dev, int clk, u32 pll, u32 khz, struct creg *reg)
  98. {
  99. struct nvbios_pll limits;
  100. u32 oclk, sclk, sdiv;
  101. int P, N, M, diff;
  102. int ret;
  103. reg->pll = 0;
  104. reg->clk = 0;
  105. if (!khz) {
  106. NV_DEBUG(dev, "no clock for 0x%04x/0x%02x\n", pll, clk);
  107. return 0;
  108. }
  109. switch (khz) {
  110. case 27000:
  111. reg->clk = 0x00000100;
  112. return khz;
  113. case 100000:
  114. reg->clk = 0x00002100;
  115. return khz;
  116. case 108000:
  117. reg->clk = 0x00002140;
  118. return khz;
  119. default:
  120. sclk = read_vco(dev, clk);
  121. sdiv = min((sclk * 2) / (khz - 2999), (u32)65);
  122. /* if the clock has a PLL attached, and we can get a within
  123. * [-2, 3) MHz of a divider, we'll disable the PLL and use
  124. * the divider instead.
  125. *
  126. * divider can go as low as 2, limited here because NVIDIA
  127. * and the VBIOS on my NVA8 seem to prefer using the PLL
  128. * for 810MHz - is there a good reason?
  129. */
  130. if (sdiv > 4) {
  131. oclk = (sclk * 2) / sdiv;
  132. diff = khz - oclk;
  133. if (!pll || (diff >= -2000 && diff < 3000)) {
  134. reg->clk = (((sdiv - 2) << 16) | 0x00003100);
  135. return oclk;
  136. }
  137. }
  138. if (!pll) {
  139. NV_ERROR(dev, "bad freq %02x: %d %d\n", clk, khz, sclk);
  140. return -ERANGE;
  141. }
  142. break;
  143. }
  144. ret = get_pll_limits(dev, pll, &limits);
  145. if (ret)
  146. return ret;
  147. limits.refclk = read_clk(dev, clk - 0x10, true);
  148. if (!limits.refclk)
  149. return -EINVAL;
  150. ret = nva3_calc_pll(dev, &limits, khz, &N, NULL, &M, &P);
  151. if (ret >= 0) {
  152. reg->clk = nv_rd32(dev, 0x4120 + (clk * 4));
  153. reg->pll = (P << 16) | (N << 8) | M;
  154. }
  155. return ret;
  156. }
  157. static void
  158. prog_pll(struct drm_device *dev, int clk, u32 pll, struct creg *reg)
  159. {
  160. const u32 src0 = 0x004120 + (clk * 4);
  161. const u32 src1 = 0x004160 + (clk * 4);
  162. const u32 ctrl = pll + 0;
  163. const u32 coef = pll + 4;
  164. if (!reg->clk && !reg->pll) {
  165. NV_DEBUG(dev, "no clock for %02x\n", clk);
  166. return;
  167. }
  168. if (reg->pll) {
  169. nv_mask(dev, src0, 0x00000101, 0x00000101);
  170. nv_wr32(dev, coef, reg->pll);
  171. nv_mask(dev, ctrl, 0x00000015, 0x00000015);
  172. nv_mask(dev, ctrl, 0x00000010, 0x00000000);
  173. nv_wait(dev, ctrl, 0x00020000, 0x00020000);
  174. nv_mask(dev, ctrl, 0x00000010, 0x00000010);
  175. nv_mask(dev, ctrl, 0x00000008, 0x00000000);
  176. nv_mask(dev, src1, 0x00000100, 0x00000000);
  177. nv_mask(dev, src1, 0x00000001, 0x00000000);
  178. } else {
  179. nv_mask(dev, src1, 0x003f3141, 0x00000101 | reg->clk);
  180. nv_mask(dev, ctrl, 0x00000018, 0x00000018);
  181. udelay(20);
  182. nv_mask(dev, ctrl, 0x00000001, 0x00000000);
  183. nv_mask(dev, src0, 0x00000100, 0x00000000);
  184. nv_mask(dev, src0, 0x00000001, 0x00000000);
  185. }
  186. }
  187. static void
  188. prog_clk(struct drm_device *dev, int clk, struct creg *reg)
  189. {
  190. if (!reg->clk) {
  191. NV_DEBUG(dev, "no clock for %02x\n", clk);
  192. return;
  193. }
  194. nv_mask(dev, 0x004120 + (clk * 4), 0x003f3141, 0x00000101 | reg->clk);
  195. }
  196. int
  197. nva3_pm_clocks_get(struct drm_device *dev, struct nouveau_pm_level *perflvl)
  198. {
  199. perflvl->core = read_pll(dev, 0x00, 0x4200);
  200. perflvl->shader = read_pll(dev, 0x01, 0x4220);
  201. perflvl->memory = read_pll(dev, 0x02, 0x4000);
  202. perflvl->unka0 = read_clk(dev, 0x20, false);
  203. perflvl->vdec = read_clk(dev, 0x21, false);
  204. perflvl->daemon = read_clk(dev, 0x25, false);
  205. perflvl->copy = perflvl->core;
  206. return 0;
  207. }
  208. struct nva3_pm_state {
  209. struct nouveau_pm_level *perflvl;
  210. struct creg nclk;
  211. struct creg sclk;
  212. struct creg vdec;
  213. struct creg unka0;
  214. struct creg mclk;
  215. u8 *rammap;
  216. u8 rammap_ver;
  217. u8 rammap_len;
  218. u8 *ramcfg;
  219. u8 ramcfg_len;
  220. u32 r004018;
  221. u32 r100760;
  222. };
  223. void *
  224. nva3_pm_clocks_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl)
  225. {
  226. struct nva3_pm_state *info;
  227. u8 ramcfg_cnt;
  228. int ret;
  229. info = kzalloc(sizeof(*info), GFP_KERNEL);
  230. if (!info)
  231. return ERR_PTR(-ENOMEM);
  232. ret = calc_clk(dev, 0x10, 0x4200, perflvl->core, &info->nclk);
  233. if (ret < 0)
  234. goto out;
  235. ret = calc_clk(dev, 0x11, 0x4220, perflvl->shader, &info->sclk);
  236. if (ret < 0)
  237. goto out;
  238. ret = calc_clk(dev, 0x12, 0x4000, perflvl->memory, &info->mclk);
  239. if (ret < 0)
  240. goto out;
  241. ret = calc_clk(dev, 0x20, 0x0000, perflvl->unka0, &info->unka0);
  242. if (ret < 0)
  243. goto out;
  244. ret = calc_clk(dev, 0x21, 0x0000, perflvl->vdec, &info->vdec);
  245. if (ret < 0)
  246. goto out;
  247. info->rammap = nouveau_perf_rammap(dev, perflvl->memory,
  248. &info->rammap_ver,
  249. &info->rammap_len,
  250. &ramcfg_cnt, &info->ramcfg_len);
  251. if (info->rammap_ver != 0x10 || info->rammap_len < 5)
  252. info->rammap = NULL;
  253. info->ramcfg = nouveau_perf_ramcfg(dev, perflvl->memory,
  254. &info->rammap_ver,
  255. &info->ramcfg_len);
  256. if (info->rammap_ver != 0x10)
  257. info->ramcfg = NULL;
  258. info->perflvl = perflvl;
  259. out:
  260. if (ret < 0) {
  261. kfree(info);
  262. info = ERR_PTR(ret);
  263. }
  264. return info;
  265. }
  266. static bool
  267. nva3_pm_grcp_idle(void *data)
  268. {
  269. struct drm_device *dev = data;
  270. if (!(nv_rd32(dev, 0x400304) & 0x00000001))
  271. return true;
  272. if (nv_rd32(dev, 0x400308) == 0x0050001c)
  273. return true;
  274. return false;
  275. }
  276. static void
  277. mclk_precharge(struct nouveau_mem_exec_func *exec)
  278. {
  279. nv_wr32(exec->dev, 0x1002d4, 0x00000001);
  280. }
  281. static void
  282. mclk_refresh(struct nouveau_mem_exec_func *exec)
  283. {
  284. nv_wr32(exec->dev, 0x1002d0, 0x00000001);
  285. }
  286. static void
  287. mclk_refresh_auto(struct nouveau_mem_exec_func *exec, bool enable)
  288. {
  289. nv_wr32(exec->dev, 0x100210, enable ? 0x80000000 : 0x00000000);
  290. }
  291. static void
  292. mclk_refresh_self(struct nouveau_mem_exec_func *exec, bool enable)
  293. {
  294. nv_wr32(exec->dev, 0x1002dc, enable ? 0x00000001 : 0x00000000);
  295. }
  296. static void
  297. mclk_wait(struct nouveau_mem_exec_func *exec, u32 nsec)
  298. {
  299. volatile u32 post = nv_rd32(exec->dev, 0); (void)post;
  300. udelay((nsec + 500) / 1000);
  301. }
  302. static u32
  303. mclk_mrg(struct nouveau_mem_exec_func *exec, int mr)
  304. {
  305. if (mr <= 1)
  306. return nv_rd32(exec->dev, 0x1002c0 + ((mr - 0) * 4));
  307. if (mr <= 3)
  308. return nv_rd32(exec->dev, 0x1002e0 + ((mr - 2) * 4));
  309. return 0;
  310. }
  311. static void
  312. mclk_mrs(struct nouveau_mem_exec_func *exec, int mr, u32 data)
  313. {
  314. if (mr <= 1) {
  315. if (nvfb_vram_rank_B(exec->dev))
  316. nv_wr32(exec->dev, 0x1002c8 + ((mr - 0) * 4), data);
  317. nv_wr32(exec->dev, 0x1002c0 + ((mr - 0) * 4), data);
  318. } else
  319. if (mr <= 3) {
  320. if (nvfb_vram_rank_B(exec->dev))
  321. nv_wr32(exec->dev, 0x1002e8 + ((mr - 2) * 4), data);
  322. nv_wr32(exec->dev, 0x1002e0 + ((mr - 2) * 4), data);
  323. }
  324. }
  325. static void
  326. mclk_clock_set(struct nouveau_mem_exec_func *exec)
  327. {
  328. struct drm_device *dev = exec->dev;
  329. struct nva3_pm_state *info = exec->priv;
  330. u32 ctrl;
  331. ctrl = nv_rd32(dev, 0x004000);
  332. if (!(ctrl & 0x00000008) && info->mclk.pll) {
  333. nv_wr32(dev, 0x004000, (ctrl |= 0x00000008));
  334. nv_mask(dev, 0x1110e0, 0x00088000, 0x00088000);
  335. nv_wr32(dev, 0x004018, 0x00001000);
  336. nv_wr32(dev, 0x004000, (ctrl &= ~0x00000001));
  337. nv_wr32(dev, 0x004004, info->mclk.pll);
  338. nv_wr32(dev, 0x004000, (ctrl |= 0x00000001));
  339. udelay(64);
  340. nv_wr32(dev, 0x004018, 0x00005000 | info->r004018);
  341. udelay(20);
  342. } else
  343. if (!info->mclk.pll) {
  344. nv_mask(dev, 0x004168, 0x003f3040, info->mclk.clk);
  345. nv_wr32(dev, 0x004000, (ctrl |= 0x00000008));
  346. nv_mask(dev, 0x1110e0, 0x00088000, 0x00088000);
  347. nv_wr32(dev, 0x004018, 0x0000d000 | info->r004018);
  348. }
  349. if (info->rammap) {
  350. if (info->ramcfg && (info->rammap[4] & 0x08)) {
  351. u32 unk5a0 = (ROM16(info->ramcfg[5]) << 8) |
  352. info->ramcfg[5];
  353. u32 unk5a4 = ROM16(info->ramcfg[7]);
  354. u32 unk804 = (info->ramcfg[9] & 0xf0) << 16 |
  355. (info->ramcfg[3] & 0x0f) << 16 |
  356. (info->ramcfg[9] & 0x0f) |
  357. 0x80000000;
  358. nv_wr32(dev, 0x1005a0, unk5a0);
  359. nv_wr32(dev, 0x1005a4, unk5a4);
  360. nv_wr32(dev, 0x10f804, unk804);
  361. nv_mask(dev, 0x10053c, 0x00001000, 0x00000000);
  362. } else {
  363. nv_mask(dev, 0x10053c, 0x00001000, 0x00001000);
  364. nv_mask(dev, 0x10f804, 0x80000000, 0x00000000);
  365. nv_mask(dev, 0x100760, 0x22222222, info->r100760);
  366. nv_mask(dev, 0x1007a0, 0x22222222, info->r100760);
  367. nv_mask(dev, 0x1007e0, 0x22222222, info->r100760);
  368. }
  369. }
  370. if (info->mclk.pll) {
  371. nv_mask(dev, 0x1110e0, 0x00088000, 0x00011000);
  372. nv_wr32(dev, 0x004000, (ctrl &= ~0x00000008));
  373. }
  374. }
  375. static void
  376. mclk_timing_set(struct nouveau_mem_exec_func *exec)
  377. {
  378. struct drm_device *dev = exec->dev;
  379. struct nva3_pm_state *info = exec->priv;
  380. struct nouveau_pm_level *perflvl = info->perflvl;
  381. int i;
  382. for (i = 0; i < 9; i++)
  383. nv_wr32(dev, 0x100220 + (i * 4), perflvl->timing.reg[i]);
  384. if (info->ramcfg) {
  385. u32 data = (info->ramcfg[2] & 0x08) ? 0x00000000 : 0x00001000;
  386. nv_mask(dev, 0x100200, 0x00001000, data);
  387. }
  388. if (info->ramcfg) {
  389. u32 unk714 = nv_rd32(dev, 0x100714) & ~0xf0000010;
  390. u32 unk718 = nv_rd32(dev, 0x100718) & ~0x00000100;
  391. u32 unk71c = nv_rd32(dev, 0x10071c) & ~0x00000100;
  392. if ( (info->ramcfg[2] & 0x20))
  393. unk714 |= 0xf0000000;
  394. if (!(info->ramcfg[2] & 0x04))
  395. unk714 |= 0x00000010;
  396. nv_wr32(dev, 0x100714, unk714);
  397. if (info->ramcfg[2] & 0x01)
  398. unk71c |= 0x00000100;
  399. nv_wr32(dev, 0x10071c, unk71c);
  400. if (info->ramcfg[2] & 0x02)
  401. unk718 |= 0x00000100;
  402. nv_wr32(dev, 0x100718, unk718);
  403. if (info->ramcfg[2] & 0x10)
  404. nv_wr32(dev, 0x111100, 0x48000000); /*XXX*/
  405. }
  406. }
  407. static void
  408. prog_mem(struct drm_device *dev, struct nva3_pm_state *info)
  409. {
  410. struct nouveau_mem_exec_func exec = {
  411. .dev = dev,
  412. .precharge = mclk_precharge,
  413. .refresh = mclk_refresh,
  414. .refresh_auto = mclk_refresh_auto,
  415. .refresh_self = mclk_refresh_self,
  416. .wait = mclk_wait,
  417. .mrg = mclk_mrg,
  418. .mrs = mclk_mrs,
  419. .clock_set = mclk_clock_set,
  420. .timing_set = mclk_timing_set,
  421. .priv = info
  422. };
  423. u32 ctrl;
  424. /* XXX: where the fuck does 750MHz come from? */
  425. if (info->perflvl->memory <= 750000) {
  426. info->r004018 = 0x10000000;
  427. info->r100760 = 0x22222222;
  428. }
  429. ctrl = nv_rd32(dev, 0x004000);
  430. if (ctrl & 0x00000008) {
  431. if (info->mclk.pll) {
  432. nv_mask(dev, 0x004128, 0x00000101, 0x00000101);
  433. nv_wr32(dev, 0x004004, info->mclk.pll);
  434. nv_wr32(dev, 0x004000, (ctrl |= 0x00000001));
  435. nv_wr32(dev, 0x004000, (ctrl &= 0xffffffef));
  436. nv_wait(dev, 0x004000, 0x00020000, 0x00020000);
  437. nv_wr32(dev, 0x004000, (ctrl |= 0x00000010));
  438. nv_wr32(dev, 0x004018, 0x00005000 | info->r004018);
  439. nv_wr32(dev, 0x004000, (ctrl |= 0x00000004));
  440. }
  441. } else {
  442. u32 ssel = 0x00000101;
  443. if (info->mclk.clk)
  444. ssel |= info->mclk.clk;
  445. else
  446. ssel |= 0x00080000; /* 324MHz, shouldn't matter... */
  447. nv_mask(dev, 0x004168, 0x003f3141, ctrl);
  448. }
  449. if (info->ramcfg) {
  450. if (info->ramcfg[2] & 0x10) {
  451. nv_mask(dev, 0x111104, 0x00000600, 0x00000000);
  452. } else {
  453. nv_mask(dev, 0x111100, 0x40000000, 0x40000000);
  454. nv_mask(dev, 0x111104, 0x00000180, 0x00000000);
  455. }
  456. }
  457. if (info->rammap && !(info->rammap[4] & 0x02))
  458. nv_mask(dev, 0x100200, 0x00000800, 0x00000000);
  459. nv_wr32(dev, 0x611200, 0x00003300);
  460. if (!(info->ramcfg[2] & 0x10))
  461. nv_wr32(dev, 0x111100, 0x4c020000); /*XXX*/
  462. nouveau_mem_exec(&exec, info->perflvl);
  463. nv_wr32(dev, 0x611200, 0x00003330);
  464. if (info->rammap && (info->rammap[4] & 0x02))
  465. nv_mask(dev, 0x100200, 0x00000800, 0x00000800);
  466. if (info->ramcfg) {
  467. if (info->ramcfg[2] & 0x10) {
  468. nv_mask(dev, 0x111104, 0x00000180, 0x00000180);
  469. nv_mask(dev, 0x111100, 0x40000000, 0x00000000);
  470. } else {
  471. nv_mask(dev, 0x111104, 0x00000600, 0x00000600);
  472. }
  473. }
  474. if (info->mclk.pll) {
  475. nv_mask(dev, 0x004168, 0x00000001, 0x00000000);
  476. nv_mask(dev, 0x004168, 0x00000100, 0x00000000);
  477. } else {
  478. nv_mask(dev, 0x004000, 0x00000001, 0x00000000);
  479. nv_mask(dev, 0x004128, 0x00000001, 0x00000000);
  480. nv_mask(dev, 0x004128, 0x00000100, 0x00000000);
  481. }
  482. }
  483. int
  484. nva3_pm_clocks_set(struct drm_device *dev, void *pre_state)
  485. {
  486. struct drm_nouveau_private *dev_priv = dev->dev_private;
  487. struct nva3_pm_state *info = pre_state;
  488. unsigned long flags;
  489. int ret = -EAGAIN;
  490. /* prevent any new grctx switches from starting */
  491. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  492. nv_wr32(dev, 0x400324, 0x00000000);
  493. nv_wr32(dev, 0x400328, 0x0050001c); /* wait flag 0x1c */
  494. /* wait for any pending grctx switches to complete */
  495. if (!nv_wait_cb(dev, nva3_pm_grcp_idle, dev)) {
  496. NV_ERROR(dev, "pm: ctxprog didn't go idle\n");
  497. goto cleanup;
  498. }
  499. /* freeze PFIFO */
  500. nv_mask(dev, 0x002504, 0x00000001, 0x00000001);
  501. if (!nv_wait(dev, 0x002504, 0x00000010, 0x00000010)) {
  502. NV_ERROR(dev, "pm: fifo didn't go idle\n");
  503. goto cleanup;
  504. }
  505. prog_pll(dev, 0x00, 0x004200, &info->nclk);
  506. prog_pll(dev, 0x01, 0x004220, &info->sclk);
  507. prog_clk(dev, 0x20, &info->unka0);
  508. prog_clk(dev, 0x21, &info->vdec);
  509. if (info->mclk.clk || info->mclk.pll)
  510. prog_mem(dev, info);
  511. ret = 0;
  512. cleanup:
  513. /* unfreeze PFIFO */
  514. nv_mask(dev, 0x002504, 0x00000001, 0x00000000);
  515. /* restore ctxprog to normal */
  516. nv_wr32(dev, 0x400324, 0x00000000);
  517. nv_wr32(dev, 0x400328, 0x0070009c); /* set flag 0x1c */
  518. /* unblock it if necessary */
  519. if (nv_rd32(dev, 0x400308) == 0x0050001c)
  520. nv_mask(dev, 0x400824, 0x10000000, 0x10000000);
  521. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  522. kfree(info);
  523. return ret;
  524. }