clk-stm32mp1.c 54 KB

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