clk-mt8135.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2014 MediaTek Inc.
  4. * Author: James Liao <[email protected]>
  5. * Copyright (c) 2023 Collabora, Ltd.
  6. * AngeloGioacchino Del Regno <[email protected]>
  7. */
  8. #include <linux/clk.h>
  9. #include <linux/of.h>
  10. #include <linux/of_address.h>
  11. #include <linux/slab.h>
  12. #include <linux/mfd/syscon.h>
  13. #include <dt-bindings/clock/mt8135-clk.h>
  14. #include "clk-gate.h"
  15. #include "clk-mtk.h"
  16. #include "clk-pll.h"
  17. static DEFINE_SPINLOCK(mt8135_clk_lock);
  18. static const struct mtk_fixed_factor root_clk_alias[] __initconst = {
  19. FACTOR(CLK_TOP_DSI0_LNTC_DSICLK, "dsi0_lntc_dsiclk", "clk_null", 1, 1),
  20. FACTOR(CLK_TOP_HDMITX_CLKDIG_CTS, "hdmitx_clkdig_cts", "clk_null", 1, 1),
  21. FACTOR(CLK_TOP_CLKPH_MCK, "clkph_mck", "clk_null", 1, 1),
  22. FACTOR(CLK_TOP_CPUM_TCK_IN, "cpum_tck_in", "clk_null", 1, 1),
  23. };
  24. static const struct mtk_fixed_factor top_divs[] __initconst = {
  25. FACTOR(CLK_TOP_MAINPLL_806M, "mainpll_806m", "mainpll", 1, 2),
  26. FACTOR(CLK_TOP_MAINPLL_537P3M, "mainpll_537p3m", "mainpll", 1, 3),
  27. FACTOR(CLK_TOP_MAINPLL_322P4M, "mainpll_322p4m", "mainpll", 1, 5),
  28. FACTOR(CLK_TOP_MAINPLL_230P3M, "mainpll_230p3m", "mainpll", 1, 7),
  29. FACTOR(CLK_TOP_UNIVPLL_624M, "univpll_624m", "univpll", 1, 2),
  30. FACTOR(CLK_TOP_UNIVPLL_416M, "univpll_416m", "univpll", 1, 3),
  31. FACTOR(CLK_TOP_UNIVPLL_249P6M, "univpll_249p6m", "univpll", 1, 5),
  32. FACTOR(CLK_TOP_UNIVPLL_178P3M, "univpll_178p3m", "univpll", 1, 7),
  33. FACTOR(CLK_TOP_UNIVPLL_48M, "univpll_48m", "univpll", 1, 26),
  34. FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll", 1, 2),
  35. FACTOR(CLK_TOP_MMPLL_D3, "mmpll_d3", "mmpll", 1, 3),
  36. FACTOR(CLK_TOP_MMPLL_D5, "mmpll_d5", "mmpll", 1, 5),
  37. FACTOR(CLK_TOP_MMPLL_D7, "mmpll_d7", "mmpll", 1, 7),
  38. FACTOR(CLK_TOP_MMPLL_D4, "mmpll_d4", "mmpll_d2", 1, 2),
  39. FACTOR(CLK_TOP_MMPLL_D6, "mmpll_d6", "mmpll_d3", 1, 2),
  40. FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "mainpll_806m", 1, 1),
  41. FACTOR(CLK_TOP_SYSPLL_D4, "syspll_d4", "mainpll_806m", 1, 2),
  42. FACTOR(CLK_TOP_SYSPLL_D6, "syspll_d6", "mainpll_806m", 1, 3),
  43. FACTOR(CLK_TOP_SYSPLL_D8, "syspll_d8", "mainpll_806m", 1, 4),
  44. FACTOR(CLK_TOP_SYSPLL_D10, "syspll_d10", "mainpll_806m", 1, 5),
  45. FACTOR(CLK_TOP_SYSPLL_D12, "syspll_d12", "mainpll_806m", 1, 6),
  46. FACTOR(CLK_TOP_SYSPLL_D16, "syspll_d16", "mainpll_806m", 1, 8),
  47. FACTOR(CLK_TOP_SYSPLL_D24, "syspll_d24", "mainpll_806m", 1, 12),
  48. FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "mainpll_537p3m", 1, 1),
  49. FACTOR(CLK_TOP_SYSPLL_D2P5, "syspll_d2p5", "mainpll_322p4m", 2, 1),
  50. FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll_322p4m", 1, 1),
  51. FACTOR(CLK_TOP_SYSPLL_D3P5, "syspll_d3p5", "mainpll_230p3m", 2, 1),
  52. FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_624m", 1, 2),
  53. FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_624m", 1, 4),
  54. FACTOR(CLK_TOP_UNIVPLL1_D6, "univpll1_d6", "univpll_624m", 1, 6),
  55. FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll_624m", 1, 8),
  56. FACTOR(CLK_TOP_UNIVPLL1_D10, "univpll1_d10", "univpll_624m", 1, 10),
  57. FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll_416m", 1, 2),
  58. FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll_416m", 1, 4),
  59. FACTOR(CLK_TOP_UNIVPLL2_D6, "univpll2_d6", "univpll_416m", 1, 6),
  60. FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll_416m", 1, 8),
  61. FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll_416m", 1, 1),
  62. FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll_249p6m", 1, 1),
  63. FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll_178p3m", 1, 1),
  64. FACTOR(CLK_TOP_UNIVPLL_D10, "univpll_d10", "univpll_249p6m", 1, 2),
  65. FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univpll_48m", 1, 1),
  66. FACTOR(CLK_TOP_APLL, "apll_ck", "audpll", 1, 1),
  67. FACTOR(CLK_TOP_APLL_D4, "apll_d4", "audpll", 1, 4),
  68. FACTOR(CLK_TOP_APLL_D8, "apll_d8", "audpll", 1, 8),
  69. FACTOR(CLK_TOP_APLL_D16, "apll_d16", "audpll", 1, 16),
  70. FACTOR(CLK_TOP_APLL_D24, "apll_d24", "audpll", 1, 24),
  71. FACTOR(CLK_TOP_LVDSPLL_D2, "lvdspll_d2", "lvdspll", 1, 2),
  72. FACTOR(CLK_TOP_LVDSPLL_D4, "lvdspll_d4", "lvdspll", 1, 4),
  73. FACTOR(CLK_TOP_LVDSPLL_D8, "lvdspll_d8", "lvdspll", 1, 8),
  74. FACTOR(CLK_TOP_LVDSTX_CLKDIG_CT, "lvdstx_clkdig_cts", "lvdspll", 1, 1),
  75. FACTOR(CLK_TOP_VPLL_DPIX, "vpll_dpix_ck", "lvdspll", 1, 1),
  76. FACTOR(CLK_TOP_TVHDMI_H, "tvhdmi_h_ck", "tvdpll", 1, 1),
  77. FACTOR(CLK_TOP_HDMITX_CLKDIG_D2, "hdmitx_clkdig_d2", "hdmitx_clkdig_cts", 1, 2),
  78. FACTOR(CLK_TOP_HDMITX_CLKDIG_D3, "hdmitx_clkdig_d3", "hdmitx_clkdig_cts", 1, 3),
  79. FACTOR(CLK_TOP_TVHDMI_D2, "tvhdmi_d2", "tvhdmi_h_ck", 1, 2),
  80. FACTOR(CLK_TOP_TVHDMI_D4, "tvhdmi_d4", "tvhdmi_h_ck", 1, 4),
  81. FACTOR(CLK_TOP_MEMPLL_MCK_D4, "mempll_mck_d4", "clkph_mck", 1, 4),
  82. };
  83. static const char * const axi_parents[] __initconst = {
  84. "clk26m",
  85. "syspll_d3",
  86. "syspll_d4",
  87. "syspll_d6",
  88. "univpll_d5",
  89. "univpll2_d2",
  90. "syspll_d3p5"
  91. };
  92. static const char * const smi_parents[] __initconst = {
  93. "clk26m",
  94. "clkph_mck",
  95. "syspll_d2p5",
  96. "syspll_d3",
  97. "syspll_d8",
  98. "univpll_d5",
  99. "univpll1_d2",
  100. "univpll1_d6",
  101. "mmpll_d3",
  102. "mmpll_d4",
  103. "mmpll_d5",
  104. "mmpll_d6",
  105. "mmpll_d7",
  106. "vdecpll",
  107. "lvdspll"
  108. };
  109. static const char * const mfg_parents[] __initconst = {
  110. "clk26m",
  111. "univpll1_d4",
  112. "syspll_d2",
  113. "syspll_d2p5",
  114. "syspll_d3",
  115. "univpll_d5",
  116. "univpll1_d2",
  117. "mmpll_d2",
  118. "mmpll_d3",
  119. "mmpll_d4",
  120. "mmpll_d5",
  121. "mmpll_d6",
  122. "mmpll_d7"
  123. };
  124. static const char * const irda_parents[] __initconst = {
  125. "clk26m",
  126. "univpll2_d8",
  127. "univpll1_d6"
  128. };
  129. static const char * const cam_parents[] __initconst = {
  130. "clk26m",
  131. "syspll_d3",
  132. "syspll_d3p5",
  133. "syspll_d4",
  134. "univpll_d5",
  135. "univpll2_d2",
  136. "univpll_d7",
  137. "univpll1_d4"
  138. };
  139. static const char * const aud_intbus_parents[] __initconst = {
  140. "clk26m",
  141. "syspll_d6",
  142. "univpll_d10"
  143. };
  144. static const char * const jpg_parents[] __initconst = {
  145. "clk26m",
  146. "syspll_d5",
  147. "syspll_d4",
  148. "syspll_d3",
  149. "univpll_d7",
  150. "univpll2_d2",
  151. "univpll_d5"
  152. };
  153. static const char * const disp_parents[] __initconst = {
  154. "clk26m",
  155. "syspll_d3p5",
  156. "syspll_d3",
  157. "univpll2_d2",
  158. "univpll_d5",
  159. "univpll1_d2",
  160. "lvdspll",
  161. "vdecpll"
  162. };
  163. static const char * const msdc30_parents[] __initconst = {
  164. "clk26m",
  165. "syspll_d6",
  166. "syspll_d5",
  167. "univpll1_d4",
  168. "univpll2_d4",
  169. "msdcpll"
  170. };
  171. static const char * const usb20_parents[] __initconst = {
  172. "clk26m",
  173. "univpll2_d6",
  174. "univpll1_d10"
  175. };
  176. static const char * const venc_parents[] __initconst = {
  177. "clk26m",
  178. "syspll_d3",
  179. "syspll_d8",
  180. "univpll_d5",
  181. "univpll1_d6",
  182. "mmpll_d4",
  183. "mmpll_d5",
  184. "mmpll_d6"
  185. };
  186. static const char * const spi_parents[] __initconst = {
  187. "clk26m",
  188. "syspll_d6",
  189. "syspll_d8",
  190. "syspll_d10",
  191. "univpll1_d6",
  192. "univpll1_d8"
  193. };
  194. static const char * const uart_parents[] __initconst = {
  195. "clk26m",
  196. "univpll2_d8"
  197. };
  198. static const char * const mem_parents[] __initconst = {
  199. "clk26m",
  200. "clkph_mck"
  201. };
  202. static const char * const camtg_parents[] __initconst = {
  203. "clk26m",
  204. "univpll_d26",
  205. "univpll1_d6",
  206. "syspll_d16",
  207. "syspll_d8"
  208. };
  209. static const char * const audio_parents[] __initconst = {
  210. "clk26m",
  211. "syspll_d24"
  212. };
  213. static const char * const fix_parents[] __initconst = {
  214. "rtc32k",
  215. "clk26m",
  216. "univpll_d5",
  217. "univpll_d7",
  218. "univpll1_d2",
  219. "univpll1_d4",
  220. "univpll1_d6",
  221. "univpll1_d8"
  222. };
  223. static const char * const vdec_parents[] __initconst = {
  224. "clk26m",
  225. "vdecpll",
  226. "clkph_mck",
  227. "syspll_d2p5",
  228. "syspll_d3",
  229. "syspll_d3p5",
  230. "syspll_d4",
  231. "syspll_d5",
  232. "syspll_d6",
  233. "syspll_d8",
  234. "univpll1_d2",
  235. "univpll2_d2",
  236. "univpll_d7",
  237. "univpll_d10",
  238. "univpll2_d4",
  239. "lvdspll"
  240. };
  241. static const char * const ddrphycfg_parents[] __initconst = {
  242. "clk26m",
  243. "axi_sel",
  244. "syspll_d12"
  245. };
  246. static const char * const dpilvds_parents[] __initconst = {
  247. "clk26m",
  248. "lvdspll",
  249. "lvdspll_d2",
  250. "lvdspll_d4",
  251. "lvdspll_d8"
  252. };
  253. static const char * const pmicspi_parents[] __initconst = {
  254. "clk26m",
  255. "univpll2_d6",
  256. "syspll_d8",
  257. "syspll_d10",
  258. "univpll1_d10",
  259. "mempll_mck_d4",
  260. "univpll_d26",
  261. "syspll_d24"
  262. };
  263. static const char * const smi_mfg_as_parents[] __initconst = {
  264. "clk26m",
  265. "smi_sel",
  266. "mfg_sel",
  267. "mem_sel"
  268. };
  269. static const char * const gcpu_parents[] __initconst = {
  270. "clk26m",
  271. "syspll_d4",
  272. "univpll_d7",
  273. "syspll_d5",
  274. "syspll_d6"
  275. };
  276. static const char * const dpi1_parents[] __initconst = {
  277. "clk26m",
  278. "tvhdmi_h_ck",
  279. "tvhdmi_d2",
  280. "tvhdmi_d4"
  281. };
  282. static const char * const cci_parents[] __initconst = {
  283. "clk26m",
  284. "mainpll_537p3m",
  285. "univpll_d3",
  286. "syspll_d2p5",
  287. "syspll_d3",
  288. "syspll_d5"
  289. };
  290. static const char * const apll_parents[] __initconst = {
  291. "clk26m",
  292. "apll_ck",
  293. "apll_d4",
  294. "apll_d8",
  295. "apll_d16",
  296. "apll_d24"
  297. };
  298. static const char * const hdmipll_parents[] __initconst = {
  299. "clk26m",
  300. "hdmitx_clkdig_cts",
  301. "hdmitx_clkdig_d2",
  302. "hdmitx_clkdig_d3"
  303. };
  304. static const struct mtk_composite top_muxes[] __initconst = {
  305. /* CLK_CFG_0 */
  306. MUX_GATE(CLK_TOP_AXI_SEL, "axi_sel", axi_parents,
  307. 0x0140, 0, 3, INVALID_MUX_GATE_BIT),
  308. MUX_GATE(CLK_TOP_SMI_SEL, "smi_sel", smi_parents, 0x0140, 8, 4, 15),
  309. MUX_GATE(CLK_TOP_MFG_SEL, "mfg_sel", mfg_parents, 0x0140, 16, 4, 23),
  310. MUX_GATE(CLK_TOP_IRDA_SEL, "irda_sel", irda_parents, 0x0140, 24, 2, 31),
  311. /* CLK_CFG_1 */
  312. MUX_GATE(CLK_TOP_CAM_SEL, "cam_sel", cam_parents, 0x0144, 0, 3, 7),
  313. MUX_GATE(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel", aud_intbus_parents,
  314. 0x0144, 8, 2, 15),
  315. MUX_GATE(CLK_TOP_JPG_SEL, "jpg_sel", jpg_parents, 0x0144, 16, 3, 23),
  316. MUX_GATE(CLK_TOP_DISP_SEL, "disp_sel", disp_parents, 0x0144, 24, 3, 31),
  317. /* CLK_CFG_2 */
  318. MUX_GATE(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel", msdc30_parents, 0x0148, 0, 3, 7),
  319. MUX_GATE(CLK_TOP_MSDC30_2_SEL, "msdc30_2_sel", msdc30_parents, 0x0148, 8, 3, 15),
  320. MUX_GATE(CLK_TOP_MSDC30_3_SEL, "msdc30_3_sel", msdc30_parents, 0x0148, 16, 3, 23),
  321. MUX_GATE(CLK_TOP_MSDC30_4_SEL, "msdc30_4_sel", msdc30_parents, 0x0148, 24, 3, 31),
  322. /* CLK_CFG_3 */
  323. MUX_GATE(CLK_TOP_USB20_SEL, "usb20_sel", usb20_parents, 0x014c, 0, 2, 7),
  324. /* CLK_CFG_4 */
  325. MUX_GATE(CLK_TOP_VENC_SEL, "venc_sel", venc_parents, 0x0150, 8, 3, 15),
  326. MUX_GATE(CLK_TOP_SPI_SEL, "spi_sel", spi_parents, 0x0150, 16, 3, 23),
  327. MUX_GATE(CLK_TOP_UART_SEL, "uart_sel", uart_parents, 0x0150, 24, 2, 31),
  328. /* CLK_CFG_6 */
  329. MUX_GATE(CLK_TOP_MEM_SEL, "mem_sel", mem_parents, 0x0158, 0, 2, 7),
  330. MUX_GATE(CLK_TOP_CAMTG_SEL, "camtg_sel", camtg_parents, 0x0158, 8, 3, 15),
  331. MUX_GATE(CLK_TOP_AUDIO_SEL, "audio_sel", audio_parents, 0x0158, 24, 2, 31),
  332. /* CLK_CFG_7 */
  333. MUX_GATE(CLK_TOP_FIX_SEL, "fix_sel", fix_parents, 0x015c, 0, 3, 7),
  334. MUX_GATE(CLK_TOP_VDEC_SEL, "vdec_sel", vdec_parents, 0x015c, 8, 4, 15),
  335. MUX_GATE(CLK_TOP_DDRPHYCFG_SEL, "ddrphycfg_sel", ddrphycfg_parents,
  336. 0x015c, 16, 2, 23),
  337. MUX_GATE(CLK_TOP_DPILVDS_SEL, "dpilvds_sel", dpilvds_parents, 0x015c, 24, 3, 31),
  338. /* CLK_CFG_8 */
  339. MUX_GATE(CLK_TOP_PMICSPI_SEL, "pmicspi_sel", pmicspi_parents, 0x0164, 0, 3, 7),
  340. MUX_GATE(CLK_TOP_MSDC30_0_SEL, "msdc30_0_sel", msdc30_parents, 0x0164, 8, 3, 15),
  341. MUX_GATE(CLK_TOP_SMI_MFG_AS_SEL, "smi_mfg_as_sel", smi_mfg_as_parents,
  342. 0x0164, 16, 2, 23),
  343. MUX_GATE(CLK_TOP_GCPU_SEL, "gcpu_sel", gcpu_parents, 0x0164, 24, 3, 31),
  344. /* CLK_CFG_9 */
  345. MUX_GATE(CLK_TOP_DPI1_SEL, "dpi1_sel", dpi1_parents, 0x0168, 0, 2, 7),
  346. MUX_GATE_FLAGS(CLK_TOP_CCI_SEL, "cci_sel", cci_parents, 0x0168, 8, 3, 15, CLK_IS_CRITICAL),
  347. MUX_GATE(CLK_TOP_APLL_SEL, "apll_sel", apll_parents, 0x0168, 16, 3, 23),
  348. MUX_GATE(CLK_TOP_HDMIPLL_SEL, "hdmipll_sel", hdmipll_parents, 0x0168, 24, 2, 31),
  349. };
  350. static const struct mtk_gate_regs infra_cg_regs = {
  351. .set_ofs = 0x0040,
  352. .clr_ofs = 0x0044,
  353. .sta_ofs = 0x0048,
  354. };
  355. #define GATE_ICG(_id, _name, _parent, _shift) \
  356. GATE_MTK(_id, _name, _parent, &infra_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  357. #define GATE_ICG_AO(_id, _name, _parent, _shift) \
  358. GATE_MTK_FLAGS(_id, _name, _parent, &infra_cg_regs, _shift, \
  359. &mtk_clk_gate_ops_setclr, CLK_IS_CRITICAL)
  360. static const struct mtk_gate infra_clks[] __initconst = {
  361. GATE_ICG(CLK_INFRA_PMIC_WRAP, "pmic_wrap_ck", "axi_sel", 23),
  362. GATE_ICG(CLK_INFRA_PMICSPI, "pmicspi_ck", "pmicspi_sel", 22),
  363. GATE_ICG(CLK_INFRA_CCIF1_AP_CTRL, "ccif1_ap_ctrl", "axi_sel", 21),
  364. GATE_ICG(CLK_INFRA_CCIF0_AP_CTRL, "ccif0_ap_ctrl", "axi_sel", 20),
  365. GATE_ICG(CLK_INFRA_KP, "kp_ck", "axi_sel", 16),
  366. GATE_ICG(CLK_INFRA_CPUM, "cpum_ck", "cpum_tck_in", 15),
  367. GATE_ICG_AO(CLK_INFRA_M4U, "m4u_ck", "mem_sel", 8),
  368. GATE_ICG(CLK_INFRA_MFGAXI, "mfgaxi_ck", "axi_sel", 7),
  369. GATE_ICG(CLK_INFRA_DEVAPC, "devapc_ck", "axi_sel", 6),
  370. GATE_ICG(CLK_INFRA_AUDIO, "audio_ck", "aud_intbus_sel", 5),
  371. GATE_ICG(CLK_INFRA_MFG_BUS, "mfg_bus_ck", "axi_sel", 2),
  372. GATE_ICG(CLK_INFRA_SMI, "smi_ck", "smi_sel", 1),
  373. GATE_ICG(CLK_INFRA_DBGCLK, "dbgclk_ck", "axi_sel", 0),
  374. };
  375. static const struct mtk_gate_regs peri0_cg_regs = {
  376. .set_ofs = 0x0008,
  377. .clr_ofs = 0x0010,
  378. .sta_ofs = 0x0018,
  379. };
  380. static const struct mtk_gate_regs peri1_cg_regs = {
  381. .set_ofs = 0x000c,
  382. .clr_ofs = 0x0014,
  383. .sta_ofs = 0x001c,
  384. };
  385. #define GATE_PERI0(_id, _name, _parent, _shift) \
  386. GATE_MTK(_id, _name, _parent, &peri0_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  387. #define GATE_PERI1(_id, _name, _parent, _shift) \
  388. GATE_MTK(_id, _name, _parent, &peri1_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
  389. static const struct mtk_gate peri_gates[] __initconst = {
  390. /* PERI0 */
  391. GATE_PERI0(CLK_PERI_I2C5, "i2c5_ck", "axi_sel", 31),
  392. GATE_PERI0(CLK_PERI_I2C4, "i2c4_ck", "axi_sel", 30),
  393. GATE_PERI0(CLK_PERI_I2C3, "i2c3_ck", "axi_sel", 29),
  394. GATE_PERI0(CLK_PERI_I2C2, "i2c2_ck", "axi_sel", 28),
  395. GATE_PERI0(CLK_PERI_I2C1, "i2c1_ck", "axi_sel", 27),
  396. GATE_PERI0(CLK_PERI_I2C0, "i2c0_ck", "axi_sel", 26),
  397. GATE_PERI0(CLK_PERI_UART3, "uart3_ck", "axi_sel", 25),
  398. GATE_PERI0(CLK_PERI_UART2, "uart2_ck", "axi_sel", 24),
  399. GATE_PERI0(CLK_PERI_UART1, "uart1_ck", "axi_sel", 23),
  400. GATE_PERI0(CLK_PERI_UART0, "uart0_ck", "axi_sel", 22),
  401. GATE_PERI0(CLK_PERI_IRDA, "irda_ck", "irda_sel", 21),
  402. GATE_PERI0(CLK_PERI_NLI, "nli_ck", "axi_sel", 20),
  403. GATE_PERI0(CLK_PERI_MD_HIF, "md_hif_ck", "axi_sel", 19),
  404. GATE_PERI0(CLK_PERI_AP_HIF, "ap_hif_ck", "axi_sel", 18),
  405. GATE_PERI0(CLK_PERI_MSDC30_3, "msdc30_3_ck", "msdc30_4_sel", 17),
  406. GATE_PERI0(CLK_PERI_MSDC30_2, "msdc30_2_ck", "msdc30_3_sel", 16),
  407. GATE_PERI0(CLK_PERI_MSDC30_1, "msdc30_1_ck", "msdc30_2_sel", 15),
  408. GATE_PERI0(CLK_PERI_MSDC20_2, "msdc20_2_ck", "msdc30_1_sel", 14),
  409. GATE_PERI0(CLK_PERI_MSDC20_1, "msdc20_1_ck", "msdc30_0_sel", 13),
  410. GATE_PERI0(CLK_PERI_AP_DMA, "ap_dma_ck", "axi_sel", 12),
  411. GATE_PERI0(CLK_PERI_USB1, "usb1_ck", "usb20_sel", 11),
  412. GATE_PERI0(CLK_PERI_USB0, "usb0_ck", "usb20_sel", 10),
  413. GATE_PERI0(CLK_PERI_PWM, "pwm_ck", "axi_sel", 9),
  414. GATE_PERI0(CLK_PERI_PWM7, "pwm7_ck", "axi_sel", 8),
  415. GATE_PERI0(CLK_PERI_PWM6, "pwm6_ck", "axi_sel", 7),
  416. GATE_PERI0(CLK_PERI_PWM5, "pwm5_ck", "axi_sel", 6),
  417. GATE_PERI0(CLK_PERI_PWM4, "pwm4_ck", "axi_sel", 5),
  418. GATE_PERI0(CLK_PERI_PWM3, "pwm3_ck", "axi_sel", 4),
  419. GATE_PERI0(CLK_PERI_PWM2, "pwm2_ck", "axi_sel", 3),
  420. GATE_PERI0(CLK_PERI_PWM1, "pwm1_ck", "axi_sel", 2),
  421. GATE_PERI0(CLK_PERI_THERM, "therm_ck", "axi_sel", 1),
  422. GATE_PERI0(CLK_PERI_NFI, "nfi_ck", "axi_sel", 0),
  423. /* PERI1 */
  424. GATE_PERI1(CLK_PERI_USBSLV, "usbslv_ck", "axi_sel", 8),
  425. GATE_PERI1(CLK_PERI_USB1_MCU, "usb1_mcu_ck", "axi_sel", 7),
  426. GATE_PERI1(CLK_PERI_USB0_MCU, "usb0_mcu_ck", "axi_sel", 6),
  427. GATE_PERI1(CLK_PERI_GCPU, "gcpu_ck", "gcpu_sel", 5),
  428. GATE_PERI1(CLK_PERI_FHCTL, "fhctl_ck", "clk26m", 4),
  429. GATE_PERI1(CLK_PERI_SPI1, "spi1_ck", "spi_sel", 3),
  430. GATE_PERI1(CLK_PERI_AUXADC, "auxadc_ck", "clk26m", 2),
  431. GATE_PERI1(CLK_PERI_PERI_PWRAP, "peri_pwrap_ck", "axi_sel", 1),
  432. GATE_PERI1(CLK_PERI_I2C6, "i2c6_ck", "axi_sel", 0),
  433. };
  434. static const char * const uart_ck_sel_parents[] __initconst = {
  435. "clk26m",
  436. "uart_sel",
  437. };
  438. static const struct mtk_composite peri_clks[] __initconst = {
  439. MUX(CLK_PERI_UART0_SEL, "uart0_ck_sel", uart_ck_sel_parents, 0x40c, 0, 1),
  440. MUX(CLK_PERI_UART1_SEL, "uart1_ck_sel", uart_ck_sel_parents, 0x40c, 1, 1),
  441. MUX(CLK_PERI_UART2_SEL, "uart2_ck_sel", uart_ck_sel_parents, 0x40c, 2, 1),
  442. MUX(CLK_PERI_UART3_SEL, "uart3_ck_sel", uart_ck_sel_parents, 0x40c, 3, 1),
  443. };
  444. static u16 infrasys_rst_ofs[] = { 0x30, 0x34, };
  445. static u16 pericfg_rst_ofs[] = { 0x0, 0x4, };
  446. static const struct mtk_clk_rst_desc clk_rst_desc[] = {
  447. /* infrasys */
  448. {
  449. .version = MTK_RST_SIMPLE,
  450. .rst_bank_ofs = infrasys_rst_ofs,
  451. .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
  452. },
  453. /* pericfg */
  454. {
  455. .version = MTK_RST_SIMPLE,
  456. .rst_bank_ofs = pericfg_rst_ofs,
  457. .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
  458. }
  459. };
  460. static void __init mtk_topckgen_init(struct device_node *node)
  461. {
  462. struct clk_hw_onecell_data *clk_data;
  463. void __iomem *base;
  464. int r;
  465. base = of_iomap(node, 0);
  466. if (!base) {
  467. pr_err("%s(): ioremap failed\n", __func__);
  468. return;
  469. }
  470. clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
  471. mtk_clk_register_factors(root_clk_alias, ARRAY_SIZE(root_clk_alias), clk_data);
  472. mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
  473. mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
  474. &mt8135_clk_lock, clk_data);
  475. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  476. if (r)
  477. pr_err("%s(): could not register clock provider: %d\n",
  478. __func__, r);
  479. }
  480. CLK_OF_DECLARE(mtk_topckgen, "mediatek,mt8135-topckgen", mtk_topckgen_init);
  481. static void __init mtk_infrasys_init(struct device_node *node)
  482. {
  483. struct clk_hw_onecell_data *clk_data;
  484. int r;
  485. clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
  486. mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
  487. clk_data);
  488. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  489. if (r)
  490. pr_err("%s(): could not register clock provider: %d\n",
  491. __func__, r);
  492. mtk_register_reset_controller(node, &clk_rst_desc[0]);
  493. }
  494. CLK_OF_DECLARE(mtk_infrasys, "mediatek,mt8135-infracfg", mtk_infrasys_init);
  495. static void __init mtk_pericfg_init(struct device_node *node)
  496. {
  497. struct clk_hw_onecell_data *clk_data;
  498. int r;
  499. void __iomem *base;
  500. base = of_iomap(node, 0);
  501. if (!base) {
  502. pr_err("%s(): ioremap failed\n", __func__);
  503. return;
  504. }
  505. clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
  506. mtk_clk_register_gates(node, peri_gates, ARRAY_SIZE(peri_gates),
  507. clk_data);
  508. mtk_clk_register_composites(peri_clks, ARRAY_SIZE(peri_clks), base,
  509. &mt8135_clk_lock, clk_data);
  510. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  511. if (r)
  512. pr_err("%s(): could not register clock provider: %d\n",
  513. __func__, r);
  514. mtk_register_reset_controller(node, &clk_rst_desc[1]);
  515. }
  516. CLK_OF_DECLARE(mtk_pericfg, "mediatek,mt8135-pericfg", mtk_pericfg_init);
  517. #define MT8135_PLL_FMAX (2000 * MHZ)
  518. #define CON0_MT8135_RST_BAR BIT(27)
  519. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift) { \
  520. .id = _id, \
  521. .name = _name, \
  522. .reg = _reg, \
  523. .pwr_reg = _pwr_reg, \
  524. .en_mask = _en_mask, \
  525. .flags = _flags, \
  526. .rst_bar_mask = CON0_MT8135_RST_BAR, \
  527. .fmax = MT8135_PLL_FMAX, \
  528. .pcwbits = _pcwbits, \
  529. .pd_reg = _pd_reg, \
  530. .pd_shift = _pd_shift, \
  531. .tuner_reg = _tuner_reg, \
  532. .pcw_reg = _pcw_reg, \
  533. .pcw_shift = _pcw_shift, \
  534. }
  535. static const struct mtk_pll_data plls[] = {
  536. PLL(CLK_APMIXED_ARMPLL1, "armpll1", 0x200, 0x218, 0x80000000, 0, 21, 0x204, 24, 0x0, 0x204, 0),
  537. PLL(CLK_APMIXED_ARMPLL2, "armpll2", 0x2cc, 0x2e4, 0x80000000, 0, 21, 0x2d0, 24, 0x0, 0x2d0, 0),
  538. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x21c, 0x234, 0xf0000000, HAVE_RST_BAR, 21, 0x21c, 6, 0x0, 0x220, 0),
  539. PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x238, 0x250, 0xf3000000, HAVE_RST_BAR, 7, 0x238, 6, 0x0, 0x238, 9),
  540. PLL(CLK_APMIXED_MMPLL, "mmpll", 0x254, 0x26c, 0xf0000000, HAVE_RST_BAR, 21, 0x254, 6, 0x0, 0x258, 0),
  541. PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x278, 0x290, 0x80000000, 0, 21, 0x278, 6, 0x0, 0x27c, 0),
  542. PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x294, 0x2ac, 0x80000000, 0, 31, 0x294, 6, 0x0, 0x298, 0),
  543. PLL(CLK_APMIXED_LVDSPLL, "lvdspll", 0x2b0, 0x2c8, 0x80000000, 0, 21, 0x2b0, 6, 0x0, 0x2b4, 0),
  544. PLL(CLK_APMIXED_AUDPLL, "audpll", 0x2e8, 0x300, 0x80000000, 0, 31, 0x2e8, 6, 0x2f8, 0x2ec, 0),
  545. PLL(CLK_APMIXED_VDECPLL, "vdecpll", 0x304, 0x31c, 0x80000000, 0, 21, 0x2b0, 6, 0x0, 0x308, 0),
  546. };
  547. static void __init mtk_apmixedsys_init(struct device_node *node)
  548. {
  549. struct clk_hw_onecell_data *clk_data;
  550. clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
  551. if (!clk_data)
  552. return;
  553. mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  554. }
  555. CLK_OF_DECLARE(mtk_apmixedsys, "mediatek,mt8135-apmixedsys",
  556. mtk_apmixedsys_init);