radeon_clocks.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include <drm/drmP.h>
  29. #include <drm/radeon_drm.h>
  30. #include "radeon_reg.h"
  31. #include "radeon.h"
  32. #include "atom.h"
  33. /* 10 khz */
  34. uint32_t radeon_legacy_get_engine_clock(struct radeon_device *rdev)
  35. {
  36. struct radeon_pll *spll = &rdev->clock.spll;
  37. uint32_t fb_div, ref_div, post_div, sclk;
  38. fb_div = RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV);
  39. fb_div = (fb_div >> RADEON_SPLL_FB_DIV_SHIFT) & RADEON_SPLL_FB_DIV_MASK;
  40. fb_div <<= 1;
  41. fb_div *= spll->reference_freq;
  42. ref_div =
  43. RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) & RADEON_M_SPLL_REF_DIV_MASK;
  44. if (ref_div == 0)
  45. return 0;
  46. sclk = fb_div / ref_div;
  47. post_div = RREG32_PLL(RADEON_SCLK_CNTL) & RADEON_SCLK_SRC_SEL_MASK;
  48. if (post_div == 2)
  49. sclk >>= 1;
  50. else if (post_div == 3)
  51. sclk >>= 2;
  52. else if (post_div == 4)
  53. sclk >>= 3;
  54. return sclk;
  55. }
  56. /* 10 khz */
  57. uint32_t radeon_legacy_get_memory_clock(struct radeon_device *rdev)
  58. {
  59. struct radeon_pll *mpll = &rdev->clock.mpll;
  60. uint32_t fb_div, ref_div, post_div, mclk;
  61. fb_div = RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV);
  62. fb_div = (fb_div >> RADEON_MPLL_FB_DIV_SHIFT) & RADEON_MPLL_FB_DIV_MASK;
  63. fb_div <<= 1;
  64. fb_div *= mpll->reference_freq;
  65. ref_div =
  66. RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) & RADEON_M_SPLL_REF_DIV_MASK;
  67. if (ref_div == 0)
  68. return 0;
  69. mclk = fb_div / ref_div;
  70. post_div = RREG32_PLL(RADEON_MCLK_CNTL) & 0x7;
  71. if (post_div == 2)
  72. mclk >>= 1;
  73. else if (post_div == 3)
  74. mclk >>= 2;
  75. else if (post_div == 4)
  76. mclk >>= 3;
  77. return mclk;
  78. }
  79. #ifdef CONFIG_OF
  80. /*
  81. * Read XTAL (ref clock), SCLK and MCLK from Open Firmware device
  82. * tree. Hopefully, ATI OF driver is kind enough to fill these
  83. */
  84. static bool radeon_read_clocks_OF(struct drm_device *dev)
  85. {
  86. struct radeon_device *rdev = dev->dev_private;
  87. struct device_node *dp = rdev->pdev->dev.of_node;
  88. const u32 *val;
  89. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  90. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  91. struct radeon_pll *spll = &rdev->clock.spll;
  92. struct radeon_pll *mpll = &rdev->clock.mpll;
  93. if (dp == NULL)
  94. return false;
  95. val = of_get_property(dp, "ATY,RefCLK", NULL);
  96. if (!val || !*val) {
  97. printk(KERN_WARNING "radeonfb: No ATY,RefCLK property !\n");
  98. return false;
  99. }
  100. p1pll->reference_freq = p2pll->reference_freq = (*val) / 10;
  101. p1pll->reference_div = RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
  102. if (p1pll->reference_div < 2)
  103. p1pll->reference_div = 12;
  104. p2pll->reference_div = p1pll->reference_div;
  105. /* These aren't in the device-tree */
  106. if (rdev->family >= CHIP_R420) {
  107. p1pll->pll_in_min = 100;
  108. p1pll->pll_in_max = 1350;
  109. p1pll->pll_out_min = 20000;
  110. p1pll->pll_out_max = 50000;
  111. p2pll->pll_in_min = 100;
  112. p2pll->pll_in_max = 1350;
  113. p2pll->pll_out_min = 20000;
  114. p2pll->pll_out_max = 50000;
  115. } else {
  116. p1pll->pll_in_min = 40;
  117. p1pll->pll_in_max = 500;
  118. p1pll->pll_out_min = 12500;
  119. p1pll->pll_out_max = 35000;
  120. p2pll->pll_in_min = 40;
  121. p2pll->pll_in_max = 500;
  122. p2pll->pll_out_min = 12500;
  123. p2pll->pll_out_max = 35000;
  124. }
  125. /* not sure what the max should be in all cases */
  126. rdev->clock.max_pixel_clock = 35000;
  127. spll->reference_freq = mpll->reference_freq = p1pll->reference_freq;
  128. spll->reference_div = mpll->reference_div =
  129. RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) &
  130. RADEON_M_SPLL_REF_DIV_MASK;
  131. val = of_get_property(dp, "ATY,SCLK", NULL);
  132. if (val && *val)
  133. rdev->clock.default_sclk = (*val) / 10;
  134. else
  135. rdev->clock.default_sclk =
  136. radeon_legacy_get_engine_clock(rdev);
  137. val = of_get_property(dp, "ATY,MCLK", NULL);
  138. if (val && *val)
  139. rdev->clock.default_mclk = (*val) / 10;
  140. else
  141. rdev->clock.default_mclk =
  142. radeon_legacy_get_memory_clock(rdev);
  143. DRM_INFO("Using device-tree clock info\n");
  144. return true;
  145. }
  146. #else
  147. static bool radeon_read_clocks_OF(struct drm_device *dev)
  148. {
  149. return false;
  150. }
  151. #endif /* CONFIG_OF */
  152. void radeon_get_clock_info(struct drm_device *dev)
  153. {
  154. struct radeon_device *rdev = dev->dev_private;
  155. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  156. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  157. struct radeon_pll *dcpll = &rdev->clock.dcpll;
  158. struct radeon_pll *spll = &rdev->clock.spll;
  159. struct radeon_pll *mpll = &rdev->clock.mpll;
  160. int ret;
  161. if (rdev->is_atom_bios)
  162. ret = radeon_atom_get_clock_info(dev);
  163. else
  164. ret = radeon_combios_get_clock_info(dev);
  165. if (!ret)
  166. ret = radeon_read_clocks_OF(dev);
  167. if (ret) {
  168. if (p1pll->reference_div < 2) {
  169. if (!ASIC_IS_AVIVO(rdev)) {
  170. u32 tmp = RREG32_PLL(RADEON_PPLL_REF_DIV);
  171. if (ASIC_IS_R300(rdev))
  172. p1pll->reference_div =
  173. (tmp & R300_PPLL_REF_DIV_ACC_MASK) >> R300_PPLL_REF_DIV_ACC_SHIFT;
  174. else
  175. p1pll->reference_div = tmp & RADEON_PPLL_REF_DIV_MASK;
  176. if (p1pll->reference_div < 2)
  177. p1pll->reference_div = 12;
  178. } else
  179. p1pll->reference_div = 12;
  180. }
  181. if (p2pll->reference_div < 2)
  182. p2pll->reference_div = 12;
  183. if (rdev->family < CHIP_RS600) {
  184. if (spll->reference_div < 2)
  185. spll->reference_div =
  186. RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) &
  187. RADEON_M_SPLL_REF_DIV_MASK;
  188. }
  189. if (mpll->reference_div < 2)
  190. mpll->reference_div = spll->reference_div;
  191. } else {
  192. if (ASIC_IS_AVIVO(rdev)) {
  193. /* TODO FALLBACK */
  194. } else {
  195. DRM_INFO("Using generic clock info\n");
  196. /* may need to be per card */
  197. rdev->clock.max_pixel_clock = 35000;
  198. if (rdev->flags & RADEON_IS_IGP) {
  199. p1pll->reference_freq = 1432;
  200. p2pll->reference_freq = 1432;
  201. spll->reference_freq = 1432;
  202. mpll->reference_freq = 1432;
  203. } else {
  204. p1pll->reference_freq = 2700;
  205. p2pll->reference_freq = 2700;
  206. spll->reference_freq = 2700;
  207. mpll->reference_freq = 2700;
  208. }
  209. p1pll->reference_div =
  210. RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
  211. if (p1pll->reference_div < 2)
  212. p1pll->reference_div = 12;
  213. p2pll->reference_div = p1pll->reference_div;
  214. if (rdev->family >= CHIP_R420) {
  215. p1pll->pll_in_min = 100;
  216. p1pll->pll_in_max = 1350;
  217. p1pll->pll_out_min = 20000;
  218. p1pll->pll_out_max = 50000;
  219. p2pll->pll_in_min = 100;
  220. p2pll->pll_in_max = 1350;
  221. p2pll->pll_out_min = 20000;
  222. p2pll->pll_out_max = 50000;
  223. } else {
  224. p1pll->pll_in_min = 40;
  225. p1pll->pll_in_max = 500;
  226. p1pll->pll_out_min = 12500;
  227. p1pll->pll_out_max = 35000;
  228. p2pll->pll_in_min = 40;
  229. p2pll->pll_in_max = 500;
  230. p2pll->pll_out_min = 12500;
  231. p2pll->pll_out_max = 35000;
  232. }
  233. spll->reference_div =
  234. RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) &
  235. RADEON_M_SPLL_REF_DIV_MASK;
  236. mpll->reference_div = spll->reference_div;
  237. rdev->clock.default_sclk =
  238. radeon_legacy_get_engine_clock(rdev);
  239. rdev->clock.default_mclk =
  240. radeon_legacy_get_memory_clock(rdev);
  241. }
  242. }
  243. /* pixel clocks */
  244. if (ASIC_IS_AVIVO(rdev)) {
  245. p1pll->min_post_div = 2;
  246. p1pll->max_post_div = 0x7f;
  247. p1pll->min_frac_feedback_div = 0;
  248. p1pll->max_frac_feedback_div = 9;
  249. p2pll->min_post_div = 2;
  250. p2pll->max_post_div = 0x7f;
  251. p2pll->min_frac_feedback_div = 0;
  252. p2pll->max_frac_feedback_div = 9;
  253. } else {
  254. p1pll->min_post_div = 1;
  255. p1pll->max_post_div = 16;
  256. p1pll->min_frac_feedback_div = 0;
  257. p1pll->max_frac_feedback_div = 0;
  258. p2pll->min_post_div = 1;
  259. p2pll->max_post_div = 12;
  260. p2pll->min_frac_feedback_div = 0;
  261. p2pll->max_frac_feedback_div = 0;
  262. }
  263. /* dcpll is DCE4 only */
  264. dcpll->min_post_div = 2;
  265. dcpll->max_post_div = 0x7f;
  266. dcpll->min_frac_feedback_div = 0;
  267. dcpll->max_frac_feedback_div = 9;
  268. dcpll->min_ref_div = 2;
  269. dcpll->max_ref_div = 0x3ff;
  270. dcpll->min_feedback_div = 4;
  271. dcpll->max_feedback_div = 0xfff;
  272. dcpll->best_vco = 0;
  273. p1pll->min_ref_div = 2;
  274. p1pll->max_ref_div = 0x3ff;
  275. p1pll->min_feedback_div = 4;
  276. p1pll->max_feedback_div = 0x7ff;
  277. p1pll->best_vco = 0;
  278. p2pll->min_ref_div = 2;
  279. p2pll->max_ref_div = 0x3ff;
  280. p2pll->min_feedback_div = 4;
  281. p2pll->max_feedback_div = 0x7ff;
  282. p2pll->best_vco = 0;
  283. /* system clock */
  284. spll->min_post_div = 1;
  285. spll->max_post_div = 1;
  286. spll->min_ref_div = 2;
  287. spll->max_ref_div = 0xff;
  288. spll->min_feedback_div = 4;
  289. spll->max_feedback_div = 0xff;
  290. spll->best_vco = 0;
  291. /* memory clock */
  292. mpll->min_post_div = 1;
  293. mpll->max_post_div = 1;
  294. mpll->min_ref_div = 2;
  295. mpll->max_ref_div = 0xff;
  296. mpll->min_feedback_div = 4;
  297. mpll->max_feedback_div = 0xff;
  298. mpll->best_vco = 0;
  299. if (!rdev->clock.default_sclk)
  300. rdev->clock.default_sclk = radeon_get_engine_clock(rdev);
  301. if ((!rdev->clock.default_mclk) && rdev->asic->pm.get_memory_clock)
  302. rdev->clock.default_mclk = radeon_get_memory_clock(rdev);
  303. rdev->pm.current_sclk = rdev->clock.default_sclk;
  304. rdev->pm.current_mclk = rdev->clock.default_mclk;
  305. }
  306. /* 10 khz */
  307. static uint32_t calc_eng_mem_clock(struct radeon_device *rdev,
  308. uint32_t req_clock,
  309. int *fb_div, int *post_div)
  310. {
  311. struct radeon_pll *spll = &rdev->clock.spll;
  312. int ref_div = spll->reference_div;
  313. if (!ref_div)
  314. ref_div =
  315. RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) &
  316. RADEON_M_SPLL_REF_DIV_MASK;
  317. if (req_clock < 15000) {
  318. *post_div = 8;
  319. req_clock *= 8;
  320. } else if (req_clock < 30000) {
  321. *post_div = 4;
  322. req_clock *= 4;
  323. } else if (req_clock < 60000) {
  324. *post_div = 2;
  325. req_clock *= 2;
  326. } else
  327. *post_div = 1;
  328. req_clock *= ref_div;
  329. req_clock += spll->reference_freq;
  330. req_clock /= (2 * spll->reference_freq);
  331. *fb_div = req_clock & 0xff;
  332. req_clock = (req_clock & 0xffff) << 1;
  333. req_clock *= spll->reference_freq;
  334. req_clock /= ref_div;
  335. req_clock /= *post_div;
  336. return req_clock;
  337. }
  338. /* 10 khz */
  339. void radeon_legacy_set_engine_clock(struct radeon_device *rdev,
  340. uint32_t eng_clock)
  341. {
  342. uint32_t tmp;
  343. int fb_div, post_div;
  344. /* XXX: wait for idle */
  345. eng_clock = calc_eng_mem_clock(rdev, eng_clock, &fb_div, &post_div);
  346. tmp = RREG32_PLL(RADEON_CLK_PIN_CNTL);
  347. tmp &= ~RADEON_DONT_USE_XTALIN;
  348. WREG32_PLL(RADEON_CLK_PIN_CNTL, tmp);
  349. tmp = RREG32_PLL(RADEON_SCLK_CNTL);
  350. tmp &= ~RADEON_SCLK_SRC_SEL_MASK;
  351. WREG32_PLL(RADEON_SCLK_CNTL, tmp);
  352. udelay(10);
  353. tmp = RREG32_PLL(RADEON_SPLL_CNTL);
  354. tmp |= RADEON_SPLL_SLEEP;
  355. WREG32_PLL(RADEON_SPLL_CNTL, tmp);
  356. udelay(2);
  357. tmp = RREG32_PLL(RADEON_SPLL_CNTL);
  358. tmp |= RADEON_SPLL_RESET;
  359. WREG32_PLL(RADEON_SPLL_CNTL, tmp);
  360. udelay(200);
  361. tmp = RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV);
  362. tmp &= ~(RADEON_SPLL_FB_DIV_MASK << RADEON_SPLL_FB_DIV_SHIFT);
  363. tmp |= (fb_div & RADEON_SPLL_FB_DIV_MASK) << RADEON_SPLL_FB_DIV_SHIFT;
  364. WREG32_PLL(RADEON_M_SPLL_REF_FB_DIV, tmp);
  365. /* XXX: verify on different asics */
  366. tmp = RREG32_PLL(RADEON_SPLL_CNTL);
  367. tmp &= ~RADEON_SPLL_PVG_MASK;
  368. if ((eng_clock * post_div) >= 90000)
  369. tmp |= (0x7 << RADEON_SPLL_PVG_SHIFT);
  370. else
  371. tmp |= (0x4 << RADEON_SPLL_PVG_SHIFT);
  372. WREG32_PLL(RADEON_SPLL_CNTL, tmp);
  373. tmp = RREG32_PLL(RADEON_SPLL_CNTL);
  374. tmp &= ~RADEON_SPLL_SLEEP;
  375. WREG32_PLL(RADEON_SPLL_CNTL, tmp);
  376. udelay(2);
  377. tmp = RREG32_PLL(RADEON_SPLL_CNTL);
  378. tmp &= ~RADEON_SPLL_RESET;
  379. WREG32_PLL(RADEON_SPLL_CNTL, tmp);
  380. udelay(200);
  381. tmp = RREG32_PLL(RADEON_SCLK_CNTL);
  382. tmp &= ~RADEON_SCLK_SRC_SEL_MASK;
  383. switch (post_div) {
  384. case 1:
  385. default:
  386. tmp |= 1;
  387. break;
  388. case 2:
  389. tmp |= 2;
  390. break;
  391. case 4:
  392. tmp |= 3;
  393. break;
  394. case 8:
  395. tmp |= 4;
  396. break;
  397. }
  398. WREG32_PLL(RADEON_SCLK_CNTL, tmp);
  399. udelay(20);
  400. tmp = RREG32_PLL(RADEON_CLK_PIN_CNTL);
  401. tmp |= RADEON_DONT_USE_XTALIN;
  402. WREG32_PLL(RADEON_CLK_PIN_CNTL, tmp);
  403. udelay(10);
  404. }
  405. void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable)
  406. {
  407. uint32_t tmp;
  408. if (enable) {
  409. if (rdev->flags & RADEON_SINGLE_CRTC) {
  410. tmp = RREG32_PLL(RADEON_SCLK_CNTL);
  411. if ((RREG32(RADEON_CONFIG_CNTL) &
  412. RADEON_CFG_ATI_REV_ID_MASK) >
  413. RADEON_CFG_ATI_REV_A13) {
  414. tmp &=
  415. ~(RADEON_SCLK_FORCE_CP |
  416. RADEON_SCLK_FORCE_RB);
  417. }
  418. tmp &=
  419. ~(RADEON_SCLK_FORCE_HDP | RADEON_SCLK_FORCE_DISP1 |
  420. RADEON_SCLK_FORCE_TOP | RADEON_SCLK_FORCE_SE |
  421. RADEON_SCLK_FORCE_IDCT | RADEON_SCLK_FORCE_RE |
  422. RADEON_SCLK_FORCE_PB | RADEON_SCLK_FORCE_TAM |
  423. RADEON_SCLK_FORCE_TDM);
  424. WREG32_PLL(RADEON_SCLK_CNTL, tmp);
  425. } else if (ASIC_IS_R300(rdev)) {
  426. if ((rdev->family == CHIP_RS400) ||
  427. (rdev->family == CHIP_RS480)) {
  428. tmp = RREG32_PLL(RADEON_SCLK_CNTL);
  429. tmp &=
  430. ~(RADEON_SCLK_FORCE_DISP2 |
  431. RADEON_SCLK_FORCE_CP |
  432. RADEON_SCLK_FORCE_HDP |
  433. RADEON_SCLK_FORCE_DISP1 |
  434. RADEON_SCLK_FORCE_TOP |
  435. RADEON_SCLK_FORCE_E2 | R300_SCLK_FORCE_VAP
  436. | RADEON_SCLK_FORCE_IDCT |
  437. RADEON_SCLK_FORCE_VIP | R300_SCLK_FORCE_SR
  438. | R300_SCLK_FORCE_PX | R300_SCLK_FORCE_TX
  439. | R300_SCLK_FORCE_US |
  440. RADEON_SCLK_FORCE_TV_SCLK |
  441. R300_SCLK_FORCE_SU |
  442. RADEON_SCLK_FORCE_OV0);
  443. tmp |= RADEON_DYN_STOP_LAT_MASK;
  444. tmp |=
  445. RADEON_SCLK_FORCE_TOP |
  446. RADEON_SCLK_FORCE_VIP;
  447. WREG32_PLL(RADEON_SCLK_CNTL, tmp);
  448. tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
  449. tmp &= ~RADEON_SCLK_MORE_FORCEON;
  450. tmp |= RADEON_SCLK_MORE_MAX_DYN_STOP_LAT;
  451. WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
  452. tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
  453. tmp |= (RADEON_PIXCLK_ALWAYS_ONb |
  454. RADEON_PIXCLK_DAC_ALWAYS_ONb);
  455. WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
  456. tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  457. tmp |= (RADEON_PIX2CLK_ALWAYS_ONb |
  458. RADEON_PIX2CLK_DAC_ALWAYS_ONb |
  459. RADEON_DISP_TVOUT_PIXCLK_TV_ALWAYS_ONb |
  460. R300_DVOCLK_ALWAYS_ONb |
  461. RADEON_PIXCLK_BLEND_ALWAYS_ONb |
  462. RADEON_PIXCLK_GV_ALWAYS_ONb |
  463. R300_PIXCLK_DVO_ALWAYS_ONb |
  464. RADEON_PIXCLK_LVDS_ALWAYS_ONb |
  465. RADEON_PIXCLK_TMDS_ALWAYS_ONb |
  466. R300_PIXCLK_TRANS_ALWAYS_ONb |
  467. R300_PIXCLK_TVO_ALWAYS_ONb |
  468. R300_P2G2CLK_ALWAYS_ONb |
  469. R300_P2G2CLK_DAC_ALWAYS_ONb);
  470. WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
  471. } else if (rdev->family >= CHIP_RV350) {
  472. tmp = RREG32_PLL(R300_SCLK_CNTL2);
  473. tmp &= ~(R300_SCLK_FORCE_TCL |
  474. R300_SCLK_FORCE_GA |
  475. R300_SCLK_FORCE_CBA);
  476. tmp |= (R300_SCLK_TCL_MAX_DYN_STOP_LAT |
  477. R300_SCLK_GA_MAX_DYN_STOP_LAT |
  478. R300_SCLK_CBA_MAX_DYN_STOP_LAT);
  479. WREG32_PLL(R300_SCLK_CNTL2, tmp);
  480. tmp = RREG32_PLL(RADEON_SCLK_CNTL);
  481. tmp &=
  482. ~(RADEON_SCLK_FORCE_DISP2 |
  483. RADEON_SCLK_FORCE_CP |
  484. RADEON_SCLK_FORCE_HDP |
  485. RADEON_SCLK_FORCE_DISP1 |
  486. RADEON_SCLK_FORCE_TOP |
  487. RADEON_SCLK_FORCE_E2 | R300_SCLK_FORCE_VAP
  488. | RADEON_SCLK_FORCE_IDCT |
  489. RADEON_SCLK_FORCE_VIP | R300_SCLK_FORCE_SR
  490. | R300_SCLK_FORCE_PX | R300_SCLK_FORCE_TX
  491. | R300_SCLK_FORCE_US |
  492. RADEON_SCLK_FORCE_TV_SCLK |
  493. R300_SCLK_FORCE_SU |
  494. RADEON_SCLK_FORCE_OV0);
  495. tmp |= RADEON_DYN_STOP_LAT_MASK;
  496. WREG32_PLL(RADEON_SCLK_CNTL, tmp);
  497. tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
  498. tmp &= ~RADEON_SCLK_MORE_FORCEON;
  499. tmp |= RADEON_SCLK_MORE_MAX_DYN_STOP_LAT;
  500. WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
  501. tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
  502. tmp |= (RADEON_PIXCLK_ALWAYS_ONb |
  503. RADEON_PIXCLK_DAC_ALWAYS_ONb);
  504. WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
  505. tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  506. tmp |= (RADEON_PIX2CLK_ALWAYS_ONb |
  507. RADEON_PIX2CLK_DAC_ALWAYS_ONb |
  508. RADEON_DISP_TVOUT_PIXCLK_TV_ALWAYS_ONb |
  509. R300_DVOCLK_ALWAYS_ONb |
  510. RADEON_PIXCLK_BLEND_ALWAYS_ONb |
  511. RADEON_PIXCLK_GV_ALWAYS_ONb |
  512. R300_PIXCLK_DVO_ALWAYS_ONb |
  513. RADEON_PIXCLK_LVDS_ALWAYS_ONb |
  514. RADEON_PIXCLK_TMDS_ALWAYS_ONb |
  515. R300_PIXCLK_TRANS_ALWAYS_ONb |
  516. R300_PIXCLK_TVO_ALWAYS_ONb |
  517. R300_P2G2CLK_ALWAYS_ONb |
  518. R300_P2G2CLK_DAC_ALWAYS_ONb);
  519. WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
  520. tmp = RREG32_PLL(RADEON_MCLK_MISC);
  521. tmp |= (RADEON_MC_MCLK_DYN_ENABLE |
  522. RADEON_IO_MCLK_DYN_ENABLE);
  523. WREG32_PLL(RADEON_MCLK_MISC, tmp);
  524. tmp = RREG32_PLL(RADEON_MCLK_CNTL);
  525. tmp |= (RADEON_FORCEON_MCLKA |
  526. RADEON_FORCEON_MCLKB);
  527. tmp &= ~(RADEON_FORCEON_YCLKA |
  528. RADEON_FORCEON_YCLKB |
  529. RADEON_FORCEON_MC);
  530. /* Some releases of vbios have set DISABLE_MC_MCLKA
  531. and DISABLE_MC_MCLKB bits in the vbios table. Setting these
  532. bits will cause H/W hang when reading video memory with dynamic clocking
  533. enabled. */
  534. if ((tmp & R300_DISABLE_MC_MCLKA) &&
  535. (tmp & R300_DISABLE_MC_MCLKB)) {
  536. /* If both bits are set, then check the active channels */
  537. tmp = RREG32_PLL(RADEON_MCLK_CNTL);
  538. if (rdev->mc.vram_width == 64) {
  539. if (RREG32(RADEON_MEM_CNTL) &
  540. R300_MEM_USE_CD_CH_ONLY)
  541. tmp &=
  542. ~R300_DISABLE_MC_MCLKB;
  543. else
  544. tmp &=
  545. ~R300_DISABLE_MC_MCLKA;
  546. } else {
  547. tmp &= ~(R300_DISABLE_MC_MCLKA |
  548. R300_DISABLE_MC_MCLKB);
  549. }
  550. }
  551. WREG32_PLL(RADEON_MCLK_CNTL, tmp);
  552. } else {
  553. tmp = RREG32_PLL(RADEON_SCLK_CNTL);
  554. tmp &= ~(R300_SCLK_FORCE_VAP);
  555. tmp |= RADEON_SCLK_FORCE_CP;
  556. WREG32_PLL(RADEON_SCLK_CNTL, tmp);
  557. mdelay(15);
  558. tmp = RREG32_PLL(R300_SCLK_CNTL2);
  559. tmp &= ~(R300_SCLK_FORCE_TCL |
  560. R300_SCLK_FORCE_GA |
  561. R300_SCLK_FORCE_CBA);
  562. WREG32_PLL(R300_SCLK_CNTL2, tmp);
  563. }
  564. } else {
  565. tmp = RREG32_PLL(RADEON_CLK_PWRMGT_CNTL);
  566. tmp &= ~(RADEON_ACTIVE_HILO_LAT_MASK |
  567. RADEON_DISP_DYN_STOP_LAT_MASK |
  568. RADEON_DYN_STOP_MODE_MASK);
  569. tmp |= (RADEON_ENGIN_DYNCLK_MODE |
  570. (0x01 << RADEON_ACTIVE_HILO_LAT_SHIFT));
  571. WREG32_PLL(RADEON_CLK_PWRMGT_CNTL, tmp);
  572. mdelay(15);
  573. tmp = RREG32_PLL(RADEON_CLK_PIN_CNTL);
  574. tmp |= RADEON_SCLK_DYN_START_CNTL;
  575. WREG32_PLL(RADEON_CLK_PIN_CNTL, tmp);
  576. mdelay(15);
  577. /* When DRI is enabled, setting DYN_STOP_LAT to zero can cause some R200
  578. to lockup randomly, leave them as set by BIOS.
  579. */
  580. tmp = RREG32_PLL(RADEON_SCLK_CNTL);
  581. /*tmp &= RADEON_SCLK_SRC_SEL_MASK; */
  582. tmp &= ~RADEON_SCLK_FORCEON_MASK;
  583. /*RAGE_6::A11 A12 A12N1 A13, RV250::A11 A12, R300 */
  584. if (((rdev->family == CHIP_RV250) &&
  585. ((RREG32(RADEON_CONFIG_CNTL) &
  586. RADEON_CFG_ATI_REV_ID_MASK) <
  587. RADEON_CFG_ATI_REV_A13))
  588. || ((rdev->family == CHIP_RV100)
  589. &&
  590. ((RREG32(RADEON_CONFIG_CNTL) &
  591. RADEON_CFG_ATI_REV_ID_MASK) <=
  592. RADEON_CFG_ATI_REV_A13))) {
  593. tmp |= RADEON_SCLK_FORCE_CP;
  594. tmp |= RADEON_SCLK_FORCE_VIP;
  595. }
  596. WREG32_PLL(RADEON_SCLK_CNTL, tmp);
  597. if ((rdev->family == CHIP_RV200) ||
  598. (rdev->family == CHIP_RV250) ||
  599. (rdev->family == CHIP_RV280)) {
  600. tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
  601. tmp &= ~RADEON_SCLK_MORE_FORCEON;
  602. /* RV200::A11 A12 RV250::A11 A12 */
  603. if (((rdev->family == CHIP_RV200) ||
  604. (rdev->family == CHIP_RV250)) &&
  605. ((RREG32(RADEON_CONFIG_CNTL) &
  606. RADEON_CFG_ATI_REV_ID_MASK) <
  607. RADEON_CFG_ATI_REV_A13)) {
  608. tmp |= RADEON_SCLK_MORE_FORCEON;
  609. }
  610. WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
  611. mdelay(15);
  612. }
  613. /* RV200::A11 A12, RV250::A11 A12 */
  614. if (((rdev->family == CHIP_RV200) ||
  615. (rdev->family == CHIP_RV250)) &&
  616. ((RREG32(RADEON_CONFIG_CNTL) &
  617. RADEON_CFG_ATI_REV_ID_MASK) <
  618. RADEON_CFG_ATI_REV_A13)) {
  619. tmp = RREG32_PLL(RADEON_PLL_PWRMGT_CNTL);
  620. tmp |= RADEON_TCL_BYPASS_DISABLE;
  621. WREG32_PLL(RADEON_PLL_PWRMGT_CNTL, tmp);
  622. }
  623. mdelay(15);
  624. /*enable dynamic mode for display clocks (PIXCLK and PIX2CLK) */
  625. tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  626. tmp |= (RADEON_PIX2CLK_ALWAYS_ONb |
  627. RADEON_PIX2CLK_DAC_ALWAYS_ONb |
  628. RADEON_PIXCLK_BLEND_ALWAYS_ONb |
  629. RADEON_PIXCLK_GV_ALWAYS_ONb |
  630. RADEON_PIXCLK_DIG_TMDS_ALWAYS_ONb |
  631. RADEON_PIXCLK_LVDS_ALWAYS_ONb |
  632. RADEON_PIXCLK_TMDS_ALWAYS_ONb);
  633. WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
  634. mdelay(15);
  635. tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
  636. tmp |= (RADEON_PIXCLK_ALWAYS_ONb |
  637. RADEON_PIXCLK_DAC_ALWAYS_ONb);
  638. WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
  639. mdelay(15);
  640. }
  641. } else {
  642. /* Turn everything OFF (ForceON to everything) */
  643. if (rdev->flags & RADEON_SINGLE_CRTC) {
  644. tmp = RREG32_PLL(RADEON_SCLK_CNTL);
  645. tmp |= (RADEON_SCLK_FORCE_CP | RADEON_SCLK_FORCE_HDP |
  646. RADEON_SCLK_FORCE_DISP1 | RADEON_SCLK_FORCE_TOP
  647. | RADEON_SCLK_FORCE_E2 | RADEON_SCLK_FORCE_SE |
  648. RADEON_SCLK_FORCE_IDCT | RADEON_SCLK_FORCE_VIP |
  649. RADEON_SCLK_FORCE_RE | RADEON_SCLK_FORCE_PB |
  650. RADEON_SCLK_FORCE_TAM | RADEON_SCLK_FORCE_TDM |
  651. RADEON_SCLK_FORCE_RB);
  652. WREG32_PLL(RADEON_SCLK_CNTL, tmp);
  653. } else if ((rdev->family == CHIP_RS400) ||
  654. (rdev->family == CHIP_RS480)) {
  655. tmp = RREG32_PLL(RADEON_SCLK_CNTL);
  656. tmp |= (RADEON_SCLK_FORCE_DISP2 | RADEON_SCLK_FORCE_CP |
  657. RADEON_SCLK_FORCE_HDP | RADEON_SCLK_FORCE_DISP1
  658. | RADEON_SCLK_FORCE_TOP | RADEON_SCLK_FORCE_E2 |
  659. R300_SCLK_FORCE_VAP | RADEON_SCLK_FORCE_IDCT |
  660. RADEON_SCLK_FORCE_VIP | R300_SCLK_FORCE_SR |
  661. R300_SCLK_FORCE_PX | R300_SCLK_FORCE_TX |
  662. R300_SCLK_FORCE_US | RADEON_SCLK_FORCE_TV_SCLK |
  663. R300_SCLK_FORCE_SU | RADEON_SCLK_FORCE_OV0);
  664. WREG32_PLL(RADEON_SCLK_CNTL, tmp);
  665. tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
  666. tmp |= RADEON_SCLK_MORE_FORCEON;
  667. WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
  668. tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
  669. tmp &= ~(RADEON_PIXCLK_ALWAYS_ONb |
  670. RADEON_PIXCLK_DAC_ALWAYS_ONb |
  671. R300_DISP_DAC_PIXCLK_DAC_BLANK_OFF);
  672. WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
  673. tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  674. tmp &= ~(RADEON_PIX2CLK_ALWAYS_ONb |
  675. RADEON_PIX2CLK_DAC_ALWAYS_ONb |
  676. RADEON_DISP_TVOUT_PIXCLK_TV_ALWAYS_ONb |
  677. R300_DVOCLK_ALWAYS_ONb |
  678. RADEON_PIXCLK_BLEND_ALWAYS_ONb |
  679. RADEON_PIXCLK_GV_ALWAYS_ONb |
  680. R300_PIXCLK_DVO_ALWAYS_ONb |
  681. RADEON_PIXCLK_LVDS_ALWAYS_ONb |
  682. RADEON_PIXCLK_TMDS_ALWAYS_ONb |
  683. R300_PIXCLK_TRANS_ALWAYS_ONb |
  684. R300_PIXCLK_TVO_ALWAYS_ONb |
  685. R300_P2G2CLK_ALWAYS_ONb |
  686. R300_P2G2CLK_DAC_ALWAYS_ONb |
  687. R300_DISP_DAC_PIXCLK_DAC2_BLANK_OFF);
  688. WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
  689. } else if (rdev->family >= CHIP_RV350) {
  690. /* for RV350/M10, no delays are required. */
  691. tmp = RREG32_PLL(R300_SCLK_CNTL2);
  692. tmp |= (R300_SCLK_FORCE_TCL |
  693. R300_SCLK_FORCE_GA | R300_SCLK_FORCE_CBA);
  694. WREG32_PLL(R300_SCLK_CNTL2, tmp);
  695. tmp = RREG32_PLL(RADEON_SCLK_CNTL);
  696. tmp |= (RADEON_SCLK_FORCE_DISP2 | RADEON_SCLK_FORCE_CP |
  697. RADEON_SCLK_FORCE_HDP | RADEON_SCLK_FORCE_DISP1
  698. | RADEON_SCLK_FORCE_TOP | RADEON_SCLK_FORCE_E2 |
  699. R300_SCLK_FORCE_VAP | RADEON_SCLK_FORCE_IDCT |
  700. RADEON_SCLK_FORCE_VIP | R300_SCLK_FORCE_SR |
  701. R300_SCLK_FORCE_PX | R300_SCLK_FORCE_TX |
  702. R300_SCLK_FORCE_US | RADEON_SCLK_FORCE_TV_SCLK |
  703. R300_SCLK_FORCE_SU | RADEON_SCLK_FORCE_OV0);
  704. WREG32_PLL(RADEON_SCLK_CNTL, tmp);
  705. tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
  706. tmp |= RADEON_SCLK_MORE_FORCEON;
  707. WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
  708. tmp = RREG32_PLL(RADEON_MCLK_CNTL);
  709. tmp |= (RADEON_FORCEON_MCLKA |
  710. RADEON_FORCEON_MCLKB |
  711. RADEON_FORCEON_YCLKA |
  712. RADEON_FORCEON_YCLKB | RADEON_FORCEON_MC);
  713. WREG32_PLL(RADEON_MCLK_CNTL, tmp);
  714. tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
  715. tmp &= ~(RADEON_PIXCLK_ALWAYS_ONb |
  716. RADEON_PIXCLK_DAC_ALWAYS_ONb |
  717. R300_DISP_DAC_PIXCLK_DAC_BLANK_OFF);
  718. WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
  719. tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  720. tmp &= ~(RADEON_PIX2CLK_ALWAYS_ONb |
  721. RADEON_PIX2CLK_DAC_ALWAYS_ONb |
  722. RADEON_DISP_TVOUT_PIXCLK_TV_ALWAYS_ONb |
  723. R300_DVOCLK_ALWAYS_ONb |
  724. RADEON_PIXCLK_BLEND_ALWAYS_ONb |
  725. RADEON_PIXCLK_GV_ALWAYS_ONb |
  726. R300_PIXCLK_DVO_ALWAYS_ONb |
  727. RADEON_PIXCLK_LVDS_ALWAYS_ONb |
  728. RADEON_PIXCLK_TMDS_ALWAYS_ONb |
  729. R300_PIXCLK_TRANS_ALWAYS_ONb |
  730. R300_PIXCLK_TVO_ALWAYS_ONb |
  731. R300_P2G2CLK_ALWAYS_ONb |
  732. R300_P2G2CLK_DAC_ALWAYS_ONb |
  733. R300_DISP_DAC_PIXCLK_DAC2_BLANK_OFF);
  734. WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
  735. } else {
  736. tmp = RREG32_PLL(RADEON_SCLK_CNTL);
  737. tmp |= (RADEON_SCLK_FORCE_CP | RADEON_SCLK_FORCE_E2);
  738. tmp |= RADEON_SCLK_FORCE_SE;
  739. if (rdev->flags & RADEON_SINGLE_CRTC) {
  740. tmp |= (RADEON_SCLK_FORCE_RB |
  741. RADEON_SCLK_FORCE_TDM |
  742. RADEON_SCLK_FORCE_TAM |
  743. RADEON_SCLK_FORCE_PB |
  744. RADEON_SCLK_FORCE_RE |
  745. RADEON_SCLK_FORCE_VIP |
  746. RADEON_SCLK_FORCE_IDCT |
  747. RADEON_SCLK_FORCE_TOP |
  748. RADEON_SCLK_FORCE_DISP1 |
  749. RADEON_SCLK_FORCE_DISP2 |
  750. RADEON_SCLK_FORCE_HDP);
  751. } else if ((rdev->family == CHIP_R300) ||
  752. (rdev->family == CHIP_R350)) {
  753. tmp |= (RADEON_SCLK_FORCE_HDP |
  754. RADEON_SCLK_FORCE_DISP1 |
  755. RADEON_SCLK_FORCE_DISP2 |
  756. RADEON_SCLK_FORCE_TOP |
  757. RADEON_SCLK_FORCE_IDCT |
  758. RADEON_SCLK_FORCE_VIP);
  759. }
  760. WREG32_PLL(RADEON_SCLK_CNTL, tmp);
  761. mdelay(16);
  762. if ((rdev->family == CHIP_R300) ||
  763. (rdev->family == CHIP_R350)) {
  764. tmp = RREG32_PLL(R300_SCLK_CNTL2);
  765. tmp |= (R300_SCLK_FORCE_TCL |
  766. R300_SCLK_FORCE_GA |
  767. R300_SCLK_FORCE_CBA);
  768. WREG32_PLL(R300_SCLK_CNTL2, tmp);
  769. mdelay(16);
  770. }
  771. if (rdev->flags & RADEON_IS_IGP) {
  772. tmp = RREG32_PLL(RADEON_MCLK_CNTL);
  773. tmp &= ~(RADEON_FORCEON_MCLKA |
  774. RADEON_FORCEON_YCLKA);
  775. WREG32_PLL(RADEON_MCLK_CNTL, tmp);
  776. mdelay(16);
  777. }
  778. if ((rdev->family == CHIP_RV200) ||
  779. (rdev->family == CHIP_RV250) ||
  780. (rdev->family == CHIP_RV280)) {
  781. tmp = RREG32_PLL(RADEON_SCLK_MORE_CNTL);
  782. tmp |= RADEON_SCLK_MORE_FORCEON;
  783. WREG32_PLL(RADEON_SCLK_MORE_CNTL, tmp);
  784. mdelay(16);
  785. }
  786. tmp = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  787. tmp &= ~(RADEON_PIX2CLK_ALWAYS_ONb |
  788. RADEON_PIX2CLK_DAC_ALWAYS_ONb |
  789. RADEON_PIXCLK_BLEND_ALWAYS_ONb |
  790. RADEON_PIXCLK_GV_ALWAYS_ONb |
  791. RADEON_PIXCLK_DIG_TMDS_ALWAYS_ONb |
  792. RADEON_PIXCLK_LVDS_ALWAYS_ONb |
  793. RADEON_PIXCLK_TMDS_ALWAYS_ONb);
  794. WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
  795. mdelay(16);
  796. tmp = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
  797. tmp &= ~(RADEON_PIXCLK_ALWAYS_ONb |
  798. RADEON_PIXCLK_DAC_ALWAYS_ONb);
  799. WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
  800. }
  801. }
  802. }