clk-tegra210.c 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596
  1. /*
  2. * Copyright (c) 2012-2014 NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/io.h>
  17. #include <linux/clk.h>
  18. #include <linux/clk-provider.h>
  19. #include <linux/clkdev.h>
  20. #include <linux/of.h>
  21. #include <linux/of_address.h>
  22. #include <linux/delay.h>
  23. #include <linux/export.h>
  24. #include <linux/mutex.h>
  25. #include <linux/clk/tegra.h>
  26. #include <dt-bindings/clock/tegra210-car.h>
  27. #include <dt-bindings/reset/tegra210-car.h>
  28. #include <linux/iopoll.h>
  29. #include <soc/tegra/pmc.h>
  30. #include "clk.h"
  31. #include "clk-id.h"
  32. /*
  33. * TEGRA210_CAR_BANK_COUNT: the number of peripheral clock register
  34. * banks present in the Tegra210 CAR IP block. The banks are
  35. * identified by single letters, e.g.: L, H, U, V, W, X, Y. See
  36. * periph_regs[] in drivers/clk/tegra/clk.c
  37. */
  38. #define TEGRA210_CAR_BANK_COUNT 7
  39. #define CLK_SOURCE_CSITE 0x1d4
  40. #define CLK_SOURCE_EMC 0x19c
  41. #define CLK_SOURCE_SOR1 0x410
  42. #define CLK_SOURCE_LA 0x1f8
  43. #define CLK_SOURCE_SDMMC2 0x154
  44. #define CLK_SOURCE_SDMMC4 0x164
  45. #define PLLC_BASE 0x80
  46. #define PLLC_OUT 0x84
  47. #define PLLC_MISC0 0x88
  48. #define PLLC_MISC1 0x8c
  49. #define PLLC_MISC2 0x5d0
  50. #define PLLC_MISC3 0x5d4
  51. #define PLLC2_BASE 0x4e8
  52. #define PLLC2_MISC0 0x4ec
  53. #define PLLC2_MISC1 0x4f0
  54. #define PLLC2_MISC2 0x4f4
  55. #define PLLC2_MISC3 0x4f8
  56. #define PLLC3_BASE 0x4fc
  57. #define PLLC3_MISC0 0x500
  58. #define PLLC3_MISC1 0x504
  59. #define PLLC3_MISC2 0x508
  60. #define PLLC3_MISC3 0x50c
  61. #define PLLM_BASE 0x90
  62. #define PLLM_MISC1 0x98
  63. #define PLLM_MISC2 0x9c
  64. #define PLLP_BASE 0xa0
  65. #define PLLP_MISC0 0xac
  66. #define PLLP_MISC1 0x680
  67. #define PLLA_BASE 0xb0
  68. #define PLLA_MISC0 0xbc
  69. #define PLLA_MISC1 0xb8
  70. #define PLLA_MISC2 0x5d8
  71. #define PLLD_BASE 0xd0
  72. #define PLLD_MISC0 0xdc
  73. #define PLLD_MISC1 0xd8
  74. #define PLLU_BASE 0xc0
  75. #define PLLU_OUTA 0xc4
  76. #define PLLU_MISC0 0xcc
  77. #define PLLU_MISC1 0xc8
  78. #define PLLX_BASE 0xe0
  79. #define PLLX_MISC0 0xe4
  80. #define PLLX_MISC1 0x510
  81. #define PLLX_MISC2 0x514
  82. #define PLLX_MISC3 0x518
  83. #define PLLX_MISC4 0x5f0
  84. #define PLLX_MISC5 0x5f4
  85. #define PLLE_BASE 0xe8
  86. #define PLLE_MISC0 0xec
  87. #define PLLD2_BASE 0x4b8
  88. #define PLLD2_MISC0 0x4bc
  89. #define PLLD2_MISC1 0x570
  90. #define PLLD2_MISC2 0x574
  91. #define PLLD2_MISC3 0x578
  92. #define PLLE_AUX 0x48c
  93. #define PLLRE_BASE 0x4c4
  94. #define PLLRE_MISC0 0x4c8
  95. #define PLLRE_OUT1 0x4cc
  96. #define PLLDP_BASE 0x590
  97. #define PLLDP_MISC 0x594
  98. #define PLLC4_BASE 0x5a4
  99. #define PLLC4_MISC0 0x5a8
  100. #define PLLC4_OUT 0x5e4
  101. #define PLLMB_BASE 0x5e8
  102. #define PLLMB_MISC1 0x5ec
  103. #define PLLA1_BASE 0x6a4
  104. #define PLLA1_MISC0 0x6a8
  105. #define PLLA1_MISC1 0x6ac
  106. #define PLLA1_MISC2 0x6b0
  107. #define PLLA1_MISC3 0x6b4
  108. #define PLLU_IDDQ_BIT 31
  109. #define PLLCX_IDDQ_BIT 27
  110. #define PLLRE_IDDQ_BIT 24
  111. #define PLLA_IDDQ_BIT 25
  112. #define PLLD_IDDQ_BIT 20
  113. #define PLLSS_IDDQ_BIT 18
  114. #define PLLM_IDDQ_BIT 5
  115. #define PLLMB_IDDQ_BIT 17
  116. #define PLLXP_IDDQ_BIT 3
  117. #define PLLCX_RESET_BIT 30
  118. #define PLL_BASE_LOCK BIT(27)
  119. #define PLLCX_BASE_LOCK BIT(26)
  120. #define PLLE_MISC_LOCK BIT(11)
  121. #define PLLRE_MISC_LOCK BIT(27)
  122. #define PLL_MISC_LOCK_ENABLE 18
  123. #define PLLC_MISC_LOCK_ENABLE 24
  124. #define PLLDU_MISC_LOCK_ENABLE 22
  125. #define PLLU_MISC_LOCK_ENABLE 29
  126. #define PLLE_MISC_LOCK_ENABLE 9
  127. #define PLLRE_MISC_LOCK_ENABLE 30
  128. #define PLLSS_MISC_LOCK_ENABLE 30
  129. #define PLLP_MISC_LOCK_ENABLE 18
  130. #define PLLM_MISC_LOCK_ENABLE 4
  131. #define PLLMB_MISC_LOCK_ENABLE 16
  132. #define PLLA_MISC_LOCK_ENABLE 28
  133. #define PLLU_MISC_LOCK_ENABLE 29
  134. #define PLLD_MISC_LOCK_ENABLE 18
  135. #define PLLA_SDM_DIN_MASK 0xffff
  136. #define PLLA_SDM_EN_MASK BIT(26)
  137. #define PLLD_SDM_EN_MASK BIT(16)
  138. #define PLLD2_SDM_EN_MASK BIT(31)
  139. #define PLLD2_SSC_EN_MASK 0
  140. #define PLLDP_SS_CFG 0x598
  141. #define PLLDP_SDM_EN_MASK BIT(31)
  142. #define PLLDP_SSC_EN_MASK BIT(30)
  143. #define PLLDP_SS_CTRL1 0x59c
  144. #define PLLDP_SS_CTRL2 0x5a0
  145. #define PMC_PLLM_WB0_OVERRIDE 0x1dc
  146. #define PMC_PLLM_WB0_OVERRIDE_2 0x2b0
  147. #define UTMIP_PLL_CFG2 0x488
  148. #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xfff) << 6)
  149. #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18)
  150. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN BIT(0)
  151. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP BIT(1)
  152. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN BIT(2)
  153. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP BIT(3)
  154. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN BIT(4)
  155. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERUP BIT(5)
  156. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN BIT(24)
  157. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP BIT(25)
  158. #define UTMIP_PLL_CFG1 0x484
  159. #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
  160. #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
  161. #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP BIT(17)
  162. #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN BIT(16)
  163. #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP BIT(15)
  164. #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN BIT(14)
  165. #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN BIT(12)
  166. #define SATA_PLL_CFG0 0x490
  167. #define SATA_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0)
  168. #define SATA_PLL_CFG0_PADPLL_USE_LOCKDET BIT(2)
  169. #define SATA_PLL_CFG0_SATA_SEQ_IN_SWCTL BIT(4)
  170. #define SATA_PLL_CFG0_SATA_SEQ_RESET_INPUT_VALUE BIT(5)
  171. #define SATA_PLL_CFG0_SATA_SEQ_LANE_PD_INPUT_VALUE BIT(6)
  172. #define SATA_PLL_CFG0_SATA_SEQ_PADPLL_PD_INPUT_VALUE BIT(7)
  173. #define SATA_PLL_CFG0_PADPLL_SLEEP_IDDQ BIT(13)
  174. #define SATA_PLL_CFG0_SEQ_ENABLE BIT(24)
  175. #define XUSBIO_PLL_CFG0 0x51c
  176. #define XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0)
  177. #define XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL BIT(2)
  178. #define XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET BIT(6)
  179. #define XUSBIO_PLL_CFG0_PADPLL_SLEEP_IDDQ BIT(13)
  180. #define XUSBIO_PLL_CFG0_SEQ_ENABLE BIT(24)
  181. #define UTMIPLL_HW_PWRDN_CFG0 0x52c
  182. #define UTMIPLL_HW_PWRDN_CFG0_UTMIPLL_LOCK BIT(31)
  183. #define UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE BIT(25)
  184. #define UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24)
  185. #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE BIT(7)
  186. #define UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET BIT(6)
  187. #define UTMIPLL_HW_PWRDN_CFG0_SEQ_RESET_INPUT_VALUE BIT(5)
  188. #define UTMIPLL_HW_PWRDN_CFG0_SEQ_IN_SWCTL BIT(4)
  189. #define UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2)
  190. #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE BIT(1)
  191. #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL BIT(0)
  192. #define PLLU_HW_PWRDN_CFG0 0x530
  193. #define PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE BIT(28)
  194. #define PLLU_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24)
  195. #define PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT BIT(7)
  196. #define PLLU_HW_PWRDN_CFG0_USE_LOCKDET BIT(6)
  197. #define PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2)
  198. #define PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL BIT(0)
  199. #define XUSB_PLL_CFG0 0x534
  200. #define XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY 0x3ff
  201. #define XUSB_PLL_CFG0_PLLU_LOCK_DLY_MASK (0x3ff << 14)
  202. #define SPARE_REG0 0x55c
  203. #define CLK_M_DIVISOR_SHIFT 2
  204. #define CLK_M_DIVISOR_MASK 0x3
  205. #define RST_DFLL_DVCO 0x2f4
  206. #define DVFS_DFLL_RESET_SHIFT 0
  207. #define CLK_RST_CONTROLLER_RST_DEV_Y_SET 0x2a8
  208. #define CLK_RST_CONTROLLER_RST_DEV_Y_CLR 0x2ac
  209. #define LVL2_CLK_GATE_OVRA 0xf8
  210. #define LVL2_CLK_GATE_OVRC 0x3a0
  211. #define LVL2_CLK_GATE_OVRD 0x3a4
  212. #define LVL2_CLK_GATE_OVRE 0x554
  213. /* I2S registers to handle during APE MBIST WAR */
  214. #define TEGRA210_I2S_BASE 0x1000
  215. #define TEGRA210_I2S_SIZE 0x100
  216. #define TEGRA210_I2S_CTRLS 5
  217. #define TEGRA210_I2S_CG 0x88
  218. #define TEGRA210_I2S_CTRL 0xa0
  219. /* DISPA registers to handle during MBIST WAR */
  220. #define DC_CMD_DISPLAY_COMMAND 0xc8
  221. #define DC_COM_DSC_TOP_CTL 0xcf8
  222. /* VIC register to handle during MBIST WAR */
  223. #define NV_PVIC_THI_SLCG_OVERRIDE_LOW 0x8c
  224. /* APE, DISPA and VIC base addesses needed for MBIST WAR */
  225. #define TEGRA210_AHUB_BASE 0x702d0000
  226. #define TEGRA210_DISPA_BASE 0x54200000
  227. #define TEGRA210_VIC_BASE 0x54340000
  228. /*
  229. * SDM fractional divisor is 16-bit 2's complement signed number within
  230. * (-2^12 ... 2^12-1) range. Represented in PLL data structure as unsigned
  231. * 16-bit value, with "0" divisor mapped to 0xFFFF. Data "0" is used to
  232. * indicate that SDM is disabled.
  233. *
  234. * Effective ndiv value when SDM is enabled: ndiv + 1/2 + sdm_din/2^13
  235. */
  236. #define PLL_SDM_COEFF BIT(13)
  237. #define sdin_din_to_data(din) ((u16)((din) ? : 0xFFFFU))
  238. #define sdin_data_to_din(dat) (((dat) == 0xFFFFU) ? 0 : (s16)dat)
  239. /* This macro returns ndiv effective scaled to SDM range */
  240. #define sdin_get_n_eff(cfg) ((cfg)->n * PLL_SDM_COEFF + ((cfg)->sdm_data ? \
  241. (PLL_SDM_COEFF/2 + sdin_data_to_din((cfg)->sdm_data)) : 0))
  242. /* Tegra CPU clock and reset control regs */
  243. #define CLK_RST_CONTROLLER_CPU_CMPLX_STATUS 0x470
  244. #ifdef CONFIG_PM_SLEEP
  245. static struct cpu_clk_suspend_context {
  246. u32 clk_csite_src;
  247. } tegra210_cpu_clk_sctx;
  248. #endif
  249. struct tegra210_domain_mbist_war {
  250. void (*handle_lvl2_ovr)(struct tegra210_domain_mbist_war *mbist);
  251. const u32 lvl2_offset;
  252. const u32 lvl2_mask;
  253. const unsigned int num_clks;
  254. const unsigned int *clk_init_data;
  255. struct clk_bulk_data *clks;
  256. };
  257. static struct clk **clks;
  258. static void __iomem *clk_base;
  259. static void __iomem *pmc_base;
  260. static void __iomem *ahub_base;
  261. static void __iomem *dispa_base;
  262. static void __iomem *vic_base;
  263. static unsigned long osc_freq;
  264. static unsigned long pll_ref_freq;
  265. static DEFINE_SPINLOCK(pll_d_lock);
  266. static DEFINE_SPINLOCK(pll_e_lock);
  267. static DEFINE_SPINLOCK(pll_re_lock);
  268. static DEFINE_SPINLOCK(pll_u_lock);
  269. static DEFINE_SPINLOCK(sor1_lock);
  270. static DEFINE_SPINLOCK(emc_lock);
  271. static DEFINE_MUTEX(lvl2_ovr_lock);
  272. /* possible OSC frequencies in Hz */
  273. static unsigned long tegra210_input_freq[] = {
  274. [5] = 38400000,
  275. [8] = 12000000,
  276. };
  277. static const char *mux_pllmcp_clkm[] = {
  278. "pll_m", "pll_c", "pll_p", "clk_m", "pll_m_ud", "pll_mb", "pll_mb",
  279. "pll_p",
  280. };
  281. #define mux_pllmcp_clkm_idx NULL
  282. #define PLL_ENABLE (1 << 30)
  283. #define PLLCX_MISC1_IDDQ (1 << 27)
  284. #define PLLCX_MISC0_RESET (1 << 30)
  285. #define PLLCX_MISC0_DEFAULT_VALUE 0x40080000
  286. #define PLLCX_MISC0_WRITE_MASK 0x400ffffb
  287. #define PLLCX_MISC1_DEFAULT_VALUE 0x08000000
  288. #define PLLCX_MISC1_WRITE_MASK 0x08003cff
  289. #define PLLCX_MISC2_DEFAULT_VALUE 0x1f720f05
  290. #define PLLCX_MISC2_WRITE_MASK 0xffffff17
  291. #define PLLCX_MISC3_DEFAULT_VALUE 0x000000c4
  292. #define PLLCX_MISC3_WRITE_MASK 0x00ffffff
  293. /* PLLA */
  294. #define PLLA_BASE_IDDQ (1 << 25)
  295. #define PLLA_BASE_LOCK (1 << 27)
  296. #define PLLA_MISC0_LOCK_ENABLE (1 << 28)
  297. #define PLLA_MISC0_LOCK_OVERRIDE (1 << 27)
  298. #define PLLA_MISC2_EN_SDM (1 << 26)
  299. #define PLLA_MISC2_EN_DYNRAMP (1 << 25)
  300. #define PLLA_MISC0_DEFAULT_VALUE 0x12000020
  301. #define PLLA_MISC0_WRITE_MASK 0x7fffffff
  302. #define PLLA_MISC2_DEFAULT_VALUE 0x0
  303. #define PLLA_MISC2_WRITE_MASK 0x06ffffff
  304. /* PLLD */
  305. #define PLLD_BASE_CSI_CLKSOURCE (1 << 23)
  306. #define PLLD_MISC0_EN_SDM (1 << 16)
  307. #define PLLD_MISC0_LOCK_OVERRIDE (1 << 17)
  308. #define PLLD_MISC0_LOCK_ENABLE (1 << 18)
  309. #define PLLD_MISC0_IDDQ (1 << 20)
  310. #define PLLD_MISC0_DSI_CLKENABLE (1 << 21)
  311. #define PLLD_MISC0_DEFAULT_VALUE 0x00140000
  312. #define PLLD_MISC0_WRITE_MASK 0x3ff7ffff
  313. #define PLLD_MISC1_DEFAULT_VALUE 0x20
  314. #define PLLD_MISC1_WRITE_MASK 0x00ffffff
  315. /* PLLD2 and PLLDP and PLLC4 */
  316. #define PLLDSS_BASE_LOCK (1 << 27)
  317. #define PLLDSS_BASE_LOCK_OVERRIDE (1 << 24)
  318. #define PLLDSS_BASE_IDDQ (1 << 18)
  319. #define PLLDSS_BASE_REF_SEL_SHIFT 25
  320. #define PLLDSS_BASE_REF_SEL_MASK (0x3 << PLLDSS_BASE_REF_SEL_SHIFT)
  321. #define PLLDSS_MISC0_LOCK_ENABLE (1 << 30)
  322. #define PLLDSS_MISC1_CFG_EN_SDM (1 << 31)
  323. #define PLLDSS_MISC1_CFG_EN_SSC (1 << 30)
  324. #define PLLD2_MISC0_DEFAULT_VALUE 0x40000020
  325. #define PLLD2_MISC1_CFG_DEFAULT_VALUE 0x10000000
  326. #define PLLD2_MISC2_CTRL1_DEFAULT_VALUE 0x0
  327. #define PLLD2_MISC3_CTRL2_DEFAULT_VALUE 0x0
  328. #define PLLDP_MISC0_DEFAULT_VALUE 0x40000020
  329. #define PLLDP_MISC1_CFG_DEFAULT_VALUE 0xc0000000
  330. #define PLLDP_MISC2_CTRL1_DEFAULT_VALUE 0xf400f0da
  331. #define PLLDP_MISC3_CTRL2_DEFAULT_VALUE 0x2004f400
  332. #define PLLDSS_MISC0_WRITE_MASK 0x47ffffff
  333. #define PLLDSS_MISC1_CFG_WRITE_MASK 0xf8000000
  334. #define PLLDSS_MISC2_CTRL1_WRITE_MASK 0xffffffff
  335. #define PLLDSS_MISC3_CTRL2_WRITE_MASK 0xffffffff
  336. #define PLLC4_MISC0_DEFAULT_VALUE 0x40000000
  337. /* PLLRE */
  338. #define PLLRE_MISC0_LOCK_ENABLE (1 << 30)
  339. #define PLLRE_MISC0_LOCK_OVERRIDE (1 << 29)
  340. #define PLLRE_MISC0_LOCK (1 << 27)
  341. #define PLLRE_MISC0_IDDQ (1 << 24)
  342. #define PLLRE_BASE_DEFAULT_VALUE 0x0
  343. #define PLLRE_MISC0_DEFAULT_VALUE 0x41000000
  344. #define PLLRE_BASE_DEFAULT_MASK 0x1c000000
  345. #define PLLRE_MISC0_WRITE_MASK 0x67ffffff
  346. /* PLLX */
  347. #define PLLX_USE_DYN_RAMP 1
  348. #define PLLX_BASE_LOCK (1 << 27)
  349. #define PLLX_MISC0_FO_G_DISABLE (0x1 << 28)
  350. #define PLLX_MISC0_LOCK_ENABLE (0x1 << 18)
  351. #define PLLX_MISC2_DYNRAMP_STEPB_SHIFT 24
  352. #define PLLX_MISC2_DYNRAMP_STEPB_MASK (0xFF << PLLX_MISC2_DYNRAMP_STEPB_SHIFT)
  353. #define PLLX_MISC2_DYNRAMP_STEPA_SHIFT 16
  354. #define PLLX_MISC2_DYNRAMP_STEPA_MASK (0xFF << PLLX_MISC2_DYNRAMP_STEPA_SHIFT)
  355. #define PLLX_MISC2_NDIV_NEW_SHIFT 8
  356. #define PLLX_MISC2_NDIV_NEW_MASK (0xFF << PLLX_MISC2_NDIV_NEW_SHIFT)
  357. #define PLLX_MISC2_LOCK_OVERRIDE (0x1 << 4)
  358. #define PLLX_MISC2_DYNRAMP_DONE (0x1 << 2)
  359. #define PLLX_MISC2_EN_DYNRAMP (0x1 << 0)
  360. #define PLLX_MISC3_IDDQ (0x1 << 3)
  361. #define PLLX_MISC0_DEFAULT_VALUE PLLX_MISC0_LOCK_ENABLE
  362. #define PLLX_MISC0_WRITE_MASK 0x10c40000
  363. #define PLLX_MISC1_DEFAULT_VALUE 0x20
  364. #define PLLX_MISC1_WRITE_MASK 0x00ffffff
  365. #define PLLX_MISC2_DEFAULT_VALUE 0x0
  366. #define PLLX_MISC2_WRITE_MASK 0xffffff11
  367. #define PLLX_MISC3_DEFAULT_VALUE PLLX_MISC3_IDDQ
  368. #define PLLX_MISC3_WRITE_MASK 0x01ff0f0f
  369. #define PLLX_MISC4_DEFAULT_VALUE 0x0
  370. #define PLLX_MISC4_WRITE_MASK 0x8000ffff
  371. #define PLLX_MISC5_DEFAULT_VALUE 0x0
  372. #define PLLX_MISC5_WRITE_MASK 0x0000ffff
  373. #define PLLX_HW_CTRL_CFG 0x548
  374. #define PLLX_HW_CTRL_CFG_SWCTRL (0x1 << 0)
  375. /* PLLMB */
  376. #define PLLMB_BASE_LOCK (1 << 27)
  377. #define PLLMB_MISC1_LOCK_OVERRIDE (1 << 18)
  378. #define PLLMB_MISC1_IDDQ (1 << 17)
  379. #define PLLMB_MISC1_LOCK_ENABLE (1 << 16)
  380. #define PLLMB_MISC1_DEFAULT_VALUE 0x00030000
  381. #define PLLMB_MISC1_WRITE_MASK 0x0007ffff
  382. /* PLLP */
  383. #define PLLP_BASE_OVERRIDE (1 << 28)
  384. #define PLLP_BASE_LOCK (1 << 27)
  385. #define PLLP_MISC0_LOCK_ENABLE (1 << 18)
  386. #define PLLP_MISC0_LOCK_OVERRIDE (1 << 17)
  387. #define PLLP_MISC0_IDDQ (1 << 3)
  388. #define PLLP_MISC1_HSIO_EN_SHIFT 29
  389. #define PLLP_MISC1_HSIO_EN (1 << PLLP_MISC1_HSIO_EN_SHIFT)
  390. #define PLLP_MISC1_XUSB_EN_SHIFT 28
  391. #define PLLP_MISC1_XUSB_EN (1 << PLLP_MISC1_XUSB_EN_SHIFT)
  392. #define PLLP_MISC0_DEFAULT_VALUE 0x00040008
  393. #define PLLP_MISC1_DEFAULT_VALUE 0x0
  394. #define PLLP_MISC0_WRITE_MASK 0xdc6000f
  395. #define PLLP_MISC1_WRITE_MASK 0x70ffffff
  396. /* PLLU */
  397. #define PLLU_BASE_LOCK (1 << 27)
  398. #define PLLU_BASE_OVERRIDE (1 << 24)
  399. #define PLLU_BASE_CLKENABLE_USB (1 << 21)
  400. #define PLLU_BASE_CLKENABLE_HSIC (1 << 22)
  401. #define PLLU_BASE_CLKENABLE_ICUSB (1 << 23)
  402. #define PLLU_BASE_CLKENABLE_48M (1 << 25)
  403. #define PLLU_BASE_CLKENABLE_ALL (PLLU_BASE_CLKENABLE_USB |\
  404. PLLU_BASE_CLKENABLE_HSIC |\
  405. PLLU_BASE_CLKENABLE_ICUSB |\
  406. PLLU_BASE_CLKENABLE_48M)
  407. #define PLLU_MISC0_IDDQ (1 << 31)
  408. #define PLLU_MISC0_LOCK_ENABLE (1 << 29)
  409. #define PLLU_MISC1_LOCK_OVERRIDE (1 << 0)
  410. #define PLLU_MISC0_DEFAULT_VALUE 0xa0000000
  411. #define PLLU_MISC1_DEFAULT_VALUE 0x0
  412. #define PLLU_MISC0_WRITE_MASK 0xbfffffff
  413. #define PLLU_MISC1_WRITE_MASK 0x00000007
  414. void tegra210_xusb_pll_hw_control_enable(void)
  415. {
  416. u32 val;
  417. val = readl_relaxed(clk_base + XUSBIO_PLL_CFG0);
  418. val &= ~(XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL |
  419. XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL);
  420. val |= XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET |
  421. XUSBIO_PLL_CFG0_PADPLL_SLEEP_IDDQ;
  422. writel_relaxed(val, clk_base + XUSBIO_PLL_CFG0);
  423. }
  424. EXPORT_SYMBOL_GPL(tegra210_xusb_pll_hw_control_enable);
  425. void tegra210_xusb_pll_hw_sequence_start(void)
  426. {
  427. u32 val;
  428. val = readl_relaxed(clk_base + XUSBIO_PLL_CFG0);
  429. val |= XUSBIO_PLL_CFG0_SEQ_ENABLE;
  430. writel_relaxed(val, clk_base + XUSBIO_PLL_CFG0);
  431. }
  432. EXPORT_SYMBOL_GPL(tegra210_xusb_pll_hw_sequence_start);
  433. void tegra210_sata_pll_hw_control_enable(void)
  434. {
  435. u32 val;
  436. val = readl_relaxed(clk_base + SATA_PLL_CFG0);
  437. val &= ~SATA_PLL_CFG0_PADPLL_RESET_SWCTL;
  438. val |= SATA_PLL_CFG0_PADPLL_USE_LOCKDET |
  439. SATA_PLL_CFG0_PADPLL_SLEEP_IDDQ;
  440. writel_relaxed(val, clk_base + SATA_PLL_CFG0);
  441. }
  442. EXPORT_SYMBOL_GPL(tegra210_sata_pll_hw_control_enable);
  443. void tegra210_sata_pll_hw_sequence_start(void)
  444. {
  445. u32 val;
  446. val = readl_relaxed(clk_base + SATA_PLL_CFG0);
  447. val |= SATA_PLL_CFG0_SEQ_ENABLE;
  448. writel_relaxed(val, clk_base + SATA_PLL_CFG0);
  449. }
  450. EXPORT_SYMBOL_GPL(tegra210_sata_pll_hw_sequence_start);
  451. void tegra210_set_sata_pll_seq_sw(bool state)
  452. {
  453. u32 val;
  454. val = readl_relaxed(clk_base + SATA_PLL_CFG0);
  455. if (state) {
  456. val |= SATA_PLL_CFG0_SATA_SEQ_IN_SWCTL;
  457. val |= SATA_PLL_CFG0_SATA_SEQ_RESET_INPUT_VALUE;
  458. val |= SATA_PLL_CFG0_SATA_SEQ_LANE_PD_INPUT_VALUE;
  459. val |= SATA_PLL_CFG0_SATA_SEQ_PADPLL_PD_INPUT_VALUE;
  460. } else {
  461. val &= ~SATA_PLL_CFG0_SATA_SEQ_IN_SWCTL;
  462. val &= ~SATA_PLL_CFG0_SATA_SEQ_RESET_INPUT_VALUE;
  463. val &= ~SATA_PLL_CFG0_SATA_SEQ_LANE_PD_INPUT_VALUE;
  464. val &= ~SATA_PLL_CFG0_SATA_SEQ_PADPLL_PD_INPUT_VALUE;
  465. }
  466. writel_relaxed(val, clk_base + SATA_PLL_CFG0);
  467. }
  468. EXPORT_SYMBOL_GPL(tegra210_set_sata_pll_seq_sw);
  469. static void tegra210_generic_mbist_war(struct tegra210_domain_mbist_war *mbist)
  470. {
  471. u32 val;
  472. val = readl_relaxed(clk_base + mbist->lvl2_offset);
  473. writel_relaxed(val | mbist->lvl2_mask, clk_base + mbist->lvl2_offset);
  474. fence_udelay(1, clk_base);
  475. writel_relaxed(val, clk_base + mbist->lvl2_offset);
  476. fence_udelay(1, clk_base);
  477. }
  478. static void tegra210_venc_mbist_war(struct tegra210_domain_mbist_war *mbist)
  479. {
  480. u32 csi_src, ovra, ovre;
  481. unsigned long flags = 0;
  482. spin_lock_irqsave(&pll_d_lock, flags);
  483. csi_src = readl_relaxed(clk_base + PLLD_BASE);
  484. writel_relaxed(csi_src | PLLD_BASE_CSI_CLKSOURCE, clk_base + PLLD_BASE);
  485. fence_udelay(1, clk_base);
  486. ovra = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRA);
  487. writel_relaxed(ovra | BIT(15), clk_base + LVL2_CLK_GATE_OVRA);
  488. ovre = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRE);
  489. writel_relaxed(ovre | BIT(3), clk_base + LVL2_CLK_GATE_OVRE);
  490. fence_udelay(1, clk_base);
  491. writel_relaxed(ovra, clk_base + LVL2_CLK_GATE_OVRA);
  492. writel_relaxed(ovre, clk_base + LVL2_CLK_GATE_OVRE);
  493. writel_relaxed(csi_src, clk_base + PLLD_BASE);
  494. fence_udelay(1, clk_base);
  495. spin_unlock_irqrestore(&pll_d_lock, flags);
  496. }
  497. static void tegra210_disp_mbist_war(struct tegra210_domain_mbist_war *mbist)
  498. {
  499. u32 ovra, dsc_top_ctrl;
  500. ovra = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRA);
  501. writel_relaxed(ovra | BIT(1), clk_base + LVL2_CLK_GATE_OVRA);
  502. fence_udelay(1, clk_base);
  503. dsc_top_ctrl = readl_relaxed(dispa_base + DC_COM_DSC_TOP_CTL);
  504. writel_relaxed(dsc_top_ctrl | BIT(2), dispa_base + DC_COM_DSC_TOP_CTL);
  505. readl_relaxed(dispa_base + DC_CMD_DISPLAY_COMMAND);
  506. writel_relaxed(dsc_top_ctrl, dispa_base + DC_COM_DSC_TOP_CTL);
  507. readl_relaxed(dispa_base + DC_CMD_DISPLAY_COMMAND);
  508. writel_relaxed(ovra, clk_base + LVL2_CLK_GATE_OVRA);
  509. fence_udelay(1, clk_base);
  510. }
  511. static void tegra210_vic_mbist_war(struct tegra210_domain_mbist_war *mbist)
  512. {
  513. u32 ovre, val;
  514. ovre = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRE);
  515. writel_relaxed(ovre | BIT(5), clk_base + LVL2_CLK_GATE_OVRE);
  516. fence_udelay(1, clk_base);
  517. val = readl_relaxed(vic_base + NV_PVIC_THI_SLCG_OVERRIDE_LOW);
  518. writel_relaxed(val | BIT(0) | GENMASK(7, 2) | BIT(24),
  519. vic_base + NV_PVIC_THI_SLCG_OVERRIDE_LOW);
  520. fence_udelay(1, vic_base + NV_PVIC_THI_SLCG_OVERRIDE_LOW);
  521. writel_relaxed(val, vic_base + NV_PVIC_THI_SLCG_OVERRIDE_LOW);
  522. readl(vic_base + NV_PVIC_THI_SLCG_OVERRIDE_LOW);
  523. writel_relaxed(ovre, clk_base + LVL2_CLK_GATE_OVRE);
  524. fence_udelay(1, clk_base);
  525. }
  526. static void tegra210_ape_mbist_war(struct tegra210_domain_mbist_war *mbist)
  527. {
  528. void __iomem *i2s_base;
  529. unsigned int i;
  530. u32 ovrc, ovre;
  531. ovrc = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRC);
  532. ovre = readl_relaxed(clk_base + LVL2_CLK_GATE_OVRE);
  533. writel_relaxed(ovrc | BIT(1), clk_base + LVL2_CLK_GATE_OVRC);
  534. writel_relaxed(ovre | BIT(10) | BIT(11),
  535. clk_base + LVL2_CLK_GATE_OVRE);
  536. fence_udelay(1, clk_base);
  537. i2s_base = ahub_base + TEGRA210_I2S_BASE;
  538. for (i = 0; i < TEGRA210_I2S_CTRLS; i++) {
  539. u32 i2s_ctrl;
  540. i2s_ctrl = readl_relaxed(i2s_base + TEGRA210_I2S_CTRL);
  541. writel_relaxed(i2s_ctrl | BIT(10),
  542. i2s_base + TEGRA210_I2S_CTRL);
  543. writel_relaxed(0, i2s_base + TEGRA210_I2S_CG);
  544. readl(i2s_base + TEGRA210_I2S_CG);
  545. writel_relaxed(1, i2s_base + TEGRA210_I2S_CG);
  546. writel_relaxed(i2s_ctrl, i2s_base + TEGRA210_I2S_CTRL);
  547. readl(i2s_base + TEGRA210_I2S_CTRL);
  548. i2s_base += TEGRA210_I2S_SIZE;
  549. }
  550. writel_relaxed(ovrc, clk_base + LVL2_CLK_GATE_OVRC);
  551. writel_relaxed(ovre, clk_base + LVL2_CLK_GATE_OVRE);
  552. fence_udelay(1, clk_base);
  553. }
  554. static inline void _pll_misc_chk_default(void __iomem *base,
  555. struct tegra_clk_pll_params *params,
  556. u8 misc_num, u32 default_val, u32 mask)
  557. {
  558. u32 boot_val = readl_relaxed(base + params->ext_misc_reg[misc_num]);
  559. boot_val &= mask;
  560. default_val &= mask;
  561. if (boot_val != default_val) {
  562. pr_warn("boot misc%d 0x%x: expected 0x%x\n",
  563. misc_num, boot_val, default_val);
  564. pr_warn(" (comparison mask = 0x%x)\n", mask);
  565. params->defaults_set = false;
  566. }
  567. }
  568. /*
  569. * PLLCX: PLLC, PLLC2, PLLC3, PLLA1
  570. * Hybrid PLLs with dynamic ramp. Dynamic ramp is allowed for any transition
  571. * that changes NDIV only, while PLL is already locked.
  572. */
  573. static void pllcx_check_defaults(struct tegra_clk_pll_params *params)
  574. {
  575. u32 default_val;
  576. default_val = PLLCX_MISC0_DEFAULT_VALUE & (~PLLCX_MISC0_RESET);
  577. _pll_misc_chk_default(clk_base, params, 0, default_val,
  578. PLLCX_MISC0_WRITE_MASK);
  579. default_val = PLLCX_MISC1_DEFAULT_VALUE & (~PLLCX_MISC1_IDDQ);
  580. _pll_misc_chk_default(clk_base, params, 1, default_val,
  581. PLLCX_MISC1_WRITE_MASK);
  582. default_val = PLLCX_MISC2_DEFAULT_VALUE;
  583. _pll_misc_chk_default(clk_base, params, 2, default_val,
  584. PLLCX_MISC2_WRITE_MASK);
  585. default_val = PLLCX_MISC3_DEFAULT_VALUE;
  586. _pll_misc_chk_default(clk_base, params, 3, default_val,
  587. PLLCX_MISC3_WRITE_MASK);
  588. }
  589. static void tegra210_pllcx_set_defaults(const char *name,
  590. struct tegra_clk_pll *pllcx)
  591. {
  592. pllcx->params->defaults_set = true;
  593. if (readl_relaxed(clk_base + pllcx->params->base_reg) & PLL_ENABLE) {
  594. /* PLL is ON: only check if defaults already set */
  595. pllcx_check_defaults(pllcx->params);
  596. if (!pllcx->params->defaults_set)
  597. pr_warn("%s already enabled. Postponing set full defaults\n",
  598. name);
  599. return;
  600. }
  601. /* Defaults assert PLL reset, and set IDDQ */
  602. writel_relaxed(PLLCX_MISC0_DEFAULT_VALUE,
  603. clk_base + pllcx->params->ext_misc_reg[0]);
  604. writel_relaxed(PLLCX_MISC1_DEFAULT_VALUE,
  605. clk_base + pllcx->params->ext_misc_reg[1]);
  606. writel_relaxed(PLLCX_MISC2_DEFAULT_VALUE,
  607. clk_base + pllcx->params->ext_misc_reg[2]);
  608. writel_relaxed(PLLCX_MISC3_DEFAULT_VALUE,
  609. clk_base + pllcx->params->ext_misc_reg[3]);
  610. udelay(1);
  611. }
  612. static void _pllc_set_defaults(struct tegra_clk_pll *pllcx)
  613. {
  614. tegra210_pllcx_set_defaults("PLL_C", pllcx);
  615. }
  616. static void _pllc2_set_defaults(struct tegra_clk_pll *pllcx)
  617. {
  618. tegra210_pllcx_set_defaults("PLL_C2", pllcx);
  619. }
  620. static void _pllc3_set_defaults(struct tegra_clk_pll *pllcx)
  621. {
  622. tegra210_pllcx_set_defaults("PLL_C3", pllcx);
  623. }
  624. static void _plla1_set_defaults(struct tegra_clk_pll *pllcx)
  625. {
  626. tegra210_pllcx_set_defaults("PLL_A1", pllcx);
  627. }
  628. /*
  629. * PLLA
  630. * PLL with dynamic ramp and fractional SDM. Dynamic ramp is not used.
  631. * Fractional SDM is allowed to provide exact audio rates.
  632. */
  633. static void tegra210_plla_set_defaults(struct tegra_clk_pll *plla)
  634. {
  635. u32 mask;
  636. u32 val = readl_relaxed(clk_base + plla->params->base_reg);
  637. plla->params->defaults_set = true;
  638. if (val & PLL_ENABLE) {
  639. /*
  640. * PLL is ON: check if defaults already set, then set those
  641. * that can be updated in flight.
  642. */
  643. if (val & PLLA_BASE_IDDQ) {
  644. pr_warn("PLL_A boot enabled with IDDQ set\n");
  645. plla->params->defaults_set = false;
  646. }
  647. pr_warn("PLL_A already enabled. Postponing set full defaults\n");
  648. val = PLLA_MISC0_DEFAULT_VALUE; /* ignore lock enable */
  649. mask = PLLA_MISC0_LOCK_ENABLE | PLLA_MISC0_LOCK_OVERRIDE;
  650. _pll_misc_chk_default(clk_base, plla->params, 0, val,
  651. ~mask & PLLA_MISC0_WRITE_MASK);
  652. val = PLLA_MISC2_DEFAULT_VALUE; /* ignore all but control bit */
  653. _pll_misc_chk_default(clk_base, plla->params, 2, val,
  654. PLLA_MISC2_EN_DYNRAMP);
  655. /* Enable lock detect */
  656. val = readl_relaxed(clk_base + plla->params->ext_misc_reg[0]);
  657. val &= ~mask;
  658. val |= PLLA_MISC0_DEFAULT_VALUE & mask;
  659. writel_relaxed(val, clk_base + plla->params->ext_misc_reg[0]);
  660. udelay(1);
  661. return;
  662. }
  663. /* set IDDQ, enable lock detect, disable dynamic ramp and SDM */
  664. val |= PLLA_BASE_IDDQ;
  665. writel_relaxed(val, clk_base + plla->params->base_reg);
  666. writel_relaxed(PLLA_MISC0_DEFAULT_VALUE,
  667. clk_base + plla->params->ext_misc_reg[0]);
  668. writel_relaxed(PLLA_MISC2_DEFAULT_VALUE,
  669. clk_base + plla->params->ext_misc_reg[2]);
  670. udelay(1);
  671. }
  672. /*
  673. * PLLD
  674. * PLL with fractional SDM.
  675. */
  676. static void tegra210_plld_set_defaults(struct tegra_clk_pll *plld)
  677. {
  678. u32 val;
  679. u32 mask = 0xffff;
  680. plld->params->defaults_set = true;
  681. if (readl_relaxed(clk_base + plld->params->base_reg) &
  682. PLL_ENABLE) {
  683. /*
  684. * PLL is ON: check if defaults already set, then set those
  685. * that can be updated in flight.
  686. */
  687. val = PLLD_MISC1_DEFAULT_VALUE;
  688. _pll_misc_chk_default(clk_base, plld->params, 1,
  689. val, PLLD_MISC1_WRITE_MASK);
  690. /* ignore lock, DSI and SDM controls, make sure IDDQ not set */
  691. val = PLLD_MISC0_DEFAULT_VALUE & (~PLLD_MISC0_IDDQ);
  692. mask |= PLLD_MISC0_DSI_CLKENABLE | PLLD_MISC0_LOCK_ENABLE |
  693. PLLD_MISC0_LOCK_OVERRIDE | PLLD_MISC0_EN_SDM;
  694. _pll_misc_chk_default(clk_base, plld->params, 0, val,
  695. ~mask & PLLD_MISC0_WRITE_MASK);
  696. if (!plld->params->defaults_set)
  697. pr_warn("PLL_D already enabled. Postponing set full defaults\n");
  698. /* Enable lock detect */
  699. mask = PLLD_MISC0_LOCK_ENABLE | PLLD_MISC0_LOCK_OVERRIDE;
  700. val = readl_relaxed(clk_base + plld->params->ext_misc_reg[0]);
  701. val &= ~mask;
  702. val |= PLLD_MISC0_DEFAULT_VALUE & mask;
  703. writel_relaxed(val, clk_base + plld->params->ext_misc_reg[0]);
  704. udelay(1);
  705. return;
  706. }
  707. val = readl_relaxed(clk_base + plld->params->ext_misc_reg[0]);
  708. val &= PLLD_MISC0_DSI_CLKENABLE;
  709. val |= PLLD_MISC0_DEFAULT_VALUE;
  710. /* set IDDQ, enable lock detect, disable SDM */
  711. writel_relaxed(val, clk_base + plld->params->ext_misc_reg[0]);
  712. writel_relaxed(PLLD_MISC1_DEFAULT_VALUE, clk_base +
  713. plld->params->ext_misc_reg[1]);
  714. udelay(1);
  715. }
  716. /*
  717. * PLLD2, PLLDP
  718. * PLL with fractional SDM and Spread Spectrum (SDM is a must if SSC is used).
  719. */
  720. static void plldss_defaults(const char *pll_name, struct tegra_clk_pll *plldss,
  721. u32 misc0_val, u32 misc1_val, u32 misc2_val, u32 misc3_val)
  722. {
  723. u32 default_val;
  724. u32 val = readl_relaxed(clk_base + plldss->params->base_reg);
  725. plldss->params->defaults_set = true;
  726. if (val & PLL_ENABLE) {
  727. /*
  728. * PLL is ON: check if defaults already set, then set those
  729. * that can be updated in flight.
  730. */
  731. if (val & PLLDSS_BASE_IDDQ) {
  732. pr_warn("plldss boot enabled with IDDQ set\n");
  733. plldss->params->defaults_set = false;
  734. }
  735. /* ignore lock enable */
  736. default_val = misc0_val;
  737. _pll_misc_chk_default(clk_base, plldss->params, 0, default_val,
  738. PLLDSS_MISC0_WRITE_MASK &
  739. (~PLLDSS_MISC0_LOCK_ENABLE));
  740. /*
  741. * If SSC is used, check all settings, otherwise just confirm
  742. * that SSC is not used on boot as well. Do nothing when using
  743. * this function for PLLC4 that has only MISC0.
  744. */
  745. if (plldss->params->ssc_ctrl_en_mask) {
  746. default_val = misc1_val;
  747. _pll_misc_chk_default(clk_base, plldss->params, 1,
  748. default_val, PLLDSS_MISC1_CFG_WRITE_MASK);
  749. default_val = misc2_val;
  750. _pll_misc_chk_default(clk_base, plldss->params, 2,
  751. default_val, PLLDSS_MISC2_CTRL1_WRITE_MASK);
  752. default_val = misc3_val;
  753. _pll_misc_chk_default(clk_base, plldss->params, 3,
  754. default_val, PLLDSS_MISC3_CTRL2_WRITE_MASK);
  755. } else if (plldss->params->ext_misc_reg[1]) {
  756. default_val = misc1_val;
  757. _pll_misc_chk_default(clk_base, plldss->params, 1,
  758. default_val, PLLDSS_MISC1_CFG_WRITE_MASK &
  759. (~PLLDSS_MISC1_CFG_EN_SDM));
  760. }
  761. if (!plldss->params->defaults_set)
  762. pr_warn("%s already enabled. Postponing set full defaults\n",
  763. pll_name);
  764. /* Enable lock detect */
  765. if (val & PLLDSS_BASE_LOCK_OVERRIDE) {
  766. val &= ~PLLDSS_BASE_LOCK_OVERRIDE;
  767. writel_relaxed(val, clk_base +
  768. plldss->params->base_reg);
  769. }
  770. val = readl_relaxed(clk_base + plldss->params->ext_misc_reg[0]);
  771. val &= ~PLLDSS_MISC0_LOCK_ENABLE;
  772. val |= misc0_val & PLLDSS_MISC0_LOCK_ENABLE;
  773. writel_relaxed(val, clk_base + plldss->params->ext_misc_reg[0]);
  774. udelay(1);
  775. return;
  776. }
  777. /* set IDDQ, enable lock detect, configure SDM/SSC */
  778. val |= PLLDSS_BASE_IDDQ;
  779. val &= ~PLLDSS_BASE_LOCK_OVERRIDE;
  780. writel_relaxed(val, clk_base + plldss->params->base_reg);
  781. /* When using this function for PLLC4 exit here */
  782. if (!plldss->params->ext_misc_reg[1]) {
  783. writel_relaxed(misc0_val, clk_base +
  784. plldss->params->ext_misc_reg[0]);
  785. udelay(1);
  786. return;
  787. }
  788. writel_relaxed(misc0_val, clk_base +
  789. plldss->params->ext_misc_reg[0]);
  790. /* if SSC used set by 1st enable */
  791. writel_relaxed(misc1_val & (~PLLDSS_MISC1_CFG_EN_SSC),
  792. clk_base + plldss->params->ext_misc_reg[1]);
  793. writel_relaxed(misc2_val, clk_base + plldss->params->ext_misc_reg[2]);
  794. writel_relaxed(misc3_val, clk_base + plldss->params->ext_misc_reg[3]);
  795. udelay(1);
  796. }
  797. static void tegra210_plld2_set_defaults(struct tegra_clk_pll *plld2)
  798. {
  799. plldss_defaults("PLL_D2", plld2, PLLD2_MISC0_DEFAULT_VALUE,
  800. PLLD2_MISC1_CFG_DEFAULT_VALUE,
  801. PLLD2_MISC2_CTRL1_DEFAULT_VALUE,
  802. PLLD2_MISC3_CTRL2_DEFAULT_VALUE);
  803. }
  804. static void tegra210_plldp_set_defaults(struct tegra_clk_pll *plldp)
  805. {
  806. plldss_defaults("PLL_DP", plldp, PLLDP_MISC0_DEFAULT_VALUE,
  807. PLLDP_MISC1_CFG_DEFAULT_VALUE,
  808. PLLDP_MISC2_CTRL1_DEFAULT_VALUE,
  809. PLLDP_MISC3_CTRL2_DEFAULT_VALUE);
  810. }
  811. /*
  812. * PLLC4
  813. * Base and misc0 layout is the same as PLLD2/PLLDP, but no SDM/SSC support.
  814. * VCO is exposed to the clock tree via fixed 1/3 and 1/5 dividers.
  815. */
  816. static void tegra210_pllc4_set_defaults(struct tegra_clk_pll *pllc4)
  817. {
  818. plldss_defaults("PLL_C4", pllc4, PLLC4_MISC0_DEFAULT_VALUE, 0, 0, 0);
  819. }
  820. /*
  821. * PLLRE
  822. * VCO is exposed to the clock tree directly along with post-divider output
  823. */
  824. static void tegra210_pllre_set_defaults(struct tegra_clk_pll *pllre)
  825. {
  826. u32 mask;
  827. u32 val = readl_relaxed(clk_base + pllre->params->base_reg);
  828. pllre->params->defaults_set = true;
  829. if (val & PLL_ENABLE) {
  830. pr_warn("PLL_RE already enabled. Postponing set full defaults\n");
  831. /*
  832. * PLL is ON: check if defaults already set, then set those
  833. * that can be updated in flight.
  834. */
  835. val &= PLLRE_BASE_DEFAULT_MASK;
  836. if (val != PLLRE_BASE_DEFAULT_VALUE) {
  837. pr_warn("pllre boot base 0x%x : expected 0x%x\n",
  838. val, PLLRE_BASE_DEFAULT_VALUE);
  839. pr_warn("(comparison mask = 0x%x)\n",
  840. PLLRE_BASE_DEFAULT_MASK);
  841. pllre->params->defaults_set = false;
  842. }
  843. /* Ignore lock enable */
  844. val = PLLRE_MISC0_DEFAULT_VALUE & (~PLLRE_MISC0_IDDQ);
  845. mask = PLLRE_MISC0_LOCK_ENABLE | PLLRE_MISC0_LOCK_OVERRIDE;
  846. _pll_misc_chk_default(clk_base, pllre->params, 0, val,
  847. ~mask & PLLRE_MISC0_WRITE_MASK);
  848. /* Enable lock detect */
  849. val = readl_relaxed(clk_base + pllre->params->ext_misc_reg[0]);
  850. val &= ~mask;
  851. val |= PLLRE_MISC0_DEFAULT_VALUE & mask;
  852. writel_relaxed(val, clk_base + pllre->params->ext_misc_reg[0]);
  853. udelay(1);
  854. return;
  855. }
  856. /* set IDDQ, enable lock detect */
  857. val &= ~PLLRE_BASE_DEFAULT_MASK;
  858. val |= PLLRE_BASE_DEFAULT_VALUE & PLLRE_BASE_DEFAULT_MASK;
  859. writel_relaxed(val, clk_base + pllre->params->base_reg);
  860. writel_relaxed(PLLRE_MISC0_DEFAULT_VALUE,
  861. clk_base + pllre->params->ext_misc_reg[0]);
  862. udelay(1);
  863. }
  864. static void pllx_get_dyn_steps(struct clk_hw *hw, u32 *step_a, u32 *step_b)
  865. {
  866. unsigned long input_rate;
  867. /* cf rate */
  868. if (!IS_ERR_OR_NULL(hw->clk))
  869. input_rate = clk_hw_get_rate(clk_hw_get_parent(hw));
  870. else
  871. input_rate = 38400000;
  872. input_rate /= tegra_pll_get_fixed_mdiv(hw, input_rate);
  873. switch (input_rate) {
  874. case 12000000:
  875. case 12800000:
  876. case 13000000:
  877. *step_a = 0x2B;
  878. *step_b = 0x0B;
  879. return;
  880. case 19200000:
  881. *step_a = 0x12;
  882. *step_b = 0x08;
  883. return;
  884. case 38400000:
  885. *step_a = 0x04;
  886. *step_b = 0x05;
  887. return;
  888. default:
  889. pr_err("%s: Unexpected reference rate %lu\n",
  890. __func__, input_rate);
  891. BUG();
  892. }
  893. }
  894. static void pllx_check_defaults(struct tegra_clk_pll *pll)
  895. {
  896. u32 default_val;
  897. default_val = PLLX_MISC0_DEFAULT_VALUE;
  898. /* ignore lock enable */
  899. _pll_misc_chk_default(clk_base, pll->params, 0, default_val,
  900. PLLX_MISC0_WRITE_MASK & (~PLLX_MISC0_LOCK_ENABLE));
  901. default_val = PLLX_MISC1_DEFAULT_VALUE;
  902. _pll_misc_chk_default(clk_base, pll->params, 1, default_val,
  903. PLLX_MISC1_WRITE_MASK);
  904. /* ignore all but control bit */
  905. default_val = PLLX_MISC2_DEFAULT_VALUE;
  906. _pll_misc_chk_default(clk_base, pll->params, 2,
  907. default_val, PLLX_MISC2_EN_DYNRAMP);
  908. default_val = PLLX_MISC3_DEFAULT_VALUE & (~PLLX_MISC3_IDDQ);
  909. _pll_misc_chk_default(clk_base, pll->params, 3, default_val,
  910. PLLX_MISC3_WRITE_MASK);
  911. default_val = PLLX_MISC4_DEFAULT_VALUE;
  912. _pll_misc_chk_default(clk_base, pll->params, 4, default_val,
  913. PLLX_MISC4_WRITE_MASK);
  914. default_val = PLLX_MISC5_DEFAULT_VALUE;
  915. _pll_misc_chk_default(clk_base, pll->params, 5, default_val,
  916. PLLX_MISC5_WRITE_MASK);
  917. }
  918. static void tegra210_pllx_set_defaults(struct tegra_clk_pll *pllx)
  919. {
  920. u32 val;
  921. u32 step_a, step_b;
  922. pllx->params->defaults_set = true;
  923. /* Get ready dyn ramp state machine settings */
  924. pllx_get_dyn_steps(&pllx->hw, &step_a, &step_b);
  925. val = PLLX_MISC2_DEFAULT_VALUE & (~PLLX_MISC2_DYNRAMP_STEPA_MASK) &
  926. (~PLLX_MISC2_DYNRAMP_STEPB_MASK);
  927. val |= step_a << PLLX_MISC2_DYNRAMP_STEPA_SHIFT;
  928. val |= step_b << PLLX_MISC2_DYNRAMP_STEPB_SHIFT;
  929. if (readl_relaxed(clk_base + pllx->params->base_reg) & PLL_ENABLE) {
  930. /*
  931. * PLL is ON: check if defaults already set, then set those
  932. * that can be updated in flight.
  933. */
  934. pllx_check_defaults(pllx);
  935. if (!pllx->params->defaults_set)
  936. pr_warn("PLL_X already enabled. Postponing set full defaults\n");
  937. /* Configure dyn ramp, disable lock override */
  938. writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]);
  939. /* Enable lock detect */
  940. val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[0]);
  941. val &= ~PLLX_MISC0_LOCK_ENABLE;
  942. val |= PLLX_MISC0_DEFAULT_VALUE & PLLX_MISC0_LOCK_ENABLE;
  943. writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[0]);
  944. udelay(1);
  945. return;
  946. }
  947. /* Enable lock detect and CPU output */
  948. writel_relaxed(PLLX_MISC0_DEFAULT_VALUE, clk_base +
  949. pllx->params->ext_misc_reg[0]);
  950. /* Setup */
  951. writel_relaxed(PLLX_MISC1_DEFAULT_VALUE, clk_base +
  952. pllx->params->ext_misc_reg[1]);
  953. /* Configure dyn ramp state machine, disable lock override */
  954. writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]);
  955. /* Set IDDQ */
  956. writel_relaxed(PLLX_MISC3_DEFAULT_VALUE, clk_base +
  957. pllx->params->ext_misc_reg[3]);
  958. /* Disable SDM */
  959. writel_relaxed(PLLX_MISC4_DEFAULT_VALUE, clk_base +
  960. pllx->params->ext_misc_reg[4]);
  961. writel_relaxed(PLLX_MISC5_DEFAULT_VALUE, clk_base +
  962. pllx->params->ext_misc_reg[5]);
  963. udelay(1);
  964. }
  965. /* PLLMB */
  966. static void tegra210_pllmb_set_defaults(struct tegra_clk_pll *pllmb)
  967. {
  968. u32 mask, val = readl_relaxed(clk_base + pllmb->params->base_reg);
  969. pllmb->params->defaults_set = true;
  970. if (val & PLL_ENABLE) {
  971. /*
  972. * PLL is ON: check if defaults already set, then set those
  973. * that can be updated in flight.
  974. */
  975. val = PLLMB_MISC1_DEFAULT_VALUE & (~PLLMB_MISC1_IDDQ);
  976. mask = PLLMB_MISC1_LOCK_ENABLE | PLLMB_MISC1_LOCK_OVERRIDE;
  977. _pll_misc_chk_default(clk_base, pllmb->params, 0, val,
  978. ~mask & PLLMB_MISC1_WRITE_MASK);
  979. if (!pllmb->params->defaults_set)
  980. pr_warn("PLL_MB already enabled. Postponing set full defaults\n");
  981. /* Enable lock detect */
  982. val = readl_relaxed(clk_base + pllmb->params->ext_misc_reg[0]);
  983. val &= ~mask;
  984. val |= PLLMB_MISC1_DEFAULT_VALUE & mask;
  985. writel_relaxed(val, clk_base + pllmb->params->ext_misc_reg[0]);
  986. udelay(1);
  987. return;
  988. }
  989. /* set IDDQ, enable lock detect */
  990. writel_relaxed(PLLMB_MISC1_DEFAULT_VALUE,
  991. clk_base + pllmb->params->ext_misc_reg[0]);
  992. udelay(1);
  993. }
  994. /*
  995. * PLLP
  996. * VCO is exposed to the clock tree directly along with post-divider output.
  997. * Both VCO and post-divider output rates are fixed at 408MHz and 204MHz,
  998. * respectively.
  999. */
  1000. static void pllp_check_defaults(struct tegra_clk_pll *pll, bool enabled)
  1001. {
  1002. u32 val, mask;
  1003. /* Ignore lock enable (will be set), make sure not in IDDQ if enabled */
  1004. val = PLLP_MISC0_DEFAULT_VALUE & (~PLLP_MISC0_IDDQ);
  1005. mask = PLLP_MISC0_LOCK_ENABLE | PLLP_MISC0_LOCK_OVERRIDE;
  1006. if (!enabled)
  1007. mask |= PLLP_MISC0_IDDQ;
  1008. _pll_misc_chk_default(clk_base, pll->params, 0, val,
  1009. ~mask & PLLP_MISC0_WRITE_MASK);
  1010. /* Ignore branch controls */
  1011. val = PLLP_MISC1_DEFAULT_VALUE;
  1012. mask = PLLP_MISC1_HSIO_EN | PLLP_MISC1_XUSB_EN;
  1013. _pll_misc_chk_default(clk_base, pll->params, 1, val,
  1014. ~mask & PLLP_MISC1_WRITE_MASK);
  1015. }
  1016. static void tegra210_pllp_set_defaults(struct tegra_clk_pll *pllp)
  1017. {
  1018. u32 mask;
  1019. u32 val = readl_relaxed(clk_base + pllp->params->base_reg);
  1020. pllp->params->defaults_set = true;
  1021. if (val & PLL_ENABLE) {
  1022. /*
  1023. * PLL is ON: check if defaults already set, then set those
  1024. * that can be updated in flight.
  1025. */
  1026. pllp_check_defaults(pllp, true);
  1027. if (!pllp->params->defaults_set)
  1028. pr_warn("PLL_P already enabled. Postponing set full defaults\n");
  1029. /* Enable lock detect */
  1030. val = readl_relaxed(clk_base + pllp->params->ext_misc_reg[0]);
  1031. mask = PLLP_MISC0_LOCK_ENABLE | PLLP_MISC0_LOCK_OVERRIDE;
  1032. val &= ~mask;
  1033. val |= PLLP_MISC0_DEFAULT_VALUE & mask;
  1034. writel_relaxed(val, clk_base + pllp->params->ext_misc_reg[0]);
  1035. udelay(1);
  1036. return;
  1037. }
  1038. /* set IDDQ, enable lock detect */
  1039. writel_relaxed(PLLP_MISC0_DEFAULT_VALUE,
  1040. clk_base + pllp->params->ext_misc_reg[0]);
  1041. /* Preserve branch control */
  1042. val = readl_relaxed(clk_base + pllp->params->ext_misc_reg[1]);
  1043. mask = PLLP_MISC1_HSIO_EN | PLLP_MISC1_XUSB_EN;
  1044. val &= mask;
  1045. val |= ~mask & PLLP_MISC1_DEFAULT_VALUE;
  1046. writel_relaxed(val, clk_base + pllp->params->ext_misc_reg[1]);
  1047. udelay(1);
  1048. }
  1049. /*
  1050. * PLLU
  1051. * VCO is exposed to the clock tree directly along with post-divider output.
  1052. * Both VCO and post-divider output rates are fixed at 480MHz and 240MHz,
  1053. * respectively.
  1054. */
  1055. static void pllu_check_defaults(struct tegra_clk_pll_params *params,
  1056. bool hw_control)
  1057. {
  1058. u32 val, mask;
  1059. /* Ignore lock enable (will be set) and IDDQ if under h/w control */
  1060. val = PLLU_MISC0_DEFAULT_VALUE & (~PLLU_MISC0_IDDQ);
  1061. mask = PLLU_MISC0_LOCK_ENABLE | (hw_control ? PLLU_MISC0_IDDQ : 0);
  1062. _pll_misc_chk_default(clk_base, params, 0, val,
  1063. ~mask & PLLU_MISC0_WRITE_MASK);
  1064. val = PLLU_MISC1_DEFAULT_VALUE;
  1065. mask = PLLU_MISC1_LOCK_OVERRIDE;
  1066. _pll_misc_chk_default(clk_base, params, 1, val,
  1067. ~mask & PLLU_MISC1_WRITE_MASK);
  1068. }
  1069. static void tegra210_pllu_set_defaults(struct tegra_clk_pll_params *pllu)
  1070. {
  1071. u32 val = readl_relaxed(clk_base + pllu->base_reg);
  1072. pllu->defaults_set = true;
  1073. if (val & PLL_ENABLE) {
  1074. /*
  1075. * PLL is ON: check if defaults already set, then set those
  1076. * that can be updated in flight.
  1077. */
  1078. pllu_check_defaults(pllu, false);
  1079. if (!pllu->defaults_set)
  1080. pr_warn("PLL_U already enabled. Postponing set full defaults\n");
  1081. /* Enable lock detect */
  1082. val = readl_relaxed(clk_base + pllu->ext_misc_reg[0]);
  1083. val &= ~PLLU_MISC0_LOCK_ENABLE;
  1084. val |= PLLU_MISC0_DEFAULT_VALUE & PLLU_MISC0_LOCK_ENABLE;
  1085. writel_relaxed(val, clk_base + pllu->ext_misc_reg[0]);
  1086. val = readl_relaxed(clk_base + pllu->ext_misc_reg[1]);
  1087. val &= ~PLLU_MISC1_LOCK_OVERRIDE;
  1088. val |= PLLU_MISC1_DEFAULT_VALUE & PLLU_MISC1_LOCK_OVERRIDE;
  1089. writel_relaxed(val, clk_base + pllu->ext_misc_reg[1]);
  1090. udelay(1);
  1091. return;
  1092. }
  1093. /* set IDDQ, enable lock detect */
  1094. writel_relaxed(PLLU_MISC0_DEFAULT_VALUE,
  1095. clk_base + pllu->ext_misc_reg[0]);
  1096. writel_relaxed(PLLU_MISC1_DEFAULT_VALUE,
  1097. clk_base + pllu->ext_misc_reg[1]);
  1098. udelay(1);
  1099. }
  1100. #define mask(w) ((1 << (w)) - 1)
  1101. #define divm_mask(p) mask(p->params->div_nmp->divm_width)
  1102. #define divn_mask(p) mask(p->params->div_nmp->divn_width)
  1103. #define divp_mask(p) (p->params->flags & TEGRA_PLLU ? PLLU_POST_DIVP_MASK :\
  1104. mask(p->params->div_nmp->divp_width))
  1105. #define divm_shift(p) ((p)->params->div_nmp->divm_shift)
  1106. #define divn_shift(p) ((p)->params->div_nmp->divn_shift)
  1107. #define divp_shift(p) ((p)->params->div_nmp->divp_shift)
  1108. #define divm_mask_shifted(p) (divm_mask(p) << divm_shift(p))
  1109. #define divn_mask_shifted(p) (divn_mask(p) << divn_shift(p))
  1110. #define divp_mask_shifted(p) (divp_mask(p) << divp_shift(p))
  1111. #define PLL_LOCKDET_DELAY 2 /* Lock detection safety delays */
  1112. static int tegra210_wait_for_mask(struct tegra_clk_pll *pll,
  1113. u32 reg, u32 mask)
  1114. {
  1115. int i;
  1116. u32 val = 0;
  1117. for (i = 0; i < pll->params->lock_delay / PLL_LOCKDET_DELAY + 1; i++) {
  1118. udelay(PLL_LOCKDET_DELAY);
  1119. val = readl_relaxed(clk_base + reg);
  1120. if ((val & mask) == mask) {
  1121. udelay(PLL_LOCKDET_DELAY);
  1122. return 0;
  1123. }
  1124. }
  1125. return -ETIMEDOUT;
  1126. }
  1127. static int tegra210_pllx_dyn_ramp(struct tegra_clk_pll *pllx,
  1128. struct tegra_clk_pll_freq_table *cfg)
  1129. {
  1130. u32 val, base, ndiv_new_mask;
  1131. ndiv_new_mask = (divn_mask(pllx) >> pllx->params->div_nmp->divn_shift)
  1132. << PLLX_MISC2_NDIV_NEW_SHIFT;
  1133. val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[2]);
  1134. val &= (~ndiv_new_mask);
  1135. val |= cfg->n << PLLX_MISC2_NDIV_NEW_SHIFT;
  1136. writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]);
  1137. udelay(1);
  1138. val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[2]);
  1139. val |= PLLX_MISC2_EN_DYNRAMP;
  1140. writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]);
  1141. udelay(1);
  1142. tegra210_wait_for_mask(pllx, pllx->params->ext_misc_reg[2],
  1143. PLLX_MISC2_DYNRAMP_DONE);
  1144. base = readl_relaxed(clk_base + pllx->params->base_reg) &
  1145. (~divn_mask_shifted(pllx));
  1146. base |= cfg->n << pllx->params->div_nmp->divn_shift;
  1147. writel_relaxed(base, clk_base + pllx->params->base_reg);
  1148. udelay(1);
  1149. val &= ~PLLX_MISC2_EN_DYNRAMP;
  1150. writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]);
  1151. udelay(1);
  1152. pr_debug("%s: dynamic ramp to m = %u n = %u p = %u, Fout = %lu kHz\n",
  1153. __clk_get_name(pllx->hw.clk), cfg->m, cfg->n, cfg->p,
  1154. cfg->input_rate / cfg->m * cfg->n /
  1155. pllx->params->pdiv_tohw[cfg->p].pdiv / 1000);
  1156. return 0;
  1157. }
  1158. /*
  1159. * Common configuration for PLLs with fixed input divider policy:
  1160. * - always set fixed M-value based on the reference rate
  1161. * - always set P-value value 1:1 for output rates above VCO minimum, and
  1162. * choose minimum necessary P-value for output rates below VCO maximum
  1163. * - calculate N-value based on selected M and P
  1164. * - calculate SDM_DIN fractional part
  1165. */
  1166. static int tegra210_pll_fixed_mdiv_cfg(struct clk_hw *hw,
  1167. struct tegra_clk_pll_freq_table *cfg,
  1168. unsigned long rate, unsigned long input_rate)
  1169. {
  1170. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1171. struct tegra_clk_pll_params *params = pll->params;
  1172. int p;
  1173. unsigned long cf, p_rate;
  1174. u32 pdiv;
  1175. if (!rate)
  1176. return -EINVAL;
  1177. if (!(params->flags & TEGRA_PLL_VCO_OUT)) {
  1178. p = DIV_ROUND_UP(params->vco_min, rate);
  1179. p = params->round_p_to_pdiv(p, &pdiv);
  1180. } else {
  1181. p = rate >= params->vco_min ? 1 : -EINVAL;
  1182. }
  1183. if (p < 0)
  1184. return -EINVAL;
  1185. cfg->m = tegra_pll_get_fixed_mdiv(hw, input_rate);
  1186. cfg->p = p;
  1187. /* Store P as HW value, as that is what is expected */
  1188. cfg->p = tegra_pll_p_div_to_hw(pll, cfg->p);
  1189. p_rate = rate * p;
  1190. if (p_rate > params->vco_max)
  1191. p_rate = params->vco_max;
  1192. cf = input_rate / cfg->m;
  1193. cfg->n = p_rate / cf;
  1194. cfg->sdm_data = 0;
  1195. cfg->output_rate = input_rate;
  1196. if (params->sdm_ctrl_reg) {
  1197. unsigned long rem = p_rate - cf * cfg->n;
  1198. /* If ssc is enabled SDM enabled as well, even for integer n */
  1199. if (rem || params->ssc_ctrl_reg) {
  1200. u64 s = rem * PLL_SDM_COEFF;
  1201. do_div(s, cf);
  1202. s -= PLL_SDM_COEFF / 2;
  1203. cfg->sdm_data = sdin_din_to_data(s);
  1204. }
  1205. cfg->output_rate *= sdin_get_n_eff(cfg);
  1206. cfg->output_rate /= p * cfg->m * PLL_SDM_COEFF;
  1207. } else {
  1208. cfg->output_rate *= cfg->n;
  1209. cfg->output_rate /= p * cfg->m;
  1210. }
  1211. cfg->input_rate = input_rate;
  1212. return 0;
  1213. }
  1214. /*
  1215. * clk_pll_set_gain - set gain to m, n to calculate correct VCO rate
  1216. *
  1217. * @cfg: struct tegra_clk_pll_freq_table * cfg
  1218. *
  1219. * For Normal mode:
  1220. * Fvco = Fref * NDIV / MDIV
  1221. *
  1222. * For fractional mode:
  1223. * Fvco = Fref * (NDIV + 0.5 + SDM_DIN / PLL_SDM_COEFF) / MDIV
  1224. */
  1225. static void tegra210_clk_pll_set_gain(struct tegra_clk_pll_freq_table *cfg)
  1226. {
  1227. cfg->n = sdin_get_n_eff(cfg);
  1228. cfg->m *= PLL_SDM_COEFF;
  1229. }
  1230. static unsigned long
  1231. tegra210_clk_adjust_vco_min(struct tegra_clk_pll_params *params,
  1232. unsigned long parent_rate)
  1233. {
  1234. unsigned long vco_min = params->vco_min;
  1235. params->vco_min += DIV_ROUND_UP(parent_rate, PLL_SDM_COEFF);
  1236. vco_min = min(vco_min, params->vco_min);
  1237. return vco_min;
  1238. }
  1239. static struct div_nmp pllx_nmp = {
  1240. .divm_shift = 0,
  1241. .divm_width = 8,
  1242. .divn_shift = 8,
  1243. .divn_width = 8,
  1244. .divp_shift = 20,
  1245. .divp_width = 5,
  1246. };
  1247. /*
  1248. * PLL post divider maps - two types: quasi-linear and exponential
  1249. * post divider.
  1250. */
  1251. #define PLL_QLIN_PDIV_MAX 16
  1252. static const struct pdiv_map pll_qlin_pdiv_to_hw[] = {
  1253. { .pdiv = 1, .hw_val = 0 },
  1254. { .pdiv = 2, .hw_val = 1 },
  1255. { .pdiv = 3, .hw_val = 2 },
  1256. { .pdiv = 4, .hw_val = 3 },
  1257. { .pdiv = 5, .hw_val = 4 },
  1258. { .pdiv = 6, .hw_val = 5 },
  1259. { .pdiv = 8, .hw_val = 6 },
  1260. { .pdiv = 9, .hw_val = 7 },
  1261. { .pdiv = 10, .hw_val = 8 },
  1262. { .pdiv = 12, .hw_val = 9 },
  1263. { .pdiv = 15, .hw_val = 10 },
  1264. { .pdiv = 16, .hw_val = 11 },
  1265. { .pdiv = 18, .hw_val = 12 },
  1266. { .pdiv = 20, .hw_val = 13 },
  1267. { .pdiv = 24, .hw_val = 14 },
  1268. { .pdiv = 30, .hw_val = 15 },
  1269. { .pdiv = 32, .hw_val = 16 },
  1270. };
  1271. static u32 pll_qlin_p_to_pdiv(u32 p, u32 *pdiv)
  1272. {
  1273. int i;
  1274. if (p) {
  1275. for (i = 0; i <= PLL_QLIN_PDIV_MAX; i++) {
  1276. if (p <= pll_qlin_pdiv_to_hw[i].pdiv) {
  1277. if (pdiv)
  1278. *pdiv = i;
  1279. return pll_qlin_pdiv_to_hw[i].pdiv;
  1280. }
  1281. }
  1282. }
  1283. return -EINVAL;
  1284. }
  1285. #define PLL_EXPO_PDIV_MAX 7
  1286. static const struct pdiv_map pll_expo_pdiv_to_hw[] = {
  1287. { .pdiv = 1, .hw_val = 0 },
  1288. { .pdiv = 2, .hw_val = 1 },
  1289. { .pdiv = 4, .hw_val = 2 },
  1290. { .pdiv = 8, .hw_val = 3 },
  1291. { .pdiv = 16, .hw_val = 4 },
  1292. { .pdiv = 32, .hw_val = 5 },
  1293. { .pdiv = 64, .hw_val = 6 },
  1294. { .pdiv = 128, .hw_val = 7 },
  1295. };
  1296. static u32 pll_expo_p_to_pdiv(u32 p, u32 *pdiv)
  1297. {
  1298. if (p) {
  1299. u32 i = fls(p);
  1300. if (i == ffs(p))
  1301. i--;
  1302. if (i <= PLL_EXPO_PDIV_MAX) {
  1303. if (pdiv)
  1304. *pdiv = i;
  1305. return 1 << i;
  1306. }
  1307. }
  1308. return -EINVAL;
  1309. }
  1310. static struct tegra_clk_pll_freq_table pll_x_freq_table[] = {
  1311. /* 1 GHz */
  1312. { 12000000, 1000000000, 166, 1, 2, 0 }, /* actual: 996.0 MHz */
  1313. { 13000000, 1000000000, 153, 1, 2, 0 }, /* actual: 994.0 MHz */
  1314. { 38400000, 1000000000, 156, 3, 2, 0 }, /* actual: 998.4 MHz */
  1315. { 0, 0, 0, 0, 0, 0 },
  1316. };
  1317. static struct tegra_clk_pll_params pll_x_params = {
  1318. .input_min = 12000000,
  1319. .input_max = 800000000,
  1320. .cf_min = 12000000,
  1321. .cf_max = 38400000,
  1322. .vco_min = 1350000000,
  1323. .vco_max = 3000000000UL,
  1324. .base_reg = PLLX_BASE,
  1325. .misc_reg = PLLX_MISC0,
  1326. .lock_mask = PLL_BASE_LOCK,
  1327. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  1328. .lock_delay = 300,
  1329. .ext_misc_reg[0] = PLLX_MISC0,
  1330. .ext_misc_reg[1] = PLLX_MISC1,
  1331. .ext_misc_reg[2] = PLLX_MISC2,
  1332. .ext_misc_reg[3] = PLLX_MISC3,
  1333. .ext_misc_reg[4] = PLLX_MISC4,
  1334. .ext_misc_reg[5] = PLLX_MISC5,
  1335. .iddq_reg = PLLX_MISC3,
  1336. .iddq_bit_idx = PLLXP_IDDQ_BIT,
  1337. .max_p = PLL_QLIN_PDIV_MAX,
  1338. .mdiv_default = 2,
  1339. .dyn_ramp_reg = PLLX_MISC2,
  1340. .stepa_shift = 16,
  1341. .stepb_shift = 24,
  1342. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1343. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1344. .div_nmp = &pllx_nmp,
  1345. .freq_table = pll_x_freq_table,
  1346. .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE,
  1347. .dyn_ramp = tegra210_pllx_dyn_ramp,
  1348. .set_defaults = tegra210_pllx_set_defaults,
  1349. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1350. };
  1351. static struct div_nmp pllc_nmp = {
  1352. .divm_shift = 0,
  1353. .divm_width = 8,
  1354. .divn_shift = 10,
  1355. .divn_width = 8,
  1356. .divp_shift = 20,
  1357. .divp_width = 5,
  1358. };
  1359. static struct tegra_clk_pll_freq_table pll_cx_freq_table[] = {
  1360. { 12000000, 510000000, 85, 1, 2, 0 },
  1361. { 13000000, 510000000, 78, 1, 2, 0 }, /* actual: 507.0 MHz */
  1362. { 38400000, 510000000, 79, 3, 2, 0 }, /* actual: 505.6 MHz */
  1363. { 0, 0, 0, 0, 0, 0 },
  1364. };
  1365. static struct tegra_clk_pll_params pll_c_params = {
  1366. .input_min = 12000000,
  1367. .input_max = 700000000,
  1368. .cf_min = 12000000,
  1369. .cf_max = 50000000,
  1370. .vco_min = 600000000,
  1371. .vco_max = 1200000000,
  1372. .base_reg = PLLC_BASE,
  1373. .misc_reg = PLLC_MISC0,
  1374. .lock_mask = PLL_BASE_LOCK,
  1375. .lock_delay = 300,
  1376. .iddq_reg = PLLC_MISC1,
  1377. .iddq_bit_idx = PLLCX_IDDQ_BIT,
  1378. .reset_reg = PLLC_MISC0,
  1379. .reset_bit_idx = PLLCX_RESET_BIT,
  1380. .max_p = PLL_QLIN_PDIV_MAX,
  1381. .ext_misc_reg[0] = PLLC_MISC0,
  1382. .ext_misc_reg[1] = PLLC_MISC1,
  1383. .ext_misc_reg[2] = PLLC_MISC2,
  1384. .ext_misc_reg[3] = PLLC_MISC3,
  1385. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1386. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1387. .mdiv_default = 3,
  1388. .div_nmp = &pllc_nmp,
  1389. .freq_table = pll_cx_freq_table,
  1390. .flags = TEGRA_PLL_USE_LOCK,
  1391. .set_defaults = _pllc_set_defaults,
  1392. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1393. };
  1394. static struct div_nmp pllcx_nmp = {
  1395. .divm_shift = 0,
  1396. .divm_width = 8,
  1397. .divn_shift = 10,
  1398. .divn_width = 8,
  1399. .divp_shift = 20,
  1400. .divp_width = 5,
  1401. };
  1402. static struct tegra_clk_pll_params pll_c2_params = {
  1403. .input_min = 12000000,
  1404. .input_max = 700000000,
  1405. .cf_min = 12000000,
  1406. .cf_max = 50000000,
  1407. .vco_min = 600000000,
  1408. .vco_max = 1200000000,
  1409. .base_reg = PLLC2_BASE,
  1410. .misc_reg = PLLC2_MISC0,
  1411. .iddq_reg = PLLC2_MISC1,
  1412. .iddq_bit_idx = PLLCX_IDDQ_BIT,
  1413. .reset_reg = PLLC2_MISC0,
  1414. .reset_bit_idx = PLLCX_RESET_BIT,
  1415. .lock_mask = PLLCX_BASE_LOCK,
  1416. .lock_delay = 300,
  1417. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1418. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1419. .mdiv_default = 3,
  1420. .div_nmp = &pllcx_nmp,
  1421. .max_p = PLL_QLIN_PDIV_MAX,
  1422. .ext_misc_reg[0] = PLLC2_MISC0,
  1423. .ext_misc_reg[1] = PLLC2_MISC1,
  1424. .ext_misc_reg[2] = PLLC2_MISC2,
  1425. .ext_misc_reg[3] = PLLC2_MISC3,
  1426. .freq_table = pll_cx_freq_table,
  1427. .flags = TEGRA_PLL_USE_LOCK,
  1428. .set_defaults = _pllc2_set_defaults,
  1429. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1430. };
  1431. static struct tegra_clk_pll_params pll_c3_params = {
  1432. .input_min = 12000000,
  1433. .input_max = 700000000,
  1434. .cf_min = 12000000,
  1435. .cf_max = 50000000,
  1436. .vco_min = 600000000,
  1437. .vco_max = 1200000000,
  1438. .base_reg = PLLC3_BASE,
  1439. .misc_reg = PLLC3_MISC0,
  1440. .lock_mask = PLLCX_BASE_LOCK,
  1441. .lock_delay = 300,
  1442. .iddq_reg = PLLC3_MISC1,
  1443. .iddq_bit_idx = PLLCX_IDDQ_BIT,
  1444. .reset_reg = PLLC3_MISC0,
  1445. .reset_bit_idx = PLLCX_RESET_BIT,
  1446. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1447. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1448. .mdiv_default = 3,
  1449. .div_nmp = &pllcx_nmp,
  1450. .max_p = PLL_QLIN_PDIV_MAX,
  1451. .ext_misc_reg[0] = PLLC3_MISC0,
  1452. .ext_misc_reg[1] = PLLC3_MISC1,
  1453. .ext_misc_reg[2] = PLLC3_MISC2,
  1454. .ext_misc_reg[3] = PLLC3_MISC3,
  1455. .freq_table = pll_cx_freq_table,
  1456. .flags = TEGRA_PLL_USE_LOCK,
  1457. .set_defaults = _pllc3_set_defaults,
  1458. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1459. };
  1460. static struct div_nmp pllss_nmp = {
  1461. .divm_shift = 0,
  1462. .divm_width = 8,
  1463. .divn_shift = 8,
  1464. .divn_width = 8,
  1465. .divp_shift = 19,
  1466. .divp_width = 5,
  1467. };
  1468. static struct tegra_clk_pll_freq_table pll_c4_vco_freq_table[] = {
  1469. { 12000000, 600000000, 50, 1, 1, 0 },
  1470. { 13000000, 600000000, 46, 1, 1, 0 }, /* actual: 598.0 MHz */
  1471. { 38400000, 600000000, 62, 4, 1, 0 }, /* actual: 595.2 MHz */
  1472. { 0, 0, 0, 0, 0, 0 },
  1473. };
  1474. static const struct clk_div_table pll_vco_post_div_table[] = {
  1475. { .val = 0, .div = 1 },
  1476. { .val = 1, .div = 2 },
  1477. { .val = 2, .div = 3 },
  1478. { .val = 3, .div = 4 },
  1479. { .val = 4, .div = 5 },
  1480. { .val = 5, .div = 6 },
  1481. { .val = 6, .div = 8 },
  1482. { .val = 7, .div = 10 },
  1483. { .val = 8, .div = 12 },
  1484. { .val = 9, .div = 16 },
  1485. { .val = 10, .div = 12 },
  1486. { .val = 11, .div = 16 },
  1487. { .val = 12, .div = 20 },
  1488. { .val = 13, .div = 24 },
  1489. { .val = 14, .div = 32 },
  1490. { .val = 0, .div = 0 },
  1491. };
  1492. static struct tegra_clk_pll_params pll_c4_vco_params = {
  1493. .input_min = 9600000,
  1494. .input_max = 800000000,
  1495. .cf_min = 9600000,
  1496. .cf_max = 19200000,
  1497. .vco_min = 500000000,
  1498. .vco_max = 1080000000,
  1499. .base_reg = PLLC4_BASE,
  1500. .misc_reg = PLLC4_MISC0,
  1501. .lock_mask = PLL_BASE_LOCK,
  1502. .lock_delay = 300,
  1503. .max_p = PLL_QLIN_PDIV_MAX,
  1504. .ext_misc_reg[0] = PLLC4_MISC0,
  1505. .iddq_reg = PLLC4_BASE,
  1506. .iddq_bit_idx = PLLSS_IDDQ_BIT,
  1507. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1508. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1509. .mdiv_default = 3,
  1510. .div_nmp = &pllss_nmp,
  1511. .freq_table = pll_c4_vco_freq_table,
  1512. .set_defaults = tegra210_pllc4_set_defaults,
  1513. .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT,
  1514. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1515. };
  1516. static struct tegra_clk_pll_freq_table pll_m_freq_table[] = {
  1517. { 12000000, 800000000, 66, 1, 1, 0 }, /* actual: 792.0 MHz */
  1518. { 13000000, 800000000, 61, 1, 1, 0 }, /* actual: 793.0 MHz */
  1519. { 38400000, 297600000, 93, 4, 3, 0 },
  1520. { 38400000, 400000000, 125, 4, 3, 0 },
  1521. { 38400000, 532800000, 111, 4, 2, 0 },
  1522. { 38400000, 665600000, 104, 3, 2, 0 },
  1523. { 38400000, 800000000, 125, 3, 2, 0 },
  1524. { 38400000, 931200000, 97, 4, 1, 0 },
  1525. { 38400000, 1065600000, 111, 4, 1, 0 },
  1526. { 38400000, 1200000000, 125, 4, 1, 0 },
  1527. { 38400000, 1331200000, 104, 3, 1, 0 },
  1528. { 38400000, 1459200000, 76, 2, 1, 0 },
  1529. { 38400000, 1600000000, 125, 3, 1, 0 },
  1530. { 0, 0, 0, 0, 0, 0 },
  1531. };
  1532. static struct div_nmp pllm_nmp = {
  1533. .divm_shift = 0,
  1534. .divm_width = 8,
  1535. .override_divm_shift = 0,
  1536. .divn_shift = 8,
  1537. .divn_width = 8,
  1538. .override_divn_shift = 8,
  1539. .divp_shift = 20,
  1540. .divp_width = 5,
  1541. .override_divp_shift = 27,
  1542. };
  1543. static struct tegra_clk_pll_params pll_m_params = {
  1544. .input_min = 9600000,
  1545. .input_max = 500000000,
  1546. .cf_min = 9600000,
  1547. .cf_max = 19200000,
  1548. .vco_min = 800000000,
  1549. .vco_max = 1866000000,
  1550. .base_reg = PLLM_BASE,
  1551. .misc_reg = PLLM_MISC2,
  1552. .lock_mask = PLL_BASE_LOCK,
  1553. .lock_enable_bit_idx = PLLM_MISC_LOCK_ENABLE,
  1554. .lock_delay = 300,
  1555. .iddq_reg = PLLM_MISC2,
  1556. .iddq_bit_idx = PLLM_IDDQ_BIT,
  1557. .max_p = PLL_QLIN_PDIV_MAX,
  1558. .ext_misc_reg[0] = PLLM_MISC2,
  1559. .ext_misc_reg[1] = PLLM_MISC1,
  1560. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1561. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1562. .div_nmp = &pllm_nmp,
  1563. .pmc_divnm_reg = PMC_PLLM_WB0_OVERRIDE,
  1564. .pmc_divp_reg = PMC_PLLM_WB0_OVERRIDE_2,
  1565. .freq_table = pll_m_freq_table,
  1566. .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE,
  1567. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1568. };
  1569. static struct tegra_clk_pll_params pll_mb_params = {
  1570. .input_min = 9600000,
  1571. .input_max = 500000000,
  1572. .cf_min = 9600000,
  1573. .cf_max = 19200000,
  1574. .vco_min = 800000000,
  1575. .vco_max = 1866000000,
  1576. .base_reg = PLLMB_BASE,
  1577. .misc_reg = PLLMB_MISC1,
  1578. .lock_mask = PLL_BASE_LOCK,
  1579. .lock_delay = 300,
  1580. .iddq_reg = PLLMB_MISC1,
  1581. .iddq_bit_idx = PLLMB_IDDQ_BIT,
  1582. .max_p = PLL_QLIN_PDIV_MAX,
  1583. .ext_misc_reg[0] = PLLMB_MISC1,
  1584. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1585. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1586. .div_nmp = &pllm_nmp,
  1587. .freq_table = pll_m_freq_table,
  1588. .flags = TEGRA_PLL_USE_LOCK,
  1589. .set_defaults = tegra210_pllmb_set_defaults,
  1590. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1591. };
  1592. static struct tegra_clk_pll_freq_table pll_e_freq_table[] = {
  1593. /* PLLE special case: use cpcon field to store cml divider value */
  1594. { 672000000, 100000000, 125, 42, 0, 13 },
  1595. { 624000000, 100000000, 125, 39, 0, 13 },
  1596. { 336000000, 100000000, 125, 21, 0, 13 },
  1597. { 312000000, 100000000, 200, 26, 0, 14 },
  1598. { 38400000, 100000000, 125, 2, 0, 14 },
  1599. { 12000000, 100000000, 200, 1, 0, 14 },
  1600. { 0, 0, 0, 0, 0, 0 },
  1601. };
  1602. static struct div_nmp plle_nmp = {
  1603. .divm_shift = 0,
  1604. .divm_width = 8,
  1605. .divn_shift = 8,
  1606. .divn_width = 8,
  1607. .divp_shift = 24,
  1608. .divp_width = 5,
  1609. };
  1610. static struct tegra_clk_pll_params pll_e_params = {
  1611. .input_min = 12000000,
  1612. .input_max = 800000000,
  1613. .cf_min = 12000000,
  1614. .cf_max = 38400000,
  1615. .vco_min = 1600000000,
  1616. .vco_max = 2500000000U,
  1617. .base_reg = PLLE_BASE,
  1618. .misc_reg = PLLE_MISC0,
  1619. .aux_reg = PLLE_AUX,
  1620. .lock_mask = PLLE_MISC_LOCK,
  1621. .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE,
  1622. .lock_delay = 300,
  1623. .div_nmp = &plle_nmp,
  1624. .freq_table = pll_e_freq_table,
  1625. .flags = TEGRA_PLL_FIXED | TEGRA_PLL_LOCK_MISC | TEGRA_PLL_USE_LOCK |
  1626. TEGRA_PLL_HAS_LOCK_ENABLE,
  1627. .fixed_rate = 100000000,
  1628. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1629. };
  1630. static struct tegra_clk_pll_freq_table pll_re_vco_freq_table[] = {
  1631. { 12000000, 672000000, 56, 1, 1, 0 },
  1632. { 13000000, 672000000, 51, 1, 1, 0 }, /* actual: 663.0 MHz */
  1633. { 38400000, 672000000, 70, 4, 1, 0 },
  1634. { 0, 0, 0, 0, 0, 0 },
  1635. };
  1636. static struct div_nmp pllre_nmp = {
  1637. .divm_shift = 0,
  1638. .divm_width = 8,
  1639. .divn_shift = 8,
  1640. .divn_width = 8,
  1641. .divp_shift = 16,
  1642. .divp_width = 5,
  1643. };
  1644. static struct tegra_clk_pll_params pll_re_vco_params = {
  1645. .input_min = 9600000,
  1646. .input_max = 800000000,
  1647. .cf_min = 9600000,
  1648. .cf_max = 19200000,
  1649. .vco_min = 350000000,
  1650. .vco_max = 700000000,
  1651. .base_reg = PLLRE_BASE,
  1652. .misc_reg = PLLRE_MISC0,
  1653. .lock_mask = PLLRE_MISC_LOCK,
  1654. .lock_delay = 300,
  1655. .max_p = PLL_QLIN_PDIV_MAX,
  1656. .ext_misc_reg[0] = PLLRE_MISC0,
  1657. .iddq_reg = PLLRE_MISC0,
  1658. .iddq_bit_idx = PLLRE_IDDQ_BIT,
  1659. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1660. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1661. .div_nmp = &pllre_nmp,
  1662. .freq_table = pll_re_vco_freq_table,
  1663. .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_LOCK_MISC | TEGRA_PLL_VCO_OUT,
  1664. .set_defaults = tegra210_pllre_set_defaults,
  1665. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1666. };
  1667. static struct div_nmp pllp_nmp = {
  1668. .divm_shift = 0,
  1669. .divm_width = 8,
  1670. .divn_shift = 10,
  1671. .divn_width = 8,
  1672. .divp_shift = 20,
  1673. .divp_width = 5,
  1674. };
  1675. static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
  1676. { 12000000, 408000000, 34, 1, 1, 0 },
  1677. { 38400000, 408000000, 85, 8, 1, 0 }, /* cf = 4.8MHz, allowed exception */
  1678. { 0, 0, 0, 0, 0, 0 },
  1679. };
  1680. static struct tegra_clk_pll_params pll_p_params = {
  1681. .input_min = 9600000,
  1682. .input_max = 800000000,
  1683. .cf_min = 9600000,
  1684. .cf_max = 19200000,
  1685. .vco_min = 350000000,
  1686. .vco_max = 700000000,
  1687. .base_reg = PLLP_BASE,
  1688. .misc_reg = PLLP_MISC0,
  1689. .lock_mask = PLL_BASE_LOCK,
  1690. .lock_delay = 300,
  1691. .iddq_reg = PLLP_MISC0,
  1692. .iddq_bit_idx = PLLXP_IDDQ_BIT,
  1693. .ext_misc_reg[0] = PLLP_MISC0,
  1694. .ext_misc_reg[1] = PLLP_MISC1,
  1695. .div_nmp = &pllp_nmp,
  1696. .freq_table = pll_p_freq_table,
  1697. .fixed_rate = 408000000,
  1698. .flags = TEGRA_PLL_FIXED | TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT,
  1699. .set_defaults = tegra210_pllp_set_defaults,
  1700. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1701. };
  1702. static struct tegra_clk_pll_params pll_a1_params = {
  1703. .input_min = 12000000,
  1704. .input_max = 700000000,
  1705. .cf_min = 12000000,
  1706. .cf_max = 50000000,
  1707. .vco_min = 600000000,
  1708. .vco_max = 1200000000,
  1709. .base_reg = PLLA1_BASE,
  1710. .misc_reg = PLLA1_MISC0,
  1711. .lock_mask = PLLCX_BASE_LOCK,
  1712. .lock_delay = 300,
  1713. .iddq_reg = PLLA1_MISC1,
  1714. .iddq_bit_idx = PLLCX_IDDQ_BIT,
  1715. .reset_reg = PLLA1_MISC0,
  1716. .reset_bit_idx = PLLCX_RESET_BIT,
  1717. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1718. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1719. .div_nmp = &pllc_nmp,
  1720. .ext_misc_reg[0] = PLLA1_MISC0,
  1721. .ext_misc_reg[1] = PLLA1_MISC1,
  1722. .ext_misc_reg[2] = PLLA1_MISC2,
  1723. .ext_misc_reg[3] = PLLA1_MISC3,
  1724. .freq_table = pll_cx_freq_table,
  1725. .flags = TEGRA_PLL_USE_LOCK,
  1726. .set_defaults = _plla1_set_defaults,
  1727. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1728. };
  1729. static struct div_nmp plla_nmp = {
  1730. .divm_shift = 0,
  1731. .divm_width = 8,
  1732. .divn_shift = 8,
  1733. .divn_width = 8,
  1734. .divp_shift = 20,
  1735. .divp_width = 5,
  1736. };
  1737. static struct tegra_clk_pll_freq_table pll_a_freq_table[] = {
  1738. { 12000000, 282240000, 47, 1, 2, 1, 0xf148 }, /* actual: 282240234 */
  1739. { 12000000, 368640000, 61, 1, 2, 1, 0xfe15 }, /* actual: 368640381 */
  1740. { 12000000, 240000000, 60, 1, 3, 1, 0 },
  1741. { 13000000, 282240000, 43, 1, 2, 1, 0xfd7d }, /* actual: 282239807 */
  1742. { 13000000, 368640000, 56, 1, 2, 1, 0x06d8 }, /* actual: 368640137 */
  1743. { 13000000, 240000000, 55, 1, 3, 1, 0 }, /* actual: 238.3 MHz */
  1744. { 38400000, 282240000, 44, 3, 2, 1, 0xf333 }, /* actual: 282239844 */
  1745. { 38400000, 368640000, 57, 3, 2, 1, 0x0333 }, /* actual: 368639844 */
  1746. { 38400000, 240000000, 75, 3, 3, 1, 0 },
  1747. { 0, 0, 0, 0, 0, 0, 0 },
  1748. };
  1749. static struct tegra_clk_pll_params pll_a_params = {
  1750. .input_min = 12000000,
  1751. .input_max = 800000000,
  1752. .cf_min = 12000000,
  1753. .cf_max = 19200000,
  1754. .vco_min = 500000000,
  1755. .vco_max = 1000000000,
  1756. .base_reg = PLLA_BASE,
  1757. .misc_reg = PLLA_MISC0,
  1758. .lock_mask = PLL_BASE_LOCK,
  1759. .lock_delay = 300,
  1760. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1761. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1762. .iddq_reg = PLLA_BASE,
  1763. .iddq_bit_idx = PLLA_IDDQ_BIT,
  1764. .div_nmp = &plla_nmp,
  1765. .sdm_din_reg = PLLA_MISC1,
  1766. .sdm_din_mask = PLLA_SDM_DIN_MASK,
  1767. .sdm_ctrl_reg = PLLA_MISC2,
  1768. .sdm_ctrl_en_mask = PLLA_SDM_EN_MASK,
  1769. .ext_misc_reg[0] = PLLA_MISC0,
  1770. .ext_misc_reg[1] = PLLA_MISC1,
  1771. .ext_misc_reg[2] = PLLA_MISC2,
  1772. .freq_table = pll_a_freq_table,
  1773. .flags = TEGRA_PLL_USE_LOCK | TEGRA_MDIV_NEW,
  1774. .set_defaults = tegra210_plla_set_defaults,
  1775. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1776. .set_gain = tegra210_clk_pll_set_gain,
  1777. .adjust_vco = tegra210_clk_adjust_vco_min,
  1778. };
  1779. static struct div_nmp plld_nmp = {
  1780. .divm_shift = 0,
  1781. .divm_width = 8,
  1782. .divn_shift = 11,
  1783. .divn_width = 8,
  1784. .divp_shift = 20,
  1785. .divp_width = 3,
  1786. };
  1787. static struct tegra_clk_pll_freq_table pll_d_freq_table[] = {
  1788. { 12000000, 594000000, 99, 1, 2, 0, 0 },
  1789. { 13000000, 594000000, 91, 1, 2, 0, 0xfc4f }, /* actual: 594000183 */
  1790. { 38400000, 594000000, 30, 1, 2, 0, 0x0e00 },
  1791. { 0, 0, 0, 0, 0, 0, 0 },
  1792. };
  1793. static struct tegra_clk_pll_params pll_d_params = {
  1794. .input_min = 12000000,
  1795. .input_max = 800000000,
  1796. .cf_min = 12000000,
  1797. .cf_max = 38400000,
  1798. .vco_min = 750000000,
  1799. .vco_max = 1500000000,
  1800. .base_reg = PLLD_BASE,
  1801. .misc_reg = PLLD_MISC0,
  1802. .lock_mask = PLL_BASE_LOCK,
  1803. .lock_delay = 1000,
  1804. .iddq_reg = PLLD_MISC0,
  1805. .iddq_bit_idx = PLLD_IDDQ_BIT,
  1806. .round_p_to_pdiv = pll_expo_p_to_pdiv,
  1807. .pdiv_tohw = pll_expo_pdiv_to_hw,
  1808. .div_nmp = &plld_nmp,
  1809. .sdm_din_reg = PLLD_MISC0,
  1810. .sdm_din_mask = PLLA_SDM_DIN_MASK,
  1811. .sdm_ctrl_reg = PLLD_MISC0,
  1812. .sdm_ctrl_en_mask = PLLD_SDM_EN_MASK,
  1813. .ext_misc_reg[0] = PLLD_MISC0,
  1814. .ext_misc_reg[1] = PLLD_MISC1,
  1815. .freq_table = pll_d_freq_table,
  1816. .flags = TEGRA_PLL_USE_LOCK,
  1817. .mdiv_default = 1,
  1818. .set_defaults = tegra210_plld_set_defaults,
  1819. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1820. .set_gain = tegra210_clk_pll_set_gain,
  1821. .adjust_vco = tegra210_clk_adjust_vco_min,
  1822. };
  1823. static struct tegra_clk_pll_freq_table tegra210_pll_d2_freq_table[] = {
  1824. { 12000000, 594000000, 99, 1, 2, 0, 0xf000 },
  1825. { 13000000, 594000000, 91, 1, 2, 0, 0xfc4f }, /* actual: 594000183 */
  1826. { 38400000, 594000000, 30, 1, 2, 0, 0x0e00 },
  1827. { 0, 0, 0, 0, 0, 0, 0 },
  1828. };
  1829. /* s/w policy, always tegra_pll_ref */
  1830. static struct tegra_clk_pll_params pll_d2_params = {
  1831. .input_min = 12000000,
  1832. .input_max = 800000000,
  1833. .cf_min = 12000000,
  1834. .cf_max = 38400000,
  1835. .vco_min = 750000000,
  1836. .vco_max = 1500000000,
  1837. .base_reg = PLLD2_BASE,
  1838. .misc_reg = PLLD2_MISC0,
  1839. .lock_mask = PLL_BASE_LOCK,
  1840. .lock_delay = 300,
  1841. .iddq_reg = PLLD2_BASE,
  1842. .iddq_bit_idx = PLLSS_IDDQ_BIT,
  1843. .sdm_din_reg = PLLD2_MISC3,
  1844. .sdm_din_mask = PLLA_SDM_DIN_MASK,
  1845. .sdm_ctrl_reg = PLLD2_MISC1,
  1846. .sdm_ctrl_en_mask = PLLD2_SDM_EN_MASK,
  1847. /* disable spread-spectrum for pll_d2 */
  1848. .ssc_ctrl_reg = 0,
  1849. .ssc_ctrl_en_mask = 0,
  1850. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1851. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1852. .div_nmp = &pllss_nmp,
  1853. .ext_misc_reg[0] = PLLD2_MISC0,
  1854. .ext_misc_reg[1] = PLLD2_MISC1,
  1855. .ext_misc_reg[2] = PLLD2_MISC2,
  1856. .ext_misc_reg[3] = PLLD2_MISC3,
  1857. .max_p = PLL_QLIN_PDIV_MAX,
  1858. .mdiv_default = 1,
  1859. .freq_table = tegra210_pll_d2_freq_table,
  1860. .set_defaults = tegra210_plld2_set_defaults,
  1861. .flags = TEGRA_PLL_USE_LOCK,
  1862. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1863. .set_gain = tegra210_clk_pll_set_gain,
  1864. .adjust_vco = tegra210_clk_adjust_vco_min,
  1865. };
  1866. static struct tegra_clk_pll_freq_table pll_dp_freq_table[] = {
  1867. { 12000000, 270000000, 90, 1, 4, 0, 0xf000 },
  1868. { 13000000, 270000000, 83, 1, 4, 0, 0xf000 }, /* actual: 269.8 MHz */
  1869. { 38400000, 270000000, 28, 1, 4, 0, 0xf400 },
  1870. { 0, 0, 0, 0, 0, 0, 0 },
  1871. };
  1872. static struct tegra_clk_pll_params pll_dp_params = {
  1873. .input_min = 12000000,
  1874. .input_max = 800000000,
  1875. .cf_min = 12000000,
  1876. .cf_max = 38400000,
  1877. .vco_min = 750000000,
  1878. .vco_max = 1500000000,
  1879. .base_reg = PLLDP_BASE,
  1880. .misc_reg = PLLDP_MISC,
  1881. .lock_mask = PLL_BASE_LOCK,
  1882. .lock_delay = 300,
  1883. .iddq_reg = PLLDP_BASE,
  1884. .iddq_bit_idx = PLLSS_IDDQ_BIT,
  1885. .sdm_din_reg = PLLDP_SS_CTRL2,
  1886. .sdm_din_mask = PLLA_SDM_DIN_MASK,
  1887. .sdm_ctrl_reg = PLLDP_SS_CFG,
  1888. .sdm_ctrl_en_mask = PLLDP_SDM_EN_MASK,
  1889. .ssc_ctrl_reg = PLLDP_SS_CFG,
  1890. .ssc_ctrl_en_mask = PLLDP_SSC_EN_MASK,
  1891. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1892. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1893. .div_nmp = &pllss_nmp,
  1894. .ext_misc_reg[0] = PLLDP_MISC,
  1895. .ext_misc_reg[1] = PLLDP_SS_CFG,
  1896. .ext_misc_reg[2] = PLLDP_SS_CTRL1,
  1897. .ext_misc_reg[3] = PLLDP_SS_CTRL2,
  1898. .max_p = PLL_QLIN_PDIV_MAX,
  1899. .mdiv_default = 1,
  1900. .freq_table = pll_dp_freq_table,
  1901. .set_defaults = tegra210_plldp_set_defaults,
  1902. .flags = TEGRA_PLL_USE_LOCK,
  1903. .calc_rate = tegra210_pll_fixed_mdiv_cfg,
  1904. .set_gain = tegra210_clk_pll_set_gain,
  1905. .adjust_vco = tegra210_clk_adjust_vco_min,
  1906. };
  1907. static struct div_nmp pllu_nmp = {
  1908. .divm_shift = 0,
  1909. .divm_width = 8,
  1910. .divn_shift = 8,
  1911. .divn_width = 8,
  1912. .divp_shift = 16,
  1913. .divp_width = 5,
  1914. };
  1915. static struct tegra_clk_pll_freq_table pll_u_freq_table[] = {
  1916. { 12000000, 480000000, 40, 1, 1, 0 },
  1917. { 13000000, 480000000, 36, 1, 1, 0 }, /* actual: 468.0 MHz */
  1918. { 38400000, 480000000, 25, 2, 1, 0 },
  1919. { 0, 0, 0, 0, 0, 0 },
  1920. };
  1921. static struct tegra_clk_pll_params pll_u_vco_params = {
  1922. .input_min = 9600000,
  1923. .input_max = 800000000,
  1924. .cf_min = 9600000,
  1925. .cf_max = 19200000,
  1926. .vco_min = 350000000,
  1927. .vco_max = 700000000,
  1928. .base_reg = PLLU_BASE,
  1929. .misc_reg = PLLU_MISC0,
  1930. .lock_mask = PLL_BASE_LOCK,
  1931. .lock_delay = 1000,
  1932. .iddq_reg = PLLU_MISC0,
  1933. .iddq_bit_idx = PLLU_IDDQ_BIT,
  1934. .ext_misc_reg[0] = PLLU_MISC0,
  1935. .ext_misc_reg[1] = PLLU_MISC1,
  1936. .round_p_to_pdiv = pll_qlin_p_to_pdiv,
  1937. .pdiv_tohw = pll_qlin_pdiv_to_hw,
  1938. .div_nmp = &pllu_nmp,
  1939. .freq_table = pll_u_freq_table,
  1940. .flags = TEGRA_PLLU | TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT,
  1941. };
  1942. struct utmi_clk_param {
  1943. /* Oscillator Frequency in KHz */
  1944. u32 osc_frequency;
  1945. /* UTMIP PLL Enable Delay Count */
  1946. u8 enable_delay_count;
  1947. /* UTMIP PLL Stable count */
  1948. u16 stable_count;
  1949. /* UTMIP PLL Active delay count */
  1950. u8 active_delay_count;
  1951. /* UTMIP PLL Xtal frequency count */
  1952. u16 xtal_freq_count;
  1953. };
  1954. static const struct utmi_clk_param utmi_parameters[] = {
  1955. {
  1956. .osc_frequency = 38400000, .enable_delay_count = 0x0,
  1957. .stable_count = 0x0, .active_delay_count = 0x6,
  1958. .xtal_freq_count = 0x80
  1959. }, {
  1960. .osc_frequency = 13000000, .enable_delay_count = 0x02,
  1961. .stable_count = 0x33, .active_delay_count = 0x05,
  1962. .xtal_freq_count = 0x7f
  1963. }, {
  1964. .osc_frequency = 19200000, .enable_delay_count = 0x03,
  1965. .stable_count = 0x4b, .active_delay_count = 0x06,
  1966. .xtal_freq_count = 0xbb
  1967. }, {
  1968. .osc_frequency = 12000000, .enable_delay_count = 0x02,
  1969. .stable_count = 0x2f, .active_delay_count = 0x08,
  1970. .xtal_freq_count = 0x76
  1971. }, {
  1972. .osc_frequency = 26000000, .enable_delay_count = 0x04,
  1973. .stable_count = 0x66, .active_delay_count = 0x09,
  1974. .xtal_freq_count = 0xfe
  1975. }, {
  1976. .osc_frequency = 16800000, .enable_delay_count = 0x03,
  1977. .stable_count = 0x41, .active_delay_count = 0x0a,
  1978. .xtal_freq_count = 0xa4
  1979. },
  1980. };
  1981. static struct tegra_clk tegra210_clks[tegra_clk_max] __initdata = {
  1982. [tegra_clk_ispb] = { .dt_id = TEGRA210_CLK_ISPB, .present = true },
  1983. [tegra_clk_rtc] = { .dt_id = TEGRA210_CLK_RTC, .present = true },
  1984. [tegra_clk_timer] = { .dt_id = TEGRA210_CLK_TIMER, .present = true },
  1985. [tegra_clk_uarta_8] = { .dt_id = TEGRA210_CLK_UARTA, .present = true },
  1986. [tegra_clk_i2s1] = { .dt_id = TEGRA210_CLK_I2S1, .present = true },
  1987. [tegra_clk_i2c1] = { .dt_id = TEGRA210_CLK_I2C1, .present = true },
  1988. [tegra_clk_sdmmc1_9] = { .dt_id = TEGRA210_CLK_SDMMC1, .present = true },
  1989. [tegra_clk_pwm] = { .dt_id = TEGRA210_CLK_PWM, .present = true },
  1990. [tegra_clk_i2s2] = { .dt_id = TEGRA210_CLK_I2S2, .present = true },
  1991. [tegra_clk_usbd] = { .dt_id = TEGRA210_CLK_USBD, .present = true },
  1992. [tegra_clk_isp_9] = { .dt_id = TEGRA210_CLK_ISP, .present = true },
  1993. [tegra_clk_disp2_8] = { .dt_id = TEGRA210_CLK_DISP2, .present = true },
  1994. [tegra_clk_disp1_8] = { .dt_id = TEGRA210_CLK_DISP1, .present = true },
  1995. [tegra_clk_host1x_9] = { .dt_id = TEGRA210_CLK_HOST1X, .present = true },
  1996. [tegra_clk_i2s0] = { .dt_id = TEGRA210_CLK_I2S0, .present = true },
  1997. [tegra_clk_apbdma] = { .dt_id = TEGRA210_CLK_APBDMA, .present = true },
  1998. [tegra_clk_kfuse] = { .dt_id = TEGRA210_CLK_KFUSE, .present = true },
  1999. [tegra_clk_sbc1_9] = { .dt_id = TEGRA210_CLK_SBC1, .present = true },
  2000. [tegra_clk_sbc2_9] = { .dt_id = TEGRA210_CLK_SBC2, .present = true },
  2001. [tegra_clk_sbc3_9] = { .dt_id = TEGRA210_CLK_SBC3, .present = true },
  2002. [tegra_clk_i2c5] = { .dt_id = TEGRA210_CLK_I2C5, .present = true },
  2003. [tegra_clk_csi] = { .dt_id = TEGRA210_CLK_CSI, .present = true },
  2004. [tegra_clk_i2c2] = { .dt_id = TEGRA210_CLK_I2C2, .present = true },
  2005. [tegra_clk_uartc_8] = { .dt_id = TEGRA210_CLK_UARTC, .present = true },
  2006. [tegra_clk_mipi_cal] = { .dt_id = TEGRA210_CLK_MIPI_CAL, .present = true },
  2007. [tegra_clk_emc] = { .dt_id = TEGRA210_CLK_EMC, .present = true },
  2008. [tegra_clk_usb2] = { .dt_id = TEGRA210_CLK_USB2, .present = true },
  2009. [tegra_clk_bsev] = { .dt_id = TEGRA210_CLK_BSEV, .present = true },
  2010. [tegra_clk_uartd_8] = { .dt_id = TEGRA210_CLK_UARTD, .present = true },
  2011. [tegra_clk_i2c3] = { .dt_id = TEGRA210_CLK_I2C3, .present = true },
  2012. [tegra_clk_sbc4_9] = { .dt_id = TEGRA210_CLK_SBC4, .present = true },
  2013. [tegra_clk_sdmmc3_9] = { .dt_id = TEGRA210_CLK_SDMMC3, .present = true },
  2014. [tegra_clk_pcie] = { .dt_id = TEGRA210_CLK_PCIE, .present = true },
  2015. [tegra_clk_owr_8] = { .dt_id = TEGRA210_CLK_OWR, .present = true },
  2016. [tegra_clk_afi] = { .dt_id = TEGRA210_CLK_AFI, .present = true },
  2017. [tegra_clk_csite_8] = { .dt_id = TEGRA210_CLK_CSITE, .present = true },
  2018. [tegra_clk_soc_therm_8] = { .dt_id = TEGRA210_CLK_SOC_THERM, .present = true },
  2019. [tegra_clk_dtv] = { .dt_id = TEGRA210_CLK_DTV, .present = true },
  2020. [tegra_clk_i2cslow] = { .dt_id = TEGRA210_CLK_I2CSLOW, .present = true },
  2021. [tegra_clk_tsec_8] = { .dt_id = TEGRA210_CLK_TSEC, .present = true },
  2022. [tegra_clk_xusb_host] = { .dt_id = TEGRA210_CLK_XUSB_HOST, .present = true },
  2023. [tegra_clk_csus] = { .dt_id = TEGRA210_CLK_CSUS, .present = true },
  2024. [tegra_clk_mselect] = { .dt_id = TEGRA210_CLK_MSELECT, .present = true },
  2025. [tegra_clk_tsensor] = { .dt_id = TEGRA210_CLK_TSENSOR, .present = true },
  2026. [tegra_clk_i2s3] = { .dt_id = TEGRA210_CLK_I2S3, .present = true },
  2027. [tegra_clk_i2s4] = { .dt_id = TEGRA210_CLK_I2S4, .present = true },
  2028. [tegra_clk_i2c4] = { .dt_id = TEGRA210_CLK_I2C4, .present = true },
  2029. [tegra_clk_d_audio] = { .dt_id = TEGRA210_CLK_D_AUDIO, .present = true },
  2030. [tegra_clk_hda2codec_2x_8] = { .dt_id = TEGRA210_CLK_HDA2CODEC_2X, .present = true },
  2031. [tegra_clk_spdif_2x] = { .dt_id = TEGRA210_CLK_SPDIF_2X, .present = true },
  2032. [tegra_clk_actmon] = { .dt_id = TEGRA210_CLK_ACTMON, .present = true },
  2033. [tegra_clk_extern1] = { .dt_id = TEGRA210_CLK_EXTERN1, .present = true },
  2034. [tegra_clk_extern2] = { .dt_id = TEGRA210_CLK_EXTERN2, .present = true },
  2035. [tegra_clk_extern3] = { .dt_id = TEGRA210_CLK_EXTERN3, .present = true },
  2036. [tegra_clk_sata_oob_8] = { .dt_id = TEGRA210_CLK_SATA_OOB, .present = true },
  2037. [tegra_clk_sata_8] = { .dt_id = TEGRA210_CLK_SATA, .present = true },
  2038. [tegra_clk_hda_8] = { .dt_id = TEGRA210_CLK_HDA, .present = true },
  2039. [tegra_clk_hda2hdmi] = { .dt_id = TEGRA210_CLK_HDA2HDMI, .present = true },
  2040. [tegra_clk_cilab] = { .dt_id = TEGRA210_CLK_CILAB, .present = true },
  2041. [tegra_clk_cilcd] = { .dt_id = TEGRA210_CLK_CILCD, .present = true },
  2042. [tegra_clk_cile] = { .dt_id = TEGRA210_CLK_CILE, .present = true },
  2043. [tegra_clk_dsialp] = { .dt_id = TEGRA210_CLK_DSIALP, .present = true },
  2044. [tegra_clk_dsiblp] = { .dt_id = TEGRA210_CLK_DSIBLP, .present = true },
  2045. [tegra_clk_entropy_8] = { .dt_id = TEGRA210_CLK_ENTROPY, .present = true },
  2046. [tegra_clk_xusb_ss] = { .dt_id = TEGRA210_CLK_XUSB_SS, .present = true },
  2047. [tegra_clk_i2c6] = { .dt_id = TEGRA210_CLK_I2C6, .present = true },
  2048. [tegra_clk_vim2_clk] = { .dt_id = TEGRA210_CLK_VIM2_CLK, .present = true },
  2049. [tegra_clk_clk72Mhz_8] = { .dt_id = TEGRA210_CLK_CLK72MHZ, .present = true },
  2050. [tegra_clk_vic03_8] = { .dt_id = TEGRA210_CLK_VIC03, .present = true },
  2051. [tegra_clk_dpaux] = { .dt_id = TEGRA210_CLK_DPAUX, .present = true },
  2052. [tegra_clk_dpaux1] = { .dt_id = TEGRA210_CLK_DPAUX1, .present = true },
  2053. [tegra_clk_sor0] = { .dt_id = TEGRA210_CLK_SOR0, .present = true },
  2054. [tegra_clk_sor0_lvds] = { .dt_id = TEGRA210_CLK_SOR0_LVDS, .present = true },
  2055. [tegra_clk_sor1] = { .dt_id = TEGRA210_CLK_SOR1, .present = true },
  2056. [tegra_clk_sor1_src] = { .dt_id = TEGRA210_CLK_SOR1_SRC, .present = true },
  2057. [tegra_clk_gpu] = { .dt_id = TEGRA210_CLK_GPU, .present = true },
  2058. [tegra_clk_pll_g_ref] = { .dt_id = TEGRA210_CLK_PLL_G_REF, .present = true, },
  2059. [tegra_clk_uartb_8] = { .dt_id = TEGRA210_CLK_UARTB, .present = true },
  2060. [tegra_clk_spdif_in_8] = { .dt_id = TEGRA210_CLK_SPDIF_IN, .present = true },
  2061. [tegra_clk_spdif_out] = { .dt_id = TEGRA210_CLK_SPDIF_OUT, .present = true },
  2062. [tegra_clk_vi_10] = { .dt_id = TEGRA210_CLK_VI, .present = true },
  2063. [tegra_clk_vi_sensor_8] = { .dt_id = TEGRA210_CLK_VI_SENSOR, .present = true },
  2064. [tegra_clk_fuse] = { .dt_id = TEGRA210_CLK_FUSE, .present = true },
  2065. [tegra_clk_fuse_burn] = { .dt_id = TEGRA210_CLK_FUSE_BURN, .present = true },
  2066. [tegra_clk_clk_32k] = { .dt_id = TEGRA210_CLK_CLK_32K, .present = true },
  2067. [tegra_clk_clk_m] = { .dt_id = TEGRA210_CLK_CLK_M, .present = true },
  2068. [tegra_clk_clk_m_div2] = { .dt_id = TEGRA210_CLK_CLK_M_DIV2, .present = true },
  2069. [tegra_clk_clk_m_div4] = { .dt_id = TEGRA210_CLK_CLK_M_DIV4, .present = true },
  2070. [tegra_clk_pll_ref] = { .dt_id = TEGRA210_CLK_PLL_REF, .present = true },
  2071. [tegra_clk_pll_c] = { .dt_id = TEGRA210_CLK_PLL_C, .present = true },
  2072. [tegra_clk_pll_c_out1] = { .dt_id = TEGRA210_CLK_PLL_C_OUT1, .present = true },
  2073. [tegra_clk_pll_c2] = { .dt_id = TEGRA210_CLK_PLL_C2, .present = true },
  2074. [tegra_clk_pll_c3] = { .dt_id = TEGRA210_CLK_PLL_C3, .present = true },
  2075. [tegra_clk_pll_m] = { .dt_id = TEGRA210_CLK_PLL_M, .present = true },
  2076. [tegra_clk_pll_p] = { .dt_id = TEGRA210_CLK_PLL_P, .present = true },
  2077. [tegra_clk_pll_p_out1] = { .dt_id = TEGRA210_CLK_PLL_P_OUT1, .present = true },
  2078. [tegra_clk_pll_p_out3] = { .dt_id = TEGRA210_CLK_PLL_P_OUT3, .present = true },
  2079. [tegra_clk_pll_p_out4_cpu] = { .dt_id = TEGRA210_CLK_PLL_P_OUT4, .present = true },
  2080. [tegra_clk_pll_p_out_hsio] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_HSIO, .present = true },
  2081. [tegra_clk_pll_p_out_xusb] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_XUSB, .present = true },
  2082. [tegra_clk_pll_p_out_cpu] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_CPU, .present = true },
  2083. [tegra_clk_pll_p_out_adsp] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_ADSP, .present = true },
  2084. [tegra_clk_pll_a] = { .dt_id = TEGRA210_CLK_PLL_A, .present = true },
  2085. [tegra_clk_pll_a_out0] = { .dt_id = TEGRA210_CLK_PLL_A_OUT0, .present = true },
  2086. [tegra_clk_pll_d] = { .dt_id = TEGRA210_CLK_PLL_D, .present = true },
  2087. [tegra_clk_pll_d_out0] = { .dt_id = TEGRA210_CLK_PLL_D_OUT0, .present = true },
  2088. [tegra_clk_pll_d2] = { .dt_id = TEGRA210_CLK_PLL_D2, .present = true },
  2089. [tegra_clk_pll_d2_out0] = { .dt_id = TEGRA210_CLK_PLL_D2_OUT0, .present = true },
  2090. [tegra_clk_pll_u] = { .dt_id = TEGRA210_CLK_PLL_U, .present = true },
  2091. [tegra_clk_pll_u_out] = { .dt_id = TEGRA210_CLK_PLL_U_OUT, .present = true },
  2092. [tegra_clk_pll_u_out1] = { .dt_id = TEGRA210_CLK_PLL_U_OUT1, .present = true },
  2093. [tegra_clk_pll_u_out2] = { .dt_id = TEGRA210_CLK_PLL_U_OUT2, .present = true },
  2094. [tegra_clk_pll_u_480m] = { .dt_id = TEGRA210_CLK_PLL_U_480M, .present = true },
  2095. [tegra_clk_pll_u_60m] = { .dt_id = TEGRA210_CLK_PLL_U_60M, .present = true },
  2096. [tegra_clk_pll_u_48m] = { .dt_id = TEGRA210_CLK_PLL_U_48M, .present = true },
  2097. [tegra_clk_pll_x] = { .dt_id = TEGRA210_CLK_PLL_X, .present = true },
  2098. [tegra_clk_pll_x_out0] = { .dt_id = TEGRA210_CLK_PLL_X_OUT0, .present = true },
  2099. [tegra_clk_pll_re_vco] = { .dt_id = TEGRA210_CLK_PLL_RE_VCO, .present = true },
  2100. [tegra_clk_pll_re_out] = { .dt_id = TEGRA210_CLK_PLL_RE_OUT, .present = true },
  2101. [tegra_clk_spdif_in_sync] = { .dt_id = TEGRA210_CLK_SPDIF_IN_SYNC, .present = true },
  2102. [tegra_clk_i2s0_sync] = { .dt_id = TEGRA210_CLK_I2S0_SYNC, .present = true },
  2103. [tegra_clk_i2s1_sync] = { .dt_id = TEGRA210_CLK_I2S1_SYNC, .present = true },
  2104. [tegra_clk_i2s2_sync] = { .dt_id = TEGRA210_CLK_I2S2_SYNC, .present = true },
  2105. [tegra_clk_i2s3_sync] = { .dt_id = TEGRA210_CLK_I2S3_SYNC, .present = true },
  2106. [tegra_clk_i2s4_sync] = { .dt_id = TEGRA210_CLK_I2S4_SYNC, .present = true },
  2107. [tegra_clk_vimclk_sync] = { .dt_id = TEGRA210_CLK_VIMCLK_SYNC, .present = true },
  2108. [tegra_clk_audio0] = { .dt_id = TEGRA210_CLK_AUDIO0, .present = true },
  2109. [tegra_clk_audio1] = { .dt_id = TEGRA210_CLK_AUDIO1, .present = true },
  2110. [tegra_clk_audio2] = { .dt_id = TEGRA210_CLK_AUDIO2, .present = true },
  2111. [tegra_clk_audio3] = { .dt_id = TEGRA210_CLK_AUDIO3, .present = true },
  2112. [tegra_clk_audio4] = { .dt_id = TEGRA210_CLK_AUDIO4, .present = true },
  2113. [tegra_clk_spdif] = { .dt_id = TEGRA210_CLK_SPDIF, .present = true },
  2114. [tegra_clk_clk_out_1] = { .dt_id = TEGRA210_CLK_CLK_OUT_1, .present = true },
  2115. [tegra_clk_clk_out_2] = { .dt_id = TEGRA210_CLK_CLK_OUT_2, .present = true },
  2116. [tegra_clk_clk_out_3] = { .dt_id = TEGRA210_CLK_CLK_OUT_3, .present = true },
  2117. [tegra_clk_blink] = { .dt_id = TEGRA210_CLK_BLINK, .present = true },
  2118. [tegra_clk_xusb_gate] = { .dt_id = TEGRA210_CLK_XUSB_GATE, .present = true },
  2119. [tegra_clk_xusb_host_src_8] = { .dt_id = TEGRA210_CLK_XUSB_HOST_SRC, .present = true },
  2120. [tegra_clk_xusb_falcon_src_8] = { .dt_id = TEGRA210_CLK_XUSB_FALCON_SRC, .present = true },
  2121. [tegra_clk_xusb_fs_src] = { .dt_id = TEGRA210_CLK_XUSB_FS_SRC, .present = true },
  2122. [tegra_clk_xusb_ss_src_8] = { .dt_id = TEGRA210_CLK_XUSB_SS_SRC, .present = true },
  2123. [tegra_clk_xusb_ss_div2] = { .dt_id = TEGRA210_CLK_XUSB_SS_DIV2, .present = true },
  2124. [tegra_clk_xusb_dev_src_8] = { .dt_id = TEGRA210_CLK_XUSB_DEV_SRC, .present = true },
  2125. [tegra_clk_xusb_dev] = { .dt_id = TEGRA210_CLK_XUSB_DEV, .present = true },
  2126. [tegra_clk_xusb_hs_src_4] = { .dt_id = TEGRA210_CLK_XUSB_HS_SRC, .present = true },
  2127. [tegra_clk_xusb_ssp_src] = { .dt_id = TEGRA210_CLK_XUSB_SSP_SRC, .present = true },
  2128. [tegra_clk_usb2_hsic_trk] = { .dt_id = TEGRA210_CLK_USB2_HSIC_TRK, .present = true },
  2129. [tegra_clk_hsic_trk] = { .dt_id = TEGRA210_CLK_HSIC_TRK, .present = true },
  2130. [tegra_clk_usb2_trk] = { .dt_id = TEGRA210_CLK_USB2_TRK, .present = true },
  2131. [tegra_clk_sclk] = { .dt_id = TEGRA210_CLK_SCLK, .present = true },
  2132. [tegra_clk_sclk_mux] = { .dt_id = TEGRA210_CLK_SCLK_MUX, .present = true },
  2133. [tegra_clk_hclk] = { .dt_id = TEGRA210_CLK_HCLK, .present = true },
  2134. [tegra_clk_pclk] = { .dt_id = TEGRA210_CLK_PCLK, .present = true },
  2135. [tegra_clk_cclk_g] = { .dt_id = TEGRA210_CLK_CCLK_G, .present = true },
  2136. [tegra_clk_cclk_lp] = { .dt_id = TEGRA210_CLK_CCLK_LP, .present = true },
  2137. [tegra_clk_dfll_ref] = { .dt_id = TEGRA210_CLK_DFLL_REF, .present = true },
  2138. [tegra_clk_dfll_soc] = { .dt_id = TEGRA210_CLK_DFLL_SOC, .present = true },
  2139. [tegra_clk_vi_sensor2_8] = { .dt_id = TEGRA210_CLK_VI_SENSOR2, .present = true },
  2140. [tegra_clk_pll_p_out5] = { .dt_id = TEGRA210_CLK_PLL_P_OUT5, .present = true },
  2141. [tegra_clk_pll_c4] = { .dt_id = TEGRA210_CLK_PLL_C4, .present = true },
  2142. [tegra_clk_pll_dp] = { .dt_id = TEGRA210_CLK_PLL_DP, .present = true },
  2143. [tegra_clk_audio0_mux] = { .dt_id = TEGRA210_CLK_AUDIO0_MUX, .present = true },
  2144. [tegra_clk_audio1_mux] = { .dt_id = TEGRA210_CLK_AUDIO1_MUX, .present = true },
  2145. [tegra_clk_audio2_mux] = { .dt_id = TEGRA210_CLK_AUDIO2_MUX, .present = true },
  2146. [tegra_clk_audio3_mux] = { .dt_id = TEGRA210_CLK_AUDIO3_MUX, .present = true },
  2147. [tegra_clk_audio4_mux] = { .dt_id = TEGRA210_CLK_AUDIO4_MUX, .present = true },
  2148. [tegra_clk_spdif_mux] = { .dt_id = TEGRA210_CLK_SPDIF_MUX, .present = true },
  2149. [tegra_clk_clk_out_1_mux] = { .dt_id = TEGRA210_CLK_CLK_OUT_1_MUX, .present = true },
  2150. [tegra_clk_clk_out_2_mux] = { .dt_id = TEGRA210_CLK_CLK_OUT_2_MUX, .present = true },
  2151. [tegra_clk_clk_out_3_mux] = { .dt_id = TEGRA210_CLK_CLK_OUT_3_MUX, .present = true },
  2152. [tegra_clk_maud] = { .dt_id = TEGRA210_CLK_MAUD, .present = true },
  2153. [tegra_clk_mipibif] = { .dt_id = TEGRA210_CLK_MIPIBIF, .present = true },
  2154. [tegra_clk_qspi] = { .dt_id = TEGRA210_CLK_QSPI, .present = true },
  2155. [tegra_clk_sdmmc_legacy] = { .dt_id = TEGRA210_CLK_SDMMC_LEGACY, .present = true },
  2156. [tegra_clk_tsecb] = { .dt_id = TEGRA210_CLK_TSECB, .present = true },
  2157. [tegra_clk_uartape] = { .dt_id = TEGRA210_CLK_UARTAPE, .present = true },
  2158. [tegra_clk_vi_i2c] = { .dt_id = TEGRA210_CLK_VI_I2C, .present = true },
  2159. [tegra_clk_ape] = { .dt_id = TEGRA210_CLK_APE, .present = true },
  2160. [tegra_clk_dbgapb] = { .dt_id = TEGRA210_CLK_DBGAPB, .present = true },
  2161. [tegra_clk_nvdec] = { .dt_id = TEGRA210_CLK_NVDEC, .present = true },
  2162. [tegra_clk_nvenc] = { .dt_id = TEGRA210_CLK_NVENC, .present = true },
  2163. [tegra_clk_nvjpg] = { .dt_id = TEGRA210_CLK_NVJPG, .present = true },
  2164. [tegra_clk_pll_c4_out0] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT0, .present = true },
  2165. [tegra_clk_pll_c4_out1] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT1, .present = true },
  2166. [tegra_clk_pll_c4_out2] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT2, .present = true },
  2167. [tegra_clk_pll_c4_out3] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT3, .present = true },
  2168. [tegra_clk_apb2ape] = { .dt_id = TEGRA210_CLK_APB2APE, .present = true },
  2169. [tegra_clk_pll_a1] = { .dt_id = TEGRA210_CLK_PLL_A1, .present = true },
  2170. [tegra_clk_ispa] = { .dt_id = TEGRA210_CLK_ISPA, .present = true },
  2171. [tegra_clk_cec] = { .dt_id = TEGRA210_CLK_CEC, .present = true },
  2172. [tegra_clk_dmic1] = { .dt_id = TEGRA210_CLK_DMIC1, .present = true },
  2173. [tegra_clk_dmic2] = { .dt_id = TEGRA210_CLK_DMIC2, .present = true },
  2174. [tegra_clk_dmic3] = { .dt_id = TEGRA210_CLK_DMIC3, .present = true },
  2175. [tegra_clk_dmic1_sync_clk] = { .dt_id = TEGRA210_CLK_DMIC1_SYNC_CLK, .present = true },
  2176. [tegra_clk_dmic2_sync_clk] = { .dt_id = TEGRA210_CLK_DMIC2_SYNC_CLK, .present = true },
  2177. [tegra_clk_dmic3_sync_clk] = { .dt_id = TEGRA210_CLK_DMIC3_SYNC_CLK, .present = true },
  2178. [tegra_clk_dmic1_sync_clk_mux] = { .dt_id = TEGRA210_CLK_DMIC1_SYNC_CLK_MUX, .present = true },
  2179. [tegra_clk_dmic2_sync_clk_mux] = { .dt_id = TEGRA210_CLK_DMIC2_SYNC_CLK_MUX, .present = true },
  2180. [tegra_clk_dmic3_sync_clk_mux] = { .dt_id = TEGRA210_CLK_DMIC3_SYNC_CLK_MUX, .present = true },
  2181. [tegra_clk_dp2] = { .dt_id = TEGRA210_CLK_DP2, .present = true },
  2182. [tegra_clk_iqc1] = { .dt_id = TEGRA210_CLK_IQC1, .present = true },
  2183. [tegra_clk_iqc2] = { .dt_id = TEGRA210_CLK_IQC2, .present = true },
  2184. [tegra_clk_pll_a_out_adsp] = { .dt_id = TEGRA210_CLK_PLL_A_OUT_ADSP, .present = true },
  2185. [tegra_clk_pll_a_out0_out_adsp] = { .dt_id = TEGRA210_CLK_PLL_A_OUT0_OUT_ADSP, .present = true },
  2186. [tegra_clk_adsp] = { .dt_id = TEGRA210_CLK_ADSP, .present = true },
  2187. [tegra_clk_adsp_neon] = { .dt_id = TEGRA210_CLK_ADSP_NEON, .present = true },
  2188. };
  2189. static struct tegra_devclk devclks[] __initdata = {
  2190. { .con_id = "clk_m", .dt_id = TEGRA210_CLK_CLK_M },
  2191. { .con_id = "pll_ref", .dt_id = TEGRA210_CLK_PLL_REF },
  2192. { .con_id = "clk_32k", .dt_id = TEGRA210_CLK_CLK_32K },
  2193. { .con_id = "clk_m_div2", .dt_id = TEGRA210_CLK_CLK_M_DIV2 },
  2194. { .con_id = "clk_m_div4", .dt_id = TEGRA210_CLK_CLK_M_DIV4 },
  2195. { .con_id = "pll_c", .dt_id = TEGRA210_CLK_PLL_C },
  2196. { .con_id = "pll_c_out1", .dt_id = TEGRA210_CLK_PLL_C_OUT1 },
  2197. { .con_id = "pll_c2", .dt_id = TEGRA210_CLK_PLL_C2 },
  2198. { .con_id = "pll_c3", .dt_id = TEGRA210_CLK_PLL_C3 },
  2199. { .con_id = "pll_p", .dt_id = TEGRA210_CLK_PLL_P },
  2200. { .con_id = "pll_p_out1", .dt_id = TEGRA210_CLK_PLL_P_OUT1 },
  2201. { .con_id = "pll_p_out2", .dt_id = TEGRA210_CLK_PLL_P_OUT2 },
  2202. { .con_id = "pll_p_out3", .dt_id = TEGRA210_CLK_PLL_P_OUT3 },
  2203. { .con_id = "pll_p_out4", .dt_id = TEGRA210_CLK_PLL_P_OUT4 },
  2204. { .con_id = "pll_m", .dt_id = TEGRA210_CLK_PLL_M },
  2205. { .con_id = "pll_x", .dt_id = TEGRA210_CLK_PLL_X },
  2206. { .con_id = "pll_x_out0", .dt_id = TEGRA210_CLK_PLL_X_OUT0 },
  2207. { .con_id = "pll_u", .dt_id = TEGRA210_CLK_PLL_U },
  2208. { .con_id = "pll_u_out", .dt_id = TEGRA210_CLK_PLL_U_OUT },
  2209. { .con_id = "pll_u_out1", .dt_id = TEGRA210_CLK_PLL_U_OUT1 },
  2210. { .con_id = "pll_u_out2", .dt_id = TEGRA210_CLK_PLL_U_OUT2 },
  2211. { .con_id = "pll_u_480M", .dt_id = TEGRA210_CLK_PLL_U_480M },
  2212. { .con_id = "pll_u_60M", .dt_id = TEGRA210_CLK_PLL_U_60M },
  2213. { .con_id = "pll_u_48M", .dt_id = TEGRA210_CLK_PLL_U_48M },
  2214. { .con_id = "pll_d", .dt_id = TEGRA210_CLK_PLL_D },
  2215. { .con_id = "pll_d_out0", .dt_id = TEGRA210_CLK_PLL_D_OUT0 },
  2216. { .con_id = "pll_d2", .dt_id = TEGRA210_CLK_PLL_D2 },
  2217. { .con_id = "pll_d2_out0", .dt_id = TEGRA210_CLK_PLL_D2_OUT0 },
  2218. { .con_id = "pll_a", .dt_id = TEGRA210_CLK_PLL_A },
  2219. { .con_id = "pll_a_out0", .dt_id = TEGRA210_CLK_PLL_A_OUT0 },
  2220. { .con_id = "pll_re_vco", .dt_id = TEGRA210_CLK_PLL_RE_VCO },
  2221. { .con_id = "pll_re_out", .dt_id = TEGRA210_CLK_PLL_RE_OUT },
  2222. { .con_id = "spdif_in_sync", .dt_id = TEGRA210_CLK_SPDIF_IN_SYNC },
  2223. { .con_id = "i2s0_sync", .dt_id = TEGRA210_CLK_I2S0_SYNC },
  2224. { .con_id = "i2s1_sync", .dt_id = TEGRA210_CLK_I2S1_SYNC },
  2225. { .con_id = "i2s2_sync", .dt_id = TEGRA210_CLK_I2S2_SYNC },
  2226. { .con_id = "i2s3_sync", .dt_id = TEGRA210_CLK_I2S3_SYNC },
  2227. { .con_id = "i2s4_sync", .dt_id = TEGRA210_CLK_I2S4_SYNC },
  2228. { .con_id = "vimclk_sync", .dt_id = TEGRA210_CLK_VIMCLK_SYNC },
  2229. { .con_id = "audio0", .dt_id = TEGRA210_CLK_AUDIO0 },
  2230. { .con_id = "audio1", .dt_id = TEGRA210_CLK_AUDIO1 },
  2231. { .con_id = "audio2", .dt_id = TEGRA210_CLK_AUDIO2 },
  2232. { .con_id = "audio3", .dt_id = TEGRA210_CLK_AUDIO3 },
  2233. { .con_id = "audio4", .dt_id = TEGRA210_CLK_AUDIO4 },
  2234. { .con_id = "spdif", .dt_id = TEGRA210_CLK_SPDIF },
  2235. { .con_id = "spdif_2x", .dt_id = TEGRA210_CLK_SPDIF_2X },
  2236. { .con_id = "extern1", .dev_id = "clk_out_1", .dt_id = TEGRA210_CLK_EXTERN1 },
  2237. { .con_id = "extern2", .dev_id = "clk_out_2", .dt_id = TEGRA210_CLK_EXTERN2 },
  2238. { .con_id = "extern3", .dev_id = "clk_out_3", .dt_id = TEGRA210_CLK_EXTERN3 },
  2239. { .con_id = "blink", .dt_id = TEGRA210_CLK_BLINK },
  2240. { .con_id = "cclk_g", .dt_id = TEGRA210_CLK_CCLK_G },
  2241. { .con_id = "cclk_lp", .dt_id = TEGRA210_CLK_CCLK_LP },
  2242. { .con_id = "sclk", .dt_id = TEGRA210_CLK_SCLK },
  2243. { .con_id = "hclk", .dt_id = TEGRA210_CLK_HCLK },
  2244. { .con_id = "pclk", .dt_id = TEGRA210_CLK_PCLK },
  2245. { .con_id = "fuse", .dt_id = TEGRA210_CLK_FUSE },
  2246. { .dev_id = "rtc-tegra", .dt_id = TEGRA210_CLK_RTC },
  2247. { .dev_id = "timer", .dt_id = TEGRA210_CLK_TIMER },
  2248. { .con_id = "pll_c4_out0", .dt_id = TEGRA210_CLK_PLL_C4_OUT0 },
  2249. { .con_id = "pll_c4_out1", .dt_id = TEGRA210_CLK_PLL_C4_OUT1 },
  2250. { .con_id = "pll_c4_out2", .dt_id = TEGRA210_CLK_PLL_C4_OUT2 },
  2251. { .con_id = "pll_c4_out3", .dt_id = TEGRA210_CLK_PLL_C4_OUT3 },
  2252. { .con_id = "dpaux", .dt_id = TEGRA210_CLK_DPAUX },
  2253. { .con_id = "sor0", .dt_id = TEGRA210_CLK_SOR0 },
  2254. };
  2255. static struct tegra_audio_clk_info tegra210_audio_plls[] = {
  2256. { "pll_a", &pll_a_params, tegra_clk_pll_a, "pll_ref" },
  2257. { "pll_a1", &pll_a1_params, tegra_clk_pll_a1, "pll_ref" },
  2258. };
  2259. static const char * const aclk_parents[] = {
  2260. "pll_a1", "pll_c", "pll_p", "pll_a_out0", "pll_c2", "pll_c3",
  2261. "clk_m"
  2262. };
  2263. static const unsigned int nvjpg_slcg_clkids[] = { TEGRA210_CLK_NVDEC };
  2264. static const unsigned int nvdec_slcg_clkids[] = { TEGRA210_CLK_NVJPG };
  2265. static const unsigned int sor_slcg_clkids[] = { TEGRA210_CLK_HDA2CODEC_2X,
  2266. TEGRA210_CLK_HDA2HDMI, TEGRA210_CLK_DISP1, TEGRA210_CLK_DISP2 };
  2267. static const unsigned int disp_slcg_clkids[] = { TEGRA210_CLK_LA,
  2268. TEGRA210_CLK_HOST1X};
  2269. static const unsigned int xusba_slcg_clkids[] = { TEGRA210_CLK_XUSB_HOST,
  2270. TEGRA210_CLK_XUSB_DEV };
  2271. static const unsigned int xusbb_slcg_clkids[] = { TEGRA210_CLK_XUSB_HOST,
  2272. TEGRA210_CLK_XUSB_SS };
  2273. static const unsigned int xusbc_slcg_clkids[] = { TEGRA210_CLK_XUSB_DEV,
  2274. TEGRA210_CLK_XUSB_SS };
  2275. static const unsigned int venc_slcg_clkids[] = { TEGRA210_CLK_HOST1X,
  2276. TEGRA210_CLK_PLL_D };
  2277. static const unsigned int ape_slcg_clkids[] = { TEGRA210_CLK_ACLK,
  2278. TEGRA210_CLK_I2S0, TEGRA210_CLK_I2S1, TEGRA210_CLK_I2S2,
  2279. TEGRA210_CLK_I2S3, TEGRA210_CLK_I2S4, TEGRA210_CLK_SPDIF_OUT,
  2280. TEGRA210_CLK_D_AUDIO };
  2281. static const unsigned int vic_slcg_clkids[] = { TEGRA210_CLK_HOST1X };
  2282. static struct tegra210_domain_mbist_war tegra210_pg_mbist_war[] = {
  2283. [TEGRA_POWERGATE_VENC] = {
  2284. .handle_lvl2_ovr = tegra210_venc_mbist_war,
  2285. .num_clks = ARRAY_SIZE(venc_slcg_clkids),
  2286. .clk_init_data = venc_slcg_clkids,
  2287. },
  2288. [TEGRA_POWERGATE_SATA] = {
  2289. .handle_lvl2_ovr = tegra210_generic_mbist_war,
  2290. .lvl2_offset = LVL2_CLK_GATE_OVRC,
  2291. .lvl2_mask = BIT(0) | BIT(17) | BIT(19),
  2292. },
  2293. [TEGRA_POWERGATE_MPE] = {
  2294. .handle_lvl2_ovr = tegra210_generic_mbist_war,
  2295. .lvl2_offset = LVL2_CLK_GATE_OVRE,
  2296. .lvl2_mask = BIT(29),
  2297. },
  2298. [TEGRA_POWERGATE_SOR] = {
  2299. .handle_lvl2_ovr = tegra210_generic_mbist_war,
  2300. .num_clks = ARRAY_SIZE(sor_slcg_clkids),
  2301. .clk_init_data = sor_slcg_clkids,
  2302. .lvl2_offset = LVL2_CLK_GATE_OVRA,
  2303. .lvl2_mask = BIT(1) | BIT(2),
  2304. },
  2305. [TEGRA_POWERGATE_DIS] = {
  2306. .handle_lvl2_ovr = tegra210_disp_mbist_war,
  2307. .num_clks = ARRAY_SIZE(disp_slcg_clkids),
  2308. .clk_init_data = disp_slcg_clkids,
  2309. },
  2310. [TEGRA_POWERGATE_DISB] = {
  2311. .num_clks = ARRAY_SIZE(disp_slcg_clkids),
  2312. .clk_init_data = disp_slcg_clkids,
  2313. .handle_lvl2_ovr = tegra210_generic_mbist_war,
  2314. .lvl2_offset = LVL2_CLK_GATE_OVRA,
  2315. .lvl2_mask = BIT(2),
  2316. },
  2317. [TEGRA_POWERGATE_XUSBA] = {
  2318. .num_clks = ARRAY_SIZE(xusba_slcg_clkids),
  2319. .clk_init_data = xusba_slcg_clkids,
  2320. .handle_lvl2_ovr = tegra210_generic_mbist_war,
  2321. .lvl2_offset = LVL2_CLK_GATE_OVRC,
  2322. .lvl2_mask = BIT(30) | BIT(31),
  2323. },
  2324. [TEGRA_POWERGATE_XUSBB] = {
  2325. .num_clks = ARRAY_SIZE(xusbb_slcg_clkids),
  2326. .clk_init_data = xusbb_slcg_clkids,
  2327. .handle_lvl2_ovr = tegra210_generic_mbist_war,
  2328. .lvl2_offset = LVL2_CLK_GATE_OVRC,
  2329. .lvl2_mask = BIT(30) | BIT(31),
  2330. },
  2331. [TEGRA_POWERGATE_XUSBC] = {
  2332. .num_clks = ARRAY_SIZE(xusbc_slcg_clkids),
  2333. .clk_init_data = xusbc_slcg_clkids,
  2334. .handle_lvl2_ovr = tegra210_generic_mbist_war,
  2335. .lvl2_offset = LVL2_CLK_GATE_OVRC,
  2336. .lvl2_mask = BIT(30) | BIT(31),
  2337. },
  2338. [TEGRA_POWERGATE_VIC] = {
  2339. .num_clks = ARRAY_SIZE(vic_slcg_clkids),
  2340. .clk_init_data = vic_slcg_clkids,
  2341. .handle_lvl2_ovr = tegra210_vic_mbist_war,
  2342. },
  2343. [TEGRA_POWERGATE_NVDEC] = {
  2344. .num_clks = ARRAY_SIZE(nvdec_slcg_clkids),
  2345. .clk_init_data = nvdec_slcg_clkids,
  2346. .handle_lvl2_ovr = tegra210_generic_mbist_war,
  2347. .lvl2_offset = LVL2_CLK_GATE_OVRE,
  2348. .lvl2_mask = BIT(9) | BIT(31),
  2349. },
  2350. [TEGRA_POWERGATE_NVJPG] = {
  2351. .num_clks = ARRAY_SIZE(nvjpg_slcg_clkids),
  2352. .clk_init_data = nvjpg_slcg_clkids,
  2353. .handle_lvl2_ovr = tegra210_generic_mbist_war,
  2354. .lvl2_offset = LVL2_CLK_GATE_OVRE,
  2355. .lvl2_mask = BIT(9) | BIT(31),
  2356. },
  2357. [TEGRA_POWERGATE_AUD] = {
  2358. .num_clks = ARRAY_SIZE(ape_slcg_clkids),
  2359. .clk_init_data = ape_slcg_clkids,
  2360. .handle_lvl2_ovr = tegra210_ape_mbist_war,
  2361. },
  2362. [TEGRA_POWERGATE_VE2] = {
  2363. .handle_lvl2_ovr = tegra210_generic_mbist_war,
  2364. .lvl2_offset = LVL2_CLK_GATE_OVRD,
  2365. .lvl2_mask = BIT(22),
  2366. },
  2367. };
  2368. int tegra210_clk_handle_mbist_war(unsigned int id)
  2369. {
  2370. int err;
  2371. struct tegra210_domain_mbist_war *mbist_war;
  2372. if (id >= ARRAY_SIZE(tegra210_pg_mbist_war)) {
  2373. WARN(1, "unknown domain id in MBIST WAR handler\n");
  2374. return -EINVAL;
  2375. }
  2376. mbist_war = &tegra210_pg_mbist_war[id];
  2377. if (!mbist_war->handle_lvl2_ovr)
  2378. return 0;
  2379. if (mbist_war->num_clks && !mbist_war->clks)
  2380. return -ENODEV;
  2381. err = clk_bulk_prepare_enable(mbist_war->num_clks, mbist_war->clks);
  2382. if (err < 0)
  2383. return err;
  2384. mutex_lock(&lvl2_ovr_lock);
  2385. mbist_war->handle_lvl2_ovr(mbist_war);
  2386. mutex_unlock(&lvl2_ovr_lock);
  2387. clk_bulk_disable_unprepare(mbist_war->num_clks, mbist_war->clks);
  2388. return 0;
  2389. }
  2390. void tegra210_put_utmipll_in_iddq(void)
  2391. {
  2392. u32 reg;
  2393. reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
  2394. if (reg & UTMIPLL_HW_PWRDN_CFG0_UTMIPLL_LOCK) {
  2395. pr_err("trying to assert IDDQ while UTMIPLL is locked\n");
  2396. return;
  2397. }
  2398. reg |= UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE;
  2399. writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0);
  2400. }
  2401. EXPORT_SYMBOL_GPL(tegra210_put_utmipll_in_iddq);
  2402. void tegra210_put_utmipll_out_iddq(void)
  2403. {
  2404. u32 reg;
  2405. reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
  2406. reg &= ~UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE;
  2407. writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0);
  2408. }
  2409. EXPORT_SYMBOL_GPL(tegra210_put_utmipll_out_iddq);
  2410. static void tegra210_utmi_param_configure(void)
  2411. {
  2412. u32 reg;
  2413. int i;
  2414. for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) {
  2415. if (osc_freq == utmi_parameters[i].osc_frequency)
  2416. break;
  2417. }
  2418. if (i >= ARRAY_SIZE(utmi_parameters)) {
  2419. pr_err("%s: Unexpected oscillator freq %lu\n", __func__,
  2420. osc_freq);
  2421. return;
  2422. }
  2423. reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
  2424. reg &= ~UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE;
  2425. writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0);
  2426. udelay(10);
  2427. reg = readl_relaxed(clk_base + UTMIP_PLL_CFG2);
  2428. /* Program UTMIP PLL stable and active counts */
  2429. /* [FIXME] arclk_rst.h says WRONG! This should be 1ms -> 0x50 Check! */
  2430. reg &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0);
  2431. reg |= UTMIP_PLL_CFG2_STABLE_COUNT(utmi_parameters[i].stable_count);
  2432. reg &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0);
  2433. reg |=
  2434. UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(utmi_parameters[i].active_delay_count);
  2435. writel_relaxed(reg, clk_base + UTMIP_PLL_CFG2);
  2436. /* Program UTMIP PLL delay and oscillator frequency counts */
  2437. reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1);
  2438. reg &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0);
  2439. reg |=
  2440. UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(utmi_parameters[i].enable_delay_count);
  2441. reg &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0);
  2442. reg |=
  2443. UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(utmi_parameters[i].xtal_freq_count);
  2444. reg |= UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN;
  2445. writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1);
  2446. /* Remove power downs from UTMIP PLL control bits */
  2447. reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1);
  2448. reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
  2449. reg |= UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP;
  2450. writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1);
  2451. udelay(20);
  2452. /* Enable samplers for SNPS, XUSB_HOST, XUSB_DEV */
  2453. reg = readl_relaxed(clk_base + UTMIP_PLL_CFG2);
  2454. reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP;
  2455. reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP;
  2456. reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP;
  2457. reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN;
  2458. reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN;
  2459. reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN;
  2460. writel_relaxed(reg, clk_base + UTMIP_PLL_CFG2);
  2461. /* Setup HW control of UTMIPLL */
  2462. reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1);
  2463. reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
  2464. reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP;
  2465. writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1);
  2466. reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
  2467. reg |= UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET;
  2468. reg &= ~UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL;
  2469. writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0);
  2470. udelay(1);
  2471. reg = readl_relaxed(clk_base + XUSB_PLL_CFG0);
  2472. reg &= ~XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY;
  2473. writel_relaxed(reg, clk_base + XUSB_PLL_CFG0);
  2474. udelay(1);
  2475. /* Enable HW control UTMIPLL */
  2476. reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
  2477. reg |= UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE;
  2478. writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0);
  2479. }
  2480. static int tegra210_enable_pllu(void)
  2481. {
  2482. struct tegra_clk_pll_freq_table *fentry;
  2483. struct tegra_clk_pll pllu;
  2484. u32 reg;
  2485. for (fentry = pll_u_freq_table; fentry->input_rate; fentry++) {
  2486. if (fentry->input_rate == pll_ref_freq)
  2487. break;
  2488. }
  2489. if (!fentry->input_rate) {
  2490. pr_err("Unknown PLL_U reference frequency %lu\n", pll_ref_freq);
  2491. return -EINVAL;
  2492. }
  2493. /* clear IDDQ bit */
  2494. pllu.params = &pll_u_vco_params;
  2495. reg = readl_relaxed(clk_base + pllu.params->ext_misc_reg[0]);
  2496. reg &= ~BIT(pllu.params->iddq_bit_idx);
  2497. writel_relaxed(reg, clk_base + pllu.params->ext_misc_reg[0]);
  2498. udelay(5);
  2499. reg = readl_relaxed(clk_base + PLLU_BASE);
  2500. reg &= ~GENMASK(20, 0);
  2501. reg |= fentry->m;
  2502. reg |= fentry->n << 8;
  2503. reg |= fentry->p << 16;
  2504. writel(reg, clk_base + PLLU_BASE);
  2505. udelay(1);
  2506. reg |= PLL_ENABLE;
  2507. writel(reg, clk_base + PLLU_BASE);
  2508. readl_relaxed_poll_timeout_atomic(clk_base + PLLU_BASE, reg,
  2509. reg & PLL_BASE_LOCK, 2, 1000);
  2510. if (!(reg & PLL_BASE_LOCK)) {
  2511. pr_err("Timed out waiting for PLL_U to lock\n");
  2512. return -ETIMEDOUT;
  2513. }
  2514. return 0;
  2515. }
  2516. static int tegra210_init_pllu(void)
  2517. {
  2518. u32 reg;
  2519. int err;
  2520. tegra210_pllu_set_defaults(&pll_u_vco_params);
  2521. /* skip initialization when pllu is in hw controlled mode */
  2522. reg = readl_relaxed(clk_base + PLLU_BASE);
  2523. if (reg & PLLU_BASE_OVERRIDE) {
  2524. if (!(reg & PLL_ENABLE)) {
  2525. err = tegra210_enable_pllu();
  2526. if (err < 0) {
  2527. WARN_ON(1);
  2528. return err;
  2529. }
  2530. }
  2531. /* enable hw controlled mode */
  2532. reg = readl_relaxed(clk_base + PLLU_BASE);
  2533. reg &= ~PLLU_BASE_OVERRIDE;
  2534. writel(reg, clk_base + PLLU_BASE);
  2535. reg = readl_relaxed(clk_base + PLLU_HW_PWRDN_CFG0);
  2536. reg |= PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE |
  2537. PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT |
  2538. PLLU_HW_PWRDN_CFG0_USE_LOCKDET;
  2539. reg &= ~(PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL |
  2540. PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL);
  2541. writel_relaxed(reg, clk_base + PLLU_HW_PWRDN_CFG0);
  2542. reg = readl_relaxed(clk_base + XUSB_PLL_CFG0);
  2543. reg &= ~XUSB_PLL_CFG0_PLLU_LOCK_DLY_MASK;
  2544. writel_relaxed(reg, clk_base + XUSB_PLL_CFG0);
  2545. udelay(1);
  2546. reg = readl_relaxed(clk_base + PLLU_HW_PWRDN_CFG0);
  2547. reg |= PLLU_HW_PWRDN_CFG0_SEQ_ENABLE;
  2548. writel_relaxed(reg, clk_base + PLLU_HW_PWRDN_CFG0);
  2549. udelay(1);
  2550. reg = readl_relaxed(clk_base + PLLU_BASE);
  2551. reg &= ~PLLU_BASE_CLKENABLE_USB;
  2552. writel_relaxed(reg, clk_base + PLLU_BASE);
  2553. }
  2554. /* enable UTMIPLL hw control if not yet done by the bootloader */
  2555. reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
  2556. if (!(reg & UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE))
  2557. tegra210_utmi_param_configure();
  2558. return 0;
  2559. }
  2560. static const char * const sor1_out_parents[] = {
  2561. /*
  2562. * Bit 0 of the mux selects sor1_pad_clkout, irrespective of bit 1, so
  2563. * the sor1_pad_clkout parent appears twice in the list below. This is
  2564. * merely to support clk_get_parent() if firmware happened to set
  2565. * these bits to 0b11. While not an invalid setting, code should
  2566. * always set the bits to 0b01 to select sor1_pad_clkout.
  2567. */
  2568. "sor_safe", "sor1_pad_clkout", "sor1", "sor1_pad_clkout",
  2569. };
  2570. static const char * const sor1_parents[] = {
  2571. "pll_p", "pll_d_out0", "pll_d2_out0", "clk_m",
  2572. };
  2573. static u32 sor1_parents_idx[] = { 0, 2, 5, 6 };
  2574. static struct tegra_periph_init_data tegra210_periph[] = {
  2575. TEGRA_INIT_DATA_TABLE("sor1", NULL, NULL, sor1_parents,
  2576. CLK_SOURCE_SOR1, 29, 0x7, 0, 0, 8, 1,
  2577. TEGRA_DIVIDER_ROUND_UP, 183, 0, tegra_clk_sor1,
  2578. sor1_parents_idx, 0, &sor1_lock),
  2579. };
  2580. static const char * const la_parents[] = {
  2581. "pll_p", "pll_c2", "pll_c", "pll_c3", "pll_re_out1", "pll_a1", "clk_m", "pll_c4_out0"
  2582. };
  2583. static struct tegra_clk_periph tegra210_la =
  2584. TEGRA_CLK_PERIPH(29, 7, 9, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP, 76, 0, NULL, 0);
  2585. static __init void tegra210_periph_clk_init(void __iomem *clk_base,
  2586. void __iomem *pmc_base)
  2587. {
  2588. struct clk *clk;
  2589. unsigned int i;
  2590. /* xusb_ss_div2 */
  2591. clk = clk_register_fixed_factor(NULL, "xusb_ss_div2", "xusb_ss_src", 0,
  2592. 1, 2);
  2593. clks[TEGRA210_CLK_XUSB_SS_DIV2] = clk;
  2594. clk = tegra_clk_register_periph_fixed("sor_safe", "pll_p", 0, clk_base,
  2595. 1, 17, 222);
  2596. clks[TEGRA210_CLK_SOR_SAFE] = clk;
  2597. clk = tegra_clk_register_periph_fixed("dpaux", "sor_safe", 0, clk_base,
  2598. 1, 17, 181);
  2599. clks[TEGRA210_CLK_DPAUX] = clk;
  2600. clk = tegra_clk_register_periph_fixed("dpaux1", "sor_safe", 0, clk_base,
  2601. 1, 17, 207);
  2602. clks[TEGRA210_CLK_DPAUX1] = clk;
  2603. clk = clk_register_mux_table(NULL, "sor1_out", sor1_out_parents,
  2604. ARRAY_SIZE(sor1_out_parents), 0,
  2605. clk_base + CLK_SOURCE_SOR1, 14, 0x3,
  2606. 0, NULL, &sor1_lock);
  2607. clks[TEGRA210_CLK_SOR1_OUT] = clk;
  2608. /* pll_d_dsi_out */
  2609. clk = clk_register_gate(NULL, "pll_d_dsi_out", "pll_d_out0", 0,
  2610. clk_base + PLLD_MISC0, 21, 0, &pll_d_lock);
  2611. clks[TEGRA210_CLK_PLL_D_DSI_OUT] = clk;
  2612. /* dsia */
  2613. clk = tegra_clk_register_periph_gate("dsia", "pll_d_dsi_out", 0,
  2614. clk_base, 0, 48,
  2615. periph_clk_enb_refcnt);
  2616. clks[TEGRA210_CLK_DSIA] = clk;
  2617. /* dsib */
  2618. clk = tegra_clk_register_periph_gate("dsib", "pll_d_dsi_out", 0,
  2619. clk_base, 0, 82,
  2620. periph_clk_enb_refcnt);
  2621. clks[TEGRA210_CLK_DSIB] = clk;
  2622. /* la */
  2623. clk = tegra_clk_register_periph("la", la_parents,
  2624. ARRAY_SIZE(la_parents), &tegra210_la, clk_base,
  2625. CLK_SOURCE_LA, 0);
  2626. clks[TEGRA210_CLK_LA] = clk;
  2627. /* emc mux */
  2628. clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm,
  2629. ARRAY_SIZE(mux_pllmcp_clkm), 0,
  2630. clk_base + CLK_SOURCE_EMC,
  2631. 29, 3, 0, &emc_lock);
  2632. clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC,
  2633. &emc_lock);
  2634. clks[TEGRA210_CLK_MC] = clk;
  2635. /* cml0 */
  2636. clk = clk_register_gate(NULL, "cml0", "pll_e", 0, clk_base + PLLE_AUX,
  2637. 0, 0, &pll_e_lock);
  2638. clk_register_clkdev(clk, "cml0", NULL);
  2639. clks[TEGRA210_CLK_CML0] = clk;
  2640. /* cml1 */
  2641. clk = clk_register_gate(NULL, "cml1", "pll_e", 0, clk_base + PLLE_AUX,
  2642. 1, 0, &pll_e_lock);
  2643. clk_register_clkdev(clk, "cml1", NULL);
  2644. clks[TEGRA210_CLK_CML1] = clk;
  2645. clk = tegra_clk_register_super_clk("aclk", aclk_parents,
  2646. ARRAY_SIZE(aclk_parents), 0, clk_base + 0x6e0,
  2647. 0, NULL);
  2648. clks[TEGRA210_CLK_ACLK] = clk;
  2649. clk = tegra_clk_register_sdmmc_mux_div("sdmmc2", clk_base,
  2650. CLK_SOURCE_SDMMC2, 9,
  2651. TEGRA_DIVIDER_ROUND_UP, 0, NULL);
  2652. clks[TEGRA210_CLK_SDMMC2] = clk;
  2653. clk = tegra_clk_register_sdmmc_mux_div("sdmmc4", clk_base,
  2654. CLK_SOURCE_SDMMC4, 15,
  2655. TEGRA_DIVIDER_ROUND_UP, 0, NULL);
  2656. clks[TEGRA210_CLK_SDMMC4] = clk;
  2657. for (i = 0; i < ARRAY_SIZE(tegra210_periph); i++) {
  2658. struct tegra_periph_init_data *init = &tegra210_periph[i];
  2659. struct clk **clkp;
  2660. clkp = tegra_lookup_dt_id(init->clk_id, tegra210_clks);
  2661. if (!clkp) {
  2662. pr_warn("clock %u not found\n", init->clk_id);
  2663. continue;
  2664. }
  2665. clk = tegra_clk_register_periph_data(clk_base, init);
  2666. *clkp = clk;
  2667. }
  2668. tegra_periph_clk_init(clk_base, pmc_base, tegra210_clks, &pll_p_params);
  2669. }
  2670. static void __init tegra210_pll_init(void __iomem *clk_base,
  2671. void __iomem *pmc)
  2672. {
  2673. struct clk *clk;
  2674. /* PLLC */
  2675. clk = tegra_clk_register_pllc_tegra210("pll_c", "pll_ref", clk_base,
  2676. pmc, 0, &pll_c_params, NULL);
  2677. if (!WARN_ON(IS_ERR(clk)))
  2678. clk_register_clkdev(clk, "pll_c", NULL);
  2679. clks[TEGRA210_CLK_PLL_C] = clk;
  2680. /* PLLC_OUT1 */
  2681. clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c",
  2682. clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
  2683. 8, 8, 1, NULL);
  2684. clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div",
  2685. clk_base + PLLC_OUT, 1, 0,
  2686. CLK_SET_RATE_PARENT, 0, NULL);
  2687. clk_register_clkdev(clk, "pll_c_out1", NULL);
  2688. clks[TEGRA210_CLK_PLL_C_OUT1] = clk;
  2689. /* PLLC_UD */
  2690. clk = clk_register_fixed_factor(NULL, "pll_c_ud", "pll_c",
  2691. CLK_SET_RATE_PARENT, 1, 1);
  2692. clk_register_clkdev(clk, "pll_c_ud", NULL);
  2693. clks[TEGRA210_CLK_PLL_C_UD] = clk;
  2694. /* PLLC2 */
  2695. clk = tegra_clk_register_pllc_tegra210("pll_c2", "pll_ref", clk_base,
  2696. pmc, 0, &pll_c2_params, NULL);
  2697. clk_register_clkdev(clk, "pll_c2", NULL);
  2698. clks[TEGRA210_CLK_PLL_C2] = clk;
  2699. /* PLLC3 */
  2700. clk = tegra_clk_register_pllc_tegra210("pll_c3", "pll_ref", clk_base,
  2701. pmc, 0, &pll_c3_params, NULL);
  2702. clk_register_clkdev(clk, "pll_c3", NULL);
  2703. clks[TEGRA210_CLK_PLL_C3] = clk;
  2704. /* PLLM */
  2705. clk = tegra_clk_register_pllm("pll_m", "osc", clk_base, pmc,
  2706. CLK_SET_RATE_GATE, &pll_m_params, NULL);
  2707. clk_register_clkdev(clk, "pll_m", NULL);
  2708. clks[TEGRA210_CLK_PLL_M] = clk;
  2709. /* PLLMB */
  2710. clk = tegra_clk_register_pllmb("pll_mb", "osc", clk_base, pmc,
  2711. CLK_SET_RATE_GATE, &pll_mb_params, NULL);
  2712. clk_register_clkdev(clk, "pll_mb", NULL);
  2713. clks[TEGRA210_CLK_PLL_MB] = clk;
  2714. /* PLLM_UD */
  2715. clk = clk_register_fixed_factor(NULL, "pll_m_ud", "pll_m",
  2716. CLK_SET_RATE_PARENT, 1, 1);
  2717. clk_register_clkdev(clk, "pll_m_ud", NULL);
  2718. clks[TEGRA210_CLK_PLL_M_UD] = clk;
  2719. /* PLLU_VCO */
  2720. if (!tegra210_init_pllu()) {
  2721. clk = clk_register_fixed_rate(NULL, "pll_u_vco", "pll_ref", 0,
  2722. 480*1000*1000);
  2723. clk_register_clkdev(clk, "pll_u_vco", NULL);
  2724. clks[TEGRA210_CLK_PLL_U] = clk;
  2725. }
  2726. /* PLLU_OUT */
  2727. clk = clk_register_divider_table(NULL, "pll_u_out", "pll_u_vco", 0,
  2728. clk_base + PLLU_BASE, 16, 4, 0,
  2729. pll_vco_post_div_table, NULL);
  2730. clk_register_clkdev(clk, "pll_u_out", NULL);
  2731. clks[TEGRA210_CLK_PLL_U_OUT] = clk;
  2732. /* PLLU_OUT1 */
  2733. clk = tegra_clk_register_divider("pll_u_out1_div", "pll_u_out",
  2734. clk_base + PLLU_OUTA, 0,
  2735. TEGRA_DIVIDER_ROUND_UP,
  2736. 8, 8, 1, &pll_u_lock);
  2737. clk = tegra_clk_register_pll_out("pll_u_out1", "pll_u_out1_div",
  2738. clk_base + PLLU_OUTA, 1, 0,
  2739. CLK_SET_RATE_PARENT, 0, &pll_u_lock);
  2740. clk_register_clkdev(clk, "pll_u_out1", NULL);
  2741. clks[TEGRA210_CLK_PLL_U_OUT1] = clk;
  2742. /* PLLU_OUT2 */
  2743. clk = tegra_clk_register_divider("pll_u_out2_div", "pll_u_out",
  2744. clk_base + PLLU_OUTA, 0,
  2745. TEGRA_DIVIDER_ROUND_UP,
  2746. 24, 8, 1, &pll_u_lock);
  2747. clk = tegra_clk_register_pll_out("pll_u_out2", "pll_u_out2_div",
  2748. clk_base + PLLU_OUTA, 17, 16,
  2749. CLK_SET_RATE_PARENT, 0, &pll_u_lock);
  2750. clk_register_clkdev(clk, "pll_u_out2", NULL);
  2751. clks[TEGRA210_CLK_PLL_U_OUT2] = clk;
  2752. /* PLLU_480M */
  2753. clk = clk_register_gate(NULL, "pll_u_480M", "pll_u_vco",
  2754. CLK_SET_RATE_PARENT, clk_base + PLLU_BASE,
  2755. 22, 0, &pll_u_lock);
  2756. clk_register_clkdev(clk, "pll_u_480M", NULL);
  2757. clks[TEGRA210_CLK_PLL_U_480M] = clk;
  2758. /* PLLU_60M */
  2759. clk = clk_register_gate(NULL, "pll_u_60M", "pll_u_out2",
  2760. CLK_SET_RATE_PARENT, clk_base + PLLU_BASE,
  2761. 23, 0, &pll_u_lock);
  2762. clk_register_clkdev(clk, "pll_u_60M", NULL);
  2763. clks[TEGRA210_CLK_PLL_U_60M] = clk;
  2764. /* PLLU_48M */
  2765. clk = clk_register_gate(NULL, "pll_u_48M", "pll_u_out1",
  2766. CLK_SET_RATE_PARENT, clk_base + PLLU_BASE,
  2767. 25, 0, &pll_u_lock);
  2768. clk_register_clkdev(clk, "pll_u_48M", NULL);
  2769. clks[TEGRA210_CLK_PLL_U_48M] = clk;
  2770. /* PLLD */
  2771. clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, pmc, 0,
  2772. &pll_d_params, &pll_d_lock);
  2773. clk_register_clkdev(clk, "pll_d", NULL);
  2774. clks[TEGRA210_CLK_PLL_D] = clk;
  2775. /* PLLD_OUT0 */
  2776. clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d",
  2777. CLK_SET_RATE_PARENT, 1, 2);
  2778. clk_register_clkdev(clk, "pll_d_out0", NULL);
  2779. clks[TEGRA210_CLK_PLL_D_OUT0] = clk;
  2780. /* PLLRE */
  2781. clk = tegra_clk_register_pllre_tegra210("pll_re_vco", "pll_ref",
  2782. clk_base, pmc, 0,
  2783. &pll_re_vco_params,
  2784. &pll_re_lock, pll_ref_freq);
  2785. clk_register_clkdev(clk, "pll_re_vco", NULL);
  2786. clks[TEGRA210_CLK_PLL_RE_VCO] = clk;
  2787. clk = clk_register_divider_table(NULL, "pll_re_out", "pll_re_vco", 0,
  2788. clk_base + PLLRE_BASE, 16, 5, 0,
  2789. pll_vco_post_div_table, &pll_re_lock);
  2790. clk_register_clkdev(clk, "pll_re_out", NULL);
  2791. clks[TEGRA210_CLK_PLL_RE_OUT] = clk;
  2792. clk = tegra_clk_register_divider("pll_re_out1_div", "pll_re_vco",
  2793. clk_base + PLLRE_OUT1, 0,
  2794. TEGRA_DIVIDER_ROUND_UP,
  2795. 8, 8, 1, NULL);
  2796. clk = tegra_clk_register_pll_out("pll_re_out1", "pll_re_out1_div",
  2797. clk_base + PLLRE_OUT1, 1, 0,
  2798. CLK_SET_RATE_PARENT, 0, NULL);
  2799. clks[TEGRA210_CLK_PLL_RE_OUT1] = clk;
  2800. /* PLLE */
  2801. clk = tegra_clk_register_plle_tegra210("pll_e", "pll_ref",
  2802. clk_base, 0, &pll_e_params, NULL);
  2803. clk_register_clkdev(clk, "pll_e", NULL);
  2804. clks[TEGRA210_CLK_PLL_E] = clk;
  2805. /* PLLC4 */
  2806. clk = tegra_clk_register_pllre("pll_c4_vco", "pll_ref", clk_base, pmc,
  2807. 0, &pll_c4_vco_params, NULL, pll_ref_freq);
  2808. clk_register_clkdev(clk, "pll_c4_vco", NULL);
  2809. clks[TEGRA210_CLK_PLL_C4] = clk;
  2810. /* PLLC4_OUT0 */
  2811. clk = clk_register_divider_table(NULL, "pll_c4_out0", "pll_c4_vco", 0,
  2812. clk_base + PLLC4_BASE, 19, 4, 0,
  2813. pll_vco_post_div_table, NULL);
  2814. clk_register_clkdev(clk, "pll_c4_out0", NULL);
  2815. clks[TEGRA210_CLK_PLL_C4_OUT0] = clk;
  2816. /* PLLC4_OUT1 */
  2817. clk = clk_register_fixed_factor(NULL, "pll_c4_out1", "pll_c4_vco",
  2818. CLK_SET_RATE_PARENT, 1, 3);
  2819. clk_register_clkdev(clk, "pll_c4_out1", NULL);
  2820. clks[TEGRA210_CLK_PLL_C4_OUT1] = clk;
  2821. /* PLLC4_OUT2 */
  2822. clk = clk_register_fixed_factor(NULL, "pll_c4_out2", "pll_c4_vco",
  2823. CLK_SET_RATE_PARENT, 1, 5);
  2824. clk_register_clkdev(clk, "pll_c4_out2", NULL);
  2825. clks[TEGRA210_CLK_PLL_C4_OUT2] = clk;
  2826. /* PLLC4_OUT3 */
  2827. clk = tegra_clk_register_divider("pll_c4_out3_div", "pll_c4_out0",
  2828. clk_base + PLLC4_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
  2829. 8, 8, 1, NULL);
  2830. clk = tegra_clk_register_pll_out("pll_c4_out3", "pll_c4_out3_div",
  2831. clk_base + PLLC4_OUT, 1, 0,
  2832. CLK_SET_RATE_PARENT, 0, NULL);
  2833. clk_register_clkdev(clk, "pll_c4_out3", NULL);
  2834. clks[TEGRA210_CLK_PLL_C4_OUT3] = clk;
  2835. /* PLLDP */
  2836. clk = tegra_clk_register_pllss_tegra210("pll_dp", "pll_ref", clk_base,
  2837. 0, &pll_dp_params, NULL);
  2838. clk_register_clkdev(clk, "pll_dp", NULL);
  2839. clks[TEGRA210_CLK_PLL_DP] = clk;
  2840. /* PLLD2 */
  2841. clk = tegra_clk_register_pllss_tegra210("pll_d2", "pll_ref", clk_base,
  2842. 0, &pll_d2_params, NULL);
  2843. clk_register_clkdev(clk, "pll_d2", NULL);
  2844. clks[TEGRA210_CLK_PLL_D2] = clk;
  2845. /* PLLD2_OUT0 */
  2846. clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2",
  2847. CLK_SET_RATE_PARENT, 1, 1);
  2848. clk_register_clkdev(clk, "pll_d2_out0", NULL);
  2849. clks[TEGRA210_CLK_PLL_D2_OUT0] = clk;
  2850. /* PLLP_OUT2 */
  2851. clk = clk_register_fixed_factor(NULL, "pll_p_out2", "pll_p",
  2852. CLK_SET_RATE_PARENT, 1, 2);
  2853. clk_register_clkdev(clk, "pll_p_out2", NULL);
  2854. clks[TEGRA210_CLK_PLL_P_OUT2] = clk;
  2855. }
  2856. /* Tegra210 CPU clock and reset control functions */
  2857. static void tegra210_wait_cpu_in_reset(u32 cpu)
  2858. {
  2859. unsigned int reg;
  2860. do {
  2861. reg = readl(clk_base + CLK_RST_CONTROLLER_CPU_CMPLX_STATUS);
  2862. cpu_relax();
  2863. } while (!(reg & (1 << cpu))); /* check CPU been reset or not */
  2864. }
  2865. static void tegra210_disable_cpu_clock(u32 cpu)
  2866. {
  2867. /* flow controller would take care in the power sequence. */
  2868. }
  2869. #ifdef CONFIG_PM_SLEEP
  2870. static void tegra210_cpu_clock_suspend(void)
  2871. {
  2872. /* switch coresite to clk_m, save off original source */
  2873. tegra210_cpu_clk_sctx.clk_csite_src =
  2874. readl(clk_base + CLK_SOURCE_CSITE);
  2875. writel(3 << 30, clk_base + CLK_SOURCE_CSITE);
  2876. }
  2877. static void tegra210_cpu_clock_resume(void)
  2878. {
  2879. writel(tegra210_cpu_clk_sctx.clk_csite_src,
  2880. clk_base + CLK_SOURCE_CSITE);
  2881. }
  2882. #endif
  2883. static struct tegra_cpu_car_ops tegra210_cpu_car_ops = {
  2884. .wait_for_reset = tegra210_wait_cpu_in_reset,
  2885. .disable_clock = tegra210_disable_cpu_clock,
  2886. #ifdef CONFIG_PM_SLEEP
  2887. .suspend = tegra210_cpu_clock_suspend,
  2888. .resume = tegra210_cpu_clock_resume,
  2889. #endif
  2890. };
  2891. static const struct of_device_id pmc_match[] __initconst = {
  2892. { .compatible = "nvidia,tegra210-pmc" },
  2893. { },
  2894. };
  2895. static struct tegra_clk_init_table init_table[] __initdata = {
  2896. { TEGRA210_CLK_UARTA, TEGRA210_CLK_PLL_P, 408000000, 0 },
  2897. { TEGRA210_CLK_UARTB, TEGRA210_CLK_PLL_P, 408000000, 0 },
  2898. { TEGRA210_CLK_UARTC, TEGRA210_CLK_PLL_P, 408000000, 0 },
  2899. { TEGRA210_CLK_UARTD, TEGRA210_CLK_PLL_P, 408000000, 0 },
  2900. { TEGRA210_CLK_PLL_A, TEGRA210_CLK_CLK_MAX, 564480000, 1 },
  2901. { TEGRA210_CLK_PLL_A_OUT0, TEGRA210_CLK_CLK_MAX, 11289600, 1 },
  2902. { TEGRA210_CLK_EXTERN1, TEGRA210_CLK_PLL_A_OUT0, 0, 1 },
  2903. { TEGRA210_CLK_CLK_OUT_1_MUX, TEGRA210_CLK_EXTERN1, 0, 1 },
  2904. { TEGRA210_CLK_CLK_OUT_1, TEGRA210_CLK_CLK_MAX, 0, 1 },
  2905. { TEGRA210_CLK_I2S0, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 },
  2906. { TEGRA210_CLK_I2S1, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 },
  2907. { TEGRA210_CLK_I2S2, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 },
  2908. { TEGRA210_CLK_I2S3, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 },
  2909. { TEGRA210_CLK_I2S4, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 },
  2910. { TEGRA210_CLK_HOST1X, TEGRA210_CLK_PLL_P, 136000000, 1 },
  2911. { TEGRA210_CLK_SCLK_MUX, TEGRA210_CLK_PLL_P, 0, 1 },
  2912. { TEGRA210_CLK_SCLK, TEGRA210_CLK_CLK_MAX, 102000000, 0 },
  2913. { TEGRA210_CLK_DFLL_SOC, TEGRA210_CLK_PLL_P, 51000000, 1 },
  2914. { TEGRA210_CLK_DFLL_REF, TEGRA210_CLK_PLL_P, 51000000, 1 },
  2915. { TEGRA210_CLK_SBC4, TEGRA210_CLK_PLL_P, 12000000, 1 },
  2916. { TEGRA210_CLK_PLL_RE_VCO, TEGRA210_CLK_CLK_MAX, 672000000, 1 },
  2917. { TEGRA210_CLK_PLL_U_OUT1, TEGRA210_CLK_CLK_MAX, 48000000, 1 },
  2918. { TEGRA210_CLK_XUSB_GATE, TEGRA210_CLK_CLK_MAX, 0, 1 },
  2919. { TEGRA210_CLK_XUSB_SS_SRC, TEGRA210_CLK_PLL_U_480M, 120000000, 0 },
  2920. { TEGRA210_CLK_XUSB_FS_SRC, TEGRA210_CLK_PLL_U_48M, 48000000, 0 },
  2921. { TEGRA210_CLK_XUSB_HS_SRC, TEGRA210_CLK_XUSB_SS_SRC, 120000000, 0 },
  2922. { TEGRA210_CLK_XUSB_SSP_SRC, TEGRA210_CLK_XUSB_SS_SRC, 120000000, 0 },
  2923. { TEGRA210_CLK_XUSB_FALCON_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 204000000, 0 },
  2924. { TEGRA210_CLK_XUSB_HOST_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 102000000, 0 },
  2925. { TEGRA210_CLK_XUSB_DEV_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 102000000, 0 },
  2926. { TEGRA210_CLK_SATA, TEGRA210_CLK_PLL_P, 104000000, 0 },
  2927. { TEGRA210_CLK_SATA_OOB, TEGRA210_CLK_PLL_P, 204000000, 0 },
  2928. { TEGRA210_CLK_MSELECT, TEGRA210_CLK_CLK_MAX, 0, 1 },
  2929. { TEGRA210_CLK_CSITE, TEGRA210_CLK_CLK_MAX, 0, 1 },
  2930. /* TODO find a way to enable this on-demand */
  2931. { TEGRA210_CLK_DBGAPB, TEGRA210_CLK_CLK_MAX, 0, 1 },
  2932. { TEGRA210_CLK_TSENSOR, TEGRA210_CLK_CLK_M, 400000, 0 },
  2933. { TEGRA210_CLK_I2C1, TEGRA210_CLK_PLL_P, 0, 0 },
  2934. { TEGRA210_CLK_I2C2, TEGRA210_CLK_PLL_P, 0, 0 },
  2935. { TEGRA210_CLK_I2C3, TEGRA210_CLK_PLL_P, 0, 0 },
  2936. { TEGRA210_CLK_I2C4, TEGRA210_CLK_PLL_P, 0, 0 },
  2937. { TEGRA210_CLK_I2C5, TEGRA210_CLK_PLL_P, 0, 0 },
  2938. { TEGRA210_CLK_I2C6, TEGRA210_CLK_PLL_P, 0, 0 },
  2939. { TEGRA210_CLK_PLL_DP, TEGRA210_CLK_CLK_MAX, 270000000, 0 },
  2940. { TEGRA210_CLK_SOC_THERM, TEGRA210_CLK_PLL_P, 51000000, 0 },
  2941. { TEGRA210_CLK_CCLK_G, TEGRA210_CLK_CLK_MAX, 0, 1 },
  2942. { TEGRA210_CLK_PLL_U_OUT2, TEGRA210_CLK_CLK_MAX, 60000000, 1 },
  2943. { TEGRA210_CLK_SPDIF_IN_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 },
  2944. { TEGRA210_CLK_I2S0_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 },
  2945. { TEGRA210_CLK_I2S1_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 },
  2946. { TEGRA210_CLK_I2S2_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 },
  2947. { TEGRA210_CLK_I2S3_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 },
  2948. { TEGRA210_CLK_I2S4_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 },
  2949. { TEGRA210_CLK_VIMCLK_SYNC, TEGRA210_CLK_CLK_MAX, 24576000, 0 },
  2950. { TEGRA210_CLK_HDA, TEGRA210_CLK_PLL_P, 51000000, 0 },
  2951. { TEGRA210_CLK_HDA2CODEC_2X, TEGRA210_CLK_PLL_P, 48000000, 0 },
  2952. /* This MUST be the last entry. */
  2953. { TEGRA210_CLK_CLK_MAX, TEGRA210_CLK_CLK_MAX, 0, 0 },
  2954. };
  2955. /**
  2956. * tegra210_clock_apply_init_table - initialize clocks on Tegra210 SoCs
  2957. *
  2958. * Program an initial clock rate and enable or disable clocks needed
  2959. * by the rest of the kernel, for Tegra210 SoCs. It is intended to be
  2960. * called by assigning a pointer to it to tegra_clk_apply_init_table -
  2961. * this will be called as an arch_initcall. No return value.
  2962. */
  2963. static void __init tegra210_clock_apply_init_table(void)
  2964. {
  2965. tegra_init_from_table(init_table, clks, TEGRA210_CLK_CLK_MAX);
  2966. }
  2967. /**
  2968. * tegra210_car_barrier - wait for pending writes to the CAR to complete
  2969. *
  2970. * Wait for any outstanding writes to the CAR MMIO space from this CPU
  2971. * to complete before continuing execution. No return value.
  2972. */
  2973. static void tegra210_car_barrier(void)
  2974. {
  2975. readl_relaxed(clk_base + RST_DFLL_DVCO);
  2976. }
  2977. /**
  2978. * tegra210_clock_assert_dfll_dvco_reset - assert the DFLL's DVCO reset
  2979. *
  2980. * Assert the reset line of the DFLL's DVCO. No return value.
  2981. */
  2982. static void tegra210_clock_assert_dfll_dvco_reset(void)
  2983. {
  2984. u32 v;
  2985. v = readl_relaxed(clk_base + RST_DFLL_DVCO);
  2986. v |= (1 << DVFS_DFLL_RESET_SHIFT);
  2987. writel_relaxed(v, clk_base + RST_DFLL_DVCO);
  2988. tegra210_car_barrier();
  2989. }
  2990. /**
  2991. * tegra210_clock_deassert_dfll_dvco_reset - deassert the DFLL's DVCO reset
  2992. *
  2993. * Deassert the reset line of the DFLL's DVCO, allowing the DVCO to
  2994. * operate. No return value.
  2995. */
  2996. static void tegra210_clock_deassert_dfll_dvco_reset(void)
  2997. {
  2998. u32 v;
  2999. v = readl_relaxed(clk_base + RST_DFLL_DVCO);
  3000. v &= ~(1 << DVFS_DFLL_RESET_SHIFT);
  3001. writel_relaxed(v, clk_base + RST_DFLL_DVCO);
  3002. tegra210_car_barrier();
  3003. }
  3004. static int tegra210_reset_assert(unsigned long id)
  3005. {
  3006. if (id == TEGRA210_RST_DFLL_DVCO)
  3007. tegra210_clock_assert_dfll_dvco_reset();
  3008. else if (id == TEGRA210_RST_ADSP)
  3009. writel(GENMASK(26, 21) | BIT(7),
  3010. clk_base + CLK_RST_CONTROLLER_RST_DEV_Y_SET);
  3011. else
  3012. return -EINVAL;
  3013. return 0;
  3014. }
  3015. static int tegra210_reset_deassert(unsigned long id)
  3016. {
  3017. if (id == TEGRA210_RST_DFLL_DVCO)
  3018. tegra210_clock_deassert_dfll_dvco_reset();
  3019. else if (id == TEGRA210_RST_ADSP) {
  3020. writel(BIT(21), clk_base + CLK_RST_CONTROLLER_RST_DEV_Y_CLR);
  3021. /*
  3022. * Considering adsp cpu clock (min: 12.5MHZ, max: 1GHz)
  3023. * a delay of 5us ensures that it's at least
  3024. * 6 * adsp_cpu_cycle_period long.
  3025. */
  3026. udelay(5);
  3027. writel(GENMASK(26, 22) | BIT(7),
  3028. clk_base + CLK_RST_CONTROLLER_RST_DEV_Y_CLR);
  3029. } else
  3030. return -EINVAL;
  3031. return 0;
  3032. }
  3033. static void tegra210_mbist_clk_init(void)
  3034. {
  3035. unsigned int i, j;
  3036. for (i = 0; i < ARRAY_SIZE(tegra210_pg_mbist_war); i++) {
  3037. unsigned int num_clks = tegra210_pg_mbist_war[i].num_clks;
  3038. struct clk_bulk_data *clk_data;
  3039. if (!num_clks)
  3040. continue;
  3041. clk_data = kmalloc_array(num_clks, sizeof(*clk_data),
  3042. GFP_KERNEL);
  3043. if (WARN_ON(!clk_data))
  3044. return;
  3045. tegra210_pg_mbist_war[i].clks = clk_data;
  3046. for (j = 0; j < num_clks; j++) {
  3047. int clk_id = tegra210_pg_mbist_war[i].clk_init_data[j];
  3048. struct clk *clk = clks[clk_id];
  3049. if (WARN(IS_ERR(clk), "clk_id: %d\n", clk_id)) {
  3050. kfree(clk_data);
  3051. tegra210_pg_mbist_war[i].clks = NULL;
  3052. break;
  3053. }
  3054. clk_data[j].clk = clk;
  3055. }
  3056. }
  3057. }
  3058. /**
  3059. * tegra210_clock_init - Tegra210-specific clock initialization
  3060. * @np: struct device_node * of the DT node for the SoC CAR IP block
  3061. *
  3062. * Register most SoC clocks for the Tegra210 system-on-chip. Intended
  3063. * to be called by the OF init code when a DT node with the
  3064. * "nvidia,tegra210-car" string is encountered, and declared with
  3065. * CLK_OF_DECLARE. No return value.
  3066. */
  3067. static void __init tegra210_clock_init(struct device_node *np)
  3068. {
  3069. struct device_node *node;
  3070. u32 value, clk_m_div;
  3071. clk_base = of_iomap(np, 0);
  3072. if (!clk_base) {
  3073. pr_err("ioremap tegra210 CAR failed\n");
  3074. return;
  3075. }
  3076. node = of_find_matching_node(NULL, pmc_match);
  3077. if (!node) {
  3078. pr_err("Failed to find pmc node\n");
  3079. WARN_ON(1);
  3080. return;
  3081. }
  3082. pmc_base = of_iomap(node, 0);
  3083. if (!pmc_base) {
  3084. pr_err("Can't map pmc registers\n");
  3085. WARN_ON(1);
  3086. return;
  3087. }
  3088. ahub_base = ioremap(TEGRA210_AHUB_BASE, SZ_64K);
  3089. if (!ahub_base) {
  3090. pr_err("ioremap tegra210 APE failed\n");
  3091. return;
  3092. }
  3093. dispa_base = ioremap(TEGRA210_DISPA_BASE, SZ_256K);
  3094. if (!dispa_base) {
  3095. pr_err("ioremap tegra210 DISPA failed\n");
  3096. return;
  3097. }
  3098. vic_base = ioremap(TEGRA210_VIC_BASE, SZ_256K);
  3099. if (!vic_base) {
  3100. pr_err("ioremap tegra210 VIC failed\n");
  3101. return;
  3102. }
  3103. clks = tegra_clk_init(clk_base, TEGRA210_CLK_CLK_MAX,
  3104. TEGRA210_CAR_BANK_COUNT);
  3105. if (!clks)
  3106. return;
  3107. value = clk_readl(clk_base + SPARE_REG0) >> CLK_M_DIVISOR_SHIFT;
  3108. clk_m_div = (value & CLK_M_DIVISOR_MASK) + 1;
  3109. if (tegra_osc_clk_init(clk_base, tegra210_clks, tegra210_input_freq,
  3110. ARRAY_SIZE(tegra210_input_freq), clk_m_div,
  3111. &osc_freq, &pll_ref_freq) < 0)
  3112. return;
  3113. tegra_fixed_clk_init(tegra210_clks);
  3114. tegra210_pll_init(clk_base, pmc_base);
  3115. tegra210_periph_clk_init(clk_base, pmc_base);
  3116. tegra_audio_clk_init(clk_base, pmc_base, tegra210_clks,
  3117. tegra210_audio_plls,
  3118. ARRAY_SIZE(tegra210_audio_plls), 24576000);
  3119. tegra_pmc_clk_init(pmc_base, tegra210_clks);
  3120. /* For Tegra210, PLLD is the only source for DSIA & DSIB */
  3121. value = clk_readl(clk_base + PLLD_BASE);
  3122. value &= ~BIT(25);
  3123. clk_writel(value, clk_base + PLLD_BASE);
  3124. tegra_clk_apply_init_table = tegra210_clock_apply_init_table;
  3125. tegra_super_clk_gen5_init(clk_base, pmc_base, tegra210_clks,
  3126. &pll_x_params);
  3127. tegra_init_special_resets(2, tegra210_reset_assert,
  3128. tegra210_reset_deassert);
  3129. tegra_add_of_provider(np, of_clk_src_onecell_get);
  3130. tegra_register_devclks(devclks, ARRAY_SIZE(devclks));
  3131. tegra210_mbist_clk_init();
  3132. tegra_cpu_car_ops = &tegra210_cpu_car_ops;
  3133. }
  3134. CLK_OF_DECLARE(tegra210, "nvidia,tegra210-car", tegra210_clock_init);