clk-mt8192.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. //
  3. // Copyright (c) 2021 MediaTek Inc.
  4. // Author: Chun-Jie Chen <[email protected]>
  5. #include <linux/clk.h>
  6. #include <linux/delay.h>
  7. #include <linux/mfd/syscon.h>
  8. #include <linux/of.h>
  9. #include <linux/of_address.h>
  10. #include <linux/of_device.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/slab.h>
  13. #include "clk-gate.h"
  14. #include "clk-mtk.h"
  15. #include "clk-mux.h"
  16. #include "clk-pll.h"
  17. #include <dt-bindings/clock/mt8192-clk.h>
  18. #include <dt-bindings/reset/mt8192-resets.h>
  19. static DEFINE_SPINLOCK(mt8192_clk_lock);
  20. static const struct mtk_fixed_clk top_fixed_clks[] = {
  21. FIXED_CLK(CLK_TOP_ULPOSC, "ulposc", NULL, 260000000),
  22. };
  23. static const struct mtk_fixed_factor top_early_divs[] = {
  24. FACTOR(CLK_TOP_CSW_F26M_D2, "csw_f26m_d2", "clk26m", 1, 2),
  25. };
  26. static const struct mtk_fixed_factor top_divs[] = {
  27. FACTOR(CLK_TOP_MAINPLL_D3, "mainpll_d3", "mainpll", 1, 3),
  28. FACTOR(CLK_TOP_MAINPLL_D4, "mainpll_d4", "mainpll", 1, 4),
  29. FACTOR(CLK_TOP_MAINPLL_D4_D2, "mainpll_d4_d2", "mainpll_d4", 1, 2),
  30. FACTOR(CLK_TOP_MAINPLL_D4_D4, "mainpll_d4_d4", "mainpll_d4", 1, 4),
  31. FACTOR(CLK_TOP_MAINPLL_D4_D8, "mainpll_d4_d8", "mainpll_d4", 1, 8),
  32. FACTOR(CLK_TOP_MAINPLL_D4_D16, "mainpll_d4_d16", "mainpll_d4", 1, 16),
  33. FACTOR(CLK_TOP_MAINPLL_D5, "mainpll_d5", "mainpll", 1, 5),
  34. FACTOR(CLK_TOP_MAINPLL_D5_D2, "mainpll_d5_d2", "mainpll_d5", 1, 2),
  35. FACTOR(CLK_TOP_MAINPLL_D5_D4, "mainpll_d5_d4", "mainpll_d5", 1, 4),
  36. FACTOR(CLK_TOP_MAINPLL_D5_D8, "mainpll_d5_d8", "mainpll_d5", 1, 8),
  37. FACTOR(CLK_TOP_MAINPLL_D6, "mainpll_d6", "mainpll", 1, 6),
  38. FACTOR(CLK_TOP_MAINPLL_D6_D2, "mainpll_d6_d2", "mainpll_d6", 1, 2),
  39. FACTOR(CLK_TOP_MAINPLL_D6_D4, "mainpll_d6_d4", "mainpll_d6", 1, 4),
  40. FACTOR(CLK_TOP_MAINPLL_D7, "mainpll_d7", "mainpll", 1, 7),
  41. FACTOR(CLK_TOP_MAINPLL_D7_D2, "mainpll_d7_d2", "mainpll_d7", 1, 2),
  42. FACTOR(CLK_TOP_MAINPLL_D7_D4, "mainpll_d7_d4", "mainpll_d7", 1, 4),
  43. FACTOR(CLK_TOP_MAINPLL_D7_D8, "mainpll_d7_d8", "mainpll_d7", 1, 8),
  44. FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3),
  45. FACTOR(CLK_TOP_UNIVPLL_D4, "univpll_d4", "univpll", 1, 4),
  46. FACTOR(CLK_TOP_UNIVPLL_D4_D2, "univpll_d4_d2", "univpll_d4", 1, 2),
  47. FACTOR(CLK_TOP_UNIVPLL_D4_D4, "univpll_d4_d4", "univpll_d4", 1, 4),
  48. FACTOR(CLK_TOP_UNIVPLL_D4_D8, "univpll_d4_d8", "univpll_d4", 1, 8),
  49. FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
  50. FACTOR(CLK_TOP_UNIVPLL_D5_D2, "univpll_d5_d2", "univpll_d5", 1, 2),
  51. FACTOR(CLK_TOP_UNIVPLL_D5_D4, "univpll_d5_d4", "univpll_d5", 1, 4),
  52. FACTOR(CLK_TOP_UNIVPLL_D5_D8, "univpll_d5_d8", "univpll_d5", 1, 8),
  53. FACTOR(CLK_TOP_UNIVPLL_D6, "univpll_d6", "univpll", 1, 6),
  54. FACTOR(CLK_TOP_UNIVPLL_D6_D2, "univpll_d6_d2", "univpll_d6", 1, 2),
  55. FACTOR(CLK_TOP_UNIVPLL_D6_D4, "univpll_d6_d4", "univpll_d6", 1, 4),
  56. FACTOR(CLK_TOP_UNIVPLL_D6_D8, "univpll_d6_d8", "univpll_d6", 1, 8),
  57. FACTOR(CLK_TOP_UNIVPLL_D6_D16, "univpll_d6_d16", "univpll_d6", 1, 16),
  58. FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1, 7),
  59. FACTOR(CLK_TOP_APLL1, "apll1_ck", "apll1", 1, 1),
  60. FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1", 1, 2),
  61. FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "apll1", 1, 4),
  62. FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "apll1", 1, 8),
  63. FACTOR(CLK_TOP_APLL2, "apll2_ck", "apll2", 1, 1),
  64. FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2", 1, 2),
  65. FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "apll2", 1, 4),
  66. FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "apll2", 1, 8),
  67. FACTOR(CLK_TOP_MMPLL_D4, "mmpll_d4", "mmpll", 1, 4),
  68. FACTOR(CLK_TOP_MMPLL_D4_D2, "mmpll_d4_d2", "mmpll_d4", 1, 2),
  69. FACTOR(CLK_TOP_MMPLL_D5, "mmpll_d5", "mmpll", 1, 5),
  70. FACTOR(CLK_TOP_MMPLL_D5_D2, "mmpll_d5_d2", "mmpll_d5", 1, 2),
  71. FACTOR(CLK_TOP_MMPLL_D6, "mmpll_d6", "mmpll", 1, 6),
  72. FACTOR(CLK_TOP_MMPLL_D6_D2, "mmpll_d6_d2", "mmpll_d6", 1, 2),
  73. FACTOR(CLK_TOP_MMPLL_D7, "mmpll_d7", "mmpll", 1, 7),
  74. FACTOR(CLK_TOP_MMPLL_D9, "mmpll_d9", "mmpll", 1, 9),
  75. FACTOR(CLK_TOP_APUPLL, "apupll_ck", "apupll", 1, 2),
  76. FACTOR(CLK_TOP_NPUPLL, "npupll_ck", "npupll", 1, 1),
  77. FACTOR(CLK_TOP_TVDPLL, "tvdpll_ck", "tvdpll", 1, 1),
  78. FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll", 1, 2),
  79. FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll", 1, 4),
  80. FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll", 1, 8),
  81. FACTOR(CLK_TOP_TVDPLL_D16, "tvdpll_d16", "tvdpll", 1, 16),
  82. FACTOR(CLK_TOP_MSDCPLL, "msdcpll_ck", "msdcpll", 1, 1),
  83. FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll", 1, 2),
  84. FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll", 1, 4),
  85. FACTOR(CLK_TOP_OSC_D2, "osc_d2", "ulposc", 1, 2),
  86. FACTOR(CLK_TOP_OSC_D4, "osc_d4", "ulposc", 1, 4),
  87. FACTOR(CLK_TOP_OSC_D8, "osc_d8", "ulposc", 1, 8),
  88. FACTOR(CLK_TOP_OSC_D10, "osc_d10", "ulposc", 1, 10),
  89. FACTOR(CLK_TOP_OSC_D16, "osc_d16", "ulposc", 1, 16),
  90. FACTOR(CLK_TOP_OSC_D20, "osc_d20", "ulposc", 1, 20),
  91. FACTOR(CLK_TOP_ADSPPLL, "adsppll_ck", "adsppll", 1, 1),
  92. FACTOR(CLK_TOP_UNIVPLL_192M, "univpll_192m", "univpll", 1, 13),
  93. FACTOR(CLK_TOP_UNIVPLL_192M_D2, "univpll_192m_d2", "univpll_192m", 1, 2),
  94. FACTOR(CLK_TOP_UNIVPLL_192M_D4, "univpll_192m_d4", "univpll_192m", 1, 4),
  95. FACTOR(CLK_TOP_UNIVPLL_192M_D8, "univpll_192m_d8", "univpll_192m", 1, 8),
  96. FACTOR(CLK_TOP_UNIVPLL_192M_D16, "univpll_192m_d16", "univpll_192m", 1, 16),
  97. FACTOR(CLK_TOP_UNIVPLL_192M_D32, "univpll_192m_d32", "univpll_192m", 1, 32),
  98. };
  99. static const char * const axi_parents[] = {
  100. "clk26m",
  101. "mainpll_d4_d4",
  102. "mainpll_d7_d2",
  103. "mainpll_d4_d2",
  104. "mainpll_d5_d2",
  105. "mainpll_d6_d2",
  106. "osc_d4"
  107. };
  108. static const char * const spm_parents[] = {
  109. "clk26m",
  110. "osc_d10",
  111. "mainpll_d7_d4",
  112. "clk32k"
  113. };
  114. static const char * const scp_parents[] = {
  115. "clk26m",
  116. "univpll_d5",
  117. "mainpll_d6_d2",
  118. "mainpll_d6",
  119. "univpll_d6",
  120. "mainpll_d4_d2",
  121. "mainpll_d5_d2",
  122. "univpll_d4_d2"
  123. };
  124. static const char * const bus_aximem_parents[] = {
  125. "clk26m",
  126. "mainpll_d7_d2",
  127. "mainpll_d4_d2",
  128. "mainpll_d5_d2",
  129. "mainpll_d6"
  130. };
  131. static const char * const disp_parents[] = {
  132. "clk26m",
  133. "univpll_d6_d2",
  134. "mainpll_d5_d2",
  135. "mmpll_d6_d2",
  136. "univpll_d5_d2",
  137. "univpll_d4_d2",
  138. "mmpll_d7",
  139. "univpll_d6",
  140. "mainpll_d4",
  141. "mmpll_d5_d2"
  142. };
  143. static const char * const mdp_parents[] = {
  144. "clk26m",
  145. "mainpll_d5_d2",
  146. "mmpll_d6_d2",
  147. "mainpll_d4_d2",
  148. "mmpll_d4_d2",
  149. "mainpll_d6",
  150. "univpll_d6",
  151. "mainpll_d4",
  152. "tvdpll_ck",
  153. "univpll_d4",
  154. "mmpll_d5_d2"
  155. };
  156. static const char * const img_parents[] = {
  157. "clk26m",
  158. "univpll_d4",
  159. "tvdpll_ck",
  160. "mainpll_d4",
  161. "univpll_d5",
  162. "mmpll_d6",
  163. "univpll_d6",
  164. "mainpll_d6",
  165. "mmpll_d4_d2",
  166. "mainpll_d4_d2",
  167. "mmpll_d6_d2",
  168. "mmpll_d5_d2"
  169. };
  170. static const char * const ipe_parents[] = {
  171. "clk26m",
  172. "mainpll_d4",
  173. "mmpll_d6",
  174. "univpll_d6",
  175. "mainpll_d6",
  176. "univpll_d4_d2",
  177. "mainpll_d4_d2",
  178. "mmpll_d6_d2",
  179. "mmpll_d5_d2"
  180. };
  181. static const char * const dpe_parents[] = {
  182. "clk26m",
  183. "mainpll_d4",
  184. "mmpll_d6",
  185. "univpll_d6",
  186. "mainpll_d6",
  187. "univpll_d4_d2",
  188. "univpll_d5_d2",
  189. "mmpll_d6_d2"
  190. };
  191. static const char * const cam_parents[] = {
  192. "clk26m",
  193. "mainpll_d4",
  194. "mmpll_d6",
  195. "univpll_d4",
  196. "univpll_d5",
  197. "univpll_d6",
  198. "mmpll_d7",
  199. "univpll_d4_d2",
  200. "mainpll_d4_d2",
  201. "univpll_d6_d2"
  202. };
  203. static const char * const ccu_parents[] = {
  204. "clk26m",
  205. "mainpll_d4",
  206. "mmpll_d6",
  207. "mainpll_d6",
  208. "mmpll_d7",
  209. "univpll_d4_d2",
  210. "mmpll_d6_d2",
  211. "mmpll_d5_d2",
  212. "univpll_d5",
  213. "univpll_d6_d2"
  214. };
  215. static const char * const dsp7_parents[] = {
  216. "clk26m",
  217. "mainpll_d4_d2",
  218. "mainpll_d6",
  219. "mmpll_d6",
  220. "univpll_d5",
  221. "mmpll_d5",
  222. "univpll_d4",
  223. "mmpll_d4"
  224. };
  225. static const char * const mfg_ref_parents[] = {
  226. "clk26m",
  227. "clk26m",
  228. "univpll_d6",
  229. "mainpll_d5_d2"
  230. };
  231. static const char * const mfg_pll_parents[] = {
  232. "mfg_ref_sel",
  233. "mfgpll"
  234. };
  235. static const char * const camtg_parents[] = {
  236. "clk26m",
  237. "univpll_192m_d8",
  238. "univpll_d6_d8",
  239. "univpll_192m_d4",
  240. "univpll_d6_d16",
  241. "csw_f26m_d2",
  242. "univpll_192m_d16",
  243. "univpll_192m_d32"
  244. };
  245. static const char * const uart_parents[] = {
  246. "clk26m",
  247. "univpll_d6_d8"
  248. };
  249. static const char * const spi_parents[] = {
  250. "clk26m",
  251. "mainpll_d5_d4",
  252. "mainpll_d6_d4",
  253. "msdcpll_d4"
  254. };
  255. static const char * const msdc50_0_h_parents[] = {
  256. "clk26m",
  257. "mainpll_d4_d2",
  258. "mainpll_d6_d2"
  259. };
  260. static const char * const msdc50_0_parents[] = {
  261. "clk26m",
  262. "msdcpll_ck",
  263. "msdcpll_d2",
  264. "univpll_d4_d4",
  265. "mainpll_d6_d2",
  266. "univpll_d4_d2"
  267. };
  268. static const char * const msdc30_parents[] = {
  269. "clk26m",
  270. "univpll_d6_d2",
  271. "mainpll_d6_d2",
  272. "mainpll_d7_d2",
  273. "msdcpll_d2"
  274. };
  275. static const char * const audio_parents[] = {
  276. "clk26m",
  277. "mainpll_d5_d8",
  278. "mainpll_d7_d8",
  279. "mainpll_d4_d16"
  280. };
  281. static const char * const aud_intbus_parents[] = {
  282. "clk26m",
  283. "mainpll_d4_d4",
  284. "mainpll_d7_d4"
  285. };
  286. static const char * const pwrap_ulposc_parents[] = {
  287. "osc_d10",
  288. "clk26m",
  289. "osc_d4",
  290. "osc_d8",
  291. "osc_d16"
  292. };
  293. static const char * const atb_parents[] = {
  294. "clk26m",
  295. "mainpll_d4_d2",
  296. "mainpll_d5_d2"
  297. };
  298. static const char * const dpi_parents[] = {
  299. "clk26m",
  300. "tvdpll_d2",
  301. "tvdpll_d4",
  302. "tvdpll_d8",
  303. "tvdpll_d16"
  304. };
  305. static const char * const scam_parents[] = {
  306. "clk26m",
  307. "mainpll_d5_d4"
  308. };
  309. static const char * const disp_pwm_parents[] = {
  310. "clk26m",
  311. "univpll_d6_d4",
  312. "osc_d2",
  313. "osc_d4",
  314. "osc_d16"
  315. };
  316. static const char * const usb_top_parents[] = {
  317. "clk26m",
  318. "univpll_d5_d4",
  319. "univpll_d6_d4",
  320. "univpll_d5_d2"
  321. };
  322. static const char * const ssusb_xhci_parents[] = {
  323. "clk26m",
  324. "univpll_d5_d4",
  325. "univpll_d6_d4",
  326. "univpll_d5_d2"
  327. };
  328. static const char * const i2c_parents[] = {
  329. "clk26m",
  330. "mainpll_d4_d8",
  331. "univpll_d5_d4"
  332. };
  333. static const char * const seninf_parents[] = {
  334. "clk26m",
  335. "univpll_d4_d4",
  336. "univpll_d6_d2",
  337. "univpll_d4_d2",
  338. "univpll_d7",
  339. "univpll_d6",
  340. "mmpll_d6",
  341. "univpll_d5"
  342. };
  343. static const char * const tl_parents[] = {
  344. "clk26m",
  345. "univpll_192m_d2",
  346. "mainpll_d6_d4"
  347. };
  348. static const char * const dxcc_parents[] = {
  349. "clk26m",
  350. "mainpll_d4_d2",
  351. "mainpll_d4_d4",
  352. "mainpll_d4_d8"
  353. };
  354. static const char * const aud_engen1_parents[] = {
  355. "clk26m",
  356. "apll1_d2",
  357. "apll1_d4",
  358. "apll1_d8"
  359. };
  360. static const char * const aud_engen2_parents[] = {
  361. "clk26m",
  362. "apll2_d2",
  363. "apll2_d4",
  364. "apll2_d8"
  365. };
  366. static const char * const aes_ufsfde_parents[] = {
  367. "clk26m",
  368. "mainpll_d4",
  369. "mainpll_d4_d2",
  370. "mainpll_d6",
  371. "mainpll_d4_d4",
  372. "univpll_d4_d2",
  373. "univpll_d6"
  374. };
  375. static const char * const ufs_parents[] = {
  376. "clk26m",
  377. "mainpll_d4_d4",
  378. "mainpll_d4_d8",
  379. "univpll_d4_d4",
  380. "mainpll_d6_d2",
  381. "mainpll_d5_d2",
  382. "msdcpll_d2"
  383. };
  384. static const char * const aud_1_parents[] = {
  385. "clk26m",
  386. "apll1_ck"
  387. };
  388. static const char * const aud_2_parents[] = {
  389. "clk26m",
  390. "apll2_ck"
  391. };
  392. static const char * const adsp_parents[] = {
  393. "clk26m",
  394. "mainpll_d6",
  395. "mainpll_d5_d2",
  396. "univpll_d4_d4",
  397. "univpll_d4",
  398. "univpll_d6",
  399. "ulposc",
  400. "adsppll_ck"
  401. };
  402. static const char * const dpmaif_main_parents[] = {
  403. "clk26m",
  404. "univpll_d4_d4",
  405. "mainpll_d6",
  406. "mainpll_d4_d2",
  407. "univpll_d4_d2"
  408. };
  409. static const char * const venc_parents[] = {
  410. "clk26m",
  411. "mmpll_d7",
  412. "mainpll_d6",
  413. "univpll_d4_d2",
  414. "mainpll_d4_d2",
  415. "univpll_d6",
  416. "mmpll_d6",
  417. "mainpll_d5_d2",
  418. "mainpll_d6_d2",
  419. "mmpll_d9",
  420. "univpll_d4_d4",
  421. "mainpll_d4",
  422. "univpll_d4",
  423. "univpll_d5",
  424. "univpll_d5_d2",
  425. "mainpll_d5"
  426. };
  427. static const char * const vdec_parents[] = {
  428. "clk26m",
  429. "univpll_192m_d2",
  430. "univpll_d5_d4",
  431. "mainpll_d5",
  432. "mainpll_d5_d2",
  433. "mmpll_d6_d2",
  434. "univpll_d5_d2",
  435. "mainpll_d4_d2",
  436. "univpll_d4_d2",
  437. "univpll_d7",
  438. "mmpll_d7",
  439. "mmpll_d6",
  440. "univpll_d5",
  441. "mainpll_d4",
  442. "univpll_d4",
  443. "univpll_d6"
  444. };
  445. static const char * const camtm_parents[] = {
  446. "clk26m",
  447. "univpll_d7",
  448. "univpll_d6_d2",
  449. "univpll_d4_d2"
  450. };
  451. static const char * const pwm_parents[] = {
  452. "clk26m",
  453. "univpll_d4_d8"
  454. };
  455. static const char * const audio_h_parents[] = {
  456. "clk26m",
  457. "univpll_d7",
  458. "apll1_ck",
  459. "apll2_ck"
  460. };
  461. static const char * const spmi_mst_parents[] = {
  462. "clk26m",
  463. "csw_f26m_d2",
  464. "osc_d8",
  465. "osc_d10",
  466. "osc_d16",
  467. "osc_d20",
  468. "clk32k"
  469. };
  470. static const char * const aes_msdcfde_parents[] = {
  471. "clk26m",
  472. "mainpll_d4_d2",
  473. "mainpll_d6",
  474. "mainpll_d4_d4",
  475. "univpll_d4_d2",
  476. "univpll_d6"
  477. };
  478. static const char * const sflash_parents[] = {
  479. "clk26m",
  480. "mainpll_d7_d8",
  481. "univpll_d6_d8",
  482. "univpll_d5_d8"
  483. };
  484. static const char * const apll_i2s_m_parents[] = {
  485. "aud_1_sel",
  486. "aud_2_sel"
  487. };
  488. /*
  489. * CRITICAL CLOCK:
  490. * axi_sel is the main bus clock of whole SOC.
  491. * spm_sel is the clock of the always-on co-processor.
  492. * bus_aximem_sel is clock of the bus that access emi.
  493. */
  494. static const struct mtk_mux top_mtk_muxes[] = {
  495. /* CLK_CFG_0 */
  496. MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_AXI_SEL, "axi_sel",
  497. axi_parents, 0x010, 0x014, 0x018, 0, 3, 7, 0x004, 0,
  498. CLK_IS_CRITICAL),
  499. MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_SPM_SEL, "spm_sel",
  500. spm_parents, 0x010, 0x014, 0x018, 8, 2, 15, 0x004, 1,
  501. CLK_IS_CRITICAL),
  502. MUX_GATE_CLR_SET_UPD(CLK_TOP_SCP_SEL, "scp_sel",
  503. scp_parents, 0x010, 0x014, 0x018, 16, 3, 23, 0x004, 2),
  504. MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_BUS_AXIMEM_SEL, "bus_aximem_sel",
  505. bus_aximem_parents, 0x010, 0x014, 0x018, 24, 3, 31, 0x004, 3,
  506. CLK_IS_CRITICAL),
  507. /* CLK_CFG_1 */
  508. MUX_GATE_CLR_SET_UPD(CLK_TOP_DISP_SEL, "disp_sel",
  509. disp_parents, 0x020, 0x024, 0x028, 0, 4, 7, 0x004, 4),
  510. MUX_GATE_CLR_SET_UPD(CLK_TOP_MDP_SEL, "mdp_sel",
  511. mdp_parents, 0x020, 0x024, 0x028, 8, 4, 15, 0x004, 5),
  512. MUX_GATE_CLR_SET_UPD(CLK_TOP_IMG1_SEL, "img1_sel",
  513. img_parents, 0x020, 0x024, 0x028, 16, 4, 23, 0x004, 6),
  514. MUX_GATE_CLR_SET_UPD(CLK_TOP_IMG2_SEL, "img2_sel",
  515. img_parents, 0x020, 0x024, 0x028, 24, 4, 31, 0x004, 7),
  516. /* CLK_CFG_2 */
  517. MUX_GATE_CLR_SET_UPD(CLK_TOP_IPE_SEL, "ipe_sel",
  518. ipe_parents, 0x030, 0x034, 0x038, 0, 4, 7, 0x004, 8),
  519. MUX_GATE_CLR_SET_UPD(CLK_TOP_DPE_SEL, "dpe_sel",
  520. dpe_parents, 0x030, 0x034, 0x038, 8, 3, 15, 0x004, 9),
  521. MUX_GATE_CLR_SET_UPD(CLK_TOP_CAM_SEL, "cam_sel",
  522. cam_parents, 0x030, 0x034, 0x038, 16, 4, 23, 0x004, 10),
  523. MUX_GATE_CLR_SET_UPD(CLK_TOP_CCU_SEL, "ccu_sel",
  524. ccu_parents, 0x030, 0x034, 0x038, 24, 4, 31, 0x004, 11),
  525. /* CLK_CFG_4 */
  526. MUX_GATE_CLR_SET_UPD(CLK_TOP_DSP7_SEL, "dsp7_sel",
  527. dsp7_parents, 0x050, 0x054, 0x058, 0, 3, 7, 0x004, 16),
  528. MUX_GATE_CLR_SET_UPD(CLK_TOP_MFG_REF_SEL, "mfg_ref_sel",
  529. mfg_ref_parents, 0x050, 0x054, 0x058, 16, 2, 23, 0x004, 18),
  530. MUX_CLR_SET_UPD(CLK_TOP_MFG_PLL_SEL, "mfg_pll_sel",
  531. mfg_pll_parents, 0x050, 0x054, 0x058, 18, 1, -1, -1),
  532. MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG_SEL, "camtg_sel",
  533. camtg_parents, 0x050, 0x054, 0x058, 24, 3, 31, 0x004, 19),
  534. /* CLK_CFG_5 */
  535. MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG2_SEL, "camtg2_sel",
  536. camtg_parents, 0x060, 0x064, 0x068, 0, 3, 7, 0x004, 20),
  537. MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG3_SEL, "camtg3_sel",
  538. camtg_parents, 0x060, 0x064, 0x068, 8, 3, 15, 0x004, 21),
  539. MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG4_SEL, "camtg4_sel",
  540. camtg_parents, 0x060, 0x064, 0x068, 16, 3, 23, 0x004, 22),
  541. MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG5_SEL, "camtg5_sel",
  542. camtg_parents, 0x060, 0x064, 0x068, 24, 3, 31, 0x004, 23),
  543. /* CLK_CFG_6 */
  544. MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG6_SEL, "camtg6_sel",
  545. camtg_parents, 0x070, 0x074, 0x078, 0, 3, 7, 0x004, 24),
  546. MUX_GATE_CLR_SET_UPD(CLK_TOP_UART_SEL, "uart_sel",
  547. uart_parents, 0x070, 0x074, 0x078, 8, 1, 15, 0x004, 25),
  548. MUX_GATE_CLR_SET_UPD(CLK_TOP_SPI_SEL, "spi_sel",
  549. spi_parents, 0x070, 0x074, 0x078, 16, 2, 23, 0x004, 26),
  550. MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC50_0_H_SEL, "msdc50_0_h_sel",
  551. msdc50_0_h_parents, 0x070, 0x074, 0x078, 24, 2, 31, 0x004, 27),
  552. /* CLK_CFG_7 */
  553. MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC50_0_SEL, "msdc50_0_sel",
  554. msdc50_0_parents, 0x080, 0x084, 0x088, 0, 3, 7, 0x004, 28),
  555. MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel",
  556. msdc30_parents, 0x080, 0x084, 0x088, 8, 3, 15, 0x004, 29),
  557. MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC30_2_SEL, "msdc30_2_sel",
  558. msdc30_parents, 0x080, 0x084, 0x088, 16, 3, 23, 0x004, 30),
  559. MUX_GATE_CLR_SET_UPD(CLK_TOP_AUDIO_SEL, "audio_sel",
  560. audio_parents, 0x080, 0x084, 0x088, 24, 2, 31, 0x008, 0),
  561. /* CLK_CFG_8 */
  562. MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel",
  563. aud_intbus_parents, 0x090, 0x094, 0x098, 0, 2, 7, 0x008, 1),
  564. MUX_GATE_CLR_SET_UPD(CLK_TOP_PWRAP_ULPOSC_SEL, "pwrap_ulposc_sel",
  565. pwrap_ulposc_parents, 0x090, 0x094, 0x098, 8, 3, 15, 0x008, 2),
  566. MUX_GATE_CLR_SET_UPD(CLK_TOP_ATB_SEL, "atb_sel",
  567. atb_parents, 0x090, 0x094, 0x098, 16, 2, 23, 0x008, 3),
  568. /* CLK_CFG_9 */
  569. MUX_GATE_CLR_SET_UPD(CLK_TOP_DPI_SEL, "dpi_sel",
  570. dpi_parents, 0x0a0, 0x0a4, 0x0a8, 0, 3, 7, 0x008, 5),
  571. MUX_GATE_CLR_SET_UPD(CLK_TOP_SCAM_SEL, "scam_sel",
  572. scam_parents, 0x0a0, 0x0a4, 0x0a8, 8, 1, 15, 0x008, 6),
  573. MUX_GATE_CLR_SET_UPD(CLK_TOP_DISP_PWM_SEL, "disp_pwm_sel",
  574. disp_pwm_parents, 0x0a0, 0x0a4, 0x0a8, 16, 3, 23, 0x008, 7),
  575. MUX_GATE_CLR_SET_UPD(CLK_TOP_USB_TOP_SEL, "usb_top_sel",
  576. usb_top_parents, 0x0a0, 0x0a4, 0x0a8, 24, 2, 31, 0x008, 8),
  577. /* CLK_CFG_10 */
  578. MUX_GATE_CLR_SET_UPD(CLK_TOP_SSUSB_XHCI_SEL, "ssusb_xhci_sel",
  579. ssusb_xhci_parents, 0x0b0, 0x0b4, 0x0b8, 0, 2, 7, 0x008, 9),
  580. MUX_GATE_CLR_SET_UPD(CLK_TOP_I2C_SEL, "i2c_sel",
  581. i2c_parents, 0x0b0, 0x0b4, 0x0b8, 8, 2, 15, 0x008, 10),
  582. MUX_GATE_CLR_SET_UPD(CLK_TOP_SENINF_SEL, "seninf_sel",
  583. seninf_parents, 0x0b0, 0x0b4, 0x0b8, 16, 3, 23, 0x008, 11),
  584. MUX_GATE_CLR_SET_UPD(CLK_TOP_SENINF1_SEL, "seninf1_sel",
  585. seninf_parents, 0x0b0, 0x0b4, 0x0b8, 24, 3, 31, 0x008, 12),
  586. /* CLK_CFG_11 */
  587. MUX_GATE_CLR_SET_UPD(CLK_TOP_SENINF2_SEL, "seninf2_sel",
  588. seninf_parents, 0x0c0, 0x0c4, 0x0c8, 0, 3, 7, 0x008, 13),
  589. MUX_GATE_CLR_SET_UPD(CLK_TOP_SENINF3_SEL, "seninf3_sel",
  590. seninf_parents, 0x0c0, 0x0c4, 0x0c8, 8, 3, 15, 0x008, 14),
  591. MUX_GATE_CLR_SET_UPD(CLK_TOP_TL_SEL, "tl_sel",
  592. tl_parents, 0x0c0, 0x0c4, 0x0c8, 16, 2, 23, 0x008, 15),
  593. MUX_GATE_CLR_SET_UPD(CLK_TOP_DXCC_SEL, "dxcc_sel",
  594. dxcc_parents, 0x0c0, 0x0c4, 0x0c8, 24, 2, 31, 0x008, 16),
  595. /* CLK_CFG_12 */
  596. MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_ENGEN1_SEL, "aud_engen1_sel",
  597. aud_engen1_parents, 0x0d0, 0x0d4, 0x0d8, 0, 2, 7, 0x008, 17),
  598. MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_ENGEN2_SEL, "aud_engen2_sel",
  599. aud_engen2_parents, 0x0d0, 0x0d4, 0x0d8, 8, 2, 15, 0x008, 18),
  600. MUX_GATE_CLR_SET_UPD(CLK_TOP_AES_UFSFDE_SEL, "aes_ufsfde_sel",
  601. aes_ufsfde_parents, 0x0d0, 0x0d4, 0x0d8, 16, 3, 23, 0x008, 19),
  602. MUX_GATE_CLR_SET_UPD(CLK_TOP_UFS_SEL, "ufs_sel",
  603. ufs_parents, 0x0d0, 0x0d4, 0x0d8, 24, 3, 31, 0x008, 20),
  604. /* CLK_CFG_13 */
  605. MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_1_SEL, "aud_1_sel",
  606. aud_1_parents, 0x0e0, 0x0e4, 0x0e8, 0, 1, 7, 0x008, 21),
  607. MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_2_SEL, "aud_2_sel",
  608. aud_2_parents, 0x0e0, 0x0e4, 0x0e8, 8, 1, 15, 0x008, 22),
  609. MUX_GATE_CLR_SET_UPD(CLK_TOP_ADSP_SEL, "adsp_sel",
  610. adsp_parents, 0x0e0, 0x0e4, 0x0e8, 16, 3, 23, 0x008, 23),
  611. MUX_GATE_CLR_SET_UPD(CLK_TOP_DPMAIF_MAIN_SEL, "dpmaif_main_sel",
  612. dpmaif_main_parents, 0x0e0, 0x0e4, 0x0e8, 24, 3, 31, 0x008, 24),
  613. /* CLK_CFG_14 */
  614. MUX_GATE_CLR_SET_UPD(CLK_TOP_VENC_SEL, "venc_sel",
  615. venc_parents, 0x0f0, 0x0f4, 0x0f8, 0, 4, 7, 0x008, 25),
  616. MUX_GATE_CLR_SET_UPD(CLK_TOP_VDEC_SEL, "vdec_sel",
  617. vdec_parents, 0x0f0, 0x0f4, 0x0f8, 8, 4, 15, 0x008, 26),
  618. MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTM_SEL, "camtm_sel",
  619. camtm_parents, 0x0f0, 0x0f4, 0x0f8, 16, 2, 23, 0x008, 27),
  620. MUX_GATE_CLR_SET_UPD(CLK_TOP_PWM_SEL, "pwm_sel",
  621. pwm_parents, 0x0f0, 0x0f4, 0x0f8, 24, 1, 31, 0x008, 28),
  622. /* CLK_CFG_15 */
  623. MUX_GATE_CLR_SET_UPD(CLK_TOP_AUDIO_H_SEL, "audio_h_sel",
  624. audio_h_parents, 0x100, 0x104, 0x108, 0, 2, 7, 0x008, 29),
  625. MUX_GATE_CLR_SET_UPD(CLK_TOP_SPMI_MST_SEL, "spmi_mst_sel",
  626. spmi_mst_parents, 0x100, 0x104, 0x108, 8, 3, 15, 0x008, 30),
  627. MUX_GATE_CLR_SET_UPD(CLK_TOP_AES_MSDCFDE_SEL, "aes_msdcfde_sel",
  628. aes_msdcfde_parents, 0x100, 0x104, 0x108, 24, 3, 31, 0x00c, 1),
  629. /* CLK_CFG_16 */
  630. MUX_GATE_CLR_SET_UPD(CLK_TOP_SFLASH_SEL, "sflash_sel",
  631. sflash_parents, 0x110, 0x114, 0x118, 8, 2, 15, 0x00c, 3),
  632. };
  633. static struct mtk_composite top_muxes[] = {
  634. /* CLK_AUDDIV_0 */
  635. MUX(CLK_TOP_APLL_I2S0_M_SEL, "apll_i2s0_m_sel", apll_i2s_m_parents, 0x320, 16, 1),
  636. MUX(CLK_TOP_APLL_I2S1_M_SEL, "apll_i2s1_m_sel", apll_i2s_m_parents, 0x320, 17, 1),
  637. MUX(CLK_TOP_APLL_I2S2_M_SEL, "apll_i2s2_m_sel", apll_i2s_m_parents, 0x320, 18, 1),
  638. MUX(CLK_TOP_APLL_I2S3_M_SEL, "apll_i2s3_m_sel", apll_i2s_m_parents, 0x320, 19, 1),
  639. MUX(CLK_TOP_APLL_I2S4_M_SEL, "apll_i2s4_m_sel", apll_i2s_m_parents, 0x320, 20, 1),
  640. MUX(CLK_TOP_APLL_I2S5_M_SEL, "apll_i2s5_m_sel", apll_i2s_m_parents, 0x320, 21, 1),
  641. MUX(CLK_TOP_APLL_I2S6_M_SEL, "apll_i2s6_m_sel", apll_i2s_m_parents, 0x320, 22, 1),
  642. MUX(CLK_TOP_APLL_I2S7_M_SEL, "apll_i2s7_m_sel", apll_i2s_m_parents, 0x320, 23, 1),
  643. MUX(CLK_TOP_APLL_I2S8_M_SEL, "apll_i2s8_m_sel", apll_i2s_m_parents, 0x320, 24, 1),
  644. MUX(CLK_TOP_APLL_I2S9_M_SEL, "apll_i2s9_m_sel", apll_i2s_m_parents, 0x320, 25, 1),
  645. };
  646. static const struct mtk_composite top_adj_divs[] = {
  647. DIV_GATE(CLK_TOP_APLL12_DIV0, "apll12_div0", "apll_i2s0_m_sel", 0x320, 0, 0x328, 8, 0),
  648. DIV_GATE(CLK_TOP_APLL12_DIV1, "apll12_div1", "apll_i2s1_m_sel", 0x320, 1, 0x328, 8, 8),
  649. DIV_GATE(CLK_TOP_APLL12_DIV2, "apll12_div2", "apll_i2s2_m_sel", 0x320, 2, 0x328, 8, 16),
  650. DIV_GATE(CLK_TOP_APLL12_DIV3, "apll12_div3", "apll_i2s3_m_sel", 0x320, 3, 0x328, 8, 24),
  651. DIV_GATE(CLK_TOP_APLL12_DIV4, "apll12_div4", "apll_i2s4_m_sel", 0x320, 4, 0x334, 8, 0),
  652. DIV_GATE(CLK_TOP_APLL12_DIVB, "apll12_divb", "apll12_div4", 0x320, 5, 0x334, 8, 8),
  653. DIV_GATE(CLK_TOP_APLL12_DIV5, "apll12_div5", "apll_i2s5_m_sel", 0x320, 6, 0x334, 8, 16),
  654. DIV_GATE(CLK_TOP_APLL12_DIV6, "apll12_div6", "apll_i2s6_m_sel", 0x320, 7, 0x334, 8, 24),
  655. DIV_GATE(CLK_TOP_APLL12_DIV7, "apll12_div7", "apll_i2s7_m_sel", 0x320, 8, 0x338, 8, 0),
  656. DIV_GATE(CLK_TOP_APLL12_DIV8, "apll12_div8", "apll_i2s8_m_sel", 0x320, 9, 0x338, 8, 8),
  657. DIV_GATE(CLK_TOP_APLL12_DIV9, "apll12_div9", "apll_i2s9_m_sel", 0x320, 10, 0x338, 8, 16),
  658. };
  659. static const struct mtk_gate_regs apmixed_cg_regs = {
  660. .set_ofs = 0x14,
  661. .clr_ofs = 0x14,
  662. .sta_ofs = 0x14,
  663. };
  664. #define GATE_APMIXED(_id, _name, _parent, _shift) \
  665. GATE_MTK(_id, _name, _parent, &apmixed_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  666. static const struct mtk_gate apmixed_clks[] = {
  667. GATE_APMIXED(CLK_APMIXED_MIPID26M, "mipid26m", "clk26m", 16),
  668. };
  669. static const struct mtk_gate_regs infra0_cg_regs = {
  670. .set_ofs = 0x80,
  671. .clr_ofs = 0x84,
  672. .sta_ofs = 0x90,
  673. };
  674. static const struct mtk_gate_regs infra1_cg_regs = {
  675. .set_ofs = 0x88,
  676. .clr_ofs = 0x8c,
  677. .sta_ofs = 0x94,
  678. };
  679. static const struct mtk_gate_regs infra2_cg_regs = {
  680. .set_ofs = 0xa4,
  681. .clr_ofs = 0xa8,
  682. .sta_ofs = 0xac,
  683. };
  684. static const struct mtk_gate_regs infra3_cg_regs = {
  685. .set_ofs = 0xc0,
  686. .clr_ofs = 0xc4,
  687. .sta_ofs = 0xc8,
  688. };
  689. static const struct mtk_gate_regs infra4_cg_regs = {
  690. .set_ofs = 0xd0,
  691. .clr_ofs = 0xd4,
  692. .sta_ofs = 0xd8,
  693. };
  694. static const struct mtk_gate_regs infra5_cg_regs = {
  695. .set_ofs = 0xe0,
  696. .clr_ofs = 0xe4,
  697. .sta_ofs = 0xe8,
  698. };
  699. #define GATE_INFRA0(_id, _name, _parent, _shift) \
  700. GATE_MTK(_id, _name, _parent, &infra0_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  701. #define GATE_INFRA1_FLAGS(_id, _name, _parent, _shift, _flag) \
  702. GATE_MTK_FLAGS(_id, _name, _parent, &infra1_cg_regs, _shift, \
  703. &mtk_clk_gate_ops_setclr, _flag)
  704. #define GATE_INFRA1(_id, _name, _parent, _shift) \
  705. GATE_INFRA1_FLAGS(_id, _name, _parent, _shift, 0)
  706. #define GATE_INFRA2(_id, _name, _parent, _shift) \
  707. GATE_MTK(_id, _name, _parent, &infra2_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  708. #define GATE_INFRA3_FLAGS(_id, _name, _parent, _shift, _flag) \
  709. GATE_MTK_FLAGS(_id, _name, _parent, &infra3_cg_regs, _shift, \
  710. &mtk_clk_gate_ops_setclr, _flag)
  711. #define GATE_INFRA3(_id, _name, _parent, _shift) \
  712. GATE_INFRA3_FLAGS(_id, _name, _parent, _shift, 0)
  713. #define GATE_INFRA4(_id, _name, _parent, _shift) \
  714. GATE_MTK(_id, _name, _parent, &infra4_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  715. #define GATE_INFRA5_FLAGS(_id, _name, _parent, _shift, _flag) \
  716. GATE_MTK_FLAGS(_id, _name, _parent, &infra5_cg_regs, _shift, \
  717. &mtk_clk_gate_ops_setclr, _flag)
  718. #define GATE_INFRA5(_id, _name, _parent, _shift) \
  719. GATE_INFRA5_FLAGS(_id, _name, _parent, _shift, 0)
  720. /*
  721. * CRITICAL CLOCK:
  722. * infra_133m and infra_66m are main peripheral bus clocks of SOC.
  723. * infra_device_apc and infra_device_apc_sync are for device access permission control module.
  724. */
  725. static const struct mtk_gate infra_clks[] = {
  726. /* INFRA0 */
  727. GATE_INFRA0(CLK_INFRA_PMIC_TMR, "infra_pmic_tmr", "pwrap_ulposc_sel", 0),
  728. GATE_INFRA0(CLK_INFRA_PMIC_AP, "infra_pmic_ap", "pwrap_ulposc_sel", 1),
  729. GATE_INFRA0(CLK_INFRA_PMIC_MD, "infra_pmic_md", "pwrap_ulposc_sel", 2),
  730. GATE_INFRA0(CLK_INFRA_PMIC_CONN, "infra_pmic_conn", "pwrap_ulposc_sel", 3),
  731. GATE_INFRA0(CLK_INFRA_SCPSYS, "infra_scpsys", "scp_sel", 4),
  732. GATE_INFRA0(CLK_INFRA_SEJ, "infra_sej", "axi_sel", 5),
  733. GATE_INFRA0(CLK_INFRA_APXGPT, "infra_apxgpt", "axi_sel", 6),
  734. GATE_INFRA0(CLK_INFRA_GCE, "infra_gce", "axi_sel", 8),
  735. GATE_INFRA0(CLK_INFRA_GCE2, "infra_gce2", "axi_sel", 9),
  736. GATE_INFRA0(CLK_INFRA_THERM, "infra_therm", "axi_sel", 10),
  737. GATE_INFRA0(CLK_INFRA_I2C0, "infra_i2c0", "i2c_sel", 11),
  738. GATE_INFRA0(CLK_INFRA_AP_DMA_PSEUDO, "infra_ap_dma_pseudo", "axi_sel", 12),
  739. GATE_INFRA0(CLK_INFRA_I2C2, "infra_i2c2", "i2c_sel", 13),
  740. GATE_INFRA0(CLK_INFRA_I2C3, "infra_i2c3", "i2c_sel", 14),
  741. GATE_INFRA0(CLK_INFRA_PWM_H, "infra_pwm_h", "axi_sel", 15),
  742. GATE_INFRA0(CLK_INFRA_PWM1, "infra_pwm1", "pwm_sel", 16),
  743. GATE_INFRA0(CLK_INFRA_PWM2, "infra_pwm2", "pwm_sel", 17),
  744. GATE_INFRA0(CLK_INFRA_PWM3, "infra_pwm3", "pwm_sel", 18),
  745. GATE_INFRA0(CLK_INFRA_PWM4, "infra_pwm4", "pwm_sel", 19),
  746. GATE_INFRA0(CLK_INFRA_PWM, "infra_pwm", "pwm_sel", 21),
  747. GATE_INFRA0(CLK_INFRA_UART0, "infra_uart0", "uart_sel", 22),
  748. GATE_INFRA0(CLK_INFRA_UART1, "infra_uart1", "uart_sel", 23),
  749. GATE_INFRA0(CLK_INFRA_UART2, "infra_uart2", "uart_sel", 24),
  750. GATE_INFRA0(CLK_INFRA_UART3, "infra_uart3", "uart_sel", 25),
  751. GATE_INFRA0(CLK_INFRA_GCE_26M, "infra_gce_26m", "axi_sel", 27),
  752. GATE_INFRA0(CLK_INFRA_CQ_DMA_FPC, "infra_cq_dma_fpc", "axi_sel", 28),
  753. GATE_INFRA0(CLK_INFRA_BTIF, "infra_btif", "axi_sel", 31),
  754. /* INFRA1 */
  755. GATE_INFRA1(CLK_INFRA_SPI0, "infra_spi0", "spi_sel", 1),
  756. GATE_INFRA1(CLK_INFRA_MSDC0, "infra_msdc0", "msdc50_0_h_sel", 2),
  757. GATE_INFRA1(CLK_INFRA_MSDC1, "infra_msdc1", "msdc50_0_h_sel", 4),
  758. GATE_INFRA1(CLK_INFRA_MSDC2, "infra_msdc2", "msdc50_0_h_sel", 5),
  759. GATE_INFRA1(CLK_INFRA_MSDC0_SRC, "infra_msdc0_src", "msdc50_0_sel", 6),
  760. GATE_INFRA1(CLK_INFRA_GCPU, "infra_gcpu", "axi_sel", 8),
  761. GATE_INFRA1(CLK_INFRA_TRNG, "infra_trng", "axi_sel", 9),
  762. GATE_INFRA1(CLK_INFRA_AUXADC, "infra_auxadc", "clk26m", 10),
  763. GATE_INFRA1(CLK_INFRA_CPUM, "infra_cpum", "axi_sel", 11),
  764. GATE_INFRA1(CLK_INFRA_CCIF1_AP, "infra_ccif1_ap", "axi_sel", 12),
  765. GATE_INFRA1(CLK_INFRA_CCIF1_MD, "infra_ccif1_md", "axi_sel", 13),
  766. GATE_INFRA1(CLK_INFRA_AUXADC_MD, "infra_auxadc_md", "clk26m", 14),
  767. GATE_INFRA1(CLK_INFRA_PCIE_TL_26M, "infra_pcie_tl_26m", "axi_sel", 15),
  768. GATE_INFRA1(CLK_INFRA_MSDC1_SRC, "infra_msdc1_src", "msdc30_1_sel", 16),
  769. GATE_INFRA1(CLK_INFRA_MSDC2_SRC, "infra_msdc2_src", "msdc30_2_sel", 17),
  770. GATE_INFRA1(CLK_INFRA_PCIE_TL_96M, "infra_pcie_tl_96m", "tl_sel", 18),
  771. GATE_INFRA1(CLK_INFRA_PCIE_PL_P_250M, "infra_pcie_pl_p_250m", "axi_sel", 19),
  772. GATE_INFRA1_FLAGS(CLK_INFRA_DEVICE_APC, "infra_device_apc", "axi_sel", 20, CLK_IS_CRITICAL),
  773. GATE_INFRA1(CLK_INFRA_CCIF_AP, "infra_ccif_ap", "axi_sel", 23),
  774. GATE_INFRA1(CLK_INFRA_DEBUGSYS, "infra_debugsys", "axi_sel", 24),
  775. GATE_INFRA1(CLK_INFRA_AUDIO, "infra_audio", "axi_sel", 25),
  776. GATE_INFRA1(CLK_INFRA_CCIF_MD, "infra_ccif_md", "axi_sel", 26),
  777. GATE_INFRA1(CLK_INFRA_DXCC_SEC_CORE, "infra_dxcc_sec_core", "dxcc_sel", 27),
  778. GATE_INFRA1(CLK_INFRA_DXCC_AO, "infra_dxcc_ao", "dxcc_sel", 28),
  779. GATE_INFRA1(CLK_INFRA_DBG_TRACE, "infra_dbg_trace", "axi_sel", 29),
  780. GATE_INFRA1(CLK_INFRA_DEVMPU_B, "infra_devmpu_b", "axi_sel", 30),
  781. GATE_INFRA1(CLK_INFRA_DRAMC_F26M, "infra_dramc_f26m", "clk26m", 31),
  782. /* INFRA2 */
  783. GATE_INFRA2(CLK_INFRA_IRTX, "infra_irtx", "clk26m", 0),
  784. GATE_INFRA2(CLK_INFRA_SSUSB, "infra_ssusb", "usb_top_sel", 1),
  785. GATE_INFRA2(CLK_INFRA_DISP_PWM, "infra_disp_pwm", "axi_sel", 2),
  786. GATE_INFRA2(CLK_INFRA_CLDMA_B, "infra_cldma_b", "axi_sel", 3),
  787. GATE_INFRA2(CLK_INFRA_AUDIO_26M_B, "infra_audio_26m_b", "clk26m", 4),
  788. GATE_INFRA2(CLK_INFRA_MODEM_TEMP_SHARE, "infra_modem_temp_share", "clk26m", 5),
  789. GATE_INFRA2(CLK_INFRA_SPI1, "infra_spi1", "spi_sel", 6),
  790. GATE_INFRA2(CLK_INFRA_I2C4, "infra_i2c4", "i2c_sel", 7),
  791. GATE_INFRA2(CLK_INFRA_SPI2, "infra_spi2", "spi_sel", 9),
  792. GATE_INFRA2(CLK_INFRA_SPI3, "infra_spi3", "spi_sel", 10),
  793. GATE_INFRA2(CLK_INFRA_UNIPRO_SYS, "infra_unipro_sys", "ufs_sel", 11),
  794. GATE_INFRA2(CLK_INFRA_UNIPRO_TICK, "infra_unipro_tick", "clk26m", 12),
  795. GATE_INFRA2(CLK_INFRA_UFS_MP_SAP_B, "infra_ufs_mp_sap_b", "clk26m", 13),
  796. GATE_INFRA2(CLK_INFRA_MD32_B, "infra_md32_b", "axi_sel", 14),
  797. GATE_INFRA2(CLK_INFRA_UNIPRO_MBIST, "infra_unipro_mbist", "axi_sel", 16),
  798. GATE_INFRA2(CLK_INFRA_I2C5, "infra_i2c5", "i2c_sel", 18),
  799. GATE_INFRA2(CLK_INFRA_I2C5_ARBITER, "infra_i2c5_arbiter", "i2c_sel", 19),
  800. GATE_INFRA2(CLK_INFRA_I2C5_IMM, "infra_i2c5_imm", "i2c_sel", 20),
  801. GATE_INFRA2(CLK_INFRA_I2C1_ARBITER, "infra_i2c1_arbiter", "i2c_sel", 21),
  802. GATE_INFRA2(CLK_INFRA_I2C1_IMM, "infra_i2c1_imm", "i2c_sel", 22),
  803. GATE_INFRA2(CLK_INFRA_I2C2_ARBITER, "infra_i2c2_arbiter", "i2c_sel", 23),
  804. GATE_INFRA2(CLK_INFRA_I2C2_IMM, "infra_i2c2_imm", "i2c_sel", 24),
  805. GATE_INFRA2(CLK_INFRA_SPI4, "infra_spi4", "spi_sel", 25),
  806. GATE_INFRA2(CLK_INFRA_SPI5, "infra_spi5", "spi_sel", 26),
  807. GATE_INFRA2(CLK_INFRA_CQ_DMA, "infra_cq_dma", "axi_sel", 27),
  808. GATE_INFRA2(CLK_INFRA_UFS, "infra_ufs", "ufs_sel", 28),
  809. GATE_INFRA2(CLK_INFRA_AES_UFSFDE, "infra_aes_ufsfde", "aes_ufsfde_sel", 29),
  810. GATE_INFRA2(CLK_INFRA_UFS_TICK, "infra_ufs_tick", "ufs_sel", 30),
  811. GATE_INFRA2(CLK_INFRA_SSUSB_XHCI, "infra_ssusb_xhci", "ssusb_xhci_sel", 31),
  812. /* INFRA3 */
  813. GATE_INFRA3(CLK_INFRA_MSDC0_SELF, "infra_msdc0_self", "msdc50_0_sel", 0),
  814. GATE_INFRA3(CLK_INFRA_MSDC1_SELF, "infra_msdc1_self", "msdc50_0_sel", 1),
  815. GATE_INFRA3(CLK_INFRA_MSDC2_SELF, "infra_msdc2_self", "msdc50_0_sel", 2),
  816. GATE_INFRA3(CLK_INFRA_UFS_AXI, "infra_ufs_axi", "axi_sel", 5),
  817. GATE_INFRA3(CLK_INFRA_I2C6, "infra_i2c6", "i2c_sel", 6),
  818. GATE_INFRA3(CLK_INFRA_AP_MSDC0, "infra_ap_msdc0", "msdc50_0_sel", 7),
  819. GATE_INFRA3(CLK_INFRA_MD_MSDC0, "infra_md_msdc0", "msdc50_0_sel", 8),
  820. GATE_INFRA3(CLK_INFRA_CCIF5_AP, "infra_ccif5_ap", "axi_sel", 9),
  821. GATE_INFRA3(CLK_INFRA_CCIF5_MD, "infra_ccif5_md", "axi_sel", 10),
  822. GATE_INFRA3(CLK_INFRA_PCIE_TOP_H_133M, "infra_pcie_top_h_133m", "axi_sel", 11),
  823. GATE_INFRA3(CLK_INFRA_FLASHIF_TOP_H_133M, "infra_flashif_top_h_133m", "axi_sel", 14),
  824. GATE_INFRA3(CLK_INFRA_PCIE_PERI_26M, "infra_pcie_peri_26m", "axi_sel", 15),
  825. GATE_INFRA3(CLK_INFRA_CCIF2_AP, "infra_ccif2_ap", "axi_sel", 16),
  826. GATE_INFRA3(CLK_INFRA_CCIF2_MD, "infra_ccif2_md", "axi_sel", 17),
  827. GATE_INFRA3(CLK_INFRA_CCIF3_AP, "infra_ccif3_ap", "axi_sel", 18),
  828. GATE_INFRA3(CLK_INFRA_CCIF3_MD, "infra_ccif3_md", "axi_sel", 19),
  829. GATE_INFRA3(CLK_INFRA_SEJ_F13M, "infra_sej_f13m", "clk26m", 20),
  830. GATE_INFRA3(CLK_INFRA_AES, "infra_aes", "axi_sel", 21),
  831. GATE_INFRA3(CLK_INFRA_I2C7, "infra_i2c7", "i2c_sel", 22),
  832. GATE_INFRA3(CLK_INFRA_I2C8, "infra_i2c8", "i2c_sel", 23),
  833. GATE_INFRA3(CLK_INFRA_FBIST2FPC, "infra_fbist2fpc", "msdc50_0_sel", 24),
  834. GATE_INFRA3_FLAGS(CLK_INFRA_DEVICE_APC_SYNC, "infra_device_apc_sync", "axi_sel", 25,
  835. CLK_IS_CRITICAL),
  836. GATE_INFRA3(CLK_INFRA_DPMAIF_MAIN, "infra_dpmaif_main", "dpmaif_main_sel", 26),
  837. GATE_INFRA3(CLK_INFRA_PCIE_TL_32K, "infra_pcie_tl_32k", "axi_sel", 27),
  838. GATE_INFRA3(CLK_INFRA_CCIF4_AP, "infra_ccif4_ap", "axi_sel", 28),
  839. GATE_INFRA3(CLK_INFRA_CCIF4_MD, "infra_ccif4_md", "axi_sel", 29),
  840. GATE_INFRA3(CLK_INFRA_SPI6, "infra_spi6", "spi_sel", 30),
  841. GATE_INFRA3(CLK_INFRA_SPI7, "infra_spi7", "spi_sel", 31),
  842. /* INFRA4 */
  843. GATE_INFRA4(CLK_INFRA_AP_DMA, "infra_ap_dma", "infra_ap_dma_pseudo", 31),
  844. /* INFRA5 */
  845. GATE_INFRA5_FLAGS(CLK_INFRA_133M, "infra_133m", "axi_sel", 0, CLK_IS_CRITICAL),
  846. GATE_INFRA5_FLAGS(CLK_INFRA_66M, "infra_66m", "axi_sel", 1, CLK_IS_CRITICAL),
  847. GATE_INFRA5(CLK_INFRA_66M_PERI_BUS, "infra_66m_peri_bus", "axi_sel", 2),
  848. GATE_INFRA5(CLK_INFRA_FREE_DCM_133M, "infra_free_dcm_133m", "axi_sel", 3),
  849. GATE_INFRA5(CLK_INFRA_FREE_DCM_66M, "infra_free_dcm_66m", "axi_sel", 4),
  850. GATE_INFRA5(CLK_INFRA_PERI_BUS_DCM_133M, "infra_peri_bus_dcm_133m", "axi_sel", 5),
  851. GATE_INFRA5(CLK_INFRA_PERI_BUS_DCM_66M, "infra_peri_bus_dcm_66m", "axi_sel", 6),
  852. GATE_INFRA5(CLK_INFRA_FLASHIF_PERI_26M, "infra_flashif_peri_26m", "axi_sel", 30),
  853. GATE_INFRA5(CLK_INFRA_FLASHIF_SFLASH, "infra_flashif_fsflash", "axi_sel", 31),
  854. };
  855. static const struct mtk_gate_regs peri_cg_regs = {
  856. .set_ofs = 0x20c,
  857. .clr_ofs = 0x20c,
  858. .sta_ofs = 0x20c,
  859. };
  860. #define GATE_PERI(_id, _name, _parent, _shift) \
  861. GATE_MTK(_id, _name, _parent, &peri_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  862. static const struct mtk_gate peri_clks[] = {
  863. GATE_PERI(CLK_PERI_PERIAXI, "peri_periaxi", "axi_sel", 31),
  864. };
  865. static const struct mtk_gate_regs top_cg_regs = {
  866. .set_ofs = 0x150,
  867. .clr_ofs = 0x150,
  868. .sta_ofs = 0x150,
  869. };
  870. #define GATE_TOP(_id, _name, _parent, _shift) \
  871. GATE_MTK(_id, _name, _parent, &top_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  872. static const struct mtk_gate top_clks[] = {
  873. GATE_TOP(CLK_TOP_SSUSB_TOP_REF, "ssusb_top_ref", "clk26m", 24),
  874. GATE_TOP(CLK_TOP_SSUSB_PHY_REF, "ssusb_phy_ref", "clk26m", 25),
  875. };
  876. static u16 infra_ao_rst_ofs[] = {
  877. INFRA_RST0_SET_OFFSET,
  878. INFRA_RST1_SET_OFFSET,
  879. INFRA_RST2_SET_OFFSET,
  880. INFRA_RST3_SET_OFFSET,
  881. INFRA_RST4_SET_OFFSET,
  882. };
  883. static u16 infra_ao_idx_map[] = {
  884. [MT8192_INFRA_RST0_THERM_CTRL_SWRST] = 0 * RST_NR_PER_BANK + 0,
  885. [MT8192_INFRA_RST2_PEXTP_PHY_SWRST] = 2 * RST_NR_PER_BANK + 15,
  886. [MT8192_INFRA_RST3_THERM_CTRL_PTP_SWRST] = 3 * RST_NR_PER_BANK + 5,
  887. [MT8192_INFRA_RST4_PCIE_TOP_SWRST] = 4 * RST_NR_PER_BANK + 1,
  888. [MT8192_INFRA_RST4_THERM_CTRL_MCU_SWRST] = 4 * RST_NR_PER_BANK + 12,
  889. };
  890. static const struct mtk_clk_rst_desc clk_rst_desc = {
  891. .version = MTK_RST_SET_CLR,
  892. .rst_bank_ofs = infra_ao_rst_ofs,
  893. .rst_bank_nr = ARRAY_SIZE(infra_ao_rst_ofs),
  894. .rst_idx_map = infra_ao_idx_map,
  895. .rst_idx_map_nr = ARRAY_SIZE(infra_ao_idx_map),
  896. };
  897. #define MT8192_PLL_FMAX (3800UL * MHZ)
  898. #define MT8192_PLL_FMIN (1500UL * MHZ)
  899. #define MT8192_INTEGER_BITS 8
  900. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  901. _rst_bar_mask, _pcwbits, _pd_reg, _pd_shift, \
  902. _tuner_reg, _tuner_en_reg, _tuner_en_bit, \
  903. _pcw_reg, _pcw_shift, _pcw_chg_reg, \
  904. _en_reg, _pll_en_bit) { \
  905. .id = _id, \
  906. .name = _name, \
  907. .reg = _reg, \
  908. .pwr_reg = _pwr_reg, \
  909. .en_mask = _en_mask, \
  910. .flags = _flags, \
  911. .rst_bar_mask = _rst_bar_mask, \
  912. .fmax = MT8192_PLL_FMAX, \
  913. .fmin = MT8192_PLL_FMIN, \
  914. .pcwbits = _pcwbits, \
  915. .pcwibits = MT8192_INTEGER_BITS, \
  916. .pd_reg = _pd_reg, \
  917. .pd_shift = _pd_shift, \
  918. .tuner_reg = _tuner_reg, \
  919. .tuner_en_reg = _tuner_en_reg, \
  920. .tuner_en_bit = _tuner_en_bit, \
  921. .pcw_reg = _pcw_reg, \
  922. .pcw_shift = _pcw_shift, \
  923. .pcw_chg_reg = _pcw_chg_reg, \
  924. .en_reg = _en_reg, \
  925. .pll_en_bit = _pll_en_bit, \
  926. }
  927. #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  928. _rst_bar_mask, _pcwbits, _pd_reg, _pd_shift, \
  929. _tuner_reg, _tuner_en_reg, _tuner_en_bit, \
  930. _pcw_reg, _pcw_shift) \
  931. PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  932. _rst_bar_mask, _pcwbits, _pd_reg, _pd_shift, \
  933. _tuner_reg, _tuner_en_reg, _tuner_en_bit, \
  934. _pcw_reg, _pcw_shift, 0, 0, 0)
  935. static const struct mtk_pll_data plls[] = {
  936. PLL_B(CLK_APMIXED_MAINPLL, "mainpll", 0x0340, 0x034c, 0xff000000,
  937. HAVE_RST_BAR, BIT(23), 22, 0x0344, 24, 0, 0, 0, 0x0344, 0),
  938. PLL_B(CLK_APMIXED_UNIVPLL, "univpll", 0x0308, 0x0314, 0xff000000,
  939. HAVE_RST_BAR, BIT(23), 22, 0x030c, 24, 0, 0, 0, 0x030c, 0),
  940. PLL(CLK_APMIXED_USBPLL, "usbpll", 0x03c4, 0x03cc, 0x00000000,
  941. 0, 0, 22, 0x03c4, 24, 0, 0, 0, 0x03c4, 0, 0x03c4, 0x03cc, 2),
  942. PLL_B(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0350, 0x035c, 0x00000000,
  943. 0, 0, 22, 0x0354, 24, 0, 0, 0, 0x0354, 0),
  944. PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x0360, 0x036c, 0xff000000,
  945. HAVE_RST_BAR, BIT(23), 22, 0x0364, 24, 0, 0, 0, 0x0364, 0),
  946. PLL_B(CLK_APMIXED_ADSPPLL, "adsppll", 0x0370, 0x037c, 0xff000000,
  947. HAVE_RST_BAR, BIT(23), 22, 0x0374, 24, 0, 0, 0, 0x0374, 0),
  948. PLL_B(CLK_APMIXED_MFGPLL, "mfgpll", 0x0268, 0x0274, 0x00000000,
  949. 0, 0, 22, 0x026c, 24, 0, 0, 0, 0x026c, 0),
  950. PLL_B(CLK_APMIXED_TVDPLL, "tvdpll", 0x0380, 0x038c, 0x00000000,
  951. 0, 0, 22, 0x0384, 24, 0, 0, 0, 0x0384, 0),
  952. PLL_B(CLK_APMIXED_APLL1, "apll1", 0x0318, 0x0328, 0x00000000,
  953. 0, 0, 32, 0x031c, 24, 0x0040, 0x000c, 0, 0x0320, 0),
  954. PLL_B(CLK_APMIXED_APLL2, "apll2", 0x032c, 0x033c, 0x00000000,
  955. 0, 0, 32, 0x0330, 24, 0, 0, 0, 0x0334, 0),
  956. };
  957. static struct clk_hw_onecell_data *top_clk_data;
  958. static void clk_mt8192_top_init_early(struct device_node *node)
  959. {
  960. int i;
  961. top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
  962. if (!top_clk_data)
  963. return;
  964. for (i = 0; i < CLK_TOP_NR_CLK; i++)
  965. top_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
  966. mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs), top_clk_data);
  967. of_clk_add_hw_provider(node, of_clk_hw_onecell_get, top_clk_data);
  968. }
  969. CLK_OF_DECLARE_DRIVER(mt8192_topckgen, "mediatek,mt8192-topckgen",
  970. clk_mt8192_top_init_early);
  971. /* Register mux notifier for MFG mux */
  972. static int clk_mt8192_reg_mfg_mux_notifier(struct device *dev, struct clk *clk)
  973. {
  974. struct mtk_mux_nb *mfg_mux_nb;
  975. int i;
  976. mfg_mux_nb = devm_kzalloc(dev, sizeof(*mfg_mux_nb), GFP_KERNEL);
  977. if (!mfg_mux_nb)
  978. return -ENOMEM;
  979. for (i = 0; i < ARRAY_SIZE(top_mtk_muxes); i++)
  980. if (top_mtk_muxes[i].id == CLK_TOP_MFG_PLL_SEL)
  981. break;
  982. if (i == ARRAY_SIZE(top_mtk_muxes))
  983. return -EINVAL;
  984. mfg_mux_nb->ops = top_mtk_muxes[i].ops;
  985. mfg_mux_nb->bypass_index = 0; /* Bypass to 26M crystal */
  986. return devm_mtk_clk_mux_notifier_register(dev, clk, mfg_mux_nb);
  987. }
  988. static int clk_mt8192_top_probe(struct platform_device *pdev)
  989. {
  990. struct device_node *node = pdev->dev.of_node;
  991. int r;
  992. void __iomem *base;
  993. base = devm_platform_ioremap_resource(pdev, 0);
  994. if (IS_ERR(base))
  995. return PTR_ERR(base);
  996. mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks), top_clk_data);
  997. mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs), top_clk_data);
  998. mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data);
  999. mtk_clk_register_muxes(top_mtk_muxes, ARRAY_SIZE(top_mtk_muxes), node, &mt8192_clk_lock,
  1000. top_clk_data);
  1001. mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base, &mt8192_clk_lock,
  1002. top_clk_data);
  1003. mtk_clk_register_composites(top_adj_divs, ARRAY_SIZE(top_adj_divs), base, &mt8192_clk_lock,
  1004. top_clk_data);
  1005. r = mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks), top_clk_data);
  1006. if (r)
  1007. return r;
  1008. r = clk_mt8192_reg_mfg_mux_notifier(&pdev->dev,
  1009. top_clk_data->hws[CLK_TOP_MFG_PLL_SEL]->clk);
  1010. if (r)
  1011. return r;
  1012. return of_clk_add_hw_provider(node, of_clk_hw_onecell_get,
  1013. top_clk_data);
  1014. }
  1015. static int clk_mt8192_infra_probe(struct platform_device *pdev)
  1016. {
  1017. struct clk_hw_onecell_data *clk_data;
  1018. struct device_node *node = pdev->dev.of_node;
  1019. int r;
  1020. clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
  1021. if (!clk_data)
  1022. return -ENOMEM;
  1023. r = mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks), clk_data);
  1024. if (r)
  1025. goto free_clk_data;
  1026. r = mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  1027. if (r)
  1028. goto free_clk_data;
  1029. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  1030. if (r)
  1031. goto free_clk_data;
  1032. return r;
  1033. free_clk_data:
  1034. mtk_free_clk_data(clk_data);
  1035. return r;
  1036. }
  1037. static int clk_mt8192_peri_probe(struct platform_device *pdev)
  1038. {
  1039. struct clk_hw_onecell_data *clk_data;
  1040. struct device_node *node = pdev->dev.of_node;
  1041. int r;
  1042. clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
  1043. if (!clk_data)
  1044. return -ENOMEM;
  1045. r = mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks), clk_data);
  1046. if (r)
  1047. goto free_clk_data;
  1048. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  1049. if (r)
  1050. goto free_clk_data;
  1051. return r;
  1052. free_clk_data:
  1053. mtk_free_clk_data(clk_data);
  1054. return r;
  1055. }
  1056. static int clk_mt8192_apmixed_probe(struct platform_device *pdev)
  1057. {
  1058. struct clk_hw_onecell_data *clk_data;
  1059. struct device_node *node = pdev->dev.of_node;
  1060. int r;
  1061. clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
  1062. if (!clk_data)
  1063. return -ENOMEM;
  1064. mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  1065. r = mtk_clk_register_gates(node, apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
  1066. if (r)
  1067. goto free_clk_data;
  1068. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  1069. if (r)
  1070. goto free_clk_data;
  1071. return r;
  1072. free_clk_data:
  1073. mtk_free_clk_data(clk_data);
  1074. return r;
  1075. }
  1076. static const struct of_device_id of_match_clk_mt8192[] = {
  1077. {
  1078. .compatible = "mediatek,mt8192-apmixedsys",
  1079. .data = clk_mt8192_apmixed_probe,
  1080. }, {
  1081. .compatible = "mediatek,mt8192-topckgen",
  1082. .data = clk_mt8192_top_probe,
  1083. }, {
  1084. .compatible = "mediatek,mt8192-infracfg",
  1085. .data = clk_mt8192_infra_probe,
  1086. }, {
  1087. .compatible = "mediatek,mt8192-pericfg",
  1088. .data = clk_mt8192_peri_probe,
  1089. }, {
  1090. /* sentinel */
  1091. }
  1092. };
  1093. static int clk_mt8192_probe(struct platform_device *pdev)
  1094. {
  1095. int (*clk_probe)(struct platform_device *pdev);
  1096. int r;
  1097. clk_probe = of_device_get_match_data(&pdev->dev);
  1098. if (!clk_probe)
  1099. return -EINVAL;
  1100. r = clk_probe(pdev);
  1101. if (r)
  1102. dev_err(&pdev->dev, "could not register clock provider: %s: %d\n", pdev->name, r);
  1103. return r;
  1104. }
  1105. static struct platform_driver clk_mt8192_drv = {
  1106. .probe = clk_mt8192_probe,
  1107. .driver = {
  1108. .name = "clk-mt8192",
  1109. .of_match_table = of_match_clk_mt8192,
  1110. },
  1111. };
  1112. static int __init clk_mt8192_init(void)
  1113. {
  1114. return platform_driver_register(&clk_mt8192_drv);
  1115. }
  1116. arch_initcall(clk_mt8192_init);