clk-mt8183.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Copyright (c) 2018 MediaTek Inc.
  4. // Author: Weiyi Lu <[email protected]>
  5. #include <linux/delay.h>
  6. #include <linux/mfd/syscon.h>
  7. #include <linux/of.h>
  8. #include <linux/of_address.h>
  9. #include <linux/of_device.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/slab.h>
  12. #include "clk-gate.h"
  13. #include "clk-mtk.h"
  14. #include "clk-mux.h"
  15. #include "clk-pll.h"
  16. #include <dt-bindings/clock/mt8183-clk.h>
  17. static DEFINE_SPINLOCK(mt8183_clk_lock);
  18. static const struct mtk_fixed_clk top_fixed_clks[] = {
  19. FIXED_CLK(CLK_TOP_CLK26M, "f_f26m_ck", "clk26m", 26000000),
  20. FIXED_CLK(CLK_TOP_ULPOSC, "osc", NULL, 250000),
  21. FIXED_CLK(CLK_TOP_UNIVP_192M, "univpll_192m", "univpll", 192000000),
  22. };
  23. static const struct mtk_fixed_factor top_early_divs[] = {
  24. FACTOR(CLK_TOP_CLK13M, "clk13m", "clk26m", 1, 2),
  25. };
  26. static const struct mtk_fixed_factor top_divs[] = {
  27. FACTOR(CLK_TOP_F26M_CK_D2, "csw_f26m_ck_d2", "clk26m", 1,
  28. 2),
  29. FACTOR(CLK_TOP_SYSPLL_CK, "syspll_ck", "mainpll", 1,
  30. 1),
  31. FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "syspll_ck", 1,
  32. 2),
  33. FACTOR(CLK_TOP_SYSPLL_D2_D2, "syspll_d2_d2", "syspll_d2", 1,
  34. 2),
  35. FACTOR(CLK_TOP_SYSPLL_D2_D4, "syspll_d2_d4", "syspll_d2", 1,
  36. 4),
  37. FACTOR(CLK_TOP_SYSPLL_D2_D8, "syspll_d2_d8", "syspll_d2", 1,
  38. 8),
  39. FACTOR(CLK_TOP_SYSPLL_D2_D16, "syspll_d2_d16", "syspll_d2", 1,
  40. 16),
  41. FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "mainpll", 1,
  42. 3),
  43. FACTOR(CLK_TOP_SYSPLL_D3_D2, "syspll_d3_d2", "syspll_d3", 1,
  44. 2),
  45. FACTOR(CLK_TOP_SYSPLL_D3_D4, "syspll_d3_d4", "syspll_d3", 1,
  46. 4),
  47. FACTOR(CLK_TOP_SYSPLL_D3_D8, "syspll_d3_d8", "syspll_d3", 1,
  48. 8),
  49. FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1,
  50. 5),
  51. FACTOR(CLK_TOP_SYSPLL_D5_D2, "syspll_d5_d2", "syspll_d5", 1,
  52. 2),
  53. FACTOR(CLK_TOP_SYSPLL_D5_D4, "syspll_d5_d4", "syspll_d5", 1,
  54. 4),
  55. FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "mainpll", 1,
  56. 7),
  57. FACTOR(CLK_TOP_SYSPLL_D7_D2, "syspll_d7_d2", "syspll_d7", 1,
  58. 2),
  59. FACTOR(CLK_TOP_SYSPLL_D7_D4, "syspll_d7_d4", "syspll_d7", 1,
  60. 4),
  61. FACTOR(CLK_TOP_UNIVPLL_CK, "univpll_ck", "univpll", 1,
  62. 1),
  63. FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll_ck", 1,
  64. 2),
  65. FACTOR(CLK_TOP_UNIVPLL_D2_D2, "univpll_d2_d2", "univpll_d2", 1,
  66. 2),
  67. FACTOR(CLK_TOP_UNIVPLL_D2_D4, "univpll_d2_d4", "univpll_d2", 1,
  68. 4),
  69. FACTOR(CLK_TOP_UNIVPLL_D2_D8, "univpll_d2_d8", "univpll_d2", 1,
  70. 8),
  71. FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1,
  72. 3),
  73. FACTOR(CLK_TOP_UNIVPLL_D3_D2, "univpll_d3_d2", "univpll_d3", 1,
  74. 2),
  75. FACTOR(CLK_TOP_UNIVPLL_D3_D4, "univpll_d3_d4", "univpll_d3", 1,
  76. 4),
  77. FACTOR(CLK_TOP_UNIVPLL_D3_D8, "univpll_d3_d8", "univpll_d3", 1,
  78. 8),
  79. FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1,
  80. 5),
  81. FACTOR(CLK_TOP_UNIVPLL_D5_D2, "univpll_d5_d2", "univpll_d5", 1,
  82. 2),
  83. FACTOR(CLK_TOP_UNIVPLL_D5_D4, "univpll_d5_d4", "univpll_d5", 1,
  84. 4),
  85. FACTOR(CLK_TOP_UNIVPLL_D5_D8, "univpll_d5_d8", "univpll_d5", 1,
  86. 8),
  87. FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1,
  88. 7),
  89. FACTOR(CLK_TOP_UNIVP_192M_CK, "univ_192m_ck", "univpll_192m", 1,
  90. 1),
  91. FACTOR(CLK_TOP_UNIVP_192M_D2, "univ_192m_d2", "univ_192m_ck", 1,
  92. 2),
  93. FACTOR(CLK_TOP_UNIVP_192M_D4, "univ_192m_d4", "univ_192m_ck", 1,
  94. 4),
  95. FACTOR(CLK_TOP_UNIVP_192M_D8, "univ_192m_d8", "univ_192m_ck", 1,
  96. 8),
  97. FACTOR(CLK_TOP_UNIVP_192M_D16, "univ_192m_d16", "univ_192m_ck", 1,
  98. 16),
  99. FACTOR(CLK_TOP_UNIVP_192M_D32, "univ_192m_d32", "univ_192m_ck", 1,
  100. 32),
  101. FACTOR(CLK_TOP_APLL1_CK, "apll1_ck", "apll1", 1,
  102. 1),
  103. FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1", 1,
  104. 2),
  105. FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "apll1", 1,
  106. 4),
  107. FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "apll1", 1,
  108. 8),
  109. FACTOR(CLK_TOP_APLL2_CK, "apll2_ck", "apll2", 1,
  110. 1),
  111. FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2", 1,
  112. 2),
  113. FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "apll2", 1,
  114. 4),
  115. FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "apll2", 1,
  116. 8),
  117. FACTOR(CLK_TOP_TVDPLL_CK, "tvdpll_ck", "tvdpll", 1,
  118. 1),
  119. FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1,
  120. 2),
  121. FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll", 1,
  122. 4),
  123. FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll", 1,
  124. 8),
  125. FACTOR(CLK_TOP_TVDPLL_D16, "tvdpll_d16", "tvdpll", 1,
  126. 16),
  127. FACTOR(CLK_TOP_MMPLL_CK, "mmpll_ck", "mmpll", 1,
  128. 1),
  129. FACTOR(CLK_TOP_MMPLL_D4, "mmpll_d4", "mmpll", 1,
  130. 4),
  131. FACTOR(CLK_TOP_MMPLL_D4_D2, "mmpll_d4_d2", "mmpll_d4", 1,
  132. 2),
  133. FACTOR(CLK_TOP_MMPLL_D4_D4, "mmpll_d4_d4", "mmpll_d4", 1,
  134. 4),
  135. FACTOR(CLK_TOP_MMPLL_D5, "mmpll_d5", "mmpll", 1,
  136. 5),
  137. FACTOR(CLK_TOP_MMPLL_D5_D2, "mmpll_d5_d2", "mmpll_d5", 1,
  138. 2),
  139. FACTOR(CLK_TOP_MMPLL_D5_D4, "mmpll_d5_d4", "mmpll_d5", 1,
  140. 4),
  141. FACTOR(CLK_TOP_MMPLL_D6, "mmpll_d6", "mmpll", 1,
  142. 6),
  143. FACTOR(CLK_TOP_MMPLL_D7, "mmpll_d7", "mmpll", 1,
  144. 7),
  145. FACTOR(CLK_TOP_MFGPLL_CK, "mfgpll_ck", "mfgpll", 1,
  146. 1),
  147. FACTOR(CLK_TOP_MSDCPLL_CK, "msdcpll_ck", "msdcpll", 1,
  148. 1),
  149. FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll", 1,
  150. 2),
  151. FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll", 1,
  152. 4),
  153. FACTOR(CLK_TOP_MSDCPLL_D8, "msdcpll_d8", "msdcpll", 1,
  154. 8),
  155. FACTOR(CLK_TOP_MSDCPLL_D16, "msdcpll_d16", "msdcpll", 1,
  156. 16),
  157. FACTOR(CLK_TOP_AD_OSC_CK, "ad_osc_ck", "osc", 1,
  158. 1),
  159. FACTOR(CLK_TOP_OSC_D2, "osc_d2", "osc", 1,
  160. 2),
  161. FACTOR(CLK_TOP_OSC_D4, "osc_d4", "osc", 1,
  162. 4),
  163. FACTOR(CLK_TOP_OSC_D8, "osc_d8", "osc", 1,
  164. 8),
  165. FACTOR(CLK_TOP_OSC_D16, "osc_d16", "osc", 1,
  166. 16),
  167. FACTOR(CLK_TOP_UNIVPLL, "univpll", "univ2pll", 1,
  168. 2),
  169. FACTOR(CLK_TOP_UNIVPLL_D3_D16, "univpll_d3_d16", "univpll_d3", 1,
  170. 16),
  171. };
  172. static const char * const axi_parents[] = {
  173. "clk26m",
  174. "syspll_d2_d4",
  175. "syspll_d7",
  176. "osc_d4"
  177. };
  178. static const char * const mm_parents[] = {
  179. "clk26m",
  180. "mmpll_d7",
  181. "syspll_d3",
  182. "univpll_d2_d2",
  183. "syspll_d2_d2",
  184. "syspll_d3_d2"
  185. };
  186. static const char * const img_parents[] = {
  187. "clk26m",
  188. "mmpll_d6",
  189. "univpll_d3",
  190. "syspll_d3",
  191. "univpll_d2_d2",
  192. "syspll_d2_d2",
  193. "univpll_d3_d2",
  194. "syspll_d3_d2"
  195. };
  196. static const char * const cam_parents[] = {
  197. "clk26m",
  198. "syspll_d2",
  199. "mmpll_d6",
  200. "syspll_d3",
  201. "mmpll_d7",
  202. "univpll_d3",
  203. "univpll_d2_d2",
  204. "syspll_d2_d2",
  205. "syspll_d3_d2",
  206. "univpll_d3_d2"
  207. };
  208. static const char * const dsp_parents[] = {
  209. "clk26m",
  210. "mmpll_d6",
  211. "mmpll_d7",
  212. "univpll_d3",
  213. "syspll_d3",
  214. "univpll_d2_d2",
  215. "syspll_d2_d2",
  216. "univpll_d3_d2",
  217. "syspll_d3_d2"
  218. };
  219. static const char * const dsp1_parents[] = {
  220. "clk26m",
  221. "mmpll_d6",
  222. "mmpll_d7",
  223. "univpll_d3",
  224. "syspll_d3",
  225. "univpll_d2_d2",
  226. "syspll_d2_d2",
  227. "univpll_d3_d2",
  228. "syspll_d3_d2"
  229. };
  230. static const char * const dsp2_parents[] = {
  231. "clk26m",
  232. "mmpll_d6",
  233. "mmpll_d7",
  234. "univpll_d3",
  235. "syspll_d3",
  236. "univpll_d2_d2",
  237. "syspll_d2_d2",
  238. "univpll_d3_d2",
  239. "syspll_d3_d2"
  240. };
  241. static const char * const ipu_if_parents[] = {
  242. "clk26m",
  243. "mmpll_d6",
  244. "mmpll_d7",
  245. "univpll_d3",
  246. "syspll_d3",
  247. "univpll_d2_d2",
  248. "syspll_d2_d2",
  249. "univpll_d3_d2",
  250. "syspll_d3_d2"
  251. };
  252. static const char * const mfg_parents[] = {
  253. "clk26m",
  254. "mfgpll_ck",
  255. "univpll_d3",
  256. "syspll_d3"
  257. };
  258. static const char * const f52m_mfg_parents[] = {
  259. "clk26m",
  260. "univpll_d3_d2",
  261. "univpll_d3_d4",
  262. "univpll_d3_d8"
  263. };
  264. static const char * const camtg_parents[] = {
  265. "clk26m",
  266. "univ_192m_d8",
  267. "univpll_d3_d8",
  268. "univ_192m_d4",
  269. "univpll_d3_d16",
  270. "csw_f26m_ck_d2",
  271. "univ_192m_d16",
  272. "univ_192m_d32"
  273. };
  274. static const char * const camtg2_parents[] = {
  275. "clk26m",
  276. "univ_192m_d8",
  277. "univpll_d3_d8",
  278. "univ_192m_d4",
  279. "univpll_d3_d16",
  280. "csw_f26m_ck_d2",
  281. "univ_192m_d16",
  282. "univ_192m_d32"
  283. };
  284. static const char * const camtg3_parents[] = {
  285. "clk26m",
  286. "univ_192m_d8",
  287. "univpll_d3_d8",
  288. "univ_192m_d4",
  289. "univpll_d3_d16",
  290. "csw_f26m_ck_d2",
  291. "univ_192m_d16",
  292. "univ_192m_d32"
  293. };
  294. static const char * const camtg4_parents[] = {
  295. "clk26m",
  296. "univ_192m_d8",
  297. "univpll_d3_d8",
  298. "univ_192m_d4",
  299. "univpll_d3_d16",
  300. "csw_f26m_ck_d2",
  301. "univ_192m_d16",
  302. "univ_192m_d32"
  303. };
  304. static const char * const uart_parents[] = {
  305. "clk26m",
  306. "univpll_d3_d8"
  307. };
  308. static const char * const spi_parents[] = {
  309. "clk26m",
  310. "syspll_d5_d2",
  311. "syspll_d3_d4",
  312. "msdcpll_d4"
  313. };
  314. static const char * const msdc50_hclk_parents[] = {
  315. "clk26m",
  316. "syspll_d2_d2",
  317. "syspll_d3_d2"
  318. };
  319. static const char * const msdc50_0_parents[] = {
  320. "clk26m",
  321. "msdcpll_ck",
  322. "msdcpll_d2",
  323. "univpll_d2_d4",
  324. "syspll_d3_d2",
  325. "univpll_d2_d2"
  326. };
  327. static const char * const msdc30_1_parents[] = {
  328. "clk26m",
  329. "univpll_d3_d2",
  330. "syspll_d3_d2",
  331. "syspll_d7",
  332. "msdcpll_d2"
  333. };
  334. static const char * const msdc30_2_parents[] = {
  335. "clk26m",
  336. "univpll_d3_d2",
  337. "syspll_d3_d2",
  338. "syspll_d7",
  339. "msdcpll_d2"
  340. };
  341. static const char * const audio_parents[] = {
  342. "clk26m",
  343. "syspll_d5_d4",
  344. "syspll_d7_d4",
  345. "syspll_d2_d16"
  346. };
  347. static const char * const aud_intbus_parents[] = {
  348. "clk26m",
  349. "syspll_d2_d4",
  350. "syspll_d7_d2"
  351. };
  352. static const char * const pmicspi_parents[] = {
  353. "clk26m",
  354. "syspll_d2_d8",
  355. "osc_d8"
  356. };
  357. static const char * const fpwrap_ulposc_parents[] = {
  358. "clk26m",
  359. "osc_d16",
  360. "osc_d4",
  361. "osc_d8"
  362. };
  363. static const char * const atb_parents[] = {
  364. "clk26m",
  365. "syspll_d2_d2",
  366. "syspll_d5"
  367. };
  368. static const char * const dpi0_parents[] = {
  369. "clk26m",
  370. "tvdpll_d2",
  371. "tvdpll_d4",
  372. "tvdpll_d8",
  373. "tvdpll_d16",
  374. "univpll_d5_d2",
  375. "univpll_d3_d4",
  376. "syspll_d3_d4",
  377. "univpll_d3_d8"
  378. };
  379. static const char * const scam_parents[] = {
  380. "clk26m",
  381. "syspll_d5_d2"
  382. };
  383. static const char * const disppwm_parents[] = {
  384. "clk26m",
  385. "univpll_d3_d4",
  386. "osc_d2",
  387. "osc_d4",
  388. "osc_d16"
  389. };
  390. static const char * const usb_top_parents[] = {
  391. "clk26m",
  392. "univpll_d5_d4",
  393. "univpll_d3_d4",
  394. "univpll_d5_d2"
  395. };
  396. static const char * const ssusb_top_xhci_parents[] = {
  397. "clk26m",
  398. "univpll_d5_d4",
  399. "univpll_d3_d4",
  400. "univpll_d5_d2"
  401. };
  402. static const char * const spm_parents[] = {
  403. "clk26m",
  404. "syspll_d2_d8"
  405. };
  406. static const char * const i2c_parents[] = {
  407. "clk26m",
  408. "syspll_d2_d8",
  409. "univpll_d5_d2"
  410. };
  411. static const char * const scp_parents[] = {
  412. "clk26m",
  413. "univpll_d2_d8",
  414. "syspll_d5",
  415. "syspll_d2_d2",
  416. "univpll_d2_d2",
  417. "syspll_d3",
  418. "univpll_d3"
  419. };
  420. static const char * const seninf_parents[] = {
  421. "clk26m",
  422. "univpll_d2_d2",
  423. "univpll_d3_d2",
  424. "univpll_d2_d4"
  425. };
  426. static const char * const dxcc_parents[] = {
  427. "clk26m",
  428. "syspll_d2_d2",
  429. "syspll_d2_d4",
  430. "syspll_d2_d8"
  431. };
  432. static const char * const aud_engen1_parents[] = {
  433. "clk26m",
  434. "apll1_d2",
  435. "apll1_d4",
  436. "apll1_d8"
  437. };
  438. static const char * const aud_engen2_parents[] = {
  439. "clk26m",
  440. "apll2_d2",
  441. "apll2_d4",
  442. "apll2_d8"
  443. };
  444. static const char * const faes_ufsfde_parents[] = {
  445. "clk26m",
  446. "syspll_d2",
  447. "syspll_d2_d2",
  448. "syspll_d3",
  449. "syspll_d2_d4",
  450. "univpll_d3"
  451. };
  452. static const char * const fufs_parents[] = {
  453. "clk26m",
  454. "syspll_d2_d4",
  455. "syspll_d2_d8",
  456. "syspll_d2_d16"
  457. };
  458. static const char * const aud_1_parents[] = {
  459. "clk26m",
  460. "apll1_ck"
  461. };
  462. static const char * const aud_2_parents[] = {
  463. "clk26m",
  464. "apll2_ck"
  465. };
  466. /*
  467. * CRITICAL CLOCK:
  468. * axi_sel is the main bus clock of whole SOC.
  469. * spm_sel is the clock of the always-on co-processor.
  470. */
  471. static const struct mtk_mux top_muxes[] = {
  472. /* CLK_CFG_0 */
  473. MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MUX_AXI, "axi_sel",
  474. axi_parents, 0x40,
  475. 0x44, 0x48, 0, 2, 7, 0x004, 0, CLK_IS_CRITICAL),
  476. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_MM, "mm_sel",
  477. mm_parents, 0x40,
  478. 0x44, 0x48, 8, 3, 15, 0x004, 1),
  479. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_IMG, "img_sel",
  480. img_parents, 0x40,
  481. 0x44, 0x48, 16, 3, 23, 0x004, 2),
  482. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_CAM, "cam_sel",
  483. cam_parents, 0x40,
  484. 0x44, 0x48, 24, 4, 31, 0x004, 3),
  485. /* CLK_CFG_1 */
  486. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DSP, "dsp_sel",
  487. dsp_parents, 0x50,
  488. 0x54, 0x58, 0, 4, 7, 0x004, 4),
  489. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DSP1, "dsp1_sel",
  490. dsp1_parents, 0x50,
  491. 0x54, 0x58, 8, 4, 15, 0x004, 5),
  492. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DSP2, "dsp2_sel",
  493. dsp2_parents, 0x50,
  494. 0x54, 0x58, 16, 4, 23, 0x004, 6),
  495. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_IPU_IF, "ipu_if_sel",
  496. ipu_if_parents, 0x50,
  497. 0x54, 0x58, 24, 4, 31, 0x004, 7),
  498. /* CLK_CFG_2 */
  499. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_MFG, "mfg_sel",
  500. mfg_parents, 0x60,
  501. 0x64, 0x68, 0, 2, 7, 0x004, 8),
  502. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_F52M_MFG, "f52m_mfg_sel",
  503. f52m_mfg_parents, 0x60,
  504. 0x64, 0x68, 8, 2, 15, 0x004, 9),
  505. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_CAMTG, "camtg_sel",
  506. camtg_parents, 0x60,
  507. 0x64, 0x68, 16, 3, 23, 0x004, 10),
  508. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_CAMTG2, "camtg2_sel",
  509. camtg2_parents, 0x60,
  510. 0x64, 0x68, 24, 3, 31, 0x004, 11),
  511. /* CLK_CFG_3 */
  512. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_CAMTG3, "camtg3_sel",
  513. camtg3_parents, 0x70,
  514. 0x74, 0x78, 0, 3, 7, 0x004, 12),
  515. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_CAMTG4, "camtg4_sel",
  516. camtg4_parents, 0x70,
  517. 0x74, 0x78, 8, 3, 15, 0x004, 13),
  518. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_UART, "uart_sel",
  519. uart_parents, 0x70,
  520. 0x74, 0x78, 16, 1, 23, 0x004, 14),
  521. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_SPI, "spi_sel",
  522. spi_parents, 0x70,
  523. 0x74, 0x78, 24, 2, 31, 0x004, 15),
  524. /* CLK_CFG_4 */
  525. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_MSDC50_0_HCLK, "msdc50_hclk_sel",
  526. msdc50_hclk_parents, 0x80,
  527. 0x84, 0x88, 0, 2, 7, 0x004, 16),
  528. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_MSDC50_0, "msdc50_0_sel",
  529. msdc50_0_parents, 0x80,
  530. 0x84, 0x88, 8, 3, 15, 0x004, 17),
  531. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_MSDC30_1, "msdc30_1_sel",
  532. msdc30_1_parents, 0x80,
  533. 0x84, 0x88, 16, 3, 23, 0x004, 18),
  534. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_MSDC30_2, "msdc30_2_sel",
  535. msdc30_2_parents, 0x80,
  536. 0x84, 0x88, 24, 3, 31, 0x004, 19),
  537. /* CLK_CFG_5 */
  538. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUDIO, "audio_sel",
  539. audio_parents, 0x90,
  540. 0x94, 0x98, 0, 2, 7, 0x004, 20),
  541. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUD_INTBUS, "aud_intbus_sel",
  542. aud_intbus_parents, 0x90,
  543. 0x94, 0x98, 8, 2, 15, 0x004, 21),
  544. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_PMICSPI, "pmicspi_sel",
  545. pmicspi_parents, 0x90,
  546. 0x94, 0x98, 16, 2, 23, 0x004, 22),
  547. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_FPWRAP_ULPOSC, "fpwrap_ulposc_sel",
  548. fpwrap_ulposc_parents, 0x90,
  549. 0x94, 0x98, 24, 2, 31, 0x004, 23),
  550. /* CLK_CFG_6 */
  551. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_ATB, "atb_sel",
  552. atb_parents, 0xa0,
  553. 0xa4, 0xa8, 0, 2, 7, 0x004, 24),
  554. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DPI0, "dpi0_sel",
  555. dpi0_parents, 0xa0,
  556. 0xa4, 0xa8, 16, 4, 23, 0x004, 26),
  557. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_SCAM, "scam_sel",
  558. scam_parents, 0xa0,
  559. 0xa4, 0xa8, 24, 1, 31, 0x004, 27),
  560. /* CLK_CFG_7 */
  561. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DISP_PWM, "disppwm_sel",
  562. disppwm_parents, 0xb0,
  563. 0xb4, 0xb8, 0, 3, 7, 0x004, 28),
  564. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_USB_TOP, "usb_top_sel",
  565. usb_top_parents, 0xb0,
  566. 0xb4, 0xb8, 8, 2, 15, 0x004, 29),
  567. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_SSUSB_TOP_XHCI, "ssusb_top_xhci_sel",
  568. ssusb_top_xhci_parents, 0xb0,
  569. 0xb4, 0xb8, 16, 2, 23, 0x004, 30),
  570. MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MUX_SPM, "spm_sel",
  571. spm_parents, 0xb0,
  572. 0xb4, 0xb8, 24, 1, 31, 0x008, 0, CLK_IS_CRITICAL),
  573. /* CLK_CFG_8 */
  574. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_I2C, "i2c_sel",
  575. i2c_parents, 0xc0,
  576. 0xc4, 0xc8, 0, 2, 7, 0x008, 1),
  577. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_SCP, "scp_sel",
  578. scp_parents, 0xc0,
  579. 0xc4, 0xc8, 8, 3, 15, 0x008, 2),
  580. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_SENINF, "seninf_sel",
  581. seninf_parents, 0xc0,
  582. 0xc4, 0xc8, 16, 2, 23, 0x008, 3),
  583. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_DXCC, "dxcc_sel",
  584. dxcc_parents, 0xc0,
  585. 0xc4, 0xc8, 24, 2, 31, 0x008, 4),
  586. /* CLK_CFG_9 */
  587. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUD_ENG1, "aud_eng1_sel",
  588. aud_engen1_parents, 0xd0,
  589. 0xd4, 0xd8, 0, 2, 7, 0x008, 5),
  590. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUD_ENG2, "aud_eng2_sel",
  591. aud_engen2_parents, 0xd0,
  592. 0xd4, 0xd8, 8, 2, 15, 0x008, 6),
  593. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_FAES_UFSFDE, "faes_ufsfde_sel",
  594. faes_ufsfde_parents, 0xd0,
  595. 0xd4, 0xd8, 16, 3, 23, 0x008, 7),
  596. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_FUFS, "fufs_sel",
  597. fufs_parents, 0xd0,
  598. 0xd4, 0xd8, 24, 2, 31, 0x008, 8),
  599. /* CLK_CFG_10 */
  600. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUD_1, "aud_1_sel",
  601. aud_1_parents, 0xe0,
  602. 0xe4, 0xe8, 0, 1, 7, 0x008, 9),
  603. MUX_GATE_CLR_SET_UPD(CLK_TOP_MUX_AUD_2, "aud_2_sel",
  604. aud_2_parents, 0xe0,
  605. 0xe4, 0xe8, 8, 1, 15, 0x008, 10),
  606. };
  607. static const char * const apll_i2s0_parents[] = {
  608. "aud_1_sel",
  609. "aud_2_sel"
  610. };
  611. static const char * const apll_i2s1_parents[] = {
  612. "aud_1_sel",
  613. "aud_2_sel"
  614. };
  615. static const char * const apll_i2s2_parents[] = {
  616. "aud_1_sel",
  617. "aud_2_sel"
  618. };
  619. static const char * const apll_i2s3_parents[] = {
  620. "aud_1_sel",
  621. "aud_2_sel"
  622. };
  623. static const char * const apll_i2s4_parents[] = {
  624. "aud_1_sel",
  625. "aud_2_sel"
  626. };
  627. static const char * const apll_i2s5_parents[] = {
  628. "aud_1_sel",
  629. "aud_2_sel"
  630. };
  631. static struct mtk_composite top_aud_muxes[] = {
  632. MUX(CLK_TOP_MUX_APLL_I2S0, "apll_i2s0_sel", apll_i2s0_parents,
  633. 0x320, 8, 1),
  634. MUX(CLK_TOP_MUX_APLL_I2S1, "apll_i2s1_sel", apll_i2s1_parents,
  635. 0x320, 9, 1),
  636. MUX(CLK_TOP_MUX_APLL_I2S2, "apll_i2s2_sel", apll_i2s2_parents,
  637. 0x320, 10, 1),
  638. MUX(CLK_TOP_MUX_APLL_I2S3, "apll_i2s3_sel", apll_i2s3_parents,
  639. 0x320, 11, 1),
  640. MUX(CLK_TOP_MUX_APLL_I2S4, "apll_i2s4_sel", apll_i2s4_parents,
  641. 0x320, 12, 1),
  642. MUX(CLK_TOP_MUX_APLL_I2S5, "apll_i2s5_sel", apll_i2s5_parents,
  643. 0x328, 20, 1),
  644. };
  645. static const char * const mcu_mp0_parents[] = {
  646. "clk26m",
  647. "armpll_ll",
  648. "armpll_div_pll1",
  649. "armpll_div_pll2"
  650. };
  651. static const char * const mcu_mp2_parents[] = {
  652. "clk26m",
  653. "armpll_l",
  654. "armpll_div_pll1",
  655. "armpll_div_pll2"
  656. };
  657. static const char * const mcu_bus_parents[] = {
  658. "clk26m",
  659. "ccipll",
  660. "armpll_div_pll1",
  661. "armpll_div_pll2"
  662. };
  663. static struct mtk_composite mcu_muxes[] = {
  664. /* mp0_pll_divider_cfg */
  665. MUX(CLK_MCU_MP0_SEL, "mcu_mp0_sel", mcu_mp0_parents, 0x7A0, 9, 2),
  666. /* mp2_pll_divider_cfg */
  667. MUX(CLK_MCU_MP2_SEL, "mcu_mp2_sel", mcu_mp2_parents, 0x7A8, 9, 2),
  668. /* bus_pll_divider_cfg */
  669. MUX(CLK_MCU_BUS_SEL, "mcu_bus_sel", mcu_bus_parents, 0x7C0, 9, 2),
  670. };
  671. static struct mtk_composite top_aud_divs[] = {
  672. DIV_GATE(CLK_TOP_APLL12_DIV0, "apll12_div0", "apll_i2s0_sel",
  673. 0x320, 2, 0x324, 8, 0),
  674. DIV_GATE(CLK_TOP_APLL12_DIV1, "apll12_div1", "apll_i2s1_sel",
  675. 0x320, 3, 0x324, 8, 8),
  676. DIV_GATE(CLK_TOP_APLL12_DIV2, "apll12_div2", "apll_i2s2_sel",
  677. 0x320, 4, 0x324, 8, 16),
  678. DIV_GATE(CLK_TOP_APLL12_DIV3, "apll12_div3", "apll_i2s3_sel",
  679. 0x320, 5, 0x324, 8, 24),
  680. DIV_GATE(CLK_TOP_APLL12_DIV4, "apll12_div4", "apll_i2s4_sel",
  681. 0x320, 6, 0x328, 8, 0),
  682. DIV_GATE(CLK_TOP_APLL12_DIVB, "apll12_divb", "apll12_div4",
  683. 0x320, 7, 0x328, 8, 8),
  684. };
  685. static const struct mtk_gate_regs top_cg_regs = {
  686. .set_ofs = 0x104,
  687. .clr_ofs = 0x104,
  688. .sta_ofs = 0x104,
  689. };
  690. #define GATE_TOP(_id, _name, _parent, _shift) \
  691. GATE_MTK(_id, _name, _parent, &top_cg_regs, _shift, \
  692. &mtk_clk_gate_ops_no_setclr_inv)
  693. static const struct mtk_gate top_clks[] = {
  694. /* TOP */
  695. GATE_TOP(CLK_TOP_ARMPLL_DIV_PLL1, "armpll_div_pll1", "mainpll", 4),
  696. GATE_TOP(CLK_TOP_ARMPLL_DIV_PLL2, "armpll_div_pll2", "univpll", 5),
  697. };
  698. static const struct mtk_gate_regs infra0_cg_regs = {
  699. .set_ofs = 0x80,
  700. .clr_ofs = 0x84,
  701. .sta_ofs = 0x90,
  702. };
  703. static const struct mtk_gate_regs infra1_cg_regs = {
  704. .set_ofs = 0x88,
  705. .clr_ofs = 0x8c,
  706. .sta_ofs = 0x94,
  707. };
  708. static const struct mtk_gate_regs infra2_cg_regs = {
  709. .set_ofs = 0xa4,
  710. .clr_ofs = 0xa8,
  711. .sta_ofs = 0xac,
  712. };
  713. static const struct mtk_gate_regs infra3_cg_regs = {
  714. .set_ofs = 0xc0,
  715. .clr_ofs = 0xc4,
  716. .sta_ofs = 0xc8,
  717. };
  718. #define GATE_INFRA0(_id, _name, _parent, _shift) \
  719. GATE_MTK(_id, _name, _parent, &infra0_cg_regs, _shift, \
  720. &mtk_clk_gate_ops_setclr)
  721. #define GATE_INFRA1(_id, _name, _parent, _shift) \
  722. GATE_MTK(_id, _name, _parent, &infra1_cg_regs, _shift, \
  723. &mtk_clk_gate_ops_setclr)
  724. #define GATE_INFRA2(_id, _name, _parent, _shift) \
  725. GATE_MTK(_id, _name, _parent, &infra2_cg_regs, _shift, \
  726. &mtk_clk_gate_ops_setclr)
  727. #define GATE_INFRA3(_id, _name, _parent, _shift) \
  728. GATE_MTK(_id, _name, _parent, &infra3_cg_regs, _shift, \
  729. &mtk_clk_gate_ops_setclr)
  730. static const struct mtk_gate infra_clks[] = {
  731. /* INFRA0 */
  732. GATE_INFRA0(CLK_INFRA_PMIC_TMR, "infra_pmic_tmr",
  733. "axi_sel", 0),
  734. GATE_INFRA0(CLK_INFRA_PMIC_AP, "infra_pmic_ap",
  735. "axi_sel", 1),
  736. GATE_INFRA0(CLK_INFRA_PMIC_MD, "infra_pmic_md",
  737. "axi_sel", 2),
  738. GATE_INFRA0(CLK_INFRA_PMIC_CONN, "infra_pmic_conn",
  739. "axi_sel", 3),
  740. GATE_INFRA0(CLK_INFRA_SCPSYS, "infra_scp",
  741. "scp_sel", 4),
  742. GATE_INFRA0(CLK_INFRA_SEJ, "infra_sej",
  743. "f_f26m_ck", 5),
  744. GATE_INFRA0(CLK_INFRA_APXGPT, "infra_apxgpt",
  745. "axi_sel", 6),
  746. GATE_INFRA0(CLK_INFRA_ICUSB, "infra_icusb",
  747. "axi_sel", 8),
  748. GATE_INFRA0(CLK_INFRA_GCE, "infra_gce",
  749. "axi_sel", 9),
  750. GATE_INFRA0(CLK_INFRA_THERM, "infra_therm",
  751. "axi_sel", 10),
  752. GATE_INFRA0(CLK_INFRA_I2C0, "infra_i2c0",
  753. "i2c_sel", 11),
  754. GATE_INFRA0(CLK_INFRA_I2C1, "infra_i2c1",
  755. "i2c_sel", 12),
  756. GATE_INFRA0(CLK_INFRA_I2C2, "infra_i2c2",
  757. "i2c_sel", 13),
  758. GATE_INFRA0(CLK_INFRA_I2C3, "infra_i2c3",
  759. "i2c_sel", 14),
  760. GATE_INFRA0(CLK_INFRA_PWM_HCLK, "infra_pwm_hclk",
  761. "axi_sel", 15),
  762. GATE_INFRA0(CLK_INFRA_PWM1, "infra_pwm1",
  763. "i2c_sel", 16),
  764. GATE_INFRA0(CLK_INFRA_PWM2, "infra_pwm2",
  765. "i2c_sel", 17),
  766. GATE_INFRA0(CLK_INFRA_PWM3, "infra_pwm3",
  767. "i2c_sel", 18),
  768. GATE_INFRA0(CLK_INFRA_PWM4, "infra_pwm4",
  769. "i2c_sel", 19),
  770. GATE_INFRA0(CLK_INFRA_PWM, "infra_pwm",
  771. "i2c_sel", 21),
  772. GATE_INFRA0(CLK_INFRA_UART0, "infra_uart0",
  773. "uart_sel", 22),
  774. GATE_INFRA0(CLK_INFRA_UART1, "infra_uart1",
  775. "uart_sel", 23),
  776. GATE_INFRA0(CLK_INFRA_UART2, "infra_uart2",
  777. "uart_sel", 24),
  778. GATE_INFRA0(CLK_INFRA_UART3, "infra_uart3",
  779. "uart_sel", 25),
  780. GATE_INFRA0(CLK_INFRA_GCE_26M, "infra_gce_26m",
  781. "axi_sel", 27),
  782. GATE_INFRA0(CLK_INFRA_CQ_DMA_FPC, "infra_cqdma_fpc",
  783. "axi_sel", 28),
  784. GATE_INFRA0(CLK_INFRA_BTIF, "infra_btif",
  785. "axi_sel", 31),
  786. /* INFRA1 */
  787. GATE_INFRA1(CLK_INFRA_SPI0, "infra_spi0",
  788. "spi_sel", 1),
  789. GATE_INFRA1(CLK_INFRA_MSDC0, "infra_msdc0",
  790. "msdc50_hclk_sel", 2),
  791. GATE_INFRA1(CLK_INFRA_MSDC1, "infra_msdc1",
  792. "axi_sel", 4),
  793. GATE_INFRA1(CLK_INFRA_MSDC2, "infra_msdc2",
  794. "axi_sel", 5),
  795. GATE_INFRA1(CLK_INFRA_MSDC0_SCK, "infra_msdc0_sck",
  796. "msdc50_0_sel", 6),
  797. GATE_INFRA1(CLK_INFRA_DVFSRC, "infra_dvfsrc",
  798. "f_f26m_ck", 7),
  799. GATE_INFRA1(CLK_INFRA_GCPU, "infra_gcpu",
  800. "axi_sel", 8),
  801. GATE_INFRA1(CLK_INFRA_TRNG, "infra_trng",
  802. "axi_sel", 9),
  803. GATE_INFRA1(CLK_INFRA_AUXADC, "infra_auxadc",
  804. "f_f26m_ck", 10),
  805. GATE_INFRA1(CLK_INFRA_CPUM, "infra_cpum",
  806. "axi_sel", 11),
  807. GATE_INFRA1(CLK_INFRA_CCIF1_AP, "infra_ccif1_ap",
  808. "axi_sel", 12),
  809. GATE_INFRA1(CLK_INFRA_CCIF1_MD, "infra_ccif1_md",
  810. "axi_sel", 13),
  811. GATE_INFRA1(CLK_INFRA_AUXADC_MD, "infra_auxadc_md",
  812. "f_f26m_ck", 14),
  813. GATE_INFRA1(CLK_INFRA_MSDC1_SCK, "infra_msdc1_sck",
  814. "msdc30_1_sel", 16),
  815. GATE_INFRA1(CLK_INFRA_MSDC2_SCK, "infra_msdc2_sck",
  816. "msdc30_2_sel", 17),
  817. GATE_INFRA1(CLK_INFRA_AP_DMA, "infra_apdma",
  818. "axi_sel", 18),
  819. GATE_INFRA1(CLK_INFRA_XIU, "infra_xiu",
  820. "axi_sel", 19),
  821. GATE_INFRA1(CLK_INFRA_DEVICE_APC, "infra_device_apc",
  822. "axi_sel", 20),
  823. GATE_INFRA1(CLK_INFRA_CCIF_AP, "infra_ccif_ap",
  824. "axi_sel", 23),
  825. GATE_INFRA1(CLK_INFRA_DEBUGSYS, "infra_debugsys",
  826. "axi_sel", 24),
  827. GATE_INFRA1(CLK_INFRA_AUDIO, "infra_audio",
  828. "axi_sel", 25),
  829. GATE_INFRA1(CLK_INFRA_CCIF_MD, "infra_ccif_md",
  830. "axi_sel", 26),
  831. GATE_INFRA1(CLK_INFRA_DXCC_SEC_CORE, "infra_dxcc_sec_core",
  832. "dxcc_sel", 27),
  833. GATE_INFRA1(CLK_INFRA_DXCC_AO, "infra_dxcc_ao",
  834. "dxcc_sel", 28),
  835. GATE_INFRA1(CLK_INFRA_DEVMPU_BCLK, "infra_devmpu_bclk",
  836. "axi_sel", 30),
  837. GATE_INFRA1(CLK_INFRA_DRAMC_F26M, "infra_dramc_f26m",
  838. "f_f26m_ck", 31),
  839. /* INFRA2 */
  840. GATE_INFRA2(CLK_INFRA_IRTX, "infra_irtx",
  841. "f_f26m_ck", 0),
  842. GATE_INFRA2(CLK_INFRA_USB, "infra_usb",
  843. "usb_top_sel", 1),
  844. GATE_INFRA2(CLK_INFRA_DISP_PWM, "infra_disppwm",
  845. "axi_sel", 2),
  846. GATE_INFRA2(CLK_INFRA_CLDMA_BCLK, "infra_cldma_bclk",
  847. "axi_sel", 3),
  848. GATE_INFRA2(CLK_INFRA_AUDIO_26M_BCLK, "infra_audio_26m_bclk",
  849. "f_f26m_ck", 4),
  850. GATE_INFRA2(CLK_INFRA_SPI1, "infra_spi1",
  851. "spi_sel", 6),
  852. GATE_INFRA2(CLK_INFRA_I2C4, "infra_i2c4",
  853. "i2c_sel", 7),
  854. GATE_INFRA2(CLK_INFRA_MODEM_TEMP_SHARE, "infra_md_tmp_share",
  855. "f_f26m_ck", 8),
  856. GATE_INFRA2(CLK_INFRA_SPI2, "infra_spi2",
  857. "spi_sel", 9),
  858. GATE_INFRA2(CLK_INFRA_SPI3, "infra_spi3",
  859. "spi_sel", 10),
  860. GATE_INFRA2(CLK_INFRA_UNIPRO_SCK, "infra_unipro_sck",
  861. "ssusb_top_xhci_sel", 11),
  862. GATE_INFRA2(CLK_INFRA_UNIPRO_TICK, "infra_unipro_tick",
  863. "fufs_sel", 12),
  864. GATE_INFRA2(CLK_INFRA_UFS_MP_SAP_BCLK, "infra_ufs_mp_sap_bck",
  865. "fufs_sel", 13),
  866. GATE_INFRA2(CLK_INFRA_MD32_BCLK, "infra_md32_bclk",
  867. "axi_sel", 14),
  868. GATE_INFRA2(CLK_INFRA_UNIPRO_MBIST, "infra_unipro_mbist",
  869. "axi_sel", 16),
  870. GATE_INFRA2(CLK_INFRA_I2C5, "infra_i2c5",
  871. "i2c_sel", 18),
  872. GATE_INFRA2(CLK_INFRA_I2C5_ARBITER, "infra_i2c5_arbiter",
  873. "i2c_sel", 19),
  874. GATE_INFRA2(CLK_INFRA_I2C5_IMM, "infra_i2c5_imm",
  875. "i2c_sel", 20),
  876. GATE_INFRA2(CLK_INFRA_I2C1_ARBITER, "infra_i2c1_arbiter",
  877. "i2c_sel", 21),
  878. GATE_INFRA2(CLK_INFRA_I2C1_IMM, "infra_i2c1_imm",
  879. "i2c_sel", 22),
  880. GATE_INFRA2(CLK_INFRA_I2C2_ARBITER, "infra_i2c2_arbiter",
  881. "i2c_sel", 23),
  882. GATE_INFRA2(CLK_INFRA_I2C2_IMM, "infra_i2c2_imm",
  883. "i2c_sel", 24),
  884. GATE_INFRA2(CLK_INFRA_SPI4, "infra_spi4",
  885. "spi_sel", 25),
  886. GATE_INFRA2(CLK_INFRA_SPI5, "infra_spi5",
  887. "spi_sel", 26),
  888. GATE_INFRA2(CLK_INFRA_CQ_DMA, "infra_cqdma",
  889. "axi_sel", 27),
  890. GATE_INFRA2(CLK_INFRA_UFS, "infra_ufs",
  891. "fufs_sel", 28),
  892. GATE_INFRA2(CLK_INFRA_AES_UFSFDE, "infra_aes_ufsfde",
  893. "faes_ufsfde_sel", 29),
  894. GATE_INFRA2(CLK_INFRA_UFS_TICK, "infra_ufs_tick",
  895. "fufs_sel", 30),
  896. /* INFRA3 */
  897. GATE_INFRA3(CLK_INFRA_MSDC0_SELF, "infra_msdc0_self",
  898. "msdc50_0_sel", 0),
  899. GATE_INFRA3(CLK_INFRA_MSDC1_SELF, "infra_msdc1_self",
  900. "msdc50_0_sel", 1),
  901. GATE_INFRA3(CLK_INFRA_MSDC2_SELF, "infra_msdc2_self",
  902. "msdc50_0_sel", 2),
  903. GATE_INFRA3(CLK_INFRA_UFS_AXI, "infra_ufs_axi",
  904. "axi_sel", 5),
  905. GATE_INFRA3(CLK_INFRA_I2C6, "infra_i2c6",
  906. "i2c_sel", 6),
  907. GATE_INFRA3(CLK_INFRA_AP_MSDC0, "infra_ap_msdc0",
  908. "msdc50_hclk_sel", 7),
  909. GATE_INFRA3(CLK_INFRA_MD_MSDC0, "infra_md_msdc0",
  910. "msdc50_hclk_sel", 8),
  911. GATE_INFRA3(CLK_INFRA_CCIF2_AP, "infra_ccif2_ap",
  912. "axi_sel", 16),
  913. GATE_INFRA3(CLK_INFRA_CCIF2_MD, "infra_ccif2_md",
  914. "axi_sel", 17),
  915. GATE_INFRA3(CLK_INFRA_CCIF3_AP, "infra_ccif3_ap",
  916. "axi_sel", 18),
  917. GATE_INFRA3(CLK_INFRA_CCIF3_MD, "infra_ccif3_md",
  918. "axi_sel", 19),
  919. GATE_INFRA3(CLK_INFRA_SEJ_F13M, "infra_sej_f13m",
  920. "f_f26m_ck", 20),
  921. GATE_INFRA3(CLK_INFRA_AES_BCLK, "infra_aes_bclk",
  922. "axi_sel", 21),
  923. GATE_INFRA3(CLK_INFRA_I2C7, "infra_i2c7",
  924. "i2c_sel", 22),
  925. GATE_INFRA3(CLK_INFRA_I2C8, "infra_i2c8",
  926. "i2c_sel", 23),
  927. GATE_INFRA3(CLK_INFRA_FBIST2FPC, "infra_fbist2fpc",
  928. "msdc50_0_sel", 24),
  929. };
  930. static const struct mtk_gate_regs peri_cg_regs = {
  931. .set_ofs = 0x20c,
  932. .clr_ofs = 0x20c,
  933. .sta_ofs = 0x20c,
  934. };
  935. #define GATE_PERI(_id, _name, _parent, _shift) \
  936. GATE_MTK(_id, _name, _parent, &peri_cg_regs, _shift, \
  937. &mtk_clk_gate_ops_no_setclr_inv)
  938. static const struct mtk_gate peri_clks[] = {
  939. GATE_PERI(CLK_PERI_AXI, "peri_axi", "axi_sel", 31),
  940. };
  941. static const struct mtk_gate_regs apmixed_cg_regs = {
  942. .set_ofs = 0x20,
  943. .clr_ofs = 0x20,
  944. .sta_ofs = 0x20,
  945. };
  946. #define GATE_APMIXED_FLAGS(_id, _name, _parent, _shift, _flags) \
  947. GATE_MTK_FLAGS(_id, _name, _parent, &apmixed_cg_regs, \
  948. _shift, &mtk_clk_gate_ops_no_setclr_inv, _flags)
  949. #define GATE_APMIXED(_id, _name, _parent, _shift) \
  950. GATE_APMIXED_FLAGS(_id, _name, _parent, _shift, 0)
  951. /*
  952. * CRITICAL CLOCK:
  953. * apmixed_appll26m is the toppest clock gate of all PLLs.
  954. */
  955. static const struct mtk_gate apmixed_clks[] = {
  956. /* AUDIO0 */
  957. GATE_APMIXED(CLK_APMIXED_SSUSB_26M, "apmixed_ssusb26m",
  958. "f_f26m_ck", 4),
  959. GATE_APMIXED_FLAGS(CLK_APMIXED_APPLL_26M, "apmixed_appll26m",
  960. "f_f26m_ck", 5, CLK_IS_CRITICAL),
  961. GATE_APMIXED(CLK_APMIXED_MIPIC0_26M, "apmixed_mipic026m",
  962. "f_f26m_ck", 6),
  963. GATE_APMIXED(CLK_APMIXED_MDPLLGP_26M, "apmixed_mdpll26m",
  964. "f_f26m_ck", 7),
  965. GATE_APMIXED(CLK_APMIXED_MMSYS_26M, "apmixed_mmsys26m",
  966. "f_f26m_ck", 8),
  967. GATE_APMIXED(CLK_APMIXED_UFS_26M, "apmixed_ufs26m",
  968. "f_f26m_ck", 9),
  969. GATE_APMIXED(CLK_APMIXED_MIPIC1_26M, "apmixed_mipic126m",
  970. "f_f26m_ck", 11),
  971. GATE_APMIXED(CLK_APMIXED_MEMPLL_26M, "apmixed_mempll26m",
  972. "f_f26m_ck", 13),
  973. GATE_APMIXED(CLK_APMIXED_CLKSQ_LVPLL_26M, "apmixed_lvpll26m",
  974. "f_f26m_ck", 14),
  975. GATE_APMIXED(CLK_APMIXED_MIPID0_26M, "apmixed_mipid026m",
  976. "f_f26m_ck", 16),
  977. GATE_APMIXED(CLK_APMIXED_MIPID1_26M, "apmixed_mipid126m",
  978. "f_f26m_ck", 17),
  979. };
  980. #define MT8183_PLL_FMAX (3800UL * MHZ)
  981. #define MT8183_PLL_FMIN (1500UL * MHZ)
  982. #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  983. _rst_bar_mask, _pcwbits, _pcwibits, _pd_reg, \
  984. _pd_shift, _tuner_reg, _tuner_en_reg, \
  985. _tuner_en_bit, _pcw_reg, _pcw_shift, \
  986. _pcw_chg_reg, _div_table) { \
  987. .id = _id, \
  988. .name = _name, \
  989. .reg = _reg, \
  990. .pwr_reg = _pwr_reg, \
  991. .en_mask = _en_mask, \
  992. .flags = _flags, \
  993. .rst_bar_mask = _rst_bar_mask, \
  994. .fmax = MT8183_PLL_FMAX, \
  995. .fmin = MT8183_PLL_FMIN, \
  996. .pcwbits = _pcwbits, \
  997. .pcwibits = _pcwibits, \
  998. .pd_reg = _pd_reg, \
  999. .pd_shift = _pd_shift, \
  1000. .tuner_reg = _tuner_reg, \
  1001. .tuner_en_reg = _tuner_en_reg, \
  1002. .tuner_en_bit = _tuner_en_bit, \
  1003. .pcw_reg = _pcw_reg, \
  1004. .pcw_shift = _pcw_shift, \
  1005. .pcw_chg_reg = _pcw_chg_reg, \
  1006. .div_table = _div_table, \
  1007. }
  1008. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  1009. _rst_bar_mask, _pcwbits, _pcwibits, _pd_reg, \
  1010. _pd_shift, _tuner_reg, _tuner_en_reg, \
  1011. _tuner_en_bit, _pcw_reg, _pcw_shift, \
  1012. _pcw_chg_reg) \
  1013. PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
  1014. _rst_bar_mask, _pcwbits, _pcwibits, _pd_reg, \
  1015. _pd_shift, _tuner_reg, _tuner_en_reg, \
  1016. _tuner_en_bit, _pcw_reg, _pcw_shift, \
  1017. _pcw_chg_reg, NULL)
  1018. static const struct mtk_pll_div_table armpll_div_table[] = {
  1019. { .div = 0, .freq = MT8183_PLL_FMAX },
  1020. { .div = 1, .freq = 1500 * MHZ },
  1021. { .div = 2, .freq = 750 * MHZ },
  1022. { .div = 3, .freq = 375 * MHZ },
  1023. { .div = 4, .freq = 187500000 },
  1024. { } /* sentinel */
  1025. };
  1026. static const struct mtk_pll_div_table mfgpll_div_table[] = {
  1027. { .div = 0, .freq = MT8183_PLL_FMAX },
  1028. { .div = 1, .freq = 1600 * MHZ },
  1029. { .div = 2, .freq = 800 * MHZ },
  1030. { .div = 3, .freq = 400 * MHZ },
  1031. { .div = 4, .freq = 200 * MHZ },
  1032. { } /* sentinel */
  1033. };
  1034. static const struct mtk_pll_data plls[] = {
  1035. PLL_B(CLK_APMIXED_ARMPLL_LL, "armpll_ll", 0x0200, 0x020C, 0,
  1036. HAVE_RST_BAR | PLL_AO, BIT(24), 22, 8, 0x0204, 24, 0x0, 0x0, 0,
  1037. 0x0204, 0, 0, armpll_div_table),
  1038. PLL_B(CLK_APMIXED_ARMPLL_L, "armpll_l", 0x0210, 0x021C, 0,
  1039. HAVE_RST_BAR | PLL_AO, BIT(24), 22, 8, 0x0214, 24, 0x0, 0x0, 0,
  1040. 0x0214, 0, 0, armpll_div_table),
  1041. PLL(CLK_APMIXED_CCIPLL, "ccipll", 0x0290, 0x029C, 0,
  1042. HAVE_RST_BAR | PLL_AO, BIT(24), 22, 8, 0x0294, 24, 0x0, 0x0, 0,
  1043. 0x0294, 0, 0),
  1044. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0220, 0x022C, 0,
  1045. HAVE_RST_BAR, BIT(24), 22, 8, 0x0224, 24, 0x0, 0x0, 0,
  1046. 0x0224, 0, 0),
  1047. PLL(CLK_APMIXED_UNIV2PLL, "univ2pll", 0x0230, 0x023C, 0,
  1048. HAVE_RST_BAR, BIT(24), 22, 8, 0x0234, 24, 0x0, 0x0, 0,
  1049. 0x0234, 0, 0),
  1050. PLL_B(CLK_APMIXED_MFGPLL, "mfgpll", 0x0240, 0x024C, 0,
  1051. 0, 0, 22, 8, 0x0244, 24, 0x0, 0x0, 0, 0x0244, 0, 0,
  1052. mfgpll_div_table),
  1053. PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0250, 0x025C, 0,
  1054. 0, 0, 22, 8, 0x0254, 24, 0x0, 0x0, 0, 0x0254, 0, 0),
  1055. PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x0260, 0x026C, 0,
  1056. 0, 0, 22, 8, 0x0264, 24, 0x0, 0x0, 0, 0x0264, 0, 0),
  1057. PLL(CLK_APMIXED_MMPLL, "mmpll", 0x0270, 0x027C, 0,
  1058. HAVE_RST_BAR, BIT(23), 22, 8, 0x0274, 24, 0x0, 0x0, 0,
  1059. 0x0274, 0, 0),
  1060. PLL(CLK_APMIXED_APLL1, "apll1", 0x02A0, 0x02B0, 0,
  1061. 0, 0, 32, 8, 0x02A0, 1, 0x02A8, 0x0014, 0, 0x02A4, 0, 0x02A0),
  1062. PLL(CLK_APMIXED_APLL2, "apll2", 0x02b4, 0x02c4, 0,
  1063. 0, 0, 32, 8, 0x02B4, 1, 0x02BC, 0x0014, 1, 0x02B8, 0, 0x02B4),
  1064. };
  1065. static u16 infra_rst_ofs[] = {
  1066. INFRA_RST0_SET_OFFSET,
  1067. INFRA_RST1_SET_OFFSET,
  1068. INFRA_RST2_SET_OFFSET,
  1069. INFRA_RST3_SET_OFFSET,
  1070. };
  1071. static const struct mtk_clk_rst_desc clk_rst_desc = {
  1072. .version = MTK_RST_SET_CLR,
  1073. .rst_bank_ofs = infra_rst_ofs,
  1074. .rst_bank_nr = ARRAY_SIZE(infra_rst_ofs),
  1075. };
  1076. static int clk_mt8183_apmixed_probe(struct platform_device *pdev)
  1077. {
  1078. struct clk_hw_onecell_data *clk_data;
  1079. struct device_node *node = pdev->dev.of_node;
  1080. clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
  1081. mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  1082. mtk_clk_register_gates(node, apmixed_clks, ARRAY_SIZE(apmixed_clks),
  1083. clk_data);
  1084. return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  1085. }
  1086. static struct clk_hw_onecell_data *top_clk_data;
  1087. static void clk_mt8183_top_init_early(struct device_node *node)
  1088. {
  1089. int i;
  1090. top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
  1091. for (i = 0; i < CLK_TOP_NR_CLK; i++)
  1092. top_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
  1093. mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs),
  1094. top_clk_data);
  1095. of_clk_add_hw_provider(node, of_clk_hw_onecell_get, top_clk_data);
  1096. }
  1097. CLK_OF_DECLARE_DRIVER(mt8183_topckgen, "mediatek,mt8183-topckgen",
  1098. clk_mt8183_top_init_early);
  1099. /* Register mux notifier for MFG mux */
  1100. static int clk_mt8183_reg_mfg_mux_notifier(struct device *dev, struct clk *clk)
  1101. {
  1102. struct mtk_mux_nb *mfg_mux_nb;
  1103. int i;
  1104. mfg_mux_nb = devm_kzalloc(dev, sizeof(*mfg_mux_nb), GFP_KERNEL);
  1105. if (!mfg_mux_nb)
  1106. return -ENOMEM;
  1107. for (i = 0; i < ARRAY_SIZE(top_muxes); i++)
  1108. if (top_muxes[i].id == CLK_TOP_MUX_MFG)
  1109. break;
  1110. if (i == ARRAY_SIZE(top_muxes))
  1111. return -EINVAL;
  1112. mfg_mux_nb->ops = top_muxes[i].ops;
  1113. mfg_mux_nb->bypass_index = 0; /* Bypass to 26M crystal */
  1114. return devm_mtk_clk_mux_notifier_register(dev, clk, mfg_mux_nb);
  1115. }
  1116. static int clk_mt8183_top_probe(struct platform_device *pdev)
  1117. {
  1118. void __iomem *base;
  1119. struct device_node *node = pdev->dev.of_node;
  1120. int ret;
  1121. base = devm_platform_ioremap_resource(pdev, 0);
  1122. if (IS_ERR(base))
  1123. return PTR_ERR(base);
  1124. mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
  1125. top_clk_data);
  1126. mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs),
  1127. top_clk_data);
  1128. mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data);
  1129. mtk_clk_register_muxes(top_muxes, ARRAY_SIZE(top_muxes),
  1130. node, &mt8183_clk_lock, top_clk_data);
  1131. mtk_clk_register_composites(top_aud_muxes, ARRAY_SIZE(top_aud_muxes),
  1132. base, &mt8183_clk_lock, top_clk_data);
  1133. mtk_clk_register_composites(top_aud_divs, ARRAY_SIZE(top_aud_divs),
  1134. base, &mt8183_clk_lock, top_clk_data);
  1135. mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
  1136. top_clk_data);
  1137. ret = clk_mt8183_reg_mfg_mux_notifier(&pdev->dev,
  1138. top_clk_data->hws[CLK_TOP_MUX_MFG]->clk);
  1139. if (ret)
  1140. return ret;
  1141. return of_clk_add_hw_provider(node, of_clk_hw_onecell_get,
  1142. top_clk_data);
  1143. }
  1144. static int clk_mt8183_infra_probe(struct platform_device *pdev)
  1145. {
  1146. struct clk_hw_onecell_data *clk_data;
  1147. struct device_node *node = pdev->dev.of_node;
  1148. int r;
  1149. clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
  1150. mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
  1151. clk_data);
  1152. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  1153. if (r) {
  1154. dev_err(&pdev->dev,
  1155. "%s(): could not register clock provider: %d\n",
  1156. __func__, r);
  1157. return r;
  1158. }
  1159. mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  1160. return r;
  1161. }
  1162. static int clk_mt8183_peri_probe(struct platform_device *pdev)
  1163. {
  1164. struct clk_hw_onecell_data *clk_data;
  1165. struct device_node *node = pdev->dev.of_node;
  1166. clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
  1167. mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks),
  1168. clk_data);
  1169. return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  1170. }
  1171. static int clk_mt8183_mcu_probe(struct platform_device *pdev)
  1172. {
  1173. struct clk_hw_onecell_data *clk_data;
  1174. struct device_node *node = pdev->dev.of_node;
  1175. void __iomem *base;
  1176. base = devm_platform_ioremap_resource(pdev, 0);
  1177. if (IS_ERR(base))
  1178. return PTR_ERR(base);
  1179. clk_data = mtk_alloc_clk_data(CLK_MCU_NR_CLK);
  1180. mtk_clk_register_composites(mcu_muxes, ARRAY_SIZE(mcu_muxes), base,
  1181. &mt8183_clk_lock, clk_data);
  1182. return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  1183. }
  1184. static const struct of_device_id of_match_clk_mt8183[] = {
  1185. {
  1186. .compatible = "mediatek,mt8183-apmixedsys",
  1187. .data = clk_mt8183_apmixed_probe,
  1188. }, {
  1189. .compatible = "mediatek,mt8183-topckgen",
  1190. .data = clk_mt8183_top_probe,
  1191. }, {
  1192. .compatible = "mediatek,mt8183-infracfg",
  1193. .data = clk_mt8183_infra_probe,
  1194. }, {
  1195. .compatible = "mediatek,mt8183-pericfg",
  1196. .data = clk_mt8183_peri_probe,
  1197. }, {
  1198. .compatible = "mediatek,mt8183-mcucfg",
  1199. .data = clk_mt8183_mcu_probe,
  1200. }, {
  1201. /* sentinel */
  1202. }
  1203. };
  1204. static int clk_mt8183_probe(struct platform_device *pdev)
  1205. {
  1206. int (*clk_probe)(struct platform_device *pdev);
  1207. int r;
  1208. clk_probe = of_device_get_match_data(&pdev->dev);
  1209. if (!clk_probe)
  1210. return -EINVAL;
  1211. r = clk_probe(pdev);
  1212. if (r)
  1213. dev_err(&pdev->dev,
  1214. "could not register clock provider: %s: %d\n",
  1215. pdev->name, r);
  1216. return r;
  1217. }
  1218. static struct platform_driver clk_mt8183_drv = {
  1219. .probe = clk_mt8183_probe,
  1220. .driver = {
  1221. .name = "clk-mt8183",
  1222. .of_match_table = of_match_clk_mt8183,
  1223. },
  1224. };
  1225. static int __init clk_mt8183_init(void)
  1226. {
  1227. return platform_driver_register(&clk_mt8183_drv);
  1228. }
  1229. arch_initcall(clk_mt8183_init);