231-v6.4-clk-mediatek-add-MT7981-clock-support.patch 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. From 8efeeb9c8b4ecf4fb4a74be9403aba951403bbaa Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Thu, 26 Jan 2023 03:34:24 +0000
  4. Subject: [PATCH] clk: mediatek: add MT7981 clock support
  5. Add MT7981 clock support, include topckgen, apmixedsys, infracfg and
  6. ethernet subsystem clocks.
  7. The drivers are based on clk-mt7981.c which can be found in MediaTek's
  8. SDK sources. To be fit for upstream inclusion the driver has been split
  9. into clock domains and the infracfg part has been significantly
  10. de-bloated by removing all the 1:1 factors (aliases).
  11. Signed-off-by: Jianhui Zhao <[email protected]>
  12. Signed-off-by: Daniel Golle <[email protected]>
  13. Link: https://lore.kernel.org/r/8136eb5b2049177bc2f6d3e0f2aefecc342d626f.1674703830.git.daniel@makrotopia.org
  14. Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
  15. [[email protected]: Add module license]
  16. Signed-off-by: Stephen Boyd <[email protected]>
  17. ---
  18. drivers/clk/mediatek/Kconfig | 17 +
  19. drivers/clk/mediatek/Makefile | 4 +
  20. drivers/clk/mediatek/clk-mt7981-apmixed.c | 102 +++++
  21. drivers/clk/mediatek/clk-mt7981-eth.c | 118 ++++++
  22. drivers/clk/mediatek/clk-mt7981-infracfg.c | 207 ++++++++++
  23. drivers/clk/mediatek/clk-mt7981-topckgen.c | 422 +++++++++++++++++++++
  24. 6 files changed, 870 insertions(+)
  25. create mode 100644 drivers/clk/mediatek/clk-mt7981-apmixed.c
  26. create mode 100644 drivers/clk/mediatek/clk-mt7981-eth.c
  27. create mode 100644 drivers/clk/mediatek/clk-mt7981-infracfg.c
  28. create mode 100644 drivers/clk/mediatek/clk-mt7981-topckgen.c
  29. --- a/drivers/clk/mediatek/Kconfig
  30. +++ b/drivers/clk/mediatek/Kconfig
  31. @@ -381,6 +381,23 @@ config COMMON_CLK_MT7629_HIFSYS
  32. This driver supports MediaTek MT7629 HIFSYS clocks providing
  33. to PCI-E and USB.
  34. +config COMMON_CLK_MT7981
  35. + bool "Clock driver for MediaTek MT7981"
  36. + depends on ARCH_MEDIATEK || COMPILE_TEST
  37. + select COMMON_CLK_MEDIATEK
  38. + default ARCH_MEDIATEK
  39. + help
  40. + This driver supports MediaTek MT7981 basic clocks and clocks
  41. + required for various peripherals found on this SoC.
  42. +
  43. +config COMMON_CLK_MT7981_ETHSYS
  44. + tristate "Clock driver for MediaTek MT7981 ETHSYS"
  45. + depends on COMMON_CLK_MT7981
  46. + default COMMON_CLK_MT7981
  47. + help
  48. + This driver adds support for clocks for Ethernet and SGMII
  49. + required on MediaTek MT7981 SoC.
  50. +
  51. config COMMON_CLK_MT7986
  52. bool "Clock driver for MediaTek MT7986"
  53. depends on ARCH_MEDIATEK || COMPILE_TEST
  54. --- a/drivers/clk/mediatek/Makefile
  55. +++ b/drivers/clk/mediatek/Makefile
  56. @@ -52,6 +52,10 @@ obj-$(CONFIG_COMMON_CLK_MT7622_AUDSYS) +
  57. obj-$(CONFIG_COMMON_CLK_MT7629) += clk-mt7629.o
  58. obj-$(CONFIG_COMMON_CLK_MT7629_ETHSYS) += clk-mt7629-eth.o
  59. obj-$(CONFIG_COMMON_CLK_MT7629_HIFSYS) += clk-mt7629-hif.o
  60. +obj-$(CONFIG_COMMON_CLK_MT7981) += clk-mt7981-apmixed.o
  61. +obj-$(CONFIG_COMMON_CLK_MT7981) += clk-mt7981-topckgen.o
  62. +obj-$(CONFIG_COMMON_CLK_MT7981) += clk-mt7981-infracfg.o
  63. +obj-$(CONFIG_COMMON_CLK_MT7981_ETHSYS) += clk-mt7981-eth.o
  64. obj-$(CONFIG_COMMON_CLK_MT7986) += clk-mt7986-apmixed.o
  65. obj-$(CONFIG_COMMON_CLK_MT7986) += clk-mt7986-topckgen.o
  66. obj-$(CONFIG_COMMON_CLK_MT7986) += clk-mt7986-infracfg.o
  67. --- /dev/null
  68. +++ b/drivers/clk/mediatek/clk-mt7981-apmixed.c
  69. @@ -0,0 +1,102 @@
  70. +// SPDX-License-Identifier: GPL-2.0
  71. +/*
  72. + * Copyright (c) 2021 MediaTek Inc.
  73. + * Author: Sam Shih <[email protected]>
  74. + * Author: Wenzhen Yu <[email protected]>
  75. + * Author: Jianhui Zhao <[email protected]>
  76. + * Author: Daniel Golle <[email protected]>
  77. + */
  78. +
  79. +#include <linux/clk-provider.h>
  80. +#include <linux/of.h>
  81. +#include <linux/of_address.h>
  82. +#include <linux/of_device.h>
  83. +#include <linux/platform_device.h>
  84. +
  85. +#include "clk-gate.h"
  86. +#include "clk-mtk.h"
  87. +#include "clk-mux.h"
  88. +#include "clk-pll.h"
  89. +
  90. +#include <dt-bindings/clock/mediatek,mt7981-clk.h>
  91. +#include <linux/clk.h>
  92. +
  93. +#define MT7981_PLL_FMAX (2500UL * MHZ)
  94. +#define CON0_MT7981_RST_BAR BIT(27)
  95. +
  96. +#define PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  97. + _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
  98. + _div_table, _parent_name) \
  99. + { \
  100. + .id = _id, .name = _name, .reg = _reg, .pwr_reg = _pwr_reg, \
  101. + .en_mask = _en_mask, .flags = _flags, \
  102. + .rst_bar_mask = CON0_MT7981_RST_BAR, .fmax = MT7981_PLL_FMAX, \
  103. + .pcwbits = _pcwbits, .pd_reg = _pd_reg, .pd_shift = _pd_shift, \
  104. + .tuner_reg = _tuner_reg, .pcw_reg = _pcw_reg, \
  105. + .pcw_shift = _pcw_shift, .div_table = _div_table, \
  106. + .parent_name = _parent_name, \
  107. + }
  108. +
  109. +#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pd_reg, \
  110. + _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift) \
  111. + PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  112. + _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, NULL, \
  113. + "clkxtal")
  114. +
  115. +static const struct mtk_pll_data plls[] = {
  116. + PLL(CLK_APMIXED_ARMPLL, "armpll", 0x0200, 0x020C, 0x00000001, PLL_AO,
  117. + 32, 0x0200, 4, 0, 0x0204, 0),
  118. + PLL(CLK_APMIXED_NET2PLL, "net2pll", 0x0210, 0x021C, 0x00000001, 0, 32,
  119. + 0x0210, 4, 0, 0x0214, 0),
  120. + PLL(CLK_APMIXED_MMPLL, "mmpll", 0x0220, 0x022C, 0x00000001, 0, 32,
  121. + 0x0220, 4, 0, 0x0224, 0),
  122. + PLL(CLK_APMIXED_SGMPLL, "sgmpll", 0x0230, 0x023C, 0x00000001, 0, 32,
  123. + 0x0230, 4, 0, 0x0234, 0),
  124. + PLL(CLK_APMIXED_WEDMCUPLL, "wedmcupll", 0x0240, 0x024C, 0x00000001, 0, 32,
  125. + 0x0240, 4, 0, 0x0244, 0),
  126. + PLL(CLK_APMIXED_NET1PLL, "net1pll", 0x0250, 0x025C, 0x00000001, 0, 32,
  127. + 0x0250, 4, 0, 0x0254, 0),
  128. + PLL(CLK_APMIXED_MPLL, "mpll", 0x0260, 0x0270, 0x00000001, 0, 32,
  129. + 0x0260, 4, 0, 0x0264, 0),
  130. + PLL(CLK_APMIXED_APLL2, "apll2", 0x0278, 0x0288, 0x00000001, 0, 32,
  131. + 0x0278, 4, 0, 0x027C, 0),
  132. +};
  133. +
  134. +static const struct of_device_id of_match_clk_mt7981_apmixed[] = {
  135. + { .compatible = "mediatek,mt7981-apmixedsys", },
  136. + { /* sentinel */ }
  137. +};
  138. +
  139. +static int clk_mt7981_apmixed_probe(struct platform_device *pdev)
  140. +{
  141. + struct clk_hw_onecell_data *clk_data;
  142. + struct device_node *node = pdev->dev.of_node;
  143. + int r;
  144. +
  145. + clk_data = mtk_alloc_clk_data(ARRAY_SIZE(plls));
  146. + if (!clk_data)
  147. + return -ENOMEM;
  148. +
  149. + mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  150. +
  151. + r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  152. + if (r) {
  153. + pr_err("%s(): could not register clock provider: %d\n",
  154. + __func__, r);
  155. + goto free_apmixed_data;
  156. + }
  157. + return r;
  158. +
  159. +free_apmixed_data:
  160. + mtk_free_clk_data(clk_data);
  161. + return r;
  162. +}
  163. +
  164. +static struct platform_driver clk_mt7981_apmixed_drv = {
  165. + .probe = clk_mt7981_apmixed_probe,
  166. + .driver = {
  167. + .name = "clk-mt7981-apmixed",
  168. + .of_match_table = of_match_clk_mt7981_apmixed,
  169. + },
  170. +};
  171. +builtin_platform_driver(clk_mt7981_apmixed_drv);
  172. --- /dev/null
  173. +++ b/drivers/clk/mediatek/clk-mt7981-eth.c
  174. @@ -0,0 +1,118 @@
  175. +// SPDX-License-Identifier: GPL-2.0
  176. +/*
  177. + * Copyright (c) 2021 MediaTek Inc.
  178. + * Author: Sam Shih <[email protected]>
  179. + * Author: Wenzhen Yu <[email protected]>
  180. + * Author: Jianhui Zhao <[email protected]>
  181. + * Author: Daniel Golle <[email protected]>
  182. + */
  183. +
  184. +#include <linux/clk-provider.h>
  185. +#include <linux/of.h>
  186. +#include <linux/of_address.h>
  187. +#include <linux/of_device.h>
  188. +#include <linux/platform_device.h>
  189. +
  190. +#include "clk-mtk.h"
  191. +#include "clk-gate.h"
  192. +
  193. +#include <dt-bindings/clock/mediatek,mt7981-clk.h>
  194. +
  195. +static const struct mtk_gate_regs sgmii0_cg_regs = {
  196. + .set_ofs = 0xE4,
  197. + .clr_ofs = 0xE4,
  198. + .sta_ofs = 0xE4,
  199. +};
  200. +
  201. +#define GATE_SGMII0(_id, _name, _parent, _shift) { \
  202. + .id = _id, \
  203. + .name = _name, \
  204. + .parent_name = _parent, \
  205. + .regs = &sgmii0_cg_regs, \
  206. + .shift = _shift, \
  207. + .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  208. + }
  209. +
  210. +static const struct mtk_gate sgmii0_clks[] __initconst = {
  211. + GATE_SGMII0(CLK_SGM0_TX_EN, "sgm0_tx_en", "usb_tx250m", 2),
  212. + GATE_SGMII0(CLK_SGM0_RX_EN, "sgm0_rx_en", "usb_eq_rx250m", 3),
  213. + GATE_SGMII0(CLK_SGM0_CK0_EN, "sgm0_ck0_en", "usb_ln0", 4),
  214. + GATE_SGMII0(CLK_SGM0_CDR_CK0_EN, "sgm0_cdr_ck0_en", "usb_cdr", 5),
  215. +};
  216. +
  217. +static const struct mtk_gate_regs sgmii1_cg_regs = {
  218. + .set_ofs = 0xE4,
  219. + .clr_ofs = 0xE4,
  220. + .sta_ofs = 0xE4,
  221. +};
  222. +
  223. +#define GATE_SGMII1(_id, _name, _parent, _shift) { \
  224. + .id = _id, \
  225. + .name = _name, \
  226. + .parent_name = _parent, \
  227. + .regs = &sgmii1_cg_regs, \
  228. + .shift = _shift, \
  229. + .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  230. + }
  231. +
  232. +static const struct mtk_gate sgmii1_clks[] __initconst = {
  233. + GATE_SGMII1(CLK_SGM1_TX_EN, "sgm1_tx_en", "usb_tx250m", 2),
  234. + GATE_SGMII1(CLK_SGM1_RX_EN, "sgm1_rx_en", "usb_eq_rx250m", 3),
  235. + GATE_SGMII1(CLK_SGM1_CK1_EN, "sgm1_ck1_en", "usb_ln0", 4),
  236. + GATE_SGMII1(CLK_SGM1_CDR_CK1_EN, "sgm1_cdr_ck1_en", "usb_cdr", 5),
  237. +};
  238. +
  239. +static const struct mtk_gate_regs eth_cg_regs = {
  240. + .set_ofs = 0x30,
  241. + .clr_ofs = 0x30,
  242. + .sta_ofs = 0x30,
  243. +};
  244. +
  245. +#define GATE_ETH(_id, _name, _parent, _shift) { \
  246. + .id = _id, \
  247. + .name = _name, \
  248. + .parent_name = _parent, \
  249. + .regs = &eth_cg_regs, \
  250. + .shift = _shift, \
  251. + .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  252. + }
  253. +
  254. +static const struct mtk_gate eth_clks[] __initconst = {
  255. + GATE_ETH(CLK_ETH_FE_EN, "eth_fe_en", "netsys_2x", 6),
  256. + GATE_ETH(CLK_ETH_GP2_EN, "eth_gp2_en", "sgm_325m", 7),
  257. + GATE_ETH(CLK_ETH_GP1_EN, "eth_gp1_en", "sgm_325m", 8),
  258. + GATE_ETH(CLK_ETH_WOCPU0_EN, "eth_wocpu0_en", "netsys_wed_mcu", 15),
  259. +};
  260. +
  261. +static const struct mtk_clk_desc eth_desc = {
  262. + .clks = eth_clks,
  263. + .num_clks = ARRAY_SIZE(eth_clks),
  264. +};
  265. +
  266. +static const struct mtk_clk_desc sgmii0_desc = {
  267. + .clks = sgmii0_clks,
  268. + .num_clks = ARRAY_SIZE(sgmii0_clks),
  269. +};
  270. +
  271. +static const struct mtk_clk_desc sgmii1_desc = {
  272. + .clks = sgmii1_clks,
  273. + .num_clks = ARRAY_SIZE(sgmii1_clks),
  274. +};
  275. +
  276. +static const struct of_device_id of_match_clk_mt7981_eth[] = {
  277. + { .compatible = "mediatek,mt7981-ethsys", .data = &eth_desc },
  278. + { .compatible = "mediatek,mt7981-sgmiisys_0", .data = &sgmii0_desc },
  279. + { .compatible = "mediatek,mt7981-sgmiisys_1", .data = &sgmii1_desc },
  280. + { /* sentinel */ }
  281. +};
  282. +
  283. +static struct platform_driver clk_mt7981_eth_drv = {
  284. + .probe = mtk_clk_simple_probe,
  285. + .remove = mtk_clk_simple_remove,
  286. + .driver = {
  287. + .name = "clk-mt7981-eth",
  288. + .of_match_table = of_match_clk_mt7981_eth,
  289. + },
  290. +};
  291. +module_platform_driver(clk_mt7981_eth_drv);
  292. +MODULE_LICENSE("GPL v2");
  293. --- /dev/null
  294. +++ b/drivers/clk/mediatek/clk-mt7981-infracfg.c
  295. @@ -0,0 +1,207 @@
  296. +// SPDX-License-Identifier: GPL-2.0
  297. +/*
  298. + * Copyright (c) 2021 MediaTek Inc.
  299. + * Author: Sam Shih <[email protected]>
  300. + * Author: Wenzhen Yu <[email protected]>
  301. + * Author: Jianhui Zhao <[email protected]>
  302. + * Author: Daniel Golle <[email protected]>
  303. + */
  304. +
  305. +#include <linux/clk-provider.h>
  306. +#include <linux/of.h>
  307. +#include <linux/of_address.h>
  308. +#include <linux/of_device.h>
  309. +#include <linux/platform_device.h>
  310. +#include "clk-mtk.h"
  311. +#include "clk-gate.h"
  312. +#include "clk-mux.h"
  313. +
  314. +#include <dt-bindings/clock/mediatek,mt7981-clk.h>
  315. +#include <linux/clk.h>
  316. +
  317. +static DEFINE_SPINLOCK(mt7981_clk_lock);
  318. +
  319. +static const struct mtk_fixed_factor infra_divs[] = {
  320. + FACTOR(CLK_INFRA_66M_MCK, "infra_66m_mck", "sysaxi_sel", 1, 2),
  321. +};
  322. +
  323. +static const char *const infra_uart_parent[] __initconst = { "csw_f26m_sel",
  324. + "uart_sel" };
  325. +
  326. +static const char *const infra_spi0_parents[] __initconst = { "i2c_sel",
  327. + "spi_sel" };
  328. +
  329. +static const char *const infra_spi1_parents[] __initconst = { "i2c_sel",
  330. + "spim_mst_sel" };
  331. +
  332. +static const char *const infra_pwm1_parents[] __initconst = { "pwm_sel" };
  333. +
  334. +static const char *const infra_pwm_bsel_parents[] __initconst = {
  335. + "cb_rtc_32p7k", "csw_f26m_sel", "infra_66m_mck", "pwm_sel"
  336. +};
  337. +
  338. +static const char *const infra_pcie_parents[] __initconst = {
  339. + "cb_rtc_32p7k", "csw_f26m_sel", "cb_cksq_40m", "pextp_tl_ck_sel"
  340. +};
  341. +
  342. +static const struct mtk_mux infra_muxes[] = {
  343. + /* MODULE_CLK_SEL_0 */
  344. + MUX_GATE_CLR_SET_UPD(CLK_INFRA_UART0_SEL, "infra_uart0_sel",
  345. + infra_uart_parent, 0x0018, 0x0010, 0x0014, 0, 1,
  346. + -1, -1, -1),
  347. + MUX_GATE_CLR_SET_UPD(CLK_INFRA_UART1_SEL, "infra_uart1_sel",
  348. + infra_uart_parent, 0x0018, 0x0010, 0x0014, 1, 1,
  349. + -1, -1, -1),
  350. + MUX_GATE_CLR_SET_UPD(CLK_INFRA_UART2_SEL, "infra_uart2_sel",
  351. + infra_uart_parent, 0x0018, 0x0010, 0x0014, 2, 1,
  352. + -1, -1, -1),
  353. + MUX_GATE_CLR_SET_UPD(CLK_INFRA_SPI0_SEL, "infra_spi0_sel",
  354. + infra_spi0_parents, 0x0018, 0x0010, 0x0014, 4, 1,
  355. + -1, -1, -1),
  356. + MUX_GATE_CLR_SET_UPD(CLK_INFRA_SPI1_SEL, "infra_spi1_sel",
  357. + infra_spi1_parents, 0x0018, 0x0010, 0x0014, 5, 1,
  358. + -1, -1, -1),
  359. + MUX_GATE_CLR_SET_UPD(CLK_INFRA_SPI2_SEL, "infra_spi2_sel",
  360. + infra_spi0_parents, 0x0018, 0x0010, 0x0014, 6, 1,
  361. + -1, -1, -1),
  362. + MUX_GATE_CLR_SET_UPD(CLK_INFRA_PWM1_SEL, "infra_pwm1_sel",
  363. + infra_pwm1_parents, 0x0018, 0x0010, 0x0014, 9, 1,
  364. + -1, -1, -1),
  365. + MUX_GATE_CLR_SET_UPD(CLK_INFRA_PWM2_SEL, "infra_pwm2_sel",
  366. + infra_pwm1_parents, 0x0018, 0x0010, 0x0014, 11, 1,
  367. + -1, -1, -1),
  368. + MUX_GATE_CLR_SET_UPD(CLK_INFRA_PWM3_SEL, "infra_pwm3_sel",
  369. + infra_pwm1_parents, 0x0018, 0x0010, 0x0014, 15, 1,
  370. + -1, -1, -1),
  371. + MUX_GATE_CLR_SET_UPD(CLK_INFRA_PWM_BSEL, "infra_pwm_bsel",
  372. + infra_pwm_bsel_parents, 0x0018, 0x0010, 0x0014, 13,
  373. + 2, -1, -1, -1),
  374. + /* MODULE_CLK_SEL_1 */
  375. + MUX_GATE_CLR_SET_UPD(CLK_INFRA_PCIE_SEL, "infra_pcie_sel",
  376. + infra_pcie_parents, 0x0028, 0x0020, 0x0024, 0, 2,
  377. + -1, -1, -1),
  378. +};
  379. +
  380. +static const struct mtk_gate_regs infra0_cg_regs = {
  381. + .set_ofs = 0x40,
  382. + .clr_ofs = 0x44,
  383. + .sta_ofs = 0x48,
  384. +};
  385. +
  386. +static const struct mtk_gate_regs infra1_cg_regs = {
  387. + .set_ofs = 0x50,
  388. + .clr_ofs = 0x54,
  389. + .sta_ofs = 0x58,
  390. +};
  391. +
  392. +static const struct mtk_gate_regs infra2_cg_regs = {
  393. + .set_ofs = 0x60,
  394. + .clr_ofs = 0x64,
  395. + .sta_ofs = 0x68,
  396. +};
  397. +
  398. +#define GATE_INFRA0(_id, _name, _parent, _shift) \
  399. + { \
  400. + .id = _id, .name = _name, .parent_name = _parent, \
  401. + .regs = &infra0_cg_regs, .shift = _shift, \
  402. + .ops = &mtk_clk_gate_ops_setclr, \
  403. + }
  404. +
  405. +#define GATE_INFRA1(_id, _name, _parent, _shift) \
  406. + { \
  407. + .id = _id, .name = _name, .parent_name = _parent, \
  408. + .regs = &infra1_cg_regs, .shift = _shift, \
  409. + .ops = &mtk_clk_gate_ops_setclr, \
  410. + }
  411. +
  412. +#define GATE_INFRA2(_id, _name, _parent, _shift) \
  413. + { \
  414. + .id = _id, .name = _name, .parent_name = _parent, \
  415. + .regs = &infra2_cg_regs, .shift = _shift, \
  416. + .ops = &mtk_clk_gate_ops_setclr, \
  417. + }
  418. +
  419. +static const struct mtk_gate infra_clks[] = {
  420. + /* INFRA0 */
  421. + GATE_INFRA0(CLK_INFRA_GPT_STA, "infra_gpt_sta", "infra_66m_mck", 0),
  422. + GATE_INFRA0(CLK_INFRA_PWM_HCK, "infra_pwm_hck", "infra_66m_mck", 1),
  423. + GATE_INFRA0(CLK_INFRA_PWM_STA, "infra_pwm_sta", "infra_pwm_bsel", 2),
  424. + GATE_INFRA0(CLK_INFRA_PWM1_CK, "infra_pwm1", "infra_pwm1_sel", 3),
  425. + GATE_INFRA0(CLK_INFRA_PWM2_CK, "infra_pwm2", "infra_pwm2_sel", 4),
  426. + GATE_INFRA0(CLK_INFRA_CQ_DMA_CK, "infra_cq_dma", "sysaxi", 6),
  427. +
  428. + GATE_INFRA0(CLK_INFRA_AUD_BUS_CK, "infra_aud_bus", "sysaxi", 8),
  429. + GATE_INFRA0(CLK_INFRA_AUD_26M_CK, "infra_aud_26m", "csw_f26m_sel", 9),
  430. + GATE_INFRA0(CLK_INFRA_AUD_L_CK, "infra_aud_l", "aud_l", 10),
  431. + GATE_INFRA0(CLK_INFRA_AUD_AUD_CK, "infra_aud_aud", "a1sys", 11),
  432. + GATE_INFRA0(CLK_INFRA_AUD_EG2_CK, "infra_aud_eg2", "a_tuner", 13),
  433. + GATE_INFRA0(CLK_INFRA_DRAMC_26M_CK, "infra_dramc_26m", "csw_f26m_sel",
  434. + 14),
  435. + GATE_INFRA0(CLK_INFRA_DBG_CK, "infra_dbg", "infra_66m_mck", 15),
  436. + GATE_INFRA0(CLK_INFRA_AP_DMA_CK, "infra_ap_dma", "infra_66m_mck", 16),
  437. + GATE_INFRA0(CLK_INFRA_SEJ_CK, "infra_sej", "infra_66m_mck", 24),
  438. + GATE_INFRA0(CLK_INFRA_SEJ_13M_CK, "infra_sej_13m", "csw_f26m_sel", 25),
  439. + GATE_INFRA0(CLK_INFRA_PWM3_CK, "infra_pwm3", "infra_pwm3_sel", 27),
  440. + /* INFRA1 */
  441. + GATE_INFRA1(CLK_INFRA_THERM_CK, "infra_therm", "csw_f26m_sel", 0),
  442. + GATE_INFRA1(CLK_INFRA_I2C0_CK, "infra_i2c0", "i2c_bck", 1),
  443. + GATE_INFRA1(CLK_INFRA_UART0_CK, "infra_uart0", "infra_uart0_sel", 2),
  444. + GATE_INFRA1(CLK_INFRA_UART1_CK, "infra_uart1", "infra_uart1_sel", 3),
  445. + GATE_INFRA1(CLK_INFRA_UART2_CK, "infra_uart2", "infra_uart2_sel", 4),
  446. + GATE_INFRA1(CLK_INFRA_SPI2_CK, "infra_spi2", "infra_spi2_sel", 6),
  447. + GATE_INFRA1(CLK_INFRA_SPI2_HCK_CK, "infra_spi2_hck", "infra_66m_mck", 7),
  448. + GATE_INFRA1(CLK_INFRA_NFI1_CK, "infra_nfi1", "nfi1x", 8),
  449. + GATE_INFRA1(CLK_INFRA_SPINFI1_CK, "infra_spinfi1", "spinfi_bck", 9),
  450. + GATE_INFRA1(CLK_INFRA_NFI_HCK_CK, "infra_nfi_hck", "infra_66m_mck", 10),
  451. + GATE_INFRA1(CLK_INFRA_SPI0_CK, "infra_spi0", "infra_spi0_sel", 11),
  452. + GATE_INFRA1(CLK_INFRA_SPI1_CK, "infra_spi1", "infra_spi1_sel", 12),
  453. + GATE_INFRA1(CLK_INFRA_SPI0_HCK_CK, "infra_spi0_hck", "infra_66m_mck",
  454. + 13),
  455. + GATE_INFRA1(CLK_INFRA_SPI1_HCK_CK, "infra_spi1_hck", "infra_66m_mck",
  456. + 14),
  457. + GATE_INFRA1(CLK_INFRA_FRTC_CK, "infra_frtc", "cb_rtc_32k", 15),
  458. + GATE_INFRA1(CLK_INFRA_MSDC_CK, "infra_msdc", "emmc_400m", 16),
  459. + GATE_INFRA1(CLK_INFRA_MSDC_HCK_CK, "infra_msdc_hck", "emmc_208m", 17),
  460. + GATE_INFRA1(CLK_INFRA_MSDC_133M_CK, "infra_msdc_133m", "sysaxi", 18),
  461. + GATE_INFRA1(CLK_INFRA_MSDC_66M_CK, "infra_msdc_66m", "sysaxi", 19),
  462. + GATE_INFRA1(CLK_INFRA_ADC_26M_CK, "infra_adc_26m", "infra_adc_frc", 20),
  463. + GATE_INFRA1(CLK_INFRA_ADC_FRC_CK, "infra_adc_frc", "csw_f26m", 21),
  464. + GATE_INFRA1(CLK_INFRA_FBIST2FPC_CK, "infra_fbist2fpc", "nfi1x", 23),
  465. + GATE_INFRA1(CLK_INFRA_I2C_MCK_CK, "infra_i2c_mck", "sysaxi", 25),
  466. + GATE_INFRA1(CLK_INFRA_I2C_PCK_CK, "infra_i2c_pck", "infra_66m_mck", 26),
  467. + /* INFRA2 */
  468. + GATE_INFRA2(CLK_INFRA_IUSB_133_CK, "infra_iusb_133", "sysaxi", 0),
  469. + GATE_INFRA2(CLK_INFRA_IUSB_66M_CK, "infra_iusb_66m", "sysaxi", 1),
  470. + GATE_INFRA2(CLK_INFRA_IUSB_SYS_CK, "infra_iusb_sys", "u2u3_sys", 2),
  471. + GATE_INFRA2(CLK_INFRA_IUSB_CK, "infra_iusb", "u2u3_ref", 3),
  472. + GATE_INFRA2(CLK_INFRA_IPCIE_CK, "infra_ipcie", "pextp_tl", 12),
  473. + GATE_INFRA2(CLK_INFRA_IPCIE_PIPE_CK, "infra_ipcie_pipe", "cb_cksq_40m",
  474. + 13),
  475. + GATE_INFRA2(CLK_INFRA_IPCIER_CK, "infra_ipcier", "csw_f26m", 14),
  476. + GATE_INFRA2(CLK_INFRA_IPCIEB_CK, "infra_ipcieb", "sysaxi", 15),
  477. +};
  478. +
  479. +static const struct mtk_clk_desc infracfg_desc = {
  480. + .factor_clks = infra_divs,
  481. + .num_factor_clks = ARRAY_SIZE(infra_divs),
  482. + .mux_clks = infra_muxes,
  483. + .num_mux_clks = ARRAY_SIZE(infra_muxes),
  484. + .clks = infra_clks,
  485. + .num_clks = ARRAY_SIZE(infra_clks),
  486. + .clk_lock = &mt7981_clk_lock,
  487. +};
  488. +
  489. +static const struct of_device_id of_match_clk_mt7981_infracfg[] = {
  490. + { .compatible = "mediatek,mt7981-infracfg", .data = &infracfg_desc },
  491. + { /* sentinel */ }
  492. +};
  493. +
  494. +static struct platform_driver clk_mt7981_infracfg_drv = {
  495. + .probe = mtk_clk_simple_probe,
  496. + .remove = mtk_clk_simple_remove,
  497. + .driver = {
  498. + .name = "clk-mt7981-infracfg",
  499. + .of_match_table = of_match_clk_mt7981_infracfg,
  500. + },
  501. +};
  502. +builtin_platform_driver(clk_mt7981_infracfg_drv);
  503. --- /dev/null
  504. +++ b/drivers/clk/mediatek/clk-mt7981-topckgen.c
  505. @@ -0,0 +1,422 @@
  506. +// SPDX-License-Identifier: GPL-2.0
  507. +/*
  508. + * Copyright (c) 2021 MediaTek Inc.
  509. + * Author: Sam Shih <[email protected]>
  510. + * Author: Wenzhen Yu <[email protected]>
  511. + * Author: Jianhui Zhao <[email protected]>
  512. + */
  513. +
  514. +
  515. +#include <linux/clk-provider.h>
  516. +#include <linux/of.h>
  517. +#include <linux/of_address.h>
  518. +#include <linux/of_device.h>
  519. +#include <linux/platform_device.h>
  520. +#include "clk-mtk.h"
  521. +#include "clk-gate.h"
  522. +#include "clk-mux.h"
  523. +
  524. +#include <dt-bindings/clock/mediatek,mt7981-clk.h>
  525. +#include <linux/clk.h>
  526. +
  527. +static DEFINE_SPINLOCK(mt7981_clk_lock);
  528. +
  529. +static const struct mtk_fixed_factor top_divs[] = {
  530. + FACTOR(CLK_TOP_CB_CKSQ_40M, "cb_cksq_40m", "clkxtal", 1, 1),
  531. + FACTOR(CLK_TOP_CB_M_416M, "cb_m_416m", "mpll", 1, 1),
  532. + FACTOR(CLK_TOP_CB_M_D2, "cb_m_d2", "mpll", 1, 2),
  533. + FACTOR(CLK_TOP_CB_M_D3, "cb_m_d3", "mpll", 1, 3),
  534. + FACTOR(CLK_TOP_M_D3_D2, "m_d3_d2", "mpll", 1, 2),
  535. + FACTOR(CLK_TOP_CB_M_D4, "cb_m_d4", "mpll", 1, 4),
  536. + FACTOR(CLK_TOP_CB_M_D8, "cb_m_d8", "mpll", 1, 8),
  537. + FACTOR(CLK_TOP_M_D8_D2, "m_d8_d2", "mpll", 1, 16),
  538. + FACTOR(CLK_TOP_CB_MM_720M, "cb_mm_720m", "mmpll", 1, 1),
  539. + FACTOR(CLK_TOP_CB_MM_D2, "cb_mm_d2", "mmpll", 1, 2),
  540. + FACTOR(CLK_TOP_CB_MM_D3, "cb_mm_d3", "mmpll", 1, 3),
  541. + FACTOR(CLK_TOP_CB_MM_D3_D5, "cb_mm_d3_d5", "mmpll", 1, 15),
  542. + FACTOR(CLK_TOP_CB_MM_D4, "cb_mm_d4", "mmpll", 1, 4),
  543. + FACTOR(CLK_TOP_CB_MM_D6, "cb_mm_d6", "mmpll", 1, 6),
  544. + FACTOR(CLK_TOP_MM_D6_D2, "mm_d6_d2", "mmpll", 1, 12),
  545. + FACTOR(CLK_TOP_CB_MM_D8, "cb_mm_d8", "mmpll", 1, 8),
  546. + FACTOR(CLK_TOP_CB_APLL2_196M, "cb_apll2_196m", "apll2", 1, 1),
  547. + FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2", 1, 2),
  548. + FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "apll2", 1, 4),
  549. + FACTOR(CLK_TOP_NET1_2500M, "net1_2500m", "net1pll", 1, 1),
  550. + FACTOR(CLK_TOP_CB_NET1_D4, "cb_net1_d4", "net1pll", 1, 4),
  551. + FACTOR(CLK_TOP_CB_NET1_D5, "cb_net1_d5", "net1pll", 1, 5),
  552. + FACTOR(CLK_TOP_NET1_D5_D2, "net1_d5_d2", "net1pll", 1, 10),
  553. + FACTOR(CLK_TOP_NET1_D5_D4, "net1_d5_d4", "net1pll", 1, 20),
  554. + FACTOR(CLK_TOP_CB_NET1_D8, "cb_net1_d8", "net1pll", 1, 8),
  555. + FACTOR(CLK_TOP_NET1_D8_D2, "net1_d8_d2", "net1pll", 1, 16),
  556. + FACTOR(CLK_TOP_NET1_D8_D4, "net1_d8_d4", "net1pll", 1, 32),
  557. + FACTOR(CLK_TOP_CB_NET2_800M, "cb_net2_800m", "net2pll", 1, 1),
  558. + FACTOR(CLK_TOP_CB_NET2_D2, "cb_net2_d2", "net2pll", 1, 2),
  559. + FACTOR(CLK_TOP_CB_NET2_D4, "cb_net2_d4", "net2pll", 1, 4),
  560. + FACTOR(CLK_TOP_NET2_D4_D2, "net2_d4_d2", "net2pll", 1, 8),
  561. + FACTOR(CLK_TOP_NET2_D4_D4, "net2_d4_d4", "net2pll", 1, 16),
  562. + FACTOR(CLK_TOP_CB_NET2_D6, "cb_net2_d6", "net2pll", 1, 6),
  563. + FACTOR(CLK_TOP_CB_WEDMCU_208M, "cb_wedmcu_208m", "wedmcupll", 1, 1),
  564. + FACTOR(CLK_TOP_CB_SGM_325M, "cb_sgm_325m", "sgmpll", 1, 1),
  565. + FACTOR(CLK_TOP_CKSQ_40M_D2, "cksq_40m_d2", "cb_cksq_40m", 1, 2),
  566. + FACTOR(CLK_TOP_CB_RTC_32K, "cb_rtc_32k", "cb_cksq_40m", 1, 1250),
  567. + FACTOR(CLK_TOP_CB_RTC_32P7K, "cb_rtc_32p7k", "cb_cksq_40m", 1, 1220),
  568. + FACTOR(CLK_TOP_USB_TX250M, "usb_tx250m", "cb_cksq_40m", 1, 1),
  569. + FACTOR(CLK_TOP_FAUD, "faud", "aud_sel", 1, 1),
  570. + FACTOR(CLK_TOP_NFI1X, "nfi1x", "nfi1x_sel", 1, 1),
  571. + FACTOR(CLK_TOP_USB_EQ_RX250M, "usb_eq_rx250m", "cb_cksq_40m", 1, 1),
  572. + FACTOR(CLK_TOP_USB_CDR_CK, "usb_cdr", "cb_cksq_40m", 1, 1),
  573. + FACTOR(CLK_TOP_USB_LN0_CK, "usb_ln0", "cb_cksq_40m", 1, 1),
  574. + FACTOR(CLK_TOP_SPINFI_BCK, "spinfi_bck", "spinfi_sel", 1, 1),
  575. + FACTOR(CLK_TOP_SPI, "spi", "spi_sel", 1, 1),
  576. + FACTOR(CLK_TOP_SPIM_MST, "spim_mst", "spim_mst_sel", 1, 1),
  577. + FACTOR(CLK_TOP_UART_BCK, "uart_bck", "uart_sel", 1, 1),
  578. + FACTOR(CLK_TOP_PWM_BCK, "pwm_bck", "pwm_sel", 1, 1),
  579. + FACTOR(CLK_TOP_I2C_BCK, "i2c_bck", "i2c_sel", 1, 1),
  580. + FACTOR(CLK_TOP_PEXTP_TL, "pextp_tl", "pextp_tl_ck_sel", 1, 1),
  581. + FACTOR(CLK_TOP_EMMC_208M, "emmc_208m", "emmc_208m_sel", 1, 1),
  582. + FACTOR(CLK_TOP_EMMC_400M, "emmc_400m", "emmc_400m_sel", 1, 1),
  583. + FACTOR(CLK_TOP_DRAMC_REF, "dramc_ref", "dramc_sel", 1, 1),
  584. + FACTOR(CLK_TOP_DRAMC_MD32, "dramc_md32", "dramc_md32_sel", 1, 1),
  585. + FACTOR(CLK_TOP_SYSAXI, "sysaxi", "sysaxi_sel", 1, 1),
  586. + FACTOR(CLK_TOP_SYSAPB, "sysapb", "sysapb_sel", 1, 1),
  587. + FACTOR(CLK_TOP_ARM_DB_MAIN, "arm_db_main", "arm_db_main_sel", 1, 1),
  588. + FACTOR(CLK_TOP_AP2CNN_HOST, "ap2cnn_host", "ap2cnn_host_sel", 1, 1),
  589. + FACTOR(CLK_TOP_NETSYS, "netsys", "netsys_sel", 1, 1),
  590. + FACTOR(CLK_TOP_NETSYS_500M, "netsys_500m", "netsys_500m_sel", 1, 1),
  591. + FACTOR(CLK_TOP_NETSYS_WED_MCU, "netsys_wed_mcu", "netsys_mcu_sel", 1, 1),
  592. + FACTOR(CLK_TOP_NETSYS_2X, "netsys_2x", "netsys_2x_sel", 1, 1),
  593. + FACTOR(CLK_TOP_SGM_325M, "sgm_325m", "sgm_325m_sel", 1, 1),
  594. + FACTOR(CLK_TOP_SGM_REG, "sgm_reg", "sgm_reg_sel", 1, 1),
  595. + FACTOR(CLK_TOP_F26M, "csw_f26m", "csw_f26m_sel", 1, 1),
  596. + FACTOR(CLK_TOP_EIP97B, "eip97b", "eip97b_sel", 1, 1),
  597. + FACTOR(CLK_TOP_USB3_PHY, "usb3_phy", "usb3_phy_sel", 1, 1),
  598. + FACTOR(CLK_TOP_AUD, "aud", "faud", 1, 1),
  599. + FACTOR(CLK_TOP_A1SYS, "a1sys", "a1sys_sel", 1, 1),
  600. + FACTOR(CLK_TOP_AUD_L, "aud_l", "aud_l_sel", 1, 1),
  601. + FACTOR(CLK_TOP_A_TUNER, "a_tuner", "a_tuner_sel", 1, 1),
  602. + FACTOR(CLK_TOP_U2U3_REF, "u2u3_ref", "u2u3_sel", 1, 1),
  603. + FACTOR(CLK_TOP_U2U3_SYS, "u2u3_sys", "u2u3_sys_sel", 1, 1),
  604. + FACTOR(CLK_TOP_U2U3_XHCI, "u2u3_xhci", "u2u3_xhci_sel", 1, 1),
  605. + FACTOR(CLK_TOP_USB_FRMCNT, "usb_frmcnt", "usb_frmcnt_sel", 1, 1),
  606. +};
  607. +
  608. +static const char * const nfi1x_parents[] __initconst = {
  609. + "cb_cksq_40m",
  610. + "cb_mm_d4",
  611. + "net1_d8_d2",
  612. + "cb_net2_d6",
  613. + "cb_m_d4",
  614. + "cb_mm_d8",
  615. + "net1_d8_d4",
  616. + "cb_m_d8"
  617. +};
  618. +
  619. +static const char * const spinfi_parents[] __initconst = {
  620. + "cksq_40m_d2",
  621. + "cb_cksq_40m",
  622. + "net1_d5_d4",
  623. + "cb_m_d4",
  624. + "cb_mm_d8",
  625. + "net1_d8_d4",
  626. + "mm_d6_d2",
  627. + "cb_m_d8"
  628. +};
  629. +
  630. +static const char * const spi_parents[] __initconst = {
  631. + "cb_cksq_40m",
  632. + "cb_m_d2",
  633. + "cb_mm_d4",
  634. + "net1_d8_d2",
  635. + "cb_net2_d6",
  636. + "net1_d5_d4",
  637. + "cb_m_d4",
  638. + "net1_d8_d4"
  639. +};
  640. +
  641. +static const char * const uart_parents[] __initconst = {
  642. + "cb_cksq_40m",
  643. + "cb_m_d8",
  644. + "m_d8_d2"
  645. +};
  646. +
  647. +static const char * const pwm_parents[] __initconst = {
  648. + "cb_cksq_40m",
  649. + "net1_d8_d2",
  650. + "net1_d5_d4",
  651. + "cb_m_d4",
  652. + "m_d8_d2",
  653. + "cb_rtc_32k"
  654. +};
  655. +
  656. +static const char * const i2c_parents[] __initconst = {
  657. + "cb_cksq_40m",
  658. + "net1_d5_d4",
  659. + "cb_m_d4",
  660. + "net1_d8_d4"
  661. +};
  662. +
  663. +static const char * const pextp_tl_ck_parents[] __initconst = {
  664. + "cb_cksq_40m",
  665. + "net1_d5_d4",
  666. + "cb_m_d4",
  667. + "cb_rtc_32k"
  668. +};
  669. +
  670. +static const char * const emmc_208m_parents[] __initconst = {
  671. + "cb_cksq_40m",
  672. + "cb_m_d2",
  673. + "cb_net2_d4",
  674. + "cb_apll2_196m",
  675. + "cb_mm_d4",
  676. + "net1_d8_d2",
  677. + "cb_mm_d6"
  678. +};
  679. +
  680. +static const char * const emmc_400m_parents[] __initconst = {
  681. + "cb_cksq_40m",
  682. + "cb_net2_d2",
  683. + "cb_mm_d2",
  684. + "cb_net2_d2"
  685. +};
  686. +
  687. +static const char * const csw_f26m_parents[] __initconst = {
  688. + "cksq_40m_d2",
  689. + "m_d8_d2"
  690. +};
  691. +
  692. +static const char * const dramc_md32_parents[] __initconst = {
  693. + "cb_cksq_40m",
  694. + "cb_m_d2",
  695. + "cb_wedmcu_208m"
  696. +};
  697. +
  698. +static const char * const sysaxi_parents[] __initconst = {
  699. + "cb_cksq_40m",
  700. + "net1_d8_d2"
  701. +};
  702. +
  703. +static const char * const sysapb_parents[] __initconst = {
  704. + "cb_cksq_40m",
  705. + "m_d3_d2"
  706. +};
  707. +
  708. +static const char * const arm_db_main_parents[] __initconst = {
  709. + "cb_cksq_40m",
  710. + "cb_net2_d6"
  711. +};
  712. +
  713. +static const char * const ap2cnn_host_parents[] __initconst = {
  714. + "cb_cksq_40m",
  715. + "net1_d8_d4"
  716. +};
  717. +
  718. +static const char * const netsys_parents[] __initconst = {
  719. + "cb_cksq_40m",
  720. + "cb_mm_d2"
  721. +};
  722. +
  723. +static const char * const netsys_500m_parents[] __initconst = {
  724. + "cb_cksq_40m",
  725. + "cb_net1_d5"
  726. +};
  727. +
  728. +static const char * const netsys_mcu_parents[] __initconst = {
  729. + "cb_cksq_40m",
  730. + "cb_mm_720m",
  731. + "cb_net1_d4",
  732. + "cb_net1_d5",
  733. + "cb_m_416m"
  734. +};
  735. +
  736. +static const char * const netsys_2x_parents[] __initconst = {
  737. + "cb_cksq_40m",
  738. + "cb_net2_800m",
  739. + "cb_mm_720m"
  740. +};
  741. +
  742. +static const char * const sgm_325m_parents[] __initconst = {
  743. + "cb_cksq_40m",
  744. + "cb_sgm_325m"
  745. +};
  746. +
  747. +static const char * const sgm_reg_parents[] __initconst = {
  748. + "cb_cksq_40m",
  749. + "cb_net2_d4"
  750. +};
  751. +
  752. +static const char * const eip97b_parents[] __initconst = {
  753. + "cb_cksq_40m",
  754. + "cb_net1_d5",
  755. + "cb_m_416m",
  756. + "cb_mm_d2",
  757. + "net1_d5_d2"
  758. +};
  759. +
  760. +static const char * const aud_parents[] __initconst = {
  761. + "cb_cksq_40m",
  762. + "cb_apll2_196m"
  763. +};
  764. +
  765. +static const char * const a1sys_parents[] __initconst = {
  766. + "cb_cksq_40m",
  767. + "apll2_d4"
  768. +};
  769. +
  770. +static const char * const aud_l_parents[] __initconst = {
  771. + "cb_cksq_40m",
  772. + "cb_apll2_196m",
  773. + "m_d8_d2"
  774. +};
  775. +
  776. +static const char * const a_tuner_parents[] __initconst = {
  777. + "cb_cksq_40m",
  778. + "apll2_d4",
  779. + "m_d8_d2"
  780. +};
  781. +
  782. +static const char * const u2u3_parents[] __initconst = {
  783. + "cb_cksq_40m",
  784. + "m_d8_d2"
  785. +};
  786. +
  787. +static const char * const u2u3_sys_parents[] __initconst = {
  788. + "cb_cksq_40m",
  789. + "net1_d5_d4"
  790. +};
  791. +
  792. +static const char * const usb_frmcnt_parents[] __initconst = {
  793. + "cb_cksq_40m",
  794. + "cb_mm_d3_d5"
  795. +};
  796. +
  797. +static const struct mtk_mux top_muxes[] = {
  798. + /* CLK_CFG_0 */
  799. + MUX_GATE_CLR_SET_UPD(CLK_TOP_NFI1X_SEL, "nfi1x_sel", nfi1x_parents,
  800. + 0x000, 0x004, 0x008, 0, 3, 7, 0x1C0, 0),
  801. + MUX_GATE_CLR_SET_UPD(CLK_TOP_SPINFI_SEL, "spinfi_sel", spinfi_parents,
  802. + 0x000, 0x004, 0x008, 8, 3, 15, 0x1C0, 1),
  803. + MUX_GATE_CLR_SET_UPD(CLK_TOP_SPI_SEL, "spi_sel", spi_parents,
  804. + 0x000, 0x004, 0x008, 16, 3, 23, 0x1C0, 2),
  805. + MUX_GATE_CLR_SET_UPD(CLK_TOP_SPIM_MST_SEL, "spim_mst_sel", spi_parents,
  806. + 0x000, 0x004, 0x008, 24, 3, 31, 0x1C0, 3),
  807. + /* CLK_CFG_1 */
  808. + MUX_GATE_CLR_SET_UPD(CLK_TOP_UART_SEL, "uart_sel", uart_parents,
  809. + 0x010, 0x014, 0x018, 0, 2, 7, 0x1C0, 4),
  810. + MUX_GATE_CLR_SET_UPD(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents,
  811. + 0x010, 0x014, 0x018, 8, 3, 15, 0x1C0, 5),
  812. + MUX_GATE_CLR_SET_UPD(CLK_TOP_I2C_SEL, "i2c_sel", i2c_parents,
  813. + 0x010, 0x014, 0x018, 16, 2, 23, 0x1C0, 6),
  814. + MUX_GATE_CLR_SET_UPD(CLK_TOP_PEXTP_TL_SEL, "pextp_tl_ck_sel",
  815. + pextp_tl_ck_parents, 0x010, 0x014, 0x018, 24, 2, 31,
  816. + 0x1C0, 7),
  817. + /* CLK_CFG_2 */
  818. + MUX_GATE_CLR_SET_UPD(CLK_TOP_EMMC_208M_SEL, "emmc_208m_sel",
  819. + emmc_208m_parents, 0x020, 0x024, 0x028, 0, 3, 7,
  820. + 0x1C0, 8),
  821. + MUX_GATE_CLR_SET_UPD(CLK_TOP_EMMC_400M_SEL, "emmc_400m_sel",
  822. + emmc_400m_parents, 0x020, 0x024, 0x028, 8, 2, 15,
  823. + 0x1C0, 9),
  824. + MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_F26M_SEL, "csw_f26m_sel",
  825. + csw_f26m_parents, 0x020, 0x024, 0x028, 16, 1, 23,
  826. + 0x1C0, 10,
  827. + CLK_IS_CRITICAL | CLK_SET_RATE_PARENT),
  828. + MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_DRAMC_SEL, "dramc_sel",
  829. + csw_f26m_parents, 0x020, 0x024, 0x028, 24, 1,
  830. + 31, 0x1C0, 11,
  831. + CLK_IS_CRITICAL | CLK_SET_RATE_PARENT),
  832. + /* CLK_CFG_3 */
  833. + MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_DRAMC_MD32_SEL, "dramc_md32_sel",
  834. + dramc_md32_parents, 0x030, 0x034, 0x038, 0, 2,
  835. + 7, 0x1C0, 12,
  836. + CLK_IS_CRITICAL | CLK_SET_RATE_PARENT),
  837. + MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_SYSAXI_SEL, "sysaxi_sel",
  838. + sysaxi_parents, 0x030, 0x034, 0x038, 8, 1, 15,
  839. + 0x1C0, 13,
  840. + CLK_IS_CRITICAL | CLK_SET_RATE_PARENT),
  841. + MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_SYSAPB_SEL, "sysapb_sel",
  842. + sysapb_parents, 0x030, 0x034, 0x038, 16, 1,
  843. + 23, 0x1C0, 14,
  844. + CLK_IS_CRITICAL | CLK_SET_RATE_PARENT),
  845. + MUX_GATE_CLR_SET_UPD(CLK_TOP_ARM_DB_MAIN_SEL, "arm_db_main_sel",
  846. + arm_db_main_parents, 0x030, 0x034, 0x038, 24, 1, 31,
  847. + 0x1C0, 15),
  848. + /* CLK_CFG_4 */
  849. + MUX_GATE_CLR_SET_UPD(CLK_TOP_AP2CNN_HOST_SEL, "ap2cnn_host_sel",
  850. + ap2cnn_host_parents, 0x040, 0x044, 0x048, 0, 1, 7,
  851. + 0x1C0, 16),
  852. + MUX_GATE_CLR_SET_UPD(CLK_TOP_NETSYS_SEL, "netsys_sel", netsys_parents,
  853. + 0x040, 0x044, 0x048, 8, 1, 15, 0x1C0, 17),
  854. + MUX_GATE_CLR_SET_UPD(CLK_TOP_NETSYS_500M_SEL, "netsys_500m_sel",
  855. + netsys_500m_parents, 0x040, 0x044, 0x048, 16, 1, 23,
  856. + 0x1C0, 18),
  857. + MUX_GATE_CLR_SET_UPD(CLK_TOP_NETSYS_MCU_SEL, "netsys_mcu_sel",
  858. + netsys_mcu_parents, 0x040, 0x044, 0x048, 24, 3, 31,
  859. + 0x1C0, 19),
  860. + /* CLK_CFG_5 */
  861. + MUX_GATE_CLR_SET_UPD(CLK_TOP_NETSYS_2X_SEL, "netsys_2x_sel",
  862. + netsys_2x_parents, 0x050, 0x054, 0x058, 0, 2, 7,
  863. + 0x1C0, 20),
  864. + MUX_GATE_CLR_SET_UPD(CLK_TOP_SGM_325M_SEL, "sgm_325m_sel",
  865. + sgm_325m_parents, 0x050, 0x054, 0x058, 8, 1, 15,
  866. + 0x1C0, 21),
  867. + MUX_GATE_CLR_SET_UPD(CLK_TOP_SGM_REG_SEL, "sgm_reg_sel", sgm_reg_parents,
  868. + 0x050, 0x054, 0x058, 16, 1, 23, 0x1C0, 22),
  869. + MUX_GATE_CLR_SET_UPD(CLK_TOP_EIP97B_SEL, "eip97b_sel", eip97b_parents,
  870. + 0x050, 0x054, 0x058, 24, 3, 31, 0x1C0, 23),
  871. + /* CLK_CFG_6 */
  872. + MUX_GATE_CLR_SET_UPD(CLK_TOP_USB3_PHY_SEL, "usb3_phy_sel",
  873. + csw_f26m_parents, 0x060, 0x064, 0x068, 0, 1,
  874. + 7, 0x1C0, 24),
  875. + MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_SEL, "aud_sel", aud_parents, 0x060,
  876. + 0x064, 0x068, 8, 1, 15, 0x1C0, 25),
  877. + MUX_GATE_CLR_SET_UPD(CLK_TOP_A1SYS_SEL, "a1sys_sel", a1sys_parents,
  878. + 0x060, 0x064, 0x068, 16, 1, 23, 0x1C0, 26),
  879. + MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_L_SEL, "aud_l_sel", aud_l_parents,
  880. + 0x060, 0x064, 0x068, 24, 2, 31, 0x1C0, 27),
  881. + /* CLK_CFG_7 */
  882. + MUX_GATE_CLR_SET_UPD(CLK_TOP_A_TUNER_SEL, "a_tuner_sel",
  883. + a_tuner_parents, 0x070, 0x074, 0x078, 0, 2, 7,
  884. + 0x1C0, 28),
  885. + MUX_GATE_CLR_SET_UPD(CLK_TOP_U2U3_SEL, "u2u3_sel", u2u3_parents, 0x070,
  886. + 0x074, 0x078, 8, 1, 15, 0x1C0, 29),
  887. + MUX_GATE_CLR_SET_UPD(CLK_TOP_U2U3_SYS_SEL, "u2u3_sys_sel",
  888. + u2u3_sys_parents, 0x070, 0x074, 0x078, 16, 1, 23,
  889. + 0x1C0, 30),
  890. + MUX_GATE_CLR_SET_UPD(CLK_TOP_U2U3_XHCI_SEL, "u2u3_xhci_sel",
  891. + u2u3_sys_parents, 0x070, 0x074, 0x078, 24, 1, 31,
  892. + 0x1C4, 0),
  893. + /* CLK_CFG_8 */
  894. + MUX_GATE_CLR_SET_UPD(CLK_TOP_USB_FRMCNT_SEL, "usb_frmcnt_sel",
  895. + usb_frmcnt_parents, 0x080, 0x084, 0x088, 0, 1, 7,
  896. + 0x1C4, 1),
  897. +};
  898. +
  899. +static struct mtk_composite top_aud_divs[] = {
  900. + DIV_GATE(CLK_TOP_AUD_I2S_M, "aud_i2s_m", "aud",
  901. + 0x0420, 0, 0x0420, 8, 8),
  902. +};
  903. +
  904. +static const struct mtk_clk_desc topck_desc = {
  905. + .factor_clks = top_divs,
  906. + .num_factor_clks = ARRAY_SIZE(top_divs),
  907. + .mux_clks = top_muxes,
  908. + .num_mux_clks = ARRAY_SIZE(top_muxes),
  909. + .composite_clks = top_aud_divs,
  910. + .num_composite_clks = ARRAY_SIZE(top_aud_divs),
  911. + .clk_lock = &mt7981_clk_lock,
  912. +};
  913. +
  914. +static const struct of_device_id of_match_clk_mt7981_topckgen[] = {
  915. + { .compatible = "mediatek,mt7981-topckgen", .data = &topck_desc },
  916. + { /* sentinel */ }
  917. +};
  918. +
  919. +static struct platform_driver clk_mt7981_topckgen_drv = {
  920. + .probe = mtk_clk_simple_probe,
  921. + .remove = mtk_clk_simple_remove,
  922. + .driver = {
  923. + .name = "clk-mt7981-topckgen",
  924. + .of_match_table = of_match_clk_mt7981_topckgen,
  925. + },
  926. +};
  927. +builtin_platform_driver(clk_mt7981_topckgen_drv);