clk-mt2701.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  1. /*
  2. * Copyright (c) 2014 MediaTek Inc.
  3. * Author: Shunli Wang <shunli.wang@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/clk-provider.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_device.h>
  18. #include <linux/platform_device.h>
  19. #include "clk-mtk.h"
  20. #include "clk-gate.h"
  21. #include <dt-bindings/clock/mt2701-clk.h>
  22. /*
  23. * For some clocks, we don't care what their actual rates are. And these
  24. * clocks may change their rate on different products or different scenarios.
  25. * So we model these clocks' rate as 0, to denote it's not an actual rate.
  26. */
  27. #define DUMMY_RATE 0
  28. static DEFINE_SPINLOCK(mt2701_clk_lock);
  29. static const struct mtk_fixed_clk top_fixed_clks[] = {
  30. FIXED_CLK(CLK_TOP_DPI, "dpi_ck", "clk26m",
  31. 108 * MHZ),
  32. FIXED_CLK(CLK_TOP_DMPLL, "dmpll_ck", "clk26m",
  33. 400 * MHZ),
  34. FIXED_CLK(CLK_TOP_VENCPLL, "vencpll_ck", "clk26m",
  35. 295750000),
  36. FIXED_CLK(CLK_TOP_HDMI_0_PIX340M, "hdmi_0_pix340m", "clk26m",
  37. 340 * MHZ),
  38. FIXED_CLK(CLK_TOP_HDMI_0_DEEP340M, "hdmi_0_deep340m", "clk26m",
  39. 340 * MHZ),
  40. FIXED_CLK(CLK_TOP_HDMI_0_PLL340M, "hdmi_0_pll340m", "clk26m",
  41. 340 * MHZ),
  42. FIXED_CLK(CLK_TOP_HDMITX_CLKDIG_CTS, "hdmitx_dig_cts", "clk26m",
  43. 300 * MHZ),
  44. FIXED_CLK(CLK_TOP_HADDS2_FB, "hadds2_fbclk", "clk26m",
  45. 27 * MHZ),
  46. FIXED_CLK(CLK_TOP_WBG_DIG_416M, "wbg_dig_ck_416m", "clk26m",
  47. 416 * MHZ),
  48. FIXED_CLK(CLK_TOP_DSI0_LNTC_DSI, "dsi0_lntc_dsi", "clk26m",
  49. 143 * MHZ),
  50. FIXED_CLK(CLK_TOP_HDMI_SCL_RX, "hdmi_scl_rx", "clk26m",
  51. 27 * MHZ),
  52. FIXED_CLK(CLK_TOP_AUD_EXT1, "aud_ext1", "clk26m",
  53. DUMMY_RATE),
  54. FIXED_CLK(CLK_TOP_AUD_EXT2, "aud_ext2", "clk26m",
  55. DUMMY_RATE),
  56. FIXED_CLK(CLK_TOP_NFI1X_PAD, "nfi1x_pad", "clk26m",
  57. DUMMY_RATE),
  58. };
  59. static const struct mtk_fixed_factor top_fixed_divs[] = {
  60. FACTOR(CLK_TOP_SYSPLL, "syspll_ck", "mainpll", 1, 1),
  61. FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "mainpll", 1, 2),
  62. FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "mainpll", 1, 3),
  63. FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1, 5),
  64. FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "mainpll", 1, 7),
  65. FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "syspll_d2", 1, 2),
  66. FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "syspll_d2", 1, 4),
  67. FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "syspll_d2", 1, 8),
  68. FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "syspll_d2", 1, 16),
  69. FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "syspll_d3", 1, 2),
  70. FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "syspll_d3", 1, 4),
  71. FACTOR(CLK_TOP_SYSPLL2_D8, "syspll2_d8", "syspll_d3", 1, 8),
  72. FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "syspll_d5", 1, 2),
  73. FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "syspll_d5", 1, 4),
  74. FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "syspll_d7", 1, 2),
  75. FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "syspll_d7", 1, 4),
  76. FACTOR(CLK_TOP_UNIVPLL, "univpll_ck", "univpll", 1, 1),
  77. FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2),
  78. FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3),
  79. FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
  80. FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1, 7),
  81. FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univpll", 1, 26),
  82. FACTOR(CLK_TOP_UNIVPLL_D52, "univpll_d52", "univpll", 1, 52),
  83. FACTOR(CLK_TOP_UNIVPLL_D108, "univpll_d108", "univpll", 1, 108),
  84. FACTOR(CLK_TOP_USB_PHY48M, "usb_phy48m_ck", "univpll", 1, 26),
  85. FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_d2", 1, 2),
  86. FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_d2", 1, 4),
  87. FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll_d2", 1, 8),
  88. FACTOR(CLK_TOP_8BDAC, "8bdac_ck", "univpll_d2", 1, 1),
  89. FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll_d3", 1, 2),
  90. FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll_d3", 1, 4),
  91. FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll_d3", 1, 8),
  92. FACTOR(CLK_TOP_UNIVPLL2_D16, "univpll2_d16", "univpll_d3", 1, 16),
  93. FACTOR(CLK_TOP_UNIVPLL2_D32, "univpll2_d32", "univpll_d3", 1, 32),
  94. FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll_d5", 1, 2),
  95. FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll_d5", 1, 4),
  96. FACTOR(CLK_TOP_UNIVPLL3_D8, "univpll3_d8", "univpll_d5", 1, 8),
  97. FACTOR(CLK_TOP_MSDCPLL, "msdcpll_ck", "msdcpll", 1, 1),
  98. FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll", 1, 2),
  99. FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll", 1, 4),
  100. FACTOR(CLK_TOP_MSDCPLL_D8, "msdcpll_d8", "msdcpll", 1, 8),
  101. FACTOR(CLK_TOP_MMPLL, "mmpll_ck", "mmpll", 1, 1),
  102. FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll", 1, 2),
  103. FACTOR(CLK_TOP_DMPLL_D2, "dmpll_d2", "dmpll_ck", 1, 2),
  104. FACTOR(CLK_TOP_DMPLL_D4, "dmpll_d4", "dmpll_ck", 1, 4),
  105. FACTOR(CLK_TOP_DMPLL_X2, "dmpll_x2", "dmpll_ck", 1, 1),
  106. FACTOR(CLK_TOP_TVDPLL, "tvdpll_ck", "tvdpll", 1, 1),
  107. FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll", 1, 2),
  108. FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll", 1, 4),
  109. FACTOR(CLK_TOP_VDECPLL, "vdecpll_ck", "vdecpll", 1, 1),
  110. FACTOR(CLK_TOP_TVD2PLL, "tvd2pll_ck", "tvd2pll", 1, 1),
  111. FACTOR(CLK_TOP_TVD2PLL_D2, "tvd2pll_d2", "tvd2pll", 1, 2),
  112. FACTOR(CLK_TOP_MIPIPLL, "mipipll", "dpi_ck", 1, 1),
  113. FACTOR(CLK_TOP_MIPIPLL_D2, "mipipll_d2", "dpi_ck", 1, 2),
  114. FACTOR(CLK_TOP_MIPIPLL_D4, "mipipll_d4", "dpi_ck", 1, 4),
  115. FACTOR(CLK_TOP_HDMIPLL, "hdmipll_ck", "hdmitx_dig_cts", 1, 1),
  116. FACTOR(CLK_TOP_HDMIPLL_D2, "hdmipll_d2", "hdmitx_dig_cts", 1, 2),
  117. FACTOR(CLK_TOP_HDMIPLL_D3, "hdmipll_d3", "hdmitx_dig_cts", 1, 3),
  118. FACTOR(CLK_TOP_ARMPLL_1P3G, "armpll_1p3g_ck", "armpll", 1, 1),
  119. FACTOR(CLK_TOP_AUDPLL, "audpll", "audpll_sel", 1, 1),
  120. FACTOR(CLK_TOP_AUDPLL_D4, "audpll_d4", "audpll_sel", 1, 4),
  121. FACTOR(CLK_TOP_AUDPLL_D8, "audpll_d8", "audpll_sel", 1, 8),
  122. FACTOR(CLK_TOP_AUDPLL_D16, "audpll_d16", "audpll_sel", 1, 16),
  123. FACTOR(CLK_TOP_AUDPLL_D24, "audpll_d24", "audpll_sel", 1, 24),
  124. FACTOR(CLK_TOP_AUD1PLL_98M, "aud1pll_98m_ck", "aud1pll", 1, 3),
  125. FACTOR(CLK_TOP_AUD2PLL_90M, "aud2pll_90m_ck", "aud2pll", 1, 3),
  126. FACTOR(CLK_TOP_HADDS2PLL_98M, "hadds2pll_98m", "hadds2pll", 1, 3),
  127. FACTOR(CLK_TOP_HADDS2PLL_294M, "hadds2pll_294m", "hadds2pll", 1, 1),
  128. FACTOR(CLK_TOP_ETHPLL_500M, "ethpll_500m_ck", "ethpll", 1, 1),
  129. FACTOR(CLK_TOP_CLK26M_D8, "clk26m_d8", "clk26m", 1, 8),
  130. FACTOR(CLK_TOP_32K_INTERNAL, "32k_internal", "clk26m", 1, 793),
  131. FACTOR(CLK_TOP_32K_EXTERNAL, "32k_external", "rtc32k", 1, 1),
  132. };
  133. static const char * const axi_parents[] = {
  134. "clk26m",
  135. "syspll1_d2",
  136. "syspll_d5",
  137. "syspll1_d4",
  138. "univpll_d5",
  139. "univpll2_d2",
  140. "mmpll_d2",
  141. "dmpll_d2"
  142. };
  143. static const char * const mem_parents[] = {
  144. "clk26m",
  145. "dmpll_ck"
  146. };
  147. static const char * const ddrphycfg_parents[] = {
  148. "clk26m",
  149. "syspll1_d8"
  150. };
  151. static const char * const mm_parents[] = {
  152. "clk26m",
  153. "vencpll_ck",
  154. "syspll1_d2",
  155. "syspll1_d4",
  156. "univpll_d5",
  157. "univpll1_d2",
  158. "univpll2_d2",
  159. "dmpll_ck"
  160. };
  161. static const char * const pwm_parents[] = {
  162. "clk26m",
  163. "univpll2_d4",
  164. "univpll3_d2",
  165. "univpll1_d4",
  166. };
  167. static const char * const vdec_parents[] = {
  168. "clk26m",
  169. "vdecpll_ck",
  170. "syspll_d5",
  171. "syspll1_d4",
  172. "univpll_d5",
  173. "univpll2_d2",
  174. "vencpll_ck",
  175. "msdcpll_d2",
  176. "mmpll_d2"
  177. };
  178. static const char * const mfg_parents[] = {
  179. "clk26m",
  180. "mmpll_ck",
  181. "dmpll_x2_ck",
  182. "msdcpll_ck",
  183. "clk26m",
  184. "syspll_d3",
  185. "univpll_d3",
  186. "univpll1_d2"
  187. };
  188. static const char * const camtg_parents[] = {
  189. "clk26m",
  190. "univpll_d26",
  191. "univpll2_d2",
  192. "syspll3_d2",
  193. "syspll3_d4",
  194. "msdcpll_d2",
  195. "mmpll_d2"
  196. };
  197. static const char * const uart_parents[] = {
  198. "clk26m",
  199. "univpll2_d8"
  200. };
  201. static const char * const spi_parents[] = {
  202. "clk26m",
  203. "syspll3_d2",
  204. "syspll4_d2",
  205. "univpll2_d4",
  206. "univpll1_d8"
  207. };
  208. static const char * const usb20_parents[] = {
  209. "clk26m",
  210. "univpll1_d8",
  211. "univpll3_d4"
  212. };
  213. static const char * const msdc30_parents[] = {
  214. "clk26m",
  215. "msdcpll_d2",
  216. "syspll2_d2",
  217. "syspll1_d4",
  218. "univpll1_d4",
  219. "univpll2_d4"
  220. };
  221. static const char * const audio_parents[] = {
  222. "clk26m",
  223. "syspll1_d16"
  224. };
  225. static const char * const aud_intbus_parents[] = {
  226. "clk26m",
  227. "syspll1_d4",
  228. "syspll3_d2",
  229. "syspll4_d2",
  230. "univpll3_d2",
  231. "univpll2_d4"
  232. };
  233. static const char * const pmicspi_parents[] = {
  234. "clk26m",
  235. "syspll1_d8",
  236. "syspll2_d4",
  237. "syspll4_d2",
  238. "syspll3_d4",
  239. "syspll2_d8",
  240. "syspll1_d16",
  241. "univpll3_d4",
  242. "univpll_d26",
  243. "dmpll_d2",
  244. "dmpll_d4"
  245. };
  246. static const char * const scp_parents[] = {
  247. "clk26m",
  248. "syspll1_d8",
  249. "dmpll_d2",
  250. "dmpll_d4"
  251. };
  252. static const char * const dpi0_parents[] = {
  253. "clk26m",
  254. "mipipll",
  255. "mipipll_d2",
  256. "mipipll_d4",
  257. "clk26m",
  258. "tvdpll_ck",
  259. "tvdpll_d2",
  260. "tvdpll_d4"
  261. };
  262. static const char * const dpi1_parents[] = {
  263. "clk26m",
  264. "tvdpll_ck",
  265. "tvdpll_d2",
  266. "tvdpll_d4"
  267. };
  268. static const char * const tve_parents[] = {
  269. "clk26m",
  270. "mipipll",
  271. "mipipll_d2",
  272. "mipipll_d4",
  273. "clk26m",
  274. "tvdpll_ck",
  275. "tvdpll_d2",
  276. "tvdpll_d4"
  277. };
  278. static const char * const hdmi_parents[] = {
  279. "clk26m",
  280. "hdmipll_ck",
  281. "hdmipll_d2",
  282. "hdmipll_d3"
  283. };
  284. static const char * const apll_parents[] = {
  285. "clk26m",
  286. "audpll",
  287. "audpll_d4",
  288. "audpll_d8",
  289. "audpll_d16",
  290. "audpll_d24",
  291. "clk26m",
  292. "clk26m"
  293. };
  294. static const char * const rtc_parents[] = {
  295. "32k_internal",
  296. "32k_external",
  297. "clk26m",
  298. "univpll3_d8"
  299. };
  300. static const char * const nfi2x_parents[] = {
  301. "clk26m",
  302. "syspll2_d2",
  303. "syspll_d7",
  304. "univpll3_d2",
  305. "syspll2_d4",
  306. "univpll3_d4",
  307. "syspll4_d4",
  308. "clk26m"
  309. };
  310. static const char * const emmc_hclk_parents[] = {
  311. "clk26m",
  312. "syspll1_d2",
  313. "syspll1_d4",
  314. "syspll2_d2"
  315. };
  316. static const char * const flash_parents[] = {
  317. "clk26m_d8",
  318. "clk26m",
  319. "syspll2_d8",
  320. "syspll3_d4",
  321. "univpll3_d4",
  322. "syspll4_d2",
  323. "syspll2_d4",
  324. "univpll2_d4"
  325. };
  326. static const char * const di_parents[] = {
  327. "clk26m",
  328. "tvd2pll_ck",
  329. "tvd2pll_d2",
  330. "clk26m"
  331. };
  332. static const char * const nr_osd_parents[] = {
  333. "clk26m",
  334. "vencpll_ck",
  335. "syspll1_d2",
  336. "syspll1_d4",
  337. "univpll_d5",
  338. "univpll1_d2",
  339. "univpll2_d2",
  340. "dmpll_ck"
  341. };
  342. static const char * const hdmirx_bist_parents[] = {
  343. "clk26m",
  344. "syspll_d3",
  345. "clk26m",
  346. "syspll1_d16",
  347. "syspll4_d2",
  348. "syspll1_d4",
  349. "vencpll_ck",
  350. "clk26m"
  351. };
  352. static const char * const intdir_parents[] = {
  353. "clk26m",
  354. "mmpll_ck",
  355. "syspll_d2",
  356. "univpll_d2"
  357. };
  358. static const char * const asm_parents[] = {
  359. "clk26m",
  360. "univpll2_d4",
  361. "univpll2_d2",
  362. "syspll_d5"
  363. };
  364. static const char * const ms_card_parents[] = {
  365. "clk26m",
  366. "univpll3_d8",
  367. "syspll4_d4"
  368. };
  369. static const char * const ethif_parents[] = {
  370. "clk26m",
  371. "syspll1_d2",
  372. "syspll_d5",
  373. "syspll1_d4",
  374. "univpll_d5",
  375. "univpll1_d2",
  376. "dmpll_ck",
  377. "dmpll_d2"
  378. };
  379. static const char * const hdmirx_parents[] = {
  380. "clk26m",
  381. "univpll_d52"
  382. };
  383. static const char * const cmsys_parents[] = {
  384. "clk26m",
  385. "syspll1_d2",
  386. "univpll1_d2",
  387. "univpll_d5",
  388. "syspll_d5",
  389. "syspll2_d2",
  390. "syspll1_d4",
  391. "syspll3_d2",
  392. "syspll2_d4",
  393. "syspll1_d8",
  394. "clk26m",
  395. "clk26m",
  396. "clk26m",
  397. "clk26m",
  398. "clk26m"
  399. };
  400. static const char * const clk_8bdac_parents[] = {
  401. "32k_internal",
  402. "8bdac_ck",
  403. "clk26m",
  404. "clk26m"
  405. };
  406. static const char * const aud2dvd_parents[] = {
  407. "a1sys_hp_ck",
  408. "a2sys_hp_ck"
  409. };
  410. static const char * const padmclk_parents[] = {
  411. "clk26m",
  412. "univpll_d26",
  413. "univpll_d52",
  414. "univpll_d108",
  415. "univpll2_d8",
  416. "univpll2_d16",
  417. "univpll2_d32"
  418. };
  419. static const char * const aud_mux_parents[] = {
  420. "clk26m",
  421. "aud1pll_98m_ck",
  422. "aud2pll_90m_ck",
  423. "hadds2pll_98m",
  424. "audio_ext1_ck",
  425. "audio_ext2_ck"
  426. };
  427. static const char * const aud_src_parents[] = {
  428. "aud_mux1_sel",
  429. "aud_mux2_sel"
  430. };
  431. static const char * const cpu_parents[] = {
  432. "clk26m",
  433. "armpll",
  434. "mainpll",
  435. "mmpll"
  436. };
  437. static const struct mtk_composite top_muxes[] = {
  438. MUX_GATE_FLAGS(CLK_TOP_AXI_SEL, "axi_sel", axi_parents,
  439. 0x0040, 0, 3, 7, CLK_IS_CRITICAL),
  440. MUX_GATE_FLAGS(CLK_TOP_MEM_SEL, "mem_sel", mem_parents,
  441. 0x0040, 8, 1, 15, CLK_IS_CRITICAL),
  442. MUX_GATE_FLAGS(CLK_TOP_DDRPHYCFG_SEL, "ddrphycfg_sel",
  443. ddrphycfg_parents, 0x0040, 16, 1, 23, CLK_IS_CRITICAL),
  444. MUX_GATE(CLK_TOP_MM_SEL, "mm_sel", mm_parents,
  445. 0x0040, 24, 3, 31),
  446. MUX_GATE(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents,
  447. 0x0050, 0, 2, 7),
  448. MUX_GATE(CLK_TOP_VDEC_SEL, "vdec_sel", vdec_parents,
  449. 0x0050, 8, 4, 15),
  450. MUX_GATE(CLK_TOP_MFG_SEL, "mfg_sel", mfg_parents,
  451. 0x0050, 16, 3, 23),
  452. MUX_GATE(CLK_TOP_CAMTG_SEL, "camtg_sel", camtg_parents,
  453. 0x0050, 24, 3, 31),
  454. MUX_GATE(CLK_TOP_UART_SEL, "uart_sel", uart_parents,
  455. 0x0060, 0, 1, 7),
  456. MUX_GATE(CLK_TOP_SPI0_SEL, "spi0_sel", spi_parents,
  457. 0x0060, 8, 3, 15),
  458. MUX_GATE(CLK_TOP_USB20_SEL, "usb20_sel", usb20_parents,
  459. 0x0060, 16, 2, 23),
  460. MUX_GATE(CLK_TOP_MSDC30_0_SEL, "msdc30_0_sel", msdc30_parents,
  461. 0x0060, 24, 3, 31),
  462. MUX_GATE(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel", msdc30_parents,
  463. 0x0070, 0, 3, 7),
  464. MUX_GATE(CLK_TOP_MSDC30_2_SEL, "msdc30_2_sel", msdc30_parents,
  465. 0x0070, 8, 3, 15),
  466. MUX_GATE(CLK_TOP_AUDIO_SEL, "audio_sel", msdc30_parents,
  467. 0x0070, 16, 1, 23),
  468. MUX_GATE(CLK_TOP_AUDINTBUS_SEL, "aud_intbus_sel", aud_intbus_parents,
  469. 0x0070, 24, 3, 31),
  470. MUX_GATE(CLK_TOP_PMICSPI_SEL, "pmicspi_sel", pmicspi_parents,
  471. 0x0080, 0, 4, 7),
  472. MUX_GATE(CLK_TOP_SCP_SEL, "scp_sel", scp_parents,
  473. 0x0080, 8, 2, 15),
  474. MUX_GATE(CLK_TOP_DPI0_SEL, "dpi0_sel", dpi0_parents,
  475. 0x0080, 16, 3, 23),
  476. MUX_GATE(CLK_TOP_DPI1_SEL, "dpi1_sel", dpi1_parents,
  477. 0x0080, 24, 2, 31),
  478. MUX_GATE(CLK_TOP_TVE_SEL, "tve_sel", tve_parents,
  479. 0x0090, 0, 3, 7),
  480. MUX_GATE(CLK_TOP_HDMI_SEL, "hdmi_sel", hdmi_parents,
  481. 0x0090, 8, 2, 15),
  482. MUX_GATE(CLK_TOP_APLL_SEL, "apll_sel", apll_parents,
  483. 0x0090, 16, 3, 23),
  484. MUX_GATE_FLAGS(CLK_TOP_RTC_SEL, "rtc_sel", rtc_parents,
  485. 0x00A0, 0, 2, 7, CLK_IS_CRITICAL),
  486. MUX_GATE(CLK_TOP_NFI2X_SEL, "nfi2x_sel", nfi2x_parents,
  487. 0x00A0, 8, 3, 15),
  488. MUX_GATE(CLK_TOP_EMMC_HCLK_SEL, "emmc_hclk_sel", emmc_hclk_parents,
  489. 0x00A0, 24, 2, 31),
  490. MUX_GATE(CLK_TOP_FLASH_SEL, "flash_sel", flash_parents,
  491. 0x00B0, 0, 3, 7),
  492. MUX_GATE(CLK_TOP_DI_SEL, "di_sel", di_parents,
  493. 0x00B0, 8, 2, 15),
  494. MUX_GATE(CLK_TOP_NR_SEL, "nr_sel", nr_osd_parents,
  495. 0x00B0, 16, 3, 23),
  496. MUX_GATE(CLK_TOP_OSD_SEL, "osd_sel", nr_osd_parents,
  497. 0x00B0, 24, 3, 31),
  498. MUX_GATE(CLK_TOP_HDMIRX_BIST_SEL, "hdmirx_bist_sel",
  499. hdmirx_bist_parents, 0x00C0, 0, 3, 7),
  500. MUX_GATE(CLK_TOP_INTDIR_SEL, "intdir_sel", intdir_parents,
  501. 0x00C0, 8, 2, 15),
  502. MUX_GATE(CLK_TOP_ASM_I_SEL, "asm_i_sel", asm_parents,
  503. 0x00C0, 16, 2, 23),
  504. MUX_GATE(CLK_TOP_ASM_M_SEL, "asm_m_sel", asm_parents,
  505. 0x00C0, 24, 3, 31),
  506. MUX_GATE(CLK_TOP_ASM_H_SEL, "asm_h_sel", asm_parents,
  507. 0x00D0, 0, 2, 7),
  508. MUX_GATE(CLK_TOP_MS_CARD_SEL, "ms_card_sel", ms_card_parents,
  509. 0x00D0, 16, 2, 23),
  510. MUX_GATE(CLK_TOP_ETHIF_SEL, "ethif_sel", ethif_parents,
  511. 0x00D0, 24, 3, 31),
  512. MUX_GATE(CLK_TOP_HDMIRX26_24_SEL, "hdmirx26_24_sel", hdmirx_parents,
  513. 0x00E0, 0, 1, 7),
  514. MUX_GATE(CLK_TOP_MSDC30_3_SEL, "msdc30_3_sel", msdc30_parents,
  515. 0x00E0, 8, 3, 15),
  516. MUX_GATE(CLK_TOP_CMSYS_SEL, "cmsys_sel", cmsys_parents,
  517. 0x00E0, 16, 4, 23),
  518. MUX_GATE(CLK_TOP_SPI1_SEL, "spi2_sel", spi_parents,
  519. 0x00E0, 24, 3, 31),
  520. MUX_GATE(CLK_TOP_SPI2_SEL, "spi1_sel", spi_parents,
  521. 0x00F0, 0, 3, 7),
  522. MUX_GATE(CLK_TOP_8BDAC_SEL, "8bdac_sel", clk_8bdac_parents,
  523. 0x00F0, 8, 2, 15),
  524. MUX_GATE(CLK_TOP_AUD2DVD_SEL, "aud2dvd_sel", aud2dvd_parents,
  525. 0x00F0, 16, 1, 23),
  526. MUX(CLK_TOP_PADMCLK_SEL, "padmclk_sel", padmclk_parents,
  527. 0x0100, 0, 3),
  528. MUX(CLK_TOP_AUD_MUX1_SEL, "aud_mux1_sel", aud_mux_parents,
  529. 0x012c, 0, 3),
  530. MUX(CLK_TOP_AUD_MUX2_SEL, "aud_mux2_sel", aud_mux_parents,
  531. 0x012c, 3, 3),
  532. MUX(CLK_TOP_AUDPLL_MUX_SEL, "audpll_sel", aud_mux_parents,
  533. 0x012c, 6, 3),
  534. MUX_GATE(CLK_TOP_AUD_K1_SRC_SEL, "aud_k1_src_sel", aud_src_parents,
  535. 0x012c, 15, 1, 23),
  536. MUX_GATE(CLK_TOP_AUD_K2_SRC_SEL, "aud_k2_src_sel", aud_src_parents,
  537. 0x012c, 16, 1, 24),
  538. MUX_GATE(CLK_TOP_AUD_K3_SRC_SEL, "aud_k3_src_sel", aud_src_parents,
  539. 0x012c, 17, 1, 25),
  540. MUX_GATE(CLK_TOP_AUD_K4_SRC_SEL, "aud_k4_src_sel", aud_src_parents,
  541. 0x012c, 18, 1, 26),
  542. MUX_GATE(CLK_TOP_AUD_K5_SRC_SEL, "aud_k5_src_sel", aud_src_parents,
  543. 0x012c, 19, 1, 27),
  544. MUX_GATE(CLK_TOP_AUD_K6_SRC_SEL, "aud_k6_src_sel", aud_src_parents,
  545. 0x012c, 20, 1, 28),
  546. };
  547. static const struct mtk_clk_divider top_adj_divs[] = {
  548. DIV_ADJ(CLK_TOP_AUD_EXTCK1_DIV, "audio_ext1_ck", "aud_ext1",
  549. 0x0120, 0, 8),
  550. DIV_ADJ(CLK_TOP_AUD_EXTCK2_DIV, "audio_ext2_ck", "aud_ext2",
  551. 0x0120, 8, 8),
  552. DIV_ADJ(CLK_TOP_AUD_MUX1_DIV, "aud_mux1_div", "aud_mux1_sel",
  553. 0x0120, 16, 8),
  554. DIV_ADJ(CLK_TOP_AUD_MUX2_DIV, "aud_mux2_div", "aud_mux2_sel",
  555. 0x0120, 24, 8),
  556. DIV_ADJ(CLK_TOP_AUD_K1_SRC_DIV, "aud_k1_src_div", "aud_k1_src_sel",
  557. 0x0124, 0, 8),
  558. DIV_ADJ(CLK_TOP_AUD_K2_SRC_DIV, "aud_k2_src_div", "aud_k2_src_sel",
  559. 0x0124, 8, 8),
  560. DIV_ADJ(CLK_TOP_AUD_K3_SRC_DIV, "aud_k3_src_div", "aud_k3_src_sel",
  561. 0x0124, 16, 8),
  562. DIV_ADJ(CLK_TOP_AUD_K4_SRC_DIV, "aud_k4_src_div", "aud_k4_src_sel",
  563. 0x0124, 24, 8),
  564. DIV_ADJ(CLK_TOP_AUD_K5_SRC_DIV, "aud_k5_src_div", "aud_k5_src_sel",
  565. 0x0128, 0, 8),
  566. DIV_ADJ(CLK_TOP_AUD_K6_SRC_DIV, "aud_k6_src_div", "aud_k6_src_sel",
  567. 0x0128, 8, 8),
  568. };
  569. static const struct mtk_gate_regs top_aud_cg_regs = {
  570. .sta_ofs = 0x012C,
  571. };
  572. #define GATE_TOP_AUD(_id, _name, _parent, _shift) { \
  573. .id = _id, \
  574. .name = _name, \
  575. .parent_name = _parent, \
  576. .regs = &top_aud_cg_regs, \
  577. .shift = _shift, \
  578. .ops = &mtk_clk_gate_ops_no_setclr, \
  579. }
  580. static const struct mtk_gate top_clks[] = {
  581. GATE_TOP_AUD(CLK_TOP_AUD_48K_TIMING, "a1sys_hp_ck", "aud_mux1_div",
  582. 21),
  583. GATE_TOP_AUD(CLK_TOP_AUD_44K_TIMING, "a2sys_hp_ck", "aud_mux2_div",
  584. 22),
  585. GATE_TOP_AUD(CLK_TOP_AUD_I2S1_MCLK, "aud_i2s1_mclk", "aud_k1_src_div",
  586. 23),
  587. GATE_TOP_AUD(CLK_TOP_AUD_I2S2_MCLK, "aud_i2s2_mclk", "aud_k2_src_div",
  588. 24),
  589. GATE_TOP_AUD(CLK_TOP_AUD_I2S3_MCLK, "aud_i2s3_mclk", "aud_k3_src_div",
  590. 25),
  591. GATE_TOP_AUD(CLK_TOP_AUD_I2S4_MCLK, "aud_i2s4_mclk", "aud_k4_src_div",
  592. 26),
  593. GATE_TOP_AUD(CLK_TOP_AUD_I2S5_MCLK, "aud_i2s5_mclk", "aud_k5_src_div",
  594. 27),
  595. GATE_TOP_AUD(CLK_TOP_AUD_I2S6_MCLK, "aud_i2s6_mclk", "aud_k6_src_div",
  596. 28),
  597. };
  598. static int mtk_topckgen_init(struct platform_device *pdev)
  599. {
  600. struct clk_onecell_data *clk_data;
  601. void __iomem *base;
  602. struct device_node *node = pdev->dev.of_node;
  603. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  604. base = devm_ioremap_resource(&pdev->dev, res);
  605. if (IS_ERR(base))
  606. return PTR_ERR(base);
  607. clk_data = mtk_alloc_clk_data(CLK_TOP_NR);
  608. mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
  609. clk_data);
  610. mtk_clk_register_factors(top_fixed_divs, ARRAY_SIZE(top_fixed_divs),
  611. clk_data);
  612. mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes),
  613. base, &mt2701_clk_lock, clk_data);
  614. mtk_clk_register_dividers(top_adj_divs, ARRAY_SIZE(top_adj_divs),
  615. base, &mt2701_clk_lock, clk_data);
  616. mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
  617. clk_data);
  618. return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  619. }
  620. static const struct mtk_gate_regs infra_cg_regs = {
  621. .set_ofs = 0x0040,
  622. .clr_ofs = 0x0044,
  623. .sta_ofs = 0x0048,
  624. };
  625. #define GATE_ICG(_id, _name, _parent, _shift) { \
  626. .id = _id, \
  627. .name = _name, \
  628. .parent_name = _parent, \
  629. .regs = &infra_cg_regs, \
  630. .shift = _shift, \
  631. .ops = &mtk_clk_gate_ops_setclr, \
  632. }
  633. static const struct mtk_gate infra_clks[] = {
  634. GATE_ICG(CLK_INFRA_DBG, "dbgclk", "axi_sel", 0),
  635. GATE_ICG(CLK_INFRA_SMI, "smi_ck", "mm_sel", 1),
  636. GATE_ICG(CLK_INFRA_QAXI_CM4, "cm4_ck", "axi_sel", 2),
  637. GATE_ICG(CLK_INFRA_AUD_SPLIN_B, "audio_splin_bck", "hadds2pll_294m", 4),
  638. GATE_ICG(CLK_INFRA_AUDIO, "audio_ck", "clk26m", 5),
  639. GATE_ICG(CLK_INFRA_EFUSE, "efuse_ck", "clk26m", 6),
  640. GATE_ICG(CLK_INFRA_L2C_SRAM, "l2c_sram_ck", "mm_sel", 7),
  641. GATE_ICG(CLK_INFRA_M4U, "m4u_ck", "mem_sel", 8),
  642. GATE_ICG(CLK_INFRA_CONNMCU, "connsys_bus", "wbg_dig_ck_416m", 12),
  643. GATE_ICG(CLK_INFRA_TRNG, "trng_ck", "axi_sel", 13),
  644. GATE_ICG(CLK_INFRA_RAMBUFIF, "rambufif_ck", "mem_sel", 14),
  645. GATE_ICG(CLK_INFRA_CPUM, "cpum_ck", "mem_sel", 15),
  646. GATE_ICG(CLK_INFRA_KP, "kp_ck", "axi_sel", 16),
  647. GATE_ICG(CLK_INFRA_CEC, "cec_ck", "rtc_sel", 18),
  648. GATE_ICG(CLK_INFRA_IRRX, "irrx_ck", "axi_sel", 19),
  649. GATE_ICG(CLK_INFRA_PMICSPI, "pmicspi_ck", "pmicspi_sel", 22),
  650. GATE_ICG(CLK_INFRA_PMICWRAP, "pmicwrap_ck", "axi_sel", 23),
  651. GATE_ICG(CLK_INFRA_DDCCI, "ddcci_ck", "axi_sel", 24),
  652. };
  653. static const struct mtk_fixed_factor infra_fixed_divs[] = {
  654. FACTOR(CLK_INFRA_CLK_13M, "clk13m", "clk26m", 1, 2),
  655. };
  656. static struct clk_onecell_data *infra_clk_data;
  657. static void mtk_infrasys_init_early(struct device_node *node)
  658. {
  659. int r, i;
  660. if (!infra_clk_data) {
  661. infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
  662. for (i = 0; i < CLK_INFRA_NR; i++)
  663. infra_clk_data->clks[i] = ERR_PTR(-EPROBE_DEFER);
  664. }
  665. mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
  666. infra_clk_data);
  667. r = of_clk_add_provider(node, of_clk_src_onecell_get, infra_clk_data);
  668. if (r)
  669. pr_err("%s(): could not register clock provider: %d\n",
  670. __func__, r);
  671. }
  672. CLK_OF_DECLARE_DRIVER(mtk_infra, "mediatek,mt2701-infracfg",
  673. mtk_infrasys_init_early);
  674. static int mtk_infrasys_init(struct platform_device *pdev)
  675. {
  676. int r, i;
  677. struct device_node *node = pdev->dev.of_node;
  678. if (!infra_clk_data) {
  679. infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
  680. } else {
  681. for (i = 0; i < CLK_INFRA_NR; i++) {
  682. if (infra_clk_data->clks[i] == ERR_PTR(-EPROBE_DEFER))
  683. infra_clk_data->clks[i] = ERR_PTR(-ENOENT);
  684. }
  685. }
  686. mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
  687. infra_clk_data);
  688. mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
  689. infra_clk_data);
  690. r = of_clk_add_provider(node, of_clk_src_onecell_get, infra_clk_data);
  691. if (r)
  692. return r;
  693. mtk_register_reset_controller(node, 2, 0x30);
  694. return 0;
  695. }
  696. static const struct mtk_gate_regs peri0_cg_regs = {
  697. .set_ofs = 0x0008,
  698. .clr_ofs = 0x0010,
  699. .sta_ofs = 0x0018,
  700. };
  701. static const struct mtk_gate_regs peri1_cg_regs = {
  702. .set_ofs = 0x000c,
  703. .clr_ofs = 0x0014,
  704. .sta_ofs = 0x001c,
  705. };
  706. #define GATE_PERI0(_id, _name, _parent, _shift) { \
  707. .id = _id, \
  708. .name = _name, \
  709. .parent_name = _parent, \
  710. .regs = &peri0_cg_regs, \
  711. .shift = _shift, \
  712. .ops = &mtk_clk_gate_ops_setclr, \
  713. }
  714. #define GATE_PERI1(_id, _name, _parent, _shift) { \
  715. .id = _id, \
  716. .name = _name, \
  717. .parent_name = _parent, \
  718. .regs = &peri1_cg_regs, \
  719. .shift = _shift, \
  720. .ops = &mtk_clk_gate_ops_setclr, \
  721. }
  722. static const struct mtk_gate peri_clks[] = {
  723. GATE_PERI0(CLK_PERI_USB0_MCU, "usb0_mcu_ck", "axi_sel", 31),
  724. GATE_PERI0(CLK_PERI_ETH, "eth_ck", "clk26m", 30),
  725. GATE_PERI0(CLK_PERI_SPI0, "spi0_ck", "spi0_sel", 29),
  726. GATE_PERI0(CLK_PERI_AUXADC, "auxadc_ck", "clk26m", 28),
  727. GATE_PERI0(CLK_PERI_I2C3, "i2c3_ck", "clk26m", 27),
  728. GATE_PERI0(CLK_PERI_I2C2, "i2c2_ck", "axi_sel", 26),
  729. GATE_PERI0(CLK_PERI_I2C1, "i2c1_ck", "axi_sel", 25),
  730. GATE_PERI0(CLK_PERI_I2C0, "i2c0_ck", "axi_sel", 24),
  731. GATE_PERI0(CLK_PERI_BTIF, "bitif_ck", "axi_sel", 23),
  732. GATE_PERI0(CLK_PERI_UART3, "uart3_ck", "axi_sel", 22),
  733. GATE_PERI0(CLK_PERI_UART2, "uart2_ck", "axi_sel", 21),
  734. GATE_PERI0(CLK_PERI_UART1, "uart1_ck", "axi_sel", 20),
  735. GATE_PERI0(CLK_PERI_UART0, "uart0_ck", "axi_sel", 19),
  736. GATE_PERI0(CLK_PERI_NLI, "nli_ck", "axi_sel", 18),
  737. GATE_PERI0(CLK_PERI_MSDC50_3, "msdc50_3_ck", "emmc_hclk_sel", 17),
  738. GATE_PERI0(CLK_PERI_MSDC30_3, "msdc30_3_ck", "msdc30_3_sel", 16),
  739. GATE_PERI0(CLK_PERI_MSDC30_2, "msdc30_2_ck", "msdc30_2_sel", 15),
  740. GATE_PERI0(CLK_PERI_MSDC30_1, "msdc30_1_ck", "msdc30_1_sel", 14),
  741. GATE_PERI0(CLK_PERI_MSDC30_0, "msdc30_0_ck", "msdc30_0_sel", 13),
  742. GATE_PERI0(CLK_PERI_AP_DMA, "ap_dma_ck", "axi_sel", 12),
  743. GATE_PERI0(CLK_PERI_USB1, "usb1_ck", "usb20_sel", 11),
  744. GATE_PERI0(CLK_PERI_USB0, "usb0_ck", "usb20_sel", 10),
  745. GATE_PERI0(CLK_PERI_PWM, "pwm_ck", "axi_sel", 9),
  746. GATE_PERI0(CLK_PERI_PWM7, "pwm7_ck", "axi_sel", 8),
  747. GATE_PERI0(CLK_PERI_PWM6, "pwm6_ck", "axi_sel", 7),
  748. GATE_PERI0(CLK_PERI_PWM5, "pwm5_ck", "axi_sel", 6),
  749. GATE_PERI0(CLK_PERI_PWM4, "pwm4_ck", "axi_sel", 5),
  750. GATE_PERI0(CLK_PERI_PWM3, "pwm3_ck", "axi_sel", 4),
  751. GATE_PERI0(CLK_PERI_PWM2, "pwm2_ck", "axi_sel", 3),
  752. GATE_PERI0(CLK_PERI_PWM1, "pwm1_ck", "axi_sel", 2),
  753. GATE_PERI0(CLK_PERI_THERM, "therm_ck", "axi_sel", 1),
  754. GATE_PERI0(CLK_PERI_NFI, "nfi_ck", "nfi2x_sel", 0),
  755. GATE_PERI1(CLK_PERI_FCI, "fci_ck", "ms_card_sel", 11),
  756. GATE_PERI1(CLK_PERI_SPI2, "spi2_ck", "spi2_sel", 10),
  757. GATE_PERI1(CLK_PERI_SPI1, "spi1_ck", "spi1_sel", 9),
  758. GATE_PERI1(CLK_PERI_HOST89_DVD, "host89_dvd_ck", "aud2dvd_sel", 8),
  759. GATE_PERI1(CLK_PERI_HOST89_SPI, "host89_spi_ck", "spi0_sel", 7),
  760. GATE_PERI1(CLK_PERI_HOST89_INT, "host89_int_ck", "axi_sel", 6),
  761. GATE_PERI1(CLK_PERI_FLASH, "flash_ck", "nfi2x_sel", 5),
  762. GATE_PERI1(CLK_PERI_NFI_PAD, "nfi_pad_ck", "nfi1x_pad", 4),
  763. GATE_PERI1(CLK_PERI_NFI_ECC, "nfi_ecc_ck", "nfi1x_pad", 3),
  764. GATE_PERI1(CLK_PERI_GCPU, "gcpu_ck", "axi_sel", 2),
  765. GATE_PERI1(CLK_PERI_USB_SLV, "usbslv_ck", "axi_sel", 1),
  766. GATE_PERI1(CLK_PERI_USB1_MCU, "usb1_mcu_ck", "axi_sel", 0),
  767. };
  768. static const char * const uart_ck_sel_parents[] = {
  769. "clk26m",
  770. "uart_sel",
  771. };
  772. static const struct mtk_composite peri_muxs[] = {
  773. MUX(CLK_PERI_UART0_SEL, "uart0_ck_sel", uart_ck_sel_parents,
  774. 0x40c, 0, 1),
  775. MUX(CLK_PERI_UART1_SEL, "uart1_ck_sel", uart_ck_sel_parents,
  776. 0x40c, 1, 1),
  777. MUX(CLK_PERI_UART2_SEL, "uart2_ck_sel", uart_ck_sel_parents,
  778. 0x40c, 2, 1),
  779. MUX(CLK_PERI_UART3_SEL, "uart3_ck_sel", uart_ck_sel_parents,
  780. 0x40c, 3, 1),
  781. };
  782. static int mtk_pericfg_init(struct platform_device *pdev)
  783. {
  784. struct clk_onecell_data *clk_data;
  785. void __iomem *base;
  786. int r;
  787. struct device_node *node = pdev->dev.of_node;
  788. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  789. base = devm_ioremap_resource(&pdev->dev, res);
  790. if (IS_ERR(base))
  791. return PTR_ERR(base);
  792. clk_data = mtk_alloc_clk_data(CLK_PERI_NR);
  793. mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks),
  794. clk_data);
  795. mtk_clk_register_composites(peri_muxs, ARRAY_SIZE(peri_muxs), base,
  796. &mt2701_clk_lock, clk_data);
  797. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  798. if (r)
  799. return r;
  800. mtk_register_reset_controller(node, 2, 0x0);
  801. return 0;
  802. }
  803. #define MT8590_PLL_FMAX (2000 * MHZ)
  804. #define CON0_MT8590_RST_BAR BIT(27)
  805. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pd_reg, \
  806. _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift) { \
  807. .id = _id, \
  808. .name = _name, \
  809. .reg = _reg, \
  810. .pwr_reg = _pwr_reg, \
  811. .en_mask = _en_mask, \
  812. .flags = _flags, \
  813. .rst_bar_mask = CON0_MT8590_RST_BAR, \
  814. .fmax = MT8590_PLL_FMAX, \
  815. .pcwbits = _pcwbits, \
  816. .pd_reg = _pd_reg, \
  817. .pd_shift = _pd_shift, \
  818. .tuner_reg = _tuner_reg, \
  819. .pcw_reg = _pcw_reg, \
  820. .pcw_shift = _pcw_shift, \
  821. }
  822. static const struct mtk_pll_data apmixed_plls[] = {
  823. PLL(CLK_APMIXED_ARMPLL, "armpll", 0x200, 0x20c, 0x80000001,
  824. PLL_AO, 21, 0x204, 24, 0x0, 0x204, 0),
  825. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x210, 0x21c, 0xf0000001,
  826. HAVE_RST_BAR, 21, 0x210, 4, 0x0, 0x214, 0),
  827. PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x220, 0x22c, 0xf3000001,
  828. HAVE_RST_BAR, 7, 0x220, 4, 0x0, 0x224, 14),
  829. PLL(CLK_APMIXED_MMPLL, "mmpll", 0x230, 0x23c, 0x00000001, 0,
  830. 21, 0x230, 4, 0x0, 0x234, 0),
  831. PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x240, 0x24c, 0x00000001, 0,
  832. 21, 0x240, 4, 0x0, 0x244, 0),
  833. PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x250, 0x25c, 0x00000001, 0,
  834. 21, 0x250, 4, 0x0, 0x254, 0),
  835. PLL(CLK_APMIXED_AUD1PLL, "aud1pll", 0x270, 0x27c, 0x00000001, 0,
  836. 31, 0x270, 4, 0x0, 0x274, 0),
  837. PLL(CLK_APMIXED_TRGPLL, "trgpll", 0x280, 0x28c, 0x00000001, 0,
  838. 31, 0x280, 4, 0x0, 0x284, 0),
  839. PLL(CLK_APMIXED_ETHPLL, "ethpll", 0x290, 0x29c, 0x00000001, 0,
  840. 31, 0x290, 4, 0x0, 0x294, 0),
  841. PLL(CLK_APMIXED_VDECPLL, "vdecpll", 0x2a0, 0x2ac, 0x00000001, 0,
  842. 31, 0x2a0, 4, 0x0, 0x2a4, 0),
  843. PLL(CLK_APMIXED_HADDS2PLL, "hadds2pll", 0x2b0, 0x2bc, 0x00000001, 0,
  844. 31, 0x2b0, 4, 0x0, 0x2b4, 0),
  845. PLL(CLK_APMIXED_AUD2PLL, "aud2pll", 0x2c0, 0x2cc, 0x00000001, 0,
  846. 31, 0x2c0, 4, 0x0, 0x2c4, 0),
  847. PLL(CLK_APMIXED_TVD2PLL, "tvd2pll", 0x2d0, 0x2dc, 0x00000001, 0,
  848. 21, 0x2d0, 4, 0x0, 0x2d4, 0),
  849. };
  850. static int mtk_apmixedsys_init(struct platform_device *pdev)
  851. {
  852. struct clk_onecell_data *clk_data;
  853. struct device_node *node = pdev->dev.of_node;
  854. clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR);
  855. if (!clk_data)
  856. return -ENOMEM;
  857. mtk_clk_register_plls(node, apmixed_plls, ARRAY_SIZE(apmixed_plls),
  858. clk_data);
  859. return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  860. }
  861. static const struct of_device_id of_match_clk_mt2701[] = {
  862. {
  863. .compatible = "mediatek,mt2701-topckgen",
  864. .data = mtk_topckgen_init,
  865. }, {
  866. .compatible = "mediatek,mt2701-infracfg",
  867. .data = mtk_infrasys_init,
  868. }, {
  869. .compatible = "mediatek,mt2701-pericfg",
  870. .data = mtk_pericfg_init,
  871. }, {
  872. .compatible = "mediatek,mt2701-apmixedsys",
  873. .data = mtk_apmixedsys_init,
  874. }, {
  875. /* sentinel */
  876. }
  877. };
  878. static int clk_mt2701_probe(struct platform_device *pdev)
  879. {
  880. int (*clk_init)(struct platform_device *);
  881. int r;
  882. clk_init = of_device_get_match_data(&pdev->dev);
  883. if (!clk_init)
  884. return -EINVAL;
  885. r = clk_init(pdev);
  886. if (r)
  887. dev_err(&pdev->dev,
  888. "could not register clock provider: %s: %d\n",
  889. pdev->name, r);
  890. return r;
  891. }
  892. static struct platform_driver clk_mt2701_drv = {
  893. .probe = clk_mt2701_probe,
  894. .driver = {
  895. .name = "clk-mt2701",
  896. .of_match_table = of_match_clk_mt2701,
  897. },
  898. };
  899. static int __init clk_mt2701_init(void)
  900. {
  901. return platform_driver_register(&clk_mt2701_drv);
  902. }
  903. arch_initcall(clk_mt2701_init);