clk-bcm2835.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211
  1. /*
  2. * Copyright (C) 2010,2015 Broadcom
  3. * Copyright (C) 2012 Stephen Warren
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. /**
  17. * DOC: BCM2835 CPRMAN (clock manager for the "audio" domain)
  18. *
  19. * The clock tree on the 2835 has several levels. There's a root
  20. * oscillator running at 19.2Mhz. After the oscillator there are 5
  21. * PLLs, roughly divided as "camera", "ARM", "core", "DSI displays",
  22. * and "HDMI displays". Those 5 PLLs each can divide their output to
  23. * produce up to 4 channels. Finally, there is the level of clocks to
  24. * be consumed by other hardware components (like "H264" or "HDMI
  25. * state machine"), which divide off of some subset of the PLL
  26. * channels.
  27. *
  28. * All of the clocks in the tree are exposed in the DT, because the DT
  29. * may want to make assignments of the final layer of clocks to the
  30. * PLL channels, and some components of the hardware will actually
  31. * skip layers of the tree (for example, the pixel clock comes
  32. * directly from the PLLH PIX channel without using a CM_*CTL clock
  33. * generator).
  34. */
  35. #include <linux/clk-provider.h>
  36. #include <linux/clkdev.h>
  37. #include <linux/clk.h>
  38. #include <linux/debugfs.h>
  39. #include <linux/delay.h>
  40. #include <linux/module.h>
  41. #include <linux/of.h>
  42. #include <linux/platform_device.h>
  43. #include <linux/slab.h>
  44. #include <dt-bindings/clock/bcm2835.h>
  45. #define CM_PASSWORD 0x5a000000
  46. #define CM_GNRICCTL 0x000
  47. #define CM_GNRICDIV 0x004
  48. # define CM_DIV_FRAC_BITS 12
  49. # define CM_DIV_FRAC_MASK GENMASK(CM_DIV_FRAC_BITS - 1, 0)
  50. #define CM_VPUCTL 0x008
  51. #define CM_VPUDIV 0x00c
  52. #define CM_SYSCTL 0x010
  53. #define CM_SYSDIV 0x014
  54. #define CM_PERIACTL 0x018
  55. #define CM_PERIADIV 0x01c
  56. #define CM_PERIICTL 0x020
  57. #define CM_PERIIDIV 0x024
  58. #define CM_H264CTL 0x028
  59. #define CM_H264DIV 0x02c
  60. #define CM_ISPCTL 0x030
  61. #define CM_ISPDIV 0x034
  62. #define CM_V3DCTL 0x038
  63. #define CM_V3DDIV 0x03c
  64. #define CM_CAM0CTL 0x040
  65. #define CM_CAM0DIV 0x044
  66. #define CM_CAM1CTL 0x048
  67. #define CM_CAM1DIV 0x04c
  68. #define CM_CCP2CTL 0x050
  69. #define CM_CCP2DIV 0x054
  70. #define CM_DSI0ECTL 0x058
  71. #define CM_DSI0EDIV 0x05c
  72. #define CM_DSI0PCTL 0x060
  73. #define CM_DSI0PDIV 0x064
  74. #define CM_DPICTL 0x068
  75. #define CM_DPIDIV 0x06c
  76. #define CM_GP0CTL 0x070
  77. #define CM_GP0DIV 0x074
  78. #define CM_GP1CTL 0x078
  79. #define CM_GP1DIV 0x07c
  80. #define CM_GP2CTL 0x080
  81. #define CM_GP2DIV 0x084
  82. #define CM_HSMCTL 0x088
  83. #define CM_HSMDIV 0x08c
  84. #define CM_OTPCTL 0x090
  85. #define CM_OTPDIV 0x094
  86. #define CM_PCMCTL 0x098
  87. #define CM_PCMDIV 0x09c
  88. #define CM_PWMCTL 0x0a0
  89. #define CM_PWMDIV 0x0a4
  90. #define CM_SLIMCTL 0x0a8
  91. #define CM_SLIMDIV 0x0ac
  92. #define CM_SMICTL 0x0b0
  93. #define CM_SMIDIV 0x0b4
  94. /* no definition for 0x0b8 and 0x0bc */
  95. #define CM_TCNTCTL 0x0c0
  96. # define CM_TCNT_SRC1_SHIFT 12
  97. #define CM_TCNTCNT 0x0c4
  98. #define CM_TECCTL 0x0c8
  99. #define CM_TECDIV 0x0cc
  100. #define CM_TD0CTL 0x0d0
  101. #define CM_TD0DIV 0x0d4
  102. #define CM_TD1CTL 0x0d8
  103. #define CM_TD1DIV 0x0dc
  104. #define CM_TSENSCTL 0x0e0
  105. #define CM_TSENSDIV 0x0e4
  106. #define CM_TIMERCTL 0x0e8
  107. #define CM_TIMERDIV 0x0ec
  108. #define CM_UARTCTL 0x0f0
  109. #define CM_UARTDIV 0x0f4
  110. #define CM_VECCTL 0x0f8
  111. #define CM_VECDIV 0x0fc
  112. #define CM_PULSECTL 0x190
  113. #define CM_PULSEDIV 0x194
  114. #define CM_SDCCTL 0x1a8
  115. #define CM_SDCDIV 0x1ac
  116. #define CM_ARMCTL 0x1b0
  117. #define CM_AVEOCTL 0x1b8
  118. #define CM_AVEODIV 0x1bc
  119. #define CM_EMMCCTL 0x1c0
  120. #define CM_EMMCDIV 0x1c4
  121. /* General bits for the CM_*CTL regs */
  122. # define CM_ENABLE BIT(4)
  123. # define CM_KILL BIT(5)
  124. # define CM_GATE_BIT 6
  125. # define CM_GATE BIT(CM_GATE_BIT)
  126. # define CM_BUSY BIT(7)
  127. # define CM_BUSYD BIT(8)
  128. # define CM_FRAC BIT(9)
  129. # define CM_SRC_SHIFT 0
  130. # define CM_SRC_BITS 4
  131. # define CM_SRC_MASK 0xf
  132. # define CM_SRC_GND 0
  133. # define CM_SRC_OSC 1
  134. # define CM_SRC_TESTDEBUG0 2
  135. # define CM_SRC_TESTDEBUG1 3
  136. # define CM_SRC_PLLA_CORE 4
  137. # define CM_SRC_PLLA_PER 4
  138. # define CM_SRC_PLLC_CORE0 5
  139. # define CM_SRC_PLLC_PER 5
  140. # define CM_SRC_PLLC_CORE1 8
  141. # define CM_SRC_PLLD_CORE 6
  142. # define CM_SRC_PLLD_PER 6
  143. # define CM_SRC_PLLH_AUX 7
  144. # define CM_SRC_PLLC_CORE1 8
  145. # define CM_SRC_PLLC_CORE2 9
  146. #define CM_OSCCOUNT 0x100
  147. #define CM_PLLA 0x104
  148. # define CM_PLL_ANARST BIT(8)
  149. # define CM_PLLA_HOLDPER BIT(7)
  150. # define CM_PLLA_LOADPER BIT(6)
  151. # define CM_PLLA_HOLDCORE BIT(5)
  152. # define CM_PLLA_LOADCORE BIT(4)
  153. # define CM_PLLA_HOLDCCP2 BIT(3)
  154. # define CM_PLLA_LOADCCP2 BIT(2)
  155. # define CM_PLLA_HOLDDSI0 BIT(1)
  156. # define CM_PLLA_LOADDSI0 BIT(0)
  157. #define CM_PLLC 0x108
  158. # define CM_PLLC_HOLDPER BIT(7)
  159. # define CM_PLLC_LOADPER BIT(6)
  160. # define CM_PLLC_HOLDCORE2 BIT(5)
  161. # define CM_PLLC_LOADCORE2 BIT(4)
  162. # define CM_PLLC_HOLDCORE1 BIT(3)
  163. # define CM_PLLC_LOADCORE1 BIT(2)
  164. # define CM_PLLC_HOLDCORE0 BIT(1)
  165. # define CM_PLLC_LOADCORE0 BIT(0)
  166. #define CM_PLLD 0x10c
  167. # define CM_PLLD_HOLDPER BIT(7)
  168. # define CM_PLLD_LOADPER BIT(6)
  169. # define CM_PLLD_HOLDCORE BIT(5)
  170. # define CM_PLLD_LOADCORE BIT(4)
  171. # define CM_PLLD_HOLDDSI1 BIT(3)
  172. # define CM_PLLD_LOADDSI1 BIT(2)
  173. # define CM_PLLD_HOLDDSI0 BIT(1)
  174. # define CM_PLLD_LOADDSI0 BIT(0)
  175. #define CM_PLLH 0x110
  176. # define CM_PLLH_LOADRCAL BIT(2)
  177. # define CM_PLLH_LOADAUX BIT(1)
  178. # define CM_PLLH_LOADPIX BIT(0)
  179. #define CM_LOCK 0x114
  180. # define CM_LOCK_FLOCKH BIT(12)
  181. # define CM_LOCK_FLOCKD BIT(11)
  182. # define CM_LOCK_FLOCKC BIT(10)
  183. # define CM_LOCK_FLOCKB BIT(9)
  184. # define CM_LOCK_FLOCKA BIT(8)
  185. #define CM_EVENT 0x118
  186. #define CM_DSI1ECTL 0x158
  187. #define CM_DSI1EDIV 0x15c
  188. #define CM_DSI1PCTL 0x160
  189. #define CM_DSI1PDIV 0x164
  190. #define CM_DFTCTL 0x168
  191. #define CM_DFTDIV 0x16c
  192. #define CM_PLLB 0x170
  193. # define CM_PLLB_HOLDARM BIT(1)
  194. # define CM_PLLB_LOADARM BIT(0)
  195. #define A2W_PLLA_CTRL 0x1100
  196. #define A2W_PLLC_CTRL 0x1120
  197. #define A2W_PLLD_CTRL 0x1140
  198. #define A2W_PLLH_CTRL 0x1160
  199. #define A2W_PLLB_CTRL 0x11e0
  200. # define A2W_PLL_CTRL_PRST_DISABLE BIT(17)
  201. # define A2W_PLL_CTRL_PWRDN BIT(16)
  202. # define A2W_PLL_CTRL_PDIV_MASK 0x000007000
  203. # define A2W_PLL_CTRL_PDIV_SHIFT 12
  204. # define A2W_PLL_CTRL_NDIV_MASK 0x0000003ff
  205. # define A2W_PLL_CTRL_NDIV_SHIFT 0
  206. #define A2W_PLLA_ANA0 0x1010
  207. #define A2W_PLLC_ANA0 0x1030
  208. #define A2W_PLLD_ANA0 0x1050
  209. #define A2W_PLLH_ANA0 0x1070
  210. #define A2W_PLLB_ANA0 0x10f0
  211. #define A2W_PLL_KA_SHIFT 7
  212. #define A2W_PLL_KA_MASK GENMASK(9, 7)
  213. #define A2W_PLL_KI_SHIFT 19
  214. #define A2W_PLL_KI_MASK GENMASK(21, 19)
  215. #define A2W_PLL_KP_SHIFT 15
  216. #define A2W_PLL_KP_MASK GENMASK(18, 15)
  217. #define A2W_PLLH_KA_SHIFT 19
  218. #define A2W_PLLH_KA_MASK GENMASK(21, 19)
  219. #define A2W_PLLH_KI_LOW_SHIFT 22
  220. #define A2W_PLLH_KI_LOW_MASK GENMASK(23, 22)
  221. #define A2W_PLLH_KI_HIGH_SHIFT 0
  222. #define A2W_PLLH_KI_HIGH_MASK GENMASK(0, 0)
  223. #define A2W_PLLH_KP_SHIFT 1
  224. #define A2W_PLLH_KP_MASK GENMASK(4, 1)
  225. #define A2W_XOSC_CTRL 0x1190
  226. # define A2W_XOSC_CTRL_PLLB_ENABLE BIT(7)
  227. # define A2W_XOSC_CTRL_PLLA_ENABLE BIT(6)
  228. # define A2W_XOSC_CTRL_PLLD_ENABLE BIT(5)
  229. # define A2W_XOSC_CTRL_DDR_ENABLE BIT(4)
  230. # define A2W_XOSC_CTRL_CPR1_ENABLE BIT(3)
  231. # define A2W_XOSC_CTRL_USB_ENABLE BIT(2)
  232. # define A2W_XOSC_CTRL_HDMI_ENABLE BIT(1)
  233. # define A2W_XOSC_CTRL_PLLC_ENABLE BIT(0)
  234. #define A2W_PLLA_FRAC 0x1200
  235. #define A2W_PLLC_FRAC 0x1220
  236. #define A2W_PLLD_FRAC 0x1240
  237. #define A2W_PLLH_FRAC 0x1260
  238. #define A2W_PLLB_FRAC 0x12e0
  239. # define A2W_PLL_FRAC_MASK ((1 << A2W_PLL_FRAC_BITS) - 1)
  240. # define A2W_PLL_FRAC_BITS 20
  241. #define A2W_PLL_CHANNEL_DISABLE BIT(8)
  242. #define A2W_PLL_DIV_BITS 8
  243. #define A2W_PLL_DIV_SHIFT 0
  244. #define A2W_PLLA_DSI0 0x1300
  245. #define A2W_PLLA_CORE 0x1400
  246. #define A2W_PLLA_PER 0x1500
  247. #define A2W_PLLA_CCP2 0x1600
  248. #define A2W_PLLC_CORE2 0x1320
  249. #define A2W_PLLC_CORE1 0x1420
  250. #define A2W_PLLC_PER 0x1520
  251. #define A2W_PLLC_CORE0 0x1620
  252. #define A2W_PLLD_DSI0 0x1340
  253. #define A2W_PLLD_CORE 0x1440
  254. #define A2W_PLLD_PER 0x1540
  255. #define A2W_PLLD_DSI1 0x1640
  256. #define A2W_PLLH_AUX 0x1360
  257. #define A2W_PLLH_RCAL 0x1460
  258. #define A2W_PLLH_PIX 0x1560
  259. #define A2W_PLLH_STS 0x1660
  260. #define A2W_PLLH_CTRLR 0x1960
  261. #define A2W_PLLH_FRACR 0x1a60
  262. #define A2W_PLLH_AUXR 0x1b60
  263. #define A2W_PLLH_RCALR 0x1c60
  264. #define A2W_PLLH_PIXR 0x1d60
  265. #define A2W_PLLH_STSR 0x1e60
  266. #define A2W_PLLB_ARM 0x13e0
  267. #define A2W_PLLB_SP0 0x14e0
  268. #define A2W_PLLB_SP1 0x15e0
  269. #define A2W_PLLB_SP2 0x16e0
  270. #define LOCK_TIMEOUT_NS 100000000
  271. #define BCM2835_MAX_FB_RATE 1750000000u
  272. /*
  273. * Names of clocks used within the driver that need to be replaced
  274. * with an external parent's name. This array is in the order that
  275. * the clocks node in the DT references external clocks.
  276. */
  277. static const char *const cprman_parent_names[] = {
  278. "xosc",
  279. "dsi0_byte",
  280. "dsi0_ddr2",
  281. "dsi0_ddr",
  282. "dsi1_byte",
  283. "dsi1_ddr2",
  284. "dsi1_ddr",
  285. };
  286. struct bcm2835_cprman {
  287. struct device *dev;
  288. void __iomem *regs;
  289. spinlock_t regs_lock; /* spinlock for all clocks */
  290. /*
  291. * Real names of cprman clock parents looked up through
  292. * of_clk_get_parent_name(), which will be used in the
  293. * parent_names[] arrays for clock registration.
  294. */
  295. const char *real_parent_names[ARRAY_SIZE(cprman_parent_names)];
  296. /* Must be last */
  297. struct clk_hw_onecell_data onecell;
  298. };
  299. static inline void cprman_write(struct bcm2835_cprman *cprman, u32 reg, u32 val)
  300. {
  301. writel(CM_PASSWORD | val, cprman->regs + reg);
  302. }
  303. static inline u32 cprman_read(struct bcm2835_cprman *cprman, u32 reg)
  304. {
  305. return readl(cprman->regs + reg);
  306. }
  307. /* Does a cycle of measuring a clock through the TCNT clock, which may
  308. * source from many other clocks in the system.
  309. */
  310. static unsigned long bcm2835_measure_tcnt_mux(struct bcm2835_cprman *cprman,
  311. u32 tcnt_mux)
  312. {
  313. u32 osccount = 19200; /* 1ms */
  314. u32 count;
  315. ktime_t timeout;
  316. spin_lock(&cprman->regs_lock);
  317. cprman_write(cprman, CM_TCNTCTL, CM_KILL);
  318. cprman_write(cprman, CM_TCNTCTL,
  319. (tcnt_mux & CM_SRC_MASK) |
  320. (tcnt_mux >> CM_SRC_BITS) << CM_TCNT_SRC1_SHIFT);
  321. cprman_write(cprman, CM_OSCCOUNT, osccount);
  322. /* do a kind delay at the start */
  323. mdelay(1);
  324. /* Finish off whatever is left of OSCCOUNT */
  325. timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
  326. while (cprman_read(cprman, CM_OSCCOUNT)) {
  327. if (ktime_after(ktime_get(), timeout)) {
  328. dev_err(cprman->dev, "timeout waiting for OSCCOUNT\n");
  329. count = 0;
  330. goto out;
  331. }
  332. cpu_relax();
  333. }
  334. /* Wait for BUSY to clear. */
  335. timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
  336. while (cprman_read(cprman, CM_TCNTCTL) & CM_BUSY) {
  337. if (ktime_after(ktime_get(), timeout)) {
  338. dev_err(cprman->dev, "timeout waiting for !BUSY\n");
  339. count = 0;
  340. goto out;
  341. }
  342. cpu_relax();
  343. }
  344. count = cprman_read(cprman, CM_TCNTCNT);
  345. cprman_write(cprman, CM_TCNTCTL, 0);
  346. out:
  347. spin_unlock(&cprman->regs_lock);
  348. return count * 1000;
  349. }
  350. static void bcm2835_debugfs_regset(struct bcm2835_cprman *cprman, u32 base,
  351. struct debugfs_reg32 *regs, size_t nregs,
  352. struct dentry *dentry)
  353. {
  354. struct debugfs_regset32 *regset;
  355. regset = devm_kzalloc(cprman->dev, sizeof(*regset), GFP_KERNEL);
  356. if (!regset)
  357. return;
  358. regset->regs = regs;
  359. regset->nregs = nregs;
  360. regset->base = cprman->regs + base;
  361. debugfs_create_regset32("regdump", S_IRUGO, dentry, regset);
  362. }
  363. struct bcm2835_pll_data {
  364. const char *name;
  365. u32 cm_ctrl_reg;
  366. u32 a2w_ctrl_reg;
  367. u32 frac_reg;
  368. u32 ana_reg_base;
  369. u32 reference_enable_mask;
  370. /* Bit in CM_LOCK to indicate when the PLL has locked. */
  371. u32 lock_mask;
  372. const struct bcm2835_pll_ana_bits *ana;
  373. unsigned long min_rate;
  374. unsigned long max_rate;
  375. /*
  376. * Highest rate for the VCO before we have to use the
  377. * pre-divide-by-2.
  378. */
  379. unsigned long max_fb_rate;
  380. };
  381. struct bcm2835_pll_ana_bits {
  382. u32 mask0;
  383. u32 set0;
  384. u32 mask1;
  385. u32 set1;
  386. u32 mask3;
  387. u32 set3;
  388. u32 fb_prediv_mask;
  389. };
  390. static const struct bcm2835_pll_ana_bits bcm2835_ana_default = {
  391. .mask0 = 0,
  392. .set0 = 0,
  393. .mask1 = A2W_PLL_KI_MASK | A2W_PLL_KP_MASK,
  394. .set1 = (2 << A2W_PLL_KI_SHIFT) | (8 << A2W_PLL_KP_SHIFT),
  395. .mask3 = A2W_PLL_KA_MASK,
  396. .set3 = (2 << A2W_PLL_KA_SHIFT),
  397. .fb_prediv_mask = BIT(14),
  398. };
  399. static const struct bcm2835_pll_ana_bits bcm2835_ana_pllh = {
  400. .mask0 = A2W_PLLH_KA_MASK | A2W_PLLH_KI_LOW_MASK,
  401. .set0 = (2 << A2W_PLLH_KA_SHIFT) | (2 << A2W_PLLH_KI_LOW_SHIFT),
  402. .mask1 = A2W_PLLH_KI_HIGH_MASK | A2W_PLLH_KP_MASK,
  403. .set1 = (6 << A2W_PLLH_KP_SHIFT),
  404. .mask3 = 0,
  405. .set3 = 0,
  406. .fb_prediv_mask = BIT(11),
  407. };
  408. struct bcm2835_pll_divider_data {
  409. const char *name;
  410. const char *source_pll;
  411. u32 cm_reg;
  412. u32 a2w_reg;
  413. u32 load_mask;
  414. u32 hold_mask;
  415. u32 fixed_divider;
  416. u32 flags;
  417. };
  418. struct bcm2835_clock_data {
  419. const char *name;
  420. const char *const *parents;
  421. int num_mux_parents;
  422. /* Bitmap encoding which parents accept rate change propagation. */
  423. unsigned int set_rate_parent;
  424. u32 ctl_reg;
  425. u32 div_reg;
  426. /* Number of integer bits in the divider */
  427. u32 int_bits;
  428. /* Number of fractional bits in the divider */
  429. u32 frac_bits;
  430. u32 flags;
  431. bool is_vpu_clock;
  432. bool is_mash_clock;
  433. bool low_jitter;
  434. u32 tcnt_mux;
  435. };
  436. struct bcm2835_gate_data {
  437. const char *name;
  438. const char *parent;
  439. u32 ctl_reg;
  440. };
  441. struct bcm2835_pll {
  442. struct clk_hw hw;
  443. struct bcm2835_cprman *cprman;
  444. const struct bcm2835_pll_data *data;
  445. };
  446. static int bcm2835_pll_is_on(struct clk_hw *hw)
  447. {
  448. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  449. struct bcm2835_cprman *cprman = pll->cprman;
  450. const struct bcm2835_pll_data *data = pll->data;
  451. return cprman_read(cprman, data->a2w_ctrl_reg) &
  452. A2W_PLL_CTRL_PRST_DISABLE;
  453. }
  454. static void bcm2835_pll_choose_ndiv_and_fdiv(unsigned long rate,
  455. unsigned long parent_rate,
  456. u32 *ndiv, u32 *fdiv)
  457. {
  458. u64 div;
  459. div = (u64)rate << A2W_PLL_FRAC_BITS;
  460. do_div(div, parent_rate);
  461. *ndiv = div >> A2W_PLL_FRAC_BITS;
  462. *fdiv = div & ((1 << A2W_PLL_FRAC_BITS) - 1);
  463. }
  464. static long bcm2835_pll_rate_from_divisors(unsigned long parent_rate,
  465. u32 ndiv, u32 fdiv, u32 pdiv)
  466. {
  467. u64 rate;
  468. if (pdiv == 0)
  469. return 0;
  470. rate = (u64)parent_rate * ((ndiv << A2W_PLL_FRAC_BITS) + fdiv);
  471. do_div(rate, pdiv);
  472. return rate >> A2W_PLL_FRAC_BITS;
  473. }
  474. static long bcm2835_pll_round_rate(struct clk_hw *hw, unsigned long rate,
  475. unsigned long *parent_rate)
  476. {
  477. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  478. const struct bcm2835_pll_data *data = pll->data;
  479. u32 ndiv, fdiv;
  480. rate = clamp(rate, data->min_rate, data->max_rate);
  481. bcm2835_pll_choose_ndiv_and_fdiv(rate, *parent_rate, &ndiv, &fdiv);
  482. return bcm2835_pll_rate_from_divisors(*parent_rate, ndiv, fdiv, 1);
  483. }
  484. static unsigned long bcm2835_pll_get_rate(struct clk_hw *hw,
  485. unsigned long parent_rate)
  486. {
  487. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  488. struct bcm2835_cprman *cprman = pll->cprman;
  489. const struct bcm2835_pll_data *data = pll->data;
  490. u32 a2wctrl = cprman_read(cprman, data->a2w_ctrl_reg);
  491. u32 ndiv, pdiv, fdiv;
  492. bool using_prediv;
  493. if (parent_rate == 0)
  494. return 0;
  495. fdiv = cprman_read(cprman, data->frac_reg) & A2W_PLL_FRAC_MASK;
  496. ndiv = (a2wctrl & A2W_PLL_CTRL_NDIV_MASK) >> A2W_PLL_CTRL_NDIV_SHIFT;
  497. pdiv = (a2wctrl & A2W_PLL_CTRL_PDIV_MASK) >> A2W_PLL_CTRL_PDIV_SHIFT;
  498. using_prediv = cprman_read(cprman, data->ana_reg_base + 4) &
  499. data->ana->fb_prediv_mask;
  500. if (using_prediv) {
  501. ndiv *= 2;
  502. fdiv *= 2;
  503. }
  504. return bcm2835_pll_rate_from_divisors(parent_rate, ndiv, fdiv, pdiv);
  505. }
  506. static void bcm2835_pll_off(struct clk_hw *hw)
  507. {
  508. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  509. struct bcm2835_cprman *cprman = pll->cprman;
  510. const struct bcm2835_pll_data *data = pll->data;
  511. spin_lock(&cprman->regs_lock);
  512. cprman_write(cprman, data->cm_ctrl_reg, CM_PLL_ANARST);
  513. cprman_write(cprman, data->a2w_ctrl_reg,
  514. cprman_read(cprman, data->a2w_ctrl_reg) |
  515. A2W_PLL_CTRL_PWRDN);
  516. spin_unlock(&cprman->regs_lock);
  517. }
  518. static int bcm2835_pll_on(struct clk_hw *hw)
  519. {
  520. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  521. struct bcm2835_cprman *cprman = pll->cprman;
  522. const struct bcm2835_pll_data *data = pll->data;
  523. ktime_t timeout;
  524. cprman_write(cprman, data->a2w_ctrl_reg,
  525. cprman_read(cprman, data->a2w_ctrl_reg) &
  526. ~A2W_PLL_CTRL_PWRDN);
  527. /* Take the PLL out of reset. */
  528. spin_lock(&cprman->regs_lock);
  529. cprman_write(cprman, data->cm_ctrl_reg,
  530. cprman_read(cprman, data->cm_ctrl_reg) & ~CM_PLL_ANARST);
  531. spin_unlock(&cprman->regs_lock);
  532. /* Wait for the PLL to lock. */
  533. timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
  534. while (!(cprman_read(cprman, CM_LOCK) & data->lock_mask)) {
  535. if (ktime_after(ktime_get(), timeout)) {
  536. dev_err(cprman->dev, "%s: couldn't lock PLL\n",
  537. clk_hw_get_name(hw));
  538. return -ETIMEDOUT;
  539. }
  540. cpu_relax();
  541. }
  542. cprman_write(cprman, data->a2w_ctrl_reg,
  543. cprman_read(cprman, data->a2w_ctrl_reg) |
  544. A2W_PLL_CTRL_PRST_DISABLE);
  545. return 0;
  546. }
  547. static void
  548. bcm2835_pll_write_ana(struct bcm2835_cprman *cprman, u32 ana_reg_base, u32 *ana)
  549. {
  550. int i;
  551. /*
  552. * ANA register setup is done as a series of writes to
  553. * ANA3-ANA0, in that order. This lets us write all 4
  554. * registers as a single cycle of the serdes interface (taking
  555. * 100 xosc clocks), whereas if we were to update ana0, 1, and
  556. * 3 individually through their partial-write registers, each
  557. * would be their own serdes cycle.
  558. */
  559. for (i = 3; i >= 0; i--)
  560. cprman_write(cprman, ana_reg_base + i * 4, ana[i]);
  561. }
  562. static int bcm2835_pll_set_rate(struct clk_hw *hw,
  563. unsigned long rate, unsigned long parent_rate)
  564. {
  565. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  566. struct bcm2835_cprman *cprman = pll->cprman;
  567. const struct bcm2835_pll_data *data = pll->data;
  568. bool was_using_prediv, use_fb_prediv, do_ana_setup_first;
  569. u32 ndiv, fdiv, a2w_ctl;
  570. u32 ana[4];
  571. int i;
  572. if (rate > data->max_fb_rate) {
  573. use_fb_prediv = true;
  574. rate /= 2;
  575. } else {
  576. use_fb_prediv = false;
  577. }
  578. bcm2835_pll_choose_ndiv_and_fdiv(rate, parent_rate, &ndiv, &fdiv);
  579. for (i = 3; i >= 0; i--)
  580. ana[i] = cprman_read(cprman, data->ana_reg_base + i * 4);
  581. was_using_prediv = ana[1] & data->ana->fb_prediv_mask;
  582. ana[0] &= ~data->ana->mask0;
  583. ana[0] |= data->ana->set0;
  584. ana[1] &= ~data->ana->mask1;
  585. ana[1] |= data->ana->set1;
  586. ana[3] &= ~data->ana->mask3;
  587. ana[3] |= data->ana->set3;
  588. if (was_using_prediv && !use_fb_prediv) {
  589. ana[1] &= ~data->ana->fb_prediv_mask;
  590. do_ana_setup_first = true;
  591. } else if (!was_using_prediv && use_fb_prediv) {
  592. ana[1] |= data->ana->fb_prediv_mask;
  593. do_ana_setup_first = false;
  594. } else {
  595. do_ana_setup_first = true;
  596. }
  597. /* Unmask the reference clock from the oscillator. */
  598. spin_lock(&cprman->regs_lock);
  599. cprman_write(cprman, A2W_XOSC_CTRL,
  600. cprman_read(cprman, A2W_XOSC_CTRL) |
  601. data->reference_enable_mask);
  602. spin_unlock(&cprman->regs_lock);
  603. if (do_ana_setup_first)
  604. bcm2835_pll_write_ana(cprman, data->ana_reg_base, ana);
  605. /* Set the PLL multiplier from the oscillator. */
  606. cprman_write(cprman, data->frac_reg, fdiv);
  607. a2w_ctl = cprman_read(cprman, data->a2w_ctrl_reg);
  608. a2w_ctl &= ~A2W_PLL_CTRL_NDIV_MASK;
  609. a2w_ctl |= ndiv << A2W_PLL_CTRL_NDIV_SHIFT;
  610. a2w_ctl &= ~A2W_PLL_CTRL_PDIV_MASK;
  611. a2w_ctl |= 1 << A2W_PLL_CTRL_PDIV_SHIFT;
  612. cprman_write(cprman, data->a2w_ctrl_reg, a2w_ctl);
  613. if (!do_ana_setup_first)
  614. bcm2835_pll_write_ana(cprman, data->ana_reg_base, ana);
  615. return 0;
  616. }
  617. static void bcm2835_pll_debug_init(struct clk_hw *hw,
  618. struct dentry *dentry)
  619. {
  620. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  621. struct bcm2835_cprman *cprman = pll->cprman;
  622. const struct bcm2835_pll_data *data = pll->data;
  623. struct debugfs_reg32 *regs;
  624. regs = devm_kcalloc(cprman->dev, 7, sizeof(*regs), GFP_KERNEL);
  625. if (!regs)
  626. return;
  627. regs[0].name = "cm_ctrl";
  628. regs[0].offset = data->cm_ctrl_reg;
  629. regs[1].name = "a2w_ctrl";
  630. regs[1].offset = data->a2w_ctrl_reg;
  631. regs[2].name = "frac";
  632. regs[2].offset = data->frac_reg;
  633. regs[3].name = "ana0";
  634. regs[3].offset = data->ana_reg_base + 0 * 4;
  635. regs[4].name = "ana1";
  636. regs[4].offset = data->ana_reg_base + 1 * 4;
  637. regs[5].name = "ana2";
  638. regs[5].offset = data->ana_reg_base + 2 * 4;
  639. regs[6].name = "ana3";
  640. regs[6].offset = data->ana_reg_base + 3 * 4;
  641. bcm2835_debugfs_regset(cprman, 0, regs, 7, dentry);
  642. }
  643. static const struct clk_ops bcm2835_pll_clk_ops = {
  644. .is_prepared = bcm2835_pll_is_on,
  645. .prepare = bcm2835_pll_on,
  646. .unprepare = bcm2835_pll_off,
  647. .recalc_rate = bcm2835_pll_get_rate,
  648. .set_rate = bcm2835_pll_set_rate,
  649. .round_rate = bcm2835_pll_round_rate,
  650. .debug_init = bcm2835_pll_debug_init,
  651. };
  652. struct bcm2835_pll_divider {
  653. struct clk_divider div;
  654. struct bcm2835_cprman *cprman;
  655. const struct bcm2835_pll_divider_data *data;
  656. };
  657. static struct bcm2835_pll_divider *
  658. bcm2835_pll_divider_from_hw(struct clk_hw *hw)
  659. {
  660. return container_of(hw, struct bcm2835_pll_divider, div.hw);
  661. }
  662. static int bcm2835_pll_divider_is_on(struct clk_hw *hw)
  663. {
  664. struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
  665. struct bcm2835_cprman *cprman = divider->cprman;
  666. const struct bcm2835_pll_divider_data *data = divider->data;
  667. return !(cprman_read(cprman, data->a2w_reg) & A2W_PLL_CHANNEL_DISABLE);
  668. }
  669. static long bcm2835_pll_divider_round_rate(struct clk_hw *hw,
  670. unsigned long rate,
  671. unsigned long *parent_rate)
  672. {
  673. return clk_divider_ops.round_rate(hw, rate, parent_rate);
  674. }
  675. static unsigned long bcm2835_pll_divider_get_rate(struct clk_hw *hw,
  676. unsigned long parent_rate)
  677. {
  678. return clk_divider_ops.recalc_rate(hw, parent_rate);
  679. }
  680. static void bcm2835_pll_divider_off(struct clk_hw *hw)
  681. {
  682. struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
  683. struct bcm2835_cprman *cprman = divider->cprman;
  684. const struct bcm2835_pll_divider_data *data = divider->data;
  685. spin_lock(&cprman->regs_lock);
  686. cprman_write(cprman, data->cm_reg,
  687. (cprman_read(cprman, data->cm_reg) &
  688. ~data->load_mask) | data->hold_mask);
  689. cprman_write(cprman, data->a2w_reg,
  690. cprman_read(cprman, data->a2w_reg) |
  691. A2W_PLL_CHANNEL_DISABLE);
  692. spin_unlock(&cprman->regs_lock);
  693. }
  694. static int bcm2835_pll_divider_on(struct clk_hw *hw)
  695. {
  696. struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
  697. struct bcm2835_cprman *cprman = divider->cprman;
  698. const struct bcm2835_pll_divider_data *data = divider->data;
  699. spin_lock(&cprman->regs_lock);
  700. cprman_write(cprman, data->a2w_reg,
  701. cprman_read(cprman, data->a2w_reg) &
  702. ~A2W_PLL_CHANNEL_DISABLE);
  703. cprman_write(cprman, data->cm_reg,
  704. cprman_read(cprman, data->cm_reg) & ~data->hold_mask);
  705. spin_unlock(&cprman->regs_lock);
  706. return 0;
  707. }
  708. static int bcm2835_pll_divider_set_rate(struct clk_hw *hw,
  709. unsigned long rate,
  710. unsigned long parent_rate)
  711. {
  712. struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
  713. struct bcm2835_cprman *cprman = divider->cprman;
  714. const struct bcm2835_pll_divider_data *data = divider->data;
  715. u32 cm, div, max_div = 1 << A2W_PLL_DIV_BITS;
  716. div = DIV_ROUND_UP_ULL(parent_rate, rate);
  717. div = min(div, max_div);
  718. if (div == max_div)
  719. div = 0;
  720. cprman_write(cprman, data->a2w_reg, div);
  721. cm = cprman_read(cprman, data->cm_reg);
  722. cprman_write(cprman, data->cm_reg, cm | data->load_mask);
  723. cprman_write(cprman, data->cm_reg, cm & ~data->load_mask);
  724. return 0;
  725. }
  726. static void bcm2835_pll_divider_debug_init(struct clk_hw *hw,
  727. struct dentry *dentry)
  728. {
  729. struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
  730. struct bcm2835_cprman *cprman = divider->cprman;
  731. const struct bcm2835_pll_divider_data *data = divider->data;
  732. struct debugfs_reg32 *regs;
  733. regs = devm_kcalloc(cprman->dev, 7, sizeof(*regs), GFP_KERNEL);
  734. if (!regs)
  735. return;
  736. regs[0].name = "cm";
  737. regs[0].offset = data->cm_reg;
  738. regs[1].name = "a2w";
  739. regs[1].offset = data->a2w_reg;
  740. bcm2835_debugfs_regset(cprman, 0, regs, 2, dentry);
  741. }
  742. static const struct clk_ops bcm2835_pll_divider_clk_ops = {
  743. .is_prepared = bcm2835_pll_divider_is_on,
  744. .prepare = bcm2835_pll_divider_on,
  745. .unprepare = bcm2835_pll_divider_off,
  746. .recalc_rate = bcm2835_pll_divider_get_rate,
  747. .set_rate = bcm2835_pll_divider_set_rate,
  748. .round_rate = bcm2835_pll_divider_round_rate,
  749. .debug_init = bcm2835_pll_divider_debug_init,
  750. };
  751. /*
  752. * The CM dividers do fixed-point division, so we can't use the
  753. * generic integer divider code like the PLL dividers do (and we can't
  754. * fake it by having some fixed shifts preceding it in the clock tree,
  755. * because we'd run out of bits in a 32-bit unsigned long).
  756. */
  757. struct bcm2835_clock {
  758. struct clk_hw hw;
  759. struct bcm2835_cprman *cprman;
  760. const struct bcm2835_clock_data *data;
  761. };
  762. static struct bcm2835_clock *bcm2835_clock_from_hw(struct clk_hw *hw)
  763. {
  764. return container_of(hw, struct bcm2835_clock, hw);
  765. }
  766. static int bcm2835_clock_is_on(struct clk_hw *hw)
  767. {
  768. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  769. struct bcm2835_cprman *cprman = clock->cprman;
  770. const struct bcm2835_clock_data *data = clock->data;
  771. return (cprman_read(cprman, data->ctl_reg) & CM_ENABLE) != 0;
  772. }
  773. static u32 bcm2835_clock_choose_div(struct clk_hw *hw,
  774. unsigned long rate,
  775. unsigned long parent_rate,
  776. bool round_up)
  777. {
  778. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  779. const struct bcm2835_clock_data *data = clock->data;
  780. u32 unused_frac_mask =
  781. GENMASK(CM_DIV_FRAC_BITS - data->frac_bits, 0) >> 1;
  782. u64 temp = (u64)parent_rate << CM_DIV_FRAC_BITS;
  783. u64 rem;
  784. u32 div, mindiv, maxdiv;
  785. rem = do_div(temp, rate);
  786. div = temp;
  787. /* Round up and mask off the unused bits */
  788. if (round_up && ((div & unused_frac_mask) != 0 || rem != 0))
  789. div += unused_frac_mask + 1;
  790. div &= ~unused_frac_mask;
  791. /* different clamping limits apply for a mash clock */
  792. if (data->is_mash_clock) {
  793. /* clamp to min divider of 2 */
  794. mindiv = 2 << CM_DIV_FRAC_BITS;
  795. /* clamp to the highest possible integer divider */
  796. maxdiv = (BIT(data->int_bits) - 1) << CM_DIV_FRAC_BITS;
  797. } else {
  798. /* clamp to min divider of 1 */
  799. mindiv = 1 << CM_DIV_FRAC_BITS;
  800. /* clamp to the highest possible fractional divider */
  801. maxdiv = GENMASK(data->int_bits + CM_DIV_FRAC_BITS - 1,
  802. CM_DIV_FRAC_BITS - data->frac_bits);
  803. }
  804. /* apply the clamping limits */
  805. div = max_t(u32, div, mindiv);
  806. div = min_t(u32, div, maxdiv);
  807. return div;
  808. }
  809. static long bcm2835_clock_rate_from_divisor(struct bcm2835_clock *clock,
  810. unsigned long parent_rate,
  811. u32 div)
  812. {
  813. const struct bcm2835_clock_data *data = clock->data;
  814. u64 temp;
  815. if (data->int_bits == 0 && data->frac_bits == 0)
  816. return parent_rate;
  817. /*
  818. * The divisor is a 12.12 fixed point field, but only some of
  819. * the bits are populated in any given clock.
  820. */
  821. div >>= CM_DIV_FRAC_BITS - data->frac_bits;
  822. div &= (1 << (data->int_bits + data->frac_bits)) - 1;
  823. if (div == 0)
  824. return 0;
  825. temp = (u64)parent_rate << data->frac_bits;
  826. do_div(temp, div);
  827. return temp;
  828. }
  829. static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw,
  830. unsigned long parent_rate)
  831. {
  832. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  833. struct bcm2835_cprman *cprman = clock->cprman;
  834. const struct bcm2835_clock_data *data = clock->data;
  835. u32 div;
  836. if (data->int_bits == 0 && data->frac_bits == 0)
  837. return parent_rate;
  838. div = cprman_read(cprman, data->div_reg);
  839. return bcm2835_clock_rate_from_divisor(clock, parent_rate, div);
  840. }
  841. static void bcm2835_clock_wait_busy(struct bcm2835_clock *clock)
  842. {
  843. struct bcm2835_cprman *cprman = clock->cprman;
  844. const struct bcm2835_clock_data *data = clock->data;
  845. ktime_t timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
  846. while (cprman_read(cprman, data->ctl_reg) & CM_BUSY) {
  847. if (ktime_after(ktime_get(), timeout)) {
  848. dev_err(cprman->dev, "%s: couldn't lock PLL\n",
  849. clk_hw_get_name(&clock->hw));
  850. return;
  851. }
  852. cpu_relax();
  853. }
  854. }
  855. static void bcm2835_clock_off(struct clk_hw *hw)
  856. {
  857. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  858. struct bcm2835_cprman *cprman = clock->cprman;
  859. const struct bcm2835_clock_data *data = clock->data;
  860. spin_lock(&cprman->regs_lock);
  861. cprman_write(cprman, data->ctl_reg,
  862. cprman_read(cprman, data->ctl_reg) & ~CM_ENABLE);
  863. spin_unlock(&cprman->regs_lock);
  864. /* BUSY will remain high until the divider completes its cycle. */
  865. bcm2835_clock_wait_busy(clock);
  866. }
  867. static int bcm2835_clock_on(struct clk_hw *hw)
  868. {
  869. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  870. struct bcm2835_cprman *cprman = clock->cprman;
  871. const struct bcm2835_clock_data *data = clock->data;
  872. spin_lock(&cprman->regs_lock);
  873. cprman_write(cprman, data->ctl_reg,
  874. cprman_read(cprman, data->ctl_reg) |
  875. CM_ENABLE |
  876. CM_GATE);
  877. spin_unlock(&cprman->regs_lock);
  878. /* Debug code to measure the clock once it's turned on to see
  879. * if it's ticking at the rate we expect.
  880. */
  881. if (data->tcnt_mux && false) {
  882. dev_info(cprman->dev,
  883. "clk %s: rate %ld, measure %ld\n",
  884. data->name,
  885. clk_hw_get_rate(hw),
  886. bcm2835_measure_tcnt_mux(cprman, data->tcnt_mux));
  887. }
  888. return 0;
  889. }
  890. static int bcm2835_clock_set_rate(struct clk_hw *hw,
  891. unsigned long rate, unsigned long parent_rate)
  892. {
  893. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  894. struct bcm2835_cprman *cprman = clock->cprman;
  895. const struct bcm2835_clock_data *data = clock->data;
  896. u32 div = bcm2835_clock_choose_div(hw, rate, parent_rate, false);
  897. u32 ctl;
  898. spin_lock(&cprman->regs_lock);
  899. /*
  900. * Setting up frac support
  901. *
  902. * In principle it is recommended to stop/start the clock first,
  903. * but as we set CLK_SET_RATE_GATE during registration of the
  904. * clock this requirement should be take care of by the
  905. * clk-framework.
  906. */
  907. ctl = cprman_read(cprman, data->ctl_reg) & ~CM_FRAC;
  908. ctl |= (div & CM_DIV_FRAC_MASK) ? CM_FRAC : 0;
  909. cprman_write(cprman, data->ctl_reg, ctl);
  910. cprman_write(cprman, data->div_reg, div);
  911. spin_unlock(&cprman->regs_lock);
  912. return 0;
  913. }
  914. static bool
  915. bcm2835_clk_is_pllc(struct clk_hw *hw)
  916. {
  917. if (!hw)
  918. return false;
  919. return strncmp(clk_hw_get_name(hw), "pllc", 4) == 0;
  920. }
  921. static unsigned long bcm2835_clock_choose_div_and_prate(struct clk_hw *hw,
  922. int parent_idx,
  923. unsigned long rate,
  924. u32 *div,
  925. unsigned long *prate,
  926. unsigned long *avgrate)
  927. {
  928. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  929. struct bcm2835_cprman *cprman = clock->cprman;
  930. const struct bcm2835_clock_data *data = clock->data;
  931. unsigned long best_rate = 0;
  932. u32 curdiv, mindiv, maxdiv;
  933. struct clk_hw *parent;
  934. parent = clk_hw_get_parent_by_index(hw, parent_idx);
  935. if (!(BIT(parent_idx) & data->set_rate_parent)) {
  936. *prate = clk_hw_get_rate(parent);
  937. *div = bcm2835_clock_choose_div(hw, rate, *prate, true);
  938. *avgrate = bcm2835_clock_rate_from_divisor(clock, *prate, *div);
  939. if (data->low_jitter && (*div & CM_DIV_FRAC_MASK)) {
  940. unsigned long high, low;
  941. u32 int_div = *div & ~CM_DIV_FRAC_MASK;
  942. high = bcm2835_clock_rate_from_divisor(clock, *prate,
  943. int_div);
  944. int_div += CM_DIV_FRAC_MASK + 1;
  945. low = bcm2835_clock_rate_from_divisor(clock, *prate,
  946. int_div);
  947. /*
  948. * Return a value which is the maximum deviation
  949. * below the ideal rate, for use as a metric.
  950. */
  951. return *avgrate - max(*avgrate - low, high - *avgrate);
  952. }
  953. return *avgrate;
  954. }
  955. if (data->frac_bits)
  956. dev_warn(cprman->dev,
  957. "frac bits are not used when propagating rate change");
  958. /* clamp to min divider of 2 if we're dealing with a mash clock */
  959. mindiv = data->is_mash_clock ? 2 : 1;
  960. maxdiv = BIT(data->int_bits) - 1;
  961. /* TODO: Be smart, and only test a subset of the available divisors. */
  962. for (curdiv = mindiv; curdiv <= maxdiv; curdiv++) {
  963. unsigned long tmp_rate;
  964. tmp_rate = clk_hw_round_rate(parent, rate * curdiv);
  965. tmp_rate /= curdiv;
  966. if (curdiv == mindiv ||
  967. (tmp_rate > best_rate && tmp_rate <= rate))
  968. best_rate = tmp_rate;
  969. if (best_rate == rate)
  970. break;
  971. }
  972. *div = curdiv << CM_DIV_FRAC_BITS;
  973. *prate = curdiv * best_rate;
  974. *avgrate = best_rate;
  975. return best_rate;
  976. }
  977. static int bcm2835_clock_determine_rate(struct clk_hw *hw,
  978. struct clk_rate_request *req)
  979. {
  980. struct clk_hw *parent, *best_parent = NULL;
  981. bool current_parent_is_pllc;
  982. unsigned long rate, best_rate = 0;
  983. unsigned long prate, best_prate = 0;
  984. unsigned long avgrate, best_avgrate = 0;
  985. size_t i;
  986. u32 div;
  987. current_parent_is_pllc = bcm2835_clk_is_pllc(clk_hw_get_parent(hw));
  988. /*
  989. * Select parent clock that results in the closest but lower rate
  990. */
  991. for (i = 0; i < clk_hw_get_num_parents(hw); ++i) {
  992. parent = clk_hw_get_parent_by_index(hw, i);
  993. if (!parent)
  994. continue;
  995. /*
  996. * Don't choose a PLLC-derived clock as our parent
  997. * unless it had been manually set that way. PLLC's
  998. * frequency gets adjusted by the firmware due to
  999. * over-temp or under-voltage conditions, without
  1000. * prior notification to our clock consumer.
  1001. */
  1002. if (bcm2835_clk_is_pllc(parent) && !current_parent_is_pllc)
  1003. continue;
  1004. rate = bcm2835_clock_choose_div_and_prate(hw, i, req->rate,
  1005. &div, &prate,
  1006. &avgrate);
  1007. if (rate > best_rate && rate <= req->rate) {
  1008. best_parent = parent;
  1009. best_prate = prate;
  1010. best_rate = rate;
  1011. best_avgrate = avgrate;
  1012. }
  1013. }
  1014. if (!best_parent)
  1015. return -EINVAL;
  1016. req->best_parent_hw = best_parent;
  1017. req->best_parent_rate = best_prate;
  1018. req->rate = best_avgrate;
  1019. return 0;
  1020. }
  1021. static int bcm2835_clock_set_parent(struct clk_hw *hw, u8 index)
  1022. {
  1023. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  1024. struct bcm2835_cprman *cprman = clock->cprman;
  1025. const struct bcm2835_clock_data *data = clock->data;
  1026. u8 src = (index << CM_SRC_SHIFT) & CM_SRC_MASK;
  1027. cprman_write(cprman, data->ctl_reg, src);
  1028. return 0;
  1029. }
  1030. static u8 bcm2835_clock_get_parent(struct clk_hw *hw)
  1031. {
  1032. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  1033. struct bcm2835_cprman *cprman = clock->cprman;
  1034. const struct bcm2835_clock_data *data = clock->data;
  1035. u32 src = cprman_read(cprman, data->ctl_reg);
  1036. return (src & CM_SRC_MASK) >> CM_SRC_SHIFT;
  1037. }
  1038. static struct debugfs_reg32 bcm2835_debugfs_clock_reg32[] = {
  1039. {
  1040. .name = "ctl",
  1041. .offset = 0,
  1042. },
  1043. {
  1044. .name = "div",
  1045. .offset = 4,
  1046. },
  1047. };
  1048. static void bcm2835_clock_debug_init(struct clk_hw *hw,
  1049. struct dentry *dentry)
  1050. {
  1051. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  1052. struct bcm2835_cprman *cprman = clock->cprman;
  1053. const struct bcm2835_clock_data *data = clock->data;
  1054. bcm2835_debugfs_regset(cprman, data->ctl_reg,
  1055. bcm2835_debugfs_clock_reg32,
  1056. ARRAY_SIZE(bcm2835_debugfs_clock_reg32),
  1057. dentry);
  1058. }
  1059. static const struct clk_ops bcm2835_clock_clk_ops = {
  1060. .is_prepared = bcm2835_clock_is_on,
  1061. .prepare = bcm2835_clock_on,
  1062. .unprepare = bcm2835_clock_off,
  1063. .recalc_rate = bcm2835_clock_get_rate,
  1064. .set_rate = bcm2835_clock_set_rate,
  1065. .determine_rate = bcm2835_clock_determine_rate,
  1066. .set_parent = bcm2835_clock_set_parent,
  1067. .get_parent = bcm2835_clock_get_parent,
  1068. .debug_init = bcm2835_clock_debug_init,
  1069. };
  1070. static int bcm2835_vpu_clock_is_on(struct clk_hw *hw)
  1071. {
  1072. return true;
  1073. }
  1074. /*
  1075. * The VPU clock can never be disabled (it doesn't have an ENABLE
  1076. * bit), so it gets its own set of clock ops.
  1077. */
  1078. static const struct clk_ops bcm2835_vpu_clock_clk_ops = {
  1079. .is_prepared = bcm2835_vpu_clock_is_on,
  1080. .recalc_rate = bcm2835_clock_get_rate,
  1081. .set_rate = bcm2835_clock_set_rate,
  1082. .determine_rate = bcm2835_clock_determine_rate,
  1083. .set_parent = bcm2835_clock_set_parent,
  1084. .get_parent = bcm2835_clock_get_parent,
  1085. .debug_init = bcm2835_clock_debug_init,
  1086. };
  1087. static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
  1088. const struct bcm2835_pll_data *data)
  1089. {
  1090. struct bcm2835_pll *pll;
  1091. struct clk_init_data init;
  1092. int ret;
  1093. memset(&init, 0, sizeof(init));
  1094. /* All of the PLLs derive from the external oscillator. */
  1095. init.parent_names = &cprman->real_parent_names[0];
  1096. init.num_parents = 1;
  1097. init.name = data->name;
  1098. init.ops = &bcm2835_pll_clk_ops;
  1099. init.flags = CLK_IGNORE_UNUSED;
  1100. pll = kzalloc(sizeof(*pll), GFP_KERNEL);
  1101. if (!pll)
  1102. return NULL;
  1103. pll->cprman = cprman;
  1104. pll->data = data;
  1105. pll->hw.init = &init;
  1106. ret = devm_clk_hw_register(cprman->dev, &pll->hw);
  1107. if (ret) {
  1108. kfree(pll);
  1109. return NULL;
  1110. }
  1111. return &pll->hw;
  1112. }
  1113. static struct clk_hw *
  1114. bcm2835_register_pll_divider(struct bcm2835_cprman *cprman,
  1115. const struct bcm2835_pll_divider_data *data)
  1116. {
  1117. struct bcm2835_pll_divider *divider;
  1118. struct clk_init_data init;
  1119. const char *divider_name;
  1120. int ret;
  1121. if (data->fixed_divider != 1) {
  1122. divider_name = devm_kasprintf(cprman->dev, GFP_KERNEL,
  1123. "%s_prediv", data->name);
  1124. if (!divider_name)
  1125. return NULL;
  1126. } else {
  1127. divider_name = data->name;
  1128. }
  1129. memset(&init, 0, sizeof(init));
  1130. init.parent_names = &data->source_pll;
  1131. init.num_parents = 1;
  1132. init.name = divider_name;
  1133. init.ops = &bcm2835_pll_divider_clk_ops;
  1134. init.flags = data->flags | CLK_IGNORE_UNUSED;
  1135. divider = devm_kzalloc(cprman->dev, sizeof(*divider), GFP_KERNEL);
  1136. if (!divider)
  1137. return NULL;
  1138. divider->div.reg = cprman->regs + data->a2w_reg;
  1139. divider->div.shift = A2W_PLL_DIV_SHIFT;
  1140. divider->div.width = A2W_PLL_DIV_BITS;
  1141. divider->div.flags = CLK_DIVIDER_MAX_AT_ZERO;
  1142. divider->div.lock = &cprman->regs_lock;
  1143. divider->div.hw.init = &init;
  1144. divider->div.table = NULL;
  1145. divider->cprman = cprman;
  1146. divider->data = data;
  1147. ret = devm_clk_hw_register(cprman->dev, &divider->div.hw);
  1148. if (ret)
  1149. return ERR_PTR(ret);
  1150. /*
  1151. * PLLH's channels have a fixed divide by 10 afterwards, which
  1152. * is what our consumers are actually using.
  1153. */
  1154. if (data->fixed_divider != 1) {
  1155. return clk_hw_register_fixed_factor(cprman->dev, data->name,
  1156. divider_name,
  1157. CLK_SET_RATE_PARENT,
  1158. 1,
  1159. data->fixed_divider);
  1160. }
  1161. return &divider->div.hw;
  1162. }
  1163. static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
  1164. const struct bcm2835_clock_data *data)
  1165. {
  1166. struct bcm2835_clock *clock;
  1167. struct clk_init_data init;
  1168. const char *parents[1 << CM_SRC_BITS];
  1169. size_t i;
  1170. int ret;
  1171. /*
  1172. * Replace our strings referencing parent clocks with the
  1173. * actual clock-output-name of the parent.
  1174. */
  1175. for (i = 0; i < data->num_mux_parents; i++) {
  1176. parents[i] = data->parents[i];
  1177. ret = match_string(cprman_parent_names,
  1178. ARRAY_SIZE(cprman_parent_names),
  1179. parents[i]);
  1180. if (ret >= 0)
  1181. parents[i] = cprman->real_parent_names[ret];
  1182. }
  1183. memset(&init, 0, sizeof(init));
  1184. init.parent_names = parents;
  1185. init.num_parents = data->num_mux_parents;
  1186. init.name = data->name;
  1187. init.flags = data->flags | CLK_IGNORE_UNUSED;
  1188. /*
  1189. * Pass the CLK_SET_RATE_PARENT flag if we are allowed to propagate
  1190. * rate changes on at least of the parents.
  1191. */
  1192. if (data->set_rate_parent)
  1193. init.flags |= CLK_SET_RATE_PARENT;
  1194. if (data->is_vpu_clock) {
  1195. init.ops = &bcm2835_vpu_clock_clk_ops;
  1196. } else {
  1197. init.ops = &bcm2835_clock_clk_ops;
  1198. init.flags |= CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE;
  1199. /* If the clock wasn't actually enabled at boot, it's not
  1200. * critical.
  1201. */
  1202. if (!(cprman_read(cprman, data->ctl_reg) & CM_ENABLE))
  1203. init.flags &= ~CLK_IS_CRITICAL;
  1204. }
  1205. clock = devm_kzalloc(cprman->dev, sizeof(*clock), GFP_KERNEL);
  1206. if (!clock)
  1207. return NULL;
  1208. clock->cprman = cprman;
  1209. clock->data = data;
  1210. clock->hw.init = &init;
  1211. ret = devm_clk_hw_register(cprman->dev, &clock->hw);
  1212. if (ret)
  1213. return ERR_PTR(ret);
  1214. return &clock->hw;
  1215. }
  1216. static struct clk_hw *bcm2835_register_gate(struct bcm2835_cprman *cprman,
  1217. const struct bcm2835_gate_data *data)
  1218. {
  1219. return clk_hw_register_gate(cprman->dev, data->name, data->parent,
  1220. CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
  1221. cprman->regs + data->ctl_reg,
  1222. CM_GATE_BIT, 0, &cprman->regs_lock);
  1223. }
  1224. typedef struct clk_hw *(*bcm2835_clk_register)(struct bcm2835_cprman *cprman,
  1225. const void *data);
  1226. struct bcm2835_clk_desc {
  1227. bcm2835_clk_register clk_register;
  1228. const void *data;
  1229. };
  1230. /* assignment helper macros for different clock types */
  1231. #define _REGISTER(f, ...) { .clk_register = (bcm2835_clk_register)f, \
  1232. .data = __VA_ARGS__ }
  1233. #define REGISTER_PLL(...) _REGISTER(&bcm2835_register_pll, \
  1234. &(struct bcm2835_pll_data) \
  1235. {__VA_ARGS__})
  1236. #define REGISTER_PLL_DIV(...) _REGISTER(&bcm2835_register_pll_divider, \
  1237. &(struct bcm2835_pll_divider_data) \
  1238. {__VA_ARGS__})
  1239. #define REGISTER_CLK(...) _REGISTER(&bcm2835_register_clock, \
  1240. &(struct bcm2835_clock_data) \
  1241. {__VA_ARGS__})
  1242. #define REGISTER_GATE(...) _REGISTER(&bcm2835_register_gate, \
  1243. &(struct bcm2835_gate_data) \
  1244. {__VA_ARGS__})
  1245. /* parent mux arrays plus helper macros */
  1246. /* main oscillator parent mux */
  1247. static const char *const bcm2835_clock_osc_parents[] = {
  1248. "gnd",
  1249. "xosc",
  1250. "testdebug0",
  1251. "testdebug1"
  1252. };
  1253. #define REGISTER_OSC_CLK(...) REGISTER_CLK( \
  1254. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_osc_parents), \
  1255. .parents = bcm2835_clock_osc_parents, \
  1256. __VA_ARGS__)
  1257. /* main peripherial parent mux */
  1258. static const char *const bcm2835_clock_per_parents[] = {
  1259. "gnd",
  1260. "xosc",
  1261. "testdebug0",
  1262. "testdebug1",
  1263. "plla_per",
  1264. "pllc_per",
  1265. "plld_per",
  1266. "pllh_aux",
  1267. };
  1268. #define REGISTER_PER_CLK(...) REGISTER_CLK( \
  1269. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_per_parents), \
  1270. .parents = bcm2835_clock_per_parents, \
  1271. __VA_ARGS__)
  1272. /*
  1273. * Restrict clock sources for the PCM peripheral to the oscillator and
  1274. * PLLD_PER because other source may have varying rates or be switched
  1275. * off.
  1276. *
  1277. * Prevent other sources from being selected by replacing their names in
  1278. * the list of potential parents with dummy entries (entry index is
  1279. * significant).
  1280. */
  1281. static const char *const bcm2835_pcm_per_parents[] = {
  1282. "-",
  1283. "xosc",
  1284. "-",
  1285. "-",
  1286. "-",
  1287. "-",
  1288. "plld_per",
  1289. "-",
  1290. };
  1291. #define REGISTER_PCM_CLK(...) REGISTER_CLK( \
  1292. .num_mux_parents = ARRAY_SIZE(bcm2835_pcm_per_parents), \
  1293. .parents = bcm2835_pcm_per_parents, \
  1294. __VA_ARGS__)
  1295. /* main vpu parent mux */
  1296. static const char *const bcm2835_clock_vpu_parents[] = {
  1297. "gnd",
  1298. "xosc",
  1299. "testdebug0",
  1300. "testdebug1",
  1301. "plla_core",
  1302. "pllc_core0",
  1303. "plld_core",
  1304. "pllh_aux",
  1305. "pllc_core1",
  1306. "pllc_core2",
  1307. };
  1308. #define REGISTER_VPU_CLK(...) REGISTER_CLK( \
  1309. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_vpu_parents), \
  1310. .parents = bcm2835_clock_vpu_parents, \
  1311. __VA_ARGS__)
  1312. /*
  1313. * DSI parent clocks. The DSI byte/DDR/DDR2 clocks come from the DSI
  1314. * analog PHY. The _inv variants are generated internally to cprman,
  1315. * but we don't use them so they aren't hooked up.
  1316. */
  1317. static const char *const bcm2835_clock_dsi0_parents[] = {
  1318. "gnd",
  1319. "xosc",
  1320. "testdebug0",
  1321. "testdebug1",
  1322. "dsi0_ddr",
  1323. "dsi0_ddr_inv",
  1324. "dsi0_ddr2",
  1325. "dsi0_ddr2_inv",
  1326. "dsi0_byte",
  1327. "dsi0_byte_inv",
  1328. };
  1329. static const char *const bcm2835_clock_dsi1_parents[] = {
  1330. "gnd",
  1331. "xosc",
  1332. "testdebug0",
  1333. "testdebug1",
  1334. "dsi1_ddr",
  1335. "dsi1_ddr_inv",
  1336. "dsi1_ddr2",
  1337. "dsi1_ddr2_inv",
  1338. "dsi1_byte",
  1339. "dsi1_byte_inv",
  1340. };
  1341. #define REGISTER_DSI0_CLK(...) REGISTER_CLK( \
  1342. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_dsi0_parents), \
  1343. .parents = bcm2835_clock_dsi0_parents, \
  1344. __VA_ARGS__)
  1345. #define REGISTER_DSI1_CLK(...) REGISTER_CLK( \
  1346. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_dsi1_parents), \
  1347. .parents = bcm2835_clock_dsi1_parents, \
  1348. __VA_ARGS__)
  1349. /*
  1350. * the real definition of all the pll, pll_dividers and clocks
  1351. * these make use of the above REGISTER_* macros
  1352. */
  1353. static const struct bcm2835_clk_desc clk_desc_array[] = {
  1354. /* the PLL + PLL dividers */
  1355. /*
  1356. * PLLA is the auxiliary PLL, used to drive the CCP2
  1357. * (Compact Camera Port 2) transmitter clock.
  1358. *
  1359. * It is in the PX LDO power domain, which is on when the
  1360. * AUDIO domain is on.
  1361. */
  1362. [BCM2835_PLLA] = REGISTER_PLL(
  1363. .name = "plla",
  1364. .cm_ctrl_reg = CM_PLLA,
  1365. .a2w_ctrl_reg = A2W_PLLA_CTRL,
  1366. .frac_reg = A2W_PLLA_FRAC,
  1367. .ana_reg_base = A2W_PLLA_ANA0,
  1368. .reference_enable_mask = A2W_XOSC_CTRL_PLLA_ENABLE,
  1369. .lock_mask = CM_LOCK_FLOCKA,
  1370. .ana = &bcm2835_ana_default,
  1371. .min_rate = 600000000u,
  1372. .max_rate = 2400000000u,
  1373. .max_fb_rate = BCM2835_MAX_FB_RATE),
  1374. [BCM2835_PLLA_CORE] = REGISTER_PLL_DIV(
  1375. .name = "plla_core",
  1376. .source_pll = "plla",
  1377. .cm_reg = CM_PLLA,
  1378. .a2w_reg = A2W_PLLA_CORE,
  1379. .load_mask = CM_PLLA_LOADCORE,
  1380. .hold_mask = CM_PLLA_HOLDCORE,
  1381. .fixed_divider = 1,
  1382. .flags = CLK_SET_RATE_PARENT),
  1383. [BCM2835_PLLA_PER] = REGISTER_PLL_DIV(
  1384. .name = "plla_per",
  1385. .source_pll = "plla",
  1386. .cm_reg = CM_PLLA,
  1387. .a2w_reg = A2W_PLLA_PER,
  1388. .load_mask = CM_PLLA_LOADPER,
  1389. .hold_mask = CM_PLLA_HOLDPER,
  1390. .fixed_divider = 1,
  1391. .flags = CLK_SET_RATE_PARENT),
  1392. [BCM2835_PLLA_DSI0] = REGISTER_PLL_DIV(
  1393. .name = "plla_dsi0",
  1394. .source_pll = "plla",
  1395. .cm_reg = CM_PLLA,
  1396. .a2w_reg = A2W_PLLA_DSI0,
  1397. .load_mask = CM_PLLA_LOADDSI0,
  1398. .hold_mask = CM_PLLA_HOLDDSI0,
  1399. .fixed_divider = 1),
  1400. [BCM2835_PLLA_CCP2] = REGISTER_PLL_DIV(
  1401. .name = "plla_ccp2",
  1402. .source_pll = "plla",
  1403. .cm_reg = CM_PLLA,
  1404. .a2w_reg = A2W_PLLA_CCP2,
  1405. .load_mask = CM_PLLA_LOADCCP2,
  1406. .hold_mask = CM_PLLA_HOLDCCP2,
  1407. .fixed_divider = 1,
  1408. .flags = CLK_SET_RATE_PARENT),
  1409. /* PLLB is used for the ARM's clock. */
  1410. [BCM2835_PLLB] = REGISTER_PLL(
  1411. .name = "pllb",
  1412. .cm_ctrl_reg = CM_PLLB,
  1413. .a2w_ctrl_reg = A2W_PLLB_CTRL,
  1414. .frac_reg = A2W_PLLB_FRAC,
  1415. .ana_reg_base = A2W_PLLB_ANA0,
  1416. .reference_enable_mask = A2W_XOSC_CTRL_PLLB_ENABLE,
  1417. .lock_mask = CM_LOCK_FLOCKB,
  1418. .ana = &bcm2835_ana_default,
  1419. .min_rate = 600000000u,
  1420. .max_rate = 3000000000u,
  1421. .max_fb_rate = BCM2835_MAX_FB_RATE),
  1422. [BCM2835_PLLB_ARM] = REGISTER_PLL_DIV(
  1423. .name = "pllb_arm",
  1424. .source_pll = "pllb",
  1425. .cm_reg = CM_PLLB,
  1426. .a2w_reg = A2W_PLLB_ARM,
  1427. .load_mask = CM_PLLB_LOADARM,
  1428. .hold_mask = CM_PLLB_HOLDARM,
  1429. .fixed_divider = 1,
  1430. .flags = CLK_SET_RATE_PARENT),
  1431. /*
  1432. * PLLC is the core PLL, used to drive the core VPU clock.
  1433. *
  1434. * It is in the PX LDO power domain, which is on when the
  1435. * AUDIO domain is on.
  1436. */
  1437. [BCM2835_PLLC] = REGISTER_PLL(
  1438. .name = "pllc",
  1439. .cm_ctrl_reg = CM_PLLC,
  1440. .a2w_ctrl_reg = A2W_PLLC_CTRL,
  1441. .frac_reg = A2W_PLLC_FRAC,
  1442. .ana_reg_base = A2W_PLLC_ANA0,
  1443. .reference_enable_mask = A2W_XOSC_CTRL_PLLC_ENABLE,
  1444. .lock_mask = CM_LOCK_FLOCKC,
  1445. .ana = &bcm2835_ana_default,
  1446. .min_rate = 600000000u,
  1447. .max_rate = 3000000000u,
  1448. .max_fb_rate = BCM2835_MAX_FB_RATE),
  1449. [BCM2835_PLLC_CORE0] = REGISTER_PLL_DIV(
  1450. .name = "pllc_core0",
  1451. .source_pll = "pllc",
  1452. .cm_reg = CM_PLLC,
  1453. .a2w_reg = A2W_PLLC_CORE0,
  1454. .load_mask = CM_PLLC_LOADCORE0,
  1455. .hold_mask = CM_PLLC_HOLDCORE0,
  1456. .fixed_divider = 1,
  1457. .flags = CLK_SET_RATE_PARENT),
  1458. [BCM2835_PLLC_CORE1] = REGISTER_PLL_DIV(
  1459. .name = "pllc_core1",
  1460. .source_pll = "pllc",
  1461. .cm_reg = CM_PLLC,
  1462. .a2w_reg = A2W_PLLC_CORE1,
  1463. .load_mask = CM_PLLC_LOADCORE1,
  1464. .hold_mask = CM_PLLC_HOLDCORE1,
  1465. .fixed_divider = 1,
  1466. .flags = CLK_SET_RATE_PARENT),
  1467. [BCM2835_PLLC_CORE2] = REGISTER_PLL_DIV(
  1468. .name = "pllc_core2",
  1469. .source_pll = "pllc",
  1470. .cm_reg = CM_PLLC,
  1471. .a2w_reg = A2W_PLLC_CORE2,
  1472. .load_mask = CM_PLLC_LOADCORE2,
  1473. .hold_mask = CM_PLLC_HOLDCORE2,
  1474. .fixed_divider = 1,
  1475. .flags = CLK_SET_RATE_PARENT),
  1476. [BCM2835_PLLC_PER] = REGISTER_PLL_DIV(
  1477. .name = "pllc_per",
  1478. .source_pll = "pllc",
  1479. .cm_reg = CM_PLLC,
  1480. .a2w_reg = A2W_PLLC_PER,
  1481. .load_mask = CM_PLLC_LOADPER,
  1482. .hold_mask = CM_PLLC_HOLDPER,
  1483. .fixed_divider = 1,
  1484. .flags = CLK_SET_RATE_PARENT),
  1485. /*
  1486. * PLLD is the display PLL, used to drive DSI display panels.
  1487. *
  1488. * It is in the PX LDO power domain, which is on when the
  1489. * AUDIO domain is on.
  1490. */
  1491. [BCM2835_PLLD] = REGISTER_PLL(
  1492. .name = "plld",
  1493. .cm_ctrl_reg = CM_PLLD,
  1494. .a2w_ctrl_reg = A2W_PLLD_CTRL,
  1495. .frac_reg = A2W_PLLD_FRAC,
  1496. .ana_reg_base = A2W_PLLD_ANA0,
  1497. .reference_enable_mask = A2W_XOSC_CTRL_DDR_ENABLE,
  1498. .lock_mask = CM_LOCK_FLOCKD,
  1499. .ana = &bcm2835_ana_default,
  1500. .min_rate = 600000000u,
  1501. .max_rate = 2400000000u,
  1502. .max_fb_rate = BCM2835_MAX_FB_RATE),
  1503. [BCM2835_PLLD_CORE] = REGISTER_PLL_DIV(
  1504. .name = "plld_core",
  1505. .source_pll = "plld",
  1506. .cm_reg = CM_PLLD,
  1507. .a2w_reg = A2W_PLLD_CORE,
  1508. .load_mask = CM_PLLD_LOADCORE,
  1509. .hold_mask = CM_PLLD_HOLDCORE,
  1510. .fixed_divider = 1,
  1511. .flags = CLK_SET_RATE_PARENT),
  1512. [BCM2835_PLLD_PER] = REGISTER_PLL_DIV(
  1513. .name = "plld_per",
  1514. .source_pll = "plld",
  1515. .cm_reg = CM_PLLD,
  1516. .a2w_reg = A2W_PLLD_PER,
  1517. .load_mask = CM_PLLD_LOADPER,
  1518. .hold_mask = CM_PLLD_HOLDPER,
  1519. .fixed_divider = 1,
  1520. .flags = CLK_SET_RATE_PARENT),
  1521. [BCM2835_PLLD_DSI0] = REGISTER_PLL_DIV(
  1522. .name = "plld_dsi0",
  1523. .source_pll = "plld",
  1524. .cm_reg = CM_PLLD,
  1525. .a2w_reg = A2W_PLLD_DSI0,
  1526. .load_mask = CM_PLLD_LOADDSI0,
  1527. .hold_mask = CM_PLLD_HOLDDSI0,
  1528. .fixed_divider = 1),
  1529. [BCM2835_PLLD_DSI1] = REGISTER_PLL_DIV(
  1530. .name = "plld_dsi1",
  1531. .source_pll = "plld",
  1532. .cm_reg = CM_PLLD,
  1533. .a2w_reg = A2W_PLLD_DSI1,
  1534. .load_mask = CM_PLLD_LOADDSI1,
  1535. .hold_mask = CM_PLLD_HOLDDSI1,
  1536. .fixed_divider = 1),
  1537. /*
  1538. * PLLH is used to supply the pixel clock or the AUX clock for the
  1539. * TV encoder.
  1540. *
  1541. * It is in the HDMI power domain.
  1542. */
  1543. [BCM2835_PLLH] = REGISTER_PLL(
  1544. "pllh",
  1545. .cm_ctrl_reg = CM_PLLH,
  1546. .a2w_ctrl_reg = A2W_PLLH_CTRL,
  1547. .frac_reg = A2W_PLLH_FRAC,
  1548. .ana_reg_base = A2W_PLLH_ANA0,
  1549. .reference_enable_mask = A2W_XOSC_CTRL_PLLC_ENABLE,
  1550. .lock_mask = CM_LOCK_FLOCKH,
  1551. .ana = &bcm2835_ana_pllh,
  1552. .min_rate = 600000000u,
  1553. .max_rate = 3000000000u,
  1554. .max_fb_rate = BCM2835_MAX_FB_RATE),
  1555. [BCM2835_PLLH_RCAL] = REGISTER_PLL_DIV(
  1556. .name = "pllh_rcal",
  1557. .source_pll = "pllh",
  1558. .cm_reg = CM_PLLH,
  1559. .a2w_reg = A2W_PLLH_RCAL,
  1560. .load_mask = CM_PLLH_LOADRCAL,
  1561. .hold_mask = 0,
  1562. .fixed_divider = 10,
  1563. .flags = CLK_SET_RATE_PARENT),
  1564. [BCM2835_PLLH_AUX] = REGISTER_PLL_DIV(
  1565. .name = "pllh_aux",
  1566. .source_pll = "pllh",
  1567. .cm_reg = CM_PLLH,
  1568. .a2w_reg = A2W_PLLH_AUX,
  1569. .load_mask = CM_PLLH_LOADAUX,
  1570. .hold_mask = 0,
  1571. .fixed_divider = 1,
  1572. .flags = CLK_SET_RATE_PARENT),
  1573. [BCM2835_PLLH_PIX] = REGISTER_PLL_DIV(
  1574. .name = "pllh_pix",
  1575. .source_pll = "pllh",
  1576. .cm_reg = CM_PLLH,
  1577. .a2w_reg = A2W_PLLH_PIX,
  1578. .load_mask = CM_PLLH_LOADPIX,
  1579. .hold_mask = 0,
  1580. .fixed_divider = 10,
  1581. .flags = CLK_SET_RATE_PARENT),
  1582. /* the clocks */
  1583. /* clocks with oscillator parent mux */
  1584. /* One Time Programmable Memory clock. Maximum 10Mhz. */
  1585. [BCM2835_CLOCK_OTP] = REGISTER_OSC_CLK(
  1586. .name = "otp",
  1587. .ctl_reg = CM_OTPCTL,
  1588. .div_reg = CM_OTPDIV,
  1589. .int_bits = 4,
  1590. .frac_bits = 0,
  1591. .tcnt_mux = 6),
  1592. /*
  1593. * Used for a 1Mhz clock for the system clocksource, and also used
  1594. * bythe watchdog timer and the camera pulse generator.
  1595. */
  1596. [BCM2835_CLOCK_TIMER] = REGISTER_OSC_CLK(
  1597. .name = "timer",
  1598. .ctl_reg = CM_TIMERCTL,
  1599. .div_reg = CM_TIMERDIV,
  1600. .int_bits = 6,
  1601. .frac_bits = 12),
  1602. /*
  1603. * Clock for the temperature sensor.
  1604. * Generally run at 2Mhz, max 5Mhz.
  1605. */
  1606. [BCM2835_CLOCK_TSENS] = REGISTER_OSC_CLK(
  1607. .name = "tsens",
  1608. .ctl_reg = CM_TSENSCTL,
  1609. .div_reg = CM_TSENSDIV,
  1610. .int_bits = 5,
  1611. .frac_bits = 0),
  1612. [BCM2835_CLOCK_TEC] = REGISTER_OSC_CLK(
  1613. .name = "tec",
  1614. .ctl_reg = CM_TECCTL,
  1615. .div_reg = CM_TECDIV,
  1616. .int_bits = 6,
  1617. .frac_bits = 0),
  1618. /* clocks with vpu parent mux */
  1619. [BCM2835_CLOCK_H264] = REGISTER_VPU_CLK(
  1620. .name = "h264",
  1621. .ctl_reg = CM_H264CTL,
  1622. .div_reg = CM_H264DIV,
  1623. .int_bits = 4,
  1624. .frac_bits = 8,
  1625. .tcnt_mux = 1),
  1626. [BCM2835_CLOCK_ISP] = REGISTER_VPU_CLK(
  1627. .name = "isp",
  1628. .ctl_reg = CM_ISPCTL,
  1629. .div_reg = CM_ISPDIV,
  1630. .int_bits = 4,
  1631. .frac_bits = 8,
  1632. .tcnt_mux = 2),
  1633. /*
  1634. * Secondary SDRAM clock. Used for low-voltage modes when the PLL
  1635. * in the SDRAM controller can't be used.
  1636. */
  1637. [BCM2835_CLOCK_SDRAM] = REGISTER_VPU_CLK(
  1638. .name = "sdram",
  1639. .ctl_reg = CM_SDCCTL,
  1640. .div_reg = CM_SDCDIV,
  1641. .int_bits = 6,
  1642. .frac_bits = 0,
  1643. .tcnt_mux = 3),
  1644. [BCM2835_CLOCK_V3D] = REGISTER_VPU_CLK(
  1645. .name = "v3d",
  1646. .ctl_reg = CM_V3DCTL,
  1647. .div_reg = CM_V3DDIV,
  1648. .int_bits = 4,
  1649. .frac_bits = 8,
  1650. .tcnt_mux = 4),
  1651. /*
  1652. * VPU clock. This doesn't have an enable bit, since it drives
  1653. * the bus for everything else, and is special so it doesn't need
  1654. * to be gated for rate changes. It is also known as "clk_audio"
  1655. * in various hardware documentation.
  1656. */
  1657. [BCM2835_CLOCK_VPU] = REGISTER_VPU_CLK(
  1658. .name = "vpu",
  1659. .ctl_reg = CM_VPUCTL,
  1660. .div_reg = CM_VPUDIV,
  1661. .int_bits = 12,
  1662. .frac_bits = 8,
  1663. .flags = CLK_IS_CRITICAL,
  1664. .is_vpu_clock = true,
  1665. .tcnt_mux = 5),
  1666. /* clocks with per parent mux */
  1667. [BCM2835_CLOCK_AVEO] = REGISTER_PER_CLK(
  1668. .name = "aveo",
  1669. .ctl_reg = CM_AVEOCTL,
  1670. .div_reg = CM_AVEODIV,
  1671. .int_bits = 4,
  1672. .frac_bits = 0,
  1673. .tcnt_mux = 38),
  1674. [BCM2835_CLOCK_CAM0] = REGISTER_PER_CLK(
  1675. .name = "cam0",
  1676. .ctl_reg = CM_CAM0CTL,
  1677. .div_reg = CM_CAM0DIV,
  1678. .int_bits = 4,
  1679. .frac_bits = 8,
  1680. .tcnt_mux = 14),
  1681. [BCM2835_CLOCK_CAM1] = REGISTER_PER_CLK(
  1682. .name = "cam1",
  1683. .ctl_reg = CM_CAM1CTL,
  1684. .div_reg = CM_CAM1DIV,
  1685. .int_bits = 4,
  1686. .frac_bits = 8,
  1687. .tcnt_mux = 15),
  1688. [BCM2835_CLOCK_DFT] = REGISTER_PER_CLK(
  1689. .name = "dft",
  1690. .ctl_reg = CM_DFTCTL,
  1691. .div_reg = CM_DFTDIV,
  1692. .int_bits = 5,
  1693. .frac_bits = 0),
  1694. [BCM2835_CLOCK_DPI] = REGISTER_PER_CLK(
  1695. .name = "dpi",
  1696. .ctl_reg = CM_DPICTL,
  1697. .div_reg = CM_DPIDIV,
  1698. .int_bits = 4,
  1699. .frac_bits = 8,
  1700. .tcnt_mux = 17),
  1701. /* Arasan EMMC clock */
  1702. [BCM2835_CLOCK_EMMC] = REGISTER_PER_CLK(
  1703. .name = "emmc",
  1704. .ctl_reg = CM_EMMCCTL,
  1705. .div_reg = CM_EMMCDIV,
  1706. .int_bits = 4,
  1707. .frac_bits = 8,
  1708. .tcnt_mux = 39),
  1709. /* General purpose (GPIO) clocks */
  1710. [BCM2835_CLOCK_GP0] = REGISTER_PER_CLK(
  1711. .name = "gp0",
  1712. .ctl_reg = CM_GP0CTL,
  1713. .div_reg = CM_GP0DIV,
  1714. .int_bits = 12,
  1715. .frac_bits = 12,
  1716. .is_mash_clock = true,
  1717. .tcnt_mux = 20),
  1718. [BCM2835_CLOCK_GP1] = REGISTER_PER_CLK(
  1719. .name = "gp1",
  1720. .ctl_reg = CM_GP1CTL,
  1721. .div_reg = CM_GP1DIV,
  1722. .int_bits = 12,
  1723. .frac_bits = 12,
  1724. .flags = CLK_IS_CRITICAL,
  1725. .is_mash_clock = true,
  1726. .tcnt_mux = 21),
  1727. [BCM2835_CLOCK_GP2] = REGISTER_PER_CLK(
  1728. .name = "gp2",
  1729. .ctl_reg = CM_GP2CTL,
  1730. .div_reg = CM_GP2DIV,
  1731. .int_bits = 12,
  1732. .frac_bits = 12,
  1733. .flags = CLK_IS_CRITICAL),
  1734. /* HDMI state machine */
  1735. [BCM2835_CLOCK_HSM] = REGISTER_PER_CLK(
  1736. .name = "hsm",
  1737. .ctl_reg = CM_HSMCTL,
  1738. .div_reg = CM_HSMDIV,
  1739. .int_bits = 4,
  1740. .frac_bits = 8,
  1741. .tcnt_mux = 22),
  1742. [BCM2835_CLOCK_PCM] = REGISTER_PCM_CLK(
  1743. .name = "pcm",
  1744. .ctl_reg = CM_PCMCTL,
  1745. .div_reg = CM_PCMDIV,
  1746. .int_bits = 12,
  1747. .frac_bits = 12,
  1748. .is_mash_clock = true,
  1749. .low_jitter = true,
  1750. .tcnt_mux = 23),
  1751. [BCM2835_CLOCK_PWM] = REGISTER_PER_CLK(
  1752. .name = "pwm",
  1753. .ctl_reg = CM_PWMCTL,
  1754. .div_reg = CM_PWMDIV,
  1755. .int_bits = 12,
  1756. .frac_bits = 12,
  1757. .is_mash_clock = true,
  1758. .tcnt_mux = 24),
  1759. [BCM2835_CLOCK_SLIM] = REGISTER_PER_CLK(
  1760. .name = "slim",
  1761. .ctl_reg = CM_SLIMCTL,
  1762. .div_reg = CM_SLIMDIV,
  1763. .int_bits = 12,
  1764. .frac_bits = 12,
  1765. .is_mash_clock = true,
  1766. .tcnt_mux = 25),
  1767. [BCM2835_CLOCK_SMI] = REGISTER_PER_CLK(
  1768. .name = "smi",
  1769. .ctl_reg = CM_SMICTL,
  1770. .div_reg = CM_SMIDIV,
  1771. .int_bits = 4,
  1772. .frac_bits = 8,
  1773. .tcnt_mux = 27),
  1774. [BCM2835_CLOCK_UART] = REGISTER_PER_CLK(
  1775. .name = "uart",
  1776. .ctl_reg = CM_UARTCTL,
  1777. .div_reg = CM_UARTDIV,
  1778. .int_bits = 10,
  1779. .frac_bits = 12,
  1780. .tcnt_mux = 28),
  1781. /* TV encoder clock. Only operating frequency is 108Mhz. */
  1782. [BCM2835_CLOCK_VEC] = REGISTER_PER_CLK(
  1783. .name = "vec",
  1784. .ctl_reg = CM_VECCTL,
  1785. .div_reg = CM_VECDIV,
  1786. .int_bits = 4,
  1787. .frac_bits = 0,
  1788. /*
  1789. * Allow rate change propagation only on PLLH_AUX which is
  1790. * assigned index 7 in the parent array.
  1791. */
  1792. .set_rate_parent = BIT(7),
  1793. .tcnt_mux = 29),
  1794. /* dsi clocks */
  1795. [BCM2835_CLOCK_DSI0E] = REGISTER_PER_CLK(
  1796. .name = "dsi0e",
  1797. .ctl_reg = CM_DSI0ECTL,
  1798. .div_reg = CM_DSI0EDIV,
  1799. .int_bits = 4,
  1800. .frac_bits = 8,
  1801. .tcnt_mux = 18),
  1802. [BCM2835_CLOCK_DSI1E] = REGISTER_PER_CLK(
  1803. .name = "dsi1e",
  1804. .ctl_reg = CM_DSI1ECTL,
  1805. .div_reg = CM_DSI1EDIV,
  1806. .int_bits = 4,
  1807. .frac_bits = 8,
  1808. .tcnt_mux = 19),
  1809. [BCM2835_CLOCK_DSI0P] = REGISTER_DSI0_CLK(
  1810. .name = "dsi0p",
  1811. .ctl_reg = CM_DSI0PCTL,
  1812. .div_reg = CM_DSI0PDIV,
  1813. .int_bits = 0,
  1814. .frac_bits = 0,
  1815. .tcnt_mux = 12),
  1816. [BCM2835_CLOCK_DSI1P] = REGISTER_DSI1_CLK(
  1817. .name = "dsi1p",
  1818. .ctl_reg = CM_DSI1PCTL,
  1819. .div_reg = CM_DSI1PDIV,
  1820. .int_bits = 0,
  1821. .frac_bits = 0,
  1822. .tcnt_mux = 13),
  1823. /* the gates */
  1824. /*
  1825. * CM_PERIICTL (and CM_PERIACTL, CM_SYSCTL and CM_VPUCTL if
  1826. * you have the debug bit set in the power manager, which we
  1827. * don't bother exposing) are individual gates off of the
  1828. * non-stop vpu clock.
  1829. */
  1830. [BCM2835_CLOCK_PERI_IMAGE] = REGISTER_GATE(
  1831. .name = "peri_image",
  1832. .parent = "vpu",
  1833. .ctl_reg = CM_PERIICTL),
  1834. };
  1835. /*
  1836. * Permanently take a reference on the parent of the SDRAM clock.
  1837. *
  1838. * While the SDRAM is being driven by its dedicated PLL most of the
  1839. * time, there is a little loop running in the firmware that
  1840. * periodically switches the SDRAM to using our CM clock to do PVT
  1841. * recalibration, with the assumption that the previously configured
  1842. * SDRAM parent is still enabled and running.
  1843. */
  1844. static int bcm2835_mark_sdc_parent_critical(struct clk *sdc)
  1845. {
  1846. struct clk *parent = clk_get_parent(sdc);
  1847. if (IS_ERR(parent))
  1848. return PTR_ERR(parent);
  1849. return clk_prepare_enable(parent);
  1850. }
  1851. static int bcm2835_clk_probe(struct platform_device *pdev)
  1852. {
  1853. struct device *dev = &pdev->dev;
  1854. struct clk_hw **hws;
  1855. struct bcm2835_cprman *cprman;
  1856. struct resource *res;
  1857. const struct bcm2835_clk_desc *desc;
  1858. const size_t asize = ARRAY_SIZE(clk_desc_array);
  1859. size_t i;
  1860. int ret;
  1861. cprman = devm_kzalloc(dev,
  1862. struct_size(cprman, onecell.hws, asize),
  1863. GFP_KERNEL);
  1864. if (!cprman)
  1865. return -ENOMEM;
  1866. spin_lock_init(&cprman->regs_lock);
  1867. cprman->dev = dev;
  1868. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1869. cprman->regs = devm_ioremap_resource(dev, res);
  1870. if (IS_ERR(cprman->regs))
  1871. return PTR_ERR(cprman->regs);
  1872. memcpy(cprman->real_parent_names, cprman_parent_names,
  1873. sizeof(cprman_parent_names));
  1874. of_clk_parent_fill(dev->of_node, cprman->real_parent_names,
  1875. ARRAY_SIZE(cprman_parent_names));
  1876. /*
  1877. * Make sure the external oscillator has been registered.
  1878. *
  1879. * The other (DSI) clocks are not present on older device
  1880. * trees, which we still need to support for backwards
  1881. * compatibility.
  1882. */
  1883. if (!cprman->real_parent_names[0])
  1884. return -ENODEV;
  1885. platform_set_drvdata(pdev, cprman);
  1886. cprman->onecell.num = asize;
  1887. hws = cprman->onecell.hws;
  1888. for (i = 0; i < asize; i++) {
  1889. desc = &clk_desc_array[i];
  1890. if (desc->clk_register && desc->data)
  1891. hws[i] = desc->clk_register(cprman, desc->data);
  1892. }
  1893. ret = bcm2835_mark_sdc_parent_critical(hws[BCM2835_CLOCK_SDRAM]->clk);
  1894. if (ret)
  1895. return ret;
  1896. return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
  1897. &cprman->onecell);
  1898. }
  1899. static const struct of_device_id bcm2835_clk_of_match[] = {
  1900. { .compatible = "brcm,bcm2835-cprman", },
  1901. {}
  1902. };
  1903. MODULE_DEVICE_TABLE(of, bcm2835_clk_of_match);
  1904. static struct platform_driver bcm2835_clk_driver = {
  1905. .driver = {
  1906. .name = "bcm2835-clk",
  1907. .of_match_table = bcm2835_clk_of_match,
  1908. },
  1909. .probe = bcm2835_clk_probe,
  1910. };
  1911. builtin_platform_driver(bcm2835_clk_driver);
  1912. MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
  1913. MODULE_DESCRIPTION("BCM2835 clock driver");
  1914. MODULE_LICENSE("GPL v2");