tegra30_clocks.c 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104
  1. /*
  2. * arch/arm/mach-tegra/tegra30_clocks.c
  3. *
  4. * Copyright (c) 2010-2011 NVIDIA CORPORATION. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/list.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/delay.h>
  25. #include <linux/err.h>
  26. #include <linux/io.h>
  27. #include <linux/clk.h>
  28. #include <linux/cpufreq.h>
  29. #include <linux/syscore_ops.h>
  30. #include <asm/clkdev.h>
  31. #include <mach/iomap.h>
  32. #include "clock.h"
  33. #include "fuse.h"
  34. #define USE_PLL_LOCK_BITS 0
  35. #define RST_DEVICES_L 0x004
  36. #define RST_DEVICES_H 0x008
  37. #define RST_DEVICES_U 0x00C
  38. #define RST_DEVICES_V 0x358
  39. #define RST_DEVICES_W 0x35C
  40. #define RST_DEVICES_SET_L 0x300
  41. #define RST_DEVICES_CLR_L 0x304
  42. #define RST_DEVICES_SET_V 0x430
  43. #define RST_DEVICES_CLR_V 0x434
  44. #define RST_DEVICES_NUM 5
  45. #define CLK_OUT_ENB_L 0x010
  46. #define CLK_OUT_ENB_H 0x014
  47. #define CLK_OUT_ENB_U 0x018
  48. #define CLK_OUT_ENB_V 0x360
  49. #define CLK_OUT_ENB_W 0x364
  50. #define CLK_OUT_ENB_SET_L 0x320
  51. #define CLK_OUT_ENB_CLR_L 0x324
  52. #define CLK_OUT_ENB_SET_V 0x440
  53. #define CLK_OUT_ENB_CLR_V 0x444
  54. #define CLK_OUT_ENB_NUM 5
  55. #define RST_DEVICES_V_SWR_CPULP_RST_DIS (0x1 << 1)
  56. #define CLK_OUT_ENB_V_CLK_ENB_CPULP_EN (0x1 << 1)
  57. #define PERIPH_CLK_TO_BIT(c) (1 << (c->u.periph.clk_num % 32))
  58. #define PERIPH_CLK_TO_RST_REG(c) \
  59. periph_clk_to_reg((c), RST_DEVICES_L, RST_DEVICES_V, 4)
  60. #define PERIPH_CLK_TO_RST_SET_REG(c) \
  61. periph_clk_to_reg((c), RST_DEVICES_SET_L, RST_DEVICES_SET_V, 8)
  62. #define PERIPH_CLK_TO_RST_CLR_REG(c) \
  63. periph_clk_to_reg((c), RST_DEVICES_CLR_L, RST_DEVICES_CLR_V, 8)
  64. #define PERIPH_CLK_TO_ENB_REG(c) \
  65. periph_clk_to_reg((c), CLK_OUT_ENB_L, CLK_OUT_ENB_V, 4)
  66. #define PERIPH_CLK_TO_ENB_SET_REG(c) \
  67. periph_clk_to_reg((c), CLK_OUT_ENB_SET_L, CLK_OUT_ENB_SET_V, 8)
  68. #define PERIPH_CLK_TO_ENB_CLR_REG(c) \
  69. periph_clk_to_reg((c), CLK_OUT_ENB_CLR_L, CLK_OUT_ENB_CLR_V, 8)
  70. #define CLK_MASK_ARM 0x44
  71. #define MISC_CLK_ENB 0x48
  72. #define OSC_CTRL 0x50
  73. #define OSC_CTRL_OSC_FREQ_MASK (0xF<<28)
  74. #define OSC_CTRL_OSC_FREQ_13MHZ (0x0<<28)
  75. #define OSC_CTRL_OSC_FREQ_19_2MHZ (0x4<<28)
  76. #define OSC_CTRL_OSC_FREQ_12MHZ (0x8<<28)
  77. #define OSC_CTRL_OSC_FREQ_26MHZ (0xC<<28)
  78. #define OSC_CTRL_OSC_FREQ_16_8MHZ (0x1<<28)
  79. #define OSC_CTRL_OSC_FREQ_38_4MHZ (0x5<<28)
  80. #define OSC_CTRL_OSC_FREQ_48MHZ (0x9<<28)
  81. #define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK)
  82. #define OSC_CTRL_PLL_REF_DIV_MASK (3<<26)
  83. #define OSC_CTRL_PLL_REF_DIV_1 (0<<26)
  84. #define OSC_CTRL_PLL_REF_DIV_2 (1<<26)
  85. #define OSC_CTRL_PLL_REF_DIV_4 (2<<26)
  86. #define OSC_FREQ_DET 0x58
  87. #define OSC_FREQ_DET_TRIG (1<<31)
  88. #define OSC_FREQ_DET_STATUS 0x5C
  89. #define OSC_FREQ_DET_BUSY (1<<31)
  90. #define OSC_FREQ_DET_CNT_MASK 0xFFFF
  91. #define PERIPH_CLK_SOURCE_I2S1 0x100
  92. #define PERIPH_CLK_SOURCE_EMC 0x19c
  93. #define PERIPH_CLK_SOURCE_OSC 0x1fc
  94. #define PERIPH_CLK_SOURCE_NUM1 \
  95. ((PERIPH_CLK_SOURCE_OSC - PERIPH_CLK_SOURCE_I2S1) / 4)
  96. #define PERIPH_CLK_SOURCE_G3D2 0x3b0
  97. #define PERIPH_CLK_SOURCE_SE 0x42c
  98. #define PERIPH_CLK_SOURCE_NUM2 \
  99. ((PERIPH_CLK_SOURCE_SE - PERIPH_CLK_SOURCE_G3D2) / 4 + 1)
  100. #define AUDIO_DLY_CLK 0x49c
  101. #define AUDIO_SYNC_CLK_SPDIF 0x4b4
  102. #define PERIPH_CLK_SOURCE_NUM3 \
  103. ((AUDIO_SYNC_CLK_SPDIF - AUDIO_DLY_CLK) / 4 + 1)
  104. #define PERIPH_CLK_SOURCE_NUM (PERIPH_CLK_SOURCE_NUM1 + \
  105. PERIPH_CLK_SOURCE_NUM2 + \
  106. PERIPH_CLK_SOURCE_NUM3)
  107. #define CPU_SOFTRST_CTRL 0x380
  108. #define PERIPH_CLK_SOURCE_DIVU71_MASK 0xFF
  109. #define PERIPH_CLK_SOURCE_DIVU16_MASK 0xFFFF
  110. #define PERIPH_CLK_SOURCE_DIV_SHIFT 0
  111. #define PERIPH_CLK_SOURCE_DIVIDLE_SHIFT 8
  112. #define PERIPH_CLK_SOURCE_DIVIDLE_VAL 50
  113. #define PERIPH_CLK_UART_DIV_ENB (1<<24)
  114. #define PERIPH_CLK_VI_SEL_EX_SHIFT 24
  115. #define PERIPH_CLK_VI_SEL_EX_MASK (0x3<<PERIPH_CLK_VI_SEL_EX_SHIFT)
  116. #define PERIPH_CLK_NAND_DIV_EX_ENB (1<<8)
  117. #define PERIPH_CLK_DTV_POLARITY_INV (1<<25)
  118. #define AUDIO_SYNC_SOURCE_MASK 0x0F
  119. #define AUDIO_SYNC_DISABLE_BIT 0x10
  120. #define AUDIO_SYNC_TAP_NIBBLE_SHIFT(c) ((c->reg_shift - 24) * 4)
  121. #define PLL_BASE 0x0
  122. #define PLL_BASE_BYPASS (1<<31)
  123. #define PLL_BASE_ENABLE (1<<30)
  124. #define PLL_BASE_REF_ENABLE (1<<29)
  125. #define PLL_BASE_OVERRIDE (1<<28)
  126. #define PLL_BASE_LOCK (1<<27)
  127. #define PLL_BASE_DIVP_MASK (0x7<<20)
  128. #define PLL_BASE_DIVP_SHIFT 20
  129. #define PLL_BASE_DIVN_MASK (0x3FF<<8)
  130. #define PLL_BASE_DIVN_SHIFT 8
  131. #define PLL_BASE_DIVM_MASK (0x1F)
  132. #define PLL_BASE_DIVM_SHIFT 0
  133. #define PLL_OUT_RATIO_MASK (0xFF<<8)
  134. #define PLL_OUT_RATIO_SHIFT 8
  135. #define PLL_OUT_OVERRIDE (1<<2)
  136. #define PLL_OUT_CLKEN (1<<1)
  137. #define PLL_OUT_RESET_DISABLE (1<<0)
  138. #define PLL_MISC(c) \
  139. (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
  140. #define PLL_MISC_LOCK_ENABLE(c) \
  141. (((c)->flags & (PLLU | PLLD)) ? (1<<22) : (1<<18))
  142. #define PLL_MISC_DCCON_SHIFT 20
  143. #define PLL_MISC_CPCON_SHIFT 8
  144. #define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT)
  145. #define PLL_MISC_LFCON_SHIFT 4
  146. #define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT)
  147. #define PLL_MISC_VCOCON_SHIFT 0
  148. #define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT)
  149. #define PLLD_MISC_CLKENABLE (1<<30)
  150. #define PLLU_BASE_POST_DIV (1<<20)
  151. #define PLLD_BASE_DSIB_MUX_SHIFT 25
  152. #define PLLD_BASE_DSIB_MUX_MASK (1<<PLLD_BASE_DSIB_MUX_SHIFT)
  153. #define PLLD_BASE_CSI_CLKENABLE (1<<26)
  154. #define PLLD_MISC_DSI_CLKENABLE (1<<30)
  155. #define PLLD_MISC_DIV_RST (1<<23)
  156. #define PLLD_MISC_DCCON_SHIFT 12
  157. #define PLLDU_LFCON_SET_DIVN 600
  158. /* FIXME: OUT_OF_TABLE_CPCON per pll */
  159. #define OUT_OF_TABLE_CPCON 0x8
  160. #define SUPER_CLK_MUX 0x00
  161. #define SUPER_STATE_SHIFT 28
  162. #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
  163. #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
  164. #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
  165. #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
  166. #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
  167. #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
  168. #define SUPER_LP_DIV2_BYPASS (0x1 << 16)
  169. #define SUPER_SOURCE_MASK 0xF
  170. #define SUPER_FIQ_SOURCE_SHIFT 12
  171. #define SUPER_IRQ_SOURCE_SHIFT 8
  172. #define SUPER_RUN_SOURCE_SHIFT 4
  173. #define SUPER_IDLE_SOURCE_SHIFT 0
  174. #define SUPER_CLK_DIVIDER 0x04
  175. #define SUPER_CLOCK_DIV_U71_SHIFT 16
  176. #define SUPER_CLOCK_DIV_U71_MASK (0xff << SUPER_CLOCK_DIV_U71_SHIFT)
  177. /* guarantees safe cpu backup */
  178. #define SUPER_CLOCK_DIV_U71_MIN 0x2
  179. #define BUS_CLK_DISABLE (1<<3)
  180. #define BUS_CLK_DIV_MASK 0x3
  181. #define PMC_CTRL 0x0
  182. #define PMC_CTRL_BLINK_ENB (1 << 7)
  183. #define PMC_DPD_PADS_ORIDE 0x1c
  184. #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20)
  185. #define PMC_BLINK_TIMER_DATA_ON_SHIFT 0
  186. #define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff
  187. #define PMC_BLINK_TIMER_ENB (1 << 15)
  188. #define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16
  189. #define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff
  190. #define PMC_PLLP_WB0_OVERRIDE 0xf8
  191. #define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE (1 << 12)
  192. #define UTMIP_PLL_CFG2 0x488
  193. #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xfff) << 6)
  194. #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18)
  195. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN (1 << 0)
  196. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN (1 << 2)
  197. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN (1 << 4)
  198. #define UTMIP_PLL_CFG1 0x484
  199. #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
  200. #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
  201. #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN (1 << 14)
  202. #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN (1 << 12)
  203. #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN (1 << 16)
  204. #define PLLE_BASE_CML_ENABLE (1<<31)
  205. #define PLLE_BASE_ENABLE (1<<30)
  206. #define PLLE_BASE_DIVCML_SHIFT 24
  207. #define PLLE_BASE_DIVCML_MASK (0xf<<PLLE_BASE_DIVCML_SHIFT)
  208. #define PLLE_BASE_DIVP_SHIFT 16
  209. #define PLLE_BASE_DIVP_MASK (0x3f<<PLLE_BASE_DIVP_SHIFT)
  210. #define PLLE_BASE_DIVN_SHIFT 8
  211. #define PLLE_BASE_DIVN_MASK (0xFF<<PLLE_BASE_DIVN_SHIFT)
  212. #define PLLE_BASE_DIVM_SHIFT 0
  213. #define PLLE_BASE_DIVM_MASK (0xFF<<PLLE_BASE_DIVM_SHIFT)
  214. #define PLLE_BASE_DIV_MASK \
  215. (PLLE_BASE_DIVCML_MASK | PLLE_BASE_DIVP_MASK | \
  216. PLLE_BASE_DIVN_MASK | PLLE_BASE_DIVM_MASK)
  217. #define PLLE_BASE_DIV(m, n, p, cml) \
  218. (((cml)<<PLLE_BASE_DIVCML_SHIFT) | ((p)<<PLLE_BASE_DIVP_SHIFT) | \
  219. ((n)<<PLLE_BASE_DIVN_SHIFT) | ((m)<<PLLE_BASE_DIVM_SHIFT))
  220. #define PLLE_MISC_SETUP_BASE_SHIFT 16
  221. #define PLLE_MISC_SETUP_BASE_MASK (0xFFFF<<PLLE_MISC_SETUP_BASE_SHIFT)
  222. #define PLLE_MISC_READY (1<<15)
  223. #define PLLE_MISC_LOCK (1<<11)
  224. #define PLLE_MISC_LOCK_ENABLE (1<<9)
  225. #define PLLE_MISC_SETUP_EX_SHIFT 2
  226. #define PLLE_MISC_SETUP_EX_MASK (0x3<<PLLE_MISC_SETUP_EX_SHIFT)
  227. #define PLLE_MISC_SETUP_MASK \
  228. (PLLE_MISC_SETUP_BASE_MASK | PLLE_MISC_SETUP_EX_MASK)
  229. #define PLLE_MISC_SETUP_VALUE \
  230. ((0x7<<PLLE_MISC_SETUP_BASE_SHIFT) | (0x0<<PLLE_MISC_SETUP_EX_SHIFT))
  231. #define PLLE_SS_CTRL 0x68
  232. #define PLLE_SS_INCINTRV_SHIFT 24
  233. #define PLLE_SS_INCINTRV_MASK (0x3f<<PLLE_SS_INCINTRV_SHIFT)
  234. #define PLLE_SS_INC_SHIFT 16
  235. #define PLLE_SS_INC_MASK (0xff<<PLLE_SS_INC_SHIFT)
  236. #define PLLE_SS_MAX_SHIFT 0
  237. #define PLLE_SS_MAX_MASK (0x1ff<<PLLE_SS_MAX_SHIFT)
  238. #define PLLE_SS_COEFFICIENTS_MASK \
  239. (PLLE_SS_INCINTRV_MASK | PLLE_SS_INC_MASK | PLLE_SS_MAX_MASK)
  240. #define PLLE_SS_COEFFICIENTS_12MHZ \
  241. ((0x18<<PLLE_SS_INCINTRV_SHIFT) | (0x1<<PLLE_SS_INC_SHIFT) | \
  242. (0x24<<PLLE_SS_MAX_SHIFT))
  243. #define PLLE_SS_DISABLE ((1<<12) | (1<<11) | (1<<10))
  244. #define PLLE_AUX 0x48c
  245. #define PLLE_AUX_PLLP_SEL (1<<2)
  246. #define PLLE_AUX_CML_SATA_ENABLE (1<<1)
  247. #define PLLE_AUX_CML_PCIE_ENABLE (1<<0)
  248. #define PMC_SATA_PWRGT 0x1ac
  249. #define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE (1<<5)
  250. #define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL (1<<4)
  251. #define ROUND_DIVIDER_UP 0
  252. #define ROUND_DIVIDER_DOWN 1
  253. /* FIXME: recommended safety delay after lock is detected */
  254. #define PLL_POST_LOCK_DELAY 100
  255. /**
  256. * Structure defining the fields for USB UTMI clocks Parameters.
  257. */
  258. struct utmi_clk_param {
  259. /* Oscillator Frequency in KHz */
  260. u32 osc_frequency;
  261. /* UTMIP PLL Enable Delay Count */
  262. u8 enable_delay_count;
  263. /* UTMIP PLL Stable count */
  264. u8 stable_count;
  265. /* UTMIP PLL Active delay count */
  266. u8 active_delay_count;
  267. /* UTMIP PLL Xtal frequency count */
  268. u8 xtal_freq_count;
  269. };
  270. static const struct utmi_clk_param utmi_parameters[] = {
  271. {
  272. .osc_frequency = 13000000,
  273. .enable_delay_count = 0x02,
  274. .stable_count = 0x33,
  275. .active_delay_count = 0x05,
  276. .xtal_freq_count = 0x7F
  277. },
  278. {
  279. .osc_frequency = 19200000,
  280. .enable_delay_count = 0x03,
  281. .stable_count = 0x4B,
  282. .active_delay_count = 0x06,
  283. .xtal_freq_count = 0xBB},
  284. {
  285. .osc_frequency = 12000000,
  286. .enable_delay_count = 0x02,
  287. .stable_count = 0x2F,
  288. .active_delay_count = 0x04,
  289. .xtal_freq_count = 0x76
  290. },
  291. {
  292. .osc_frequency = 26000000,
  293. .enable_delay_count = 0x04,
  294. .stable_count = 0x66,
  295. .active_delay_count = 0x09,
  296. .xtal_freq_count = 0xFE
  297. },
  298. {
  299. .osc_frequency = 16800000,
  300. .enable_delay_count = 0x03,
  301. .stable_count = 0x41,
  302. .active_delay_count = 0x0A,
  303. .xtal_freq_count = 0xA4
  304. },
  305. };
  306. static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
  307. static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
  308. static void __iomem *misc_gp_hidrev_base = IO_ADDRESS(TEGRA_APB_MISC_BASE);
  309. #define MISC_GP_HIDREV 0x804
  310. /*
  311. * Some peripheral clocks share an enable bit, so refcount the enable bits
  312. * in registers CLK_ENABLE_L, ... CLK_ENABLE_W
  313. */
  314. static int tegra_periph_clk_enable_refcount[CLK_OUT_ENB_NUM * 32];
  315. #define clk_writel(value, reg) \
  316. __raw_writel(value, (u32)reg_clk_base + (reg))
  317. #define clk_readl(reg) \
  318. __raw_readl((u32)reg_clk_base + (reg))
  319. #define pmc_writel(value, reg) \
  320. __raw_writel(value, (u32)reg_pmc_base + (reg))
  321. #define pmc_readl(reg) \
  322. __raw_readl((u32)reg_pmc_base + (reg))
  323. #define chipid_readl() \
  324. __raw_readl((u32)misc_gp_hidrev_base + MISC_GP_HIDREV)
  325. #define clk_writel_delay(value, reg) \
  326. do { \
  327. __raw_writel((value), (u32)reg_clk_base + (reg)); \
  328. udelay(2); \
  329. } while (0)
  330. static inline int clk_set_div(struct clk *c, u32 n)
  331. {
  332. return clk_set_rate(c, (clk_get_rate(c->parent) + n-1) / n);
  333. }
  334. static inline u32 periph_clk_to_reg(
  335. struct clk *c, u32 reg_L, u32 reg_V, int offs)
  336. {
  337. u32 reg = c->u.periph.clk_num / 32;
  338. BUG_ON(reg >= RST_DEVICES_NUM);
  339. if (reg < 3)
  340. reg = reg_L + (reg * offs);
  341. else
  342. reg = reg_V + ((reg - 3) * offs);
  343. return reg;
  344. }
  345. static unsigned long clk_measure_input_freq(void)
  346. {
  347. u32 clock_autodetect;
  348. clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET);
  349. do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY);
  350. clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS);
  351. if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) {
  352. return 12000000;
  353. } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) {
  354. return 13000000;
  355. } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) {
  356. return 19200000;
  357. } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) {
  358. return 26000000;
  359. } else if (clock_autodetect >= 1025 - 3 && clock_autodetect <= 1025 + 3) {
  360. return 16800000;
  361. } else if (clock_autodetect >= 2344 - 3 && clock_autodetect <= 2344 + 3) {
  362. return 38400000;
  363. } else if (clock_autodetect >= 2928 - 3 && clock_autodetect <= 2928 + 3) {
  364. return 48000000;
  365. } else {
  366. pr_err("%s: Unexpected clock autodetect value %d", __func__,
  367. clock_autodetect);
  368. BUG();
  369. return 0;
  370. }
  371. }
  372. static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate,
  373. u32 flags, u32 round_mode)
  374. {
  375. s64 divider_u71 = parent_rate;
  376. if (!rate)
  377. return -EINVAL;
  378. if (!(flags & DIV_U71_INT))
  379. divider_u71 *= 2;
  380. if (round_mode == ROUND_DIVIDER_UP)
  381. divider_u71 += rate - 1;
  382. do_div(divider_u71, rate);
  383. if (flags & DIV_U71_INT)
  384. divider_u71 *= 2;
  385. if (divider_u71 - 2 < 0)
  386. return 0;
  387. if (divider_u71 - 2 > 255)
  388. return -EINVAL;
  389. return divider_u71 - 2;
  390. }
  391. static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate)
  392. {
  393. s64 divider_u16;
  394. divider_u16 = parent_rate;
  395. if (!rate)
  396. return -EINVAL;
  397. divider_u16 += rate - 1;
  398. do_div(divider_u16, rate);
  399. if (divider_u16 - 1 < 0)
  400. return 0;
  401. if (divider_u16 - 1 > 0xFFFF)
  402. return -EINVAL;
  403. return divider_u16 - 1;
  404. }
  405. /* clk_m functions */
  406. static unsigned long tegra30_clk_m_autodetect_rate(struct clk *c)
  407. {
  408. u32 osc_ctrl = clk_readl(OSC_CTRL);
  409. u32 auto_clock_control = osc_ctrl & ~OSC_CTRL_OSC_FREQ_MASK;
  410. u32 pll_ref_div = osc_ctrl & OSC_CTRL_PLL_REF_DIV_MASK;
  411. c->rate = clk_measure_input_freq();
  412. switch (c->rate) {
  413. case 12000000:
  414. auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ;
  415. BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1);
  416. break;
  417. case 13000000:
  418. auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ;
  419. BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1);
  420. break;
  421. case 19200000:
  422. auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ;
  423. BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1);
  424. break;
  425. case 26000000:
  426. auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ;
  427. BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1);
  428. break;
  429. case 16800000:
  430. auto_clock_control |= OSC_CTRL_OSC_FREQ_16_8MHZ;
  431. BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1);
  432. break;
  433. case 38400000:
  434. auto_clock_control |= OSC_CTRL_OSC_FREQ_38_4MHZ;
  435. BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_2);
  436. break;
  437. case 48000000:
  438. auto_clock_control |= OSC_CTRL_OSC_FREQ_48MHZ;
  439. BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_4);
  440. break;
  441. default:
  442. pr_err("%s: Unexpected clock rate %ld", __func__, c->rate);
  443. BUG();
  444. }
  445. clk_writel(auto_clock_control, OSC_CTRL);
  446. return c->rate;
  447. }
  448. static void tegra30_clk_m_init(struct clk *c)
  449. {
  450. pr_debug("%s on clock %s\n", __func__, c->name);
  451. tegra30_clk_m_autodetect_rate(c);
  452. }
  453. static int tegra30_clk_m_enable(struct clk *c)
  454. {
  455. pr_debug("%s on clock %s\n", __func__, c->name);
  456. return 0;
  457. }
  458. static void tegra30_clk_m_disable(struct clk *c)
  459. {
  460. pr_debug("%s on clock %s\n", __func__, c->name);
  461. WARN(1, "Attempting to disable main SoC clock\n");
  462. }
  463. static struct clk_ops tegra_clk_m_ops = {
  464. .init = tegra30_clk_m_init,
  465. .enable = tegra30_clk_m_enable,
  466. .disable = tegra30_clk_m_disable,
  467. };
  468. static struct clk_ops tegra_clk_m_div_ops = {
  469. .enable = tegra30_clk_m_enable,
  470. };
  471. /* PLL reference divider functions */
  472. static void tegra30_pll_ref_init(struct clk *c)
  473. {
  474. u32 pll_ref_div = clk_readl(OSC_CTRL) & OSC_CTRL_PLL_REF_DIV_MASK;
  475. pr_debug("%s on clock %s\n", __func__, c->name);
  476. switch (pll_ref_div) {
  477. case OSC_CTRL_PLL_REF_DIV_1:
  478. c->div = 1;
  479. break;
  480. case OSC_CTRL_PLL_REF_DIV_2:
  481. c->div = 2;
  482. break;
  483. case OSC_CTRL_PLL_REF_DIV_4:
  484. c->div = 4;
  485. break;
  486. default:
  487. pr_err("%s: Invalid pll ref divider %d", __func__, pll_ref_div);
  488. BUG();
  489. }
  490. c->mul = 1;
  491. c->state = ON;
  492. }
  493. static struct clk_ops tegra_pll_ref_ops = {
  494. .init = tegra30_pll_ref_init,
  495. .enable = tegra30_clk_m_enable,
  496. .disable = tegra30_clk_m_disable,
  497. };
  498. /* super clock functions */
  499. /* "super clocks" on tegra30 have two-stage muxes, fractional 7.1 divider and
  500. * clock skipping super divider. We will ignore the clock skipping divider,
  501. * since we can't lower the voltage when using the clock skip, but we can if
  502. * we lower the PLL frequency. We will use 7.1 divider for CPU super-clock
  503. * only when its parent is a fixed rate PLL, since we can't change PLL rate
  504. * in this case.
  505. */
  506. static void tegra30_super_clk_init(struct clk *c)
  507. {
  508. u32 val;
  509. int source;
  510. int shift;
  511. const struct clk_mux_sel *sel;
  512. val = clk_readl(c->reg + SUPER_CLK_MUX);
  513. c->state = ON;
  514. BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
  515. ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
  516. shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
  517. SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
  518. source = (val >> shift) & SUPER_SOURCE_MASK;
  519. if (c->flags & DIV_2)
  520. source |= val & SUPER_LP_DIV2_BYPASS;
  521. for (sel = c->inputs; sel->input != NULL; sel++) {
  522. if (sel->value == source)
  523. break;
  524. }
  525. BUG_ON(sel->input == NULL);
  526. c->parent = sel->input;
  527. if (c->flags & DIV_U71) {
  528. /* Init safe 7.1 divider value (does not affect PLLX path) */
  529. clk_writel(SUPER_CLOCK_DIV_U71_MIN << SUPER_CLOCK_DIV_U71_SHIFT,
  530. c->reg + SUPER_CLK_DIVIDER);
  531. c->mul = 2;
  532. c->div = 2;
  533. if (!(c->parent->flags & PLLX))
  534. c->div += SUPER_CLOCK_DIV_U71_MIN;
  535. } else
  536. clk_writel(0, c->reg + SUPER_CLK_DIVIDER);
  537. }
  538. static int tegra30_super_clk_enable(struct clk *c)
  539. {
  540. return 0;
  541. }
  542. static void tegra30_super_clk_disable(struct clk *c)
  543. {
  544. /* since tegra 3 has 2 CPU super clocks - low power lp-mode clock and
  545. geared up g-mode super clock - mode switch may request to disable
  546. either of them; accept request with no affect on h/w */
  547. }
  548. static int tegra30_super_clk_set_parent(struct clk *c, struct clk *p)
  549. {
  550. u32 val;
  551. const struct clk_mux_sel *sel;
  552. int shift;
  553. val = clk_readl(c->reg + SUPER_CLK_MUX);
  554. BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
  555. ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
  556. shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
  557. SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
  558. for (sel = c->inputs; sel->input != NULL; sel++) {
  559. if (sel->input == p) {
  560. /* For LP mode super-clock switch between PLLX direct
  561. and divided-by-2 outputs is allowed only when other
  562. than PLLX clock source is current parent */
  563. if ((c->flags & DIV_2) && (p->flags & PLLX) &&
  564. ((sel->value ^ val) & SUPER_LP_DIV2_BYPASS)) {
  565. if (c->parent->flags & PLLX)
  566. return -EINVAL;
  567. val ^= SUPER_LP_DIV2_BYPASS;
  568. clk_writel_delay(val, c->reg);
  569. }
  570. val &= ~(SUPER_SOURCE_MASK << shift);
  571. val |= (sel->value & SUPER_SOURCE_MASK) << shift;
  572. /* 7.1 divider for CPU super-clock does not affect
  573. PLLX path */
  574. if (c->flags & DIV_U71) {
  575. u32 div = 0;
  576. if (!(p->flags & PLLX)) {
  577. div = clk_readl(c->reg +
  578. SUPER_CLK_DIVIDER);
  579. div &= SUPER_CLOCK_DIV_U71_MASK;
  580. div >>= SUPER_CLOCK_DIV_U71_SHIFT;
  581. }
  582. c->div = div + 2;
  583. c->mul = 2;
  584. }
  585. if (c->refcnt)
  586. clk_enable(p);
  587. clk_writel_delay(val, c->reg);
  588. if (c->refcnt && c->parent)
  589. clk_disable(c->parent);
  590. clk_reparent(c, p);
  591. return 0;
  592. }
  593. }
  594. return -EINVAL;
  595. }
  596. /*
  597. * Do not use super clocks "skippers", since dividing using a clock skipper
  598. * does not allow the voltage to be scaled down. Instead adjust the rate of
  599. * the parent clock. This requires that the parent of a super clock have no
  600. * other children, otherwise the rate will change underneath the other
  601. * children. Special case: if fixed rate PLL is CPU super clock parent the
  602. * rate of this PLL can't be changed, and it has many other children. In
  603. * this case use 7.1 fractional divider to adjust the super clock rate.
  604. */
  605. static int tegra30_super_clk_set_rate(struct clk *c, unsigned long rate)
  606. {
  607. if ((c->flags & DIV_U71) && (c->parent->flags & PLL_FIXED)) {
  608. int div = clk_div71_get_divider(c->parent->u.pll.fixed_rate,
  609. rate, c->flags, ROUND_DIVIDER_DOWN);
  610. div = max(div, SUPER_CLOCK_DIV_U71_MIN);
  611. clk_writel(div << SUPER_CLOCK_DIV_U71_SHIFT,
  612. c->reg + SUPER_CLK_DIVIDER);
  613. c->div = div + 2;
  614. c->mul = 2;
  615. return 0;
  616. }
  617. return clk_set_rate(c->parent, rate);
  618. }
  619. static struct clk_ops tegra_super_ops = {
  620. .init = tegra30_super_clk_init,
  621. .enable = tegra30_super_clk_enable,
  622. .disable = tegra30_super_clk_disable,
  623. .set_parent = tegra30_super_clk_set_parent,
  624. .set_rate = tegra30_super_clk_set_rate,
  625. };
  626. static int tegra30_twd_clk_set_rate(struct clk *c, unsigned long rate)
  627. {
  628. /* The input value 'rate' is the clock rate of the CPU complex. */
  629. c->rate = (rate * c->mul) / c->div;
  630. return 0;
  631. }
  632. static struct clk_ops tegra30_twd_ops = {
  633. .set_rate = tegra30_twd_clk_set_rate,
  634. };
  635. /* Blink output functions */
  636. static void tegra30_blink_clk_init(struct clk *c)
  637. {
  638. u32 val;
  639. val = pmc_readl(PMC_CTRL);
  640. c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF;
  641. c->mul = 1;
  642. val = pmc_readl(c->reg);
  643. if (val & PMC_BLINK_TIMER_ENB) {
  644. unsigned int on_off;
  645. on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) &
  646. PMC_BLINK_TIMER_DATA_ON_MASK;
  647. val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
  648. val &= PMC_BLINK_TIMER_DATA_OFF_MASK;
  649. on_off += val;
  650. /* each tick in the blink timer is 4 32KHz clocks */
  651. c->div = on_off * 4;
  652. } else {
  653. c->div = 1;
  654. }
  655. }
  656. static int tegra30_blink_clk_enable(struct clk *c)
  657. {
  658. u32 val;
  659. val = pmc_readl(PMC_DPD_PADS_ORIDE);
  660. pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
  661. val = pmc_readl(PMC_CTRL);
  662. pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL);
  663. return 0;
  664. }
  665. static void tegra30_blink_clk_disable(struct clk *c)
  666. {
  667. u32 val;
  668. val = pmc_readl(PMC_CTRL);
  669. pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL);
  670. val = pmc_readl(PMC_DPD_PADS_ORIDE);
  671. pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
  672. }
  673. static int tegra30_blink_clk_set_rate(struct clk *c, unsigned long rate)
  674. {
  675. unsigned long parent_rate = clk_get_rate(c->parent);
  676. if (rate >= parent_rate) {
  677. c->div = 1;
  678. pmc_writel(0, c->reg);
  679. } else {
  680. unsigned int on_off;
  681. u32 val;
  682. on_off = DIV_ROUND_UP(parent_rate / 8, rate);
  683. c->div = on_off * 8;
  684. val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) <<
  685. PMC_BLINK_TIMER_DATA_ON_SHIFT;
  686. on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK;
  687. on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
  688. val |= on_off;
  689. val |= PMC_BLINK_TIMER_ENB;
  690. pmc_writel(val, c->reg);
  691. }
  692. return 0;
  693. }
  694. static struct clk_ops tegra_blink_clk_ops = {
  695. .init = &tegra30_blink_clk_init,
  696. .enable = &tegra30_blink_clk_enable,
  697. .disable = &tegra30_blink_clk_disable,
  698. .set_rate = &tegra30_blink_clk_set_rate,
  699. };
  700. /* PLL Functions */
  701. static int tegra30_pll_clk_wait_for_lock(struct clk *c, u32 lock_reg,
  702. u32 lock_bit)
  703. {
  704. #if USE_PLL_LOCK_BITS
  705. int i;
  706. for (i = 0; i < c->u.pll.lock_delay; i++) {
  707. if (clk_readl(lock_reg) & lock_bit) {
  708. udelay(PLL_POST_LOCK_DELAY);
  709. return 0;
  710. }
  711. udelay(2); /* timeout = 2 * lock time */
  712. }
  713. pr_err("Timed out waiting for lock bit on pll %s", c->name);
  714. return -1;
  715. #endif
  716. udelay(c->u.pll.lock_delay);
  717. return 0;
  718. }
  719. static void tegra30_utmi_param_configure(struct clk *c)
  720. {
  721. u32 reg;
  722. int i;
  723. unsigned long main_rate =
  724. clk_get_rate(c->parent->parent);
  725. for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) {
  726. if (main_rate == utmi_parameters[i].osc_frequency)
  727. break;
  728. }
  729. if (i >= ARRAY_SIZE(utmi_parameters)) {
  730. pr_err("%s: Unexpected main rate %lu\n", __func__, main_rate);
  731. return;
  732. }
  733. reg = clk_readl(UTMIP_PLL_CFG2);
  734. /* Program UTMIP PLL stable and active counts */
  735. /* [FIXME] arclk_rst.h says WRONG! This should be 1ms -> 0x50 Check! */
  736. reg &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0);
  737. reg |= UTMIP_PLL_CFG2_STABLE_COUNT(
  738. utmi_parameters[i].stable_count);
  739. reg &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0);
  740. reg |= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(
  741. utmi_parameters[i].active_delay_count);
  742. /* Remove power downs from UTMIP PLL control bits */
  743. reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN;
  744. reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN;
  745. reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN;
  746. clk_writel(reg, UTMIP_PLL_CFG2);
  747. /* Program UTMIP PLL delay and oscillator frequency counts */
  748. reg = clk_readl(UTMIP_PLL_CFG1);
  749. reg &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0);
  750. reg |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(
  751. utmi_parameters[i].enable_delay_count);
  752. reg &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0);
  753. reg |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(
  754. utmi_parameters[i].xtal_freq_count);
  755. /* Remove power downs from UTMIP PLL control bits */
  756. reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
  757. reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN;
  758. reg &= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN;
  759. clk_writel(reg, UTMIP_PLL_CFG1);
  760. }
  761. static void tegra30_pll_clk_init(struct clk *c)
  762. {
  763. u32 val = clk_readl(c->reg + PLL_BASE);
  764. c->state = (val & PLL_BASE_ENABLE) ? ON : OFF;
  765. if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) {
  766. const struct clk_pll_freq_table *sel;
  767. unsigned long input_rate = clk_get_rate(c->parent);
  768. for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
  769. if (sel->input_rate == input_rate &&
  770. sel->output_rate == c->u.pll.fixed_rate) {
  771. c->mul = sel->n;
  772. c->div = sel->m * sel->p;
  773. return;
  774. }
  775. }
  776. pr_err("Clock %s has unknown fixed frequency\n", c->name);
  777. BUG();
  778. } else if (val & PLL_BASE_BYPASS) {
  779. c->mul = 1;
  780. c->div = 1;
  781. } else {
  782. c->mul = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT;
  783. c->div = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT;
  784. if (c->flags & PLLU)
  785. c->div *= (val & PLLU_BASE_POST_DIV) ? 1 : 2;
  786. else
  787. c->div *= (0x1 << ((val & PLL_BASE_DIVP_MASK) >>
  788. PLL_BASE_DIVP_SHIFT));
  789. if (c->flags & PLL_FIXED) {
  790. unsigned long rate = clk_get_rate_locked(c);
  791. BUG_ON(rate != c->u.pll.fixed_rate);
  792. }
  793. }
  794. if (c->flags & PLLU)
  795. tegra30_utmi_param_configure(c);
  796. }
  797. static int tegra30_pll_clk_enable(struct clk *c)
  798. {
  799. u32 val;
  800. pr_debug("%s on clock %s\n", __func__, c->name);
  801. #if USE_PLL_LOCK_BITS
  802. val = clk_readl(c->reg + PLL_MISC(c));
  803. val |= PLL_MISC_LOCK_ENABLE(c);
  804. clk_writel(val, c->reg + PLL_MISC(c));
  805. #endif
  806. val = clk_readl(c->reg + PLL_BASE);
  807. val &= ~PLL_BASE_BYPASS;
  808. val |= PLL_BASE_ENABLE;
  809. clk_writel(val, c->reg + PLL_BASE);
  810. if (c->flags & PLLM) {
  811. val = pmc_readl(PMC_PLLP_WB0_OVERRIDE);
  812. val |= PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE;
  813. pmc_writel(val, PMC_PLLP_WB0_OVERRIDE);
  814. }
  815. tegra30_pll_clk_wait_for_lock(c, c->reg + PLL_BASE, PLL_BASE_LOCK);
  816. return 0;
  817. }
  818. static void tegra30_pll_clk_disable(struct clk *c)
  819. {
  820. u32 val;
  821. pr_debug("%s on clock %s\n", __func__, c->name);
  822. val = clk_readl(c->reg);
  823. val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
  824. clk_writel(val, c->reg);
  825. if (c->flags & PLLM) {
  826. val = pmc_readl(PMC_PLLP_WB0_OVERRIDE);
  827. val &= ~PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE;
  828. pmc_writel(val, PMC_PLLP_WB0_OVERRIDE);
  829. }
  830. }
  831. static int tegra30_pll_clk_set_rate(struct clk *c, unsigned long rate)
  832. {
  833. u32 val, p_div, old_base;
  834. unsigned long input_rate;
  835. const struct clk_pll_freq_table *sel;
  836. struct clk_pll_freq_table cfg;
  837. pr_debug("%s: %s %lu\n", __func__, c->name, rate);
  838. if (c->flags & PLL_FIXED) {
  839. int ret = 0;
  840. if (rate != c->u.pll.fixed_rate) {
  841. pr_err("%s: Can not change %s fixed rate %lu to %lu\n",
  842. __func__, c->name, c->u.pll.fixed_rate, rate);
  843. ret = -EINVAL;
  844. }
  845. return ret;
  846. }
  847. if (c->flags & PLLM) {
  848. if (rate != clk_get_rate_locked(c)) {
  849. pr_err("%s: Can not change memory %s rate in flight\n",
  850. __func__, c->name);
  851. return -EINVAL;
  852. }
  853. return 0;
  854. }
  855. p_div = 0;
  856. input_rate = clk_get_rate(c->parent);
  857. /* Check if the target rate is tabulated */
  858. for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
  859. if (sel->input_rate == input_rate && sel->output_rate == rate) {
  860. if (c->flags & PLLU) {
  861. BUG_ON(sel->p < 1 || sel->p > 2);
  862. if (sel->p == 1)
  863. p_div = PLLU_BASE_POST_DIV;
  864. } else {
  865. BUG_ON(sel->p < 1);
  866. for (val = sel->p; val > 1; val >>= 1)
  867. p_div++;
  868. p_div <<= PLL_BASE_DIVP_SHIFT;
  869. }
  870. break;
  871. }
  872. }
  873. /* Configure out-of-table rate */
  874. if (sel->input_rate == 0) {
  875. unsigned long cfreq;
  876. BUG_ON(c->flags & PLLU);
  877. sel = &cfg;
  878. switch (input_rate) {
  879. case 12000000:
  880. case 26000000:
  881. cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2000000;
  882. break;
  883. case 13000000:
  884. cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2600000;
  885. break;
  886. case 16800000:
  887. case 19200000:
  888. cfreq = (rate <= 1200000 * 1000) ? 1200000 : 2400000;
  889. break;
  890. default:
  891. pr_err("%s: Unexpected reference rate %lu\n",
  892. __func__, input_rate);
  893. BUG();
  894. }
  895. /* Raise VCO to guarantee 0.5% accuracy */
  896. for (cfg.output_rate = rate; cfg.output_rate < 200 * cfreq;
  897. cfg.output_rate <<= 1)
  898. p_div++;
  899. cfg.p = 0x1 << p_div;
  900. cfg.m = input_rate / cfreq;
  901. cfg.n = cfg.output_rate / cfreq;
  902. cfg.cpcon = OUT_OF_TABLE_CPCON;
  903. if ((cfg.m > (PLL_BASE_DIVM_MASK >> PLL_BASE_DIVM_SHIFT)) ||
  904. (cfg.n > (PLL_BASE_DIVN_MASK >> PLL_BASE_DIVN_SHIFT)) ||
  905. (p_div > (PLL_BASE_DIVP_MASK >> PLL_BASE_DIVP_SHIFT)) ||
  906. (cfg.output_rate > c->u.pll.vco_max)) {
  907. pr_err("%s: Failed to set %s out-of-table rate %lu\n",
  908. __func__, c->name, rate);
  909. return -EINVAL;
  910. }
  911. p_div <<= PLL_BASE_DIVP_SHIFT;
  912. }
  913. c->mul = sel->n;
  914. c->div = sel->m * sel->p;
  915. old_base = val = clk_readl(c->reg + PLL_BASE);
  916. val &= ~(PLL_BASE_DIVM_MASK | PLL_BASE_DIVN_MASK |
  917. ((c->flags & PLLU) ? PLLU_BASE_POST_DIV : PLL_BASE_DIVP_MASK));
  918. val |= (sel->m << PLL_BASE_DIVM_SHIFT) |
  919. (sel->n << PLL_BASE_DIVN_SHIFT) | p_div;
  920. if (val == old_base)
  921. return 0;
  922. if (c->state == ON) {
  923. tegra30_pll_clk_disable(c);
  924. val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
  925. }
  926. clk_writel(val, c->reg + PLL_BASE);
  927. if (c->flags & PLL_HAS_CPCON) {
  928. val = clk_readl(c->reg + PLL_MISC(c));
  929. val &= ~PLL_MISC_CPCON_MASK;
  930. val |= sel->cpcon << PLL_MISC_CPCON_SHIFT;
  931. if (c->flags & (PLLU | PLLD)) {
  932. val &= ~PLL_MISC_LFCON_MASK;
  933. if (sel->n >= PLLDU_LFCON_SET_DIVN)
  934. val |= 0x1 << PLL_MISC_LFCON_SHIFT;
  935. } else if (c->flags & (PLLX | PLLM)) {
  936. val &= ~(0x1 << PLL_MISC_DCCON_SHIFT);
  937. if (rate >= (c->u.pll.vco_max >> 1))
  938. val |= 0x1 << PLL_MISC_DCCON_SHIFT;
  939. }
  940. clk_writel(val, c->reg + PLL_MISC(c));
  941. }
  942. if (c->state == ON)
  943. tegra30_pll_clk_enable(c);
  944. return 0;
  945. }
  946. static struct clk_ops tegra_pll_ops = {
  947. .init = tegra30_pll_clk_init,
  948. .enable = tegra30_pll_clk_enable,
  949. .disable = tegra30_pll_clk_disable,
  950. .set_rate = tegra30_pll_clk_set_rate,
  951. };
  952. static int
  953. tegra30_plld_clk_cfg_ex(struct clk *c, enum tegra_clk_ex_param p, u32 setting)
  954. {
  955. u32 val, mask, reg;
  956. switch (p) {
  957. case TEGRA_CLK_PLLD_CSI_OUT_ENB:
  958. mask = PLLD_BASE_CSI_CLKENABLE;
  959. reg = c->reg + PLL_BASE;
  960. break;
  961. case TEGRA_CLK_PLLD_DSI_OUT_ENB:
  962. mask = PLLD_MISC_DSI_CLKENABLE;
  963. reg = c->reg + PLL_MISC(c);
  964. break;
  965. case TEGRA_CLK_PLLD_MIPI_MUX_SEL:
  966. if (!(c->flags & PLL_ALT_MISC_REG)) {
  967. mask = PLLD_BASE_DSIB_MUX_MASK;
  968. reg = c->reg + PLL_BASE;
  969. break;
  970. }
  971. /* fall through - error since PLLD2 does not have MUX_SEL control */
  972. default:
  973. return -EINVAL;
  974. }
  975. val = clk_readl(reg);
  976. if (setting)
  977. val |= mask;
  978. else
  979. val &= ~mask;
  980. clk_writel(val, reg);
  981. return 0;
  982. }
  983. static struct clk_ops tegra_plld_ops = {
  984. .init = tegra30_pll_clk_init,
  985. .enable = tegra30_pll_clk_enable,
  986. .disable = tegra30_pll_clk_disable,
  987. .set_rate = tegra30_pll_clk_set_rate,
  988. .clk_cfg_ex = tegra30_plld_clk_cfg_ex,
  989. };
  990. static void tegra30_plle_clk_init(struct clk *c)
  991. {
  992. u32 val;
  993. val = clk_readl(PLLE_AUX);
  994. c->parent = (val & PLLE_AUX_PLLP_SEL) ?
  995. tegra_get_clock_by_name("pll_p") :
  996. tegra_get_clock_by_name("pll_ref");
  997. val = clk_readl(c->reg + PLL_BASE);
  998. c->state = (val & PLLE_BASE_ENABLE) ? ON : OFF;
  999. c->mul = (val & PLLE_BASE_DIVN_MASK) >> PLLE_BASE_DIVN_SHIFT;
  1000. c->div = (val & PLLE_BASE_DIVM_MASK) >> PLLE_BASE_DIVM_SHIFT;
  1001. c->div *= (val & PLLE_BASE_DIVP_MASK) >> PLLE_BASE_DIVP_SHIFT;
  1002. }
  1003. static void tegra30_plle_clk_disable(struct clk *c)
  1004. {
  1005. u32 val;
  1006. pr_debug("%s on clock %s\n", __func__, c->name);
  1007. val = clk_readl(c->reg + PLL_BASE);
  1008. val &= ~(PLLE_BASE_CML_ENABLE | PLLE_BASE_ENABLE);
  1009. clk_writel(val, c->reg + PLL_BASE);
  1010. }
  1011. static void tegra30_plle_training(struct clk *c)
  1012. {
  1013. u32 val;
  1014. /* PLLE is already disabled, and setup cleared;
  1015. * create falling edge on PLLE IDDQ input */
  1016. val = pmc_readl(PMC_SATA_PWRGT);
  1017. val |= PMC_SATA_PWRGT_PLLE_IDDQ_VALUE;
  1018. pmc_writel(val, PMC_SATA_PWRGT);
  1019. val = pmc_readl(PMC_SATA_PWRGT);
  1020. val |= PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL;
  1021. pmc_writel(val, PMC_SATA_PWRGT);
  1022. val = pmc_readl(PMC_SATA_PWRGT);
  1023. val &= ~PMC_SATA_PWRGT_PLLE_IDDQ_VALUE;
  1024. pmc_writel(val, PMC_SATA_PWRGT);
  1025. do {
  1026. val = clk_readl(c->reg + PLL_MISC(c));
  1027. } while (!(val & PLLE_MISC_READY));
  1028. }
  1029. static int tegra30_plle_configure(struct clk *c, bool force_training)
  1030. {
  1031. u32 val;
  1032. const struct clk_pll_freq_table *sel;
  1033. unsigned long rate = c->u.pll.fixed_rate;
  1034. unsigned long input_rate = clk_get_rate(c->parent);
  1035. for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
  1036. if (sel->input_rate == input_rate && sel->output_rate == rate)
  1037. break;
  1038. }
  1039. if (sel->input_rate == 0)
  1040. return -ENOSYS;
  1041. /* disable PLLE, clear setup fiels */
  1042. tegra30_plle_clk_disable(c);
  1043. val = clk_readl(c->reg + PLL_MISC(c));
  1044. val &= ~(PLLE_MISC_LOCK_ENABLE | PLLE_MISC_SETUP_MASK);
  1045. clk_writel(val, c->reg + PLL_MISC(c));
  1046. /* training */
  1047. val = clk_readl(c->reg + PLL_MISC(c));
  1048. if (force_training || (!(val & PLLE_MISC_READY)))
  1049. tegra30_plle_training(c);
  1050. /* configure dividers, setup, disable SS */
  1051. val = clk_readl(c->reg + PLL_BASE);
  1052. val &= ~PLLE_BASE_DIV_MASK;
  1053. val |= PLLE_BASE_DIV(sel->m, sel->n, sel->p, sel->cpcon);
  1054. clk_writel(val, c->reg + PLL_BASE);
  1055. c->mul = sel->n;
  1056. c->div = sel->m * sel->p;
  1057. val = clk_readl(c->reg + PLL_MISC(c));
  1058. val |= PLLE_MISC_SETUP_VALUE;
  1059. val |= PLLE_MISC_LOCK_ENABLE;
  1060. clk_writel(val, c->reg + PLL_MISC(c));
  1061. val = clk_readl(PLLE_SS_CTRL);
  1062. val |= PLLE_SS_DISABLE;
  1063. clk_writel(val, PLLE_SS_CTRL);
  1064. /* enable and lock PLLE*/
  1065. val = clk_readl(c->reg + PLL_BASE);
  1066. val |= (PLLE_BASE_CML_ENABLE | PLLE_BASE_ENABLE);
  1067. clk_writel(val, c->reg + PLL_BASE);
  1068. tegra30_pll_clk_wait_for_lock(c, c->reg + PLL_MISC(c), PLLE_MISC_LOCK);
  1069. return 0;
  1070. }
  1071. static int tegra30_plle_clk_enable(struct clk *c)
  1072. {
  1073. pr_debug("%s on clock %s\n", __func__, c->name);
  1074. return tegra30_plle_configure(c, !c->set);
  1075. }
  1076. static struct clk_ops tegra_plle_ops = {
  1077. .init = tegra30_plle_clk_init,
  1078. .enable = tegra30_plle_clk_enable,
  1079. .disable = tegra30_plle_clk_disable,
  1080. };
  1081. /* Clock divider ops */
  1082. static void tegra30_pll_div_clk_init(struct clk *c)
  1083. {
  1084. if (c->flags & DIV_U71) {
  1085. u32 divu71;
  1086. u32 val = clk_readl(c->reg);
  1087. val >>= c->reg_shift;
  1088. c->state = (val & PLL_OUT_CLKEN) ? ON : OFF;
  1089. if (!(val & PLL_OUT_RESET_DISABLE))
  1090. c->state = OFF;
  1091. divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT;
  1092. c->div = (divu71 + 2);
  1093. c->mul = 2;
  1094. } else if (c->flags & DIV_2) {
  1095. c->state = ON;
  1096. if (c->flags & (PLLD | PLLX)) {
  1097. c->div = 2;
  1098. c->mul = 1;
  1099. } else
  1100. BUG();
  1101. } else {
  1102. c->state = ON;
  1103. c->div = 1;
  1104. c->mul = 1;
  1105. }
  1106. }
  1107. static int tegra30_pll_div_clk_enable(struct clk *c)
  1108. {
  1109. u32 val;
  1110. u32 new_val;
  1111. pr_debug("%s: %s\n", __func__, c->name);
  1112. if (c->flags & DIV_U71) {
  1113. val = clk_readl(c->reg);
  1114. new_val = val >> c->reg_shift;
  1115. new_val &= 0xFFFF;
  1116. new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
  1117. val &= ~(0xFFFF << c->reg_shift);
  1118. val |= new_val << c->reg_shift;
  1119. clk_writel_delay(val, c->reg);
  1120. return 0;
  1121. } else if (c->flags & DIV_2) {
  1122. return 0;
  1123. }
  1124. return -EINVAL;
  1125. }
  1126. static void tegra30_pll_div_clk_disable(struct clk *c)
  1127. {
  1128. u32 val;
  1129. u32 new_val;
  1130. pr_debug("%s: %s\n", __func__, c->name);
  1131. if (c->flags & DIV_U71) {
  1132. val = clk_readl(c->reg);
  1133. new_val = val >> c->reg_shift;
  1134. new_val &= 0xFFFF;
  1135. new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE);
  1136. val &= ~(0xFFFF << c->reg_shift);
  1137. val |= new_val << c->reg_shift;
  1138. clk_writel_delay(val, c->reg);
  1139. }
  1140. }
  1141. static int tegra30_pll_div_clk_set_rate(struct clk *c, unsigned long rate)
  1142. {
  1143. u32 val;
  1144. u32 new_val;
  1145. int divider_u71;
  1146. unsigned long parent_rate = clk_get_rate(c->parent);
  1147. pr_debug("%s: %s %lu\n", __func__, c->name, rate);
  1148. if (c->flags & DIV_U71) {
  1149. divider_u71 = clk_div71_get_divider(
  1150. parent_rate, rate, c->flags, ROUND_DIVIDER_UP);
  1151. if (divider_u71 >= 0) {
  1152. val = clk_readl(c->reg);
  1153. new_val = val >> c->reg_shift;
  1154. new_val &= 0xFFFF;
  1155. if (c->flags & DIV_U71_FIXED)
  1156. new_val |= PLL_OUT_OVERRIDE;
  1157. new_val &= ~PLL_OUT_RATIO_MASK;
  1158. new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT;
  1159. val &= ~(0xFFFF << c->reg_shift);
  1160. val |= new_val << c->reg_shift;
  1161. clk_writel_delay(val, c->reg);
  1162. c->div = divider_u71 + 2;
  1163. c->mul = 2;
  1164. return 0;
  1165. }
  1166. } else if (c->flags & DIV_2)
  1167. return clk_set_rate(c->parent, rate * 2);
  1168. return -EINVAL;
  1169. }
  1170. static long tegra30_pll_div_clk_round_rate(struct clk *c, unsigned long rate)
  1171. {
  1172. int divider;
  1173. unsigned long parent_rate = clk_get_rate(c->parent);
  1174. pr_debug("%s: %s %lu\n", __func__, c->name, rate);
  1175. if (c->flags & DIV_U71) {
  1176. divider = clk_div71_get_divider(
  1177. parent_rate, rate, c->flags, ROUND_DIVIDER_UP);
  1178. if (divider < 0)
  1179. return divider;
  1180. return DIV_ROUND_UP(parent_rate * 2, divider + 2);
  1181. } else if (c->flags & DIV_2)
  1182. /* no rounding - fixed DIV_2 dividers pass rate to parent PLL */
  1183. return rate;
  1184. return -EINVAL;
  1185. }
  1186. static struct clk_ops tegra_pll_div_ops = {
  1187. .init = tegra30_pll_div_clk_init,
  1188. .enable = tegra30_pll_div_clk_enable,
  1189. .disable = tegra30_pll_div_clk_disable,
  1190. .set_rate = tegra30_pll_div_clk_set_rate,
  1191. .round_rate = tegra30_pll_div_clk_round_rate,
  1192. };
  1193. /* Periph clk ops */
  1194. static inline u32 periph_clk_source_mask(struct clk *c)
  1195. {
  1196. if (c->flags & MUX8)
  1197. return 7 << 29;
  1198. else if (c->flags & MUX_PWM)
  1199. return 3 << 28;
  1200. else if (c->flags & MUX_CLK_OUT)
  1201. return 3 << (c->u.periph.clk_num + 4);
  1202. else if (c->flags & PLLD)
  1203. return PLLD_BASE_DSIB_MUX_MASK;
  1204. else
  1205. return 3 << 30;
  1206. }
  1207. static inline u32 periph_clk_source_shift(struct clk *c)
  1208. {
  1209. if (c->flags & MUX8)
  1210. return 29;
  1211. else if (c->flags & MUX_PWM)
  1212. return 28;
  1213. else if (c->flags & MUX_CLK_OUT)
  1214. return c->u.periph.clk_num + 4;
  1215. else if (c->flags & PLLD)
  1216. return PLLD_BASE_DSIB_MUX_SHIFT;
  1217. else
  1218. return 30;
  1219. }
  1220. static void tegra30_periph_clk_init(struct clk *c)
  1221. {
  1222. u32 val = clk_readl(c->reg);
  1223. const struct clk_mux_sel *mux = 0;
  1224. const struct clk_mux_sel *sel;
  1225. if (c->flags & MUX) {
  1226. for (sel = c->inputs; sel->input != NULL; sel++) {
  1227. if (((val & periph_clk_source_mask(c)) >>
  1228. periph_clk_source_shift(c)) == sel->value)
  1229. mux = sel;
  1230. }
  1231. BUG_ON(!mux);
  1232. c->parent = mux->input;
  1233. } else {
  1234. c->parent = c->inputs[0].input;
  1235. }
  1236. if (c->flags & DIV_U71) {
  1237. u32 divu71 = val & PERIPH_CLK_SOURCE_DIVU71_MASK;
  1238. if ((c->flags & DIV_U71_UART) &&
  1239. (!(val & PERIPH_CLK_UART_DIV_ENB))) {
  1240. divu71 = 0;
  1241. }
  1242. if (c->flags & DIV_U71_IDLE) {
  1243. val &= ~(PERIPH_CLK_SOURCE_DIVU71_MASK <<
  1244. PERIPH_CLK_SOURCE_DIVIDLE_SHIFT);
  1245. val |= (PERIPH_CLK_SOURCE_DIVIDLE_VAL <<
  1246. PERIPH_CLK_SOURCE_DIVIDLE_SHIFT);
  1247. clk_writel(val, c->reg);
  1248. }
  1249. c->div = divu71 + 2;
  1250. c->mul = 2;
  1251. } else if (c->flags & DIV_U16) {
  1252. u32 divu16 = val & PERIPH_CLK_SOURCE_DIVU16_MASK;
  1253. c->div = divu16 + 1;
  1254. c->mul = 1;
  1255. } else {
  1256. c->div = 1;
  1257. c->mul = 1;
  1258. }
  1259. c->state = ON;
  1260. if (!(clk_readl(PERIPH_CLK_TO_ENB_REG(c)) & PERIPH_CLK_TO_BIT(c)))
  1261. c->state = OFF;
  1262. if (!(c->flags & PERIPH_NO_RESET))
  1263. if (clk_readl(PERIPH_CLK_TO_RST_REG(c)) & PERIPH_CLK_TO_BIT(c))
  1264. c->state = OFF;
  1265. }
  1266. static int tegra30_periph_clk_enable(struct clk *c)
  1267. {
  1268. pr_debug("%s on clock %s\n", __func__, c->name);
  1269. tegra_periph_clk_enable_refcount[c->u.periph.clk_num]++;
  1270. if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] > 1)
  1271. return 0;
  1272. clk_writel_delay(PERIPH_CLK_TO_BIT(c), PERIPH_CLK_TO_ENB_SET_REG(c));
  1273. if (!(c->flags & PERIPH_NO_RESET) &&
  1274. !(c->flags & PERIPH_MANUAL_RESET)) {
  1275. if (clk_readl(PERIPH_CLK_TO_RST_REG(c)) &
  1276. PERIPH_CLK_TO_BIT(c)) {
  1277. udelay(5); /* reset propagation delay */
  1278. clk_writel(PERIPH_CLK_TO_BIT(c),
  1279. PERIPH_CLK_TO_RST_CLR_REG(c));
  1280. }
  1281. }
  1282. return 0;
  1283. }
  1284. static void tegra30_periph_clk_disable(struct clk *c)
  1285. {
  1286. unsigned long val;
  1287. pr_debug("%s on clock %s\n", __func__, c->name);
  1288. if (c->refcnt)
  1289. tegra_periph_clk_enable_refcount[c->u.periph.clk_num]--;
  1290. if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] == 0) {
  1291. /* If peripheral is in the APB bus then read the APB bus to
  1292. * flush the write operation in apb bus. This will avoid the
  1293. * peripheral access after disabling clock*/
  1294. if (c->flags & PERIPH_ON_APB)
  1295. val = chipid_readl();
  1296. clk_writel_delay(
  1297. PERIPH_CLK_TO_BIT(c), PERIPH_CLK_TO_ENB_CLR_REG(c));
  1298. }
  1299. }
  1300. static void tegra30_periph_clk_reset(struct clk *c, bool assert)
  1301. {
  1302. unsigned long val;
  1303. pr_debug("%s %s on clock %s\n", __func__,
  1304. assert ? "assert" : "deassert", c->name);
  1305. if (!(c->flags & PERIPH_NO_RESET)) {
  1306. if (assert) {
  1307. /* If peripheral is in the APB bus then read the APB
  1308. * bus to flush the write operation in apb bus. This
  1309. * will avoid the peripheral access after disabling
  1310. * clock */
  1311. if (c->flags & PERIPH_ON_APB)
  1312. val = chipid_readl();
  1313. clk_writel(PERIPH_CLK_TO_BIT(c),
  1314. PERIPH_CLK_TO_RST_SET_REG(c));
  1315. } else
  1316. clk_writel(PERIPH_CLK_TO_BIT(c),
  1317. PERIPH_CLK_TO_RST_CLR_REG(c));
  1318. }
  1319. }
  1320. static int tegra30_periph_clk_set_parent(struct clk *c, struct clk *p)
  1321. {
  1322. u32 val;
  1323. const struct clk_mux_sel *sel;
  1324. pr_debug("%s: %s %s\n", __func__, c->name, p->name);
  1325. if (!(c->flags & MUX))
  1326. return (p == c->parent) ? 0 : (-EINVAL);
  1327. for (sel = c->inputs; sel->input != NULL; sel++) {
  1328. if (sel->input == p) {
  1329. val = clk_readl(c->reg);
  1330. val &= ~periph_clk_source_mask(c);
  1331. val |= (sel->value << periph_clk_source_shift(c));
  1332. if (c->refcnt)
  1333. clk_enable(p);
  1334. clk_writel_delay(val, c->reg);
  1335. if (c->refcnt && c->parent)
  1336. clk_disable(c->parent);
  1337. clk_reparent(c, p);
  1338. return 0;
  1339. }
  1340. }
  1341. return -EINVAL;
  1342. }
  1343. static int tegra30_periph_clk_set_rate(struct clk *c, unsigned long rate)
  1344. {
  1345. u32 val;
  1346. int divider;
  1347. unsigned long parent_rate = clk_get_rate(c->parent);
  1348. if (c->flags & DIV_U71) {
  1349. divider = clk_div71_get_divider(
  1350. parent_rate, rate, c->flags, ROUND_DIVIDER_UP);
  1351. if (divider >= 0) {
  1352. val = clk_readl(c->reg);
  1353. val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK;
  1354. val |= divider;
  1355. if (c->flags & DIV_U71_UART) {
  1356. if (divider)
  1357. val |= PERIPH_CLK_UART_DIV_ENB;
  1358. else
  1359. val &= ~PERIPH_CLK_UART_DIV_ENB;
  1360. }
  1361. clk_writel_delay(val, c->reg);
  1362. c->div = divider + 2;
  1363. c->mul = 2;
  1364. return 0;
  1365. }
  1366. } else if (c->flags & DIV_U16) {
  1367. divider = clk_div16_get_divider(parent_rate, rate);
  1368. if (divider >= 0) {
  1369. val = clk_readl(c->reg);
  1370. val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK;
  1371. val |= divider;
  1372. clk_writel_delay(val, c->reg);
  1373. c->div = divider + 1;
  1374. c->mul = 1;
  1375. return 0;
  1376. }
  1377. } else if (parent_rate <= rate) {
  1378. c->div = 1;
  1379. c->mul = 1;
  1380. return 0;
  1381. }
  1382. return -EINVAL;
  1383. }
  1384. static long tegra30_periph_clk_round_rate(struct clk *c,
  1385. unsigned long rate)
  1386. {
  1387. int divider;
  1388. unsigned long parent_rate = clk_get_rate(c->parent);
  1389. pr_debug("%s: %s %lu\n", __func__, c->name, rate);
  1390. if (c->flags & DIV_U71) {
  1391. divider = clk_div71_get_divider(
  1392. parent_rate, rate, c->flags, ROUND_DIVIDER_UP);
  1393. if (divider < 0)
  1394. return divider;
  1395. return DIV_ROUND_UP(parent_rate * 2, divider + 2);
  1396. } else if (c->flags & DIV_U16) {
  1397. divider = clk_div16_get_divider(parent_rate, rate);
  1398. if (divider < 0)
  1399. return divider;
  1400. return DIV_ROUND_UP(parent_rate, divider + 1);
  1401. }
  1402. return -EINVAL;
  1403. }
  1404. static struct clk_ops tegra_periph_clk_ops = {
  1405. .init = &tegra30_periph_clk_init,
  1406. .enable = &tegra30_periph_clk_enable,
  1407. .disable = &tegra30_periph_clk_disable,
  1408. .set_parent = &tegra30_periph_clk_set_parent,
  1409. .set_rate = &tegra30_periph_clk_set_rate,
  1410. .round_rate = &tegra30_periph_clk_round_rate,
  1411. .reset = &tegra30_periph_clk_reset,
  1412. };
  1413. /* Periph extended clock configuration ops */
  1414. static int
  1415. tegra30_vi_clk_cfg_ex(struct clk *c, enum tegra_clk_ex_param p, u32 setting)
  1416. {
  1417. if (p == TEGRA_CLK_VI_INP_SEL) {
  1418. u32 val = clk_readl(c->reg);
  1419. val &= ~PERIPH_CLK_VI_SEL_EX_MASK;
  1420. val |= (setting << PERIPH_CLK_VI_SEL_EX_SHIFT) &
  1421. PERIPH_CLK_VI_SEL_EX_MASK;
  1422. clk_writel(val, c->reg);
  1423. return 0;
  1424. }
  1425. return -EINVAL;
  1426. }
  1427. static struct clk_ops tegra_vi_clk_ops = {
  1428. .init = &tegra30_periph_clk_init,
  1429. .enable = &tegra30_periph_clk_enable,
  1430. .disable = &tegra30_periph_clk_disable,
  1431. .set_parent = &tegra30_periph_clk_set_parent,
  1432. .set_rate = &tegra30_periph_clk_set_rate,
  1433. .round_rate = &tegra30_periph_clk_round_rate,
  1434. .clk_cfg_ex = &tegra30_vi_clk_cfg_ex,
  1435. .reset = &tegra30_periph_clk_reset,
  1436. };
  1437. static int
  1438. tegra30_nand_clk_cfg_ex(struct clk *c, enum tegra_clk_ex_param p, u32 setting)
  1439. {
  1440. if (p == TEGRA_CLK_NAND_PAD_DIV2_ENB) {
  1441. u32 val = clk_readl(c->reg);
  1442. if (setting)
  1443. val |= PERIPH_CLK_NAND_DIV_EX_ENB;
  1444. else
  1445. val &= ~PERIPH_CLK_NAND_DIV_EX_ENB;
  1446. clk_writel(val, c->reg);
  1447. return 0;
  1448. }
  1449. return -EINVAL;
  1450. }
  1451. static struct clk_ops tegra_nand_clk_ops = {
  1452. .init = &tegra30_periph_clk_init,
  1453. .enable = &tegra30_periph_clk_enable,
  1454. .disable = &tegra30_periph_clk_disable,
  1455. .set_parent = &tegra30_periph_clk_set_parent,
  1456. .set_rate = &tegra30_periph_clk_set_rate,
  1457. .round_rate = &tegra30_periph_clk_round_rate,
  1458. .clk_cfg_ex = &tegra30_nand_clk_cfg_ex,
  1459. .reset = &tegra30_periph_clk_reset,
  1460. };
  1461. static int
  1462. tegra30_dtv_clk_cfg_ex(struct clk *c, enum tegra_clk_ex_param p, u32 setting)
  1463. {
  1464. if (p == TEGRA_CLK_DTV_INVERT) {
  1465. u32 val = clk_readl(c->reg);
  1466. if (setting)
  1467. val |= PERIPH_CLK_DTV_POLARITY_INV;
  1468. else
  1469. val &= ~PERIPH_CLK_DTV_POLARITY_INV;
  1470. clk_writel(val, c->reg);
  1471. return 0;
  1472. }
  1473. return -EINVAL;
  1474. }
  1475. static struct clk_ops tegra_dtv_clk_ops = {
  1476. .init = &tegra30_periph_clk_init,
  1477. .enable = &tegra30_periph_clk_enable,
  1478. .disable = &tegra30_periph_clk_disable,
  1479. .set_parent = &tegra30_periph_clk_set_parent,
  1480. .set_rate = &tegra30_periph_clk_set_rate,
  1481. .round_rate = &tegra30_periph_clk_round_rate,
  1482. .clk_cfg_ex = &tegra30_dtv_clk_cfg_ex,
  1483. .reset = &tegra30_periph_clk_reset,
  1484. };
  1485. static int tegra30_dsib_clk_set_parent(struct clk *c, struct clk *p)
  1486. {
  1487. const struct clk_mux_sel *sel;
  1488. struct clk *d = tegra_get_clock_by_name("pll_d");
  1489. pr_debug("%s: %s %s\n", __func__, c->name, p->name);
  1490. for (sel = c->inputs; sel->input != NULL; sel++) {
  1491. if (sel->input == p) {
  1492. if (c->refcnt)
  1493. clk_enable(p);
  1494. /* The DSIB parent selection bit is in PLLD base
  1495. register - can not do direct r-m-w, must be
  1496. protected by PLLD lock */
  1497. tegra_clk_cfg_ex(
  1498. d, TEGRA_CLK_PLLD_MIPI_MUX_SEL, sel->value);
  1499. if (c->refcnt && c->parent)
  1500. clk_disable(c->parent);
  1501. clk_reparent(c, p);
  1502. return 0;
  1503. }
  1504. }
  1505. return -EINVAL;
  1506. }
  1507. static struct clk_ops tegra_dsib_clk_ops = {
  1508. .init = &tegra30_periph_clk_init,
  1509. .enable = &tegra30_periph_clk_enable,
  1510. .disable = &tegra30_periph_clk_disable,
  1511. .set_parent = &tegra30_dsib_clk_set_parent,
  1512. .set_rate = &tegra30_periph_clk_set_rate,
  1513. .round_rate = &tegra30_periph_clk_round_rate,
  1514. .reset = &tegra30_periph_clk_reset,
  1515. };
  1516. /* pciex clock support only reset function */
  1517. static struct clk_ops tegra_pciex_clk_ops = {
  1518. .reset = tegra30_periph_clk_reset,
  1519. };
  1520. /* Output clock ops */
  1521. static DEFINE_SPINLOCK(clk_out_lock);
  1522. static void tegra30_clk_out_init(struct clk *c)
  1523. {
  1524. const struct clk_mux_sel *mux = 0;
  1525. const struct clk_mux_sel *sel;
  1526. u32 val = pmc_readl(c->reg);
  1527. c->state = (val & (0x1 << c->u.periph.clk_num)) ? ON : OFF;
  1528. c->mul = 1;
  1529. c->div = 1;
  1530. for (sel = c->inputs; sel->input != NULL; sel++) {
  1531. if (((val & periph_clk_source_mask(c)) >>
  1532. periph_clk_source_shift(c)) == sel->value)
  1533. mux = sel;
  1534. }
  1535. BUG_ON(!mux);
  1536. c->parent = mux->input;
  1537. }
  1538. static int tegra30_clk_out_enable(struct clk *c)
  1539. {
  1540. u32 val;
  1541. unsigned long flags;
  1542. pr_debug("%s on clock %s\n", __func__, c->name);
  1543. spin_lock_irqsave(&clk_out_lock, flags);
  1544. val = pmc_readl(c->reg);
  1545. val |= (0x1 << c->u.periph.clk_num);
  1546. pmc_writel(val, c->reg);
  1547. spin_unlock_irqrestore(&clk_out_lock, flags);
  1548. return 0;
  1549. }
  1550. static void tegra30_clk_out_disable(struct clk *c)
  1551. {
  1552. u32 val;
  1553. unsigned long flags;
  1554. pr_debug("%s on clock %s\n", __func__, c->name);
  1555. spin_lock_irqsave(&clk_out_lock, flags);
  1556. val = pmc_readl(c->reg);
  1557. val &= ~(0x1 << c->u.periph.clk_num);
  1558. pmc_writel(val, c->reg);
  1559. spin_unlock_irqrestore(&clk_out_lock, flags);
  1560. }
  1561. static int tegra30_clk_out_set_parent(struct clk *c, struct clk *p)
  1562. {
  1563. u32 val;
  1564. unsigned long flags;
  1565. const struct clk_mux_sel *sel;
  1566. pr_debug("%s: %s %s\n", __func__, c->name, p->name);
  1567. for (sel = c->inputs; sel->input != NULL; sel++) {
  1568. if (sel->input == p) {
  1569. if (c->refcnt)
  1570. clk_enable(p);
  1571. spin_lock_irqsave(&clk_out_lock, flags);
  1572. val = pmc_readl(c->reg);
  1573. val &= ~periph_clk_source_mask(c);
  1574. val |= (sel->value << periph_clk_source_shift(c));
  1575. pmc_writel(val, c->reg);
  1576. spin_unlock_irqrestore(&clk_out_lock, flags);
  1577. if (c->refcnt && c->parent)
  1578. clk_disable(c->parent);
  1579. clk_reparent(c, p);
  1580. return 0;
  1581. }
  1582. }
  1583. return -EINVAL;
  1584. }
  1585. static struct clk_ops tegra_clk_out_ops = {
  1586. .init = &tegra30_clk_out_init,
  1587. .enable = &tegra30_clk_out_enable,
  1588. .disable = &tegra30_clk_out_disable,
  1589. .set_parent = &tegra30_clk_out_set_parent,
  1590. };
  1591. /* Clock doubler ops */
  1592. static void tegra30_clk_double_init(struct clk *c)
  1593. {
  1594. u32 val = clk_readl(c->reg);
  1595. c->mul = val & (0x1 << c->reg_shift) ? 1 : 2;
  1596. c->div = 1;
  1597. c->state = ON;
  1598. if (!(clk_readl(PERIPH_CLK_TO_ENB_REG(c)) & PERIPH_CLK_TO_BIT(c)))
  1599. c->state = OFF;
  1600. };
  1601. static int tegra30_clk_double_set_rate(struct clk *c, unsigned long rate)
  1602. {
  1603. u32 val;
  1604. unsigned long parent_rate = clk_get_rate(c->parent);
  1605. if (rate == parent_rate) {
  1606. val = clk_readl(c->reg) | (0x1 << c->reg_shift);
  1607. clk_writel(val, c->reg);
  1608. c->mul = 1;
  1609. c->div = 1;
  1610. return 0;
  1611. } else if (rate == 2 * parent_rate) {
  1612. val = clk_readl(c->reg) & (~(0x1 << c->reg_shift));
  1613. clk_writel(val, c->reg);
  1614. c->mul = 2;
  1615. c->div = 1;
  1616. return 0;
  1617. }
  1618. return -EINVAL;
  1619. }
  1620. static struct clk_ops tegra_clk_double_ops = {
  1621. .init = &tegra30_clk_double_init,
  1622. .enable = &tegra30_periph_clk_enable,
  1623. .disable = &tegra30_periph_clk_disable,
  1624. .set_rate = &tegra30_clk_double_set_rate,
  1625. };
  1626. /* Audio sync clock ops */
  1627. static int tegra30_sync_source_set_rate(struct clk *c, unsigned long rate)
  1628. {
  1629. c->rate = rate;
  1630. return 0;
  1631. }
  1632. static struct clk_ops tegra_sync_source_ops = {
  1633. .set_rate = &tegra30_sync_source_set_rate,
  1634. };
  1635. static void tegra30_audio_sync_clk_init(struct clk *c)
  1636. {
  1637. int source;
  1638. const struct clk_mux_sel *sel;
  1639. u32 val = clk_readl(c->reg);
  1640. c->state = (val & AUDIO_SYNC_DISABLE_BIT) ? OFF : ON;
  1641. source = val & AUDIO_SYNC_SOURCE_MASK;
  1642. for (sel = c->inputs; sel->input != NULL; sel++)
  1643. if (sel->value == source)
  1644. break;
  1645. BUG_ON(sel->input == NULL);
  1646. c->parent = sel->input;
  1647. }
  1648. static int tegra30_audio_sync_clk_enable(struct clk *c)
  1649. {
  1650. u32 val = clk_readl(c->reg);
  1651. clk_writel((val & (~AUDIO_SYNC_DISABLE_BIT)), c->reg);
  1652. return 0;
  1653. }
  1654. static void tegra30_audio_sync_clk_disable(struct clk *c)
  1655. {
  1656. u32 val = clk_readl(c->reg);
  1657. clk_writel((val | AUDIO_SYNC_DISABLE_BIT), c->reg);
  1658. }
  1659. static int tegra30_audio_sync_clk_set_parent(struct clk *c, struct clk *p)
  1660. {
  1661. u32 val;
  1662. const struct clk_mux_sel *sel;
  1663. for (sel = c->inputs; sel->input != NULL; sel++) {
  1664. if (sel->input == p) {
  1665. val = clk_readl(c->reg);
  1666. val &= ~AUDIO_SYNC_SOURCE_MASK;
  1667. val |= sel->value;
  1668. if (c->refcnt)
  1669. clk_enable(p);
  1670. clk_writel(val, c->reg);
  1671. if (c->refcnt && c->parent)
  1672. clk_disable(c->parent);
  1673. clk_reparent(c, p);
  1674. return 0;
  1675. }
  1676. }
  1677. return -EINVAL;
  1678. }
  1679. static struct clk_ops tegra_audio_sync_clk_ops = {
  1680. .init = tegra30_audio_sync_clk_init,
  1681. .enable = tegra30_audio_sync_clk_enable,
  1682. .disable = tegra30_audio_sync_clk_disable,
  1683. .set_parent = tegra30_audio_sync_clk_set_parent,
  1684. };
  1685. /* cml0 (pcie), and cml1 (sata) clock ops */
  1686. static void tegra30_cml_clk_init(struct clk *c)
  1687. {
  1688. u32 val = clk_readl(c->reg);
  1689. c->state = val & (0x1 << c->u.periph.clk_num) ? ON : OFF;
  1690. }
  1691. static int tegra30_cml_clk_enable(struct clk *c)
  1692. {
  1693. u32 val = clk_readl(c->reg);
  1694. val |= (0x1 << c->u.periph.clk_num);
  1695. clk_writel(val, c->reg);
  1696. return 0;
  1697. }
  1698. static void tegra30_cml_clk_disable(struct clk *c)
  1699. {
  1700. u32 val = clk_readl(c->reg);
  1701. val &= ~(0x1 << c->u.periph.clk_num);
  1702. clk_writel(val, c->reg);
  1703. }
  1704. static struct clk_ops tegra_cml_clk_ops = {
  1705. .init = &tegra30_cml_clk_init,
  1706. .enable = &tegra30_cml_clk_enable,
  1707. .disable = &tegra30_cml_clk_disable,
  1708. };
  1709. /* Clock definitions */
  1710. static struct clk tegra_clk_32k = {
  1711. .name = "clk_32k",
  1712. .rate = 32768,
  1713. .ops = NULL,
  1714. .max_rate = 32768,
  1715. };
  1716. static struct clk tegra_clk_m = {
  1717. .name = "clk_m",
  1718. .flags = ENABLE_ON_INIT,
  1719. .ops = &tegra_clk_m_ops,
  1720. .reg = 0x1fc,
  1721. .reg_shift = 28,
  1722. .max_rate = 48000000,
  1723. };
  1724. static struct clk tegra_clk_m_div2 = {
  1725. .name = "clk_m_div2",
  1726. .ops = &tegra_clk_m_div_ops,
  1727. .parent = &tegra_clk_m,
  1728. .mul = 1,
  1729. .div = 2,
  1730. .state = ON,
  1731. .max_rate = 24000000,
  1732. };
  1733. static struct clk tegra_clk_m_div4 = {
  1734. .name = "clk_m_div4",
  1735. .ops = &tegra_clk_m_div_ops,
  1736. .parent = &tegra_clk_m,
  1737. .mul = 1,
  1738. .div = 4,
  1739. .state = ON,
  1740. .max_rate = 12000000,
  1741. };
  1742. static struct clk tegra_pll_ref = {
  1743. .name = "pll_ref",
  1744. .flags = ENABLE_ON_INIT,
  1745. .ops = &tegra_pll_ref_ops,
  1746. .parent = &tegra_clk_m,
  1747. .max_rate = 26000000,
  1748. };
  1749. static struct clk_pll_freq_table tegra_pll_c_freq_table[] = {
  1750. { 12000000, 1040000000, 520, 6, 1, 8},
  1751. { 13000000, 1040000000, 480, 6, 1, 8},
  1752. { 16800000, 1040000000, 495, 8, 1, 8}, /* actual: 1039.5 MHz */
  1753. { 19200000, 1040000000, 325, 6, 1, 6},
  1754. { 26000000, 1040000000, 520, 13, 1, 8},
  1755. { 12000000, 832000000, 416, 6, 1, 8},
  1756. { 13000000, 832000000, 832, 13, 1, 8},
  1757. { 16800000, 832000000, 396, 8, 1, 8}, /* actual: 831.6 MHz */
  1758. { 19200000, 832000000, 260, 6, 1, 8},
  1759. { 26000000, 832000000, 416, 13, 1, 8},
  1760. { 12000000, 624000000, 624, 12, 1, 8},
  1761. { 13000000, 624000000, 624, 13, 1, 8},
  1762. { 16800000, 600000000, 520, 14, 1, 8},
  1763. { 19200000, 624000000, 520, 16, 1, 8},
  1764. { 26000000, 624000000, 624, 26, 1, 8},
  1765. { 12000000, 600000000, 600, 12, 1, 8},
  1766. { 13000000, 600000000, 600, 13, 1, 8},
  1767. { 16800000, 600000000, 500, 14, 1, 8},
  1768. { 19200000, 600000000, 375, 12, 1, 6},
  1769. { 26000000, 600000000, 600, 26, 1, 8},
  1770. { 12000000, 520000000, 520, 12, 1, 8},
  1771. { 13000000, 520000000, 520, 13, 1, 8},
  1772. { 16800000, 520000000, 495, 16, 1, 8}, /* actual: 519.75 MHz */
  1773. { 19200000, 520000000, 325, 12, 1, 6},
  1774. { 26000000, 520000000, 520, 26, 1, 8},
  1775. { 12000000, 416000000, 416, 12, 1, 8},
  1776. { 13000000, 416000000, 416, 13, 1, 8},
  1777. { 16800000, 416000000, 396, 16, 1, 8}, /* actual: 415.8 MHz */
  1778. { 19200000, 416000000, 260, 12, 1, 6},
  1779. { 26000000, 416000000, 416, 26, 1, 8},
  1780. { 0, 0, 0, 0, 0, 0 },
  1781. };
  1782. static struct clk tegra_pll_c = {
  1783. .name = "pll_c",
  1784. .flags = PLL_HAS_CPCON,
  1785. .ops = &tegra_pll_ops,
  1786. .reg = 0x80,
  1787. .parent = &tegra_pll_ref,
  1788. .max_rate = 1400000000,
  1789. .u.pll = {
  1790. .input_min = 2000000,
  1791. .input_max = 31000000,
  1792. .cf_min = 1000000,
  1793. .cf_max = 6000000,
  1794. .vco_min = 20000000,
  1795. .vco_max = 1400000000,
  1796. .freq_table = tegra_pll_c_freq_table,
  1797. .lock_delay = 300,
  1798. },
  1799. };
  1800. static struct clk tegra_pll_c_out1 = {
  1801. .name = "pll_c_out1",
  1802. .ops = &tegra_pll_div_ops,
  1803. .flags = DIV_U71,
  1804. .parent = &tegra_pll_c,
  1805. .reg = 0x84,
  1806. .reg_shift = 0,
  1807. .max_rate = 700000000,
  1808. };
  1809. static struct clk_pll_freq_table tegra_pll_m_freq_table[] = {
  1810. { 12000000, 666000000, 666, 12, 1, 8},
  1811. { 13000000, 666000000, 666, 13, 1, 8},
  1812. { 16800000, 666000000, 555, 14, 1, 8},
  1813. { 19200000, 666000000, 555, 16, 1, 8},
  1814. { 26000000, 666000000, 666, 26, 1, 8},
  1815. { 12000000, 600000000, 600, 12, 1, 8},
  1816. { 13000000, 600000000, 600, 13, 1, 8},
  1817. { 16800000, 600000000, 500, 14, 1, 8},
  1818. { 19200000, 600000000, 375, 12, 1, 6},
  1819. { 26000000, 600000000, 600, 26, 1, 8},
  1820. { 0, 0, 0, 0, 0, 0 },
  1821. };
  1822. static struct clk tegra_pll_m = {
  1823. .name = "pll_m",
  1824. .flags = PLL_HAS_CPCON | PLLM,
  1825. .ops = &tegra_pll_ops,
  1826. .reg = 0x90,
  1827. .parent = &tegra_pll_ref,
  1828. .max_rate = 800000000,
  1829. .u.pll = {
  1830. .input_min = 2000000,
  1831. .input_max = 31000000,
  1832. .cf_min = 1000000,
  1833. .cf_max = 6000000,
  1834. .vco_min = 20000000,
  1835. .vco_max = 1200000000,
  1836. .freq_table = tegra_pll_m_freq_table,
  1837. .lock_delay = 300,
  1838. },
  1839. };
  1840. static struct clk tegra_pll_m_out1 = {
  1841. .name = "pll_m_out1",
  1842. .ops = &tegra_pll_div_ops,
  1843. .flags = DIV_U71,
  1844. .parent = &tegra_pll_m,
  1845. .reg = 0x94,
  1846. .reg_shift = 0,
  1847. .max_rate = 600000000,
  1848. };
  1849. static struct clk_pll_freq_table tegra_pll_p_freq_table[] = {
  1850. { 12000000, 216000000, 432, 12, 2, 8},
  1851. { 13000000, 216000000, 432, 13, 2, 8},
  1852. { 16800000, 216000000, 360, 14, 2, 8},
  1853. { 19200000, 216000000, 360, 16, 2, 8},
  1854. { 26000000, 216000000, 432, 26, 2, 8},
  1855. { 0, 0, 0, 0, 0, 0 },
  1856. };
  1857. static struct clk tegra_pll_p = {
  1858. .name = "pll_p",
  1859. .flags = ENABLE_ON_INIT | PLL_FIXED | PLL_HAS_CPCON,
  1860. .ops = &tegra_pll_ops,
  1861. .reg = 0xa0,
  1862. .parent = &tegra_pll_ref,
  1863. .max_rate = 432000000,
  1864. .u.pll = {
  1865. .input_min = 2000000,
  1866. .input_max = 31000000,
  1867. .cf_min = 1000000,
  1868. .cf_max = 6000000,
  1869. .vco_min = 20000000,
  1870. .vco_max = 1400000000,
  1871. .freq_table = tegra_pll_p_freq_table,
  1872. .lock_delay = 300,
  1873. .fixed_rate = 408000000,
  1874. },
  1875. };
  1876. static struct clk tegra_pll_p_out1 = {
  1877. .name = "pll_p_out1",
  1878. .ops = &tegra_pll_div_ops,
  1879. .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
  1880. .parent = &tegra_pll_p,
  1881. .reg = 0xa4,
  1882. .reg_shift = 0,
  1883. .max_rate = 432000000,
  1884. };
  1885. static struct clk tegra_pll_p_out2 = {
  1886. .name = "pll_p_out2",
  1887. .ops = &tegra_pll_div_ops,
  1888. .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
  1889. .parent = &tegra_pll_p,
  1890. .reg = 0xa4,
  1891. .reg_shift = 16,
  1892. .max_rate = 432000000,
  1893. };
  1894. static struct clk tegra_pll_p_out3 = {
  1895. .name = "pll_p_out3",
  1896. .ops = &tegra_pll_div_ops,
  1897. .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
  1898. .parent = &tegra_pll_p,
  1899. .reg = 0xa8,
  1900. .reg_shift = 0,
  1901. .max_rate = 432000000,
  1902. };
  1903. static struct clk tegra_pll_p_out4 = {
  1904. .name = "pll_p_out4",
  1905. .ops = &tegra_pll_div_ops,
  1906. .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
  1907. .parent = &tegra_pll_p,
  1908. .reg = 0xa8,
  1909. .reg_shift = 16,
  1910. .max_rate = 432000000,
  1911. };
  1912. static struct clk_pll_freq_table tegra_pll_a_freq_table[] = {
  1913. { 9600000, 564480000, 294, 5, 1, 4},
  1914. { 9600000, 552960000, 288, 5, 1, 4},
  1915. { 9600000, 24000000, 5, 2, 1, 1},
  1916. { 28800000, 56448000, 49, 25, 1, 1},
  1917. { 28800000, 73728000, 64, 25, 1, 1},
  1918. { 28800000, 24000000, 5, 6, 1, 1},
  1919. { 0, 0, 0, 0, 0, 0 },
  1920. };
  1921. static struct clk tegra_pll_a = {
  1922. .name = "pll_a",
  1923. .flags = PLL_HAS_CPCON,
  1924. .ops = &tegra_pll_ops,
  1925. .reg = 0xb0,
  1926. .parent = &tegra_pll_p_out1,
  1927. .max_rate = 700000000,
  1928. .u.pll = {
  1929. .input_min = 2000000,
  1930. .input_max = 31000000,
  1931. .cf_min = 1000000,
  1932. .cf_max = 6000000,
  1933. .vco_min = 20000000,
  1934. .vco_max = 1400000000,
  1935. .freq_table = tegra_pll_a_freq_table,
  1936. .lock_delay = 300,
  1937. },
  1938. };
  1939. static struct clk tegra_pll_a_out0 = {
  1940. .name = "pll_a_out0",
  1941. .ops = &tegra_pll_div_ops,
  1942. .flags = DIV_U71,
  1943. .parent = &tegra_pll_a,
  1944. .reg = 0xb4,
  1945. .reg_shift = 0,
  1946. .max_rate = 100000000,
  1947. };
  1948. static struct clk_pll_freq_table tegra_pll_d_freq_table[] = {
  1949. { 12000000, 216000000, 216, 12, 1, 4},
  1950. { 13000000, 216000000, 216, 13, 1, 4},
  1951. { 16800000, 216000000, 180, 14, 1, 4},
  1952. { 19200000, 216000000, 180, 16, 1, 4},
  1953. { 26000000, 216000000, 216, 26, 1, 4},
  1954. { 12000000, 594000000, 594, 12, 1, 8},
  1955. { 13000000, 594000000, 594, 13, 1, 8},
  1956. { 16800000, 594000000, 495, 14, 1, 8},
  1957. { 19200000, 594000000, 495, 16, 1, 8},
  1958. { 26000000, 594000000, 594, 26, 1, 8},
  1959. { 12000000, 1000000000, 1000, 12, 1, 12},
  1960. { 13000000, 1000000000, 1000, 13, 1, 12},
  1961. { 19200000, 1000000000, 625, 12, 1, 8},
  1962. { 26000000, 1000000000, 1000, 26, 1, 12},
  1963. { 0, 0, 0, 0, 0, 0 },
  1964. };
  1965. static struct clk tegra_pll_d = {
  1966. .name = "pll_d",
  1967. .flags = PLL_HAS_CPCON | PLLD,
  1968. .ops = &tegra_plld_ops,
  1969. .reg = 0xd0,
  1970. .parent = &tegra_pll_ref,
  1971. .max_rate = 1000000000,
  1972. .u.pll = {
  1973. .input_min = 2000000,
  1974. .input_max = 40000000,
  1975. .cf_min = 1000000,
  1976. .cf_max = 6000000,
  1977. .vco_min = 40000000,
  1978. .vco_max = 1000000000,
  1979. .freq_table = tegra_pll_d_freq_table,
  1980. .lock_delay = 1000,
  1981. },
  1982. };
  1983. static struct clk tegra_pll_d_out0 = {
  1984. .name = "pll_d_out0",
  1985. .ops = &tegra_pll_div_ops,
  1986. .flags = DIV_2 | PLLD,
  1987. .parent = &tegra_pll_d,
  1988. .max_rate = 500000000,
  1989. };
  1990. static struct clk tegra_pll_d2 = {
  1991. .name = "pll_d2",
  1992. .flags = PLL_HAS_CPCON | PLL_ALT_MISC_REG | PLLD,
  1993. .ops = &tegra_plld_ops,
  1994. .reg = 0x4b8,
  1995. .parent = &tegra_pll_ref,
  1996. .max_rate = 1000000000,
  1997. .u.pll = {
  1998. .input_min = 2000000,
  1999. .input_max = 40000000,
  2000. .cf_min = 1000000,
  2001. .cf_max = 6000000,
  2002. .vco_min = 40000000,
  2003. .vco_max = 1000000000,
  2004. .freq_table = tegra_pll_d_freq_table,
  2005. .lock_delay = 1000,
  2006. },
  2007. };
  2008. static struct clk tegra_pll_d2_out0 = {
  2009. .name = "pll_d2_out0",
  2010. .ops = &tegra_pll_div_ops,
  2011. .flags = DIV_2 | PLLD,
  2012. .parent = &tegra_pll_d2,
  2013. .max_rate = 500000000,
  2014. };
  2015. static struct clk_pll_freq_table tegra_pll_u_freq_table[] = {
  2016. { 12000000, 480000000, 960, 12, 2, 12},
  2017. { 13000000, 480000000, 960, 13, 2, 12},
  2018. { 16800000, 480000000, 400, 7, 2, 5},
  2019. { 19200000, 480000000, 200, 4, 2, 3},
  2020. { 26000000, 480000000, 960, 26, 2, 12},
  2021. { 0, 0, 0, 0, 0, 0 },
  2022. };
  2023. static struct clk tegra_pll_u = {
  2024. .name = "pll_u",
  2025. .flags = PLL_HAS_CPCON | PLLU,
  2026. .ops = &tegra_pll_ops,
  2027. .reg = 0xc0,
  2028. .parent = &tegra_pll_ref,
  2029. .max_rate = 480000000,
  2030. .u.pll = {
  2031. .input_min = 2000000,
  2032. .input_max = 40000000,
  2033. .cf_min = 1000000,
  2034. .cf_max = 6000000,
  2035. .vco_min = 480000000,
  2036. .vco_max = 960000000,
  2037. .freq_table = tegra_pll_u_freq_table,
  2038. .lock_delay = 1000,
  2039. },
  2040. };
  2041. static struct clk_pll_freq_table tegra_pll_x_freq_table[] = {
  2042. /* 1.7 GHz */
  2043. { 12000000, 1700000000, 850, 6, 1, 8},
  2044. { 13000000, 1700000000, 915, 7, 1, 8}, /* actual: 1699.2 MHz */
  2045. { 16800000, 1700000000, 708, 7, 1, 8}, /* actual: 1699.2 MHz */
  2046. { 19200000, 1700000000, 885, 10, 1, 8}, /* actual: 1699.2 MHz */
  2047. { 26000000, 1700000000, 850, 13, 1, 8},
  2048. /* 1.6 GHz */
  2049. { 12000000, 1600000000, 800, 6, 1, 8},
  2050. { 13000000, 1600000000, 738, 6, 1, 8}, /* actual: 1599.0 MHz */
  2051. { 16800000, 1600000000, 857, 9, 1, 8}, /* actual: 1599.7 MHz */
  2052. { 19200000, 1600000000, 500, 6, 1, 8},
  2053. { 26000000, 1600000000, 800, 13, 1, 8},
  2054. /* 1.5 GHz */
  2055. { 12000000, 1500000000, 750, 6, 1, 8},
  2056. { 13000000, 1500000000, 923, 8, 1, 8}, /* actual: 1499.8 MHz */
  2057. { 16800000, 1500000000, 625, 7, 1, 8},
  2058. { 19200000, 1500000000, 625, 8, 1, 8},
  2059. { 26000000, 1500000000, 750, 13, 1, 8},
  2060. /* 1.4 GHz */
  2061. { 12000000, 1400000000, 700, 6, 1, 8},
  2062. { 13000000, 1400000000, 969, 9, 1, 8}, /* actual: 1399.7 MHz */
  2063. { 16800000, 1400000000, 1000, 12, 1, 8},
  2064. { 19200000, 1400000000, 875, 12, 1, 8},
  2065. { 26000000, 1400000000, 700, 13, 1, 8},
  2066. /* 1.3 GHz */
  2067. { 12000000, 1300000000, 975, 9, 1, 8},
  2068. { 13000000, 1300000000, 1000, 10, 1, 8},
  2069. { 16800000, 1300000000, 928, 12, 1, 8}, /* actual: 1299.2 MHz */
  2070. { 19200000, 1300000000, 812, 12, 1, 8}, /* actual: 1299.2 MHz */
  2071. { 26000000, 1300000000, 650, 13, 1, 8},
  2072. /* 1.2 GHz */
  2073. { 12000000, 1200000000, 1000, 10, 1, 8},
  2074. { 13000000, 1200000000, 923, 10, 1, 8}, /* actual: 1199.9 MHz */
  2075. { 16800000, 1200000000, 1000, 14, 1, 8},
  2076. { 19200000, 1200000000, 1000, 16, 1, 8},
  2077. { 26000000, 1200000000, 600, 13, 1, 8},
  2078. /* 1.1 GHz */
  2079. { 12000000, 1100000000, 825, 9, 1, 8},
  2080. { 13000000, 1100000000, 846, 10, 1, 8}, /* actual: 1099.8 MHz */
  2081. { 16800000, 1100000000, 982, 15, 1, 8}, /* actual: 1099.8 MHz */
  2082. { 19200000, 1100000000, 859, 15, 1, 8}, /* actual: 1099.5 MHz */
  2083. { 26000000, 1100000000, 550, 13, 1, 8},
  2084. /* 1 GHz */
  2085. { 12000000, 1000000000, 1000, 12, 1, 8},
  2086. { 13000000, 1000000000, 1000, 13, 1, 8},
  2087. { 16800000, 1000000000, 833, 14, 1, 8}, /* actual: 999.6 MHz */
  2088. { 19200000, 1000000000, 625, 12, 1, 8},
  2089. { 26000000, 1000000000, 1000, 26, 1, 8},
  2090. { 0, 0, 0, 0, 0, 0 },
  2091. };
  2092. static struct clk tegra_pll_x = {
  2093. .name = "pll_x",
  2094. .flags = PLL_HAS_CPCON | PLL_ALT_MISC_REG | PLLX,
  2095. .ops = &tegra_pll_ops,
  2096. .reg = 0xe0,
  2097. .parent = &tegra_pll_ref,
  2098. .max_rate = 1700000000,
  2099. .u.pll = {
  2100. .input_min = 2000000,
  2101. .input_max = 31000000,
  2102. .cf_min = 1000000,
  2103. .cf_max = 6000000,
  2104. .vco_min = 20000000,
  2105. .vco_max = 1700000000,
  2106. .freq_table = tegra_pll_x_freq_table,
  2107. .lock_delay = 300,
  2108. },
  2109. };
  2110. static struct clk tegra_pll_x_out0 = {
  2111. .name = "pll_x_out0",
  2112. .ops = &tegra_pll_div_ops,
  2113. .flags = DIV_2 | PLLX,
  2114. .parent = &tegra_pll_x,
  2115. .max_rate = 850000000,
  2116. };
  2117. static struct clk_pll_freq_table tegra_pll_e_freq_table[] = {
  2118. /* PLLE special case: use cpcon field to store cml divider value */
  2119. { 12000000, 100000000, 150, 1, 18, 11},
  2120. { 216000000, 100000000, 200, 18, 24, 13},
  2121. { 0, 0, 0, 0, 0, 0 },
  2122. };
  2123. static struct clk tegra_pll_e = {
  2124. .name = "pll_e",
  2125. .flags = PLL_ALT_MISC_REG,
  2126. .ops = &tegra_plle_ops,
  2127. .reg = 0xe8,
  2128. .max_rate = 100000000,
  2129. .u.pll = {
  2130. .input_min = 12000000,
  2131. .input_max = 216000000,
  2132. .cf_min = 12000000,
  2133. .cf_max = 12000000,
  2134. .vco_min = 1200000000,
  2135. .vco_max = 2400000000U,
  2136. .freq_table = tegra_pll_e_freq_table,
  2137. .lock_delay = 300,
  2138. .fixed_rate = 100000000,
  2139. },
  2140. };
  2141. static struct clk tegra_cml0_clk = {
  2142. .name = "cml0",
  2143. .parent = &tegra_pll_e,
  2144. .ops = &tegra_cml_clk_ops,
  2145. .reg = PLLE_AUX,
  2146. .max_rate = 100000000,
  2147. .u.periph = {
  2148. .clk_num = 0,
  2149. },
  2150. };
  2151. static struct clk tegra_cml1_clk = {
  2152. .name = "cml1",
  2153. .parent = &tegra_pll_e,
  2154. .ops = &tegra_cml_clk_ops,
  2155. .reg = PLLE_AUX,
  2156. .max_rate = 100000000,
  2157. .u.periph = {
  2158. .clk_num = 1,
  2159. },
  2160. };
  2161. static struct clk tegra_pciex_clk = {
  2162. .name = "pciex",
  2163. .parent = &tegra_pll_e,
  2164. .ops = &tegra_pciex_clk_ops,
  2165. .max_rate = 100000000,
  2166. .u.periph = {
  2167. .clk_num = 74,
  2168. },
  2169. };
  2170. /* Audio sync clocks */
  2171. #define SYNC_SOURCE(_id) \
  2172. { \
  2173. .name = #_id "_sync", \
  2174. .rate = 24000000, \
  2175. .max_rate = 24000000, \
  2176. .ops = &tegra_sync_source_ops \
  2177. }
  2178. static struct clk tegra_sync_source_list[] = {
  2179. SYNC_SOURCE(spdif_in),
  2180. SYNC_SOURCE(i2s0),
  2181. SYNC_SOURCE(i2s1),
  2182. SYNC_SOURCE(i2s2),
  2183. SYNC_SOURCE(i2s3),
  2184. SYNC_SOURCE(i2s4),
  2185. SYNC_SOURCE(vimclk),
  2186. };
  2187. static struct clk_mux_sel mux_audio_sync_clk[] = {
  2188. { .input = &tegra_sync_source_list[0], .value = 0},
  2189. { .input = &tegra_sync_source_list[1], .value = 1},
  2190. { .input = &tegra_sync_source_list[2], .value = 2},
  2191. { .input = &tegra_sync_source_list[3], .value = 3},
  2192. { .input = &tegra_sync_source_list[4], .value = 4},
  2193. { .input = &tegra_sync_source_list[5], .value = 5},
  2194. { .input = &tegra_pll_a_out0, .value = 6},
  2195. { .input = &tegra_sync_source_list[6], .value = 7},
  2196. { 0, 0 }
  2197. };
  2198. #define AUDIO_SYNC_CLK(_id, _index) \
  2199. { \
  2200. .name = #_id, \
  2201. .inputs = mux_audio_sync_clk, \
  2202. .reg = 0x4A0 + (_index) * 4, \
  2203. .max_rate = 24000000, \
  2204. .ops = &tegra_audio_sync_clk_ops \
  2205. }
  2206. static struct clk tegra_clk_audio_list[] = {
  2207. AUDIO_SYNC_CLK(audio0, 0),
  2208. AUDIO_SYNC_CLK(audio1, 1),
  2209. AUDIO_SYNC_CLK(audio2, 2),
  2210. AUDIO_SYNC_CLK(audio3, 3),
  2211. AUDIO_SYNC_CLK(audio4, 4),
  2212. AUDIO_SYNC_CLK(audio, 5), /* SPDIF */
  2213. };
  2214. #define AUDIO_SYNC_2X_CLK(_id, _index) \
  2215. { \
  2216. .name = #_id "_2x", \
  2217. .flags = PERIPH_NO_RESET, \
  2218. .max_rate = 48000000, \
  2219. .ops = &tegra_clk_double_ops, \
  2220. .reg = 0x49C, \
  2221. .reg_shift = 24 + (_index), \
  2222. .parent = &tegra_clk_audio_list[(_index)], \
  2223. .u.periph = { \
  2224. .clk_num = 113 + (_index), \
  2225. }, \
  2226. }
  2227. static struct clk tegra_clk_audio_2x_list[] = {
  2228. AUDIO_SYNC_2X_CLK(audio0, 0),
  2229. AUDIO_SYNC_2X_CLK(audio1, 1),
  2230. AUDIO_SYNC_2X_CLK(audio2, 2),
  2231. AUDIO_SYNC_2X_CLK(audio3, 3),
  2232. AUDIO_SYNC_2X_CLK(audio4, 4),
  2233. AUDIO_SYNC_2X_CLK(audio, 5), /* SPDIF */
  2234. };
  2235. #define MUX_I2S_SPDIF(_id, _index) \
  2236. static struct clk_mux_sel mux_pllaout0_##_id##_2x_pllp_clkm[] = { \
  2237. {.input = &tegra_pll_a_out0, .value = 0}, \
  2238. {.input = &tegra_clk_audio_2x_list[(_index)], .value = 1}, \
  2239. {.input = &tegra_pll_p, .value = 2}, \
  2240. {.input = &tegra_clk_m, .value = 3}, \
  2241. { 0, 0}, \
  2242. }
  2243. MUX_I2S_SPDIF(audio0, 0);
  2244. MUX_I2S_SPDIF(audio1, 1);
  2245. MUX_I2S_SPDIF(audio2, 2);
  2246. MUX_I2S_SPDIF(audio3, 3);
  2247. MUX_I2S_SPDIF(audio4, 4);
  2248. MUX_I2S_SPDIF(audio, 5); /* SPDIF */
  2249. /* External clock outputs (through PMC) */
  2250. #define MUX_EXTERN_OUT(_id) \
  2251. static struct clk_mux_sel mux_clkm_clkm2_clkm4_extern##_id[] = { \
  2252. {.input = &tegra_clk_m, .value = 0}, \
  2253. {.input = &tegra_clk_m_div2, .value = 1}, \
  2254. {.input = &tegra_clk_m_div4, .value = 2}, \
  2255. {.input = NULL, .value = 3}, /* placeholder */ \
  2256. { 0, 0}, \
  2257. }
  2258. MUX_EXTERN_OUT(1);
  2259. MUX_EXTERN_OUT(2);
  2260. MUX_EXTERN_OUT(3);
  2261. static struct clk_mux_sel *mux_extern_out_list[] = {
  2262. mux_clkm_clkm2_clkm4_extern1,
  2263. mux_clkm_clkm2_clkm4_extern2,
  2264. mux_clkm_clkm2_clkm4_extern3,
  2265. };
  2266. #define CLK_OUT_CLK(_id) \
  2267. { \
  2268. .name = "clk_out_" #_id, \
  2269. .lookup = { \
  2270. .dev_id = "clk_out_" #_id, \
  2271. .con_id = "extern" #_id, \
  2272. }, \
  2273. .ops = &tegra_clk_out_ops, \
  2274. .reg = 0x1a8, \
  2275. .inputs = mux_clkm_clkm2_clkm4_extern##_id, \
  2276. .flags = MUX_CLK_OUT, \
  2277. .max_rate = 216000000, \
  2278. .u.periph = { \
  2279. .clk_num = (_id - 1) * 8 + 2, \
  2280. }, \
  2281. }
  2282. static struct clk tegra_clk_out_list[] = {
  2283. CLK_OUT_CLK(1),
  2284. CLK_OUT_CLK(2),
  2285. CLK_OUT_CLK(3),
  2286. };
  2287. /* called after peripheral external clocks are initialized */
  2288. static void init_clk_out_mux(void)
  2289. {
  2290. int i;
  2291. struct clk *c;
  2292. /* output clock con_id is the name of peripheral
  2293. external clock connected to input 3 of the output mux */
  2294. for (i = 0; i < ARRAY_SIZE(tegra_clk_out_list); i++) {
  2295. c = tegra_get_clock_by_name(
  2296. tegra_clk_out_list[i].lookup.con_id);
  2297. if (!c)
  2298. pr_err("%s: could not find clk %s\n", __func__,
  2299. tegra_clk_out_list[i].lookup.con_id);
  2300. mux_extern_out_list[i][3].input = c;
  2301. }
  2302. }
  2303. /* Peripheral muxes */
  2304. static struct clk_mux_sel mux_sclk[] = {
  2305. { .input = &tegra_clk_m, .value = 0},
  2306. { .input = &tegra_pll_c_out1, .value = 1},
  2307. { .input = &tegra_pll_p_out4, .value = 2},
  2308. { .input = &tegra_pll_p_out3, .value = 3},
  2309. { .input = &tegra_pll_p_out2, .value = 4},
  2310. /* { .input = &tegra_clk_d, .value = 5}, - no use on tegra30 */
  2311. { .input = &tegra_clk_32k, .value = 6},
  2312. { .input = &tegra_pll_m_out1, .value = 7},
  2313. { 0, 0},
  2314. };
  2315. static struct clk tegra_clk_sclk = {
  2316. .name = "sclk",
  2317. .inputs = mux_sclk,
  2318. .reg = 0x28,
  2319. .ops = &tegra_super_ops,
  2320. .max_rate = 334000000,
  2321. .min_rate = 40000000,
  2322. };
  2323. static struct clk tegra_clk_blink = {
  2324. .name = "blink",
  2325. .parent = &tegra_clk_32k,
  2326. .reg = 0x40,
  2327. .ops = &tegra_blink_clk_ops,
  2328. .max_rate = 32768,
  2329. };
  2330. static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = {
  2331. { .input = &tegra_pll_m, .value = 0},
  2332. { .input = &tegra_pll_c, .value = 1},
  2333. { .input = &tegra_pll_p, .value = 2},
  2334. { .input = &tegra_pll_a_out0, .value = 3},
  2335. { 0, 0},
  2336. };
  2337. static struct clk_mux_sel mux_pllp_pllc_pllm_clkm[] = {
  2338. { .input = &tegra_pll_p, .value = 0},
  2339. { .input = &tegra_pll_c, .value = 1},
  2340. { .input = &tegra_pll_m, .value = 2},
  2341. { .input = &tegra_clk_m, .value = 3},
  2342. { 0, 0},
  2343. };
  2344. static struct clk_mux_sel mux_pllp_clkm[] = {
  2345. { .input = &tegra_pll_p, .value = 0},
  2346. { .input = &tegra_clk_m, .value = 3},
  2347. { 0, 0},
  2348. };
  2349. static struct clk_mux_sel mux_pllp_plld_pllc_clkm[] = {
  2350. {.input = &tegra_pll_p, .value = 0},
  2351. {.input = &tegra_pll_d_out0, .value = 1},
  2352. {.input = &tegra_pll_c, .value = 2},
  2353. {.input = &tegra_clk_m, .value = 3},
  2354. { 0, 0},
  2355. };
  2356. static struct clk_mux_sel mux_pllp_pllm_plld_plla_pllc_plld2_clkm[] = {
  2357. {.input = &tegra_pll_p, .value = 0},
  2358. {.input = &tegra_pll_m, .value = 1},
  2359. {.input = &tegra_pll_d_out0, .value = 2},
  2360. {.input = &tegra_pll_a_out0, .value = 3},
  2361. {.input = &tegra_pll_c, .value = 4},
  2362. {.input = &tegra_pll_d2_out0, .value = 5},
  2363. {.input = &tegra_clk_m, .value = 6},
  2364. { 0, 0},
  2365. };
  2366. static struct clk_mux_sel mux_plla_pllc_pllp_clkm[] = {
  2367. { .input = &tegra_pll_a_out0, .value = 0},
  2368. /* { .input = &tegra_pll_c, .value = 1}, no use on tegra30 */
  2369. { .input = &tegra_pll_p, .value = 2},
  2370. { .input = &tegra_clk_m, .value = 3},
  2371. { 0, 0},
  2372. };
  2373. static struct clk_mux_sel mux_pllp_pllc_clk32_clkm[] = {
  2374. {.input = &tegra_pll_p, .value = 0},
  2375. {.input = &tegra_pll_c, .value = 1},
  2376. {.input = &tegra_clk_32k, .value = 2},
  2377. {.input = &tegra_clk_m, .value = 3},
  2378. { 0, 0},
  2379. };
  2380. static struct clk_mux_sel mux_pllp_pllc_clkm_clk32[] = {
  2381. {.input = &tegra_pll_p, .value = 0},
  2382. {.input = &tegra_pll_c, .value = 1},
  2383. {.input = &tegra_clk_m, .value = 2},
  2384. {.input = &tegra_clk_32k, .value = 3},
  2385. { 0, 0},
  2386. };
  2387. static struct clk_mux_sel mux_pllp_pllc_pllm[] = {
  2388. {.input = &tegra_pll_p, .value = 0},
  2389. {.input = &tegra_pll_c, .value = 1},
  2390. {.input = &tegra_pll_m, .value = 2},
  2391. { 0, 0},
  2392. };
  2393. static struct clk_mux_sel mux_clk_m[] = {
  2394. { .input = &tegra_clk_m, .value = 0},
  2395. { 0, 0},
  2396. };
  2397. static struct clk_mux_sel mux_pllp_out3[] = {
  2398. { .input = &tegra_pll_p_out3, .value = 0},
  2399. { 0, 0},
  2400. };
  2401. static struct clk_mux_sel mux_plld_out0[] = {
  2402. { .input = &tegra_pll_d_out0, .value = 0},
  2403. { 0, 0},
  2404. };
  2405. static struct clk_mux_sel mux_plld_out0_plld2_out0[] = {
  2406. { .input = &tegra_pll_d_out0, .value = 0},
  2407. { .input = &tegra_pll_d2_out0, .value = 1},
  2408. { 0, 0},
  2409. };
  2410. static struct clk_mux_sel mux_clk_32k[] = {
  2411. { .input = &tegra_clk_32k, .value = 0},
  2412. { 0, 0},
  2413. };
  2414. static struct clk_mux_sel mux_plla_clk32_pllp_clkm_plle[] = {
  2415. { .input = &tegra_pll_a_out0, .value = 0},
  2416. { .input = &tegra_clk_32k, .value = 1},
  2417. { .input = &tegra_pll_p, .value = 2},
  2418. { .input = &tegra_clk_m, .value = 3},
  2419. { .input = &tegra_pll_e, .value = 4},
  2420. { 0, 0},
  2421. };
  2422. static struct clk_mux_sel mux_cclk_g[] = {
  2423. { .input = &tegra_clk_m, .value = 0},
  2424. { .input = &tegra_pll_c, .value = 1},
  2425. { .input = &tegra_clk_32k, .value = 2},
  2426. { .input = &tegra_pll_m, .value = 3},
  2427. { .input = &tegra_pll_p, .value = 4},
  2428. { .input = &tegra_pll_p_out4, .value = 5},
  2429. { .input = &tegra_pll_p_out3, .value = 6},
  2430. { .input = &tegra_pll_x, .value = 8},
  2431. { 0, 0},
  2432. };
  2433. static struct clk tegra_clk_cclk_g = {
  2434. .name = "cclk_g",
  2435. .flags = DIV_U71 | DIV_U71_INT,
  2436. .inputs = mux_cclk_g,
  2437. .reg = 0x368,
  2438. .ops = &tegra_super_ops,
  2439. .max_rate = 1700000000,
  2440. };
  2441. static struct clk tegra30_clk_twd = {
  2442. .parent = &tegra_clk_cclk_g,
  2443. .name = "twd",
  2444. .ops = &tegra30_twd_ops,
  2445. .max_rate = 1400000000, /* Same as tegra_clk_cpu_cmplx.max_rate */
  2446. .mul = 1,
  2447. .div = 2,
  2448. };
  2449. #define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags) \
  2450. { \
  2451. .name = _name, \
  2452. .lookup = { \
  2453. .dev_id = _dev, \
  2454. .con_id = _con, \
  2455. }, \
  2456. .ops = &tegra_periph_clk_ops, \
  2457. .reg = _reg, \
  2458. .inputs = _inputs, \
  2459. .flags = _flags, \
  2460. .max_rate = _max, \
  2461. .u.periph = { \
  2462. .clk_num = _clk_num, \
  2463. }, \
  2464. }
  2465. #define PERIPH_CLK_EX(_name, _dev, _con, _clk_num, _reg, _max, _inputs, \
  2466. _flags, _ops) \
  2467. { \
  2468. .name = _name, \
  2469. .lookup = { \
  2470. .dev_id = _dev, \
  2471. .con_id = _con, \
  2472. }, \
  2473. .ops = _ops, \
  2474. .reg = _reg, \
  2475. .inputs = _inputs, \
  2476. .flags = _flags, \
  2477. .max_rate = _max, \
  2478. .u.periph = { \
  2479. .clk_num = _clk_num, \
  2480. }, \
  2481. }
  2482. #define SHARED_CLK(_name, _dev, _con, _parent, _id, _div, _mode)\
  2483. { \
  2484. .name = _name, \
  2485. .lookup = { \
  2486. .dev_id = _dev, \
  2487. .con_id = _con, \
  2488. }, \
  2489. .ops = &tegra_clk_shared_bus_ops, \
  2490. .parent = _parent, \
  2491. .u.shared_bus_user = { \
  2492. .client_id = _id, \
  2493. .client_div = _div, \
  2494. .mode = _mode, \
  2495. }, \
  2496. }
  2497. struct clk tegra_list_clks[] = {
  2498. PERIPH_CLK("apbdma", "tegra-apbdma", NULL, 34, 0, 26000000, mux_clk_m, 0),
  2499. PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, 32768, mux_clk_32k, PERIPH_NO_RESET | PERIPH_ON_APB),
  2500. PERIPH_CLK("kbc", "tegra-kbc", NULL, 36, 0, 32768, mux_clk_32k, PERIPH_NO_RESET | PERIPH_ON_APB),
  2501. PERIPH_CLK("timer", "timer", NULL, 5, 0, 26000000, mux_clk_m, 0),
  2502. PERIPH_CLK("kfuse", "kfuse-tegra", NULL, 40, 0, 26000000, mux_clk_m, 0),
  2503. PERIPH_CLK("fuse", "fuse-tegra", "fuse", 39, 0, 26000000, mux_clk_m, PERIPH_ON_APB),
  2504. PERIPH_CLK("fuse_burn", "fuse-tegra", "fuse_burn", 39, 0, 26000000, mux_clk_m, PERIPH_ON_APB),
  2505. PERIPH_CLK("apbif", "tegra30-ahub", "apbif", 107, 0, 26000000, mux_clk_m, 0),
  2506. PERIPH_CLK("i2s0", "tegra30-i2s.0", NULL, 30, 0x1d8, 26000000, mux_pllaout0_audio0_2x_pllp_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2507. PERIPH_CLK("i2s1", "tegra30-i2s.1", NULL, 11, 0x100, 26000000, mux_pllaout0_audio1_2x_pllp_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2508. PERIPH_CLK("i2s2", "tegra30-i2s.2", NULL, 18, 0x104, 26000000, mux_pllaout0_audio2_2x_pllp_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2509. PERIPH_CLK("i2s3", "tegra30-i2s.3", NULL, 101, 0x3bc, 26000000, mux_pllaout0_audio3_2x_pllp_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2510. PERIPH_CLK("i2s4", "tegra30-i2s.4", NULL, 102, 0x3c0, 26000000, mux_pllaout0_audio4_2x_pllp_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2511. PERIPH_CLK("spdif_out", "tegra30-spdif", "spdif_out", 10, 0x108, 100000000, mux_pllaout0_audio_2x_pllp_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2512. PERIPH_CLK("spdif_in", "tegra30-spdif", "spdif_in", 10, 0x10c, 100000000, mux_pllp_pllc_pllm, MUX | DIV_U71 | PERIPH_ON_APB),
  2513. PERIPH_CLK("pwm", "tegra-pwm", NULL, 17, 0x110, 432000000, mux_pllp_pllc_clk32_clkm, MUX | MUX_PWM | DIV_U71 | PERIPH_ON_APB),
  2514. PERIPH_CLK("d_audio", "tegra30-ahub", "d_audio", 106, 0x3d0, 48000000, mux_plla_pllc_pllp_clkm, MUX | DIV_U71),
  2515. PERIPH_CLK("dam0", "tegra30-dam.0", NULL, 108, 0x3d8, 48000000, mux_plla_pllc_pllp_clkm, MUX | DIV_U71),
  2516. PERIPH_CLK("dam1", "tegra30-dam.1", NULL, 109, 0x3dc, 48000000, mux_plla_pllc_pllp_clkm, MUX | DIV_U71),
  2517. PERIPH_CLK("dam2", "tegra30-dam.2", NULL, 110, 0x3e0, 48000000, mux_plla_pllc_pllp_clkm, MUX | DIV_U71),
  2518. PERIPH_CLK("hda", "tegra30-hda", "hda", 125, 0x428, 108000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  2519. PERIPH_CLK("hda2codec_2x", "tegra30-hda", "hda2codec", 111, 0x3e4, 48000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  2520. PERIPH_CLK("hda2hdmi", "tegra30-hda", "hda2hdmi", 128, 0, 48000000, mux_clk_m, 0),
  2521. PERIPH_CLK("sbc1", "spi_tegra.0", NULL, 41, 0x134, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2522. PERIPH_CLK("sbc2", "spi_tegra.1", NULL, 44, 0x118, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2523. PERIPH_CLK("sbc3", "spi_tegra.2", NULL, 46, 0x11c, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2524. PERIPH_CLK("sbc4", "spi_tegra.3", NULL, 68, 0x1b4, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2525. PERIPH_CLK("sbc5", "spi_tegra.4", NULL, 104, 0x3c8, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2526. PERIPH_CLK("sbc6", "spi_tegra.5", NULL, 105, 0x3cc, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2527. PERIPH_CLK("sata_oob", "tegra_sata_oob", NULL, 123, 0x420, 216000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  2528. PERIPH_CLK("sata", "tegra_sata", NULL, 124, 0x424, 216000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  2529. PERIPH_CLK("sata_cold", "tegra_sata_cold", NULL, 129, 0, 48000000, mux_clk_m, 0),
  2530. PERIPH_CLK_EX("ndflash", "tegra_nand", NULL, 13, 0x160, 240000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71, &tegra_nand_clk_ops),
  2531. PERIPH_CLK("ndspeed", "tegra_nand_speed", NULL, 80, 0x3f8, 240000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  2532. PERIPH_CLK("vfir", "vfir", NULL, 7, 0x168, 72000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2533. PERIPH_CLK("sdmmc1", "sdhci-tegra.0", NULL, 14, 0x150, 208000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
  2534. PERIPH_CLK("sdmmc2", "sdhci-tegra.1", NULL, 9, 0x154, 104000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
  2535. PERIPH_CLK("sdmmc3", "sdhci-tegra.2", NULL, 69, 0x1bc, 208000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
  2536. PERIPH_CLK("sdmmc4", "sdhci-tegra.3", NULL, 15, 0x164, 104000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
  2537. PERIPH_CLK("vcp", "tegra-avp", "vcp", 29, 0, 250000000, mux_clk_m, 0),
  2538. PERIPH_CLK("bsea", "tegra-avp", "bsea", 62, 0, 250000000, mux_clk_m, 0),
  2539. PERIPH_CLK("bsev", "tegra-aes", "bsev", 63, 0, 250000000, mux_clk_m, 0),
  2540. PERIPH_CLK("vde", "vde", NULL, 61, 0x1c8, 520000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | DIV_U71_INT),
  2541. PERIPH_CLK("csite", "csite", NULL, 73, 0x1d4, 144000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* max rate ??? */
  2542. PERIPH_CLK("la", "la", NULL, 76, 0x1f8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
  2543. PERIPH_CLK("owr", "tegra_w1", NULL, 71, 0x1cc, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2544. PERIPH_CLK("nor", "nor", NULL, 42, 0x1d0, 127000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
  2545. PERIPH_CLK("mipi", "mipi", NULL, 50, 0x174, 60000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | PERIPH_ON_APB), /* scales with voltage */
  2546. PERIPH_CLK("i2c1", "tegra-i2c.0", NULL, 12, 0x124, 26000000, mux_pllp_clkm, MUX | DIV_U16 | PERIPH_ON_APB),
  2547. PERIPH_CLK("i2c2", "tegra-i2c.1", NULL, 54, 0x198, 26000000, mux_pllp_clkm, MUX | DIV_U16 | PERIPH_ON_APB),
  2548. PERIPH_CLK("i2c3", "tegra-i2c.2", NULL, 67, 0x1b8, 26000000, mux_pllp_clkm, MUX | DIV_U16 | PERIPH_ON_APB),
  2549. PERIPH_CLK("i2c4", "tegra-i2c.3", NULL, 103, 0x3c4, 26000000, mux_pllp_clkm, MUX | DIV_U16 | PERIPH_ON_APB),
  2550. PERIPH_CLK("i2c5", "tegra-i2c.4", NULL, 47, 0x128, 26000000, mux_pllp_clkm, MUX | DIV_U16 | PERIPH_ON_APB),
  2551. PERIPH_CLK("uarta", "tegra-uart.0", NULL, 6, 0x178, 800000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | DIV_U71_UART | PERIPH_ON_APB),
  2552. PERIPH_CLK("uartb", "tegra-uart.1", NULL, 7, 0x17c, 800000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | DIV_U71_UART | PERIPH_ON_APB),
  2553. PERIPH_CLK("uartc", "tegra-uart.2", NULL, 55, 0x1a0, 800000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | DIV_U71_UART | PERIPH_ON_APB),
  2554. PERIPH_CLK("uartd", "tegra-uart.3", NULL, 65, 0x1c0, 800000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | DIV_U71_UART | PERIPH_ON_APB),
  2555. PERIPH_CLK("uarte", "tegra-uart.4", NULL, 66, 0x1c4, 800000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | DIV_U71_UART | PERIPH_ON_APB),
  2556. PERIPH_CLK_EX("vi", "tegra_camera", "vi", 20, 0x148, 425000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | DIV_U71_INT, &tegra_vi_clk_ops),
  2557. PERIPH_CLK("3d", "3d", NULL, 24, 0x158, 520000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | DIV_U71_INT | DIV_U71_IDLE | PERIPH_MANUAL_RESET),
  2558. PERIPH_CLK("3d2", "3d2", NULL, 98, 0x3b0, 520000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | DIV_U71_INT | DIV_U71_IDLE | PERIPH_MANUAL_RESET),
  2559. PERIPH_CLK("2d", "2d", NULL, 21, 0x15c, 520000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | DIV_U71_INT | DIV_U71_IDLE),
  2560. PERIPH_CLK("vi_sensor", "tegra_camera", "vi_sensor", 20, 0x1a8, 150000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | PERIPH_NO_RESET),
  2561. PERIPH_CLK("epp", "epp", NULL, 19, 0x16c, 520000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | DIV_U71_INT),
  2562. PERIPH_CLK("mpe", "mpe", NULL, 60, 0x170, 520000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | DIV_U71_INT),
  2563. PERIPH_CLK("host1x", "host1x", NULL, 28, 0x180, 260000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | DIV_U71_INT),
  2564. PERIPH_CLK("cve", "cve", NULL, 49, 0x140, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
  2565. PERIPH_CLK("tvo", "tvo", NULL, 49, 0x188, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
  2566. PERIPH_CLK_EX("dtv", "dtv", NULL, 79, 0x1dc, 250000000, mux_clk_m, 0, &tegra_dtv_clk_ops),
  2567. PERIPH_CLK("hdmi", "hdmi", NULL, 51, 0x18c, 148500000, mux_pllp_pllm_plld_plla_pllc_plld2_clkm, MUX | MUX8 | DIV_U71),
  2568. PERIPH_CLK("tvdac", "tvdac", NULL, 53, 0x194, 220000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
  2569. PERIPH_CLK("disp1", "tegradc.0", NULL, 27, 0x138, 600000000, mux_pllp_pllm_plld_plla_pllc_plld2_clkm, MUX | MUX8),
  2570. PERIPH_CLK("disp2", "tegradc.1", NULL, 26, 0x13c, 600000000, mux_pllp_pllm_plld_plla_pllc_plld2_clkm, MUX | MUX8),
  2571. PERIPH_CLK("usbd", "fsl-tegra-udc", NULL, 22, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
  2572. PERIPH_CLK("usb2", "tegra-ehci.1", NULL, 58, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
  2573. PERIPH_CLK("usb3", "tegra-ehci.2", NULL, 59, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
  2574. PERIPH_CLK("dsia", "tegradc.0", "dsia", 48, 0, 500000000, mux_plld_out0, 0),
  2575. PERIPH_CLK_EX("dsib", "tegradc.1", "dsib", 82, 0xd0, 500000000, mux_plld_out0_plld2_out0, MUX | PLLD, &tegra_dsib_clk_ops),
  2576. PERIPH_CLK("csi", "tegra_camera", "csi", 52, 0, 102000000, mux_pllp_out3, 0),
  2577. PERIPH_CLK("isp", "tegra_camera", "isp", 23, 0, 150000000, mux_clk_m, 0), /* same frequency as VI */
  2578. PERIPH_CLK("csus", "tegra_camera", "csus", 92, 0, 150000000, mux_clk_m, PERIPH_NO_RESET),
  2579. PERIPH_CLK("tsensor", "tegra-tsensor", NULL, 100, 0x3b8, 216000000, mux_pllp_pllc_clkm_clk32, MUX | DIV_U71),
  2580. PERIPH_CLK("actmon", "actmon", NULL, 119, 0x3e8, 216000000, mux_pllp_pllc_clk32_clkm, MUX | DIV_U71),
  2581. PERIPH_CLK("extern1", "extern1", NULL, 120, 0x3ec, 216000000, mux_plla_clk32_pllp_clkm_plle, MUX | MUX8 | DIV_U71),
  2582. PERIPH_CLK("extern2", "extern2", NULL, 121, 0x3f0, 216000000, mux_plla_clk32_pllp_clkm_plle, MUX | MUX8 | DIV_U71),
  2583. PERIPH_CLK("extern3", "extern3", NULL, 122, 0x3f4, 216000000, mux_plla_clk32_pllp_clkm_plle, MUX | MUX8 | DIV_U71),
  2584. PERIPH_CLK("i2cslow", "i2cslow", NULL, 81, 0x3fc, 26000000, mux_pllp_pllc_clk32_clkm, MUX | DIV_U71 | PERIPH_ON_APB),
  2585. PERIPH_CLK("pcie", "tegra-pcie", "pcie", 70, 0, 250000000, mux_clk_m, 0),
  2586. PERIPH_CLK("afi", "tegra-pcie", "afi", 72, 0, 250000000, mux_clk_m, 0),
  2587. PERIPH_CLK("se", "se", NULL, 127, 0x42c, 520000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71 | DIV_U71_INT),
  2588. };
  2589. #define CLK_DUPLICATE(_name, _dev, _con) \
  2590. { \
  2591. .name = _name, \
  2592. .lookup = { \
  2593. .dev_id = _dev, \
  2594. .con_id = _con, \
  2595. }, \
  2596. }
  2597. /* Some clocks may be used by different drivers depending on the board
  2598. * configuration. List those here to register them twice in the clock lookup
  2599. * table under two names.
  2600. */
  2601. struct clk_duplicate tegra_clk_duplicates[] = {
  2602. CLK_DUPLICATE("uarta", "serial8250.0", NULL),
  2603. CLK_DUPLICATE("uartb", "serial8250.1", NULL),
  2604. CLK_DUPLICATE("uartc", "serial8250.2", NULL),
  2605. CLK_DUPLICATE("uartd", "serial8250.3", NULL),
  2606. CLK_DUPLICATE("uarte", "serial8250.4", NULL),
  2607. CLK_DUPLICATE("usbd", "utmip-pad", NULL),
  2608. CLK_DUPLICATE("usbd", "tegra-ehci.0", NULL),
  2609. CLK_DUPLICATE("usbd", "tegra-otg", NULL),
  2610. CLK_DUPLICATE("hdmi", "tegradc.0", "hdmi"),
  2611. CLK_DUPLICATE("hdmi", "tegradc.1", "hdmi"),
  2612. CLK_DUPLICATE("dsib", "tegradc.0", "dsib"),
  2613. CLK_DUPLICATE("dsia", "tegradc.1", "dsia"),
  2614. CLK_DUPLICATE("bsev", "tegra-avp", "bsev"),
  2615. CLK_DUPLICATE("bsev", "nvavp", "bsev"),
  2616. CLK_DUPLICATE("vde", "tegra-aes", "vde"),
  2617. CLK_DUPLICATE("bsea", "tegra-aes", "bsea"),
  2618. CLK_DUPLICATE("bsea", "nvavp", "bsea"),
  2619. CLK_DUPLICATE("cml1", "tegra_sata_cml", NULL),
  2620. CLK_DUPLICATE("cml0", "tegra_pcie", "cml"),
  2621. CLK_DUPLICATE("pciex", "tegra_pcie", "pciex"),
  2622. CLK_DUPLICATE("i2c1", "tegra-i2c-slave.0", NULL),
  2623. CLK_DUPLICATE("i2c2", "tegra-i2c-slave.1", NULL),
  2624. CLK_DUPLICATE("i2c3", "tegra-i2c-slave.2", NULL),
  2625. CLK_DUPLICATE("i2c4", "tegra-i2c-slave.3", NULL),
  2626. CLK_DUPLICATE("i2c5", "tegra-i2c-slave.4", NULL),
  2627. CLK_DUPLICATE("sbc1", "spi_slave_tegra.0", NULL),
  2628. CLK_DUPLICATE("sbc2", "spi_slave_tegra.1", NULL),
  2629. CLK_DUPLICATE("sbc3", "spi_slave_tegra.2", NULL),
  2630. CLK_DUPLICATE("sbc4", "spi_slave_tegra.3", NULL),
  2631. CLK_DUPLICATE("sbc5", "spi_slave_tegra.4", NULL),
  2632. CLK_DUPLICATE("sbc6", "spi_slave_tegra.5", NULL),
  2633. CLK_DUPLICATE("twd", "smp_twd", NULL),
  2634. CLK_DUPLICATE("vcp", "nvavp", "vcp"),
  2635. CLK_DUPLICATE("i2s0", NULL, "i2s0"),
  2636. CLK_DUPLICATE("i2s1", NULL, "i2s1"),
  2637. CLK_DUPLICATE("i2s2", NULL, "i2s2"),
  2638. CLK_DUPLICATE("i2s3", NULL, "i2s3"),
  2639. CLK_DUPLICATE("i2s4", NULL, "i2s4"),
  2640. CLK_DUPLICATE("dam0", NULL, "dam0"),
  2641. CLK_DUPLICATE("dam1", NULL, "dam1"),
  2642. CLK_DUPLICATE("dam2", NULL, "dam2"),
  2643. CLK_DUPLICATE("spdif_in", NULL, "spdif_in"),
  2644. };
  2645. struct clk *tegra_ptr_clks[] = {
  2646. &tegra_clk_32k,
  2647. &tegra_clk_m,
  2648. &tegra_clk_m_div2,
  2649. &tegra_clk_m_div4,
  2650. &tegra_pll_ref,
  2651. &tegra_pll_m,
  2652. &tegra_pll_m_out1,
  2653. &tegra_pll_c,
  2654. &tegra_pll_c_out1,
  2655. &tegra_pll_p,
  2656. &tegra_pll_p_out1,
  2657. &tegra_pll_p_out2,
  2658. &tegra_pll_p_out3,
  2659. &tegra_pll_p_out4,
  2660. &tegra_pll_a,
  2661. &tegra_pll_a_out0,
  2662. &tegra_pll_d,
  2663. &tegra_pll_d_out0,
  2664. &tegra_pll_d2,
  2665. &tegra_pll_d2_out0,
  2666. &tegra_pll_u,
  2667. &tegra_pll_x,
  2668. &tegra_pll_x_out0,
  2669. &tegra_pll_e,
  2670. &tegra_clk_cclk_g,
  2671. &tegra_cml0_clk,
  2672. &tegra_cml1_clk,
  2673. &tegra_pciex_clk,
  2674. &tegra_clk_sclk,
  2675. &tegra_clk_blink,
  2676. &tegra30_clk_twd,
  2677. };
  2678. static void tegra30_init_one_clock(struct clk *c)
  2679. {
  2680. clk_init(c);
  2681. INIT_LIST_HEAD(&c->shared_bus_list);
  2682. if (!c->lookup.dev_id && !c->lookup.con_id)
  2683. c->lookup.con_id = c->name;
  2684. c->lookup.clk = c;
  2685. clkdev_add(&c->lookup);
  2686. }
  2687. void __init tegra30_init_clocks(void)
  2688. {
  2689. int i;
  2690. struct clk *c;
  2691. for (i = 0; i < ARRAY_SIZE(tegra_ptr_clks); i++)
  2692. tegra30_init_one_clock(tegra_ptr_clks[i]);
  2693. for (i = 0; i < ARRAY_SIZE(tegra_list_clks); i++)
  2694. tegra30_init_one_clock(&tegra_list_clks[i]);
  2695. for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) {
  2696. c = tegra_get_clock_by_name(tegra_clk_duplicates[i].name);
  2697. if (!c) {
  2698. pr_err("%s: Unknown duplicate clock %s\n", __func__,
  2699. tegra_clk_duplicates[i].name);
  2700. continue;
  2701. }
  2702. tegra_clk_duplicates[i].lookup.clk = c;
  2703. clkdev_add(&tegra_clk_duplicates[i].lookup);
  2704. }
  2705. for (i = 0; i < ARRAY_SIZE(tegra_sync_source_list); i++)
  2706. tegra30_init_one_clock(&tegra_sync_source_list[i]);
  2707. for (i = 0; i < ARRAY_SIZE(tegra_clk_audio_list); i++)
  2708. tegra30_init_one_clock(&tegra_clk_audio_list[i]);
  2709. for (i = 0; i < ARRAY_SIZE(tegra_clk_audio_2x_list); i++)
  2710. tegra30_init_one_clock(&tegra_clk_audio_2x_list[i]);
  2711. init_clk_out_mux();
  2712. for (i = 0; i < ARRAY_SIZE(tegra_clk_out_list); i++)
  2713. tegra30_init_one_clock(&tegra_clk_out_list[i]);
  2714. }