clk-tegra210.c 104 KB

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