rv6xx_dpm.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159
  1. /*
  2. * Copyright 2011 Advanced Micro Devices, 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: Alex Deucher
  23. */
  24. #include "drmP.h"
  25. #include "radeon.h"
  26. #include "radeon_asic.h"
  27. #include "rv6xxd.h"
  28. #include "r600_dpm.h"
  29. #include "rv6xx_dpm.h"
  30. #include "atom.h"
  31. #include <linux/seq_file.h>
  32. static u32 rv6xx_scale_count_given_unit(struct radeon_device *rdev,
  33. u32 unscaled_count, u32 unit);
  34. static struct rv6xx_ps *rv6xx_get_ps(struct radeon_ps *rps)
  35. {
  36. struct rv6xx_ps *ps = rps->ps_priv;
  37. return ps;
  38. }
  39. static struct rv6xx_power_info *rv6xx_get_pi(struct radeon_device *rdev)
  40. {
  41. struct rv6xx_power_info *pi = rdev->pm.dpm.priv;
  42. return pi;
  43. }
  44. static void rv6xx_force_pcie_gen1(struct radeon_device *rdev)
  45. {
  46. u32 tmp;
  47. int i;
  48. tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  49. tmp &= LC_GEN2_EN;
  50. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
  51. tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  52. tmp |= LC_INITIATE_LINK_SPEED_CHANGE;
  53. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
  54. for (i = 0; i < rdev->usec_timeout; i++) {
  55. if (!(RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL) & LC_CURRENT_DATA_RATE))
  56. break;
  57. udelay(1);
  58. }
  59. tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  60. tmp &= ~LC_INITIATE_LINK_SPEED_CHANGE;
  61. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
  62. }
  63. static void rv6xx_enable_pcie_gen2_support(struct radeon_device *rdev)
  64. {
  65. u32 tmp;
  66. tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  67. if ((tmp & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
  68. (tmp & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
  69. tmp |= LC_GEN2_EN;
  70. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
  71. }
  72. }
  73. static void rv6xx_enable_bif_dynamic_pcie_gen2(struct radeon_device *rdev,
  74. bool enable)
  75. {
  76. u32 tmp;
  77. tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL) & ~LC_HW_VOLTAGE_IF_CONTROL_MASK;
  78. if (enable)
  79. tmp |= LC_HW_VOLTAGE_IF_CONTROL(1);
  80. else
  81. tmp |= LC_HW_VOLTAGE_IF_CONTROL(0);
  82. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
  83. }
  84. static void rv6xx_enable_l0s(struct radeon_device *rdev)
  85. {
  86. u32 tmp;
  87. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL) & ~LC_L0S_INACTIVITY_MASK;
  88. tmp |= LC_L0S_INACTIVITY(3);
  89. WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp);
  90. }
  91. static void rv6xx_enable_l1(struct radeon_device *rdev)
  92. {
  93. u32 tmp;
  94. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  95. tmp &= ~LC_L1_INACTIVITY_MASK;
  96. tmp |= LC_L1_INACTIVITY(4);
  97. tmp &= ~LC_PMI_TO_L1_DIS;
  98. tmp &= ~LC_ASPM_TO_L1_DIS;
  99. WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp);
  100. }
  101. static void rv6xx_enable_pll_sleep_in_l1(struct radeon_device *rdev)
  102. {
  103. u32 tmp;
  104. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL) & ~LC_L1_INACTIVITY_MASK;
  105. tmp |= LC_L1_INACTIVITY(8);
  106. WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp);
  107. /* NOTE, this is a PCIE indirect reg, not PCIE PORT */
  108. tmp = RREG32_PCIE(PCIE_P_CNTL);
  109. tmp |= P_PLL_PWRDN_IN_L1L23;
  110. tmp &= ~P_PLL_BUF_PDNB;
  111. tmp &= ~P_PLL_PDNB;
  112. tmp |= P_ALLOW_PRX_FRONTEND_SHUTOFF;
  113. WREG32_PCIE(PCIE_P_CNTL, tmp);
  114. }
  115. static int rv6xx_convert_clock_to_stepping(struct radeon_device *rdev,
  116. u32 clock, struct rv6xx_sclk_stepping *step)
  117. {
  118. int ret;
  119. struct atom_clock_dividers dividers;
  120. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  121. clock, false, &dividers);
  122. if (ret)
  123. return ret;
  124. if (dividers.enable_post_div)
  125. step->post_divider = 2 + (dividers.post_div & 0xF) + (dividers.post_div >> 4);
  126. else
  127. step->post_divider = 1;
  128. step->vco_frequency = clock * step->post_divider;
  129. return 0;
  130. }
  131. static void rv6xx_output_stepping(struct radeon_device *rdev,
  132. u32 step_index, struct rv6xx_sclk_stepping *step)
  133. {
  134. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  135. u32 ref_clk = rdev->clock.spll.reference_freq;
  136. u32 fb_divider;
  137. u32 spll_step_count = rv6xx_scale_count_given_unit(rdev,
  138. R600_SPLLSTEPTIME_DFLT *
  139. pi->spll_ref_div,
  140. R600_SPLLSTEPUNIT_DFLT);
  141. r600_engine_clock_entry_enable(rdev, step_index, true);
  142. r600_engine_clock_entry_enable_pulse_skipping(rdev, step_index, false);
  143. if (step->post_divider == 1)
  144. r600_engine_clock_entry_enable_post_divider(rdev, step_index, false);
  145. else {
  146. u32 lo_len = (step->post_divider - 2) / 2;
  147. u32 hi_len = step->post_divider - 2 - lo_len;
  148. r600_engine_clock_entry_enable_post_divider(rdev, step_index, true);
  149. r600_engine_clock_entry_set_post_divider(rdev, step_index, (hi_len << 4) | lo_len);
  150. }
  151. fb_divider = ((step->vco_frequency * pi->spll_ref_div) / ref_clk) >>
  152. pi->fb_div_scale;
  153. r600_engine_clock_entry_set_reference_divider(rdev, step_index,
  154. pi->spll_ref_div - 1);
  155. r600_engine_clock_entry_set_feedback_divider(rdev, step_index, fb_divider);
  156. r600_engine_clock_entry_set_step_time(rdev, step_index, spll_step_count);
  157. }
  158. static struct rv6xx_sclk_stepping rv6xx_next_vco_step(struct radeon_device *rdev,
  159. struct rv6xx_sclk_stepping *cur,
  160. bool increasing_vco, u32 step_size)
  161. {
  162. struct rv6xx_sclk_stepping next;
  163. next.post_divider = cur->post_divider;
  164. if (increasing_vco)
  165. next.vco_frequency = (cur->vco_frequency * (100 + step_size)) / 100;
  166. else
  167. next.vco_frequency = (cur->vco_frequency * 100 + 99 + step_size) / (100 + step_size);
  168. return next;
  169. }
  170. static bool rv6xx_can_step_post_div(struct radeon_device *rdev,
  171. struct rv6xx_sclk_stepping *cur,
  172. struct rv6xx_sclk_stepping *target)
  173. {
  174. return (cur->post_divider > target->post_divider) &&
  175. ((cur->vco_frequency * target->post_divider) <=
  176. (target->vco_frequency * (cur->post_divider - 1)));
  177. }
  178. static struct rv6xx_sclk_stepping rv6xx_next_post_div_step(struct radeon_device *rdev,
  179. struct rv6xx_sclk_stepping *cur,
  180. struct rv6xx_sclk_stepping *target)
  181. {
  182. struct rv6xx_sclk_stepping next = *cur;
  183. while (rv6xx_can_step_post_div(rdev, &next, target))
  184. next.post_divider--;
  185. return next;
  186. }
  187. static bool rv6xx_reached_stepping_target(struct radeon_device *rdev,
  188. struct rv6xx_sclk_stepping *cur,
  189. struct rv6xx_sclk_stepping *target,
  190. bool increasing_vco)
  191. {
  192. return (increasing_vco && (cur->vco_frequency >= target->vco_frequency)) ||
  193. (!increasing_vco && (cur->vco_frequency <= target->vco_frequency));
  194. }
  195. static void rv6xx_generate_steps(struct radeon_device *rdev,
  196. u32 low, u32 high,
  197. u32 start_index, u8 *end_index)
  198. {
  199. struct rv6xx_sclk_stepping cur;
  200. struct rv6xx_sclk_stepping target;
  201. bool increasing_vco;
  202. u32 step_index = start_index;
  203. rv6xx_convert_clock_to_stepping(rdev, low, &cur);
  204. rv6xx_convert_clock_to_stepping(rdev, high, &target);
  205. rv6xx_output_stepping(rdev, step_index++, &cur);
  206. increasing_vco = (target.vco_frequency >= cur.vco_frequency);
  207. if (target.post_divider > cur.post_divider)
  208. cur.post_divider = target.post_divider;
  209. while (1) {
  210. struct rv6xx_sclk_stepping next;
  211. if (rv6xx_can_step_post_div(rdev, &cur, &target))
  212. next = rv6xx_next_post_div_step(rdev, &cur, &target);
  213. else
  214. next = rv6xx_next_vco_step(rdev, &cur, increasing_vco, R600_VCOSTEPPCT_DFLT);
  215. if (rv6xx_reached_stepping_target(rdev, &next, &target, increasing_vco)) {
  216. struct rv6xx_sclk_stepping tiny =
  217. rv6xx_next_vco_step(rdev, &target, !increasing_vco, R600_ENDINGVCOSTEPPCT_DFLT);
  218. tiny.post_divider = next.post_divider;
  219. if (!rv6xx_reached_stepping_target(rdev, &tiny, &cur, !increasing_vco))
  220. rv6xx_output_stepping(rdev, step_index++, &tiny);
  221. if ((next.post_divider != target.post_divider) &&
  222. (next.vco_frequency != target.vco_frequency)) {
  223. struct rv6xx_sclk_stepping final_vco;
  224. final_vco.vco_frequency = target.vco_frequency;
  225. final_vco.post_divider = next.post_divider;
  226. rv6xx_output_stepping(rdev, step_index++, &final_vco);
  227. }
  228. rv6xx_output_stepping(rdev, step_index++, &target);
  229. break;
  230. } else
  231. rv6xx_output_stepping(rdev, step_index++, &next);
  232. cur = next;
  233. }
  234. *end_index = (u8)step_index - 1;
  235. }
  236. static void rv6xx_generate_single_step(struct radeon_device *rdev,
  237. u32 clock, u32 index)
  238. {
  239. struct rv6xx_sclk_stepping step;
  240. rv6xx_convert_clock_to_stepping(rdev, clock, &step);
  241. rv6xx_output_stepping(rdev, index, &step);
  242. }
  243. static void rv6xx_invalidate_intermediate_steps_range(struct radeon_device *rdev,
  244. u32 start_index, u32 end_index)
  245. {
  246. u32 step_index;
  247. for (step_index = start_index + 1; step_index < end_index; step_index++)
  248. r600_engine_clock_entry_enable(rdev, step_index, false);
  249. }
  250. static void rv6xx_set_engine_spread_spectrum_clk_s(struct radeon_device *rdev,
  251. u32 index, u32 clk_s)
  252. {
  253. WREG32_P(CG_SPLL_SPREAD_SPECTRUM_LOW + (index * 4),
  254. CLKS(clk_s), ~CLKS_MASK);
  255. }
  256. static void rv6xx_set_engine_spread_spectrum_clk_v(struct radeon_device *rdev,
  257. u32 index, u32 clk_v)
  258. {
  259. WREG32_P(CG_SPLL_SPREAD_SPECTRUM_LOW + (index * 4),
  260. CLKV(clk_v), ~CLKV_MASK);
  261. }
  262. static void rv6xx_enable_engine_spread_spectrum(struct radeon_device *rdev,
  263. u32 index, bool enable)
  264. {
  265. if (enable)
  266. WREG32_P(CG_SPLL_SPREAD_SPECTRUM_LOW + (index * 4),
  267. SSEN, ~SSEN);
  268. else
  269. WREG32_P(CG_SPLL_SPREAD_SPECTRUM_LOW + (index * 4),
  270. 0, ~SSEN);
  271. }
  272. static void rv6xx_set_memory_spread_spectrum_clk_s(struct radeon_device *rdev,
  273. u32 clk_s)
  274. {
  275. WREG32_P(CG_MPLL_SPREAD_SPECTRUM, CLKS(clk_s), ~CLKS_MASK);
  276. }
  277. static void rv6xx_set_memory_spread_spectrum_clk_v(struct radeon_device *rdev,
  278. u32 clk_v)
  279. {
  280. WREG32_P(CG_MPLL_SPREAD_SPECTRUM, CLKV(clk_v), ~CLKV_MASK);
  281. }
  282. static void rv6xx_enable_memory_spread_spectrum(struct radeon_device *rdev,
  283. bool enable)
  284. {
  285. if (enable)
  286. WREG32_P(CG_MPLL_SPREAD_SPECTRUM, SSEN, ~SSEN);
  287. else
  288. WREG32_P(CG_MPLL_SPREAD_SPECTRUM, 0, ~SSEN);
  289. }
  290. static void rv6xx_enable_dynamic_spread_spectrum(struct radeon_device *rdev,
  291. bool enable)
  292. {
  293. if (enable)
  294. WREG32_P(GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, ~DYN_SPREAD_SPECTRUM_EN);
  295. else
  296. WREG32_P(GENERAL_PWRMGT, 0, ~DYN_SPREAD_SPECTRUM_EN);
  297. }
  298. static void rv6xx_memory_clock_entry_enable_post_divider(struct radeon_device *rdev,
  299. u32 index, bool enable)
  300. {
  301. if (enable)
  302. WREG32_P(MPLL_FREQ_LEVEL_0 + (index * 4),
  303. LEVEL0_MPLL_DIV_EN, ~LEVEL0_MPLL_DIV_EN);
  304. else
  305. WREG32_P(MPLL_FREQ_LEVEL_0 + (index * 4), 0, ~LEVEL0_MPLL_DIV_EN);
  306. }
  307. static void rv6xx_memory_clock_entry_set_post_divider(struct radeon_device *rdev,
  308. u32 index, u32 divider)
  309. {
  310. WREG32_P(MPLL_FREQ_LEVEL_0 + (index * 4),
  311. LEVEL0_MPLL_POST_DIV(divider), ~LEVEL0_MPLL_POST_DIV_MASK);
  312. }
  313. static void rv6xx_memory_clock_entry_set_feedback_divider(struct radeon_device *rdev,
  314. u32 index, u32 divider)
  315. {
  316. WREG32_P(MPLL_FREQ_LEVEL_0 + (index * 4), LEVEL0_MPLL_FB_DIV(divider),
  317. ~LEVEL0_MPLL_FB_DIV_MASK);
  318. }
  319. static void rv6xx_memory_clock_entry_set_reference_divider(struct radeon_device *rdev,
  320. u32 index, u32 divider)
  321. {
  322. WREG32_P(MPLL_FREQ_LEVEL_0 + (index * 4),
  323. LEVEL0_MPLL_REF_DIV(divider), ~LEVEL0_MPLL_REF_DIV_MASK);
  324. }
  325. static void rv6xx_vid_response_set_brt(struct radeon_device *rdev, u32 rt)
  326. {
  327. WREG32_P(VID_RT, BRT(rt), ~BRT_MASK);
  328. }
  329. static void rv6xx_enable_engine_feedback_and_reference_sync(struct radeon_device *rdev)
  330. {
  331. WREG32_P(SPLL_CNTL_MODE, SPLL_DIV_SYNC, ~SPLL_DIV_SYNC);
  332. }
  333. static u32 rv6xx_clocks_per_unit(u32 unit)
  334. {
  335. u32 tmp = 1 << (2 * unit);
  336. return tmp;
  337. }
  338. static u32 rv6xx_scale_count_given_unit(struct radeon_device *rdev,
  339. u32 unscaled_count, u32 unit)
  340. {
  341. u32 count_per_unit = rv6xx_clocks_per_unit(unit);
  342. return (unscaled_count + count_per_unit - 1) / count_per_unit;
  343. }
  344. static u32 rv6xx_compute_count_for_delay(struct radeon_device *rdev,
  345. u32 delay_us, u32 unit)
  346. {
  347. u32 ref_clk = rdev->clock.spll.reference_freq;
  348. return rv6xx_scale_count_given_unit(rdev, delay_us * (ref_clk / 100), unit);
  349. }
  350. static void rv6xx_calculate_engine_speed_stepping_parameters(struct radeon_device *rdev,
  351. struct rv6xx_ps *state)
  352. {
  353. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  354. pi->hw.sclks[R600_POWER_LEVEL_LOW] =
  355. state->low.sclk;
  356. pi->hw.sclks[R600_POWER_LEVEL_MEDIUM] =
  357. state->medium.sclk;
  358. pi->hw.sclks[R600_POWER_LEVEL_HIGH] =
  359. state->high.sclk;
  360. pi->hw.low_sclk_index = R600_POWER_LEVEL_LOW;
  361. pi->hw.medium_sclk_index = R600_POWER_LEVEL_MEDIUM;
  362. pi->hw.high_sclk_index = R600_POWER_LEVEL_HIGH;
  363. }
  364. static void rv6xx_calculate_memory_clock_stepping_parameters(struct radeon_device *rdev,
  365. struct rv6xx_ps *state)
  366. {
  367. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  368. pi->hw.mclks[R600_POWER_LEVEL_CTXSW] =
  369. state->high.mclk;
  370. pi->hw.mclks[R600_POWER_LEVEL_HIGH] =
  371. state->high.mclk;
  372. pi->hw.mclks[R600_POWER_LEVEL_MEDIUM] =
  373. state->medium.mclk;
  374. pi->hw.mclks[R600_POWER_LEVEL_LOW] =
  375. state->low.mclk;
  376. pi->hw.high_mclk_index = R600_POWER_LEVEL_HIGH;
  377. if (state->high.mclk == state->medium.mclk)
  378. pi->hw.medium_mclk_index =
  379. pi->hw.high_mclk_index;
  380. else
  381. pi->hw.medium_mclk_index = R600_POWER_LEVEL_MEDIUM;
  382. if (state->medium.mclk == state->low.mclk)
  383. pi->hw.low_mclk_index =
  384. pi->hw.medium_mclk_index;
  385. else
  386. pi->hw.low_mclk_index = R600_POWER_LEVEL_LOW;
  387. }
  388. static void rv6xx_calculate_voltage_stepping_parameters(struct radeon_device *rdev,
  389. struct rv6xx_ps *state)
  390. {
  391. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  392. pi->hw.vddc[R600_POWER_LEVEL_CTXSW] = state->high.vddc;
  393. pi->hw.vddc[R600_POWER_LEVEL_HIGH] = state->high.vddc;
  394. pi->hw.vddc[R600_POWER_LEVEL_MEDIUM] = state->medium.vddc;
  395. pi->hw.vddc[R600_POWER_LEVEL_LOW] = state->low.vddc;
  396. pi->hw.backbias[R600_POWER_LEVEL_CTXSW] =
  397. (state->high.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ? true : false;
  398. pi->hw.backbias[R600_POWER_LEVEL_HIGH] =
  399. (state->high.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ? true : false;
  400. pi->hw.backbias[R600_POWER_LEVEL_MEDIUM] =
  401. (state->medium.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ? true : false;
  402. pi->hw.backbias[R600_POWER_LEVEL_LOW] =
  403. (state->low.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ? true : false;
  404. pi->hw.pcie_gen2[R600_POWER_LEVEL_HIGH] =
  405. (state->high.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? true : false;
  406. pi->hw.pcie_gen2[R600_POWER_LEVEL_MEDIUM] =
  407. (state->medium.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? true : false;
  408. pi->hw.pcie_gen2[R600_POWER_LEVEL_LOW] =
  409. (state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? true : false;
  410. pi->hw.high_vddc_index = R600_POWER_LEVEL_HIGH;
  411. if ((state->high.vddc == state->medium.vddc) &&
  412. ((state->high.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ==
  413. (state->medium.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE)))
  414. pi->hw.medium_vddc_index =
  415. pi->hw.high_vddc_index;
  416. else
  417. pi->hw.medium_vddc_index = R600_POWER_LEVEL_MEDIUM;
  418. if ((state->medium.vddc == state->low.vddc) &&
  419. ((state->medium.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ==
  420. (state->low.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE)))
  421. pi->hw.low_vddc_index =
  422. pi->hw.medium_vddc_index;
  423. else
  424. pi->hw.medium_vddc_index = R600_POWER_LEVEL_LOW;
  425. }
  426. static inline u32 rv6xx_calculate_vco_frequency(u32 ref_clock,
  427. struct atom_clock_dividers *dividers,
  428. u32 fb_divider_scale)
  429. {
  430. return ref_clock * ((dividers->fb_div & ~1) << fb_divider_scale) /
  431. (dividers->ref_div + 1);
  432. }
  433. static inline u32 rv6xx_calculate_spread_spectrum_clk_v(u32 vco_freq, u32 ref_freq,
  434. u32 ss_rate, u32 ss_percent,
  435. u32 fb_divider_scale)
  436. {
  437. u32 fb_divider = vco_freq / ref_freq;
  438. return (ss_percent * ss_rate * 4 * (fb_divider * fb_divider) /
  439. (5375 * ((vco_freq * 10) / (4096 >> fb_divider_scale))));
  440. }
  441. static inline u32 rv6xx_calculate_spread_spectrum_clk_s(u32 ss_rate, u32 ref_freq)
  442. {
  443. return (((ref_freq * 10) / (ss_rate * 2)) - 1) / 4;
  444. }
  445. static void rv6xx_program_engine_spread_spectrum(struct radeon_device *rdev,
  446. u32 clock, enum r600_power_level level)
  447. {
  448. u32 ref_clk = rdev->clock.spll.reference_freq;
  449. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  450. struct atom_clock_dividers dividers;
  451. struct radeon_atom_ss ss;
  452. u32 vco_freq, clk_v, clk_s;
  453. rv6xx_enable_engine_spread_spectrum(rdev, level, false);
  454. if (clock && pi->sclk_ss) {
  455. if (radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, clock, false, &dividers) == 0) {
  456. vco_freq = rv6xx_calculate_vco_frequency(ref_clk, &dividers,
  457. pi->fb_div_scale);
  458. if (radeon_atombios_get_asic_ss_info(rdev, &ss,
  459. ASIC_INTERNAL_ENGINE_SS, vco_freq)) {
  460. clk_v = rv6xx_calculate_spread_spectrum_clk_v(vco_freq,
  461. (ref_clk / (dividers.ref_div + 1)),
  462. ss.rate,
  463. ss.percentage,
  464. pi->fb_div_scale);
  465. clk_s = rv6xx_calculate_spread_spectrum_clk_s(ss.rate,
  466. (ref_clk / (dividers.ref_div + 1)));
  467. rv6xx_set_engine_spread_spectrum_clk_v(rdev, level, clk_v);
  468. rv6xx_set_engine_spread_spectrum_clk_s(rdev, level, clk_s);
  469. rv6xx_enable_engine_spread_spectrum(rdev, level, true);
  470. }
  471. }
  472. }
  473. }
  474. static void rv6xx_program_sclk_spread_spectrum_parameters_except_lowest_entry(struct radeon_device *rdev)
  475. {
  476. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  477. rv6xx_program_engine_spread_spectrum(rdev,
  478. pi->hw.sclks[R600_POWER_LEVEL_HIGH],
  479. R600_POWER_LEVEL_HIGH);
  480. rv6xx_program_engine_spread_spectrum(rdev,
  481. pi->hw.sclks[R600_POWER_LEVEL_MEDIUM],
  482. R600_POWER_LEVEL_MEDIUM);
  483. }
  484. static int rv6xx_program_mclk_stepping_entry(struct radeon_device *rdev,
  485. u32 entry, u32 clock)
  486. {
  487. struct atom_clock_dividers dividers;
  488. if (radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM, clock, false, &dividers))
  489. return -EINVAL;
  490. rv6xx_memory_clock_entry_set_reference_divider(rdev, entry, dividers.ref_div);
  491. rv6xx_memory_clock_entry_set_feedback_divider(rdev, entry, dividers.fb_div);
  492. rv6xx_memory_clock_entry_set_post_divider(rdev, entry, dividers.post_div);
  493. if (dividers.enable_post_div)
  494. rv6xx_memory_clock_entry_enable_post_divider(rdev, entry, true);
  495. else
  496. rv6xx_memory_clock_entry_enable_post_divider(rdev, entry, false);
  497. return 0;
  498. }
  499. static void rv6xx_program_mclk_stepping_parameters_except_lowest_entry(struct radeon_device *rdev)
  500. {
  501. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  502. int i;
  503. for (i = 1; i < R600_PM_NUMBER_OF_MCLKS; i++) {
  504. if (pi->hw.mclks[i])
  505. rv6xx_program_mclk_stepping_entry(rdev, i,
  506. pi->hw.mclks[i]);
  507. }
  508. }
  509. static void rv6xx_find_memory_clock_with_highest_vco(struct radeon_device *rdev,
  510. u32 requested_memory_clock,
  511. u32 ref_clk,
  512. struct atom_clock_dividers *dividers,
  513. u32 *vco_freq)
  514. {
  515. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  516. struct atom_clock_dividers req_dividers;
  517. u32 vco_freq_temp;
  518. if (radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM,
  519. requested_memory_clock, false, &req_dividers) == 0) {
  520. vco_freq_temp = rv6xx_calculate_vco_frequency(ref_clk, &req_dividers,
  521. pi->fb_div_scale);
  522. if (vco_freq_temp > *vco_freq) {
  523. *dividers = req_dividers;
  524. *vco_freq = vco_freq_temp;
  525. }
  526. }
  527. }
  528. static void rv6xx_program_mclk_spread_spectrum_parameters(struct radeon_device *rdev)
  529. {
  530. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  531. u32 ref_clk = rdev->clock.mpll.reference_freq;
  532. struct atom_clock_dividers dividers;
  533. struct radeon_atom_ss ss;
  534. u32 vco_freq = 0, clk_v, clk_s;
  535. rv6xx_enable_memory_spread_spectrum(rdev, false);
  536. if (pi->mclk_ss) {
  537. rv6xx_find_memory_clock_with_highest_vco(rdev,
  538. pi->hw.mclks[pi->hw.high_mclk_index],
  539. ref_clk,
  540. &dividers,
  541. &vco_freq);
  542. rv6xx_find_memory_clock_with_highest_vco(rdev,
  543. pi->hw.mclks[pi->hw.medium_mclk_index],
  544. ref_clk,
  545. &dividers,
  546. &vco_freq);
  547. rv6xx_find_memory_clock_with_highest_vco(rdev,
  548. pi->hw.mclks[pi->hw.low_mclk_index],
  549. ref_clk,
  550. &dividers,
  551. &vco_freq);
  552. if (vco_freq) {
  553. if (radeon_atombios_get_asic_ss_info(rdev, &ss,
  554. ASIC_INTERNAL_MEMORY_SS, vco_freq)) {
  555. clk_v = rv6xx_calculate_spread_spectrum_clk_v(vco_freq,
  556. (ref_clk / (dividers.ref_div + 1)),
  557. ss.rate,
  558. ss.percentage,
  559. pi->fb_div_scale);
  560. clk_s = rv6xx_calculate_spread_spectrum_clk_s(ss.rate,
  561. (ref_clk / (dividers.ref_div + 1)));
  562. rv6xx_set_memory_spread_spectrum_clk_v(rdev, clk_v);
  563. rv6xx_set_memory_spread_spectrum_clk_s(rdev, clk_s);
  564. rv6xx_enable_memory_spread_spectrum(rdev, true);
  565. }
  566. }
  567. }
  568. }
  569. static int rv6xx_program_voltage_stepping_entry(struct radeon_device *rdev,
  570. u32 entry, u16 voltage)
  571. {
  572. u32 mask, set_pins;
  573. int ret;
  574. ret = radeon_atom_get_voltage_gpio_settings(rdev, voltage,
  575. SET_VOLTAGE_TYPE_ASIC_VDDC,
  576. &set_pins, &mask);
  577. if (ret)
  578. return ret;
  579. r600_voltage_control_program_voltages(rdev, entry, set_pins);
  580. return 0;
  581. }
  582. static void rv6xx_program_voltage_stepping_parameters_except_lowest_entry(struct radeon_device *rdev)
  583. {
  584. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  585. int i;
  586. for (i = 1; i < R600_PM_NUMBER_OF_VOLTAGE_LEVELS; i++)
  587. rv6xx_program_voltage_stepping_entry(rdev, i,
  588. pi->hw.vddc[i]);
  589. }
  590. static void rv6xx_program_backbias_stepping_parameters_except_lowest_entry(struct radeon_device *rdev)
  591. {
  592. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  593. if (pi->hw.backbias[1])
  594. WREG32_P(VID_UPPER_GPIO_CNTL, MEDIUM_BACKBIAS_VALUE, ~MEDIUM_BACKBIAS_VALUE);
  595. else
  596. WREG32_P(VID_UPPER_GPIO_CNTL, 0, ~MEDIUM_BACKBIAS_VALUE);
  597. if (pi->hw.backbias[2])
  598. WREG32_P(VID_UPPER_GPIO_CNTL, HIGH_BACKBIAS_VALUE, ~HIGH_BACKBIAS_VALUE);
  599. else
  600. WREG32_P(VID_UPPER_GPIO_CNTL, 0, ~HIGH_BACKBIAS_VALUE);
  601. }
  602. static void rv6xx_program_sclk_spread_spectrum_parameters_lowest_entry(struct radeon_device *rdev)
  603. {
  604. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  605. rv6xx_program_engine_spread_spectrum(rdev,
  606. pi->hw.sclks[R600_POWER_LEVEL_LOW],
  607. R600_POWER_LEVEL_LOW);
  608. }
  609. static void rv6xx_program_mclk_stepping_parameters_lowest_entry(struct radeon_device *rdev)
  610. {
  611. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  612. if (pi->hw.mclks[0])
  613. rv6xx_program_mclk_stepping_entry(rdev, 0,
  614. pi->hw.mclks[0]);
  615. }
  616. static void rv6xx_program_voltage_stepping_parameters_lowest_entry(struct radeon_device *rdev)
  617. {
  618. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  619. rv6xx_program_voltage_stepping_entry(rdev, 0,
  620. pi->hw.vddc[0]);
  621. }
  622. static void rv6xx_program_backbias_stepping_parameters_lowest_entry(struct radeon_device *rdev)
  623. {
  624. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  625. if (pi->hw.backbias[0])
  626. WREG32_P(VID_UPPER_GPIO_CNTL, LOW_BACKBIAS_VALUE, ~LOW_BACKBIAS_VALUE);
  627. else
  628. WREG32_P(VID_UPPER_GPIO_CNTL, 0, ~LOW_BACKBIAS_VALUE);
  629. }
  630. static u32 calculate_memory_refresh_rate(struct radeon_device *rdev,
  631. u32 engine_clock)
  632. {
  633. u32 dram_rows, dram_refresh_rate;
  634. u32 tmp;
  635. tmp = (RREG32(RAMCFG) & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
  636. dram_rows = 1 << (tmp + 10);
  637. dram_refresh_rate = 1 << ((RREG32(MC_SEQ_RESERVE_M) & 0x3) + 3);
  638. return ((engine_clock * 10) * dram_refresh_rate / dram_rows - 32) / 64;
  639. }
  640. static void rv6xx_program_memory_timing_parameters(struct radeon_device *rdev)
  641. {
  642. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  643. u32 sqm_ratio;
  644. u32 arb_refresh_rate;
  645. u32 high_clock;
  646. if (pi->hw.sclks[R600_POWER_LEVEL_HIGH] <
  647. (pi->hw.sclks[R600_POWER_LEVEL_LOW] * 0xFF / 0x40))
  648. high_clock = pi->hw.sclks[R600_POWER_LEVEL_HIGH];
  649. else
  650. high_clock =
  651. pi->hw.sclks[R600_POWER_LEVEL_LOW] * 0xFF / 0x40;
  652. radeon_atom_set_engine_dram_timings(rdev, high_clock, 0);
  653. sqm_ratio = (STATE0(64 * high_clock / pi->hw.sclks[R600_POWER_LEVEL_LOW]) |
  654. STATE1(64 * high_clock / pi->hw.sclks[R600_POWER_LEVEL_MEDIUM]) |
  655. STATE2(64 * high_clock / pi->hw.sclks[R600_POWER_LEVEL_HIGH]) |
  656. STATE3(64 * high_clock / pi->hw.sclks[R600_POWER_LEVEL_HIGH]));
  657. WREG32(SQM_RATIO, sqm_ratio);
  658. arb_refresh_rate =
  659. (POWERMODE0(calculate_memory_refresh_rate(rdev,
  660. pi->hw.sclks[R600_POWER_LEVEL_LOW])) |
  661. POWERMODE1(calculate_memory_refresh_rate(rdev,
  662. pi->hw.sclks[R600_POWER_LEVEL_MEDIUM])) |
  663. POWERMODE2(calculate_memory_refresh_rate(rdev,
  664. pi->hw.sclks[R600_POWER_LEVEL_HIGH])) |
  665. POWERMODE3(calculate_memory_refresh_rate(rdev,
  666. pi->hw.sclks[R600_POWER_LEVEL_HIGH])));
  667. WREG32(ARB_RFSH_RATE, arb_refresh_rate);
  668. }
  669. static void rv6xx_program_mpll_timing_parameters(struct radeon_device *rdev)
  670. {
  671. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  672. r600_set_mpll_lock_time(rdev, R600_MPLLLOCKTIME_DFLT *
  673. pi->mpll_ref_div);
  674. r600_set_mpll_reset_time(rdev, R600_MPLLRESETTIME_DFLT);
  675. }
  676. static void rv6xx_program_bsp(struct radeon_device *rdev)
  677. {
  678. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  679. u32 ref_clk = rdev->clock.spll.reference_freq;
  680. r600_calculate_u_and_p(R600_ASI_DFLT,
  681. ref_clk, 16,
  682. &pi->bsp,
  683. &pi->bsu);
  684. r600_set_bsp(rdev, pi->bsu, pi->bsp);
  685. }
  686. static void rv6xx_program_at(struct radeon_device *rdev)
  687. {
  688. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  689. r600_set_at(rdev,
  690. (pi->hw.rp[0] * pi->bsp) / 200,
  691. (pi->hw.rp[1] * pi->bsp) / 200,
  692. (pi->hw.lp[2] * pi->bsp) / 200,
  693. (pi->hw.lp[1] * pi->bsp) / 200);
  694. }
  695. static void rv6xx_program_git(struct radeon_device *rdev)
  696. {
  697. r600_set_git(rdev, R600_GICST_DFLT);
  698. }
  699. static void rv6xx_program_tp(struct radeon_device *rdev)
  700. {
  701. int i;
  702. for (i = 0; i < R600_PM_NUMBER_OF_TC; i++)
  703. r600_set_tc(rdev, i, r600_utc[i], r600_dtc[i]);
  704. r600_select_td(rdev, R600_TD_DFLT);
  705. }
  706. static void rv6xx_program_vc(struct radeon_device *rdev)
  707. {
  708. r600_set_vrc(rdev, R600_VRC_DFLT);
  709. }
  710. static void rv6xx_clear_vc(struct radeon_device *rdev)
  711. {
  712. r600_set_vrc(rdev, 0);
  713. }
  714. static void rv6xx_program_tpp(struct radeon_device *rdev)
  715. {
  716. r600_set_tpu(rdev, R600_TPU_DFLT);
  717. r600_set_tpc(rdev, R600_TPC_DFLT);
  718. }
  719. static void rv6xx_program_sstp(struct radeon_device *rdev)
  720. {
  721. r600_set_sstu(rdev, R600_SSTU_DFLT);
  722. r600_set_sst(rdev, R600_SST_DFLT);
  723. }
  724. static void rv6xx_program_fcp(struct radeon_device *rdev)
  725. {
  726. r600_set_fctu(rdev, R600_FCTU_DFLT);
  727. r600_set_fct(rdev, R600_FCT_DFLT);
  728. }
  729. static void rv6xx_program_vddc3d_parameters(struct radeon_device *rdev)
  730. {
  731. r600_set_vddc3d_oorsu(rdev, R600_VDDC3DOORSU_DFLT);
  732. r600_set_vddc3d_oorphc(rdev, R600_VDDC3DOORPHC_DFLT);
  733. r600_set_vddc3d_oorsdc(rdev, R600_VDDC3DOORSDC_DFLT);
  734. r600_set_ctxcgtt3d_rphc(rdev, R600_CTXCGTT3DRPHC_DFLT);
  735. r600_set_ctxcgtt3d_rsdc(rdev, R600_CTXCGTT3DRSDC_DFLT);
  736. }
  737. static void rv6xx_program_voltage_timing_parameters(struct radeon_device *rdev)
  738. {
  739. u32 rt;
  740. r600_vid_rt_set_vru(rdev, R600_VRU_DFLT);
  741. r600_vid_rt_set_vrt(rdev,
  742. rv6xx_compute_count_for_delay(rdev,
  743. rdev->pm.dpm.voltage_response_time,
  744. R600_VRU_DFLT));
  745. rt = rv6xx_compute_count_for_delay(rdev,
  746. rdev->pm.dpm.backbias_response_time,
  747. R600_VRU_DFLT);
  748. rv6xx_vid_response_set_brt(rdev, (rt + 0x1F) >> 5);
  749. }
  750. static void rv6xx_program_engine_speed_parameters(struct radeon_device *rdev)
  751. {
  752. r600_vid_rt_set_ssu(rdev, R600_SPLLSTEPUNIT_DFLT);
  753. rv6xx_enable_engine_feedback_and_reference_sync(rdev);
  754. }
  755. static u64 rv6xx_get_master_voltage_mask(struct radeon_device *rdev)
  756. {
  757. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  758. u64 master_mask = 0;
  759. int i;
  760. for (i = 0; i < R600_PM_NUMBER_OF_VOLTAGE_LEVELS; i++) {
  761. u32 tmp_mask, tmp_set_pins;
  762. int ret;
  763. ret = radeon_atom_get_voltage_gpio_settings(rdev,
  764. pi->hw.vddc[i],
  765. SET_VOLTAGE_TYPE_ASIC_VDDC,
  766. &tmp_set_pins, &tmp_mask);
  767. if (ret == 0)
  768. master_mask |= tmp_mask;
  769. }
  770. return master_mask;
  771. }
  772. static void rv6xx_program_voltage_gpio_pins(struct radeon_device *rdev)
  773. {
  774. r600_voltage_control_enable_pins(rdev,
  775. rv6xx_get_master_voltage_mask(rdev));
  776. }
  777. static void rv6xx_enable_static_voltage_control(struct radeon_device *rdev,
  778. struct radeon_ps *new_ps,
  779. bool enable)
  780. {
  781. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  782. if (enable)
  783. radeon_atom_set_voltage(rdev,
  784. new_state->low.vddc,
  785. SET_VOLTAGE_TYPE_ASIC_VDDC);
  786. else
  787. r600_voltage_control_deactivate_static_control(rdev,
  788. rv6xx_get_master_voltage_mask(rdev));
  789. }
  790. static void rv6xx_enable_display_gap(struct radeon_device *rdev, bool enable)
  791. {
  792. if (enable) {
  793. u32 tmp = (DISP1_GAP(R600_PM_DISPLAY_GAP_VBLANK_OR_WM) |
  794. DISP2_GAP(R600_PM_DISPLAY_GAP_VBLANK_OR_WM) |
  795. DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE) |
  796. DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE) |
  797. VBI_TIMER_COUNT(0x3FFF) |
  798. VBI_TIMER_UNIT(7));
  799. WREG32(CG_DISPLAY_GAP_CNTL, tmp);
  800. WREG32_P(MCLK_PWRMGT_CNTL, USE_DISPLAY_GAP, ~USE_DISPLAY_GAP);
  801. } else
  802. WREG32_P(MCLK_PWRMGT_CNTL, 0, ~USE_DISPLAY_GAP);
  803. }
  804. static void rv6xx_program_power_level_enter_state(struct radeon_device *rdev)
  805. {
  806. r600_power_level_set_enter_index(rdev, R600_POWER_LEVEL_MEDIUM);
  807. }
  808. static void rv6xx_calculate_t(u32 l_f, u32 h_f, int h,
  809. int d_l, int d_r, u8 *l, u8 *r)
  810. {
  811. int a_n, a_d, h_r, l_r;
  812. h_r = d_l;
  813. l_r = 100 - d_r;
  814. a_n = (int)h_f * d_l + (int)l_f * (h - d_r);
  815. a_d = (int)l_f * l_r + (int)h_f * h_r;
  816. if (a_d != 0) {
  817. *l = d_l - h_r * a_n / a_d;
  818. *r = d_r + l_r * a_n / a_d;
  819. }
  820. }
  821. static void rv6xx_calculate_ap(struct radeon_device *rdev,
  822. struct rv6xx_ps *state)
  823. {
  824. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  825. pi->hw.lp[0] = 0;
  826. pi->hw.rp[R600_PM_NUMBER_OF_ACTIVITY_LEVELS - 1]
  827. = 100;
  828. rv6xx_calculate_t(state->low.sclk,
  829. state->medium.sclk,
  830. R600_AH_DFLT,
  831. R600_LMP_DFLT,
  832. R600_RLP_DFLT,
  833. &pi->hw.lp[1],
  834. &pi->hw.rp[0]);
  835. rv6xx_calculate_t(state->medium.sclk,
  836. state->high.sclk,
  837. R600_AH_DFLT,
  838. R600_LHP_DFLT,
  839. R600_RMP_DFLT,
  840. &pi->hw.lp[2],
  841. &pi->hw.rp[1]);
  842. }
  843. static void rv6xx_calculate_stepping_parameters(struct radeon_device *rdev,
  844. struct radeon_ps *new_ps)
  845. {
  846. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  847. rv6xx_calculate_engine_speed_stepping_parameters(rdev, new_state);
  848. rv6xx_calculate_memory_clock_stepping_parameters(rdev, new_state);
  849. rv6xx_calculate_voltage_stepping_parameters(rdev, new_state);
  850. rv6xx_calculate_ap(rdev, new_state);
  851. }
  852. static void rv6xx_program_stepping_parameters_except_lowest_entry(struct radeon_device *rdev)
  853. {
  854. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  855. rv6xx_program_mclk_stepping_parameters_except_lowest_entry(rdev);
  856. if (pi->voltage_control)
  857. rv6xx_program_voltage_stepping_parameters_except_lowest_entry(rdev);
  858. rv6xx_program_backbias_stepping_parameters_except_lowest_entry(rdev);
  859. rv6xx_program_sclk_spread_spectrum_parameters_except_lowest_entry(rdev);
  860. rv6xx_program_mclk_spread_spectrum_parameters(rdev);
  861. rv6xx_program_memory_timing_parameters(rdev);
  862. }
  863. static void rv6xx_program_stepping_parameters_lowest_entry(struct radeon_device *rdev)
  864. {
  865. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  866. rv6xx_program_mclk_stepping_parameters_lowest_entry(rdev);
  867. if (pi->voltage_control)
  868. rv6xx_program_voltage_stepping_parameters_lowest_entry(rdev);
  869. rv6xx_program_backbias_stepping_parameters_lowest_entry(rdev);
  870. rv6xx_program_sclk_spread_spectrum_parameters_lowest_entry(rdev);
  871. }
  872. static void rv6xx_program_power_level_low(struct radeon_device *rdev)
  873. {
  874. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  875. r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_LOW,
  876. pi->hw.low_vddc_index);
  877. r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_LOW,
  878. pi->hw.low_mclk_index);
  879. r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_LOW,
  880. pi->hw.low_sclk_index);
  881. r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_LOW,
  882. R600_DISPLAY_WATERMARK_LOW);
  883. r600_power_level_set_pcie_gen2(rdev, R600_POWER_LEVEL_LOW,
  884. pi->hw.pcie_gen2[R600_POWER_LEVEL_LOW]);
  885. }
  886. static void rv6xx_program_power_level_low_to_lowest_state(struct radeon_device *rdev)
  887. {
  888. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  889. r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_LOW, 0);
  890. r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_LOW, 0);
  891. r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_LOW, 0);
  892. r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_LOW,
  893. R600_DISPLAY_WATERMARK_LOW);
  894. r600_power_level_set_pcie_gen2(rdev, R600_POWER_LEVEL_LOW,
  895. pi->hw.pcie_gen2[R600_POWER_LEVEL_LOW]);
  896. }
  897. static void rv6xx_program_power_level_medium(struct radeon_device *rdev)
  898. {
  899. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  900. r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_MEDIUM,
  901. pi->hw.medium_vddc_index);
  902. r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_MEDIUM,
  903. pi->hw.medium_mclk_index);
  904. r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_MEDIUM,
  905. pi->hw.medium_sclk_index);
  906. r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_MEDIUM,
  907. R600_DISPLAY_WATERMARK_LOW);
  908. r600_power_level_set_pcie_gen2(rdev, R600_POWER_LEVEL_MEDIUM,
  909. pi->hw.pcie_gen2[R600_POWER_LEVEL_MEDIUM]);
  910. }
  911. static void rv6xx_program_power_level_medium_for_transition(struct radeon_device *rdev)
  912. {
  913. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  914. rv6xx_program_mclk_stepping_entry(rdev,
  915. R600_POWER_LEVEL_CTXSW,
  916. pi->hw.mclks[pi->hw.low_mclk_index]);
  917. r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_MEDIUM, 1);
  918. r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_MEDIUM,
  919. R600_POWER_LEVEL_CTXSW);
  920. r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_MEDIUM,
  921. pi->hw.medium_sclk_index);
  922. r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_MEDIUM,
  923. R600_DISPLAY_WATERMARK_LOW);
  924. rv6xx_enable_engine_spread_spectrum(rdev, R600_POWER_LEVEL_MEDIUM, false);
  925. r600_power_level_set_pcie_gen2(rdev, R600_POWER_LEVEL_MEDIUM,
  926. pi->hw.pcie_gen2[R600_POWER_LEVEL_LOW]);
  927. }
  928. static void rv6xx_program_power_level_high(struct radeon_device *rdev)
  929. {
  930. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  931. r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_HIGH,
  932. pi->hw.high_vddc_index);
  933. r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_HIGH,
  934. pi->hw.high_mclk_index);
  935. r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_HIGH,
  936. pi->hw.high_sclk_index);
  937. r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_HIGH,
  938. R600_DISPLAY_WATERMARK_HIGH);
  939. r600_power_level_set_pcie_gen2(rdev, R600_POWER_LEVEL_HIGH,
  940. pi->hw.pcie_gen2[R600_POWER_LEVEL_HIGH]);
  941. }
  942. static void rv6xx_enable_backbias(struct radeon_device *rdev, bool enable)
  943. {
  944. if (enable)
  945. WREG32_P(GENERAL_PWRMGT, BACKBIAS_PAD_EN | BACKBIAS_DPM_CNTL,
  946. ~(BACKBIAS_PAD_EN | BACKBIAS_DPM_CNTL));
  947. else
  948. WREG32_P(GENERAL_PWRMGT, 0,
  949. ~(BACKBIAS_VALUE | BACKBIAS_PAD_EN | BACKBIAS_DPM_CNTL));
  950. }
  951. static void rv6xx_program_display_gap(struct radeon_device *rdev)
  952. {
  953. u32 tmp = RREG32(CG_DISPLAY_GAP_CNTL);
  954. tmp &= ~(DISP1_GAP_MCHG_MASK | DISP2_GAP_MCHG_MASK);
  955. if (rdev->pm.dpm.new_active_crtcs & 1) {
  956. tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK);
  957. tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
  958. } else if (rdev->pm.dpm.new_active_crtcs & 2) {
  959. tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
  960. tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK);
  961. } else {
  962. tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
  963. tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
  964. }
  965. WREG32(CG_DISPLAY_GAP_CNTL, tmp);
  966. }
  967. static void rv6xx_set_sw_voltage_to_safe(struct radeon_device *rdev,
  968. struct radeon_ps *new_ps,
  969. struct radeon_ps *old_ps)
  970. {
  971. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  972. struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
  973. u16 safe_voltage;
  974. safe_voltage = (new_state->low.vddc >= old_state->low.vddc) ?
  975. new_state->low.vddc : old_state->low.vddc;
  976. rv6xx_program_voltage_stepping_entry(rdev, R600_POWER_LEVEL_CTXSW,
  977. safe_voltage);
  978. WREG32_P(GENERAL_PWRMGT, SW_GPIO_INDEX(R600_POWER_LEVEL_CTXSW),
  979. ~SW_GPIO_INDEX_MASK);
  980. }
  981. static void rv6xx_set_sw_voltage_to_low(struct radeon_device *rdev,
  982. struct radeon_ps *old_ps)
  983. {
  984. struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
  985. rv6xx_program_voltage_stepping_entry(rdev, R600_POWER_LEVEL_CTXSW,
  986. old_state->low.vddc);
  987. WREG32_P(GENERAL_PWRMGT, SW_GPIO_INDEX(R600_POWER_LEVEL_CTXSW),
  988. ~SW_GPIO_INDEX_MASK);
  989. }
  990. static void rv6xx_set_safe_backbias(struct radeon_device *rdev,
  991. struct radeon_ps *new_ps,
  992. struct radeon_ps *old_ps)
  993. {
  994. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  995. struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
  996. if ((new_state->low.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) &&
  997. (old_state->low.flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE))
  998. WREG32_P(GENERAL_PWRMGT, BACKBIAS_VALUE, ~BACKBIAS_VALUE);
  999. else
  1000. WREG32_P(GENERAL_PWRMGT, 0, ~BACKBIAS_VALUE);
  1001. }
  1002. static void rv6xx_set_safe_pcie_gen2(struct radeon_device *rdev,
  1003. struct radeon_ps *new_ps,
  1004. struct radeon_ps *old_ps)
  1005. {
  1006. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  1007. struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
  1008. if ((new_state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) !=
  1009. (old_state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2))
  1010. rv6xx_force_pcie_gen1(rdev);
  1011. }
  1012. static void rv6xx_enable_dynamic_voltage_control(struct radeon_device *rdev,
  1013. bool enable)
  1014. {
  1015. if (enable)
  1016. WREG32_P(GENERAL_PWRMGT, VOLT_PWRMGT_EN, ~VOLT_PWRMGT_EN);
  1017. else
  1018. WREG32_P(GENERAL_PWRMGT, 0, ~VOLT_PWRMGT_EN);
  1019. }
  1020. static void rv6xx_enable_dynamic_backbias_control(struct radeon_device *rdev,
  1021. bool enable)
  1022. {
  1023. if (enable)
  1024. WREG32_P(GENERAL_PWRMGT, BACKBIAS_DPM_CNTL, ~BACKBIAS_DPM_CNTL);
  1025. else
  1026. WREG32_P(GENERAL_PWRMGT, 0, ~BACKBIAS_DPM_CNTL);
  1027. }
  1028. static int rv6xx_step_sw_voltage(struct radeon_device *rdev,
  1029. u16 initial_voltage,
  1030. u16 target_voltage)
  1031. {
  1032. u16 current_voltage;
  1033. u16 true_target_voltage;
  1034. u16 voltage_step;
  1035. int signed_voltage_step;
  1036. if ((radeon_atom_get_voltage_step(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC,
  1037. &voltage_step)) ||
  1038. (radeon_atom_round_to_true_voltage(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC,
  1039. initial_voltage, &current_voltage)) ||
  1040. (radeon_atom_round_to_true_voltage(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC,
  1041. target_voltage, &true_target_voltage)))
  1042. return -EINVAL;
  1043. if (true_target_voltage < current_voltage)
  1044. signed_voltage_step = -(int)voltage_step;
  1045. else
  1046. signed_voltage_step = voltage_step;
  1047. while (current_voltage != true_target_voltage) {
  1048. current_voltage += signed_voltage_step;
  1049. rv6xx_program_voltage_stepping_entry(rdev, R600_POWER_LEVEL_CTXSW,
  1050. current_voltage);
  1051. msleep((rdev->pm.dpm.voltage_response_time + 999) / 1000);
  1052. }
  1053. return 0;
  1054. }
  1055. static int rv6xx_step_voltage_if_increasing(struct radeon_device *rdev,
  1056. struct radeon_ps *new_ps,
  1057. struct radeon_ps *old_ps)
  1058. {
  1059. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  1060. struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
  1061. if (new_state->low.vddc > old_state->low.vddc)
  1062. return rv6xx_step_sw_voltage(rdev,
  1063. old_state->low.vddc,
  1064. new_state->low.vddc);
  1065. return 0;
  1066. }
  1067. static int rv6xx_step_voltage_if_decreasing(struct radeon_device *rdev,
  1068. struct radeon_ps *new_ps,
  1069. struct radeon_ps *old_ps)
  1070. {
  1071. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  1072. struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
  1073. if (new_state->low.vddc < old_state->low.vddc)
  1074. return rv6xx_step_sw_voltage(rdev,
  1075. old_state->low.vddc,
  1076. new_state->low.vddc);
  1077. else
  1078. return 0;
  1079. }
  1080. static void rv6xx_enable_high(struct radeon_device *rdev)
  1081. {
  1082. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1083. if ((pi->restricted_levels < 1) ||
  1084. (pi->restricted_levels == 3))
  1085. r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, true);
  1086. }
  1087. static void rv6xx_enable_medium(struct radeon_device *rdev)
  1088. {
  1089. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1090. if (pi->restricted_levels < 2)
  1091. r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, true);
  1092. }
  1093. static void rv6xx_set_dpm_event_sources(struct radeon_device *rdev, u32 sources)
  1094. {
  1095. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1096. bool want_thermal_protection;
  1097. enum radeon_dpm_event_src dpm_event_src;
  1098. switch (sources) {
  1099. case 0:
  1100. default:
  1101. want_thermal_protection = false;
  1102. break;
  1103. case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL):
  1104. want_thermal_protection = true;
  1105. dpm_event_src = RADEON_DPM_EVENT_SRC_DIGITAL;
  1106. break;
  1107. case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL):
  1108. want_thermal_protection = true;
  1109. dpm_event_src = RADEON_DPM_EVENT_SRC_EXTERNAL;
  1110. break;
  1111. case ((1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL) |
  1112. (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL)):
  1113. want_thermal_protection = true;
  1114. dpm_event_src = RADEON_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL;
  1115. break;
  1116. }
  1117. if (want_thermal_protection) {
  1118. WREG32_P(CG_THERMAL_CTRL, DPM_EVENT_SRC(dpm_event_src), ~DPM_EVENT_SRC_MASK);
  1119. if (pi->thermal_protection)
  1120. WREG32_P(GENERAL_PWRMGT, 0, ~THERMAL_PROTECTION_DIS);
  1121. } else {
  1122. WREG32_P(GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, ~THERMAL_PROTECTION_DIS);
  1123. }
  1124. }
  1125. static void rv6xx_enable_auto_throttle_source(struct radeon_device *rdev,
  1126. enum radeon_dpm_auto_throttle_src source,
  1127. bool enable)
  1128. {
  1129. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1130. if (enable) {
  1131. if (!(pi->active_auto_throttle_sources & (1 << source))) {
  1132. pi->active_auto_throttle_sources |= 1 << source;
  1133. rv6xx_set_dpm_event_sources(rdev, pi->active_auto_throttle_sources);
  1134. }
  1135. } else {
  1136. if (pi->active_auto_throttle_sources & (1 << source)) {
  1137. pi->active_auto_throttle_sources &= ~(1 << source);
  1138. rv6xx_set_dpm_event_sources(rdev, pi->active_auto_throttle_sources);
  1139. }
  1140. }
  1141. }
  1142. static void rv6xx_enable_thermal_protection(struct radeon_device *rdev,
  1143. bool enable)
  1144. {
  1145. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1146. if (pi->active_auto_throttle_sources)
  1147. r600_enable_thermal_protection(rdev, enable);
  1148. }
  1149. static void rv6xx_generate_transition_stepping(struct radeon_device *rdev,
  1150. struct radeon_ps *new_ps,
  1151. struct radeon_ps *old_ps)
  1152. {
  1153. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  1154. struct rv6xx_ps *old_state = rv6xx_get_ps(old_ps);
  1155. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1156. rv6xx_generate_steps(rdev,
  1157. old_state->low.sclk,
  1158. new_state->low.sclk,
  1159. 0, &pi->hw.medium_sclk_index);
  1160. }
  1161. static void rv6xx_generate_low_step(struct radeon_device *rdev,
  1162. struct radeon_ps *new_ps)
  1163. {
  1164. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  1165. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1166. pi->hw.low_sclk_index = 0;
  1167. rv6xx_generate_single_step(rdev,
  1168. new_state->low.sclk,
  1169. 0);
  1170. }
  1171. static void rv6xx_invalidate_intermediate_steps(struct radeon_device *rdev)
  1172. {
  1173. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1174. rv6xx_invalidate_intermediate_steps_range(rdev, 0,
  1175. pi->hw.medium_sclk_index);
  1176. }
  1177. static void rv6xx_generate_stepping_table(struct radeon_device *rdev,
  1178. struct radeon_ps *new_ps)
  1179. {
  1180. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  1181. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1182. pi->hw.low_sclk_index = 0;
  1183. rv6xx_generate_steps(rdev,
  1184. new_state->low.sclk,
  1185. new_state->medium.sclk,
  1186. 0,
  1187. &pi->hw.medium_sclk_index);
  1188. rv6xx_generate_steps(rdev,
  1189. new_state->medium.sclk,
  1190. new_state->high.sclk,
  1191. pi->hw.medium_sclk_index,
  1192. &pi->hw.high_sclk_index);
  1193. }
  1194. static void rv6xx_enable_spread_spectrum(struct radeon_device *rdev,
  1195. bool enable)
  1196. {
  1197. if (enable)
  1198. rv6xx_enable_dynamic_spread_spectrum(rdev, true);
  1199. else {
  1200. rv6xx_enable_engine_spread_spectrum(rdev, R600_POWER_LEVEL_LOW, false);
  1201. rv6xx_enable_engine_spread_spectrum(rdev, R600_POWER_LEVEL_MEDIUM, false);
  1202. rv6xx_enable_engine_spread_spectrum(rdev, R600_POWER_LEVEL_HIGH, false);
  1203. rv6xx_enable_dynamic_spread_spectrum(rdev, false);
  1204. rv6xx_enable_memory_spread_spectrum(rdev, false);
  1205. }
  1206. }
  1207. static void rv6xx_reset_lvtm_data_sync(struct radeon_device *rdev)
  1208. {
  1209. if (ASIC_IS_DCE3(rdev))
  1210. WREG32_P(DCE3_LVTMA_DATA_SYNCHRONIZATION, LVTMA_PFREQCHG, ~LVTMA_PFREQCHG);
  1211. else
  1212. WREG32_P(LVTMA_DATA_SYNCHRONIZATION, LVTMA_PFREQCHG, ~LVTMA_PFREQCHG);
  1213. }
  1214. static void rv6xx_enable_dynamic_pcie_gen2(struct radeon_device *rdev,
  1215. struct radeon_ps *new_ps,
  1216. bool enable)
  1217. {
  1218. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  1219. if (enable) {
  1220. rv6xx_enable_bif_dynamic_pcie_gen2(rdev, true);
  1221. rv6xx_enable_pcie_gen2_support(rdev);
  1222. r600_enable_dynamic_pcie_gen2(rdev, true);
  1223. } else {
  1224. if (!(new_state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2))
  1225. rv6xx_force_pcie_gen1(rdev);
  1226. rv6xx_enable_bif_dynamic_pcie_gen2(rdev, false);
  1227. r600_enable_dynamic_pcie_gen2(rdev, false);
  1228. }
  1229. }
  1230. static void rv6xx_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev,
  1231. struct radeon_ps *new_ps,
  1232. struct radeon_ps *old_ps)
  1233. {
  1234. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  1235. struct rv6xx_ps *current_state = rv6xx_get_ps(old_ps);
  1236. if ((new_ps->vclk == old_ps->vclk) &&
  1237. (new_ps->dclk == old_ps->dclk))
  1238. return;
  1239. if (new_state->high.sclk >= current_state->high.sclk)
  1240. return;
  1241. radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk);
  1242. }
  1243. static void rv6xx_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev,
  1244. struct radeon_ps *new_ps,
  1245. struct radeon_ps *old_ps)
  1246. {
  1247. struct rv6xx_ps *new_state = rv6xx_get_ps(new_ps);
  1248. struct rv6xx_ps *current_state = rv6xx_get_ps(old_ps);
  1249. if ((new_ps->vclk == old_ps->vclk) &&
  1250. (new_ps->dclk == old_ps->dclk))
  1251. return;
  1252. if (new_state->high.sclk < current_state->high.sclk)
  1253. return;
  1254. radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk);
  1255. }
  1256. int rv6xx_dpm_enable(struct radeon_device *rdev)
  1257. {
  1258. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1259. struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps;
  1260. if (r600_dynamicpm_enabled(rdev))
  1261. return -EINVAL;
  1262. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
  1263. rv6xx_enable_backbias(rdev, true);
  1264. if (pi->dynamic_ss)
  1265. rv6xx_enable_spread_spectrum(rdev, true);
  1266. rv6xx_program_mpll_timing_parameters(rdev);
  1267. rv6xx_program_bsp(rdev);
  1268. rv6xx_program_git(rdev);
  1269. rv6xx_program_tp(rdev);
  1270. rv6xx_program_tpp(rdev);
  1271. rv6xx_program_sstp(rdev);
  1272. rv6xx_program_fcp(rdev);
  1273. rv6xx_program_vddc3d_parameters(rdev);
  1274. rv6xx_program_voltage_timing_parameters(rdev);
  1275. rv6xx_program_engine_speed_parameters(rdev);
  1276. rv6xx_enable_display_gap(rdev, true);
  1277. if (pi->display_gap == false)
  1278. rv6xx_enable_display_gap(rdev, false);
  1279. rv6xx_program_power_level_enter_state(rdev);
  1280. rv6xx_calculate_stepping_parameters(rdev, boot_ps);
  1281. if (pi->voltage_control)
  1282. rv6xx_program_voltage_gpio_pins(rdev);
  1283. rv6xx_generate_stepping_table(rdev, boot_ps);
  1284. rv6xx_program_stepping_parameters_except_lowest_entry(rdev);
  1285. rv6xx_program_stepping_parameters_lowest_entry(rdev);
  1286. rv6xx_program_power_level_low(rdev);
  1287. rv6xx_program_power_level_medium(rdev);
  1288. rv6xx_program_power_level_high(rdev);
  1289. rv6xx_program_vc(rdev);
  1290. rv6xx_program_at(rdev);
  1291. r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true);
  1292. r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, true);
  1293. r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, true);
  1294. rv6xx_enable_auto_throttle_source(rdev, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL, true);
  1295. r600_start_dpm(rdev);
  1296. if (pi->voltage_control)
  1297. rv6xx_enable_static_voltage_control(rdev, boot_ps, false);
  1298. if (pi->dynamic_pcie_gen2)
  1299. rv6xx_enable_dynamic_pcie_gen2(rdev, boot_ps, true);
  1300. if (pi->gfx_clock_gating)
  1301. r600_gfx_clockgating_enable(rdev, true);
  1302. return 0;
  1303. }
  1304. void rv6xx_dpm_disable(struct radeon_device *rdev)
  1305. {
  1306. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1307. struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps;
  1308. if (!r600_dynamicpm_enabled(rdev))
  1309. return;
  1310. r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true);
  1311. r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, true);
  1312. rv6xx_enable_display_gap(rdev, false);
  1313. rv6xx_clear_vc(rdev);
  1314. r600_set_at(rdev, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
  1315. if (pi->thermal_protection)
  1316. r600_enable_thermal_protection(rdev, false);
  1317. r600_wait_for_power_level(rdev, R600_POWER_LEVEL_LOW);
  1318. r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, false);
  1319. r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, false);
  1320. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
  1321. rv6xx_enable_backbias(rdev, false);
  1322. rv6xx_enable_spread_spectrum(rdev, false);
  1323. if (pi->voltage_control)
  1324. rv6xx_enable_static_voltage_control(rdev, boot_ps, true);
  1325. if (pi->dynamic_pcie_gen2)
  1326. rv6xx_enable_dynamic_pcie_gen2(rdev, boot_ps, false);
  1327. if (rdev->irq.installed &&
  1328. r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
  1329. rdev->irq.dpm_thermal = false;
  1330. radeon_irq_set(rdev);
  1331. }
  1332. if (pi->gfx_clock_gating)
  1333. r600_gfx_clockgating_enable(rdev, false);
  1334. r600_stop_dpm(rdev);
  1335. }
  1336. int rv6xx_dpm_set_power_state(struct radeon_device *rdev)
  1337. {
  1338. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1339. struct radeon_ps *new_ps = rdev->pm.dpm.requested_ps;
  1340. struct radeon_ps *old_ps = rdev->pm.dpm.current_ps;
  1341. int ret;
  1342. pi->restricted_levels = 0;
  1343. rv6xx_set_uvd_clock_before_set_eng_clock(rdev, new_ps, old_ps);
  1344. rv6xx_clear_vc(rdev);
  1345. r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true);
  1346. r600_set_at(rdev, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
  1347. if (pi->thermal_protection)
  1348. r600_enable_thermal_protection(rdev, false);
  1349. r600_wait_for_power_level(rdev, R600_POWER_LEVEL_LOW);
  1350. r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, false);
  1351. r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, false);
  1352. rv6xx_generate_transition_stepping(rdev, new_ps, old_ps);
  1353. rv6xx_program_power_level_medium_for_transition(rdev);
  1354. if (pi->voltage_control) {
  1355. rv6xx_set_sw_voltage_to_safe(rdev, new_ps, old_ps);
  1356. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC)
  1357. rv6xx_set_sw_voltage_to_low(rdev, old_ps);
  1358. }
  1359. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
  1360. rv6xx_set_safe_backbias(rdev, new_ps, old_ps);
  1361. if (pi->dynamic_pcie_gen2)
  1362. rv6xx_set_safe_pcie_gen2(rdev, new_ps, old_ps);
  1363. if (pi->voltage_control)
  1364. rv6xx_enable_dynamic_voltage_control(rdev, false);
  1365. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
  1366. rv6xx_enable_dynamic_backbias_control(rdev, false);
  1367. if (pi->voltage_control) {
  1368. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC)
  1369. rv6xx_step_voltage_if_increasing(rdev, new_ps, old_ps);
  1370. msleep((rdev->pm.dpm.voltage_response_time + 999) / 1000);
  1371. }
  1372. r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, true);
  1373. r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, false);
  1374. r600_wait_for_power_level_unequal(rdev, R600_POWER_LEVEL_LOW);
  1375. rv6xx_generate_low_step(rdev, new_ps);
  1376. rv6xx_invalidate_intermediate_steps(rdev);
  1377. rv6xx_calculate_stepping_parameters(rdev, new_ps);
  1378. rv6xx_program_stepping_parameters_lowest_entry(rdev);
  1379. rv6xx_program_power_level_low_to_lowest_state(rdev);
  1380. r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true);
  1381. r600_wait_for_power_level(rdev, R600_POWER_LEVEL_LOW);
  1382. r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, false);
  1383. if (pi->voltage_control) {
  1384. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC) {
  1385. ret = rv6xx_step_voltage_if_decreasing(rdev, new_ps, old_ps);
  1386. if (ret)
  1387. return ret;
  1388. }
  1389. rv6xx_enable_dynamic_voltage_control(rdev, true);
  1390. }
  1391. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
  1392. rv6xx_enable_dynamic_backbias_control(rdev, true);
  1393. if (pi->dynamic_pcie_gen2)
  1394. rv6xx_enable_dynamic_pcie_gen2(rdev, new_ps, true);
  1395. rv6xx_reset_lvtm_data_sync(rdev);
  1396. rv6xx_generate_stepping_table(rdev, new_ps);
  1397. rv6xx_program_stepping_parameters_except_lowest_entry(rdev);
  1398. rv6xx_program_power_level_low(rdev);
  1399. rv6xx_program_power_level_medium(rdev);
  1400. rv6xx_program_power_level_high(rdev);
  1401. rv6xx_enable_medium(rdev);
  1402. rv6xx_enable_high(rdev);
  1403. if (pi->thermal_protection)
  1404. rv6xx_enable_thermal_protection(rdev, true);
  1405. rv6xx_program_vc(rdev);
  1406. rv6xx_program_at(rdev);
  1407. rv6xx_set_uvd_clock_after_set_eng_clock(rdev, new_ps, old_ps);
  1408. return 0;
  1409. }
  1410. void rv6xx_setup_asic(struct radeon_device *rdev)
  1411. {
  1412. r600_enable_acpi_pm(rdev);
  1413. if (radeon_aspm != 0) {
  1414. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_ASPM_L0s)
  1415. rv6xx_enable_l0s(rdev);
  1416. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_ASPM_L1)
  1417. rv6xx_enable_l1(rdev);
  1418. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_TURNOFFPLL_ASPML1)
  1419. rv6xx_enable_pll_sleep_in_l1(rdev);
  1420. }
  1421. }
  1422. void rv6xx_dpm_display_configuration_changed(struct radeon_device *rdev)
  1423. {
  1424. rv6xx_program_display_gap(rdev);
  1425. }
  1426. union power_info {
  1427. struct _ATOM_POWERPLAY_INFO info;
  1428. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1429. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1430. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  1431. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  1432. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  1433. };
  1434. union pplib_clock_info {
  1435. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  1436. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  1437. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  1438. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  1439. };
  1440. union pplib_power_state {
  1441. struct _ATOM_PPLIB_STATE v1;
  1442. struct _ATOM_PPLIB_STATE_V2 v2;
  1443. };
  1444. static void rv6xx_parse_pplib_non_clock_info(struct radeon_device *rdev,
  1445. struct radeon_ps *rps,
  1446. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
  1447. {
  1448. rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  1449. rps->class = le16_to_cpu(non_clock_info->usClassification);
  1450. rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
  1451. if (r600_is_uvd_state(rps->class, rps->class2)) {
  1452. rps->vclk = RV6XX_DEFAULT_VCLK_FREQ;
  1453. rps->dclk = RV6XX_DEFAULT_DCLK_FREQ;
  1454. } else {
  1455. rps->vclk = 0;
  1456. rps->dclk = 0;
  1457. }
  1458. if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT)
  1459. rdev->pm.dpm.boot_ps = rps;
  1460. if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
  1461. rdev->pm.dpm.uvd_ps = rps;
  1462. }
  1463. static void rv6xx_parse_pplib_clock_info(struct radeon_device *rdev,
  1464. struct radeon_ps *rps, int index,
  1465. union pplib_clock_info *clock_info)
  1466. {
  1467. struct rv6xx_ps *ps = rv6xx_get_ps(rps);
  1468. u32 sclk, mclk;
  1469. u16 vddc;
  1470. struct rv6xx_pl *pl;
  1471. switch (index) {
  1472. case 0:
  1473. pl = &ps->low;
  1474. break;
  1475. case 1:
  1476. pl = &ps->medium;
  1477. break;
  1478. case 2:
  1479. default:
  1480. pl = &ps->high;
  1481. break;
  1482. }
  1483. sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
  1484. sclk |= clock_info->r600.ucEngineClockHigh << 16;
  1485. mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
  1486. mclk |= clock_info->r600.ucMemoryClockHigh << 16;
  1487. pl->mclk = mclk;
  1488. pl->sclk = sclk;
  1489. pl->vddc = le16_to_cpu(clock_info->r600.usVDDC);
  1490. pl->flags = le32_to_cpu(clock_info->r600.ulFlags);
  1491. /* patch up vddc if necessary */
  1492. if (pl->vddc == 0xff01) {
  1493. if (radeon_atom_get_max_vddc(rdev, 0, 0, &vddc) == 0)
  1494. pl->vddc = vddc;
  1495. }
  1496. /* fix up pcie gen2 */
  1497. if (pl->flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) {
  1498. if ((rdev->family == CHIP_RV610) || (rdev->family == CHIP_RV630)) {
  1499. if (pl->vddc < 1100)
  1500. pl->flags &= ~ATOM_PPLIB_R600_FLAGS_PCIEGEN2;
  1501. }
  1502. }
  1503. /* patch up boot state */
  1504. if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  1505. u16 vddc, vddci, mvdd;
  1506. radeon_atombios_get_default_voltages(rdev, &vddc, &vddci, &mvdd);
  1507. pl->mclk = rdev->clock.default_mclk;
  1508. pl->sclk = rdev->clock.default_sclk;
  1509. pl->vddc = vddc;
  1510. }
  1511. }
  1512. static int rv6xx_parse_power_table(struct radeon_device *rdev)
  1513. {
  1514. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1515. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  1516. union pplib_power_state *power_state;
  1517. int i, j;
  1518. union pplib_clock_info *clock_info;
  1519. union power_info *power_info;
  1520. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1521. u16 data_offset;
  1522. u8 frev, crev;
  1523. struct rv6xx_ps *ps;
  1524. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  1525. &frev, &crev, &data_offset))
  1526. return -EINVAL;
  1527. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1528. rdev->pm.dpm.ps = kzalloc(sizeof(struct radeon_ps) *
  1529. power_info->pplib.ucNumStates, GFP_KERNEL);
  1530. if (!rdev->pm.dpm.ps)
  1531. return -ENOMEM;
  1532. for (i = 0; i < power_info->pplib.ucNumStates; i++) {
  1533. power_state = (union pplib_power_state *)
  1534. (mode_info->atom_context->bios + data_offset +
  1535. le16_to_cpu(power_info->pplib.usStateArrayOffset) +
  1536. i * power_info->pplib.ucStateEntrySize);
  1537. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  1538. (mode_info->atom_context->bios + data_offset +
  1539. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
  1540. (power_state->v1.ucNonClockStateIndex *
  1541. power_info->pplib.ucNonClockSize));
  1542. if (power_info->pplib.ucStateEntrySize - 1) {
  1543. u8 *idx;
  1544. ps = kzalloc(sizeof(struct rv6xx_ps), GFP_KERNEL);
  1545. if (ps == NULL) {
  1546. kfree(rdev->pm.dpm.ps);
  1547. return -ENOMEM;
  1548. }
  1549. rdev->pm.dpm.ps[i].ps_priv = ps;
  1550. rv6xx_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i],
  1551. non_clock_info);
  1552. idx = (u8 *)&power_state->v1.ucClockStateIndices[0];
  1553. for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
  1554. clock_info = (union pplib_clock_info *)
  1555. (mode_info->atom_context->bios + data_offset +
  1556. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
  1557. (idx[j] * power_info->pplib.ucClockInfoSize));
  1558. rv6xx_parse_pplib_clock_info(rdev,
  1559. &rdev->pm.dpm.ps[i], j,
  1560. clock_info);
  1561. }
  1562. }
  1563. }
  1564. rdev->pm.dpm.num_ps = power_info->pplib.ucNumStates;
  1565. return 0;
  1566. }
  1567. int rv6xx_dpm_init(struct radeon_device *rdev)
  1568. {
  1569. struct radeon_atom_ss ss;
  1570. struct atom_clock_dividers dividers;
  1571. struct rv6xx_power_info *pi;
  1572. int ret;
  1573. pi = kzalloc(sizeof(struct rv6xx_power_info), GFP_KERNEL);
  1574. if (pi == NULL)
  1575. return -ENOMEM;
  1576. rdev->pm.dpm.priv = pi;
  1577. ret = r600_get_platform_caps(rdev);
  1578. if (ret)
  1579. return ret;
  1580. ret = rv6xx_parse_power_table(rdev);
  1581. if (ret)
  1582. return ret;
  1583. if (rdev->pm.dpm.voltage_response_time == 0)
  1584. rdev->pm.dpm.voltage_response_time = R600_VOLTAGERESPONSETIME_DFLT;
  1585. if (rdev->pm.dpm.backbias_response_time == 0)
  1586. rdev->pm.dpm.backbias_response_time = R600_BACKBIASRESPONSETIME_DFLT;
  1587. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  1588. 0, false, &dividers);
  1589. if (ret)
  1590. pi->spll_ref_div = dividers.ref_div + 1;
  1591. else
  1592. pi->spll_ref_div = R600_REFERENCEDIVIDER_DFLT;
  1593. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM,
  1594. 0, false, &dividers);
  1595. if (ret)
  1596. pi->mpll_ref_div = dividers.ref_div + 1;
  1597. else
  1598. pi->mpll_ref_div = R600_REFERENCEDIVIDER_DFLT;
  1599. if (rdev->family >= CHIP_RV670)
  1600. pi->fb_div_scale = 1;
  1601. else
  1602. pi->fb_div_scale = 0;
  1603. pi->voltage_control =
  1604. radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, 0);
  1605. pi->gfx_clock_gating = true;
  1606. pi->sclk_ss = radeon_atombios_get_asic_ss_info(rdev, &ss,
  1607. ASIC_INTERNAL_ENGINE_SS, 0);
  1608. pi->mclk_ss = radeon_atombios_get_asic_ss_info(rdev, &ss,
  1609. ASIC_INTERNAL_MEMORY_SS, 0);
  1610. /* Disable sclk ss, causes hangs on a lot of systems */
  1611. pi->sclk_ss = false;
  1612. if (pi->sclk_ss || pi->mclk_ss)
  1613. pi->dynamic_ss = true;
  1614. else
  1615. pi->dynamic_ss = false;
  1616. pi->dynamic_pcie_gen2 = true;
  1617. if (pi->gfx_clock_gating &&
  1618. (rdev->pm.int_thermal_type != THERMAL_TYPE_NONE))
  1619. pi->thermal_protection = true;
  1620. else
  1621. pi->thermal_protection = false;
  1622. pi->display_gap = true;
  1623. return 0;
  1624. }
  1625. void rv6xx_dpm_print_power_state(struct radeon_device *rdev,
  1626. struct radeon_ps *rps)
  1627. {
  1628. struct rv6xx_ps *ps = rv6xx_get_ps(rps);
  1629. struct rv6xx_pl *pl;
  1630. r600_dpm_print_class_info(rps->class, rps->class2);
  1631. r600_dpm_print_cap_info(rps->caps);
  1632. printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  1633. pl = &ps->low;
  1634. printk("\t\tpower level 0 sclk: %u mclk: %u vddc: %u\n",
  1635. pl->sclk, pl->mclk, pl->vddc);
  1636. pl = &ps->medium;
  1637. printk("\t\tpower level 1 sclk: %u mclk: %u vddc: %u\n",
  1638. pl->sclk, pl->mclk, pl->vddc);
  1639. pl = &ps->high;
  1640. printk("\t\tpower level 2 sclk: %u mclk: %u vddc: %u\n",
  1641. pl->sclk, pl->mclk, pl->vddc);
  1642. r600_dpm_print_ps_status(rdev, rps);
  1643. }
  1644. void rv6xx_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
  1645. struct seq_file *m)
  1646. {
  1647. struct radeon_ps *rps = rdev->pm.dpm.current_ps;
  1648. struct rv6xx_ps *ps = rv6xx_get_ps(rps);
  1649. struct rv6xx_pl *pl;
  1650. u32 current_index =
  1651. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >>
  1652. CURRENT_PROFILE_INDEX_SHIFT;
  1653. if (current_index > 2) {
  1654. seq_printf(m, "invalid dpm profile %d\n", current_index);
  1655. } else {
  1656. if (current_index == 0)
  1657. pl = &ps->low;
  1658. else if (current_index == 1)
  1659. pl = &ps->medium;
  1660. else /* current_index == 2 */
  1661. pl = &ps->high;
  1662. seq_printf(m, "uvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  1663. seq_printf(m, "power level %d sclk: %u mclk: %u vddc: %u\n",
  1664. current_index, pl->sclk, pl->mclk, pl->vddc);
  1665. }
  1666. }
  1667. /* get the current sclk in 10 khz units */
  1668. u32 rv6xx_dpm_get_current_sclk(struct radeon_device *rdev)
  1669. {
  1670. struct radeon_ps *rps = rdev->pm.dpm.current_ps;
  1671. struct rv6xx_ps *ps = rv6xx_get_ps(rps);
  1672. struct rv6xx_pl *pl;
  1673. u32 current_index =
  1674. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >>
  1675. CURRENT_PROFILE_INDEX_SHIFT;
  1676. if (current_index > 2) {
  1677. return 0;
  1678. } else {
  1679. if (current_index == 0)
  1680. pl = &ps->low;
  1681. else if (current_index == 1)
  1682. pl = &ps->medium;
  1683. else /* current_index == 2 */
  1684. pl = &ps->high;
  1685. return pl->sclk;
  1686. }
  1687. }
  1688. /* get the current mclk in 10 khz units */
  1689. u32 rv6xx_dpm_get_current_mclk(struct radeon_device *rdev)
  1690. {
  1691. struct radeon_ps *rps = rdev->pm.dpm.current_ps;
  1692. struct rv6xx_ps *ps = rv6xx_get_ps(rps);
  1693. struct rv6xx_pl *pl;
  1694. u32 current_index =
  1695. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >>
  1696. CURRENT_PROFILE_INDEX_SHIFT;
  1697. if (current_index > 2) {
  1698. return 0;
  1699. } else {
  1700. if (current_index == 0)
  1701. pl = &ps->low;
  1702. else if (current_index == 1)
  1703. pl = &ps->medium;
  1704. else /* current_index == 2 */
  1705. pl = &ps->high;
  1706. return pl->mclk;
  1707. }
  1708. }
  1709. void rv6xx_dpm_fini(struct radeon_device *rdev)
  1710. {
  1711. int i;
  1712. for (i = 0; i < rdev->pm.dpm.num_ps; i++) {
  1713. kfree(rdev->pm.dpm.ps[i].ps_priv);
  1714. }
  1715. kfree(rdev->pm.dpm.ps);
  1716. kfree(rdev->pm.dpm.priv);
  1717. }
  1718. u32 rv6xx_dpm_get_sclk(struct radeon_device *rdev, bool low)
  1719. {
  1720. struct rv6xx_ps *requested_state = rv6xx_get_ps(rdev->pm.dpm.requested_ps);
  1721. if (low)
  1722. return requested_state->low.sclk;
  1723. else
  1724. return requested_state->high.sclk;
  1725. }
  1726. u32 rv6xx_dpm_get_mclk(struct radeon_device *rdev, bool low)
  1727. {
  1728. struct rv6xx_ps *requested_state = rv6xx_get_ps(rdev->pm.dpm.requested_ps);
  1729. if (low)
  1730. return requested_state->low.mclk;
  1731. else
  1732. return requested_state->high.mclk;
  1733. }
  1734. int rv6xx_dpm_force_performance_level(struct radeon_device *rdev,
  1735. enum radeon_dpm_forced_level level)
  1736. {
  1737. struct rv6xx_power_info *pi = rv6xx_get_pi(rdev);
  1738. if (level == RADEON_DPM_FORCED_LEVEL_HIGH) {
  1739. pi->restricted_levels = 3;
  1740. } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) {
  1741. pi->restricted_levels = 2;
  1742. } else {
  1743. pi->restricted_levels = 0;
  1744. }
  1745. rv6xx_clear_vc(rdev);
  1746. r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true);
  1747. r600_set_at(rdev, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
  1748. r600_wait_for_power_level(rdev, R600_POWER_LEVEL_LOW);
  1749. r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, false);
  1750. r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, false);
  1751. rv6xx_enable_medium(rdev);
  1752. rv6xx_enable_high(rdev);
  1753. if (pi->restricted_levels == 3)
  1754. r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, false);
  1755. rv6xx_program_vc(rdev);
  1756. rv6xx_program_at(rdev);
  1757. rdev->pm.dpm.forced_level = level;
  1758. return 0;
  1759. }