clk-stm32mp1.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
  4. * Author: Olivier Bideau <olivier.bideau@st.com> for STMicroelectronics.
  5. * Author: Gabriel Fernandez <gabriel.fernandez@st.com> for STMicroelectronics.
  6. */
  7. #include <linux/clk.h>
  8. #include <linux/clk-provider.h>
  9. #include <linux/delay.h>
  10. #include <linux/err.h>
  11. #include <linux/io.h>
  12. #include <linux/of.h>
  13. #include <linux/of_address.h>
  14. #include <linux/slab.h>
  15. #include <linux/spinlock.h>
  16. #include <dt-bindings/clock/stm32mp1-clks.h>
  17. static DEFINE_SPINLOCK(rlock);
  18. #define RCC_OCENSETR 0x0C
  19. #define RCC_HSICFGR 0x18
  20. #define RCC_RDLSICR 0x144
  21. #define RCC_PLL1CR 0x80
  22. #define RCC_PLL1CFGR1 0x84
  23. #define RCC_PLL1CFGR2 0x88
  24. #define RCC_PLL2CR 0x94
  25. #define RCC_PLL2CFGR1 0x98
  26. #define RCC_PLL2CFGR2 0x9C
  27. #define RCC_PLL3CR 0x880
  28. #define RCC_PLL3CFGR1 0x884
  29. #define RCC_PLL3CFGR2 0x888
  30. #define RCC_PLL4CR 0x894
  31. #define RCC_PLL4CFGR1 0x898
  32. #define RCC_PLL4CFGR2 0x89C
  33. #define RCC_APB1ENSETR 0xA00
  34. #define RCC_APB2ENSETR 0xA08
  35. #define RCC_APB3ENSETR 0xA10
  36. #define RCC_APB4ENSETR 0x200
  37. #define RCC_APB5ENSETR 0x208
  38. #define RCC_AHB2ENSETR 0xA18
  39. #define RCC_AHB3ENSETR 0xA20
  40. #define RCC_AHB4ENSETR 0xA28
  41. #define RCC_AHB5ENSETR 0x210
  42. #define RCC_AHB6ENSETR 0x218
  43. #define RCC_AHB6LPENSETR 0x318
  44. #define RCC_RCK12SELR 0x28
  45. #define RCC_RCK3SELR 0x820
  46. #define RCC_RCK4SELR 0x824
  47. #define RCC_MPCKSELR 0x20
  48. #define RCC_ASSCKSELR 0x24
  49. #define RCC_MSSCKSELR 0x48
  50. #define RCC_SPI6CKSELR 0xC4
  51. #define RCC_SDMMC12CKSELR 0x8F4
  52. #define RCC_SDMMC3CKSELR 0x8F8
  53. #define RCC_FMCCKSELR 0x904
  54. #define RCC_I2C46CKSELR 0xC0
  55. #define RCC_I2C12CKSELR 0x8C0
  56. #define RCC_I2C35CKSELR 0x8C4
  57. #define RCC_UART1CKSELR 0xC8
  58. #define RCC_QSPICKSELR 0x900
  59. #define RCC_ETHCKSELR 0x8FC
  60. #define RCC_RNG1CKSELR 0xCC
  61. #define RCC_RNG2CKSELR 0x920
  62. #define RCC_GPUCKSELR 0x938
  63. #define RCC_USBCKSELR 0x91C
  64. #define RCC_STGENCKSELR 0xD4
  65. #define RCC_SPDIFCKSELR 0x914
  66. #define RCC_SPI2S1CKSELR 0x8D8
  67. #define RCC_SPI2S23CKSELR 0x8DC
  68. #define RCC_SPI2S45CKSELR 0x8E0
  69. #define RCC_CECCKSELR 0x918
  70. #define RCC_LPTIM1CKSELR 0x934
  71. #define RCC_LPTIM23CKSELR 0x930
  72. #define RCC_LPTIM45CKSELR 0x92C
  73. #define RCC_UART24CKSELR 0x8E8
  74. #define RCC_UART35CKSELR 0x8EC
  75. #define RCC_UART6CKSELR 0x8E4
  76. #define RCC_UART78CKSELR 0x8F0
  77. #define RCC_FDCANCKSELR 0x90C
  78. #define RCC_SAI1CKSELR 0x8C8
  79. #define RCC_SAI2CKSELR 0x8CC
  80. #define RCC_SAI3CKSELR 0x8D0
  81. #define RCC_SAI4CKSELR 0x8D4
  82. #define RCC_ADCCKSELR 0x928
  83. #define RCC_MPCKDIVR 0x2C
  84. #define RCC_DSICKSELR 0x924
  85. #define RCC_CPERCKSELR 0xD0
  86. #define RCC_MCO1CFGR 0x800
  87. #define RCC_MCO2CFGR 0x804
  88. #define RCC_BDCR 0x140
  89. #define RCC_AXIDIVR 0x30
  90. #define RCC_MCUDIVR 0x830
  91. #define RCC_APB1DIVR 0x834
  92. #define RCC_APB2DIVR 0x838
  93. #define RCC_APB3DIVR 0x83C
  94. #define RCC_APB4DIVR 0x3C
  95. #define RCC_APB5DIVR 0x40
  96. #define RCC_TIMG1PRER 0x828
  97. #define RCC_TIMG2PRER 0x82C
  98. #define RCC_RTCDIVR 0x44
  99. #define RCC_DBGCFGR 0x80C
  100. #define RCC_CLR 0x4
  101. static const char * const ref12_parents[] = {
  102. "ck_hsi", "ck_hse"
  103. };
  104. static const char * const ref3_parents[] = {
  105. "ck_hsi", "ck_hse", "ck_csi"
  106. };
  107. static const char * const ref4_parents[] = {
  108. "ck_hsi", "ck_hse", "ck_csi"
  109. };
  110. static const char * const cpu_src[] = {
  111. "ck_hsi", "ck_hse", "pll1_p"
  112. };
  113. static const char * const axi_src[] = {
  114. "ck_hsi", "ck_hse", "pll2_p", "pll3_p"
  115. };
  116. static const char * const per_src[] = {
  117. "ck_hsi", "ck_csi", "ck_hse"
  118. };
  119. static const char * const mcu_src[] = {
  120. "ck_hsi", "ck_hse", "ck_csi", "pll3_p"
  121. };
  122. static const char * const sdmmc12_src[] = {
  123. "ck_axi", "pll3_r", "pll4_p", "ck_hsi"
  124. };
  125. static const char * const sdmmc3_src[] = {
  126. "ck_mcu", "pll3_r", "pll4_p", "ck_hsi"
  127. };
  128. static const char * const fmc_src[] = {
  129. "ck_axi", "pll3_r", "pll4_p", "ck_per"
  130. };
  131. static const char * const qspi_src[] = {
  132. "ck_axi", "pll3_r", "pll4_p", "ck_per"
  133. };
  134. static const char * const eth_src[] = {
  135. "pll4_p", "pll3_q"
  136. };
  137. static const char * const rng_src[] = {
  138. "ck_csi", "pll4_r", "ck_lse", "ck_lsi"
  139. };
  140. static const char * const usbphy_src[] = {
  141. "ck_hse", "pll4_r", "clk-hse-div2"
  142. };
  143. static const char * const usbo_src[] = {
  144. "pll4_r", "ck_usbo_48m"
  145. };
  146. static const char * const stgen_src[] = {
  147. "ck_hsi", "ck_hse"
  148. };
  149. static const char * const spdif_src[] = {
  150. "pll4_p", "pll3_q", "ck_hsi"
  151. };
  152. static const char * const spi123_src[] = {
  153. "pll4_p", "pll3_q", "i2s_ckin", "ck_per", "pll3_r"
  154. };
  155. static const char * const spi45_src[] = {
  156. "pclk2", "pll4_q", "ck_hsi", "ck_csi", "ck_hse"
  157. };
  158. static const char * const spi6_src[] = {
  159. "pclk5", "pll4_q", "ck_hsi", "ck_csi", "ck_hse", "pll3_q"
  160. };
  161. static const char * const cec_src[] = {
  162. "ck_lse", "ck_lsi", "ck_csi"
  163. };
  164. static const char * const i2c12_src[] = {
  165. "pclk1", "pll4_r", "ck_hsi", "ck_csi"
  166. };
  167. static const char * const i2c35_src[] = {
  168. "pclk1", "pll4_r", "ck_hsi", "ck_csi"
  169. };
  170. static const char * const i2c46_src[] = {
  171. "pclk5", "pll3_q", "ck_hsi", "ck_csi"
  172. };
  173. static const char * const lptim1_src[] = {
  174. "pclk1", "pll4_p", "pll3_q", "ck_lse", "ck_lsi", "ck_per"
  175. };
  176. static const char * const lptim23_src[] = {
  177. "pclk3", "pll4_q", "ck_per", "ck_lse", "ck_lsi"
  178. };
  179. static const char * const lptim45_src[] = {
  180. "pclk3", "pll4_p", "pll3_q", "ck_lse", "ck_lsi", "ck_per"
  181. };
  182. static const char * const usart1_src[] = {
  183. "pclk5", "pll3_q", "ck_hsi", "ck_csi", "pll4_q", "ck_hse"
  184. };
  185. const char * const usart234578_src[] = {
  186. "pclk1", "pll4_q", "ck_hsi", "ck_csi", "ck_hse"
  187. };
  188. static const char * const usart6_src[] = {
  189. "pclk2", "pll4_q", "ck_hsi", "ck_csi", "ck_hse"
  190. };
  191. static const char * const dfsdm_src[] = {
  192. "pclk2", "ck_mcu"
  193. };
  194. static const char * const fdcan_src[] = {
  195. "ck_hse", "pll3_q", "pll4_q"
  196. };
  197. static const char * const sai_src[] = {
  198. "pll4_q", "pll3_q", "i2s_ckin", "ck_per"
  199. };
  200. static const char * const sai2_src[] = {
  201. "pll4_q", "pll3_q", "i2s_ckin", "ck_per", "spdif_ck_symb"
  202. };
  203. static const char * const adc12_src[] = {
  204. "pll4_q", "ck_per"
  205. };
  206. static const char * const dsi_src[] = {
  207. "ck_dsi_phy", "pll4_p"
  208. };
  209. static const char * const rtc_src[] = {
  210. "off", "ck_lse", "ck_lsi", "ck_hse_rtc"
  211. };
  212. static const char * const mco1_src[] = {
  213. "ck_hsi", "ck_hse", "ck_csi", "ck_lsi", "ck_lse"
  214. };
  215. static const char * const mco2_src[] = {
  216. "ck_mpu", "ck_axi", "ck_mcu", "pll4_p", "ck_hse", "ck_hsi"
  217. };
  218. static const char * const ck_trace_src[] = {
  219. "ck_axi"
  220. };
  221. static const struct clk_div_table axi_div_table[] = {
  222. { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 4 },
  223. { 4, 4 }, { 5, 4 }, { 6, 4 }, { 7, 4 },
  224. { 0 },
  225. };
  226. static const struct clk_div_table mcu_div_table[] = {
  227. { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 },
  228. { 4, 16 }, { 5, 32 }, { 6, 64 }, { 7, 128 },
  229. { 8, 512 }, { 9, 512 }, { 10, 512}, { 11, 512 },
  230. { 12, 512 }, { 13, 512 }, { 14, 512}, { 15, 512 },
  231. { 0 },
  232. };
  233. static const struct clk_div_table apb_div_table[] = {
  234. { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 },
  235. { 4, 16 }, { 5, 16 }, { 6, 16 }, { 7, 16 },
  236. { 0 },
  237. };
  238. static const struct clk_div_table ck_trace_div_table[] = {
  239. { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 },
  240. { 4, 16 }, { 5, 16 }, { 6, 16 }, { 7, 16 },
  241. { 0 },
  242. };
  243. #define MAX_MUX_CLK 2
  244. struct stm32_mmux {
  245. u8 nbr_clk;
  246. struct clk_hw *hws[MAX_MUX_CLK];
  247. };
  248. struct stm32_clk_mmux {
  249. struct clk_mux mux;
  250. struct stm32_mmux *mmux;
  251. };
  252. struct stm32_mgate {
  253. u8 nbr_clk;
  254. u32 flag;
  255. };
  256. struct stm32_clk_mgate {
  257. struct clk_gate gate;
  258. struct stm32_mgate *mgate;
  259. u32 mask;
  260. };
  261. struct clock_config {
  262. u32 id;
  263. const char *name;
  264. union {
  265. const char *parent_name;
  266. const char * const *parent_names;
  267. };
  268. int num_parents;
  269. unsigned long flags;
  270. void *cfg;
  271. struct clk_hw * (*func)(struct device *dev,
  272. struct clk_hw_onecell_data *clk_data,
  273. void __iomem *base, spinlock_t *lock,
  274. const struct clock_config *cfg);
  275. };
  276. #define NO_ID ~0
  277. struct gate_cfg {
  278. u32 reg_off;
  279. u8 bit_idx;
  280. u8 gate_flags;
  281. };
  282. struct fixed_factor_cfg {
  283. unsigned int mult;
  284. unsigned int div;
  285. };
  286. struct div_cfg {
  287. u32 reg_off;
  288. u8 shift;
  289. u8 width;
  290. u8 div_flags;
  291. const struct clk_div_table *table;
  292. };
  293. struct mux_cfg {
  294. u32 reg_off;
  295. u8 shift;
  296. u8 width;
  297. u8 mux_flags;
  298. u32 *table;
  299. };
  300. struct stm32_gate_cfg {
  301. struct gate_cfg *gate;
  302. struct stm32_mgate *mgate;
  303. const struct clk_ops *ops;
  304. };
  305. struct stm32_div_cfg {
  306. struct div_cfg *div;
  307. const struct clk_ops *ops;
  308. };
  309. struct stm32_mux_cfg {
  310. struct mux_cfg *mux;
  311. struct stm32_mmux *mmux;
  312. const struct clk_ops *ops;
  313. };
  314. /* STM32 Composite clock */
  315. struct stm32_composite_cfg {
  316. const struct stm32_gate_cfg *gate;
  317. const struct stm32_div_cfg *div;
  318. const struct stm32_mux_cfg *mux;
  319. };
  320. static struct clk_hw *
  321. _clk_hw_register_gate(struct device *dev,
  322. struct clk_hw_onecell_data *clk_data,
  323. void __iomem *base, spinlock_t *lock,
  324. const struct clock_config *cfg)
  325. {
  326. struct gate_cfg *gate_cfg = cfg->cfg;
  327. return clk_hw_register_gate(dev,
  328. cfg->name,
  329. cfg->parent_name,
  330. cfg->flags,
  331. gate_cfg->reg_off + base,
  332. gate_cfg->bit_idx,
  333. gate_cfg->gate_flags,
  334. lock);
  335. }
  336. static struct clk_hw *
  337. _clk_hw_register_fixed_factor(struct device *dev,
  338. struct clk_hw_onecell_data *clk_data,
  339. void __iomem *base, spinlock_t *lock,
  340. const struct clock_config *cfg)
  341. {
  342. struct fixed_factor_cfg *ff_cfg = cfg->cfg;
  343. return clk_hw_register_fixed_factor(dev, cfg->name, cfg->parent_name,
  344. cfg->flags, ff_cfg->mult,
  345. ff_cfg->div);
  346. }
  347. static struct clk_hw *
  348. _clk_hw_register_divider_table(struct device *dev,
  349. struct clk_hw_onecell_data *clk_data,
  350. void __iomem *base, spinlock_t *lock,
  351. const struct clock_config *cfg)
  352. {
  353. struct div_cfg *div_cfg = cfg->cfg;
  354. return clk_hw_register_divider_table(dev,
  355. cfg->name,
  356. cfg->parent_name,
  357. cfg->flags,
  358. div_cfg->reg_off + base,
  359. div_cfg->shift,
  360. div_cfg->width,
  361. div_cfg->div_flags,
  362. div_cfg->table,
  363. lock);
  364. }
  365. static struct clk_hw *
  366. _clk_hw_register_mux(struct device *dev,
  367. struct clk_hw_onecell_data *clk_data,
  368. void __iomem *base, spinlock_t *lock,
  369. const struct clock_config *cfg)
  370. {
  371. struct mux_cfg *mux_cfg = cfg->cfg;
  372. return clk_hw_register_mux(dev, cfg->name, cfg->parent_names,
  373. cfg->num_parents, cfg->flags,
  374. mux_cfg->reg_off + base, mux_cfg->shift,
  375. mux_cfg->width, mux_cfg->mux_flags, lock);
  376. }
  377. /* MP1 Gate clock with set & clear registers */
  378. static int mp1_gate_clk_enable(struct clk_hw *hw)
  379. {
  380. if (!clk_gate_ops.is_enabled(hw))
  381. clk_gate_ops.enable(hw);
  382. return 0;
  383. }
  384. static void mp1_gate_clk_disable(struct clk_hw *hw)
  385. {
  386. struct clk_gate *gate = to_clk_gate(hw);
  387. unsigned long flags = 0;
  388. if (clk_gate_ops.is_enabled(hw)) {
  389. spin_lock_irqsave(gate->lock, flags);
  390. writel_relaxed(BIT(gate->bit_idx), gate->reg + RCC_CLR);
  391. spin_unlock_irqrestore(gate->lock, flags);
  392. }
  393. }
  394. const struct clk_ops mp1_gate_clk_ops = {
  395. .enable = mp1_gate_clk_enable,
  396. .disable = mp1_gate_clk_disable,
  397. .is_enabled = clk_gate_is_enabled,
  398. };
  399. static struct clk_hw *_get_stm32_mux(void __iomem *base,
  400. const struct stm32_mux_cfg *cfg,
  401. spinlock_t *lock)
  402. {
  403. struct stm32_clk_mmux *mmux;
  404. struct clk_mux *mux;
  405. struct clk_hw *mux_hw;
  406. if (cfg->mmux) {
  407. mmux = kzalloc(sizeof(*mmux), GFP_KERNEL);
  408. if (!mmux)
  409. return ERR_PTR(-ENOMEM);
  410. mmux->mux.reg = cfg->mux->reg_off + base;
  411. mmux->mux.shift = cfg->mux->shift;
  412. mmux->mux.mask = (1 << cfg->mux->width) - 1;
  413. mmux->mux.flags = cfg->mux->mux_flags;
  414. mmux->mux.table = cfg->mux->table;
  415. mmux->mux.lock = lock;
  416. mmux->mmux = cfg->mmux;
  417. mux_hw = &mmux->mux.hw;
  418. cfg->mmux->hws[cfg->mmux->nbr_clk++] = mux_hw;
  419. } else {
  420. mux = kzalloc(sizeof(*mux), GFP_KERNEL);
  421. if (!mux)
  422. return ERR_PTR(-ENOMEM);
  423. mux->reg = cfg->mux->reg_off + base;
  424. mux->shift = cfg->mux->shift;
  425. mux->mask = (1 << cfg->mux->width) - 1;
  426. mux->flags = cfg->mux->mux_flags;
  427. mux->table = cfg->mux->table;
  428. mux->lock = lock;
  429. mux_hw = &mux->hw;
  430. }
  431. return mux_hw;
  432. }
  433. static struct clk_hw *_get_stm32_div(void __iomem *base,
  434. const struct stm32_div_cfg *cfg,
  435. spinlock_t *lock)
  436. {
  437. struct clk_divider *div;
  438. div = kzalloc(sizeof(*div), GFP_KERNEL);
  439. if (!div)
  440. return ERR_PTR(-ENOMEM);
  441. div->reg = cfg->div->reg_off + base;
  442. div->shift = cfg->div->shift;
  443. div->width = cfg->div->width;
  444. div->flags = cfg->div->div_flags;
  445. div->table = cfg->div->table;
  446. div->lock = lock;
  447. return &div->hw;
  448. }
  449. static struct clk_hw *
  450. _get_stm32_gate(void __iomem *base,
  451. const struct stm32_gate_cfg *cfg, spinlock_t *lock)
  452. {
  453. struct stm32_clk_mgate *mgate;
  454. struct clk_gate *gate;
  455. struct clk_hw *gate_hw;
  456. if (cfg->mgate) {
  457. mgate = kzalloc(sizeof(*mgate), GFP_KERNEL);
  458. if (!mgate)
  459. return ERR_PTR(-ENOMEM);
  460. mgate->gate.reg = cfg->gate->reg_off + base;
  461. mgate->gate.bit_idx = cfg->gate->bit_idx;
  462. mgate->gate.flags = cfg->gate->gate_flags;
  463. mgate->gate.lock = lock;
  464. mgate->mask = BIT(cfg->mgate->nbr_clk++);
  465. mgate->mgate = cfg->mgate;
  466. gate_hw = &mgate->gate.hw;
  467. } else {
  468. gate = kzalloc(sizeof(*gate), GFP_KERNEL);
  469. if (!gate)
  470. return ERR_PTR(-ENOMEM);
  471. gate->reg = cfg->gate->reg_off + base;
  472. gate->bit_idx = cfg->gate->bit_idx;
  473. gate->flags = cfg->gate->gate_flags;
  474. gate->lock = lock;
  475. gate_hw = &gate->hw;
  476. }
  477. return gate_hw;
  478. }
  479. static struct clk_hw *
  480. clk_stm32_register_gate_ops(struct device *dev,
  481. const char *name,
  482. const char *parent_name,
  483. unsigned long flags,
  484. void __iomem *base,
  485. const struct stm32_gate_cfg *cfg,
  486. spinlock_t *lock)
  487. {
  488. struct clk_init_data init = { NULL };
  489. struct clk_gate *gate;
  490. struct clk_hw *hw;
  491. int ret;
  492. gate = kzalloc(sizeof(*gate), GFP_KERNEL);
  493. if (!gate)
  494. return ERR_PTR(-ENOMEM);
  495. init.name = name;
  496. init.parent_names = &parent_name;
  497. init.num_parents = 1;
  498. init.flags = flags;
  499. init.ops = &clk_gate_ops;
  500. if (cfg->ops)
  501. init.ops = cfg->ops;
  502. hw = _get_stm32_gate(base, cfg, lock);
  503. if (IS_ERR(hw))
  504. return ERR_PTR(-ENOMEM);
  505. hw->init = &init;
  506. ret = clk_hw_register(dev, hw);
  507. if (ret) {
  508. kfree(gate);
  509. hw = ERR_PTR(ret);
  510. }
  511. return hw;
  512. }
  513. static struct clk_hw *
  514. clk_stm32_register_composite(struct device *dev,
  515. const char *name, const char * const *parent_names,
  516. int num_parents, void __iomem *base,
  517. const struct stm32_composite_cfg *cfg,
  518. unsigned long flags, spinlock_t *lock)
  519. {
  520. const struct clk_ops *mux_ops, *div_ops, *gate_ops;
  521. struct clk_hw *mux_hw, *div_hw, *gate_hw;
  522. mux_hw = NULL;
  523. div_hw = NULL;
  524. gate_hw = NULL;
  525. mux_ops = NULL;
  526. div_ops = NULL;
  527. gate_ops = NULL;
  528. if (cfg->mux) {
  529. mux_hw = _get_stm32_mux(base, cfg->mux, lock);
  530. if (!IS_ERR(mux_hw)) {
  531. mux_ops = &clk_mux_ops;
  532. if (cfg->mux->ops)
  533. mux_ops = cfg->mux->ops;
  534. }
  535. }
  536. if (cfg->div) {
  537. div_hw = _get_stm32_div(base, cfg->div, lock);
  538. if (!IS_ERR(div_hw)) {
  539. div_ops = &clk_divider_ops;
  540. if (cfg->div->ops)
  541. div_ops = cfg->div->ops;
  542. }
  543. }
  544. if (cfg->gate) {
  545. gate_hw = _get_stm32_gate(base, cfg->gate, lock);
  546. if (!IS_ERR(gate_hw)) {
  547. gate_ops = &clk_gate_ops;
  548. if (cfg->gate->ops)
  549. gate_ops = cfg->gate->ops;
  550. }
  551. }
  552. return clk_hw_register_composite(dev, name, parent_names, num_parents,
  553. mux_hw, mux_ops, div_hw, div_ops,
  554. gate_hw, gate_ops, flags);
  555. }
  556. #define to_clk_mgate(_gate) container_of(_gate, struct stm32_clk_mgate, gate)
  557. static int mp1_mgate_clk_enable(struct clk_hw *hw)
  558. {
  559. struct clk_gate *gate = to_clk_gate(hw);
  560. struct stm32_clk_mgate *clk_mgate = to_clk_mgate(gate);
  561. clk_mgate->mgate->flag |= clk_mgate->mask;
  562. mp1_gate_clk_enable(hw);
  563. return 0;
  564. }
  565. static void mp1_mgate_clk_disable(struct clk_hw *hw)
  566. {
  567. struct clk_gate *gate = to_clk_gate(hw);
  568. struct stm32_clk_mgate *clk_mgate = to_clk_mgate(gate);
  569. clk_mgate->mgate->flag &= ~clk_mgate->mask;
  570. if (clk_mgate->mgate->flag == 0)
  571. mp1_gate_clk_disable(hw);
  572. }
  573. const struct clk_ops mp1_mgate_clk_ops = {
  574. .enable = mp1_mgate_clk_enable,
  575. .disable = mp1_mgate_clk_disable,
  576. .is_enabled = clk_gate_is_enabled,
  577. };
  578. #define to_clk_mmux(_mux) container_of(_mux, struct stm32_clk_mmux, mux)
  579. static u8 clk_mmux_get_parent(struct clk_hw *hw)
  580. {
  581. return clk_mux_ops.get_parent(hw);
  582. }
  583. static int clk_mmux_set_parent(struct clk_hw *hw, u8 index)
  584. {
  585. struct clk_mux *mux = to_clk_mux(hw);
  586. struct stm32_clk_mmux *clk_mmux = to_clk_mmux(mux);
  587. struct clk_hw *hwp;
  588. int ret, n;
  589. ret = clk_mux_ops.set_parent(hw, index);
  590. if (ret)
  591. return ret;
  592. hwp = clk_hw_get_parent(hw);
  593. for (n = 0; n < clk_mmux->mmux->nbr_clk; n++)
  594. if (clk_mmux->mmux->hws[n] != hw)
  595. clk_hw_reparent(clk_mmux->mmux->hws[n], hwp);
  596. return 0;
  597. }
  598. const struct clk_ops clk_mmux_ops = {
  599. .get_parent = clk_mmux_get_parent,
  600. .set_parent = clk_mmux_set_parent,
  601. .determine_rate = __clk_mux_determine_rate,
  602. };
  603. /* STM32 PLL */
  604. struct stm32_pll_obj {
  605. /* lock pll enable/disable registers */
  606. spinlock_t *lock;
  607. void __iomem *reg;
  608. struct clk_hw hw;
  609. };
  610. #define to_pll(_hw) container_of(_hw, struct stm32_pll_obj, hw)
  611. #define PLL_ON BIT(0)
  612. #define PLL_RDY BIT(1)
  613. #define DIVN_MASK 0x1FF
  614. #define DIVM_MASK 0x3F
  615. #define DIVM_SHIFT 16
  616. #define DIVN_SHIFT 0
  617. #define FRAC_OFFSET 0xC
  618. #define FRAC_MASK 0x1FFF
  619. #define FRAC_SHIFT 3
  620. #define FRACLE BIT(16)
  621. static int __pll_is_enabled(struct clk_hw *hw)
  622. {
  623. struct stm32_pll_obj *clk_elem = to_pll(hw);
  624. return readl_relaxed(clk_elem->reg) & PLL_ON;
  625. }
  626. #define TIMEOUT 5
  627. static int pll_enable(struct clk_hw *hw)
  628. {
  629. struct stm32_pll_obj *clk_elem = to_pll(hw);
  630. u32 reg;
  631. unsigned long flags = 0;
  632. unsigned int timeout = TIMEOUT;
  633. int bit_status = 0;
  634. spin_lock_irqsave(clk_elem->lock, flags);
  635. if (__pll_is_enabled(hw))
  636. goto unlock;
  637. reg = readl_relaxed(clk_elem->reg);
  638. reg |= PLL_ON;
  639. writel_relaxed(reg, clk_elem->reg);
  640. /* We can't use readl_poll_timeout() because we can be blocked if
  641. * someone enables this clock before clocksource changes.
  642. * Only jiffies counter is available. Jiffies are incremented by
  643. * interruptions and enable op does not allow to be interrupted.
  644. */
  645. do {
  646. bit_status = !(readl_relaxed(clk_elem->reg) & PLL_RDY);
  647. if (bit_status)
  648. udelay(120);
  649. } while (bit_status && --timeout);
  650. unlock:
  651. spin_unlock_irqrestore(clk_elem->lock, flags);
  652. return bit_status;
  653. }
  654. static void pll_disable(struct clk_hw *hw)
  655. {
  656. struct stm32_pll_obj *clk_elem = to_pll(hw);
  657. u32 reg;
  658. unsigned long flags = 0;
  659. spin_lock_irqsave(clk_elem->lock, flags);
  660. reg = readl_relaxed(clk_elem->reg);
  661. reg &= ~PLL_ON;
  662. writel_relaxed(reg, clk_elem->reg);
  663. spin_unlock_irqrestore(clk_elem->lock, flags);
  664. }
  665. static u32 pll_frac_val(struct clk_hw *hw)
  666. {
  667. struct stm32_pll_obj *clk_elem = to_pll(hw);
  668. u32 reg, frac = 0;
  669. reg = readl_relaxed(clk_elem->reg + FRAC_OFFSET);
  670. if (reg & FRACLE)
  671. frac = (reg >> FRAC_SHIFT) & FRAC_MASK;
  672. return frac;
  673. }
  674. static unsigned long pll_recalc_rate(struct clk_hw *hw,
  675. unsigned long parent_rate)
  676. {
  677. struct stm32_pll_obj *clk_elem = to_pll(hw);
  678. u32 reg;
  679. u32 frac, divm, divn;
  680. u64 rate, rate_frac = 0;
  681. reg = readl_relaxed(clk_elem->reg + 4);
  682. divm = ((reg >> DIVM_SHIFT) & DIVM_MASK) + 1;
  683. divn = ((reg >> DIVN_SHIFT) & DIVN_MASK) + 1;
  684. rate = (u64)parent_rate * divn;
  685. do_div(rate, divm);
  686. frac = pll_frac_val(hw);
  687. if (frac) {
  688. rate_frac = (u64)parent_rate * (u64)frac;
  689. do_div(rate_frac, (divm * 8192));
  690. }
  691. return rate + rate_frac;
  692. }
  693. static int pll_is_enabled(struct clk_hw *hw)
  694. {
  695. struct stm32_pll_obj *clk_elem = to_pll(hw);
  696. unsigned long flags = 0;
  697. int ret;
  698. spin_lock_irqsave(clk_elem->lock, flags);
  699. ret = __pll_is_enabled(hw);
  700. spin_unlock_irqrestore(clk_elem->lock, flags);
  701. return ret;
  702. }
  703. static const struct clk_ops pll_ops = {
  704. .enable = pll_enable,
  705. .disable = pll_disable,
  706. .recalc_rate = pll_recalc_rate,
  707. .is_enabled = pll_is_enabled,
  708. };
  709. static struct clk_hw *clk_register_pll(struct device *dev, const char *name,
  710. const char *parent_name,
  711. void __iomem *reg,
  712. unsigned long flags,
  713. spinlock_t *lock)
  714. {
  715. struct stm32_pll_obj *element;
  716. struct clk_init_data init;
  717. struct clk_hw *hw;
  718. int err;
  719. element = kzalloc(sizeof(*element), GFP_KERNEL);
  720. if (!element)
  721. return ERR_PTR(-ENOMEM);
  722. init.name = name;
  723. init.ops = &pll_ops;
  724. init.flags = flags;
  725. init.parent_names = &parent_name;
  726. init.num_parents = 1;
  727. element->hw.init = &init;
  728. element->reg = reg;
  729. element->lock = lock;
  730. hw = &element->hw;
  731. err = clk_hw_register(dev, hw);
  732. if (err) {
  733. kfree(element);
  734. return ERR_PTR(err);
  735. }
  736. return hw;
  737. }
  738. /* Kernel Timer */
  739. struct timer_cker {
  740. /* lock the kernel output divider register */
  741. spinlock_t *lock;
  742. void __iomem *apbdiv;
  743. void __iomem *timpre;
  744. struct clk_hw hw;
  745. };
  746. #define to_timer_cker(_hw) container_of(_hw, struct timer_cker, hw)
  747. #define APB_DIV_MASK 0x07
  748. #define TIM_PRE_MASK 0x01
  749. static unsigned long __bestmult(struct clk_hw *hw, unsigned long rate,
  750. unsigned long parent_rate)
  751. {
  752. struct timer_cker *tim_ker = to_timer_cker(hw);
  753. u32 prescaler;
  754. unsigned int mult = 0;
  755. prescaler = readl_relaxed(tim_ker->apbdiv) & APB_DIV_MASK;
  756. if (prescaler < 2)
  757. return 1;
  758. mult = 2;
  759. if (rate / parent_rate >= 4)
  760. mult = 4;
  761. return mult;
  762. }
  763. static long timer_ker_round_rate(struct clk_hw *hw, unsigned long rate,
  764. unsigned long *parent_rate)
  765. {
  766. unsigned long factor = __bestmult(hw, rate, *parent_rate);
  767. return *parent_rate * factor;
  768. }
  769. static int timer_ker_set_rate(struct clk_hw *hw, unsigned long rate,
  770. unsigned long parent_rate)
  771. {
  772. struct timer_cker *tim_ker = to_timer_cker(hw);
  773. unsigned long flags = 0;
  774. unsigned long factor = __bestmult(hw, rate, parent_rate);
  775. int ret = 0;
  776. spin_lock_irqsave(tim_ker->lock, flags);
  777. switch (factor) {
  778. case 1:
  779. break;
  780. case 2:
  781. writel_relaxed(0, tim_ker->timpre);
  782. break;
  783. case 4:
  784. writel_relaxed(1, tim_ker->timpre);
  785. break;
  786. default:
  787. ret = -EINVAL;
  788. }
  789. spin_unlock_irqrestore(tim_ker->lock, flags);
  790. return ret;
  791. }
  792. static unsigned long timer_ker_recalc_rate(struct clk_hw *hw,
  793. unsigned long parent_rate)
  794. {
  795. struct timer_cker *tim_ker = to_timer_cker(hw);
  796. u32 prescaler, timpre;
  797. u32 mul;
  798. prescaler = readl_relaxed(tim_ker->apbdiv) & APB_DIV_MASK;
  799. timpre = readl_relaxed(tim_ker->timpre) & TIM_PRE_MASK;
  800. if (!prescaler)
  801. return parent_rate;
  802. mul = (timpre + 1) * 2;
  803. return parent_rate * mul;
  804. }
  805. static const struct clk_ops timer_ker_ops = {
  806. .recalc_rate = timer_ker_recalc_rate,
  807. .round_rate = timer_ker_round_rate,
  808. .set_rate = timer_ker_set_rate,
  809. };
  810. static struct clk_hw *clk_register_cktim(struct device *dev, const char *name,
  811. const char *parent_name,
  812. unsigned long flags,
  813. void __iomem *apbdiv,
  814. void __iomem *timpre,
  815. spinlock_t *lock)
  816. {
  817. struct timer_cker *tim_ker;
  818. struct clk_init_data init;
  819. struct clk_hw *hw;
  820. int err;
  821. tim_ker = kzalloc(sizeof(*tim_ker), GFP_KERNEL);
  822. if (!tim_ker)
  823. return ERR_PTR(-ENOMEM);
  824. init.name = name;
  825. init.ops = &timer_ker_ops;
  826. init.flags = flags;
  827. init.parent_names = &parent_name;
  828. init.num_parents = 1;
  829. tim_ker->hw.init = &init;
  830. tim_ker->lock = lock;
  831. tim_ker->apbdiv = apbdiv;
  832. tim_ker->timpre = timpre;
  833. hw = &tim_ker->hw;
  834. err = clk_hw_register(dev, hw);
  835. if (err) {
  836. kfree(tim_ker);
  837. return ERR_PTR(err);
  838. }
  839. return hw;
  840. }
  841. struct stm32_pll_cfg {
  842. u32 offset;
  843. };
  844. struct clk_hw *_clk_register_pll(struct device *dev,
  845. struct clk_hw_onecell_data *clk_data,
  846. void __iomem *base, spinlock_t *lock,
  847. const struct clock_config *cfg)
  848. {
  849. struct stm32_pll_cfg *stm_pll_cfg = cfg->cfg;
  850. return clk_register_pll(dev, cfg->name, cfg->parent_name,
  851. base + stm_pll_cfg->offset, cfg->flags, lock);
  852. }
  853. struct stm32_cktim_cfg {
  854. u32 offset_apbdiv;
  855. u32 offset_timpre;
  856. };
  857. static struct clk_hw *_clk_register_cktim(struct device *dev,
  858. struct clk_hw_onecell_data *clk_data,
  859. void __iomem *base, spinlock_t *lock,
  860. const struct clock_config *cfg)
  861. {
  862. struct stm32_cktim_cfg *cktim_cfg = cfg->cfg;
  863. return clk_register_cktim(dev, cfg->name, cfg->parent_name, cfg->flags,
  864. cktim_cfg->offset_apbdiv + base,
  865. cktim_cfg->offset_timpre + base, lock);
  866. }
  867. static struct clk_hw *
  868. _clk_stm32_register_gate(struct device *dev,
  869. struct clk_hw_onecell_data *clk_data,
  870. void __iomem *base, spinlock_t *lock,
  871. const struct clock_config *cfg)
  872. {
  873. return clk_stm32_register_gate_ops(dev,
  874. cfg->name,
  875. cfg->parent_name,
  876. cfg->flags,
  877. base,
  878. cfg->cfg,
  879. lock);
  880. }
  881. static struct clk_hw *
  882. _clk_stm32_register_composite(struct device *dev,
  883. struct clk_hw_onecell_data *clk_data,
  884. void __iomem *base, spinlock_t *lock,
  885. const struct clock_config *cfg)
  886. {
  887. return clk_stm32_register_composite(dev, cfg->name, cfg->parent_names,
  888. cfg->num_parents, base, cfg->cfg,
  889. cfg->flags, lock);
  890. }
  891. #define GATE(_id, _name, _parent, _flags, _offset, _bit_idx, _gate_flags)\
  892. {\
  893. .id = _id,\
  894. .name = _name,\
  895. .parent_name = _parent,\
  896. .flags = _flags,\
  897. .cfg = &(struct gate_cfg) {\
  898. .reg_off = _offset,\
  899. .bit_idx = _bit_idx,\
  900. .gate_flags = _gate_flags,\
  901. },\
  902. .func = _clk_hw_register_gate,\
  903. }
  904. #define FIXED_FACTOR(_id, _name, _parent, _flags, _mult, _div)\
  905. {\
  906. .id = _id,\
  907. .name = _name,\
  908. .parent_name = _parent,\
  909. .flags = _flags,\
  910. .cfg = &(struct fixed_factor_cfg) {\
  911. .mult = _mult,\
  912. .div = _div,\
  913. },\
  914. .func = _clk_hw_register_fixed_factor,\
  915. }
  916. #define DIV_TABLE(_id, _name, _parent, _flags, _offset, _shift, _width,\
  917. _div_flags, _div_table)\
  918. {\
  919. .id = _id,\
  920. .name = _name,\
  921. .parent_name = _parent,\
  922. .flags = _flags,\
  923. .cfg = &(struct div_cfg) {\
  924. .reg_off = _offset,\
  925. .shift = _shift,\
  926. .width = _width,\
  927. .div_flags = _div_flags,\
  928. .table = _div_table,\
  929. },\
  930. .func = _clk_hw_register_divider_table,\
  931. }
  932. #define DIV(_id, _name, _parent, _flags, _offset, _shift, _width, _div_flags)\
  933. DIV_TABLE(_id, _name, _parent, _flags, _offset, _shift, _width,\
  934. _div_flags, NULL)
  935. #define MUX(_id, _name, _parents, _flags, _offset, _shift, _width, _mux_flags)\
  936. {\
  937. .id = _id,\
  938. .name = _name,\
  939. .parent_names = _parents,\
  940. .num_parents = ARRAY_SIZE(_parents),\
  941. .flags = _flags,\
  942. .cfg = &(struct mux_cfg) {\
  943. .reg_off = _offset,\
  944. .shift = _shift,\
  945. .width = _width,\
  946. .mux_flags = _mux_flags,\
  947. },\
  948. .func = _clk_hw_register_mux,\
  949. }
  950. #define PLL(_id, _name, _parent, _flags, _offset)\
  951. {\
  952. .id = _id,\
  953. .name = _name,\
  954. .parent_name = _parent,\
  955. .flags = _flags,\
  956. .cfg = &(struct stm32_pll_cfg) {\
  957. .offset = _offset,\
  958. },\
  959. .func = _clk_register_pll,\
  960. }
  961. #define STM32_CKTIM(_name, _parent, _flags, _offset_apbdiv, _offset_timpre)\
  962. {\
  963. .id = NO_ID,\
  964. .name = _name,\
  965. .parent_name = _parent,\
  966. .flags = _flags,\
  967. .cfg = &(struct stm32_cktim_cfg) {\
  968. .offset_apbdiv = _offset_apbdiv,\
  969. .offset_timpre = _offset_timpre,\
  970. },\
  971. .func = _clk_register_cktim,\
  972. }
  973. #define STM32_TIM(_id, _name, _parent, _offset_set, _bit_idx)\
  974. GATE_MP1(_id, _name, _parent, CLK_SET_RATE_PARENT,\
  975. _offset_set, _bit_idx, 0)
  976. /* STM32 GATE */
  977. #define STM32_GATE(_id, _name, _parent, _flags, _gate)\
  978. {\
  979. .id = _id,\
  980. .name = _name,\
  981. .parent_name = _parent,\
  982. .flags = _flags,\
  983. .cfg = (struct stm32_gate_cfg *) {_gate},\
  984. .func = _clk_stm32_register_gate,\
  985. }
  986. #define _STM32_GATE(_gate_offset, _gate_bit_idx, _gate_flags, _mgate, _ops)\
  987. (&(struct stm32_gate_cfg) {\
  988. &(struct gate_cfg) {\
  989. .reg_off = _gate_offset,\
  990. .bit_idx = _gate_bit_idx,\
  991. .gate_flags = _gate_flags,\
  992. },\
  993. .mgate = _mgate,\
  994. .ops = _ops,\
  995. })
  996. #define _STM32_MGATE(_mgate)\
  997. (&per_gate_cfg[_mgate])
  998. #define _GATE(_gate_offset, _gate_bit_idx, _gate_flags)\
  999. _STM32_GATE(_gate_offset, _gate_bit_idx, _gate_flags,\
  1000. NULL, NULL)\
  1001. #define _GATE_MP1(_gate_offset, _gate_bit_idx, _gate_flags)\
  1002. _STM32_GATE(_gate_offset, _gate_bit_idx, _gate_flags,\
  1003. NULL, &mp1_gate_clk_ops)\
  1004. #define _MGATE_MP1(_mgate)\
  1005. .gate = &per_gate_cfg[_mgate]
  1006. #define GATE_MP1(_id, _name, _parent, _flags, _offset, _bit_idx, _gate_flags)\
  1007. STM32_GATE(_id, _name, _parent, _flags,\
  1008. _GATE_MP1(_offset, _bit_idx, _gate_flags))
  1009. #define MGATE_MP1(_id, _name, _parent, _flags, _mgate)\
  1010. STM32_GATE(_id, _name, _parent, _flags,\
  1011. _STM32_MGATE(_mgate))
  1012. #define _STM32_DIV(_div_offset, _div_shift, _div_width,\
  1013. _div_flags, _div_table, _ops)\
  1014. .div = &(struct stm32_div_cfg) {\
  1015. &(struct div_cfg) {\
  1016. .reg_off = _div_offset,\
  1017. .shift = _div_shift,\
  1018. .width = _div_width,\
  1019. .div_flags = _div_flags,\
  1020. .table = _div_table,\
  1021. },\
  1022. .ops = _ops,\
  1023. }
  1024. #define _DIV(_div_offset, _div_shift, _div_width, _div_flags, _div_table)\
  1025. _STM32_DIV(_div_offset, _div_shift, _div_width,\
  1026. _div_flags, _div_table, NULL)\
  1027. #define _STM32_MUX(_offset, _shift, _width, _mux_flags, _mmux, _ops)\
  1028. .mux = &(struct stm32_mux_cfg) {\
  1029. &(struct mux_cfg) {\
  1030. .reg_off = _offset,\
  1031. .shift = _shift,\
  1032. .width = _width,\
  1033. .mux_flags = _mux_flags,\
  1034. .table = NULL,\
  1035. },\
  1036. .mmux = _mmux,\
  1037. .ops = _ops,\
  1038. }
  1039. #define _MUX(_offset, _shift, _width, _mux_flags)\
  1040. _STM32_MUX(_offset, _shift, _width, _mux_flags, NULL, NULL)\
  1041. #define _MMUX(_mmux) .mux = &ker_mux_cfg[_mmux]
  1042. #define PARENT(_parent) ((const char *[]) { _parent})
  1043. #define _NO_MUX .mux = NULL
  1044. #define _NO_DIV .div = NULL
  1045. #define _NO_GATE .gate = NULL
  1046. #define COMPOSITE(_id, _name, _parents, _flags, _gate, _mux, _div)\
  1047. {\
  1048. .id = _id,\
  1049. .name = _name,\
  1050. .parent_names = _parents,\
  1051. .num_parents = ARRAY_SIZE(_parents),\
  1052. .flags = _flags,\
  1053. .cfg = &(struct stm32_composite_cfg) {\
  1054. _gate,\
  1055. _mux,\
  1056. _div,\
  1057. },\
  1058. .func = _clk_stm32_register_composite,\
  1059. }
  1060. #define PCLK(_id, _name, _parent, _flags, _mgate)\
  1061. MGATE_MP1(_id, _name, _parent, _flags, _mgate)
  1062. #define KCLK(_id, _name, _parents, _flags, _mgate, _mmux)\
  1063. COMPOSITE(_id, _name, _parents, CLK_OPS_PARENT_ENABLE | _flags,\
  1064. _MGATE_MP1(_mgate),\
  1065. _MMUX(_mmux),\
  1066. _NO_DIV)
  1067. enum {
  1068. G_SAI1,
  1069. G_SAI2,
  1070. G_SAI3,
  1071. G_SAI4,
  1072. G_SPI1,
  1073. G_SPI2,
  1074. G_SPI3,
  1075. G_SPI4,
  1076. G_SPI5,
  1077. G_SPI6,
  1078. G_SPDIF,
  1079. G_I2C1,
  1080. G_I2C2,
  1081. G_I2C3,
  1082. G_I2C4,
  1083. G_I2C5,
  1084. G_I2C6,
  1085. G_USART2,
  1086. G_UART4,
  1087. G_USART3,
  1088. G_UART5,
  1089. G_USART1,
  1090. G_USART6,
  1091. G_UART7,
  1092. G_UART8,
  1093. G_LPTIM1,
  1094. G_LPTIM2,
  1095. G_LPTIM3,
  1096. G_LPTIM4,
  1097. G_LPTIM5,
  1098. G_LTDC,
  1099. G_DSI,
  1100. G_QSPI,
  1101. G_FMC,
  1102. G_SDMMC1,
  1103. G_SDMMC2,
  1104. G_SDMMC3,
  1105. G_USBO,
  1106. G_USBPHY,
  1107. G_RNG1,
  1108. G_RNG2,
  1109. G_FDCAN,
  1110. G_DAC12,
  1111. G_CEC,
  1112. G_ADC12,
  1113. G_GPU,
  1114. G_STGEN,
  1115. G_DFSDM,
  1116. G_ADFSDM,
  1117. G_TIM2,
  1118. G_TIM3,
  1119. G_TIM4,
  1120. G_TIM5,
  1121. G_TIM6,
  1122. G_TIM7,
  1123. G_TIM12,
  1124. G_TIM13,
  1125. G_TIM14,
  1126. G_MDIO,
  1127. G_TIM1,
  1128. G_TIM8,
  1129. G_TIM15,
  1130. G_TIM16,
  1131. G_TIM17,
  1132. G_SYSCFG,
  1133. G_VREF,
  1134. G_TMPSENS,
  1135. G_PMBCTRL,
  1136. G_HDP,
  1137. G_IWDG2,
  1138. G_STGENRO,
  1139. G_DMA1,
  1140. G_DMA2,
  1141. G_DMAMUX,
  1142. G_DCMI,
  1143. G_CRYP2,
  1144. G_HASH2,
  1145. G_CRC2,
  1146. G_HSEM,
  1147. G_IPCC,
  1148. G_GPIOA,
  1149. G_GPIOB,
  1150. G_GPIOC,
  1151. G_GPIOD,
  1152. G_GPIOE,
  1153. G_GPIOF,
  1154. G_GPIOG,
  1155. G_GPIOH,
  1156. G_GPIOI,
  1157. G_GPIOJ,
  1158. G_GPIOK,
  1159. G_MDMA,
  1160. G_ETHCK,
  1161. G_ETHTX,
  1162. G_ETHRX,
  1163. G_ETHMAC,
  1164. G_CRC1,
  1165. G_USBH,
  1166. G_ETHSTP,
  1167. G_RTCAPB,
  1168. G_TZC,
  1169. G_TZPC,
  1170. G_IWDG1,
  1171. G_BSEC,
  1172. G_GPIOZ,
  1173. G_CRYP1,
  1174. G_HASH1,
  1175. G_BKPSRAM,
  1176. G_LAST
  1177. };
  1178. struct stm32_mgate mp1_mgate[G_LAST];
  1179. #define _K_GATE(_id, _gate_offset, _gate_bit_idx, _gate_flags,\
  1180. _mgate, _ops)\
  1181. [_id] = {\
  1182. &(struct gate_cfg) {\
  1183. .reg_off = _gate_offset,\
  1184. .bit_idx = _gate_bit_idx,\
  1185. .gate_flags = _gate_flags,\
  1186. },\
  1187. .mgate = _mgate,\
  1188. .ops = _ops,\
  1189. }
  1190. #define K_GATE(_id, _gate_offset, _gate_bit_idx, _gate_flags)\
  1191. _K_GATE(_id, _gate_offset, _gate_bit_idx, _gate_flags,\
  1192. NULL, &mp1_gate_clk_ops)
  1193. #define K_MGATE(_id, _gate_offset, _gate_bit_idx, _gate_flags)\
  1194. _K_GATE(_id, _gate_offset, _gate_bit_idx, _gate_flags,\
  1195. &mp1_mgate[_id], &mp1_mgate_clk_ops)
  1196. /* Peripheral gates */
  1197. struct stm32_gate_cfg per_gate_cfg[G_LAST] = {
  1198. /* Multi gates */
  1199. K_GATE(G_MDIO, RCC_APB1ENSETR, 31, 0),
  1200. K_MGATE(G_DAC12, RCC_APB1ENSETR, 29, 0),
  1201. K_MGATE(G_CEC, RCC_APB1ENSETR, 27, 0),
  1202. K_MGATE(G_SPDIF, RCC_APB1ENSETR, 26, 0),
  1203. K_MGATE(G_I2C5, RCC_APB1ENSETR, 24, 0),
  1204. K_MGATE(G_I2C3, RCC_APB1ENSETR, 23, 0),
  1205. K_MGATE(G_I2C2, RCC_APB1ENSETR, 22, 0),
  1206. K_MGATE(G_I2C1, RCC_APB1ENSETR, 21, 0),
  1207. K_MGATE(G_UART8, RCC_APB1ENSETR, 19, 0),
  1208. K_MGATE(G_UART7, RCC_APB1ENSETR, 18, 0),
  1209. K_MGATE(G_UART5, RCC_APB1ENSETR, 17, 0),
  1210. K_MGATE(G_UART4, RCC_APB1ENSETR, 16, 0),
  1211. K_MGATE(G_USART3, RCC_APB1ENSETR, 15, 0),
  1212. K_MGATE(G_USART2, RCC_APB1ENSETR, 14, 0),
  1213. K_MGATE(G_SPI3, RCC_APB1ENSETR, 12, 0),
  1214. K_MGATE(G_SPI2, RCC_APB1ENSETR, 11, 0),
  1215. K_MGATE(G_LPTIM1, RCC_APB1ENSETR, 9, 0),
  1216. K_GATE(G_TIM14, RCC_APB1ENSETR, 8, 0),
  1217. K_GATE(G_TIM13, RCC_APB1ENSETR, 7, 0),
  1218. K_GATE(G_TIM12, RCC_APB1ENSETR, 6, 0),
  1219. K_GATE(G_TIM7, RCC_APB1ENSETR, 5, 0),
  1220. K_GATE(G_TIM6, RCC_APB1ENSETR, 4, 0),
  1221. K_GATE(G_TIM5, RCC_APB1ENSETR, 3, 0),
  1222. K_GATE(G_TIM4, RCC_APB1ENSETR, 2, 0),
  1223. K_GATE(G_TIM3, RCC_APB1ENSETR, 1, 0),
  1224. K_GATE(G_TIM2, RCC_APB1ENSETR, 0, 0),
  1225. K_MGATE(G_FDCAN, RCC_APB2ENSETR, 24, 0),
  1226. K_GATE(G_ADFSDM, RCC_APB2ENSETR, 21, 0),
  1227. K_GATE(G_DFSDM, RCC_APB2ENSETR, 20, 0),
  1228. K_MGATE(G_SAI3, RCC_APB2ENSETR, 18, 0),
  1229. K_MGATE(G_SAI2, RCC_APB2ENSETR, 17, 0),
  1230. K_MGATE(G_SAI1, RCC_APB2ENSETR, 16, 0),
  1231. K_MGATE(G_USART6, RCC_APB2ENSETR, 13, 0),
  1232. K_MGATE(G_SPI5, RCC_APB2ENSETR, 10, 0),
  1233. K_MGATE(G_SPI4, RCC_APB2ENSETR, 9, 0),
  1234. K_MGATE(G_SPI1, RCC_APB2ENSETR, 8, 0),
  1235. K_GATE(G_TIM17, RCC_APB2ENSETR, 4, 0),
  1236. K_GATE(G_TIM16, RCC_APB2ENSETR, 3, 0),
  1237. K_GATE(G_TIM15, RCC_APB2ENSETR, 2, 0),
  1238. K_GATE(G_TIM8, RCC_APB2ENSETR, 1, 0),
  1239. K_GATE(G_TIM1, RCC_APB2ENSETR, 0, 0),
  1240. K_GATE(G_HDP, RCC_APB3ENSETR, 20, 0),
  1241. K_GATE(G_PMBCTRL, RCC_APB3ENSETR, 17, 0),
  1242. K_GATE(G_TMPSENS, RCC_APB3ENSETR, 16, 0),
  1243. K_GATE(G_VREF, RCC_APB3ENSETR, 13, 0),
  1244. K_GATE(G_SYSCFG, RCC_APB3ENSETR, 11, 0),
  1245. K_MGATE(G_SAI4, RCC_APB3ENSETR, 8, 0),
  1246. K_MGATE(G_LPTIM5, RCC_APB3ENSETR, 3, 0),
  1247. K_MGATE(G_LPTIM4, RCC_APB3ENSETR, 2, 0),
  1248. K_MGATE(G_LPTIM3, RCC_APB3ENSETR, 1, 0),
  1249. K_MGATE(G_LPTIM2, RCC_APB3ENSETR, 0, 0),
  1250. K_GATE(G_STGENRO, RCC_APB4ENSETR, 20, 0),
  1251. K_MGATE(G_USBPHY, RCC_APB4ENSETR, 16, 0),
  1252. K_GATE(G_IWDG2, RCC_APB4ENSETR, 15, 0),
  1253. K_MGATE(G_DSI, RCC_APB4ENSETR, 4, 0),
  1254. K_MGATE(G_LTDC, RCC_APB4ENSETR, 0, 0),
  1255. K_GATE(G_STGEN, RCC_APB5ENSETR, 20, 0),
  1256. K_GATE(G_BSEC, RCC_APB5ENSETR, 16, 0),
  1257. K_GATE(G_IWDG1, RCC_APB5ENSETR, 15, 0),
  1258. K_GATE(G_TZPC, RCC_APB5ENSETR, 13, 0),
  1259. K_GATE(G_TZC, RCC_APB5ENSETR, 12, 0),
  1260. K_GATE(G_RTCAPB, RCC_APB5ENSETR, 8, 0),
  1261. K_MGATE(G_USART1, RCC_APB5ENSETR, 4, 0),
  1262. K_MGATE(G_I2C6, RCC_APB5ENSETR, 3, 0),
  1263. K_MGATE(G_I2C4, RCC_APB5ENSETR, 2, 0),
  1264. K_MGATE(G_SPI6, RCC_APB5ENSETR, 0, 0),
  1265. K_MGATE(G_SDMMC3, RCC_AHB2ENSETR, 16, 0),
  1266. K_MGATE(G_USBO, RCC_AHB2ENSETR, 8, 0),
  1267. K_MGATE(G_ADC12, RCC_AHB2ENSETR, 5, 0),
  1268. K_GATE(G_DMAMUX, RCC_AHB2ENSETR, 2, 0),
  1269. K_GATE(G_DMA2, RCC_AHB2ENSETR, 1, 0),
  1270. K_GATE(G_DMA1, RCC_AHB2ENSETR, 0, 0),
  1271. K_GATE(G_IPCC, RCC_AHB3ENSETR, 12, 0),
  1272. K_GATE(G_HSEM, RCC_AHB3ENSETR, 11, 0),
  1273. K_GATE(G_CRC2, RCC_AHB3ENSETR, 7, 0),
  1274. K_MGATE(G_RNG2, RCC_AHB3ENSETR, 6, 0),
  1275. K_GATE(G_HASH2, RCC_AHB3ENSETR, 5, 0),
  1276. K_GATE(G_CRYP2, RCC_AHB3ENSETR, 4, 0),
  1277. K_GATE(G_DCMI, RCC_AHB3ENSETR, 0, 0),
  1278. K_GATE(G_GPIOK, RCC_AHB4ENSETR, 10, 0),
  1279. K_GATE(G_GPIOJ, RCC_AHB4ENSETR, 9, 0),
  1280. K_GATE(G_GPIOI, RCC_AHB4ENSETR, 8, 0),
  1281. K_GATE(G_GPIOH, RCC_AHB4ENSETR, 7, 0),
  1282. K_GATE(G_GPIOG, RCC_AHB4ENSETR, 6, 0),
  1283. K_GATE(G_GPIOF, RCC_AHB4ENSETR, 5, 0),
  1284. K_GATE(G_GPIOE, RCC_AHB4ENSETR, 4, 0),
  1285. K_GATE(G_GPIOD, RCC_AHB4ENSETR, 3, 0),
  1286. K_GATE(G_GPIOC, RCC_AHB4ENSETR, 2, 0),
  1287. K_GATE(G_GPIOB, RCC_AHB4ENSETR, 1, 0),
  1288. K_GATE(G_GPIOA, RCC_AHB4ENSETR, 0, 0),
  1289. K_GATE(G_BKPSRAM, RCC_AHB5ENSETR, 8, 0),
  1290. K_MGATE(G_RNG1, RCC_AHB5ENSETR, 6, 0),
  1291. K_GATE(G_HASH1, RCC_AHB5ENSETR, 5, 0),
  1292. K_GATE(G_CRYP1, RCC_AHB5ENSETR, 4, 0),
  1293. K_GATE(G_GPIOZ, RCC_AHB5ENSETR, 0, 0),
  1294. K_GATE(G_USBH, RCC_AHB6ENSETR, 24, 0),
  1295. K_GATE(G_CRC1, RCC_AHB6ENSETR, 20, 0),
  1296. K_MGATE(G_SDMMC2, RCC_AHB6ENSETR, 17, 0),
  1297. K_MGATE(G_SDMMC1, RCC_AHB6ENSETR, 16, 0),
  1298. K_MGATE(G_QSPI, RCC_AHB6ENSETR, 14, 0),
  1299. K_MGATE(G_FMC, RCC_AHB6ENSETR, 12, 0),
  1300. K_GATE(G_ETHMAC, RCC_AHB6ENSETR, 10, 0),
  1301. K_GATE(G_ETHRX, RCC_AHB6ENSETR, 9, 0),
  1302. K_GATE(G_ETHTX, RCC_AHB6ENSETR, 8, 0),
  1303. K_GATE(G_ETHCK, RCC_AHB6ENSETR, 7, 0),
  1304. K_MGATE(G_GPU, RCC_AHB6ENSETR, 5, 0),
  1305. K_GATE(G_MDMA, RCC_AHB6ENSETR, 0, 0),
  1306. K_GATE(G_ETHSTP, RCC_AHB6LPENSETR, 11, 0),
  1307. };
  1308. enum {
  1309. M_SDMMC12,
  1310. M_SDMMC3,
  1311. M_FMC,
  1312. M_QSPI,
  1313. M_RNG1,
  1314. M_RNG2,
  1315. M_USBPHY,
  1316. M_USBO,
  1317. M_STGEN,
  1318. M_SPDIF,
  1319. M_SPI1,
  1320. M_SPI23,
  1321. M_SPI45,
  1322. M_SPI6,
  1323. M_CEC,
  1324. M_I2C12,
  1325. M_I2C35,
  1326. M_I2C46,
  1327. M_LPTIM1,
  1328. M_LPTIM23,
  1329. M_LPTIM45,
  1330. M_USART1,
  1331. M_UART24,
  1332. M_UART35,
  1333. M_USART6,
  1334. M_UART78,
  1335. M_SAI1,
  1336. M_SAI2,
  1337. M_SAI3,
  1338. M_SAI4,
  1339. M_DSI,
  1340. M_FDCAN,
  1341. M_ADC12,
  1342. M_ETHCK,
  1343. M_CKPER,
  1344. M_LAST
  1345. };
  1346. struct stm32_mmux ker_mux[M_LAST];
  1347. #define _K_MUX(_id, _offset, _shift, _width, _mux_flags, _mmux, _ops)\
  1348. [_id] = {\
  1349. &(struct mux_cfg) {\
  1350. .reg_off = _offset,\
  1351. .shift = _shift,\
  1352. .width = _width,\
  1353. .mux_flags = _mux_flags,\
  1354. .table = NULL,\
  1355. },\
  1356. .mmux = _mmux,\
  1357. .ops = _ops,\
  1358. }
  1359. #define K_MUX(_id, _offset, _shift, _width, _mux_flags)\
  1360. _K_MUX(_id, _offset, _shift, _width, _mux_flags,\
  1361. NULL, NULL)
  1362. #define K_MMUX(_id, _offset, _shift, _width, _mux_flags)\
  1363. _K_MUX(_id, _offset, _shift, _width, _mux_flags,\
  1364. &ker_mux[_id], &clk_mmux_ops)
  1365. const struct stm32_mux_cfg ker_mux_cfg[M_LAST] = {
  1366. /* Kernel multi mux */
  1367. K_MMUX(M_SDMMC12, RCC_SDMMC12CKSELR, 0, 3, 0),
  1368. K_MMUX(M_SPI23, RCC_SPI2S23CKSELR, 0, 3, 0),
  1369. K_MMUX(M_SPI45, RCC_SPI2S45CKSELR, 0, 3, 0),
  1370. K_MMUX(M_I2C12, RCC_I2C12CKSELR, 0, 3, 0),
  1371. K_MMUX(M_I2C35, RCC_I2C35CKSELR, 0, 3, 0),
  1372. K_MMUX(M_LPTIM23, RCC_LPTIM23CKSELR, 0, 3, 0),
  1373. K_MMUX(M_LPTIM45, RCC_LPTIM45CKSELR, 0, 3, 0),
  1374. K_MMUX(M_UART24, RCC_UART24CKSELR, 0, 3, 0),
  1375. K_MMUX(M_UART35, RCC_UART35CKSELR, 0, 3, 0),
  1376. K_MMUX(M_UART78, RCC_UART78CKSELR, 0, 3, 0),
  1377. K_MMUX(M_SAI1, RCC_SAI1CKSELR, 0, 3, 0),
  1378. K_MMUX(M_ETHCK, RCC_ETHCKSELR, 0, 2, 0),
  1379. K_MMUX(M_I2C46, RCC_I2C46CKSELR, 0, 3, 0),
  1380. /* Kernel simple mux */
  1381. K_MUX(M_RNG2, RCC_RNG2CKSELR, 0, 2, 0),
  1382. K_MUX(M_SDMMC3, RCC_SDMMC3CKSELR, 0, 3, 0),
  1383. K_MUX(M_FMC, RCC_FMCCKSELR, 0, 2, 0),
  1384. K_MUX(M_QSPI, RCC_QSPICKSELR, 0, 2, 0),
  1385. K_MUX(M_USBPHY, RCC_USBCKSELR, 0, 2, 0),
  1386. K_MUX(M_USBO, RCC_USBCKSELR, 4, 1, 0),
  1387. K_MUX(M_SPDIF, RCC_SPDIFCKSELR, 0, 2, 0),
  1388. K_MUX(M_SPI1, RCC_SPI2S1CKSELR, 0, 3, 0),
  1389. K_MUX(M_CEC, RCC_CECCKSELR, 0, 2, 0),
  1390. K_MUX(M_LPTIM1, RCC_LPTIM1CKSELR, 0, 3, 0),
  1391. K_MUX(M_USART6, RCC_UART6CKSELR, 0, 3, 0),
  1392. K_MUX(M_FDCAN, RCC_FDCANCKSELR, 0, 2, 0),
  1393. K_MUX(M_SAI2, RCC_SAI2CKSELR, 0, 3, 0),
  1394. K_MUX(M_SAI3, RCC_SAI3CKSELR, 0, 3, 0),
  1395. K_MUX(M_SAI4, RCC_SAI4CKSELR, 0, 3, 0),
  1396. K_MUX(M_ADC12, RCC_ADCCKSELR, 0, 2, 0),
  1397. K_MUX(M_DSI, RCC_DSICKSELR, 0, 1, 0),
  1398. K_MUX(M_CKPER, RCC_CPERCKSELR, 0, 2, 0),
  1399. K_MUX(M_RNG1, RCC_RNG1CKSELR, 0, 2, 0),
  1400. K_MUX(M_STGEN, RCC_STGENCKSELR, 0, 2, 0),
  1401. K_MUX(M_USART1, RCC_UART1CKSELR, 0, 3, 0),
  1402. K_MUX(M_SPI6, RCC_SPI6CKSELR, 0, 3, 0),
  1403. };
  1404. static const struct clock_config stm32mp1_clock_cfg[] = {
  1405. /* Oscillator divider */
  1406. DIV(NO_ID, "clk-hsi-div", "clk-hsi", 0, RCC_HSICFGR, 0, 2,
  1407. CLK_DIVIDER_READ_ONLY),
  1408. /* External / Internal Oscillators */
  1409. GATE_MP1(CK_HSE, "ck_hse", "clk-hse", 0, RCC_OCENSETR, 8, 0),
  1410. GATE_MP1(CK_CSI, "ck_csi", "clk-csi", 0, RCC_OCENSETR, 4, 0),
  1411. GATE_MP1(CK_HSI, "ck_hsi", "clk-hsi-div", 0, RCC_OCENSETR, 0, 0),
  1412. GATE(CK_LSI, "ck_lsi", "clk-lsi", 0, RCC_RDLSICR, 0, 0),
  1413. GATE(CK_LSE, "ck_lse", "clk-lse", 0, RCC_BDCR, 0, 0),
  1414. FIXED_FACTOR(CK_HSE_DIV2, "clk-hse-div2", "ck_hse", 0, 1, 2),
  1415. /* ref clock pll */
  1416. MUX(NO_ID, "ref1", ref12_parents, CLK_OPS_PARENT_ENABLE, RCC_RCK12SELR,
  1417. 0, 2, CLK_MUX_READ_ONLY),
  1418. MUX(NO_ID, "ref3", ref3_parents, CLK_OPS_PARENT_ENABLE, RCC_RCK3SELR,
  1419. 0, 2, CLK_MUX_READ_ONLY),
  1420. MUX(NO_ID, "ref4", ref4_parents, CLK_OPS_PARENT_ENABLE, RCC_RCK4SELR,
  1421. 0, 2, CLK_MUX_READ_ONLY),
  1422. /* PLLs */
  1423. PLL(PLL1, "pll1", "ref1", CLK_IGNORE_UNUSED, RCC_PLL1CR),
  1424. PLL(PLL2, "pll2", "ref1", CLK_IGNORE_UNUSED, RCC_PLL2CR),
  1425. PLL(PLL3, "pll3", "ref3", CLK_IGNORE_UNUSED, RCC_PLL3CR),
  1426. PLL(PLL4, "pll4", "ref4", CLK_IGNORE_UNUSED, RCC_PLL4CR),
  1427. /* ODF */
  1428. COMPOSITE(PLL1_P, "pll1_p", PARENT("pll1"), 0,
  1429. _GATE(RCC_PLL1CR, 4, 0),
  1430. _NO_MUX,
  1431. _DIV(RCC_PLL1CFGR2, 0, 7, 0, NULL)),
  1432. COMPOSITE(PLL2_P, "pll2_p", PARENT("pll2"), 0,
  1433. _GATE(RCC_PLL2CR, 4, 0),
  1434. _NO_MUX,
  1435. _DIV(RCC_PLL2CFGR2, 0, 7, 0, NULL)),
  1436. COMPOSITE(PLL2_Q, "pll2_q", PARENT("pll2"), 0,
  1437. _GATE(RCC_PLL2CR, 5, 0),
  1438. _NO_MUX,
  1439. _DIV(RCC_PLL2CFGR2, 8, 7, 0, NULL)),
  1440. COMPOSITE(PLL2_R, "pll2_r", PARENT("pll2"), CLK_IS_CRITICAL,
  1441. _GATE(RCC_PLL2CR, 6, 0),
  1442. _NO_MUX,
  1443. _DIV(RCC_PLL2CFGR2, 16, 7, 0, NULL)),
  1444. COMPOSITE(PLL3_P, "pll3_p", PARENT("pll3"), 0,
  1445. _GATE(RCC_PLL3CR, 4, 0),
  1446. _NO_MUX,
  1447. _DIV(RCC_PLL3CFGR2, 0, 7, 0, NULL)),
  1448. COMPOSITE(PLL3_Q, "pll3_q", PARENT("pll3"), 0,
  1449. _GATE(RCC_PLL3CR, 5, 0),
  1450. _NO_MUX,
  1451. _DIV(RCC_PLL3CFGR2, 8, 7, 0, NULL)),
  1452. COMPOSITE(PLL3_R, "pll3_r", PARENT("pll3"), 0,
  1453. _GATE(RCC_PLL3CR, 6, 0),
  1454. _NO_MUX,
  1455. _DIV(RCC_PLL3CFGR2, 16, 7, 0, NULL)),
  1456. COMPOSITE(PLL4_P, "pll4_p", PARENT("pll4"), 0,
  1457. _GATE(RCC_PLL4CR, 4, 0),
  1458. _NO_MUX,
  1459. _DIV(RCC_PLL4CFGR2, 0, 7, 0, NULL)),
  1460. COMPOSITE(PLL4_Q, "pll4_q", PARENT("pll4"), 0,
  1461. _GATE(RCC_PLL4CR, 5, 0),
  1462. _NO_MUX,
  1463. _DIV(RCC_PLL4CFGR2, 8, 7, 0, NULL)),
  1464. COMPOSITE(PLL4_R, "pll4_r", PARENT("pll4"), 0,
  1465. _GATE(RCC_PLL4CR, 6, 0),
  1466. _NO_MUX,
  1467. _DIV(RCC_PLL4CFGR2, 16, 7, 0, NULL)),
  1468. /* MUX system clocks */
  1469. MUX(CK_PER, "ck_per", per_src, CLK_OPS_PARENT_ENABLE,
  1470. RCC_CPERCKSELR, 0, 2, 0),
  1471. MUX(CK_MPU, "ck_mpu", cpu_src, CLK_OPS_PARENT_ENABLE |
  1472. CLK_IS_CRITICAL, RCC_MPCKSELR, 0, 2, 0),
  1473. COMPOSITE(CK_AXI, "ck_axi", axi_src, CLK_IS_CRITICAL |
  1474. CLK_OPS_PARENT_ENABLE,
  1475. _NO_GATE,
  1476. _MUX(RCC_ASSCKSELR, 0, 2, 0),
  1477. _DIV(RCC_AXIDIVR, 0, 3, 0, axi_div_table)),
  1478. COMPOSITE(CK_MCU, "ck_mcu", mcu_src, CLK_IS_CRITICAL |
  1479. CLK_OPS_PARENT_ENABLE,
  1480. _NO_GATE,
  1481. _MUX(RCC_MSSCKSELR, 0, 2, 0),
  1482. _DIV(RCC_MCUDIVR, 0, 4, 0, mcu_div_table)),
  1483. DIV_TABLE(NO_ID, "pclk1", "ck_mcu", CLK_IGNORE_UNUSED, RCC_APB1DIVR, 0,
  1484. 3, CLK_DIVIDER_READ_ONLY, apb_div_table),
  1485. DIV_TABLE(NO_ID, "pclk2", "ck_mcu", CLK_IGNORE_UNUSED, RCC_APB2DIVR, 0,
  1486. 3, CLK_DIVIDER_READ_ONLY, apb_div_table),
  1487. DIV_TABLE(NO_ID, "pclk3", "ck_mcu", CLK_IGNORE_UNUSED, RCC_APB3DIVR, 0,
  1488. 3, CLK_DIVIDER_READ_ONLY, apb_div_table),
  1489. DIV_TABLE(NO_ID, "pclk4", "ck_axi", CLK_IGNORE_UNUSED, RCC_APB4DIVR, 0,
  1490. 3, CLK_DIVIDER_READ_ONLY, apb_div_table),
  1491. DIV_TABLE(NO_ID, "pclk5", "ck_axi", CLK_IGNORE_UNUSED, RCC_APB5DIVR, 0,
  1492. 3, CLK_DIVIDER_READ_ONLY, apb_div_table),
  1493. /* Kernel Timers */
  1494. STM32_CKTIM("ck1_tim", "pclk1", 0, RCC_APB1DIVR, RCC_TIMG1PRER),
  1495. STM32_CKTIM("ck2_tim", "pclk2", 0, RCC_APB2DIVR, RCC_TIMG2PRER),
  1496. STM32_TIM(TIM2_K, "tim2_k", "ck1_tim", RCC_APB1ENSETR, 0),
  1497. STM32_TIM(TIM3_K, "tim3_k", "ck1_tim", RCC_APB1ENSETR, 1),
  1498. STM32_TIM(TIM4_K, "tim4_k", "ck1_tim", RCC_APB1ENSETR, 2),
  1499. STM32_TIM(TIM5_K, "tim5_k", "ck1_tim", RCC_APB1ENSETR, 3),
  1500. STM32_TIM(TIM6_K, "tim6_k", "ck1_tim", RCC_APB1ENSETR, 4),
  1501. STM32_TIM(TIM7_K, "tim7_k", "ck1_tim", RCC_APB1ENSETR, 5),
  1502. STM32_TIM(TIM12_K, "tim12_k", "ck1_tim", RCC_APB1ENSETR, 6),
  1503. STM32_TIM(TIM13_K, "tim13_k", "ck1_tim", RCC_APB1ENSETR, 7),
  1504. STM32_TIM(TIM14_K, "tim14_k", "ck1_tim", RCC_APB1ENSETR, 8),
  1505. STM32_TIM(TIM1_K, "tim1_k", "ck2_tim", RCC_APB2ENSETR, 0),
  1506. STM32_TIM(TIM8_K, "tim8_k", "ck2_tim", RCC_APB2ENSETR, 1),
  1507. STM32_TIM(TIM15_K, "tim15_k", "ck2_tim", RCC_APB2ENSETR, 2),
  1508. STM32_TIM(TIM16_K, "tim16_k", "ck2_tim", RCC_APB2ENSETR, 3),
  1509. STM32_TIM(TIM17_K, "tim17_k", "ck2_tim", RCC_APB2ENSETR, 4),
  1510. /* Peripheral clocks */
  1511. PCLK(TIM2, "tim2", "pclk1", CLK_IGNORE_UNUSED, G_TIM2),
  1512. PCLK(TIM3, "tim3", "pclk1", CLK_IGNORE_UNUSED, G_TIM3),
  1513. PCLK(TIM4, "tim4", "pclk1", CLK_IGNORE_UNUSED, G_TIM4),
  1514. PCLK(TIM5, "tim5", "pclk1", CLK_IGNORE_UNUSED, G_TIM5),
  1515. PCLK(TIM6, "tim6", "pclk1", CLK_IGNORE_UNUSED, G_TIM6),
  1516. PCLK(TIM7, "tim7", "pclk1", CLK_IGNORE_UNUSED, G_TIM7),
  1517. PCLK(TIM12, "tim12", "pclk1", CLK_IGNORE_UNUSED, G_TIM12),
  1518. PCLK(TIM13, "tim13", "pclk1", CLK_IGNORE_UNUSED, G_TIM13),
  1519. PCLK(TIM14, "tim14", "pclk1", CLK_IGNORE_UNUSED, G_TIM14),
  1520. PCLK(LPTIM1, "lptim1", "pclk1", 0, G_LPTIM1),
  1521. PCLK(SPI2, "spi2", "pclk1", 0, G_SPI2),
  1522. PCLK(SPI3, "spi3", "pclk1", 0, G_SPI3),
  1523. PCLK(USART2, "usart2", "pclk1", 0, G_USART2),
  1524. PCLK(USART3, "usart3", "pclk1", 0, G_USART3),
  1525. PCLK(UART4, "uart4", "pclk1", 0, G_UART4),
  1526. PCLK(UART5, "uart5", "pclk1", 0, G_UART5),
  1527. PCLK(UART7, "uart7", "pclk1", 0, G_UART7),
  1528. PCLK(UART8, "uart8", "pclk1", 0, G_UART8),
  1529. PCLK(I2C1, "i2c1", "pclk1", 0, G_I2C1),
  1530. PCLK(I2C2, "i2c2", "pclk1", 0, G_I2C2),
  1531. PCLK(I2C3, "i2c3", "pclk1", 0, G_I2C3),
  1532. PCLK(I2C5, "i2c5", "pclk1", 0, G_I2C5),
  1533. PCLK(SPDIF, "spdif", "pclk1", 0, G_SPDIF),
  1534. PCLK(CEC, "cec", "pclk1", 0, G_CEC),
  1535. PCLK(DAC12, "dac12", "pclk1", 0, G_DAC12),
  1536. PCLK(MDIO, "mdio", "pclk1", 0, G_MDIO),
  1537. PCLK(TIM1, "tim1", "pclk2", CLK_IGNORE_UNUSED, G_TIM1),
  1538. PCLK(TIM8, "tim8", "pclk2", CLK_IGNORE_UNUSED, G_TIM8),
  1539. PCLK(TIM15, "tim15", "pclk2", CLK_IGNORE_UNUSED, G_TIM15),
  1540. PCLK(TIM16, "tim16", "pclk2", CLK_IGNORE_UNUSED, G_TIM16),
  1541. PCLK(TIM17, "tim17", "pclk2", CLK_IGNORE_UNUSED, G_TIM17),
  1542. PCLK(SPI1, "spi1", "pclk2", 0, G_SPI1),
  1543. PCLK(SPI4, "spi4", "pclk2", 0, G_SPI4),
  1544. PCLK(SPI5, "spi5", "pclk2", 0, G_SPI5),
  1545. PCLK(USART6, "usart6", "pclk2", 0, G_USART6),
  1546. PCLK(SAI1, "sai1", "pclk2", 0, G_SAI1),
  1547. PCLK(SAI2, "sai2", "pclk2", 0, G_SAI2),
  1548. PCLK(SAI3, "sai3", "pclk2", 0, G_SAI3),
  1549. PCLK(DFSDM, "dfsdm", "pclk2", 0, G_DFSDM),
  1550. PCLK(FDCAN, "fdcan", "pclk2", 0, G_FDCAN),
  1551. PCLK(LPTIM2, "lptim2", "pclk3", 0, G_LPTIM2),
  1552. PCLK(LPTIM3, "lptim3", "pclk3", 0, G_LPTIM3),
  1553. PCLK(LPTIM4, "lptim4", "pclk3", 0, G_LPTIM4),
  1554. PCLK(LPTIM5, "lptim5", "pclk3", 0, G_LPTIM5),
  1555. PCLK(SAI4, "sai4", "pclk3", 0, G_SAI4),
  1556. PCLK(SYSCFG, "syscfg", "pclk3", 0, G_SYSCFG),
  1557. PCLK(VREF, "vref", "pclk3", 13, G_VREF),
  1558. PCLK(TMPSENS, "tmpsens", "pclk3", 0, G_TMPSENS),
  1559. PCLK(PMBCTRL, "pmbctrl", "pclk3", 0, G_PMBCTRL),
  1560. PCLK(HDP, "hdp", "pclk3", 0, G_HDP),
  1561. PCLK(LTDC, "ltdc", "pclk4", 0, G_LTDC),
  1562. PCLK(DSI, "dsi", "pclk4", 0, G_DSI),
  1563. PCLK(IWDG2, "iwdg2", "pclk4", 0, G_IWDG2),
  1564. PCLK(USBPHY, "usbphy", "pclk4", 0, G_USBPHY),
  1565. PCLK(STGENRO, "stgenro", "pclk4", 0, G_STGENRO),
  1566. PCLK(SPI6, "spi6", "pclk5", 0, G_SPI6),
  1567. PCLK(I2C4, "i2c4", "pclk5", 0, G_I2C4),
  1568. PCLK(I2C6, "i2c6", "pclk5", 0, G_I2C6),
  1569. PCLK(USART1, "usart1", "pclk5", 0, G_USART1),
  1570. PCLK(RTCAPB, "rtcapb", "pclk5", CLK_IGNORE_UNUSED |
  1571. CLK_IS_CRITICAL, G_RTCAPB),
  1572. PCLK(TZC, "tzc", "pclk5", CLK_IGNORE_UNUSED, G_TZC),
  1573. PCLK(TZPC, "tzpc", "pclk5", CLK_IGNORE_UNUSED, G_TZPC),
  1574. PCLK(IWDG1, "iwdg1", "pclk5", 0, G_IWDG1),
  1575. PCLK(BSEC, "bsec", "pclk5", CLK_IGNORE_UNUSED, G_BSEC),
  1576. PCLK(STGEN, "stgen", "pclk5", CLK_IGNORE_UNUSED, G_STGEN),
  1577. PCLK(DMA1, "dma1", "ck_mcu", 0, G_DMA1),
  1578. PCLK(DMA2, "dma2", "ck_mcu", 0, G_DMA2),
  1579. PCLK(DMAMUX, "dmamux", "ck_mcu", 0, G_DMAMUX),
  1580. PCLK(ADC12, "adc12", "ck_mcu", 0, G_ADC12),
  1581. PCLK(USBO, "usbo", "ck_mcu", 0, G_USBO),
  1582. PCLK(SDMMC3, "sdmmc3", "ck_mcu", 0, G_SDMMC3),
  1583. PCLK(DCMI, "dcmi", "ck_mcu", 0, G_DCMI),
  1584. PCLK(CRYP2, "cryp2", "ck_mcu", 0, G_CRYP2),
  1585. PCLK(HASH2, "hash2", "ck_mcu", 0, G_HASH2),
  1586. PCLK(RNG2, "rng2", "ck_mcu", 0, G_RNG2),
  1587. PCLK(CRC2, "crc2", "ck_mcu", 0, G_CRC2),
  1588. PCLK(HSEM, "hsem", "ck_mcu", 0, G_HSEM),
  1589. PCLK(IPCC, "ipcc", "ck_mcu", 0, G_IPCC),
  1590. PCLK(GPIOA, "gpioa", "ck_mcu", 0, G_GPIOA),
  1591. PCLK(GPIOB, "gpiob", "ck_mcu", 0, G_GPIOB),
  1592. PCLK(GPIOC, "gpioc", "ck_mcu", 0, G_GPIOC),
  1593. PCLK(GPIOD, "gpiod", "ck_mcu", 0, G_GPIOD),
  1594. PCLK(GPIOE, "gpioe", "ck_mcu", 0, G_GPIOE),
  1595. PCLK(GPIOF, "gpiof", "ck_mcu", 0, G_GPIOF),
  1596. PCLK(GPIOG, "gpiog", "ck_mcu", 0, G_GPIOG),
  1597. PCLK(GPIOH, "gpioh", "ck_mcu", 0, G_GPIOH),
  1598. PCLK(GPIOI, "gpioi", "ck_mcu", 0, G_GPIOI),
  1599. PCLK(GPIOJ, "gpioj", "ck_mcu", 0, G_GPIOJ),
  1600. PCLK(GPIOK, "gpiok", "ck_mcu", 0, G_GPIOK),
  1601. PCLK(GPIOZ, "gpioz", "ck_axi", CLK_IGNORE_UNUSED, G_GPIOZ),
  1602. PCLK(CRYP1, "cryp1", "ck_axi", CLK_IGNORE_UNUSED, G_CRYP1),
  1603. PCLK(HASH1, "hash1", "ck_axi", CLK_IGNORE_UNUSED, G_HASH1),
  1604. PCLK(RNG1, "rng1", "ck_axi", 0, G_RNG1),
  1605. PCLK(BKPSRAM, "bkpsram", "ck_axi", CLK_IGNORE_UNUSED, G_BKPSRAM),
  1606. PCLK(MDMA, "mdma", "ck_axi", 0, G_MDMA),
  1607. PCLK(GPU, "gpu", "ck_axi", 0, G_GPU),
  1608. PCLK(ETHTX, "ethtx", "ck_axi", 0, G_ETHTX),
  1609. PCLK(ETHRX, "ethrx", "ck_axi", 0, G_ETHRX),
  1610. PCLK(ETHMAC, "ethmac", "ck_axi", 0, G_ETHMAC),
  1611. PCLK(FMC, "fmc", "ck_axi", CLK_IGNORE_UNUSED, G_FMC),
  1612. PCLK(QSPI, "qspi", "ck_axi", CLK_IGNORE_UNUSED, G_QSPI),
  1613. PCLK(SDMMC1, "sdmmc1", "ck_axi", 0, G_SDMMC1),
  1614. PCLK(SDMMC2, "sdmmc2", "ck_axi", 0, G_SDMMC2),
  1615. PCLK(CRC1, "crc1", "ck_axi", 0, G_CRC1),
  1616. PCLK(USBH, "usbh", "ck_axi", 0, G_USBH),
  1617. PCLK(ETHSTP, "ethstp", "ck_axi", 0, G_ETHSTP),
  1618. /* Kernel clocks */
  1619. KCLK(SDMMC1_K, "sdmmc1_k", sdmmc12_src, 0, G_SDMMC1, M_SDMMC12),
  1620. KCLK(SDMMC2_K, "sdmmc2_k", sdmmc12_src, 0, G_SDMMC2, M_SDMMC12),
  1621. KCLK(SDMMC3_K, "sdmmc3_k", sdmmc3_src, 0, G_SDMMC3, M_SDMMC3),
  1622. KCLK(FMC_K, "fmc_k", fmc_src, 0, G_FMC, M_FMC),
  1623. KCLK(QSPI_K, "qspi_k", qspi_src, 0, G_QSPI, M_QSPI),
  1624. KCLK(RNG1_K, "rng1_k", rng_src, 0, G_RNG1, M_RNG1),
  1625. KCLK(RNG2_K, "rng2_k", rng_src, 0, G_RNG2, M_RNG2),
  1626. KCLK(USBPHY_K, "usbphy_k", usbphy_src, 0, G_USBPHY, M_USBPHY),
  1627. KCLK(STGEN_K, "stgen_k", stgen_src, CLK_IGNORE_UNUSED,
  1628. G_STGEN, M_STGEN),
  1629. KCLK(SPDIF_K, "spdif_k", spdif_src, 0, G_SPDIF, M_SPDIF),
  1630. KCLK(SPI1_K, "spi1_k", spi123_src, 0, G_SPI1, M_SPI1),
  1631. KCLK(SPI2_K, "spi2_k", spi123_src, 0, G_SPI2, M_SPI23),
  1632. KCLK(SPI3_K, "spi3_k", spi123_src, 0, G_SPI3, M_SPI23),
  1633. KCLK(SPI4_K, "spi4_k", spi45_src, 0, G_SPI4, M_SPI45),
  1634. KCLK(SPI5_K, "spi5_k", spi45_src, 0, G_SPI5, M_SPI45),
  1635. KCLK(SPI6_K, "spi6_k", spi6_src, 0, G_SPI6, M_SPI6),
  1636. KCLK(CEC_K, "cec_k", cec_src, 0, G_CEC, M_CEC),
  1637. KCLK(I2C1_K, "i2c1_k", i2c12_src, 0, G_I2C1, M_I2C12),
  1638. KCLK(I2C2_K, "i2c2_k", i2c12_src, 0, G_I2C2, M_I2C12),
  1639. KCLK(I2C3_K, "i2c3_k", i2c35_src, 0, G_I2C3, M_I2C35),
  1640. KCLK(I2C5_K, "i2c5_k", i2c35_src, 0, G_I2C5, M_I2C35),
  1641. KCLK(I2C4_K, "i2c4_k", i2c46_src, 0, G_I2C4, M_I2C46),
  1642. KCLK(I2C6_K, "i2c6_k", i2c46_src, 0, G_I2C6, M_I2C46),
  1643. KCLK(LPTIM1_K, "lptim1_k", lptim1_src, 0, G_LPTIM1, M_LPTIM1),
  1644. KCLK(LPTIM2_K, "lptim2_k", lptim23_src, 0, G_LPTIM2, M_LPTIM23),
  1645. KCLK(LPTIM3_K, "lptim3_k", lptim23_src, 0, G_LPTIM3, M_LPTIM23),
  1646. KCLK(LPTIM4_K, "lptim4_k", lptim45_src, 0, G_LPTIM4, M_LPTIM45),
  1647. KCLK(LPTIM5_K, "lptim5_k", lptim45_src, 0, G_LPTIM5, M_LPTIM45),
  1648. KCLK(USART1_K, "usart1_k", usart1_src, 0, G_USART1, M_USART1),
  1649. KCLK(USART2_K, "usart2_k", usart234578_src, 0, G_USART2, M_UART24),
  1650. KCLK(USART3_K, "usart3_k", usart234578_src, 0, G_USART3, M_UART35),
  1651. KCLK(UART4_K, "uart4_k", usart234578_src, 0, G_UART4, M_UART24),
  1652. KCLK(UART5_K, "uart5_k", usart234578_src, 0, G_UART5, M_UART35),
  1653. KCLK(USART6_K, "uart6_k", usart6_src, 0, G_USART6, M_USART6),
  1654. KCLK(UART7_K, "uart7_k", usart234578_src, 0, G_UART7, M_UART78),
  1655. KCLK(UART8_K, "uart8_k", usart234578_src, 0, G_UART8, M_UART78),
  1656. KCLK(FDCAN_K, "fdcan_k", fdcan_src, 0, G_FDCAN, M_FDCAN),
  1657. KCLK(SAI1_K, "sai1_k", sai_src, 0, G_SAI1, M_SAI1),
  1658. KCLK(SAI2_K, "sai2_k", sai2_src, 0, G_SAI2, M_SAI2),
  1659. KCLK(SAI3_K, "sai3_k", sai_src, 0, G_SAI2, M_SAI3),
  1660. KCLK(SAI4_K, "sai4_k", sai_src, 0, G_SAI2, M_SAI4),
  1661. KCLK(ADC12_K, "adc12_k", adc12_src, 0, G_ADC12, M_ADC12),
  1662. KCLK(DSI_K, "dsi_k", dsi_src, 0, G_DSI, M_DSI),
  1663. KCLK(ADFSDM_K, "adfsdm_k", sai_src, 0, G_ADFSDM, M_SAI1),
  1664. KCLK(USBO_K, "usbo_k", usbo_src, 0, G_USBO, M_USBO),
  1665. KCLK(ETHCK_K, "ethck_k", eth_src, 0, G_ETHCK, M_ETHCK),
  1666. /* Particulary Kernel Clocks (no mux or no gate) */
  1667. MGATE_MP1(DFSDM_K, "dfsdm_k", "ck_mcu", 0, G_DFSDM),
  1668. MGATE_MP1(DSI_PX, "dsi_px", "pll4_q", CLK_SET_RATE_PARENT, G_DSI),
  1669. MGATE_MP1(LTDC_PX, "ltdc_px", "pll4_q", CLK_SET_RATE_PARENT, G_LTDC),
  1670. MGATE_MP1(GPU_K, "gpu_k", "pll2_q", 0, G_GPU),
  1671. MGATE_MP1(DAC12_K, "dac12_k", "ck_lsi", 0, G_DAC12),
  1672. COMPOSITE(ETHPTP_K, "ethptp_k", eth_src, CLK_OPS_PARENT_ENABLE,
  1673. _NO_GATE,
  1674. _MMUX(M_ETHCK),
  1675. _DIV(RCC_ETHCKSELR, 4, 4, CLK_DIVIDER_ALLOW_ZERO, NULL)),
  1676. /* RTC clock */
  1677. DIV(NO_ID, "ck_hse_rtc", "ck_hse", 0, RCC_RTCDIVR, 0, 7,
  1678. CLK_DIVIDER_ALLOW_ZERO),
  1679. COMPOSITE(RTC, "ck_rtc", rtc_src, CLK_OPS_PARENT_ENABLE |
  1680. CLK_SET_RATE_PARENT,
  1681. _GATE(RCC_BDCR, 20, 0),
  1682. _MUX(RCC_BDCR, 16, 2, 0),
  1683. _NO_DIV),
  1684. /* MCO clocks */
  1685. COMPOSITE(CK_MCO1, "ck_mco1", mco1_src, CLK_OPS_PARENT_ENABLE |
  1686. CLK_SET_RATE_NO_REPARENT,
  1687. _GATE(RCC_MCO1CFGR, 12, 0),
  1688. _MUX(RCC_MCO1CFGR, 0, 3, 0),
  1689. _DIV(RCC_MCO1CFGR, 4, 4, 0, NULL)),
  1690. COMPOSITE(CK_MCO2, "ck_mco2", mco2_src, CLK_OPS_PARENT_ENABLE |
  1691. CLK_SET_RATE_NO_REPARENT,
  1692. _GATE(RCC_MCO2CFGR, 12, 0),
  1693. _MUX(RCC_MCO2CFGR, 0, 3, 0),
  1694. _DIV(RCC_MCO2CFGR, 4, 4, 0, NULL)),
  1695. /* Debug clocks */
  1696. FIXED_FACTOR(NO_ID, "ck_axi_div2", "ck_axi", 0, 1, 2),
  1697. GATE(DBG, "ck_apb_dbg", "ck_axi_div2", 0, RCC_DBGCFGR, 8, 0),
  1698. GATE(CK_DBG, "ck_sys_dbg", "ck_axi", 0, RCC_DBGCFGR, 8, 0),
  1699. COMPOSITE(CK_TRACE, "ck_trace", ck_trace_src, CLK_OPS_PARENT_ENABLE,
  1700. _GATE(RCC_DBGCFGR, 9, 0),
  1701. _NO_MUX,
  1702. _DIV(RCC_DBGCFGR, 0, 3, 0, ck_trace_div_table)),
  1703. };
  1704. struct stm32_clock_match_data {
  1705. const struct clock_config *cfg;
  1706. unsigned int num;
  1707. unsigned int maxbinding;
  1708. };
  1709. static struct stm32_clock_match_data stm32mp1_data = {
  1710. .cfg = stm32mp1_clock_cfg,
  1711. .num = ARRAY_SIZE(stm32mp1_clock_cfg),
  1712. .maxbinding = STM32MP1_LAST_CLK,
  1713. };
  1714. static const struct of_device_id stm32mp1_match_data[] = {
  1715. {
  1716. .compatible = "st,stm32mp1-rcc",
  1717. .data = &stm32mp1_data,
  1718. },
  1719. { }
  1720. };
  1721. static int stm32_register_hw_clk(struct device *dev,
  1722. struct clk_hw_onecell_data *clk_data,
  1723. void __iomem *base, spinlock_t *lock,
  1724. const struct clock_config *cfg)
  1725. {
  1726. static struct clk_hw **hws;
  1727. struct clk_hw *hw = ERR_PTR(-ENOENT);
  1728. hws = clk_data->hws;
  1729. if (cfg->func)
  1730. hw = (*cfg->func)(dev, clk_data, base, lock, cfg);
  1731. if (IS_ERR(hw)) {
  1732. pr_err("Unable to register %s\n", cfg->name);
  1733. return PTR_ERR(hw);
  1734. }
  1735. if (cfg->id != NO_ID)
  1736. hws[cfg->id] = hw;
  1737. return 0;
  1738. }
  1739. static int stm32_rcc_init(struct device_node *np,
  1740. void __iomem *base,
  1741. const struct of_device_id *match_data)
  1742. {
  1743. struct clk_hw_onecell_data *clk_data;
  1744. struct clk_hw **hws;
  1745. const struct of_device_id *match;
  1746. const struct stm32_clock_match_data *data;
  1747. int err, n, max_binding;
  1748. match = of_match_node(match_data, np);
  1749. if (!match) {
  1750. pr_err("%s: match data not found\n", __func__);
  1751. return -ENODEV;
  1752. }
  1753. data = match->data;
  1754. max_binding = data->maxbinding;
  1755. clk_data = kzalloc(sizeof(*clk_data) +
  1756. sizeof(*clk_data->hws) * max_binding,
  1757. GFP_KERNEL);
  1758. if (!clk_data)
  1759. return -ENOMEM;
  1760. clk_data->num = max_binding;
  1761. hws = clk_data->hws;
  1762. for (n = 0; n < max_binding; n++)
  1763. hws[n] = ERR_PTR(-ENOENT);
  1764. for (n = 0; n < data->num; n++) {
  1765. err = stm32_register_hw_clk(NULL, clk_data, base, &rlock,
  1766. &data->cfg[n]);
  1767. if (err) {
  1768. pr_err("%s: can't register %s\n", __func__,
  1769. data->cfg[n].name);
  1770. kfree(clk_data);
  1771. return err;
  1772. }
  1773. }
  1774. return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
  1775. }
  1776. static void stm32mp1_rcc_init(struct device_node *np)
  1777. {
  1778. void __iomem *base;
  1779. base = of_iomap(np, 0);
  1780. if (!base) {
  1781. pr_err("%s: unable to map resource", np->name);
  1782. of_node_put(np);
  1783. return;
  1784. }
  1785. if (stm32_rcc_init(np, base, stm32mp1_match_data)) {
  1786. iounmap(base);
  1787. of_node_put(np);
  1788. }
  1789. }
  1790. CLK_OF_DECLARE_DRIVER(stm32mp1_rcc, "st,stm32mp1-rcc", stm32mp1_rcc_init);