clk-stm32mp2.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357
  1. /*
  2. * Copyright (C) 2024, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <limits.h>
  9. #include <stdint.h>
  10. #include "clk-stm32-core.h"
  11. #include <common/fdt_wrappers.h>
  12. #include <drivers/clk.h>
  13. #include <drivers/delay_timer.h>
  14. #include <drivers/generic_delay_timer.h>
  15. #include <drivers/st/stm32mp2_clk.h>
  16. #include <drivers/st/stm32mp_clkfunc.h>
  17. #include <lib/mmio.h>
  18. #include <lib/spinlock.h>
  19. #include <lib/utils_def.h>
  20. #include <libfdt.h>
  21. #include <platform_def.h>
  22. struct stm32_osci_dt_cfg {
  23. unsigned long freq;
  24. uint32_t drive;
  25. bool bypass;
  26. bool digbyp;
  27. bool css;
  28. };
  29. struct stm32_pll_dt_cfg {
  30. uint32_t src;
  31. uint32_t frac;
  32. uint32_t cfg[PLLCFG_NB];
  33. uint32_t csg[PLLCSG_NB];
  34. bool csg_enabled;
  35. bool enabled;
  36. };
  37. struct stm32_clk_platdata {
  38. uintptr_t rcc_base;
  39. uint32_t nosci;
  40. struct stm32_osci_dt_cfg *osci;
  41. uint32_t npll;
  42. struct stm32_pll_dt_cfg *pll;
  43. uint32_t nflexgen;
  44. uint32_t *flexgen;
  45. uint32_t nbusclk;
  46. uint32_t *busclk;
  47. uint32_t nkernelclk;
  48. uint32_t *kernelclk;
  49. };
  50. /* A35 Sub-System which manages its own PLL (PLL1) */
  51. #define A35_SS_CHGCLKREQ 0x0000
  52. #define A35_SS_PLL_FREQ1 0x0080
  53. #define A35_SS_PLL_FREQ2 0x0090
  54. #define A35_SS_PLL_ENABLE 0x00a0
  55. #define A35_SS_CHGCLKREQ_ARM_CHGCLKREQ BIT(0)
  56. #define A35_SS_CHGCLKREQ_ARM_CHGCLKACK BIT(1)
  57. #define A35_SS_PLL_FREQ1_FBDIV_MASK GENMASK(11, 0)
  58. #define A35_SS_PLL_FREQ1_FBDIV_SHIFT 0
  59. #define A35_SS_PLL_FREQ1_REFDIV_MASK GENMASK(21, 16)
  60. #define A35_SS_PLL_FREQ1_REFDIV_SHIFT 16
  61. #define A35_SS_PLL_FREQ2_POSTDIV1_MASK GENMASK(2, 0)
  62. #define A35_SS_PLL_FREQ2_POSTDIV1_SHIFT 0
  63. #define A35_SS_PLL_FREQ2_POSTDIV2_MASK GENMASK(5, 3)
  64. #define A35_SS_PLL_FREQ2_POSTDIV2_SHIFT 3
  65. #define A35_SS_PLL_ENABLE_PD BIT(0)
  66. #define A35_SS_PLL_ENABLE_LOCKP BIT(1)
  67. #define A35_SS_PLL_ENABLE_NRESET_SWPLL_FF BIT(2)
  68. #define TIMEOUT_US_200MS U(200000)
  69. #define TIMEOUT_US_1S U(1000000)
  70. #define PLLRDY_TIMEOUT TIMEOUT_US_200MS
  71. #define CLKSRC_TIMEOUT TIMEOUT_US_200MS
  72. #define CLKDIV_TIMEOUT TIMEOUT_US_200MS
  73. #define OSCRDY_TIMEOUT TIMEOUT_US_1S
  74. /* PLL minimal frequencies for clock sources */
  75. #define PLL_REFCLK_MIN UL(5000000)
  76. #define PLL_FRAC_REFCLK_MIN UL(10000000)
  77. #define XBAR_CHANNEL_NB 64
  78. /* Warning, should be start to 1 */
  79. enum clock {
  80. _CK_0_MHZ,
  81. /* ROOT CLOCKS */
  82. _CK_HSI,
  83. _CK_HSE,
  84. _CK_MSI,
  85. _CK_LSI,
  86. _CK_LSE,
  87. _I2SCKIN,
  88. _SPDIFSYMB,
  89. _CK_PLL1,
  90. _CK_PLL2,
  91. _CK_PLL3,
  92. _CK_PLL4,
  93. _CK_PLL5,
  94. _CK_PLL6,
  95. _CK_PLL7,
  96. _CK_PLL8,
  97. _CK_HSE_RTC,
  98. _CK_RTCCK,
  99. _CK_ICN_HS_MCU,
  100. _CK_ICN_SDMMC,
  101. _CK_ICN_DDR,
  102. _CK_ICN_HSL,
  103. _CK_ICN_NIC,
  104. _CK_ICN_LS_MCU,
  105. _CK_FLEXGEN_07,
  106. _CK_FLEXGEN_08,
  107. _CK_FLEXGEN_09,
  108. _CK_FLEXGEN_10,
  109. _CK_FLEXGEN_11,
  110. _CK_FLEXGEN_12,
  111. _CK_FLEXGEN_13,
  112. _CK_FLEXGEN_14,
  113. _CK_FLEXGEN_15,
  114. _CK_FLEXGEN_16,
  115. _CK_FLEXGEN_17,
  116. _CK_FLEXGEN_18,
  117. _CK_FLEXGEN_19,
  118. _CK_FLEXGEN_20,
  119. _CK_FLEXGEN_21,
  120. _CK_FLEXGEN_22,
  121. _CK_FLEXGEN_23,
  122. _CK_FLEXGEN_24,
  123. _CK_FLEXGEN_25,
  124. _CK_FLEXGEN_26,
  125. _CK_FLEXGEN_27,
  126. _CK_FLEXGEN_28,
  127. _CK_FLEXGEN_29,
  128. _CK_FLEXGEN_30,
  129. _CK_FLEXGEN_31,
  130. _CK_FLEXGEN_32,
  131. _CK_FLEXGEN_33,
  132. _CK_FLEXGEN_34,
  133. _CK_FLEXGEN_35,
  134. _CK_FLEXGEN_36,
  135. _CK_FLEXGEN_37,
  136. _CK_FLEXGEN_38,
  137. _CK_FLEXGEN_39,
  138. _CK_FLEXGEN_40,
  139. _CK_FLEXGEN_41,
  140. _CK_FLEXGEN_42,
  141. _CK_FLEXGEN_43,
  142. _CK_FLEXGEN_44,
  143. _CK_FLEXGEN_45,
  144. _CK_FLEXGEN_46,
  145. _CK_FLEXGEN_47,
  146. _CK_FLEXGEN_48,
  147. _CK_FLEXGEN_49,
  148. _CK_FLEXGEN_50,
  149. _CK_FLEXGEN_51,
  150. _CK_FLEXGEN_52,
  151. _CK_FLEXGEN_53,
  152. _CK_FLEXGEN_54,
  153. _CK_FLEXGEN_55,
  154. _CK_FLEXGEN_56,
  155. _CK_FLEXGEN_57,
  156. _CK_FLEXGEN_58,
  157. _CK_FLEXGEN_59,
  158. _CK_FLEXGEN_60,
  159. _CK_FLEXGEN_61,
  160. _CK_FLEXGEN_62,
  161. _CK_FLEXGEN_63,
  162. _CK_ICN_APB1,
  163. _CK_ICN_APB2,
  164. _CK_ICN_APB3,
  165. _CK_ICN_APB4,
  166. _CK_ICN_APBDBG,
  167. _CK_BKPSRAM,
  168. _CK_BSEC,
  169. _CK_CRC,
  170. _CK_CRYP1,
  171. _CK_CRYP2,
  172. _CK_DDR,
  173. _CK_DDRCAPB,
  174. _CK_DDRCP,
  175. _CK_DDRPHYC,
  176. _CK_FMC,
  177. _CK_GPIOA,
  178. _CK_GPIOB,
  179. _CK_GPIOC,
  180. _CK_GPIOD,
  181. _CK_GPIOE,
  182. _CK_GPIOF,
  183. _CK_GPIOG,
  184. _CK_GPIOH,
  185. _CK_GPIOI,
  186. _CK_GPIOJ,
  187. _CK_GPIOK,
  188. _CK_GPIOZ,
  189. _CK_HASH,
  190. _CK_I2C1,
  191. _CK_I2C2,
  192. _CK_I2C3,
  193. _CK_I2C4,
  194. _CK_I2C5,
  195. _CK_I2C6,
  196. _CK_I2C7,
  197. _CK_I2C8,
  198. _CK_IWDG1,
  199. _CK_IWDG2,
  200. _CK_OSPI1,
  201. _CK_OSPI2,
  202. _CK_OSPIIOM,
  203. _CK_PKA,
  204. _CK_RETRAM,
  205. _CK_RNG,
  206. _CK_RTC,
  207. _CK_SAES,
  208. _CK_SDMMC1,
  209. _CK_SDMMC2,
  210. _CK_SRAM1,
  211. _CK_SRAM2,
  212. _CK_STGEN,
  213. _CK_SYSCPU1,
  214. _CK_SYSRAM,
  215. _CK_UART4,
  216. _CK_UART5,
  217. _CK_UART7,
  218. _CK_UART8,
  219. _CK_UART9,
  220. _CK_USART1,
  221. _CK_USART2,
  222. _CK_USART3,
  223. _CK_USART6,
  224. _CK_USB2EHCI,
  225. _CK_USB2OHCI,
  226. _CK_USB2PHY1,
  227. _CK_USB2PHY2,
  228. _CK_USB3DR,
  229. _CK_USB3PCIEPHY,
  230. _CK_USBTC,
  231. CK_LAST
  232. };
  233. static const uint16_t muxsel_src[] = {
  234. _CK_HSI, _CK_HSE, _CK_MSI, _CK_0_MHZ
  235. };
  236. static const uint16_t xbarsel_src[] = {
  237. _CK_PLL4, _CK_PLL5, _CK_PLL6, _CK_PLL7, _CK_PLL8,
  238. _CK_HSI, _CK_HSE, _CK_MSI, _CK_HSI, _CK_HSE, _CK_MSI,
  239. _SPDIFSYMB, _I2SCKIN, _CK_LSI, _CK_LSE
  240. };
  241. static const uint16_t rtc_src[] = {
  242. _CK_0_MHZ, _CK_LSE, _CK_LSI, _CK_HSE_RTC
  243. };
  244. static const uint16_t usb2phy1_src[] = {
  245. _CK_FLEXGEN_57, _CK_HSE
  246. };
  247. static const uint16_t usb2phy2_src[] = {
  248. _CK_FLEXGEN_58, _CK_HSE
  249. };
  250. static const uint16_t usb3pciphy_src[] = {
  251. _CK_FLEXGEN_34, _CK_HSE
  252. };
  253. static const uint16_t d3per_src[] = {
  254. _CK_MSI, _CK_LSI, _CK_LSE
  255. };
  256. #define MUX_CONF(id, src, _offset, _shift, _witdh)[id] = {\
  257. .id_parents = src,\
  258. .num_parents = ARRAY_SIZE(src),\
  259. .mux = &(struct mux_cfg) {\
  260. .offset = (_offset),\
  261. .shift = (_shift),\
  262. .width = (_witdh),\
  263. .bitrdy = UINT8_MAX,\
  264. },\
  265. }
  266. static const struct parent_cfg parent_mp25[] = {
  267. MUX_CONF(MUX_MUXSEL0, muxsel_src, RCC_MUXSELCFGR, 0, 2),
  268. MUX_CONF(MUX_MUXSEL1, muxsel_src, RCC_MUXSELCFGR, 4, 2),
  269. MUX_CONF(MUX_MUXSEL2, muxsel_src, RCC_MUXSELCFGR, 8, 2),
  270. MUX_CONF(MUX_MUXSEL3, muxsel_src, RCC_MUXSELCFGR, 12, 2),
  271. MUX_CONF(MUX_MUXSEL4, muxsel_src, RCC_MUXSELCFGR, 16, 2),
  272. MUX_CONF(MUX_MUXSEL5, muxsel_src, RCC_MUXSELCFGR, 20, 2),
  273. MUX_CONF(MUX_MUXSEL6, muxsel_src, RCC_MUXSELCFGR, 24, 2),
  274. MUX_CONF(MUX_MUXSEL7, muxsel_src, RCC_MUXSELCFGR, 28, 2),
  275. MUX_CONF(MUX_XBARSEL, xbarsel_src, RCC_XBAR0CFGR, 0, 4),
  276. MUX_CONF(MUX_RTC, rtc_src, RCC_BDCR, 16, 2),
  277. MUX_CONF(MUX_USB2PHY1, usb2phy1_src, RCC_USB2PHY1CFGR, 15, 1),
  278. MUX_CONF(MUX_USB2PHY2, usb2phy2_src, RCC_USB2PHY2CFGR, 15, 1),
  279. MUX_CONF(MUX_USB3PCIEPHY, usb3pciphy_src, RCC_USB3PCIEPHYCFGR, 15, 1),
  280. MUX_CONF(MUX_D3PER, d3per_src, RCC_D3DCR, 16, 2),
  281. };
  282. /* GATES */
  283. enum enum_gate_cfg {
  284. GATE_ZERO, /* reserved for no gate */
  285. GATE_LSE,
  286. GATE_RTCCK,
  287. GATE_LSI,
  288. GATE_HSI,
  289. GATE_MSI,
  290. GATE_HSE,
  291. GATE_LSI_RDY,
  292. GATE_MSI_RDY,
  293. GATE_LSE_RDY,
  294. GATE_HSE_RDY,
  295. GATE_HSI_RDY,
  296. GATE_SYSRAM,
  297. GATE_RETRAM,
  298. GATE_SRAM1,
  299. GATE_SRAM2,
  300. GATE_DDRPHYC,
  301. GATE_SYSCPU1,
  302. GATE_CRC,
  303. GATE_OSPIIOM,
  304. GATE_BKPSRAM,
  305. GATE_HASH,
  306. GATE_RNG,
  307. GATE_CRYP1,
  308. GATE_CRYP2,
  309. GATE_SAES,
  310. GATE_PKA,
  311. GATE_GPIOA,
  312. GATE_GPIOB,
  313. GATE_GPIOC,
  314. GATE_GPIOD,
  315. GATE_GPIOE,
  316. GATE_GPIOF,
  317. GATE_GPIOG,
  318. GATE_GPIOH,
  319. GATE_GPIOI,
  320. GATE_GPIOJ,
  321. GATE_GPIOK,
  322. GATE_GPIOZ,
  323. GATE_RTC,
  324. GATE_DDRCP,
  325. /* WARNING 2 CLOCKS FOR ONE GATE */
  326. GATE_USB2OHCI,
  327. GATE_USB2EHCI,
  328. GATE_USB3DR,
  329. GATE_BSEC,
  330. GATE_IWDG1,
  331. GATE_IWDG2,
  332. GATE_DDRCAPB,
  333. GATE_DDR,
  334. GATE_USART2,
  335. GATE_UART4,
  336. GATE_USART3,
  337. GATE_UART5,
  338. GATE_I2C1,
  339. GATE_I2C2,
  340. GATE_I2C3,
  341. GATE_I2C5,
  342. GATE_I2C4,
  343. GATE_I2C6,
  344. GATE_I2C7,
  345. GATE_USART1,
  346. GATE_USART6,
  347. GATE_UART7,
  348. GATE_UART8,
  349. GATE_UART9,
  350. GATE_STGEN,
  351. GATE_USB3PCIEPHY,
  352. GATE_USBTC,
  353. GATE_I2C8,
  354. GATE_OSPI1,
  355. GATE_OSPI2,
  356. GATE_FMC,
  357. GATE_SDMMC1,
  358. GATE_SDMMC2,
  359. GATE_USB2PHY1,
  360. GATE_USB2PHY2,
  361. LAST_GATE
  362. };
  363. #define GATE_CFG(id, _offset, _bit_idx, _offset_clr)[id] = {\
  364. .offset = (_offset),\
  365. .bit_idx = (_bit_idx),\
  366. .set_clr = (_offset_clr),\
  367. }
  368. static const struct gate_cfg gates_mp25[LAST_GATE] = {
  369. GATE_CFG(GATE_LSE, RCC_BDCR, 0, 0),
  370. GATE_CFG(GATE_LSI, RCC_BDCR, 9, 0),
  371. GATE_CFG(GATE_RTCCK, RCC_BDCR, 20, 0),
  372. GATE_CFG(GATE_HSI, RCC_OCENSETR, 0, 1),
  373. GATE_CFG(GATE_HSE, RCC_OCENSETR, 8, 1),
  374. GATE_CFG(GATE_MSI, RCC_D3DCR, 0, 0),
  375. GATE_CFG(GATE_LSI_RDY, RCC_BDCR, 10, 0),
  376. GATE_CFG(GATE_LSE_RDY, RCC_BDCR, 2, 0),
  377. GATE_CFG(GATE_MSI_RDY, RCC_D3DCR, 2, 0),
  378. GATE_CFG(GATE_HSE_RDY, RCC_OCRDYR, 8, 0),
  379. GATE_CFG(GATE_HSI_RDY, RCC_OCRDYR, 0, 0),
  380. GATE_CFG(GATE_SYSRAM, RCC_SYSRAMCFGR, 1, 0),
  381. GATE_CFG(GATE_RETRAM, RCC_RETRAMCFGR, 1, 0),
  382. GATE_CFG(GATE_SRAM1, RCC_SRAM1CFGR, 1, 0),
  383. GATE_CFG(GATE_SRAM2, RCC_SRAM2CFGR, 1, 0),
  384. GATE_CFG(GATE_DDRPHYC, RCC_DDRPHYCAPBCFGR, 1, 0),
  385. GATE_CFG(GATE_SYSCPU1, RCC_SYSCPU1CFGR, 1, 0),
  386. GATE_CFG(GATE_CRC, RCC_CRCCFGR, 1, 0),
  387. GATE_CFG(GATE_OSPIIOM, RCC_OSPIIOMCFGR, 1, 0),
  388. GATE_CFG(GATE_BKPSRAM, RCC_BKPSRAMCFGR, 1, 0),
  389. GATE_CFG(GATE_HASH, RCC_HASHCFGR, 1, 0),
  390. GATE_CFG(GATE_RNG, RCC_RNGCFGR, 1, 0),
  391. GATE_CFG(GATE_CRYP1, RCC_CRYP1CFGR, 1, 0),
  392. GATE_CFG(GATE_CRYP2, RCC_CRYP2CFGR, 1, 0),
  393. GATE_CFG(GATE_SAES, RCC_SAESCFGR, 1, 0),
  394. GATE_CFG(GATE_PKA, RCC_PKACFGR, 1, 0),
  395. GATE_CFG(GATE_GPIOA, RCC_GPIOACFGR, 1, 0),
  396. GATE_CFG(GATE_GPIOB, RCC_GPIOBCFGR, 1, 0),
  397. GATE_CFG(GATE_GPIOC, RCC_GPIOCCFGR, 1, 0),
  398. GATE_CFG(GATE_GPIOD, RCC_GPIODCFGR, 1, 0),
  399. GATE_CFG(GATE_GPIOE, RCC_GPIOECFGR, 1, 0),
  400. GATE_CFG(GATE_GPIOF, RCC_GPIOFCFGR, 1, 0),
  401. GATE_CFG(GATE_GPIOG, RCC_GPIOGCFGR, 1, 0),
  402. GATE_CFG(GATE_GPIOH, RCC_GPIOHCFGR, 1, 0),
  403. GATE_CFG(GATE_GPIOI, RCC_GPIOICFGR, 1, 0),
  404. GATE_CFG(GATE_GPIOJ, RCC_GPIOJCFGR, 1, 0),
  405. GATE_CFG(GATE_GPIOK, RCC_GPIOKCFGR, 1, 0),
  406. GATE_CFG(GATE_GPIOZ, RCC_GPIOZCFGR, 1, 0),
  407. GATE_CFG(GATE_RTC, RCC_RTCCFGR, 1, 0),
  408. GATE_CFG(GATE_DDRCP, RCC_DDRCPCFGR, 1, 0),
  409. /* WARNING 2 CLOCKS FOR ONE GATE */
  410. GATE_CFG(GATE_USB2OHCI, RCC_USB2CFGR, 1, 0),
  411. GATE_CFG(GATE_USB2EHCI, RCC_USB2CFGR, 1, 0),
  412. GATE_CFG(GATE_USB3DR, RCC_USB3DRCFGR, 1, 0),
  413. GATE_CFG(GATE_BSEC, RCC_BSECCFGR, 1, 0),
  414. GATE_CFG(GATE_IWDG1, RCC_IWDG1CFGR, 1, 0),
  415. GATE_CFG(GATE_IWDG2, RCC_IWDG2CFGR, 1, 0),
  416. GATE_CFG(GATE_DDRCAPB, RCC_DDRCAPBCFGR, 1, 0),
  417. GATE_CFG(GATE_DDR, RCC_DDRCFGR, 1, 0),
  418. GATE_CFG(GATE_USART2, RCC_USART2CFGR, 1, 0),
  419. GATE_CFG(GATE_UART4, RCC_UART4CFGR, 1, 0),
  420. GATE_CFG(GATE_USART3, RCC_USART3CFGR, 1, 0),
  421. GATE_CFG(GATE_UART5, RCC_UART5CFGR, 1, 0),
  422. GATE_CFG(GATE_I2C1, RCC_I2C1CFGR, 1, 0),
  423. GATE_CFG(GATE_I2C2, RCC_I2C2CFGR, 1, 0),
  424. GATE_CFG(GATE_I2C3, RCC_I2C3CFGR, 1, 0),
  425. GATE_CFG(GATE_I2C5, RCC_I2C5CFGR, 1, 0),
  426. GATE_CFG(GATE_I2C4, RCC_I2C4CFGR, 1, 0),
  427. GATE_CFG(GATE_I2C6, RCC_I2C6CFGR, 1, 0),
  428. GATE_CFG(GATE_I2C7, RCC_I2C7CFGR, 1, 0),
  429. GATE_CFG(GATE_USART1, RCC_USART1CFGR, 1, 0),
  430. GATE_CFG(GATE_USART6, RCC_USART6CFGR, 1, 0),
  431. GATE_CFG(GATE_UART7, RCC_UART7CFGR, 1, 0),
  432. GATE_CFG(GATE_UART8, RCC_UART8CFGR, 1, 0),
  433. GATE_CFG(GATE_UART9, RCC_UART9CFGR, 1, 0),
  434. GATE_CFG(GATE_STGEN, RCC_STGENCFGR, 1, 0),
  435. GATE_CFG(GATE_USB3PCIEPHY, RCC_USB3PCIEPHYCFGR, 1, 0),
  436. GATE_CFG(GATE_USBTC, RCC_USBTCCFGR, 1, 0),
  437. GATE_CFG(GATE_I2C8, RCC_I2C8CFGR, 1, 0),
  438. GATE_CFG(GATE_OSPI1, RCC_OSPI1CFGR, 1, 0),
  439. GATE_CFG(GATE_OSPI2, RCC_OSPI2CFGR, 1, 0),
  440. GATE_CFG(GATE_FMC, RCC_FMCCFGR, 1, 0),
  441. GATE_CFG(GATE_SDMMC1, RCC_SDMMC1CFGR, 1, 0),
  442. GATE_CFG(GATE_SDMMC2, RCC_SDMMC2CFGR, 1, 0),
  443. GATE_CFG(GATE_USB2PHY1, RCC_USB2PHY1CFGR, 1, 0),
  444. GATE_CFG(GATE_USB2PHY2, RCC_USB2PHY2CFGR, 1, 0),
  445. };
  446. static const struct clk_div_table apb_div_table[] = {
  447. { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 }, { 4, 16 },
  448. { 5, 16 }, { 6, 16 }, { 7, 16 }, { 0 },
  449. };
  450. #undef DIV_CFG
  451. #define DIV_CFG(id, _offset, _shift, _width, _flags, _table, _bitrdy)[id] = {\
  452. .offset = _offset,\
  453. .shift = _shift,\
  454. .width = _width,\
  455. .flags = _flags,\
  456. .table = _table,\
  457. .bitrdy = _bitrdy,\
  458. }
  459. static const struct div_cfg dividers_mp25[] = {
  460. DIV_CFG(DIV_APB1, RCC_APB1DIVR, 0, 3, 0, apb_div_table, 31),
  461. DIV_CFG(DIV_APB2, RCC_APB2DIVR, 0, 3, 0, apb_div_table, 31),
  462. DIV_CFG(DIV_APB3, RCC_APB3DIVR, 0, 3, 0, apb_div_table, 31),
  463. DIV_CFG(DIV_APB4, RCC_APB4DIVR, 0, 3, 0, apb_div_table, 31),
  464. DIV_CFG(DIV_APBDBG, RCC_APBDBGDIVR, 0, 3, 0, apb_div_table, 31),
  465. DIV_CFG(DIV_LSMCU, RCC_LSMCUDIVR, 0, 1, 0, NULL, 31),
  466. DIV_CFG(DIV_RTC, RCC_RTCDIVR, 0, 6, 0, NULL, 0),
  467. };
  468. enum stm32_osc {
  469. OSC_HSI,
  470. OSC_HSE,
  471. OSC_MSI,
  472. OSC_LSI,
  473. OSC_LSE,
  474. OSC_I2SCKIN,
  475. OSC_SPDIFSYMB,
  476. NB_OSCILLATOR
  477. };
  478. static struct clk_oscillator_data stm32mp25_osc_data[] = {
  479. OSCILLATOR(OSC_HSI, _CK_HSI, "clk-hsi", GATE_HSI, GATE_HSI_RDY,
  480. NULL, NULL, NULL),
  481. OSCILLATOR(OSC_LSI, _CK_LSI, "clk-lsi", GATE_LSI, GATE_LSI_RDY,
  482. NULL, NULL, NULL),
  483. OSCILLATOR(OSC_MSI, _CK_MSI, "clk-msi", GATE_MSI, GATE_MSI_RDY,
  484. NULL, NULL, NULL),
  485. OSCILLATOR(OSC_HSE, _CK_HSE, "clk-hse", GATE_HSE, GATE_HSE_RDY,
  486. BYPASS(RCC_OCENSETR, 10, 7),
  487. CSS(RCC_OCENSETR, 11),
  488. NULL),
  489. OSCILLATOR(OSC_LSE, _CK_LSE, "clk-lse", GATE_LSE, GATE_LSE_RDY,
  490. BYPASS(RCC_BDCR, 1, 3),
  491. CSS(RCC_BDCR, 8),
  492. DRIVE(RCC_BDCR, 4, 2, 2)),
  493. OSCILLATOR(OSC_I2SCKIN, _I2SCKIN, "i2s_ckin", NO_GATE, NO_GATE,
  494. NULL, NULL, NULL),
  495. OSCILLATOR(OSC_SPDIFSYMB, _SPDIFSYMB, "spdif_symb", NO_GATE, NO_GATE,
  496. NULL, NULL, NULL),
  497. };
  498. #ifdef IMAGE_BL2
  499. static const char *clk_stm32_get_oscillator_name(enum stm32_osc id)
  500. {
  501. if (id < NB_OSCILLATOR) {
  502. return stm32mp25_osc_data[id].name;
  503. }
  504. return NULL;
  505. }
  506. #endif
  507. enum pll_id {
  508. _PLL1,
  509. _PLL2,
  510. _PLL3,
  511. _PLL4,
  512. _PLL5,
  513. _PLL6,
  514. _PLL7,
  515. _PLL8,
  516. _PLL_NB
  517. };
  518. /* PLL configuration registers offsets from RCC_PLLxCFGR1 */
  519. #define RCC_OFFSET_PLLXCFGR1 0x00
  520. #define RCC_OFFSET_PLLXCFGR2 0x04
  521. #define RCC_OFFSET_PLLXCFGR3 0x08
  522. #define RCC_OFFSET_PLLXCFGR4 0x0C
  523. #define RCC_OFFSET_PLLXCFGR5 0x10
  524. #define RCC_OFFSET_PLLXCFGR6 0x18
  525. #define RCC_OFFSET_PLLXCFGR7 0x1C
  526. struct stm32_clk_pll {
  527. uint16_t clk_id;
  528. uint16_t reg_pllxcfgr1;
  529. };
  530. #define CLK_PLL_CFG(_idx, _clk_id, _reg)\
  531. [(_idx)] = {\
  532. .clk_id = (_clk_id),\
  533. .reg_pllxcfgr1 = (_reg),\
  534. }
  535. static const struct stm32_clk_pll stm32mp25_clk_pll[_PLL_NB] = {
  536. CLK_PLL_CFG(_PLL1, _CK_PLL1, A35_SS_CHGCLKREQ),
  537. CLK_PLL_CFG(_PLL2, _CK_PLL2, RCC_PLL2CFGR1),
  538. CLK_PLL_CFG(_PLL3, _CK_PLL3, RCC_PLL3CFGR1),
  539. CLK_PLL_CFG(_PLL4, _CK_PLL4, RCC_PLL4CFGR1),
  540. CLK_PLL_CFG(_PLL5, _CK_PLL5, RCC_PLL5CFGR1),
  541. CLK_PLL_CFG(_PLL6, _CK_PLL6, RCC_PLL6CFGR1),
  542. CLK_PLL_CFG(_PLL7, _CK_PLL7, RCC_PLL7CFGR1),
  543. CLK_PLL_CFG(_PLL8, _CK_PLL8, RCC_PLL8CFGR1),
  544. };
  545. static const struct stm32_clk_pll *clk_stm32_pll_data(unsigned int idx)
  546. {
  547. return &stm32mp25_clk_pll[idx];
  548. }
  549. static unsigned long clk_get_pll_fvco(struct stm32_clk_priv *priv,
  550. const struct stm32_clk_pll *pll,
  551. unsigned long prate)
  552. {
  553. unsigned long refclk, fvco;
  554. uint32_t fracin, fbdiv, refdiv;
  555. uintptr_t pllxcfgr1 = priv->base + pll->reg_pllxcfgr1;
  556. uintptr_t pllxcfgr2 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR2;
  557. uintptr_t pllxcfgr3 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR3;
  558. refclk = prate;
  559. fracin = mmio_read_32(pllxcfgr3) & RCC_PLLxCFGR3_FRACIN_MASK;
  560. fbdiv = (mmio_read_32(pllxcfgr2) & RCC_PLLxCFGR2_FBDIV_MASK) >>
  561. RCC_PLLxCFGR2_FBDIV_SHIFT;
  562. refdiv = mmio_read_32(pllxcfgr2) & RCC_PLLxCFGR2_FREFDIV_MASK;
  563. if (fracin != 0U) {
  564. uint64_t numerator, denominator;
  565. numerator = ((uint64_t)fbdiv << 24) + fracin;
  566. numerator = refclk * numerator;
  567. denominator = (uint64_t)refdiv << 24;
  568. fvco = (unsigned long)(numerator / denominator);
  569. } else {
  570. fvco = (unsigned long)(refclk * fbdiv / refdiv);
  571. }
  572. return fvco;
  573. }
  574. struct stm32_pll_cfg {
  575. uint16_t pll_id;
  576. };
  577. static bool _clk_stm32_pll_is_enabled(struct stm32_clk_priv *priv, const struct stm32_clk_pll *pll)
  578. {
  579. uintptr_t pllxcfgr1 = priv->base + pll->reg_pllxcfgr1;
  580. return ((mmio_read_32(pllxcfgr1) & RCC_PLLxCFGR1_PLLEN) != 0U);
  581. }
  582. static void _clk_stm32_pll_set_on(struct stm32_clk_priv *priv, const struct stm32_clk_pll *pll)
  583. {
  584. uintptr_t pllxcfgr1 = priv->base + pll->reg_pllxcfgr1;
  585. mmio_setbits_32(pllxcfgr1, RCC_PLLxCFGR1_PLLEN);
  586. }
  587. static void _clk_stm32_pll_set_off(struct stm32_clk_priv *priv, const struct stm32_clk_pll *pll)
  588. {
  589. uintptr_t pllxcfgr1 = priv->base + pll->reg_pllxcfgr1;
  590. /* Stop PLL */
  591. mmio_clrbits_32(pllxcfgr1, RCC_PLLxCFGR1_PLLEN);
  592. }
  593. static int _clk_stm32_pll_wait_ready_on(struct stm32_clk_priv *priv,
  594. const struct stm32_clk_pll *pll)
  595. {
  596. uintptr_t pllxcfgr1 = priv->base + pll->reg_pllxcfgr1;
  597. uint64_t timeout = timeout_init_us(PLLRDY_TIMEOUT);
  598. /* Wait PLL lock */
  599. while ((mmio_read_32(pllxcfgr1) & RCC_PLLxCFGR1_PLLRDY) == 0U) {
  600. if (timeout_elapsed(timeout)) {
  601. ERROR("PLL%d start failed @ 0x%x: 0x%x\n",
  602. pll->clk_id - _CK_PLL1 + 1, pll->reg_pllxcfgr1,
  603. mmio_read_32(pllxcfgr1));
  604. return -ETIMEDOUT;
  605. }
  606. }
  607. return 0;
  608. }
  609. static int _clk_stm32_pll_wait_ready_off(struct stm32_clk_priv *priv,
  610. const struct stm32_clk_pll *pll)
  611. {
  612. uintptr_t pllxcfgr1 = priv->base + pll->reg_pllxcfgr1;
  613. uint64_t timeout = timeout_init_us(PLLRDY_TIMEOUT);
  614. /* Wait PLL stopped */
  615. while ((mmio_read_32(pllxcfgr1) & RCC_PLLxCFGR1_PLLRDY) != 0U) {
  616. if (timeout_elapsed(timeout)) {
  617. ERROR("PLL%d stop failed @ 0x%lx: 0x%x\n",
  618. pll->clk_id - _CK_PLL1 + 1, pllxcfgr1, mmio_read_32(pllxcfgr1));
  619. return -ETIMEDOUT;
  620. }
  621. }
  622. return 0;
  623. }
  624. static int _clk_stm32_pll_enable(struct stm32_clk_priv *priv, const struct stm32_clk_pll *pll)
  625. {
  626. if (_clk_stm32_pll_is_enabled(priv, pll)) {
  627. return 0;
  628. }
  629. _clk_stm32_pll_set_on(priv, pll);
  630. return _clk_stm32_pll_wait_ready_on(priv, pll);
  631. }
  632. static void _clk_stm32_pll_disable(struct stm32_clk_priv *priv, const struct stm32_clk_pll *pll)
  633. {
  634. if (!_clk_stm32_pll_is_enabled(priv, pll)) {
  635. return;
  636. }
  637. _clk_stm32_pll_set_off(priv, pll);
  638. _clk_stm32_pll_wait_ready_off(priv, pll);
  639. }
  640. static bool clk_stm32_pll_is_enabled(struct stm32_clk_priv *priv, int id)
  641. {
  642. const struct clk_stm32 *clk = _clk_get(priv, id);
  643. struct stm32_pll_cfg *pll_cfg = clk->clock_cfg;
  644. const struct stm32_clk_pll *pll = clk_stm32_pll_data(pll_cfg->pll_id);
  645. return _clk_stm32_pll_is_enabled(priv, pll);
  646. }
  647. static int clk_stm32_pll_enable(struct stm32_clk_priv *priv, int id)
  648. {
  649. const struct clk_stm32 *clk = _clk_get(priv, id);
  650. struct stm32_pll_cfg *pll_cfg = clk->clock_cfg;
  651. const struct stm32_clk_pll *pll = clk_stm32_pll_data(pll_cfg->pll_id);
  652. return _clk_stm32_pll_enable(priv, pll);
  653. }
  654. static void clk_stm32_pll_disable(struct stm32_clk_priv *priv, int id)
  655. {
  656. const struct clk_stm32 *clk = _clk_get(priv, id);
  657. struct stm32_pll_cfg *pll_cfg = clk->clock_cfg;
  658. const struct stm32_clk_pll *pll = clk_stm32_pll_data(pll_cfg->pll_id);
  659. _clk_stm32_pll_disable(priv, pll);
  660. }
  661. static unsigned long clk_stm32_pll_recalc_rate(struct stm32_clk_priv *priv, int id,
  662. unsigned long prate)
  663. {
  664. const struct clk_stm32 *clk = _clk_get(priv, id);
  665. struct stm32_pll_cfg *pll_cfg = clk->clock_cfg;
  666. const struct stm32_clk_pll *pll = clk_stm32_pll_data(pll_cfg->pll_id);
  667. uintptr_t pllxcfgr1 = priv->base + pll->reg_pllxcfgr1;
  668. uintptr_t pllxcfgr4 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR4;
  669. uintptr_t pllxcfgr6 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR6;
  670. uintptr_t pllxcfgr7 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR7;
  671. unsigned long dfout;
  672. uint32_t postdiv1, postdiv2;
  673. postdiv1 = mmio_read_32(pllxcfgr6) & RCC_PLLxCFGR6_POSTDIV1_MASK;
  674. postdiv2 = mmio_read_32(pllxcfgr7) & RCC_PLLxCFGR7_POSTDIV2_MASK;
  675. if ((mmio_read_32(pllxcfgr4) & RCC_PLLxCFGR4_BYPASS) != 0U) {
  676. dfout = prate;
  677. } else {
  678. if ((postdiv1 == 0U) || (postdiv2 == 0U)) {
  679. dfout = prate;
  680. } else {
  681. dfout = clk_get_pll_fvco(priv, pll, prate) / (postdiv1 * postdiv2);
  682. }
  683. }
  684. return dfout;
  685. }
  686. static const struct stm32_clk_ops clk_stm32_pll_ops = {
  687. .recalc_rate = clk_stm32_pll_recalc_rate,
  688. .enable = clk_stm32_pll_enable,
  689. .disable = clk_stm32_pll_disable,
  690. .is_enabled = clk_stm32_pll_is_enabled,
  691. };
  692. #define CLK_PLL(idx, _idx, _parent, _pll_id, _flags)[idx] = {\
  693. .binding = _idx,\
  694. .parent = _parent,\
  695. .flags = (_flags),\
  696. .clock_cfg = &(struct stm32_pll_cfg) {\
  697. .pll_id = _pll_id,\
  698. },\
  699. .ops = STM32_PLL_OPS,\
  700. }
  701. static unsigned long clk_get_pll1_fvco(unsigned long refclk)
  702. {
  703. uintptr_t pll_freq1_reg = A35SSC_BASE + A35_SS_PLL_FREQ1;
  704. uint32_t reg, fbdiv, refdiv;
  705. reg = mmio_read_32(pll_freq1_reg);
  706. fbdiv = (reg & A35_SS_PLL_FREQ1_FBDIV_MASK) >> A35_SS_PLL_FREQ1_FBDIV_SHIFT;
  707. refdiv = (reg & A35_SS_PLL_FREQ1_REFDIV_MASK) >> A35_SS_PLL_FREQ1_REFDIV_SHIFT;
  708. return (unsigned long)(refclk * fbdiv / refdiv);
  709. }
  710. static unsigned long clk_stm32_pll1_recalc_rate(struct stm32_clk_priv *priv,
  711. int id, unsigned long prate)
  712. {
  713. uintptr_t pll_freq2_reg = A35SSC_BASE + A35_SS_PLL_FREQ2;
  714. uint32_t postdiv1, postdiv2;
  715. unsigned long dfout;
  716. postdiv1 = (mmio_read_32(pll_freq2_reg) & A35_SS_PLL_FREQ2_POSTDIV1_MASK) >>
  717. A35_SS_PLL_FREQ2_POSTDIV1_SHIFT;
  718. postdiv2 = (mmio_read_32(pll_freq2_reg) & A35_SS_PLL_FREQ2_POSTDIV2_MASK) >>
  719. A35_SS_PLL_FREQ2_POSTDIV2_SHIFT;
  720. if ((postdiv1 == 0U) || (postdiv2 == 0U)) {
  721. dfout = prate;
  722. } else {
  723. dfout = clk_get_pll1_fvco(prate) / (postdiv1 * postdiv2);
  724. }
  725. return dfout;
  726. }
  727. static const struct stm32_clk_ops clk_stm32_pll1_ops = {
  728. .recalc_rate = clk_stm32_pll1_recalc_rate,
  729. };
  730. #define CLK_PLL1(idx, _idx, _parent, _pll_id, _flags)[idx] = {\
  731. .binding = _idx,\
  732. .parent = _parent,\
  733. .flags = (_flags),\
  734. .clock_cfg = &(struct stm32_pll_cfg) {\
  735. .pll_id = _pll_id,\
  736. },\
  737. .ops = STM32_PLL1_OPS,\
  738. }
  739. struct stm32_clk_flexgen_cfg {
  740. uint8_t id;
  741. };
  742. static unsigned long clk_flexgen_recalc(struct stm32_clk_priv *priv, int idx,
  743. unsigned long prate)
  744. {
  745. const struct clk_stm32 *clk = _clk_get(priv, idx);
  746. struct stm32_clk_flexgen_cfg *cfg = clk->clock_cfg;
  747. uintptr_t rcc_base = priv->base;
  748. uint32_t prediv, findiv;
  749. uint8_t channel = cfg->id;
  750. unsigned long freq = prate;
  751. prediv = mmio_read_32(rcc_base + RCC_PREDIV0CFGR + (0x4U * channel)) &
  752. RCC_PREDIVxCFGR_PREDIVx_MASK;
  753. findiv = mmio_read_32(rcc_base + RCC_FINDIV0CFGR + (0x4U * channel)) &
  754. RCC_FINDIVxCFGR_FINDIVx_MASK;
  755. if (freq == 0UL) {
  756. return 0U;
  757. }
  758. switch (prediv) {
  759. case 0x0:
  760. case 0x1:
  761. case 0x3:
  762. case 0x3FF:
  763. break;
  764. default:
  765. ERROR("Unsupported PREDIV value (%x)\n", prediv);
  766. panic();
  767. break;
  768. }
  769. freq /= (prediv + 1U);
  770. freq /= (findiv + 1U);
  771. return freq;
  772. }
  773. static int clk_flexgen_get_parent(struct stm32_clk_priv *priv, int idx)
  774. {
  775. const struct clk_stm32 *clk = _clk_get(priv, idx);
  776. struct stm32_clk_flexgen_cfg *cfg = clk->clock_cfg;
  777. uint32_t sel;
  778. uint32_t address;
  779. uintptr_t rcc_base = priv->base;
  780. address = RCC_XBAR0CFGR + (cfg->id * 4);
  781. sel = mmio_read_32(rcc_base + address) & RCC_XBARxCFGR_XBARxSEL_MASK;
  782. return sel;
  783. }
  784. static int clk_flexgen_gate_enable(struct stm32_clk_priv *priv, int idx)
  785. {
  786. const struct clk_stm32 *clk = _clk_get(priv, idx);
  787. struct stm32_clk_flexgen_cfg *cfg = clk->clock_cfg;
  788. uintptr_t rcc_base = priv->base;
  789. uint8_t channel = cfg->id;
  790. mmio_setbits_32(rcc_base + RCC_FINDIV0CFGR + (0x4U * channel),
  791. RCC_FINDIVxCFGR_FINDIVxEN);
  792. return 0;
  793. }
  794. static void clk_flexgen_gate_disable(struct stm32_clk_priv *priv, int id)
  795. {
  796. const struct clk_stm32 *clk = _clk_get(priv, id);
  797. struct stm32_clk_flexgen_cfg *cfg = clk->clock_cfg;
  798. uintptr_t rcc_base = priv->base;
  799. uint8_t channel = cfg->id;
  800. mmio_clrbits_32(rcc_base + RCC_FINDIV0CFGR + (0x4U * channel),
  801. RCC_FINDIVxCFGR_FINDIVxEN);
  802. }
  803. static bool clk_flexgen_gate_is_enabled(struct stm32_clk_priv *priv, int id)
  804. {
  805. const struct clk_stm32 *clk = _clk_get(priv, id);
  806. struct stm32_clk_flexgen_cfg *cfg = clk->clock_cfg;
  807. uintptr_t rcc_base = priv->base;
  808. uint8_t channel = cfg->id;
  809. return !!(mmio_read_32(rcc_base + RCC_FINDIV0CFGR + (0x4U * channel)) &
  810. RCC_FINDIVxCFGR_FINDIVxEN);
  811. }
  812. static const struct stm32_clk_ops clk_stm32_flexgen_ops = {
  813. .recalc_rate = clk_flexgen_recalc,
  814. .get_parent = clk_flexgen_get_parent,
  815. .enable = clk_flexgen_gate_enable,
  816. .disable = clk_flexgen_gate_disable,
  817. .is_enabled = clk_flexgen_gate_is_enabled,
  818. };
  819. #define FLEXGEN(idx, _idx, _flags, _id)[idx] = {\
  820. .binding = _idx,\
  821. .parent = MUX(MUX_XBARSEL),\
  822. .flags = (_flags),\
  823. .clock_cfg = &(struct stm32_clk_flexgen_cfg) {\
  824. .id = _id,\
  825. },\
  826. .ops = STM32_FLEXGEN_OPS,\
  827. }
  828. #define RCC_0_MHZ UL(0)
  829. #define RCC_4_MHZ UL(4000000)
  830. #define RCC_16_MHZ UL(16000000)
  831. #ifdef IMAGE_BL2
  832. static int clk_stm32_osc_msi_set_rate(struct stm32_clk_priv *priv, int id, unsigned long rate,
  833. unsigned long prate)
  834. {
  835. uintptr_t address = priv->base + RCC_BDCR;
  836. uint32_t mask = RCC_BDCR_MSIFREQSEL;
  837. int ret = -1;
  838. switch (rate) {
  839. case RCC_4_MHZ:
  840. mmio_clrbits_32(address, mask);
  841. ret = 0;
  842. break;
  843. case RCC_16_MHZ:
  844. mmio_setbits_32(address, mask);
  845. ret = 0;
  846. break;
  847. default:
  848. break;
  849. }
  850. return ret;
  851. }
  852. #endif /* IMAGE_BL2 */
  853. static unsigned long clk_stm32_osc_msi_recalc_rate(struct stm32_clk_priv *priv,
  854. int id __unused,
  855. unsigned long prate __unused)
  856. {
  857. uintptr_t address = priv->base + RCC_BDCR;
  858. if ((mmio_read_32(address) & RCC_BDCR_MSIFREQSEL) == 0U) {
  859. return RCC_4_MHZ;
  860. } else {
  861. return RCC_16_MHZ;
  862. }
  863. }
  864. static const struct stm32_clk_ops clk_stm32_osc_msi_ops = {
  865. .recalc_rate = clk_stm32_osc_msi_recalc_rate,
  866. .is_enabled = clk_stm32_osc_gate_is_enabled,
  867. .enable = clk_stm32_osc_gate_enable,
  868. .disable = clk_stm32_osc_gate_disable,
  869. .init = clk_stm32_osc_init,
  870. };
  871. #define CLK_OSC_MSI(idx, _idx, _parent, _osc_id) \
  872. [(idx)] = (struct clk_stm32){ \
  873. .binding = (_idx),\
  874. .parent = (_parent),\
  875. .flags = CLK_IS_CRITICAL,\
  876. .clock_cfg = &(struct stm32_osc_cfg){\
  877. .osc_id = (_osc_id),\
  878. },\
  879. .ops = STM32_OSC_MSI_OPS,\
  880. }
  881. static const struct stm32_clk_ops clk_stm32_rtc_ops = {
  882. .enable = clk_stm32_gate_enable,
  883. .disable = clk_stm32_gate_disable,
  884. .is_enabled = clk_stm32_gate_is_enabled,
  885. };
  886. #define CLK_RTC(idx, _binding, _parent, _flags, _gate_id)[idx] = {\
  887. .binding = (_binding),\
  888. .parent = (_parent),\
  889. .flags = (_flags),\
  890. .clock_cfg = &(struct clk_stm32_gate_cfg) {\
  891. .id = (_gate_id),\
  892. },\
  893. .ops = STM32_RTC_OPS,\
  894. }
  895. enum {
  896. STM32_PLL_OPS = STM32_LAST_OPS,
  897. STM32_PLL1_OPS,
  898. STM32_FLEXGEN_OPS,
  899. STM32_OSC_MSI_OPS,
  900. STM32_RTC_OPS,
  901. MP25_LAST_OPS
  902. };
  903. static const struct stm32_clk_ops *ops_array_mp25[MP25_LAST_OPS] = {
  904. [NO_OPS] = NULL,
  905. [FIXED_FACTOR_OPS] = &clk_fixed_factor_ops,
  906. [GATE_OPS] = &clk_gate_ops,
  907. [STM32_MUX_OPS] = &clk_mux_ops,
  908. [STM32_DIVIDER_OPS] = &clk_stm32_divider_ops,
  909. [STM32_GATE_OPS] = &clk_stm32_gate_ops,
  910. [STM32_TIMER_OPS] = &clk_timer_ops,
  911. [STM32_FIXED_RATE_OPS] = &clk_stm32_fixed_rate_ops,
  912. [STM32_OSC_OPS] = &clk_stm32_osc_ops,
  913. [STM32_OSC_NOGATE_OPS] = &clk_stm32_osc_nogate_ops,
  914. [STM32_PLL_OPS] = &clk_stm32_pll_ops,
  915. [STM32_PLL1_OPS] = &clk_stm32_pll1_ops,
  916. [STM32_FLEXGEN_OPS] = &clk_stm32_flexgen_ops,
  917. [STM32_OSC_MSI_OPS] = &clk_stm32_osc_msi_ops,
  918. [STM32_RTC_OPS] = &clk_stm32_rtc_ops
  919. };
  920. static const struct clk_stm32 stm32mp25_clk[CK_LAST] = {
  921. CLK_FIXED_RATE(_CK_0_MHZ, _NO_ID, RCC_0_MHZ),
  922. /* ROOT CLOCKS */
  923. CLK_OSC(_CK_HSE, HSE_CK, CLK_IS_ROOT, OSC_HSE),
  924. CLK_OSC(_CK_LSE, LSE_CK, CLK_IS_ROOT, OSC_LSE),
  925. CLK_OSC(_CK_HSI, HSI_CK, CLK_IS_ROOT, OSC_HSI),
  926. CLK_OSC(_CK_LSI, LSI_CK, CLK_IS_ROOT, OSC_LSI),
  927. CLK_OSC_MSI(_CK_MSI, MSI_CK, CLK_IS_ROOT, OSC_MSI),
  928. CLK_OSC_FIXED(_I2SCKIN, _NO_ID, CLK_IS_ROOT, OSC_I2SCKIN),
  929. CLK_OSC_FIXED(_SPDIFSYMB, _NO_ID, CLK_IS_ROOT, OSC_SPDIFSYMB),
  930. STM32_DIV(_CK_HSE_RTC, _NO_ID, _CK_HSE, 0, DIV_RTC),
  931. CLK_RTC(_CK_RTCCK, RTC_CK, MUX(MUX_RTC), 0, GATE_RTCCK),
  932. CLK_PLL1(_CK_PLL1, PLL1_CK, MUX(MUX_MUXSEL5), _PLL1, 0),
  933. CLK_PLL(_CK_PLL2, PLL2_CK, MUX(MUX_MUXSEL6), _PLL2, 0),
  934. CLK_PLL(_CK_PLL3, PLL3_CK, MUX(MUX_MUXSEL7), _PLL3, 0),
  935. CLK_PLL(_CK_PLL4, PLL4_CK, MUX(MUX_MUXSEL0), _PLL4, 0),
  936. CLK_PLL(_CK_PLL5, PLL5_CK, MUX(MUX_MUXSEL1), _PLL5, 0),
  937. CLK_PLL(_CK_PLL6, PLL6_CK, MUX(MUX_MUXSEL2), _PLL6, 0),
  938. CLK_PLL(_CK_PLL7, PLL7_CK, MUX(MUX_MUXSEL3), _PLL7, 0),
  939. CLK_PLL(_CK_PLL8, PLL8_CK, MUX(MUX_MUXSEL4), _PLL8, 0),
  940. FLEXGEN(_CK_ICN_HS_MCU, CK_ICN_HS_MCU, CLK_IS_CRITICAL, 0),
  941. FLEXGEN(_CK_ICN_SDMMC, CK_ICN_SDMMC, CLK_IS_CRITICAL, 1),
  942. FLEXGEN(_CK_ICN_DDR, CK_ICN_DDR, CLK_IS_CRITICAL, 2),
  943. FLEXGEN(_CK_ICN_HSL, CK_ICN_HSL, CLK_IS_CRITICAL, 4),
  944. FLEXGEN(_CK_ICN_NIC, CK_ICN_NIC, CLK_IS_CRITICAL, 5),
  945. STM32_DIV(_CK_ICN_LS_MCU, CK_ICN_LS_MCU, _CK_ICN_HS_MCU, 0, DIV_LSMCU),
  946. FLEXGEN(_CK_FLEXGEN_07, CK_FLEXGEN_07, 0, 7),
  947. FLEXGEN(_CK_FLEXGEN_08, CK_FLEXGEN_08, 0, 8),
  948. FLEXGEN(_CK_FLEXGEN_09, CK_FLEXGEN_09, 0, 9),
  949. FLEXGEN(_CK_FLEXGEN_10, CK_FLEXGEN_10, 0, 10),
  950. FLEXGEN(_CK_FLEXGEN_11, CK_FLEXGEN_11, 0, 11),
  951. FLEXGEN(_CK_FLEXGEN_12, CK_FLEXGEN_12, 0, 12),
  952. FLEXGEN(_CK_FLEXGEN_13, CK_FLEXGEN_13, 0, 13),
  953. FLEXGEN(_CK_FLEXGEN_14, CK_FLEXGEN_14, 0, 14),
  954. FLEXGEN(_CK_FLEXGEN_15, CK_FLEXGEN_15, 0, 15),
  955. FLEXGEN(_CK_FLEXGEN_16, CK_FLEXGEN_16, 0, 16),
  956. FLEXGEN(_CK_FLEXGEN_17, CK_FLEXGEN_17, 0, 17),
  957. FLEXGEN(_CK_FLEXGEN_18, CK_FLEXGEN_18, 0, 18),
  958. FLEXGEN(_CK_FLEXGEN_19, CK_FLEXGEN_19, 0, 19),
  959. FLEXGEN(_CK_FLEXGEN_20, CK_FLEXGEN_20, 0, 20),
  960. FLEXGEN(_CK_FLEXGEN_21, CK_FLEXGEN_21, 0, 21),
  961. FLEXGEN(_CK_FLEXGEN_22, CK_FLEXGEN_22, 0, 22),
  962. FLEXGEN(_CK_FLEXGEN_23, CK_FLEXGEN_23, 0, 23),
  963. FLEXGEN(_CK_FLEXGEN_24, CK_FLEXGEN_24, 0, 24),
  964. FLEXGEN(_CK_FLEXGEN_25, CK_FLEXGEN_25, 0, 25),
  965. FLEXGEN(_CK_FLEXGEN_26, CK_FLEXGEN_26, 0, 26),
  966. FLEXGEN(_CK_FLEXGEN_27, CK_FLEXGEN_27, 0, 27),
  967. FLEXGEN(_CK_FLEXGEN_28, CK_FLEXGEN_28, 0, 28),
  968. FLEXGEN(_CK_FLEXGEN_29, CK_FLEXGEN_29, 0, 29),
  969. FLEXGEN(_CK_FLEXGEN_30, CK_FLEXGEN_30, 0, 30),
  970. FLEXGEN(_CK_FLEXGEN_31, CK_FLEXGEN_31, 0, 31),
  971. FLEXGEN(_CK_FLEXGEN_32, CK_FLEXGEN_32, 0, 32),
  972. FLEXGEN(_CK_FLEXGEN_33, CK_FLEXGEN_33, 0, 33),
  973. FLEXGEN(_CK_FLEXGEN_34, CK_FLEXGEN_34, 0, 34),
  974. FLEXGEN(_CK_FLEXGEN_35, CK_FLEXGEN_35, 0, 35),
  975. FLEXGEN(_CK_FLEXGEN_36, CK_FLEXGEN_36, 0, 36),
  976. FLEXGEN(_CK_FLEXGEN_37, CK_FLEXGEN_37, 0, 37),
  977. FLEXGEN(_CK_FLEXGEN_38, CK_FLEXGEN_38, 0, 38),
  978. FLEXGEN(_CK_FLEXGEN_39, CK_FLEXGEN_39, 0, 39),
  979. FLEXGEN(_CK_FLEXGEN_40, CK_FLEXGEN_40, 0, 40),
  980. FLEXGEN(_CK_FLEXGEN_41, CK_FLEXGEN_41, 0, 41),
  981. FLEXGEN(_CK_FLEXGEN_42, CK_FLEXGEN_42, 0, 42),
  982. FLEXGEN(_CK_FLEXGEN_43, CK_FLEXGEN_43, 0, 43),
  983. FLEXGEN(_CK_FLEXGEN_44, CK_FLEXGEN_44, 0, 44),
  984. FLEXGEN(_CK_FLEXGEN_45, CK_FLEXGEN_45, 0, 45),
  985. FLEXGEN(_CK_FLEXGEN_46, CK_FLEXGEN_46, 0, 46),
  986. FLEXGEN(_CK_FLEXGEN_47, CK_FLEXGEN_47, 0, 47),
  987. FLEXGEN(_CK_FLEXGEN_48, CK_FLEXGEN_48, 0, 48),
  988. FLEXGEN(_CK_FLEXGEN_49, CK_FLEXGEN_49, 0, 49),
  989. FLEXGEN(_CK_FLEXGEN_50, CK_FLEXGEN_50, 0, 50),
  990. FLEXGEN(_CK_FLEXGEN_51, CK_FLEXGEN_51, 0, 51),
  991. FLEXGEN(_CK_FLEXGEN_52, CK_FLEXGEN_52, 0, 52),
  992. FLEXGEN(_CK_FLEXGEN_53, CK_FLEXGEN_53, 0, 53),
  993. FLEXGEN(_CK_FLEXGEN_54, CK_FLEXGEN_54, 0, 54),
  994. FLEXGEN(_CK_FLEXGEN_55, CK_FLEXGEN_55, 0, 55),
  995. FLEXGEN(_CK_FLEXGEN_56, CK_FLEXGEN_56, 0, 56),
  996. FLEXGEN(_CK_FLEXGEN_57, CK_FLEXGEN_57, 0, 57),
  997. FLEXGEN(_CK_FLEXGEN_58, CK_FLEXGEN_58, 0, 58),
  998. FLEXGEN(_CK_FLEXGEN_59, CK_FLEXGEN_59, 0, 59),
  999. FLEXGEN(_CK_FLEXGEN_60, CK_FLEXGEN_60, 0, 60),
  1000. FLEXGEN(_CK_FLEXGEN_61, CK_FLEXGEN_61, 0, 61),
  1001. FLEXGEN(_CK_FLEXGEN_62, CK_FLEXGEN_62, 0, 62),
  1002. FLEXGEN(_CK_FLEXGEN_63, CK_FLEXGEN_63, 0, 63),
  1003. STM32_DIV(_CK_ICN_APB1, CK_ICN_APB1, _CK_ICN_LS_MCU, 0, DIV_APB1),
  1004. STM32_DIV(_CK_ICN_APB2, CK_ICN_APB2, _CK_ICN_LS_MCU, 0, DIV_APB2),
  1005. STM32_DIV(_CK_ICN_APB3, CK_ICN_APB3, _CK_ICN_LS_MCU, 0, DIV_APB3),
  1006. STM32_DIV(_CK_ICN_APB4, CK_ICN_APB4, _CK_ICN_LS_MCU, 0, DIV_APB4),
  1007. STM32_DIV(_CK_ICN_APBDBG, CK_ICN_APBDBG, _CK_ICN_LS_MCU, 0, DIV_APBDBG),
  1008. /* KERNEL CLOCK */
  1009. STM32_GATE(_CK_SYSRAM, CK_BUS_SYSRAM, _CK_ICN_HS_MCU, 0, GATE_SYSRAM),
  1010. STM32_GATE(_CK_RETRAM, CK_BUS_RETRAM, _CK_ICN_HS_MCU, 0, GATE_RETRAM),
  1011. STM32_GATE(_CK_SRAM1, CK_BUS_SRAM1, _CK_ICN_HS_MCU, CLK_IS_CRITICAL, GATE_SRAM1),
  1012. STM32_GATE(_CK_SRAM2, CK_BUS_SRAM2, _CK_ICN_HS_MCU, CLK_IS_CRITICAL, GATE_SRAM2),
  1013. STM32_GATE(_CK_DDRPHYC, CK_BUS_DDRPHYC, _CK_ICN_LS_MCU, 0, GATE_DDRPHYC),
  1014. STM32_GATE(_CK_SYSCPU1, CK_BUS_SYSCPU1, _CK_ICN_LS_MCU, 0, GATE_SYSCPU1),
  1015. STM32_GATE(_CK_CRC, CK_BUS_CRC, _CK_ICN_LS_MCU, 0, GATE_CRC),
  1016. STM32_GATE(_CK_OSPIIOM, CK_BUS_OSPIIOM, _CK_ICN_LS_MCU, 0, GATE_OSPIIOM),
  1017. STM32_GATE(_CK_BKPSRAM, CK_BUS_BKPSRAM, _CK_ICN_LS_MCU, 0, GATE_BKPSRAM),
  1018. STM32_GATE(_CK_HASH, CK_BUS_HASH, _CK_ICN_LS_MCU, 0, GATE_HASH),
  1019. STM32_GATE(_CK_RNG, CK_BUS_RNG, _CK_ICN_LS_MCU, 0, GATE_RNG),
  1020. STM32_GATE(_CK_CRYP1, CK_BUS_CRYP1, _CK_ICN_LS_MCU, 0, GATE_CRYP1),
  1021. STM32_GATE(_CK_CRYP2, CK_BUS_CRYP2, _CK_ICN_LS_MCU, 0, GATE_CRYP2),
  1022. STM32_GATE(_CK_SAES, CK_BUS_SAES, _CK_ICN_LS_MCU, 0, GATE_SAES),
  1023. STM32_GATE(_CK_PKA, CK_BUS_PKA, _CK_ICN_LS_MCU, 0, GATE_PKA),
  1024. STM32_GATE(_CK_GPIOA, CK_BUS_GPIOA, _CK_ICN_LS_MCU, 0, GATE_GPIOA),
  1025. STM32_GATE(_CK_GPIOB, CK_BUS_GPIOB, _CK_ICN_LS_MCU, 0, GATE_GPIOB),
  1026. STM32_GATE(_CK_GPIOC, CK_BUS_GPIOC, _CK_ICN_LS_MCU, 0, GATE_GPIOC),
  1027. STM32_GATE(_CK_GPIOD, CK_BUS_GPIOD, _CK_ICN_LS_MCU, 0, GATE_GPIOD),
  1028. STM32_GATE(_CK_GPIOE, CK_BUS_GPIOE, _CK_ICN_LS_MCU, 0, GATE_GPIOE),
  1029. STM32_GATE(_CK_GPIOF, CK_BUS_GPIOF, _CK_ICN_LS_MCU, 0, GATE_GPIOF),
  1030. STM32_GATE(_CK_GPIOG, CK_BUS_GPIOG, _CK_ICN_LS_MCU, 0, GATE_GPIOG),
  1031. STM32_GATE(_CK_GPIOH, CK_BUS_GPIOH, _CK_ICN_LS_MCU, 0, GATE_GPIOH),
  1032. STM32_GATE(_CK_GPIOI, CK_BUS_GPIOI, _CK_ICN_LS_MCU, 0, GATE_GPIOI),
  1033. STM32_GATE(_CK_GPIOJ, CK_BUS_GPIOJ, _CK_ICN_LS_MCU, 0, GATE_GPIOJ),
  1034. STM32_GATE(_CK_GPIOK, CK_BUS_GPIOK, _CK_ICN_LS_MCU, 0, GATE_GPIOK),
  1035. STM32_GATE(_CK_GPIOZ, CK_BUS_GPIOZ, _CK_ICN_LS_MCU, 0, GATE_GPIOZ),
  1036. STM32_GATE(_CK_RTC, CK_BUS_RTC, _CK_ICN_LS_MCU, 0, GATE_RTC),
  1037. STM32_GATE(_CK_DDRCP, CK_BUS_DDR, _CK_ICN_DDR, 0, GATE_DDRCP),
  1038. /* WARNING 2 CLOCKS FOR ONE GATE */
  1039. STM32_GATE(_CK_USB2OHCI, CK_BUS_USB2OHCI, _CK_ICN_HSL, 0, GATE_USB2OHCI),
  1040. STM32_GATE(_CK_USB2EHCI, CK_BUS_USB2EHCI, _CK_ICN_HSL, 0, GATE_USB2EHCI),
  1041. STM32_GATE(_CK_USB3DR, CK_BUS_USB3DR, _CK_ICN_HSL, 0, GATE_USB3DR),
  1042. STM32_GATE(_CK_BSEC, CK_BUS_BSEC, _CK_ICN_APB3, 0, GATE_BSEC),
  1043. STM32_GATE(_CK_IWDG1, CK_BUS_IWDG1, _CK_ICN_APB3, 0, GATE_IWDG1),
  1044. STM32_GATE(_CK_IWDG2, CK_BUS_IWDG2, _CK_ICN_APB3, 0, GATE_IWDG2),
  1045. STM32_GATE(_CK_DDRCAPB, CK_BUS_DDRC, _CK_ICN_APB4, 0, GATE_DDRCAPB),
  1046. STM32_GATE(_CK_DDR, CK_BUS_DDRCFG, _CK_ICN_APB4, 0, GATE_DDR),
  1047. STM32_GATE(_CK_USART2, CK_KER_USART2, _CK_FLEXGEN_08, 0, GATE_USART2),
  1048. STM32_GATE(_CK_UART4, CK_KER_UART4, _CK_FLEXGEN_08, 0, GATE_UART4),
  1049. STM32_GATE(_CK_USART3, CK_KER_USART3, _CK_FLEXGEN_09, 0, GATE_USART3),
  1050. STM32_GATE(_CK_UART5, CK_KER_UART5, _CK_FLEXGEN_09, 0, GATE_UART5),
  1051. STM32_GATE(_CK_I2C1, CK_KER_I2C1, _CK_FLEXGEN_12, 0, GATE_I2C1),
  1052. STM32_GATE(_CK_I2C2, CK_KER_I2C2, _CK_FLEXGEN_12, 0, GATE_I2C2),
  1053. STM32_GATE(_CK_I2C3, CK_KER_I2C3, _CK_FLEXGEN_13, 0, GATE_I2C3),
  1054. STM32_GATE(_CK_I2C5, CK_KER_I2C5, _CK_FLEXGEN_13, 0, GATE_I2C5),
  1055. STM32_GATE(_CK_I2C4, CK_KER_I2C4, _CK_FLEXGEN_14, 0, GATE_I2C4),
  1056. STM32_GATE(_CK_I2C6, CK_KER_I2C6, _CK_FLEXGEN_14, 0, GATE_I2C6),
  1057. STM32_GATE(_CK_I2C7, CK_KER_I2C7, _CK_FLEXGEN_15, 0, GATE_I2C7),
  1058. STM32_GATE(_CK_USART1, CK_KER_USART1, _CK_FLEXGEN_19, 0, GATE_USART1),
  1059. STM32_GATE(_CK_USART6, CK_KER_USART6, _CK_FLEXGEN_20, 0, GATE_USART6),
  1060. STM32_GATE(_CK_UART7, CK_KER_UART7, _CK_FLEXGEN_21, 0, GATE_UART7),
  1061. STM32_GATE(_CK_UART8, CK_KER_UART8, _CK_FLEXGEN_21, 0, GATE_UART8),
  1062. STM32_GATE(_CK_UART9, CK_KER_UART9, _CK_FLEXGEN_22, 0, GATE_UART9),
  1063. STM32_GATE(_CK_STGEN, CK_KER_STGEN, _CK_FLEXGEN_33, 0, GATE_STGEN),
  1064. STM32_GATE(_CK_USB3PCIEPHY, CK_KER_USB3PCIEPHY, _CK_FLEXGEN_34, 0, GATE_USB3PCIEPHY),
  1065. STM32_GATE(_CK_USBTC, CK_KER_USBTC, _CK_FLEXGEN_35, 0, GATE_USBTC),
  1066. STM32_GATE(_CK_I2C8, CK_KER_I2C8, _CK_FLEXGEN_38, 0, GATE_I2C8),
  1067. STM32_GATE(_CK_OSPI1, CK_KER_OSPI1, _CK_FLEXGEN_48, 0, GATE_OSPI1),
  1068. STM32_GATE(_CK_OSPI2, CK_KER_OSPI2, _CK_FLEXGEN_49, 0, GATE_OSPI2),
  1069. STM32_GATE(_CK_FMC, CK_KER_FMC, _CK_FLEXGEN_50, 0, GATE_FMC),
  1070. STM32_GATE(_CK_SDMMC1, CK_KER_SDMMC1, _CK_FLEXGEN_51, 0, GATE_SDMMC1),
  1071. STM32_GATE(_CK_SDMMC2, CK_KER_SDMMC2, _CK_FLEXGEN_52, 0, GATE_SDMMC2),
  1072. STM32_GATE(_CK_USB2PHY1, CK_KER_USB2PHY1, _CK_FLEXGEN_57, 0, GATE_USB2PHY1),
  1073. STM32_GATE(_CK_USB2PHY2, CK_KER_USB2PHY2, _CK_FLEXGEN_58, 0, GATE_USB2PHY2),
  1074. };
  1075. enum clksrc_id {
  1076. CLKSRC_CA35SS,
  1077. CLKSRC_PLL1,
  1078. CLKSRC_PLL2,
  1079. CLKSRC_PLL3,
  1080. CLKSRC_PLL4,
  1081. CLKSRC_PLL5,
  1082. CLKSRC_PLL6,
  1083. CLKSRC_PLL7,
  1084. CLKSRC_PLL8,
  1085. CLKSRC_XBAR_CHANNEL0,
  1086. CLKSRC_XBAR_CHANNEL1,
  1087. CLKSRC_XBAR_CHANNEL2,
  1088. CLKSRC_XBAR_CHANNEL3,
  1089. CLKSRC_XBAR_CHANNEL4,
  1090. CLKSRC_XBAR_CHANNEL5,
  1091. CLKSRC_XBAR_CHANNEL6,
  1092. CLKSRC_XBAR_CHANNEL7,
  1093. CLKSRC_XBAR_CHANNEL8,
  1094. CLKSRC_XBAR_CHANNEL9,
  1095. CLKSRC_XBAR_CHANNEL10,
  1096. CLKSRC_XBAR_CHANNEL11,
  1097. CLKSRC_XBAR_CHANNEL12,
  1098. CLKSRC_XBAR_CHANNEL13,
  1099. CLKSRC_XBAR_CHANNEL14,
  1100. CLKSRC_XBAR_CHANNEL15,
  1101. CLKSRC_XBAR_CHANNEL16,
  1102. CLKSRC_XBAR_CHANNEL17,
  1103. CLKSRC_XBAR_CHANNEL18,
  1104. CLKSRC_XBAR_CHANNEL19,
  1105. CLKSRC_XBAR_CHANNEL20,
  1106. CLKSRC_XBAR_CHANNEL21,
  1107. CLKSRC_XBAR_CHANNEL22,
  1108. CLKSRC_XBAR_CHANNEL23,
  1109. CLKSRC_XBAR_CHANNEL24,
  1110. CLKSRC_XBAR_CHANNEL25,
  1111. CLKSRC_XBAR_CHANNEL26,
  1112. CLKSRC_XBAR_CHANNEL27,
  1113. CLKSRC_XBAR_CHANNEL28,
  1114. CLKSRC_XBAR_CHANNEL29,
  1115. CLKSRC_XBAR_CHANNEL30,
  1116. CLKSRC_XBAR_CHANNEL31,
  1117. CLKSRC_XBAR_CHANNEL32,
  1118. CLKSRC_XBAR_CHANNEL33,
  1119. CLKSRC_XBAR_CHANNEL34,
  1120. CLKSRC_XBAR_CHANNEL35,
  1121. CLKSRC_XBAR_CHANNEL36,
  1122. CLKSRC_XBAR_CHANNEL37,
  1123. CLKSRC_XBAR_CHANNEL38,
  1124. CLKSRC_XBAR_CHANNEL39,
  1125. CLKSRC_XBAR_CHANNEL40,
  1126. CLKSRC_XBAR_CHANNEL41,
  1127. CLKSRC_XBAR_CHANNEL42,
  1128. CLKSRC_XBAR_CHANNEL43,
  1129. CLKSRC_XBAR_CHANNEL44,
  1130. CLKSRC_XBAR_CHANNEL45,
  1131. CLKSRC_XBAR_CHANNEL46,
  1132. CLKSRC_XBAR_CHANNEL47,
  1133. CLKSRC_XBAR_CHANNEL48,
  1134. CLKSRC_XBAR_CHANNEL49,
  1135. CLKSRC_XBAR_CHANNEL50,
  1136. CLKSRC_XBAR_CHANNEL51,
  1137. CLKSRC_XBAR_CHANNEL52,
  1138. CLKSRC_XBAR_CHANNEL53,
  1139. CLKSRC_XBAR_CHANNEL54,
  1140. CLKSRC_XBAR_CHANNEL55,
  1141. CLKSRC_XBAR_CHANNEL56,
  1142. CLKSRC_XBAR_CHANNEL57,
  1143. CLKSRC_XBAR_CHANNEL58,
  1144. CLKSRC_XBAR_CHANNEL59,
  1145. CLKSRC_XBAR_CHANNEL60,
  1146. CLKSRC_XBAR_CHANNEL61,
  1147. CLKSRC_XBAR_CHANNEL62,
  1148. CLKSRC_XBAR_CHANNEL63,
  1149. CLKSRC_RTC,
  1150. CLKSRC_MCO1,
  1151. CLKSRC_MCO2,
  1152. CLKSRC_NB
  1153. };
  1154. static void stm32mp2_a35_ss_on_hsi(void)
  1155. {
  1156. uintptr_t a35_ss_address = A35SSC_BASE;
  1157. uintptr_t chgclkreq_reg = a35_ss_address + A35_SS_CHGCLKREQ;
  1158. uintptr_t pll_enable_reg = a35_ss_address + A35_SS_PLL_ENABLE;
  1159. uint64_t timeout;
  1160. if ((mmio_read_32(chgclkreq_reg) & A35_SS_CHGCLKREQ_ARM_CHGCLKACK) ==
  1161. A35_SS_CHGCLKREQ_ARM_CHGCLKACK) {
  1162. /* Nothing to do, clock source is already set on bypass clock */
  1163. return;
  1164. }
  1165. mmio_setbits_32(chgclkreq_reg, A35_SS_CHGCLKREQ_ARM_CHGCLKREQ);
  1166. timeout = timeout_init_us(CLKSRC_TIMEOUT);
  1167. while ((mmio_read_32(chgclkreq_reg) & A35_SS_CHGCLKREQ_ARM_CHGCLKACK) !=
  1168. A35_SS_CHGCLKREQ_ARM_CHGCLKACK) {
  1169. if (timeout_elapsed(timeout)) {
  1170. EARLY_ERROR("Cannot switch A35 to bypass clock\n");
  1171. panic();
  1172. }
  1173. }
  1174. mmio_clrbits_32(pll_enable_reg, A35_SS_PLL_ENABLE_NRESET_SWPLL_FF);
  1175. }
  1176. #ifdef IMAGE_BL2
  1177. static void stm32mp2_clk_muxsel_on_hsi(struct stm32_clk_priv *priv)
  1178. {
  1179. mmio_clrbits_32(priv->base + RCC_MUXSELCFGR,
  1180. RCC_MUXSELCFGR_MUXSEL0_MASK |
  1181. RCC_MUXSELCFGR_MUXSEL1_MASK |
  1182. RCC_MUXSELCFGR_MUXSEL2_MASK |
  1183. RCC_MUXSELCFGR_MUXSEL3_MASK |
  1184. RCC_MUXSELCFGR_MUXSEL4_MASK |
  1185. RCC_MUXSELCFGR_MUXSEL5_MASK |
  1186. RCC_MUXSELCFGR_MUXSEL6_MASK |
  1187. RCC_MUXSELCFGR_MUXSEL7_MASK);
  1188. }
  1189. static void stm32mp2_clk_xbar_on_hsi(struct stm32_clk_priv *priv)
  1190. {
  1191. uintptr_t xbar0cfgr = priv->base + RCC_XBAR0CFGR;
  1192. uint32_t i;
  1193. for (i = 0; i < XBAR_CHANNEL_NB; i++) {
  1194. mmio_clrsetbits_32(xbar0cfgr + (0x4 * i),
  1195. RCC_XBAR0CFGR_XBAR0SEL_MASK,
  1196. XBAR_SRC_HSI);
  1197. }
  1198. }
  1199. static int stm32mp2_a35_pll1_start(void)
  1200. {
  1201. uintptr_t a35_ss_address = A35SSC_BASE;
  1202. uintptr_t pll_enable_reg = a35_ss_address + A35_SS_PLL_ENABLE;
  1203. uintptr_t chgclkreq_reg = a35_ss_address + A35_SS_CHGCLKREQ;
  1204. uint64_t timeout = timeout_init_us(PLLRDY_TIMEOUT);
  1205. mmio_setbits_32(pll_enable_reg, A35_SS_PLL_ENABLE_PD);
  1206. /* Wait PLL lock */
  1207. while ((mmio_read_32(pll_enable_reg) & A35_SS_PLL_ENABLE_LOCKP) == 0U) {
  1208. if (timeout_elapsed(timeout)) {
  1209. EARLY_ERROR("PLL1 start failed @ 0x%lx: 0x%x\n",
  1210. pll_enable_reg, mmio_read_32(pll_enable_reg));
  1211. return -ETIMEDOUT;
  1212. }
  1213. }
  1214. /* De-assert reset on PLL output clock path */
  1215. mmio_setbits_32(pll_enable_reg, A35_SS_PLL_ENABLE_NRESET_SWPLL_FF);
  1216. /* Switch CPU clock to PLL clock */
  1217. mmio_clrbits_32(chgclkreq_reg, A35_SS_CHGCLKREQ_ARM_CHGCLKREQ);
  1218. /* Wait for clock change acknowledge */
  1219. timeout = timeout_init_us(CLKSRC_TIMEOUT);
  1220. while ((mmio_read_32(chgclkreq_reg) & A35_SS_CHGCLKREQ_ARM_CHGCLKACK) != 0U) {
  1221. if (timeout_elapsed(timeout)) {
  1222. EARLY_ERROR("CA35SS switch to PLL1 failed @ 0x%lx: 0x%x\n",
  1223. chgclkreq_reg, mmio_read_32(chgclkreq_reg));
  1224. return -ETIMEDOUT;
  1225. }
  1226. }
  1227. return 0;
  1228. }
  1229. static void stm32mp2_a35_pll1_config(uint32_t fbdiv, uint32_t refdiv, uint32_t postdiv1,
  1230. uint32_t postdiv2)
  1231. {
  1232. uintptr_t a35_ss_address = A35SSC_BASE;
  1233. uintptr_t pll_freq1_reg = a35_ss_address + A35_SS_PLL_FREQ1;
  1234. uintptr_t pll_freq2_reg = a35_ss_address + A35_SS_PLL_FREQ2;
  1235. mmio_clrsetbits_32(pll_freq1_reg, A35_SS_PLL_FREQ1_REFDIV_MASK,
  1236. (refdiv << A35_SS_PLL_FREQ1_REFDIV_SHIFT) &
  1237. A35_SS_PLL_FREQ1_REFDIV_MASK);
  1238. mmio_clrsetbits_32(pll_freq1_reg, A35_SS_PLL_FREQ1_FBDIV_MASK,
  1239. (fbdiv << A35_SS_PLL_FREQ1_FBDIV_SHIFT) &
  1240. A35_SS_PLL_FREQ1_FBDIV_MASK);
  1241. mmio_clrsetbits_32(pll_freq2_reg, A35_SS_PLL_FREQ2_POSTDIV1_MASK,
  1242. (postdiv1 << A35_SS_PLL_FREQ2_POSTDIV1_SHIFT) &
  1243. A35_SS_PLL_FREQ2_POSTDIV1_MASK);
  1244. mmio_clrsetbits_32(pll_freq2_reg, A35_SS_PLL_FREQ2_POSTDIV2_MASK,
  1245. (postdiv2 << A35_SS_PLL_FREQ2_POSTDIV2_SHIFT) &
  1246. A35_SS_PLL_FREQ2_POSTDIV2_MASK);
  1247. }
  1248. static int clk_stm32_pll_config_output(struct stm32_clk_priv *priv,
  1249. const struct stm32_clk_pll *pll,
  1250. uint32_t *pllcfg,
  1251. uint32_t fracv)
  1252. {
  1253. uintptr_t pllxcfgr1 = priv->base + pll->reg_pllxcfgr1;
  1254. uintptr_t pllxcfgr2 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR2;
  1255. uintptr_t pllxcfgr3 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR3;
  1256. uintptr_t pllxcfgr4 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR4;
  1257. uintptr_t pllxcfgr6 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR6;
  1258. uintptr_t pllxcfgr7 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR7;
  1259. unsigned long refclk;
  1260. refclk = _clk_stm32_get_parent_rate(priv, pll->clk_id);
  1261. if (fracv == 0U) {
  1262. /* PLL in integer mode */
  1263. /*
  1264. * No need to check max clock, as oscillator reference clocks
  1265. * will always be less than 1.2GHz
  1266. */
  1267. if (refclk < PLL_REFCLK_MIN) {
  1268. panic();
  1269. }
  1270. mmio_clrbits_32(pllxcfgr3, RCC_PLLxCFGR3_FRACIN_MASK);
  1271. mmio_clrbits_32(pllxcfgr4, RCC_PLLxCFGR4_DSMEN);
  1272. mmio_clrbits_32(pllxcfgr3, RCC_PLLxCFGR3_DACEN);
  1273. mmio_setbits_32(pllxcfgr3, RCC_PLLxCFGR3_SSCGDIS);
  1274. mmio_setbits_32(pllxcfgr1, RCC_PLLxCFGR1_SSMODRST);
  1275. } else {
  1276. /* PLL in frac mode */
  1277. /*
  1278. * No need to check max clock, as oscillator reference clocks
  1279. * will always be less than 1.2GHz
  1280. */
  1281. if (refclk < PLL_FRAC_REFCLK_MIN) {
  1282. panic();
  1283. }
  1284. mmio_clrsetbits_32(pllxcfgr3, RCC_PLLxCFGR3_FRACIN_MASK,
  1285. fracv & RCC_PLLxCFGR3_FRACIN_MASK);
  1286. mmio_setbits_32(pllxcfgr3, RCC_PLLxCFGR3_SSCGDIS);
  1287. mmio_setbits_32(pllxcfgr4, RCC_PLLxCFGR4_DSMEN);
  1288. }
  1289. assert(pllcfg[REFDIV] != 0U);
  1290. mmio_clrsetbits_32(pllxcfgr2, RCC_PLLxCFGR2_FBDIV_MASK,
  1291. (pllcfg[FBDIV] << RCC_PLLxCFGR2_FBDIV_SHIFT) &
  1292. RCC_PLLxCFGR2_FBDIV_MASK);
  1293. mmio_clrsetbits_32(pllxcfgr2, RCC_PLLxCFGR2_FREFDIV_MASK,
  1294. pllcfg[REFDIV] & RCC_PLLxCFGR2_FREFDIV_MASK);
  1295. mmio_clrsetbits_32(pllxcfgr6, RCC_PLLxCFGR6_POSTDIV1_MASK,
  1296. pllcfg[POSTDIV1] & RCC_PLLxCFGR6_POSTDIV1_MASK);
  1297. mmio_clrsetbits_32(pllxcfgr7, RCC_PLLxCFGR7_POSTDIV2_MASK,
  1298. pllcfg[POSTDIV2] & RCC_PLLxCFGR7_POSTDIV2_MASK);
  1299. if ((pllcfg[POSTDIV1] == 0U) || (pllcfg[POSTDIV2] == 0U)) {
  1300. /* Bypass mode */
  1301. mmio_setbits_32(pllxcfgr4, RCC_PLLxCFGR4_BYPASS);
  1302. mmio_clrbits_32(pllxcfgr4, RCC_PLLxCFGR4_FOUTPOSTDIVEN);
  1303. } else {
  1304. mmio_clrbits_32(pllxcfgr4, RCC_PLLxCFGR4_BYPASS);
  1305. mmio_setbits_32(pllxcfgr4, RCC_PLLxCFGR4_FOUTPOSTDIVEN);
  1306. }
  1307. return 0;
  1308. }
  1309. static void clk_stm32_pll_config_csg(struct stm32_clk_priv *priv,
  1310. const struct stm32_clk_pll *pll,
  1311. uint32_t *csg)
  1312. {
  1313. uintptr_t pllxcfgr1 = priv->base + pll->reg_pllxcfgr1;
  1314. uintptr_t pllxcfgr3 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR3;
  1315. uintptr_t pllxcfgr4 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR4;
  1316. uintptr_t pllxcfgr5 = pllxcfgr1 + RCC_OFFSET_PLLXCFGR5;
  1317. mmio_clrsetbits_32(pllxcfgr5, RCC_PLLxCFGR5_DIVVAL_MASK,
  1318. csg[DIVVAL] & RCC_PLLxCFGR5_DIVVAL_MASK);
  1319. mmio_clrsetbits_32(pllxcfgr5, RCC_PLLxCFGR5_SPREAD_MASK,
  1320. (csg[SPREAD] << RCC_PLLxCFGR5_SPREAD_SHIFT) &
  1321. RCC_PLLxCFGR5_SPREAD_MASK);
  1322. if (csg[DOWNSPREAD] != 0) {
  1323. mmio_setbits_32(pllxcfgr3, RCC_PLLxCFGR3_DOWNSPREAD);
  1324. } else {
  1325. mmio_clrbits_32(pllxcfgr3, RCC_PLLxCFGR3_DOWNSPREAD);
  1326. }
  1327. mmio_clrbits_32(pllxcfgr3, RCC_PLLxCFGR3_SSCGDIS);
  1328. mmio_clrbits_32(pllxcfgr1, RCC_PLLxCFGR1_PLLEN);
  1329. udelay(1);
  1330. mmio_setbits_32(pllxcfgr4, RCC_PLLxCFGR4_DSMEN);
  1331. mmio_setbits_32(pllxcfgr3, RCC_PLLxCFGR3_DACEN);
  1332. }
  1333. static int stm32_clk_configure_mux(struct stm32_clk_priv *priv, uint32_t data);
  1334. static inline struct stm32_pll_dt_cfg *clk_stm32_pll_get_pdata(int pll_idx)
  1335. {
  1336. struct stm32_clk_priv *priv = clk_stm32_get_priv();
  1337. struct stm32_clk_platdata *pdata = priv->pdata;
  1338. return &pdata->pll[pll_idx];
  1339. }
  1340. static int _clk_stm32_pll1_init(struct stm32_clk_priv *priv, int pll_idx,
  1341. struct stm32_pll_dt_cfg *pll_conf)
  1342. {
  1343. const struct stm32_clk_pll *pll = clk_stm32_pll_data(pll_idx);
  1344. unsigned long refclk;
  1345. int ret = 0;
  1346. stm32mp2_a35_ss_on_hsi();
  1347. ret = stm32_clk_configure_mux(priv, pll_conf->src);
  1348. if (ret != 0) {
  1349. panic();
  1350. }
  1351. refclk = _clk_stm32_get_parent_rate(priv, pll->clk_id);
  1352. /*
  1353. * No need to check max clock, as oscillator reference clocks will
  1354. * always be less than 1.2 GHz
  1355. */
  1356. if (refclk < PLL_REFCLK_MIN) {
  1357. EARLY_ERROR("%s: %d\n", __func__, __LINE__);
  1358. panic();
  1359. }
  1360. stm32mp2_a35_pll1_config(pll_conf->cfg[FBDIV], pll_conf->cfg[REFDIV],
  1361. pll_conf->cfg[POSTDIV1], pll_conf->cfg[POSTDIV2]);
  1362. ret = stm32mp2_a35_pll1_start();
  1363. if (ret != 0) {
  1364. panic();
  1365. }
  1366. return 0;
  1367. }
  1368. static int clk_stm32_pll_wait_mux_ready(struct stm32_clk_priv *priv,
  1369. const struct stm32_clk_pll *pll)
  1370. {
  1371. uintptr_t pllxcfgr1 = priv->base + pll->reg_pllxcfgr1;
  1372. uint64_t timeout = timeout_init_us(CLKSRC_TIMEOUT);
  1373. while ((mmio_read_32(pllxcfgr1) & RCC_PLLxCFGR1_CKREFST) !=
  1374. RCC_PLLxCFGR1_CKREFST) {
  1375. if (timeout_elapsed(timeout)) {
  1376. EARLY_ERROR("PLL%d ref clock not started\n", pll->clk_id - _CK_PLL1 + 1);
  1377. return -ETIMEDOUT;
  1378. }
  1379. }
  1380. return 0;
  1381. }
  1382. static int _clk_stm32_pll_init(struct stm32_clk_priv *priv, int pll_idx,
  1383. struct stm32_pll_dt_cfg *pll_conf)
  1384. {
  1385. const struct stm32_clk_pll *pll = clk_stm32_pll_data(pll_idx);
  1386. uintptr_t pllxcfgr1 = priv->base + pll->reg_pllxcfgr1;
  1387. bool spread_spectrum = false;
  1388. int ret = 0;
  1389. _clk_stm32_pll_disable(priv, pll);
  1390. ret = stm32_clk_configure_mux(priv, pll_conf->src);
  1391. if (ret != 0) {
  1392. panic();
  1393. }
  1394. ret = clk_stm32_pll_wait_mux_ready(priv, pll);
  1395. if (ret != 0) {
  1396. panic();
  1397. }
  1398. ret = clk_stm32_pll_config_output(priv, pll, pll_conf->cfg, pll_conf->frac);
  1399. if (ret != 0) {
  1400. panic();
  1401. }
  1402. if (pll_conf->csg_enabled) {
  1403. clk_stm32_pll_config_csg(priv, pll, pll_conf->csg);
  1404. spread_spectrum = true;
  1405. }
  1406. _clk_stm32_pll_enable(priv, pll);
  1407. if (spread_spectrum) {
  1408. mmio_clrbits_32(pllxcfgr1, RCC_PLLxCFGR1_SSMODRST);
  1409. }
  1410. return 0;
  1411. }
  1412. static int clk_stm32_pll_init(struct stm32_clk_priv *priv, int pll_idx)
  1413. {
  1414. struct stm32_pll_dt_cfg *pll_conf = clk_stm32_pll_get_pdata(pll_idx);
  1415. if (pll_conf->enabled) {
  1416. if (pll_idx == _PLL1) {
  1417. return _clk_stm32_pll1_init(priv, pll_idx, pll_conf);
  1418. } else {
  1419. return _clk_stm32_pll_init(priv, pll_idx, pll_conf);
  1420. }
  1421. }
  1422. return 0;
  1423. }
  1424. static int stm32mp2_clk_pll_configure(struct stm32_clk_priv *priv)
  1425. {
  1426. enum pll_id i;
  1427. int err;
  1428. for (i = _PLL1; i < _PLL_NB; i++) {
  1429. err = clk_stm32_pll_init(priv, i);
  1430. if (err) {
  1431. return err;
  1432. }
  1433. }
  1434. return 0;
  1435. }
  1436. static int wait_predivsr(uint16_t channel)
  1437. {
  1438. struct stm32_clk_priv *priv = clk_stm32_get_priv();
  1439. uintptr_t rcc_base = priv->base;
  1440. uintptr_t previvsr;
  1441. uint32_t channel_bit;
  1442. uint64_t timeout;
  1443. if (channel < __WORD_BIT) {
  1444. previvsr = rcc_base + RCC_PREDIVSR1;
  1445. channel_bit = BIT(channel);
  1446. } else {
  1447. previvsr = rcc_base + RCC_PREDIVSR2;
  1448. channel_bit = BIT(channel - __WORD_BIT);
  1449. }
  1450. timeout = timeout_init_us(CLKDIV_TIMEOUT);
  1451. while ((mmio_read_32(previvsr) & channel_bit) != 0U) {
  1452. if (timeout_elapsed(timeout)) {
  1453. EARLY_ERROR("Pre divider status: %x\n",
  1454. mmio_read_32(previvsr));
  1455. return -ETIMEDOUT;
  1456. }
  1457. }
  1458. return 0;
  1459. }
  1460. static int wait_findivsr(uint16_t channel)
  1461. {
  1462. struct stm32_clk_priv *priv = clk_stm32_get_priv();
  1463. uintptr_t rcc_base = priv->base;
  1464. uintptr_t finvivsr;
  1465. uint32_t channel_bit;
  1466. uint64_t timeout;
  1467. if (channel < __WORD_BIT) {
  1468. finvivsr = rcc_base + RCC_FINDIVSR1;
  1469. channel_bit = BIT(channel);
  1470. } else {
  1471. finvivsr = rcc_base + RCC_FINDIVSR2;
  1472. channel_bit = BIT(channel - __WORD_BIT);
  1473. }
  1474. timeout = timeout_init_us(CLKDIV_TIMEOUT);
  1475. while ((mmio_read_32(finvivsr) & channel_bit) != 0U) {
  1476. if (timeout_elapsed(timeout)) {
  1477. EARLY_ERROR("Final divider status: %x\n",
  1478. mmio_read_32(finvivsr));
  1479. return -ETIMEDOUT;
  1480. }
  1481. }
  1482. return 0;
  1483. }
  1484. static int wait_xbar_sts(uint16_t channel)
  1485. {
  1486. struct stm32_clk_priv *priv = clk_stm32_get_priv();
  1487. uintptr_t rcc_base = priv->base;
  1488. uintptr_t xbar_cfgr = rcc_base + RCC_XBAR0CFGR + (0x4U * channel);
  1489. uint64_t timeout;
  1490. timeout = timeout_init_us(CLKDIV_TIMEOUT);
  1491. while ((mmio_read_32(xbar_cfgr) & RCC_XBAR0CFGR_XBAR0STS) != 0U) {
  1492. if (timeout_elapsed(timeout)) {
  1493. EARLY_ERROR("XBAR%uCFGR: %x\n", channel,
  1494. mmio_read_32(xbar_cfgr));
  1495. return -ETIMEDOUT;
  1496. }
  1497. }
  1498. return 0;
  1499. }
  1500. static void flexclkgen_config_channel(uint16_t channel, unsigned int clk_src,
  1501. unsigned int prediv, unsigned int findiv)
  1502. {
  1503. struct stm32_clk_priv *priv = clk_stm32_get_priv();
  1504. uintptr_t rcc_base = priv->base;
  1505. if (wait_predivsr(channel) != 0) {
  1506. panic();
  1507. }
  1508. mmio_clrsetbits_32(rcc_base + RCC_PREDIV0CFGR + (0x4U * channel),
  1509. RCC_PREDIV0CFGR_PREDIV0_MASK,
  1510. prediv);
  1511. if (wait_predivsr(channel) != 0) {
  1512. panic();
  1513. }
  1514. if (wait_findivsr(channel) != 0) {
  1515. panic();
  1516. }
  1517. mmio_clrsetbits_32(rcc_base + RCC_FINDIV0CFGR + (0x4U * channel),
  1518. RCC_FINDIV0CFGR_FINDIV0_MASK,
  1519. findiv);
  1520. if (wait_findivsr(channel) != 0) {
  1521. panic();
  1522. }
  1523. if (wait_xbar_sts(channel) != 0) {
  1524. panic();
  1525. }
  1526. mmio_clrsetbits_32(rcc_base + RCC_XBAR0CFGR + (0x4U * channel),
  1527. RCC_XBARxCFGR_XBARxSEL_MASK,
  1528. clk_src);
  1529. mmio_setbits_32(rcc_base + RCC_XBAR0CFGR + (0x4U * channel),
  1530. RCC_XBARxCFGR_XBARxEN);
  1531. if (wait_xbar_sts(channel) != 0) {
  1532. panic();
  1533. }
  1534. }
  1535. static int stm32mp2_clk_flexgen_configure(struct stm32_clk_priv *priv)
  1536. {
  1537. struct stm32_clk_platdata *pdata = priv->pdata;
  1538. uint32_t i;
  1539. for (i = 0U; i < pdata->nflexgen; i++) {
  1540. uint32_t val = pdata->flexgen[i];
  1541. uint32_t cmd, cmd_data;
  1542. unsigned int channel, clk_src, pdiv, fdiv;
  1543. cmd = (val & CMD_MASK) >> CMD_SHIFT;
  1544. cmd_data = val & ~CMD_MASK;
  1545. if (cmd != CMD_FLEXGEN) {
  1546. continue;
  1547. }
  1548. channel = (cmd_data & FLEX_ID_MASK) >> FLEX_ID_SHIFT;
  1549. clk_src = (cmd_data & FLEX_SEL_MASK) >> FLEX_SEL_SHIFT;
  1550. pdiv = (cmd_data & FLEX_PDIV_MASK) >> FLEX_PDIV_SHIFT;
  1551. fdiv = (cmd_data & FLEX_FDIV_MASK) >> FLEX_FDIV_SHIFT;
  1552. switch (channel) {
  1553. case 33U: /* STGEN */
  1554. break;
  1555. default:
  1556. flexclkgen_config_channel(channel, clk_src, pdiv, fdiv);
  1557. break;
  1558. }
  1559. }
  1560. return 0;
  1561. }
  1562. static void stm32_enable_oscillator_hse(struct stm32_clk_priv *priv)
  1563. {
  1564. struct stm32_clk_platdata *pdata = priv->pdata;
  1565. struct stm32_osci_dt_cfg *osci = &pdata->osci[OSC_HSE];
  1566. bool digbyp = osci->digbyp;
  1567. bool bypass = osci->bypass;
  1568. bool css = osci->css;
  1569. if (_clk_stm32_get_rate(priv, _CK_HSE) == 0U) {
  1570. return;
  1571. }
  1572. clk_oscillator_set_bypass(priv, _CK_HSE, digbyp, bypass);
  1573. _clk_stm32_enable(priv, _CK_HSE);
  1574. clk_oscillator_set_css(priv, _CK_HSE, css);
  1575. }
  1576. static void stm32_enable_oscillator_lse(struct stm32_clk_priv *priv)
  1577. {
  1578. struct clk_oscillator_data *osc_data = clk_oscillator_get_data(priv, _CK_LSE);
  1579. struct stm32_clk_platdata *pdata = priv->pdata;
  1580. struct stm32_osci_dt_cfg *osci = &pdata->osci[OSC_LSE];
  1581. bool digbyp = osci->digbyp;
  1582. bool bypass = osci->bypass;
  1583. uint8_t drive = osci->drive;
  1584. if (_clk_stm32_get_rate(priv, _CK_LSE) == 0U) {
  1585. return;
  1586. }
  1587. /* Do not reconfigure LSE if already enabled */
  1588. if (_clk_stm32_gate_is_enabled(priv, osc_data->gate_id)) {
  1589. return;
  1590. }
  1591. clk_oscillator_set_bypass(priv, _CK_LSE, digbyp, bypass);
  1592. clk_oscillator_set_drive(priv, _CK_LSE, drive);
  1593. _clk_stm32_gate_enable(priv, osc_data->gate_id);
  1594. }
  1595. static int stm32mp2_clk_switch_to_hsi(struct stm32_clk_priv *priv)
  1596. {
  1597. stm32mp2_a35_ss_on_hsi();
  1598. stm32mp2_clk_muxsel_on_hsi(priv);
  1599. stm32mp2_clk_xbar_on_hsi(priv);
  1600. return 0;
  1601. }
  1602. static int stm32_clk_oscillators_wait_lse_ready(struct stm32_clk_priv *priv)
  1603. {
  1604. int ret = 0;
  1605. if (_clk_stm32_get_rate(priv, _CK_LSE) != 0U) {
  1606. ret = clk_oscillator_wait_ready_on(priv, _CK_LSE);
  1607. }
  1608. return ret;
  1609. }
  1610. static void stm32_enable_oscillator_msi(struct stm32_clk_priv *priv)
  1611. {
  1612. struct stm32_clk_platdata *pdata = priv->pdata;
  1613. struct stm32_osci_dt_cfg *osci = &pdata->osci[OSC_MSI];
  1614. int err;
  1615. err = clk_stm32_osc_msi_set_rate(priv, _CK_MSI, osci->freq, 0);
  1616. if (err != 0) {
  1617. EARLY_ERROR("Invalid rate %lu MHz for MSI ! (4 or 16 only)\n",
  1618. osci->freq / 1000000U);
  1619. panic();
  1620. }
  1621. _clk_stm32_enable(priv, _CK_MSI);
  1622. }
  1623. static void stm32_clk_oscillators_enable(struct stm32_clk_priv *priv)
  1624. {
  1625. stm32_enable_oscillator_hse(priv);
  1626. stm32_enable_oscillator_lse(priv);
  1627. stm32_enable_oscillator_msi(priv);
  1628. _clk_stm32_enable(priv, _CK_LSI);
  1629. }
  1630. static int stm32_clk_configure_div(struct stm32_clk_priv *priv, uint32_t data)
  1631. {
  1632. int div_id = (data & DIV_ID_MASK) >> DIV_ID_SHIFT;
  1633. int div_n = (data & DIV_DIVN_MASK) >> DIV_DIVN_SHIFT;
  1634. return clk_stm32_set_div(priv, div_id, div_n);
  1635. }
  1636. static int stm32_clk_configure_mux(struct stm32_clk_priv *priv, uint32_t data)
  1637. {
  1638. int mux_id = (data & MUX_ID_MASK) >> MUX_ID_SHIFT;
  1639. int sel = (data & MUX_SEL_MASK) >> MUX_SEL_SHIFT;
  1640. return clk_mux_set_parent(priv, mux_id, sel);
  1641. }
  1642. static int stm32_clk_configure_clk_get_binding_id(struct stm32_clk_priv *priv, uint32_t data)
  1643. {
  1644. unsigned long binding_id = ((unsigned long)data & CLK_ID_MASK) >> CLK_ID_SHIFT;
  1645. return clk_get_index(priv, binding_id);
  1646. }
  1647. static int stm32_clk_configure_clk(struct stm32_clk_priv *priv, uint32_t data)
  1648. {
  1649. int sel = (data & CLK_SEL_MASK) >> CLK_SEL_SHIFT;
  1650. bool enable = ((data & CLK_ON_MASK) >> CLK_ON_SHIFT) != 0U;
  1651. int clk_id = 0;
  1652. int ret = 0;
  1653. clk_id = stm32_clk_configure_clk_get_binding_id(priv, data);
  1654. if (clk_id < 0) {
  1655. return clk_id;
  1656. }
  1657. if (sel != CLK_NOMUX) {
  1658. ret = _clk_stm32_set_parent_by_index(priv, clk_id, sel);
  1659. if (ret != 0) {
  1660. return ret;
  1661. }
  1662. }
  1663. if (enable) {
  1664. clk_stm32_enable_call_ops(priv, clk_id);
  1665. } else {
  1666. clk_stm32_disable_call_ops(priv, clk_id);
  1667. }
  1668. return 0;
  1669. }
  1670. static int stm32_clk_configure(struct stm32_clk_priv *priv, uint32_t val)
  1671. {
  1672. uint32_t cmd = (val & CMD_MASK) >> CMD_SHIFT;
  1673. uint32_t cmd_data = val & ~CMD_MASK;
  1674. int ret = -1;
  1675. switch (cmd) {
  1676. case CMD_DIV:
  1677. ret = stm32_clk_configure_div(priv, cmd_data);
  1678. break;
  1679. case CMD_MUX:
  1680. ret = stm32_clk_configure_mux(priv, cmd_data);
  1681. break;
  1682. case CMD_CLK:
  1683. ret = stm32_clk_configure_clk(priv, cmd_data);
  1684. break;
  1685. default:
  1686. EARLY_ERROR("%s: cmd unknown ! : 0x%x\n", __func__, val);
  1687. break;
  1688. }
  1689. return ret;
  1690. }
  1691. static int stm32_clk_bus_configure(struct stm32_clk_priv *priv)
  1692. {
  1693. struct stm32_clk_platdata *pdata = priv->pdata;
  1694. uint32_t i;
  1695. for (i = 0; i < pdata->nbusclk; i++) {
  1696. int ret;
  1697. ret = stm32_clk_configure(priv, pdata->busclk[i]);
  1698. if (ret != 0) {
  1699. return ret;
  1700. }
  1701. }
  1702. return 0;
  1703. }
  1704. static int stm32_clk_kernel_configure(struct stm32_clk_priv *priv)
  1705. {
  1706. struct stm32_clk_platdata *pdata = priv->pdata;
  1707. uint32_t i;
  1708. for (i = 0U; i < pdata->nkernelclk; i++) {
  1709. int ret;
  1710. ret = stm32_clk_configure(priv, pdata->kernelclk[i]);
  1711. if (ret != 0) {
  1712. return ret;
  1713. }
  1714. }
  1715. return 0;
  1716. }
  1717. static int stm32mp2_init_clock_tree(void)
  1718. {
  1719. struct stm32_clk_priv *priv = clk_stm32_get_priv();
  1720. int ret;
  1721. /* Set timer with STGEN without changing its clock source */
  1722. stm32mp_stgen_restore_rate();
  1723. generic_delay_timer_init();
  1724. stm32_clk_oscillators_enable(priv);
  1725. /* Come back to HSI */
  1726. ret = stm32mp2_clk_switch_to_hsi(priv);
  1727. if (ret != 0) {
  1728. panic();
  1729. }
  1730. ret = stm32mp2_clk_pll_configure(priv);
  1731. if (ret != 0) {
  1732. panic();
  1733. }
  1734. /* Wait LSE ready before to use it */
  1735. ret = stm32_clk_oscillators_wait_lse_ready(priv);
  1736. if (ret != 0) {
  1737. panic();
  1738. }
  1739. ret = stm32mp2_clk_flexgen_configure(priv);
  1740. if (ret != 0) {
  1741. panic();
  1742. }
  1743. ret = stm32_clk_bus_configure(priv);
  1744. if (ret != 0) {
  1745. panic();
  1746. }
  1747. ret = stm32_clk_kernel_configure(priv);
  1748. if (ret != 0) {
  1749. panic();
  1750. }
  1751. return 0;
  1752. }
  1753. static int clk_stm32_parse_oscillator_fdt(void *fdt, int node, const char *name,
  1754. struct stm32_osci_dt_cfg *osci)
  1755. {
  1756. int subnode = 0;
  1757. /* Default value oscillator not found, freq=0 */
  1758. osci->freq = 0;
  1759. fdt_for_each_subnode(subnode, fdt, node) {
  1760. const char *cchar = NULL;
  1761. const fdt32_t *cuint = NULL;
  1762. int ret = 0;
  1763. cchar = fdt_get_name(fdt, subnode, &ret);
  1764. if (cchar == NULL) {
  1765. return ret;
  1766. }
  1767. if (strncmp(cchar, name, (size_t)ret) ||
  1768. fdt_get_status(subnode) == DT_DISABLED) {
  1769. continue;
  1770. }
  1771. cuint = fdt_getprop(fdt, subnode, "clock-frequency", &ret);
  1772. if (cuint == NULL) {
  1773. return ret;
  1774. }
  1775. osci->freq = fdt32_to_cpu(*cuint);
  1776. if (fdt_getprop(fdt, subnode, "st,bypass", NULL) != NULL) {
  1777. osci->bypass = true;
  1778. }
  1779. if (fdt_getprop(fdt, subnode, "st,digbypass", NULL) != NULL) {
  1780. osci->digbyp = true;
  1781. }
  1782. if (fdt_getprop(fdt, subnode, "st,css", NULL) != NULL) {
  1783. osci->css = true;
  1784. }
  1785. osci->drive = fdt_read_uint32_default(fdt, subnode, "st,drive", LSEDRV_MEDIUM_HIGH);
  1786. return 0;
  1787. }
  1788. return 0;
  1789. }
  1790. static int stm32_clk_parse_fdt_all_oscillator(void *fdt, struct stm32_clk_platdata *pdata)
  1791. {
  1792. int fdt_err = 0;
  1793. uint32_t i = 0;
  1794. int node = 0;
  1795. node = fdt_path_offset(fdt, "/clocks");
  1796. if (node < 0) {
  1797. return -FDT_ERR_NOTFOUND;
  1798. }
  1799. for (i = 0; i < pdata->nosci; i++) {
  1800. const char *name = NULL;
  1801. name = clk_stm32_get_oscillator_name((enum stm32_osc)i);
  1802. if (name == NULL) {
  1803. continue;
  1804. }
  1805. fdt_err = clk_stm32_parse_oscillator_fdt(fdt, node, name, &pdata->osci[i]);
  1806. if (fdt_err < 0) {
  1807. panic();
  1808. }
  1809. }
  1810. return 0;
  1811. }
  1812. static int clk_stm32_parse_pll_fdt(void *fdt, int subnode, struct stm32_pll_dt_cfg *pll)
  1813. {
  1814. const fdt32_t *cuint = NULL;
  1815. int subnode_pll = 0;
  1816. uint32_t val = 0;
  1817. int err = 0;
  1818. cuint = fdt_getprop(fdt, subnode, "st,pll", NULL);
  1819. if (!cuint) {
  1820. return -FDT_ERR_NOTFOUND;
  1821. }
  1822. subnode_pll = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*cuint));
  1823. if (subnode_pll < 0) {
  1824. return -FDT_ERR_NOTFOUND;
  1825. }
  1826. err = fdt_read_uint32_array(fdt, subnode_pll, "cfg", (int)PLLCFG_NB, pll->cfg);
  1827. if (err != 0) {
  1828. return err;
  1829. }
  1830. err = fdt_read_uint32_array(fdt, subnode_pll, "csg", (int)PLLCSG_NB, pll->csg);
  1831. pll->csg_enabled = (err == 0);
  1832. if (err == -FDT_ERR_NOTFOUND) {
  1833. err = 0;
  1834. }
  1835. if (err != 0) {
  1836. return err;
  1837. }
  1838. pll->enabled = true;
  1839. pll->frac = fdt_read_uint32_default(fdt, subnode_pll, "frac", 0);
  1840. pll->src = UINT32_MAX;
  1841. err = fdt_read_uint32(fdt, subnode_pll, "src", &val);
  1842. if (err == 0) {
  1843. pll->src = val;
  1844. }
  1845. return 0;
  1846. }
  1847. #define RCC_PLL_NAME_SIZE 12
  1848. static int stm32_clk_parse_fdt_all_pll(void *fdt, int node, struct stm32_clk_platdata *pdata)
  1849. {
  1850. unsigned int i = 0;
  1851. for (i = _PLL1; i < pdata->npll; i++) {
  1852. struct stm32_pll_dt_cfg *pll = pdata->pll + i;
  1853. char name[RCC_PLL_NAME_SIZE];
  1854. int subnode = 0;
  1855. int err = 0;
  1856. snprintf(name, sizeof(name), "st,pll-%u", i + 1);
  1857. subnode = fdt_subnode_offset(fdt, node, name);
  1858. if (!fdt_check_node(subnode)) {
  1859. continue;
  1860. }
  1861. err = clk_stm32_parse_pll_fdt(fdt, subnode, pll);
  1862. if (err != 0) {
  1863. panic();
  1864. }
  1865. }
  1866. return 0;
  1867. }
  1868. static int stm32_clk_parse_fdt(struct stm32_clk_platdata *pdata)
  1869. {
  1870. void *fdt = NULL;
  1871. int node;
  1872. int err;
  1873. if (fdt_get_address(&fdt) == 0) {
  1874. return -ENOENT;
  1875. }
  1876. node = fdt_node_offset_by_compatible(fdt, -1, DT_RCC_CLK_COMPAT);
  1877. if (node < 0) {
  1878. panic();
  1879. }
  1880. err = stm32_clk_parse_fdt_all_oscillator(fdt, pdata);
  1881. if (err != 0) {
  1882. return err;
  1883. }
  1884. err = stm32_clk_parse_fdt_all_pll(fdt, node, pdata);
  1885. if (err != 0) {
  1886. return err;
  1887. }
  1888. err = stm32_clk_parse_fdt_by_name(fdt, node, "st,busclk", pdata->busclk, &pdata->nbusclk);
  1889. if (err != 0) {
  1890. return err;
  1891. }
  1892. err = stm32_clk_parse_fdt_by_name(fdt, node, "st,flexgen", pdata->flexgen,
  1893. &pdata->nflexgen);
  1894. if (err != 0) {
  1895. return err;
  1896. }
  1897. err = stm32_clk_parse_fdt_by_name(fdt, node, "st,kerclk", pdata->kernelclk,
  1898. &pdata->nkernelclk);
  1899. if (err != 0) {
  1900. return err;
  1901. }
  1902. return 0;
  1903. }
  1904. #endif /* IMAGE_BL2 */
  1905. static struct stm32_osci_dt_cfg mp25_osci[NB_OSCILLATOR];
  1906. static struct stm32_pll_dt_cfg mp25_pll[_PLL_NB];
  1907. #define DT_FLEXGEN_CLK_MAX 64
  1908. static uint32_t mp25_flexgen[DT_FLEXGEN_CLK_MAX];
  1909. #define DT_BUS_CLK_MAX 6
  1910. static uint32_t mp25_busclk[DT_BUS_CLK_MAX];
  1911. #define DT_KERNEL_CLK_MAX 20
  1912. static uint32_t mp25_kernelclk[DT_KERNEL_CLK_MAX];
  1913. static struct stm32_clk_platdata stm32mp25_pdata = {
  1914. .osci = mp25_osci,
  1915. .nosci = NB_OSCILLATOR,
  1916. .pll = mp25_pll,
  1917. .npll = _PLL_NB,
  1918. .flexgen = mp25_flexgen,
  1919. .nflexgen = DT_FLEXGEN_CLK_MAX,
  1920. .busclk = mp25_busclk,
  1921. .nbusclk = DT_BUS_CLK_MAX,
  1922. .kernelclk = mp25_kernelclk,
  1923. .nkernelclk = DT_KERNEL_CLK_MAX,
  1924. };
  1925. static uint8_t refcounts_mp25[CK_LAST];
  1926. static struct stm32_clk_priv stm32mp25_clock_data = {
  1927. .base = RCC_BASE,
  1928. .num = ARRAY_SIZE(stm32mp25_clk),
  1929. .clks = stm32mp25_clk,
  1930. .parents = parent_mp25,
  1931. .nb_parents = ARRAY_SIZE(parent_mp25),
  1932. .gates = gates_mp25,
  1933. .nb_gates = ARRAY_SIZE(gates_mp25),
  1934. .div = dividers_mp25,
  1935. .nb_div = ARRAY_SIZE(dividers_mp25),
  1936. .osci_data = stm32mp25_osc_data,
  1937. .nb_osci_data = ARRAY_SIZE(stm32mp25_osc_data),
  1938. .gate_refcounts = refcounts_mp25,
  1939. .pdata = &stm32mp25_pdata,
  1940. .ops_array = ops_array_mp25,
  1941. };
  1942. int stm32mp2_clk_init(void)
  1943. {
  1944. uintptr_t base = RCC_BASE;
  1945. int ret;
  1946. #ifdef IMAGE_BL2
  1947. ret = stm32_clk_parse_fdt(&stm32mp25_pdata);
  1948. if (ret != 0) {
  1949. return ret;
  1950. }
  1951. #endif
  1952. ret = clk_stm32_init(&stm32mp25_clock_data, base);
  1953. if (ret != 0) {
  1954. return ret;
  1955. }
  1956. #ifdef IMAGE_BL2
  1957. ret = stm32mp2_init_clock_tree();
  1958. if (ret != 0) {
  1959. return ret;
  1960. }
  1961. clk_stm32_enable_critical_clocks();
  1962. #endif
  1963. return 0;
  1964. }
  1965. int stm32mp2_pll1_disable(void)
  1966. {
  1967. #ifdef IMAGE_BL2
  1968. return -EPERM;
  1969. #else
  1970. uintptr_t a35_ss_address = A35SSC_BASE;
  1971. uintptr_t pll_enable_reg = a35_ss_address + A35_SS_PLL_ENABLE;
  1972. stm32mp2_a35_ss_on_hsi();
  1973. mmio_clrbits_32(pll_enable_reg, A35_SS_PLL_ENABLE_PD);
  1974. return 0;
  1975. #endif
  1976. }