002-0026-clk-mediatek-add-clock-driver-support-for-MediaTek-M.patch 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. From 54b66dd24310dba4798caa6e4c02b8571f522602 Mon Sep 17 00:00:00 2001
  2. From: Weijie Gao <[email protected]>
  3. Date: Wed, 31 Aug 2022 19:05:13 +0800
  4. Subject: [PATCH 26/32] clk: mediatek: add clock driver support for MediaTek
  5. MT7986 SoC
  6. This patch adds clock driver support for MediaTek MT7986 SoC
  7. Reviewed-by: Sean Anderson <[email protected]>
  8. Reviewed-by: Simon Glass <[email protected]>
  9. Signed-off-by: Weijie Gao <[email protected]>
  10. ---
  11. drivers/clk/mediatek/Makefile | 1 +
  12. drivers/clk/mediatek/clk-mt7986.c | 672 +++++++++++++++++++++++++
  13. include/dt-bindings/clock/mt7986-clk.h | 249 +++++++++
  14. 3 files changed, 922 insertions(+)
  15. create mode 100644 drivers/clk/mediatek/clk-mt7986.c
  16. create mode 100644 include/dt-bindings/clock/mt7986-clk.h
  17. --- a/drivers/clk/mediatek/Makefile
  18. +++ b/drivers/clk/mediatek/Makefile
  19. @@ -7,6 +7,7 @@ obj-$(CONFIG_MT8512) += clk-mt8512.o
  20. obj-$(CONFIG_TARGET_MT7623) += clk-mt7623.o
  21. obj-$(CONFIG_TARGET_MT7622) += clk-mt7622.o
  22. obj-$(CONFIG_TARGET_MT7629) += clk-mt7629.o
  23. +obj-$(CONFIG_TARGET_MT7986) += clk-mt7986.o
  24. obj-$(CONFIG_TARGET_MT8183) += clk-mt8183.o
  25. obj-$(CONFIG_TARGET_MT8516) += clk-mt8516.o
  26. obj-$(CONFIG_TARGET_MT8518) += clk-mt8518.o
  27. --- /dev/null
  28. +++ b/drivers/clk/mediatek/clk-mt7986.c
  29. @@ -0,0 +1,672 @@
  30. +// SPDX-License-Identifier: GPL-2.0
  31. +/*
  32. + * MediaTek clock driver for MT7986 SoC
  33. + *
  34. + * Copyright (C) 2022 MediaTek Inc.
  35. + * Author: Sam Shih <[email protected]>
  36. + */
  37. +
  38. +#include <dm.h>
  39. +#include <log.h>
  40. +#include <asm/arch-mediatek/reset.h>
  41. +#include <asm/io.h>
  42. +#include <dt-bindings/clock/mt7986-clk.h>
  43. +#include <linux/bitops.h>
  44. +
  45. +#include "clk-mtk.h"
  46. +
  47. +#define MT7986_CLK_PDN 0x250
  48. +#define MT7986_CLK_PDN_EN_WRITE BIT(31)
  49. +
  50. +#define PLL_FACTOR(_id, _name, _parent, _mult, _div) \
  51. + FACTOR(_id, _parent, _mult, _div, CLK_PARENT_APMIXED)
  52. +
  53. +#define TOP_FACTOR(_id, _name, _parent, _mult, _div) \
  54. + FACTOR(_id, _parent, _mult, _div, CLK_PARENT_TOPCKGEN)
  55. +
  56. +#define INFRA_FACTOR(_id, _name, _parent, _mult, _div) \
  57. + FACTOR(_id, _parent, _mult, _div, CLK_PARENT_INFRASYS)
  58. +
  59. +/* FIXED PLLS */
  60. +static const struct mtk_fixed_clk fixed_pll_clks[] = {
  61. + FIXED_CLK(CK_APMIXED_ARMPLL, CLK_XTAL, 2000000000),
  62. + FIXED_CLK(CK_APMIXED_NET2PLL, CLK_XTAL, 800000000),
  63. + FIXED_CLK(CK_APMIXED_MMPLL, CLK_XTAL, 1440000000),
  64. + FIXED_CLK(CK_APMIXED_SGMPLL, CLK_XTAL, 325000000),
  65. + FIXED_CLK(CK_APMIXED_WEDMCUPLL, CLK_XTAL, 760000000),
  66. + FIXED_CLK(CK_APMIXED_NET1PLL, CLK_XTAL, 2500000000),
  67. + FIXED_CLK(CK_APMIXED_MPLL, CLK_XTAL, 416000000),
  68. + FIXED_CLK(CK_APMIXED_APLL2, CLK_XTAL, 196608000),
  69. +};
  70. +
  71. +/* TOPCKGEN FIXED CLK */
  72. +static const struct mtk_fixed_clk top_fixed_clks[] = {
  73. + FIXED_CLK(CK_TOP_CB_CKSQ_40M, CLK_XTAL, 40000000),
  74. +};
  75. +
  76. +/* TOPCKGEN FIXED DIV */
  77. +static const struct mtk_fixed_factor top_fixed_divs[] = {
  78. + PLL_FACTOR(CK_TOP_CB_M_416M, "cb_m_416m", CK_APMIXED_MPLL, 1, 1),
  79. + PLL_FACTOR(CK_TOP_CB_M_D2, "cb_m_d2", CK_APMIXED_MPLL, 1, 2),
  80. + PLL_FACTOR(CK_TOP_CB_M_D4, "cb_m_d4", CK_APMIXED_MPLL, 1, 4),
  81. + PLL_FACTOR(CK_TOP_CB_M_D8, "cb_m_d8", CK_APMIXED_MPLL, 1, 8),
  82. + PLL_FACTOR(CK_TOP_M_D8_D2, "m_d8_d2", CK_APMIXED_MPLL, 1, 16),
  83. + PLL_FACTOR(CK_TOP_M_D3_D2, "m_d3_d2", CK_APMIXED_MPLL, 1, 2),
  84. + PLL_FACTOR(CK_TOP_CB_MM_D2, "cb_mm_d2", CK_APMIXED_MMPLL, 1, 2),
  85. + PLL_FACTOR(CK_TOP_CB_MM_D4, "cb_mm_d4", CK_APMIXED_MMPLL, 1, 4),
  86. + PLL_FACTOR(CK_TOP_CB_MM_D8, "cb_mm_d8", CK_APMIXED_MMPLL, 1, 8),
  87. + PLL_FACTOR(CK_TOP_MM_D8_D2, "mm_d8_d2", CK_APMIXED_MMPLL, 1, 16),
  88. + PLL_FACTOR(CK_TOP_MM_D3_D8, "mm_d3_d8", CK_APMIXED_MMPLL, 1, 8),
  89. + PLL_FACTOR(CK_TOP_CB_U2_PHYD_CK, "cb_u2_phyd", CK_APMIXED_MMPLL, 1, 30),
  90. + PLL_FACTOR(CK_TOP_CB_APLL2_196M, "cb_apll2_196m", CK_APMIXED_APLL2, 1,
  91. + 1),
  92. + PLL_FACTOR(CK_TOP_APLL2_D4, "apll2_d4", CK_APMIXED_APLL2, 1, 4),
  93. + PLL_FACTOR(CK_TOP_CB_NET1_D4, "cb_net1_d4", CK_APMIXED_NET1PLL, 1, 4),
  94. + PLL_FACTOR(CK_TOP_CB_NET1_D5, "cb_net1_d5", CK_APMIXED_NET1PLL, 1, 5),
  95. + PLL_FACTOR(CK_TOP_NET1_D5_D2, "net1_d5_d2", CK_APMIXED_NET1PLL, 1, 10),
  96. + PLL_FACTOR(CK_TOP_NET1_D5_D4, "net1_d5_d4", CK_APMIXED_NET1PLL, 1, 20),
  97. + PLL_FACTOR(CK_TOP_NET1_D8_D2, "net1_d8_d2", CK_APMIXED_NET1PLL, 1, 16),
  98. + PLL_FACTOR(CK_TOP_NET1_D8_D4, "net1_d8_d4", CK_APMIXED_NET1PLL, 1, 32),
  99. + PLL_FACTOR(CK_TOP_CB_NET2_800M, "cb_net2_800m", CK_APMIXED_NET2PLL, 1,
  100. + 1),
  101. + PLL_FACTOR(CK_TOP_CB_NET2_D4, "cb_net2_d4", CK_APMIXED_NET2PLL, 1, 4),
  102. + PLL_FACTOR(CK_TOP_NET2_D4_D2, "net2_d4_d2", CK_APMIXED_NET2PLL, 1, 8),
  103. + PLL_FACTOR(CK_TOP_NET2_D3_D2, "net2_d3_d2", CK_APMIXED_NET2PLL, 1, 2),
  104. + PLL_FACTOR(CK_TOP_CB_WEDMCU_760M, "cb_wedmcu_760m",
  105. + CK_APMIXED_WEDMCUPLL, 1, 1),
  106. + PLL_FACTOR(CK_TOP_WEDMCU_D5_D2, "wedmcu_d5_d2", CK_APMIXED_WEDMCUPLL, 1,
  107. + 10),
  108. + PLL_FACTOR(CK_TOP_CB_SGM_325M, "cb_sgm_325m", CK_APMIXED_SGMPLL, 1, 1),
  109. + TOP_FACTOR(CK_TOP_CB_CKSQ_40M_D2, "cb_cksq_40m_d2", CK_TOP_CB_CKSQ_40M,
  110. + 1, 2),
  111. + TOP_FACTOR(CK_TOP_CB_RTC_32K, "cb_rtc_32k", CK_TOP_CB_CKSQ_40M, 1,
  112. + 1250),
  113. + TOP_FACTOR(CK_TOP_CB_RTC_32P7K, "cb_rtc_32p7k", CK_TOP_CB_CKSQ_40M, 1,
  114. + 1220),
  115. + TOP_FACTOR(CK_TOP_NFI1X, "nfi1x", CK_TOP_NFI1X_SEL, 1, 1),
  116. + TOP_FACTOR(CK_TOP_USB_EQ_RX250M, "usb_eq_rx250m", CK_TOP_CB_CKSQ_40M, 1,
  117. + 1),
  118. + TOP_FACTOR(CK_TOP_USB_TX250M, "usb_tx250m", CK_TOP_CB_CKSQ_40M, 1, 1),
  119. + TOP_FACTOR(CK_TOP_USB_LN0_CK, "usb_ln0", CK_TOP_CB_CKSQ_40M, 1, 1),
  120. + TOP_FACTOR(CK_TOP_USB_CDR_CK, "usb_cdr", CK_TOP_CB_CKSQ_40M, 1, 1),
  121. + TOP_FACTOR(CK_TOP_SPINFI_BCK, "spinfi_bck", CK_TOP_SPINFI_SEL, 1, 1),
  122. + TOP_FACTOR(CK_TOP_I2C_BCK, "i2c_bck", CK_TOP_I2C_SEL, 1, 1),
  123. + TOP_FACTOR(CK_TOP_PEXTP_TL, "pextp_tl", CK_TOP_PEXTP_TL_SEL, 1, 1),
  124. + TOP_FACTOR(CK_TOP_EMMC_250M, "emmc_250m", CK_TOP_EMMC_250M_SEL, 1, 1),
  125. + TOP_FACTOR(CK_TOP_EMMC_416M, "emmc_416m", CK_TOP_EMMC_416M_SEL, 1, 1),
  126. + TOP_FACTOR(CK_TOP_F_26M_ADC_CK, "f_26m_adc", CK_TOP_F_26M_ADC_SEL, 1,
  127. + 1),
  128. + TOP_FACTOR(CK_TOP_SYSAXI, "sysaxi", CK_TOP_SYSAXI_SEL, 1, 1),
  129. + TOP_FACTOR(CK_TOP_NETSYS_WED_MCU, "netsys_wed_mcu",
  130. + CK_TOP_NETSYS_MCU_SEL, 1, 1),
  131. + TOP_FACTOR(CK_TOP_NETSYS_2X, "netsys_2x", CK_TOP_NETSYS_2X_SEL, 1, 1),
  132. + TOP_FACTOR(CK_TOP_SGM_325M, "sgm_325m", CK_TOP_SGM_325M_SEL, 1, 1),
  133. + TOP_FACTOR(CK_TOP_A1SYS, "a1sys", CK_TOP_A1SYS_SEL, 1, 1),
  134. + TOP_FACTOR(CK_TOP_EIP_B, "eip_b", CK_TOP_EIP_B_SEL, 1, 1),
  135. + TOP_FACTOR(CK_TOP_F26M, "csw_f26m", CK_TOP_F26M_SEL, 1, 1),
  136. + TOP_FACTOR(CK_TOP_AUD_L, "aud_l", CK_TOP_AUD_L_SEL, 1, 1),
  137. + TOP_FACTOR(CK_TOP_A_TUNER, "a_tuner", CK_TOP_A_TUNER_SEL, 2, 1),
  138. + TOP_FACTOR(CK_TOP_U2U3_REF, "u2u3_ref", CK_TOP_U2U3_SEL, 1, 1),
  139. + TOP_FACTOR(CK_TOP_U2U3_SYS, "u2u3_sys", CK_TOP_U2U3_SYS_SEL, 1, 1),
  140. + TOP_FACTOR(CK_TOP_U2U3_XHCI, "u2u3_xhci", CK_TOP_U2U3_XHCI_SEL, 1, 1),
  141. + TOP_FACTOR(CK_TOP_AP2CNN_HOST, "ap2cnn_host", CK_TOP_AP2CNN_HOST_SEL, 1,
  142. + 1),
  143. +};
  144. +
  145. +/* TOPCKGEN MUX PARENTS */
  146. +static const int nfi1x_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_CB_MM_D8,
  147. + CK_TOP_NET1_D8_D2, CK_TOP_NET2_D3_D2,
  148. + CK_TOP_CB_M_D4, CK_TOP_MM_D8_D2,
  149. + CK_TOP_WEDMCU_D5_D2, CK_TOP_CB_M_D8 };
  150. +
  151. +static const int spinfi_parents[] = {
  152. + CK_TOP_CB_CKSQ_40M_D2, CK_TOP_CB_CKSQ_40M, CK_TOP_NET1_D5_D4,
  153. + CK_TOP_CB_M_D4, CK_TOP_MM_D8_D2, CK_TOP_WEDMCU_D5_D2,
  154. + CK_TOP_MM_D3_D8, CK_TOP_CB_M_D8
  155. +};
  156. +
  157. +static const int spi_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_CB_M_D2,
  158. + CK_TOP_CB_MM_D8, CK_TOP_NET1_D8_D2,
  159. + CK_TOP_NET2_D3_D2, CK_TOP_NET1_D5_D4,
  160. + CK_TOP_CB_M_D4, CK_TOP_WEDMCU_D5_D2 };
  161. +
  162. +static const int uart_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_CB_M_D8,
  163. + CK_TOP_M_D8_D2 };
  164. +
  165. +static const int pwm_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_NET1_D8_D2,
  166. + CK_TOP_NET1_D5_D4, CK_TOP_CB_M_D4 };
  167. +
  168. +static const int i2c_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_NET1_D5_D4,
  169. + CK_TOP_CB_M_D4, CK_TOP_NET1_D8_D4 };
  170. +
  171. +static const int pextp_tl_ck_parents[] = { CK_TOP_CB_CKSQ_40M,
  172. + CK_TOP_NET1_D5_D4, CK_TOP_NET2_D4_D2,
  173. + CK_TOP_CB_RTC_32K };
  174. +
  175. +static const int emmc_250m_parents[] = { CK_TOP_CB_CKSQ_40M,
  176. + CK_TOP_NET1_D5_D2 };
  177. +
  178. +static const int emmc_416m_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_CB_M_416M };
  179. +
  180. +static const int f_26m_adc_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_M_D8_D2 };
  181. +
  182. +static const int dramc_md32_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_CB_M_D2 };
  183. +
  184. +static const int sysaxi_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_NET1_D8_D2,
  185. + CK_TOP_CB_NET2_D4 };
  186. +
  187. +static const int sysapb_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_M_D3_D2,
  188. + CK_TOP_NET2_D4_D2 };
  189. +
  190. +static const int arm_db_main_parents[] = { CK_TOP_CB_CKSQ_40M,
  191. + CK_TOP_NET2_D3_D2 };
  192. +
  193. +static const int arm_db_jtsel_parents[] = { -1, CK_TOP_CB_CKSQ_40M };
  194. +
  195. +static const int netsys_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_CB_MM_D4 };
  196. +
  197. +static const int netsys_500m_parents[] = { CK_TOP_CB_CKSQ_40M,
  198. + CK_TOP_CB_NET1_D5 };
  199. +
  200. +static const int netsys_mcu_parents[] = { CK_TOP_CB_CKSQ_40M,
  201. + CK_TOP_CB_WEDMCU_760M,
  202. + CK_TOP_CB_MM_D2, CK_TOP_CB_NET1_D4,
  203. + CK_TOP_CB_NET1_D5 };
  204. +
  205. +static const int netsys_2x_parents[] = { CK_TOP_CB_CKSQ_40M,
  206. + CK_TOP_CB_NET2_800M,
  207. + CK_TOP_CB_WEDMCU_760M,
  208. + CK_TOP_CB_MM_D2 };
  209. +
  210. +static const int sgm_325m_parents[] = { CK_TOP_CB_CKSQ_40M,
  211. + CK_TOP_CB_SGM_325M };
  212. +
  213. +static const int sgm_reg_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_NET1_D8_D4 };
  214. +
  215. +static const int a1sys_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_APLL2_D4 };
  216. +
  217. +static const int conn_mcusys_parents[] = { CK_TOP_CB_CKSQ_40M,
  218. + CK_TOP_CB_MM_D2 };
  219. +
  220. +static const int eip_b_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_CB_NET2_800M };
  221. +
  222. +static const int aud_l_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_CB_APLL2_196M,
  223. + CK_TOP_M_D8_D2 };
  224. +
  225. +static const int a_tuner_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_APLL2_D4,
  226. + CK_TOP_M_D8_D2 };
  227. +
  228. +static const int u2u3_sys_parents[] = { CK_TOP_CB_CKSQ_40M, CK_TOP_NET1_D5_D4 };
  229. +
  230. +static const int da_u2_refsel_parents[] = { CK_TOP_CB_CKSQ_40M,
  231. + CK_TOP_CB_U2_PHYD_CK };
  232. +
  233. +#define TOP_MUX(_id, _name, _parents, _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \
  234. + _shift, _width, _gate, _upd_ofs, _upd) \
  235. + { \
  236. + .id = _id, .mux_reg = _mux_ofs, .mux_set_reg = _mux_set_ofs, \
  237. + .mux_clr_reg = _mux_clr_ofs, .upd_reg = _upd_ofs, \
  238. + .upd_shift = _upd, .mux_shift = _shift, \
  239. + .mux_mask = BIT(_width) - 1, .gate_reg = _mux_ofs, \
  240. + .gate_shift = _gate, .parent = _parents, \
  241. + .num_parents = ARRAY_SIZE(_parents), \
  242. + .flags = CLK_MUX_SETCLR_UPD, \
  243. + }
  244. +
  245. +/* TOPCKGEN MUX_GATE */
  246. +static const struct mtk_composite top_muxes[] = {
  247. + /* CLK_CFG_0 */
  248. + TOP_MUX(CK_TOP_NFI1X_SEL, "nfi1x_sel", nfi1x_parents, 0x000, 0x004,
  249. + 0x008, 0, 3, 7, 0x1C0, 0),
  250. + TOP_MUX(CK_TOP_SPINFI_SEL, "spinfi_sel", spinfi_parents, 0x000, 0x004,
  251. + 0x008, 8, 3, 15, 0x1C0, 1),
  252. + TOP_MUX(CK_TOP_SPI_SEL, "spi_sel", spi_parents, 0x000, 0x004, 0x008, 16,
  253. + 3, 23, 0x1C0, 2),
  254. + TOP_MUX(CK_TOP_SPIM_MST_SEL, "spim_mst_sel", spi_parents, 0x000, 0x004,
  255. + 0x008, 24, 3, 31, 0x1C0, 3),
  256. + /* CLK_CFG_1 */
  257. + TOP_MUX(CK_TOP_UART_SEL, "uart_sel", uart_parents, 0x010, 0x014, 0x018,
  258. + 0, 2, 7, 0x1C0, 4),
  259. + TOP_MUX(CK_TOP_PWM_SEL, "pwm_sel", pwm_parents, 0x010, 0x014, 0x018, 8,
  260. + 2, 15, 0x1C0, 5),
  261. + TOP_MUX(CK_TOP_I2C_SEL, "i2c_sel", i2c_parents, 0x010, 0x014, 0x018, 16,
  262. + 2, 23, 0x1C0, 6),
  263. + TOP_MUX(CK_TOP_PEXTP_TL_SEL, "pextp_tl_ck_sel", pextp_tl_ck_parents,
  264. + 0x010, 0x014, 0x018, 24, 2, 31, 0x1C0, 7),
  265. + /* CLK_CFG_2 */
  266. + TOP_MUX(CK_TOP_EMMC_250M_SEL, "emmc_250m_sel", emmc_250m_parents, 0x020,
  267. + 0x024, 0x028, 0, 1, 7, 0x1C0, 8),
  268. + TOP_MUX(CK_TOP_EMMC_416M_SEL, "emmc_416m_sel", emmc_416m_parents, 0x020,
  269. + 0x024, 0x028, 8, 1, 15, 0x1C0, 9),
  270. + TOP_MUX(CK_TOP_F_26M_ADC_SEL, "f_26m_adc_sel", f_26m_adc_parents, 0x020,
  271. + 0x024, 0x028, 16, 1, 23, 0x1C0, 10),
  272. + TOP_MUX(CK_TOP_DRAMC_SEL, "dramc_sel", f_26m_adc_parents, 0x020, 0x024,
  273. + 0x028, 24, 1, 31, 0x1C0, 11),
  274. + /* CLK_CFG_3 */
  275. + TOP_MUX(CK_TOP_DRAMC_MD32_SEL, "dramc_md32_sel", dramc_md32_parents,
  276. + 0x030, 0x034, 0x038, 0, 1, 7, 0x1C0, 12),
  277. + TOP_MUX(CK_TOP_SYSAXI_SEL, "sysaxi_sel", sysaxi_parents, 0x030, 0x034,
  278. + 0x038, 8, 2, 15, 0x1C0, 13),
  279. + TOP_MUX(CK_TOP_SYSAPB_SEL, "sysapb_sel", sysapb_parents, 0x030, 0x034,
  280. + 0x038, 16, 2, 23, 0x1C0, 14),
  281. + TOP_MUX(CK_TOP_ARM_DB_MAIN_SEL, "arm_db_main_sel", arm_db_main_parents,
  282. + 0x030, 0x034, 0x038, 24, 1, 31, 0x1C0, 15),
  283. + /* CLK_CFG_4 */
  284. + TOP_MUX(CK_TOP_ARM_DB_JTSEL, "arm_db_jtsel", arm_db_jtsel_parents,
  285. + 0x040, 0x044, 0x048, 0, 1, 7, 0x1C0, 16),
  286. + TOP_MUX(CK_TOP_NETSYS_SEL, "netsys_sel", netsys_parents, 0x040, 0x044,
  287. + 0x048, 8, 1, 15, 0x1C0, 17),
  288. + TOP_MUX(CK_TOP_NETSYS_500M_SEL, "netsys_500m_sel", netsys_500m_parents,
  289. + 0x040, 0x044, 0x048, 16, 1, 23, 0x1C0, 18),
  290. + TOP_MUX(CK_TOP_NETSYS_MCU_SEL, "netsys_mcu_sel", netsys_mcu_parents,
  291. + 0x040, 0x044, 0x048, 24, 3, 31, 0x1C0, 19),
  292. + /* CLK_CFG_5 */
  293. + TOP_MUX(CK_TOP_NETSYS_2X_SEL, "netsys_2x_sel", netsys_2x_parents, 0x050,
  294. + 0x054, 0x058, 0, 2, 7, 0x1C0, 20),
  295. + TOP_MUX(CK_TOP_SGM_325M_SEL, "sgm_325m_sel", sgm_325m_parents, 0x050,
  296. + 0x054, 0x058, 8, 1, 15, 0x1C0, 21),
  297. + TOP_MUX(CK_TOP_SGM_REG_SEL, "sgm_reg_sel", sgm_reg_parents, 0x050,
  298. + 0x054, 0x058, 16, 1, 23, 0x1C0, 22),
  299. + TOP_MUX(CK_TOP_A1SYS_SEL, "a1sys_sel", a1sys_parents, 0x050, 0x054,
  300. + 0x058, 24, 1, 31, 0x1C0, 23),
  301. + /* CLK_CFG_6 */
  302. + TOP_MUX(CK_TOP_CONN_MCUSYS_SEL, "conn_mcusys_sel", conn_mcusys_parents,
  303. + 0x060, 0x064, 0x068, 0, 1, 7, 0x1C0, 24),
  304. + TOP_MUX(CK_TOP_EIP_B_SEL, "eip_b_sel", eip_b_parents, 0x060, 0x064,
  305. + 0x068, 8, 1, 15, 0x1C0, 25),
  306. + TOP_MUX(CK_TOP_PCIE_PHY_SEL, "pcie_phy_sel", f_26m_adc_parents, 0x060,
  307. + 0x064, 0x068, 16, 1, 23, 0x1C0, 26),
  308. + TOP_MUX(CK_TOP_USB3_PHY_SEL, "usb3_phy_sel", f_26m_adc_parents, 0x060,
  309. + 0x064, 0x068, 24, 1, 31, 0x1C0, 27),
  310. + /* CLK_CFG_7 */
  311. + TOP_MUX(CK_TOP_F26M_SEL, "csw_f26m_sel", f_26m_adc_parents, 0x070,
  312. + 0x074, 0x078, 0, 1, 7, 0x1C0, 28),
  313. + TOP_MUX(CK_TOP_AUD_L_SEL, "aud_l_sel", aud_l_parents, 0x070, 0x074,
  314. + 0x078, 8, 2, 15, 0x1C0, 29),
  315. + TOP_MUX(CK_TOP_A_TUNER_SEL, "a_tuner_sel", a_tuner_parents, 0x070,
  316. + 0x074, 0x078, 16, 2, 23, 0x1C0, 30),
  317. + TOP_MUX(CK_TOP_U2U3_SEL, "u2u3_sel", f_26m_adc_parents, 0x070, 0x074,
  318. + 0x078, 24, 1, 31, 0x1C4, 0),
  319. + /* CLK_CFG_8 */
  320. + TOP_MUX(CK_TOP_U2U3_SYS_SEL, "u2u3_sys_sel", u2u3_sys_parents, 0x080,
  321. + 0x084, 0x088, 0, 1, 7, 0x1C4, 1),
  322. + TOP_MUX(CK_TOP_U2U3_XHCI_SEL, "u2u3_xhci_sel", u2u3_sys_parents, 0x080,
  323. + 0x084, 0x088, 8, 1, 15, 0x1C4, 2),
  324. + TOP_MUX(CK_TOP_DA_U2_REFSEL, "da_u2_refsel", da_u2_refsel_parents,
  325. + 0x080, 0x084, 0x088, 16, 1, 23, 0x1C4, 3),
  326. + TOP_MUX(CK_TOP_DA_U2_CK_1P_SEL, "da_u2_ck_1p_sel", da_u2_refsel_parents,
  327. + 0x080, 0x084, 0x088, 24, 1, 31, 0x1C4, 4),
  328. + /* CLK_CFG_9 */
  329. + TOP_MUX(CK_TOP_AP2CNN_HOST_SEL, "ap2cnn_host_sel", sgm_reg_parents,
  330. + 0x090, 0x094, 0x098, 0, 1, 7, 0x1C4, 5),
  331. +};
  332. +
  333. +/* INFRA FIXED DIV */
  334. +static const struct mtk_fixed_factor infra_fixed_divs[] = {
  335. + TOP_FACTOR(CK_INFRA_CK_F26M, "infra_ck_f26m", CK_TOP_F26M_SEL, 1, 1),
  336. + TOP_FACTOR(CK_INFRA_UART, "infra_uart", CK_TOP_UART_SEL, 1, 1),
  337. + TOP_FACTOR(CK_INFRA_ISPI0, "infra_ispi0", CK_TOP_SPI_SEL, 1, 1),
  338. + TOP_FACTOR(CK_INFRA_I2C, "infra_i2c", CK_TOP_I2C_SEL, 1, 1),
  339. + TOP_FACTOR(CK_INFRA_ISPI1, "infra_ispi1", CK_TOP_SPINFI_SEL, 1, 1),
  340. + TOP_FACTOR(CK_INFRA_PWM, "infra_pwm", CK_TOP_PWM_SEL, 1, 1),
  341. + TOP_FACTOR(CK_INFRA_66M_MCK, "infra_66m_mck", CK_TOP_SYSAXI_SEL, 1, 2),
  342. + TOP_FACTOR(CK_INFRA_CK_F32K, "infra_ck_f32k", CK_TOP_CB_RTC_32P7K, 1,
  343. + 1),
  344. + TOP_FACTOR(CK_INFRA_PCIE_CK, "infra_pcie", CK_TOP_PEXTP_TL_SEL, 1, 1),
  345. + INFRA_FACTOR(CK_INFRA_PWM_BCK, "infra_pwm_bck", CK_INFRA_PWM_BSEL, 1,
  346. + 1),
  347. + INFRA_FACTOR(CK_INFRA_PWM_CK1, "infra_pwm_ck1", CK_INFRA_PWM1_SEL, 1,
  348. + 1),
  349. + INFRA_FACTOR(CK_INFRA_PWM_CK2, "infra_pwm_ck2", CK_INFRA_PWM2_SEL, 1,
  350. + 1),
  351. + TOP_FACTOR(CK_INFRA_133M_HCK, "infra_133m_hck", CK_TOP_SYSAXI, 1, 1),
  352. + TOP_FACTOR(CK_INFRA_EIP_CK, "infra_eip", CK_TOP_EIP_B, 1, 1),
  353. + INFRA_FACTOR(CK_INFRA_66M_PHCK, "infra_66m_phck", CK_INFRA_133M_HCK, 1,
  354. + 1),
  355. + TOP_FACTOR(CK_INFRA_FAUD_L_CK, "infra_faud_l", CK_TOP_AUD_L, 1, 1),
  356. + TOP_FACTOR(CK_INFRA_FAUD_AUD_CK, "infra_faud_aud", CK_TOP_A1SYS, 1, 1),
  357. + TOP_FACTOR(CK_INFRA_FAUD_EG2_CK, "infra_faud_eg2", CK_TOP_A_TUNER, 1,
  358. + 1),
  359. + TOP_FACTOR(CK_INFRA_I2CS_CK, "infra_i2cs", CK_TOP_I2C_BCK, 1, 1),
  360. + INFRA_FACTOR(CK_INFRA_MUX_UART0, "infra_mux_uart0", CK_INFRA_UART0_SEL,
  361. + 1, 1),
  362. + INFRA_FACTOR(CK_INFRA_MUX_UART1, "infra_mux_uart1", CK_INFRA_UART1_SEL,
  363. + 1, 1),
  364. + INFRA_FACTOR(CK_INFRA_MUX_UART2, "infra_mux_uart2", CK_INFRA_UART2_SEL,
  365. + 1, 1),
  366. + TOP_FACTOR(CK_INFRA_NFI_CK, "infra_nfi", CK_TOP_NFI1X, 1, 1),
  367. + TOP_FACTOR(CK_INFRA_SPINFI_CK, "infra_spinfi", CK_TOP_SPINFI_BCK, 1, 1),
  368. + INFRA_FACTOR(CK_INFRA_MUX_SPI0, "infra_mux_spi0", CK_INFRA_SPI0_SEL, 1,
  369. + 1),
  370. + INFRA_FACTOR(CK_INFRA_MUX_SPI1, "infra_mux_spi1", CK_INFRA_SPI1_SEL, 1,
  371. + 1),
  372. + TOP_FACTOR(CK_INFRA_RTC_32K, "infra_rtc_32k", CK_TOP_CB_RTC_32K, 1, 1),
  373. + TOP_FACTOR(CK_INFRA_FMSDC_CK, "infra_fmsdc", CK_TOP_EMMC_416M, 1, 1),
  374. + TOP_FACTOR(CK_INFRA_FMSDC_HCK_CK, "infra_fmsdc_hck", CK_TOP_EMMC_250M,
  375. + 1, 1),
  376. + TOP_FACTOR(CK_INFRA_PERI_133M, "infra_peri_133m", CK_TOP_SYSAXI, 1, 1),
  377. + TOP_FACTOR(CK_INFRA_133M_PHCK, "infra_133m_phck", CK_TOP_SYSAXI, 1, 1),
  378. + TOP_FACTOR(CK_INFRA_USB_SYS_CK, "infra_usb_sys", CK_TOP_U2U3_SYS, 1, 1),
  379. + TOP_FACTOR(CK_INFRA_USB_CK, "infra_usb", CK_TOP_U2U3_REF, 1, 1),
  380. + TOP_FACTOR(CK_INFRA_USB_XHCI_CK, "infra_usb_xhci", CK_TOP_U2U3_XHCI, 1,
  381. + 1),
  382. + TOP_FACTOR(CK_INFRA_PCIE_GFMUX_TL_O_PRE, "infra_pcie_mux",
  383. + CK_TOP_PEXTP_TL, 1, 1),
  384. + TOP_FACTOR(CK_INFRA_F26M_CK0, "infra_f26m_ck0", CK_TOP_F26M, 1, 1),
  385. + TOP_FACTOR(CK_INFRA_HD_133M, "infra_hd_133m", CK_TOP_SYSAXI, 1, 1),
  386. +};
  387. +
  388. +/* INFRASYS MUX PARENTS */
  389. +static const int infra_uart0_parents[] = { CK_INFRA_CK_F26M, CK_INFRA_UART };
  390. +
  391. +static const int infra_spi0_parents[] = { CK_INFRA_I2C, CK_INFRA_ISPI0 };
  392. +
  393. +static const int infra_spi1_parents[] = { CK_INFRA_I2C, CK_INFRA_ISPI1 };
  394. +
  395. +static const int infra_pwm_bsel_parents[] = { CK_INFRA_CK_F32K,
  396. + CK_INFRA_CK_F26M,
  397. + CK_INFRA_66M_MCK, CK_INFRA_PWM };
  398. +
  399. +static const int infra_pcie_parents[] = { CK_INFRA_CK_F32K, CK_INFRA_CK_F26M,
  400. + -1, CK_INFRA_PCIE_CK };
  401. +
  402. +#define INFRA_MUX(_id, _name, _parents, _reg, _shift, _width) \
  403. + { \
  404. + .id = _id, .mux_reg = (_reg) + 0x8, \
  405. + .mux_set_reg = (_reg) + 0x0, .mux_clr_reg = (_reg) + 0x4, \
  406. + .mux_shift = _shift, .mux_mask = BIT(_width) - 1, \
  407. + .parent = _parents, .num_parents = ARRAY_SIZE(_parents), \
  408. + .flags = CLK_MUX_SETCLR_UPD | CLK_PARENT_INFRASYS, \
  409. + }
  410. +
  411. +/* INFRA MUX */
  412. +
  413. +static const struct mtk_composite infra_muxes[] = {
  414. + /* MODULE_CLK_SEL_0 */
  415. + INFRA_MUX(CK_INFRA_UART0_SEL, "infra_uart0_sel", infra_uart0_parents,
  416. + 0x10, 0, 1),
  417. + INFRA_MUX(CK_INFRA_UART1_SEL, "infra_uart1_sel", infra_uart0_parents,
  418. + 0x10, 1, 1),
  419. + INFRA_MUX(CK_INFRA_UART2_SEL, "infra_uart2_sel", infra_uart0_parents,
  420. + 0x10, 2, 1),
  421. + INFRA_MUX(CK_INFRA_SPI0_SEL, "infra_spi0_sel", infra_spi0_parents, 0x10,
  422. + 4, 1),
  423. + INFRA_MUX(CK_INFRA_SPI1_SEL, "infra_spi1_sel", infra_spi1_parents, 0x10,
  424. + 5, 1),
  425. + INFRA_MUX(CK_INFRA_PWM1_SEL, "infra_pwm1_sel", infra_pwm_bsel_parents,
  426. + 0x10, 9, 2),
  427. + INFRA_MUX(CK_INFRA_PWM2_SEL, "infra_pwm2_sel", infra_pwm_bsel_parents,
  428. + 0x10, 11, 2),
  429. + INFRA_MUX(CK_INFRA_PWM_BSEL, "infra_pwm_bsel", infra_pwm_bsel_parents,
  430. + 0x10, 13, 2),
  431. + /* MODULE_CLK_SEL_1 */
  432. + INFRA_MUX(CK_INFRA_PCIE_SEL, "infra_pcie_sel", infra_pcie_parents, 0x20,
  433. + 0, 2),
  434. +};
  435. +
  436. +static const struct mtk_gate_regs infra_0_cg_regs = {
  437. + .set_ofs = 0x40,
  438. + .clr_ofs = 0x44,
  439. + .sta_ofs = 0x48,
  440. +};
  441. +
  442. +static const struct mtk_gate_regs infra_1_cg_regs = {
  443. + .set_ofs = 0x50,
  444. + .clr_ofs = 0x54,
  445. + .sta_ofs = 0x58,
  446. +};
  447. +
  448. +static const struct mtk_gate_regs infra_2_cg_regs = {
  449. + .set_ofs = 0x60,
  450. + .clr_ofs = 0x64,
  451. + .sta_ofs = 0x68,
  452. +};
  453. +
  454. +#define GATE_INFRA0(_id, _name, _parent, _shift) \
  455. + { \
  456. + .id = _id, .parent = _parent, .regs = &infra_0_cg_regs, \
  457. + .shift = _shift, \
  458. + .flags = CLK_GATE_SETCLR | CLK_PARENT_INFRASYS, \
  459. + }
  460. +
  461. +#define GATE_INFRA1(_id, _name, _parent, _shift) \
  462. + { \
  463. + .id = _id, .parent = _parent, .regs = &infra_1_cg_regs, \
  464. + .shift = _shift, \
  465. + .flags = CLK_GATE_SETCLR | CLK_PARENT_INFRASYS, \
  466. + }
  467. +
  468. +#define GATE_INFRA2(_id, _name, _parent, _shift) \
  469. + { \
  470. + .id = _id, .parent = _parent, .regs = &infra_2_cg_regs, \
  471. + .shift = _shift, \
  472. + .flags = CLK_GATE_SETCLR | CLK_PARENT_INFRASYS, \
  473. + }
  474. +
  475. +/* INFRA GATE */
  476. +
  477. +static const struct mtk_gate infracfg_ao_gates[] = {
  478. + /* INFRA0 */
  479. + GATE_INFRA0(CK_INFRA_GPT_STA, "infra_gpt_sta", CK_INFRA_66M_MCK, 0),
  480. + GATE_INFRA0(CK_INFRA_PWM_HCK, "infra_pwm_hck", CK_INFRA_66M_MCK, 1),
  481. + GATE_INFRA0(CK_INFRA_PWM_STA, "infra_pwm_sta", CK_INFRA_PWM_BCK, 2),
  482. + GATE_INFRA0(CK_INFRA_PWM1_CK, "infra_pwm1", CK_INFRA_PWM_CK1, 3),
  483. + GATE_INFRA0(CK_INFRA_PWM2_CK, "infra_pwm2", CK_INFRA_PWM_CK2, 4),
  484. + GATE_INFRA0(CK_INFRA_CQ_DMA_CK, "infra_cq_dma", CK_INFRA_133M_HCK, 6),
  485. + GATE_INFRA0(CK_INFRA_EIP97_CK, "infra_eip97", CK_INFRA_EIP_CK, 7),
  486. + GATE_INFRA0(CK_INFRA_AUD_BUS_CK, "infra_aud_bus", CK_INFRA_66M_PHCK, 8),
  487. + GATE_INFRA0(CK_INFRA_AUD_26M_CK, "infra_aud_26m", CK_INFRA_CK_F26M, 9),
  488. + GATE_INFRA0(CK_INFRA_AUD_L_CK, "infra_aud_l", CK_INFRA_FAUD_L_CK, 10),
  489. + GATE_INFRA0(CK_INFRA_AUD_AUD_CK, "infra_aud_aud", CK_INFRA_FAUD_AUD_CK,
  490. + 11),
  491. + GATE_INFRA0(CK_INFRA_AUD_EG2_CK, "infra_aud_eg2", CK_INFRA_FAUD_EG2_CK,
  492. + 13),
  493. + GATE_INFRA0(CK_INFRA_DRAMC_26M_CK, "infra_dramc_26m", CK_INFRA_CK_F26M,
  494. + 14),
  495. + GATE_INFRA0(CK_INFRA_DBG_CK, "infra_dbg", CK_INFRA_66M_MCK, 15),
  496. + GATE_INFRA0(CK_INFRA_AP_DMA_CK, "infra_ap_dma", CK_INFRA_66M_MCK, 16),
  497. + GATE_INFRA0(CK_INFRA_SEJ_CK, "infra_sej", CK_INFRA_66M_MCK, 24),
  498. + GATE_INFRA0(CK_INFRA_SEJ_13M_CK, "infra_sej_13m", CK_INFRA_CK_F26M, 25),
  499. + GATE_INFRA0(CK_INFRA_TRNG_CK, "infra_trng", CK_INFRA_HD_133M, 26),
  500. + /* INFRA1 */
  501. + GATE_INFRA1(CK_INFRA_THERM_CK, "infra_therm", CK_INFRA_CK_F26M, 0),
  502. + GATE_INFRA1(CK_INFRA_I2CO_CK, "infra_i2co", CK_INFRA_I2CS_CK, 1),
  503. + GATE_INFRA1(CK_INFRA_UART0_CK, "infra_uart0", CK_INFRA_MUX_UART0, 2),
  504. + GATE_INFRA1(CK_INFRA_UART1_CK, "infra_uart1", CK_INFRA_MUX_UART1, 3),
  505. + GATE_INFRA1(CK_INFRA_UART2_CK, "infra_uart2", CK_INFRA_MUX_UART2, 4),
  506. + GATE_INFRA1(CK_INFRA_NFI1_CK, "infra_nfi1", CK_INFRA_NFI_CK, 8),
  507. + GATE_INFRA1(CK_INFRA_SPINFI1_CK, "infra_spinfi1", CK_INFRA_SPINFI_CK,
  508. + 9),
  509. + GATE_INFRA1(CK_INFRA_NFI_HCK_CK, "infra_nfi_hck", CK_INFRA_66M_MCK, 10),
  510. + GATE_INFRA1(CK_INFRA_SPI0_CK, "infra_spi0", CK_INFRA_MUX_SPI0, 11),
  511. + GATE_INFRA1(CK_INFRA_SPI1_CK, "infra_spi1", CK_INFRA_MUX_SPI1, 12),
  512. + GATE_INFRA1(CK_INFRA_SPI0_HCK_CK, "infra_spi0_hck", CK_INFRA_66M_MCK,
  513. + 13),
  514. + GATE_INFRA1(CK_INFRA_SPI1_HCK_CK, "infra_spi1_hck", CK_INFRA_66M_MCK,
  515. + 14),
  516. + GATE_INFRA1(CK_INFRA_FRTC_CK, "infra_frtc", CK_INFRA_RTC_32K, 15),
  517. + GATE_INFRA1(CK_INFRA_MSDC_CK, "infra_msdc", CK_INFRA_FMSDC_CK, 16),
  518. + GATE_INFRA1(CK_INFRA_MSDC_HCK_CK, "infra_msdc_hck",
  519. + CK_INFRA_FMSDC_HCK_CK, 17),
  520. + GATE_INFRA1(CK_INFRA_MSDC_133M_CK, "infra_msdc_133m",
  521. + CK_INFRA_PERI_133M, 18),
  522. + GATE_INFRA1(CK_INFRA_MSDC_66M_CK, "infra_msdc_66m", CK_INFRA_66M_PHCK,
  523. + 19),
  524. + GATE_INFRA1(CK_INFRA_ADC_26M_CK, "infra_adc_26m", CK_INFRA_CK_F26M, 20),
  525. + GATE_INFRA1(CK_INFRA_ADC_FRC_CK, "infra_adc_frc", CK_INFRA_CK_F26M, 21),
  526. + GATE_INFRA1(CK_INFRA_FBIST2FPC_CK, "infra_fbist2fpc", CK_INFRA_NFI_CK,
  527. + 23),
  528. + /* INFRA2 */
  529. + GATE_INFRA2(CK_INFRA_IUSB_133_CK, "infra_iusb_133", CK_INFRA_133M_PHCK,
  530. + 0),
  531. + GATE_INFRA2(CK_INFRA_IUSB_66M_CK, "infra_iusb_66m", CK_INFRA_66M_PHCK,
  532. + 1),
  533. + GATE_INFRA2(CK_INFRA_IUSB_SYS_CK, "infra_iusb_sys", CK_INFRA_USB_SYS_CK,
  534. + 2),
  535. + GATE_INFRA2(CK_INFRA_IUSB_CK, "infra_iusb", CK_INFRA_USB_CK, 3),
  536. + GATE_INFRA2(CK_INFRA_IPCIE_CK, "infra_ipcie", CK_INFRA_PCIE_CK, 13),
  537. + GATE_INFRA2(CK_INFRA_IPCIER_CK, "infra_ipcier", CK_INFRA_F26M_CK0, 15),
  538. + GATE_INFRA2(CK_INFRA_IPCIEB_CK, "infra_ipcieb", CK_INFRA_133M_PHCK, 15),
  539. +};
  540. +
  541. +static const struct mtk_clk_tree mt7986_fixed_pll_clk_tree = {
  542. + .fdivs_offs = CLK_APMIXED_NR_CLK,
  543. + .xtal_rate = 40 * MHZ,
  544. + .fclks = fixed_pll_clks,
  545. +};
  546. +
  547. +static const struct mtk_clk_tree mt7986_topckgen_clk_tree = {
  548. + .fdivs_offs = CK_TOP_CB_M_416M,
  549. + .muxes_offs = CK_TOP_NFI1X_SEL,
  550. + .fclks = top_fixed_clks,
  551. + .fdivs = top_fixed_divs,
  552. + .muxes = top_muxes,
  553. + .flags = CLK_BYPASS_XTAL,
  554. +};
  555. +
  556. +static const struct mtk_clk_tree mt7986_infracfg_clk_tree = {
  557. + .fdivs_offs = CK_INFRA_CK_F26M,
  558. + .muxes_offs = CK_INFRA_UART0_SEL,
  559. + .fdivs = infra_fixed_divs,
  560. + .muxes = infra_muxes,
  561. +};
  562. +
  563. +static const struct udevice_id mt7986_fixed_pll_compat[] = {
  564. + { .compatible = "mediatek,mt7986-fixed-plls" },
  565. + {}
  566. +};
  567. +
  568. +static const struct udevice_id mt7986_topckgen_compat[] = {
  569. + { .compatible = "mediatek,mt7986-topckgen" },
  570. + {}
  571. +};
  572. +
  573. +static int mt7986_fixed_pll_probe(struct udevice *dev)
  574. +{
  575. + return mtk_common_clk_init(dev, &mt7986_fixed_pll_clk_tree);
  576. +}
  577. +
  578. +static int mt7986_topckgen_probe(struct udevice *dev)
  579. +{
  580. + struct mtk_clk_priv *priv = dev_get_priv(dev);
  581. +
  582. + priv->base = dev_read_addr_ptr(dev);
  583. + writel(MT7986_CLK_PDN_EN_WRITE, priv->base + MT7986_CLK_PDN);
  584. +
  585. + return mtk_common_clk_init(dev, &mt7986_topckgen_clk_tree);
  586. +}
  587. +
  588. +U_BOOT_DRIVER(mtk_clk_apmixedsys) = {
  589. + .name = "mt7986-clock-fixed-pll",
  590. + .id = UCLASS_CLK,
  591. + .of_match = mt7986_fixed_pll_compat,
  592. + .probe = mt7986_fixed_pll_probe,
  593. + .priv_auto = sizeof(struct mtk_clk_priv),
  594. + .ops = &mtk_clk_topckgen_ops,
  595. + .flags = DM_FLAG_PRE_RELOC,
  596. +};
  597. +
  598. +U_BOOT_DRIVER(mtk_clk_topckgen) = {
  599. + .name = "mt7986-clock-topckgen",
  600. + .id = UCLASS_CLK,
  601. + .of_match = mt7986_topckgen_compat,
  602. + .probe = mt7986_topckgen_probe,
  603. + .priv_auto = sizeof(struct mtk_clk_priv),
  604. + .ops = &mtk_clk_topckgen_ops,
  605. + .flags = DM_FLAG_PRE_RELOC,
  606. +};
  607. +
  608. +static const struct udevice_id mt7986_infracfg_compat[] = {
  609. + { .compatible = "mediatek,mt7986-infracfg" },
  610. + {}
  611. +};
  612. +
  613. +static const struct udevice_id mt7986_infracfg_ao_compat[] = {
  614. + { .compatible = "mediatek,mt7986-infracfg_ao" },
  615. + {}
  616. +};
  617. +
  618. +static int mt7986_infracfg_probe(struct udevice *dev)
  619. +{
  620. + return mtk_common_clk_init(dev, &mt7986_infracfg_clk_tree);
  621. +}
  622. +
  623. +static int mt7986_infracfg_ao_probe(struct udevice *dev)
  624. +{
  625. + return mtk_common_clk_gate_init(dev, &mt7986_infracfg_clk_tree,
  626. + infracfg_ao_gates);
  627. +}
  628. +
  629. +U_BOOT_DRIVER(mtk_clk_infracfg) = {
  630. + .name = "mt7986-clock-infracfg",
  631. + .id = UCLASS_CLK,
  632. + .of_match = mt7986_infracfg_compat,
  633. + .probe = mt7986_infracfg_probe,
  634. + .priv_auto = sizeof(struct mtk_clk_priv),
  635. + .ops = &mtk_clk_infrasys_ops,
  636. + .flags = DM_FLAG_PRE_RELOC,
  637. +};
  638. +
  639. +U_BOOT_DRIVER(mtk_clk_infracfg_ao) = {
  640. + .name = "mt7986-clock-infracfg-ao",
  641. + .id = UCLASS_CLK,
  642. + .of_match = mt7986_infracfg_ao_compat,
  643. + .probe = mt7986_infracfg_ao_probe,
  644. + .priv_auto = sizeof(struct mtk_cg_priv),
  645. + .ops = &mtk_clk_gate_ops,
  646. + .flags = DM_FLAG_PRE_RELOC,
  647. +};
  648. +
  649. +/* ethsys */
  650. +static const struct mtk_gate_regs eth_cg_regs = {
  651. + .sta_ofs = 0x30,
  652. +};
  653. +
  654. +#define GATE_ETH(_id, _name, _parent, _shift) \
  655. + { \
  656. + .id = _id, .parent = _parent, .regs = &eth_cg_regs, \
  657. + .shift = _shift, \
  658. + .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
  659. + }
  660. +
  661. +static const struct mtk_gate eth_cgs[] = {
  662. + GATE_ETH(CK_ETH_FE_EN, "eth_fe_en", CK_TOP_NETSYS_2X, 7),
  663. + GATE_ETH(CK_ETH_GP2_EN, "eth_gp2_en", CK_TOP_SGM_325M, 8),
  664. + GATE_ETH(CK_ETH_GP1_EN, "eth_gp1_en", CK_TOP_SGM_325M, 8),
  665. + GATE_ETH(CK_ETH_WOCPU1_EN, "eth_wocpu1_en", CK_TOP_NETSYS_WED_MCU, 14),
  666. + GATE_ETH(CK_ETH_WOCPU0_EN, "eth_wocpu0_en", CK_TOP_NETSYS_WED_MCU, 15),
  667. +};
  668. +
  669. +static int mt7986_ethsys_probe(struct udevice *dev)
  670. +{
  671. + return mtk_common_clk_gate_init(dev, &mt7986_topckgen_clk_tree,
  672. + eth_cgs);
  673. +}
  674. +
  675. +static int mt7986_ethsys_bind(struct udevice *dev)
  676. +{
  677. + int ret = 0;
  678. +
  679. + if (CONFIG_IS_ENABLED(RESET_MEDIATEK)) {
  680. + ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1);
  681. + if (ret)
  682. + debug("Warning: failed to bind reset controller\n");
  683. + }
  684. +
  685. + return ret;
  686. +}
  687. +
  688. +static const struct udevice_id mt7986_ethsys_compat[] = {
  689. + { .compatible = "mediatek,mt7986-ethsys" },
  690. + { }
  691. +};
  692. +
  693. +U_BOOT_DRIVER(mtk_clk_ethsys) = {
  694. + .name = "mt7986-clock-ethsys",
  695. + .id = UCLASS_CLK,
  696. + .of_match = mt7986_ethsys_compat,
  697. + .probe = mt7986_ethsys_probe,
  698. + .bind = mt7986_ethsys_bind,
  699. + .priv_auto = sizeof(struct mtk_cg_priv),
  700. + .ops = &mtk_clk_gate_ops,
  701. +};
  702. --- /dev/null
  703. +++ b/include/dt-bindings/clock/mt7986-clk.h
  704. @@ -0,0 +1,249 @@
  705. +/* SPDX-License-Identifier: GPL-2.0 */
  706. +/*
  707. + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
  708. + *
  709. + * Author: Sam Shih <[email protected]>
  710. + */
  711. +
  712. +#ifndef _DT_BINDINGS_CLK_MT7986_H
  713. +#define _DT_BINDINGS_CLK_MT7986_H
  714. +
  715. +/* INFRACFG */
  716. +
  717. +#define CK_INFRA_CK_F26M 0
  718. +#define CK_INFRA_UART 1
  719. +#define CK_INFRA_ISPI0 2
  720. +#define CK_INFRA_I2C 3
  721. +#define CK_INFRA_ISPI1 4
  722. +#define CK_INFRA_PWM 5
  723. +#define CK_INFRA_66M_MCK 6
  724. +#define CK_INFRA_CK_F32K 7
  725. +#define CK_INFRA_PCIE_CK 8
  726. +#define CK_INFRA_PWM_BCK 9
  727. +#define CK_INFRA_PWM_CK1 10
  728. +#define CK_INFRA_PWM_CK2 11
  729. +#define CK_INFRA_133M_HCK 12
  730. +#define CK_INFRA_EIP_CK 13
  731. +#define CK_INFRA_66M_PHCK 14
  732. +#define CK_INFRA_FAUD_L_CK 15
  733. +#define CK_INFRA_FAUD_AUD_CK 17
  734. +#define CK_INFRA_FAUD_EG2_CK 17
  735. +#define CK_INFRA_I2CS_CK 18
  736. +#define CK_INFRA_MUX_UART0 19
  737. +#define CK_INFRA_MUX_UART1 20
  738. +#define CK_INFRA_MUX_UART2 21
  739. +#define CK_INFRA_NFI_CK 22
  740. +#define CK_INFRA_SPINFI_CK 23
  741. +#define CK_INFRA_MUX_SPI0 24
  742. +#define CK_INFRA_MUX_SPI1 25
  743. +#define CK_INFRA_RTC_32K 26
  744. +#define CK_INFRA_FMSDC_CK 27
  745. +#define CK_INFRA_FMSDC_HCK_CK 28
  746. +#define CK_INFRA_PERI_133M 29
  747. +#define CK_INFRA_133M_PHCK 30
  748. +#define CK_INFRA_USB_SYS_CK 31
  749. +#define CK_INFRA_USB_CK 32
  750. +#define CK_INFRA_USB_XHCI_CK 33
  751. +#define CK_INFRA_PCIE_GFMUX_TL_O_PRE 34
  752. +#define CK_INFRA_F26M_CK0 35
  753. +#define CK_INFRA_HD_133M 36
  754. +#define CLK_INFRA_NR_CLK 37
  755. +
  756. +/* TOPCKGEN */
  757. +
  758. +#define CK_TOP_CB_CKSQ_40M 0
  759. +#define CK_TOP_CB_M_416M 1
  760. +#define CK_TOP_CB_M_D2 2
  761. +#define CK_TOP_CB_M_D4 3
  762. +#define CK_TOP_CB_M_D8 4
  763. +#define CK_TOP_M_D8_D2 5
  764. +#define CK_TOP_M_D3_D2 6
  765. +#define CK_TOP_CB_MM_D2 7
  766. +#define CK_TOP_CB_MM_D4 8
  767. +#define CK_TOP_CB_MM_D8 9
  768. +#define CK_TOP_MM_D8_D2 10
  769. +#define CK_TOP_MM_D3_D8 11
  770. +#define CK_TOP_CB_U2_PHYD_CK 12
  771. +#define CK_TOP_CB_APLL2_196M 13
  772. +#define CK_TOP_APLL2_D4 14
  773. +#define CK_TOP_CB_NET1_D4 15
  774. +#define CK_TOP_CB_NET1_D5 16
  775. +#define CK_TOP_NET1_D5_D2 17
  776. +#define CK_TOP_NET1_D5_D4 18
  777. +#define CK_TOP_NET1_D8_D2 19
  778. +#define CK_TOP_NET1_D8_D4 20
  779. +#define CK_TOP_CB_NET2_800M 21
  780. +#define CK_TOP_CB_NET2_D4 22
  781. +#define CK_TOP_NET2_D4_D2 23
  782. +#define CK_TOP_NET2_D3_D2 24
  783. +#define CK_TOP_CB_WEDMCU_760M 25
  784. +#define CK_TOP_WEDMCU_D5_D2 26
  785. +#define CK_TOP_CB_SGM_325M 27
  786. +#define CK_TOP_CB_CKSQ_40M_D2 28
  787. +#define CK_TOP_CB_RTC_32K 29
  788. +#define CK_TOP_CB_RTC_32P7K 30
  789. +#define CK_TOP_NFI1X 31
  790. +#define CK_TOP_USB_EQ_RX250M 32
  791. +#define CK_TOP_USB_TX250M 33
  792. +#define CK_TOP_USB_LN0_CK 34
  793. +#define CK_TOP_USB_CDR_CK 35
  794. +#define CK_TOP_SPINFI_BCK 36
  795. +#define CK_TOP_I2C_BCK 37
  796. +#define CK_TOP_PEXTP_TL 38
  797. +#define CK_TOP_EMMC_250M 39
  798. +#define CK_TOP_EMMC_416M 40
  799. +#define CK_TOP_F_26M_ADC_CK 41
  800. +#define CK_TOP_SYSAXI 42
  801. +#define CK_TOP_NETSYS_WED_MCU 43
  802. +#define CK_TOP_NETSYS_2X 44
  803. +#define CK_TOP_SGM_325M 45
  804. +#define CK_TOP_A1SYS 46
  805. +#define CK_TOP_EIP_B 47
  806. +#define CK_TOP_F26M 48
  807. +#define CK_TOP_AUD_L 49
  808. +#define CK_TOP_A_TUNER 50
  809. +#define CK_TOP_U2U3_REF 51
  810. +#define CK_TOP_U2U3_SYS 52
  811. +#define CK_TOP_U2U3_XHCI 53
  812. +#define CK_TOP_AP2CNN_HOST 54
  813. +#define CK_TOP_NFI1X_SEL 55
  814. +#define CK_TOP_SPINFI_SEL 56
  815. +#define CK_TOP_SPI_SEL 57
  816. +#define CK_TOP_SPIM_MST_SEL 58
  817. +#define CK_TOP_UART_SEL 59
  818. +#define CK_TOP_PWM_SEL 60
  819. +#define CK_TOP_I2C_SEL 61
  820. +#define CK_TOP_PEXTP_TL_SEL 62
  821. +#define CK_TOP_EMMC_250M_SEL 63
  822. +#define CK_TOP_EMMC_416M_SEL 64
  823. +#define CK_TOP_F_26M_ADC_SEL 65
  824. +#define CK_TOP_DRAMC_SEL 66
  825. +#define CK_TOP_DRAMC_MD32_SEL 67
  826. +#define CK_TOP_SYSAXI_SEL 68
  827. +#define CK_TOP_SYSAPB_SEL 69
  828. +#define CK_TOP_ARM_DB_MAIN_SEL 70
  829. +#define CK_TOP_ARM_DB_JTSEL 71
  830. +#define CK_TOP_NETSYS_SEL 72
  831. +#define CK_TOP_NETSYS_500M_SEL 73
  832. +#define CK_TOP_NETSYS_MCU_SEL 74
  833. +#define CK_TOP_NETSYS_2X_SEL 75
  834. +#define CK_TOP_SGM_325M_SEL 76
  835. +#define CK_TOP_SGM_REG_SEL 77
  836. +#define CK_TOP_A1SYS_SEL 78
  837. +#define CK_TOP_CONN_MCUSYS_SEL 79
  838. +#define CK_TOP_EIP_B_SEL 80
  839. +#define CK_TOP_PCIE_PHY_SEL 81
  840. +#define CK_TOP_USB3_PHY_SEL 82
  841. +#define CK_TOP_F26M_SEL 83
  842. +#define CK_TOP_AUD_L_SEL 84
  843. +#define CK_TOP_A_TUNER_SEL 85
  844. +#define CK_TOP_U2U3_SEL 86
  845. +#define CK_TOP_U2U3_SYS_SEL 87
  846. +#define CK_TOP_U2U3_XHCI_SEL 88
  847. +#define CK_TOP_DA_U2_REFSEL 89
  848. +#define CK_TOP_DA_U2_CK_1P_SEL 90
  849. +#define CK_TOP_AP2CNN_HOST_SEL 91
  850. +#define CLK_TOP_NR_CLK 92
  851. +
  852. +/*
  853. + * INFRACFG_AO
  854. + * clock muxes need to be append to infracfg domain, and clock gates
  855. + * need to be keep in infracgh_ao domain
  856. + */
  857. +
  858. +#define CK_INFRA_UART0_SEL (0 + CLK_INFRA_NR_CLK)
  859. +#define CK_INFRA_UART1_SEL (1 + CLK_INFRA_NR_CLK)
  860. +#define CK_INFRA_UART2_SEL (2 + CLK_INFRA_NR_CLK)
  861. +#define CK_INFRA_SPI0_SEL (3 + CLK_INFRA_NR_CLK)
  862. +#define CK_INFRA_SPI1_SEL (4 + CLK_INFRA_NR_CLK)
  863. +#define CK_INFRA_PWM1_SEL (5 + CLK_INFRA_NR_CLK)
  864. +#define CK_INFRA_PWM2_SEL (6 + CLK_INFRA_NR_CLK)
  865. +#define CK_INFRA_PWM_BSEL (7 + CLK_INFRA_NR_CLK)
  866. +#define CK_INFRA_PCIE_SEL (8 + CLK_INFRA_NR_CLK)
  867. +#define CK_INFRA_GPT_STA 0
  868. +#define CK_INFRA_PWM_HCK 1
  869. +#define CK_INFRA_PWM_STA 2
  870. +#define CK_INFRA_PWM1_CK 3
  871. +#define CK_INFRA_PWM2_CK 4
  872. +#define CK_INFRA_CQ_DMA_CK 5
  873. +#define CK_INFRA_EIP97_CK 6
  874. +#define CK_INFRA_AUD_BUS_CK 7
  875. +#define CK_INFRA_AUD_26M_CK 8
  876. +#define CK_INFRA_AUD_L_CK 9
  877. +#define CK_INFRA_AUD_AUD_CK 10
  878. +#define CK_INFRA_AUD_EG2_CK 11
  879. +#define CK_INFRA_DRAMC_26M_CK 12
  880. +#define CK_INFRA_DBG_CK 13
  881. +#define CK_INFRA_AP_DMA_CK 14
  882. +#define CK_INFRA_SEJ_CK 15
  883. +#define CK_INFRA_SEJ_13M_CK 16
  884. +#define CK_INFRA_THERM_CK 17
  885. +#define CK_INFRA_I2CO_CK 18
  886. +#define CK_INFRA_TRNG_CK 19
  887. +#define CK_INFRA_UART0_CK 20
  888. +#define CK_INFRA_UART1_CK 21
  889. +#define CK_INFRA_UART2_CK 22
  890. +#define CK_INFRA_NFI1_CK 23
  891. +#define CK_INFRA_SPINFI1_CK 24
  892. +#define CK_INFRA_NFI_HCK_CK 25
  893. +#define CK_INFRA_SPI0_CK 26
  894. +#define CK_INFRA_SPI1_CK 27
  895. +#define CK_INFRA_SPI0_HCK_CK 28
  896. +#define CK_INFRA_SPI1_HCK_CK 29
  897. +#define CK_INFRA_FRTC_CK 30
  898. +#define CK_INFRA_MSDC_CK 31
  899. +#define CK_INFRA_MSDC_HCK_CK 32
  900. +#define CK_INFRA_MSDC_133M_CK 33
  901. +#define CK_INFRA_MSDC_66M_CK 34
  902. +#define CK_INFRA_ADC_26M_CK 35
  903. +#define CK_INFRA_ADC_FRC_CK 36
  904. +#define CK_INFRA_FBIST2FPC_CK 37
  905. +#define CK_INFRA_IUSB_133_CK 38
  906. +#define CK_INFRA_IUSB_66M_CK 39
  907. +#define CK_INFRA_IUSB_SYS_CK 40
  908. +#define CK_INFRA_IUSB_CK 41
  909. +#define CK_INFRA_IPCIE_CK 42
  910. +#define CK_INFRA_IPCIER_CK 43
  911. +#define CK_INFRA_IPCIEB_CK 44
  912. +#define CLK_INFRA_AO_NR_CLK 45
  913. +
  914. +/* APMIXEDSYS */
  915. +
  916. +#define CK_APMIXED_ARMPLL 0
  917. +#define CK_APMIXED_NET2PLL 1
  918. +#define CK_APMIXED_MMPLL 2
  919. +#define CK_APMIXED_SGMPLL 3
  920. +#define CK_APMIXED_WEDMCUPLL 4
  921. +#define CK_APMIXED_NET1PLL 5
  922. +#define CK_APMIXED_MPLL 6
  923. +#define CK_APMIXED_APLL2 7
  924. +#define CLK_APMIXED_NR_CLK 8
  925. +
  926. +/* SGMIISYS_0 */
  927. +
  928. +#define CK_SGM0_TX_EN 0
  929. +#define CK_SGM0_RX_EN 1
  930. +#define CK_SGM0_CK0_EN 2
  931. +#define CK_SGM0_CDR_CK0_EN 3
  932. +#define CLK_SGMII0_NR_CLK 4
  933. +
  934. +/* SGMIISYS_1 */
  935. +
  936. +#define CK_SGM1_TX_EN 0
  937. +#define CK_SGM1_RX_EN 1
  938. +#define CK_SGM1_CK1_EN 2
  939. +#define CK_SGM1_CDR_CK1_EN 3
  940. +#define CLK_SGMII1_NR_CLK 4
  941. +
  942. +/* ETHSYS */
  943. +
  944. +#define CK_ETH_FE_EN 0
  945. +#define CK_ETH_GP2_EN 1
  946. +#define CK_ETH_GP1_EN 2
  947. +#define CK_ETH_WOCPU1_EN 3
  948. +#define CK_ETH_WOCPU0_EN 4
  949. +#define CLK_ETH_NR_CLK 5
  950. +
  951. +#endif
  952. +
  953. +/* _DT_BINDINGS_CLK_MT7986_H */