clk-mt8516.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2019 MediaTek Inc.
  4. * Author: James Liao <[email protected]>
  5. * Fabien Parent <[email protected]>
  6. */
  7. #include <linux/delay.h>
  8. #include <linux/of.h>
  9. #include <linux/of_address.h>
  10. #include <linux/slab.h>
  11. #include <linux/mfd/syscon.h>
  12. #include "clk-gate.h"
  13. #include "clk-mtk.h"
  14. #include "clk-pll.h"
  15. #include <dt-bindings/clock/mt8516-clk.h>
  16. static DEFINE_SPINLOCK(mt8516_clk_lock);
  17. static const struct mtk_fixed_clk fixed_clks[] __initconst = {
  18. FIXED_CLK(CLK_TOP_CLK_NULL, "clk_null", NULL, 0),
  19. FIXED_CLK(CLK_TOP_I2S_INFRA_BCK, "i2s_infra_bck", "clk_null", 26000000),
  20. FIXED_CLK(CLK_TOP_MEMPLL, "mempll", "clk26m", 800000000),
  21. };
  22. static const struct mtk_fixed_factor top_divs[] __initconst = {
  23. FACTOR(CLK_TOP_DMPLL, "dmpll_ck", "mempll", 1, 1),
  24. FACTOR(CLK_TOP_MAINPLL_D2, "mainpll_d2", "mainpll", 1, 2),
  25. FACTOR(CLK_TOP_MAINPLL_D4, "mainpll_d4", "mainpll", 1, 4),
  26. FACTOR(CLK_TOP_MAINPLL_D8, "mainpll_d8", "mainpll", 1, 8),
  27. FACTOR(CLK_TOP_MAINPLL_D16, "mainpll_d16", "mainpll", 1, 16),
  28. FACTOR(CLK_TOP_MAINPLL_D11, "mainpll_d11", "mainpll", 1, 11),
  29. FACTOR(CLK_TOP_MAINPLL_D22, "mainpll_d22", "mainpll", 1, 22),
  30. FACTOR(CLK_TOP_MAINPLL_D3, "mainpll_d3", "mainpll", 1, 3),
  31. FACTOR(CLK_TOP_MAINPLL_D6, "mainpll_d6", "mainpll", 1, 6),
  32. FACTOR(CLK_TOP_MAINPLL_D12, "mainpll_d12", "mainpll", 1, 12),
  33. FACTOR(CLK_TOP_MAINPLL_D5, "mainpll_d5", "mainpll", 1, 5),
  34. FACTOR(CLK_TOP_MAINPLL_D10, "mainpll_d10", "mainpll", 1, 10),
  35. FACTOR(CLK_TOP_MAINPLL_D20, "mainpll_d20", "mainpll", 1, 20),
  36. FACTOR(CLK_TOP_MAINPLL_D40, "mainpll_d40", "mainpll", 1, 40),
  37. FACTOR(CLK_TOP_MAINPLL_D7, "mainpll_d7", "mainpll", 1, 7),
  38. FACTOR(CLK_TOP_MAINPLL_D14, "mainpll_d14", "mainpll", 1, 14),
  39. FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2),
  40. FACTOR(CLK_TOP_UNIVPLL_D4, "univpll_d4", "univpll", 1, 4),
  41. FACTOR(CLK_TOP_UNIVPLL_D8, "univpll_d8", "univpll", 1, 8),
  42. FACTOR(CLK_TOP_UNIVPLL_D16, "univpll_d16", "univpll", 1, 16),
  43. FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3),
  44. FACTOR(CLK_TOP_UNIVPLL_D6, "univpll_d6", "univpll", 1, 6),
  45. FACTOR(CLK_TOP_UNIVPLL_D12, "univpll_d12", "univpll", 1, 12),
  46. FACTOR(CLK_TOP_UNIVPLL_D24, "univpll_d24", "univpll", 1, 24),
  47. FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
  48. FACTOR(CLK_TOP_UNIVPLL_D20, "univpll_d20", "univpll", 1, 20),
  49. FACTOR(CLK_TOP_MMPLL380M, "mmpll380m", "mmpll", 1, 1),
  50. FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll", 1, 2),
  51. FACTOR(CLK_TOP_MMPLL_200M, "mmpll_200m", "mmpll", 1, 3),
  52. FACTOR(CLK_TOP_USB_PHY48M, "usb_phy48m_ck", "univpll", 1, 26),
  53. FACTOR(CLK_TOP_APLL1, "apll1_ck", "apll1", 1, 1),
  54. FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1_ck", 1, 2),
  55. FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "rg_apll1_d2_en", 1, 2),
  56. FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "rg_apll1_d4_en", 1, 2),
  57. FACTOR(CLK_TOP_APLL2, "apll2_ck", "apll2", 1, 1),
  58. FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2_ck", 1, 2),
  59. FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "rg_apll2_d2_en", 1, 2),
  60. FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "rg_apll2_d4_en", 1, 2),
  61. FACTOR(CLK_TOP_CLK26M, "clk26m_ck", "clk26m", 1, 1),
  62. FACTOR(CLK_TOP_CLK26M_D2, "clk26m_d2", "clk26m", 1, 2),
  63. FACTOR(CLK_TOP_AHB_INFRA_D2, "ahb_infra_d2", "ahb_infra_sel", 1, 2),
  64. FACTOR(CLK_TOP_NFI1X, "nfi1x_ck", "nfi2x_pad_sel", 1, 2),
  65. FACTOR(CLK_TOP_ETH_D2, "eth_d2_ck", "eth_sel", 1, 2),
  66. };
  67. static const char * const uart0_parents[] __initconst = {
  68. "clk26m_ck",
  69. "univpll_d24"
  70. };
  71. static const char * const ahb_infra_parents[] __initconst = {
  72. "clk_null",
  73. "clk26m_ck",
  74. "mainpll_d11",
  75. "clk_null",
  76. "mainpll_d12",
  77. "clk_null",
  78. "clk_null",
  79. "clk_null",
  80. "clk_null",
  81. "clk_null",
  82. "clk_null",
  83. "clk_null",
  84. "mainpll_d10"
  85. };
  86. static const char * const msdc0_parents[] __initconst = {
  87. "clk26m_ck",
  88. "univpll_d6",
  89. "mainpll_d8",
  90. "univpll_d8",
  91. "mainpll_d16",
  92. "mmpll_200m",
  93. "mainpll_d12",
  94. "mmpll_d2"
  95. };
  96. static const char * const uart1_parents[] __initconst = {
  97. "clk26m_ck",
  98. "univpll_d24"
  99. };
  100. static const char * const msdc1_parents[] __initconst = {
  101. "clk26m_ck",
  102. "univpll_d6",
  103. "mainpll_d8",
  104. "univpll_d8",
  105. "mainpll_d16",
  106. "mmpll_200m",
  107. "mainpll_d12",
  108. "mmpll_d2"
  109. };
  110. static const char * const pmicspi_parents[] __initconst = {
  111. "univpll_d20",
  112. "usb_phy48m_ck",
  113. "univpll_d16",
  114. "clk26m_ck"
  115. };
  116. static const char * const qaxi_aud26m_parents[] __initconst = {
  117. "clk26m_ck",
  118. "ahb_infra_sel"
  119. };
  120. static const char * const aud_intbus_parents[] __initconst = {
  121. "clk_null",
  122. "clk26m_ck",
  123. "mainpll_d22",
  124. "clk_null",
  125. "mainpll_d11"
  126. };
  127. static const char * const nfi2x_pad_parents[] __initconst = {
  128. "clk_null",
  129. "clk_null",
  130. "clk_null",
  131. "clk_null",
  132. "clk_null",
  133. "clk_null",
  134. "clk_null",
  135. "clk_null",
  136. "clk26m_ck",
  137. "clk_null",
  138. "clk_null",
  139. "clk_null",
  140. "clk_null",
  141. "clk_null",
  142. "clk_null",
  143. "clk_null",
  144. "clk_null",
  145. "mainpll_d12",
  146. "mainpll_d8",
  147. "clk_null",
  148. "mainpll_d6",
  149. "clk_null",
  150. "clk_null",
  151. "clk_null",
  152. "clk_null",
  153. "clk_null",
  154. "clk_null",
  155. "clk_null",
  156. "clk_null",
  157. "clk_null",
  158. "clk_null",
  159. "clk_null",
  160. "mainpll_d4",
  161. "clk_null",
  162. "clk_null",
  163. "clk_null",
  164. "clk_null",
  165. "clk_null",
  166. "clk_null",
  167. "clk_null",
  168. "clk_null",
  169. "clk_null",
  170. "clk_null",
  171. "clk_null",
  172. "clk_null",
  173. "clk_null",
  174. "clk_null",
  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. "clk_null",
  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. "clk_null",
  193. "clk_null",
  194. "clk_null",
  195. "clk_null",
  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. "clk_null",
  208. "clk_null",
  209. "mainpll_d10",
  210. "mainpll_d7",
  211. "clk_null",
  212. "mainpll_d5"
  213. };
  214. static const char * const nfi1x_pad_parents[] __initconst = {
  215. "ahb_infra_sel",
  216. "nfi1x_ck"
  217. };
  218. static const char * const usb_78m_parents[] __initconst = {
  219. "clk_null",
  220. "clk26m_ck",
  221. "univpll_d16",
  222. "clk_null",
  223. "mainpll_d20"
  224. };
  225. static const char * const spinor_parents[] __initconst = {
  226. "clk26m_d2",
  227. "clk26m_ck",
  228. "mainpll_d40",
  229. "univpll_d24",
  230. "univpll_d20",
  231. "mainpll_d20",
  232. "mainpll_d16",
  233. "univpll_d12"
  234. };
  235. static const char * const msdc2_parents[] __initconst = {
  236. "clk26m_ck",
  237. "univpll_d6",
  238. "mainpll_d8",
  239. "univpll_d8",
  240. "mainpll_d16",
  241. "mmpll_200m",
  242. "mainpll_d12",
  243. "mmpll_d2"
  244. };
  245. static const char * const eth_parents[] __initconst = {
  246. "clk26m_ck",
  247. "mainpll_d40",
  248. "univpll_d24",
  249. "univpll_d20",
  250. "mainpll_d20"
  251. };
  252. static const char * const aud1_parents[] __initconst = {
  253. "clk26m_ck",
  254. "apll1_ck"
  255. };
  256. static const char * const aud2_parents[] __initconst = {
  257. "clk26m_ck",
  258. "apll2_ck"
  259. };
  260. static const char * const aud_engen1_parents[] __initconst = {
  261. "clk26m_ck",
  262. "rg_apll1_d2_en",
  263. "rg_apll1_d4_en",
  264. "rg_apll1_d8_en"
  265. };
  266. static const char * const aud_engen2_parents[] __initconst = {
  267. "clk26m_ck",
  268. "rg_apll2_d2_en",
  269. "rg_apll2_d4_en",
  270. "rg_apll2_d8_en"
  271. };
  272. static const char * const i2c_parents[] __initconst = {
  273. "clk26m_ck",
  274. "univpll_d20",
  275. "univpll_d16",
  276. "univpll_d12"
  277. };
  278. static const char * const aud_i2s0_m_parents[] __initconst = {
  279. "rg_aud1",
  280. "rg_aud2"
  281. };
  282. static const char * const pwm_parents[] __initconst = {
  283. "clk26m_ck",
  284. "univpll_d12"
  285. };
  286. static const char * const spi_parents[] __initconst = {
  287. "clk26m_ck",
  288. "univpll_d12",
  289. "univpll_d8",
  290. "univpll_d6"
  291. };
  292. static const char * const aud_spdifin_parents[] __initconst = {
  293. "clk26m_ck",
  294. "univpll_d2"
  295. };
  296. static const char * const uart2_parents[] __initconst = {
  297. "clk26m_ck",
  298. "univpll_d24"
  299. };
  300. static const char * const bsi_parents[] __initconst = {
  301. "clk26m_ck",
  302. "mainpll_d10",
  303. "mainpll_d12",
  304. "mainpll_d20"
  305. };
  306. static const char * const dbg_atclk_parents[] __initconst = {
  307. "clk_null",
  308. "clk26m_ck",
  309. "mainpll_d5",
  310. "clk_null",
  311. "univpll_d5"
  312. };
  313. static const char * const csw_nfiecc_parents[] __initconst = {
  314. "clk_null",
  315. "mainpll_d7",
  316. "mainpll_d6",
  317. "clk_null",
  318. "mainpll_d5"
  319. };
  320. static const char * const nfiecc_parents[] __initconst = {
  321. "clk_null",
  322. "nfi2x_pad_sel",
  323. "mainpll_d4",
  324. "clk_null",
  325. "csw_nfiecc_sel"
  326. };
  327. static struct mtk_composite top_muxes[] __initdata = {
  328. /* CLK_MUX_SEL0 */
  329. MUX(CLK_TOP_UART0_SEL, "uart0_sel", uart0_parents,
  330. 0x000, 0, 1),
  331. MUX(CLK_TOP_AHB_INFRA_SEL, "ahb_infra_sel", ahb_infra_parents,
  332. 0x000, 4, 4),
  333. MUX(CLK_TOP_MSDC0_SEL, "msdc0_sel", msdc0_parents,
  334. 0x000, 11, 3),
  335. MUX(CLK_TOP_UART1_SEL, "uart1_sel", uart1_parents,
  336. 0x000, 19, 1),
  337. MUX(CLK_TOP_MSDC1_SEL, "msdc1_sel", msdc1_parents,
  338. 0x000, 20, 3),
  339. MUX(CLK_TOP_PMICSPI_SEL, "pmicspi_sel", pmicspi_parents,
  340. 0x000, 24, 2),
  341. MUX(CLK_TOP_QAXI_AUD26M_SEL, "qaxi_aud26m_sel", qaxi_aud26m_parents,
  342. 0x000, 26, 1),
  343. MUX(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel", aud_intbus_parents,
  344. 0x000, 27, 3),
  345. /* CLK_MUX_SEL1 */
  346. MUX(CLK_TOP_NFI2X_PAD_SEL, "nfi2x_pad_sel", nfi2x_pad_parents,
  347. 0x004, 0, 7),
  348. MUX(CLK_TOP_NFI1X_PAD_SEL, "nfi1x_pad_sel", nfi1x_pad_parents,
  349. 0x004, 7, 1),
  350. MUX(CLK_TOP_USB_78M_SEL, "usb_78m_sel", usb_78m_parents,
  351. 0x004, 20, 3),
  352. /* CLK_MUX_SEL8 */
  353. MUX(CLK_TOP_SPINOR_SEL, "spinor_sel", spinor_parents,
  354. 0x040, 0, 3),
  355. MUX(CLK_TOP_MSDC2_SEL, "msdc2_sel", msdc2_parents,
  356. 0x040, 3, 3),
  357. MUX(CLK_TOP_ETH_SEL, "eth_sel", eth_parents,
  358. 0x040, 6, 3),
  359. MUX(CLK_TOP_AUD1_SEL, "aud1_sel", aud1_parents,
  360. 0x040, 22, 1),
  361. MUX(CLK_TOP_AUD2_SEL, "aud2_sel", aud2_parents,
  362. 0x040, 23, 1),
  363. MUX(CLK_TOP_AUD_ENGEN1_SEL, "aud_engen1_sel", aud_engen1_parents,
  364. 0x040, 24, 2),
  365. MUX(CLK_TOP_AUD_ENGEN2_SEL, "aud_engen2_sel", aud_engen2_parents,
  366. 0x040, 26, 2),
  367. MUX(CLK_TOP_I2C_SEL, "i2c_sel", i2c_parents,
  368. 0x040, 28, 2),
  369. /* CLK_SEL_9 */
  370. MUX(CLK_TOP_AUD_I2S0_M_SEL, "aud_i2s0_m_sel", aud_i2s0_m_parents,
  371. 0x044, 12, 1),
  372. MUX(CLK_TOP_AUD_I2S1_M_SEL, "aud_i2s1_m_sel", aud_i2s0_m_parents,
  373. 0x044, 13, 1),
  374. MUX(CLK_TOP_AUD_I2S2_M_SEL, "aud_i2s2_m_sel", aud_i2s0_m_parents,
  375. 0x044, 14, 1),
  376. MUX(CLK_TOP_AUD_I2S3_M_SEL, "aud_i2s3_m_sel", aud_i2s0_m_parents,
  377. 0x044, 15, 1),
  378. MUX(CLK_TOP_AUD_I2S4_M_SEL, "aud_i2s4_m_sel", aud_i2s0_m_parents,
  379. 0x044, 16, 1),
  380. MUX(CLK_TOP_AUD_I2S5_M_SEL, "aud_i2s5_m_sel", aud_i2s0_m_parents,
  381. 0x044, 17, 1),
  382. MUX(CLK_TOP_AUD_SPDIF_B_SEL, "aud_spdif_b_sel", aud_i2s0_m_parents,
  383. 0x044, 18, 1),
  384. /* CLK_MUX_SEL13 */
  385. MUX(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents,
  386. 0x07c, 0, 1),
  387. MUX(CLK_TOP_SPI_SEL, "spi_sel", spi_parents,
  388. 0x07c, 1, 2),
  389. MUX(CLK_TOP_AUD_SPDIFIN_SEL, "aud_spdifin_sel", aud_spdifin_parents,
  390. 0x07c, 3, 1),
  391. MUX(CLK_TOP_UART2_SEL, "uart2_sel", uart2_parents,
  392. 0x07c, 4, 1),
  393. MUX(CLK_TOP_BSI_SEL, "bsi_sel", bsi_parents,
  394. 0x07c, 5, 2),
  395. MUX(CLK_TOP_DBG_ATCLK_SEL, "dbg_atclk_sel", dbg_atclk_parents,
  396. 0x07c, 7, 3),
  397. MUX(CLK_TOP_CSW_NFIECC_SEL, "csw_nfiecc_sel", csw_nfiecc_parents,
  398. 0x07c, 10, 3),
  399. MUX(CLK_TOP_NFIECC_SEL, "nfiecc_sel", nfiecc_parents,
  400. 0x07c, 13, 3),
  401. };
  402. static const char * const ifr_mux1_parents[] __initconst = {
  403. "clk26m_ck",
  404. "armpll",
  405. "univpll",
  406. "mainpll_d2"
  407. };
  408. static const char * const ifr_eth_25m_parents[] __initconst = {
  409. "eth_d2_ck",
  410. "rg_eth"
  411. };
  412. static const char * const ifr_i2c0_parents[] __initconst = {
  413. "ahb_infra_d2",
  414. "rg_i2c"
  415. };
  416. static const struct mtk_composite ifr_muxes[] __initconst = {
  417. MUX(CLK_IFR_MUX1_SEL, "ifr_mux1_sel", ifr_mux1_parents, 0x000,
  418. 2, 2),
  419. MUX(CLK_IFR_ETH_25M_SEL, "ifr_eth_25m_sel", ifr_eth_25m_parents, 0x080,
  420. 0, 1),
  421. MUX(CLK_IFR_I2C0_SEL, "ifr_i2c0_sel", ifr_i2c0_parents, 0x080,
  422. 1, 1),
  423. MUX(CLK_IFR_I2C1_SEL, "ifr_i2c1_sel", ifr_i2c0_parents, 0x080,
  424. 2, 1),
  425. MUX(CLK_IFR_I2C2_SEL, "ifr_i2c2_sel", ifr_i2c0_parents, 0x080,
  426. 3, 1),
  427. };
  428. #define DIV_ADJ(_id, _name, _parent, _reg, _shift, _width) { \
  429. .id = _id, \
  430. .name = _name, \
  431. .parent_name = _parent, \
  432. .div_reg = _reg, \
  433. .div_shift = _shift, \
  434. .div_width = _width, \
  435. }
  436. static const struct mtk_clk_divider top_adj_divs[] = {
  437. DIV_ADJ(CLK_TOP_APLL12_CK_DIV0, "apll12_ck_div0", "aud_i2s0_m_sel",
  438. 0x0048, 0, 8),
  439. DIV_ADJ(CLK_TOP_APLL12_CK_DIV1, "apll12_ck_div1", "aud_i2s1_m_sel",
  440. 0x0048, 8, 8),
  441. DIV_ADJ(CLK_TOP_APLL12_CK_DIV2, "apll12_ck_div2", "aud_i2s2_m_sel",
  442. 0x0048, 16, 8),
  443. DIV_ADJ(CLK_TOP_APLL12_CK_DIV3, "apll12_ck_div3", "aud_i2s3_m_sel",
  444. 0x0048, 24, 8),
  445. DIV_ADJ(CLK_TOP_APLL12_CK_DIV4, "apll12_ck_div4", "aud_i2s4_m_sel",
  446. 0x004c, 0, 8),
  447. DIV_ADJ(CLK_TOP_APLL12_CK_DIV4B, "apll12_ck_div4b", "apll12_div4",
  448. 0x004c, 8, 8),
  449. DIV_ADJ(CLK_TOP_APLL12_CK_DIV5, "apll12_ck_div5", "aud_i2s5_m_sel",
  450. 0x004c, 16, 8),
  451. DIV_ADJ(CLK_TOP_APLL12_CK_DIV5B, "apll12_ck_div5b", "apll12_div5",
  452. 0x004c, 24, 8),
  453. DIV_ADJ(CLK_TOP_APLL12_CK_DIV6, "apll12_ck_div6", "aud_spdif_b_sel",
  454. 0x0078, 0, 8),
  455. };
  456. static const struct mtk_gate_regs top1_cg_regs = {
  457. .set_ofs = 0x54,
  458. .clr_ofs = 0x84,
  459. .sta_ofs = 0x24,
  460. };
  461. static const struct mtk_gate_regs top2_cg_regs = {
  462. .set_ofs = 0x6c,
  463. .clr_ofs = 0x9c,
  464. .sta_ofs = 0x3c,
  465. };
  466. static const struct mtk_gate_regs top3_cg_regs = {
  467. .set_ofs = 0xa0,
  468. .clr_ofs = 0xb0,
  469. .sta_ofs = 0x70,
  470. };
  471. static const struct mtk_gate_regs top4_cg_regs = {
  472. .set_ofs = 0xa4,
  473. .clr_ofs = 0xb4,
  474. .sta_ofs = 0x74,
  475. };
  476. static const struct mtk_gate_regs top5_cg_regs = {
  477. .set_ofs = 0x44,
  478. .clr_ofs = 0x44,
  479. .sta_ofs = 0x44,
  480. };
  481. #define GATE_TOP1(_id, _name, _parent, _shift) \
  482. GATE_MTK(_id, _name, _parent, &top1_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  483. #define GATE_TOP2(_id, _name, _parent, _shift) \
  484. GATE_MTK(_id, _name, _parent, &top2_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  485. #define GATE_TOP2_I(_id, _name, _parent, _shift) \
  486. GATE_MTK(_id, _name, _parent, &top2_cg_regs, _shift, &mtk_clk_gate_ops_setclr_inv)
  487. #define GATE_TOP3(_id, _name, _parent, _shift) \
  488. GATE_MTK(_id, _name, _parent, &top3_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  489. #define GATE_TOP4_I(_id, _name, _parent, _shift) \
  490. GATE_MTK(_id, _name, _parent, &top4_cg_regs, _shift, &mtk_clk_gate_ops_setclr_inv)
  491. #define GATE_TOP5(_id, _name, _parent, _shift) \
  492. GATE_MTK(_id, _name, _parent, &top5_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  493. static const struct mtk_gate top_clks[] __initconst = {
  494. /* TOP1 */
  495. GATE_TOP1(CLK_TOP_THEM, "them", "ahb_infra_sel", 1),
  496. GATE_TOP1(CLK_TOP_APDMA, "apdma", "ahb_infra_sel", 2),
  497. GATE_TOP1(CLK_TOP_I2C0, "i2c0", "ifr_i2c0_sel", 3),
  498. GATE_TOP1(CLK_TOP_I2C1, "i2c1", "ifr_i2c1_sel", 4),
  499. GATE_TOP1(CLK_TOP_AUXADC1, "auxadc1", "ahb_infra_sel", 5),
  500. GATE_TOP1(CLK_TOP_NFI, "nfi", "nfi1x_pad_sel", 6),
  501. GATE_TOP1(CLK_TOP_NFIECC, "nfiecc", "rg_nfiecc", 7),
  502. GATE_TOP1(CLK_TOP_DEBUGSYS, "debugsys", "rg_dbg_atclk", 8),
  503. GATE_TOP1(CLK_TOP_PWM, "pwm", "ahb_infra_sel", 9),
  504. GATE_TOP1(CLK_TOP_UART0, "uart0", "uart0_sel", 10),
  505. GATE_TOP1(CLK_TOP_UART1, "uart1", "uart1_sel", 11),
  506. GATE_TOP1(CLK_TOP_BTIF, "btif", "ahb_infra_sel", 12),
  507. GATE_TOP1(CLK_TOP_USB, "usb", "usb_78m", 13),
  508. GATE_TOP1(CLK_TOP_FLASHIF_26M, "flashif_26m", "clk26m_ck", 14),
  509. GATE_TOP1(CLK_TOP_AUXADC2, "auxadc2", "ahb_infra_sel", 15),
  510. GATE_TOP1(CLK_TOP_I2C2, "i2c2", "ifr_i2c2_sel", 16),
  511. GATE_TOP1(CLK_TOP_MSDC0, "msdc0", "msdc0_sel", 17),
  512. GATE_TOP1(CLK_TOP_MSDC1, "msdc1", "msdc1_sel", 18),
  513. GATE_TOP1(CLK_TOP_NFI2X, "nfi2x", "nfi2x_pad_sel", 19),
  514. GATE_TOP1(CLK_TOP_PMICWRAP_AP, "pwrap_ap", "clk26m_ck", 20),
  515. GATE_TOP1(CLK_TOP_SEJ, "sej", "ahb_infra_sel", 21),
  516. GATE_TOP1(CLK_TOP_MEMSLP_DLYER, "memslp_dlyer", "clk26m_ck", 22),
  517. GATE_TOP1(CLK_TOP_SPI, "spi", "spi_sel", 23),
  518. GATE_TOP1(CLK_TOP_APXGPT, "apxgpt", "clk26m_ck", 24),
  519. GATE_TOP1(CLK_TOP_AUDIO, "audio", "clk26m_ck", 25),
  520. GATE_TOP1(CLK_TOP_PMICWRAP_MD, "pwrap_md", "clk26m_ck", 27),
  521. GATE_TOP1(CLK_TOP_PMICWRAP_CONN, "pwrap_conn", "clk26m_ck", 28),
  522. GATE_TOP1(CLK_TOP_PMICWRAP_26M, "pwrap_26m", "clk26m_ck", 29),
  523. GATE_TOP1(CLK_TOP_AUX_ADC, "aux_adc", "clk26m_ck", 30),
  524. GATE_TOP1(CLK_TOP_AUX_TP, "aux_tp", "clk26m_ck", 31),
  525. /* TOP2 */
  526. GATE_TOP2(CLK_TOP_MSDC2, "msdc2", "ahb_infra_sel", 0),
  527. GATE_TOP2(CLK_TOP_RBIST, "rbist", "univpll_d12", 1),
  528. GATE_TOP2(CLK_TOP_NFI_BUS, "nfi_bus", "ahb_infra_sel", 2),
  529. GATE_TOP2(CLK_TOP_GCE, "gce", "ahb_infra_sel", 4),
  530. GATE_TOP2(CLK_TOP_TRNG, "trng", "ahb_infra_sel", 5),
  531. GATE_TOP2(CLK_TOP_SEJ_13M, "sej_13m", "clk26m_ck", 6),
  532. GATE_TOP2(CLK_TOP_AES, "aes", "ahb_infra_sel", 7),
  533. GATE_TOP2(CLK_TOP_PWM_B, "pwm_b", "rg_pwm_infra", 8),
  534. GATE_TOP2(CLK_TOP_PWM1_FB, "pwm1_fb", "rg_pwm_infra", 9),
  535. GATE_TOP2(CLK_TOP_PWM2_FB, "pwm2_fb", "rg_pwm_infra", 10),
  536. GATE_TOP2(CLK_TOP_PWM3_FB, "pwm3_fb", "rg_pwm_infra", 11),
  537. GATE_TOP2(CLK_TOP_PWM4_FB, "pwm4_fb", "rg_pwm_infra", 12),
  538. GATE_TOP2(CLK_TOP_PWM5_FB, "pwm5_fb", "rg_pwm_infra", 13),
  539. GATE_TOP2(CLK_TOP_USB_1P, "usb_1p", "usb_78m", 14),
  540. GATE_TOP2(CLK_TOP_FLASHIF_FREERUN, "flashif_freerun", "ahb_infra_sel",
  541. 15),
  542. GATE_TOP2(CLK_TOP_66M_ETH, "eth_66m", "ahb_infra_d2", 19),
  543. GATE_TOP2(CLK_TOP_133M_ETH, "eth_133m", "ahb_infra_sel", 20),
  544. GATE_TOP2(CLK_TOP_FETH_25M, "feth_25m", "ifr_eth_25m_sel", 21),
  545. GATE_TOP2(CLK_TOP_FETH_50M, "feth_50m", "rg_eth", 22),
  546. GATE_TOP2(CLK_TOP_FLASHIF_AXI, "flashif_axi", "ahb_infra_sel", 23),
  547. GATE_TOP2(CLK_TOP_USBIF, "usbif", "ahb_infra_sel", 24),
  548. GATE_TOP2(CLK_TOP_UART2, "uart2", "rg_uart2", 25),
  549. GATE_TOP2(CLK_TOP_BSI, "bsi", "ahb_infra_sel", 26),
  550. GATE_TOP2_I(CLK_TOP_MSDC0_INFRA, "msdc0_infra", "msdc0", 28),
  551. GATE_TOP2_I(CLK_TOP_MSDC1_INFRA, "msdc1_infra", "msdc1", 29),
  552. GATE_TOP2_I(CLK_TOP_MSDC2_INFRA, "msdc2_infra", "rg_msdc2", 30),
  553. GATE_TOP2(CLK_TOP_USB_78M, "usb_78m", "usb_78m_sel", 31),
  554. /* TOP3 */
  555. GATE_TOP3(CLK_TOP_RG_SPINOR, "rg_spinor", "spinor_sel", 0),
  556. GATE_TOP3(CLK_TOP_RG_MSDC2, "rg_msdc2", "msdc2_sel", 1),
  557. GATE_TOP3(CLK_TOP_RG_ETH, "rg_eth", "eth_sel", 2),
  558. GATE_TOP3(CLK_TOP_RG_AUD1, "rg_aud1", "aud1_sel", 8),
  559. GATE_TOP3(CLK_TOP_RG_AUD2, "rg_aud2", "aud2_sel", 9),
  560. GATE_TOP3(CLK_TOP_RG_AUD_ENGEN1, "rg_aud_engen1", "aud_engen1_sel", 10),
  561. GATE_TOP3(CLK_TOP_RG_AUD_ENGEN2, "rg_aud_engen2", "aud_engen2_sel", 11),
  562. GATE_TOP3(CLK_TOP_RG_I2C, "rg_i2c", "i2c_sel", 12),
  563. GATE_TOP3(CLK_TOP_RG_PWM_INFRA, "rg_pwm_infra", "pwm_sel", 13),
  564. GATE_TOP3(CLK_TOP_RG_AUD_SPDIF_IN, "rg_aud_spdif_in", "aud_spdifin_sel",
  565. 14),
  566. GATE_TOP3(CLK_TOP_RG_UART2, "rg_uart2", "uart2_sel", 15),
  567. GATE_TOP3(CLK_TOP_RG_BSI, "rg_bsi", "bsi_sel", 16),
  568. GATE_TOP3(CLK_TOP_RG_DBG_ATCLK, "rg_dbg_atclk", "dbg_atclk_sel", 17),
  569. GATE_TOP3(CLK_TOP_RG_NFIECC, "rg_nfiecc", "nfiecc_sel", 18),
  570. /* TOP4 */
  571. GATE_TOP4_I(CLK_TOP_RG_APLL1_D2_EN, "rg_apll1_d2_en", "apll1_d2", 8),
  572. GATE_TOP4_I(CLK_TOP_RG_APLL1_D4_EN, "rg_apll1_d4_en", "apll1_d4", 9),
  573. GATE_TOP4_I(CLK_TOP_RG_APLL1_D8_EN, "rg_apll1_d8_en", "apll1_d8", 10),
  574. GATE_TOP4_I(CLK_TOP_RG_APLL2_D2_EN, "rg_apll2_d2_en", "apll2_d2", 11),
  575. GATE_TOP4_I(CLK_TOP_RG_APLL2_D4_EN, "rg_apll2_d4_en", "apll2_d4", 12),
  576. GATE_TOP4_I(CLK_TOP_RG_APLL2_D8_EN, "rg_apll2_d8_en", "apll2_d8", 13),
  577. /* TOP5 */
  578. GATE_TOP5(CLK_TOP_APLL12_DIV0, "apll12_div0", "apll12_ck_div0", 0),
  579. GATE_TOP5(CLK_TOP_APLL12_DIV1, "apll12_div1", "apll12_ck_div1", 1),
  580. GATE_TOP5(CLK_TOP_APLL12_DIV2, "apll12_div2", "apll12_ck_div2", 2),
  581. GATE_TOP5(CLK_TOP_APLL12_DIV3, "apll12_div3", "apll12_ck_div3", 3),
  582. GATE_TOP5(CLK_TOP_APLL12_DIV4, "apll12_div4", "apll12_ck_div4", 4),
  583. GATE_TOP5(CLK_TOP_APLL12_DIV4B, "apll12_div4b", "apll12_ck_div4b", 5),
  584. GATE_TOP5(CLK_TOP_APLL12_DIV5, "apll12_div5", "apll12_ck_div5", 6),
  585. GATE_TOP5(CLK_TOP_APLL12_DIV5B, "apll12_div5b", "apll12_ck_div5b", 7),
  586. GATE_TOP5(CLK_TOP_APLL12_DIV6, "apll12_div6", "apll12_ck_div6", 8),
  587. };
  588. static void __init mtk_topckgen_init(struct device_node *node)
  589. {
  590. struct clk_hw_onecell_data *clk_data;
  591. int r;
  592. void __iomem *base;
  593. base = of_iomap(node, 0);
  594. if (!base) {
  595. pr_err("%s(): ioremap failed\n", __func__);
  596. return;
  597. }
  598. clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
  599. mtk_clk_register_fixed_clks(fixed_clks, ARRAY_SIZE(fixed_clks),
  600. clk_data);
  601. mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks), clk_data);
  602. mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
  603. mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
  604. &mt8516_clk_lock, clk_data);
  605. mtk_clk_register_dividers(top_adj_divs, ARRAY_SIZE(top_adj_divs),
  606. base, &mt8516_clk_lock, clk_data);
  607. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  608. if (r)
  609. pr_err("%s(): could not register clock provider: %d\n",
  610. __func__, r);
  611. }
  612. CLK_OF_DECLARE(mtk_topckgen, "mediatek,mt8516-topckgen", mtk_topckgen_init);
  613. static void __init mtk_infracfg_init(struct device_node *node)
  614. {
  615. struct clk_hw_onecell_data *clk_data;
  616. int r;
  617. void __iomem *base;
  618. base = of_iomap(node, 0);
  619. if (!base) {
  620. pr_err("%s(): ioremap failed\n", __func__);
  621. return;
  622. }
  623. clk_data = mtk_alloc_clk_data(CLK_IFR_NR_CLK);
  624. mtk_clk_register_composites(ifr_muxes, ARRAY_SIZE(ifr_muxes), base,
  625. &mt8516_clk_lock, clk_data);
  626. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  627. if (r)
  628. pr_err("%s(): could not register clock provider: %d\n",
  629. __func__, r);
  630. }
  631. CLK_OF_DECLARE(mtk_infracfg, "mediatek,mt8516-infracfg", mtk_infracfg_init);
  632. #define MT8516_PLL_FMAX (1502UL * MHZ)
  633. #define CON0_MT8516_RST_BAR BIT(27)
  634. #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  635. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  636. _pcw_shift, _div_table) { \
  637. .id = _id, \
  638. .name = _name, \
  639. .reg = _reg, \
  640. .pwr_reg = _pwr_reg, \
  641. .en_mask = _en_mask, \
  642. .flags = _flags, \
  643. .rst_bar_mask = CON0_MT8516_RST_BAR, \
  644. .fmax = MT8516_PLL_FMAX, \
  645. .pcwbits = _pcwbits, \
  646. .pd_reg = _pd_reg, \
  647. .pd_shift = _pd_shift, \
  648. .tuner_reg = _tuner_reg, \
  649. .pcw_reg = _pcw_reg, \
  650. .pcw_shift = _pcw_shift, \
  651. .div_table = _div_table, \
  652. }
  653. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  654. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  655. _pcw_shift) \
  656. PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  657. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
  658. NULL)
  659. static const struct mtk_pll_div_table mmpll_div_table[] = {
  660. { .div = 0, .freq = MT8516_PLL_FMAX },
  661. { .div = 1, .freq = 1000000000 },
  662. { .div = 2, .freq = 604500000 },
  663. { .div = 3, .freq = 253500000 },
  664. { .div = 4, .freq = 126750000 },
  665. { } /* sentinel */
  666. };
  667. static const struct mtk_pll_data plls[] = {
  668. PLL(CLK_APMIXED_ARMPLL, "armpll", 0x0100, 0x0110, 0, 0,
  669. 21, 0x0104, 24, 0, 0x0104, 0),
  670. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0120, 0x0130, 0,
  671. HAVE_RST_BAR, 21, 0x0124, 24, 0, 0x0124, 0),
  672. PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0140, 0x0150, 0x30000000,
  673. HAVE_RST_BAR, 7, 0x0144, 24, 0, 0x0144, 0),
  674. PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x0160, 0x0170, 0, 0,
  675. 21, 0x0164, 24, 0, 0x0164, 0, mmpll_div_table),
  676. PLL(CLK_APMIXED_APLL1, "apll1", 0x0180, 0x0190, 0, 0,
  677. 31, 0x0180, 1, 0x0194, 0x0184, 0),
  678. PLL(CLK_APMIXED_APLL2, "apll2", 0x01A0, 0x01B0, 0, 0,
  679. 31, 0x01A0, 1, 0x01B4, 0x01A4, 0),
  680. };
  681. static void __init mtk_apmixedsys_init(struct device_node *node)
  682. {
  683. struct clk_hw_onecell_data *clk_data;
  684. void __iomem *base;
  685. int r;
  686. base = of_iomap(node, 0);
  687. if (!base) {
  688. pr_err("%s(): ioremap failed\n", __func__);
  689. return;
  690. }
  691. clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
  692. mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  693. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  694. if (r)
  695. pr_err("%s(): could not register clock provider: %d\n",
  696. __func__, r);
  697. }
  698. CLK_OF_DECLARE(mtk_apmixedsys, "mediatek,mt8516-apmixedsys",
  699. mtk_apmixedsys_init);