clk-mt7622.c 22 KB

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