clk-mt6797.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * Copyright (c) 2016 MediaTek Inc.
  3. * Author: Kevin Chen <kevin-cw.chen@mediatek.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/of_device.h>
  17. #include <linux/platform_device.h>
  18. #include "clk-mtk.h"
  19. #include "clk-gate.h"
  20. #include <dt-bindings/clock/mt6797-clk.h>
  21. /*
  22. * For some clocks, we don't care what their actual rates are. And these
  23. * clocks may change their rate on different products or different scenarios.
  24. * So we model these clocks' rate as 0, to denote it's not an actual rate.
  25. */
  26. static DEFINE_SPINLOCK(mt6797_clk_lock);
  27. static const struct mtk_fixed_factor top_fixed_divs[] = {
  28. FACTOR(CLK_TOP_SYSPLL_CK, "syspll_ck", "mainpll", 1, 1),
  29. FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "mainpll", 1, 2),
  30. FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "syspll_d2", 1, 2),
  31. FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "syspll_d2", 1, 4),
  32. FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "syspll_d2", 1, 8),
  33. FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "syspll_d2", 1, 16),
  34. FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "mainpll", 1, 3),
  35. FACTOR(CLK_TOP_SYSPLL_D3_D3, "syspll_d3_d3", "syspll_d3", 1, 3),
  36. FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "syspll_d3", 1, 2),
  37. FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "syspll_d3", 1, 4),
  38. FACTOR(CLK_TOP_SYSPLL2_D8, "syspll2_d8", "syspll_d3", 1, 8),
  39. FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1, 5),
  40. FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "syspll_d5", 1, 2),
  41. FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "syspll_d5", 1, 4),
  42. FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "mainpll", 1, 7),
  43. FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "syspll_d7", 1, 2),
  44. FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "syspll_d7", 1, 4),
  45. FACTOR(CLK_TOP_UNIVPLL_CK, "univpll_ck", "univpll", 1, 1),
  46. FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1, 7),
  47. FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univpll", 1, 26),
  48. FACTOR(CLK_TOP_SSUSB_PHY_48M_CK, "ssusb_phy_48m_ck", "univpll", 1, 1),
  49. FACTOR(CLK_TOP_USB_PHY48M_CK, "usb_phy48m_ck", "univpll", 1, 1),
  50. FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2),
  51. FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_d2", 1, 2),
  52. FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_d2", 1, 4),
  53. FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll_d2", 1, 8),
  54. FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3),
  55. FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll", 1, 2),
  56. FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll", 1, 4),
  57. FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll", 1, 8),
  58. FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
  59. FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll_d5", 1, 2),
  60. FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll_d5", 1, 4),
  61. FACTOR(CLK_TOP_UNIVPLL3_D8, "univpll3_d8", "univpll_d5", 1, 8),
  62. FACTOR(CLK_TOP_ULPOSC_CK_ORG, "ulposc_ck_org", "ulposc", 1, 1),
  63. FACTOR(CLK_TOP_ULPOSC_CK, "ulposc_ck", "ulposc_ck_org", 1, 3),
  64. FACTOR(CLK_TOP_ULPOSC_D2, "ulposc_d2", "ulposc_ck", 1, 2),
  65. FACTOR(CLK_TOP_ULPOSC_D3, "ulposc_d3", "ulposc_ck", 1, 4),
  66. FACTOR(CLK_TOP_ULPOSC_D4, "ulposc_d4", "ulposc_ck", 1, 8),
  67. FACTOR(CLK_TOP_ULPOSC_D8, "ulposc_d8", "ulposc_ck", 1, 10),
  68. FACTOR(CLK_TOP_ULPOSC_D10, "ulposc_d10", "ulposc_ck_org", 1, 1),
  69. FACTOR(CLK_TOP_APLL1_CK, "apll1_ck", "apll1", 1, 1),
  70. FACTOR(CLK_TOP_APLL2_CK, "apll2_ck", "apll2", 1, 1),
  71. FACTOR(CLK_TOP_MFGPLL_CK, "mfgpll_ck", "mfgpll", 1, 1),
  72. FACTOR(CLK_TOP_MFGPLL_D2, "mfgpll_d2", "mfgpll_ck", 1, 2),
  73. FACTOR(CLK_TOP_IMGPLL_CK, "imgpll_ck", "imgpll", 1, 1),
  74. FACTOR(CLK_TOP_IMGPLL_D2, "imgpll_d2", "imgpll_ck", 1, 2),
  75. FACTOR(CLK_TOP_IMGPLL_D4, "imgpll_d4", "imgpll_ck", 1, 4),
  76. FACTOR(CLK_TOP_CODECPLL_CK, "codecpll_ck", "codecpll", 1, 1),
  77. FACTOR(CLK_TOP_CODECPLL_D2, "codecpll_d2", "codecpll_ck", 1, 2),
  78. FACTOR(CLK_TOP_VDECPLL_CK, "vdecpll_ck", "vdecpll", 1, 1),
  79. FACTOR(CLK_TOP_TVDPLL_CK, "tvdpll_ck", "tvdpll", 1, 1),
  80. FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1, 2),
  81. FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll_ck", 1, 4),
  82. FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll_ck", 1, 8),
  83. FACTOR(CLK_TOP_TVDPLL_D16, "tvdpll_d16", "tvdpll_ck", 1, 16),
  84. FACTOR(CLK_TOP_MSDCPLL_CK, "msdcpll_ck", "msdcpll", 1, 1),
  85. FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll_ck", 1, 2),
  86. FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll_ck", 1, 4),
  87. FACTOR(CLK_TOP_MSDCPLL_D8, "msdcpll_d8", "msdcpll_ck", 1, 8),
  88. };
  89. static const char * const axi_parents[] = {
  90. "clk26m",
  91. "syspll_d7",
  92. "ulposc_axi_ck_mux",
  93. };
  94. static const char * const ulposc_axi_ck_mux_parents[] = {
  95. "syspll1_d4",
  96. "ulposc_axi_ck_mux_pre",
  97. };
  98. static const char * const ulposc_axi_ck_mux_pre_parents[] = {
  99. "ulposc_d2",
  100. "ulposc_d3",
  101. };
  102. static const char * const ddrphycfg_parents[] = {
  103. "clk26m",
  104. "syspll3_d2",
  105. "syspll2_d4",
  106. "syspll1_d8",
  107. };
  108. static const char * const mm_parents[] = {
  109. "clk26m",
  110. "imgpll_ck",
  111. "univpll1_d2",
  112. "syspll1_d2",
  113. };
  114. static const char * const pwm_parents[] = {
  115. "clk26m",
  116. "univpll2_d4",
  117. "ulposc_d2",
  118. "ulposc_d3",
  119. "ulposc_d8",
  120. "ulposc_d10",
  121. "ulposc_d4",
  122. };
  123. static const char * const vdec_parents[] = {
  124. "clk26m",
  125. "vdecpll_ck",
  126. "imgpll_ck",
  127. "syspll_d3",
  128. "univpll_d5",
  129. "clk26m",
  130. "clk26m",
  131. };
  132. static const char * const venc_parents[] = {
  133. "clk26m",
  134. "codecpll_ck",
  135. "syspll_d3",
  136. };
  137. static const char * const mfg_parents[] = {
  138. "clk26m",
  139. "mfgpll_ck",
  140. "syspll_d3",
  141. "univpll_d3",
  142. };
  143. static const char * const camtg[] = {
  144. "clk26m",
  145. "univpll_d26",
  146. "univpll2_d2",
  147. };
  148. static const char * const uart_parents[] = {
  149. "clk26m",
  150. "univpll2_d8",
  151. };
  152. static const char * const spi_parents[] = {
  153. "clk26m",
  154. "syspll3_d2",
  155. "syspll2_d4",
  156. "ulposc_spi_ck_mux",
  157. };
  158. static const char * const ulposc_spi_ck_mux_parents[] = {
  159. "ulposc_d2",
  160. "ulposc_d3",
  161. };
  162. static const char * const usb20_parents[] = {
  163. "clk26m",
  164. "univpll1_d8",
  165. "syspll4_d2",
  166. };
  167. static const char * const msdc50_0_hclk_parents[] = {
  168. "clk26m",
  169. "syspll1_d2",
  170. "syspll2_d2",
  171. "syspll4_d2",
  172. };
  173. static const char * const msdc50_0_parents[] = {
  174. "clk26m",
  175. "msdcpll",
  176. "syspll_d3",
  177. "univpll1_d4",
  178. "syspll2_d2",
  179. "syspll_d7",
  180. "msdcpll_d2",
  181. "univpll1_d2",
  182. "univpll_d3",
  183. };
  184. static const char * const msdc30_1_parents[] = {
  185. "clk26m",
  186. "univpll2_d2",
  187. "msdcpll_d2",
  188. "univpll1_d4",
  189. "syspll2_d2",
  190. "syspll_d7",
  191. "univpll_d7",
  192. };
  193. static const char * const msdc30_2_parents[] = {
  194. "clk26m",
  195. "univpll2_d8",
  196. "syspll2_d8",
  197. "syspll1_d8",
  198. "msdcpll_d8",
  199. "syspll3_d4",
  200. "univpll_d26",
  201. };
  202. static const char * const audio_parents[] = {
  203. "clk26m",
  204. "syspll3_d4",
  205. "syspll4_d4",
  206. "syspll1_d16",
  207. };
  208. static const char * const aud_intbus_parents[] = {
  209. "clk26m",
  210. "syspll1_d4",
  211. "syspll4_d2",
  212. };
  213. static const char * const pmicspi_parents[] = {
  214. "clk26m",
  215. "univpll_d26",
  216. "syspll3_d4",
  217. "syspll1_d8",
  218. "ulposc_d4",
  219. "ulposc_d8",
  220. "syspll2_d8",
  221. };
  222. static const char * const scp_parents[] = {
  223. "clk26m",
  224. "syspll_d3",
  225. "ulposc_ck",
  226. "univpll_d5",
  227. };
  228. static const char * const atb_parents[] = {
  229. "clk26m",
  230. "syspll1_d2",
  231. "syspll_d5",
  232. };
  233. static const char * const mjc_parents[] = {
  234. "clk26m",
  235. "imgpll_ck",
  236. "univpll_d5",
  237. "syspll1_d2",
  238. };
  239. static const char * const dpi0_parents[] = {
  240. "clk26m",
  241. "tvdpll_d2",
  242. "tvdpll_d4",
  243. "tvdpll_d8",
  244. "tvdpll_d16",
  245. "clk26m",
  246. "clk26m",
  247. };
  248. static const char * const aud_1_parents[] = {
  249. "clk26m",
  250. "apll1_ck",
  251. };
  252. static const char * const aud_2_parents[] = {
  253. "clk26m",
  254. "apll2_ck",
  255. };
  256. static const char * const ssusb_top_sys_parents[] = {
  257. "clk26m",
  258. "univpll3_d2",
  259. };
  260. static const char * const spm_parents[] = {
  261. "clk26m",
  262. "syspll1_d8",
  263. };
  264. static const char * const bsi_spi_parents[] = {
  265. "clk26m",
  266. "syspll_d3_d3",
  267. "syspll1_d4",
  268. "syspll_d7",
  269. };
  270. static const char * const audio_h_parents[] = {
  271. "clk26m",
  272. "apll2_ck",
  273. "apll1_ck",
  274. "univpll_d7",
  275. };
  276. static const char * const mfg_52m_parents[] = {
  277. "clk26m",
  278. "univpll2_d8",
  279. "univpll2_d4",
  280. "univpll2_d4",
  281. };
  282. static const char * const anc_md32_parents[] = {
  283. "clk26m",
  284. "syspll1_d2",
  285. "univpll_d5",
  286. };
  287. static const struct mtk_composite top_muxes[] = {
  288. MUX(CLK_TOP_MUX_ULPOSC_AXI_CK_MUX_PRE, "ulposc_axi_ck_mux_pre",
  289. ulposc_axi_ck_mux_pre_parents, 0x0040, 3, 1),
  290. MUX(CLK_TOP_MUX_ULPOSC_AXI_CK_MUX, "ulposc_axi_ck_mux",
  291. ulposc_axi_ck_mux_parents, 0x0040, 2, 1),
  292. MUX(CLK_TOP_MUX_AXI, "axi_sel", axi_parents,
  293. 0x0040, 0, 2),
  294. MUX(CLK_TOP_MUX_DDRPHYCFG, "ddrphycfg_sel", ddrphycfg_parents,
  295. 0x0040, 16, 2),
  296. MUX(CLK_TOP_MUX_MM, "mm_sel", mm_parents,
  297. 0x0040, 24, 2),
  298. MUX_GATE(CLK_TOP_MUX_PWM, "pwm_sel", pwm_parents, 0x0050, 0, 3, 7),
  299. MUX_GATE(CLK_TOP_MUX_VDEC, "vdec_sel", vdec_parents, 0x0050, 8, 3, 15),
  300. MUX_GATE(CLK_TOP_MUX_VENC, "venc_sel", venc_parents, 0x0050, 16, 2, 23),
  301. MUX_GATE(CLK_TOP_MUX_MFG, "mfg_sel", mfg_parents, 0x0050, 24, 2, 31),
  302. MUX_GATE(CLK_TOP_MUX_CAMTG, "camtg_sel", camtg, 0x0060, 0, 2, 7),
  303. MUX_GATE(CLK_TOP_MUX_UART, "uart_sel", uart_parents, 0x0060, 8, 1, 15),
  304. MUX_GATE(CLK_TOP_MUX_SPI, "spi_sel", spi_parents, 0x0060, 16, 2, 23),
  305. MUX(CLK_TOP_MUX_ULPOSC_SPI_CK_MUX, "ulposc_spi_ck_mux",
  306. ulposc_spi_ck_mux_parents, 0x0060, 18, 1),
  307. MUX_GATE(CLK_TOP_MUX_USB20, "usb20_sel", usb20_parents,
  308. 0x0060, 24, 2, 31),
  309. MUX(CLK_TOP_MUX_MSDC50_0_HCLK, "msdc50_0_hclk_sel",
  310. msdc50_0_hclk_parents, 0x0070, 8, 2),
  311. MUX_GATE(CLK_TOP_MUX_MSDC50_0, "msdc50_0_sel", msdc50_0_parents,
  312. 0x0070, 16, 4, 23),
  313. MUX_GATE(CLK_TOP_MUX_MSDC30_1, "msdc30_1_sel", msdc30_1_parents,
  314. 0x0070, 24, 3, 31),
  315. MUX_GATE(CLK_TOP_MUX_MSDC30_2, "msdc30_2_sel", msdc30_2_parents,
  316. 0x0080, 0, 3, 7),
  317. MUX_GATE(CLK_TOP_MUX_AUDIO, "audio_sel", audio_parents,
  318. 0x0080, 16, 2, 23),
  319. MUX(CLK_TOP_MUX_AUD_INTBUS, "aud_intbus_sel", aud_intbus_parents,
  320. 0x0080, 24, 2),
  321. MUX(CLK_TOP_MUX_PMICSPI, "pmicspi_sel", pmicspi_parents,
  322. 0x0090, 0, 3),
  323. MUX(CLK_TOP_MUX_SCP, "scp_sel", scp_parents,
  324. 0x0090, 8, 2),
  325. MUX(CLK_TOP_MUX_ATB, "atb_sel", atb_parents,
  326. 0x0090, 16, 2),
  327. MUX_GATE(CLK_TOP_MUX_MJC, "mjc_sel", mjc_parents, 0x0090, 24, 2, 31),
  328. MUX_GATE(CLK_TOP_MUX_DPI0, "dpi0_sel", dpi0_parents, 0x00A0, 0, 3, 7),
  329. MUX_GATE(CLK_TOP_MUX_AUD_1, "aud_1_sel", aud_1_parents,
  330. 0x00A0, 16, 1, 23),
  331. MUX_GATE(CLK_TOP_MUX_AUD_2, "aud_2_sel", aud_2_parents,
  332. 0x00A0, 24, 1, 31),
  333. MUX(CLK_TOP_MUX_SSUSB_TOP_SYS, "ssusb_top_sys_sel",
  334. ssusb_top_sys_parents, 0x00B0, 8, 1),
  335. MUX(CLK_TOP_MUX_SPM, "spm_sel", spm_parents,
  336. 0x00C0, 0, 1),
  337. MUX(CLK_TOP_MUX_BSI_SPI, "bsi_spi_sel", bsi_spi_parents,
  338. 0x00C0, 8, 2),
  339. MUX_GATE(CLK_TOP_MUX_AUDIO_H, "audio_h_sel", audio_h_parents,
  340. 0x00C0, 16, 2, 23),
  341. MUX_GATE(CLK_TOP_MUX_ANC_MD32, "anc_md32_sel", anc_md32_parents,
  342. 0x00C0, 24, 2, 31),
  343. MUX(CLK_TOP_MUX_MFG_52M, "mfg_52m_sel", mfg_52m_parents,
  344. 0x0104, 1, 2),
  345. };
  346. static int mtk_topckgen_init(struct platform_device *pdev)
  347. {
  348. struct clk_onecell_data *clk_data;
  349. void __iomem *base;
  350. struct device_node *node = pdev->dev.of_node;
  351. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  352. base = devm_ioremap_resource(&pdev->dev, res);
  353. if (IS_ERR(base))
  354. return PTR_ERR(base);
  355. clk_data = mtk_alloc_clk_data(CLK_TOP_NR);
  356. mtk_clk_register_factors(top_fixed_divs, ARRAY_SIZE(top_fixed_divs),
  357. clk_data);
  358. mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
  359. &mt6797_clk_lock, clk_data);
  360. return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  361. }
  362. static const struct mtk_gate_regs infra0_cg_regs = {
  363. .set_ofs = 0x0080,
  364. .clr_ofs = 0x0084,
  365. .sta_ofs = 0x0090,
  366. };
  367. static const struct mtk_gate_regs infra1_cg_regs = {
  368. .set_ofs = 0x0088,
  369. .clr_ofs = 0x008c,
  370. .sta_ofs = 0x0094,
  371. };
  372. static const struct mtk_gate_regs infra2_cg_regs = {
  373. .set_ofs = 0x00a8,
  374. .clr_ofs = 0x00ac,
  375. .sta_ofs = 0x00b0,
  376. };
  377. #define GATE_ICG0(_id, _name, _parent, _shift) { \
  378. .id = _id, \
  379. .name = _name, \
  380. .parent_name = _parent, \
  381. .regs = &infra0_cg_regs, \
  382. .shift = _shift, \
  383. .ops = &mtk_clk_gate_ops_setclr, \
  384. }
  385. #define GATE_ICG1(_id, _name, _parent, _shift) { \
  386. .id = _id, \
  387. .name = _name, \
  388. .parent_name = _parent, \
  389. .regs = &infra1_cg_regs, \
  390. .shift = _shift, \
  391. .ops = &mtk_clk_gate_ops_setclr, \
  392. }
  393. #define GATE_ICG2(_id, _name, _parent, _shift) { \
  394. .id = _id, \
  395. .name = _name, \
  396. .parent_name = _parent, \
  397. .regs = &infra2_cg_regs, \
  398. .shift = _shift, \
  399. .ops = &mtk_clk_gate_ops_setclr, \
  400. }
  401. static const struct mtk_gate infra_clks[] = {
  402. GATE_ICG0(CLK_INFRA_PMIC_TMR, "infra_pmic_tmr", "ulposc", 0),
  403. GATE_ICG0(CLK_INFRA_PMIC_AP, "infra_pmic_ap", "pmicspi_sel", 1),
  404. GATE_ICG0(CLK_INFRA_PMIC_MD, "infra_pmic_md", "pmicspi_sel", 2),
  405. GATE_ICG0(CLK_INFRA_PMIC_CONN, "infra_pmic_conn", "pmicspi_sel", 3),
  406. GATE_ICG0(CLK_INFRA_SCP, "infra_scp", "scp_sel", 4),
  407. GATE_ICG0(CLK_INFRA_SEJ, "infra_sej", "axi_sel", 5),
  408. GATE_ICG0(CLK_INFRA_APXGPT, "infra_apxgpt", "axi_sel", 6),
  409. GATE_ICG0(CLK_INFRA_SEJ_13M, "infra_sej_13m", "clk26m", 7),
  410. GATE_ICG0(CLK_INFRA_ICUSB, "infra_icusb", "usb20_sel", 8),
  411. GATE_ICG0(CLK_INFRA_GCE, "infra_gce", "axi_sel", 9),
  412. GATE_ICG0(CLK_INFRA_THERM, "infra_therm", "axi_sel", 10),
  413. GATE_ICG0(CLK_INFRA_I2C0, "infra_i2c0", "axi_sel", 11),
  414. GATE_ICG0(CLK_INFRA_I2C1, "infra_i2c1", "axi_sel", 12),
  415. GATE_ICG0(CLK_INFRA_I2C2, "infra_i2c2", "axi_sel", 13),
  416. GATE_ICG0(CLK_INFRA_I2C3, "infra_i2c3", "axi_sel", 14),
  417. GATE_ICG0(CLK_INFRA_PWM_HCLK, "infra_pwm_hclk", "axi_sel", 15),
  418. GATE_ICG0(CLK_INFRA_PWM1, "infra_pwm1", "axi_sel", 16),
  419. GATE_ICG0(CLK_INFRA_PWM2, "infra_pwm2", "axi_sel", 17),
  420. GATE_ICG0(CLK_INFRA_PWM3, "infra_pwm3", "axi_sel", 18),
  421. GATE_ICG0(CLK_INFRA_PWM4, "infra_pwm4", "axi_sel", 19),
  422. GATE_ICG0(CLK_INFRA_PWM, "infra_pwm", "axi_sel", 21),
  423. GATE_ICG0(CLK_INFRA_UART0, "infra_uart0", "uart_sel", 22),
  424. GATE_ICG0(CLK_INFRA_UART1, "infra_uart1", "uart_sel", 23),
  425. GATE_ICG0(CLK_INFRA_UART2, "infra_uart2", "uart_sel", 24),
  426. GATE_ICG0(CLK_INFRA_UART3, "infra_uart3", "uart_sel", 25),
  427. GATE_ICG0(CLK_INFRA_MD2MD_CCIF_0, "infra_md2md_ccif_0", "axi_sel", 27),
  428. GATE_ICG0(CLK_INFRA_MD2MD_CCIF_1, "infra_md2md_ccif_1", "axi_sel", 28),
  429. GATE_ICG0(CLK_INFRA_MD2MD_CCIF_2, "infra_md2md_ccif_2", "axi_sel", 29),
  430. GATE_ICG0(CLK_INFRA_FHCTL, "infra_fhctl", "clk26m", 30),
  431. GATE_ICG0(CLK_INFRA_BTIF, "infra_btif", "axi_sel", 31),
  432. GATE_ICG1(CLK_INFRA_MD2MD_CCIF_3, "infra_md2md_ccif_3", "axi_sel", 0),
  433. GATE_ICG1(CLK_INFRA_SPI, "infra_spi", "spi_sel", 1),
  434. GATE_ICG1(CLK_INFRA_MSDC0, "infra_msdc0", "msdc50_0_sel", 2),
  435. GATE_ICG1(CLK_INFRA_MD2MD_CCIF_4, "infra_md2md_ccif_4", "axi_sel", 3),
  436. GATE_ICG1(CLK_INFRA_MSDC1, "infra_msdc1", "msdc30_1_sel", 4),
  437. GATE_ICG1(CLK_INFRA_MSDC2, "infra_msdc2", "msdc30_2_sel", 5),
  438. GATE_ICG1(CLK_INFRA_MD2MD_CCIF_5, "infra_md2md_ccif_5", "axi_sel", 7),
  439. GATE_ICG1(CLK_INFRA_GCPU, "infra_gcpu", "axi_sel", 8),
  440. GATE_ICG1(CLK_INFRA_TRNG, "infra_trng", "axi_sel", 9),
  441. GATE_ICG1(CLK_INFRA_AUXADC, "infra_auxadc", "clk26m", 10),
  442. GATE_ICG1(CLK_INFRA_CPUM, "infra_cpum", "axi_sel", 11),
  443. GATE_ICG1(CLK_INFRA_AP_C2K_CCIF_0, "infra_ap_c2k_ccif_0",
  444. "axi_sel", 12),
  445. GATE_ICG1(CLK_INFRA_AP_C2K_CCIF_1, "infra_ap_c2k_ccif_1",
  446. "axi_sel", 13),
  447. GATE_ICG1(CLK_INFRA_CLDMA, "infra_cldma", "axi_sel", 16),
  448. GATE_ICG1(CLK_INFRA_DISP_PWM, "infra_disp_pwm", "pwm_sel", 17),
  449. GATE_ICG1(CLK_INFRA_AP_DMA, "infra_ap_dma", "axi_sel", 18),
  450. GATE_ICG1(CLK_INFRA_DEVICE_APC, "infra_device_apc", "axi_sel", 20),
  451. GATE_ICG1(CLK_INFRA_L2C_SRAM, "infra_l2c_sram", "mm_sel", 22),
  452. GATE_ICG1(CLK_INFRA_CCIF_AP, "infra_ccif_ap", "axi_sel", 23),
  453. GATE_ICG1(CLK_INFRA_AUDIO, "infra_audio", "axi_sel", 25),
  454. GATE_ICG1(CLK_INFRA_CCIF_MD, "infra_ccif_md", "axi_sel", 26),
  455. GATE_ICG1(CLK_INFRA_DRAMC_F26M, "infra_dramc_f26m", "clk26m", 31),
  456. GATE_ICG2(CLK_INFRA_I2C4, "infra_i2c4", "axi_sel", 0),
  457. GATE_ICG2(CLK_INFRA_I2C_APPM, "infra_i2c_appm", "axi_sel", 1),
  458. GATE_ICG2(CLK_INFRA_I2C_GPUPM, "infra_i2c_gpupm", "axi_sel", 2),
  459. GATE_ICG2(CLK_INFRA_I2C2_IMM, "infra_i2c2_imm", "axi_sel", 3),
  460. GATE_ICG2(CLK_INFRA_I2C2_ARB, "infra_i2c2_arb", "axi_sel", 4),
  461. GATE_ICG2(CLK_INFRA_I2C3_IMM, "infra_i2c3_imm", "axi_sel", 5),
  462. GATE_ICG2(CLK_INFRA_I2C3_ARB, "infra_i2c3_arb", "axi_sel", 6),
  463. GATE_ICG2(CLK_INFRA_I2C5, "infra_i2c5", "axi_sel", 7),
  464. GATE_ICG2(CLK_INFRA_SYS_CIRQ, "infra_sys_cirq", "axi_sel", 8),
  465. GATE_ICG2(CLK_INFRA_SPI1, "infra_spi1", "spi_sel", 10),
  466. GATE_ICG2(CLK_INFRA_DRAMC_B_F26M, "infra_dramc_b_f26m", "clk26m", 11),
  467. GATE_ICG2(CLK_INFRA_ANC_MD32, "infra_anc_md32", "anc_md32_sel", 12),
  468. GATE_ICG2(CLK_INFRA_ANC_MD32_32K, "infra_anc_md32_32k", "clk26m", 13),
  469. GATE_ICG2(CLK_INFRA_DVFS_SPM1, "infra_dvfs_spm1", "axi_sel", 15),
  470. GATE_ICG2(CLK_INFRA_AES_TOP0, "infra_aes_top0", "axi_sel", 16),
  471. GATE_ICG2(CLK_INFRA_AES_TOP1, "infra_aes_top1", "axi_sel", 17),
  472. GATE_ICG2(CLK_INFRA_SSUSB_BUS, "infra_ssusb_bus", "axi_sel", 18),
  473. GATE_ICG2(CLK_INFRA_SPI2, "infra_spi2", "spi_sel", 19),
  474. GATE_ICG2(CLK_INFRA_SPI3, "infra_spi3", "spi_sel", 20),
  475. GATE_ICG2(CLK_INFRA_SPI4, "infra_spi4", "spi_sel", 21),
  476. GATE_ICG2(CLK_INFRA_SPI5, "infra_spi5", "spi_sel", 22),
  477. GATE_ICG2(CLK_INFRA_IRTX, "infra_irtx", "spi_sel", 23),
  478. GATE_ICG2(CLK_INFRA_SSUSB_SYS, "infra_ssusb_sys",
  479. "ssusb_top_sys_sel", 24),
  480. GATE_ICG2(CLK_INFRA_SSUSB_REF, "infra_ssusb_ref", "clk26m", 9),
  481. GATE_ICG2(CLK_INFRA_AUDIO_26M, "infra_audio_26m", "clk26m", 26),
  482. GATE_ICG2(CLK_INFRA_AUDIO_26M_PAD_TOP, "infra_audio_26m_pad_top",
  483. "clk26m", 27),
  484. GATE_ICG2(CLK_INFRA_MODEM_TEMP_SHARE, "infra_modem_temp_share",
  485. "axi_sel", 28),
  486. GATE_ICG2(CLK_INFRA_VAD_WRAP_SOC, "infra_vad_wrap_soc", "axi_sel", 29),
  487. GATE_ICG2(CLK_INFRA_DRAMC_CONF, "infra_dramc_conf", "axi_sel", 30),
  488. GATE_ICG2(CLK_INFRA_DRAMC_B_CONF, "infra_dramc_b_conf", "axi_sel", 31),
  489. GATE_ICG1(CLK_INFRA_MFG_VCG, "infra_mfg_vcg", "mfg_52m_sel", 14),
  490. };
  491. static const struct mtk_fixed_factor infra_fixed_divs[] = {
  492. FACTOR(CLK_INFRA_13M, "clk13m", "clk26m", 1, 2),
  493. };
  494. static struct clk_onecell_data *infra_clk_data;
  495. static void mtk_infrasys_init_early(struct device_node *node)
  496. {
  497. int r, i;
  498. if (!infra_clk_data) {
  499. infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
  500. for (i = 0; i < CLK_INFRA_NR; i++)
  501. infra_clk_data->clks[i] = ERR_PTR(-EPROBE_DEFER);
  502. }
  503. mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
  504. infra_clk_data);
  505. r = of_clk_add_provider(node, of_clk_src_onecell_get, infra_clk_data);
  506. if (r)
  507. pr_err("%s(): could not register clock provider: %d\n",
  508. __func__, r);
  509. }
  510. CLK_OF_DECLARE_DRIVER(mtk_infra, "mediatek,mt6797-infracfg",
  511. mtk_infrasys_init_early);
  512. static int mtk_infrasys_init(struct platform_device *pdev)
  513. {
  514. int r, i;
  515. struct device_node *node = pdev->dev.of_node;
  516. if (!infra_clk_data) {
  517. infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
  518. } else {
  519. for (i = 0; i < CLK_INFRA_NR; i++) {
  520. if (infra_clk_data->clks[i] == ERR_PTR(-EPROBE_DEFER))
  521. infra_clk_data->clks[i] = ERR_PTR(-ENOENT);
  522. }
  523. }
  524. mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
  525. infra_clk_data);
  526. mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
  527. infra_clk_data);
  528. r = of_clk_add_provider(node, of_clk_src_onecell_get, infra_clk_data);
  529. if (r)
  530. return r;
  531. return 0;
  532. }
  533. #define MT6797_PLL_FMAX (3000UL * MHZ)
  534. #define CON0_MT6797_RST_BAR BIT(24)
  535. #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  536. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  537. _pcw_shift, _div_table) { \
  538. .id = _id, \
  539. .name = _name, \
  540. .reg = _reg, \
  541. .pwr_reg = _pwr_reg, \
  542. .en_mask = _en_mask, \
  543. .flags = _flags, \
  544. .rst_bar_mask = CON0_MT6797_RST_BAR, \
  545. .fmax = MT6797_PLL_FMAX, \
  546. .pcwbits = _pcwbits, \
  547. .pd_reg = _pd_reg, \
  548. .pd_shift = _pd_shift, \
  549. .tuner_reg = _tuner_reg, \
  550. .pcw_reg = _pcw_reg, \
  551. .pcw_shift = _pcw_shift, \
  552. .div_table = _div_table, \
  553. }
  554. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  555. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  556. _pcw_shift) \
  557. PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  558. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
  559. NULL)
  560. static const struct mtk_pll_data plls[] = {
  561. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0220, 0x022C, 0xF0000101, PLL_AO,
  562. 21, 0x220, 4, 0x0, 0x224, 0),
  563. PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0230, 0x023C, 0xFE000011, 0, 7,
  564. 0x230, 4, 0x0, 0x234, 14),
  565. PLL(CLK_APMIXED_MFGPLL, "mfgpll", 0x0240, 0x024C, 0x00000101, 0, 21,
  566. 0x244, 24, 0x0, 0x244, 0),
  567. PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0250, 0x025C, 0x00000121, 0, 21,
  568. 0x250, 4, 0x0, 0x254, 0),
  569. PLL(CLK_APMIXED_IMGPLL, "imgpll", 0x0260, 0x026C, 0x00000121, 0, 21,
  570. 0x260, 4, 0x0, 0x264, 0),
  571. PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x0270, 0x027C, 0xC0000121, 0, 21,
  572. 0x270, 4, 0x0, 0x274, 0),
  573. PLL(CLK_APMIXED_CODECPLL, "codecpll", 0x0290, 0x029C, 0x00000121, 0, 21,
  574. 0x290, 4, 0x0, 0x294, 0),
  575. PLL(CLK_APMIXED_VDECPLL, "vdecpll", 0x02E4, 0x02F0, 0x00000121, 0, 21,
  576. 0x2E4, 4, 0x0, 0x2E8, 0),
  577. PLL(CLK_APMIXED_APLL1, "apll1", 0x02A0, 0x02B0, 0x00000131, 0, 31,
  578. 0x2A0, 4, 0x2A8, 0x2A4, 0),
  579. PLL(CLK_APMIXED_APLL2, "apll2", 0x02B4, 0x02C4, 0x00000131, 0, 31,
  580. 0x2B4, 4, 0x2BC, 0x2B8, 0),
  581. };
  582. static int mtk_apmixedsys_init(struct platform_device *pdev)
  583. {
  584. struct clk_onecell_data *clk_data;
  585. struct device_node *node = pdev->dev.of_node;
  586. clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR);
  587. if (!clk_data)
  588. return -ENOMEM;
  589. mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  590. return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  591. }
  592. static const struct of_device_id of_match_clk_mt6797[] = {
  593. {
  594. .compatible = "mediatek,mt6797-topckgen",
  595. .data = mtk_topckgen_init,
  596. }, {
  597. .compatible = "mediatek,mt6797-infracfg",
  598. .data = mtk_infrasys_init,
  599. }, {
  600. .compatible = "mediatek,mt6797-apmixedsys",
  601. .data = mtk_apmixedsys_init,
  602. }, {
  603. /* sentinel */
  604. }
  605. };
  606. static int clk_mt6797_probe(struct platform_device *pdev)
  607. {
  608. int (*clk_init)(struct platform_device *);
  609. int r;
  610. clk_init = of_device_get_match_data(&pdev->dev);
  611. if (!clk_init)
  612. return -EINVAL;
  613. r = clk_init(pdev);
  614. if (r)
  615. dev_err(&pdev->dev,
  616. "could not register clock provider: %s: %d\n",
  617. pdev->name, r);
  618. return r;
  619. }
  620. static struct platform_driver clk_mt6797_drv = {
  621. .probe = clk_mt6797_probe,
  622. .driver = {
  623. .name = "clk-mt6797",
  624. .of_match_table = of_match_clk_mt6797,
  625. },
  626. };
  627. static int __init clk_mt6797_init(void)
  628. {
  629. return platform_driver_register(&clk_mt6797_drv);
  630. }
  631. arch_initcall(clk_mt6797_init);