nva3_pm.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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. };
  221. void *
  222. nva3_pm_clocks_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl)
  223. {
  224. struct nva3_pm_state *info;
  225. u8 ramcfg_cnt;
  226. int ret;
  227. info = kzalloc(sizeof(*info), GFP_KERNEL);
  228. if (!info)
  229. return ERR_PTR(-ENOMEM);
  230. ret = calc_clk(dev, 0x10, 0x4200, perflvl->core, &info->nclk);
  231. if (ret < 0)
  232. goto out;
  233. ret = calc_clk(dev, 0x11, 0x4220, perflvl->shader, &info->sclk);
  234. if (ret < 0)
  235. goto out;
  236. ret = calc_clk(dev, 0x12, 0x4000, perflvl->memory, &info->mclk);
  237. if (ret < 0)
  238. goto out;
  239. ret = calc_clk(dev, 0x20, 0x0000, perflvl->unka0, &info->unka0);
  240. if (ret < 0)
  241. goto out;
  242. ret = calc_clk(dev, 0x21, 0x0000, perflvl->vdec, &info->vdec);
  243. if (ret < 0)
  244. goto out;
  245. info->rammap = nouveau_perf_rammap(dev, perflvl->memory,
  246. &info->rammap_ver,
  247. &info->rammap_len,
  248. &ramcfg_cnt, &info->ramcfg_len);
  249. if (info->rammap_ver != 0x10 || info->rammap_len < 5)
  250. info->rammap = NULL;
  251. info->ramcfg = nouveau_perf_ramcfg(dev, perflvl->memory,
  252. &info->rammap_ver,
  253. &info->ramcfg_len);
  254. if (info->rammap_ver != 0x10)
  255. info->ramcfg = NULL;
  256. info->perflvl = perflvl;
  257. out:
  258. if (ret < 0) {
  259. kfree(info);
  260. info = ERR_PTR(ret);
  261. }
  262. return info;
  263. }
  264. static bool
  265. nva3_pm_grcp_idle(void *data)
  266. {
  267. struct drm_device *dev = data;
  268. if (!(nv_rd32(dev, 0x400304) & 0x00000001))
  269. return true;
  270. if (nv_rd32(dev, 0x400308) == 0x0050001c)
  271. return true;
  272. return false;
  273. }
  274. static void
  275. mclk_precharge(struct nouveau_mem_exec_func *exec)
  276. {
  277. nv_wr32(exec->dev, 0x1002d4, 0x00000001);
  278. }
  279. static void
  280. mclk_refresh(struct nouveau_mem_exec_func *exec)
  281. {
  282. nv_wr32(exec->dev, 0x1002d0, 0x00000001);
  283. }
  284. static void
  285. mclk_refresh_auto(struct nouveau_mem_exec_func *exec, bool enable)
  286. {
  287. nv_wr32(exec->dev, 0x100210, enable ? 0x80000000 : 0x00000000);
  288. }
  289. static void
  290. mclk_refresh_self(struct nouveau_mem_exec_func *exec, bool enable)
  291. {
  292. nv_wr32(exec->dev, 0x1002dc, enable ? 0x00000001 : 0x00000000);
  293. }
  294. static void
  295. mclk_wait(struct nouveau_mem_exec_func *exec, u32 nsec)
  296. {
  297. udelay((nsec + 500) / 1000);
  298. }
  299. static u32
  300. mclk_mrg(struct nouveau_mem_exec_func *exec, int mr)
  301. {
  302. if (mr <= 1)
  303. return nv_rd32(exec->dev, 0x1002c0 + ((mr - 0) * 4));
  304. if (mr <= 3)
  305. return nv_rd32(exec->dev, 0x1002e0 + ((mr - 2) * 4));
  306. return 0;
  307. }
  308. static void
  309. mclk_mrs(struct nouveau_mem_exec_func *exec, int mr, u32 data)
  310. {
  311. struct drm_nouveau_private *dev_priv = exec->dev->dev_private;
  312. if (mr <= 1) {
  313. if (dev_priv->vram_rank_B)
  314. nv_wr32(exec->dev, 0x1002c8 + ((mr - 0) * 4), data);
  315. nv_wr32(exec->dev, 0x1002c0 + ((mr - 0) * 4), data);
  316. } else
  317. if (mr <= 3) {
  318. if (dev_priv->vram_rank_B)
  319. nv_wr32(exec->dev, 0x1002e8 + ((mr - 2) * 4), data);
  320. nv_wr32(exec->dev, 0x1002e0 + ((mr - 2) * 4), data);
  321. }
  322. }
  323. static void
  324. mclk_clock_set(struct nouveau_mem_exec_func *exec)
  325. {
  326. struct drm_device *dev = exec->dev;
  327. struct nva3_pm_state *info = exec->priv;
  328. u32 ctrl;
  329. ctrl = nv_rd32(dev, 0x004000);
  330. if (!(ctrl & 0x00000008) && info->mclk.pll) {
  331. nv_wr32(dev, 0x004000, (ctrl |= 0x00000008));
  332. nv_mask(dev, 0x1110e0, 0x00088000, 0x00088000);
  333. nv_wr32(dev, 0x004018, 0x00001000); /*XXX*/
  334. nv_wr32(dev, 0x004000, (ctrl &= ~0x00000001));
  335. nv_wr32(dev, 0x004004, info->mclk.pll);
  336. nv_wr32(dev, 0x004000, (ctrl |= 0x00000001));
  337. udelay(64);
  338. nv_wr32(dev, 0x004018, 0x10005000); /*XXX*/
  339. udelay(20);
  340. } else
  341. if (!info->mclk.pll) {
  342. nv_mask(dev, 0x004168, 0x003f3040, info->mclk.clk);
  343. nv_wr32(dev, 0x004000, (ctrl |= 0x00000008));
  344. nv_mask(dev, 0x1110e0, 0x00088000, 0x00088000);
  345. nv_wr32(dev, 0x004018, 0x1000d000); /*XXX*/
  346. }
  347. if (info->rammap) {
  348. if (info->ramcfg && (info->rammap[4] & 0x08)) {
  349. u32 unk5a0 = (ROM16(info->ramcfg[5]) << 8) |
  350. info->ramcfg[5];
  351. u32 unk5a4 = ROM16(info->ramcfg[7]);
  352. u32 unk804 = (info->ramcfg[9] & 0xf0) << 16 |
  353. (info->ramcfg[3] & 0x0f) << 16 |
  354. (info->ramcfg[9] & 0x0f) |
  355. 0x80000000;
  356. nv_wr32(dev, 0x1005a0, unk5a0);
  357. nv_wr32(dev, 0x1005a4, unk5a4);
  358. nv_wr32(dev, 0x10f804, unk804);
  359. nv_mask(dev, 0x10053c, 0x00001000, 0x00000000);
  360. } else {
  361. nv_mask(dev, 0x10053c, 0x00001000, 0x00001000);
  362. nv_mask(dev, 0x10f804, 0x80000000, 0x00000000);
  363. }
  364. }
  365. if (info->mclk.pll) {
  366. nv_mask(dev, 0x1110e0, 0x00088000, 0x00011000);
  367. nv_wr32(dev, 0x004000, (ctrl &= ~0x00000008));
  368. }
  369. }
  370. static void
  371. mclk_timing_set(struct nouveau_mem_exec_func *exec)
  372. {
  373. struct drm_device *dev = exec->dev;
  374. struct nva3_pm_state *info = exec->priv;
  375. struct nouveau_pm_level *perflvl = info->perflvl;
  376. int i;
  377. for (i = 0; i < 9; i++)
  378. nv_wr32(dev, 0x100220 + (i * 4), perflvl->timing.reg[i]);
  379. if (info->ramcfg) {
  380. u32 data = (info->ramcfg[2] & 0x08) ? 0x00000000 : 0x00001000;
  381. nv_mask(dev, 0x100200, 0x00001000, data);
  382. }
  383. if (info->ramcfg) {
  384. u32 unk714 = nv_rd32(dev, 0x100714) & ~0xf0000010;
  385. u32 unk718 = nv_rd32(dev, 0x100718) & ~0x00000100;
  386. u32 unk71c = nv_rd32(dev, 0x10071c) & ~0x00000100;
  387. if ( (info->ramcfg[2] & 0x20))
  388. unk714 |= 0xf0000000;
  389. if (!(info->ramcfg[2] & 0x04))
  390. unk714 |= 0x00000010;
  391. nv_wr32(dev, 0x100714, unk714);
  392. if (info->ramcfg[2] & 0x01)
  393. unk71c |= 0x00000100;
  394. nv_wr32(dev, 0x10071c, unk71c);
  395. if (info->ramcfg[2] & 0x02)
  396. unk718 |= 0x00000100;
  397. nv_wr32(dev, 0x100718, unk718);
  398. if (info->ramcfg[2] & 0x10)
  399. nv_wr32(dev, 0x111100, 0x48000000); /*XXX*/
  400. }
  401. }
  402. static void
  403. prog_mem(struct drm_device *dev, struct nva3_pm_state *info)
  404. {
  405. struct nouveau_mem_exec_func exec = {
  406. .dev = dev,
  407. .precharge = mclk_precharge,
  408. .refresh = mclk_refresh,
  409. .refresh_auto = mclk_refresh_auto,
  410. .refresh_self = mclk_refresh_self,
  411. .wait = mclk_wait,
  412. .mrg = mclk_mrg,
  413. .mrs = mclk_mrs,
  414. .clock_set = mclk_clock_set,
  415. .timing_set = mclk_timing_set,
  416. .priv = info
  417. };
  418. u32 ctrl;
  419. ctrl = nv_rd32(dev, 0x004000);
  420. if (ctrl & 0x00000008) {
  421. if (info->mclk.pll) {
  422. nv_mask(dev, 0x004128, 0x00000101, 0x00000101);
  423. nv_wr32(dev, 0x004004, info->mclk.pll);
  424. nv_wr32(dev, 0x004000, (ctrl |= 0x00000001));
  425. nv_wr32(dev, 0x004000, (ctrl &= 0xffffffef));
  426. nv_wait(dev, 0x004000, 0x00020000, 0x00020000);
  427. nv_wr32(dev, 0x004000, (ctrl |= 0x00000010));
  428. nv_wr32(dev, 0x004018, 0x00005000); /*XXX*/
  429. nv_wr32(dev, 0x004000, (ctrl |= 0x00000004));
  430. }
  431. } else {
  432. u32 ssel = 0x00000101;
  433. if (info->mclk.clk)
  434. ssel |= info->mclk.clk;
  435. else
  436. ssel |= 0x00080000; /* 324MHz, shouldn't matter... */
  437. nv_mask(dev, 0x004168, 0x003f3141, ctrl);
  438. }
  439. if (info->ramcfg) {
  440. if (info->ramcfg[2] & 0x10) {
  441. nv_mask(dev, 0x111104, 0x00000600, 0x00000000);
  442. } else {
  443. nv_mask(dev, 0x111100, 0x40000000, 0x40000000);
  444. nv_mask(dev, 0x111104, 0x00000180, 0x00000000);
  445. }
  446. }
  447. if (info->rammap && !(info->rammap[4] & 0x02))
  448. nv_mask(dev, 0x100200, 0x00000800, 0x00000000);
  449. nv_wr32(dev, 0x611200, 0x00003300);
  450. if (!(info->ramcfg[2] & 0x10))
  451. nv_wr32(dev, 0x111100, 0x4c020000); /*XXX*/
  452. nouveau_mem_exec(&exec, info->perflvl);
  453. nv_wr32(dev, 0x611200, 0x00003330);
  454. if (info->rammap && (info->rammap[4] & 0x02))
  455. nv_mask(dev, 0x100200, 0x00000800, 0x00000800);
  456. if (info->ramcfg) {
  457. if (info->ramcfg[2] & 0x10) {
  458. nv_mask(dev, 0x111104, 0x00000180, 0x00000180);
  459. nv_mask(dev, 0x111100, 0x40000000, 0x00000000);
  460. } else {
  461. nv_mask(dev, 0x111104, 0x00000600, 0x00000600);
  462. }
  463. }
  464. if (info->mclk.pll) {
  465. nv_mask(dev, 0x004168, 0x00000001, 0x00000000);
  466. nv_mask(dev, 0x004168, 0x00000100, 0x00000000);
  467. } else {
  468. nv_mask(dev, 0x004000, 0x00000001, 0x00000000);
  469. nv_mask(dev, 0x004128, 0x00000001, 0x00000000);
  470. nv_mask(dev, 0x004128, 0x00000100, 0x00000000);
  471. }
  472. }
  473. int
  474. nva3_pm_clocks_set(struct drm_device *dev, void *pre_state)
  475. {
  476. struct drm_nouveau_private *dev_priv = dev->dev_private;
  477. struct nva3_pm_state *info = pre_state;
  478. unsigned long flags;
  479. int ret = -EAGAIN;
  480. /* prevent any new grctx switches from starting */
  481. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  482. nv_wr32(dev, 0x400324, 0x00000000);
  483. nv_wr32(dev, 0x400328, 0x0050001c); /* wait flag 0x1c */
  484. /* wait for any pending grctx switches to complete */
  485. if (!nv_wait_cb(dev, nva3_pm_grcp_idle, dev)) {
  486. NV_ERROR(dev, "pm: ctxprog didn't go idle\n");
  487. goto cleanup;
  488. }
  489. /* freeze PFIFO */
  490. nv_mask(dev, 0x002504, 0x00000001, 0x00000001);
  491. if (!nv_wait(dev, 0x002504, 0x00000010, 0x00000010)) {
  492. NV_ERROR(dev, "pm: fifo didn't go idle\n");
  493. goto cleanup;
  494. }
  495. prog_pll(dev, 0x00, 0x004200, &info->nclk);
  496. prog_pll(dev, 0x01, 0x004220, &info->sclk);
  497. prog_clk(dev, 0x20, &info->unka0);
  498. prog_clk(dev, 0x21, &info->vdec);
  499. if (info->mclk.clk || info->mclk.pll)
  500. prog_mem(dev, info);
  501. ret = 0;
  502. cleanup:
  503. /* unfreeze PFIFO */
  504. nv_mask(dev, 0x002504, 0x00000001, 0x00000000);
  505. /* restore ctxprog to normal */
  506. nv_wr32(dev, 0x400324, 0x00000000);
  507. nv_wr32(dev, 0x400328, 0x0070009c); /* set flag 0x1c */
  508. /* unblock it if necessary */
  509. if (nv_rd32(dev, 0x400308) == 0x0050001c)
  510. nv_mask(dev, 0x400824, 0x10000000, 0x10000000);
  511. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  512. kfree(info);
  513. return ret;
  514. }