nva3_pm.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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 pll_lims 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. struct drm_nouveau_private *dev_priv = exec->dev->dev_private;
  315. if (mr <= 1) {
  316. if (dev_priv->vram_rank_B)
  317. nv_wr32(exec->dev, 0x1002c8 + ((mr - 0) * 4), data);
  318. nv_wr32(exec->dev, 0x1002c0 + ((mr - 0) * 4), data);
  319. } else
  320. if (mr <= 3) {
  321. if (dev_priv->vram_rank_B)
  322. nv_wr32(exec->dev, 0x1002e8 + ((mr - 2) * 4), data);
  323. nv_wr32(exec->dev, 0x1002e0 + ((mr - 2) * 4), data);
  324. }
  325. }
  326. static void
  327. mclk_clock_set(struct nouveau_mem_exec_func *exec)
  328. {
  329. struct drm_device *dev = exec->dev;
  330. struct nva3_pm_state *info = exec->priv;
  331. u32 ctrl;
  332. ctrl = nv_rd32(dev, 0x004000);
  333. if (!(ctrl & 0x00000008) && info->mclk.pll) {
  334. nv_wr32(dev, 0x004000, (ctrl |= 0x00000008));
  335. nv_mask(dev, 0x1110e0, 0x00088000, 0x00088000);
  336. nv_wr32(dev, 0x004018, 0x00001000);
  337. nv_wr32(dev, 0x004000, (ctrl &= ~0x00000001));
  338. nv_wr32(dev, 0x004004, info->mclk.pll);
  339. nv_wr32(dev, 0x004000, (ctrl |= 0x00000001));
  340. udelay(64);
  341. nv_wr32(dev, 0x004018, 0x00005000 | info->r004018);
  342. udelay(20);
  343. } else
  344. if (!info->mclk.pll) {
  345. nv_mask(dev, 0x004168, 0x003f3040, info->mclk.clk);
  346. nv_wr32(dev, 0x004000, (ctrl |= 0x00000008));
  347. nv_mask(dev, 0x1110e0, 0x00088000, 0x00088000);
  348. nv_wr32(dev, 0x004018, 0x0000d000 | info->r004018);
  349. }
  350. if (info->rammap) {
  351. if (info->ramcfg && (info->rammap[4] & 0x08)) {
  352. u32 unk5a0 = (ROM16(info->ramcfg[5]) << 8) |
  353. info->ramcfg[5];
  354. u32 unk5a4 = ROM16(info->ramcfg[7]);
  355. u32 unk804 = (info->ramcfg[9] & 0xf0) << 16 |
  356. (info->ramcfg[3] & 0x0f) << 16 |
  357. (info->ramcfg[9] & 0x0f) |
  358. 0x80000000;
  359. nv_wr32(dev, 0x1005a0, unk5a0);
  360. nv_wr32(dev, 0x1005a4, unk5a4);
  361. nv_wr32(dev, 0x10f804, unk804);
  362. nv_mask(dev, 0x10053c, 0x00001000, 0x00000000);
  363. } else {
  364. nv_mask(dev, 0x10053c, 0x00001000, 0x00001000);
  365. nv_mask(dev, 0x10f804, 0x80000000, 0x00000000);
  366. nv_mask(dev, 0x100760, 0x22222222, info->r100760);
  367. nv_mask(dev, 0x1007a0, 0x22222222, info->r100760);
  368. nv_mask(dev, 0x1007e0, 0x22222222, info->r100760);
  369. }
  370. }
  371. if (info->mclk.pll) {
  372. nv_mask(dev, 0x1110e0, 0x00088000, 0x00011000);
  373. nv_wr32(dev, 0x004000, (ctrl &= ~0x00000008));
  374. }
  375. }
  376. static void
  377. mclk_timing_set(struct nouveau_mem_exec_func *exec)
  378. {
  379. struct drm_device *dev = exec->dev;
  380. struct nva3_pm_state *info = exec->priv;
  381. struct nouveau_pm_level *perflvl = info->perflvl;
  382. int i;
  383. for (i = 0; i < 9; i++)
  384. nv_wr32(dev, 0x100220 + (i * 4), perflvl->timing.reg[i]);
  385. if (info->ramcfg) {
  386. u32 data = (info->ramcfg[2] & 0x08) ? 0x00000000 : 0x00001000;
  387. nv_mask(dev, 0x100200, 0x00001000, data);
  388. }
  389. if (info->ramcfg) {
  390. u32 unk714 = nv_rd32(dev, 0x100714) & ~0xf0000010;
  391. u32 unk718 = nv_rd32(dev, 0x100718) & ~0x00000100;
  392. u32 unk71c = nv_rd32(dev, 0x10071c) & ~0x00000100;
  393. if ( (info->ramcfg[2] & 0x20))
  394. unk714 |= 0xf0000000;
  395. if (!(info->ramcfg[2] & 0x04))
  396. unk714 |= 0x00000010;
  397. nv_wr32(dev, 0x100714, unk714);
  398. if (info->ramcfg[2] & 0x01)
  399. unk71c |= 0x00000100;
  400. nv_wr32(dev, 0x10071c, unk71c);
  401. if (info->ramcfg[2] & 0x02)
  402. unk718 |= 0x00000100;
  403. nv_wr32(dev, 0x100718, unk718);
  404. if (info->ramcfg[2] & 0x10)
  405. nv_wr32(dev, 0x111100, 0x48000000); /*XXX*/
  406. }
  407. }
  408. static void
  409. prog_mem(struct drm_device *dev, struct nva3_pm_state *info)
  410. {
  411. struct nouveau_mem_exec_func exec = {
  412. .dev = dev,
  413. .precharge = mclk_precharge,
  414. .refresh = mclk_refresh,
  415. .refresh_auto = mclk_refresh_auto,
  416. .refresh_self = mclk_refresh_self,
  417. .wait = mclk_wait,
  418. .mrg = mclk_mrg,
  419. .mrs = mclk_mrs,
  420. .clock_set = mclk_clock_set,
  421. .timing_set = mclk_timing_set,
  422. .priv = info
  423. };
  424. u32 ctrl;
  425. /* XXX: where the fuck does 750MHz come from? */
  426. if (info->perflvl->memory <= 750000) {
  427. info->r004018 = 0x10000000;
  428. info->r100760 = 0x22222222;
  429. }
  430. ctrl = nv_rd32(dev, 0x004000);
  431. if (ctrl & 0x00000008) {
  432. if (info->mclk.pll) {
  433. nv_mask(dev, 0x004128, 0x00000101, 0x00000101);
  434. nv_wr32(dev, 0x004004, info->mclk.pll);
  435. nv_wr32(dev, 0x004000, (ctrl |= 0x00000001));
  436. nv_wr32(dev, 0x004000, (ctrl &= 0xffffffef));
  437. nv_wait(dev, 0x004000, 0x00020000, 0x00020000);
  438. nv_wr32(dev, 0x004000, (ctrl |= 0x00000010));
  439. nv_wr32(dev, 0x004018, 0x00005000 | info->r004018);
  440. nv_wr32(dev, 0x004000, (ctrl |= 0x00000004));
  441. }
  442. } else {
  443. u32 ssel = 0x00000101;
  444. if (info->mclk.clk)
  445. ssel |= info->mclk.clk;
  446. else
  447. ssel |= 0x00080000; /* 324MHz, shouldn't matter... */
  448. nv_mask(dev, 0x004168, 0x003f3141, ctrl);
  449. }
  450. if (info->ramcfg) {
  451. if (info->ramcfg[2] & 0x10) {
  452. nv_mask(dev, 0x111104, 0x00000600, 0x00000000);
  453. } else {
  454. nv_mask(dev, 0x111100, 0x40000000, 0x40000000);
  455. nv_mask(dev, 0x111104, 0x00000180, 0x00000000);
  456. }
  457. }
  458. if (info->rammap && !(info->rammap[4] & 0x02))
  459. nv_mask(dev, 0x100200, 0x00000800, 0x00000000);
  460. nv_wr32(dev, 0x611200, 0x00003300);
  461. if (!(info->ramcfg[2] & 0x10))
  462. nv_wr32(dev, 0x111100, 0x4c020000); /*XXX*/
  463. nouveau_mem_exec(&exec, info->perflvl);
  464. nv_wr32(dev, 0x611200, 0x00003330);
  465. if (info->rammap && (info->rammap[4] & 0x02))
  466. nv_mask(dev, 0x100200, 0x00000800, 0x00000800);
  467. if (info->ramcfg) {
  468. if (info->ramcfg[2] & 0x10) {
  469. nv_mask(dev, 0x111104, 0x00000180, 0x00000180);
  470. nv_mask(dev, 0x111100, 0x40000000, 0x00000000);
  471. } else {
  472. nv_mask(dev, 0x111104, 0x00000600, 0x00000600);
  473. }
  474. }
  475. if (info->mclk.pll) {
  476. nv_mask(dev, 0x004168, 0x00000001, 0x00000000);
  477. nv_mask(dev, 0x004168, 0x00000100, 0x00000000);
  478. } else {
  479. nv_mask(dev, 0x004000, 0x00000001, 0x00000000);
  480. nv_mask(dev, 0x004128, 0x00000001, 0x00000000);
  481. nv_mask(dev, 0x004128, 0x00000100, 0x00000000);
  482. }
  483. }
  484. int
  485. nva3_pm_clocks_set(struct drm_device *dev, void *pre_state)
  486. {
  487. struct drm_nouveau_private *dev_priv = dev->dev_private;
  488. struct nva3_pm_state *info = pre_state;
  489. unsigned long flags;
  490. int ret = -EAGAIN;
  491. /* prevent any new grctx switches from starting */
  492. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  493. nv_wr32(dev, 0x400324, 0x00000000);
  494. nv_wr32(dev, 0x400328, 0x0050001c); /* wait flag 0x1c */
  495. /* wait for any pending grctx switches to complete */
  496. if (!nv_wait_cb(dev, nva3_pm_grcp_idle, dev)) {
  497. NV_ERROR(dev, "pm: ctxprog didn't go idle\n");
  498. goto cleanup;
  499. }
  500. /* freeze PFIFO */
  501. nv_mask(dev, 0x002504, 0x00000001, 0x00000001);
  502. if (!nv_wait(dev, 0x002504, 0x00000010, 0x00000010)) {
  503. NV_ERROR(dev, "pm: fifo didn't go idle\n");
  504. goto cleanup;
  505. }
  506. prog_pll(dev, 0x00, 0x004200, &info->nclk);
  507. prog_pll(dev, 0x01, 0x004220, &info->sclk);
  508. prog_clk(dev, 0x20, &info->unka0);
  509. prog_clk(dev, 0x21, &info->vdec);
  510. if (info->mclk.clk || info->mclk.pll)
  511. prog_mem(dev, info);
  512. ret = 0;
  513. cleanup:
  514. /* unfreeze PFIFO */
  515. nv_mask(dev, 0x002504, 0x00000001, 0x00000000);
  516. /* restore ctxprog to normal */
  517. nv_wr32(dev, 0x400324, 0x00000000);
  518. nv_wr32(dev, 0x400328, 0x0070009c); /* set flag 0x1c */
  519. /* unblock it if necessary */
  520. if (nv_rd32(dev, 0x400308) == 0x0050001c)
  521. nv_mask(dev, 0x400824, 0x10000000, 0x10000000);
  522. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  523. kfree(info);
  524. return ret;
  525. }