clk-bcm2835.c 59 KB

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