clk-bcm2835.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625
  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. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. /**
  20. * DOC: BCM2835 CPRMAN (clock manager for the "audio" domain)
  21. *
  22. * The clock tree on the 2835 has several levels. There's a root
  23. * oscillator running at 19.2Mhz. After the oscillator there are 5
  24. * PLLs, roughly divided as "camera", "ARM", "core", "DSI displays",
  25. * and "HDMI displays". Those 5 PLLs each can divide their output to
  26. * produce up to 4 channels. Finally, there is the level of clocks to
  27. * be consumed by other hardware components (like "H264" or "HDMI
  28. * state machine"), which divide off of some subset of the PLL
  29. * channels.
  30. *
  31. * All of the clocks in the tree are exposed in the DT, because the DT
  32. * may want to make assignments of the final layer of clocks to the
  33. * PLL channels, and some components of the hardware will actually
  34. * skip layers of the tree (for example, the pixel clock comes
  35. * directly from the PLLH PIX channel without using a CM_*CTL clock
  36. * generator).
  37. */
  38. #include <linux/clk-provider.h>
  39. #include <linux/clkdev.h>
  40. #include <linux/clk/bcm2835.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_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_TCNTDIV 0x0c4
  97. #define CM_TECCTL 0x0c8
  98. #define CM_TECDIV 0x0cc
  99. #define CM_TD0CTL 0x0d0
  100. #define CM_TD0DIV 0x0d4
  101. #define CM_TD1CTL 0x0d8
  102. #define CM_TD1DIV 0x0dc
  103. #define CM_TSENSCTL 0x0e0
  104. #define CM_TSENSDIV 0x0e4
  105. #define CM_TIMERCTL 0x0e8
  106. #define CM_TIMERDIV 0x0ec
  107. #define CM_UARTCTL 0x0f0
  108. #define CM_UARTDIV 0x0f4
  109. #define CM_VECCTL 0x0f8
  110. #define CM_VECDIV 0x0fc
  111. #define CM_PULSECTL 0x190
  112. #define CM_PULSEDIV 0x194
  113. #define CM_SDCCTL 0x1a8
  114. #define CM_SDCDIV 0x1ac
  115. #define CM_ARMCTL 0x1b0
  116. #define CM_EMMCCTL 0x1c0
  117. #define CM_EMMCDIV 0x1c4
  118. /* General bits for the CM_*CTL regs */
  119. # define CM_ENABLE BIT(4)
  120. # define CM_KILL BIT(5)
  121. # define CM_GATE_BIT 6
  122. # define CM_GATE BIT(CM_GATE_BIT)
  123. # define CM_BUSY BIT(7)
  124. # define CM_BUSYD BIT(8)
  125. # define CM_SRC_SHIFT 0
  126. # define CM_SRC_BITS 4
  127. # define CM_SRC_MASK 0xf
  128. # define CM_SRC_GND 0
  129. # define CM_SRC_OSC 1
  130. # define CM_SRC_TESTDEBUG0 2
  131. # define CM_SRC_TESTDEBUG1 3
  132. # define CM_SRC_PLLA_CORE 4
  133. # define CM_SRC_PLLA_PER 4
  134. # define CM_SRC_PLLC_CORE0 5
  135. # define CM_SRC_PLLC_PER 5
  136. # define CM_SRC_PLLC_CORE1 8
  137. # define CM_SRC_PLLD_CORE 6
  138. # define CM_SRC_PLLD_PER 6
  139. # define CM_SRC_PLLH_AUX 7
  140. # define CM_SRC_PLLC_CORE1 8
  141. # define CM_SRC_PLLC_CORE2 9
  142. #define CM_OSCCOUNT 0x100
  143. #define CM_PLLA 0x104
  144. # define CM_PLL_ANARST BIT(8)
  145. # define CM_PLLA_HOLDPER BIT(7)
  146. # define CM_PLLA_LOADPER BIT(6)
  147. # define CM_PLLA_HOLDCORE BIT(5)
  148. # define CM_PLLA_LOADCORE BIT(4)
  149. # define CM_PLLA_HOLDCCP2 BIT(3)
  150. # define CM_PLLA_LOADCCP2 BIT(2)
  151. # define CM_PLLA_HOLDDSI0 BIT(1)
  152. # define CM_PLLA_LOADDSI0 BIT(0)
  153. #define CM_PLLC 0x108
  154. # define CM_PLLC_HOLDPER BIT(7)
  155. # define CM_PLLC_LOADPER BIT(6)
  156. # define CM_PLLC_HOLDCORE2 BIT(5)
  157. # define CM_PLLC_LOADCORE2 BIT(4)
  158. # define CM_PLLC_HOLDCORE1 BIT(3)
  159. # define CM_PLLC_LOADCORE1 BIT(2)
  160. # define CM_PLLC_HOLDCORE0 BIT(1)
  161. # define CM_PLLC_LOADCORE0 BIT(0)
  162. #define CM_PLLD 0x10c
  163. # define CM_PLLD_HOLDPER BIT(7)
  164. # define CM_PLLD_LOADPER BIT(6)
  165. # define CM_PLLD_HOLDCORE BIT(5)
  166. # define CM_PLLD_LOADCORE BIT(4)
  167. # define CM_PLLD_HOLDDSI1 BIT(3)
  168. # define CM_PLLD_LOADDSI1 BIT(2)
  169. # define CM_PLLD_HOLDDSI0 BIT(1)
  170. # define CM_PLLD_LOADDSI0 BIT(0)
  171. #define CM_PLLH 0x110
  172. # define CM_PLLH_LOADRCAL BIT(2)
  173. # define CM_PLLH_LOADAUX BIT(1)
  174. # define CM_PLLH_LOADPIX BIT(0)
  175. #define CM_LOCK 0x114
  176. # define CM_LOCK_FLOCKH BIT(12)
  177. # define CM_LOCK_FLOCKD BIT(11)
  178. # define CM_LOCK_FLOCKC BIT(10)
  179. # define CM_LOCK_FLOCKB BIT(9)
  180. # define CM_LOCK_FLOCKA BIT(8)
  181. #define CM_EVENT 0x118
  182. #define CM_DSI1ECTL 0x158
  183. #define CM_DSI1EDIV 0x15c
  184. #define CM_DSI1PCTL 0x160
  185. #define CM_DSI1PDIV 0x164
  186. #define CM_DFTCTL 0x168
  187. #define CM_DFTDIV 0x16c
  188. #define CM_PLLB 0x170
  189. # define CM_PLLB_HOLDARM BIT(1)
  190. # define CM_PLLB_LOADARM BIT(0)
  191. #define A2W_PLLA_CTRL 0x1100
  192. #define A2W_PLLC_CTRL 0x1120
  193. #define A2W_PLLD_CTRL 0x1140
  194. #define A2W_PLLH_CTRL 0x1160
  195. #define A2W_PLLB_CTRL 0x11e0
  196. # define A2W_PLL_CTRL_PRST_DISABLE BIT(17)
  197. # define A2W_PLL_CTRL_PWRDN BIT(16)
  198. # define A2W_PLL_CTRL_PDIV_MASK 0x000007000
  199. # define A2W_PLL_CTRL_PDIV_SHIFT 12
  200. # define A2W_PLL_CTRL_NDIV_MASK 0x0000003ff
  201. # define A2W_PLL_CTRL_NDIV_SHIFT 0
  202. #define A2W_PLLA_ANA0 0x1010
  203. #define A2W_PLLC_ANA0 0x1030
  204. #define A2W_PLLD_ANA0 0x1050
  205. #define A2W_PLLH_ANA0 0x1070
  206. #define A2W_PLLB_ANA0 0x10f0
  207. #define A2W_PLL_KA_SHIFT 7
  208. #define A2W_PLL_KA_MASK GENMASK(9, 7)
  209. #define A2W_PLL_KI_SHIFT 19
  210. #define A2W_PLL_KI_MASK GENMASK(21, 19)
  211. #define A2W_PLL_KP_SHIFT 15
  212. #define A2W_PLL_KP_MASK GENMASK(18, 15)
  213. #define A2W_PLLH_KA_SHIFT 19
  214. #define A2W_PLLH_KA_MASK GENMASK(21, 19)
  215. #define A2W_PLLH_KI_LOW_SHIFT 22
  216. #define A2W_PLLH_KI_LOW_MASK GENMASK(23, 22)
  217. #define A2W_PLLH_KI_HIGH_SHIFT 0
  218. #define A2W_PLLH_KI_HIGH_MASK GENMASK(0, 0)
  219. #define A2W_PLLH_KP_SHIFT 1
  220. #define A2W_PLLH_KP_MASK GENMASK(4, 1)
  221. #define A2W_XOSC_CTRL 0x1190
  222. # define A2W_XOSC_CTRL_PLLB_ENABLE BIT(7)
  223. # define A2W_XOSC_CTRL_PLLA_ENABLE BIT(6)
  224. # define A2W_XOSC_CTRL_PLLD_ENABLE BIT(5)
  225. # define A2W_XOSC_CTRL_DDR_ENABLE BIT(4)
  226. # define A2W_XOSC_CTRL_CPR1_ENABLE BIT(3)
  227. # define A2W_XOSC_CTRL_USB_ENABLE BIT(2)
  228. # define A2W_XOSC_CTRL_HDMI_ENABLE BIT(1)
  229. # define A2W_XOSC_CTRL_PLLC_ENABLE BIT(0)
  230. #define A2W_PLLA_FRAC 0x1200
  231. #define A2W_PLLC_FRAC 0x1220
  232. #define A2W_PLLD_FRAC 0x1240
  233. #define A2W_PLLH_FRAC 0x1260
  234. #define A2W_PLLB_FRAC 0x12e0
  235. # define A2W_PLL_FRAC_MASK ((1 << A2W_PLL_FRAC_BITS) - 1)
  236. # define A2W_PLL_FRAC_BITS 20
  237. #define A2W_PLL_CHANNEL_DISABLE BIT(8)
  238. #define A2W_PLL_DIV_BITS 8
  239. #define A2W_PLL_DIV_SHIFT 0
  240. #define A2W_PLLA_DSI0 0x1300
  241. #define A2W_PLLA_CORE 0x1400
  242. #define A2W_PLLA_PER 0x1500
  243. #define A2W_PLLA_CCP2 0x1600
  244. #define A2W_PLLC_CORE2 0x1320
  245. #define A2W_PLLC_CORE1 0x1420
  246. #define A2W_PLLC_PER 0x1520
  247. #define A2W_PLLC_CORE0 0x1620
  248. #define A2W_PLLD_DSI0 0x1340
  249. #define A2W_PLLD_CORE 0x1440
  250. #define A2W_PLLD_PER 0x1540
  251. #define A2W_PLLD_DSI1 0x1640
  252. #define A2W_PLLH_AUX 0x1360
  253. #define A2W_PLLH_RCAL 0x1460
  254. #define A2W_PLLH_PIX 0x1560
  255. #define A2W_PLLH_STS 0x1660
  256. #define A2W_PLLH_CTRLR 0x1960
  257. #define A2W_PLLH_FRACR 0x1a60
  258. #define A2W_PLLH_AUXR 0x1b60
  259. #define A2W_PLLH_RCALR 0x1c60
  260. #define A2W_PLLH_PIXR 0x1d60
  261. #define A2W_PLLH_STSR 0x1e60
  262. #define A2W_PLLB_ARM 0x13e0
  263. #define A2W_PLLB_SP0 0x14e0
  264. #define A2W_PLLB_SP1 0x15e0
  265. #define A2W_PLLB_SP2 0x16e0
  266. #define LOCK_TIMEOUT_NS 100000000
  267. #define BCM2835_MAX_FB_RATE 1750000000u
  268. struct bcm2835_cprman {
  269. struct device *dev;
  270. void __iomem *regs;
  271. spinlock_t regs_lock;
  272. const char *osc_name;
  273. struct clk_onecell_data onecell;
  274. struct clk *clks[BCM2835_CLOCK_COUNT];
  275. };
  276. static inline void cprman_write(struct bcm2835_cprman *cprman, u32 reg, u32 val)
  277. {
  278. writel(CM_PASSWORD | val, cprman->regs + reg);
  279. }
  280. static inline u32 cprman_read(struct bcm2835_cprman *cprman, u32 reg)
  281. {
  282. return readl(cprman->regs + reg);
  283. }
  284. /*
  285. * These are fixed clocks. They're probably not all root clocks and it may
  286. * be possible to turn them on and off but until this is mapped out better
  287. * it's the only way they can be used.
  288. */
  289. void __init bcm2835_init_clocks(void)
  290. {
  291. struct clk *clk;
  292. int ret;
  293. clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, 0, 126000000);
  294. if (IS_ERR(clk))
  295. pr_err("apb_pclk not registered\n");
  296. clk = clk_register_fixed_rate(NULL, "uart0_pclk", NULL, 0, 3000000);
  297. if (IS_ERR(clk))
  298. pr_err("uart0_pclk not registered\n");
  299. ret = clk_register_clkdev(clk, NULL, "20201000.uart");
  300. if (ret)
  301. pr_err("uart0_pclk alias not registered\n");
  302. clk = clk_register_fixed_rate(NULL, "uart1_pclk", NULL, 0, 125000000);
  303. if (IS_ERR(clk))
  304. pr_err("uart1_pclk not registered\n");
  305. ret = clk_register_clkdev(clk, NULL, "20215000.uart");
  306. if (ret)
  307. pr_err("uart1_pclk alias not registered\n");
  308. }
  309. struct bcm2835_pll_data {
  310. const char *name;
  311. u32 cm_ctrl_reg;
  312. u32 a2w_ctrl_reg;
  313. u32 frac_reg;
  314. u32 ana_reg_base;
  315. u32 reference_enable_mask;
  316. /* Bit in CM_LOCK to indicate when the PLL has locked. */
  317. u32 lock_mask;
  318. const struct bcm2835_pll_ana_bits *ana;
  319. unsigned long min_rate;
  320. unsigned long max_rate;
  321. /*
  322. * Highest rate for the VCO before we have to use the
  323. * pre-divide-by-2.
  324. */
  325. unsigned long max_fb_rate;
  326. };
  327. struct bcm2835_pll_ana_bits {
  328. u32 mask0;
  329. u32 set0;
  330. u32 mask1;
  331. u32 set1;
  332. u32 mask3;
  333. u32 set3;
  334. u32 fb_prediv_mask;
  335. };
  336. static const struct bcm2835_pll_ana_bits bcm2835_ana_default = {
  337. .mask0 = 0,
  338. .set0 = 0,
  339. .mask1 = ~(A2W_PLL_KI_MASK | A2W_PLL_KP_MASK),
  340. .set1 = (2 << A2W_PLL_KI_SHIFT) | (8 << A2W_PLL_KP_SHIFT),
  341. .mask3 = ~A2W_PLL_KA_MASK,
  342. .set3 = (2 << A2W_PLL_KA_SHIFT),
  343. .fb_prediv_mask = BIT(14),
  344. };
  345. static const struct bcm2835_pll_ana_bits bcm2835_ana_pllh = {
  346. .mask0 = ~(A2W_PLLH_KA_MASK | A2W_PLLH_KI_LOW_MASK),
  347. .set0 = (2 << A2W_PLLH_KA_SHIFT) | (2 << A2W_PLLH_KI_LOW_SHIFT),
  348. .mask1 = ~(A2W_PLLH_KI_HIGH_MASK | A2W_PLLH_KP_MASK),
  349. .set1 = (6 << A2W_PLLH_KP_SHIFT),
  350. .mask3 = 0,
  351. .set3 = 0,
  352. .fb_prediv_mask = BIT(11),
  353. };
  354. /*
  355. * PLLA is the auxiliary PLL, used to drive the CCP2 (Compact Camera
  356. * Port 2) transmitter clock.
  357. *
  358. * It is in the PX LDO power domain, which is on when the AUDIO domain
  359. * is on.
  360. */
  361. static const struct bcm2835_pll_data bcm2835_plla_data = {
  362. .name = "plla",
  363. .cm_ctrl_reg = CM_PLLA,
  364. .a2w_ctrl_reg = A2W_PLLA_CTRL,
  365. .frac_reg = A2W_PLLA_FRAC,
  366. .ana_reg_base = A2W_PLLA_ANA0,
  367. .reference_enable_mask = A2W_XOSC_CTRL_PLLA_ENABLE,
  368. .lock_mask = CM_LOCK_FLOCKA,
  369. .ana = &bcm2835_ana_default,
  370. .min_rate = 600000000u,
  371. .max_rate = 2400000000u,
  372. .max_fb_rate = BCM2835_MAX_FB_RATE,
  373. };
  374. /* PLLB is used for the ARM's clock. */
  375. static const struct bcm2835_pll_data bcm2835_pllb_data = {
  376. .name = "pllb",
  377. .cm_ctrl_reg = CM_PLLB,
  378. .a2w_ctrl_reg = A2W_PLLB_CTRL,
  379. .frac_reg = A2W_PLLB_FRAC,
  380. .ana_reg_base = A2W_PLLB_ANA0,
  381. .reference_enable_mask = A2W_XOSC_CTRL_PLLB_ENABLE,
  382. .lock_mask = CM_LOCK_FLOCKB,
  383. .ana = &bcm2835_ana_default,
  384. .min_rate = 600000000u,
  385. .max_rate = 3000000000u,
  386. .max_fb_rate = BCM2835_MAX_FB_RATE,
  387. };
  388. /*
  389. * PLLC is the core PLL, used to drive the core VPU clock.
  390. *
  391. * It is in the PX LDO power domain, which is on when the AUDIO domain
  392. * is on.
  393. */
  394. static const struct bcm2835_pll_data bcm2835_pllc_data = {
  395. .name = "pllc",
  396. .cm_ctrl_reg = CM_PLLC,
  397. .a2w_ctrl_reg = A2W_PLLC_CTRL,
  398. .frac_reg = A2W_PLLC_FRAC,
  399. .ana_reg_base = A2W_PLLC_ANA0,
  400. .reference_enable_mask = A2W_XOSC_CTRL_PLLC_ENABLE,
  401. .lock_mask = CM_LOCK_FLOCKC,
  402. .ana = &bcm2835_ana_default,
  403. .min_rate = 600000000u,
  404. .max_rate = 3000000000u,
  405. .max_fb_rate = BCM2835_MAX_FB_RATE,
  406. };
  407. /*
  408. * PLLD is the display PLL, used to drive DSI display panels.
  409. *
  410. * It is in the PX LDO power domain, which is on when the AUDIO domain
  411. * is on.
  412. */
  413. static const struct bcm2835_pll_data bcm2835_plld_data = {
  414. .name = "plld",
  415. .cm_ctrl_reg = CM_PLLD,
  416. .a2w_ctrl_reg = A2W_PLLD_CTRL,
  417. .frac_reg = A2W_PLLD_FRAC,
  418. .ana_reg_base = A2W_PLLD_ANA0,
  419. .reference_enable_mask = A2W_XOSC_CTRL_DDR_ENABLE,
  420. .lock_mask = CM_LOCK_FLOCKD,
  421. .ana = &bcm2835_ana_default,
  422. .min_rate = 600000000u,
  423. .max_rate = 2400000000u,
  424. .max_fb_rate = BCM2835_MAX_FB_RATE,
  425. };
  426. /*
  427. * PLLH is used to supply the pixel clock or the AUX clock for the TV
  428. * encoder.
  429. *
  430. * It is in the HDMI power domain.
  431. */
  432. static const struct bcm2835_pll_data bcm2835_pllh_data = {
  433. "pllh",
  434. .cm_ctrl_reg = CM_PLLH,
  435. .a2w_ctrl_reg = A2W_PLLH_CTRL,
  436. .frac_reg = A2W_PLLH_FRAC,
  437. .ana_reg_base = A2W_PLLH_ANA0,
  438. .reference_enable_mask = A2W_XOSC_CTRL_PLLC_ENABLE,
  439. .lock_mask = CM_LOCK_FLOCKH,
  440. .ana = &bcm2835_ana_pllh,
  441. .min_rate = 600000000u,
  442. .max_rate = 3000000000u,
  443. .max_fb_rate = BCM2835_MAX_FB_RATE,
  444. };
  445. struct bcm2835_pll_divider_data {
  446. const char *name;
  447. const struct bcm2835_pll_data *source_pll;
  448. u32 cm_reg;
  449. u32 a2w_reg;
  450. u32 load_mask;
  451. u32 hold_mask;
  452. u32 fixed_divider;
  453. };
  454. static const struct bcm2835_pll_divider_data bcm2835_plla_core_data = {
  455. .name = "plla_core",
  456. .source_pll = &bcm2835_plla_data,
  457. .cm_reg = CM_PLLA,
  458. .a2w_reg = A2W_PLLA_CORE,
  459. .load_mask = CM_PLLA_LOADCORE,
  460. .hold_mask = CM_PLLA_HOLDCORE,
  461. .fixed_divider = 1,
  462. };
  463. static const struct bcm2835_pll_divider_data bcm2835_plla_per_data = {
  464. .name = "plla_per",
  465. .source_pll = &bcm2835_plla_data,
  466. .cm_reg = CM_PLLA,
  467. .a2w_reg = A2W_PLLA_PER,
  468. .load_mask = CM_PLLA_LOADPER,
  469. .hold_mask = CM_PLLA_HOLDPER,
  470. .fixed_divider = 1,
  471. };
  472. static const struct bcm2835_pll_divider_data bcm2835_pllb_arm_data = {
  473. .name = "pllb_arm",
  474. .source_pll = &bcm2835_pllb_data,
  475. .cm_reg = CM_PLLB,
  476. .a2w_reg = A2W_PLLB_ARM,
  477. .load_mask = CM_PLLB_LOADARM,
  478. .hold_mask = CM_PLLB_HOLDARM,
  479. .fixed_divider = 1,
  480. };
  481. static const struct bcm2835_pll_divider_data bcm2835_pllc_core0_data = {
  482. .name = "pllc_core0",
  483. .source_pll = &bcm2835_pllc_data,
  484. .cm_reg = CM_PLLC,
  485. .a2w_reg = A2W_PLLC_CORE0,
  486. .load_mask = CM_PLLC_LOADCORE0,
  487. .hold_mask = CM_PLLC_HOLDCORE0,
  488. .fixed_divider = 1,
  489. };
  490. static const struct bcm2835_pll_divider_data bcm2835_pllc_core1_data = {
  491. .name = "pllc_core1", .source_pll = &bcm2835_pllc_data,
  492. .cm_reg = CM_PLLC, A2W_PLLC_CORE1,
  493. .load_mask = CM_PLLC_LOADCORE1,
  494. .hold_mask = CM_PLLC_HOLDCORE1,
  495. .fixed_divider = 1,
  496. };
  497. static const struct bcm2835_pll_divider_data bcm2835_pllc_core2_data = {
  498. .name = "pllc_core2",
  499. .source_pll = &bcm2835_pllc_data,
  500. .cm_reg = CM_PLLC,
  501. .a2w_reg = A2W_PLLC_CORE2,
  502. .load_mask = CM_PLLC_LOADCORE2,
  503. .hold_mask = CM_PLLC_HOLDCORE2,
  504. .fixed_divider = 1,
  505. };
  506. static const struct bcm2835_pll_divider_data bcm2835_pllc_per_data = {
  507. .name = "pllc_per",
  508. .source_pll = &bcm2835_pllc_data,
  509. .cm_reg = CM_PLLC,
  510. .a2w_reg = A2W_PLLC_PER,
  511. .load_mask = CM_PLLC_LOADPER,
  512. .hold_mask = CM_PLLC_HOLDPER,
  513. .fixed_divider = 1,
  514. };
  515. static const struct bcm2835_pll_divider_data bcm2835_plld_core_data = {
  516. .name = "plld_core",
  517. .source_pll = &bcm2835_plld_data,
  518. .cm_reg = CM_PLLD,
  519. .a2w_reg = A2W_PLLD_CORE,
  520. .load_mask = CM_PLLD_LOADCORE,
  521. .hold_mask = CM_PLLD_HOLDCORE,
  522. .fixed_divider = 1,
  523. };
  524. static const struct bcm2835_pll_divider_data bcm2835_plld_per_data = {
  525. .name = "plld_per",
  526. .source_pll = &bcm2835_plld_data,
  527. .cm_reg = CM_PLLD,
  528. .a2w_reg = A2W_PLLD_PER,
  529. .load_mask = CM_PLLD_LOADPER,
  530. .hold_mask = CM_PLLD_HOLDPER,
  531. .fixed_divider = 1,
  532. };
  533. static const struct bcm2835_pll_divider_data bcm2835_pllh_rcal_data = {
  534. .name = "pllh_rcal",
  535. .source_pll = &bcm2835_pllh_data,
  536. .cm_reg = CM_PLLH,
  537. .a2w_reg = A2W_PLLH_RCAL,
  538. .load_mask = CM_PLLH_LOADRCAL,
  539. .hold_mask = 0,
  540. .fixed_divider = 10,
  541. };
  542. static const struct bcm2835_pll_divider_data bcm2835_pllh_aux_data = {
  543. .name = "pllh_aux",
  544. .source_pll = &bcm2835_pllh_data,
  545. .cm_reg = CM_PLLH,
  546. .a2w_reg = A2W_PLLH_AUX,
  547. .load_mask = CM_PLLH_LOADAUX,
  548. .hold_mask = 0,
  549. .fixed_divider = 10,
  550. };
  551. static const struct bcm2835_pll_divider_data bcm2835_pllh_pix_data = {
  552. .name = "pllh_pix",
  553. .source_pll = &bcm2835_pllh_data,
  554. .cm_reg = CM_PLLH,
  555. .a2w_reg = A2W_PLLH_PIX,
  556. .load_mask = CM_PLLH_LOADPIX,
  557. .hold_mask = 0,
  558. .fixed_divider = 10,
  559. };
  560. struct bcm2835_clock_data {
  561. const char *name;
  562. const char *const *parents;
  563. int num_mux_parents;
  564. u32 ctl_reg;
  565. u32 div_reg;
  566. /* Number of integer bits in the divider */
  567. u32 int_bits;
  568. /* Number of fractional bits in the divider */
  569. u32 frac_bits;
  570. bool is_vpu_clock;
  571. };
  572. static const char *const bcm2835_clock_per_parents[] = {
  573. "gnd",
  574. "xosc",
  575. "testdebug0",
  576. "testdebug1",
  577. "plla_per",
  578. "pllc_per",
  579. "plld_per",
  580. "pllh_aux",
  581. };
  582. static const char *const bcm2835_clock_vpu_parents[] = {
  583. "gnd",
  584. "xosc",
  585. "testdebug0",
  586. "testdebug1",
  587. "plla_core",
  588. "pllc_core0",
  589. "plld_core",
  590. "pllh_aux",
  591. "pllc_core1",
  592. "pllc_core2",
  593. };
  594. static const char *const bcm2835_clock_osc_parents[] = {
  595. "gnd",
  596. "xosc",
  597. "testdebug0",
  598. "testdebug1"
  599. };
  600. /*
  601. * Used for a 1Mhz clock for the system clocksource, and also used by
  602. * the watchdog timer and the camera pulse generator.
  603. */
  604. static const struct bcm2835_clock_data bcm2835_clock_timer_data = {
  605. .name = "timer",
  606. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_osc_parents),
  607. .parents = bcm2835_clock_osc_parents,
  608. .ctl_reg = CM_TIMERCTL,
  609. .div_reg = CM_TIMERDIV,
  610. .int_bits = 6,
  611. .frac_bits = 12,
  612. };
  613. /* One Time Programmable Memory clock. Maximum 10Mhz. */
  614. static const struct bcm2835_clock_data bcm2835_clock_otp_data = {
  615. .name = "otp",
  616. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_osc_parents),
  617. .parents = bcm2835_clock_osc_parents,
  618. .ctl_reg = CM_OTPCTL,
  619. .div_reg = CM_OTPDIV,
  620. .int_bits = 4,
  621. .frac_bits = 0,
  622. };
  623. /*
  624. * VPU clock. This doesn't have an enable bit, since it drives the
  625. * bus for everything else, and is special so it doesn't need to be
  626. * gated for rate changes. It is also known as "clk_audio" in various
  627. * hardware documentation.
  628. */
  629. static const struct bcm2835_clock_data bcm2835_clock_vpu_data = {
  630. .name = "vpu",
  631. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_vpu_parents),
  632. .parents = bcm2835_clock_vpu_parents,
  633. .ctl_reg = CM_VPUCTL,
  634. .div_reg = CM_VPUDIV,
  635. .int_bits = 12,
  636. .frac_bits = 8,
  637. .is_vpu_clock = true,
  638. };
  639. static const struct bcm2835_clock_data bcm2835_clock_v3d_data = {
  640. .name = "v3d",
  641. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_vpu_parents),
  642. .parents = bcm2835_clock_vpu_parents,
  643. .ctl_reg = CM_V3DCTL,
  644. .div_reg = CM_V3DDIV,
  645. .int_bits = 4,
  646. .frac_bits = 8,
  647. };
  648. static const struct bcm2835_clock_data bcm2835_clock_isp_data = {
  649. .name = "isp",
  650. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_vpu_parents),
  651. .parents = bcm2835_clock_vpu_parents,
  652. .ctl_reg = CM_ISPCTL,
  653. .div_reg = CM_ISPDIV,
  654. .int_bits = 4,
  655. .frac_bits = 8,
  656. };
  657. static const struct bcm2835_clock_data bcm2835_clock_h264_data = {
  658. .name = "h264",
  659. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_vpu_parents),
  660. .parents = bcm2835_clock_vpu_parents,
  661. .ctl_reg = CM_H264CTL,
  662. .div_reg = CM_H264DIV,
  663. .int_bits = 4,
  664. .frac_bits = 8,
  665. };
  666. /* TV encoder clock. Only operating frequency is 108Mhz. */
  667. static const struct bcm2835_clock_data bcm2835_clock_vec_data = {
  668. .name = "vec",
  669. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_per_parents),
  670. .parents = bcm2835_clock_per_parents,
  671. .ctl_reg = CM_VECCTL,
  672. .div_reg = CM_VECDIV,
  673. .int_bits = 4,
  674. .frac_bits = 0,
  675. };
  676. static const struct bcm2835_clock_data bcm2835_clock_uart_data = {
  677. .name = "uart",
  678. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_per_parents),
  679. .parents = bcm2835_clock_per_parents,
  680. .ctl_reg = CM_UARTCTL,
  681. .div_reg = CM_UARTDIV,
  682. .int_bits = 10,
  683. .frac_bits = 12,
  684. };
  685. /* HDMI state machine */
  686. static const struct bcm2835_clock_data bcm2835_clock_hsm_data = {
  687. .name = "hsm",
  688. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_per_parents),
  689. .parents = bcm2835_clock_per_parents,
  690. .ctl_reg = CM_HSMCTL,
  691. .div_reg = CM_HSMDIV,
  692. .int_bits = 4,
  693. .frac_bits = 8,
  694. };
  695. /*
  696. * Secondary SDRAM clock. Used for low-voltage modes when the PLL in
  697. * the SDRAM controller can't be used.
  698. */
  699. static const struct bcm2835_clock_data bcm2835_clock_sdram_data = {
  700. .name = "sdram",
  701. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_vpu_parents),
  702. .parents = bcm2835_clock_vpu_parents,
  703. .ctl_reg = CM_SDCCTL,
  704. .div_reg = CM_SDCDIV,
  705. .int_bits = 6,
  706. .frac_bits = 0,
  707. };
  708. /* Clock for the temperature sensor. Generally run at 2Mhz, max 5Mhz. */
  709. static const struct bcm2835_clock_data bcm2835_clock_tsens_data = {
  710. .name = "tsens",
  711. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_osc_parents),
  712. .parents = bcm2835_clock_osc_parents,
  713. .ctl_reg = CM_TSENSCTL,
  714. .div_reg = CM_TSENSDIV,
  715. .int_bits = 5,
  716. .frac_bits = 0,
  717. };
  718. /* Arasan EMMC clock */
  719. static const struct bcm2835_clock_data bcm2835_clock_emmc_data = {
  720. .name = "emmc",
  721. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_per_parents),
  722. .parents = bcm2835_clock_per_parents,
  723. .ctl_reg = CM_EMMCCTL,
  724. .div_reg = CM_EMMCDIV,
  725. .int_bits = 4,
  726. .frac_bits = 8,
  727. };
  728. static const struct bcm2835_clock_data bcm2835_clock_pwm_data = {
  729. .name = "pwm",
  730. .num_mux_parents = ARRAY_SIZE(bcm2835_clock_per_parents),
  731. .parents = bcm2835_clock_per_parents,
  732. .ctl_reg = CM_PWMCTL,
  733. .div_reg = CM_PWMDIV,
  734. .int_bits = 12,
  735. .frac_bits = 12,
  736. };
  737. struct bcm2835_pll {
  738. struct clk_hw hw;
  739. struct bcm2835_cprman *cprman;
  740. const struct bcm2835_pll_data *data;
  741. };
  742. static int bcm2835_pll_is_on(struct clk_hw *hw)
  743. {
  744. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  745. struct bcm2835_cprman *cprman = pll->cprman;
  746. const struct bcm2835_pll_data *data = pll->data;
  747. return cprman_read(cprman, data->a2w_ctrl_reg) &
  748. A2W_PLL_CTRL_PRST_DISABLE;
  749. }
  750. static void bcm2835_pll_choose_ndiv_and_fdiv(unsigned long rate,
  751. unsigned long parent_rate,
  752. u32 *ndiv, u32 *fdiv)
  753. {
  754. u64 div;
  755. div = (u64)rate << A2W_PLL_FRAC_BITS;
  756. do_div(div, parent_rate);
  757. *ndiv = div >> A2W_PLL_FRAC_BITS;
  758. *fdiv = div & ((1 << A2W_PLL_FRAC_BITS) - 1);
  759. }
  760. static long bcm2835_pll_rate_from_divisors(unsigned long parent_rate,
  761. u32 ndiv, u32 fdiv, u32 pdiv)
  762. {
  763. u64 rate;
  764. if (pdiv == 0)
  765. return 0;
  766. rate = (u64)parent_rate * ((ndiv << A2W_PLL_FRAC_BITS) + fdiv);
  767. do_div(rate, pdiv);
  768. return rate >> A2W_PLL_FRAC_BITS;
  769. }
  770. static long bcm2835_pll_round_rate(struct clk_hw *hw, unsigned long rate,
  771. unsigned long *parent_rate)
  772. {
  773. u32 ndiv, fdiv;
  774. bcm2835_pll_choose_ndiv_and_fdiv(rate, *parent_rate, &ndiv, &fdiv);
  775. return bcm2835_pll_rate_from_divisors(*parent_rate, ndiv, fdiv, 1);
  776. }
  777. static unsigned long bcm2835_pll_get_rate(struct clk_hw *hw,
  778. unsigned long parent_rate)
  779. {
  780. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  781. struct bcm2835_cprman *cprman = pll->cprman;
  782. const struct bcm2835_pll_data *data = pll->data;
  783. u32 a2wctrl = cprman_read(cprman, data->a2w_ctrl_reg);
  784. u32 ndiv, pdiv, fdiv;
  785. bool using_prediv;
  786. if (parent_rate == 0)
  787. return 0;
  788. fdiv = cprman_read(cprman, data->frac_reg) & A2W_PLL_FRAC_MASK;
  789. ndiv = (a2wctrl & A2W_PLL_CTRL_NDIV_MASK) >> A2W_PLL_CTRL_NDIV_SHIFT;
  790. pdiv = (a2wctrl & A2W_PLL_CTRL_PDIV_MASK) >> A2W_PLL_CTRL_PDIV_SHIFT;
  791. using_prediv = cprman_read(cprman, data->ana_reg_base + 4) &
  792. data->ana->fb_prediv_mask;
  793. if (using_prediv)
  794. ndiv *= 2;
  795. return bcm2835_pll_rate_from_divisors(parent_rate, ndiv, fdiv, pdiv);
  796. }
  797. static void bcm2835_pll_off(struct clk_hw *hw)
  798. {
  799. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  800. struct bcm2835_cprman *cprman = pll->cprman;
  801. const struct bcm2835_pll_data *data = pll->data;
  802. cprman_write(cprman, data->cm_ctrl_reg, CM_PLL_ANARST);
  803. cprman_write(cprman, data->a2w_ctrl_reg, A2W_PLL_CTRL_PWRDN);
  804. }
  805. static int bcm2835_pll_on(struct clk_hw *hw)
  806. {
  807. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  808. struct bcm2835_cprman *cprman = pll->cprman;
  809. const struct bcm2835_pll_data *data = pll->data;
  810. ktime_t timeout;
  811. /* Take the PLL out of reset. */
  812. cprman_write(cprman, data->cm_ctrl_reg,
  813. cprman_read(cprman, data->cm_ctrl_reg) & ~CM_PLL_ANARST);
  814. /* Wait for the PLL to lock. */
  815. timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
  816. while (!(cprman_read(cprman, CM_LOCK) & data->lock_mask)) {
  817. if (ktime_after(ktime_get(), timeout)) {
  818. dev_err(cprman->dev, "%s: couldn't lock PLL\n",
  819. clk_hw_get_name(hw));
  820. return -ETIMEDOUT;
  821. }
  822. cpu_relax();
  823. }
  824. return 0;
  825. }
  826. static void
  827. bcm2835_pll_write_ana(struct bcm2835_cprman *cprman, u32 ana_reg_base, u32 *ana)
  828. {
  829. int i;
  830. /*
  831. * ANA register setup is done as a series of writes to
  832. * ANA3-ANA0, in that order. This lets us write all 4
  833. * registers as a single cycle of the serdes interface (taking
  834. * 100 xosc clocks), whereas if we were to update ana0, 1, and
  835. * 3 individually through their partial-write registers, each
  836. * would be their own serdes cycle.
  837. */
  838. for (i = 3; i >= 0; i--)
  839. cprman_write(cprman, ana_reg_base + i * 4, ana[i]);
  840. }
  841. static int bcm2835_pll_set_rate(struct clk_hw *hw,
  842. unsigned long rate, unsigned long parent_rate)
  843. {
  844. struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
  845. struct bcm2835_cprman *cprman = pll->cprman;
  846. const struct bcm2835_pll_data *data = pll->data;
  847. bool was_using_prediv, use_fb_prediv, do_ana_setup_first;
  848. u32 ndiv, fdiv, a2w_ctl;
  849. u32 ana[4];
  850. int i;
  851. if (rate < data->min_rate || rate > data->max_rate) {
  852. dev_err(cprman->dev, "%s: rate out of spec: %lu vs (%lu, %lu)\n",
  853. clk_hw_get_name(hw), rate,
  854. data->min_rate, data->max_rate);
  855. return -EINVAL;
  856. }
  857. if (rate > data->max_fb_rate) {
  858. use_fb_prediv = true;
  859. rate /= 2;
  860. } else {
  861. use_fb_prediv = false;
  862. }
  863. bcm2835_pll_choose_ndiv_and_fdiv(rate, parent_rate, &ndiv, &fdiv);
  864. for (i = 3; i >= 0; i--)
  865. ana[i] = cprman_read(cprman, data->ana_reg_base + i * 4);
  866. was_using_prediv = ana[1] & data->ana->fb_prediv_mask;
  867. ana[0] &= ~data->ana->mask0;
  868. ana[0] |= data->ana->set0;
  869. ana[1] &= ~data->ana->mask1;
  870. ana[1] |= data->ana->set1;
  871. ana[3] &= ~data->ana->mask3;
  872. ana[3] |= data->ana->set3;
  873. if (was_using_prediv && !use_fb_prediv) {
  874. ana[1] &= ~data->ana->fb_prediv_mask;
  875. do_ana_setup_first = true;
  876. } else if (!was_using_prediv && use_fb_prediv) {
  877. ana[1] |= data->ana->fb_prediv_mask;
  878. do_ana_setup_first = false;
  879. } else {
  880. do_ana_setup_first = true;
  881. }
  882. /* Unmask the reference clock from the oscillator. */
  883. cprman_write(cprman, A2W_XOSC_CTRL,
  884. cprman_read(cprman, A2W_XOSC_CTRL) |
  885. data->reference_enable_mask);
  886. if (do_ana_setup_first)
  887. bcm2835_pll_write_ana(cprman, data->ana_reg_base, ana);
  888. /* Set the PLL multiplier from the oscillator. */
  889. cprman_write(cprman, data->frac_reg, fdiv);
  890. a2w_ctl = cprman_read(cprman, data->a2w_ctrl_reg);
  891. a2w_ctl &= ~A2W_PLL_CTRL_NDIV_MASK;
  892. a2w_ctl |= ndiv << A2W_PLL_CTRL_NDIV_SHIFT;
  893. a2w_ctl &= ~A2W_PLL_CTRL_PDIV_MASK;
  894. a2w_ctl |= 1 << A2W_PLL_CTRL_PDIV_SHIFT;
  895. cprman_write(cprman, data->a2w_ctrl_reg, a2w_ctl);
  896. if (!do_ana_setup_first)
  897. bcm2835_pll_write_ana(cprman, data->ana_reg_base, ana);
  898. return 0;
  899. }
  900. static const struct clk_ops bcm2835_pll_clk_ops = {
  901. .is_prepared = bcm2835_pll_is_on,
  902. .prepare = bcm2835_pll_on,
  903. .unprepare = bcm2835_pll_off,
  904. .recalc_rate = bcm2835_pll_get_rate,
  905. .set_rate = bcm2835_pll_set_rate,
  906. .round_rate = bcm2835_pll_round_rate,
  907. };
  908. struct bcm2835_pll_divider {
  909. struct clk_divider div;
  910. struct bcm2835_cprman *cprman;
  911. const struct bcm2835_pll_divider_data *data;
  912. };
  913. static struct bcm2835_pll_divider *
  914. bcm2835_pll_divider_from_hw(struct clk_hw *hw)
  915. {
  916. return container_of(hw, struct bcm2835_pll_divider, div.hw);
  917. }
  918. static int bcm2835_pll_divider_is_on(struct clk_hw *hw)
  919. {
  920. struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
  921. struct bcm2835_cprman *cprman = divider->cprman;
  922. const struct bcm2835_pll_divider_data *data = divider->data;
  923. return !(cprman_read(cprman, data->a2w_reg) & A2W_PLL_CHANNEL_DISABLE);
  924. }
  925. static long bcm2835_pll_divider_round_rate(struct clk_hw *hw,
  926. unsigned long rate,
  927. unsigned long *parent_rate)
  928. {
  929. return clk_divider_ops.round_rate(hw, rate, parent_rate);
  930. }
  931. static unsigned long bcm2835_pll_divider_get_rate(struct clk_hw *hw,
  932. unsigned long parent_rate)
  933. {
  934. return clk_divider_ops.recalc_rate(hw, parent_rate);
  935. }
  936. static void bcm2835_pll_divider_off(struct clk_hw *hw)
  937. {
  938. struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
  939. struct bcm2835_cprman *cprman = divider->cprman;
  940. const struct bcm2835_pll_divider_data *data = divider->data;
  941. cprman_write(cprman, data->cm_reg,
  942. (cprman_read(cprman, data->cm_reg) &
  943. ~data->load_mask) | data->hold_mask);
  944. cprman_write(cprman, data->a2w_reg, A2W_PLL_CHANNEL_DISABLE);
  945. }
  946. static int bcm2835_pll_divider_on(struct clk_hw *hw)
  947. {
  948. struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
  949. struct bcm2835_cprman *cprman = divider->cprman;
  950. const struct bcm2835_pll_divider_data *data = divider->data;
  951. cprman_write(cprman, data->a2w_reg,
  952. cprman_read(cprman, data->a2w_reg) &
  953. ~A2W_PLL_CHANNEL_DISABLE);
  954. cprman_write(cprman, data->cm_reg,
  955. cprman_read(cprman, data->cm_reg) & ~data->hold_mask);
  956. return 0;
  957. }
  958. static int bcm2835_pll_divider_set_rate(struct clk_hw *hw,
  959. unsigned long rate,
  960. unsigned long parent_rate)
  961. {
  962. struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
  963. struct bcm2835_cprman *cprman = divider->cprman;
  964. const struct bcm2835_pll_divider_data *data = divider->data;
  965. u32 cm, div, max_div = 1 << A2W_PLL_DIV_BITS;
  966. div = DIV_ROUND_UP_ULL(parent_rate, rate);
  967. div = min(div, max_div);
  968. if (div == max_div)
  969. div = 0;
  970. cprman_write(cprman, data->a2w_reg, div);
  971. cm = cprman_read(cprman, data->cm_reg);
  972. cprman_write(cprman, data->cm_reg, cm | data->load_mask);
  973. cprman_write(cprman, data->cm_reg, cm & ~data->load_mask);
  974. return 0;
  975. }
  976. static const struct clk_ops bcm2835_pll_divider_clk_ops = {
  977. .is_prepared = bcm2835_pll_divider_is_on,
  978. .prepare = bcm2835_pll_divider_on,
  979. .unprepare = bcm2835_pll_divider_off,
  980. .recalc_rate = bcm2835_pll_divider_get_rate,
  981. .set_rate = bcm2835_pll_divider_set_rate,
  982. .round_rate = bcm2835_pll_divider_round_rate,
  983. };
  984. /*
  985. * The CM dividers do fixed-point division, so we can't use the
  986. * generic integer divider code like the PLL dividers do (and we can't
  987. * fake it by having some fixed shifts preceding it in the clock tree,
  988. * because we'd run out of bits in a 32-bit unsigned long).
  989. */
  990. struct bcm2835_clock {
  991. struct clk_hw hw;
  992. struct bcm2835_cprman *cprman;
  993. const struct bcm2835_clock_data *data;
  994. };
  995. static struct bcm2835_clock *bcm2835_clock_from_hw(struct clk_hw *hw)
  996. {
  997. return container_of(hw, struct bcm2835_clock, hw);
  998. }
  999. static int bcm2835_clock_is_on(struct clk_hw *hw)
  1000. {
  1001. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  1002. struct bcm2835_cprman *cprman = clock->cprman;
  1003. const struct bcm2835_clock_data *data = clock->data;
  1004. return (cprman_read(cprman, data->ctl_reg) & CM_ENABLE) != 0;
  1005. }
  1006. static u32 bcm2835_clock_choose_div(struct clk_hw *hw,
  1007. unsigned long rate,
  1008. unsigned long parent_rate,
  1009. bool round_up)
  1010. {
  1011. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  1012. const struct bcm2835_clock_data *data = clock->data;
  1013. u32 unused_frac_mask =
  1014. GENMASK(CM_DIV_FRAC_BITS - data->frac_bits, 0) >> 1;
  1015. u64 temp = (u64)parent_rate << CM_DIV_FRAC_BITS;
  1016. u64 rem;
  1017. u32 div;
  1018. rem = do_div(temp, rate);
  1019. div = temp;
  1020. /* Round up and mask off the unused bits */
  1021. if (round_up && ((div & unused_frac_mask) != 0 || rem != 0))
  1022. div += unused_frac_mask + 1;
  1023. div &= ~unused_frac_mask;
  1024. /* Clamp to the limits. */
  1025. div = max(div, unused_frac_mask + 1);
  1026. div = min_t(u32, div, GENMASK(data->int_bits + CM_DIV_FRAC_BITS - 1,
  1027. CM_DIV_FRAC_BITS - data->frac_bits));
  1028. return div;
  1029. }
  1030. static long bcm2835_clock_rate_from_divisor(struct bcm2835_clock *clock,
  1031. unsigned long parent_rate,
  1032. u32 div)
  1033. {
  1034. const struct bcm2835_clock_data *data = clock->data;
  1035. u64 temp;
  1036. /*
  1037. * The divisor is a 12.12 fixed point field, but only some of
  1038. * the bits are populated in any given clock.
  1039. */
  1040. div >>= CM_DIV_FRAC_BITS - data->frac_bits;
  1041. div &= (1 << (data->int_bits + data->frac_bits)) - 1;
  1042. if (div == 0)
  1043. return 0;
  1044. temp = (u64)parent_rate << data->frac_bits;
  1045. do_div(temp, div);
  1046. return temp;
  1047. }
  1048. static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw,
  1049. unsigned long parent_rate)
  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. u32 div = cprman_read(cprman, data->div_reg);
  1055. return bcm2835_clock_rate_from_divisor(clock, parent_rate, div);
  1056. }
  1057. static void bcm2835_clock_wait_busy(struct bcm2835_clock *clock)
  1058. {
  1059. struct bcm2835_cprman *cprman = clock->cprman;
  1060. const struct bcm2835_clock_data *data = clock->data;
  1061. ktime_t timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
  1062. while (cprman_read(cprman, data->ctl_reg) & CM_BUSY) {
  1063. if (ktime_after(ktime_get(), timeout)) {
  1064. dev_err(cprman->dev, "%s: couldn't lock PLL\n",
  1065. clk_hw_get_name(&clock->hw));
  1066. return;
  1067. }
  1068. cpu_relax();
  1069. }
  1070. }
  1071. static void bcm2835_clock_off(struct clk_hw *hw)
  1072. {
  1073. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  1074. struct bcm2835_cprman *cprman = clock->cprman;
  1075. const struct bcm2835_clock_data *data = clock->data;
  1076. spin_lock(&cprman->regs_lock);
  1077. cprman_write(cprman, data->ctl_reg,
  1078. cprman_read(cprman, data->ctl_reg) & ~CM_ENABLE);
  1079. spin_unlock(&cprman->regs_lock);
  1080. /* BUSY will remain high until the divider completes its cycle. */
  1081. bcm2835_clock_wait_busy(clock);
  1082. }
  1083. static int bcm2835_clock_on(struct clk_hw *hw)
  1084. {
  1085. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  1086. struct bcm2835_cprman *cprman = clock->cprman;
  1087. const struct bcm2835_clock_data *data = clock->data;
  1088. spin_lock(&cprman->regs_lock);
  1089. cprman_write(cprman, data->ctl_reg,
  1090. cprman_read(cprman, data->ctl_reg) |
  1091. CM_ENABLE |
  1092. CM_GATE);
  1093. spin_unlock(&cprman->regs_lock);
  1094. return 0;
  1095. }
  1096. static int bcm2835_clock_set_rate(struct clk_hw *hw,
  1097. unsigned long rate, unsigned long parent_rate)
  1098. {
  1099. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  1100. struct bcm2835_cprman *cprman = clock->cprman;
  1101. const struct bcm2835_clock_data *data = clock->data;
  1102. u32 div = bcm2835_clock_choose_div(hw, rate, parent_rate, false);
  1103. cprman_write(cprman, data->div_reg, div);
  1104. return 0;
  1105. }
  1106. static int bcm2835_clock_determine_rate(struct clk_hw *hw,
  1107. struct clk_rate_request *req)
  1108. {
  1109. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  1110. struct clk_hw *parent, *best_parent = NULL;
  1111. unsigned long rate, best_rate = 0;
  1112. unsigned long prate, best_prate = 0;
  1113. size_t i;
  1114. u32 div;
  1115. /*
  1116. * Select parent clock that results in the closest but lower rate
  1117. */
  1118. for (i = 0; i < clk_hw_get_num_parents(hw); ++i) {
  1119. parent = clk_hw_get_parent_by_index(hw, i);
  1120. if (!parent)
  1121. continue;
  1122. prate = clk_hw_get_rate(parent);
  1123. div = bcm2835_clock_choose_div(hw, req->rate, prate, true);
  1124. rate = bcm2835_clock_rate_from_divisor(clock, prate, div);
  1125. if (rate > best_rate && rate <= req->rate) {
  1126. best_parent = parent;
  1127. best_prate = prate;
  1128. best_rate = rate;
  1129. }
  1130. }
  1131. if (!best_parent)
  1132. return -EINVAL;
  1133. req->best_parent_hw = best_parent;
  1134. req->best_parent_rate = best_prate;
  1135. req->rate = best_rate;
  1136. return 0;
  1137. }
  1138. static int bcm2835_clock_set_parent(struct clk_hw *hw, u8 index)
  1139. {
  1140. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  1141. struct bcm2835_cprman *cprman = clock->cprman;
  1142. const struct bcm2835_clock_data *data = clock->data;
  1143. u8 src = (index << CM_SRC_SHIFT) & CM_SRC_MASK;
  1144. cprman_write(cprman, data->ctl_reg, src);
  1145. return 0;
  1146. }
  1147. static u8 bcm2835_clock_get_parent(struct clk_hw *hw)
  1148. {
  1149. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  1150. struct bcm2835_cprman *cprman = clock->cprman;
  1151. const struct bcm2835_clock_data *data = clock->data;
  1152. u32 src = cprman_read(cprman, data->ctl_reg);
  1153. return (src & CM_SRC_MASK) >> CM_SRC_SHIFT;
  1154. }
  1155. static const struct clk_ops bcm2835_clock_clk_ops = {
  1156. .is_prepared = bcm2835_clock_is_on,
  1157. .prepare = bcm2835_clock_on,
  1158. .unprepare = bcm2835_clock_off,
  1159. .recalc_rate = bcm2835_clock_get_rate,
  1160. .set_rate = bcm2835_clock_set_rate,
  1161. .determine_rate = bcm2835_clock_determine_rate,
  1162. .set_parent = bcm2835_clock_set_parent,
  1163. .get_parent = bcm2835_clock_get_parent,
  1164. };
  1165. static int bcm2835_vpu_clock_is_on(struct clk_hw *hw)
  1166. {
  1167. return true;
  1168. }
  1169. /*
  1170. * The VPU clock can never be disabled (it doesn't have an ENABLE
  1171. * bit), so it gets its own set of clock ops.
  1172. */
  1173. static const struct clk_ops bcm2835_vpu_clock_clk_ops = {
  1174. .is_prepared = bcm2835_vpu_clock_is_on,
  1175. .recalc_rate = bcm2835_clock_get_rate,
  1176. .set_rate = bcm2835_clock_set_rate,
  1177. .determine_rate = bcm2835_clock_determine_rate,
  1178. .set_parent = bcm2835_clock_set_parent,
  1179. .get_parent = bcm2835_clock_get_parent,
  1180. };
  1181. static struct clk *bcm2835_register_pll(struct bcm2835_cprman *cprman,
  1182. const struct bcm2835_pll_data *data)
  1183. {
  1184. struct bcm2835_pll *pll;
  1185. struct clk_init_data init;
  1186. memset(&init, 0, sizeof(init));
  1187. /* All of the PLLs derive from the external oscillator. */
  1188. init.parent_names = &cprman->osc_name;
  1189. init.num_parents = 1;
  1190. init.name = data->name;
  1191. init.ops = &bcm2835_pll_clk_ops;
  1192. init.flags = CLK_IGNORE_UNUSED;
  1193. pll = kzalloc(sizeof(*pll), GFP_KERNEL);
  1194. if (!pll)
  1195. return NULL;
  1196. pll->cprman = cprman;
  1197. pll->data = data;
  1198. pll->hw.init = &init;
  1199. return devm_clk_register(cprman->dev, &pll->hw);
  1200. }
  1201. static struct clk *
  1202. bcm2835_register_pll_divider(struct bcm2835_cprman *cprman,
  1203. const struct bcm2835_pll_divider_data *data)
  1204. {
  1205. struct bcm2835_pll_divider *divider;
  1206. struct clk_init_data init;
  1207. struct clk *clk;
  1208. const char *divider_name;
  1209. if (data->fixed_divider != 1) {
  1210. divider_name = devm_kasprintf(cprman->dev, GFP_KERNEL,
  1211. "%s_prediv", data->name);
  1212. if (!divider_name)
  1213. return NULL;
  1214. } else {
  1215. divider_name = data->name;
  1216. }
  1217. memset(&init, 0, sizeof(init));
  1218. init.parent_names = &data->source_pll->name;
  1219. init.num_parents = 1;
  1220. init.name = divider_name;
  1221. init.ops = &bcm2835_pll_divider_clk_ops;
  1222. init.flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED;
  1223. divider = devm_kzalloc(cprman->dev, sizeof(*divider), GFP_KERNEL);
  1224. if (!divider)
  1225. return NULL;
  1226. divider->div.reg = cprman->regs + data->a2w_reg;
  1227. divider->div.shift = A2W_PLL_DIV_SHIFT;
  1228. divider->div.width = A2W_PLL_DIV_BITS;
  1229. divider->div.flags = CLK_DIVIDER_MAX_AT_ZERO;
  1230. divider->div.lock = &cprman->regs_lock;
  1231. divider->div.hw.init = &init;
  1232. divider->div.table = NULL;
  1233. divider->cprman = cprman;
  1234. divider->data = data;
  1235. clk = devm_clk_register(cprman->dev, &divider->div.hw);
  1236. if (IS_ERR(clk))
  1237. return clk;
  1238. /*
  1239. * PLLH's channels have a fixed divide by 10 afterwards, which
  1240. * is what our consumers are actually using.
  1241. */
  1242. if (data->fixed_divider != 1) {
  1243. return clk_register_fixed_factor(cprman->dev, data->name,
  1244. divider_name,
  1245. CLK_SET_RATE_PARENT,
  1246. 1,
  1247. data->fixed_divider);
  1248. }
  1249. return clk;
  1250. }
  1251. static struct clk *bcm2835_register_clock(struct bcm2835_cprman *cprman,
  1252. const struct bcm2835_clock_data *data)
  1253. {
  1254. struct bcm2835_clock *clock;
  1255. struct clk_init_data init;
  1256. const char *parents[1 << CM_SRC_BITS];
  1257. size_t i;
  1258. /*
  1259. * Replace our "xosc" references with the oscillator's
  1260. * actual name.
  1261. */
  1262. for (i = 0; i < data->num_mux_parents; i++) {
  1263. if (strcmp(data->parents[i], "xosc") == 0)
  1264. parents[i] = cprman->osc_name;
  1265. else
  1266. parents[i] = data->parents[i];
  1267. }
  1268. memset(&init, 0, sizeof(init));
  1269. init.parent_names = parents;
  1270. init.num_parents = data->num_mux_parents;
  1271. init.name = data->name;
  1272. init.flags = CLK_IGNORE_UNUSED;
  1273. if (data->is_vpu_clock) {
  1274. init.ops = &bcm2835_vpu_clock_clk_ops;
  1275. } else {
  1276. init.ops = &bcm2835_clock_clk_ops;
  1277. init.flags |= CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE;
  1278. }
  1279. clock = devm_kzalloc(cprman->dev, sizeof(*clock), GFP_KERNEL);
  1280. if (!clock)
  1281. return NULL;
  1282. clock->cprman = cprman;
  1283. clock->data = data;
  1284. clock->hw.init = &init;
  1285. return devm_clk_register(cprman->dev, &clock->hw);
  1286. }
  1287. static int bcm2835_clk_probe(struct platform_device *pdev)
  1288. {
  1289. struct device *dev = &pdev->dev;
  1290. struct clk **clks;
  1291. struct bcm2835_cprman *cprman;
  1292. struct resource *res;
  1293. cprman = devm_kzalloc(dev, sizeof(*cprman), GFP_KERNEL);
  1294. if (!cprman)
  1295. return -ENOMEM;
  1296. spin_lock_init(&cprman->regs_lock);
  1297. cprman->dev = dev;
  1298. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1299. cprman->regs = devm_ioremap_resource(dev, res);
  1300. if (IS_ERR(cprman->regs))
  1301. return PTR_ERR(cprman->regs);
  1302. cprman->osc_name = of_clk_get_parent_name(dev->of_node, 0);
  1303. if (!cprman->osc_name)
  1304. return -ENODEV;
  1305. platform_set_drvdata(pdev, cprman);
  1306. cprman->onecell.clk_num = BCM2835_CLOCK_COUNT;
  1307. cprman->onecell.clks = cprman->clks;
  1308. clks = cprman->clks;
  1309. clks[BCM2835_PLLA] = bcm2835_register_pll(cprman, &bcm2835_plla_data);
  1310. clks[BCM2835_PLLB] = bcm2835_register_pll(cprman, &bcm2835_pllb_data);
  1311. clks[BCM2835_PLLC] = bcm2835_register_pll(cprman, &bcm2835_pllc_data);
  1312. clks[BCM2835_PLLD] = bcm2835_register_pll(cprman, &bcm2835_plld_data);
  1313. clks[BCM2835_PLLH] = bcm2835_register_pll(cprman, &bcm2835_pllh_data);
  1314. clks[BCM2835_PLLA_CORE] =
  1315. bcm2835_register_pll_divider(cprman, &bcm2835_plla_core_data);
  1316. clks[BCM2835_PLLA_PER] =
  1317. bcm2835_register_pll_divider(cprman, &bcm2835_plla_per_data);
  1318. clks[BCM2835_PLLC_CORE0] =
  1319. bcm2835_register_pll_divider(cprman, &bcm2835_pllc_core0_data);
  1320. clks[BCM2835_PLLC_CORE1] =
  1321. bcm2835_register_pll_divider(cprman, &bcm2835_pllc_core1_data);
  1322. clks[BCM2835_PLLC_CORE2] =
  1323. bcm2835_register_pll_divider(cprman, &bcm2835_pllc_core2_data);
  1324. clks[BCM2835_PLLC_PER] =
  1325. bcm2835_register_pll_divider(cprman, &bcm2835_pllc_per_data);
  1326. clks[BCM2835_PLLD_CORE] =
  1327. bcm2835_register_pll_divider(cprman, &bcm2835_plld_core_data);
  1328. clks[BCM2835_PLLD_PER] =
  1329. bcm2835_register_pll_divider(cprman, &bcm2835_plld_per_data);
  1330. clks[BCM2835_PLLH_RCAL] =
  1331. bcm2835_register_pll_divider(cprman, &bcm2835_pllh_rcal_data);
  1332. clks[BCM2835_PLLH_AUX] =
  1333. bcm2835_register_pll_divider(cprman, &bcm2835_pllh_aux_data);
  1334. clks[BCM2835_PLLH_PIX] =
  1335. bcm2835_register_pll_divider(cprman, &bcm2835_pllh_pix_data);
  1336. clks[BCM2835_CLOCK_TIMER] =
  1337. bcm2835_register_clock(cprman, &bcm2835_clock_timer_data);
  1338. clks[BCM2835_CLOCK_OTP] =
  1339. bcm2835_register_clock(cprman, &bcm2835_clock_otp_data);
  1340. clks[BCM2835_CLOCK_TSENS] =
  1341. bcm2835_register_clock(cprman, &bcm2835_clock_tsens_data);
  1342. clks[BCM2835_CLOCK_VPU] =
  1343. bcm2835_register_clock(cprman, &bcm2835_clock_vpu_data);
  1344. clks[BCM2835_CLOCK_V3D] =
  1345. bcm2835_register_clock(cprman, &bcm2835_clock_v3d_data);
  1346. clks[BCM2835_CLOCK_ISP] =
  1347. bcm2835_register_clock(cprman, &bcm2835_clock_isp_data);
  1348. clks[BCM2835_CLOCK_H264] =
  1349. bcm2835_register_clock(cprman, &bcm2835_clock_h264_data);
  1350. clks[BCM2835_CLOCK_V3D] =
  1351. bcm2835_register_clock(cprman, &bcm2835_clock_v3d_data);
  1352. clks[BCM2835_CLOCK_SDRAM] =
  1353. bcm2835_register_clock(cprman, &bcm2835_clock_sdram_data);
  1354. clks[BCM2835_CLOCK_UART] =
  1355. bcm2835_register_clock(cprman, &bcm2835_clock_uart_data);
  1356. clks[BCM2835_CLOCK_VEC] =
  1357. bcm2835_register_clock(cprman, &bcm2835_clock_vec_data);
  1358. clks[BCM2835_CLOCK_HSM] =
  1359. bcm2835_register_clock(cprman, &bcm2835_clock_hsm_data);
  1360. clks[BCM2835_CLOCK_EMMC] =
  1361. bcm2835_register_clock(cprman, &bcm2835_clock_emmc_data);
  1362. /*
  1363. * CM_PERIICTL (and CM_PERIACTL, CM_SYSCTL and CM_VPUCTL if
  1364. * you have the debug bit set in the power manager, which we
  1365. * don't bother exposing) are individual gates off of the
  1366. * non-stop vpu clock.
  1367. */
  1368. clks[BCM2835_CLOCK_PERI_IMAGE] =
  1369. clk_register_gate(dev, "peri_image", "vpu",
  1370. CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
  1371. cprman->regs + CM_PERIICTL, CM_GATE_BIT,
  1372. 0, &cprman->regs_lock);
  1373. clks[BCM2835_CLOCK_PWM] =
  1374. bcm2835_register_clock(cprman, &bcm2835_clock_pwm_data);
  1375. return of_clk_add_provider(dev->of_node, of_clk_src_onecell_get,
  1376. &cprman->onecell);
  1377. }
  1378. static const struct of_device_id bcm2835_clk_of_match[] = {
  1379. { .compatible = "brcm,bcm2835-cprman", },
  1380. {}
  1381. };
  1382. MODULE_DEVICE_TABLE(of, bcm2835_clk_of_match);
  1383. static struct platform_driver bcm2835_clk_driver = {
  1384. .driver = {
  1385. .name = "bcm2835-clk",
  1386. .of_match_table = bcm2835_clk_of_match,
  1387. },
  1388. .probe = bcm2835_clk_probe,
  1389. };
  1390. builtin_platform_driver(bcm2835_clk_driver);
  1391. MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
  1392. MODULE_DESCRIPTION("BCM2835 clock driver");
  1393. MODULE_LICENSE("GPL v2");