clk-mt8516.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2019 MediaTek Inc.
  4. * Author: James Liao <jamesjj.liao@mediatek.com>
  5. * Fabien Parent <fparent@baylibre.com>
  6. * Copyright (c) 2023 Collabora Ltd.
  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 <linux/platform_device.h>
  14. #include "clk-gate.h"
  15. #include "clk-mtk.h"
  16. #include <dt-bindings/clock/mt8516-clk.h>
  17. static DEFINE_SPINLOCK(mt8516_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. };
  23. static const struct mtk_fixed_factor top_divs[] __initconst = {
  24. FACTOR(CLK_TOP_DMPLL, "dmpll_ck", "mempll", 1, 1),
  25. FACTOR(CLK_TOP_MAINPLL_D2, "mainpll_d2", "mainpll", 1, 2),
  26. FACTOR(CLK_TOP_MAINPLL_D4, "mainpll_d4", "mainpll", 1, 4),
  27. FACTOR(CLK_TOP_MAINPLL_D8, "mainpll_d8", "mainpll", 1, 8),
  28. FACTOR(CLK_TOP_MAINPLL_D16, "mainpll_d16", "mainpll", 1, 16),
  29. FACTOR(CLK_TOP_MAINPLL_D11, "mainpll_d11", "mainpll", 1, 11),
  30. FACTOR(CLK_TOP_MAINPLL_D22, "mainpll_d22", "mainpll", 1, 22),
  31. FACTOR(CLK_TOP_MAINPLL_D3, "mainpll_d3", "mainpll", 1, 3),
  32. FACTOR(CLK_TOP_MAINPLL_D6, "mainpll_d6", "mainpll", 1, 6),
  33. FACTOR(CLK_TOP_MAINPLL_D12, "mainpll_d12", "mainpll", 1, 12),
  34. FACTOR(CLK_TOP_MAINPLL_D5, "mainpll_d5", "mainpll", 1, 5),
  35. FACTOR(CLK_TOP_MAINPLL_D10, "mainpll_d10", "mainpll", 1, 10),
  36. FACTOR(CLK_TOP_MAINPLL_D20, "mainpll_d20", "mainpll", 1, 20),
  37. FACTOR(CLK_TOP_MAINPLL_D40, "mainpll_d40", "mainpll", 1, 40),
  38. FACTOR(CLK_TOP_MAINPLL_D7, "mainpll_d7", "mainpll", 1, 7),
  39. FACTOR(CLK_TOP_MAINPLL_D14, "mainpll_d14", "mainpll", 1, 14),
  40. FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2),
  41. FACTOR(CLK_TOP_UNIVPLL_D4, "univpll_d4", "univpll", 1, 4),
  42. FACTOR(CLK_TOP_UNIVPLL_D8, "univpll_d8", "univpll", 1, 8),
  43. FACTOR(CLK_TOP_UNIVPLL_D16, "univpll_d16", "univpll", 1, 16),
  44. FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3),
  45. FACTOR(CLK_TOP_UNIVPLL_D6, "univpll_d6", "univpll", 1, 6),
  46. FACTOR(CLK_TOP_UNIVPLL_D12, "univpll_d12", "univpll", 1, 12),
  47. FACTOR(CLK_TOP_UNIVPLL_D24, "univpll_d24", "univpll", 1, 24),
  48. FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
  49. FACTOR(CLK_TOP_UNIVPLL_D20, "univpll_d20", "univpll", 1, 20),
  50. FACTOR(CLK_TOP_MMPLL380M, "mmpll380m", "mmpll", 1, 1),
  51. FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll", 1, 2),
  52. FACTOR(CLK_TOP_MMPLL_200M, "mmpll_200m", "mmpll", 1, 3),
  53. FACTOR(CLK_TOP_USB_PHY48M, "usb_phy48m_ck", "univpll", 1, 26),
  54. FACTOR(CLK_TOP_APLL1, "apll1_ck", "apll1", 1, 1),
  55. FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1_ck", 1, 2),
  56. FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "rg_apll1_d2_en", 1, 2),
  57. FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "rg_apll1_d4_en", 1, 2),
  58. FACTOR(CLK_TOP_APLL2, "apll2_ck", "apll2", 1, 1),
  59. FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2_ck", 1, 2),
  60. FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "rg_apll2_d2_en", 1, 2),
  61. FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "rg_apll2_d4_en", 1, 2),
  62. FACTOR(CLK_TOP_CLK26M, "clk26m_ck", "clk26m", 1, 1),
  63. FACTOR(CLK_TOP_CLK26M_D2, "clk26m_d2", "clk26m", 1, 2),
  64. FACTOR(CLK_TOP_AHB_INFRA_D2, "ahb_infra_d2", "ahb_infra_sel", 1, 2),
  65. FACTOR(CLK_TOP_NFI1X, "nfi1x_ck", "nfi2x_pad_sel", 1, 2),
  66. FACTOR(CLK_TOP_ETH_D2, "eth_d2_ck", "eth_sel", 1, 2),
  67. };
  68. static const char * const uart0_parents[] __initconst = {
  69. "clk26m_ck",
  70. "univpll_d24"
  71. };
  72. static const char * const ahb_infra_parents[] __initconst = {
  73. "clk_null",
  74. "clk26m_ck",
  75. "mainpll_d11",
  76. "clk_null",
  77. "mainpll_d12",
  78. "clk_null",
  79. "clk_null",
  80. "clk_null",
  81. "clk_null",
  82. "clk_null",
  83. "clk_null",
  84. "clk_null",
  85. "mainpll_d10"
  86. };
  87. static const char * const msdc0_parents[] __initconst = {
  88. "clk26m_ck",
  89. "univpll_d6",
  90. "mainpll_d8",
  91. "univpll_d8",
  92. "mainpll_d16",
  93. "mmpll_200m",
  94. "mainpll_d12",
  95. "mmpll_d2"
  96. };
  97. static const char * const uart1_parents[] __initconst = {
  98. "clk26m_ck",
  99. "univpll_d24"
  100. };
  101. static const char * const msdc1_parents[] __initconst = {
  102. "clk26m_ck",
  103. "univpll_d6",
  104. "mainpll_d8",
  105. "univpll_d8",
  106. "mainpll_d16",
  107. "mmpll_200m",
  108. "mainpll_d12",
  109. "mmpll_d2"
  110. };
  111. static const char * const pmicspi_parents[] __initconst = {
  112. "univpll_d20",
  113. "usb_phy48m_ck",
  114. "univpll_d16",
  115. "clk26m_ck"
  116. };
  117. static const char * const qaxi_aud26m_parents[] __initconst = {
  118. "clk26m_ck",
  119. "ahb_infra_sel"
  120. };
  121. static const char * const aud_intbus_parents[] __initconst = {
  122. "clk_null",
  123. "clk26m_ck",
  124. "mainpll_d22",
  125. "clk_null",
  126. "mainpll_d11"
  127. };
  128. static const char * const nfi2x_pad_parents[] __initconst = {
  129. "clk_null",
  130. "clk_null",
  131. "clk_null",
  132. "clk_null",
  133. "clk_null",
  134. "clk_null",
  135. "clk_null",
  136. "clk_null",
  137. "clk26m_ck",
  138. "clk_null",
  139. "clk_null",
  140. "clk_null",
  141. "clk_null",
  142. "clk_null",
  143. "clk_null",
  144. "clk_null",
  145. "clk_null",
  146. "mainpll_d12",
  147. "mainpll_d8",
  148. "clk_null",
  149. "mainpll_d6",
  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. "clk_null",
  161. "mainpll_d4",
  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. "clk_null",
  210. "mainpll_d10",
  211. "mainpll_d7",
  212. "clk_null",
  213. "mainpll_d5"
  214. };
  215. static const char * const nfi1x_pad_parents[] __initconst = {
  216. "ahb_infra_sel",
  217. "nfi1x_ck"
  218. };
  219. static const char * const usb_78m_parents[] __initconst = {
  220. "clk_null",
  221. "clk26m_ck",
  222. "univpll_d16",
  223. "clk_null",
  224. "mainpll_d20"
  225. };
  226. static const char * const spinor_parents[] __initconst = {
  227. "clk26m_d2",
  228. "clk26m_ck",
  229. "mainpll_d40",
  230. "univpll_d24",
  231. "univpll_d20",
  232. "mainpll_d20",
  233. "mainpll_d16",
  234. "univpll_d12"
  235. };
  236. static const char * const msdc2_parents[] __initconst = {
  237. "clk26m_ck",
  238. "univpll_d6",
  239. "mainpll_d8",
  240. "univpll_d8",
  241. "mainpll_d16",
  242. "mmpll_200m",
  243. "mainpll_d12",
  244. "mmpll_d2"
  245. };
  246. static const char * const eth_parents[] __initconst = {
  247. "clk26m_ck",
  248. "mainpll_d40",
  249. "univpll_d24",
  250. "univpll_d20",
  251. "mainpll_d20"
  252. };
  253. static const char * const aud1_parents[] __initconst = {
  254. "clk26m_ck",
  255. "apll1_ck"
  256. };
  257. static const char * const aud2_parents[] __initconst = {
  258. "clk26m_ck",
  259. "apll2_ck"
  260. };
  261. static const char * const aud_engen1_parents[] __initconst = {
  262. "clk26m_ck",
  263. "rg_apll1_d2_en",
  264. "rg_apll1_d4_en",
  265. "rg_apll1_d8_en"
  266. };
  267. static const char * const aud_engen2_parents[] __initconst = {
  268. "clk26m_ck",
  269. "rg_apll2_d2_en",
  270. "rg_apll2_d4_en",
  271. "rg_apll2_d8_en"
  272. };
  273. static const char * const i2c_parents[] __initconst = {
  274. "clk26m_ck",
  275. "univpll_d20",
  276. "univpll_d16",
  277. "univpll_d12"
  278. };
  279. static const char * const aud_i2s0_m_parents[] __initconst = {
  280. "rg_aud1",
  281. "rg_aud2"
  282. };
  283. static const char * const pwm_parents[] __initconst = {
  284. "clk26m_ck",
  285. "univpll_d12"
  286. };
  287. static const char * const spi_parents[] __initconst = {
  288. "clk26m_ck",
  289. "univpll_d12",
  290. "univpll_d8",
  291. "univpll_d6"
  292. };
  293. static const char * const aud_spdifin_parents[] __initconst = {
  294. "clk26m_ck",
  295. "univpll_d2"
  296. };
  297. static const char * const uart2_parents[] __initconst = {
  298. "clk26m_ck",
  299. "univpll_d24"
  300. };
  301. static const char * const bsi_parents[] __initconst = {
  302. "clk26m_ck",
  303. "mainpll_d10",
  304. "mainpll_d12",
  305. "mainpll_d20"
  306. };
  307. static const char * const dbg_atclk_parents[] __initconst = {
  308. "clk_null",
  309. "clk26m_ck",
  310. "mainpll_d5",
  311. "clk_null",
  312. "univpll_d5"
  313. };
  314. static const char * const csw_nfiecc_parents[] __initconst = {
  315. "clk_null",
  316. "mainpll_d7",
  317. "mainpll_d6",
  318. "clk_null",
  319. "mainpll_d5"
  320. };
  321. static const char * const nfiecc_parents[] __initconst = {
  322. "clk_null",
  323. "nfi2x_pad_sel",
  324. "mainpll_d4",
  325. "clk_null",
  326. "csw_nfiecc_sel"
  327. };
  328. static struct mtk_composite top_muxes[] __initdata = {
  329. /* CLK_MUX_SEL0 */
  330. MUX(CLK_TOP_UART0_SEL, "uart0_sel", uart0_parents,
  331. 0x000, 0, 1),
  332. MUX(CLK_TOP_AHB_INFRA_SEL, "ahb_infra_sel", ahb_infra_parents,
  333. 0x000, 4, 4),
  334. MUX(CLK_TOP_MSDC0_SEL, "msdc0_sel", msdc0_parents,
  335. 0x000, 11, 3),
  336. MUX(CLK_TOP_UART1_SEL, "uart1_sel", uart1_parents,
  337. 0x000, 19, 1),
  338. MUX(CLK_TOP_MSDC1_SEL, "msdc1_sel", msdc1_parents,
  339. 0x000, 20, 3),
  340. MUX(CLK_TOP_PMICSPI_SEL, "pmicspi_sel", pmicspi_parents,
  341. 0x000, 24, 2),
  342. MUX(CLK_TOP_QAXI_AUD26M_SEL, "qaxi_aud26m_sel", qaxi_aud26m_parents,
  343. 0x000, 26, 1),
  344. MUX(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel", aud_intbus_parents,
  345. 0x000, 27, 3),
  346. /* CLK_MUX_SEL1 */
  347. MUX(CLK_TOP_NFI2X_PAD_SEL, "nfi2x_pad_sel", nfi2x_pad_parents,
  348. 0x004, 0, 7),
  349. MUX(CLK_TOP_NFI1X_PAD_SEL, "nfi1x_pad_sel", nfi1x_pad_parents,
  350. 0x004, 7, 1),
  351. MUX(CLK_TOP_USB_78M_SEL, "usb_78m_sel", usb_78m_parents,
  352. 0x004, 20, 3),
  353. /* CLK_MUX_SEL8 */
  354. MUX(CLK_TOP_SPINOR_SEL, "spinor_sel", spinor_parents,
  355. 0x040, 0, 3),
  356. MUX(CLK_TOP_MSDC2_SEL, "msdc2_sel", msdc2_parents,
  357. 0x040, 3, 3),
  358. MUX(CLK_TOP_ETH_SEL, "eth_sel", eth_parents,
  359. 0x040, 6, 3),
  360. MUX(CLK_TOP_AUD1_SEL, "aud1_sel", aud1_parents,
  361. 0x040, 22, 1),
  362. MUX(CLK_TOP_AUD2_SEL, "aud2_sel", aud2_parents,
  363. 0x040, 23, 1),
  364. MUX(CLK_TOP_AUD_ENGEN1_SEL, "aud_engen1_sel", aud_engen1_parents,
  365. 0x040, 24, 2),
  366. MUX(CLK_TOP_AUD_ENGEN2_SEL, "aud_engen2_sel", aud_engen2_parents,
  367. 0x040, 26, 2),
  368. MUX(CLK_TOP_I2C_SEL, "i2c_sel", i2c_parents,
  369. 0x040, 28, 2),
  370. /* CLK_SEL_9 */
  371. MUX(CLK_TOP_AUD_I2S0_M_SEL, "aud_i2s0_m_sel", aud_i2s0_m_parents,
  372. 0x044, 12, 1),
  373. MUX(CLK_TOP_AUD_I2S1_M_SEL, "aud_i2s1_m_sel", aud_i2s0_m_parents,
  374. 0x044, 13, 1),
  375. MUX(CLK_TOP_AUD_I2S2_M_SEL, "aud_i2s2_m_sel", aud_i2s0_m_parents,
  376. 0x044, 14, 1),
  377. MUX(CLK_TOP_AUD_I2S3_M_SEL, "aud_i2s3_m_sel", aud_i2s0_m_parents,
  378. 0x044, 15, 1),
  379. MUX(CLK_TOP_AUD_I2S4_M_SEL, "aud_i2s4_m_sel", aud_i2s0_m_parents,
  380. 0x044, 16, 1),
  381. MUX(CLK_TOP_AUD_I2S5_M_SEL, "aud_i2s5_m_sel", aud_i2s0_m_parents,
  382. 0x044, 17, 1),
  383. MUX(CLK_TOP_AUD_SPDIF_B_SEL, "aud_spdif_b_sel", aud_i2s0_m_parents,
  384. 0x044, 18, 1),
  385. /* CLK_MUX_SEL13 */
  386. MUX(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents,
  387. 0x07c, 0, 1),
  388. MUX(CLK_TOP_SPI_SEL, "spi_sel", spi_parents,
  389. 0x07c, 1, 2),
  390. MUX(CLK_TOP_AUD_SPDIFIN_SEL, "aud_spdifin_sel", aud_spdifin_parents,
  391. 0x07c, 3, 1),
  392. MUX(CLK_TOP_UART2_SEL, "uart2_sel", uart2_parents,
  393. 0x07c, 4, 1),
  394. MUX(CLK_TOP_BSI_SEL, "bsi_sel", bsi_parents,
  395. 0x07c, 5, 2),
  396. MUX(CLK_TOP_DBG_ATCLK_SEL, "dbg_atclk_sel", dbg_atclk_parents,
  397. 0x07c, 7, 3),
  398. MUX(CLK_TOP_CSW_NFIECC_SEL, "csw_nfiecc_sel", csw_nfiecc_parents,
  399. 0x07c, 10, 3),
  400. MUX(CLK_TOP_NFIECC_SEL, "nfiecc_sel", nfiecc_parents,
  401. 0x07c, 13, 3),
  402. };
  403. static const char * const ifr_mux1_parents[] __initconst = {
  404. "clk26m_ck",
  405. "armpll",
  406. "univpll",
  407. "mainpll_d2"
  408. };
  409. static const char * const ifr_eth_25m_parents[] __initconst = {
  410. "eth_d2_ck",
  411. "rg_eth"
  412. };
  413. static const char * const ifr_i2c0_parents[] __initconst = {
  414. "ahb_infra_d2",
  415. "rg_i2c"
  416. };
  417. static const struct mtk_composite ifr_muxes[] __initconst = {
  418. MUX(CLK_IFR_MUX1_SEL, "ifr_mux1_sel", ifr_mux1_parents, 0x000,
  419. 2, 2),
  420. MUX(CLK_IFR_ETH_25M_SEL, "ifr_eth_25m_sel", ifr_eth_25m_parents, 0x080,
  421. 0, 1),
  422. MUX(CLK_IFR_I2C0_SEL, "ifr_i2c0_sel", ifr_i2c0_parents, 0x080,
  423. 1, 1),
  424. MUX(CLK_IFR_I2C1_SEL, "ifr_i2c1_sel", ifr_i2c0_parents, 0x080,
  425. 2, 1),
  426. MUX(CLK_IFR_I2C2_SEL, "ifr_i2c2_sel", ifr_i2c0_parents, 0x080,
  427. 3, 1),
  428. };
  429. #define DIV_ADJ(_id, _name, _parent, _reg, _shift, _width) { \
  430. .id = _id, \
  431. .name = _name, \
  432. .parent_name = _parent, \
  433. .div_reg = _reg, \
  434. .div_shift = _shift, \
  435. .div_width = _width, \
  436. }
  437. static const struct mtk_clk_divider top_adj_divs[] = {
  438. DIV_ADJ(CLK_TOP_APLL12_CK_DIV0, "apll12_ck_div0", "aud_i2s0_m_sel",
  439. 0x0048, 0, 8),
  440. DIV_ADJ(CLK_TOP_APLL12_CK_DIV1, "apll12_ck_div1", "aud_i2s1_m_sel",
  441. 0x0048, 8, 8),
  442. DIV_ADJ(CLK_TOP_APLL12_CK_DIV2, "apll12_ck_div2", "aud_i2s2_m_sel",
  443. 0x0048, 16, 8),
  444. DIV_ADJ(CLK_TOP_APLL12_CK_DIV3, "apll12_ck_div3", "aud_i2s3_m_sel",
  445. 0x0048, 24, 8),
  446. DIV_ADJ(CLK_TOP_APLL12_CK_DIV4, "apll12_ck_div4", "aud_i2s4_m_sel",
  447. 0x004c, 0, 8),
  448. DIV_ADJ(CLK_TOP_APLL12_CK_DIV4B, "apll12_ck_div4b", "apll12_div4",
  449. 0x004c, 8, 8),
  450. DIV_ADJ(CLK_TOP_APLL12_CK_DIV5, "apll12_ck_div5", "aud_i2s5_m_sel",
  451. 0x004c, 16, 8),
  452. DIV_ADJ(CLK_TOP_APLL12_CK_DIV5B, "apll12_ck_div5b", "apll12_div5",
  453. 0x004c, 24, 8),
  454. DIV_ADJ(CLK_TOP_APLL12_CK_DIV6, "apll12_ck_div6", "aud_spdif_b_sel",
  455. 0x0078, 0, 8),
  456. };
  457. static const struct mtk_gate_regs top1_cg_regs = {
  458. .set_ofs = 0x54,
  459. .clr_ofs = 0x84,
  460. .sta_ofs = 0x24,
  461. };
  462. static const struct mtk_gate_regs top2_cg_regs = {
  463. .set_ofs = 0x6c,
  464. .clr_ofs = 0x9c,
  465. .sta_ofs = 0x3c,
  466. };
  467. static const struct mtk_gate_regs top3_cg_regs = {
  468. .set_ofs = 0xa0,
  469. .clr_ofs = 0xb0,
  470. .sta_ofs = 0x70,
  471. };
  472. static const struct mtk_gate_regs top4_cg_regs = {
  473. .set_ofs = 0xa4,
  474. .clr_ofs = 0xb4,
  475. .sta_ofs = 0x74,
  476. };
  477. static const struct mtk_gate_regs top5_cg_regs = {
  478. .set_ofs = 0x44,
  479. .clr_ofs = 0x44,
  480. .sta_ofs = 0x44,
  481. };
  482. #define GATE_TOP1(_id, _name, _parent, _shift) \
  483. GATE_MTK(_id, _name, _parent, &top1_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  484. #define GATE_TOP2(_id, _name, _parent, _shift) \
  485. GATE_MTK(_id, _name, _parent, &top2_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  486. #define GATE_TOP2_I(_id, _name, _parent, _shift) \
  487. GATE_MTK(_id, _name, _parent, &top2_cg_regs, _shift, &mtk_clk_gate_ops_setclr_inv)
  488. #define GATE_TOP3(_id, _name, _parent, _shift) \
  489. GATE_MTK(_id, _name, _parent, &top3_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  490. #define GATE_TOP4_I(_id, _name, _parent, _shift) \
  491. GATE_MTK(_id, _name, _parent, &top4_cg_regs, _shift, &mtk_clk_gate_ops_setclr_inv)
  492. #define GATE_TOP5(_id, _name, _parent, _shift) \
  493. GATE_MTK(_id, _name, _parent, &top5_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  494. static const struct mtk_gate top_clks[] __initconst = {
  495. /* TOP1 */
  496. GATE_TOP1(CLK_TOP_THEM, "them", "ahb_infra_sel", 1),
  497. GATE_TOP1(CLK_TOP_APDMA, "apdma", "ahb_infra_sel", 2),
  498. GATE_TOP1(CLK_TOP_I2C0, "i2c0", "ifr_i2c0_sel", 3),
  499. GATE_TOP1(CLK_TOP_I2C1, "i2c1", "ifr_i2c1_sel", 4),
  500. GATE_TOP1(CLK_TOP_AUXADC1, "auxadc1", "ahb_infra_sel", 5),
  501. GATE_TOP1(CLK_TOP_NFI, "nfi", "nfi1x_pad_sel", 6),
  502. GATE_TOP1(CLK_TOP_NFIECC, "nfiecc", "rg_nfiecc", 7),
  503. GATE_TOP1(CLK_TOP_DEBUGSYS, "debugsys", "rg_dbg_atclk", 8),
  504. GATE_TOP1(CLK_TOP_PWM, "pwm", "ahb_infra_sel", 9),
  505. GATE_TOP1(CLK_TOP_UART0, "uart0", "uart0_sel", 10),
  506. GATE_TOP1(CLK_TOP_UART1, "uart1", "uart1_sel", 11),
  507. GATE_TOP1(CLK_TOP_BTIF, "btif", "ahb_infra_sel", 12),
  508. GATE_TOP1(CLK_TOP_USB, "usb", "usb_78m", 13),
  509. GATE_TOP1(CLK_TOP_FLASHIF_26M, "flashif_26m", "clk26m_ck", 14),
  510. GATE_TOP1(CLK_TOP_AUXADC2, "auxadc2", "ahb_infra_sel", 15),
  511. GATE_TOP1(CLK_TOP_I2C2, "i2c2", "ifr_i2c2_sel", 16),
  512. GATE_TOP1(CLK_TOP_MSDC0, "msdc0", "msdc0_sel", 17),
  513. GATE_TOP1(CLK_TOP_MSDC1, "msdc1", "msdc1_sel", 18),
  514. GATE_TOP1(CLK_TOP_NFI2X, "nfi2x", "nfi2x_pad_sel", 19),
  515. GATE_TOP1(CLK_TOP_PMICWRAP_AP, "pwrap_ap", "clk26m_ck", 20),
  516. GATE_TOP1(CLK_TOP_SEJ, "sej", "ahb_infra_sel", 21),
  517. GATE_TOP1(CLK_TOP_MEMSLP_DLYER, "memslp_dlyer", "clk26m_ck", 22),
  518. GATE_TOP1(CLK_TOP_SPI, "spi", "spi_sel", 23),
  519. GATE_TOP1(CLK_TOP_APXGPT, "apxgpt", "clk26m_ck", 24),
  520. GATE_TOP1(CLK_TOP_AUDIO, "audio", "clk26m_ck", 25),
  521. GATE_TOP1(CLK_TOP_PMICWRAP_MD, "pwrap_md", "clk26m_ck", 27),
  522. GATE_TOP1(CLK_TOP_PMICWRAP_CONN, "pwrap_conn", "clk26m_ck", 28),
  523. GATE_TOP1(CLK_TOP_PMICWRAP_26M, "pwrap_26m", "clk26m_ck", 29),
  524. GATE_TOP1(CLK_TOP_AUX_ADC, "aux_adc", "clk26m_ck", 30),
  525. GATE_TOP1(CLK_TOP_AUX_TP, "aux_tp", "clk26m_ck", 31),
  526. /* TOP2 */
  527. GATE_TOP2(CLK_TOP_MSDC2, "msdc2", "ahb_infra_sel", 0),
  528. GATE_TOP2(CLK_TOP_RBIST, "rbist", "univpll_d12", 1),
  529. GATE_TOP2(CLK_TOP_NFI_BUS, "nfi_bus", "ahb_infra_sel", 2),
  530. GATE_TOP2(CLK_TOP_GCE, "gce", "ahb_infra_sel", 4),
  531. GATE_TOP2(CLK_TOP_TRNG, "trng", "ahb_infra_sel", 5),
  532. GATE_TOP2(CLK_TOP_SEJ_13M, "sej_13m", "clk26m_ck", 6),
  533. GATE_TOP2(CLK_TOP_AES, "aes", "ahb_infra_sel", 7),
  534. GATE_TOP2(CLK_TOP_PWM_B, "pwm_b", "rg_pwm_infra", 8),
  535. GATE_TOP2(CLK_TOP_PWM1_FB, "pwm1_fb", "rg_pwm_infra", 9),
  536. GATE_TOP2(CLK_TOP_PWM2_FB, "pwm2_fb", "rg_pwm_infra", 10),
  537. GATE_TOP2(CLK_TOP_PWM3_FB, "pwm3_fb", "rg_pwm_infra", 11),
  538. GATE_TOP2(CLK_TOP_PWM4_FB, "pwm4_fb", "rg_pwm_infra", 12),
  539. GATE_TOP2(CLK_TOP_PWM5_FB, "pwm5_fb", "rg_pwm_infra", 13),
  540. GATE_TOP2(CLK_TOP_USB_1P, "usb_1p", "usb_78m", 14),
  541. GATE_TOP2(CLK_TOP_FLASHIF_FREERUN, "flashif_freerun", "ahb_infra_sel",
  542. 15),
  543. GATE_TOP2(CLK_TOP_66M_ETH, "eth_66m", "ahb_infra_d2", 19),
  544. GATE_TOP2(CLK_TOP_133M_ETH, "eth_133m", "ahb_infra_sel", 20),
  545. GATE_TOP2(CLK_TOP_FETH_25M, "feth_25m", "ifr_eth_25m_sel", 21),
  546. GATE_TOP2(CLK_TOP_FETH_50M, "feth_50m", "rg_eth", 22),
  547. GATE_TOP2(CLK_TOP_FLASHIF_AXI, "flashif_axi", "ahb_infra_sel", 23),
  548. GATE_TOP2(CLK_TOP_USBIF, "usbif", "ahb_infra_sel", 24),
  549. GATE_TOP2(CLK_TOP_UART2, "uart2", "rg_uart2", 25),
  550. GATE_TOP2(CLK_TOP_BSI, "bsi", "ahb_infra_sel", 26),
  551. GATE_TOP2_I(CLK_TOP_MSDC0_INFRA, "msdc0_infra", "msdc0", 28),
  552. GATE_TOP2_I(CLK_TOP_MSDC1_INFRA, "msdc1_infra", "msdc1", 29),
  553. GATE_TOP2_I(CLK_TOP_MSDC2_INFRA, "msdc2_infra", "rg_msdc2", 30),
  554. GATE_TOP2(CLK_TOP_USB_78M, "usb_78m", "usb_78m_sel", 31),
  555. /* TOP3 */
  556. GATE_TOP3(CLK_TOP_RG_SPINOR, "rg_spinor", "spinor_sel", 0),
  557. GATE_TOP3(CLK_TOP_RG_MSDC2, "rg_msdc2", "msdc2_sel", 1),
  558. GATE_TOP3(CLK_TOP_RG_ETH, "rg_eth", "eth_sel", 2),
  559. GATE_TOP3(CLK_TOP_RG_AUD1, "rg_aud1", "aud1_sel", 8),
  560. GATE_TOP3(CLK_TOP_RG_AUD2, "rg_aud2", "aud2_sel", 9),
  561. GATE_TOP3(CLK_TOP_RG_AUD_ENGEN1, "rg_aud_engen1", "aud_engen1_sel", 10),
  562. GATE_TOP3(CLK_TOP_RG_AUD_ENGEN2, "rg_aud_engen2", "aud_engen2_sel", 11),
  563. GATE_TOP3(CLK_TOP_RG_I2C, "rg_i2c", "i2c_sel", 12),
  564. GATE_TOP3(CLK_TOP_RG_PWM_INFRA, "rg_pwm_infra", "pwm_sel", 13),
  565. GATE_TOP3(CLK_TOP_RG_AUD_SPDIF_IN, "rg_aud_spdif_in", "aud_spdifin_sel",
  566. 14),
  567. GATE_TOP3(CLK_TOP_RG_UART2, "rg_uart2", "uart2_sel", 15),
  568. GATE_TOP3(CLK_TOP_RG_BSI, "rg_bsi", "bsi_sel", 16),
  569. GATE_TOP3(CLK_TOP_RG_DBG_ATCLK, "rg_dbg_atclk", "dbg_atclk_sel", 17),
  570. GATE_TOP3(CLK_TOP_RG_NFIECC, "rg_nfiecc", "nfiecc_sel", 18),
  571. /* TOP4 */
  572. GATE_TOP4_I(CLK_TOP_RG_APLL1_D2_EN, "rg_apll1_d2_en", "apll1_d2", 8),
  573. GATE_TOP4_I(CLK_TOP_RG_APLL1_D4_EN, "rg_apll1_d4_en", "apll1_d4", 9),
  574. GATE_TOP4_I(CLK_TOP_RG_APLL1_D8_EN, "rg_apll1_d8_en", "apll1_d8", 10),
  575. GATE_TOP4_I(CLK_TOP_RG_APLL2_D2_EN, "rg_apll2_d2_en", "apll2_d2", 11),
  576. GATE_TOP4_I(CLK_TOP_RG_APLL2_D4_EN, "rg_apll2_d4_en", "apll2_d4", 12),
  577. GATE_TOP4_I(CLK_TOP_RG_APLL2_D8_EN, "rg_apll2_d8_en", "apll2_d8", 13),
  578. /* TOP5 */
  579. GATE_TOP5(CLK_TOP_APLL12_DIV0, "apll12_div0", "apll12_ck_div0", 0),
  580. GATE_TOP5(CLK_TOP_APLL12_DIV1, "apll12_div1", "apll12_ck_div1", 1),
  581. GATE_TOP5(CLK_TOP_APLL12_DIV2, "apll12_div2", "apll12_ck_div2", 2),
  582. GATE_TOP5(CLK_TOP_APLL12_DIV3, "apll12_div3", "apll12_ck_div3", 3),
  583. GATE_TOP5(CLK_TOP_APLL12_DIV4, "apll12_div4", "apll12_ck_div4", 4),
  584. GATE_TOP5(CLK_TOP_APLL12_DIV4B, "apll12_div4b", "apll12_ck_div4b", 5),
  585. GATE_TOP5(CLK_TOP_APLL12_DIV5, "apll12_div5", "apll12_ck_div5", 6),
  586. GATE_TOP5(CLK_TOP_APLL12_DIV5B, "apll12_div5b", "apll12_ck_div5b", 7),
  587. GATE_TOP5(CLK_TOP_APLL12_DIV6, "apll12_div6", "apll12_ck_div6", 8),
  588. };
  589. static const struct mtk_clk_desc topck_desc = {
  590. .clks = top_clks,
  591. .num_clks = ARRAY_SIZE(top_clks),
  592. .fixed_clks = fixed_clks,
  593. .num_fixed_clks = ARRAY_SIZE(fixed_clks),
  594. .factor_clks = top_divs,
  595. .num_factor_clks = ARRAY_SIZE(top_divs),
  596. .composite_clks = top_muxes,
  597. .num_composite_clks = ARRAY_SIZE(top_muxes),
  598. .divider_clks = top_adj_divs,
  599. .num_divider_clks = ARRAY_SIZE(top_adj_divs),
  600. .clk_lock = &mt8516_clk_lock,
  601. };
  602. static const struct mtk_clk_desc infra_desc = {
  603. .composite_clks = ifr_muxes,
  604. .num_composite_clks = ARRAY_SIZE(ifr_muxes),
  605. .clk_lock = &mt8516_clk_lock,
  606. };
  607. static const struct of_device_id of_match_clk_mt8516[] = {
  608. { .compatible = "mediatek,mt8516-topckgen", .data = &topck_desc },
  609. { .compatible = "mediatek,mt8516-infracfg", .data = &infra_desc },
  610. { /* sentinel */ }
  611. };
  612. MODULE_DEVICE_TABLE(of, of_match_clk_mt8516);
  613. static struct platform_driver clk_mt8516_drv = {
  614. .probe = mtk_clk_simple_probe,
  615. .remove = mtk_clk_simple_remove,
  616. .driver = {
  617. .name = "clk-mt8516",
  618. .of_match_table = of_match_clk_mt8516,
  619. },
  620. };
  621. module_platform_driver(clk_mt8516_drv);
  622. MODULE_DESCRIPTION("MediaTek MT8516 clocks driver");
  623. MODULE_LICENSE("GPL");