tonga_smc.c 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275
  1. /*
  2. * Copyright 2015 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  8. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  9. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  10. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  11. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  12. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  13. * OTHER DEALINGS IN THE SOFTWARE.
  14. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. * and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included in
  19. * all copies or substantial portions of the Software.
  20. *
  21. *
  22. */
  23. #include "pp_debug.h"
  24. #include "tonga_smc.h"
  25. #include "smu7_dyn_defaults.h"
  26. #include "smu7_hwmgr.h"
  27. #include "hardwaremanager.h"
  28. #include "ppatomctrl.h"
  29. #include "cgs_common.h"
  30. #include "atombios.h"
  31. #include "tonga_smumgr.h"
  32. #include "pppcielanes.h"
  33. #include "pp_endian.h"
  34. #include "smu7_ppsmc.h"
  35. #include "smu72_discrete.h"
  36. #include "smu/smu_7_1_2_d.h"
  37. #include "smu/smu_7_1_2_sh_mask.h"
  38. #include "gmc/gmc_8_1_d.h"
  39. #include "gmc/gmc_8_1_sh_mask.h"
  40. #include "bif/bif_5_0_d.h"
  41. #include "bif/bif_5_0_sh_mask.h"
  42. #include "dce/dce_10_0_d.h"
  43. #include "dce/dce_10_0_sh_mask.h"
  44. #define VOLTAGE_SCALE 4
  45. #define POWERTUNE_DEFAULT_SET_MAX 1
  46. #define VOLTAGE_VID_OFFSET_SCALE1 625
  47. #define VOLTAGE_VID_OFFSET_SCALE2 100
  48. #define MC_CG_ARB_FREQ_F1 0x0b
  49. #define VDDC_VDDCI_DELTA 200
  50. static const struct tonga_pt_defaults tonga_power_tune_data_set_array[POWERTUNE_DEFAULT_SET_MAX] = {
  51. /* sviLoadLIneEn, SviLoadLineVddC, TDC_VDDC_ThrottleReleaseLimitPerc, TDC_MAWt,
  52. * TdcWaterfallCtl, DTEAmbientTempBase, DisplayCac, BAPM_TEMP_GRADIENT
  53. */
  54. {1, 0xF, 0xFD, 0x19,
  55. 5, 45, 0, 0xB0000,
  56. {0x79, 0x253, 0x25D, 0xAE, 0x72, 0x80, 0x83, 0x86, 0x6F, 0xC8,
  57. 0xC9, 0xC9, 0x2F, 0x4D, 0x61},
  58. {0x17C, 0x172, 0x180, 0x1BC, 0x1B3, 0x1BD, 0x206, 0x200, 0x203,
  59. 0x25D, 0x25A, 0x255, 0x2C3, 0x2C5, 0x2B4}
  60. },
  61. };
  62. /* [Fmin, Fmax, LDO_REFSEL, USE_FOR_LOW_FREQ] */
  63. static const uint16_t tonga_clock_stretcher_lookup_table[2][4] = {
  64. {600, 1050, 3, 0},
  65. {600, 1050, 6, 1}
  66. };
  67. /* [FF, SS] type, [] 4 voltage ranges,
  68. * and [Floor Freq, Boundary Freq, VID min , VID max]
  69. */
  70. static const uint32_t tonga_clock_stretcher_ddt_table[2][4][4] = {
  71. { {265, 529, 120, 128}, {325, 650, 96, 119}, {430, 860, 32, 95}, {0, 0, 0, 31} },
  72. { {275, 550, 104, 112}, {319, 638, 96, 103}, {360, 720, 64, 95}, {384, 768, 32, 63} }
  73. };
  74. /* [Use_For_Low_freq] value, [0%, 5%, 10%, 7.14%, 14.28%, 20%] */
  75. static const uint8_t tonga_clock_stretch_amount_conversion[2][6] = {
  76. {0, 1, 3, 2, 4, 5},
  77. {0, 2, 4, 5, 6, 5}
  78. };
  79. /* PPGen has the gain setting generated in x * 100 unit
  80. * This function is to convert the unit to x * 4096(0x1000) unit.
  81. * This is the unit expected by SMC firmware
  82. */
  83. static int tonga_get_dependecy_volt_by_clk(struct pp_hwmgr *hwmgr,
  84. phm_ppt_v1_clock_voltage_dependency_table *allowed_clock_voltage_table,
  85. uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd)
  86. {
  87. uint32_t i = 0;
  88. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  89. struct phm_ppt_v1_information *pptable_info =
  90. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  91. /* clock - voltage dependency table is empty table */
  92. if (allowed_clock_voltage_table->count == 0)
  93. return -EINVAL;
  94. for (i = 0; i < allowed_clock_voltage_table->count; i++) {
  95. /* find first sclk bigger than request */
  96. if (allowed_clock_voltage_table->entries[i].clk >= clock) {
  97. voltage->VddGfx = phm_get_voltage_index(
  98. pptable_info->vddgfx_lookup_table,
  99. allowed_clock_voltage_table->entries[i].vddgfx);
  100. voltage->Vddc = phm_get_voltage_index(
  101. pptable_info->vddc_lookup_table,
  102. allowed_clock_voltage_table->entries[i].vddc);
  103. if (allowed_clock_voltage_table->entries[i].vddci)
  104. voltage->Vddci =
  105. phm_get_voltage_id(&data->vddci_voltage_table, allowed_clock_voltage_table->entries[i].vddci);
  106. else
  107. voltage->Vddci =
  108. phm_get_voltage_id(&data->vddci_voltage_table,
  109. allowed_clock_voltage_table->entries[i].vddc - VDDC_VDDCI_DELTA);
  110. if (allowed_clock_voltage_table->entries[i].mvdd)
  111. *mvdd = (uint32_t) allowed_clock_voltage_table->entries[i].mvdd;
  112. voltage->Phases = 1;
  113. return 0;
  114. }
  115. }
  116. /* sclk is bigger than max sclk in the dependence table */
  117. voltage->VddGfx = phm_get_voltage_index(pptable_info->vddgfx_lookup_table,
  118. allowed_clock_voltage_table->entries[i-1].vddgfx);
  119. voltage->Vddc = phm_get_voltage_index(pptable_info->vddc_lookup_table,
  120. allowed_clock_voltage_table->entries[i-1].vddc);
  121. if (allowed_clock_voltage_table->entries[i-1].vddci)
  122. voltage->Vddci = phm_get_voltage_id(&data->vddci_voltage_table,
  123. allowed_clock_voltage_table->entries[i-1].vddci);
  124. if (allowed_clock_voltage_table->entries[i-1].mvdd)
  125. *mvdd = (uint32_t) allowed_clock_voltage_table->entries[i-1].mvdd;
  126. return 0;
  127. }
  128. /**
  129. * Vddc table preparation for SMC.
  130. *
  131. * @param hwmgr the address of the hardware manager
  132. * @param table the SMC DPM table structure to be populated
  133. * @return always 0
  134. */
  135. static int tonga_populate_smc_vddc_table(struct pp_hwmgr *hwmgr,
  136. SMU72_Discrete_DpmTable *table)
  137. {
  138. unsigned int count;
  139. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  140. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
  141. table->VddcLevelCount = data->vddc_voltage_table.count;
  142. for (count = 0; count < table->VddcLevelCount; count++) {
  143. table->VddcTable[count] =
  144. PP_HOST_TO_SMC_US(data->vddc_voltage_table.entries[count].value * VOLTAGE_SCALE);
  145. }
  146. CONVERT_FROM_HOST_TO_SMC_UL(table->VddcLevelCount);
  147. }
  148. return 0;
  149. }
  150. /**
  151. * VddGfx table preparation for SMC.
  152. *
  153. * @param hwmgr the address of the hardware manager
  154. * @param table the SMC DPM table structure to be populated
  155. * @return always 0
  156. */
  157. static int tonga_populate_smc_vdd_gfx_table(struct pp_hwmgr *hwmgr,
  158. SMU72_Discrete_DpmTable *table)
  159. {
  160. unsigned int count;
  161. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  162. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) {
  163. table->VddGfxLevelCount = data->vddgfx_voltage_table.count;
  164. for (count = 0; count < data->vddgfx_voltage_table.count; count++) {
  165. table->VddGfxTable[count] =
  166. PP_HOST_TO_SMC_US(data->vddgfx_voltage_table.entries[count].value * VOLTAGE_SCALE);
  167. }
  168. CONVERT_FROM_HOST_TO_SMC_UL(table->VddGfxLevelCount);
  169. }
  170. return 0;
  171. }
  172. /**
  173. * Vddci table preparation for SMC.
  174. *
  175. * @param *hwmgr The address of the hardware manager.
  176. * @param *table The SMC DPM table structure to be populated.
  177. * @return 0
  178. */
  179. static int tonga_populate_smc_vdd_ci_table(struct pp_hwmgr *hwmgr,
  180. SMU72_Discrete_DpmTable *table)
  181. {
  182. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  183. uint32_t count;
  184. table->VddciLevelCount = data->vddci_voltage_table.count;
  185. for (count = 0; count < table->VddciLevelCount; count++) {
  186. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
  187. table->VddciTable[count] =
  188. PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[count].value * VOLTAGE_SCALE);
  189. } else if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
  190. table->SmioTable1.Pattern[count].Voltage =
  191. PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[count].value * VOLTAGE_SCALE);
  192. /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level. */
  193. table->SmioTable1.Pattern[count].Smio =
  194. (uint8_t) count;
  195. table->Smio[count] |=
  196. data->vddci_voltage_table.entries[count].smio_low;
  197. table->VddciTable[count] =
  198. PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[count].value * VOLTAGE_SCALE);
  199. }
  200. }
  201. table->SmioMask1 = data->vddci_voltage_table.mask_low;
  202. CONVERT_FROM_HOST_TO_SMC_UL(table->VddciLevelCount);
  203. return 0;
  204. }
  205. /**
  206. * Mvdd table preparation for SMC.
  207. *
  208. * @param *hwmgr The address of the hardware manager.
  209. * @param *table The SMC DPM table structure to be populated.
  210. * @return 0
  211. */
  212. static int tonga_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr,
  213. SMU72_Discrete_DpmTable *table)
  214. {
  215. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  216. uint32_t count;
  217. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
  218. table->MvddLevelCount = data->mvdd_voltage_table.count;
  219. for (count = 0; count < table->MvddLevelCount; count++) {
  220. table->SmioTable2.Pattern[count].Voltage =
  221. PP_HOST_TO_SMC_US(data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE);
  222. /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/
  223. table->SmioTable2.Pattern[count].Smio =
  224. (uint8_t) count;
  225. table->Smio[count] |=
  226. data->mvdd_voltage_table.entries[count].smio_low;
  227. }
  228. table->SmioMask2 = data->mvdd_voltage_table.mask_low;
  229. CONVERT_FROM_HOST_TO_SMC_UL(table->MvddLevelCount);
  230. }
  231. return 0;
  232. }
  233. /**
  234. * Preparation of vddc and vddgfx CAC tables for SMC.
  235. *
  236. * @param hwmgr the address of the hardware manager
  237. * @param table the SMC DPM table structure to be populated
  238. * @return always 0
  239. */
  240. static int tonga_populate_cac_tables(struct pp_hwmgr *hwmgr,
  241. SMU72_Discrete_DpmTable *table)
  242. {
  243. uint32_t count;
  244. uint8_t index = 0;
  245. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  246. struct phm_ppt_v1_information *pptable_info =
  247. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  248. struct phm_ppt_v1_voltage_lookup_table *vddgfx_lookup_table =
  249. pptable_info->vddgfx_lookup_table;
  250. struct phm_ppt_v1_voltage_lookup_table *vddc_lookup_table =
  251. pptable_info->vddc_lookup_table;
  252. /* table is already swapped, so in order to use the value from it
  253. * we need to swap it back.
  254. */
  255. uint32_t vddc_level_count = PP_SMC_TO_HOST_UL(table->VddcLevelCount);
  256. uint32_t vddgfx_level_count = PP_SMC_TO_HOST_UL(table->VddGfxLevelCount);
  257. for (count = 0; count < vddc_level_count; count++) {
  258. /* We are populating vddc CAC data to BapmVddc table in split and merged mode */
  259. index = phm_get_voltage_index(vddc_lookup_table,
  260. data->vddc_voltage_table.entries[count].value);
  261. table->BapmVddcVidLoSidd[count] =
  262. convert_to_vid(vddc_lookup_table->entries[index].us_cac_low);
  263. table->BapmVddcVidHiSidd[count] =
  264. convert_to_vid(vddc_lookup_table->entries[index].us_cac_mid);
  265. table->BapmVddcVidHiSidd2[count] =
  266. convert_to_vid(vddc_lookup_table->entries[index].us_cac_high);
  267. }
  268. if ((data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2)) {
  269. /* We are populating vddgfx CAC data to BapmVddgfx table in split mode */
  270. for (count = 0; count < vddgfx_level_count; count++) {
  271. index = phm_get_voltage_index(vddgfx_lookup_table,
  272. convert_to_vid(vddgfx_lookup_table->entries[index].us_cac_mid));
  273. table->BapmVddGfxVidHiSidd2[count] =
  274. convert_to_vid(vddgfx_lookup_table->entries[index].us_cac_high);
  275. }
  276. } else {
  277. for (count = 0; count < vddc_level_count; count++) {
  278. index = phm_get_voltage_index(vddc_lookup_table,
  279. data->vddc_voltage_table.entries[count].value);
  280. table->BapmVddGfxVidLoSidd[count] =
  281. convert_to_vid(vddc_lookup_table->entries[index].us_cac_low);
  282. table->BapmVddGfxVidHiSidd[count] =
  283. convert_to_vid(vddc_lookup_table->entries[index].us_cac_mid);
  284. table->BapmVddGfxVidHiSidd2[count] =
  285. convert_to_vid(vddc_lookup_table->entries[index].us_cac_high);
  286. }
  287. }
  288. return 0;
  289. }
  290. /**
  291. * Preparation of voltage tables for SMC.
  292. *
  293. * @param hwmgr the address of the hardware manager
  294. * @param table the SMC DPM table structure to be populated
  295. * @return always 0
  296. */
  297. static int tonga_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
  298. SMU72_Discrete_DpmTable *table)
  299. {
  300. int result;
  301. result = tonga_populate_smc_vddc_table(hwmgr, table);
  302. PP_ASSERT_WITH_CODE(!result,
  303. "can not populate VDDC voltage table to SMC",
  304. return -EINVAL);
  305. result = tonga_populate_smc_vdd_ci_table(hwmgr, table);
  306. PP_ASSERT_WITH_CODE(!result,
  307. "can not populate VDDCI voltage table to SMC",
  308. return -EINVAL);
  309. result = tonga_populate_smc_vdd_gfx_table(hwmgr, table);
  310. PP_ASSERT_WITH_CODE(!result,
  311. "can not populate VDDGFX voltage table to SMC",
  312. return -EINVAL);
  313. result = tonga_populate_smc_mvdd_table(hwmgr, table);
  314. PP_ASSERT_WITH_CODE(!result,
  315. "can not populate MVDD voltage table to SMC",
  316. return -EINVAL);
  317. result = tonga_populate_cac_tables(hwmgr, table);
  318. PP_ASSERT_WITH_CODE(!result,
  319. "can not populate CAC voltage tables to SMC",
  320. return -EINVAL);
  321. return 0;
  322. }
  323. static int tonga_populate_ulv_level(struct pp_hwmgr *hwmgr,
  324. struct SMU72_Discrete_Ulv *state)
  325. {
  326. struct phm_ppt_v1_information *table_info =
  327. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  328. state->CcPwrDynRm = 0;
  329. state->CcPwrDynRm1 = 0;
  330. state->VddcOffset = (uint16_t) table_info->us_ulv_voltage_offset;
  331. state->VddcOffsetVid = (uint8_t)(table_info->us_ulv_voltage_offset *
  332. VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1);
  333. state->VddcPhase = 1;
  334. CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm);
  335. CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm1);
  336. CONVERT_FROM_HOST_TO_SMC_US(state->VddcOffset);
  337. return 0;
  338. }
  339. static int tonga_populate_ulv_state(struct pp_hwmgr *hwmgr,
  340. struct SMU72_Discrete_DpmTable *table)
  341. {
  342. return tonga_populate_ulv_level(hwmgr, &table->Ulv);
  343. }
  344. static int tonga_populate_smc_link_level(struct pp_hwmgr *hwmgr, SMU72_Discrete_DpmTable *table)
  345. {
  346. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  347. struct smu7_dpm_table *dpm_table = &data->dpm_table;
  348. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  349. uint32_t i;
  350. /* Index (dpm_table->pcie_speed_table.count) is reserved for PCIE boot level. */
  351. for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
  352. table->LinkLevel[i].PcieGenSpeed =
  353. (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
  354. table->LinkLevel[i].PcieLaneCount =
  355. (uint8_t)encode_pcie_lane_width(dpm_table->pcie_speed_table.dpm_levels[i].param1);
  356. table->LinkLevel[i].EnabledForActivity =
  357. 1;
  358. table->LinkLevel[i].SPC =
  359. (uint8_t)(data->pcie_spc_cap & 0xff);
  360. table->LinkLevel[i].DownThreshold =
  361. PP_HOST_TO_SMC_UL(5);
  362. table->LinkLevel[i].UpThreshold =
  363. PP_HOST_TO_SMC_UL(30);
  364. }
  365. smu_data->smc_state_table.LinkLevelCount =
  366. (uint8_t)dpm_table->pcie_speed_table.count;
  367. data->dpm_level_enable_mask.pcie_dpm_enable_mask =
  368. phm_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
  369. return 0;
  370. }
  371. /**
  372. * Calculates the SCLK dividers using the provided engine clock
  373. *
  374. * @param hwmgr the address of the hardware manager
  375. * @param engine_clock the engine clock to use to populate the structure
  376. * @param sclk the SMC SCLK structure to be populated
  377. */
  378. static int tonga_calculate_sclk_params(struct pp_hwmgr *hwmgr,
  379. uint32_t engine_clock, SMU72_Discrete_GraphicsLevel *sclk)
  380. {
  381. const struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  382. pp_atomctrl_clock_dividers_vi dividers;
  383. uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
  384. uint32_t spll_func_cntl_3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
  385. uint32_t spll_func_cntl_4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
  386. uint32_t cg_spll_spread_spectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
  387. uint32_t cg_spll_spread_spectrum_2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
  388. uint32_t reference_clock;
  389. uint32_t reference_divider;
  390. uint32_t fbdiv;
  391. int result;
  392. /* get the engine clock dividers for this clock value*/
  393. result = atomctrl_get_engine_pll_dividers_vi(hwmgr, engine_clock, &dividers);
  394. PP_ASSERT_WITH_CODE(result == 0,
  395. "Error retrieving Engine Clock dividers from VBIOS.", return result);
  396. /* To get FBDIV we need to multiply this by 16384 and divide it by Fref.*/
  397. reference_clock = atomctrl_get_reference_clock(hwmgr);
  398. reference_divider = 1 + dividers.uc_pll_ref_div;
  399. /* low 14 bits is fraction and high 12 bits is divider*/
  400. fbdiv = dividers.ul_fb_div.ul_fb_divider & 0x3FFFFFF;
  401. /* SPLL_FUNC_CNTL setup*/
  402. spll_func_cntl = PHM_SET_FIELD(spll_func_cntl,
  403. CG_SPLL_FUNC_CNTL, SPLL_REF_DIV, dividers.uc_pll_ref_div);
  404. spll_func_cntl = PHM_SET_FIELD(spll_func_cntl,
  405. CG_SPLL_FUNC_CNTL, SPLL_PDIV_A, dividers.uc_pll_post_div);
  406. /* SPLL_FUNC_CNTL_3 setup*/
  407. spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3,
  408. CG_SPLL_FUNC_CNTL_3, SPLL_FB_DIV, fbdiv);
  409. /* set to use fractional accumulation*/
  410. spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3,
  411. CG_SPLL_FUNC_CNTL_3, SPLL_DITHEN, 1);
  412. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  413. PHM_PlatformCaps_EngineSpreadSpectrumSupport)) {
  414. pp_atomctrl_internal_ss_info ss_info;
  415. uint32_t vcoFreq = engine_clock * dividers.uc_pll_post_div;
  416. if (0 == atomctrl_get_engine_clock_spread_spectrum(hwmgr, vcoFreq, &ss_info)) {
  417. /*
  418. * ss_info.speed_spectrum_percentage -- in unit of 0.01%
  419. * ss_info.speed_spectrum_rate -- in unit of khz
  420. */
  421. /* clks = reference_clock * 10 / (REFDIV + 1) / speed_spectrum_rate / 2 */
  422. uint32_t clkS = reference_clock * 5 / (reference_divider * ss_info.speed_spectrum_rate);
  423. /* clkv = 2 * D * fbdiv / NS */
  424. uint32_t clkV = 4 * ss_info.speed_spectrum_percentage * fbdiv / (clkS * 10000);
  425. cg_spll_spread_spectrum =
  426. PHM_SET_FIELD(cg_spll_spread_spectrum, CG_SPLL_SPREAD_SPECTRUM, CLKS, clkS);
  427. cg_spll_spread_spectrum =
  428. PHM_SET_FIELD(cg_spll_spread_spectrum, CG_SPLL_SPREAD_SPECTRUM, SSEN, 1);
  429. cg_spll_spread_spectrum_2 =
  430. PHM_SET_FIELD(cg_spll_spread_spectrum_2, CG_SPLL_SPREAD_SPECTRUM_2, CLKV, clkV);
  431. }
  432. }
  433. sclk->SclkFrequency = engine_clock;
  434. sclk->CgSpllFuncCntl3 = spll_func_cntl_3;
  435. sclk->CgSpllFuncCntl4 = spll_func_cntl_4;
  436. sclk->SpllSpreadSpectrum = cg_spll_spread_spectrum;
  437. sclk->SpllSpreadSpectrum2 = cg_spll_spread_spectrum_2;
  438. sclk->SclkDid = (uint8_t)dividers.pll_post_divider;
  439. return 0;
  440. }
  441. /**
  442. * Populates single SMC SCLK structure using the provided engine clock
  443. *
  444. * @param hwmgr the address of the hardware manager
  445. * @param engine_clock the engine clock to use to populate the structure
  446. * @param sclk the SMC SCLK structure to be populated
  447. */
  448. static int tonga_populate_single_graphic_level(struct pp_hwmgr *hwmgr,
  449. uint32_t engine_clock,
  450. uint16_t sclk_activity_level_threshold,
  451. SMU72_Discrete_GraphicsLevel *graphic_level)
  452. {
  453. int result;
  454. uint32_t mvdd;
  455. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  456. struct phm_ppt_v1_information *pptable_info =
  457. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  458. result = tonga_calculate_sclk_params(hwmgr, engine_clock, graphic_level);
  459. /* populate graphics levels*/
  460. result = tonga_get_dependecy_volt_by_clk(hwmgr,
  461. pptable_info->vdd_dep_on_sclk, engine_clock,
  462. &graphic_level->MinVoltage, &mvdd);
  463. PP_ASSERT_WITH_CODE((!result),
  464. "can not find VDDC voltage value for VDDC "
  465. "engine clock dependency table", return result);
  466. /* SCLK frequency in units of 10KHz*/
  467. graphic_level->SclkFrequency = engine_clock;
  468. /* Indicates maximum activity level for this performance level. 50% for now*/
  469. graphic_level->ActivityLevel = sclk_activity_level_threshold;
  470. graphic_level->CcPwrDynRm = 0;
  471. graphic_level->CcPwrDynRm1 = 0;
  472. /* this level can be used if activity is high enough.*/
  473. graphic_level->EnabledForActivity = 0;
  474. /* this level can be used for throttling.*/
  475. graphic_level->EnabledForThrottle = 1;
  476. graphic_level->UpHyst = 0;
  477. graphic_level->DownHyst = 0;
  478. graphic_level->VoltageDownHyst = 0;
  479. graphic_level->PowerThrottle = 0;
  480. data->display_timing.min_clock_in_sr =
  481. hwmgr->display_config.min_core_set_clock_in_sr;
  482. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  483. PHM_PlatformCaps_SclkDeepSleep))
  484. graphic_level->DeepSleepDivId =
  485. smu7_get_sleep_divider_id_from_clock(engine_clock,
  486. data->display_timing.min_clock_in_sr);
  487. /* Default to slow, highest DPM level will be set to PPSMC_DISPLAY_WATERMARK_LOW later.*/
  488. graphic_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
  489. if (!result) {
  490. /* CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->MinVoltage);*/
  491. /* CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->MinVddcPhases);*/
  492. CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SclkFrequency);
  493. CONVERT_FROM_HOST_TO_SMC_US(graphic_level->ActivityLevel);
  494. CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CgSpllFuncCntl3);
  495. CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CgSpllFuncCntl4);
  496. CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SpllSpreadSpectrum);
  497. CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SpllSpreadSpectrum2);
  498. CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CcPwrDynRm);
  499. CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CcPwrDynRm1);
  500. }
  501. return result;
  502. }
  503. /**
  504. * Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states
  505. *
  506. * @param hwmgr the address of the hardware manager
  507. */
  508. int tonga_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
  509. {
  510. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  511. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  512. struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
  513. struct smu7_dpm_table *dpm_table = &data->dpm_table;
  514. struct phm_ppt_v1_pcie_table *pcie_table = pptable_info->pcie_table;
  515. uint8_t pcie_entry_count = (uint8_t) data->dpm_table.pcie_speed_table.count;
  516. uint32_t level_array_address = smu_data->smu7_data.dpm_table_start +
  517. offsetof(SMU72_Discrete_DpmTable, GraphicsLevel);
  518. uint32_t level_array_size = sizeof(SMU72_Discrete_GraphicsLevel) *
  519. SMU72_MAX_LEVELS_GRAPHICS;
  520. SMU72_Discrete_GraphicsLevel *levels = smu_data->smc_state_table.GraphicsLevel;
  521. uint32_t i, max_entry;
  522. uint8_t highest_pcie_level_enabled = 0;
  523. uint8_t lowest_pcie_level_enabled = 0, mid_pcie_level_enabled = 0;
  524. uint8_t count = 0;
  525. int result = 0;
  526. memset(levels, 0x00, level_array_size);
  527. for (i = 0; i < dpm_table->sclk_table.count; i++) {
  528. result = tonga_populate_single_graphic_level(hwmgr,
  529. dpm_table->sclk_table.dpm_levels[i].value,
  530. (uint16_t)smu_data->activity_target[i],
  531. &(smu_data->smc_state_table.GraphicsLevel[i]));
  532. if (result != 0)
  533. return result;
  534. /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
  535. if (i > 1)
  536. smu_data->smc_state_table.GraphicsLevel[i].DeepSleepDivId = 0;
  537. }
  538. /* Only enable level 0 for now. */
  539. smu_data->smc_state_table.GraphicsLevel[0].EnabledForActivity = 1;
  540. /* set highest level watermark to high */
  541. if (dpm_table->sclk_table.count > 1)
  542. smu_data->smc_state_table.GraphicsLevel[dpm_table->sclk_table.count-1].DisplayWatermark =
  543. PPSMC_DISPLAY_WATERMARK_HIGH;
  544. smu_data->smc_state_table.GraphicsDpmLevelCount =
  545. (uint8_t)dpm_table->sclk_table.count;
  546. data->dpm_level_enable_mask.sclk_dpm_enable_mask =
  547. phm_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
  548. if (pcie_table != NULL) {
  549. PP_ASSERT_WITH_CODE((pcie_entry_count >= 1),
  550. "There must be 1 or more PCIE levels defined in PPTable.",
  551. return -EINVAL);
  552. max_entry = pcie_entry_count - 1; /* for indexing, we need to decrement by 1.*/
  553. for (i = 0; i < dpm_table->sclk_table.count; i++) {
  554. smu_data->smc_state_table.GraphicsLevel[i].pcieDpmLevel =
  555. (uint8_t) ((i < max_entry) ? i : max_entry);
  556. }
  557. } else {
  558. if (0 == data->dpm_level_enable_mask.pcie_dpm_enable_mask)
  559. pr_err("Pcie Dpm Enablemask is 0 !");
  560. while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
  561. ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
  562. (1<<(highest_pcie_level_enabled+1))) != 0)) {
  563. highest_pcie_level_enabled++;
  564. }
  565. while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
  566. ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
  567. (1<<lowest_pcie_level_enabled)) == 0)) {
  568. lowest_pcie_level_enabled++;
  569. }
  570. while ((count < highest_pcie_level_enabled) &&
  571. ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
  572. (1<<(lowest_pcie_level_enabled+1+count))) == 0)) {
  573. count++;
  574. }
  575. mid_pcie_level_enabled = (lowest_pcie_level_enabled+1+count) < highest_pcie_level_enabled ?
  576. (lowest_pcie_level_enabled+1+count) : highest_pcie_level_enabled;
  577. /* set pcieDpmLevel to highest_pcie_level_enabled*/
  578. for (i = 2; i < dpm_table->sclk_table.count; i++)
  579. smu_data->smc_state_table.GraphicsLevel[i].pcieDpmLevel = highest_pcie_level_enabled;
  580. /* set pcieDpmLevel to lowest_pcie_level_enabled*/
  581. smu_data->smc_state_table.GraphicsLevel[0].pcieDpmLevel = lowest_pcie_level_enabled;
  582. /* set pcieDpmLevel to mid_pcie_level_enabled*/
  583. smu_data->smc_state_table.GraphicsLevel[1].pcieDpmLevel = mid_pcie_level_enabled;
  584. }
  585. /* level count will send to smc once at init smc table and never change*/
  586. result = smu7_copy_bytes_to_smc(hwmgr->smumgr, level_array_address,
  587. (uint8_t *)levels, (uint32_t)level_array_size,
  588. SMC_RAM_END);
  589. return result;
  590. }
  591. /**
  592. * Populates the SMC MCLK structure using the provided memory clock
  593. *
  594. * @param hwmgr the address of the hardware manager
  595. * @param memory_clock the memory clock to use to populate the structure
  596. * @param sclk the SMC SCLK structure to be populated
  597. */
  598. static int tonga_calculate_mclk_params(
  599. struct pp_hwmgr *hwmgr,
  600. uint32_t memory_clock,
  601. SMU72_Discrete_MemoryLevel *mclk,
  602. bool strobe_mode,
  603. bool dllStateOn
  604. )
  605. {
  606. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  607. uint32_t dll_cntl = data->clock_registers.vDLL_CNTL;
  608. uint32_t mclk_pwrmgt_cntl = data->clock_registers.vMCLK_PWRMGT_CNTL;
  609. uint32_t mpll_ad_func_cntl = data->clock_registers.vMPLL_AD_FUNC_CNTL;
  610. uint32_t mpll_dq_func_cntl = data->clock_registers.vMPLL_DQ_FUNC_CNTL;
  611. uint32_t mpll_func_cntl = data->clock_registers.vMPLL_FUNC_CNTL;
  612. uint32_t mpll_func_cntl_1 = data->clock_registers.vMPLL_FUNC_CNTL_1;
  613. uint32_t mpll_func_cntl_2 = data->clock_registers.vMPLL_FUNC_CNTL_2;
  614. uint32_t mpll_ss1 = data->clock_registers.vMPLL_SS1;
  615. uint32_t mpll_ss2 = data->clock_registers.vMPLL_SS2;
  616. pp_atomctrl_memory_clock_param mpll_param;
  617. int result;
  618. result = atomctrl_get_memory_pll_dividers_si(hwmgr,
  619. memory_clock, &mpll_param, strobe_mode);
  620. PP_ASSERT_WITH_CODE(
  621. !result,
  622. "Error retrieving Memory Clock Parameters from VBIOS.",
  623. return result);
  624. /* MPLL_FUNC_CNTL setup*/
  625. mpll_func_cntl = PHM_SET_FIELD(mpll_func_cntl, MPLL_FUNC_CNTL, BWCTRL,
  626. mpll_param.bw_ctrl);
  627. /* MPLL_FUNC_CNTL_1 setup*/
  628. mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1,
  629. MPLL_FUNC_CNTL_1, CLKF,
  630. mpll_param.mpll_fb_divider.cl_kf);
  631. mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1,
  632. MPLL_FUNC_CNTL_1, CLKFRAC,
  633. mpll_param.mpll_fb_divider.clk_frac);
  634. mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1,
  635. MPLL_FUNC_CNTL_1, VCO_MODE,
  636. mpll_param.vco_mode);
  637. /* MPLL_AD_FUNC_CNTL setup*/
  638. mpll_ad_func_cntl = PHM_SET_FIELD(mpll_ad_func_cntl,
  639. MPLL_AD_FUNC_CNTL, YCLK_POST_DIV,
  640. mpll_param.mpll_post_divider);
  641. if (data->is_memory_gddr5) {
  642. /* MPLL_DQ_FUNC_CNTL setup*/
  643. mpll_dq_func_cntl = PHM_SET_FIELD(mpll_dq_func_cntl,
  644. MPLL_DQ_FUNC_CNTL, YCLK_SEL,
  645. mpll_param.yclk_sel);
  646. mpll_dq_func_cntl = PHM_SET_FIELD(mpll_dq_func_cntl,
  647. MPLL_DQ_FUNC_CNTL, YCLK_POST_DIV,
  648. mpll_param.mpll_post_divider);
  649. }
  650. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  651. PHM_PlatformCaps_MemorySpreadSpectrumSupport)) {
  652. /*
  653. ************************************
  654. Fref = Reference Frequency
  655. NF = Feedback divider ratio
  656. NR = Reference divider ratio
  657. Fnom = Nominal VCO output frequency = Fref * NF / NR
  658. Fs = Spreading Rate
  659. D = Percentage down-spread / 2
  660. Fint = Reference input frequency to PFD = Fref / NR
  661. NS = Spreading rate divider ratio = int(Fint / (2 * Fs))
  662. CLKS = NS - 1 = ISS_STEP_NUM[11:0]
  663. NV = D * Fs / Fnom * 4 * ((Fnom/Fref * NR) ^ 2)
  664. CLKV = 65536 * NV = ISS_STEP_SIZE[25:0]
  665. *************************************
  666. */
  667. pp_atomctrl_internal_ss_info ss_info;
  668. uint32_t freq_nom;
  669. uint32_t tmp;
  670. uint32_t reference_clock = atomctrl_get_mpll_reference_clock(hwmgr);
  671. /* for GDDR5 for all modes and DDR3 */
  672. if (1 == mpll_param.qdr)
  673. freq_nom = memory_clock * 4 * (1 << mpll_param.mpll_post_divider);
  674. else
  675. freq_nom = memory_clock * 2 * (1 << mpll_param.mpll_post_divider);
  676. /* tmp = (freq_nom / reference_clock * reference_divider) ^ 2 Note: S.I. reference_divider = 1*/
  677. tmp = (freq_nom / reference_clock);
  678. tmp = tmp * tmp;
  679. if (0 == atomctrl_get_memory_clock_spread_spectrum(hwmgr, freq_nom, &ss_info)) {
  680. /* ss_info.speed_spectrum_percentage -- in unit of 0.01% */
  681. /* ss.Info.speed_spectrum_rate -- in unit of khz */
  682. /* CLKS = reference_clock / (2 * speed_spectrum_rate * reference_divider) * 10 */
  683. /* = reference_clock * 5 / speed_spectrum_rate */
  684. uint32_t clks = reference_clock * 5 / ss_info.speed_spectrum_rate;
  685. /* CLKV = 65536 * speed_spectrum_percentage / 2 * spreadSpecrumRate / freq_nom * 4 / 100000 * ((freq_nom / reference_clock) ^ 2) */
  686. /* = 131 * speed_spectrum_percentage * speed_spectrum_rate / 100 * ((freq_nom / reference_clock) ^ 2) / freq_nom */
  687. uint32_t clkv =
  688. (uint32_t)((((131 * ss_info.speed_spectrum_percentage *
  689. ss_info.speed_spectrum_rate) / 100) * tmp) / freq_nom);
  690. mpll_ss1 = PHM_SET_FIELD(mpll_ss1, MPLL_SS1, CLKV, clkv);
  691. mpll_ss2 = PHM_SET_FIELD(mpll_ss2, MPLL_SS2, CLKS, clks);
  692. }
  693. }
  694. /* MCLK_PWRMGT_CNTL setup */
  695. mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
  696. MCLK_PWRMGT_CNTL, DLL_SPEED, mpll_param.dll_speed);
  697. mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
  698. MCLK_PWRMGT_CNTL, MRDCK0_PDNB, dllStateOn);
  699. mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
  700. MCLK_PWRMGT_CNTL, MRDCK1_PDNB, dllStateOn);
  701. /* Save the result data to outpupt memory level structure */
  702. mclk->MclkFrequency = memory_clock;
  703. mclk->MpllFuncCntl = mpll_func_cntl;
  704. mclk->MpllFuncCntl_1 = mpll_func_cntl_1;
  705. mclk->MpllFuncCntl_2 = mpll_func_cntl_2;
  706. mclk->MpllAdFuncCntl = mpll_ad_func_cntl;
  707. mclk->MpllDqFuncCntl = mpll_dq_func_cntl;
  708. mclk->MclkPwrmgtCntl = mclk_pwrmgt_cntl;
  709. mclk->DllCntl = dll_cntl;
  710. mclk->MpllSs1 = mpll_ss1;
  711. mclk->MpllSs2 = mpll_ss2;
  712. return 0;
  713. }
  714. static uint8_t tonga_get_mclk_frequency_ratio(uint32_t memory_clock,
  715. bool strobe_mode)
  716. {
  717. uint8_t mc_para_index;
  718. if (strobe_mode) {
  719. if (memory_clock < 12500)
  720. mc_para_index = 0x00;
  721. else if (memory_clock > 47500)
  722. mc_para_index = 0x0f;
  723. else
  724. mc_para_index = (uint8_t)((memory_clock - 10000) / 2500);
  725. } else {
  726. if (memory_clock < 65000)
  727. mc_para_index = 0x00;
  728. else if (memory_clock > 135000)
  729. mc_para_index = 0x0f;
  730. else
  731. mc_para_index = (uint8_t)((memory_clock - 60000) / 5000);
  732. }
  733. return mc_para_index;
  734. }
  735. static uint8_t tonga_get_ddr3_mclk_frequency_ratio(uint32_t memory_clock)
  736. {
  737. uint8_t mc_para_index;
  738. if (memory_clock < 10000)
  739. mc_para_index = 0;
  740. else if (memory_clock >= 80000)
  741. mc_para_index = 0x0f;
  742. else
  743. mc_para_index = (uint8_t)((memory_clock - 10000) / 5000 + 1);
  744. return mc_para_index;
  745. }
  746. static int tonga_populate_single_memory_level(
  747. struct pp_hwmgr *hwmgr,
  748. uint32_t memory_clock,
  749. SMU72_Discrete_MemoryLevel *memory_level
  750. )
  751. {
  752. uint32_t mvdd = 0;
  753. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  754. struct phm_ppt_v1_information *pptable_info =
  755. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  756. int result = 0;
  757. bool dll_state_on;
  758. struct cgs_display_info info = {0};
  759. uint32_t mclk_edc_wr_enable_threshold = 40000;
  760. uint32_t mclk_stutter_mode_threshold = 30000;
  761. uint32_t mclk_edc_enable_threshold = 40000;
  762. uint32_t mclk_strobe_mode_threshold = 40000;
  763. if (NULL != pptable_info->vdd_dep_on_mclk) {
  764. result = tonga_get_dependecy_volt_by_clk(hwmgr,
  765. pptable_info->vdd_dep_on_mclk,
  766. memory_clock,
  767. &memory_level->MinVoltage, &mvdd);
  768. PP_ASSERT_WITH_CODE(
  769. !result,
  770. "can not find MinVddc voltage value from memory VDDC "
  771. "voltage dependency table",
  772. return result);
  773. }
  774. if (data->mvdd_control == SMU7_VOLTAGE_CONTROL_NONE)
  775. memory_level->MinMvdd = data->vbios_boot_state.mvdd_bootup_value;
  776. else
  777. memory_level->MinMvdd = mvdd;
  778. memory_level->EnabledForThrottle = 1;
  779. memory_level->EnabledForActivity = 0;
  780. memory_level->UpHyst = 0;
  781. memory_level->DownHyst = 100;
  782. memory_level->VoltageDownHyst = 0;
  783. /* Indicates maximum activity level for this performance level.*/
  784. memory_level->ActivityLevel = (uint16_t)data->mclk_activity_target;
  785. memory_level->StutterEnable = 0;
  786. memory_level->StrobeEnable = 0;
  787. memory_level->EdcReadEnable = 0;
  788. memory_level->EdcWriteEnable = 0;
  789. memory_level->RttEnable = 0;
  790. /* default set to low watermark. Highest level will be set to high later.*/
  791. memory_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
  792. cgs_get_active_displays_info(hwmgr->device, &info);
  793. data->display_timing.num_existing_displays = info.display_count;
  794. if ((mclk_stutter_mode_threshold != 0) &&
  795. (memory_clock <= mclk_stutter_mode_threshold) &&
  796. (!data->is_uvd_enabled)
  797. && (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL, STUTTER_ENABLE) & 0x1)
  798. && (data->display_timing.num_existing_displays <= 2)
  799. && (data->display_timing.num_existing_displays != 0))
  800. memory_level->StutterEnable = 1;
  801. /* decide strobe mode*/
  802. memory_level->StrobeEnable = (mclk_strobe_mode_threshold != 0) &&
  803. (memory_clock <= mclk_strobe_mode_threshold);
  804. /* decide EDC mode and memory clock ratio*/
  805. if (data->is_memory_gddr5) {
  806. memory_level->StrobeRatio = tonga_get_mclk_frequency_ratio(memory_clock,
  807. memory_level->StrobeEnable);
  808. if ((mclk_edc_enable_threshold != 0) &&
  809. (memory_clock > mclk_edc_enable_threshold)) {
  810. memory_level->EdcReadEnable = 1;
  811. }
  812. if ((mclk_edc_wr_enable_threshold != 0) &&
  813. (memory_clock > mclk_edc_wr_enable_threshold)) {
  814. memory_level->EdcWriteEnable = 1;
  815. }
  816. if (memory_level->StrobeEnable) {
  817. if (tonga_get_mclk_frequency_ratio(memory_clock, 1) >=
  818. ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC7) >> 16) & 0xf)) {
  819. dll_state_on = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC5) >> 1) & 0x1) ? 1 : 0;
  820. } else {
  821. dll_state_on = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC6) >> 1) & 0x1) ? 1 : 0;
  822. }
  823. } else {
  824. dll_state_on = data->dll_default_on;
  825. }
  826. } else {
  827. memory_level->StrobeRatio =
  828. tonga_get_ddr3_mclk_frequency_ratio(memory_clock);
  829. dll_state_on = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC5) >> 1) & 0x1) ? 1 : 0;
  830. }
  831. result = tonga_calculate_mclk_params(hwmgr,
  832. memory_clock, memory_level, memory_level->StrobeEnable, dll_state_on);
  833. if (!result) {
  834. CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MinMvdd);
  835. /* MCLK frequency in units of 10KHz*/
  836. CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MclkFrequency);
  837. /* Indicates maximum activity level for this performance level.*/
  838. CONVERT_FROM_HOST_TO_SMC_US(memory_level->ActivityLevel);
  839. CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl);
  840. CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl_1);
  841. CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl_2);
  842. CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllAdFuncCntl);
  843. CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllDqFuncCntl);
  844. CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MclkPwrmgtCntl);
  845. CONVERT_FROM_HOST_TO_SMC_UL(memory_level->DllCntl);
  846. CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllSs1);
  847. CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllSs2);
  848. }
  849. return result;
  850. }
  851. int tonga_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
  852. {
  853. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  854. struct tonga_smumgr *smu_data =
  855. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  856. struct smu7_dpm_table *dpm_table = &data->dpm_table;
  857. int result;
  858. /* populate MCLK dpm table to SMU7 */
  859. uint32_t level_array_address =
  860. smu_data->smu7_data.dpm_table_start +
  861. offsetof(SMU72_Discrete_DpmTable, MemoryLevel);
  862. uint32_t level_array_size =
  863. sizeof(SMU72_Discrete_MemoryLevel) *
  864. SMU72_MAX_LEVELS_MEMORY;
  865. SMU72_Discrete_MemoryLevel *levels =
  866. smu_data->smc_state_table.MemoryLevel;
  867. uint32_t i;
  868. memset(levels, 0x00, level_array_size);
  869. for (i = 0; i < dpm_table->mclk_table.count; i++) {
  870. PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value),
  871. "can not populate memory level as memory clock is zero",
  872. return -EINVAL);
  873. result = tonga_populate_single_memory_level(
  874. hwmgr,
  875. dpm_table->mclk_table.dpm_levels[i].value,
  876. &(smu_data->smc_state_table.MemoryLevel[i]));
  877. if (result)
  878. return result;
  879. }
  880. /* Only enable level 0 for now.*/
  881. smu_data->smc_state_table.MemoryLevel[0].EnabledForActivity = 1;
  882. /*
  883. * in order to prevent MC activity from stutter mode to push DPM up.
  884. * the UVD change complements this by putting the MCLK in a higher state
  885. * by default such that we are not effected by up threshold or and MCLK DPM latency.
  886. */
  887. smu_data->smc_state_table.MemoryLevel[0].ActivityLevel = 0x1F;
  888. CONVERT_FROM_HOST_TO_SMC_US(smu_data->smc_state_table.MemoryLevel[0].ActivityLevel);
  889. smu_data->smc_state_table.MemoryDpmLevelCount = (uint8_t)dpm_table->mclk_table.count;
  890. data->dpm_level_enable_mask.mclk_dpm_enable_mask = phm_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
  891. /* set highest level watermark to high*/
  892. smu_data->smc_state_table.MemoryLevel[dpm_table->mclk_table.count-1].DisplayWatermark = PPSMC_DISPLAY_WATERMARK_HIGH;
  893. /* level count will send to smc once at init smc table and never change*/
  894. result = smu7_copy_bytes_to_smc(hwmgr->smumgr,
  895. level_array_address, (uint8_t *)levels, (uint32_t)level_array_size,
  896. SMC_RAM_END);
  897. return result;
  898. }
  899. static int tonga_populate_mvdd_value(struct pp_hwmgr *hwmgr,
  900. uint32_t mclk, SMIO_Pattern *smio_pattern)
  901. {
  902. const struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  903. struct phm_ppt_v1_information *table_info =
  904. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  905. uint32_t i = 0;
  906. if (SMU7_VOLTAGE_CONTROL_NONE != data->mvdd_control) {
  907. /* find mvdd value which clock is more than request */
  908. for (i = 0; i < table_info->vdd_dep_on_mclk->count; i++) {
  909. if (mclk <= table_info->vdd_dep_on_mclk->entries[i].clk) {
  910. /* Always round to higher voltage. */
  911. smio_pattern->Voltage =
  912. data->mvdd_voltage_table.entries[i].value;
  913. break;
  914. }
  915. }
  916. PP_ASSERT_WITH_CODE(i < table_info->vdd_dep_on_mclk->count,
  917. "MVDD Voltage is outside the supported range.",
  918. return -EINVAL);
  919. } else {
  920. return -EINVAL;
  921. }
  922. return 0;
  923. }
  924. static int tonga_populate_smc_acpi_level(struct pp_hwmgr *hwmgr,
  925. SMU72_Discrete_DpmTable *table)
  926. {
  927. int result = 0;
  928. struct tonga_smumgr *smu_data =
  929. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  930. const struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  931. struct pp_atomctrl_clock_dividers_vi dividers;
  932. SMIO_Pattern voltage_level;
  933. uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
  934. uint32_t spll_func_cntl_2 = data->clock_registers.vCG_SPLL_FUNC_CNTL_2;
  935. uint32_t dll_cntl = data->clock_registers.vDLL_CNTL;
  936. uint32_t mclk_pwrmgt_cntl = data->clock_registers.vMCLK_PWRMGT_CNTL;
  937. /* The ACPI state should not do DPM on DC (or ever).*/
  938. table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
  939. table->ACPILevel.MinVoltage =
  940. smu_data->smc_state_table.GraphicsLevel[0].MinVoltage;
  941. /* assign zero for now*/
  942. table->ACPILevel.SclkFrequency = atomctrl_get_reference_clock(hwmgr);
  943. /* get the engine clock dividers for this clock value*/
  944. result = atomctrl_get_engine_pll_dividers_vi(hwmgr,
  945. table->ACPILevel.SclkFrequency, &dividers);
  946. PP_ASSERT_WITH_CODE(result == 0,
  947. "Error retrieving Engine Clock dividers from VBIOS.",
  948. return result);
  949. /* divider ID for required SCLK*/
  950. table->ACPILevel.SclkDid = (uint8_t)dividers.pll_post_divider;
  951. table->ACPILevel.DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
  952. table->ACPILevel.DeepSleepDivId = 0;
  953. spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
  954. SPLL_PWRON, 0);
  955. spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
  956. SPLL_RESET, 1);
  957. spll_func_cntl_2 = PHM_SET_FIELD(spll_func_cntl_2, CG_SPLL_FUNC_CNTL_2,
  958. SCLK_MUX_SEL, 4);
  959. table->ACPILevel.CgSpllFuncCntl = spll_func_cntl;
  960. table->ACPILevel.CgSpllFuncCntl2 = spll_func_cntl_2;
  961. table->ACPILevel.CgSpllFuncCntl3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
  962. table->ACPILevel.CgSpllFuncCntl4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
  963. table->ACPILevel.SpllSpreadSpectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
  964. table->ACPILevel.SpllSpreadSpectrum2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
  965. table->ACPILevel.CcPwrDynRm = 0;
  966. table->ACPILevel.CcPwrDynRm1 = 0;
  967. /* For various features to be enabled/disabled while this level is active.*/
  968. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags);
  969. /* SCLK frequency in units of 10KHz*/
  970. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkFrequency);
  971. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl);
  972. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl2);
  973. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl3);
  974. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl4);
  975. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum);
  976. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum2);
  977. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm);
  978. CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1);
  979. /* table->MemoryACPILevel.MinVddcPhases = table->ACPILevel.MinVddcPhases;*/
  980. table->MemoryACPILevel.MinVoltage =
  981. smu_data->smc_state_table.MemoryLevel[0].MinVoltage;
  982. /* CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);*/
  983. if (0 == tonga_populate_mvdd_value(hwmgr, 0, &voltage_level))
  984. table->MemoryACPILevel.MinMvdd =
  985. PP_HOST_TO_SMC_UL(voltage_level.Voltage * VOLTAGE_SCALE);
  986. else
  987. table->MemoryACPILevel.MinMvdd = 0;
  988. /* Force reset on DLL*/
  989. mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
  990. MCLK_PWRMGT_CNTL, MRDCK0_RESET, 0x1);
  991. mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
  992. MCLK_PWRMGT_CNTL, MRDCK1_RESET, 0x1);
  993. /* Disable DLL in ACPIState*/
  994. mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
  995. MCLK_PWRMGT_CNTL, MRDCK0_PDNB, 0);
  996. mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
  997. MCLK_PWRMGT_CNTL, MRDCK1_PDNB, 0);
  998. /* Enable DLL bypass signal*/
  999. dll_cntl = PHM_SET_FIELD(dll_cntl,
  1000. DLL_CNTL, MRDCK0_BYPASS, 0);
  1001. dll_cntl = PHM_SET_FIELD(dll_cntl,
  1002. DLL_CNTL, MRDCK1_BYPASS, 0);
  1003. table->MemoryACPILevel.DllCntl =
  1004. PP_HOST_TO_SMC_UL(dll_cntl);
  1005. table->MemoryACPILevel.MclkPwrmgtCntl =
  1006. PP_HOST_TO_SMC_UL(mclk_pwrmgt_cntl);
  1007. table->MemoryACPILevel.MpllAdFuncCntl =
  1008. PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_AD_FUNC_CNTL);
  1009. table->MemoryACPILevel.MpllDqFuncCntl =
  1010. PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_DQ_FUNC_CNTL);
  1011. table->MemoryACPILevel.MpllFuncCntl =
  1012. PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL);
  1013. table->MemoryACPILevel.MpllFuncCntl_1 =
  1014. PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL_1);
  1015. table->MemoryACPILevel.MpllFuncCntl_2 =
  1016. PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL_2);
  1017. table->MemoryACPILevel.MpllSs1 =
  1018. PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_SS1);
  1019. table->MemoryACPILevel.MpllSs2 =
  1020. PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_SS2);
  1021. table->MemoryACPILevel.EnabledForThrottle = 0;
  1022. table->MemoryACPILevel.EnabledForActivity = 0;
  1023. table->MemoryACPILevel.UpHyst = 0;
  1024. table->MemoryACPILevel.DownHyst = 100;
  1025. table->MemoryACPILevel.VoltageDownHyst = 0;
  1026. /* Indicates maximum activity level for this performance level.*/
  1027. table->MemoryACPILevel.ActivityLevel =
  1028. PP_HOST_TO_SMC_US((uint16_t)data->mclk_activity_target);
  1029. table->MemoryACPILevel.StutterEnable = 0;
  1030. table->MemoryACPILevel.StrobeEnable = 0;
  1031. table->MemoryACPILevel.EdcReadEnable = 0;
  1032. table->MemoryACPILevel.EdcWriteEnable = 0;
  1033. table->MemoryACPILevel.RttEnable = 0;
  1034. return result;
  1035. }
  1036. static int tonga_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
  1037. SMU72_Discrete_DpmTable *table)
  1038. {
  1039. int result = 0;
  1040. uint8_t count;
  1041. pp_atomctrl_clock_dividers_vi dividers;
  1042. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1043. struct phm_ppt_v1_information *pptable_info =
  1044. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1045. phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
  1046. pptable_info->mm_dep_table;
  1047. table->UvdLevelCount = (uint8_t) (mm_table->count);
  1048. table->UvdBootLevel = 0;
  1049. for (count = 0; count < table->UvdLevelCount; count++) {
  1050. table->UvdLevel[count].VclkFrequency = mm_table->entries[count].vclk;
  1051. table->UvdLevel[count].DclkFrequency = mm_table->entries[count].dclk;
  1052. table->UvdLevel[count].MinVoltage.Vddc =
  1053. phm_get_voltage_index(pptable_info->vddc_lookup_table,
  1054. mm_table->entries[count].vddc);
  1055. table->UvdLevel[count].MinVoltage.VddGfx =
  1056. (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) ?
  1057. phm_get_voltage_index(pptable_info->vddgfx_lookup_table,
  1058. mm_table->entries[count].vddgfx) : 0;
  1059. table->UvdLevel[count].MinVoltage.Vddci =
  1060. phm_get_voltage_id(&data->vddci_voltage_table,
  1061. mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
  1062. table->UvdLevel[count].MinVoltage.Phases = 1;
  1063. /* retrieve divider value for VBIOS */
  1064. result = atomctrl_get_dfs_pll_dividers_vi(
  1065. hwmgr,
  1066. table->UvdLevel[count].VclkFrequency,
  1067. &dividers);
  1068. PP_ASSERT_WITH_CODE((!result),
  1069. "can not find divide id for Vclk clock",
  1070. return result);
  1071. table->UvdLevel[count].VclkDivider = (uint8_t)dividers.pll_post_divider;
  1072. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
  1073. table->UvdLevel[count].DclkFrequency, &dividers);
  1074. PP_ASSERT_WITH_CODE((!result),
  1075. "can not find divide id for Dclk clock",
  1076. return result);
  1077. table->UvdLevel[count].DclkDivider =
  1078. (uint8_t)dividers.pll_post_divider;
  1079. CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].VclkFrequency);
  1080. CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].DclkFrequency);
  1081. }
  1082. return result;
  1083. }
  1084. static int tonga_populate_smc_vce_level(struct pp_hwmgr *hwmgr,
  1085. SMU72_Discrete_DpmTable *table)
  1086. {
  1087. int result = 0;
  1088. uint8_t count;
  1089. pp_atomctrl_clock_dividers_vi dividers;
  1090. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1091. struct phm_ppt_v1_information *pptable_info =
  1092. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1093. phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
  1094. pptable_info->mm_dep_table;
  1095. table->VceLevelCount = (uint8_t) (mm_table->count);
  1096. table->VceBootLevel = 0;
  1097. for (count = 0; count < table->VceLevelCount; count++) {
  1098. table->VceLevel[count].Frequency =
  1099. mm_table->entries[count].eclk;
  1100. table->VceLevel[count].MinVoltage.Vddc =
  1101. phm_get_voltage_index(pptable_info->vddc_lookup_table,
  1102. mm_table->entries[count].vddc);
  1103. table->VceLevel[count].MinVoltage.VddGfx =
  1104. (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) ?
  1105. phm_get_voltage_index(pptable_info->vddgfx_lookup_table,
  1106. mm_table->entries[count].vddgfx) : 0;
  1107. table->VceLevel[count].MinVoltage.Vddci =
  1108. phm_get_voltage_id(&data->vddci_voltage_table,
  1109. mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
  1110. table->VceLevel[count].MinVoltage.Phases = 1;
  1111. /* retrieve divider value for VBIOS */
  1112. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
  1113. table->VceLevel[count].Frequency, &dividers);
  1114. PP_ASSERT_WITH_CODE((!result),
  1115. "can not find divide id for VCE engine clock",
  1116. return result);
  1117. table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
  1118. CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency);
  1119. }
  1120. return result;
  1121. }
  1122. static int tonga_populate_smc_acp_level(struct pp_hwmgr *hwmgr,
  1123. SMU72_Discrete_DpmTable *table)
  1124. {
  1125. int result = 0;
  1126. uint8_t count;
  1127. pp_atomctrl_clock_dividers_vi dividers;
  1128. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1129. struct phm_ppt_v1_information *pptable_info =
  1130. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1131. phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
  1132. pptable_info->mm_dep_table;
  1133. table->AcpLevelCount = (uint8_t) (mm_table->count);
  1134. table->AcpBootLevel = 0;
  1135. for (count = 0; count < table->AcpLevelCount; count++) {
  1136. table->AcpLevel[count].Frequency =
  1137. pptable_info->mm_dep_table->entries[count].aclk;
  1138. table->AcpLevel[count].MinVoltage.Vddc =
  1139. phm_get_voltage_index(pptable_info->vddc_lookup_table,
  1140. mm_table->entries[count].vddc);
  1141. table->AcpLevel[count].MinVoltage.VddGfx =
  1142. (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) ?
  1143. phm_get_voltage_index(pptable_info->vddgfx_lookup_table,
  1144. mm_table->entries[count].vddgfx) : 0;
  1145. table->AcpLevel[count].MinVoltage.Vddci =
  1146. phm_get_voltage_id(&data->vddci_voltage_table,
  1147. mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
  1148. table->AcpLevel[count].MinVoltage.Phases = 1;
  1149. /* retrieve divider value for VBIOS */
  1150. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
  1151. table->AcpLevel[count].Frequency, &dividers);
  1152. PP_ASSERT_WITH_CODE((!result),
  1153. "can not find divide id for engine clock", return result);
  1154. table->AcpLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
  1155. CONVERT_FROM_HOST_TO_SMC_UL(table->AcpLevel[count].Frequency);
  1156. }
  1157. return result;
  1158. }
  1159. static int tonga_populate_smc_samu_level(struct pp_hwmgr *hwmgr,
  1160. SMU72_Discrete_DpmTable *table)
  1161. {
  1162. int result = 0;
  1163. uint8_t count;
  1164. pp_atomctrl_clock_dividers_vi dividers;
  1165. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1166. struct phm_ppt_v1_information *pptable_info =
  1167. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1168. phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
  1169. pptable_info->mm_dep_table;
  1170. table->SamuBootLevel = 0;
  1171. table->SamuLevelCount = (uint8_t) (mm_table->count);
  1172. for (count = 0; count < table->SamuLevelCount; count++) {
  1173. /* not sure whether we need evclk or not */
  1174. table->SamuLevel[count].Frequency =
  1175. pptable_info->mm_dep_table->entries[count].samclock;
  1176. table->SamuLevel[count].MinVoltage.Vddc =
  1177. phm_get_voltage_index(pptable_info->vddc_lookup_table,
  1178. mm_table->entries[count].vddc);
  1179. table->SamuLevel[count].MinVoltage.VddGfx =
  1180. (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) ?
  1181. phm_get_voltage_index(pptable_info->vddgfx_lookup_table,
  1182. mm_table->entries[count].vddgfx) : 0;
  1183. table->SamuLevel[count].MinVoltage.Vddci =
  1184. phm_get_voltage_id(&data->vddci_voltage_table,
  1185. mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
  1186. table->SamuLevel[count].MinVoltage.Phases = 1;
  1187. /* retrieve divider value for VBIOS */
  1188. result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
  1189. table->SamuLevel[count].Frequency, &dividers);
  1190. PP_ASSERT_WITH_CODE((!result),
  1191. "can not find divide id for samu clock", return result);
  1192. table->SamuLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
  1193. CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].Frequency);
  1194. }
  1195. return result;
  1196. }
  1197. static int tonga_populate_memory_timing_parameters(
  1198. struct pp_hwmgr *hwmgr,
  1199. uint32_t engine_clock,
  1200. uint32_t memory_clock,
  1201. struct SMU72_Discrete_MCArbDramTimingTableEntry *arb_regs
  1202. )
  1203. {
  1204. uint32_t dramTiming;
  1205. uint32_t dramTiming2;
  1206. uint32_t burstTime;
  1207. int result;
  1208. result = atomctrl_set_engine_dram_timings_rv770(hwmgr,
  1209. engine_clock, memory_clock);
  1210. PP_ASSERT_WITH_CODE(result == 0,
  1211. "Error calling VBIOS to set DRAM_TIMING.", return result);
  1212. dramTiming = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
  1213. dramTiming2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
  1214. burstTime = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
  1215. arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dramTiming);
  1216. arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dramTiming2);
  1217. arb_regs->McArbBurstTime = (uint8_t)burstTime;
  1218. return 0;
  1219. }
  1220. /**
  1221. * Setup parameters for the MC ARB.
  1222. *
  1223. * @param hwmgr the address of the powerplay hardware manager.
  1224. * @return always 0
  1225. * This function is to be called from the SetPowerState table.
  1226. */
  1227. static int tonga_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
  1228. {
  1229. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1230. struct tonga_smumgr *smu_data =
  1231. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1232. int result = 0;
  1233. SMU72_Discrete_MCArbDramTimingTable arb_regs;
  1234. uint32_t i, j;
  1235. memset(&arb_regs, 0x00, sizeof(SMU72_Discrete_MCArbDramTimingTable));
  1236. for (i = 0; i < data->dpm_table.sclk_table.count; i++) {
  1237. for (j = 0; j < data->dpm_table.mclk_table.count; j++) {
  1238. result = tonga_populate_memory_timing_parameters
  1239. (hwmgr, data->dpm_table.sclk_table.dpm_levels[i].value,
  1240. data->dpm_table.mclk_table.dpm_levels[j].value,
  1241. &arb_regs.entries[i][j]);
  1242. if (result)
  1243. break;
  1244. }
  1245. }
  1246. if (!result) {
  1247. result = smu7_copy_bytes_to_smc(
  1248. hwmgr->smumgr,
  1249. smu_data->smu7_data.arb_table_start,
  1250. (uint8_t *)&arb_regs,
  1251. sizeof(SMU72_Discrete_MCArbDramTimingTable),
  1252. SMC_RAM_END
  1253. );
  1254. }
  1255. return result;
  1256. }
  1257. static int tonga_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
  1258. SMU72_Discrete_DpmTable *table)
  1259. {
  1260. int result = 0;
  1261. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1262. struct tonga_smumgr *smu_data =
  1263. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1264. table->GraphicsBootLevel = 0;
  1265. table->MemoryBootLevel = 0;
  1266. /* find boot level from dpm table*/
  1267. result = phm_find_boot_level(&(data->dpm_table.sclk_table),
  1268. data->vbios_boot_state.sclk_bootup_value,
  1269. (uint32_t *)&(smu_data->smc_state_table.GraphicsBootLevel));
  1270. if (result != 0) {
  1271. smu_data->smc_state_table.GraphicsBootLevel = 0;
  1272. pr_err("[powerplay] VBIOS did not find boot engine "
  1273. "clock value in dependency table. "
  1274. "Using Graphics DPM level 0 !");
  1275. result = 0;
  1276. }
  1277. result = phm_find_boot_level(&(data->dpm_table.mclk_table),
  1278. data->vbios_boot_state.mclk_bootup_value,
  1279. (uint32_t *)&(smu_data->smc_state_table.MemoryBootLevel));
  1280. if (result != 0) {
  1281. smu_data->smc_state_table.MemoryBootLevel = 0;
  1282. pr_err("[powerplay] VBIOS did not find boot "
  1283. "engine clock value in dependency table."
  1284. "Using Memory DPM level 0 !");
  1285. result = 0;
  1286. }
  1287. table->BootVoltage.Vddc =
  1288. phm_get_voltage_id(&(data->vddc_voltage_table),
  1289. data->vbios_boot_state.vddc_bootup_value);
  1290. table->BootVoltage.VddGfx =
  1291. phm_get_voltage_id(&(data->vddgfx_voltage_table),
  1292. data->vbios_boot_state.vddgfx_bootup_value);
  1293. table->BootVoltage.Vddci =
  1294. phm_get_voltage_id(&(data->vddci_voltage_table),
  1295. data->vbios_boot_state.vddci_bootup_value);
  1296. table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value;
  1297. CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
  1298. return result;
  1299. }
  1300. static int tonga_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr)
  1301. {
  1302. uint32_t ro, efuse, efuse2, clock_freq, volt_without_cks,
  1303. volt_with_cks, value;
  1304. uint16_t clock_freq_u16;
  1305. struct tonga_smumgr *smu_data =
  1306. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1307. uint8_t type, i, j, cks_setting, stretch_amount, stretch_amount2,
  1308. volt_offset = 0;
  1309. struct phm_ppt_v1_information *table_info =
  1310. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1311. struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
  1312. table_info->vdd_dep_on_sclk;
  1313. uint32_t hw_revision, dev_id;
  1314. struct cgs_system_info sys_info = {0};
  1315. stretch_amount = (uint8_t)table_info->cac_dtp_table->usClockStretchAmount;
  1316. sys_info.size = sizeof(struct cgs_system_info);
  1317. sys_info.info_id = CGS_SYSTEM_INFO_PCIE_REV;
  1318. cgs_query_system_info(hwmgr->device, &sys_info);
  1319. hw_revision = (uint32_t)sys_info.value;
  1320. sys_info.info_id = CGS_SYSTEM_INFO_PCIE_DEV;
  1321. cgs_query_system_info(hwmgr->device, &sys_info);
  1322. dev_id = (uint32_t)sys_info.value;
  1323. /* Read SMU_Eefuse to read and calculate RO and determine
  1324. * if the part is SS or FF. if RO >= 1660MHz, part is FF.
  1325. */
  1326. efuse = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  1327. ixSMU_EFUSE_0 + (146 * 4));
  1328. efuse2 = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  1329. ixSMU_EFUSE_0 + (148 * 4));
  1330. efuse &= 0xFF000000;
  1331. efuse = efuse >> 24;
  1332. efuse2 &= 0xF;
  1333. if (efuse2 == 1)
  1334. ro = (2300 - 1350) * efuse / 255 + 1350;
  1335. else
  1336. ro = (2500 - 1000) * efuse / 255 + 1000;
  1337. if (ro >= 1660)
  1338. type = 0;
  1339. else
  1340. type = 1;
  1341. /* Populate Stretch amount */
  1342. smu_data->smc_state_table.ClockStretcherAmount = stretch_amount;
  1343. /* Populate Sclk_CKS_masterEn0_7 and Sclk_voltageOffset */
  1344. for (i = 0; i < sclk_table->count; i++) {
  1345. smu_data->smc_state_table.Sclk_CKS_masterEn0_7 |=
  1346. sclk_table->entries[i].cks_enable << i;
  1347. if (ASICID_IS_TONGA_P(dev_id, hw_revision)) {
  1348. volt_without_cks = (uint32_t)((7732 + 60 - ro - 20838 *
  1349. (sclk_table->entries[i].clk/100) / 10000) * 1000 /
  1350. (8730 - (5301 * (sclk_table->entries[i].clk/100) / 1000)));
  1351. volt_with_cks = (uint32_t)((5250 + 51 - ro - 2404 *
  1352. (sclk_table->entries[i].clk/100) / 100000) * 1000 /
  1353. (6146 - (3193 * (sclk_table->entries[i].clk/100) / 1000)));
  1354. } else {
  1355. volt_without_cks = (uint32_t)((14041 *
  1356. (sclk_table->entries[i].clk/100) / 10000 + 3571 + 75 - ro) * 1000 /
  1357. (4026 - (13924 * (sclk_table->entries[i].clk/100) / 10000)));
  1358. volt_with_cks = (uint32_t)((13946 *
  1359. (sclk_table->entries[i].clk/100) / 10000 + 3320 + 45 - ro) * 1000 /
  1360. (3664 - (11454 * (sclk_table->entries[i].clk/100) / 10000)));
  1361. }
  1362. if (volt_without_cks >= volt_with_cks)
  1363. volt_offset = (uint8_t)(((volt_without_cks - volt_with_cks +
  1364. sclk_table->entries[i].cks_voffset) * 100 / 625) + 1);
  1365. smu_data->smc_state_table.Sclk_voltageOffset[i] = volt_offset;
  1366. }
  1367. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
  1368. STRETCH_ENABLE, 0x0);
  1369. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
  1370. masterReset, 0x1);
  1371. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
  1372. staticEnable, 0x1);
  1373. PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
  1374. masterReset, 0x0);
  1375. /* Populate CKS Lookup Table */
  1376. if (stretch_amount == 1 || stretch_amount == 2 || stretch_amount == 5)
  1377. stretch_amount2 = 0;
  1378. else if (stretch_amount == 3 || stretch_amount == 4)
  1379. stretch_amount2 = 1;
  1380. else {
  1381. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  1382. PHM_PlatformCaps_ClockStretcher);
  1383. PP_ASSERT_WITH_CODE(false,
  1384. "Stretch Amount in PPTable not supported\n",
  1385. return -EINVAL);
  1386. }
  1387. value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  1388. ixPWR_CKS_CNTL);
  1389. value &= 0xFFC2FF87;
  1390. smu_data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].minFreq =
  1391. tonga_clock_stretcher_lookup_table[stretch_amount2][0];
  1392. smu_data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].maxFreq =
  1393. tonga_clock_stretcher_lookup_table[stretch_amount2][1];
  1394. clock_freq_u16 = (uint16_t)(PP_SMC_TO_HOST_UL(smu_data->smc_state_table.
  1395. GraphicsLevel[smu_data->smc_state_table.GraphicsDpmLevelCount - 1].
  1396. SclkFrequency) / 100);
  1397. if (tonga_clock_stretcher_lookup_table[stretch_amount2][0] <
  1398. clock_freq_u16 &&
  1399. tonga_clock_stretcher_lookup_table[stretch_amount2][1] >
  1400. clock_freq_u16) {
  1401. /* Program PWR_CKS_CNTL. CKS_USE_FOR_LOW_FREQ */
  1402. value |= (tonga_clock_stretcher_lookup_table[stretch_amount2][3]) << 16;
  1403. /* Program PWR_CKS_CNTL. CKS_LDO_REFSEL */
  1404. value |= (tonga_clock_stretcher_lookup_table[stretch_amount2][2]) << 18;
  1405. /* Program PWR_CKS_CNTL. CKS_STRETCH_AMOUNT */
  1406. value |= (tonga_clock_stretch_amount_conversion
  1407. [tonga_clock_stretcher_lookup_table[stretch_amount2][3]]
  1408. [stretch_amount]) << 3;
  1409. }
  1410. CONVERT_FROM_HOST_TO_SMC_US(smu_data->smc_state_table.CKS_LOOKUPTable.
  1411. CKS_LOOKUPTableEntry[0].minFreq);
  1412. CONVERT_FROM_HOST_TO_SMC_US(smu_data->smc_state_table.CKS_LOOKUPTable.
  1413. CKS_LOOKUPTableEntry[0].maxFreq);
  1414. smu_data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting =
  1415. tonga_clock_stretcher_lookup_table[stretch_amount2][2] & 0x7F;
  1416. smu_data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting |=
  1417. (tonga_clock_stretcher_lookup_table[stretch_amount2][3]) << 7;
  1418. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  1419. ixPWR_CKS_CNTL, value);
  1420. /* Populate DDT Lookup Table */
  1421. for (i = 0; i < 4; i++) {
  1422. /* Assign the minimum and maximum VID stored
  1423. * in the last row of Clock Stretcher Voltage Table.
  1424. */
  1425. smu_data->smc_state_table.ClockStretcherDataTable.
  1426. ClockStretcherDataTableEntry[i].minVID =
  1427. (uint8_t) tonga_clock_stretcher_ddt_table[type][i][2];
  1428. smu_data->smc_state_table.ClockStretcherDataTable.
  1429. ClockStretcherDataTableEntry[i].maxVID =
  1430. (uint8_t) tonga_clock_stretcher_ddt_table[type][i][3];
  1431. /* Loop through each SCLK and check the frequency
  1432. * to see if it lies within the frequency for clock stretcher.
  1433. */
  1434. for (j = 0; j < smu_data->smc_state_table.GraphicsDpmLevelCount; j++) {
  1435. cks_setting = 0;
  1436. clock_freq = PP_SMC_TO_HOST_UL(
  1437. smu_data->smc_state_table.GraphicsLevel[j].SclkFrequency);
  1438. /* Check the allowed frequency against the sclk level[j].
  1439. * Sclk's endianness has already been converted,
  1440. * and it's in 10Khz unit,
  1441. * as opposed to Data table, which is in Mhz unit.
  1442. */
  1443. if (clock_freq >= tonga_clock_stretcher_ddt_table[type][i][0] * 100) {
  1444. cks_setting |= 0x2;
  1445. if (clock_freq < tonga_clock_stretcher_ddt_table[type][i][1] * 100)
  1446. cks_setting |= 0x1;
  1447. }
  1448. smu_data->smc_state_table.ClockStretcherDataTable.
  1449. ClockStretcherDataTableEntry[i].setting |= cks_setting << (j * 2);
  1450. }
  1451. CONVERT_FROM_HOST_TO_SMC_US(smu_data->smc_state_table.
  1452. ClockStretcherDataTable.
  1453. ClockStretcherDataTableEntry[i].setting);
  1454. }
  1455. value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  1456. ixPWR_CKS_CNTL);
  1457. value &= 0xFFFFFFFE;
  1458. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  1459. ixPWR_CKS_CNTL, value);
  1460. return 0;
  1461. }
  1462. /**
  1463. * Populates the SMC VRConfig field in DPM table.
  1464. *
  1465. * @param hwmgr the address of the hardware manager
  1466. * @param table the SMC DPM table structure to be populated
  1467. * @return always 0
  1468. */
  1469. static int tonga_populate_vr_config(struct pp_hwmgr *hwmgr,
  1470. SMU72_Discrete_DpmTable *table)
  1471. {
  1472. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1473. uint16_t config;
  1474. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) {
  1475. /* Splitted mode */
  1476. config = VR_SVI2_PLANE_1;
  1477. table->VRConfig |= (config<<VRCONF_VDDGFX_SHIFT);
  1478. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
  1479. config = VR_SVI2_PLANE_2;
  1480. table->VRConfig |= config;
  1481. } else {
  1482. pr_err("VDDC and VDDGFX should "
  1483. "be both on SVI2 control in splitted mode !\n");
  1484. }
  1485. } else {
  1486. /* Merged mode */
  1487. config = VR_MERGED_WITH_VDDC;
  1488. table->VRConfig |= (config<<VRCONF_VDDGFX_SHIFT);
  1489. /* Set Vddc Voltage Controller */
  1490. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
  1491. config = VR_SVI2_PLANE_1;
  1492. table->VRConfig |= config;
  1493. } else {
  1494. pr_err("VDDC should be on "
  1495. "SVI2 control in merged mode !\n");
  1496. }
  1497. }
  1498. /* Set Vddci Voltage Controller */
  1499. if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
  1500. config = VR_SVI2_PLANE_2; /* only in merged mode */
  1501. table->VRConfig |= (config<<VRCONF_VDDCI_SHIFT);
  1502. } else if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
  1503. config = VR_SMIO_PATTERN_1;
  1504. table->VRConfig |= (config<<VRCONF_VDDCI_SHIFT);
  1505. }
  1506. /* Set Mvdd Voltage Controller */
  1507. if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
  1508. config = VR_SMIO_PATTERN_2;
  1509. table->VRConfig |= (config<<VRCONF_MVDD_SHIFT);
  1510. }
  1511. return 0;
  1512. }
  1513. /**
  1514. * Initialize the ARB DRAM timing table's index field.
  1515. *
  1516. * @param hwmgr the address of the powerplay hardware manager.
  1517. * @return always 0
  1518. */
  1519. static int tonga_init_arb_table_index(struct pp_smumgr *smumgr)
  1520. {
  1521. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(smumgr->backend);
  1522. uint32_t tmp;
  1523. int result;
  1524. /*
  1525. * This is a read-modify-write on the first byte of the ARB table.
  1526. * The first byte in the SMU72_Discrete_MCArbDramTimingTable structure
  1527. * is the field 'current'.
  1528. * This solution is ugly, but we never write the whole table only
  1529. * individual fields in it.
  1530. * In reality this field should not be in that structure
  1531. * but in a soft register.
  1532. */
  1533. result = smu7_read_smc_sram_dword(smumgr,
  1534. smu_data->smu7_data.arb_table_start, &tmp, SMC_RAM_END);
  1535. if (result != 0)
  1536. return result;
  1537. tmp &= 0x00FFFFFF;
  1538. tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24;
  1539. return smu7_write_smc_sram_dword(smumgr,
  1540. smu_data->smu7_data.arb_table_start, tmp, SMC_RAM_END);
  1541. }
  1542. static int tonga_populate_bapm_parameters_in_dpm_table(struct pp_hwmgr *hwmgr)
  1543. {
  1544. struct tonga_smumgr *smu_data =
  1545. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1546. const struct tonga_pt_defaults *defaults = smu_data->power_tune_defaults;
  1547. SMU72_Discrete_DpmTable *dpm_table = &(smu_data->smc_state_table);
  1548. struct phm_ppt_v1_information *table_info =
  1549. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1550. struct phm_cac_tdp_table *cac_dtp_table = table_info->cac_dtp_table;
  1551. int i, j, k;
  1552. const uint16_t *pdef1, *pdef2;
  1553. dpm_table->DefaultTdp = PP_HOST_TO_SMC_US(
  1554. (uint16_t)(cac_dtp_table->usTDP * 256));
  1555. dpm_table->TargetTdp = PP_HOST_TO_SMC_US(
  1556. (uint16_t)(cac_dtp_table->usConfigurableTDP * 256));
  1557. PP_ASSERT_WITH_CODE(cac_dtp_table->usTargetOperatingTemp <= 255,
  1558. "Target Operating Temp is out of Range !",
  1559. );
  1560. dpm_table->GpuTjMax = (uint8_t)(cac_dtp_table->usTargetOperatingTemp);
  1561. dpm_table->GpuTjHyst = 8;
  1562. dpm_table->DTEAmbientTempBase = defaults->dte_ambient_temp_base;
  1563. dpm_table->BAPM_TEMP_GRADIENT =
  1564. PP_HOST_TO_SMC_UL(defaults->bamp_temp_gradient);
  1565. pdef1 = defaults->bapmti_r;
  1566. pdef2 = defaults->bapmti_rc;
  1567. for (i = 0; i < SMU72_DTE_ITERATIONS; i++) {
  1568. for (j = 0; j < SMU72_DTE_SOURCES; j++) {
  1569. for (k = 0; k < SMU72_DTE_SINKS; k++) {
  1570. dpm_table->BAPMTI_R[i][j][k] =
  1571. PP_HOST_TO_SMC_US(*pdef1);
  1572. dpm_table->BAPMTI_RC[i][j][k] =
  1573. PP_HOST_TO_SMC_US(*pdef2);
  1574. pdef1++;
  1575. pdef2++;
  1576. }
  1577. }
  1578. }
  1579. return 0;
  1580. }
  1581. static int tonga_populate_svi_load_line(struct pp_hwmgr *hwmgr)
  1582. {
  1583. struct tonga_smumgr *smu_data =
  1584. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1585. const struct tonga_pt_defaults *defaults = smu_data->power_tune_defaults;
  1586. smu_data->power_tune_table.SviLoadLineEn = defaults->svi_load_line_en;
  1587. smu_data->power_tune_table.SviLoadLineVddC = defaults->svi_load_line_vddC;
  1588. smu_data->power_tune_table.SviLoadLineTrimVddC = 3;
  1589. smu_data->power_tune_table.SviLoadLineOffsetVddC = 0;
  1590. return 0;
  1591. }
  1592. static int tonga_populate_tdc_limit(struct pp_hwmgr *hwmgr)
  1593. {
  1594. uint16_t tdc_limit;
  1595. struct tonga_smumgr *smu_data =
  1596. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1597. const struct tonga_pt_defaults *defaults = smu_data->power_tune_defaults;
  1598. struct phm_ppt_v1_information *table_info =
  1599. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1600. /* TDC number of fraction bits are changed from 8 to 7
  1601. * for Fiji as requested by SMC team
  1602. */
  1603. tdc_limit = (uint16_t)(table_info->cac_dtp_table->usTDC * 256);
  1604. smu_data->power_tune_table.TDC_VDDC_PkgLimit =
  1605. CONVERT_FROM_HOST_TO_SMC_US(tdc_limit);
  1606. smu_data->power_tune_table.TDC_VDDC_ThrottleReleaseLimitPerc =
  1607. defaults->tdc_vddc_throttle_release_limit_perc;
  1608. smu_data->power_tune_table.TDC_MAWt = defaults->tdc_mawt;
  1609. return 0;
  1610. }
  1611. static int tonga_populate_dw8(struct pp_hwmgr *hwmgr, uint32_t fuse_table_offset)
  1612. {
  1613. struct tonga_smumgr *smu_data =
  1614. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1615. const struct tonga_pt_defaults *defaults = smu_data->power_tune_defaults;
  1616. uint32_t temp;
  1617. if (smu7_read_smc_sram_dword(hwmgr->smumgr,
  1618. fuse_table_offset +
  1619. offsetof(SMU72_Discrete_PmFuses, TdcWaterfallCtl),
  1620. (uint32_t *)&temp, SMC_RAM_END))
  1621. PP_ASSERT_WITH_CODE(false,
  1622. "Attempt to read PmFuses.DW6 "
  1623. "(SviLoadLineEn) from SMC Failed !",
  1624. return -EINVAL);
  1625. else
  1626. smu_data->power_tune_table.TdcWaterfallCtl = defaults->tdc_waterfall_ctl;
  1627. return 0;
  1628. }
  1629. static int tonga_populate_temperature_scaler(struct pp_hwmgr *hwmgr)
  1630. {
  1631. int i;
  1632. struct tonga_smumgr *smu_data =
  1633. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1634. /* Currently not used. Set all to zero. */
  1635. for (i = 0; i < 16; i++)
  1636. smu_data->power_tune_table.LPMLTemperatureScaler[i] = 0;
  1637. return 0;
  1638. }
  1639. static int tonga_populate_fuzzy_fan(struct pp_hwmgr *hwmgr)
  1640. {
  1641. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1642. if ((hwmgr->thermal_controller.advanceFanControlParameters.
  1643. usFanOutputSensitivity & (1 << 15)) ||
  1644. (hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity == 0))
  1645. hwmgr->thermal_controller.advanceFanControlParameters.
  1646. usFanOutputSensitivity = hwmgr->thermal_controller.
  1647. advanceFanControlParameters.usDefaultFanOutputSensitivity;
  1648. smu_data->power_tune_table.FuzzyFan_PwmSetDelta =
  1649. PP_HOST_TO_SMC_US(hwmgr->thermal_controller.
  1650. advanceFanControlParameters.usFanOutputSensitivity);
  1651. return 0;
  1652. }
  1653. static int tonga_populate_gnb_lpml(struct pp_hwmgr *hwmgr)
  1654. {
  1655. int i;
  1656. struct tonga_smumgr *smu_data =
  1657. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1658. /* Currently not used. Set all to zero. */
  1659. for (i = 0; i < 16; i++)
  1660. smu_data->power_tune_table.GnbLPML[i] = 0;
  1661. return 0;
  1662. }
  1663. static int tonga_min_max_vgnb_lpml_id_from_bapm_vddc(struct pp_hwmgr *hwmgr)
  1664. {
  1665. return 0;
  1666. }
  1667. static int tonga_populate_bapm_vddc_base_leakage_sidd(struct pp_hwmgr *hwmgr)
  1668. {
  1669. struct tonga_smumgr *smu_data =
  1670. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1671. struct phm_ppt_v1_information *table_info =
  1672. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1673. uint16_t hi_sidd = smu_data->power_tune_table.BapmVddCBaseLeakageHiSidd;
  1674. uint16_t lo_sidd = smu_data->power_tune_table.BapmVddCBaseLeakageLoSidd;
  1675. struct phm_cac_tdp_table *cac_table = table_info->cac_dtp_table;
  1676. hi_sidd = (uint16_t)(cac_table->usHighCACLeakage / 100 * 256);
  1677. lo_sidd = (uint16_t)(cac_table->usLowCACLeakage / 100 * 256);
  1678. smu_data->power_tune_table.BapmVddCBaseLeakageHiSidd =
  1679. CONVERT_FROM_HOST_TO_SMC_US(hi_sidd);
  1680. smu_data->power_tune_table.BapmVddCBaseLeakageLoSidd =
  1681. CONVERT_FROM_HOST_TO_SMC_US(lo_sidd);
  1682. return 0;
  1683. }
  1684. static int tonga_populate_pm_fuses(struct pp_hwmgr *hwmgr)
  1685. {
  1686. struct tonga_smumgr *smu_data =
  1687. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1688. uint32_t pm_fuse_table_offset;
  1689. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1690. PHM_PlatformCaps_PowerContainment)) {
  1691. if (smu7_read_smc_sram_dword(hwmgr->smumgr,
  1692. SMU72_FIRMWARE_HEADER_LOCATION +
  1693. offsetof(SMU72_Firmware_Header, PmFuseTable),
  1694. &pm_fuse_table_offset, SMC_RAM_END))
  1695. PP_ASSERT_WITH_CODE(false,
  1696. "Attempt to get pm_fuse_table_offset Failed !",
  1697. return -EINVAL);
  1698. /* DW6 */
  1699. if (tonga_populate_svi_load_line(hwmgr))
  1700. PP_ASSERT_WITH_CODE(false,
  1701. "Attempt to populate SviLoadLine Failed !",
  1702. return -EINVAL);
  1703. /* DW7 */
  1704. if (tonga_populate_tdc_limit(hwmgr))
  1705. PP_ASSERT_WITH_CODE(false,
  1706. "Attempt to populate TDCLimit Failed !",
  1707. return -EINVAL);
  1708. /* DW8 */
  1709. if (tonga_populate_dw8(hwmgr, pm_fuse_table_offset))
  1710. PP_ASSERT_WITH_CODE(false,
  1711. "Attempt to populate TdcWaterfallCtl Failed !",
  1712. return -EINVAL);
  1713. /* DW9-DW12 */
  1714. if (tonga_populate_temperature_scaler(hwmgr) != 0)
  1715. PP_ASSERT_WITH_CODE(false,
  1716. "Attempt to populate LPMLTemperatureScaler Failed !",
  1717. return -EINVAL);
  1718. /* DW13-DW14 */
  1719. if (tonga_populate_fuzzy_fan(hwmgr))
  1720. PP_ASSERT_WITH_CODE(false,
  1721. "Attempt to populate Fuzzy Fan "
  1722. "Control parameters Failed !",
  1723. return -EINVAL);
  1724. /* DW15-DW18 */
  1725. if (tonga_populate_gnb_lpml(hwmgr))
  1726. PP_ASSERT_WITH_CODE(false,
  1727. "Attempt to populate GnbLPML Failed !",
  1728. return -EINVAL);
  1729. /* DW19 */
  1730. if (tonga_min_max_vgnb_lpml_id_from_bapm_vddc(hwmgr))
  1731. PP_ASSERT_WITH_CODE(false,
  1732. "Attempt to populate GnbLPML "
  1733. "Min and Max Vid Failed !",
  1734. return -EINVAL);
  1735. /* DW20 */
  1736. if (tonga_populate_bapm_vddc_base_leakage_sidd(hwmgr))
  1737. PP_ASSERT_WITH_CODE(
  1738. false,
  1739. "Attempt to populate BapmVddCBaseLeakage "
  1740. "Hi and Lo Sidd Failed !",
  1741. return -EINVAL);
  1742. if (smu7_copy_bytes_to_smc(hwmgr->smumgr, pm_fuse_table_offset,
  1743. (uint8_t *)&smu_data->power_tune_table,
  1744. sizeof(struct SMU72_Discrete_PmFuses), SMC_RAM_END))
  1745. PP_ASSERT_WITH_CODE(false,
  1746. "Attempt to download PmFuseTable Failed !",
  1747. return -EINVAL);
  1748. }
  1749. return 0;
  1750. }
  1751. static int tonga_populate_mc_reg_address(struct pp_smumgr *smumgr,
  1752. SMU72_Discrete_MCRegisters *mc_reg_table)
  1753. {
  1754. const struct tonga_smumgr *smu_data = (struct tonga_smumgr *)smumgr->backend;
  1755. uint32_t i, j;
  1756. for (i = 0, j = 0; j < smu_data->mc_reg_table.last; j++) {
  1757. if (smu_data->mc_reg_table.validflag & 1<<j) {
  1758. PP_ASSERT_WITH_CODE(
  1759. i < SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE,
  1760. "Index of mc_reg_table->address[] array "
  1761. "out of boundary",
  1762. return -EINVAL);
  1763. mc_reg_table->address[i].s0 =
  1764. PP_HOST_TO_SMC_US(smu_data->mc_reg_table.mc_reg_address[j].s0);
  1765. mc_reg_table->address[i].s1 =
  1766. PP_HOST_TO_SMC_US(smu_data->mc_reg_table.mc_reg_address[j].s1);
  1767. i++;
  1768. }
  1769. }
  1770. mc_reg_table->last = (uint8_t)i;
  1771. return 0;
  1772. }
  1773. /*convert register values from driver to SMC format */
  1774. static void tonga_convert_mc_registers(
  1775. const struct tonga_mc_reg_entry *entry,
  1776. SMU72_Discrete_MCRegisterSet *data,
  1777. uint32_t num_entries, uint32_t valid_flag)
  1778. {
  1779. uint32_t i, j;
  1780. for (i = 0, j = 0; j < num_entries; j++) {
  1781. if (valid_flag & 1<<j) {
  1782. data->value[i] = PP_HOST_TO_SMC_UL(entry->mc_data[j]);
  1783. i++;
  1784. }
  1785. }
  1786. }
  1787. static int tonga_convert_mc_reg_table_entry_to_smc(
  1788. struct pp_smumgr *smumgr,
  1789. const uint32_t memory_clock,
  1790. SMU72_Discrete_MCRegisterSet *mc_reg_table_data
  1791. )
  1792. {
  1793. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(smumgr->backend);
  1794. uint32_t i = 0;
  1795. for (i = 0; i < smu_data->mc_reg_table.num_entries; i++) {
  1796. if (memory_clock <=
  1797. smu_data->mc_reg_table.mc_reg_table_entry[i].mclk_max) {
  1798. break;
  1799. }
  1800. }
  1801. if ((i == smu_data->mc_reg_table.num_entries) && (i > 0))
  1802. --i;
  1803. tonga_convert_mc_registers(&smu_data->mc_reg_table.mc_reg_table_entry[i],
  1804. mc_reg_table_data, smu_data->mc_reg_table.last,
  1805. smu_data->mc_reg_table.validflag);
  1806. return 0;
  1807. }
  1808. static int tonga_convert_mc_reg_table_to_smc(struct pp_hwmgr *hwmgr,
  1809. SMU72_Discrete_MCRegisters *mc_regs)
  1810. {
  1811. int result = 0;
  1812. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1813. int res;
  1814. uint32_t i;
  1815. for (i = 0; i < data->dpm_table.mclk_table.count; i++) {
  1816. res = tonga_convert_mc_reg_table_entry_to_smc(
  1817. hwmgr->smumgr,
  1818. data->dpm_table.mclk_table.dpm_levels[i].value,
  1819. &mc_regs->data[i]
  1820. );
  1821. if (0 != res)
  1822. result = res;
  1823. }
  1824. return result;
  1825. }
  1826. static int tonga_update_and_upload_mc_reg_table(struct pp_hwmgr *hwmgr)
  1827. {
  1828. struct pp_smumgr *smumgr = hwmgr->smumgr;
  1829. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(smumgr->backend);
  1830. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1831. uint32_t address;
  1832. int32_t result;
  1833. if (0 == (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK))
  1834. return 0;
  1835. memset(&smu_data->mc_regs, 0, sizeof(SMU72_Discrete_MCRegisters));
  1836. result = tonga_convert_mc_reg_table_to_smc(hwmgr, &(smu_data->mc_regs));
  1837. if (result != 0)
  1838. return result;
  1839. address = smu_data->smu7_data.mc_reg_table_start +
  1840. (uint32_t)offsetof(SMU72_Discrete_MCRegisters, data[0]);
  1841. return smu7_copy_bytes_to_smc(
  1842. hwmgr->smumgr, address,
  1843. (uint8_t *)&smu_data->mc_regs.data[0],
  1844. sizeof(SMU72_Discrete_MCRegisterSet) *
  1845. data->dpm_table.mclk_table.count,
  1846. SMC_RAM_END);
  1847. }
  1848. static int tonga_populate_initial_mc_reg_table(struct pp_hwmgr *hwmgr)
  1849. {
  1850. int result;
  1851. struct pp_smumgr *smumgr = hwmgr->smumgr;
  1852. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(smumgr->backend);
  1853. memset(&smu_data->mc_regs, 0x00, sizeof(SMU72_Discrete_MCRegisters));
  1854. result = tonga_populate_mc_reg_address(smumgr, &(smu_data->mc_regs));
  1855. PP_ASSERT_WITH_CODE(!result,
  1856. "Failed to initialize MCRegTable for the MC register addresses !",
  1857. return result;);
  1858. result = tonga_convert_mc_reg_table_to_smc(hwmgr, &smu_data->mc_regs);
  1859. PP_ASSERT_WITH_CODE(!result,
  1860. "Failed to initialize MCRegTable for driver state !",
  1861. return result;);
  1862. return smu7_copy_bytes_to_smc(smumgr, smu_data->smu7_data.mc_reg_table_start,
  1863. (uint8_t *)&smu_data->mc_regs, sizeof(SMU72_Discrete_MCRegisters), SMC_RAM_END);
  1864. }
  1865. static void tonga_initialize_power_tune_defaults(struct pp_hwmgr *hwmgr)
  1866. {
  1867. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1868. struct phm_ppt_v1_information *table_info =
  1869. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1870. if (table_info &&
  1871. table_info->cac_dtp_table->usPowerTuneDataSetID <= POWERTUNE_DEFAULT_SET_MAX &&
  1872. table_info->cac_dtp_table->usPowerTuneDataSetID)
  1873. smu_data->power_tune_defaults =
  1874. &tonga_power_tune_data_set_array
  1875. [table_info->cac_dtp_table->usPowerTuneDataSetID - 1];
  1876. else
  1877. smu_data->power_tune_defaults = &tonga_power_tune_data_set_array[0];
  1878. }
  1879. static void tonga_save_default_power_profile(struct pp_hwmgr *hwmgr)
  1880. {
  1881. struct tonga_smumgr *data = (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1882. struct SMU72_Discrete_GraphicsLevel *levels =
  1883. data->smc_state_table.GraphicsLevel;
  1884. unsigned min_level = 1;
  1885. hwmgr->default_gfx_power_profile.activity_threshold =
  1886. be16_to_cpu(levels[0].ActivityLevel);
  1887. hwmgr->default_gfx_power_profile.up_hyst = levels[0].UpHyst;
  1888. hwmgr->default_gfx_power_profile.down_hyst = levels[0].DownHyst;
  1889. hwmgr->default_gfx_power_profile.type = AMD_PP_GFX_PROFILE;
  1890. hwmgr->default_compute_power_profile = hwmgr->default_gfx_power_profile;
  1891. hwmgr->default_compute_power_profile.type = AMD_PP_COMPUTE_PROFILE;
  1892. /* Workaround compute SDMA instability: disable lowest SCLK
  1893. * DPM level. Optimize compute power profile: Use only highest
  1894. * 2 power levels (if more than 2 are available), Hysteresis:
  1895. * 0ms up, 5ms down
  1896. */
  1897. if (data->smc_state_table.GraphicsDpmLevelCount > 2)
  1898. min_level = data->smc_state_table.GraphicsDpmLevelCount - 2;
  1899. else if (data->smc_state_table.GraphicsDpmLevelCount == 2)
  1900. min_level = 1;
  1901. else
  1902. min_level = 0;
  1903. hwmgr->default_compute_power_profile.min_sclk =
  1904. be32_to_cpu(levels[min_level].SclkFrequency);
  1905. hwmgr->default_compute_power_profile.up_hyst = 0;
  1906. hwmgr->default_compute_power_profile.down_hyst = 5;
  1907. hwmgr->gfx_power_profile = hwmgr->default_gfx_power_profile;
  1908. hwmgr->compute_power_profile = hwmgr->default_compute_power_profile;
  1909. }
  1910. /**
  1911. * Initializes the SMC table and uploads it
  1912. *
  1913. * @param hwmgr the address of the powerplay hardware manager.
  1914. * @param pInput the pointer to input data (PowerState)
  1915. * @return always 0
  1916. */
  1917. int tonga_init_smc_table(struct pp_hwmgr *hwmgr)
  1918. {
  1919. int result;
  1920. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  1921. struct tonga_smumgr *smu_data =
  1922. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  1923. SMU72_Discrete_DpmTable *table = &(smu_data->smc_state_table);
  1924. struct phm_ppt_v1_information *table_info =
  1925. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  1926. uint8_t i;
  1927. pp_atomctrl_gpio_pin_assignment gpio_pin_assignment;
  1928. memset(&(smu_data->smc_state_table), 0x00, sizeof(smu_data->smc_state_table));
  1929. tonga_initialize_power_tune_defaults(hwmgr);
  1930. if (SMU7_VOLTAGE_CONTROL_NONE != data->voltage_control)
  1931. tonga_populate_smc_voltage_tables(hwmgr, table);
  1932. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1933. PHM_PlatformCaps_AutomaticDCTransition))
  1934. table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
  1935. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1936. PHM_PlatformCaps_StepVddc))
  1937. table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
  1938. if (data->is_memory_gddr5)
  1939. table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
  1940. i = PHM_READ_FIELD(hwmgr->device, CC_MC_MAX_CHANNEL, NOOFCHAN);
  1941. if (i == 1 || i == 0)
  1942. table->SystemFlags |= 0x40;
  1943. if (data->ulv_supported && table_info->us_ulv_voltage_offset) {
  1944. result = tonga_populate_ulv_state(hwmgr, table);
  1945. PP_ASSERT_WITH_CODE(!result,
  1946. "Failed to initialize ULV state !",
  1947. return result;);
  1948. cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
  1949. ixCG_ULV_PARAMETER, 0x40035);
  1950. }
  1951. result = tonga_populate_smc_link_level(hwmgr, table);
  1952. PP_ASSERT_WITH_CODE(!result,
  1953. "Failed to initialize Link Level !", return result);
  1954. result = tonga_populate_all_graphic_levels(hwmgr);
  1955. PP_ASSERT_WITH_CODE(!result,
  1956. "Failed to initialize Graphics Level !", return result);
  1957. result = tonga_populate_all_memory_levels(hwmgr);
  1958. PP_ASSERT_WITH_CODE(!result,
  1959. "Failed to initialize Memory Level !", return result);
  1960. result = tonga_populate_smc_acpi_level(hwmgr, table);
  1961. PP_ASSERT_WITH_CODE(!result,
  1962. "Failed to initialize ACPI Level !", return result);
  1963. result = tonga_populate_smc_vce_level(hwmgr, table);
  1964. PP_ASSERT_WITH_CODE(!result,
  1965. "Failed to initialize VCE Level !", return result);
  1966. result = tonga_populate_smc_acp_level(hwmgr, table);
  1967. PP_ASSERT_WITH_CODE(!result,
  1968. "Failed to initialize ACP Level !", return result);
  1969. result = tonga_populate_smc_samu_level(hwmgr, table);
  1970. PP_ASSERT_WITH_CODE(!result,
  1971. "Failed to initialize SAMU Level !", return result);
  1972. /* Since only the initial state is completely set up at this
  1973. * point (the other states are just copies of the boot state) we only
  1974. * need to populate the ARB settings for the initial state.
  1975. */
  1976. result = tonga_program_memory_timing_parameters(hwmgr);
  1977. PP_ASSERT_WITH_CODE(!result,
  1978. "Failed to Write ARB settings for the initial state.",
  1979. return result;);
  1980. result = tonga_populate_smc_uvd_level(hwmgr, table);
  1981. PP_ASSERT_WITH_CODE(!result,
  1982. "Failed to initialize UVD Level !", return result);
  1983. result = tonga_populate_smc_boot_level(hwmgr, table);
  1984. PP_ASSERT_WITH_CODE(!result,
  1985. "Failed to initialize Boot Level !", return result);
  1986. tonga_populate_bapm_parameters_in_dpm_table(hwmgr);
  1987. PP_ASSERT_WITH_CODE(!result,
  1988. "Failed to populate BAPM Parameters !", return result);
  1989. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1990. PHM_PlatformCaps_ClockStretcher)) {
  1991. result = tonga_populate_clock_stretcher_data_table(hwmgr);
  1992. PP_ASSERT_WITH_CODE(!result,
  1993. "Failed to populate Clock Stretcher Data Table !",
  1994. return result;);
  1995. }
  1996. table->GraphicsVoltageChangeEnable = 1;
  1997. table->GraphicsThermThrottleEnable = 1;
  1998. table->GraphicsInterval = 1;
  1999. table->VoltageInterval = 1;
  2000. table->ThermalInterval = 1;
  2001. table->TemperatureLimitHigh =
  2002. table_info->cac_dtp_table->usTargetOperatingTemp *
  2003. SMU7_Q88_FORMAT_CONVERSION_UNIT;
  2004. table->TemperatureLimitLow =
  2005. (table_info->cac_dtp_table->usTargetOperatingTemp - 1) *
  2006. SMU7_Q88_FORMAT_CONVERSION_UNIT;
  2007. table->MemoryVoltageChangeEnable = 1;
  2008. table->MemoryInterval = 1;
  2009. table->VoltageResponseTime = 0;
  2010. table->PhaseResponseTime = 0;
  2011. table->MemoryThermThrottleEnable = 1;
  2012. /*
  2013. * Cail reads current link status and reports it as cap (we cannot
  2014. * change this due to some previous issues we had)
  2015. * SMC drops the link status to lowest level after enabling
  2016. * DPM by PowerPlay. After pnp or toggling CF, driver gets reloaded again
  2017. * but this time Cail reads current link status which was set to low by
  2018. * SMC and reports it as cap to powerplay
  2019. * To avoid it, we set PCIeBootLinkLevel to highest dpm level
  2020. */
  2021. PP_ASSERT_WITH_CODE((1 <= data->dpm_table.pcie_speed_table.count),
  2022. "There must be 1 or more PCIE levels defined in PPTable.",
  2023. return -EINVAL);
  2024. table->PCIeBootLinkLevel = (uint8_t) (data->dpm_table.pcie_speed_table.count);
  2025. table->PCIeGenInterval = 1;
  2026. result = tonga_populate_vr_config(hwmgr, table);
  2027. PP_ASSERT_WITH_CODE(!result,
  2028. "Failed to populate VRConfig setting !", return result);
  2029. table->ThermGpio = 17;
  2030. table->SclkStepSize = 0x4000;
  2031. if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_VRHOT_GPIO_PINID,
  2032. &gpio_pin_assignment)) {
  2033. table->VRHotGpio = gpio_pin_assignment.uc_gpio_pin_bit_shift;
  2034. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  2035. PHM_PlatformCaps_RegulatorHot);
  2036. } else {
  2037. table->VRHotGpio = SMU7_UNUSED_GPIO_PIN;
  2038. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  2039. PHM_PlatformCaps_RegulatorHot);
  2040. }
  2041. if (atomctrl_get_pp_assign_pin(hwmgr, PP_AC_DC_SWITCH_GPIO_PINID,
  2042. &gpio_pin_assignment)) {
  2043. table->AcDcGpio = gpio_pin_assignment.uc_gpio_pin_bit_shift;
  2044. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  2045. PHM_PlatformCaps_AutomaticDCTransition);
  2046. } else {
  2047. table->AcDcGpio = SMU7_UNUSED_GPIO_PIN;
  2048. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  2049. PHM_PlatformCaps_AutomaticDCTransition);
  2050. }
  2051. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  2052. PHM_PlatformCaps_Falcon_QuickTransition);
  2053. if (0) {
  2054. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  2055. PHM_PlatformCaps_AutomaticDCTransition);
  2056. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  2057. PHM_PlatformCaps_Falcon_QuickTransition);
  2058. }
  2059. if (atomctrl_get_pp_assign_pin(hwmgr,
  2060. THERMAL_INT_OUTPUT_GPIO_PINID, &gpio_pin_assignment)) {
  2061. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  2062. PHM_PlatformCaps_ThermalOutGPIO);
  2063. table->ThermOutGpio = gpio_pin_assignment.uc_gpio_pin_bit_shift;
  2064. table->ThermOutPolarity =
  2065. (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A) &
  2066. (1 << gpio_pin_assignment.uc_gpio_pin_bit_shift))) ? 1 : 0;
  2067. table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY;
  2068. /* if required, combine VRHot/PCC with thermal out GPIO*/
  2069. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  2070. PHM_PlatformCaps_RegulatorHot) &&
  2071. phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  2072. PHM_PlatformCaps_CombinePCCWithThermalSignal)){
  2073. table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT;
  2074. }
  2075. } else {
  2076. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  2077. PHM_PlatformCaps_ThermalOutGPIO);
  2078. table->ThermOutGpio = 17;
  2079. table->ThermOutPolarity = 1;
  2080. table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE;
  2081. }
  2082. for (i = 0; i < SMU72_MAX_ENTRIES_SMIO; i++)
  2083. table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]);
  2084. CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags);
  2085. CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig);
  2086. CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1);
  2087. CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2);
  2088. CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize);
  2089. CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh);
  2090. CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow);
  2091. CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime);
  2092. CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
  2093. /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
  2094. result = smu7_copy_bytes_to_smc(
  2095. hwmgr->smumgr,
  2096. smu_data->smu7_data.dpm_table_start + offsetof(SMU72_Discrete_DpmTable, SystemFlags),
  2097. (uint8_t *)&(table->SystemFlags),
  2098. sizeof(SMU72_Discrete_DpmTable) - 3 * sizeof(SMU72_PIDController),
  2099. SMC_RAM_END);
  2100. PP_ASSERT_WITH_CODE(!result,
  2101. "Failed to upload dpm data to SMC memory !", return result;);
  2102. result = tonga_init_arb_table_index(hwmgr->smumgr);
  2103. PP_ASSERT_WITH_CODE(!result,
  2104. "Failed to upload arb data to SMC memory !", return result);
  2105. tonga_populate_pm_fuses(hwmgr);
  2106. PP_ASSERT_WITH_CODE((!result),
  2107. "Failed to populate initialize pm fuses !", return result);
  2108. result = tonga_populate_initial_mc_reg_table(hwmgr);
  2109. PP_ASSERT_WITH_CODE((!result),
  2110. "Failed to populate initialize MC Reg table !", return result);
  2111. tonga_save_default_power_profile(hwmgr);
  2112. return 0;
  2113. }
  2114. /**
  2115. * Set up the fan table to control the fan using the SMC.
  2116. * @param hwmgr the address of the powerplay hardware manager.
  2117. * @param pInput the pointer to input data
  2118. * @param pOutput the pointer to output data
  2119. * @param pStorage the pointer to temporary storage
  2120. * @param Result the last failure code
  2121. * @return result from set temperature range routine
  2122. */
  2123. int tonga_thermal_setup_fan_table(struct pp_hwmgr *hwmgr)
  2124. {
  2125. struct tonga_smumgr *smu_data =
  2126. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  2127. SMU72_Discrete_FanTable fan_table = { FDO_MODE_HARDWARE };
  2128. uint32_t duty100;
  2129. uint32_t t_diff1, t_diff2, pwm_diff1, pwm_diff2;
  2130. uint16_t fdo_min, slope1, slope2;
  2131. uint32_t reference_clock;
  2132. int res;
  2133. uint64_t tmp64;
  2134. if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  2135. PHM_PlatformCaps_MicrocodeFanControl))
  2136. return 0;
  2137. if (hwmgr->thermal_controller.fanInfo.bNoFan) {
  2138. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  2139. PHM_PlatformCaps_MicrocodeFanControl);
  2140. return 0;
  2141. }
  2142. if (0 == smu_data->smu7_data.fan_table_start) {
  2143. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  2144. PHM_PlatformCaps_MicrocodeFanControl);
  2145. return 0;
  2146. }
  2147. duty100 = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
  2148. CGS_IND_REG__SMC,
  2149. CG_FDO_CTRL1, FMAX_DUTY100);
  2150. if (0 == duty100) {
  2151. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  2152. PHM_PlatformCaps_MicrocodeFanControl);
  2153. return 0;
  2154. }
  2155. tmp64 = hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin * duty100;
  2156. do_div(tmp64, 10000);
  2157. fdo_min = (uint16_t)tmp64;
  2158. t_diff1 = hwmgr->thermal_controller.advanceFanControlParameters.usTMed -
  2159. hwmgr->thermal_controller.advanceFanControlParameters.usTMin;
  2160. t_diff2 = hwmgr->thermal_controller.advanceFanControlParameters.usTHigh -
  2161. hwmgr->thermal_controller.advanceFanControlParameters.usTMed;
  2162. pwm_diff1 = hwmgr->thermal_controller.advanceFanControlParameters.usPWMMed -
  2163. hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin;
  2164. pwm_diff2 = hwmgr->thermal_controller.advanceFanControlParameters.usPWMHigh -
  2165. hwmgr->thermal_controller.advanceFanControlParameters.usPWMMed;
  2166. slope1 = (uint16_t)((50 + ((16 * duty100 * pwm_diff1) / t_diff1)) / 100);
  2167. slope2 = (uint16_t)((50 + ((16 * duty100 * pwm_diff2) / t_diff2)) / 100);
  2168. fan_table.TempMin = cpu_to_be16((50 + hwmgr->thermal_controller.advanceFanControlParameters.usTMin) / 100);
  2169. fan_table.TempMed = cpu_to_be16((50 + hwmgr->thermal_controller.advanceFanControlParameters.usTMed) / 100);
  2170. fan_table.TempMax = cpu_to_be16((50 + hwmgr->thermal_controller.advanceFanControlParameters.usTMax) / 100);
  2171. fan_table.Slope1 = cpu_to_be16(slope1);
  2172. fan_table.Slope2 = cpu_to_be16(slope2);
  2173. fan_table.FdoMin = cpu_to_be16(fdo_min);
  2174. fan_table.HystDown = cpu_to_be16(hwmgr->thermal_controller.advanceFanControlParameters.ucTHyst);
  2175. fan_table.HystUp = cpu_to_be16(1);
  2176. fan_table.HystSlope = cpu_to_be16(1);
  2177. fan_table.TempRespLim = cpu_to_be16(5);
  2178. reference_clock = smu7_get_xclk(hwmgr);
  2179. fan_table.RefreshPeriod = cpu_to_be32((hwmgr->thermal_controller.advanceFanControlParameters.ulCycleDelay * reference_clock) / 1600);
  2180. fan_table.FdoMax = cpu_to_be16((uint16_t)duty100);
  2181. fan_table.TempSrc = (uint8_t)PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_MULT_THERMAL_CTRL, TEMP_SEL);
  2182. fan_table.FanControl_GL_Flag = 1;
  2183. res = smu7_copy_bytes_to_smc(hwmgr->smumgr,
  2184. smu_data->smu7_data.fan_table_start,
  2185. (uint8_t *)&fan_table,
  2186. (uint32_t)sizeof(fan_table),
  2187. SMC_RAM_END);
  2188. return 0;
  2189. }
  2190. static int tonga_program_mem_timing_parameters(struct pp_hwmgr *hwmgr)
  2191. {
  2192. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2193. if (data->need_update_smu7_dpm_table &
  2194. (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_OD_UPDATE_MCLK))
  2195. return tonga_program_memory_timing_parameters(hwmgr);
  2196. return 0;
  2197. }
  2198. int tonga_update_sclk_threshold(struct pp_hwmgr *hwmgr)
  2199. {
  2200. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2201. struct tonga_smumgr *smu_data =
  2202. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  2203. int result = 0;
  2204. uint32_t low_sclk_interrupt_threshold = 0;
  2205. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  2206. PHM_PlatformCaps_SclkThrottleLowNotification)
  2207. && (hwmgr->gfx_arbiter.sclk_threshold !=
  2208. data->low_sclk_interrupt_threshold)) {
  2209. data->low_sclk_interrupt_threshold =
  2210. hwmgr->gfx_arbiter.sclk_threshold;
  2211. low_sclk_interrupt_threshold =
  2212. data->low_sclk_interrupt_threshold;
  2213. CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
  2214. result = smu7_copy_bytes_to_smc(
  2215. hwmgr->smumgr,
  2216. smu_data->smu7_data.dpm_table_start +
  2217. offsetof(SMU72_Discrete_DpmTable,
  2218. LowSclkInterruptThreshold),
  2219. (uint8_t *)&low_sclk_interrupt_threshold,
  2220. sizeof(uint32_t),
  2221. SMC_RAM_END);
  2222. }
  2223. result = tonga_update_and_upload_mc_reg_table(hwmgr);
  2224. PP_ASSERT_WITH_CODE((!result),
  2225. "Failed to upload MC reg table !",
  2226. return result);
  2227. result = tonga_program_mem_timing_parameters(hwmgr);
  2228. PP_ASSERT_WITH_CODE((result == 0),
  2229. "Failed to program memory timing parameters !",
  2230. );
  2231. return result;
  2232. }
  2233. uint32_t tonga_get_offsetof(uint32_t type, uint32_t member)
  2234. {
  2235. switch (type) {
  2236. case SMU_SoftRegisters:
  2237. switch (member) {
  2238. case HandshakeDisables:
  2239. return offsetof(SMU72_SoftRegisters, HandshakeDisables);
  2240. case VoltageChangeTimeout:
  2241. return offsetof(SMU72_SoftRegisters, VoltageChangeTimeout);
  2242. case AverageGraphicsActivity:
  2243. return offsetof(SMU72_SoftRegisters, AverageGraphicsActivity);
  2244. case PreVBlankGap:
  2245. return offsetof(SMU72_SoftRegisters, PreVBlankGap);
  2246. case VBlankTimeout:
  2247. return offsetof(SMU72_SoftRegisters, VBlankTimeout);
  2248. case UcodeLoadStatus:
  2249. return offsetof(SMU72_SoftRegisters, UcodeLoadStatus);
  2250. }
  2251. case SMU_Discrete_DpmTable:
  2252. switch (member) {
  2253. case UvdBootLevel:
  2254. return offsetof(SMU72_Discrete_DpmTable, UvdBootLevel);
  2255. case VceBootLevel:
  2256. return offsetof(SMU72_Discrete_DpmTable, VceBootLevel);
  2257. case SamuBootLevel:
  2258. return offsetof(SMU72_Discrete_DpmTable, SamuBootLevel);
  2259. case LowSclkInterruptThreshold:
  2260. return offsetof(SMU72_Discrete_DpmTable, LowSclkInterruptThreshold);
  2261. }
  2262. }
  2263. pr_warn("can't get the offset of type %x member %x\n", type, member);
  2264. return 0;
  2265. }
  2266. uint32_t tonga_get_mac_definition(uint32_t value)
  2267. {
  2268. switch (value) {
  2269. case SMU_MAX_LEVELS_GRAPHICS:
  2270. return SMU72_MAX_LEVELS_GRAPHICS;
  2271. case SMU_MAX_LEVELS_MEMORY:
  2272. return SMU72_MAX_LEVELS_MEMORY;
  2273. case SMU_MAX_LEVELS_LINK:
  2274. return SMU72_MAX_LEVELS_LINK;
  2275. case SMU_MAX_ENTRIES_SMIO:
  2276. return SMU72_MAX_ENTRIES_SMIO;
  2277. case SMU_MAX_LEVELS_VDDC:
  2278. return SMU72_MAX_LEVELS_VDDC;
  2279. case SMU_MAX_LEVELS_VDDGFX:
  2280. return SMU72_MAX_LEVELS_VDDGFX;
  2281. case SMU_MAX_LEVELS_VDDCI:
  2282. return SMU72_MAX_LEVELS_VDDCI;
  2283. case SMU_MAX_LEVELS_MVDD:
  2284. return SMU72_MAX_LEVELS_MVDD;
  2285. }
  2286. pr_warn("can't get the mac value %x\n", value);
  2287. return 0;
  2288. }
  2289. static int tonga_update_uvd_smc_table(struct pp_hwmgr *hwmgr)
  2290. {
  2291. struct tonga_smumgr *smu_data =
  2292. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  2293. uint32_t mm_boot_level_offset, mm_boot_level_value;
  2294. struct phm_ppt_v1_information *table_info =
  2295. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  2296. smu_data->smc_state_table.UvdBootLevel = 0;
  2297. if (table_info->mm_dep_table->count > 0)
  2298. smu_data->smc_state_table.UvdBootLevel =
  2299. (uint8_t) (table_info->mm_dep_table->count - 1);
  2300. mm_boot_level_offset = smu_data->smu7_data.dpm_table_start +
  2301. offsetof(SMU72_Discrete_DpmTable, UvdBootLevel);
  2302. mm_boot_level_offset /= 4;
  2303. mm_boot_level_offset *= 4;
  2304. mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
  2305. CGS_IND_REG__SMC, mm_boot_level_offset);
  2306. mm_boot_level_value &= 0x00FFFFFF;
  2307. mm_boot_level_value |= smu_data->smc_state_table.UvdBootLevel << 24;
  2308. cgs_write_ind_register(hwmgr->device,
  2309. CGS_IND_REG__SMC,
  2310. mm_boot_level_offset, mm_boot_level_value);
  2311. if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  2312. PHM_PlatformCaps_UVDDPM) ||
  2313. phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  2314. PHM_PlatformCaps_StablePState))
  2315. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  2316. PPSMC_MSG_UVDDPM_SetEnabledMask,
  2317. (uint32_t)(1 << smu_data->smc_state_table.UvdBootLevel));
  2318. return 0;
  2319. }
  2320. static int tonga_update_vce_smc_table(struct pp_hwmgr *hwmgr)
  2321. {
  2322. struct tonga_smumgr *smu_data =
  2323. (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  2324. uint32_t mm_boot_level_offset, mm_boot_level_value;
  2325. struct phm_ppt_v1_information *table_info =
  2326. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  2327. smu_data->smc_state_table.VceBootLevel =
  2328. (uint8_t) (table_info->mm_dep_table->count - 1);
  2329. mm_boot_level_offset = smu_data->smu7_data.dpm_table_start +
  2330. offsetof(SMU72_Discrete_DpmTable, VceBootLevel);
  2331. mm_boot_level_offset /= 4;
  2332. mm_boot_level_offset *= 4;
  2333. mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
  2334. CGS_IND_REG__SMC, mm_boot_level_offset);
  2335. mm_boot_level_value &= 0xFF00FFFF;
  2336. mm_boot_level_value |= smu_data->smc_state_table.VceBootLevel << 16;
  2337. cgs_write_ind_register(hwmgr->device,
  2338. CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
  2339. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  2340. PHM_PlatformCaps_StablePState))
  2341. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  2342. PPSMC_MSG_VCEDPM_SetEnabledMask,
  2343. (uint32_t)1 << smu_data->smc_state_table.VceBootLevel);
  2344. return 0;
  2345. }
  2346. static int tonga_update_samu_smc_table(struct pp_hwmgr *hwmgr)
  2347. {
  2348. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  2349. uint32_t mm_boot_level_offset, mm_boot_level_value;
  2350. smu_data->smc_state_table.SamuBootLevel = 0;
  2351. mm_boot_level_offset = smu_data->smu7_data.dpm_table_start +
  2352. offsetof(SMU72_Discrete_DpmTable, SamuBootLevel);
  2353. mm_boot_level_offset /= 4;
  2354. mm_boot_level_offset *= 4;
  2355. mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
  2356. CGS_IND_REG__SMC, mm_boot_level_offset);
  2357. mm_boot_level_value &= 0xFFFFFF00;
  2358. mm_boot_level_value |= smu_data->smc_state_table.SamuBootLevel << 0;
  2359. cgs_write_ind_register(hwmgr->device,
  2360. CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
  2361. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  2362. PHM_PlatformCaps_StablePState))
  2363. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  2364. PPSMC_MSG_SAMUDPM_SetEnabledMask,
  2365. (uint32_t)(1 << smu_data->smc_state_table.SamuBootLevel));
  2366. return 0;
  2367. }
  2368. int tonga_update_smc_table(struct pp_hwmgr *hwmgr, uint32_t type)
  2369. {
  2370. switch (type) {
  2371. case SMU_UVD_TABLE:
  2372. tonga_update_uvd_smc_table(hwmgr);
  2373. break;
  2374. case SMU_VCE_TABLE:
  2375. tonga_update_vce_smc_table(hwmgr);
  2376. break;
  2377. case SMU_SAMU_TABLE:
  2378. tonga_update_samu_smc_table(hwmgr);
  2379. break;
  2380. default:
  2381. break;
  2382. }
  2383. return 0;
  2384. }
  2385. /**
  2386. * Get the location of various tables inside the FW image.
  2387. *
  2388. * @param hwmgr the address of the powerplay hardware manager.
  2389. * @return always 0
  2390. */
  2391. int tonga_process_firmware_header(struct pp_hwmgr *hwmgr)
  2392. {
  2393. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2394. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  2395. uint32_t tmp;
  2396. int result;
  2397. bool error = false;
  2398. result = smu7_read_smc_sram_dword(hwmgr->smumgr,
  2399. SMU72_FIRMWARE_HEADER_LOCATION +
  2400. offsetof(SMU72_Firmware_Header, DpmTable),
  2401. &tmp, SMC_RAM_END);
  2402. if (!result)
  2403. smu_data->smu7_data.dpm_table_start = tmp;
  2404. error |= (result != 0);
  2405. result = smu7_read_smc_sram_dword(hwmgr->smumgr,
  2406. SMU72_FIRMWARE_HEADER_LOCATION +
  2407. offsetof(SMU72_Firmware_Header, SoftRegisters),
  2408. &tmp, SMC_RAM_END);
  2409. if (!result) {
  2410. data->soft_regs_start = tmp;
  2411. smu_data->smu7_data.soft_regs_start = tmp;
  2412. }
  2413. error |= (result != 0);
  2414. result = smu7_read_smc_sram_dword(hwmgr->smumgr,
  2415. SMU72_FIRMWARE_HEADER_LOCATION +
  2416. offsetof(SMU72_Firmware_Header, mcRegisterTable),
  2417. &tmp, SMC_RAM_END);
  2418. if (!result)
  2419. smu_data->smu7_data.mc_reg_table_start = tmp;
  2420. result = smu7_read_smc_sram_dword(hwmgr->smumgr,
  2421. SMU72_FIRMWARE_HEADER_LOCATION +
  2422. offsetof(SMU72_Firmware_Header, FanTable),
  2423. &tmp, SMC_RAM_END);
  2424. if (!result)
  2425. smu_data->smu7_data.fan_table_start = tmp;
  2426. error |= (result != 0);
  2427. result = smu7_read_smc_sram_dword(hwmgr->smumgr,
  2428. SMU72_FIRMWARE_HEADER_LOCATION +
  2429. offsetof(SMU72_Firmware_Header, mcArbDramTimingTable),
  2430. &tmp, SMC_RAM_END);
  2431. if (!result)
  2432. smu_data->smu7_data.arb_table_start = tmp;
  2433. error |= (result != 0);
  2434. result = smu7_read_smc_sram_dword(hwmgr->smumgr,
  2435. SMU72_FIRMWARE_HEADER_LOCATION +
  2436. offsetof(SMU72_Firmware_Header, Version),
  2437. &tmp, SMC_RAM_END);
  2438. if (!result)
  2439. hwmgr->microcode_version_info.SMC = tmp;
  2440. error |= (result != 0);
  2441. return error ? 1 : 0;
  2442. }
  2443. /*---------------------------MC----------------------------*/
  2444. static uint8_t tonga_get_memory_modile_index(struct pp_hwmgr *hwmgr)
  2445. {
  2446. return (uint8_t) (0xFF & (cgs_read_register(hwmgr->device, mmBIOS_SCRATCH_4) >> 16));
  2447. }
  2448. static bool tonga_check_s0_mc_reg_index(uint16_t in_reg, uint16_t *out_reg)
  2449. {
  2450. bool result = true;
  2451. switch (in_reg) {
  2452. case mmMC_SEQ_RAS_TIMING:
  2453. *out_reg = mmMC_SEQ_RAS_TIMING_LP;
  2454. break;
  2455. case mmMC_SEQ_DLL_STBY:
  2456. *out_reg = mmMC_SEQ_DLL_STBY_LP;
  2457. break;
  2458. case mmMC_SEQ_G5PDX_CMD0:
  2459. *out_reg = mmMC_SEQ_G5PDX_CMD0_LP;
  2460. break;
  2461. case mmMC_SEQ_G5PDX_CMD1:
  2462. *out_reg = mmMC_SEQ_G5PDX_CMD1_LP;
  2463. break;
  2464. case mmMC_SEQ_G5PDX_CTRL:
  2465. *out_reg = mmMC_SEQ_G5PDX_CTRL_LP;
  2466. break;
  2467. case mmMC_SEQ_CAS_TIMING:
  2468. *out_reg = mmMC_SEQ_CAS_TIMING_LP;
  2469. break;
  2470. case mmMC_SEQ_MISC_TIMING:
  2471. *out_reg = mmMC_SEQ_MISC_TIMING_LP;
  2472. break;
  2473. case mmMC_SEQ_MISC_TIMING2:
  2474. *out_reg = mmMC_SEQ_MISC_TIMING2_LP;
  2475. break;
  2476. case mmMC_SEQ_PMG_DVS_CMD:
  2477. *out_reg = mmMC_SEQ_PMG_DVS_CMD_LP;
  2478. break;
  2479. case mmMC_SEQ_PMG_DVS_CTL:
  2480. *out_reg = mmMC_SEQ_PMG_DVS_CTL_LP;
  2481. break;
  2482. case mmMC_SEQ_RD_CTL_D0:
  2483. *out_reg = mmMC_SEQ_RD_CTL_D0_LP;
  2484. break;
  2485. case mmMC_SEQ_RD_CTL_D1:
  2486. *out_reg = mmMC_SEQ_RD_CTL_D1_LP;
  2487. break;
  2488. case mmMC_SEQ_WR_CTL_D0:
  2489. *out_reg = mmMC_SEQ_WR_CTL_D0_LP;
  2490. break;
  2491. case mmMC_SEQ_WR_CTL_D1:
  2492. *out_reg = mmMC_SEQ_WR_CTL_D1_LP;
  2493. break;
  2494. case mmMC_PMG_CMD_EMRS:
  2495. *out_reg = mmMC_SEQ_PMG_CMD_EMRS_LP;
  2496. break;
  2497. case mmMC_PMG_CMD_MRS:
  2498. *out_reg = mmMC_SEQ_PMG_CMD_MRS_LP;
  2499. break;
  2500. case mmMC_PMG_CMD_MRS1:
  2501. *out_reg = mmMC_SEQ_PMG_CMD_MRS1_LP;
  2502. break;
  2503. case mmMC_SEQ_PMG_TIMING:
  2504. *out_reg = mmMC_SEQ_PMG_TIMING_LP;
  2505. break;
  2506. case mmMC_PMG_CMD_MRS2:
  2507. *out_reg = mmMC_SEQ_PMG_CMD_MRS2_LP;
  2508. break;
  2509. case mmMC_SEQ_WR_CTL_2:
  2510. *out_reg = mmMC_SEQ_WR_CTL_2_LP;
  2511. break;
  2512. default:
  2513. result = false;
  2514. break;
  2515. }
  2516. return result;
  2517. }
  2518. static int tonga_set_s0_mc_reg_index(struct tonga_mc_reg_table *table)
  2519. {
  2520. uint32_t i;
  2521. uint16_t address;
  2522. for (i = 0; i < table->last; i++) {
  2523. table->mc_reg_address[i].s0 =
  2524. tonga_check_s0_mc_reg_index(table->mc_reg_address[i].s1,
  2525. &address) ?
  2526. address :
  2527. table->mc_reg_address[i].s1;
  2528. }
  2529. return 0;
  2530. }
  2531. static int tonga_copy_vbios_smc_reg_table(const pp_atomctrl_mc_reg_table *table,
  2532. struct tonga_mc_reg_table *ni_table)
  2533. {
  2534. uint8_t i, j;
  2535. PP_ASSERT_WITH_CODE((table->last <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
  2536. "Invalid VramInfo table.", return -EINVAL);
  2537. PP_ASSERT_WITH_CODE((table->num_entries <= MAX_AC_TIMING_ENTRIES),
  2538. "Invalid VramInfo table.", return -EINVAL);
  2539. for (i = 0; i < table->last; i++)
  2540. ni_table->mc_reg_address[i].s1 = table->mc_reg_address[i].s1;
  2541. ni_table->last = table->last;
  2542. for (i = 0; i < table->num_entries; i++) {
  2543. ni_table->mc_reg_table_entry[i].mclk_max =
  2544. table->mc_reg_table_entry[i].mclk_max;
  2545. for (j = 0; j < table->last; j++) {
  2546. ni_table->mc_reg_table_entry[i].mc_data[j] =
  2547. table->mc_reg_table_entry[i].mc_data[j];
  2548. }
  2549. }
  2550. ni_table->num_entries = table->num_entries;
  2551. return 0;
  2552. }
  2553. /**
  2554. * VBIOS omits some information to reduce size, we need to recover them here.
  2555. * 1. when we see mmMC_SEQ_MISC1, bit[31:16] EMRS1, need to be write to
  2556. * mmMC_PMG_CMD_EMRS /_LP[15:0]. Bit[15:0] MRS, need to be update
  2557. * mmMC_PMG_CMD_MRS/_LP[15:0]
  2558. * 2. when we see mmMC_SEQ_RESERVE_M, bit[15:0] EMRS2, need to be write to
  2559. * mmMC_PMG_CMD_MRS1/_LP[15:0].
  2560. * 3. need to set these data for each clock range
  2561. * @param hwmgr the address of the powerplay hardware manager.
  2562. * @param table the address of MCRegTable
  2563. * @return always 0
  2564. */
  2565. static int tonga_set_mc_special_registers(struct pp_hwmgr *hwmgr,
  2566. struct tonga_mc_reg_table *table)
  2567. {
  2568. uint8_t i, j, k;
  2569. uint32_t temp_reg;
  2570. struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
  2571. for (i = 0, j = table->last; i < table->last; i++) {
  2572. PP_ASSERT_WITH_CODE((j < SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
  2573. "Invalid VramInfo table.", return -EINVAL);
  2574. switch (table->mc_reg_address[i].s1) {
  2575. case mmMC_SEQ_MISC1:
  2576. temp_reg = cgs_read_register(hwmgr->device,
  2577. mmMC_PMG_CMD_EMRS);
  2578. table->mc_reg_address[j].s1 = mmMC_PMG_CMD_EMRS;
  2579. table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_EMRS_LP;
  2580. for (k = 0; k < table->num_entries; k++) {
  2581. table->mc_reg_table_entry[k].mc_data[j] =
  2582. ((temp_reg & 0xffff0000)) |
  2583. ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16);
  2584. }
  2585. j++;
  2586. PP_ASSERT_WITH_CODE((j < SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
  2587. "Invalid VramInfo table.", return -EINVAL);
  2588. temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS);
  2589. table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS;
  2590. table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS_LP;
  2591. for (k = 0; k < table->num_entries; k++) {
  2592. table->mc_reg_table_entry[k].mc_data[j] =
  2593. (temp_reg & 0xffff0000) |
  2594. (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
  2595. if (!data->is_memory_gddr5)
  2596. table->mc_reg_table_entry[k].mc_data[j] |= 0x100;
  2597. }
  2598. j++;
  2599. PP_ASSERT_WITH_CODE((j <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
  2600. "Invalid VramInfo table.", return -EINVAL);
  2601. if (!data->is_memory_gddr5) {
  2602. table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD;
  2603. table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD;
  2604. for (k = 0; k < table->num_entries; k++)
  2605. table->mc_reg_table_entry[k].mc_data[j] =
  2606. (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16;
  2607. j++;
  2608. PP_ASSERT_WITH_CODE((j <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
  2609. "Invalid VramInfo table.", return -EINVAL);
  2610. }
  2611. break;
  2612. case mmMC_SEQ_RESERVE_M:
  2613. temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS1);
  2614. table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS1;
  2615. table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS1_LP;
  2616. for (k = 0; k < table->num_entries; k++) {
  2617. table->mc_reg_table_entry[k].mc_data[j] =
  2618. (temp_reg & 0xffff0000) |
  2619. (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
  2620. }
  2621. j++;
  2622. PP_ASSERT_WITH_CODE((j <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
  2623. "Invalid VramInfo table.", return -EINVAL);
  2624. break;
  2625. default:
  2626. break;
  2627. }
  2628. }
  2629. table->last = j;
  2630. return 0;
  2631. }
  2632. static int tonga_set_valid_flag(struct tonga_mc_reg_table *table)
  2633. {
  2634. uint8_t i, j;
  2635. for (i = 0; i < table->last; i++) {
  2636. for (j = 1; j < table->num_entries; j++) {
  2637. if (table->mc_reg_table_entry[j-1].mc_data[i] !=
  2638. table->mc_reg_table_entry[j].mc_data[i]) {
  2639. table->validflag |= (1<<i);
  2640. break;
  2641. }
  2642. }
  2643. }
  2644. return 0;
  2645. }
  2646. int tonga_initialize_mc_reg_table(struct pp_hwmgr *hwmgr)
  2647. {
  2648. int result;
  2649. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(hwmgr->smumgr->backend);
  2650. pp_atomctrl_mc_reg_table *table;
  2651. struct tonga_mc_reg_table *ni_table = &smu_data->mc_reg_table;
  2652. uint8_t module_index = tonga_get_memory_modile_index(hwmgr);
  2653. table = kzalloc(sizeof(pp_atomctrl_mc_reg_table), GFP_KERNEL);
  2654. if (table == NULL)
  2655. return -ENOMEM;
  2656. /* Program additional LP registers that are no longer programmed by VBIOS */
  2657. cgs_write_register(hwmgr->device, mmMC_SEQ_RAS_TIMING_LP,
  2658. cgs_read_register(hwmgr->device, mmMC_SEQ_RAS_TIMING));
  2659. cgs_write_register(hwmgr->device, mmMC_SEQ_CAS_TIMING_LP,
  2660. cgs_read_register(hwmgr->device, mmMC_SEQ_CAS_TIMING));
  2661. cgs_write_register(hwmgr->device, mmMC_SEQ_DLL_STBY_LP,
  2662. cgs_read_register(hwmgr->device, mmMC_SEQ_DLL_STBY));
  2663. cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD0_LP,
  2664. cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD0));
  2665. cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD1_LP,
  2666. cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD1));
  2667. cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CTRL_LP,
  2668. cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CTRL));
  2669. cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CMD_LP,
  2670. cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CMD));
  2671. cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CTL_LP,
  2672. cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CTL));
  2673. cgs_write_register(hwmgr->device, mmMC_SEQ_MISC_TIMING_LP,
  2674. cgs_read_register(hwmgr->device, mmMC_SEQ_MISC_TIMING));
  2675. cgs_write_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2_LP,
  2676. cgs_read_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2));
  2677. cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_EMRS_LP,
  2678. cgs_read_register(hwmgr->device, mmMC_PMG_CMD_EMRS));
  2679. cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS_LP,
  2680. cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS));
  2681. cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS1_LP,
  2682. cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS1));
  2683. cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_D0_LP,
  2684. cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_D0));
  2685. cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1_LP,
  2686. cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1));
  2687. cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0_LP,
  2688. cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0));
  2689. cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1_LP,
  2690. cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1));
  2691. cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_TIMING_LP,
  2692. cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_TIMING));
  2693. cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS2_LP,
  2694. cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS2));
  2695. cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_2_LP,
  2696. cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_2));
  2697. memset(table, 0x00, sizeof(pp_atomctrl_mc_reg_table));
  2698. result = atomctrl_initialize_mc_reg_table(hwmgr, module_index, table);
  2699. if (!result)
  2700. result = tonga_copy_vbios_smc_reg_table(table, ni_table);
  2701. if (!result) {
  2702. tonga_set_s0_mc_reg_index(ni_table);
  2703. result = tonga_set_mc_special_registers(hwmgr, ni_table);
  2704. }
  2705. if (!result)
  2706. tonga_set_valid_flag(ni_table);
  2707. kfree(table);
  2708. return result;
  2709. }
  2710. bool tonga_is_dpm_running(struct pp_hwmgr *hwmgr)
  2711. {
  2712. return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
  2713. CGS_IND_REG__SMC, FEATURE_STATUS, VOLTAGE_CONTROLLER_ON))
  2714. ? true : false;
  2715. }
  2716. int tonga_populate_requested_graphic_levels(struct pp_hwmgr *hwmgr,
  2717. struct amd_pp_profile *request)
  2718. {
  2719. struct tonga_smumgr *smu_data = (struct tonga_smumgr *)
  2720. (hwmgr->smumgr->backend);
  2721. struct SMU72_Discrete_GraphicsLevel *levels =
  2722. smu_data->smc_state_table.GraphicsLevel;
  2723. uint32_t array = smu_data->smu7_data.dpm_table_start +
  2724. offsetof(SMU72_Discrete_DpmTable, GraphicsLevel);
  2725. uint32_t array_size = sizeof(struct SMU72_Discrete_GraphicsLevel) *
  2726. SMU72_MAX_LEVELS_GRAPHICS;
  2727. uint32_t i;
  2728. for (i = 0; i < smu_data->smc_state_table.GraphicsDpmLevelCount; i++) {
  2729. levels[i].ActivityLevel =
  2730. cpu_to_be16(request->activity_threshold);
  2731. levels[i].EnabledForActivity = 1;
  2732. levels[i].UpHyst = request->up_hyst;
  2733. levels[i].DownHyst = request->down_hyst;
  2734. }
  2735. return smu7_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
  2736. array_size, SMC_RAM_END);
  2737. }