clk-mt7622.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017 MediaTek Inc.
  4. * Author: Chen Zhong <[email protected]>
  5. * Sean Wang <[email protected]>
  6. */
  7. #include <linux/clk-provider.h>
  8. #include <linux/of.h>
  9. #include <linux/of_address.h>
  10. #include <linux/of_device.h>
  11. #include <linux/platform_device.h>
  12. #include "clk-cpumux.h"
  13. #include "clk-gate.h"
  14. #include "clk-mtk.h"
  15. #include "clk-pll.h"
  16. #include <dt-bindings/clock/mt7622-clk.h>
  17. #include <linux/clk.h> /* for consumer */
  18. #define MT7622_PLL_FMAX (2500UL * MHZ)
  19. #define CON0_MT7622_RST_BAR BIT(27)
  20. #define PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,\
  21. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  22. _pcw_shift, _div_table, _parent_name) { \
  23. .id = _id, \
  24. .name = _name, \
  25. .reg = _reg, \
  26. .pwr_reg = _pwr_reg, \
  27. .en_mask = _en_mask, \
  28. .flags = _flags, \
  29. .rst_bar_mask = CON0_MT7622_RST_BAR, \
  30. .fmax = MT7622_PLL_FMAX, \
  31. .pcwbits = _pcwbits, \
  32. .pd_reg = _pd_reg, \
  33. .pd_shift = _pd_shift, \
  34. .tuner_reg = _tuner_reg, \
  35. .pcw_reg = _pcw_reg, \
  36. .pcw_shift = _pcw_shift, \
  37. .div_table = _div_table, \
  38. .parent_name = _parent_name, \
  39. }
  40. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  41. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  42. _pcw_shift) \
  43. PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,\
  44. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
  45. NULL, "clkxtal")
  46. #define GATE_APMIXED_AO(_id, _name, _parent, _shift) \
  47. GATE_MTK_FLAGS(_id, _name, _parent, &apmixed_cg_regs, _shift, \
  48. &mtk_clk_gate_ops_no_setclr_inv, CLK_IS_CRITICAL)
  49. #define GATE_INFRA(_id, _name, _parent, _shift) \
  50. GATE_MTK(_id, _name, _parent, &infra_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  51. #define GATE_TOP0(_id, _name, _parent, _shift) \
  52. GATE_MTK(_id, _name, _parent, &top0_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr)
  53. #define GATE_TOP1(_id, _name, _parent, _shift) \
  54. GATE_MTK(_id, _name, _parent, &top1_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr)
  55. #define GATE_PERI0(_id, _name, _parent, _shift) \
  56. GATE_MTK(_id, _name, _parent, &peri0_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  57. #define GATE_PERI0_AO(_id, _name, _parent, _shift) \
  58. GATE_MTK_FLAGS(_id, _name, _parent, &peri0_cg_regs, _shift, \
  59. &mtk_clk_gate_ops_setclr, CLK_IS_CRITICAL)
  60. #define GATE_PERI1(_id, _name, _parent, _shift) \
  61. GATE_MTK(_id, _name, _parent, &peri1_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  62. static DEFINE_SPINLOCK(mt7622_clk_lock);
  63. static const char * const infra_mux1_parents[] = {
  64. "clkxtal",
  65. "armpll",
  66. "main_core_en",
  67. "armpll"
  68. };
  69. static const char * const axi_parents[] = {
  70. "clkxtal",
  71. "syspll1_d2",
  72. "syspll_d5",
  73. "syspll1_d4",
  74. "univpll_d5",
  75. "univpll2_d2",
  76. "univpll_d7"
  77. };
  78. static const char * const mem_parents[] = {
  79. "clkxtal",
  80. "dmpll_ck"
  81. };
  82. static const char * const ddrphycfg_parents[] = {
  83. "clkxtal",
  84. "syspll1_d8"
  85. };
  86. static const char * const eth_parents[] = {
  87. "clkxtal",
  88. "syspll1_d2",
  89. "univpll1_d2",
  90. "syspll1_d4",
  91. "univpll_d5",
  92. "clk_null",
  93. "univpll_d7"
  94. };
  95. static const char * const pwm_parents[] = {
  96. "clkxtal",
  97. "univpll2_d4"
  98. };
  99. static const char * const f10m_ref_parents[] = {
  100. "clkxtal",
  101. "syspll4_d16"
  102. };
  103. static const char * const nfi_infra_parents[] = {
  104. "clkxtal",
  105. "clkxtal",
  106. "clkxtal",
  107. "clkxtal",
  108. "clkxtal",
  109. "clkxtal",
  110. "clkxtal",
  111. "clkxtal",
  112. "univpll2_d8",
  113. "syspll1_d8",
  114. "univpll1_d8",
  115. "syspll4_d2",
  116. "univpll2_d4",
  117. "univpll3_d2",
  118. "syspll1_d4"
  119. };
  120. static const char * const flash_parents[] = {
  121. "clkxtal",
  122. "univpll_d80_d4",
  123. "syspll2_d8",
  124. "syspll3_d4",
  125. "univpll3_d4",
  126. "univpll1_d8",
  127. "syspll2_d4",
  128. "univpll2_d4"
  129. };
  130. static const char * const uart_parents[] = {
  131. "clkxtal",
  132. "univpll2_d8"
  133. };
  134. static const char * const spi0_parents[] = {
  135. "clkxtal",
  136. "syspll3_d2",
  137. "clkxtal",
  138. "syspll2_d4",
  139. "syspll4_d2",
  140. "univpll2_d4",
  141. "univpll1_d8",
  142. "clkxtal"
  143. };
  144. static const char * const spi1_parents[] = {
  145. "clkxtal",
  146. "syspll3_d2",
  147. "clkxtal",
  148. "syspll4_d4",
  149. "syspll4_d2",
  150. "univpll2_d4",
  151. "univpll1_d8",
  152. "clkxtal"
  153. };
  154. static const char * const msdc30_0_parents[] = {
  155. "clkxtal",
  156. "univpll2_d16",
  157. "univ48m"
  158. };
  159. static const char * const a1sys_hp_parents[] = {
  160. "clkxtal",
  161. "aud1pll_ck",
  162. "aud2pll_ck",
  163. "clkxtal"
  164. };
  165. static const char * const intdir_parents[] = {
  166. "clkxtal",
  167. "syspll_d2",
  168. "univpll_d2",
  169. "sgmiipll_ck"
  170. };
  171. static const char * const aud_intbus_parents[] = {
  172. "clkxtal",
  173. "syspll1_d4",
  174. "syspll4_d2",
  175. "syspll3_d2"
  176. };
  177. static const char * const pmicspi_parents[] = {
  178. "clkxtal",
  179. "clk_null",
  180. "clk_null",
  181. "clk_null",
  182. "clk_null",
  183. "univpll2_d16"
  184. };
  185. static const char * const atb_parents[] = {
  186. "clkxtal",
  187. "syspll1_d2",
  188. "syspll_d5"
  189. };
  190. static const char * const audio_parents[] = {
  191. "clkxtal",
  192. "syspll3_d4",
  193. "syspll4_d4",
  194. "univpll1_d16"
  195. };
  196. static const char * const usb20_parents[] = {
  197. "clkxtal",
  198. "univpll3_d4",
  199. "syspll1_d8",
  200. "clkxtal"
  201. };
  202. static const char * const aud1_parents[] = {
  203. "clkxtal",
  204. "aud1pll_ck"
  205. };
  206. static const char * const aud2_parents[] = {
  207. "clkxtal",
  208. "aud2pll_ck"
  209. };
  210. static const char * const asm_l_parents[] = {
  211. "clkxtal",
  212. "syspll_d5",
  213. "univpll2_d2",
  214. "univpll2_d4"
  215. };
  216. static const char * const apll1_ck_parents[] = {
  217. "aud1_sel",
  218. "aud2_sel"
  219. };
  220. static const char * const peribus_ck_parents[] = {
  221. "syspll1_d8",
  222. "syspll1_d4"
  223. };
  224. static const struct mtk_gate_regs apmixed_cg_regs = {
  225. .set_ofs = 0x8,
  226. .clr_ofs = 0x8,
  227. .sta_ofs = 0x8,
  228. };
  229. static const struct mtk_gate_regs infra_cg_regs = {
  230. .set_ofs = 0x40,
  231. .clr_ofs = 0x44,
  232. .sta_ofs = 0x48,
  233. };
  234. static const struct mtk_gate_regs top0_cg_regs = {
  235. .set_ofs = 0x120,
  236. .clr_ofs = 0x120,
  237. .sta_ofs = 0x120,
  238. };
  239. static const struct mtk_gate_regs top1_cg_regs = {
  240. .set_ofs = 0x128,
  241. .clr_ofs = 0x128,
  242. .sta_ofs = 0x128,
  243. };
  244. static const struct mtk_gate_regs peri0_cg_regs = {
  245. .set_ofs = 0x8,
  246. .clr_ofs = 0x10,
  247. .sta_ofs = 0x18,
  248. };
  249. static const struct mtk_gate_regs peri1_cg_regs = {
  250. .set_ofs = 0xC,
  251. .clr_ofs = 0x14,
  252. .sta_ofs = 0x1C,
  253. };
  254. static const struct mtk_pll_data plls[] = {
  255. PLL(CLK_APMIXED_ARMPLL, "armpll", 0x0200, 0x020C, 0,
  256. PLL_AO, 21, 0x0204, 24, 0, 0x0204, 0),
  257. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0210, 0x021C, 0,
  258. HAVE_RST_BAR, 21, 0x0214, 24, 0, 0x0214, 0),
  259. PLL(CLK_APMIXED_UNIV2PLL, "univ2pll", 0x0220, 0x022C, 0,
  260. HAVE_RST_BAR, 7, 0x0224, 24, 0, 0x0224, 14),
  261. PLL(CLK_APMIXED_ETH1PLL, "eth1pll", 0x0300, 0x0310, 0,
  262. 0, 21, 0x0300, 1, 0, 0x0304, 0),
  263. PLL(CLK_APMIXED_ETH2PLL, "eth2pll", 0x0314, 0x0320, 0,
  264. 0, 21, 0x0314, 1, 0, 0x0318, 0),
  265. PLL(CLK_APMIXED_AUD1PLL, "aud1pll", 0x0324, 0x0330, 0,
  266. 0, 31, 0x0324, 1, 0, 0x0328, 0),
  267. PLL(CLK_APMIXED_AUD2PLL, "aud2pll", 0x0334, 0x0340, 0,
  268. 0, 31, 0x0334, 1, 0, 0x0338, 0),
  269. PLL(CLK_APMIXED_TRGPLL, "trgpll", 0x0344, 0x0354, 0,
  270. 0, 21, 0x0344, 1, 0, 0x0348, 0),
  271. PLL(CLK_APMIXED_SGMIPLL, "sgmipll", 0x0358, 0x0368, 0,
  272. 0, 21, 0x0358, 1, 0, 0x035C, 0),
  273. };
  274. static const struct mtk_gate apmixed_clks[] = {
  275. GATE_APMIXED_AO(CLK_APMIXED_MAIN_CORE_EN, "main_core_en", "mainpll", 5),
  276. };
  277. static const struct mtk_gate infra_clks[] = {
  278. GATE_INFRA(CLK_INFRA_DBGCLK_PD, "infra_dbgclk_pd", "axi_sel", 0),
  279. GATE_INFRA(CLK_INFRA_TRNG, "trng_ck", "axi_sel", 2),
  280. GATE_INFRA(CLK_INFRA_AUDIO_PD, "infra_audio_pd", "aud_intbus_sel", 5),
  281. GATE_INFRA(CLK_INFRA_IRRX_PD, "infra_irrx_pd", "irrx_sel", 16),
  282. GATE_INFRA(CLK_INFRA_APXGPT_PD, "infra_apxgpt_pd", "f10m_ref_sel", 18),
  283. GATE_INFRA(CLK_INFRA_PMIC_PD, "infra_pmic_pd", "pmicspi_sel", 22),
  284. };
  285. static const struct mtk_fixed_clk top_fixed_clks[] = {
  286. FIXED_CLK(CLK_TOP_TO_U2_PHY, "to_u2_phy", "clkxtal",
  287. 31250000),
  288. FIXED_CLK(CLK_TOP_TO_U2_PHY_1P, "to_u2_phy_1p", "clkxtal",
  289. 31250000),
  290. FIXED_CLK(CLK_TOP_PCIE0_PIPE_EN, "pcie0_pipe_en", "clkxtal",
  291. 125000000),
  292. FIXED_CLK(CLK_TOP_PCIE1_PIPE_EN, "pcie1_pipe_en", "clkxtal",
  293. 125000000),
  294. FIXED_CLK(CLK_TOP_SSUSB_TX250M, "ssusb_tx250m", "clkxtal",
  295. 250000000),
  296. FIXED_CLK(CLK_TOP_SSUSB_EQ_RX250M, "ssusb_eq_rx250m", "clkxtal",
  297. 250000000),
  298. FIXED_CLK(CLK_TOP_SSUSB_CDR_REF, "ssusb_cdr_ref", "clkxtal",
  299. 33333333),
  300. FIXED_CLK(CLK_TOP_SSUSB_CDR_FB, "ssusb_cdr_fb", "clkxtal",
  301. 50000000),
  302. FIXED_CLK(CLK_TOP_SATA_ASIC, "sata_asic", "clkxtal",
  303. 50000000),
  304. FIXED_CLK(CLK_TOP_SATA_RBC, "sata_rbc", "clkxtal",
  305. 50000000),
  306. };
  307. static const struct mtk_fixed_factor top_divs[] = {
  308. FACTOR(CLK_TOP_TO_USB3_SYS, "to_usb3_sys", "eth1pll", 1, 4),
  309. FACTOR(CLK_TOP_P1_1MHZ, "p1_1mhz", "eth1pll", 1, 500),
  310. FACTOR(CLK_TOP_4MHZ, "free_run_4mhz", "eth1pll", 1, 125),
  311. FACTOR(CLK_TOP_P0_1MHZ, "p0_1mhz", "eth1pll", 1, 500),
  312. FACTOR(CLK_TOP_TXCLK_SRC_PRE, "txclk_src_pre", "sgmiipll_d2", 1, 1),
  313. FACTOR(CLK_TOP_RTC, "rtc", "clkxtal", 1, 1024),
  314. FACTOR(CLK_TOP_MEMPLL, "mempll", "clkxtal", 32, 1),
  315. FACTOR(CLK_TOP_DMPLL, "dmpll_ck", "mempll", 1, 1),
  316. FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "mainpll", 1, 2),
  317. FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "mainpll", 1, 4),
  318. FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "mainpll", 1, 8),
  319. FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "mainpll", 1, 16),
  320. FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "mainpll", 1, 12),
  321. FACTOR(CLK_TOP_SYSPLL2_D8, "syspll2_d8", "mainpll", 1, 24),
  322. FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1, 5),
  323. FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "mainpll", 1, 10),
  324. FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "mainpll", 1, 20),
  325. FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "mainpll", 1, 14),
  326. FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "mainpll", 1, 28),
  327. FACTOR(CLK_TOP_SYSPLL4_D16, "syspll4_d16", "mainpll", 1, 112),
  328. FACTOR(CLK_TOP_UNIVPLL, "univpll", "univ2pll", 1, 2),
  329. FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2),
  330. FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll", 1, 4),
  331. FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll", 1, 8),
  332. FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll", 1, 16),
  333. FACTOR(CLK_TOP_UNIVPLL1_D16, "univpll1_d16", "univpll", 1, 32),
  334. FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll", 1, 6),
  335. FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll", 1, 12),
  336. FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll", 1, 24),
  337. FACTOR(CLK_TOP_UNIVPLL2_D16, "univpll2_d16", "univpll", 1, 48),
  338. FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
  339. FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll", 1, 10),
  340. FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll", 1, 20),
  341. FACTOR(CLK_TOP_UNIVPLL3_D16, "univpll3_d16", "univpll", 1, 80),
  342. FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1, 7),
  343. FACTOR(CLK_TOP_UNIVPLL_D80_D4, "univpll_d80_d4", "univpll", 1, 320),
  344. FACTOR(CLK_TOP_UNIV48M, "univ48m", "univpll", 1, 25),
  345. FACTOR(CLK_TOP_SGMIIPLL, "sgmiipll_ck", "sgmipll", 1, 1),
  346. FACTOR(CLK_TOP_SGMIIPLL_D2, "sgmiipll_d2", "sgmipll", 1, 2),
  347. FACTOR(CLK_TOP_AUD1PLL, "aud1pll_ck", "aud1pll", 1, 1),
  348. FACTOR(CLK_TOP_AUD2PLL, "aud2pll_ck", "aud2pll", 1, 1),
  349. FACTOR(CLK_TOP_AUD_I2S2_MCK, "aud_i2s2_mck", "i2s2_mck_sel", 1, 2),
  350. FACTOR(CLK_TOP_TO_USB3_REF, "to_usb3_ref", "univpll2_d4", 1, 4),
  351. FACTOR(CLK_TOP_PCIE1_MAC_EN, "pcie1_mac_en", "univpll1_d4", 1, 1),
  352. FACTOR(CLK_TOP_PCIE0_MAC_EN, "pcie0_mac_en", "univpll1_d4", 1, 1),
  353. FACTOR(CLK_TOP_ETH_500M, "eth_500m", "eth1pll", 1, 1),
  354. };
  355. static const struct mtk_gate top_clks[] = {
  356. /* TOP0 */
  357. GATE_TOP0(CLK_TOP_APLL1_DIV_PD, "apll1_ck_div_pd", "apll1_ck_div", 0),
  358. GATE_TOP0(CLK_TOP_APLL2_DIV_PD, "apll2_ck_div_pd", "apll2_ck_div", 1),
  359. GATE_TOP0(CLK_TOP_I2S0_MCK_DIV_PD, "i2s0_mck_div_pd", "i2s0_mck_div",
  360. 2),
  361. GATE_TOP0(CLK_TOP_I2S1_MCK_DIV_PD, "i2s1_mck_div_pd", "i2s1_mck_div",
  362. 3),
  363. GATE_TOP0(CLK_TOP_I2S2_MCK_DIV_PD, "i2s2_mck_div_pd", "i2s2_mck_div",
  364. 4),
  365. GATE_TOP0(CLK_TOP_I2S3_MCK_DIV_PD, "i2s3_mck_div_pd", "i2s3_mck_div",
  366. 5),
  367. /* TOP1 */
  368. GATE_TOP1(CLK_TOP_A1SYS_HP_DIV_PD, "a1sys_div_pd", "a1sys_div", 0),
  369. GATE_TOP1(CLK_TOP_A2SYS_HP_DIV_PD, "a2sys_div_pd", "a2sys_div", 16),
  370. };
  371. static const struct mtk_clk_divider top_adj_divs[] = {
  372. DIV_ADJ(CLK_TOP_APLL1_DIV, "apll1_ck_div", "apll1_ck_sel",
  373. 0x120, 24, 3),
  374. DIV_ADJ(CLK_TOP_APLL2_DIV, "apll2_ck_div", "apll2_ck_sel",
  375. 0x120, 28, 3),
  376. DIV_ADJ(CLK_TOP_I2S0_MCK_DIV, "i2s0_mck_div", "i2s0_mck_sel",
  377. 0x124, 0, 7),
  378. DIV_ADJ(CLK_TOP_I2S1_MCK_DIV, "i2s1_mck_div", "i2s1_mck_sel",
  379. 0x124, 8, 7),
  380. DIV_ADJ(CLK_TOP_I2S2_MCK_DIV, "i2s2_mck_div", "aud_i2s2_mck",
  381. 0x124, 16, 7),
  382. DIV_ADJ(CLK_TOP_I2S3_MCK_DIV, "i2s3_mck_div", "i2s3_mck_sel",
  383. 0x124, 24, 7),
  384. DIV_ADJ(CLK_TOP_A1SYS_HP_DIV, "a1sys_div", "a1sys_hp_sel",
  385. 0x128, 8, 7),
  386. DIV_ADJ(CLK_TOP_A2SYS_HP_DIV, "a2sys_div", "a2sys_hp_sel",
  387. 0x128, 24, 7),
  388. };
  389. static const struct mtk_gate peri_clks[] = {
  390. /* PERI0 */
  391. GATE_PERI0(CLK_PERI_THERM_PD, "peri_therm_pd", "axi_sel", 1),
  392. GATE_PERI0(CLK_PERI_PWM1_PD, "peri_pwm1_pd", "clkxtal", 2),
  393. GATE_PERI0(CLK_PERI_PWM2_PD, "peri_pwm2_pd", "clkxtal", 3),
  394. GATE_PERI0(CLK_PERI_PWM3_PD, "peri_pwm3_pd", "clkxtal", 4),
  395. GATE_PERI0(CLK_PERI_PWM4_PD, "peri_pwm4_pd", "clkxtal", 5),
  396. GATE_PERI0(CLK_PERI_PWM5_PD, "peri_pwm5_pd", "clkxtal", 6),
  397. GATE_PERI0(CLK_PERI_PWM6_PD, "peri_pwm6_pd", "clkxtal", 7),
  398. GATE_PERI0(CLK_PERI_PWM7_PD, "peri_pwm7_pd", "clkxtal", 8),
  399. GATE_PERI0(CLK_PERI_PWM_PD, "peri_pwm_pd", "clkxtal", 9),
  400. GATE_PERI0(CLK_PERI_AP_DMA_PD, "peri_ap_dma_pd", "axi_sel", 12),
  401. GATE_PERI0(CLK_PERI_MSDC30_0_PD, "peri_msdc30_0", "msdc30_0_sel", 13),
  402. GATE_PERI0(CLK_PERI_MSDC30_1_PD, "peri_msdc30_1", "msdc30_1_sel", 14),
  403. GATE_PERI0_AO(CLK_PERI_UART0_PD, "peri_uart0_pd", "axi_sel", 17),
  404. GATE_PERI0(CLK_PERI_UART1_PD, "peri_uart1_pd", "axi_sel", 18),
  405. GATE_PERI0(CLK_PERI_UART2_PD, "peri_uart2_pd", "axi_sel", 19),
  406. GATE_PERI0(CLK_PERI_UART3_PD, "peri_uart3_pd", "axi_sel", 20),
  407. GATE_PERI0(CLK_PERI_UART4_PD, "peri_uart4_pd", "axi_sel", 21),
  408. GATE_PERI0(CLK_PERI_BTIF_PD, "peri_btif_pd", "axi_sel", 22),
  409. GATE_PERI0(CLK_PERI_I2C0_PD, "peri_i2c0_pd", "axi_sel", 23),
  410. GATE_PERI0(CLK_PERI_I2C1_PD, "peri_i2c1_pd", "axi_sel", 24),
  411. GATE_PERI0(CLK_PERI_I2C2_PD, "peri_i2c2_pd", "axi_sel", 25),
  412. GATE_PERI0(CLK_PERI_SPI1_PD, "peri_spi1_pd", "spi1_sel", 26),
  413. GATE_PERI0(CLK_PERI_AUXADC_PD, "peri_auxadc_pd", "clkxtal", 27),
  414. GATE_PERI0(CLK_PERI_SPI0_PD, "peri_spi0_pd", "spi0_sel", 28),
  415. GATE_PERI0(CLK_PERI_SNFI_PD, "peri_snfi_pd", "nfi_infra_sel", 29),
  416. GATE_PERI0(CLK_PERI_NFI_PD, "peri_nfi_pd", "axi_sel", 30),
  417. GATE_PERI0(CLK_PERI_NFIECC_PD, "peri_nfiecc_pd", "axi_sel", 31),
  418. /* PERI1 */
  419. GATE_PERI1(CLK_PERI_FLASH_PD, "peri_flash_pd", "flash_sel", 1),
  420. GATE_PERI1(CLK_PERI_IRTX_PD, "peri_irtx_pd", "irtx_sel", 2),
  421. };
  422. static struct mtk_composite infra_muxes[] = {
  423. MUX(CLK_INFRA_MUX1_SEL, "infra_mux1_sel", infra_mux1_parents,
  424. 0x000, 2, 2),
  425. };
  426. static struct mtk_composite top_muxes[] = {
  427. /* CLK_CFG_0 */
  428. MUX_GATE_FLAGS(CLK_TOP_AXI_SEL, "axi_sel", axi_parents,
  429. 0x040, 0, 3, 7, CLK_IS_CRITICAL),
  430. MUX_GATE_FLAGS(CLK_TOP_MEM_SEL, "mem_sel", mem_parents,
  431. 0x040, 8, 1, 15, CLK_IS_CRITICAL),
  432. MUX_GATE_FLAGS(CLK_TOP_DDRPHYCFG_SEL, "ddrphycfg_sel", ddrphycfg_parents,
  433. 0x040, 16, 1, 23, CLK_IS_CRITICAL),
  434. MUX_GATE(CLK_TOP_ETH_SEL, "eth_sel", eth_parents,
  435. 0x040, 24, 3, 31),
  436. /* CLK_CFG_1 */
  437. MUX_GATE(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents,
  438. 0x050, 0, 2, 7),
  439. MUX_GATE(CLK_TOP_F10M_REF_SEL, "f10m_ref_sel", f10m_ref_parents,
  440. 0x050, 8, 1, 15),
  441. MUX_GATE(CLK_TOP_NFI_INFRA_SEL, "nfi_infra_sel", nfi_infra_parents,
  442. 0x050, 16, 4, 23),
  443. MUX_GATE(CLK_TOP_FLASH_SEL, "flash_sel", flash_parents,
  444. 0x050, 24, 3, 31),
  445. /* CLK_CFG_2 */
  446. MUX_GATE(CLK_TOP_UART_SEL, "uart_sel", uart_parents,
  447. 0x060, 0, 1, 7),
  448. MUX_GATE(CLK_TOP_SPI0_SEL, "spi0_sel", spi0_parents,
  449. 0x060, 8, 3, 15),
  450. MUX_GATE(CLK_TOP_SPI1_SEL, "spi1_sel", spi1_parents,
  451. 0x060, 16, 3, 23),
  452. MUX_GATE(CLK_TOP_MSDC50_0_SEL, "msdc50_0_sel", uart_parents,
  453. 0x060, 24, 3, 31),
  454. /* CLK_CFG_3 */
  455. MUX_GATE(CLK_TOP_MSDC30_0_SEL, "msdc30_0_sel", msdc30_0_parents,
  456. 0x070, 0, 3, 7),
  457. MUX_GATE(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel", msdc30_0_parents,
  458. 0x070, 8, 3, 15),
  459. MUX_GATE(CLK_TOP_A1SYS_HP_SEL, "a1sys_hp_sel", a1sys_hp_parents,
  460. 0x070, 16, 2, 23),
  461. MUX_GATE(CLK_TOP_A2SYS_HP_SEL, "a2sys_hp_sel", a1sys_hp_parents,
  462. 0x070, 24, 2, 31),
  463. /* CLK_CFG_4 */
  464. MUX_GATE(CLK_TOP_INTDIR_SEL, "intdir_sel", intdir_parents,
  465. 0x080, 0, 2, 7),
  466. MUX_GATE(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel", aud_intbus_parents,
  467. 0x080, 8, 2, 15),
  468. MUX_GATE(CLK_TOP_PMICSPI_SEL, "pmicspi_sel", pmicspi_parents,
  469. 0x080, 16, 3, 23),
  470. MUX_GATE(CLK_TOP_SCP_SEL, "scp_sel", ddrphycfg_parents,
  471. 0x080, 24, 2, 31),
  472. /* CLK_CFG_5 */
  473. MUX_GATE(CLK_TOP_ATB_SEL, "atb_sel", atb_parents,
  474. 0x090, 0, 2, 7),
  475. MUX_GATE(CLK_TOP_HIF_SEL, "hif_sel", eth_parents,
  476. 0x090, 8, 3, 15),
  477. MUX_GATE(CLK_TOP_AUDIO_SEL, "audio_sel", audio_parents,
  478. 0x090, 16, 2, 23),
  479. MUX_GATE(CLK_TOP_U2_SEL, "usb20_sel", usb20_parents,
  480. 0x090, 24, 2, 31),
  481. /* CLK_CFG_6 */
  482. MUX_GATE(CLK_TOP_AUD1_SEL, "aud1_sel", aud1_parents,
  483. 0x0A0, 0, 1, 7),
  484. MUX_GATE(CLK_TOP_AUD2_SEL, "aud2_sel", aud2_parents,
  485. 0x0A0, 8, 1, 15),
  486. MUX_GATE(CLK_TOP_IRRX_SEL, "irrx_sel", f10m_ref_parents,
  487. 0x0A0, 16, 1, 23),
  488. MUX_GATE(CLK_TOP_IRTX_SEL, "irtx_sel", f10m_ref_parents,
  489. 0x0A0, 24, 1, 31),
  490. /* CLK_CFG_7 */
  491. MUX_GATE(CLK_TOP_ASM_L_SEL, "asm_l_sel", asm_l_parents,
  492. 0x0B0, 0, 2, 7),
  493. MUX_GATE(CLK_TOP_ASM_M_SEL, "asm_m_sel", asm_l_parents,
  494. 0x0B0, 8, 2, 15),
  495. MUX_GATE(CLK_TOP_ASM_H_SEL, "asm_h_sel", asm_l_parents,
  496. 0x0B0, 16, 2, 23),
  497. /* CLK_AUDDIV_0 */
  498. MUX(CLK_TOP_APLL1_SEL, "apll1_ck_sel", apll1_ck_parents,
  499. 0x120, 6, 1),
  500. MUX(CLK_TOP_APLL2_SEL, "apll2_ck_sel", apll1_ck_parents,
  501. 0x120, 7, 1),
  502. MUX(CLK_TOP_I2S0_MCK_SEL, "i2s0_mck_sel", apll1_ck_parents,
  503. 0x120, 8, 1),
  504. MUX(CLK_TOP_I2S1_MCK_SEL, "i2s1_mck_sel", apll1_ck_parents,
  505. 0x120, 9, 1),
  506. MUX(CLK_TOP_I2S2_MCK_SEL, "i2s2_mck_sel", apll1_ck_parents,
  507. 0x120, 10, 1),
  508. MUX(CLK_TOP_I2S3_MCK_SEL, "i2s3_mck_sel", apll1_ck_parents,
  509. 0x120, 11, 1),
  510. };
  511. static struct mtk_composite peri_muxes[] = {
  512. /* PERI_GLOBALCON_CKSEL */
  513. MUX(CLK_PERIBUS_SEL, "peribus_ck_sel", peribus_ck_parents, 0x05C, 0, 1),
  514. };
  515. static u16 infrasys_rst_ofs[] = { 0x30, };
  516. static u16 pericfg_rst_ofs[] = { 0x0, 0x4, };
  517. static const struct mtk_clk_rst_desc clk_rst_desc[] = {
  518. /* infrasys */
  519. {
  520. .version = MTK_RST_SIMPLE,
  521. .rst_bank_ofs = infrasys_rst_ofs,
  522. .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
  523. },
  524. /* pericfg */
  525. {
  526. .version = MTK_RST_SIMPLE,
  527. .rst_bank_ofs = pericfg_rst_ofs,
  528. .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
  529. },
  530. };
  531. static int mtk_topckgen_init(struct platform_device *pdev)
  532. {
  533. struct clk_hw_onecell_data *clk_data;
  534. void __iomem *base;
  535. struct device_node *node = pdev->dev.of_node;
  536. base = devm_platform_ioremap_resource(pdev, 0);
  537. if (IS_ERR(base))
  538. return PTR_ERR(base);
  539. clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
  540. mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
  541. clk_data);
  542. mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs),
  543. clk_data);
  544. mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes),
  545. base, &mt7622_clk_lock, clk_data);
  546. mtk_clk_register_dividers(top_adj_divs, ARRAY_SIZE(top_adj_divs),
  547. base, &mt7622_clk_lock, clk_data);
  548. mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
  549. clk_data);
  550. return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  551. }
  552. static int mtk_infrasys_init(struct platform_device *pdev)
  553. {
  554. struct device_node *node = pdev->dev.of_node;
  555. struct clk_hw_onecell_data *clk_data;
  556. int r;
  557. clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
  558. mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
  559. clk_data);
  560. mtk_clk_register_cpumuxes(node, infra_muxes, ARRAY_SIZE(infra_muxes),
  561. clk_data);
  562. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get,
  563. clk_data);
  564. if (r)
  565. return r;
  566. mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc[0]);
  567. return 0;
  568. }
  569. static int mtk_apmixedsys_init(struct platform_device *pdev)
  570. {
  571. struct clk_hw_onecell_data *clk_data;
  572. struct device_node *node = pdev->dev.of_node;
  573. clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
  574. if (!clk_data)
  575. return -ENOMEM;
  576. mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls),
  577. clk_data);
  578. mtk_clk_register_gates(node, apmixed_clks,
  579. ARRAY_SIZE(apmixed_clks), clk_data);
  580. return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  581. }
  582. static int mtk_pericfg_init(struct platform_device *pdev)
  583. {
  584. struct clk_hw_onecell_data *clk_data;
  585. void __iomem *base;
  586. int r;
  587. struct device_node *node = pdev->dev.of_node;
  588. base = devm_platform_ioremap_resource(pdev, 0);
  589. if (IS_ERR(base))
  590. return PTR_ERR(base);
  591. clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
  592. mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks),
  593. clk_data);
  594. mtk_clk_register_composites(peri_muxes, ARRAY_SIZE(peri_muxes), base,
  595. &mt7622_clk_lock, clk_data);
  596. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  597. if (r)
  598. return r;
  599. mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc[1]);
  600. return 0;
  601. }
  602. static const struct of_device_id of_match_clk_mt7622[] = {
  603. {
  604. .compatible = "mediatek,mt7622-apmixedsys",
  605. .data = mtk_apmixedsys_init,
  606. }, {
  607. .compatible = "mediatek,mt7622-infracfg",
  608. .data = mtk_infrasys_init,
  609. }, {
  610. .compatible = "mediatek,mt7622-topckgen",
  611. .data = mtk_topckgen_init,
  612. }, {
  613. .compatible = "mediatek,mt7622-pericfg",
  614. .data = mtk_pericfg_init,
  615. }, {
  616. /* sentinel */
  617. }
  618. };
  619. static int clk_mt7622_probe(struct platform_device *pdev)
  620. {
  621. int (*clk_init)(struct platform_device *);
  622. int r;
  623. clk_init = of_device_get_match_data(&pdev->dev);
  624. if (!clk_init)
  625. return -EINVAL;
  626. r = clk_init(pdev);
  627. if (r)
  628. dev_err(&pdev->dev,
  629. "could not register clock provider: %s: %d\n",
  630. pdev->name, r);
  631. return r;
  632. }
  633. static struct platform_driver clk_mt7622_drv = {
  634. .probe = clk_mt7622_probe,
  635. .driver = {
  636. .name = "clk-mt7622",
  637. .of_match_table = of_match_clk_mt7622,
  638. },
  639. };
  640. static int clk_mt7622_init(void)
  641. {
  642. return platform_driver_register(&clk_mt7622_drv);
  643. }
  644. arch_initcall(clk_mt7622_init);