clk-mt8167.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2020 MediaTek Inc.
  4. * Copyright (c) 2020 BayLibre, SAS
  5. * Author: James Liao <[email protected]>
  6. * Fabien Parent <[email protected]>
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/of.h>
  10. #include <linux/of_address.h>
  11. #include <linux/slab.h>
  12. #include <linux/mfd/syscon.h>
  13. #include "clk-gate.h"
  14. #include "clk-mtk.h"
  15. #include "clk-pll.h"
  16. #include <dt-bindings/clock/mt8167-clk.h>
  17. static DEFINE_SPINLOCK(mt8167_clk_lock);
  18. static const struct mtk_fixed_clk fixed_clks[] __initconst = {
  19. FIXED_CLK(CLK_TOP_CLK_NULL, "clk_null", NULL, 0),
  20. FIXED_CLK(CLK_TOP_I2S_INFRA_BCK, "i2s_infra_bck", "clk_null", 26000000),
  21. FIXED_CLK(CLK_TOP_MEMPLL, "mempll", "clk26m", 800000000),
  22. FIXED_CLK(CLK_TOP_DSI0_LNTC_DSICK, "dsi0_lntc_dsick", "clk26m", 75000000),
  23. FIXED_CLK(CLK_TOP_VPLL_DPIX, "vpll_dpix", "clk26m", 75000000),
  24. FIXED_CLK(CLK_TOP_LVDSTX_CLKDIG_CTS, "lvdstx_dig_cts", "clk26m", 52500000),
  25. };
  26. static const struct mtk_fixed_factor top_divs[] __initconst = {
  27. FACTOR(CLK_TOP_DMPLL, "dmpll_ck", "mempll", 1, 1),
  28. FACTOR(CLK_TOP_MAINPLL_D2, "mainpll_d2", "mainpll", 1, 2),
  29. FACTOR(CLK_TOP_MAINPLL_D4, "mainpll_d4", "mainpll", 1, 4),
  30. FACTOR(CLK_TOP_MAINPLL_D8, "mainpll_d8", "mainpll", 1, 8),
  31. FACTOR(CLK_TOP_MAINPLL_D16, "mainpll_d16", "mainpll", 1, 16),
  32. FACTOR(CLK_TOP_MAINPLL_D11, "mainpll_d11", "mainpll", 1, 11),
  33. FACTOR(CLK_TOP_MAINPLL_D22, "mainpll_d22", "mainpll", 1, 22),
  34. FACTOR(CLK_TOP_MAINPLL_D3, "mainpll_d3", "mainpll", 1, 3),
  35. FACTOR(CLK_TOP_MAINPLL_D6, "mainpll_d6", "mainpll", 1, 6),
  36. FACTOR(CLK_TOP_MAINPLL_D12, "mainpll_d12", "mainpll", 1, 12),
  37. FACTOR(CLK_TOP_MAINPLL_D5, "mainpll_d5", "mainpll", 1, 5),
  38. FACTOR(CLK_TOP_MAINPLL_D10, "mainpll_d10", "mainpll", 1, 10),
  39. FACTOR(CLK_TOP_MAINPLL_D20, "mainpll_d20", "mainpll", 1, 20),
  40. FACTOR(CLK_TOP_MAINPLL_D40, "mainpll_d40", "mainpll", 1, 40),
  41. FACTOR(CLK_TOP_MAINPLL_D7, "mainpll_d7", "mainpll", 1, 7),
  42. FACTOR(CLK_TOP_MAINPLL_D14, "mainpll_d14", "mainpll", 1, 14),
  43. FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2),
  44. FACTOR(CLK_TOP_UNIVPLL_D4, "univpll_d4", "univpll", 1, 4),
  45. FACTOR(CLK_TOP_UNIVPLL_D8, "univpll_d8", "univpll", 1, 8),
  46. FACTOR(CLK_TOP_UNIVPLL_D16, "univpll_d16", "univpll", 1, 16),
  47. FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3),
  48. FACTOR(CLK_TOP_UNIVPLL_D6, "univpll_d6", "univpll", 1, 6),
  49. FACTOR(CLK_TOP_UNIVPLL_D12, "univpll_d12", "univpll", 1, 12),
  50. FACTOR(CLK_TOP_UNIVPLL_D24, "univpll_d24", "univpll", 1, 24),
  51. FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
  52. FACTOR(CLK_TOP_UNIVPLL_D20, "univpll_d20", "univpll", 1, 20),
  53. FACTOR(CLK_TOP_MMPLL380M, "mmpll380m", "mmpll", 1, 1),
  54. FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll", 1, 2),
  55. FACTOR(CLK_TOP_MMPLL_200M, "mmpll_200m", "mmpll", 1, 3),
  56. FACTOR(CLK_TOP_LVDSPLL, "lvdspll_ck", "lvdspll", 1, 1),
  57. FACTOR(CLK_TOP_LVDSPLL_D2, "lvdspll_d2", "lvdspll", 1, 2),
  58. FACTOR(CLK_TOP_LVDSPLL_D4, "lvdspll_d4", "lvdspll", 1, 4),
  59. FACTOR(CLK_TOP_LVDSPLL_D8, "lvdspll_d8", "lvdspll", 1, 8),
  60. FACTOR(CLK_TOP_USB_PHY48M, "usb_phy48m_ck", "univpll", 1, 26),
  61. FACTOR(CLK_TOP_APLL1, "apll1_ck", "apll1", 1, 1),
  62. FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1_ck", 1, 2),
  63. FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "rg_apll1_d2_en", 1, 2),
  64. FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "rg_apll1_d4_en", 1, 2),
  65. FACTOR(CLK_TOP_APLL2, "apll2_ck", "apll2", 1, 1),
  66. FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2_ck", 1, 2),
  67. FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "rg_apll2_d2_en", 1, 2),
  68. FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "rg_apll2_d4_en", 1, 2),
  69. FACTOR(CLK_TOP_CLK26M, "clk26m_ck", "clk26m", 1, 1),
  70. FACTOR(CLK_TOP_CLK26M_D2, "clk26m_d2", "clk26m", 1, 2),
  71. FACTOR(CLK_TOP_MIPI_26M, "mipi_26m", "clk26m", 1, 1),
  72. FACTOR(CLK_TOP_TVDPLL, "tvdpll_ck", "tvdpll", 1, 1),
  73. FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1, 2),
  74. FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll_ck", 1, 4),
  75. FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll_ck", 1, 8),
  76. FACTOR(CLK_TOP_TVDPLL_D16, "tvdpll_d16", "tvdpll_ck", 1, 16),
  77. FACTOR(CLK_TOP_AHB_INFRA_D2, "ahb_infra_d2", "ahb_infra_sel", 1, 2),
  78. FACTOR(CLK_TOP_NFI1X, "nfi1x_ck", "nfi2x_pad_sel", 1, 2),
  79. FACTOR(CLK_TOP_ETH_D2, "eth_d2_ck", "eth_sel", 1, 2),
  80. };
  81. static const char * const uart0_parents[] __initconst = {
  82. "clk26m_ck",
  83. "univpll_d24"
  84. };
  85. static const char * const gfmux_emi1x_parents[] __initconst = {
  86. "clk26m_ck",
  87. "dmpll_ck"
  88. };
  89. static const char * const emi_ddrphy_parents[] __initconst = {
  90. "gfmux_emi1x_sel",
  91. "gfmux_emi1x_sel"
  92. };
  93. static const char * const ahb_infra_parents[] __initconst = {
  94. "clk_null",
  95. "clk26m_ck",
  96. "mainpll_d11",
  97. "clk_null",
  98. "mainpll_d12",
  99. "clk_null",
  100. "clk_null",
  101. "clk_null",
  102. "clk_null",
  103. "clk_null",
  104. "clk_null",
  105. "clk_null",
  106. "mainpll_d10"
  107. };
  108. static const char * const csw_mux_mfg_parents[] __initconst = {
  109. "clk_null",
  110. "clk_null",
  111. "univpll_d3",
  112. "univpll_d2",
  113. "clk26m_ck",
  114. "mainpll_d4",
  115. "univpll_d24",
  116. "mmpll380m"
  117. };
  118. static const char * const msdc0_parents[] __initconst = {
  119. "clk26m_ck",
  120. "univpll_d6",
  121. "mainpll_d8",
  122. "univpll_d8",
  123. "mainpll_d16",
  124. "mmpll_200m",
  125. "mainpll_d12",
  126. "mmpll_d2"
  127. };
  128. static const char * const camtg_mm_parents[] __initconst = {
  129. "clk_null",
  130. "clk26m_ck",
  131. "usb_phy48m_ck",
  132. "clk_null",
  133. "univpll_d6"
  134. };
  135. static const char * const pwm_mm_parents[] __initconst = {
  136. "clk26m_ck",
  137. "univpll_d12"
  138. };
  139. static const char * const uart1_parents[] __initconst = {
  140. "clk26m_ck",
  141. "univpll_d24"
  142. };
  143. static const char * const msdc1_parents[] __initconst = {
  144. "clk26m_ck",
  145. "univpll_d6",
  146. "mainpll_d8",
  147. "univpll_d8",
  148. "mainpll_d16",
  149. "mmpll_200m",
  150. "mainpll_d12",
  151. "mmpll_d2"
  152. };
  153. static const char * const spm_52m_parents[] __initconst = {
  154. "clk26m_ck",
  155. "univpll_d24"
  156. };
  157. static const char * const pmicspi_parents[] __initconst = {
  158. "univpll_d20",
  159. "usb_phy48m_ck",
  160. "univpll_d16",
  161. "clk26m_ck"
  162. };
  163. static const char * const qaxi_aud26m_parents[] __initconst = {
  164. "clk26m_ck",
  165. "ahb_infra_sel"
  166. };
  167. static const char * const aud_intbus_parents[] __initconst = {
  168. "clk_null",
  169. "clk26m_ck",
  170. "mainpll_d22",
  171. "clk_null",
  172. "mainpll_d11"
  173. };
  174. static const char * const nfi2x_pad_parents[] __initconst = {
  175. "clk_null",
  176. "clk_null",
  177. "clk_null",
  178. "clk_null",
  179. "clk_null",
  180. "clk_null",
  181. "clk_null",
  182. "clk_null",
  183. "clk26m_ck",
  184. "clk_null",
  185. "clk_null",
  186. "clk_null",
  187. "clk_null",
  188. "clk_null",
  189. "clk_null",
  190. "clk_null",
  191. "clk_null",
  192. "mainpll_d12",
  193. "mainpll_d8",
  194. "clk_null",
  195. "mainpll_d6",
  196. "clk_null",
  197. "clk_null",
  198. "clk_null",
  199. "clk_null",
  200. "clk_null",
  201. "clk_null",
  202. "clk_null",
  203. "clk_null",
  204. "clk_null",
  205. "clk_null",
  206. "clk_null",
  207. "mainpll_d4",
  208. "clk_null",
  209. "clk_null",
  210. "clk_null",
  211. "clk_null",
  212. "clk_null",
  213. "clk_null",
  214. "clk_null",
  215. "clk_null",
  216. "clk_null",
  217. "clk_null",
  218. "clk_null",
  219. "clk_null",
  220. "clk_null",
  221. "clk_null",
  222. "clk_null",
  223. "clk_null",
  224. "clk_null",
  225. "clk_null",
  226. "clk_null",
  227. "clk_null",
  228. "clk_null",
  229. "clk_null",
  230. "clk_null",
  231. "clk_null",
  232. "clk_null",
  233. "clk_null",
  234. "clk_null",
  235. "clk_null",
  236. "clk_null",
  237. "clk_null",
  238. "clk_null",
  239. "clk_null",
  240. "clk_null",
  241. "clk_null",
  242. "clk_null",
  243. "clk_null",
  244. "clk_null",
  245. "clk_null",
  246. "clk_null",
  247. "clk_null",
  248. "clk_null",
  249. "clk_null",
  250. "clk_null",
  251. "clk_null",
  252. "clk_null",
  253. "clk_null",
  254. "clk_null",
  255. "clk_null",
  256. "mainpll_d10",
  257. "mainpll_d7",
  258. "clk_null",
  259. "mainpll_d5"
  260. };
  261. static const char * const nfi1x_pad_parents[] __initconst = {
  262. "ahb_infra_sel",
  263. "nfi1x_ck"
  264. };
  265. static const char * const mfg_mm_parents[] __initconst = {
  266. "clk_null",
  267. "clk_null",
  268. "clk_null",
  269. "clk_null",
  270. "clk_null",
  271. "clk_null",
  272. "clk_null",
  273. "clk_null",
  274. "csw_mux_mfg_sel",
  275. "clk_null",
  276. "clk_null",
  277. "clk_null",
  278. "clk_null",
  279. "clk_null",
  280. "clk_null",
  281. "clk_null",
  282. "mainpll_d3",
  283. "clk_null",
  284. "clk_null",
  285. "clk_null",
  286. "clk_null",
  287. "clk_null",
  288. "clk_null",
  289. "clk_null",
  290. "clk_null",
  291. "clk_null",
  292. "clk_null",
  293. "clk_null",
  294. "clk_null",
  295. "clk_null",
  296. "clk_null",
  297. "clk_null",
  298. "clk_null",
  299. "mainpll_d5",
  300. "mainpll_d7",
  301. "clk_null",
  302. "mainpll_d14"
  303. };
  304. static const char * const ddrphycfg_parents[] __initconst = {
  305. "clk26m_ck",
  306. "mainpll_d16"
  307. };
  308. static const char * const smi_mm_parents[] __initconst = {
  309. "clk26m_ck",
  310. "clk_null",
  311. "clk_null",
  312. "clk_null",
  313. "clk_null",
  314. "clk_null",
  315. "clk_null",
  316. "clk_null",
  317. "clk_null",
  318. "univpll_d4",
  319. "mainpll_d7",
  320. "clk_null",
  321. "mainpll_d14"
  322. };
  323. static const char * const usb_78m_parents[] __initconst = {
  324. "clk_null",
  325. "clk26m_ck",
  326. "univpll_d16",
  327. "clk_null",
  328. "mainpll_d20"
  329. };
  330. static const char * const scam_mm_parents[] __initconst = {
  331. "clk_null",
  332. "clk26m_ck",
  333. "mainpll_d14",
  334. "clk_null",
  335. "mainpll_d12"
  336. };
  337. static const char * const spinor_parents[] __initconst = {
  338. "clk26m_d2",
  339. "clk26m_ck",
  340. "mainpll_d40",
  341. "univpll_d24",
  342. "univpll_d20",
  343. "mainpll_d20",
  344. "mainpll_d16",
  345. "univpll_d12"
  346. };
  347. static const char * const msdc2_parents[] __initconst = {
  348. "clk26m_ck",
  349. "univpll_d6",
  350. "mainpll_d8",
  351. "univpll_d8",
  352. "mainpll_d16",
  353. "mmpll_200m",
  354. "mainpll_d12",
  355. "mmpll_d2"
  356. };
  357. static const char * const eth_parents[] __initconst = {
  358. "clk26m_ck",
  359. "mainpll_d40",
  360. "univpll_d24",
  361. "univpll_d20",
  362. "mainpll_d20"
  363. };
  364. static const char * const vdec_mm_parents[] __initconst = {
  365. "clk26m_ck",
  366. "univpll_d4",
  367. "mainpll_d4",
  368. "univpll_d5",
  369. "univpll_d6",
  370. "mainpll_d6"
  371. };
  372. static const char * const dpi0_mm_parents[] __initconst = {
  373. "clk26m_ck",
  374. "lvdspll_ck",
  375. "lvdspll_d2",
  376. "lvdspll_d4",
  377. "lvdspll_d8"
  378. };
  379. static const char * const dpi1_mm_parents[] __initconst = {
  380. "clk26m_ck",
  381. "tvdpll_d2",
  382. "tvdpll_d4",
  383. "tvdpll_d8",
  384. "tvdpll_d16"
  385. };
  386. static const char * const axi_mfg_in_parents[] __initconst = {
  387. "clk26m_ck",
  388. "mainpll_d11",
  389. "univpll_d24",
  390. "mmpll380m"
  391. };
  392. static const char * const slow_mfg_parents[] __initconst = {
  393. "clk26m_ck",
  394. "univpll_d12",
  395. "univpll_d24"
  396. };
  397. static const char * const aud1_parents[] __initconst = {
  398. "clk26m_ck",
  399. "apll1_ck"
  400. };
  401. static const char * const aud2_parents[] __initconst = {
  402. "clk26m_ck",
  403. "apll2_ck"
  404. };
  405. static const char * const aud_engen1_parents[] __initconst = {
  406. "clk26m_ck",
  407. "rg_apll1_d2_en",
  408. "rg_apll1_d4_en",
  409. "rg_apll1_d8_en"
  410. };
  411. static const char * const aud_engen2_parents[] __initconst = {
  412. "clk26m_ck",
  413. "rg_apll2_d2_en",
  414. "rg_apll2_d4_en",
  415. "rg_apll2_d8_en"
  416. };
  417. static const char * const i2c_parents[] __initconst = {
  418. "clk26m_ck",
  419. "univpll_d20",
  420. "univpll_d16",
  421. "univpll_d12"
  422. };
  423. static const char * const aud_i2s0_m_parents[] __initconst = {
  424. "rg_aud1",
  425. "rg_aud2"
  426. };
  427. static const char * const pwm_parents[] __initconst = {
  428. "clk26m_ck",
  429. "univpll_d12"
  430. };
  431. static const char * const spi_parents[] __initconst = {
  432. "clk26m_ck",
  433. "univpll_d12",
  434. "univpll_d8",
  435. "univpll_d6"
  436. };
  437. static const char * const aud_spdifin_parents[] __initconst = {
  438. "clk26m_ck",
  439. "univpll_d2"
  440. };
  441. static const char * const uart2_parents[] __initconst = {
  442. "clk26m_ck",
  443. "univpll_d24"
  444. };
  445. static const char * const bsi_parents[] __initconst = {
  446. "clk26m_ck",
  447. "mainpll_d10",
  448. "mainpll_d12",
  449. "mainpll_d20"
  450. };
  451. static const char * const dbg_atclk_parents[] __initconst = {
  452. "clk_null",
  453. "clk26m_ck",
  454. "mainpll_d5",
  455. "clk_null",
  456. "univpll_d5"
  457. };
  458. static const char * const csw_nfiecc_parents[] __initconst = {
  459. "clk_null",
  460. "mainpll_d7",
  461. "mainpll_d6",
  462. "clk_null",
  463. "mainpll_d5"
  464. };
  465. static const char * const nfiecc_parents[] __initconst = {
  466. "clk_null",
  467. "nfi2x_pad_sel",
  468. "mainpll_d4",
  469. "clk_null",
  470. "csw_nfiecc_sel"
  471. };
  472. static struct mtk_composite top_muxes[] __initdata = {
  473. /* CLK_MUX_SEL0 */
  474. MUX(CLK_TOP_UART0_SEL, "uart0_sel", uart0_parents,
  475. 0x000, 0, 1),
  476. MUX(CLK_TOP_GFMUX_EMI1X_SEL, "gfmux_emi1x_sel", gfmux_emi1x_parents,
  477. 0x000, 1, 1),
  478. MUX(CLK_TOP_EMI_DDRPHY_SEL, "emi_ddrphy_sel", emi_ddrphy_parents,
  479. 0x000, 2, 1),
  480. MUX(CLK_TOP_AHB_INFRA_SEL, "ahb_infra_sel", ahb_infra_parents,
  481. 0x000, 4, 4),
  482. MUX(CLK_TOP_CSW_MUX_MFG_SEL, "csw_mux_mfg_sel", csw_mux_mfg_parents,
  483. 0x000, 8, 3),
  484. MUX(CLK_TOP_MSDC0_SEL, "msdc0_sel", msdc0_parents,
  485. 0x000, 11, 3),
  486. MUX(CLK_TOP_CAMTG_MM_SEL, "camtg_mm_sel", camtg_mm_parents,
  487. 0x000, 15, 3),
  488. MUX(CLK_TOP_PWM_MM_SEL, "pwm_mm_sel", pwm_mm_parents,
  489. 0x000, 18, 1),
  490. MUX(CLK_TOP_UART1_SEL, "uart1_sel", uart1_parents,
  491. 0x000, 19, 1),
  492. MUX(CLK_TOP_MSDC1_SEL, "msdc1_sel", msdc1_parents,
  493. 0x000, 20, 3),
  494. MUX(CLK_TOP_SPM_52M_SEL, "spm_52m_sel", spm_52m_parents,
  495. 0x000, 23, 1),
  496. MUX(CLK_TOP_PMICSPI_SEL, "pmicspi_sel", pmicspi_parents,
  497. 0x000, 24, 2),
  498. MUX(CLK_TOP_QAXI_AUD26M_SEL, "qaxi_aud26m_sel", qaxi_aud26m_parents,
  499. 0x000, 26, 1),
  500. MUX(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel", aud_intbus_parents,
  501. 0x000, 27, 3),
  502. /* CLK_MUX_SEL1 */
  503. MUX(CLK_TOP_NFI2X_PAD_SEL, "nfi2x_pad_sel", nfi2x_pad_parents,
  504. 0x004, 0, 7),
  505. MUX(CLK_TOP_NFI1X_PAD_SEL, "nfi1x_pad_sel", nfi1x_pad_parents,
  506. 0x004, 7, 1),
  507. MUX(CLK_TOP_MFG_MM_SEL, "mfg_mm_sel", mfg_mm_parents,
  508. 0x004, 8, 6),
  509. MUX(CLK_TOP_DDRPHYCFG_SEL, "ddrphycfg_sel", ddrphycfg_parents,
  510. 0x004, 15, 1),
  511. MUX(CLK_TOP_SMI_MM_SEL, "smi_mm_sel", smi_mm_parents,
  512. 0x004, 16, 4),
  513. MUX(CLK_TOP_USB_78M_SEL, "usb_78m_sel", usb_78m_parents,
  514. 0x004, 20, 3),
  515. MUX(CLK_TOP_SCAM_MM_SEL, "scam_mm_sel", scam_mm_parents,
  516. 0x004, 23, 3),
  517. /* CLK_MUX_SEL8 */
  518. MUX(CLK_TOP_SPINOR_SEL, "spinor_sel", spinor_parents,
  519. 0x040, 0, 3),
  520. MUX(CLK_TOP_MSDC2_SEL, "msdc2_sel", msdc2_parents,
  521. 0x040, 3, 3),
  522. MUX(CLK_TOP_ETH_SEL, "eth_sel", eth_parents,
  523. 0x040, 6, 3),
  524. MUX(CLK_TOP_VDEC_MM_SEL, "vdec_mm_sel", vdec_mm_parents,
  525. 0x040, 9, 3),
  526. MUX(CLK_TOP_DPI0_MM_SEL, "dpi0_mm_sel", dpi0_mm_parents,
  527. 0x040, 12, 3),
  528. MUX(CLK_TOP_DPI1_MM_SEL, "dpi1_mm_sel", dpi1_mm_parents,
  529. 0x040, 15, 3),
  530. MUX(CLK_TOP_AXI_MFG_IN_SEL, "axi_mfg_in_sel", axi_mfg_in_parents,
  531. 0x040, 18, 2),
  532. MUX(CLK_TOP_SLOW_MFG_SEL, "slow_mfg_sel", slow_mfg_parents,
  533. 0x040, 20, 2),
  534. MUX(CLK_TOP_AUD1_SEL, "aud1_sel", aud1_parents,
  535. 0x040, 22, 1),
  536. MUX(CLK_TOP_AUD2_SEL, "aud2_sel", aud2_parents,
  537. 0x040, 23, 1),
  538. MUX(CLK_TOP_AUD_ENGEN1_SEL, "aud_engen1_sel", aud_engen1_parents,
  539. 0x040, 24, 2),
  540. MUX(CLK_TOP_AUD_ENGEN2_SEL, "aud_engen2_sel", aud_engen2_parents,
  541. 0x040, 26, 2),
  542. MUX(CLK_TOP_I2C_SEL, "i2c_sel", i2c_parents,
  543. 0x040, 28, 2),
  544. /* CLK_SEL_9 */
  545. MUX(CLK_TOP_AUD_I2S0_M_SEL, "aud_i2s0_m_sel", aud_i2s0_m_parents,
  546. 0x044, 12, 1),
  547. MUX(CLK_TOP_AUD_I2S1_M_SEL, "aud_i2s1_m_sel", aud_i2s0_m_parents,
  548. 0x044, 13, 1),
  549. MUX(CLK_TOP_AUD_I2S2_M_SEL, "aud_i2s2_m_sel", aud_i2s0_m_parents,
  550. 0x044, 14, 1),
  551. MUX(CLK_TOP_AUD_I2S3_M_SEL, "aud_i2s3_m_sel", aud_i2s0_m_parents,
  552. 0x044, 15, 1),
  553. MUX(CLK_TOP_AUD_I2S4_M_SEL, "aud_i2s4_m_sel", aud_i2s0_m_parents,
  554. 0x044, 16, 1),
  555. MUX(CLK_TOP_AUD_I2S5_M_SEL, "aud_i2s5_m_sel", aud_i2s0_m_parents,
  556. 0x044, 17, 1),
  557. MUX(CLK_TOP_AUD_SPDIF_B_SEL, "aud_spdif_b_sel", aud_i2s0_m_parents,
  558. 0x044, 18, 1),
  559. /* CLK_MUX_SEL13 */
  560. MUX(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents,
  561. 0x07c, 0, 1),
  562. MUX(CLK_TOP_SPI_SEL, "spi_sel", spi_parents,
  563. 0x07c, 1, 2),
  564. MUX(CLK_TOP_AUD_SPDIFIN_SEL, "aud_spdifin_sel", aud_spdifin_parents,
  565. 0x07c, 3, 1),
  566. MUX(CLK_TOP_UART2_SEL, "uart2_sel", uart2_parents,
  567. 0x07c, 4, 1),
  568. MUX(CLK_TOP_BSI_SEL, "bsi_sel", bsi_parents,
  569. 0x07c, 5, 2),
  570. MUX(CLK_TOP_DBG_ATCLK_SEL, "dbg_atclk_sel", dbg_atclk_parents,
  571. 0x07c, 7, 3),
  572. MUX(CLK_TOP_CSW_NFIECC_SEL, "csw_nfiecc_sel", csw_nfiecc_parents,
  573. 0x07c, 10, 3),
  574. MUX(CLK_TOP_NFIECC_SEL, "nfiecc_sel", nfiecc_parents,
  575. 0x07c, 13, 3),
  576. };
  577. static const char * const ifr_mux1_parents[] __initconst = {
  578. "clk26m_ck",
  579. "armpll",
  580. "univpll",
  581. "mainpll_d2"
  582. };
  583. static const char * const ifr_eth_25m_parents[] __initconst = {
  584. "eth_d2_ck",
  585. "rg_eth"
  586. };
  587. static const char * const ifr_i2c0_parents[] __initconst = {
  588. "ahb_infra_d2",
  589. "rg_i2c"
  590. };
  591. static const struct mtk_composite ifr_muxes[] __initconst = {
  592. MUX(CLK_IFR_MUX1_SEL, "ifr_mux1_sel", ifr_mux1_parents, 0x000,
  593. 2, 2),
  594. MUX(CLK_IFR_ETH_25M_SEL, "ifr_eth_25m_sel", ifr_eth_25m_parents, 0x080,
  595. 0, 1),
  596. MUX(CLK_IFR_I2C0_SEL, "ifr_i2c0_sel", ifr_i2c0_parents, 0x080,
  597. 1, 1),
  598. MUX(CLK_IFR_I2C1_SEL, "ifr_i2c1_sel", ifr_i2c0_parents, 0x080,
  599. 2, 1),
  600. MUX(CLK_IFR_I2C2_SEL, "ifr_i2c2_sel", ifr_i2c0_parents, 0x080,
  601. 3, 1),
  602. };
  603. #define DIV_ADJ(_id, _name, _parent, _reg, _shift, _width) { \
  604. .id = _id, \
  605. .name = _name, \
  606. .parent_name = _parent, \
  607. .div_reg = _reg, \
  608. .div_shift = _shift, \
  609. .div_width = _width, \
  610. }
  611. static const struct mtk_clk_divider top_adj_divs[] = {
  612. DIV_ADJ(CLK_TOP_APLL12_CK_DIV0, "apll12_ck_div0", "aud_i2s0_m_sel",
  613. 0x0048, 0, 8),
  614. DIV_ADJ(CLK_TOP_APLL12_CK_DIV1, "apll12_ck_div1", "aud_i2s1_m_sel",
  615. 0x0048, 8, 8),
  616. DIV_ADJ(CLK_TOP_APLL12_CK_DIV2, "apll12_ck_div2", "aud_i2s2_m_sel",
  617. 0x0048, 16, 8),
  618. DIV_ADJ(CLK_TOP_APLL12_CK_DIV3, "apll12_ck_div3", "aud_i2s3_m_sel",
  619. 0x0048, 24, 8),
  620. DIV_ADJ(CLK_TOP_APLL12_CK_DIV4, "apll12_ck_div4", "aud_i2s4_m_sel",
  621. 0x004c, 0, 8),
  622. DIV_ADJ(CLK_TOP_APLL12_CK_DIV4B, "apll12_ck_div4b", "apll12_div4",
  623. 0x004c, 8, 8),
  624. DIV_ADJ(CLK_TOP_APLL12_CK_DIV5, "apll12_ck_div5", "aud_i2s5_m_sel",
  625. 0x004c, 16, 8),
  626. DIV_ADJ(CLK_TOP_APLL12_CK_DIV5B, "apll12_ck_div5b", "apll12_div5",
  627. 0x004c, 24, 8),
  628. DIV_ADJ(CLK_TOP_APLL12_CK_DIV6, "apll12_ck_div6", "aud_spdif_b_sel",
  629. 0x0078, 0, 8),
  630. };
  631. #define DIV_ADJ_FLAG(_id, _name, _parent, _reg, _shift, _width, _flag) { \
  632. .id = _id, \
  633. .name = _name, \
  634. .parent_name = _parent, \
  635. .div_reg = _reg, \
  636. .div_shift = _shift, \
  637. .div_width = _width, \
  638. .clk_divider_flags = _flag, \
  639. }
  640. static const struct mtk_clk_divider apmixed_adj_divs[] = {
  641. DIV_ADJ_FLAG(CLK_APMIXED_HDMI_REF, "hdmi_ref", "tvdpll",
  642. 0x1c4, 24, 3, CLK_DIVIDER_POWER_OF_TWO),
  643. };
  644. static const struct mtk_gate_regs top0_cg_regs = {
  645. .set_ofs = 0x50,
  646. .clr_ofs = 0x80,
  647. .sta_ofs = 0x20,
  648. };
  649. static const struct mtk_gate_regs top1_cg_regs = {
  650. .set_ofs = 0x54,
  651. .clr_ofs = 0x84,
  652. .sta_ofs = 0x24,
  653. };
  654. static const struct mtk_gate_regs top2_cg_regs = {
  655. .set_ofs = 0x6c,
  656. .clr_ofs = 0x9c,
  657. .sta_ofs = 0x3c,
  658. };
  659. static const struct mtk_gate_regs top3_cg_regs = {
  660. .set_ofs = 0xa0,
  661. .clr_ofs = 0xb0,
  662. .sta_ofs = 0x70,
  663. };
  664. static const struct mtk_gate_regs top4_cg_regs = {
  665. .set_ofs = 0xa4,
  666. .clr_ofs = 0xb4,
  667. .sta_ofs = 0x74,
  668. };
  669. static const struct mtk_gate_regs top5_cg_regs = {
  670. .set_ofs = 0x44,
  671. .clr_ofs = 0x44,
  672. .sta_ofs = 0x44,
  673. };
  674. #define GATE_TOP0(_id, _name, _parent, _shift) { \
  675. .id = _id, \
  676. .name = _name, \
  677. .parent_name = _parent, \
  678. .regs = &top0_cg_regs, \
  679. .shift = _shift, \
  680. .ops = &mtk_clk_gate_ops_setclr, \
  681. }
  682. #define GATE_TOP0_I(_id, _name, _parent, _shift) { \
  683. .id = _id, \
  684. .name = _name, \
  685. .parent_name = _parent, \
  686. .regs = &top0_cg_regs, \
  687. .shift = _shift, \
  688. .ops = &mtk_clk_gate_ops_setclr_inv, \
  689. }
  690. #define GATE_TOP1(_id, _name, _parent, _shift) { \
  691. .id = _id, \
  692. .name = _name, \
  693. .parent_name = _parent, \
  694. .regs = &top1_cg_regs, \
  695. .shift = _shift, \
  696. .ops = &mtk_clk_gate_ops_setclr, \
  697. }
  698. #define GATE_TOP2(_id, _name, _parent, _shift) { \
  699. .id = _id, \
  700. .name = _name, \
  701. .parent_name = _parent, \
  702. .regs = &top2_cg_regs, \
  703. .shift = _shift, \
  704. .ops = &mtk_clk_gate_ops_setclr, \
  705. }
  706. #define GATE_TOP2_I(_id, _name, _parent, _shift) { \
  707. .id = _id, \
  708. .name = _name, \
  709. .parent_name = _parent, \
  710. .regs = &top2_cg_regs, \
  711. .shift = _shift, \
  712. .ops = &mtk_clk_gate_ops_setclr_inv, \
  713. }
  714. #define GATE_TOP3(_id, _name, _parent, _shift) { \
  715. .id = _id, \
  716. .name = _name, \
  717. .parent_name = _parent, \
  718. .regs = &top3_cg_regs, \
  719. .shift = _shift, \
  720. .ops = &mtk_clk_gate_ops_setclr, \
  721. }
  722. #define GATE_TOP4_I(_id, _name, _parent, _shift) { \
  723. .id = _id, \
  724. .name = _name, \
  725. .parent_name = _parent, \
  726. .regs = &top4_cg_regs, \
  727. .shift = _shift, \
  728. .ops = &mtk_clk_gate_ops_setclr_inv, \
  729. }
  730. #define GATE_TOP5(_id, _name, _parent, _shift) { \
  731. .id = _id, \
  732. .name = _name, \
  733. .parent_name = _parent, \
  734. .regs = &top5_cg_regs, \
  735. .shift = _shift, \
  736. .ops = &mtk_clk_gate_ops_no_setclr, \
  737. }
  738. static const struct mtk_gate top_clks[] __initconst = {
  739. /* TOP0 */
  740. GATE_TOP0(CLK_TOP_PWM_MM, "pwm_mm", "pwm_mm_sel", 0),
  741. GATE_TOP0(CLK_TOP_CAM_MM, "cam_mm", "camtg_mm_sel", 1),
  742. GATE_TOP0(CLK_TOP_MFG_MM, "mfg_mm", "mfg_mm_sel", 2),
  743. GATE_TOP0(CLK_TOP_SPM_52M, "spm_52m", "spm_52m_sel", 3),
  744. GATE_TOP0_I(CLK_TOP_MIPI_26M_DBG, "mipi_26m_dbg", "mipi_26m", 4),
  745. GATE_TOP0(CLK_TOP_SCAM_MM, "scam_mm", "scam_mm_sel", 5),
  746. GATE_TOP0(CLK_TOP_SMI_MM, "smi_mm", "smi_mm_sel", 9),
  747. /* TOP1 */
  748. GATE_TOP1(CLK_TOP_THEM, "them", "ahb_infra_sel", 1),
  749. GATE_TOP1(CLK_TOP_APDMA, "apdma", "ahb_infra_sel", 2),
  750. GATE_TOP1(CLK_TOP_I2C0, "i2c0", "ifr_i2c0_sel", 3),
  751. GATE_TOP1(CLK_TOP_I2C1, "i2c1", "ifr_i2c1_sel", 4),
  752. GATE_TOP1(CLK_TOP_AUXADC1, "auxadc1", "ahb_infra_sel", 5),
  753. GATE_TOP1(CLK_TOP_NFI, "nfi", "nfi1x_pad_sel", 6),
  754. GATE_TOP1(CLK_TOP_NFIECC, "nfiecc", "rg_nfiecc", 7),
  755. GATE_TOP1(CLK_TOP_DEBUGSYS, "debugsys", "rg_dbg_atclk", 8),
  756. GATE_TOP1(CLK_TOP_PWM, "pwm", "ahb_infra_sel", 9),
  757. GATE_TOP1(CLK_TOP_UART0, "uart0", "uart0_sel", 10),
  758. GATE_TOP1(CLK_TOP_UART1, "uart1", "uart1_sel", 11),
  759. GATE_TOP1(CLK_TOP_BTIF, "btif", "ahb_infra_sel", 12),
  760. GATE_TOP1(CLK_TOP_USB, "usb", "usb_78m", 13),
  761. GATE_TOP1(CLK_TOP_FLASHIF_26M, "flashif_26m", "clk26m_ck", 14),
  762. GATE_TOP1(CLK_TOP_AUXADC2, "auxadc2", "ahb_infra_sel", 15),
  763. GATE_TOP1(CLK_TOP_I2C2, "i2c2", "ifr_i2c2_sel", 16),
  764. GATE_TOP1(CLK_TOP_MSDC0, "msdc0", "msdc0_sel", 17),
  765. GATE_TOP1(CLK_TOP_MSDC1, "msdc1", "msdc1_sel", 18),
  766. GATE_TOP1(CLK_TOP_NFI2X, "nfi2x", "nfi2x_pad_sel", 19),
  767. GATE_TOP1(CLK_TOP_PMICWRAP_AP, "pwrap_ap", "clk26m_ck", 20),
  768. GATE_TOP1(CLK_TOP_SEJ, "sej", "ahb_infra_sel", 21),
  769. GATE_TOP1(CLK_TOP_MEMSLP_DLYER, "memslp_dlyer", "clk26m_ck", 22),
  770. GATE_TOP1(CLK_TOP_SPI, "spi", "spi_sel", 23),
  771. GATE_TOP1(CLK_TOP_APXGPT, "apxgpt", "clk26m_ck", 24),
  772. GATE_TOP1(CLK_TOP_AUDIO, "audio", "clk26m_ck", 25),
  773. GATE_TOP1(CLK_TOP_PMICWRAP_MD, "pwrap_md", "clk26m_ck", 27),
  774. GATE_TOP1(CLK_TOP_PMICWRAP_CONN, "pwrap_conn", "clk26m_ck", 28),
  775. GATE_TOP1(CLK_TOP_PMICWRAP_26M, "pwrap_26m", "clk26m_ck", 29),
  776. GATE_TOP1(CLK_TOP_AUX_ADC, "aux_adc", "clk26m_ck", 30),
  777. GATE_TOP1(CLK_TOP_AUX_TP, "aux_tp", "clk26m_ck", 31),
  778. /* TOP2 */
  779. GATE_TOP2(CLK_TOP_MSDC2, "msdc2", "ahb_infra_sel", 0),
  780. GATE_TOP2(CLK_TOP_RBIST, "rbist", "univpll_d12", 1),
  781. GATE_TOP2(CLK_TOP_NFI_BUS, "nfi_bus", "ahb_infra_sel", 2),
  782. GATE_TOP2(CLK_TOP_GCE, "gce", "ahb_infra_sel", 4),
  783. GATE_TOP2(CLK_TOP_TRNG, "trng", "ahb_infra_sel", 5),
  784. GATE_TOP2(CLK_TOP_SEJ_13M, "sej_13m", "clk26m_ck", 6),
  785. GATE_TOP2(CLK_TOP_AES, "aes", "ahb_infra_sel", 7),
  786. GATE_TOP2(CLK_TOP_PWM_B, "pwm_b", "rg_pwm_infra", 8),
  787. GATE_TOP2(CLK_TOP_PWM1_FB, "pwm1_fb", "rg_pwm_infra", 9),
  788. GATE_TOP2(CLK_TOP_PWM2_FB, "pwm2_fb", "rg_pwm_infra", 10),
  789. GATE_TOP2(CLK_TOP_PWM3_FB, "pwm3_fb", "rg_pwm_infra", 11),
  790. GATE_TOP2(CLK_TOP_PWM4_FB, "pwm4_fb", "rg_pwm_infra", 12),
  791. GATE_TOP2(CLK_TOP_PWM5_FB, "pwm5_fb", "rg_pwm_infra", 13),
  792. GATE_TOP2(CLK_TOP_USB_1P, "usb_1p", "usb_78m", 14),
  793. GATE_TOP2(CLK_TOP_FLASHIF_FREERUN, "flashif_freerun", "ahb_infra_sel",
  794. 15),
  795. GATE_TOP2(CLK_TOP_26M_HDMI_SIFM, "hdmi_sifm_26m", "clk26m_ck", 16),
  796. GATE_TOP2(CLK_TOP_26M_CEC, "cec_26m", "clk26m_ck", 17),
  797. GATE_TOP2(CLK_TOP_32K_CEC, "cec_32k", "clk32k", 18),
  798. GATE_TOP2(CLK_TOP_66M_ETH, "eth_66m", "ahb_infra_d2", 19),
  799. GATE_TOP2(CLK_TOP_133M_ETH, "eth_133m", "ahb_infra_sel", 20),
  800. GATE_TOP2(CLK_TOP_FETH_25M, "feth_25m", "ifr_eth_25m_sel", 21),
  801. GATE_TOP2(CLK_TOP_FETH_50M, "feth_50m", "rg_eth", 22),
  802. GATE_TOP2(CLK_TOP_FLASHIF_AXI, "flashif_axi", "ahb_infra_sel", 23),
  803. GATE_TOP2(CLK_TOP_USBIF, "usbif", "ahb_infra_sel", 24),
  804. GATE_TOP2(CLK_TOP_UART2, "uart2", "rg_uart2", 25),
  805. GATE_TOP2(CLK_TOP_BSI, "bsi", "ahb_infra_sel", 26),
  806. GATE_TOP2(CLK_TOP_GCPU_B, "gcpu_b", "ahb_infra_sel", 27),
  807. GATE_TOP2_I(CLK_TOP_MSDC0_INFRA, "msdc0_infra", "msdc0", 28),
  808. GATE_TOP2_I(CLK_TOP_MSDC1_INFRA, "msdc1_infra", "msdc1", 29),
  809. GATE_TOP2_I(CLK_TOP_MSDC2_INFRA, "msdc2_infra", "rg_msdc2", 30),
  810. GATE_TOP2(CLK_TOP_USB_78M, "usb_78m", "usb_78m_sel", 31),
  811. /* TOP3 */
  812. GATE_TOP3(CLK_TOP_RG_SPINOR, "rg_spinor", "spinor_sel", 0),
  813. GATE_TOP3(CLK_TOP_RG_MSDC2, "rg_msdc2", "msdc2_sel", 1),
  814. GATE_TOP3(CLK_TOP_RG_ETH, "rg_eth", "eth_sel", 2),
  815. GATE_TOP3(CLK_TOP_RG_VDEC, "rg_vdec", "vdec_mm_sel", 3),
  816. GATE_TOP3(CLK_TOP_RG_FDPI0, "rg_fdpi0", "dpi0_mm_sel", 4),
  817. GATE_TOP3(CLK_TOP_RG_FDPI1, "rg_fdpi1", "dpi1_mm_sel", 5),
  818. GATE_TOP3(CLK_TOP_RG_AXI_MFG, "rg_axi_mfg", "axi_mfg_in_sel", 6),
  819. GATE_TOP3(CLK_TOP_RG_SLOW_MFG, "rg_slow_mfg", "slow_mfg_sel", 7),
  820. GATE_TOP3(CLK_TOP_RG_AUD1, "rg_aud1", "aud1_sel", 8),
  821. GATE_TOP3(CLK_TOP_RG_AUD2, "rg_aud2", "aud2_sel", 9),
  822. GATE_TOP3(CLK_TOP_RG_AUD_ENGEN1, "rg_aud_engen1", "aud_engen1_sel", 10),
  823. GATE_TOP3(CLK_TOP_RG_AUD_ENGEN2, "rg_aud_engen2", "aud_engen2_sel", 11),
  824. GATE_TOP3(CLK_TOP_RG_I2C, "rg_i2c", "i2c_sel", 12),
  825. GATE_TOP3(CLK_TOP_RG_PWM_INFRA, "rg_pwm_infra", "pwm_sel", 13),
  826. GATE_TOP3(CLK_TOP_RG_AUD_SPDIF_IN, "rg_aud_spdif_in", "aud_spdifin_sel",
  827. 14),
  828. GATE_TOP3(CLK_TOP_RG_UART2, "rg_uart2", "uart2_sel", 15),
  829. GATE_TOP3(CLK_TOP_RG_BSI, "rg_bsi", "bsi_sel", 16),
  830. GATE_TOP3(CLK_TOP_RG_DBG_ATCLK, "rg_dbg_atclk", "dbg_atclk_sel", 17),
  831. GATE_TOP3(CLK_TOP_RG_NFIECC, "rg_nfiecc", "nfiecc_sel", 18),
  832. /* TOP4 */
  833. GATE_TOP4_I(CLK_TOP_RG_APLL1_D2_EN, "rg_apll1_d2_en", "apll1_d2", 8),
  834. GATE_TOP4_I(CLK_TOP_RG_APLL1_D4_EN, "rg_apll1_d4_en", "apll1_d4", 9),
  835. GATE_TOP4_I(CLK_TOP_RG_APLL1_D8_EN, "rg_apll1_d8_en", "apll1_d8", 10),
  836. GATE_TOP4_I(CLK_TOP_RG_APLL2_D2_EN, "rg_apll2_d2_en", "apll2_d2", 11),
  837. GATE_TOP4_I(CLK_TOP_RG_APLL2_D4_EN, "rg_apll2_d4_en", "apll2_d4", 12),
  838. GATE_TOP4_I(CLK_TOP_RG_APLL2_D8_EN, "rg_apll2_d8_en", "apll2_d8", 13),
  839. /* TOP5 */
  840. GATE_TOP5(CLK_TOP_APLL12_DIV0, "apll12_div0", "apll12_ck_div0", 0),
  841. GATE_TOP5(CLK_TOP_APLL12_DIV1, "apll12_div1", "apll12_ck_div1", 1),
  842. GATE_TOP5(CLK_TOP_APLL12_DIV2, "apll12_div2", "apll12_ck_div2", 2),
  843. GATE_TOP5(CLK_TOP_APLL12_DIV3, "apll12_div3", "apll12_ck_div3", 3),
  844. GATE_TOP5(CLK_TOP_APLL12_DIV4, "apll12_div4", "apll12_ck_div4", 4),
  845. GATE_TOP5(CLK_TOP_APLL12_DIV4B, "apll12_div4b", "apll12_ck_div4b", 5),
  846. GATE_TOP5(CLK_TOP_APLL12_DIV5, "apll12_div5", "apll12_ck_div5", 6),
  847. GATE_TOP5(CLK_TOP_APLL12_DIV5B, "apll12_div5b", "apll12_ck_div5b", 7),
  848. GATE_TOP5(CLK_TOP_APLL12_DIV6, "apll12_div6", "apll12_ck_div6", 8),
  849. };
  850. static void __init mtk_topckgen_init(struct device_node *node)
  851. {
  852. struct clk_hw_onecell_data *clk_data;
  853. int r;
  854. void __iomem *base;
  855. base = of_iomap(node, 0);
  856. if (!base) {
  857. pr_err("%s(): ioremap failed\n", __func__);
  858. return;
  859. }
  860. clk_data = mtk_alloc_clk_data(MT8167_CLK_TOP_NR_CLK);
  861. mtk_clk_register_fixed_clks(fixed_clks, ARRAY_SIZE(fixed_clks),
  862. clk_data);
  863. mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks), clk_data);
  864. mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
  865. mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
  866. &mt8167_clk_lock, clk_data);
  867. mtk_clk_register_dividers(top_adj_divs, ARRAY_SIZE(top_adj_divs),
  868. base, &mt8167_clk_lock, clk_data);
  869. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  870. if (r)
  871. pr_err("%s(): could not register clock provider: %d\n",
  872. __func__, r);
  873. }
  874. CLK_OF_DECLARE(mtk_topckgen, "mediatek,mt8167-topckgen", mtk_topckgen_init);
  875. static void __init mtk_infracfg_init(struct device_node *node)
  876. {
  877. struct clk_hw_onecell_data *clk_data;
  878. int r;
  879. void __iomem *base;
  880. base = of_iomap(node, 0);
  881. if (!base) {
  882. pr_err("%s(): ioremap failed\n", __func__);
  883. return;
  884. }
  885. clk_data = mtk_alloc_clk_data(CLK_IFR_NR_CLK);
  886. mtk_clk_register_composites(ifr_muxes, ARRAY_SIZE(ifr_muxes), base,
  887. &mt8167_clk_lock, clk_data);
  888. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  889. if (r)
  890. pr_err("%s(): could not register clock provider: %d\n",
  891. __func__, r);
  892. }
  893. CLK_OF_DECLARE(mtk_infracfg, "mediatek,mt8167-infracfg", mtk_infracfg_init);
  894. #define MT8167_PLL_FMAX (2500UL * MHZ)
  895. #define CON0_MT8167_RST_BAR BIT(27)
  896. #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  897. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  898. _pcw_shift, _div_table) { \
  899. .id = _id, \
  900. .name = _name, \
  901. .reg = _reg, \
  902. .pwr_reg = _pwr_reg, \
  903. .en_mask = _en_mask, \
  904. .flags = _flags, \
  905. .rst_bar_mask = CON0_MT8167_RST_BAR, \
  906. .fmax = MT8167_PLL_FMAX, \
  907. .pcwbits = _pcwbits, \
  908. .pd_reg = _pd_reg, \
  909. .pd_shift = _pd_shift, \
  910. .tuner_reg = _tuner_reg, \
  911. .pcw_reg = _pcw_reg, \
  912. .pcw_shift = _pcw_shift, \
  913. .div_table = _div_table, \
  914. }
  915. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  916. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  917. _pcw_shift) \
  918. PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  919. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
  920. NULL)
  921. static const struct mtk_pll_div_table mmpll_div_table[] = {
  922. { .div = 0, .freq = MT8167_PLL_FMAX },
  923. { .div = 1, .freq = 1000000000 },
  924. { .div = 2, .freq = 604500000 },
  925. { .div = 3, .freq = 253500000 },
  926. { .div = 4, .freq = 126750000 },
  927. { } /* sentinel */
  928. };
  929. static const struct mtk_pll_data plls[] = {
  930. PLL(CLK_APMIXED_ARMPLL, "armpll", 0x0100, 0x0110, 0, 0,
  931. 21, 0x0104, 24, 0, 0x0104, 0),
  932. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0120, 0x0130, 0,
  933. HAVE_RST_BAR, 21, 0x0124, 24, 0, 0x0124, 0),
  934. PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0140, 0x0150, 0x30000000,
  935. HAVE_RST_BAR, 7, 0x0144, 24, 0, 0x0144, 0),
  936. PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x0160, 0x0170, 0, 0,
  937. 21, 0x0164, 24, 0, 0x0164, 0, mmpll_div_table),
  938. PLL(CLK_APMIXED_APLL1, "apll1", 0x0180, 0x0190, 0, 0,
  939. 31, 0x0180, 1, 0x0194, 0x0184, 0),
  940. PLL(CLK_APMIXED_APLL2, "apll2", 0x01A0, 0x01B0, 0, 0,
  941. 31, 0x01A0, 1, 0x01B4, 0x01A4, 0),
  942. PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x01C0, 0x01D0, 0, 0,
  943. 21, 0x01C4, 24, 0, 0x01C4, 0),
  944. PLL(CLK_APMIXED_LVDSPLL, "lvdspll", 0x01E0, 0x01F0, 0, 0,
  945. 21, 0x01E4, 24, 0, 0x01E4, 0),
  946. };
  947. static void __init mtk_apmixedsys_init(struct device_node *node)
  948. {
  949. struct clk_hw_onecell_data *clk_data;
  950. void __iomem *base;
  951. int r;
  952. base = of_iomap(node, 0);
  953. if (!base) {
  954. pr_err("%s(): ioremap failed\n", __func__);
  955. return;
  956. }
  957. clk_data = mtk_alloc_clk_data(MT8167_CLK_APMIXED_NR_CLK);
  958. mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  959. mtk_clk_register_dividers(apmixed_adj_divs, ARRAY_SIZE(apmixed_adj_divs),
  960. base, &mt8167_clk_lock, clk_data);
  961. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  962. if (r)
  963. pr_err("%s(): could not register clock provider: %d\n",
  964. __func__, r);
  965. }
  966. CLK_OF_DECLARE(mtk_apmixedsys, "mediatek,mt8167-apmixedsys",
  967. mtk_apmixedsys_init);