clk-pll.c 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685
  1. /*
  2. * Copyright (c) 2012, 2013, 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/slab.h>
  17. #include <linux/io.h>
  18. #include <linux/delay.h>
  19. #include <linux/err.h>
  20. #include <linux/clk.h>
  21. #include <linux/clk-provider.h>
  22. #include "clk.h"
  23. #define PLL_BASE_BYPASS BIT(31)
  24. #define PLL_BASE_ENABLE BIT(30)
  25. #define PLL_BASE_REF_ENABLE BIT(29)
  26. #define PLL_BASE_OVERRIDE BIT(28)
  27. #define PLL_BASE_DIVP_SHIFT 20
  28. #define PLL_BASE_DIVP_WIDTH 3
  29. #define PLL_BASE_DIVN_SHIFT 8
  30. #define PLL_BASE_DIVN_WIDTH 10
  31. #define PLL_BASE_DIVM_SHIFT 0
  32. #define PLL_BASE_DIVM_WIDTH 5
  33. #define PLLU_POST_DIVP_MASK 0x1
  34. #define PLL_MISC_DCCON_SHIFT 20
  35. #define PLL_MISC_CPCON_SHIFT 8
  36. #define PLL_MISC_CPCON_WIDTH 4
  37. #define PLL_MISC_CPCON_MASK ((1 << PLL_MISC_CPCON_WIDTH) - 1)
  38. #define PLL_MISC_LFCON_SHIFT 4
  39. #define PLL_MISC_LFCON_WIDTH 4
  40. #define PLL_MISC_LFCON_MASK ((1 << PLL_MISC_LFCON_WIDTH) - 1)
  41. #define PLL_MISC_VCOCON_SHIFT 0
  42. #define PLL_MISC_VCOCON_WIDTH 4
  43. #define PLL_MISC_VCOCON_MASK ((1 << PLL_MISC_VCOCON_WIDTH) - 1)
  44. #define OUT_OF_TABLE_CPCON 8
  45. #define PMC_PLLP_WB0_OVERRIDE 0xf8
  46. #define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE BIT(12)
  47. #define PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE BIT(11)
  48. #define PLL_POST_LOCK_DELAY 50
  49. #define PLLDU_LFCON_SET_DIVN 600
  50. #define PLLE_BASE_DIVCML_SHIFT 24
  51. #define PLLE_BASE_DIVCML_MASK 0xf
  52. #define PLLE_BASE_DIVP_SHIFT 16
  53. #define PLLE_BASE_DIVP_WIDTH 6
  54. #define PLLE_BASE_DIVN_SHIFT 8
  55. #define PLLE_BASE_DIVN_WIDTH 8
  56. #define PLLE_BASE_DIVM_SHIFT 0
  57. #define PLLE_BASE_DIVM_WIDTH 8
  58. #define PLLE_BASE_ENABLE BIT(31)
  59. #define PLLE_MISC_SETUP_BASE_SHIFT 16
  60. #define PLLE_MISC_SETUP_BASE_MASK (0xffff << PLLE_MISC_SETUP_BASE_SHIFT)
  61. #define PLLE_MISC_LOCK_ENABLE BIT(9)
  62. #define PLLE_MISC_READY BIT(15)
  63. #define PLLE_MISC_SETUP_EX_SHIFT 2
  64. #define PLLE_MISC_SETUP_EX_MASK (3 << PLLE_MISC_SETUP_EX_SHIFT)
  65. #define PLLE_MISC_SETUP_MASK (PLLE_MISC_SETUP_BASE_MASK | \
  66. PLLE_MISC_SETUP_EX_MASK)
  67. #define PLLE_MISC_SETUP_VALUE (7 << PLLE_MISC_SETUP_BASE_SHIFT)
  68. #define PLLE_SS_CTRL 0x68
  69. #define PLLE_SS_CNTL_BYPASS_SS BIT(10)
  70. #define PLLE_SS_CNTL_INTERP_RESET BIT(11)
  71. #define PLLE_SS_CNTL_SSC_BYP BIT(12)
  72. #define PLLE_SS_CNTL_CENTER BIT(14)
  73. #define PLLE_SS_CNTL_INVERT BIT(15)
  74. #define PLLE_SS_DISABLE (PLLE_SS_CNTL_BYPASS_SS | PLLE_SS_CNTL_INTERP_RESET |\
  75. PLLE_SS_CNTL_SSC_BYP)
  76. #define PLLE_SS_MAX_MASK 0x1ff
  77. #define PLLE_SS_MAX_VAL_TEGRA114 0x25
  78. #define PLLE_SS_MAX_VAL_TEGRA210 0x21
  79. #define PLLE_SS_INC_MASK (0xff << 16)
  80. #define PLLE_SS_INC_VAL (0x1 << 16)
  81. #define PLLE_SS_INCINTRV_MASK (0x3f << 24)
  82. #define PLLE_SS_INCINTRV_VAL_TEGRA114 (0x20 << 24)
  83. #define PLLE_SS_INCINTRV_VAL_TEGRA210 (0x23 << 24)
  84. #define PLLE_SS_COEFFICIENTS_MASK \
  85. (PLLE_SS_MAX_MASK | PLLE_SS_INC_MASK | PLLE_SS_INCINTRV_MASK)
  86. #define PLLE_SS_COEFFICIENTS_VAL_TEGRA114 \
  87. (PLLE_SS_MAX_VAL_TEGRA114 | PLLE_SS_INC_VAL |\
  88. PLLE_SS_INCINTRV_VAL_TEGRA114)
  89. #define PLLE_SS_COEFFICIENTS_VAL_TEGRA210 \
  90. (PLLE_SS_MAX_VAL_TEGRA210 | PLLE_SS_INC_VAL |\
  91. PLLE_SS_INCINTRV_VAL_TEGRA210)
  92. #define PLLE_AUX_PLLP_SEL BIT(2)
  93. #define PLLE_AUX_USE_LOCKDET BIT(3)
  94. #define PLLE_AUX_ENABLE_SWCTL BIT(4)
  95. #define PLLE_AUX_SS_SWCTL BIT(6)
  96. #define PLLE_AUX_SEQ_ENABLE BIT(24)
  97. #define PLLE_AUX_SEQ_START_STATE BIT(25)
  98. #define PLLE_AUX_PLLRE_SEL BIT(28)
  99. #define PLLE_AUX_SS_SEQ_INCLUDE BIT(31)
  100. #define XUSBIO_PLL_CFG0 0x51c
  101. #define XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0)
  102. #define XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL BIT(2)
  103. #define XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET BIT(6)
  104. #define XUSBIO_PLL_CFG0_SEQ_ENABLE BIT(24)
  105. #define XUSBIO_PLL_CFG0_SEQ_START_STATE BIT(25)
  106. #define SATA_PLL_CFG0 0x490
  107. #define SATA_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0)
  108. #define SATA_PLL_CFG0_PADPLL_USE_LOCKDET BIT(2)
  109. #define SATA_PLL_CFG0_SEQ_ENABLE BIT(24)
  110. #define SATA_PLL_CFG0_SEQ_START_STATE BIT(25)
  111. #define PLLE_MISC_PLLE_PTS BIT(8)
  112. #define PLLE_MISC_IDDQ_SW_VALUE BIT(13)
  113. #define PLLE_MISC_IDDQ_SW_CTRL BIT(14)
  114. #define PLLE_MISC_VREG_BG_CTRL_SHIFT 4
  115. #define PLLE_MISC_VREG_BG_CTRL_MASK (3 << PLLE_MISC_VREG_BG_CTRL_SHIFT)
  116. #define PLLE_MISC_VREG_CTRL_SHIFT 2
  117. #define PLLE_MISC_VREG_CTRL_MASK (2 << PLLE_MISC_VREG_CTRL_SHIFT)
  118. #define PLLCX_MISC_STROBE BIT(31)
  119. #define PLLCX_MISC_RESET BIT(30)
  120. #define PLLCX_MISC_SDM_DIV_SHIFT 28
  121. #define PLLCX_MISC_SDM_DIV_MASK (0x3 << PLLCX_MISC_SDM_DIV_SHIFT)
  122. #define PLLCX_MISC_FILT_DIV_SHIFT 26
  123. #define PLLCX_MISC_FILT_DIV_MASK (0x3 << PLLCX_MISC_FILT_DIV_SHIFT)
  124. #define PLLCX_MISC_ALPHA_SHIFT 18
  125. #define PLLCX_MISC_DIV_LOW_RANGE \
  126. ((0x1 << PLLCX_MISC_SDM_DIV_SHIFT) | \
  127. (0x1 << PLLCX_MISC_FILT_DIV_SHIFT))
  128. #define PLLCX_MISC_DIV_HIGH_RANGE \
  129. ((0x2 << PLLCX_MISC_SDM_DIV_SHIFT) | \
  130. (0x2 << PLLCX_MISC_FILT_DIV_SHIFT))
  131. #define PLLCX_MISC_COEF_LOW_RANGE \
  132. ((0x14 << PLLCX_MISC_KA_SHIFT) | (0x38 << PLLCX_MISC_KB_SHIFT))
  133. #define PLLCX_MISC_KA_SHIFT 2
  134. #define PLLCX_MISC_KB_SHIFT 9
  135. #define PLLCX_MISC_DEFAULT (PLLCX_MISC_COEF_LOW_RANGE | \
  136. (0x19 << PLLCX_MISC_ALPHA_SHIFT) | \
  137. PLLCX_MISC_DIV_LOW_RANGE | \
  138. PLLCX_MISC_RESET)
  139. #define PLLCX_MISC1_DEFAULT 0x000d2308
  140. #define PLLCX_MISC2_DEFAULT 0x30211200
  141. #define PLLCX_MISC3_DEFAULT 0x200
  142. #define PMC_SATA_PWRGT 0x1ac
  143. #define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE BIT(5)
  144. #define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL BIT(4)
  145. #define PLLSS_MISC_KCP 0
  146. #define PLLSS_MISC_KVCO 0
  147. #define PLLSS_MISC_SETUP 0
  148. #define PLLSS_EN_SDM 0
  149. #define PLLSS_EN_SSC 0
  150. #define PLLSS_EN_DITHER2 0
  151. #define PLLSS_EN_DITHER 1
  152. #define PLLSS_SDM_RESET 0
  153. #define PLLSS_CLAMP 0
  154. #define PLLSS_SDM_SSC_MAX 0
  155. #define PLLSS_SDM_SSC_MIN 0
  156. #define PLLSS_SDM_SSC_STEP 0
  157. #define PLLSS_SDM_DIN 0
  158. #define PLLSS_MISC_DEFAULT ((PLLSS_MISC_KCP << 25) | \
  159. (PLLSS_MISC_KVCO << 24) | \
  160. PLLSS_MISC_SETUP)
  161. #define PLLSS_CFG_DEFAULT ((PLLSS_EN_SDM << 31) | \
  162. (PLLSS_EN_SSC << 30) | \
  163. (PLLSS_EN_DITHER2 << 29) | \
  164. (PLLSS_EN_DITHER << 28) | \
  165. (PLLSS_SDM_RESET) << 27 | \
  166. (PLLSS_CLAMP << 22))
  167. #define PLLSS_CTRL1_DEFAULT \
  168. ((PLLSS_SDM_SSC_MAX << 16) | PLLSS_SDM_SSC_MIN)
  169. #define PLLSS_CTRL2_DEFAULT \
  170. ((PLLSS_SDM_SSC_STEP << 16) | PLLSS_SDM_DIN)
  171. #define PLLSS_LOCK_OVERRIDE BIT(24)
  172. #define PLLSS_REF_SRC_SEL_SHIFT 25
  173. #define PLLSS_REF_SRC_SEL_MASK (3 << PLLSS_REF_SRC_SEL_SHIFT)
  174. #define UTMIP_PLL_CFG1 0x484
  175. #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
  176. #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
  177. #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN BIT(12)
  178. #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN BIT(14)
  179. #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP BIT(15)
  180. #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN BIT(16)
  181. #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP BIT(17)
  182. #define UTMIP_PLL_CFG2 0x488
  183. #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xfff) << 6)
  184. #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18)
  185. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN BIT(0)
  186. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP BIT(1)
  187. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN BIT(2)
  188. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP BIT(3)
  189. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN BIT(4)
  190. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERUP BIT(5)
  191. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN BIT(24)
  192. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP BIT(25)
  193. #define UTMIP_PLL_CFG2_PHY_XTAL_CLOCKEN BIT(30)
  194. #define UTMIPLL_HW_PWRDN_CFG0 0x52c
  195. #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL BIT(0)
  196. #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE BIT(1)
  197. #define UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2)
  198. #define UTMIPLL_HW_PWRDN_CFG0_SEQ_IN_SWCTL BIT(4)
  199. #define UTMIPLL_HW_PWRDN_CFG0_SEQ_RESET_INPUT_VALUE BIT(5)
  200. #define UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET BIT(6)
  201. #define UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24)
  202. #define UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE BIT(25)
  203. #define PLLU_HW_PWRDN_CFG0 0x530
  204. #define PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL BIT(0)
  205. #define PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2)
  206. #define PLLU_HW_PWRDN_CFG0_USE_LOCKDET BIT(6)
  207. #define PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT BIT(7)
  208. #define PLLU_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24)
  209. #define PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE BIT(28)
  210. #define XUSB_PLL_CFG0 0x534
  211. #define XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY 0x3ff
  212. #define XUSB_PLL_CFG0_PLLU_LOCK_DLY (0x3ff << 14)
  213. #define PLLU_BASE_CLKENABLE_USB BIT(21)
  214. #define PLLU_BASE_OVERRIDE BIT(24)
  215. #define pll_readl(offset, p) readl_relaxed(p->clk_base + offset)
  216. #define pll_readl_base(p) pll_readl(p->params->base_reg, p)
  217. #define pll_readl_misc(p) pll_readl(p->params->misc_reg, p)
  218. #define pll_override_readl(offset, p) readl_relaxed(p->pmc + offset)
  219. #define pll_readl_sdm_din(p) pll_readl(p->params->sdm_din_reg, p)
  220. #define pll_readl_sdm_ctrl(p) pll_readl(p->params->sdm_ctrl_reg, p)
  221. #define pll_writel(val, offset, p) writel_relaxed(val, p->clk_base + offset)
  222. #define pll_writel_base(val, p) pll_writel(val, p->params->base_reg, p)
  223. #define pll_writel_misc(val, p) pll_writel(val, p->params->misc_reg, p)
  224. #define pll_override_writel(val, offset, p) writel(val, p->pmc + offset)
  225. #define pll_writel_sdm_din(val, p) pll_writel(val, p->params->sdm_din_reg, p)
  226. #define pll_writel_sdm_ctrl(val, p) pll_writel(val, p->params->sdm_ctrl_reg, p)
  227. #define mask(w) ((1 << (w)) - 1)
  228. #define divm_mask(p) mask(p->params->div_nmp->divm_width)
  229. #define divn_mask(p) mask(p->params->div_nmp->divn_width)
  230. #define divp_mask(p) (p->params->flags & TEGRA_PLLU ? PLLU_POST_DIVP_MASK :\
  231. mask(p->params->div_nmp->divp_width))
  232. #define sdm_din_mask(p) p->params->sdm_din_mask
  233. #define sdm_en_mask(p) p->params->sdm_ctrl_en_mask
  234. #define divm_shift(p) (p)->params->div_nmp->divm_shift
  235. #define divn_shift(p) (p)->params->div_nmp->divn_shift
  236. #define divp_shift(p) (p)->params->div_nmp->divp_shift
  237. #define divm_mask_shifted(p) (divm_mask(p) << divm_shift(p))
  238. #define divn_mask_shifted(p) (divn_mask(p) << divn_shift(p))
  239. #define divp_mask_shifted(p) (divp_mask(p) << divp_shift(p))
  240. #define divm_max(p) (divm_mask(p))
  241. #define divn_max(p) (divn_mask(p))
  242. #define divp_max(p) (1 << (divp_mask(p)))
  243. #define sdin_din_to_data(din) ((u16)((din) ? : 0xFFFFU))
  244. #define sdin_data_to_din(dat) (((dat) == 0xFFFFU) ? 0 : (s16)dat)
  245. static struct div_nmp default_nmp = {
  246. .divn_shift = PLL_BASE_DIVN_SHIFT,
  247. .divn_width = PLL_BASE_DIVN_WIDTH,
  248. .divm_shift = PLL_BASE_DIVM_SHIFT,
  249. .divm_width = PLL_BASE_DIVM_WIDTH,
  250. .divp_shift = PLL_BASE_DIVP_SHIFT,
  251. .divp_width = PLL_BASE_DIVP_WIDTH,
  252. };
  253. static void clk_pll_enable_lock(struct tegra_clk_pll *pll)
  254. {
  255. u32 val;
  256. if (!(pll->params->flags & TEGRA_PLL_USE_LOCK))
  257. return;
  258. if (!(pll->params->flags & TEGRA_PLL_HAS_LOCK_ENABLE))
  259. return;
  260. val = pll_readl_misc(pll);
  261. val |= BIT(pll->params->lock_enable_bit_idx);
  262. pll_writel_misc(val, pll);
  263. }
  264. static int clk_pll_wait_for_lock(struct tegra_clk_pll *pll)
  265. {
  266. int i;
  267. u32 val, lock_mask;
  268. void __iomem *lock_addr;
  269. if (!(pll->params->flags & TEGRA_PLL_USE_LOCK)) {
  270. udelay(pll->params->lock_delay);
  271. return 0;
  272. }
  273. lock_addr = pll->clk_base;
  274. if (pll->params->flags & TEGRA_PLL_LOCK_MISC)
  275. lock_addr += pll->params->misc_reg;
  276. else
  277. lock_addr += pll->params->base_reg;
  278. lock_mask = pll->params->lock_mask;
  279. for (i = 0; i < pll->params->lock_delay; i++) {
  280. val = readl_relaxed(lock_addr);
  281. if ((val & lock_mask) == lock_mask) {
  282. udelay(PLL_POST_LOCK_DELAY);
  283. return 0;
  284. }
  285. udelay(2); /* timeout = 2 * lock time */
  286. }
  287. pr_err("%s: Timed out waiting for pll %s lock\n", __func__,
  288. clk_hw_get_name(&pll->hw));
  289. return -1;
  290. }
  291. int tegra_pll_wait_for_lock(struct tegra_clk_pll *pll)
  292. {
  293. return clk_pll_wait_for_lock(pll);
  294. }
  295. static int clk_pll_is_enabled(struct clk_hw *hw)
  296. {
  297. struct tegra_clk_pll *pll = to_clk_pll(hw);
  298. u32 val;
  299. if (pll->params->flags & TEGRA_PLLM) {
  300. val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE);
  301. if (val & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE)
  302. return val & PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE ? 1 : 0;
  303. }
  304. val = pll_readl_base(pll);
  305. return val & PLL_BASE_ENABLE ? 1 : 0;
  306. }
  307. static void _clk_pll_enable(struct clk_hw *hw)
  308. {
  309. struct tegra_clk_pll *pll = to_clk_pll(hw);
  310. u32 val;
  311. if (pll->params->iddq_reg) {
  312. val = pll_readl(pll->params->iddq_reg, pll);
  313. val &= ~BIT(pll->params->iddq_bit_idx);
  314. pll_writel(val, pll->params->iddq_reg, pll);
  315. udelay(5);
  316. }
  317. if (pll->params->reset_reg) {
  318. val = pll_readl(pll->params->reset_reg, pll);
  319. val &= ~BIT(pll->params->reset_bit_idx);
  320. pll_writel(val, pll->params->reset_reg, pll);
  321. }
  322. clk_pll_enable_lock(pll);
  323. val = pll_readl_base(pll);
  324. if (pll->params->flags & TEGRA_PLL_BYPASS)
  325. val &= ~PLL_BASE_BYPASS;
  326. val |= PLL_BASE_ENABLE;
  327. pll_writel_base(val, pll);
  328. if (pll->params->flags & TEGRA_PLLM) {
  329. val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE);
  330. val |= PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE;
  331. writel_relaxed(val, pll->pmc + PMC_PLLP_WB0_OVERRIDE);
  332. }
  333. }
  334. static void _clk_pll_disable(struct clk_hw *hw)
  335. {
  336. struct tegra_clk_pll *pll = to_clk_pll(hw);
  337. u32 val;
  338. val = pll_readl_base(pll);
  339. if (pll->params->flags & TEGRA_PLL_BYPASS)
  340. val &= ~PLL_BASE_BYPASS;
  341. val &= ~PLL_BASE_ENABLE;
  342. pll_writel_base(val, pll);
  343. if (pll->params->flags & TEGRA_PLLM) {
  344. val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE);
  345. val &= ~PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE;
  346. writel_relaxed(val, pll->pmc + PMC_PLLP_WB0_OVERRIDE);
  347. }
  348. if (pll->params->reset_reg) {
  349. val = pll_readl(pll->params->reset_reg, pll);
  350. val |= BIT(pll->params->reset_bit_idx);
  351. pll_writel(val, pll->params->reset_reg, pll);
  352. }
  353. if (pll->params->iddq_reg) {
  354. val = pll_readl(pll->params->iddq_reg, pll);
  355. val |= BIT(pll->params->iddq_bit_idx);
  356. pll_writel(val, pll->params->iddq_reg, pll);
  357. udelay(2);
  358. }
  359. }
  360. static void pll_clk_start_ss(struct tegra_clk_pll *pll)
  361. {
  362. if (pll->params->defaults_set && pll->params->ssc_ctrl_reg) {
  363. u32 val = pll_readl(pll->params->ssc_ctrl_reg, pll);
  364. val |= pll->params->ssc_ctrl_en_mask;
  365. pll_writel(val, pll->params->ssc_ctrl_reg, pll);
  366. }
  367. }
  368. static void pll_clk_stop_ss(struct tegra_clk_pll *pll)
  369. {
  370. if (pll->params->defaults_set && pll->params->ssc_ctrl_reg) {
  371. u32 val = pll_readl(pll->params->ssc_ctrl_reg, pll);
  372. val &= ~pll->params->ssc_ctrl_en_mask;
  373. pll_writel(val, pll->params->ssc_ctrl_reg, pll);
  374. }
  375. }
  376. static int clk_pll_enable(struct clk_hw *hw)
  377. {
  378. struct tegra_clk_pll *pll = to_clk_pll(hw);
  379. unsigned long flags = 0;
  380. int ret;
  381. if (pll->lock)
  382. spin_lock_irqsave(pll->lock, flags);
  383. _clk_pll_enable(hw);
  384. ret = clk_pll_wait_for_lock(pll);
  385. pll_clk_start_ss(pll);
  386. if (pll->lock)
  387. spin_unlock_irqrestore(pll->lock, flags);
  388. return ret;
  389. }
  390. static void clk_pll_disable(struct clk_hw *hw)
  391. {
  392. struct tegra_clk_pll *pll = to_clk_pll(hw);
  393. unsigned long flags = 0;
  394. if (pll->lock)
  395. spin_lock_irqsave(pll->lock, flags);
  396. pll_clk_stop_ss(pll);
  397. _clk_pll_disable(hw);
  398. if (pll->lock)
  399. spin_unlock_irqrestore(pll->lock, flags);
  400. }
  401. static int _p_div_to_hw(struct clk_hw *hw, u8 p_div)
  402. {
  403. struct tegra_clk_pll *pll = to_clk_pll(hw);
  404. const struct pdiv_map *p_tohw = pll->params->pdiv_tohw;
  405. if (p_tohw) {
  406. while (p_tohw->pdiv) {
  407. if (p_div <= p_tohw->pdiv)
  408. return p_tohw->hw_val;
  409. p_tohw++;
  410. }
  411. return -EINVAL;
  412. }
  413. return -EINVAL;
  414. }
  415. int tegra_pll_p_div_to_hw(struct tegra_clk_pll *pll, u8 p_div)
  416. {
  417. return _p_div_to_hw(&pll->hw, p_div);
  418. }
  419. static int _hw_to_p_div(struct clk_hw *hw, u8 p_div_hw)
  420. {
  421. struct tegra_clk_pll *pll = to_clk_pll(hw);
  422. const struct pdiv_map *p_tohw = pll->params->pdiv_tohw;
  423. if (p_tohw) {
  424. while (p_tohw->pdiv) {
  425. if (p_div_hw == p_tohw->hw_val)
  426. return p_tohw->pdiv;
  427. p_tohw++;
  428. }
  429. return -EINVAL;
  430. }
  431. return 1 << p_div_hw;
  432. }
  433. static int _get_table_rate(struct clk_hw *hw,
  434. struct tegra_clk_pll_freq_table *cfg,
  435. unsigned long rate, unsigned long parent_rate)
  436. {
  437. struct tegra_clk_pll *pll = to_clk_pll(hw);
  438. struct tegra_clk_pll_freq_table *sel;
  439. int p;
  440. for (sel = pll->params->freq_table; sel->input_rate != 0; sel++)
  441. if (sel->input_rate == parent_rate &&
  442. sel->output_rate == rate)
  443. break;
  444. if (sel->input_rate == 0)
  445. return -EINVAL;
  446. if (pll->params->pdiv_tohw) {
  447. p = _p_div_to_hw(hw, sel->p);
  448. if (p < 0)
  449. return p;
  450. } else {
  451. p = ilog2(sel->p);
  452. }
  453. cfg->input_rate = sel->input_rate;
  454. cfg->output_rate = sel->output_rate;
  455. cfg->m = sel->m;
  456. cfg->n = sel->n;
  457. cfg->p = p;
  458. cfg->cpcon = sel->cpcon;
  459. cfg->sdm_data = sel->sdm_data;
  460. return 0;
  461. }
  462. static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
  463. unsigned long rate, unsigned long parent_rate)
  464. {
  465. struct tegra_clk_pll *pll = to_clk_pll(hw);
  466. unsigned long cfreq;
  467. u32 p_div = 0;
  468. int ret;
  469. switch (parent_rate) {
  470. case 12000000:
  471. case 26000000:
  472. cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2000000;
  473. break;
  474. case 13000000:
  475. cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2600000;
  476. break;
  477. case 16800000:
  478. case 19200000:
  479. cfreq = (rate <= 1200000 * 1000) ? 1200000 : 2400000;
  480. break;
  481. case 9600000:
  482. case 28800000:
  483. /*
  484. * PLL_P_OUT1 rate is not listed in PLLA table
  485. */
  486. cfreq = parent_rate / (parent_rate / 1000000);
  487. break;
  488. default:
  489. pr_err("%s Unexpected reference rate %lu\n",
  490. __func__, parent_rate);
  491. BUG();
  492. }
  493. /* Raise VCO to guarantee 0.5% accuracy */
  494. for (cfg->output_rate = rate; cfg->output_rate < 200 * cfreq;
  495. cfg->output_rate <<= 1)
  496. p_div++;
  497. cfg->m = parent_rate / cfreq;
  498. cfg->n = cfg->output_rate / cfreq;
  499. cfg->cpcon = OUT_OF_TABLE_CPCON;
  500. if (cfg->m > divm_max(pll) || cfg->n > divn_max(pll) ||
  501. (1 << p_div) > divp_max(pll)
  502. || cfg->output_rate > pll->params->vco_max) {
  503. return -EINVAL;
  504. }
  505. cfg->output_rate >>= p_div;
  506. if (pll->params->pdiv_tohw) {
  507. ret = _p_div_to_hw(hw, 1 << p_div);
  508. if (ret < 0)
  509. return ret;
  510. else
  511. cfg->p = ret;
  512. } else
  513. cfg->p = p_div;
  514. return 0;
  515. }
  516. /*
  517. * SDM (Sigma Delta Modulator) divisor is 16-bit 2's complement signed number
  518. * within (-2^12 ... 2^12-1) range. Represented in PLL data structure as
  519. * unsigned 16-bit value, with "0" divisor mapped to 0xFFFF. Data "0" is used
  520. * to indicate that SDM is disabled.
  521. *
  522. * Effective ndiv value when SDM is enabled: ndiv + 1/2 + sdm_din/2^13
  523. */
  524. static void clk_pll_set_sdm_data(struct clk_hw *hw,
  525. struct tegra_clk_pll_freq_table *cfg)
  526. {
  527. struct tegra_clk_pll *pll = to_clk_pll(hw);
  528. u32 val;
  529. bool enabled;
  530. if (!pll->params->sdm_din_reg)
  531. return;
  532. if (cfg->sdm_data) {
  533. val = pll_readl_sdm_din(pll) & (~sdm_din_mask(pll));
  534. val |= sdin_data_to_din(cfg->sdm_data) & sdm_din_mask(pll);
  535. pll_writel_sdm_din(val, pll);
  536. }
  537. val = pll_readl_sdm_ctrl(pll);
  538. enabled = (val & sdm_en_mask(pll));
  539. if (cfg->sdm_data == 0 && enabled)
  540. val &= ~pll->params->sdm_ctrl_en_mask;
  541. if (cfg->sdm_data != 0 && !enabled)
  542. val |= pll->params->sdm_ctrl_en_mask;
  543. pll_writel_sdm_ctrl(val, pll);
  544. }
  545. static void _update_pll_mnp(struct tegra_clk_pll *pll,
  546. struct tegra_clk_pll_freq_table *cfg)
  547. {
  548. u32 val;
  549. struct tegra_clk_pll_params *params = pll->params;
  550. struct div_nmp *div_nmp = params->div_nmp;
  551. if ((params->flags & (TEGRA_PLLM | TEGRA_PLLMB)) &&
  552. (pll_override_readl(PMC_PLLP_WB0_OVERRIDE, pll) &
  553. PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE)) {
  554. val = pll_override_readl(params->pmc_divp_reg, pll);
  555. val &= ~(divp_mask(pll) << div_nmp->override_divp_shift);
  556. val |= cfg->p << div_nmp->override_divp_shift;
  557. pll_override_writel(val, params->pmc_divp_reg, pll);
  558. val = pll_override_readl(params->pmc_divnm_reg, pll);
  559. val &= ~(divm_mask(pll) << div_nmp->override_divm_shift) |
  560. ~(divn_mask(pll) << div_nmp->override_divn_shift);
  561. val |= (cfg->m << div_nmp->override_divm_shift) |
  562. (cfg->n << div_nmp->override_divn_shift);
  563. pll_override_writel(val, params->pmc_divnm_reg, pll);
  564. } else {
  565. val = pll_readl_base(pll);
  566. val &= ~(divm_mask_shifted(pll) | divn_mask_shifted(pll) |
  567. divp_mask_shifted(pll));
  568. val |= (cfg->m << divm_shift(pll)) |
  569. (cfg->n << divn_shift(pll)) |
  570. (cfg->p << divp_shift(pll));
  571. pll_writel_base(val, pll);
  572. clk_pll_set_sdm_data(&pll->hw, cfg);
  573. }
  574. }
  575. static void _get_pll_mnp(struct tegra_clk_pll *pll,
  576. struct tegra_clk_pll_freq_table *cfg)
  577. {
  578. u32 val;
  579. struct tegra_clk_pll_params *params = pll->params;
  580. struct div_nmp *div_nmp = params->div_nmp;
  581. *cfg = (struct tegra_clk_pll_freq_table) { };
  582. if ((params->flags & (TEGRA_PLLM | TEGRA_PLLMB)) &&
  583. (pll_override_readl(PMC_PLLP_WB0_OVERRIDE, pll) &
  584. PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE)) {
  585. val = pll_override_readl(params->pmc_divp_reg, pll);
  586. cfg->p = (val >> div_nmp->override_divp_shift) & divp_mask(pll);
  587. val = pll_override_readl(params->pmc_divnm_reg, pll);
  588. cfg->m = (val >> div_nmp->override_divm_shift) & divm_mask(pll);
  589. cfg->n = (val >> div_nmp->override_divn_shift) & divn_mask(pll);
  590. } else {
  591. val = pll_readl_base(pll);
  592. cfg->m = (val >> div_nmp->divm_shift) & divm_mask(pll);
  593. cfg->n = (val >> div_nmp->divn_shift) & divn_mask(pll);
  594. cfg->p = (val >> div_nmp->divp_shift) & divp_mask(pll);
  595. if (pll->params->sdm_din_reg) {
  596. if (sdm_en_mask(pll) & pll_readl_sdm_ctrl(pll)) {
  597. val = pll_readl_sdm_din(pll);
  598. val &= sdm_din_mask(pll);
  599. cfg->sdm_data = sdin_din_to_data(val);
  600. }
  601. }
  602. }
  603. }
  604. static void _update_pll_cpcon(struct tegra_clk_pll *pll,
  605. struct tegra_clk_pll_freq_table *cfg,
  606. unsigned long rate)
  607. {
  608. u32 val;
  609. val = pll_readl_misc(pll);
  610. val &= ~(PLL_MISC_CPCON_MASK << PLL_MISC_CPCON_SHIFT);
  611. val |= cfg->cpcon << PLL_MISC_CPCON_SHIFT;
  612. if (pll->params->flags & TEGRA_PLL_SET_LFCON) {
  613. val &= ~(PLL_MISC_LFCON_MASK << PLL_MISC_LFCON_SHIFT);
  614. if (cfg->n >= PLLDU_LFCON_SET_DIVN)
  615. val |= 1 << PLL_MISC_LFCON_SHIFT;
  616. } else if (pll->params->flags & TEGRA_PLL_SET_DCCON) {
  617. val &= ~(1 << PLL_MISC_DCCON_SHIFT);
  618. if (rate >= (pll->params->vco_max >> 1))
  619. val |= 1 << PLL_MISC_DCCON_SHIFT;
  620. }
  621. pll_writel_misc(val, pll);
  622. }
  623. static int _program_pll(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
  624. unsigned long rate)
  625. {
  626. struct tegra_clk_pll *pll = to_clk_pll(hw);
  627. struct tegra_clk_pll_freq_table old_cfg;
  628. int state, ret = 0;
  629. state = clk_pll_is_enabled(hw);
  630. _get_pll_mnp(pll, &old_cfg);
  631. if (state && pll->params->defaults_set && pll->params->dyn_ramp &&
  632. (cfg->m == old_cfg.m) && (cfg->p == old_cfg.p)) {
  633. ret = pll->params->dyn_ramp(pll, cfg);
  634. if (!ret)
  635. return 0;
  636. }
  637. if (state) {
  638. pll_clk_stop_ss(pll);
  639. _clk_pll_disable(hw);
  640. }
  641. if (!pll->params->defaults_set && pll->params->set_defaults)
  642. pll->params->set_defaults(pll);
  643. _update_pll_mnp(pll, cfg);
  644. if (pll->params->flags & TEGRA_PLL_HAS_CPCON)
  645. _update_pll_cpcon(pll, cfg, rate);
  646. if (state) {
  647. _clk_pll_enable(hw);
  648. ret = clk_pll_wait_for_lock(pll);
  649. pll_clk_start_ss(pll);
  650. }
  651. return ret;
  652. }
  653. static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
  654. unsigned long parent_rate)
  655. {
  656. struct tegra_clk_pll *pll = to_clk_pll(hw);
  657. struct tegra_clk_pll_freq_table cfg, old_cfg;
  658. unsigned long flags = 0;
  659. int ret = 0;
  660. if (pll->params->flags & TEGRA_PLL_FIXED) {
  661. if (rate != pll->params->fixed_rate) {
  662. pr_err("%s: Can not change %s fixed rate %lu to %lu\n",
  663. __func__, clk_hw_get_name(hw),
  664. pll->params->fixed_rate, rate);
  665. return -EINVAL;
  666. }
  667. return 0;
  668. }
  669. if (_get_table_rate(hw, &cfg, rate, parent_rate) &&
  670. pll->params->calc_rate(hw, &cfg, rate, parent_rate)) {
  671. pr_err("%s: Failed to set %s rate %lu\n", __func__,
  672. clk_hw_get_name(hw), rate);
  673. WARN_ON(1);
  674. return -EINVAL;
  675. }
  676. if (pll->lock)
  677. spin_lock_irqsave(pll->lock, flags);
  678. _get_pll_mnp(pll, &old_cfg);
  679. if (pll->params->flags & TEGRA_PLL_VCO_OUT)
  680. cfg.p = old_cfg.p;
  681. if (old_cfg.m != cfg.m || old_cfg.n != cfg.n || old_cfg.p != cfg.p ||
  682. old_cfg.sdm_data != cfg.sdm_data)
  683. ret = _program_pll(hw, &cfg, rate);
  684. if (pll->lock)
  685. spin_unlock_irqrestore(pll->lock, flags);
  686. return ret;
  687. }
  688. static long clk_pll_round_rate(struct clk_hw *hw, unsigned long rate,
  689. unsigned long *prate)
  690. {
  691. struct tegra_clk_pll *pll = to_clk_pll(hw);
  692. struct tegra_clk_pll_freq_table cfg;
  693. if (pll->params->flags & TEGRA_PLL_FIXED) {
  694. /* PLLM/MB are used for memory; we do not change rate */
  695. if (pll->params->flags & (TEGRA_PLLM | TEGRA_PLLMB))
  696. return clk_hw_get_rate(hw);
  697. return pll->params->fixed_rate;
  698. }
  699. if (_get_table_rate(hw, &cfg, rate, *prate) &&
  700. pll->params->calc_rate(hw, &cfg, rate, *prate))
  701. return -EINVAL;
  702. return cfg.output_rate;
  703. }
  704. static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
  705. unsigned long parent_rate)
  706. {
  707. struct tegra_clk_pll *pll = to_clk_pll(hw);
  708. struct tegra_clk_pll_freq_table cfg;
  709. u32 val;
  710. u64 rate = parent_rate;
  711. int pdiv;
  712. val = pll_readl_base(pll);
  713. if ((pll->params->flags & TEGRA_PLL_BYPASS) && (val & PLL_BASE_BYPASS))
  714. return parent_rate;
  715. if ((pll->params->flags & TEGRA_PLL_FIXED) &&
  716. !(pll->params->flags & (TEGRA_PLLM | TEGRA_PLLMB)) &&
  717. !(val & PLL_BASE_OVERRIDE)) {
  718. struct tegra_clk_pll_freq_table sel;
  719. if (_get_table_rate(hw, &sel, pll->params->fixed_rate,
  720. parent_rate)) {
  721. pr_err("Clock %s has unknown fixed frequency\n",
  722. clk_hw_get_name(hw));
  723. BUG();
  724. }
  725. return pll->params->fixed_rate;
  726. }
  727. _get_pll_mnp(pll, &cfg);
  728. if (pll->params->flags & TEGRA_PLL_VCO_OUT) {
  729. pdiv = 1;
  730. } else {
  731. pdiv = _hw_to_p_div(hw, cfg.p);
  732. if (pdiv < 0) {
  733. WARN(1, "Clock %s has invalid pdiv value : 0x%x\n",
  734. clk_hw_get_name(hw), cfg.p);
  735. pdiv = 1;
  736. }
  737. }
  738. if (pll->params->set_gain)
  739. pll->params->set_gain(&cfg);
  740. cfg.m *= pdiv;
  741. rate *= cfg.n;
  742. do_div(rate, cfg.m);
  743. return rate;
  744. }
  745. static int clk_plle_training(struct tegra_clk_pll *pll)
  746. {
  747. u32 val;
  748. unsigned long timeout;
  749. if (!pll->pmc)
  750. return -ENOSYS;
  751. /*
  752. * PLLE is already disabled, and setup cleared;
  753. * create falling edge on PLLE IDDQ input.
  754. */
  755. val = readl(pll->pmc + PMC_SATA_PWRGT);
  756. val |= PMC_SATA_PWRGT_PLLE_IDDQ_VALUE;
  757. writel(val, pll->pmc + PMC_SATA_PWRGT);
  758. val = readl(pll->pmc + PMC_SATA_PWRGT);
  759. val |= PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL;
  760. writel(val, pll->pmc + PMC_SATA_PWRGT);
  761. val = readl(pll->pmc + PMC_SATA_PWRGT);
  762. val &= ~PMC_SATA_PWRGT_PLLE_IDDQ_VALUE;
  763. writel(val, pll->pmc + PMC_SATA_PWRGT);
  764. val = pll_readl_misc(pll);
  765. timeout = jiffies + msecs_to_jiffies(100);
  766. while (1) {
  767. val = pll_readl_misc(pll);
  768. if (val & PLLE_MISC_READY)
  769. break;
  770. if (time_after(jiffies, timeout)) {
  771. pr_err("%s: timeout waiting for PLLE\n", __func__);
  772. return -EBUSY;
  773. }
  774. udelay(300);
  775. }
  776. return 0;
  777. }
  778. static int clk_plle_enable(struct clk_hw *hw)
  779. {
  780. struct tegra_clk_pll *pll = to_clk_pll(hw);
  781. unsigned long input_rate = clk_hw_get_rate(clk_hw_get_parent(hw));
  782. struct tegra_clk_pll_freq_table sel;
  783. u32 val;
  784. int err;
  785. if (_get_table_rate(hw, &sel, pll->params->fixed_rate, input_rate))
  786. return -EINVAL;
  787. clk_pll_disable(hw);
  788. val = pll_readl_misc(pll);
  789. val &= ~(PLLE_MISC_LOCK_ENABLE | PLLE_MISC_SETUP_MASK);
  790. pll_writel_misc(val, pll);
  791. val = pll_readl_misc(pll);
  792. if (!(val & PLLE_MISC_READY)) {
  793. err = clk_plle_training(pll);
  794. if (err)
  795. return err;
  796. }
  797. if (pll->params->flags & TEGRA_PLLE_CONFIGURE) {
  798. /* configure dividers */
  799. val = pll_readl_base(pll);
  800. val &= ~(divp_mask_shifted(pll) | divn_mask_shifted(pll) |
  801. divm_mask_shifted(pll));
  802. val &= ~(PLLE_BASE_DIVCML_MASK << PLLE_BASE_DIVCML_SHIFT);
  803. val |= sel.m << divm_shift(pll);
  804. val |= sel.n << divn_shift(pll);
  805. val |= sel.p << divp_shift(pll);
  806. val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT;
  807. pll_writel_base(val, pll);
  808. }
  809. val = pll_readl_misc(pll);
  810. val |= PLLE_MISC_SETUP_VALUE;
  811. val |= PLLE_MISC_LOCK_ENABLE;
  812. pll_writel_misc(val, pll);
  813. val = readl(pll->clk_base + PLLE_SS_CTRL);
  814. val &= ~PLLE_SS_COEFFICIENTS_MASK;
  815. val |= PLLE_SS_DISABLE;
  816. writel(val, pll->clk_base + PLLE_SS_CTRL);
  817. val = pll_readl_base(pll);
  818. val |= (PLL_BASE_BYPASS | PLL_BASE_ENABLE);
  819. pll_writel_base(val, pll);
  820. clk_pll_wait_for_lock(pll);
  821. return 0;
  822. }
  823. static unsigned long clk_plle_recalc_rate(struct clk_hw *hw,
  824. unsigned long parent_rate)
  825. {
  826. struct tegra_clk_pll *pll = to_clk_pll(hw);
  827. u32 val = pll_readl_base(pll);
  828. u32 divn = 0, divm = 0, divp = 0;
  829. u64 rate = parent_rate;
  830. divp = (val >> pll->params->div_nmp->divp_shift) & (divp_mask(pll));
  831. divn = (val >> pll->params->div_nmp->divn_shift) & (divn_mask(pll));
  832. divm = (val >> pll->params->div_nmp->divm_shift) & (divm_mask(pll));
  833. divm *= divp;
  834. rate *= divn;
  835. do_div(rate, divm);
  836. return rate;
  837. }
  838. const struct clk_ops tegra_clk_pll_ops = {
  839. .is_enabled = clk_pll_is_enabled,
  840. .enable = clk_pll_enable,
  841. .disable = clk_pll_disable,
  842. .recalc_rate = clk_pll_recalc_rate,
  843. .round_rate = clk_pll_round_rate,
  844. .set_rate = clk_pll_set_rate,
  845. };
  846. const struct clk_ops tegra_clk_plle_ops = {
  847. .recalc_rate = clk_plle_recalc_rate,
  848. .is_enabled = clk_pll_is_enabled,
  849. .disable = clk_pll_disable,
  850. .enable = clk_plle_enable,
  851. };
  852. /*
  853. * Structure defining the fields for USB UTMI clocks Parameters.
  854. */
  855. struct utmi_clk_param {
  856. /* Oscillator Frequency in Hz */
  857. u32 osc_frequency;
  858. /* UTMIP PLL Enable Delay Count */
  859. u8 enable_delay_count;
  860. /* UTMIP PLL Stable count */
  861. u8 stable_count;
  862. /* UTMIP PLL Active delay count */
  863. u8 active_delay_count;
  864. /* UTMIP PLL Xtal frequency count */
  865. u8 xtal_freq_count;
  866. };
  867. static const struct utmi_clk_param utmi_parameters[] = {
  868. {
  869. .osc_frequency = 13000000, .enable_delay_count = 0x02,
  870. .stable_count = 0x33, .active_delay_count = 0x05,
  871. .xtal_freq_count = 0x7f
  872. }, {
  873. .osc_frequency = 19200000, .enable_delay_count = 0x03,
  874. .stable_count = 0x4b, .active_delay_count = 0x06,
  875. .xtal_freq_count = 0xbb
  876. }, {
  877. .osc_frequency = 12000000, .enable_delay_count = 0x02,
  878. .stable_count = 0x2f, .active_delay_count = 0x04,
  879. .xtal_freq_count = 0x76
  880. }, {
  881. .osc_frequency = 26000000, .enable_delay_count = 0x04,
  882. .stable_count = 0x66, .active_delay_count = 0x09,
  883. .xtal_freq_count = 0xfe
  884. }, {
  885. .osc_frequency = 16800000, .enable_delay_count = 0x03,
  886. .stable_count = 0x41, .active_delay_count = 0x0a,
  887. .xtal_freq_count = 0xa4
  888. }, {
  889. .osc_frequency = 38400000, .enable_delay_count = 0x0,
  890. .stable_count = 0x0, .active_delay_count = 0x6,
  891. .xtal_freq_count = 0x80
  892. },
  893. };
  894. static int clk_pllu_enable(struct clk_hw *hw)
  895. {
  896. struct tegra_clk_pll *pll = to_clk_pll(hw);
  897. struct clk_hw *pll_ref = clk_hw_get_parent(hw);
  898. struct clk_hw *osc = clk_hw_get_parent(pll_ref);
  899. const struct utmi_clk_param *params = NULL;
  900. unsigned long flags = 0, input_rate;
  901. unsigned int i;
  902. int ret = 0;
  903. u32 value;
  904. if (!osc) {
  905. pr_err("%s: failed to get OSC clock\n", __func__);
  906. return -EINVAL;
  907. }
  908. input_rate = clk_hw_get_rate(osc);
  909. if (pll->lock)
  910. spin_lock_irqsave(pll->lock, flags);
  911. _clk_pll_enable(hw);
  912. ret = clk_pll_wait_for_lock(pll);
  913. if (ret < 0)
  914. goto out;
  915. for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) {
  916. if (input_rate == utmi_parameters[i].osc_frequency) {
  917. params = &utmi_parameters[i];
  918. break;
  919. }
  920. }
  921. if (!params) {
  922. pr_err("%s: unexpected input rate %lu Hz\n", __func__,
  923. input_rate);
  924. ret = -EINVAL;
  925. goto out;
  926. }
  927. value = pll_readl_base(pll);
  928. value &= ~PLLU_BASE_OVERRIDE;
  929. pll_writel_base(value, pll);
  930. value = readl_relaxed(pll->clk_base + UTMIP_PLL_CFG2);
  931. /* Program UTMIP PLL stable and active counts */
  932. value &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0);
  933. value |= UTMIP_PLL_CFG2_STABLE_COUNT(params->stable_count);
  934. value &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0);
  935. value |= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(params->active_delay_count);
  936. /* Remove power downs from UTMIP PLL control bits */
  937. value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN;
  938. value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN;
  939. value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN;
  940. writel_relaxed(value, pll->clk_base + UTMIP_PLL_CFG2);
  941. value = readl_relaxed(pll->clk_base + UTMIP_PLL_CFG1);
  942. /* Program UTMIP PLL delay and oscillator frequency counts */
  943. value &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0);
  944. value |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(params->enable_delay_count);
  945. value &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0);
  946. value |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(params->xtal_freq_count);
  947. /* Remove power downs from UTMIP PLL control bits */
  948. value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
  949. value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN;
  950. value &= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN;
  951. writel_relaxed(value, pll->clk_base + UTMIP_PLL_CFG1);
  952. out:
  953. if (pll->lock)
  954. spin_unlock_irqrestore(pll->lock, flags);
  955. return ret;
  956. }
  957. static const struct clk_ops tegra_clk_pllu_ops = {
  958. .is_enabled = clk_pll_is_enabled,
  959. .enable = clk_pllu_enable,
  960. .disable = clk_pll_disable,
  961. .recalc_rate = clk_pll_recalc_rate,
  962. };
  963. static int _pll_fixed_mdiv(struct tegra_clk_pll_params *pll_params,
  964. unsigned long parent_rate)
  965. {
  966. u16 mdiv = parent_rate / pll_params->cf_min;
  967. if (pll_params->flags & TEGRA_MDIV_NEW)
  968. return (!pll_params->mdiv_default ? mdiv :
  969. min(mdiv, pll_params->mdiv_default));
  970. if (pll_params->mdiv_default)
  971. return pll_params->mdiv_default;
  972. if (parent_rate > pll_params->cf_max)
  973. return 2;
  974. else
  975. return 1;
  976. }
  977. static int _calc_dynamic_ramp_rate(struct clk_hw *hw,
  978. struct tegra_clk_pll_freq_table *cfg,
  979. unsigned long rate, unsigned long parent_rate)
  980. {
  981. struct tegra_clk_pll *pll = to_clk_pll(hw);
  982. unsigned int p;
  983. int p_div;
  984. if (!rate)
  985. return -EINVAL;
  986. p = DIV_ROUND_UP(pll->params->vco_min, rate);
  987. cfg->m = _pll_fixed_mdiv(pll->params, parent_rate);
  988. cfg->output_rate = rate * p;
  989. cfg->n = cfg->output_rate * cfg->m / parent_rate;
  990. cfg->input_rate = parent_rate;
  991. p_div = _p_div_to_hw(hw, p);
  992. if (p_div < 0)
  993. return p_div;
  994. cfg->p = p_div;
  995. if (cfg->n > divn_max(pll) || cfg->output_rate > pll->params->vco_max)
  996. return -EINVAL;
  997. return 0;
  998. }
  999. #if defined(CONFIG_ARCH_TEGRA_114_SOC) || \
  1000. defined(CONFIG_ARCH_TEGRA_124_SOC) || \
  1001. defined(CONFIG_ARCH_TEGRA_132_SOC) || \
  1002. defined(CONFIG_ARCH_TEGRA_210_SOC)
  1003. u16 tegra_pll_get_fixed_mdiv(struct clk_hw *hw, unsigned long input_rate)
  1004. {
  1005. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1006. return (u16)_pll_fixed_mdiv(pll->params, input_rate);
  1007. }
  1008. static unsigned long _clip_vco_min(unsigned long vco_min,
  1009. unsigned long parent_rate)
  1010. {
  1011. return DIV_ROUND_UP(vco_min, parent_rate) * parent_rate;
  1012. }
  1013. static int _setup_dynamic_ramp(struct tegra_clk_pll_params *pll_params,
  1014. void __iomem *clk_base,
  1015. unsigned long parent_rate)
  1016. {
  1017. u32 val;
  1018. u32 step_a, step_b;
  1019. switch (parent_rate) {
  1020. case 12000000:
  1021. case 13000000:
  1022. case 26000000:
  1023. step_a = 0x2B;
  1024. step_b = 0x0B;
  1025. break;
  1026. case 16800000:
  1027. step_a = 0x1A;
  1028. step_b = 0x09;
  1029. break;
  1030. case 19200000:
  1031. step_a = 0x12;
  1032. step_b = 0x08;
  1033. break;
  1034. default:
  1035. pr_err("%s: Unexpected reference rate %lu\n",
  1036. __func__, parent_rate);
  1037. WARN_ON(1);
  1038. return -EINVAL;
  1039. }
  1040. val = step_a << pll_params->stepa_shift;
  1041. val |= step_b << pll_params->stepb_shift;
  1042. writel_relaxed(val, clk_base + pll_params->dyn_ramp_reg);
  1043. return 0;
  1044. }
  1045. static int _pll_ramp_calc_pll(struct clk_hw *hw,
  1046. struct tegra_clk_pll_freq_table *cfg,
  1047. unsigned long rate, unsigned long parent_rate)
  1048. {
  1049. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1050. int err = 0;
  1051. err = _get_table_rate(hw, cfg, rate, parent_rate);
  1052. if (err < 0)
  1053. err = _calc_dynamic_ramp_rate(hw, cfg, rate, parent_rate);
  1054. else {
  1055. if (cfg->m != _pll_fixed_mdiv(pll->params, parent_rate)) {
  1056. WARN_ON(1);
  1057. err = -EINVAL;
  1058. goto out;
  1059. }
  1060. }
  1061. if (cfg->p > pll->params->max_p)
  1062. err = -EINVAL;
  1063. out:
  1064. return err;
  1065. }
  1066. static int clk_pllxc_set_rate(struct clk_hw *hw, unsigned long rate,
  1067. unsigned long parent_rate)
  1068. {
  1069. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1070. struct tegra_clk_pll_freq_table cfg, old_cfg;
  1071. unsigned long flags = 0;
  1072. int ret;
  1073. ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate);
  1074. if (ret < 0)
  1075. return ret;
  1076. if (pll->lock)
  1077. spin_lock_irqsave(pll->lock, flags);
  1078. _get_pll_mnp(pll, &old_cfg);
  1079. if (pll->params->flags & TEGRA_PLL_VCO_OUT)
  1080. cfg.p = old_cfg.p;
  1081. if (old_cfg.m != cfg.m || old_cfg.n != cfg.n || old_cfg.p != cfg.p)
  1082. ret = _program_pll(hw, &cfg, rate);
  1083. if (pll->lock)
  1084. spin_unlock_irqrestore(pll->lock, flags);
  1085. return ret;
  1086. }
  1087. static long clk_pll_ramp_round_rate(struct clk_hw *hw, unsigned long rate,
  1088. unsigned long *prate)
  1089. {
  1090. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1091. struct tegra_clk_pll_freq_table cfg;
  1092. int ret, p_div;
  1093. u64 output_rate = *prate;
  1094. ret = _pll_ramp_calc_pll(hw, &cfg, rate, *prate);
  1095. if (ret < 0)
  1096. return ret;
  1097. p_div = _hw_to_p_div(hw, cfg.p);
  1098. if (p_div < 0)
  1099. return p_div;
  1100. if (pll->params->set_gain)
  1101. pll->params->set_gain(&cfg);
  1102. output_rate *= cfg.n;
  1103. do_div(output_rate, cfg.m * p_div);
  1104. return output_rate;
  1105. }
  1106. static void _pllcx_strobe(struct tegra_clk_pll *pll)
  1107. {
  1108. u32 val;
  1109. val = pll_readl_misc(pll);
  1110. val |= PLLCX_MISC_STROBE;
  1111. pll_writel_misc(val, pll);
  1112. udelay(2);
  1113. val &= ~PLLCX_MISC_STROBE;
  1114. pll_writel_misc(val, pll);
  1115. }
  1116. static int clk_pllc_enable(struct clk_hw *hw)
  1117. {
  1118. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1119. u32 val;
  1120. int ret;
  1121. unsigned long flags = 0;
  1122. if (pll->lock)
  1123. spin_lock_irqsave(pll->lock, flags);
  1124. _clk_pll_enable(hw);
  1125. udelay(2);
  1126. val = pll_readl_misc(pll);
  1127. val &= ~PLLCX_MISC_RESET;
  1128. pll_writel_misc(val, pll);
  1129. udelay(2);
  1130. _pllcx_strobe(pll);
  1131. ret = clk_pll_wait_for_lock(pll);
  1132. if (pll->lock)
  1133. spin_unlock_irqrestore(pll->lock, flags);
  1134. return ret;
  1135. }
  1136. static void _clk_pllc_disable(struct clk_hw *hw)
  1137. {
  1138. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1139. u32 val;
  1140. _clk_pll_disable(hw);
  1141. val = pll_readl_misc(pll);
  1142. val |= PLLCX_MISC_RESET;
  1143. pll_writel_misc(val, pll);
  1144. udelay(2);
  1145. }
  1146. static void clk_pllc_disable(struct clk_hw *hw)
  1147. {
  1148. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1149. unsigned long flags = 0;
  1150. if (pll->lock)
  1151. spin_lock_irqsave(pll->lock, flags);
  1152. _clk_pllc_disable(hw);
  1153. if (pll->lock)
  1154. spin_unlock_irqrestore(pll->lock, flags);
  1155. }
  1156. static int _pllcx_update_dynamic_coef(struct tegra_clk_pll *pll,
  1157. unsigned long input_rate, u32 n)
  1158. {
  1159. u32 val, n_threshold;
  1160. switch (input_rate) {
  1161. case 12000000:
  1162. n_threshold = 70;
  1163. break;
  1164. case 13000000:
  1165. case 26000000:
  1166. n_threshold = 71;
  1167. break;
  1168. case 16800000:
  1169. n_threshold = 55;
  1170. break;
  1171. case 19200000:
  1172. n_threshold = 48;
  1173. break;
  1174. default:
  1175. pr_err("%s: Unexpected reference rate %lu\n",
  1176. __func__, input_rate);
  1177. return -EINVAL;
  1178. }
  1179. val = pll_readl_misc(pll);
  1180. val &= ~(PLLCX_MISC_SDM_DIV_MASK | PLLCX_MISC_FILT_DIV_MASK);
  1181. val |= n <= n_threshold ?
  1182. PLLCX_MISC_DIV_LOW_RANGE : PLLCX_MISC_DIV_HIGH_RANGE;
  1183. pll_writel_misc(val, pll);
  1184. return 0;
  1185. }
  1186. static int clk_pllc_set_rate(struct clk_hw *hw, unsigned long rate,
  1187. unsigned long parent_rate)
  1188. {
  1189. struct tegra_clk_pll_freq_table cfg, old_cfg;
  1190. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1191. unsigned long flags = 0;
  1192. int state, ret = 0;
  1193. if (pll->lock)
  1194. spin_lock_irqsave(pll->lock, flags);
  1195. ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate);
  1196. if (ret < 0)
  1197. goto out;
  1198. _get_pll_mnp(pll, &old_cfg);
  1199. if (cfg.m != old_cfg.m) {
  1200. WARN_ON(1);
  1201. goto out;
  1202. }
  1203. if (old_cfg.n == cfg.n && old_cfg.p == cfg.p)
  1204. goto out;
  1205. state = clk_pll_is_enabled(hw);
  1206. if (state)
  1207. _clk_pllc_disable(hw);
  1208. ret = _pllcx_update_dynamic_coef(pll, parent_rate, cfg.n);
  1209. if (ret < 0)
  1210. goto out;
  1211. _update_pll_mnp(pll, &cfg);
  1212. if (state)
  1213. ret = clk_pllc_enable(hw);
  1214. out:
  1215. if (pll->lock)
  1216. spin_unlock_irqrestore(pll->lock, flags);
  1217. return ret;
  1218. }
  1219. static long _pllre_calc_rate(struct tegra_clk_pll *pll,
  1220. struct tegra_clk_pll_freq_table *cfg,
  1221. unsigned long rate, unsigned long parent_rate)
  1222. {
  1223. u16 m, n;
  1224. u64 output_rate = parent_rate;
  1225. m = _pll_fixed_mdiv(pll->params, parent_rate);
  1226. n = rate * m / parent_rate;
  1227. output_rate *= n;
  1228. do_div(output_rate, m);
  1229. if (cfg) {
  1230. cfg->m = m;
  1231. cfg->n = n;
  1232. }
  1233. return output_rate;
  1234. }
  1235. static int clk_pllre_set_rate(struct clk_hw *hw, unsigned long rate,
  1236. unsigned long parent_rate)
  1237. {
  1238. struct tegra_clk_pll_freq_table cfg, old_cfg;
  1239. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1240. unsigned long flags = 0;
  1241. int state, ret = 0;
  1242. if (pll->lock)
  1243. spin_lock_irqsave(pll->lock, flags);
  1244. _pllre_calc_rate(pll, &cfg, rate, parent_rate);
  1245. _get_pll_mnp(pll, &old_cfg);
  1246. cfg.p = old_cfg.p;
  1247. if (cfg.m != old_cfg.m || cfg.n != old_cfg.n) {
  1248. state = clk_pll_is_enabled(hw);
  1249. if (state)
  1250. _clk_pll_disable(hw);
  1251. _update_pll_mnp(pll, &cfg);
  1252. if (state) {
  1253. _clk_pll_enable(hw);
  1254. ret = clk_pll_wait_for_lock(pll);
  1255. }
  1256. }
  1257. if (pll->lock)
  1258. spin_unlock_irqrestore(pll->lock, flags);
  1259. return ret;
  1260. }
  1261. static unsigned long clk_pllre_recalc_rate(struct clk_hw *hw,
  1262. unsigned long parent_rate)
  1263. {
  1264. struct tegra_clk_pll_freq_table cfg;
  1265. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1266. u64 rate = parent_rate;
  1267. _get_pll_mnp(pll, &cfg);
  1268. rate *= cfg.n;
  1269. do_div(rate, cfg.m);
  1270. return rate;
  1271. }
  1272. static long clk_pllre_round_rate(struct clk_hw *hw, unsigned long rate,
  1273. unsigned long *prate)
  1274. {
  1275. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1276. return _pllre_calc_rate(pll, NULL, rate, *prate);
  1277. }
  1278. static int clk_plle_tegra114_enable(struct clk_hw *hw)
  1279. {
  1280. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1281. struct tegra_clk_pll_freq_table sel;
  1282. u32 val;
  1283. int ret;
  1284. unsigned long flags = 0;
  1285. unsigned long input_rate = clk_hw_get_rate(clk_hw_get_parent(hw));
  1286. if (_get_table_rate(hw, &sel, pll->params->fixed_rate, input_rate))
  1287. return -EINVAL;
  1288. if (pll->lock)
  1289. spin_lock_irqsave(pll->lock, flags);
  1290. val = pll_readl_base(pll);
  1291. val &= ~BIT(29); /* Disable lock override */
  1292. pll_writel_base(val, pll);
  1293. val = pll_readl(pll->params->aux_reg, pll);
  1294. val |= PLLE_AUX_ENABLE_SWCTL;
  1295. val &= ~PLLE_AUX_SEQ_ENABLE;
  1296. pll_writel(val, pll->params->aux_reg, pll);
  1297. udelay(1);
  1298. val = pll_readl_misc(pll);
  1299. val |= PLLE_MISC_LOCK_ENABLE;
  1300. val |= PLLE_MISC_IDDQ_SW_CTRL;
  1301. val &= ~PLLE_MISC_IDDQ_SW_VALUE;
  1302. val |= PLLE_MISC_PLLE_PTS;
  1303. val &= ~(PLLE_MISC_VREG_BG_CTRL_MASK | PLLE_MISC_VREG_CTRL_MASK);
  1304. pll_writel_misc(val, pll);
  1305. udelay(5);
  1306. val = pll_readl(PLLE_SS_CTRL, pll);
  1307. val |= PLLE_SS_DISABLE;
  1308. pll_writel(val, PLLE_SS_CTRL, pll);
  1309. val = pll_readl_base(pll);
  1310. val &= ~(divp_mask_shifted(pll) | divn_mask_shifted(pll) |
  1311. divm_mask_shifted(pll));
  1312. val &= ~(PLLE_BASE_DIVCML_MASK << PLLE_BASE_DIVCML_SHIFT);
  1313. val |= sel.m << divm_shift(pll);
  1314. val |= sel.n << divn_shift(pll);
  1315. val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT;
  1316. pll_writel_base(val, pll);
  1317. udelay(1);
  1318. _clk_pll_enable(hw);
  1319. ret = clk_pll_wait_for_lock(pll);
  1320. if (ret < 0)
  1321. goto out;
  1322. val = pll_readl(PLLE_SS_CTRL, pll);
  1323. val &= ~(PLLE_SS_CNTL_CENTER | PLLE_SS_CNTL_INVERT);
  1324. val &= ~PLLE_SS_COEFFICIENTS_MASK;
  1325. val |= PLLE_SS_COEFFICIENTS_VAL_TEGRA114;
  1326. pll_writel(val, PLLE_SS_CTRL, pll);
  1327. val &= ~(PLLE_SS_CNTL_SSC_BYP | PLLE_SS_CNTL_BYPASS_SS);
  1328. pll_writel(val, PLLE_SS_CTRL, pll);
  1329. udelay(1);
  1330. val &= ~PLLE_SS_CNTL_INTERP_RESET;
  1331. pll_writel(val, PLLE_SS_CTRL, pll);
  1332. udelay(1);
  1333. /* Enable hw control of xusb brick pll */
  1334. val = pll_readl_misc(pll);
  1335. val &= ~PLLE_MISC_IDDQ_SW_CTRL;
  1336. pll_writel_misc(val, pll);
  1337. val = pll_readl(pll->params->aux_reg, pll);
  1338. val |= (PLLE_AUX_USE_LOCKDET | PLLE_AUX_SEQ_START_STATE);
  1339. val &= ~(PLLE_AUX_ENABLE_SWCTL | PLLE_AUX_SS_SWCTL);
  1340. pll_writel(val, pll->params->aux_reg, pll);
  1341. udelay(1);
  1342. val |= PLLE_AUX_SEQ_ENABLE;
  1343. pll_writel(val, pll->params->aux_reg, pll);
  1344. val = pll_readl(XUSBIO_PLL_CFG0, pll);
  1345. val |= (XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET |
  1346. XUSBIO_PLL_CFG0_SEQ_START_STATE);
  1347. val &= ~(XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL |
  1348. XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL);
  1349. pll_writel(val, XUSBIO_PLL_CFG0, pll);
  1350. udelay(1);
  1351. val |= XUSBIO_PLL_CFG0_SEQ_ENABLE;
  1352. pll_writel(val, XUSBIO_PLL_CFG0, pll);
  1353. /* Enable hw control of SATA pll */
  1354. val = pll_readl(SATA_PLL_CFG0, pll);
  1355. val &= ~SATA_PLL_CFG0_PADPLL_RESET_SWCTL;
  1356. val |= SATA_PLL_CFG0_PADPLL_USE_LOCKDET;
  1357. val |= SATA_PLL_CFG0_SEQ_START_STATE;
  1358. pll_writel(val, SATA_PLL_CFG0, pll);
  1359. udelay(1);
  1360. val = pll_readl(SATA_PLL_CFG0, pll);
  1361. val |= SATA_PLL_CFG0_SEQ_ENABLE;
  1362. pll_writel(val, SATA_PLL_CFG0, pll);
  1363. out:
  1364. if (pll->lock)
  1365. spin_unlock_irqrestore(pll->lock, flags);
  1366. return ret;
  1367. }
  1368. static void clk_plle_tegra114_disable(struct clk_hw *hw)
  1369. {
  1370. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1371. unsigned long flags = 0;
  1372. u32 val;
  1373. if (pll->lock)
  1374. spin_lock_irqsave(pll->lock, flags);
  1375. _clk_pll_disable(hw);
  1376. val = pll_readl_misc(pll);
  1377. val |= PLLE_MISC_IDDQ_SW_CTRL | PLLE_MISC_IDDQ_SW_VALUE;
  1378. pll_writel_misc(val, pll);
  1379. udelay(1);
  1380. if (pll->lock)
  1381. spin_unlock_irqrestore(pll->lock, flags);
  1382. }
  1383. static int clk_pllu_tegra114_enable(struct clk_hw *hw)
  1384. {
  1385. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1386. const struct utmi_clk_param *params = NULL;
  1387. struct clk *osc = __clk_lookup("osc");
  1388. unsigned long flags = 0, input_rate;
  1389. unsigned int i;
  1390. int ret = 0;
  1391. u32 value;
  1392. if (!osc) {
  1393. pr_err("%s: failed to get OSC clock\n", __func__);
  1394. return -EINVAL;
  1395. }
  1396. input_rate = clk_hw_get_rate(__clk_get_hw(osc));
  1397. if (pll->lock)
  1398. spin_lock_irqsave(pll->lock, flags);
  1399. _clk_pll_enable(hw);
  1400. ret = clk_pll_wait_for_lock(pll);
  1401. if (ret < 0)
  1402. goto out;
  1403. for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) {
  1404. if (input_rate == utmi_parameters[i].osc_frequency) {
  1405. params = &utmi_parameters[i];
  1406. break;
  1407. }
  1408. }
  1409. if (!params) {
  1410. pr_err("%s: unexpected input rate %lu Hz\n", __func__,
  1411. input_rate);
  1412. ret = -EINVAL;
  1413. goto out;
  1414. }
  1415. value = pll_readl_base(pll);
  1416. value &= ~PLLU_BASE_OVERRIDE;
  1417. pll_writel_base(value, pll);
  1418. value = readl_relaxed(pll->clk_base + UTMIP_PLL_CFG2);
  1419. /* Program UTMIP PLL stable and active counts */
  1420. value &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0);
  1421. value |= UTMIP_PLL_CFG2_STABLE_COUNT(params->stable_count);
  1422. value &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0);
  1423. value |= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(params->active_delay_count);
  1424. /* Remove power downs from UTMIP PLL control bits */
  1425. value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN;
  1426. value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN;
  1427. value &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN;
  1428. writel_relaxed(value, pll->clk_base + UTMIP_PLL_CFG2);
  1429. value = readl_relaxed(pll->clk_base + UTMIP_PLL_CFG1);
  1430. /* Program UTMIP PLL delay and oscillator frequency counts */
  1431. value &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0);
  1432. value |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(params->enable_delay_count);
  1433. value &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0);
  1434. value |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(params->xtal_freq_count);
  1435. /* Remove power downs from UTMIP PLL control bits */
  1436. value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
  1437. value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN;
  1438. value &= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP;
  1439. value &= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN;
  1440. writel_relaxed(value, pll->clk_base + UTMIP_PLL_CFG1);
  1441. /* Setup HW control of UTMIPLL */
  1442. value = readl_relaxed(pll->clk_base + UTMIPLL_HW_PWRDN_CFG0);
  1443. value |= UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET;
  1444. value &= ~UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL;
  1445. value |= UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE;
  1446. writel_relaxed(value, pll->clk_base + UTMIPLL_HW_PWRDN_CFG0);
  1447. value = readl_relaxed(pll->clk_base + UTMIP_PLL_CFG1);
  1448. value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP;
  1449. value &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
  1450. writel_relaxed(value, pll->clk_base + UTMIP_PLL_CFG1);
  1451. udelay(1);
  1452. /*
  1453. * Setup SW override of UTMIPLL assuming USB2.0 ports are assigned
  1454. * to USB2
  1455. */
  1456. value = readl_relaxed(pll->clk_base + UTMIPLL_HW_PWRDN_CFG0);
  1457. value |= UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL;
  1458. value &= ~UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE;
  1459. writel_relaxed(value, pll->clk_base + UTMIPLL_HW_PWRDN_CFG0);
  1460. udelay(1);
  1461. /* Enable HW control of UTMIPLL */
  1462. value = readl_relaxed(pll->clk_base + UTMIPLL_HW_PWRDN_CFG0);
  1463. value |= UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE;
  1464. writel_relaxed(value, pll->clk_base + UTMIPLL_HW_PWRDN_CFG0);
  1465. out:
  1466. if (pll->lock)
  1467. spin_unlock_irqrestore(pll->lock, flags);
  1468. return ret;
  1469. }
  1470. #endif
  1471. static struct tegra_clk_pll *_tegra_init_pll(void __iomem *clk_base,
  1472. void __iomem *pmc, struct tegra_clk_pll_params *pll_params,
  1473. spinlock_t *lock)
  1474. {
  1475. struct tegra_clk_pll *pll;
  1476. pll = kzalloc(sizeof(*pll), GFP_KERNEL);
  1477. if (!pll)
  1478. return ERR_PTR(-ENOMEM);
  1479. pll->clk_base = clk_base;
  1480. pll->pmc = pmc;
  1481. pll->params = pll_params;
  1482. pll->lock = lock;
  1483. if (!pll_params->div_nmp)
  1484. pll_params->div_nmp = &default_nmp;
  1485. return pll;
  1486. }
  1487. static struct clk *_tegra_clk_register_pll(struct tegra_clk_pll *pll,
  1488. const char *name, const char *parent_name, unsigned long flags,
  1489. const struct clk_ops *ops)
  1490. {
  1491. struct clk_init_data init;
  1492. init.name = name;
  1493. init.ops = ops;
  1494. init.flags = flags;
  1495. init.parent_names = (parent_name ? &parent_name : NULL);
  1496. init.num_parents = (parent_name ? 1 : 0);
  1497. /* Default to _calc_rate if unspecified */
  1498. if (!pll->params->calc_rate) {
  1499. if (pll->params->flags & TEGRA_PLLM)
  1500. pll->params->calc_rate = _calc_dynamic_ramp_rate;
  1501. else
  1502. pll->params->calc_rate = _calc_rate;
  1503. }
  1504. if (pll->params->set_defaults)
  1505. pll->params->set_defaults(pll);
  1506. /* Data in .init is copied by clk_register(), so stack variable OK */
  1507. pll->hw.init = &init;
  1508. return clk_register(NULL, &pll->hw);
  1509. }
  1510. struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
  1511. void __iomem *clk_base, void __iomem *pmc,
  1512. unsigned long flags, struct tegra_clk_pll_params *pll_params,
  1513. spinlock_t *lock)
  1514. {
  1515. struct tegra_clk_pll *pll;
  1516. struct clk *clk;
  1517. pll_params->flags |= TEGRA_PLL_BYPASS;
  1518. pll = _tegra_init_pll(clk_base, pmc, pll_params, lock);
  1519. if (IS_ERR(pll))
  1520. return ERR_CAST(pll);
  1521. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  1522. &tegra_clk_pll_ops);
  1523. if (IS_ERR(clk))
  1524. kfree(pll);
  1525. return clk;
  1526. }
  1527. static struct div_nmp pll_e_nmp = {
  1528. .divn_shift = PLLE_BASE_DIVN_SHIFT,
  1529. .divn_width = PLLE_BASE_DIVN_WIDTH,
  1530. .divm_shift = PLLE_BASE_DIVM_SHIFT,
  1531. .divm_width = PLLE_BASE_DIVM_WIDTH,
  1532. .divp_shift = PLLE_BASE_DIVP_SHIFT,
  1533. .divp_width = PLLE_BASE_DIVP_WIDTH,
  1534. };
  1535. struct clk *tegra_clk_register_plle(const char *name, const char *parent_name,
  1536. void __iomem *clk_base, void __iomem *pmc,
  1537. unsigned long flags, struct tegra_clk_pll_params *pll_params,
  1538. spinlock_t *lock)
  1539. {
  1540. struct tegra_clk_pll *pll;
  1541. struct clk *clk;
  1542. pll_params->flags |= TEGRA_PLL_BYPASS;
  1543. if (!pll_params->div_nmp)
  1544. pll_params->div_nmp = &pll_e_nmp;
  1545. pll = _tegra_init_pll(clk_base, pmc, pll_params, lock);
  1546. if (IS_ERR(pll))
  1547. return ERR_CAST(pll);
  1548. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  1549. &tegra_clk_plle_ops);
  1550. if (IS_ERR(clk))
  1551. kfree(pll);
  1552. return clk;
  1553. }
  1554. struct clk *tegra_clk_register_pllu(const char *name, const char *parent_name,
  1555. void __iomem *clk_base, unsigned long flags,
  1556. struct tegra_clk_pll_params *pll_params, spinlock_t *lock)
  1557. {
  1558. struct tegra_clk_pll *pll;
  1559. struct clk *clk;
  1560. pll_params->flags |= TEGRA_PLLU;
  1561. pll = _tegra_init_pll(clk_base, NULL, pll_params, lock);
  1562. if (IS_ERR(pll))
  1563. return ERR_CAST(pll);
  1564. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  1565. &tegra_clk_pllu_ops);
  1566. if (IS_ERR(clk))
  1567. kfree(pll);
  1568. return clk;
  1569. }
  1570. #if defined(CONFIG_ARCH_TEGRA_114_SOC) || \
  1571. defined(CONFIG_ARCH_TEGRA_124_SOC) || \
  1572. defined(CONFIG_ARCH_TEGRA_132_SOC) || \
  1573. defined(CONFIG_ARCH_TEGRA_210_SOC)
  1574. static const struct clk_ops tegra_clk_pllxc_ops = {
  1575. .is_enabled = clk_pll_is_enabled,
  1576. .enable = clk_pll_enable,
  1577. .disable = clk_pll_disable,
  1578. .recalc_rate = clk_pll_recalc_rate,
  1579. .round_rate = clk_pll_ramp_round_rate,
  1580. .set_rate = clk_pllxc_set_rate,
  1581. };
  1582. static const struct clk_ops tegra_clk_pllc_ops = {
  1583. .is_enabled = clk_pll_is_enabled,
  1584. .enable = clk_pllc_enable,
  1585. .disable = clk_pllc_disable,
  1586. .recalc_rate = clk_pll_recalc_rate,
  1587. .round_rate = clk_pll_ramp_round_rate,
  1588. .set_rate = clk_pllc_set_rate,
  1589. };
  1590. static const struct clk_ops tegra_clk_pllre_ops = {
  1591. .is_enabled = clk_pll_is_enabled,
  1592. .enable = clk_pll_enable,
  1593. .disable = clk_pll_disable,
  1594. .recalc_rate = clk_pllre_recalc_rate,
  1595. .round_rate = clk_pllre_round_rate,
  1596. .set_rate = clk_pllre_set_rate,
  1597. };
  1598. static const struct clk_ops tegra_clk_plle_tegra114_ops = {
  1599. .is_enabled = clk_pll_is_enabled,
  1600. .enable = clk_plle_tegra114_enable,
  1601. .disable = clk_plle_tegra114_disable,
  1602. .recalc_rate = clk_pll_recalc_rate,
  1603. };
  1604. static const struct clk_ops tegra_clk_pllu_tegra114_ops = {
  1605. .is_enabled = clk_pll_is_enabled,
  1606. .enable = clk_pllu_tegra114_enable,
  1607. .disable = clk_pll_disable,
  1608. .recalc_rate = clk_pll_recalc_rate,
  1609. };
  1610. struct clk *tegra_clk_register_pllxc(const char *name, const char *parent_name,
  1611. void __iomem *clk_base, void __iomem *pmc,
  1612. unsigned long flags,
  1613. struct tegra_clk_pll_params *pll_params,
  1614. spinlock_t *lock)
  1615. {
  1616. struct tegra_clk_pll *pll;
  1617. struct clk *clk, *parent;
  1618. unsigned long parent_rate;
  1619. u32 val, val_iddq;
  1620. parent = __clk_lookup(parent_name);
  1621. if (!parent) {
  1622. WARN(1, "parent clk %s of %s must be registered first\n",
  1623. parent_name, name);
  1624. return ERR_PTR(-EINVAL);
  1625. }
  1626. if (!pll_params->pdiv_tohw)
  1627. return ERR_PTR(-EINVAL);
  1628. parent_rate = clk_get_rate(parent);
  1629. pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate);
  1630. if (pll_params->adjust_vco)
  1631. pll_params->vco_min = pll_params->adjust_vco(pll_params,
  1632. parent_rate);
  1633. /*
  1634. * If the pll has a set_defaults callback, it will take care of
  1635. * configuring dynamic ramping and setting IDDQ in that path.
  1636. */
  1637. if (!pll_params->set_defaults) {
  1638. int err;
  1639. err = _setup_dynamic_ramp(pll_params, clk_base, parent_rate);
  1640. if (err)
  1641. return ERR_PTR(err);
  1642. val = readl_relaxed(clk_base + pll_params->base_reg);
  1643. val_iddq = readl_relaxed(clk_base + pll_params->iddq_reg);
  1644. if (val & PLL_BASE_ENABLE)
  1645. WARN_ON(val_iddq & BIT(pll_params->iddq_bit_idx));
  1646. else {
  1647. val_iddq |= BIT(pll_params->iddq_bit_idx);
  1648. writel_relaxed(val_iddq,
  1649. clk_base + pll_params->iddq_reg);
  1650. }
  1651. }
  1652. pll = _tegra_init_pll(clk_base, pmc, pll_params, lock);
  1653. if (IS_ERR(pll))
  1654. return ERR_CAST(pll);
  1655. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  1656. &tegra_clk_pllxc_ops);
  1657. if (IS_ERR(clk))
  1658. kfree(pll);
  1659. return clk;
  1660. }
  1661. struct clk *tegra_clk_register_pllre(const char *name, const char *parent_name,
  1662. void __iomem *clk_base, void __iomem *pmc,
  1663. unsigned long flags,
  1664. struct tegra_clk_pll_params *pll_params,
  1665. spinlock_t *lock, unsigned long parent_rate)
  1666. {
  1667. u32 val;
  1668. struct tegra_clk_pll *pll;
  1669. struct clk *clk;
  1670. pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate);
  1671. if (pll_params->adjust_vco)
  1672. pll_params->vco_min = pll_params->adjust_vco(pll_params,
  1673. parent_rate);
  1674. pll = _tegra_init_pll(clk_base, pmc, pll_params, lock);
  1675. if (IS_ERR(pll))
  1676. return ERR_CAST(pll);
  1677. /* program minimum rate by default */
  1678. val = pll_readl_base(pll);
  1679. if (val & PLL_BASE_ENABLE)
  1680. WARN_ON(readl_relaxed(clk_base + pll_params->iddq_reg) &
  1681. BIT(pll_params->iddq_bit_idx));
  1682. else {
  1683. int m;
  1684. m = _pll_fixed_mdiv(pll_params, parent_rate);
  1685. val = m << divm_shift(pll);
  1686. val |= (pll_params->vco_min / parent_rate) << divn_shift(pll);
  1687. pll_writel_base(val, pll);
  1688. }
  1689. /* disable lock override */
  1690. val = pll_readl_misc(pll);
  1691. val &= ~BIT(29);
  1692. pll_writel_misc(val, pll);
  1693. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  1694. &tegra_clk_pllre_ops);
  1695. if (IS_ERR(clk))
  1696. kfree(pll);
  1697. return clk;
  1698. }
  1699. struct clk *tegra_clk_register_pllm(const char *name, const char *parent_name,
  1700. void __iomem *clk_base, void __iomem *pmc,
  1701. unsigned long flags,
  1702. struct tegra_clk_pll_params *pll_params,
  1703. spinlock_t *lock)
  1704. {
  1705. struct tegra_clk_pll *pll;
  1706. struct clk *clk, *parent;
  1707. unsigned long parent_rate;
  1708. if (!pll_params->pdiv_tohw)
  1709. return ERR_PTR(-EINVAL);
  1710. parent = __clk_lookup(parent_name);
  1711. if (!parent) {
  1712. WARN(1, "parent clk %s of %s must be registered first\n",
  1713. parent_name, name);
  1714. return ERR_PTR(-EINVAL);
  1715. }
  1716. parent_rate = clk_get_rate(parent);
  1717. pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate);
  1718. if (pll_params->adjust_vco)
  1719. pll_params->vco_min = pll_params->adjust_vco(pll_params,
  1720. parent_rate);
  1721. pll_params->flags |= TEGRA_PLL_BYPASS;
  1722. pll_params->flags |= TEGRA_PLLM;
  1723. pll = _tegra_init_pll(clk_base, pmc, pll_params, lock);
  1724. if (IS_ERR(pll))
  1725. return ERR_CAST(pll);
  1726. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  1727. &tegra_clk_pll_ops);
  1728. if (IS_ERR(clk))
  1729. kfree(pll);
  1730. return clk;
  1731. }
  1732. struct clk *tegra_clk_register_pllc(const char *name, const char *parent_name,
  1733. void __iomem *clk_base, void __iomem *pmc,
  1734. unsigned long flags,
  1735. struct tegra_clk_pll_params *pll_params,
  1736. spinlock_t *lock)
  1737. {
  1738. struct clk *parent, *clk;
  1739. const struct pdiv_map *p_tohw = pll_params->pdiv_tohw;
  1740. struct tegra_clk_pll *pll;
  1741. struct tegra_clk_pll_freq_table cfg;
  1742. unsigned long parent_rate;
  1743. if (!p_tohw)
  1744. return ERR_PTR(-EINVAL);
  1745. parent = __clk_lookup(parent_name);
  1746. if (!parent) {
  1747. WARN(1, "parent clk %s of %s must be registered first\n",
  1748. parent_name, name);
  1749. return ERR_PTR(-EINVAL);
  1750. }
  1751. parent_rate = clk_get_rate(parent);
  1752. pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate);
  1753. pll_params->flags |= TEGRA_PLL_BYPASS;
  1754. pll = _tegra_init_pll(clk_base, pmc, pll_params, lock);
  1755. if (IS_ERR(pll))
  1756. return ERR_CAST(pll);
  1757. /*
  1758. * Most of PLLC register fields are shadowed, and can not be read
  1759. * directly from PLL h/w. Hence, actual PLLC boot state is unknown.
  1760. * Initialize PLL to default state: disabled, reset; shadow registers
  1761. * loaded with default parameters; dividers are preset for half of
  1762. * minimum VCO rate (the latter assured that shadowed divider settings
  1763. * are within supported range).
  1764. */
  1765. cfg.m = _pll_fixed_mdiv(pll_params, parent_rate);
  1766. cfg.n = cfg.m * pll_params->vco_min / parent_rate;
  1767. while (p_tohw->pdiv) {
  1768. if (p_tohw->pdiv == 2) {
  1769. cfg.p = p_tohw->hw_val;
  1770. break;
  1771. }
  1772. p_tohw++;
  1773. }
  1774. if (!p_tohw->pdiv) {
  1775. WARN_ON(1);
  1776. return ERR_PTR(-EINVAL);
  1777. }
  1778. pll_writel_base(0, pll);
  1779. _update_pll_mnp(pll, &cfg);
  1780. pll_writel_misc(PLLCX_MISC_DEFAULT, pll);
  1781. pll_writel(PLLCX_MISC1_DEFAULT, pll_params->ext_misc_reg[0], pll);
  1782. pll_writel(PLLCX_MISC2_DEFAULT, pll_params->ext_misc_reg[1], pll);
  1783. pll_writel(PLLCX_MISC3_DEFAULT, pll_params->ext_misc_reg[2], pll);
  1784. _pllcx_update_dynamic_coef(pll, parent_rate, cfg.n);
  1785. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  1786. &tegra_clk_pllc_ops);
  1787. if (IS_ERR(clk))
  1788. kfree(pll);
  1789. return clk;
  1790. }
  1791. struct clk *tegra_clk_register_plle_tegra114(const char *name,
  1792. const char *parent_name,
  1793. void __iomem *clk_base, unsigned long flags,
  1794. struct tegra_clk_pll_params *pll_params,
  1795. spinlock_t *lock)
  1796. {
  1797. struct tegra_clk_pll *pll;
  1798. struct clk *clk;
  1799. u32 val, val_aux;
  1800. pll = _tegra_init_pll(clk_base, NULL, pll_params, lock);
  1801. if (IS_ERR(pll))
  1802. return ERR_CAST(pll);
  1803. /* ensure parent is set to pll_re_vco */
  1804. val = pll_readl_base(pll);
  1805. val_aux = pll_readl(pll_params->aux_reg, pll);
  1806. if (val & PLL_BASE_ENABLE) {
  1807. if ((val_aux & PLLE_AUX_PLLRE_SEL) ||
  1808. (val_aux & PLLE_AUX_PLLP_SEL))
  1809. WARN(1, "pll_e enabled with unsupported parent %s\n",
  1810. (val_aux & PLLE_AUX_PLLP_SEL) ? "pllp_out0" :
  1811. "pll_re_vco");
  1812. } else {
  1813. val_aux &= ~(PLLE_AUX_PLLRE_SEL | PLLE_AUX_PLLP_SEL);
  1814. pll_writel(val_aux, pll_params->aux_reg, pll);
  1815. }
  1816. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  1817. &tegra_clk_plle_tegra114_ops);
  1818. if (IS_ERR(clk))
  1819. kfree(pll);
  1820. return clk;
  1821. }
  1822. struct clk *
  1823. tegra_clk_register_pllu_tegra114(const char *name, const char *parent_name,
  1824. void __iomem *clk_base, unsigned long flags,
  1825. struct tegra_clk_pll_params *pll_params,
  1826. spinlock_t *lock)
  1827. {
  1828. struct tegra_clk_pll *pll;
  1829. struct clk *clk;
  1830. pll_params->flags |= TEGRA_PLLU;
  1831. pll = _tegra_init_pll(clk_base, NULL, pll_params, lock);
  1832. if (IS_ERR(pll))
  1833. return ERR_CAST(pll);
  1834. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  1835. &tegra_clk_pllu_tegra114_ops);
  1836. if (IS_ERR(clk))
  1837. kfree(pll);
  1838. return clk;
  1839. }
  1840. #endif
  1841. #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC) || defined(CONFIG_ARCH_TEGRA_210_SOC)
  1842. static const struct clk_ops tegra_clk_pllss_ops = {
  1843. .is_enabled = clk_pll_is_enabled,
  1844. .enable = clk_pll_enable,
  1845. .disable = clk_pll_disable,
  1846. .recalc_rate = clk_pll_recalc_rate,
  1847. .round_rate = clk_pll_ramp_round_rate,
  1848. .set_rate = clk_pllxc_set_rate,
  1849. };
  1850. struct clk *tegra_clk_register_pllss(const char *name, const char *parent_name,
  1851. void __iomem *clk_base, unsigned long flags,
  1852. struct tegra_clk_pll_params *pll_params,
  1853. spinlock_t *lock)
  1854. {
  1855. struct tegra_clk_pll *pll;
  1856. struct clk *clk, *parent;
  1857. struct tegra_clk_pll_freq_table cfg;
  1858. unsigned long parent_rate;
  1859. u32 val, val_iddq;
  1860. int i;
  1861. if (!pll_params->div_nmp)
  1862. return ERR_PTR(-EINVAL);
  1863. parent = __clk_lookup(parent_name);
  1864. if (!parent) {
  1865. WARN(1, "parent clk %s of %s must be registered first\n",
  1866. parent_name, name);
  1867. return ERR_PTR(-EINVAL);
  1868. }
  1869. pll = _tegra_init_pll(clk_base, NULL, pll_params, lock);
  1870. if (IS_ERR(pll))
  1871. return ERR_CAST(pll);
  1872. val = pll_readl_base(pll);
  1873. val &= ~PLLSS_REF_SRC_SEL_MASK;
  1874. pll_writel_base(val, pll);
  1875. parent_rate = clk_get_rate(parent);
  1876. pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate);
  1877. /* initialize PLL to minimum rate */
  1878. cfg.m = _pll_fixed_mdiv(pll_params, parent_rate);
  1879. cfg.n = cfg.m * pll_params->vco_min / parent_rate;
  1880. for (i = 0; pll_params->pdiv_tohw[i].pdiv; i++)
  1881. ;
  1882. if (!i) {
  1883. kfree(pll);
  1884. return ERR_PTR(-EINVAL);
  1885. }
  1886. cfg.p = pll_params->pdiv_tohw[i-1].hw_val;
  1887. _update_pll_mnp(pll, &cfg);
  1888. pll_writel_misc(PLLSS_MISC_DEFAULT, pll);
  1889. pll_writel(PLLSS_CFG_DEFAULT, pll_params->ext_misc_reg[0], pll);
  1890. pll_writel(PLLSS_CTRL1_DEFAULT, pll_params->ext_misc_reg[1], pll);
  1891. pll_writel(PLLSS_CTRL1_DEFAULT, pll_params->ext_misc_reg[2], pll);
  1892. val = pll_readl_base(pll);
  1893. val_iddq = readl_relaxed(clk_base + pll_params->iddq_reg);
  1894. if (val & PLL_BASE_ENABLE) {
  1895. if (val_iddq & BIT(pll_params->iddq_bit_idx)) {
  1896. WARN(1, "%s is on but IDDQ set\n", name);
  1897. kfree(pll);
  1898. return ERR_PTR(-EINVAL);
  1899. }
  1900. } else {
  1901. val_iddq |= BIT(pll_params->iddq_bit_idx);
  1902. writel_relaxed(val_iddq, clk_base + pll_params->iddq_reg);
  1903. }
  1904. val &= ~PLLSS_LOCK_OVERRIDE;
  1905. pll_writel_base(val, pll);
  1906. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  1907. &tegra_clk_pllss_ops);
  1908. if (IS_ERR(clk))
  1909. kfree(pll);
  1910. return clk;
  1911. }
  1912. #endif
  1913. #if defined(CONFIG_ARCH_TEGRA_210_SOC)
  1914. struct clk *tegra_clk_register_pllre_tegra210(const char *name,
  1915. const char *parent_name, void __iomem *clk_base,
  1916. void __iomem *pmc, unsigned long flags,
  1917. struct tegra_clk_pll_params *pll_params,
  1918. spinlock_t *lock, unsigned long parent_rate)
  1919. {
  1920. struct tegra_clk_pll *pll;
  1921. struct clk *clk;
  1922. pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate);
  1923. if (pll_params->adjust_vco)
  1924. pll_params->vco_min = pll_params->adjust_vco(pll_params,
  1925. parent_rate);
  1926. pll = _tegra_init_pll(clk_base, pmc, pll_params, lock);
  1927. if (IS_ERR(pll))
  1928. return ERR_CAST(pll);
  1929. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  1930. &tegra_clk_pll_ops);
  1931. if (IS_ERR(clk))
  1932. kfree(pll);
  1933. return clk;
  1934. }
  1935. static int clk_plle_tegra210_enable(struct clk_hw *hw)
  1936. {
  1937. struct tegra_clk_pll *pll = to_clk_pll(hw);
  1938. struct tegra_clk_pll_freq_table sel;
  1939. u32 val;
  1940. int ret = 0;
  1941. unsigned long flags = 0;
  1942. unsigned long input_rate = clk_hw_get_rate(clk_hw_get_parent(hw));
  1943. if (_get_table_rate(hw, &sel, pll->params->fixed_rate, input_rate))
  1944. return -EINVAL;
  1945. if (pll->lock)
  1946. spin_lock_irqsave(pll->lock, flags);
  1947. val = pll_readl(pll->params->aux_reg, pll);
  1948. if (val & PLLE_AUX_SEQ_ENABLE)
  1949. goto out;
  1950. val = pll_readl_base(pll);
  1951. val &= ~BIT(30); /* Disable lock override */
  1952. pll_writel_base(val, pll);
  1953. val = pll_readl_misc(pll);
  1954. val |= PLLE_MISC_LOCK_ENABLE;
  1955. val |= PLLE_MISC_IDDQ_SW_CTRL;
  1956. val &= ~PLLE_MISC_IDDQ_SW_VALUE;
  1957. val |= PLLE_MISC_PLLE_PTS;
  1958. val &= ~(PLLE_MISC_VREG_BG_CTRL_MASK | PLLE_MISC_VREG_CTRL_MASK);
  1959. pll_writel_misc(val, pll);
  1960. udelay(5);
  1961. val = pll_readl(PLLE_SS_CTRL, pll);
  1962. val |= PLLE_SS_DISABLE;
  1963. pll_writel(val, PLLE_SS_CTRL, pll);
  1964. val = pll_readl_base(pll);
  1965. val &= ~(divp_mask_shifted(pll) | divn_mask_shifted(pll) |
  1966. divm_mask_shifted(pll));
  1967. val &= ~(PLLE_BASE_DIVCML_MASK << PLLE_BASE_DIVCML_SHIFT);
  1968. val |= sel.m << divm_shift(pll);
  1969. val |= sel.n << divn_shift(pll);
  1970. val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT;
  1971. pll_writel_base(val, pll);
  1972. udelay(1);
  1973. val = pll_readl_base(pll);
  1974. val |= PLLE_BASE_ENABLE;
  1975. pll_writel_base(val, pll);
  1976. ret = clk_pll_wait_for_lock(pll);
  1977. if (ret < 0)
  1978. goto out;
  1979. val = pll_readl(PLLE_SS_CTRL, pll);
  1980. val &= ~(PLLE_SS_CNTL_CENTER | PLLE_SS_CNTL_INVERT);
  1981. val &= ~PLLE_SS_COEFFICIENTS_MASK;
  1982. val |= PLLE_SS_COEFFICIENTS_VAL_TEGRA210;
  1983. pll_writel(val, PLLE_SS_CTRL, pll);
  1984. val &= ~(PLLE_SS_CNTL_SSC_BYP | PLLE_SS_CNTL_BYPASS_SS);
  1985. pll_writel(val, PLLE_SS_CTRL, pll);
  1986. udelay(1);
  1987. val &= ~PLLE_SS_CNTL_INTERP_RESET;
  1988. pll_writel(val, PLLE_SS_CTRL, pll);
  1989. udelay(1);
  1990. val = pll_readl_misc(pll);
  1991. val &= ~PLLE_MISC_IDDQ_SW_CTRL;
  1992. pll_writel_misc(val, pll);
  1993. val = pll_readl(pll->params->aux_reg, pll);
  1994. val |= (PLLE_AUX_USE_LOCKDET | PLLE_AUX_SS_SEQ_INCLUDE);
  1995. val &= ~(PLLE_AUX_ENABLE_SWCTL | PLLE_AUX_SS_SWCTL);
  1996. pll_writel(val, pll->params->aux_reg, pll);
  1997. udelay(1);
  1998. val |= PLLE_AUX_SEQ_ENABLE;
  1999. pll_writel(val, pll->params->aux_reg, pll);
  2000. out:
  2001. if (pll->lock)
  2002. spin_unlock_irqrestore(pll->lock, flags);
  2003. return ret;
  2004. }
  2005. static void clk_plle_tegra210_disable(struct clk_hw *hw)
  2006. {
  2007. struct tegra_clk_pll *pll = to_clk_pll(hw);
  2008. unsigned long flags = 0;
  2009. u32 val;
  2010. if (pll->lock)
  2011. spin_lock_irqsave(pll->lock, flags);
  2012. /* If PLLE HW sequencer is enabled, SW should not disable PLLE */
  2013. val = pll_readl(pll->params->aux_reg, pll);
  2014. if (val & PLLE_AUX_SEQ_ENABLE)
  2015. goto out;
  2016. val = pll_readl_base(pll);
  2017. val &= ~PLLE_BASE_ENABLE;
  2018. pll_writel_base(val, pll);
  2019. val = pll_readl(pll->params->aux_reg, pll);
  2020. val |= PLLE_AUX_ENABLE_SWCTL | PLLE_AUX_SS_SWCTL;
  2021. pll_writel(val, pll->params->aux_reg, pll);
  2022. val = pll_readl_misc(pll);
  2023. val |= PLLE_MISC_IDDQ_SW_CTRL | PLLE_MISC_IDDQ_SW_VALUE;
  2024. pll_writel_misc(val, pll);
  2025. udelay(1);
  2026. out:
  2027. if (pll->lock)
  2028. spin_unlock_irqrestore(pll->lock, flags);
  2029. }
  2030. static int clk_plle_tegra210_is_enabled(struct clk_hw *hw)
  2031. {
  2032. struct tegra_clk_pll *pll = to_clk_pll(hw);
  2033. u32 val;
  2034. val = pll_readl_base(pll);
  2035. return val & PLLE_BASE_ENABLE ? 1 : 0;
  2036. }
  2037. static const struct clk_ops tegra_clk_plle_tegra210_ops = {
  2038. .is_enabled = clk_plle_tegra210_is_enabled,
  2039. .enable = clk_plle_tegra210_enable,
  2040. .disable = clk_plle_tegra210_disable,
  2041. .recalc_rate = clk_pll_recalc_rate,
  2042. };
  2043. struct clk *tegra_clk_register_plle_tegra210(const char *name,
  2044. const char *parent_name,
  2045. void __iomem *clk_base, unsigned long flags,
  2046. struct tegra_clk_pll_params *pll_params,
  2047. spinlock_t *lock)
  2048. {
  2049. struct tegra_clk_pll *pll;
  2050. struct clk *clk;
  2051. u32 val, val_aux;
  2052. pll = _tegra_init_pll(clk_base, NULL, pll_params, lock);
  2053. if (IS_ERR(pll))
  2054. return ERR_CAST(pll);
  2055. /* ensure parent is set to pll_re_vco */
  2056. val = pll_readl_base(pll);
  2057. val_aux = pll_readl(pll_params->aux_reg, pll);
  2058. if (val & PLLE_BASE_ENABLE) {
  2059. if ((val_aux & PLLE_AUX_PLLRE_SEL) ||
  2060. (val_aux & PLLE_AUX_PLLP_SEL))
  2061. WARN(1, "pll_e enabled with unsupported parent %s\n",
  2062. (val_aux & PLLE_AUX_PLLP_SEL) ? "pllp_out0" :
  2063. "pll_re_vco");
  2064. } else {
  2065. val_aux &= ~(PLLE_AUX_PLLRE_SEL | PLLE_AUX_PLLP_SEL);
  2066. pll_writel(val_aux, pll_params->aux_reg, pll);
  2067. }
  2068. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  2069. &tegra_clk_plle_tegra210_ops);
  2070. if (IS_ERR(clk))
  2071. kfree(pll);
  2072. return clk;
  2073. }
  2074. struct clk *tegra_clk_register_pllc_tegra210(const char *name,
  2075. const char *parent_name, void __iomem *clk_base,
  2076. void __iomem *pmc, unsigned long flags,
  2077. struct tegra_clk_pll_params *pll_params,
  2078. spinlock_t *lock)
  2079. {
  2080. struct clk *parent, *clk;
  2081. const struct pdiv_map *p_tohw = pll_params->pdiv_tohw;
  2082. struct tegra_clk_pll *pll;
  2083. unsigned long parent_rate;
  2084. if (!p_tohw)
  2085. return ERR_PTR(-EINVAL);
  2086. parent = __clk_lookup(parent_name);
  2087. if (!parent) {
  2088. WARN(1, "parent clk %s of %s must be registered first\n",
  2089. name, parent_name);
  2090. return ERR_PTR(-EINVAL);
  2091. }
  2092. parent_rate = clk_get_rate(parent);
  2093. pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate);
  2094. if (pll_params->adjust_vco)
  2095. pll_params->vco_min = pll_params->adjust_vco(pll_params,
  2096. parent_rate);
  2097. pll_params->flags |= TEGRA_PLL_BYPASS;
  2098. pll = _tegra_init_pll(clk_base, pmc, pll_params, lock);
  2099. if (IS_ERR(pll))
  2100. return ERR_CAST(pll);
  2101. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  2102. &tegra_clk_pll_ops);
  2103. if (IS_ERR(clk))
  2104. kfree(pll);
  2105. return clk;
  2106. }
  2107. struct clk *tegra_clk_register_pllss_tegra210(const char *name,
  2108. const char *parent_name, void __iomem *clk_base,
  2109. unsigned long flags,
  2110. struct tegra_clk_pll_params *pll_params,
  2111. spinlock_t *lock)
  2112. {
  2113. struct tegra_clk_pll *pll;
  2114. struct clk *clk, *parent;
  2115. unsigned long parent_rate;
  2116. u32 val;
  2117. if (!pll_params->div_nmp)
  2118. return ERR_PTR(-EINVAL);
  2119. parent = __clk_lookup(parent_name);
  2120. if (!parent) {
  2121. WARN(1, "parent clk %s of %s must be registered first\n",
  2122. name, parent_name);
  2123. return ERR_PTR(-EINVAL);
  2124. }
  2125. val = readl_relaxed(clk_base + pll_params->base_reg);
  2126. if (val & PLLSS_REF_SRC_SEL_MASK) {
  2127. WARN(1, "not supported reference clock for %s\n", name);
  2128. return ERR_PTR(-EINVAL);
  2129. }
  2130. parent_rate = clk_get_rate(parent);
  2131. pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate);
  2132. if (pll_params->adjust_vco)
  2133. pll_params->vco_min = pll_params->adjust_vco(pll_params,
  2134. parent_rate);
  2135. pll_params->flags |= TEGRA_PLL_BYPASS;
  2136. pll = _tegra_init_pll(clk_base, NULL, pll_params, lock);
  2137. if (IS_ERR(pll))
  2138. return ERR_CAST(pll);
  2139. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  2140. &tegra_clk_pll_ops);
  2141. if (IS_ERR(clk))
  2142. kfree(pll);
  2143. return clk;
  2144. }
  2145. struct clk *tegra_clk_register_pllmb(const char *name, const char *parent_name,
  2146. void __iomem *clk_base, void __iomem *pmc,
  2147. unsigned long flags,
  2148. struct tegra_clk_pll_params *pll_params,
  2149. spinlock_t *lock)
  2150. {
  2151. struct tegra_clk_pll *pll;
  2152. struct clk *clk, *parent;
  2153. unsigned long parent_rate;
  2154. if (!pll_params->pdiv_tohw)
  2155. return ERR_PTR(-EINVAL);
  2156. parent = __clk_lookup(parent_name);
  2157. if (!parent) {
  2158. WARN(1, "parent clk %s of %s must be registered first\n",
  2159. parent_name, name);
  2160. return ERR_PTR(-EINVAL);
  2161. }
  2162. parent_rate = clk_get_rate(parent);
  2163. pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate);
  2164. if (pll_params->adjust_vco)
  2165. pll_params->vco_min = pll_params->adjust_vco(pll_params,
  2166. parent_rate);
  2167. pll_params->flags |= TEGRA_PLL_BYPASS;
  2168. pll_params->flags |= TEGRA_PLLMB;
  2169. pll = _tegra_init_pll(clk_base, pmc, pll_params, lock);
  2170. if (IS_ERR(pll))
  2171. return ERR_CAST(pll);
  2172. clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
  2173. &tegra_clk_pll_ops);
  2174. if (IS_ERR(clk))
  2175. kfree(pll);
  2176. return clk;
  2177. }
  2178. #endif