clk-bcm2835.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209
  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. return NULL;
  1109. return &pll->hw;
  1110. }
  1111. static struct clk_hw *
  1112. bcm2835_register_pll_divider(struct bcm2835_cprman *cprman,
  1113. const struct bcm2835_pll_divider_data *data)
  1114. {
  1115. struct bcm2835_pll_divider *divider;
  1116. struct clk_init_data init;
  1117. const char *divider_name;
  1118. int ret;
  1119. if (data->fixed_divider != 1) {
  1120. divider_name = devm_kasprintf(cprman->dev, GFP_KERNEL,
  1121. "%s_prediv", data->name);
  1122. if (!divider_name)
  1123. return NULL;
  1124. } else {
  1125. divider_name = data->name;
  1126. }
  1127. memset(&init, 0, sizeof(init));
  1128. init.parent_names = &data->source_pll;
  1129. init.num_parents = 1;
  1130. init.name = divider_name;
  1131. init.ops = &bcm2835_pll_divider_clk_ops;
  1132. init.flags = data->flags | CLK_IGNORE_UNUSED;
  1133. divider = devm_kzalloc(cprman->dev, sizeof(*divider), GFP_KERNEL);
  1134. if (!divider)
  1135. return NULL;
  1136. divider->div.reg = cprman->regs + data->a2w_reg;
  1137. divider->div.shift = A2W_PLL_DIV_SHIFT;
  1138. divider->div.width = A2W_PLL_DIV_BITS;
  1139. divider->div.flags = CLK_DIVIDER_MAX_AT_ZERO;
  1140. divider->div.lock = &cprman->regs_lock;
  1141. divider->div.hw.init = &init;
  1142. divider->div.table = NULL;
  1143. divider->cprman = cprman;
  1144. divider->data = data;
  1145. ret = devm_clk_hw_register(cprman->dev, &divider->div.hw);
  1146. if (ret)
  1147. return ERR_PTR(ret);
  1148. /*
  1149. * PLLH's channels have a fixed divide by 10 afterwards, which
  1150. * is what our consumers are actually using.
  1151. */
  1152. if (data->fixed_divider != 1) {
  1153. return clk_hw_register_fixed_factor(cprman->dev, data->name,
  1154. divider_name,
  1155. CLK_SET_RATE_PARENT,
  1156. 1,
  1157. data->fixed_divider);
  1158. }
  1159. return &divider->div.hw;
  1160. }
  1161. static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
  1162. const struct bcm2835_clock_data *data)
  1163. {
  1164. struct bcm2835_clock *clock;
  1165. struct clk_init_data init;
  1166. const char *parents[1 << CM_SRC_BITS];
  1167. size_t i;
  1168. int ret;
  1169. /*
  1170. * Replace our strings referencing parent clocks with the
  1171. * actual clock-output-name of the parent.
  1172. */
  1173. for (i = 0; i < data->num_mux_parents; i++) {
  1174. parents[i] = data->parents[i];
  1175. ret = match_string(cprman_parent_names,
  1176. ARRAY_SIZE(cprman_parent_names),
  1177. parents[i]);
  1178. if (ret >= 0)
  1179. parents[i] = cprman->real_parent_names[ret];
  1180. }
  1181. memset(&init, 0, sizeof(init));
  1182. init.parent_names = parents;
  1183. init.num_parents = data->num_mux_parents;
  1184. init.name = data->name;
  1185. init.flags = data->flags | CLK_IGNORE_UNUSED;
  1186. /*
  1187. * Pass the CLK_SET_RATE_PARENT flag if we are allowed to propagate
  1188. * rate changes on at least of the parents.
  1189. */
  1190. if (data->set_rate_parent)
  1191. init.flags |= CLK_SET_RATE_PARENT;
  1192. if (data->is_vpu_clock) {
  1193. init.ops = &bcm2835_vpu_clock_clk_ops;
  1194. } else {
  1195. init.ops = &bcm2835_clock_clk_ops;
  1196. init.flags |= CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE;
  1197. /* If the clock wasn't actually enabled at boot, it's not
  1198. * critical.
  1199. */
  1200. if (!(cprman_read(cprman, data->ctl_reg) & CM_ENABLE))
  1201. init.flags &= ~CLK_IS_CRITICAL;
  1202. }
  1203. clock = devm_kzalloc(cprman->dev, sizeof(*clock), GFP_KERNEL);
  1204. if (!clock)
  1205. return NULL;
  1206. clock->cprman = cprman;
  1207. clock->data = data;
  1208. clock->hw.init = &init;
  1209. ret = devm_clk_hw_register(cprman->dev, &clock->hw);
  1210. if (ret)
  1211. return ERR_PTR(ret);
  1212. return &clock->hw;
  1213. }
  1214. static struct clk *bcm2835_register_gate(struct bcm2835_cprman *cprman,
  1215. const struct bcm2835_gate_data *data)
  1216. {
  1217. return clk_register_gate(cprman->dev, data->name, data->parent,
  1218. CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
  1219. cprman->regs + data->ctl_reg,
  1220. CM_GATE_BIT, 0, &cprman->regs_lock);
  1221. }
  1222. typedef struct clk_hw *(*bcm2835_clk_register)(struct bcm2835_cprman *cprman,
  1223. const void *data);
  1224. struct bcm2835_clk_desc {
  1225. bcm2835_clk_register clk_register;
  1226. const void *data;
  1227. };
  1228. /* assignment helper macros for different clock types */
  1229. #define _REGISTER(f, ...) { .clk_register = (bcm2835_clk_register)f, \
  1230. .data = __VA_ARGS__ }
  1231. #define REGISTER_PLL(...) _REGISTER(&bcm2835_register_pll, \
  1232. &(struct bcm2835_pll_data) \
  1233. {__VA_ARGS__})
  1234. #define REGISTER_PLL_DIV(...) _REGISTER(&bcm2835_register_pll_divider, \
  1235. &(struct bcm2835_pll_divider_data) \
  1236. {__VA_ARGS__})
  1237. #define REGISTER_CLK(...) _REGISTER(&bcm2835_register_clock, \
  1238. &(struct bcm2835_clock_data) \
  1239. {__VA_ARGS__})
  1240. #define REGISTER_GATE(...) _REGISTER(&bcm2835_register_gate, \
  1241. &(struct bcm2835_gate_data) \
  1242. {__VA_ARGS__})
  1243. /* parent mux arrays plus helper macros */
  1244. /* main oscillator parent mux */
  1245. static const char *const bcm2835_clock_osc_parents[] = {
  1246. "gnd",
  1247. "xosc",
  1248. "testdebug0",
  1249. "testdebug1"
  1250. };
  1251. #define REGISTER_OSC_CLK(...) REGISTER_CLK( \
  1252. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_osc_parents), \
  1253. .parents = bcm2835_clock_osc_parents, \
  1254. __VA_ARGS__)
  1255. /* main peripherial parent mux */
  1256. static const char *const bcm2835_clock_per_parents[] = {
  1257. "gnd",
  1258. "xosc",
  1259. "testdebug0",
  1260. "testdebug1",
  1261. "plla_per",
  1262. "pllc_per",
  1263. "plld_per",
  1264. "pllh_aux",
  1265. };
  1266. #define REGISTER_PER_CLK(...) REGISTER_CLK( \
  1267. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_per_parents), \
  1268. .parents = bcm2835_clock_per_parents, \
  1269. __VA_ARGS__)
  1270. /*
  1271. * Restrict clock sources for the PCM peripheral to the oscillator and
  1272. * PLLD_PER because other source may have varying rates or be switched
  1273. * off.
  1274. *
  1275. * Prevent other sources from being selected by replacing their names in
  1276. * the list of potential parents with dummy entries (entry index is
  1277. * significant).
  1278. */
  1279. static const char *const bcm2835_pcm_per_parents[] = {
  1280. "-",
  1281. "xosc",
  1282. "-",
  1283. "-",
  1284. "-",
  1285. "-",
  1286. "plld_per",
  1287. "-",
  1288. };
  1289. #define REGISTER_PCM_CLK(...) REGISTER_CLK( \
  1290. .num_mux_parents = ARRAY_SIZE(bcm2835_pcm_per_parents), \
  1291. .parents = bcm2835_pcm_per_parents, \
  1292. __VA_ARGS__)
  1293. /* main vpu parent mux */
  1294. static const char *const bcm2835_clock_vpu_parents[] = {
  1295. "gnd",
  1296. "xosc",
  1297. "testdebug0",
  1298. "testdebug1",
  1299. "plla_core",
  1300. "pllc_core0",
  1301. "plld_core",
  1302. "pllh_aux",
  1303. "pllc_core1",
  1304. "pllc_core2",
  1305. };
  1306. #define REGISTER_VPU_CLK(...) REGISTER_CLK( \
  1307. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_vpu_parents), \
  1308. .parents = bcm2835_clock_vpu_parents, \
  1309. __VA_ARGS__)
  1310. /*
  1311. * DSI parent clocks. The DSI byte/DDR/DDR2 clocks come from the DSI
  1312. * analog PHY. The _inv variants are generated internally to cprman,
  1313. * but we don't use them so they aren't hooked up.
  1314. */
  1315. static const char *const bcm2835_clock_dsi0_parents[] = {
  1316. "gnd",
  1317. "xosc",
  1318. "testdebug0",
  1319. "testdebug1",
  1320. "dsi0_ddr",
  1321. "dsi0_ddr_inv",
  1322. "dsi0_ddr2",
  1323. "dsi0_ddr2_inv",
  1324. "dsi0_byte",
  1325. "dsi0_byte_inv",
  1326. };
  1327. static const char *const bcm2835_clock_dsi1_parents[] = {
  1328. "gnd",
  1329. "xosc",
  1330. "testdebug0",
  1331. "testdebug1",
  1332. "dsi1_ddr",
  1333. "dsi1_ddr_inv",
  1334. "dsi1_ddr2",
  1335. "dsi1_ddr2_inv",
  1336. "dsi1_byte",
  1337. "dsi1_byte_inv",
  1338. };
  1339. #define REGISTER_DSI0_CLK(...) REGISTER_CLK( \
  1340. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_dsi0_parents), \
  1341. .parents = bcm2835_clock_dsi0_parents, \
  1342. __VA_ARGS__)
  1343. #define REGISTER_DSI1_CLK(...) REGISTER_CLK( \
  1344. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_dsi1_parents), \
  1345. .parents = bcm2835_clock_dsi1_parents, \
  1346. __VA_ARGS__)
  1347. /*
  1348. * the real definition of all the pll, pll_dividers and clocks
  1349. * these make use of the above REGISTER_* macros
  1350. */
  1351. static const struct bcm2835_clk_desc clk_desc_array[] = {
  1352. /* the PLL + PLL dividers */
  1353. /*
  1354. * PLLA is the auxiliary PLL, used to drive the CCP2
  1355. * (Compact Camera Port 2) transmitter clock.
  1356. *
  1357. * It is in the PX LDO power domain, which is on when the
  1358. * AUDIO domain is on.
  1359. */
  1360. [BCM2835_PLLA] = REGISTER_PLL(
  1361. .name = "plla",
  1362. .cm_ctrl_reg = CM_PLLA,
  1363. .a2w_ctrl_reg = A2W_PLLA_CTRL,
  1364. .frac_reg = A2W_PLLA_FRAC,
  1365. .ana_reg_base = A2W_PLLA_ANA0,
  1366. .reference_enable_mask = A2W_XOSC_CTRL_PLLA_ENABLE,
  1367. .lock_mask = CM_LOCK_FLOCKA,
  1368. .ana = &bcm2835_ana_default,
  1369. .min_rate = 600000000u,
  1370. .max_rate = 2400000000u,
  1371. .max_fb_rate = BCM2835_MAX_FB_RATE),
  1372. [BCM2835_PLLA_CORE] = REGISTER_PLL_DIV(
  1373. .name = "plla_core",
  1374. .source_pll = "plla",
  1375. .cm_reg = CM_PLLA,
  1376. .a2w_reg = A2W_PLLA_CORE,
  1377. .load_mask = CM_PLLA_LOADCORE,
  1378. .hold_mask = CM_PLLA_HOLDCORE,
  1379. .fixed_divider = 1,
  1380. .flags = CLK_SET_RATE_PARENT),
  1381. [BCM2835_PLLA_PER] = REGISTER_PLL_DIV(
  1382. .name = "plla_per",
  1383. .source_pll = "plla",
  1384. .cm_reg = CM_PLLA,
  1385. .a2w_reg = A2W_PLLA_PER,
  1386. .load_mask = CM_PLLA_LOADPER,
  1387. .hold_mask = CM_PLLA_HOLDPER,
  1388. .fixed_divider = 1,
  1389. .flags = CLK_SET_RATE_PARENT),
  1390. [BCM2835_PLLA_DSI0] = REGISTER_PLL_DIV(
  1391. .name = "plla_dsi0",
  1392. .source_pll = "plla",
  1393. .cm_reg = CM_PLLA,
  1394. .a2w_reg = A2W_PLLA_DSI0,
  1395. .load_mask = CM_PLLA_LOADDSI0,
  1396. .hold_mask = CM_PLLA_HOLDDSI0,
  1397. .fixed_divider = 1),
  1398. [BCM2835_PLLA_CCP2] = REGISTER_PLL_DIV(
  1399. .name = "plla_ccp2",
  1400. .source_pll = "plla",
  1401. .cm_reg = CM_PLLA,
  1402. .a2w_reg = A2W_PLLA_CCP2,
  1403. .load_mask = CM_PLLA_LOADCCP2,
  1404. .hold_mask = CM_PLLA_HOLDCCP2,
  1405. .fixed_divider = 1,
  1406. .flags = CLK_SET_RATE_PARENT),
  1407. /* PLLB is used for the ARM's clock. */
  1408. [BCM2835_PLLB] = REGISTER_PLL(
  1409. .name = "pllb",
  1410. .cm_ctrl_reg = CM_PLLB,
  1411. .a2w_ctrl_reg = A2W_PLLB_CTRL,
  1412. .frac_reg = A2W_PLLB_FRAC,
  1413. .ana_reg_base = A2W_PLLB_ANA0,
  1414. .reference_enable_mask = A2W_XOSC_CTRL_PLLB_ENABLE,
  1415. .lock_mask = CM_LOCK_FLOCKB,
  1416. .ana = &bcm2835_ana_default,
  1417. .min_rate = 600000000u,
  1418. .max_rate = 3000000000u,
  1419. .max_fb_rate = BCM2835_MAX_FB_RATE),
  1420. [BCM2835_PLLB_ARM] = REGISTER_PLL_DIV(
  1421. .name = "pllb_arm",
  1422. .source_pll = "pllb",
  1423. .cm_reg = CM_PLLB,
  1424. .a2w_reg = A2W_PLLB_ARM,
  1425. .load_mask = CM_PLLB_LOADARM,
  1426. .hold_mask = CM_PLLB_HOLDARM,
  1427. .fixed_divider = 1,
  1428. .flags = CLK_SET_RATE_PARENT),
  1429. /*
  1430. * PLLC is the core PLL, used to drive the core VPU clock.
  1431. *
  1432. * It is in the PX LDO power domain, which is on when the
  1433. * AUDIO domain is on.
  1434. */
  1435. [BCM2835_PLLC] = REGISTER_PLL(
  1436. .name = "pllc",
  1437. .cm_ctrl_reg = CM_PLLC,
  1438. .a2w_ctrl_reg = A2W_PLLC_CTRL,
  1439. .frac_reg = A2W_PLLC_FRAC,
  1440. .ana_reg_base = A2W_PLLC_ANA0,
  1441. .reference_enable_mask = A2W_XOSC_CTRL_PLLC_ENABLE,
  1442. .lock_mask = CM_LOCK_FLOCKC,
  1443. .ana = &bcm2835_ana_default,
  1444. .min_rate = 600000000u,
  1445. .max_rate = 3000000000u,
  1446. .max_fb_rate = BCM2835_MAX_FB_RATE),
  1447. [BCM2835_PLLC_CORE0] = REGISTER_PLL_DIV(
  1448. .name = "pllc_core0",
  1449. .source_pll = "pllc",
  1450. .cm_reg = CM_PLLC,
  1451. .a2w_reg = A2W_PLLC_CORE0,
  1452. .load_mask = CM_PLLC_LOADCORE0,
  1453. .hold_mask = CM_PLLC_HOLDCORE0,
  1454. .fixed_divider = 1,
  1455. .flags = CLK_SET_RATE_PARENT),
  1456. [BCM2835_PLLC_CORE1] = REGISTER_PLL_DIV(
  1457. .name = "pllc_core1",
  1458. .source_pll = "pllc",
  1459. .cm_reg = CM_PLLC,
  1460. .a2w_reg = A2W_PLLC_CORE1,
  1461. .load_mask = CM_PLLC_LOADCORE1,
  1462. .hold_mask = CM_PLLC_HOLDCORE1,
  1463. .fixed_divider = 1,
  1464. .flags = CLK_SET_RATE_PARENT),
  1465. [BCM2835_PLLC_CORE2] = REGISTER_PLL_DIV(
  1466. .name = "pllc_core2",
  1467. .source_pll = "pllc",
  1468. .cm_reg = CM_PLLC,
  1469. .a2w_reg = A2W_PLLC_CORE2,
  1470. .load_mask = CM_PLLC_LOADCORE2,
  1471. .hold_mask = CM_PLLC_HOLDCORE2,
  1472. .fixed_divider = 1,
  1473. .flags = CLK_SET_RATE_PARENT),
  1474. [BCM2835_PLLC_PER] = REGISTER_PLL_DIV(
  1475. .name = "pllc_per",
  1476. .source_pll = "pllc",
  1477. .cm_reg = CM_PLLC,
  1478. .a2w_reg = A2W_PLLC_PER,
  1479. .load_mask = CM_PLLC_LOADPER,
  1480. .hold_mask = CM_PLLC_HOLDPER,
  1481. .fixed_divider = 1,
  1482. .flags = CLK_SET_RATE_PARENT),
  1483. /*
  1484. * PLLD is the display PLL, used to drive DSI display panels.
  1485. *
  1486. * It is in the PX LDO power domain, which is on when the
  1487. * AUDIO domain is on.
  1488. */
  1489. [BCM2835_PLLD] = REGISTER_PLL(
  1490. .name = "plld",
  1491. .cm_ctrl_reg = CM_PLLD,
  1492. .a2w_ctrl_reg = A2W_PLLD_CTRL,
  1493. .frac_reg = A2W_PLLD_FRAC,
  1494. .ana_reg_base = A2W_PLLD_ANA0,
  1495. .reference_enable_mask = A2W_XOSC_CTRL_DDR_ENABLE,
  1496. .lock_mask = CM_LOCK_FLOCKD,
  1497. .ana = &bcm2835_ana_default,
  1498. .min_rate = 600000000u,
  1499. .max_rate = 2400000000u,
  1500. .max_fb_rate = BCM2835_MAX_FB_RATE),
  1501. [BCM2835_PLLD_CORE] = REGISTER_PLL_DIV(
  1502. .name = "plld_core",
  1503. .source_pll = "plld",
  1504. .cm_reg = CM_PLLD,
  1505. .a2w_reg = A2W_PLLD_CORE,
  1506. .load_mask = CM_PLLD_LOADCORE,
  1507. .hold_mask = CM_PLLD_HOLDCORE,
  1508. .fixed_divider = 1,
  1509. .flags = CLK_SET_RATE_PARENT),
  1510. [BCM2835_PLLD_PER] = REGISTER_PLL_DIV(
  1511. .name = "plld_per",
  1512. .source_pll = "plld",
  1513. .cm_reg = CM_PLLD,
  1514. .a2w_reg = A2W_PLLD_PER,
  1515. .load_mask = CM_PLLD_LOADPER,
  1516. .hold_mask = CM_PLLD_HOLDPER,
  1517. .fixed_divider = 1,
  1518. .flags = CLK_SET_RATE_PARENT),
  1519. [BCM2835_PLLD_DSI0] = REGISTER_PLL_DIV(
  1520. .name = "plld_dsi0",
  1521. .source_pll = "plld",
  1522. .cm_reg = CM_PLLD,
  1523. .a2w_reg = A2W_PLLD_DSI0,
  1524. .load_mask = CM_PLLD_LOADDSI0,
  1525. .hold_mask = CM_PLLD_HOLDDSI0,
  1526. .fixed_divider = 1),
  1527. [BCM2835_PLLD_DSI1] = REGISTER_PLL_DIV(
  1528. .name = "plld_dsi1",
  1529. .source_pll = "plld",
  1530. .cm_reg = CM_PLLD,
  1531. .a2w_reg = A2W_PLLD_DSI1,
  1532. .load_mask = CM_PLLD_LOADDSI1,
  1533. .hold_mask = CM_PLLD_HOLDDSI1,
  1534. .fixed_divider = 1),
  1535. /*
  1536. * PLLH is used to supply the pixel clock or the AUX clock for the
  1537. * TV encoder.
  1538. *
  1539. * It is in the HDMI power domain.
  1540. */
  1541. [BCM2835_PLLH] = REGISTER_PLL(
  1542. "pllh",
  1543. .cm_ctrl_reg = CM_PLLH,
  1544. .a2w_ctrl_reg = A2W_PLLH_CTRL,
  1545. .frac_reg = A2W_PLLH_FRAC,
  1546. .ana_reg_base = A2W_PLLH_ANA0,
  1547. .reference_enable_mask = A2W_XOSC_CTRL_PLLC_ENABLE,
  1548. .lock_mask = CM_LOCK_FLOCKH,
  1549. .ana = &bcm2835_ana_pllh,
  1550. .min_rate = 600000000u,
  1551. .max_rate = 3000000000u,
  1552. .max_fb_rate = BCM2835_MAX_FB_RATE),
  1553. [BCM2835_PLLH_RCAL] = REGISTER_PLL_DIV(
  1554. .name = "pllh_rcal",
  1555. .source_pll = "pllh",
  1556. .cm_reg = CM_PLLH,
  1557. .a2w_reg = A2W_PLLH_RCAL,
  1558. .load_mask = CM_PLLH_LOADRCAL,
  1559. .hold_mask = 0,
  1560. .fixed_divider = 10,
  1561. .flags = CLK_SET_RATE_PARENT),
  1562. [BCM2835_PLLH_AUX] = REGISTER_PLL_DIV(
  1563. .name = "pllh_aux",
  1564. .source_pll = "pllh",
  1565. .cm_reg = CM_PLLH,
  1566. .a2w_reg = A2W_PLLH_AUX,
  1567. .load_mask = CM_PLLH_LOADAUX,
  1568. .hold_mask = 0,
  1569. .fixed_divider = 1,
  1570. .flags = CLK_SET_RATE_PARENT),
  1571. [BCM2835_PLLH_PIX] = REGISTER_PLL_DIV(
  1572. .name = "pllh_pix",
  1573. .source_pll = "pllh",
  1574. .cm_reg = CM_PLLH,
  1575. .a2w_reg = A2W_PLLH_PIX,
  1576. .load_mask = CM_PLLH_LOADPIX,
  1577. .hold_mask = 0,
  1578. .fixed_divider = 10,
  1579. .flags = CLK_SET_RATE_PARENT),
  1580. /* the clocks */
  1581. /* clocks with oscillator parent mux */
  1582. /* One Time Programmable Memory clock. Maximum 10Mhz. */
  1583. [BCM2835_CLOCK_OTP] = REGISTER_OSC_CLK(
  1584. .name = "otp",
  1585. .ctl_reg = CM_OTPCTL,
  1586. .div_reg = CM_OTPDIV,
  1587. .int_bits = 4,
  1588. .frac_bits = 0,
  1589. .tcnt_mux = 6),
  1590. /*
  1591. * Used for a 1Mhz clock for the system clocksource, and also used
  1592. * bythe watchdog timer and the camera pulse generator.
  1593. */
  1594. [BCM2835_CLOCK_TIMER] = REGISTER_OSC_CLK(
  1595. .name = "timer",
  1596. .ctl_reg = CM_TIMERCTL,
  1597. .div_reg = CM_TIMERDIV,
  1598. .int_bits = 6,
  1599. .frac_bits = 12),
  1600. /*
  1601. * Clock for the temperature sensor.
  1602. * Generally run at 2Mhz, max 5Mhz.
  1603. */
  1604. [BCM2835_CLOCK_TSENS] = REGISTER_OSC_CLK(
  1605. .name = "tsens",
  1606. .ctl_reg = CM_TSENSCTL,
  1607. .div_reg = CM_TSENSDIV,
  1608. .int_bits = 5,
  1609. .frac_bits = 0),
  1610. [BCM2835_CLOCK_TEC] = REGISTER_OSC_CLK(
  1611. .name = "tec",
  1612. .ctl_reg = CM_TECCTL,
  1613. .div_reg = CM_TECDIV,
  1614. .int_bits = 6,
  1615. .frac_bits = 0),
  1616. /* clocks with vpu parent mux */
  1617. [BCM2835_CLOCK_H264] = REGISTER_VPU_CLK(
  1618. .name = "h264",
  1619. .ctl_reg = CM_H264CTL,
  1620. .div_reg = CM_H264DIV,
  1621. .int_bits = 4,
  1622. .frac_bits = 8,
  1623. .tcnt_mux = 1),
  1624. [BCM2835_CLOCK_ISP] = REGISTER_VPU_CLK(
  1625. .name = "isp",
  1626. .ctl_reg = CM_ISPCTL,
  1627. .div_reg = CM_ISPDIV,
  1628. .int_bits = 4,
  1629. .frac_bits = 8,
  1630. .tcnt_mux = 2),
  1631. /*
  1632. * Secondary SDRAM clock. Used for low-voltage modes when the PLL
  1633. * in the SDRAM controller can't be used.
  1634. */
  1635. [BCM2835_CLOCK_SDRAM] = REGISTER_VPU_CLK(
  1636. .name = "sdram",
  1637. .ctl_reg = CM_SDCCTL,
  1638. .div_reg = CM_SDCDIV,
  1639. .int_bits = 6,
  1640. .frac_bits = 0,
  1641. .tcnt_mux = 3),
  1642. [BCM2835_CLOCK_V3D] = REGISTER_VPU_CLK(
  1643. .name = "v3d",
  1644. .ctl_reg = CM_V3DCTL,
  1645. .div_reg = CM_V3DDIV,
  1646. .int_bits = 4,
  1647. .frac_bits = 8,
  1648. .tcnt_mux = 4),
  1649. /*
  1650. * VPU clock. This doesn't have an enable bit, since it drives
  1651. * the bus for everything else, and is special so it doesn't need
  1652. * to be gated for rate changes. It is also known as "clk_audio"
  1653. * in various hardware documentation.
  1654. */
  1655. [BCM2835_CLOCK_VPU] = REGISTER_VPU_CLK(
  1656. .name = "vpu",
  1657. .ctl_reg = CM_VPUCTL,
  1658. .div_reg = CM_VPUDIV,
  1659. .int_bits = 12,
  1660. .frac_bits = 8,
  1661. .flags = CLK_IS_CRITICAL,
  1662. .is_vpu_clock = true,
  1663. .tcnt_mux = 5),
  1664. /* clocks with per parent mux */
  1665. [BCM2835_CLOCK_AVEO] = REGISTER_PER_CLK(
  1666. .name = "aveo",
  1667. .ctl_reg = CM_AVEOCTL,
  1668. .div_reg = CM_AVEODIV,
  1669. .int_bits = 4,
  1670. .frac_bits = 0,
  1671. .tcnt_mux = 38),
  1672. [BCM2835_CLOCK_CAM0] = REGISTER_PER_CLK(
  1673. .name = "cam0",
  1674. .ctl_reg = CM_CAM0CTL,
  1675. .div_reg = CM_CAM0DIV,
  1676. .int_bits = 4,
  1677. .frac_bits = 8,
  1678. .tcnt_mux = 14),
  1679. [BCM2835_CLOCK_CAM1] = REGISTER_PER_CLK(
  1680. .name = "cam1",
  1681. .ctl_reg = CM_CAM1CTL,
  1682. .div_reg = CM_CAM1DIV,
  1683. .int_bits = 4,
  1684. .frac_bits = 8,
  1685. .tcnt_mux = 15),
  1686. [BCM2835_CLOCK_DFT] = REGISTER_PER_CLK(
  1687. .name = "dft",
  1688. .ctl_reg = CM_DFTCTL,
  1689. .div_reg = CM_DFTDIV,
  1690. .int_bits = 5,
  1691. .frac_bits = 0),
  1692. [BCM2835_CLOCK_DPI] = REGISTER_PER_CLK(
  1693. .name = "dpi",
  1694. .ctl_reg = CM_DPICTL,
  1695. .div_reg = CM_DPIDIV,
  1696. .int_bits = 4,
  1697. .frac_bits = 8,
  1698. .tcnt_mux = 17),
  1699. /* Arasan EMMC clock */
  1700. [BCM2835_CLOCK_EMMC] = REGISTER_PER_CLK(
  1701. .name = "emmc",
  1702. .ctl_reg = CM_EMMCCTL,
  1703. .div_reg = CM_EMMCDIV,
  1704. .int_bits = 4,
  1705. .frac_bits = 8,
  1706. .tcnt_mux = 39),
  1707. /* General purpose (GPIO) clocks */
  1708. [BCM2835_CLOCK_GP0] = REGISTER_PER_CLK(
  1709. .name = "gp0",
  1710. .ctl_reg = CM_GP0CTL,
  1711. .div_reg = CM_GP0DIV,
  1712. .int_bits = 12,
  1713. .frac_bits = 12,
  1714. .is_mash_clock = true,
  1715. .tcnt_mux = 20),
  1716. [BCM2835_CLOCK_GP1] = REGISTER_PER_CLK(
  1717. .name = "gp1",
  1718. .ctl_reg = CM_GP1CTL,
  1719. .div_reg = CM_GP1DIV,
  1720. .int_bits = 12,
  1721. .frac_bits = 12,
  1722. .flags = CLK_IS_CRITICAL,
  1723. .is_mash_clock = true,
  1724. .tcnt_mux = 21),
  1725. [BCM2835_CLOCK_GP2] = REGISTER_PER_CLK(
  1726. .name = "gp2",
  1727. .ctl_reg = CM_GP2CTL,
  1728. .div_reg = CM_GP2DIV,
  1729. .int_bits = 12,
  1730. .frac_bits = 12,
  1731. .flags = CLK_IS_CRITICAL),
  1732. /* HDMI state machine */
  1733. [BCM2835_CLOCK_HSM] = REGISTER_PER_CLK(
  1734. .name = "hsm",
  1735. .ctl_reg = CM_HSMCTL,
  1736. .div_reg = CM_HSMDIV,
  1737. .int_bits = 4,
  1738. .frac_bits = 8,
  1739. .tcnt_mux = 22),
  1740. [BCM2835_CLOCK_PCM] = REGISTER_PCM_CLK(
  1741. .name = "pcm",
  1742. .ctl_reg = CM_PCMCTL,
  1743. .div_reg = CM_PCMDIV,
  1744. .int_bits = 12,
  1745. .frac_bits = 12,
  1746. .is_mash_clock = true,
  1747. .low_jitter = true,
  1748. .tcnt_mux = 23),
  1749. [BCM2835_CLOCK_PWM] = REGISTER_PER_CLK(
  1750. .name = "pwm",
  1751. .ctl_reg = CM_PWMCTL,
  1752. .div_reg = CM_PWMDIV,
  1753. .int_bits = 12,
  1754. .frac_bits = 12,
  1755. .is_mash_clock = true,
  1756. .tcnt_mux = 24),
  1757. [BCM2835_CLOCK_SLIM] = REGISTER_PER_CLK(
  1758. .name = "slim",
  1759. .ctl_reg = CM_SLIMCTL,
  1760. .div_reg = CM_SLIMDIV,
  1761. .int_bits = 12,
  1762. .frac_bits = 12,
  1763. .is_mash_clock = true,
  1764. .tcnt_mux = 25),
  1765. [BCM2835_CLOCK_SMI] = REGISTER_PER_CLK(
  1766. .name = "smi",
  1767. .ctl_reg = CM_SMICTL,
  1768. .div_reg = CM_SMIDIV,
  1769. .int_bits = 4,
  1770. .frac_bits = 8,
  1771. .tcnt_mux = 27),
  1772. [BCM2835_CLOCK_UART] = REGISTER_PER_CLK(
  1773. .name = "uart",
  1774. .ctl_reg = CM_UARTCTL,
  1775. .div_reg = CM_UARTDIV,
  1776. .int_bits = 10,
  1777. .frac_bits = 12,
  1778. .tcnt_mux = 28),
  1779. /* TV encoder clock. Only operating frequency is 108Mhz. */
  1780. [BCM2835_CLOCK_VEC] = REGISTER_PER_CLK(
  1781. .name = "vec",
  1782. .ctl_reg = CM_VECCTL,
  1783. .div_reg = CM_VECDIV,
  1784. .int_bits = 4,
  1785. .frac_bits = 0,
  1786. /*
  1787. * Allow rate change propagation only on PLLH_AUX which is
  1788. * assigned index 7 in the parent array.
  1789. */
  1790. .set_rate_parent = BIT(7),
  1791. .tcnt_mux = 29),
  1792. /* dsi clocks */
  1793. [BCM2835_CLOCK_DSI0E] = REGISTER_PER_CLK(
  1794. .name = "dsi0e",
  1795. .ctl_reg = CM_DSI0ECTL,
  1796. .div_reg = CM_DSI0EDIV,
  1797. .int_bits = 4,
  1798. .frac_bits = 8,
  1799. .tcnt_mux = 18),
  1800. [BCM2835_CLOCK_DSI1E] = REGISTER_PER_CLK(
  1801. .name = "dsi1e",
  1802. .ctl_reg = CM_DSI1ECTL,
  1803. .div_reg = CM_DSI1EDIV,
  1804. .int_bits = 4,
  1805. .frac_bits = 8,
  1806. .tcnt_mux = 19),
  1807. [BCM2835_CLOCK_DSI0P] = REGISTER_DSI0_CLK(
  1808. .name = "dsi0p",
  1809. .ctl_reg = CM_DSI0PCTL,
  1810. .div_reg = CM_DSI0PDIV,
  1811. .int_bits = 0,
  1812. .frac_bits = 0,
  1813. .tcnt_mux = 12),
  1814. [BCM2835_CLOCK_DSI1P] = REGISTER_DSI1_CLK(
  1815. .name = "dsi1p",
  1816. .ctl_reg = CM_DSI1PCTL,
  1817. .div_reg = CM_DSI1PDIV,
  1818. .int_bits = 0,
  1819. .frac_bits = 0,
  1820. .tcnt_mux = 13),
  1821. /* the gates */
  1822. /*
  1823. * CM_PERIICTL (and CM_PERIACTL, CM_SYSCTL and CM_VPUCTL if
  1824. * you have the debug bit set in the power manager, which we
  1825. * don't bother exposing) are individual gates off of the
  1826. * non-stop vpu clock.
  1827. */
  1828. [BCM2835_CLOCK_PERI_IMAGE] = REGISTER_GATE(
  1829. .name = "peri_image",
  1830. .parent = "vpu",
  1831. .ctl_reg = CM_PERIICTL),
  1832. };
  1833. /*
  1834. * Permanently take a reference on the parent of the SDRAM clock.
  1835. *
  1836. * While the SDRAM is being driven by its dedicated PLL most of the
  1837. * time, there is a little loop running in the firmware that
  1838. * periodically switches the SDRAM to using our CM clock to do PVT
  1839. * recalibration, with the assumption that the previously configured
  1840. * SDRAM parent is still enabled and running.
  1841. */
  1842. static int bcm2835_mark_sdc_parent_critical(struct clk *sdc)
  1843. {
  1844. struct clk *parent = clk_get_parent(sdc);
  1845. if (IS_ERR(parent))
  1846. return PTR_ERR(parent);
  1847. return clk_prepare_enable(parent);
  1848. }
  1849. static int bcm2835_clk_probe(struct platform_device *pdev)
  1850. {
  1851. struct device *dev = &pdev->dev;
  1852. struct clk_hw **hws;
  1853. struct bcm2835_cprman *cprman;
  1854. struct resource *res;
  1855. const struct bcm2835_clk_desc *desc;
  1856. const size_t asize = ARRAY_SIZE(clk_desc_array);
  1857. size_t i;
  1858. int ret;
  1859. cprman = devm_kzalloc(dev,
  1860. struct_size(cprman, onecell.hws, asize),
  1861. GFP_KERNEL);
  1862. if (!cprman)
  1863. return -ENOMEM;
  1864. spin_lock_init(&cprman->regs_lock);
  1865. cprman->dev = dev;
  1866. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1867. cprman->regs = devm_ioremap_resource(dev, res);
  1868. if (IS_ERR(cprman->regs))
  1869. return PTR_ERR(cprman->regs);
  1870. memcpy(cprman->real_parent_names, cprman_parent_names,
  1871. sizeof(cprman_parent_names));
  1872. of_clk_parent_fill(dev->of_node, cprman->real_parent_names,
  1873. ARRAY_SIZE(cprman_parent_names));
  1874. /*
  1875. * Make sure the external oscillator has been registered.
  1876. *
  1877. * The other (DSI) clocks are not present on older device
  1878. * trees, which we still need to support for backwards
  1879. * compatibility.
  1880. */
  1881. if (!cprman->real_parent_names[0])
  1882. return -ENODEV;
  1883. platform_set_drvdata(pdev, cprman);
  1884. cprman->onecell.num = asize;
  1885. hws = cprman->onecell.hws;
  1886. for (i = 0; i < asize; i++) {
  1887. desc = &clk_desc_array[i];
  1888. if (desc->clk_register && desc->data)
  1889. hws[i] = desc->clk_register(cprman, desc->data);
  1890. }
  1891. ret = bcm2835_mark_sdc_parent_critical(hws[BCM2835_CLOCK_SDRAM]->clk);
  1892. if (ret)
  1893. return ret;
  1894. return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
  1895. &cprman->onecell);
  1896. }
  1897. static const struct of_device_id bcm2835_clk_of_match[] = {
  1898. { .compatible = "brcm,bcm2835-cprman", },
  1899. {}
  1900. };
  1901. MODULE_DEVICE_TABLE(of, bcm2835_clk_of_match);
  1902. static struct platform_driver bcm2835_clk_driver = {
  1903. .driver = {
  1904. .name = "bcm2835-clk",
  1905. .of_match_table = bcm2835_clk_of_match,
  1906. },
  1907. .probe = bcm2835_clk_probe,
  1908. };
  1909. builtin_platform_driver(bcm2835_clk_driver);
  1910. MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
  1911. MODULE_DESCRIPTION("BCM2835 clock driver");
  1912. MODULE_LICENSE("GPL v2");