clk-mt8173.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. /*
  2. * Copyright (c) 2014 MediaTek Inc.
  3. * Author: James Liao <jamesjj.liao@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.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include "clk-mtk.h"
  18. #include "clk-gate.h"
  19. #include <dt-bindings/clock/mt8173-clk.h>
  20. /*
  21. * For some clocks, we don't care what their actual rates are. And these
  22. * clocks may change their rate on different products or different scenarios.
  23. * So we model these clocks' rate as 0, to denote it's not an actual rate.
  24. */
  25. #define DUMMY_RATE 0
  26. static DEFINE_SPINLOCK(mt8173_clk_lock);
  27. static const struct mtk_fixed_clk fixed_clks[] __initconst = {
  28. FIXED_CLK(CLK_TOP_CLKPH_MCK_O, "clkph_mck_o", "clk26m", DUMMY_RATE),
  29. FIXED_CLK(CLK_TOP_USB_SYSPLL_125M, "usb_syspll_125m", "clk26m", 125 * MHZ),
  30. FIXED_CLK(CLK_TOP_DSI0_DIG, "dsi0_dig", "clk26m", DUMMY_RATE),
  31. FIXED_CLK(CLK_TOP_DSI1_DIG, "dsi1_dig", "clk26m", DUMMY_RATE),
  32. FIXED_CLK(CLK_TOP_LVDS_PXL, "lvds_pxl", "lvdspll", DUMMY_RATE),
  33. FIXED_CLK(CLK_TOP_LVDS_CTS, "lvds_cts", "lvdspll", DUMMY_RATE),
  34. };
  35. static const struct mtk_fixed_factor top_divs[] __initconst = {
  36. FACTOR(CLK_TOP_ARMCA7PLL_754M, "armca7pll_754m", "armca7pll", 1, 2),
  37. FACTOR(CLK_TOP_ARMCA7PLL_502M, "armca7pll_502m", "armca7pll", 1, 3),
  38. FACTOR(CLK_TOP_MAIN_H546M, "main_h546m", "mainpll", 1, 2),
  39. FACTOR(CLK_TOP_MAIN_H364M, "main_h364m", "mainpll", 1, 3),
  40. FACTOR(CLK_TOP_MAIN_H218P4M, "main_h218p4m", "mainpll", 1, 5),
  41. FACTOR(CLK_TOP_MAIN_H156M, "main_h156m", "mainpll", 1, 7),
  42. FACTOR(CLK_TOP_TVDPLL_445P5M, "tvdpll_445p5m", "tvdpll", 1, 4),
  43. FACTOR(CLK_TOP_TVDPLL_594M, "tvdpll_594m", "tvdpll", 1, 3),
  44. FACTOR(CLK_TOP_UNIV_624M, "univ_624m", "univpll", 1, 2),
  45. FACTOR(CLK_TOP_UNIV_416M, "univ_416m", "univpll", 1, 3),
  46. FACTOR(CLK_TOP_UNIV_249P6M, "univ_249p6m", "univpll", 1, 5),
  47. FACTOR(CLK_TOP_UNIV_178P3M, "univ_178p3m", "univpll", 1, 7),
  48. FACTOR(CLK_TOP_UNIV_48M, "univ_48m", "univpll", 1, 26),
  49. FACTOR(CLK_TOP_CLKRTC_EXT, "clkrtc_ext", "clk32k", 1, 1),
  50. FACTOR(CLK_TOP_CLKRTC_INT, "clkrtc_int", "clk26m", 1, 793),
  51. FACTOR(CLK_TOP_FPC, "fpc_ck", "clk26m", 1, 1),
  52. FACTOR(CLK_TOP_HDMITX_DIG_CTS, "hdmitx_dig_cts", "tvdpll_445p5m", 1, 3),
  53. FACTOR(CLK_TOP_HDMITXPLL_D2, "hdmitxpll_d2", "hdmitx_dig_cts", 1, 2),
  54. FACTOR(CLK_TOP_HDMITXPLL_D3, "hdmitxpll_d3", "hdmitx_dig_cts", 1, 3),
  55. FACTOR(CLK_TOP_ARMCA7PLL_D2, "armca7pll_d2", "armca7pll_754m", 1, 1),
  56. FACTOR(CLK_TOP_ARMCA7PLL_D3, "armca7pll_d3", "armca7pll_502m", 1, 1),
  57. FACTOR(CLK_TOP_APLL1, "apll1_ck", "apll1", 1, 1),
  58. FACTOR(CLK_TOP_APLL2, "apll2_ck", "apll2", 1, 1),
  59. FACTOR(CLK_TOP_DMPLL, "dmpll_ck", "clkph_mck_o", 1, 1),
  60. FACTOR(CLK_TOP_DMPLL_D2, "dmpll_d2", "clkph_mck_o", 1, 2),
  61. FACTOR(CLK_TOP_DMPLL_D4, "dmpll_d4", "clkph_mck_o", 1, 4),
  62. FACTOR(CLK_TOP_DMPLL_D8, "dmpll_d8", "clkph_mck_o", 1, 8),
  63. FACTOR(CLK_TOP_DMPLL_D16, "dmpll_d16", "clkph_mck_o", 1, 16),
  64. FACTOR(CLK_TOP_LVDSPLL_D2, "lvdspll_d2", "lvdspll", 1, 2),
  65. FACTOR(CLK_TOP_LVDSPLL_D4, "lvdspll_d4", "lvdspll", 1, 4),
  66. FACTOR(CLK_TOP_LVDSPLL_D8, "lvdspll_d8", "lvdspll", 1, 8),
  67. FACTOR(CLK_TOP_MMPLL, "mmpll_ck", "mmpll", 1, 1),
  68. FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll", 1, 2),
  69. FACTOR(CLK_TOP_MSDCPLL, "msdcpll_ck", "msdcpll", 1, 1),
  70. FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll", 1, 2),
  71. FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll", 1, 4),
  72. FACTOR(CLK_TOP_MSDCPLL2, "msdcpll2_ck", "msdcpll2", 1, 1),
  73. FACTOR(CLK_TOP_MSDCPLL2_D2, "msdcpll2_d2", "msdcpll2", 1, 2),
  74. FACTOR(CLK_TOP_MSDCPLL2_D4, "msdcpll2_d4", "msdcpll2", 1, 4),
  75. FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "main_h546m", 1, 1),
  76. FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "main_h546m", 1, 2),
  77. FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "main_h546m", 1, 4),
  78. FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "main_h546m", 1, 8),
  79. FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "main_h546m", 1, 16),
  80. FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "main_h364m", 1, 1),
  81. FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "main_h364m", 1, 2),
  82. FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "main_h364m", 1, 4),
  83. FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "main_h218p4m", 1, 1),
  84. FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "main_h218p4m", 1, 2),
  85. FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "main_h218p4m", 1, 4),
  86. FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "main_h156m", 1, 1),
  87. FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "main_h156m", 1, 2),
  88. FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "main_h156m", 1, 4),
  89. FACTOR(CLK_TOP_TVDPLL, "tvdpll_ck", "tvdpll_594m", 1, 1),
  90. FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_594m", 1, 2),
  91. FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll_594m", 1, 4),
  92. FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll_594m", 1, 8),
  93. FACTOR(CLK_TOP_TVDPLL_D16, "tvdpll_d16", "tvdpll_594m", 1, 16),
  94. FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univ_624m", 1, 1),
  95. FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univ_624m", 1, 2),
  96. FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univ_624m", 1, 4),
  97. FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univ_624m", 1, 8),
  98. FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univ_416m", 1, 1),
  99. FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univ_416m", 1, 2),
  100. FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univ_416m", 1, 4),
  101. FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univ_416m", 1, 8),
  102. FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univ_249p6m", 1, 1),
  103. FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univ_249p6m", 1, 2),
  104. FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univ_249p6m", 1, 4),
  105. FACTOR(CLK_TOP_UNIVPLL3_D8, "univpll3_d8", "univ_249p6m", 1, 8),
  106. FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univ_178p3m", 1, 1),
  107. FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univ_48m", 1, 1),
  108. FACTOR(CLK_TOP_UNIVPLL_D52, "univpll_d52", "univ_48m", 1, 2),
  109. FACTOR(CLK_TOP_VCODECPLL, "vcodecpll_ck", "vcodecpll", 1, 3),
  110. FACTOR(CLK_TOP_VCODECPLL_370P5, "vcodecpll_370p5", "vcodecpll", 1, 4),
  111. FACTOR(CLK_TOP_VENCPLL, "vencpll_ck", "vencpll", 1, 1),
  112. FACTOR(CLK_TOP_VENCPLL_D2, "vencpll_d2", "vencpll", 1, 2),
  113. FACTOR(CLK_TOP_VENCPLL_D4, "vencpll_d4", "vencpll", 1, 4),
  114. };
  115. static const char * const axi_parents[] __initconst = {
  116. "clk26m",
  117. "syspll1_d2",
  118. "syspll_d5",
  119. "syspll1_d4",
  120. "univpll_d5",
  121. "univpll2_d2",
  122. "dmpll_d2",
  123. "dmpll_d4"
  124. };
  125. static const char * const mem_parents[] __initconst = {
  126. "clk26m",
  127. "dmpll_ck"
  128. };
  129. static const char * const ddrphycfg_parents[] __initconst = {
  130. "clk26m",
  131. "syspll1_d8"
  132. };
  133. static const char * const mm_parents[] __initconst = {
  134. "clk26m",
  135. "vencpll_d2",
  136. "main_h364m",
  137. "syspll1_d2",
  138. "syspll_d5",
  139. "syspll1_d4",
  140. "univpll1_d2",
  141. "univpll2_d2",
  142. "dmpll_d2"
  143. };
  144. static const char * const pwm_parents[] __initconst = {
  145. "clk26m",
  146. "univpll2_d4",
  147. "univpll3_d2",
  148. "univpll1_d4"
  149. };
  150. static const char * const vdec_parents[] __initconst = {
  151. "clk26m",
  152. "vcodecpll_ck",
  153. "tvdpll_445p5m",
  154. "univpll_d3",
  155. "vencpll_d2",
  156. "syspll_d3",
  157. "univpll1_d2",
  158. "mmpll_d2",
  159. "dmpll_d2",
  160. "dmpll_d4"
  161. };
  162. static const char * const venc_parents[] __initconst = {
  163. "clk26m",
  164. "vcodecpll_ck",
  165. "tvdpll_445p5m",
  166. "univpll_d3",
  167. "vencpll_d2",
  168. "syspll_d3",
  169. "univpll1_d2",
  170. "univpll2_d2",
  171. "dmpll_d2",
  172. "dmpll_d4"
  173. };
  174. static const char * const mfg_parents[] __initconst = {
  175. "clk26m",
  176. "mmpll_ck",
  177. "dmpll_ck",
  178. "clk26m",
  179. "clk26m",
  180. "clk26m",
  181. "clk26m",
  182. "clk26m",
  183. "clk26m",
  184. "syspll_d3",
  185. "syspll1_d2",
  186. "syspll_d5",
  187. "univpll_d3",
  188. "univpll1_d2",
  189. "univpll_d5",
  190. "univpll2_d2"
  191. };
  192. static const char * const camtg_parents[] __initconst = {
  193. "clk26m",
  194. "univpll_d26",
  195. "univpll2_d2",
  196. "syspll3_d2",
  197. "syspll3_d4",
  198. "univpll1_d4"
  199. };
  200. static const char * const uart_parents[] __initconst = {
  201. "clk26m",
  202. "univpll2_d8"
  203. };
  204. static const char * const spi_parents[] __initconst = {
  205. "clk26m",
  206. "syspll3_d2",
  207. "syspll1_d4",
  208. "syspll4_d2",
  209. "univpll3_d2",
  210. "univpll2_d4",
  211. "univpll1_d8"
  212. };
  213. static const char * const usb20_parents[] __initconst = {
  214. "clk26m",
  215. "univpll1_d8",
  216. "univpll3_d4"
  217. };
  218. static const char * const usb30_parents[] __initconst = {
  219. "clk26m",
  220. "univpll3_d2",
  221. "usb_syspll_125m",
  222. "univpll2_d4"
  223. };
  224. static const char * const msdc50_0_h_parents[] __initconst = {
  225. "clk26m",
  226. "syspll1_d2",
  227. "syspll2_d2",
  228. "syspll4_d2",
  229. "univpll_d5",
  230. "univpll1_d4"
  231. };
  232. static const char * const msdc50_0_parents[] __initconst = {
  233. "clk26m",
  234. "msdcpll_ck",
  235. "msdcpll_d2",
  236. "univpll1_d4",
  237. "syspll2_d2",
  238. "syspll_d7",
  239. "msdcpll_d4",
  240. "vencpll_d4",
  241. "tvdpll_ck",
  242. "univpll_d2",
  243. "univpll1_d2",
  244. "mmpll_ck",
  245. "msdcpll2_ck",
  246. "msdcpll2_d2",
  247. "msdcpll2_d4"
  248. };
  249. static const char * const msdc30_1_parents[] __initconst = {
  250. "clk26m",
  251. "univpll2_d2",
  252. "msdcpll_d4",
  253. "univpll1_d4",
  254. "syspll2_d2",
  255. "syspll_d7",
  256. "univpll_d7",
  257. "vencpll_d4"
  258. };
  259. static const char * const msdc30_2_parents[] __initconst = {
  260. "clk26m",
  261. "univpll2_d2",
  262. "msdcpll_d4",
  263. "univpll1_d4",
  264. "syspll2_d2",
  265. "syspll_d7",
  266. "univpll_d7",
  267. "vencpll_d2"
  268. };
  269. static const char * const msdc30_3_parents[] __initconst = {
  270. "clk26m",
  271. "msdcpll2_ck",
  272. "msdcpll2_d2",
  273. "univpll2_d2",
  274. "msdcpll2_d4",
  275. "msdcpll_d4",
  276. "univpll1_d4",
  277. "syspll2_d2",
  278. "syspll_d7",
  279. "univpll_d7",
  280. "vencpll_d4",
  281. "msdcpll_ck",
  282. "msdcpll_d2",
  283. "msdcpll_d4"
  284. };
  285. static const char * const audio_parents[] __initconst = {
  286. "clk26m",
  287. "syspll3_d4",
  288. "syspll4_d4",
  289. "syspll1_d16"
  290. };
  291. static const char * const aud_intbus_parents[] __initconst = {
  292. "clk26m",
  293. "syspll1_d4",
  294. "syspll4_d2",
  295. "univpll3_d2",
  296. "univpll2_d8",
  297. "dmpll_d4",
  298. "dmpll_d8"
  299. };
  300. static const char * const pmicspi_parents[] __initconst = {
  301. "clk26m",
  302. "syspll1_d8",
  303. "syspll3_d4",
  304. "syspll1_d16",
  305. "univpll3_d4",
  306. "univpll_d26",
  307. "dmpll_d8",
  308. "dmpll_d16"
  309. };
  310. static const char * const scp_parents[] __initconst = {
  311. "clk26m",
  312. "syspll1_d2",
  313. "univpll_d5",
  314. "syspll_d5",
  315. "dmpll_d2",
  316. "dmpll_d4"
  317. };
  318. static const char * const atb_parents[] __initconst = {
  319. "clk26m",
  320. "syspll1_d2",
  321. "univpll_d5",
  322. "dmpll_d2"
  323. };
  324. static const char * const venc_lt_parents[] __initconst = {
  325. "clk26m",
  326. "univpll_d3",
  327. "vcodecpll_ck",
  328. "tvdpll_445p5m",
  329. "vencpll_d2",
  330. "syspll_d3",
  331. "univpll1_d2",
  332. "univpll2_d2",
  333. "syspll1_d2",
  334. "univpll_d5",
  335. "vcodecpll_370p5",
  336. "dmpll_ck"
  337. };
  338. static const char * const dpi0_parents[] __initconst = {
  339. "clk26m",
  340. "tvdpll_d2",
  341. "tvdpll_d4",
  342. "clk26m",
  343. "clk26m",
  344. "tvdpll_d8",
  345. "tvdpll_d16"
  346. };
  347. static const char * const irda_parents[] __initconst = {
  348. "clk26m",
  349. "univpll2_d4",
  350. "syspll2_d4"
  351. };
  352. static const char * const cci400_parents[] __initconst = {
  353. "clk26m",
  354. "vencpll_ck",
  355. "armca7pll_754m",
  356. "armca7pll_502m",
  357. "univpll_d2",
  358. "syspll_d2",
  359. "msdcpll_ck",
  360. "dmpll_ck"
  361. };
  362. static const char * const aud_1_parents[] __initconst = {
  363. "clk26m",
  364. "apll1_ck",
  365. "univpll2_d4",
  366. "univpll2_d8"
  367. };
  368. static const char * const aud_2_parents[] __initconst = {
  369. "clk26m",
  370. "apll2_ck",
  371. "univpll2_d4",
  372. "univpll2_d8"
  373. };
  374. static const char * const mem_mfg_in_parents[] __initconst = {
  375. "clk26m",
  376. "mmpll_ck",
  377. "dmpll_ck",
  378. "clk26m"
  379. };
  380. static const char * const axi_mfg_in_parents[] __initconst = {
  381. "clk26m",
  382. "axi_sel",
  383. "dmpll_d2"
  384. };
  385. static const char * const scam_parents[] __initconst = {
  386. "clk26m",
  387. "syspll3_d2",
  388. "univpll2_d4",
  389. "dmpll_d4"
  390. };
  391. static const char * const spinfi_ifr_parents[] __initconst = {
  392. "clk26m",
  393. "univpll2_d8",
  394. "univpll3_d4",
  395. "syspll4_d2",
  396. "univpll2_d4",
  397. "univpll3_d2",
  398. "syspll1_d4",
  399. "univpll1_d4"
  400. };
  401. static const char * const hdmi_parents[] __initconst = {
  402. "clk26m",
  403. "hdmitx_dig_cts",
  404. "hdmitxpll_d2",
  405. "hdmitxpll_d3"
  406. };
  407. static const char * const dpilvds_parents[] __initconst = {
  408. "clk26m",
  409. "lvdspll",
  410. "lvdspll_d2",
  411. "lvdspll_d4",
  412. "lvdspll_d8",
  413. "fpc_ck"
  414. };
  415. static const char * const msdc50_2_h_parents[] __initconst = {
  416. "clk26m",
  417. "syspll1_d2",
  418. "syspll2_d2",
  419. "syspll4_d2",
  420. "univpll_d5",
  421. "univpll1_d4"
  422. };
  423. static const char * const hdcp_parents[] __initconst = {
  424. "clk26m",
  425. "syspll4_d2",
  426. "syspll3_d4",
  427. "univpll2_d4"
  428. };
  429. static const char * const hdcp_24m_parents[] __initconst = {
  430. "clk26m",
  431. "univpll_d26",
  432. "univpll_d52",
  433. "univpll2_d8"
  434. };
  435. static const char * const rtc_parents[] __initconst = {
  436. "clkrtc_int",
  437. "clkrtc_ext",
  438. "clk26m",
  439. "univpll3_d8"
  440. };
  441. static const char * const i2s0_m_ck_parents[] __initconst = {
  442. "apll1_div1",
  443. "apll2_div1"
  444. };
  445. static const char * const i2s1_m_ck_parents[] __initconst = {
  446. "apll1_div2",
  447. "apll2_div2"
  448. };
  449. static const char * const i2s2_m_ck_parents[] __initconst = {
  450. "apll1_div3",
  451. "apll2_div3"
  452. };
  453. static const char * const i2s3_m_ck_parents[] __initconst = {
  454. "apll1_div4",
  455. "apll2_div4"
  456. };
  457. static const char * const i2s3_b_ck_parents[] __initconst = {
  458. "apll1_div5",
  459. "apll2_div5"
  460. };
  461. static const struct mtk_composite top_muxes[] __initconst = {
  462. /* CLK_CFG_0 */
  463. MUX(CLK_TOP_AXI_SEL, "axi_sel", axi_parents, 0x0040, 0, 3),
  464. MUX(CLK_TOP_MEM_SEL, "mem_sel", mem_parents, 0x0040, 8, 1),
  465. MUX_GATE(CLK_TOP_DDRPHYCFG_SEL, "ddrphycfg_sel", ddrphycfg_parents, 0x0040, 16, 1, 23),
  466. MUX_GATE(CLK_TOP_MM_SEL, "mm_sel", mm_parents, 0x0040, 24, 4, 31),
  467. /* CLK_CFG_1 */
  468. MUX_GATE(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents, 0x0050, 0, 2, 7),
  469. MUX_GATE(CLK_TOP_VDEC_SEL, "vdec_sel", vdec_parents, 0x0050, 8, 4, 15),
  470. MUX_GATE(CLK_TOP_VENC_SEL, "venc_sel", venc_parents, 0x0050, 16, 4, 23),
  471. MUX_GATE(CLK_TOP_MFG_SEL, "mfg_sel", mfg_parents, 0x0050, 24, 4, 31),
  472. /* CLK_CFG_2 */
  473. MUX_GATE(CLK_TOP_CAMTG_SEL, "camtg_sel", camtg_parents, 0x0060, 0, 3, 7),
  474. MUX_GATE(CLK_TOP_UART_SEL, "uart_sel", uart_parents, 0x0060, 8, 1, 15),
  475. MUX_GATE(CLK_TOP_SPI_SEL, "spi_sel", spi_parents, 0x0060, 16, 3, 23),
  476. MUX_GATE(CLK_TOP_USB20_SEL, "usb20_sel", usb20_parents, 0x0060, 24, 2, 31),
  477. /* CLK_CFG_3 */
  478. MUX_GATE(CLK_TOP_USB30_SEL, "usb30_sel", usb30_parents, 0x0070, 0, 2, 7),
  479. MUX_GATE(CLK_TOP_MSDC50_0_H_SEL, "msdc50_0_h_sel", msdc50_0_h_parents, 0x0070, 8, 3, 15),
  480. MUX_GATE(CLK_TOP_MSDC50_0_SEL, "msdc50_0_sel", msdc50_0_parents, 0x0070, 16, 4, 23),
  481. MUX_GATE(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel", msdc30_1_parents, 0x0070, 24, 3, 31),
  482. /* CLK_CFG_4 */
  483. MUX_GATE(CLK_TOP_MSDC30_2_SEL, "msdc30_2_sel", msdc30_2_parents, 0x0080, 0, 3, 7),
  484. MUX_GATE(CLK_TOP_MSDC30_3_SEL, "msdc30_3_sel", msdc30_3_parents, 0x0080, 8, 4, 15),
  485. MUX_GATE(CLK_TOP_AUDIO_SEL, "audio_sel", audio_parents, 0x0080, 16, 2, 23),
  486. MUX_GATE(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel", aud_intbus_parents, 0x0080, 24, 3, 31),
  487. /* CLK_CFG_5 */
  488. MUX_GATE(CLK_TOP_PMICSPI_SEL, "pmicspi_sel", pmicspi_parents, 0x0090, 0, 3, 7 /* 7:5 */),
  489. MUX_GATE(CLK_TOP_SCP_SEL, "scp_sel", scp_parents, 0x0090, 8, 3, 15),
  490. MUX_GATE(CLK_TOP_ATB_SEL, "atb_sel", atb_parents, 0x0090, 16, 2, 23),
  491. MUX_GATE(CLK_TOP_VENC_LT_SEL, "venclt_sel", venc_lt_parents, 0x0090, 24, 4, 31),
  492. /* CLK_CFG_6 */
  493. MUX_GATE(CLK_TOP_DPI0_SEL, "dpi0_sel", dpi0_parents, 0x00a0, 0, 3, 7),
  494. MUX_GATE(CLK_TOP_IRDA_SEL, "irda_sel", irda_parents, 0x00a0, 8, 2, 15),
  495. MUX_GATE(CLK_TOP_CCI400_SEL, "cci400_sel", cci400_parents, 0x00a0, 16, 3, 23),
  496. MUX_GATE(CLK_TOP_AUD_1_SEL, "aud_1_sel", aud_1_parents, 0x00a0, 24, 2, 31),
  497. /* CLK_CFG_7 */
  498. MUX_GATE(CLK_TOP_AUD_2_SEL, "aud_2_sel", aud_2_parents, 0x00b0, 0, 2, 7),
  499. MUX_GATE(CLK_TOP_MEM_MFG_IN_SEL, "mem_mfg_in_sel", mem_mfg_in_parents, 0x00b0, 8, 2, 15),
  500. MUX_GATE(CLK_TOP_AXI_MFG_IN_SEL, "axi_mfg_in_sel", axi_mfg_in_parents, 0x00b0, 16, 2, 23),
  501. MUX_GATE(CLK_TOP_SCAM_SEL, "scam_sel", scam_parents, 0x00b0, 24, 2, 31),
  502. /* CLK_CFG_12 */
  503. MUX_GATE(CLK_TOP_SPINFI_IFR_SEL, "spinfi_ifr_sel", spinfi_ifr_parents, 0x00c0, 0, 3, 7),
  504. MUX_GATE(CLK_TOP_HDMI_SEL, "hdmi_sel", hdmi_parents, 0x00c0, 8, 2, 15),
  505. MUX_GATE(CLK_TOP_DPILVDS_SEL, "dpilvds_sel", dpilvds_parents, 0x00c0, 24, 3, 31),
  506. /* CLK_CFG_13 */
  507. MUX_GATE(CLK_TOP_MSDC50_2_H_SEL, "msdc50_2_h_sel", msdc50_2_h_parents, 0x00d0, 0, 3, 7),
  508. MUX_GATE(CLK_TOP_HDCP_SEL, "hdcp_sel", hdcp_parents, 0x00d0, 8, 2, 15),
  509. MUX_GATE(CLK_TOP_HDCP_24M_SEL, "hdcp_24m_sel", hdcp_24m_parents, 0x00d0, 16, 2, 23),
  510. MUX(CLK_TOP_RTC_SEL, "rtc_sel", rtc_parents, 0x00d0, 24, 2),
  511. DIV_GATE(CLK_TOP_APLL1_DIV0, "apll1_div0", "aud_1_sel", 0x12c, 8, 0x120, 4, 24),
  512. DIV_GATE(CLK_TOP_APLL1_DIV1, "apll1_div1", "aud_1_sel", 0x12c, 9, 0x124, 8, 0),
  513. DIV_GATE(CLK_TOP_APLL1_DIV2, "apll1_div2", "aud_1_sel", 0x12c, 10, 0x124, 8, 8),
  514. DIV_GATE(CLK_TOP_APLL1_DIV3, "apll1_div3", "aud_1_sel", 0x12c, 11, 0x124, 8, 16),
  515. DIV_GATE(CLK_TOP_APLL1_DIV4, "apll1_div4", "aud_1_sel", 0x12c, 12, 0x124, 8, 24),
  516. DIV_GATE(CLK_TOP_APLL1_DIV5, "apll1_div5", "apll1_div4", 0x12c, 13, 0x12c, 4, 0),
  517. DIV_GATE(CLK_TOP_APLL2_DIV0, "apll2_div0", "aud_2_sel", 0x12c, 16, 0x120, 4, 28),
  518. DIV_GATE(CLK_TOP_APLL2_DIV1, "apll2_div1", "aud_2_sel", 0x12c, 17, 0x128, 8, 0),
  519. DIV_GATE(CLK_TOP_APLL2_DIV2, "apll2_div2", "aud_2_sel", 0x12c, 18, 0x128, 8, 8),
  520. DIV_GATE(CLK_TOP_APLL2_DIV3, "apll2_div3", "aud_2_sel", 0x12c, 19, 0x128, 8, 16),
  521. DIV_GATE(CLK_TOP_APLL2_DIV4, "apll2_div4", "aud_2_sel", 0x12c, 20, 0x128, 8, 24),
  522. DIV_GATE(CLK_TOP_APLL2_DIV5, "apll2_div5", "apll2_div4", 0x12c, 21, 0x12c, 4, 4),
  523. MUX(CLK_TOP_I2S0_M_SEL, "i2s0_m_ck_sel", i2s0_m_ck_parents, 0x120, 4, 1),
  524. MUX(CLK_TOP_I2S1_M_SEL, "i2s1_m_ck_sel", i2s1_m_ck_parents, 0x120, 5, 1),
  525. MUX(CLK_TOP_I2S2_M_SEL, "i2s2_m_ck_sel", i2s2_m_ck_parents, 0x120, 6, 1),
  526. MUX(CLK_TOP_I2S3_M_SEL, "i2s3_m_ck_sel", i2s3_m_ck_parents, 0x120, 7, 1),
  527. MUX(CLK_TOP_I2S3_B_SEL, "i2s3_b_ck_sel", i2s3_b_ck_parents, 0x120, 8, 1),
  528. };
  529. static const struct mtk_gate_regs infra_cg_regs __initconst = {
  530. .set_ofs = 0x0040,
  531. .clr_ofs = 0x0044,
  532. .sta_ofs = 0x0048,
  533. };
  534. #define GATE_ICG(_id, _name, _parent, _shift) { \
  535. .id = _id, \
  536. .name = _name, \
  537. .parent_name = _parent, \
  538. .regs = &infra_cg_regs, \
  539. .shift = _shift, \
  540. .ops = &mtk_clk_gate_ops_setclr, \
  541. }
  542. static const struct mtk_gate infra_clks[] __initconst = {
  543. GATE_ICG(CLK_INFRA_DBGCLK, "infra_dbgclk", "axi_sel", 0),
  544. GATE_ICG(CLK_INFRA_SMI, "infra_smi", "mm_sel", 1),
  545. GATE_ICG(CLK_INFRA_AUDIO, "infra_audio", "aud_intbus_sel", 5),
  546. GATE_ICG(CLK_INFRA_GCE, "infra_gce", "axi_sel", 6),
  547. GATE_ICG(CLK_INFRA_L2C_SRAM, "infra_l2c_sram", "axi_sel", 7),
  548. GATE_ICG(CLK_INFRA_M4U, "infra_m4u", "mem_sel", 8),
  549. GATE_ICG(CLK_INFRA_CPUM, "infra_cpum", "cpum_ck", 15),
  550. GATE_ICG(CLK_INFRA_KP, "infra_kp", "axi_sel", 16),
  551. GATE_ICG(CLK_INFRA_CEC, "infra_cec", "clk26m", 18),
  552. GATE_ICG(CLK_INFRA_PMICSPI, "infra_pmicspi", "pmicspi_sel", 22),
  553. GATE_ICG(CLK_INFRA_PMICWRAP, "infra_pmicwrap", "axi_sel", 23),
  554. };
  555. static const struct mtk_fixed_factor infra_divs[] __initconst = {
  556. FACTOR(CLK_INFRA_CLK_13M, "clk13m", "clk26m", 1, 2),
  557. };
  558. static const struct mtk_gate_regs peri0_cg_regs __initconst = {
  559. .set_ofs = 0x0008,
  560. .clr_ofs = 0x0010,
  561. .sta_ofs = 0x0018,
  562. };
  563. static const struct mtk_gate_regs peri1_cg_regs __initconst = {
  564. .set_ofs = 0x000c,
  565. .clr_ofs = 0x0014,
  566. .sta_ofs = 0x001c,
  567. };
  568. #define GATE_PERI0(_id, _name, _parent, _shift) { \
  569. .id = _id, \
  570. .name = _name, \
  571. .parent_name = _parent, \
  572. .regs = &peri0_cg_regs, \
  573. .shift = _shift, \
  574. .ops = &mtk_clk_gate_ops_setclr, \
  575. }
  576. #define GATE_PERI1(_id, _name, _parent, _shift) { \
  577. .id = _id, \
  578. .name = _name, \
  579. .parent_name = _parent, \
  580. .regs = &peri1_cg_regs, \
  581. .shift = _shift, \
  582. .ops = &mtk_clk_gate_ops_setclr, \
  583. }
  584. static const struct mtk_gate peri_gates[] __initconst = {
  585. /* PERI0 */
  586. GATE_PERI0(CLK_PERI_NFI, "peri_nfi", "axi_sel", 0),
  587. GATE_PERI0(CLK_PERI_THERM, "peri_therm", "axi_sel", 1),
  588. GATE_PERI0(CLK_PERI_PWM1, "peri_pwm1", "axi_sel", 2),
  589. GATE_PERI0(CLK_PERI_PWM2, "peri_pwm2", "axi_sel", 3),
  590. GATE_PERI0(CLK_PERI_PWM3, "peri_pwm3", "axi_sel", 4),
  591. GATE_PERI0(CLK_PERI_PWM4, "peri_pwm4", "axi_sel", 5),
  592. GATE_PERI0(CLK_PERI_PWM5, "peri_pwm5", "axi_sel", 6),
  593. GATE_PERI0(CLK_PERI_PWM6, "peri_pwm6", "axi_sel", 7),
  594. GATE_PERI0(CLK_PERI_PWM7, "peri_pwm7", "axi_sel", 8),
  595. GATE_PERI0(CLK_PERI_PWM, "peri_pwm", "axi_sel", 9),
  596. GATE_PERI0(CLK_PERI_USB0, "peri_usb0", "usb20_sel", 10),
  597. GATE_PERI0(CLK_PERI_USB1, "peri_usb1", "usb20_sel", 11),
  598. GATE_PERI0(CLK_PERI_AP_DMA, "peri_ap_dma", "axi_sel", 12),
  599. GATE_PERI0(CLK_PERI_MSDC30_0, "peri_msdc30_0", "msdc50_0_sel", 13),
  600. GATE_PERI0(CLK_PERI_MSDC30_1, "peri_msdc30_1", "msdc30_1_sel", 14),
  601. GATE_PERI0(CLK_PERI_MSDC30_2, "peri_msdc30_2", "msdc30_2_sel", 15),
  602. GATE_PERI0(CLK_PERI_MSDC30_3, "peri_msdc30_3", "msdc30_3_sel", 16),
  603. GATE_PERI0(CLK_PERI_NLI_ARB, "peri_nli_arb", "axi_sel", 17),
  604. GATE_PERI0(CLK_PERI_IRDA, "peri_irda", "irda_sel", 18),
  605. GATE_PERI0(CLK_PERI_UART0, "peri_uart0", "axi_sel", 19),
  606. GATE_PERI0(CLK_PERI_UART1, "peri_uart1", "axi_sel", 20),
  607. GATE_PERI0(CLK_PERI_UART2, "peri_uart2", "axi_sel", 21),
  608. GATE_PERI0(CLK_PERI_UART3, "peri_uart3", "axi_sel", 22),
  609. GATE_PERI0(CLK_PERI_I2C0, "peri_i2c0", "axi_sel", 23),
  610. GATE_PERI0(CLK_PERI_I2C1, "peri_i2c1", "axi_sel", 24),
  611. GATE_PERI0(CLK_PERI_I2C2, "peri_i2c2", "axi_sel", 25),
  612. GATE_PERI0(CLK_PERI_I2C3, "peri_i2c3", "axi_sel", 26),
  613. GATE_PERI0(CLK_PERI_I2C4, "peri_i2c4", "axi_sel", 27),
  614. GATE_PERI0(CLK_PERI_AUXADC, "peri_auxadc", "clk26m", 28),
  615. GATE_PERI0(CLK_PERI_SPI0, "peri_spi0", "spi_sel", 29),
  616. GATE_PERI0(CLK_PERI_I2C5, "peri_i2c5", "axi_sel", 30),
  617. GATE_PERI0(CLK_PERI_NFIECC, "peri_nfiecc", "axi_sel", 31),
  618. /* PERI1 */
  619. GATE_PERI1(CLK_PERI_SPI, "peri_spi", "spi_sel", 0),
  620. GATE_PERI1(CLK_PERI_IRRX, "peri_irrx", "spi_sel", 1),
  621. GATE_PERI1(CLK_PERI_I2C6, "peri_i2c6", "axi_sel", 2),
  622. };
  623. static const char * const uart_ck_sel_parents[] __initconst = {
  624. "clk26m",
  625. "uart_sel",
  626. };
  627. static const struct mtk_composite peri_clks[] __initconst = {
  628. MUX(CLK_PERI_UART0_SEL, "uart0_ck_sel", uart_ck_sel_parents, 0x40c, 0, 1),
  629. MUX(CLK_PERI_UART1_SEL, "uart1_ck_sel", uart_ck_sel_parents, 0x40c, 1, 1),
  630. MUX(CLK_PERI_UART2_SEL, "uart2_ck_sel", uart_ck_sel_parents, 0x40c, 2, 1),
  631. MUX(CLK_PERI_UART3_SEL, "uart3_ck_sel", uart_ck_sel_parents, 0x40c, 3, 1),
  632. };
  633. static const struct mtk_gate_regs cg_regs_4_8_0 __initconst = {
  634. .set_ofs = 0x0004,
  635. .clr_ofs = 0x0008,
  636. .sta_ofs = 0x0000,
  637. };
  638. #define GATE_IMG(_id, _name, _parent, _shift) { \
  639. .id = _id, \
  640. .name = _name, \
  641. .parent_name = _parent, \
  642. .regs = &cg_regs_4_8_0, \
  643. .shift = _shift, \
  644. .ops = &mtk_clk_gate_ops_setclr, \
  645. }
  646. static const struct mtk_gate img_clks[] __initconst = {
  647. GATE_IMG(CLK_IMG_LARB2_SMI, "img_larb2_smi", "mm_sel", 0),
  648. GATE_IMG(CLK_IMG_CAM_SMI, "img_cam_smi", "mm_sel", 5),
  649. GATE_IMG(CLK_IMG_CAM_CAM, "img_cam_cam", "mm_sel", 6),
  650. GATE_IMG(CLK_IMG_SEN_TG, "img_sen_tg", "camtg_sel", 7),
  651. GATE_IMG(CLK_IMG_SEN_CAM, "img_sen_cam", "mm_sel", 8),
  652. GATE_IMG(CLK_IMG_CAM_SV, "img_cam_sv", "mm_sel", 9),
  653. GATE_IMG(CLK_IMG_FD, "img_fd", "mm_sel", 11),
  654. };
  655. static const struct mtk_gate_regs mm0_cg_regs __initconst = {
  656. .set_ofs = 0x0104,
  657. .clr_ofs = 0x0108,
  658. .sta_ofs = 0x0100,
  659. };
  660. static const struct mtk_gate_regs mm1_cg_regs __initconst = {
  661. .set_ofs = 0x0114,
  662. .clr_ofs = 0x0118,
  663. .sta_ofs = 0x0110,
  664. };
  665. #define GATE_MM0(_id, _name, _parent, _shift) { \
  666. .id = _id, \
  667. .name = _name, \
  668. .parent_name = _parent, \
  669. .regs = &mm0_cg_regs, \
  670. .shift = _shift, \
  671. .ops = &mtk_clk_gate_ops_setclr, \
  672. }
  673. #define GATE_MM1(_id, _name, _parent, _shift) { \
  674. .id = _id, \
  675. .name = _name, \
  676. .parent_name = _parent, \
  677. .regs = &mm1_cg_regs, \
  678. .shift = _shift, \
  679. .ops = &mtk_clk_gate_ops_setclr, \
  680. }
  681. static const struct mtk_gate mm_clks[] __initconst = {
  682. /* MM0 */
  683. GATE_MM0(CLK_MM_SMI_COMMON, "mm_smi_common", "mm_sel", 0),
  684. GATE_MM0(CLK_MM_SMI_LARB0, "mm_smi_larb0", "mm_sel", 1),
  685. GATE_MM0(CLK_MM_CAM_MDP, "mm_cam_mdp", "mm_sel", 2),
  686. GATE_MM0(CLK_MM_MDP_RDMA0, "mm_mdp_rdma0", "mm_sel", 3),
  687. GATE_MM0(CLK_MM_MDP_RDMA1, "mm_mdp_rdma1", "mm_sel", 4),
  688. GATE_MM0(CLK_MM_MDP_RSZ0, "mm_mdp_rsz0", "mm_sel", 5),
  689. GATE_MM0(CLK_MM_MDP_RSZ1, "mm_mdp_rsz1", "mm_sel", 6),
  690. GATE_MM0(CLK_MM_MDP_RSZ2, "mm_mdp_rsz2", "mm_sel", 7),
  691. GATE_MM0(CLK_MM_MDP_TDSHP0, "mm_mdp_tdshp0", "mm_sel", 8),
  692. GATE_MM0(CLK_MM_MDP_TDSHP1, "mm_mdp_tdshp1", "mm_sel", 9),
  693. GATE_MM0(CLK_MM_MDP_WDMA, "mm_mdp_wdma", "mm_sel", 11),
  694. GATE_MM0(CLK_MM_MDP_WROT0, "mm_mdp_wrot0", "mm_sel", 12),
  695. GATE_MM0(CLK_MM_MDP_WROT1, "mm_mdp_wrot1", "mm_sel", 13),
  696. GATE_MM0(CLK_MM_FAKE_ENG, "mm_fake_eng", "mm_sel", 14),
  697. GATE_MM0(CLK_MM_MUTEX_32K, "mm_mutex_32k", "rtc_sel", 15),
  698. GATE_MM0(CLK_MM_DISP_OVL0, "mm_disp_ovl0", "mm_sel", 16),
  699. GATE_MM0(CLK_MM_DISP_OVL1, "mm_disp_ovl1", "mm_sel", 17),
  700. GATE_MM0(CLK_MM_DISP_RDMA0, "mm_disp_rdma0", "mm_sel", 18),
  701. GATE_MM0(CLK_MM_DISP_RDMA1, "mm_disp_rdma1", "mm_sel", 19),
  702. GATE_MM0(CLK_MM_DISP_RDMA2, "mm_disp_rdma2", "mm_sel", 20),
  703. GATE_MM0(CLK_MM_DISP_WDMA0, "mm_disp_wdma0", "mm_sel", 21),
  704. GATE_MM0(CLK_MM_DISP_WDMA1, "mm_disp_wdma1", "mm_sel", 22),
  705. GATE_MM0(CLK_MM_DISP_COLOR0, "mm_disp_color0", "mm_sel", 23),
  706. GATE_MM0(CLK_MM_DISP_COLOR1, "mm_disp_color1", "mm_sel", 24),
  707. GATE_MM0(CLK_MM_DISP_AAL, "mm_disp_aal", "mm_sel", 25),
  708. GATE_MM0(CLK_MM_DISP_GAMMA, "mm_disp_gamma", "mm_sel", 26),
  709. GATE_MM0(CLK_MM_DISP_UFOE, "mm_disp_ufoe", "mm_sel", 27),
  710. GATE_MM0(CLK_MM_DISP_SPLIT0, "mm_disp_split0", "mm_sel", 28),
  711. GATE_MM0(CLK_MM_DISP_SPLIT1, "mm_disp_split1", "mm_sel", 29),
  712. GATE_MM0(CLK_MM_DISP_MERGE, "mm_disp_merge", "mm_sel", 30),
  713. GATE_MM0(CLK_MM_DISP_OD, "mm_disp_od", "mm_sel", 31),
  714. /* MM1 */
  715. GATE_MM1(CLK_MM_DISP_PWM0MM, "mm_disp_pwm0mm", "mm_sel", 0),
  716. GATE_MM1(CLK_MM_DISP_PWM026M, "mm_disp_pwm026m", "pwm_sel", 1),
  717. GATE_MM1(CLK_MM_DISP_PWM1MM, "mm_disp_pwm1mm", "mm_sel", 2),
  718. GATE_MM1(CLK_MM_DISP_PWM126M, "mm_disp_pwm126m", "pwm_sel", 3),
  719. GATE_MM1(CLK_MM_DSI0_ENGINE, "mm_dsi0_engine", "mm_sel", 4),
  720. GATE_MM1(CLK_MM_DSI0_DIGITAL, "mm_dsi0_digital", "dsi0_dig", 5),
  721. GATE_MM1(CLK_MM_DSI1_ENGINE, "mm_dsi1_engine", "mm_sel", 6),
  722. GATE_MM1(CLK_MM_DSI1_DIGITAL, "mm_dsi1_digital", "dsi1_dig", 7),
  723. GATE_MM1(CLK_MM_DPI_PIXEL, "mm_dpi_pixel", "dpi0_sel", 8),
  724. GATE_MM1(CLK_MM_DPI_ENGINE, "mm_dpi_engine", "mm_sel", 9),
  725. GATE_MM1(CLK_MM_DPI1_PIXEL, "mm_dpi1_pixel", "lvds_pxl", 10),
  726. GATE_MM1(CLK_MM_DPI1_ENGINE, "mm_dpi1_engine", "mm_sel", 11),
  727. GATE_MM1(CLK_MM_HDMI_PIXEL, "mm_hdmi_pixel", "dpi0_sel", 12),
  728. GATE_MM1(CLK_MM_HDMI_PLLCK, "mm_hdmi_pllck", "hdmi_sel", 13),
  729. GATE_MM1(CLK_MM_HDMI_AUDIO, "mm_hdmi_audio", "apll1", 14),
  730. GATE_MM1(CLK_MM_HDMI_SPDIF, "mm_hdmi_spdif", "apll2", 15),
  731. GATE_MM1(CLK_MM_LVDS_PIXEL, "mm_lvds_pixel", "lvds_pxl", 16),
  732. GATE_MM1(CLK_MM_LVDS_CTS, "mm_lvds_cts", "lvds_cts", 17),
  733. GATE_MM1(CLK_MM_SMI_LARB4, "mm_smi_larb4", "mm_sel", 18),
  734. GATE_MM1(CLK_MM_HDMI_HDCP, "mm_hdmi_hdcp", "hdcp_sel", 19),
  735. GATE_MM1(CLK_MM_HDMI_HDCP24M, "mm_hdmi_hdcp24m", "hdcp_24m_sel", 20),
  736. };
  737. static const struct mtk_gate_regs vdec0_cg_regs __initconst = {
  738. .set_ofs = 0x0000,
  739. .clr_ofs = 0x0004,
  740. .sta_ofs = 0x0000,
  741. };
  742. static const struct mtk_gate_regs vdec1_cg_regs __initconst = {
  743. .set_ofs = 0x0008,
  744. .clr_ofs = 0x000c,
  745. .sta_ofs = 0x0008,
  746. };
  747. #define GATE_VDEC0(_id, _name, _parent, _shift) { \
  748. .id = _id, \
  749. .name = _name, \
  750. .parent_name = _parent, \
  751. .regs = &vdec0_cg_regs, \
  752. .shift = _shift, \
  753. .ops = &mtk_clk_gate_ops_setclr_inv, \
  754. }
  755. #define GATE_VDEC1(_id, _name, _parent, _shift) { \
  756. .id = _id, \
  757. .name = _name, \
  758. .parent_name = _parent, \
  759. .regs = &vdec1_cg_regs, \
  760. .shift = _shift, \
  761. .ops = &mtk_clk_gate_ops_setclr_inv, \
  762. }
  763. static const struct mtk_gate vdec_clks[] __initconst = {
  764. GATE_VDEC0(CLK_VDEC_CKEN, "vdec_cken", "vdec_sel", 0),
  765. GATE_VDEC1(CLK_VDEC_LARB_CKEN, "vdec_larb_cken", "mm_sel", 0),
  766. };
  767. #define GATE_VENC(_id, _name, _parent, _shift) { \
  768. .id = _id, \
  769. .name = _name, \
  770. .parent_name = _parent, \
  771. .regs = &cg_regs_4_8_0, \
  772. .shift = _shift, \
  773. .ops = &mtk_clk_gate_ops_setclr_inv, \
  774. }
  775. static const struct mtk_gate venc_clks[] __initconst = {
  776. GATE_VENC(CLK_VENC_CKE0, "venc_cke0", "mm_sel", 0),
  777. GATE_VENC(CLK_VENC_CKE1, "venc_cke1", "venc_sel", 4),
  778. GATE_VENC(CLK_VENC_CKE2, "venc_cke2", "venc_sel", 8),
  779. GATE_VENC(CLK_VENC_CKE3, "venc_cke3", "venc_sel", 12),
  780. };
  781. #define GATE_VENCLT(_id, _name, _parent, _shift) { \
  782. .id = _id, \
  783. .name = _name, \
  784. .parent_name = _parent, \
  785. .regs = &cg_regs_4_8_0, \
  786. .shift = _shift, \
  787. .ops = &mtk_clk_gate_ops_setclr_inv, \
  788. }
  789. static const struct mtk_gate venclt_clks[] __initconst = {
  790. GATE_VENCLT(CLK_VENCLT_CKE0, "venclt_cke0", "mm_sel", 0),
  791. GATE_VENCLT(CLK_VENCLT_CKE1, "venclt_cke1", "venclt_sel", 4),
  792. };
  793. static struct clk_onecell_data *mt8173_top_clk_data __initdata;
  794. static struct clk_onecell_data *mt8173_pll_clk_data __initdata;
  795. static void __init mtk_clk_enable_critical(void)
  796. {
  797. if (!mt8173_top_clk_data || !mt8173_pll_clk_data)
  798. return;
  799. clk_prepare_enable(mt8173_pll_clk_data->clks[CLK_APMIXED_ARMCA15PLL]);
  800. clk_prepare_enable(mt8173_pll_clk_data->clks[CLK_APMIXED_ARMCA7PLL]);
  801. clk_prepare_enable(mt8173_top_clk_data->clks[CLK_TOP_MEM_SEL]);
  802. clk_prepare_enable(mt8173_top_clk_data->clks[CLK_TOP_DDRPHYCFG_SEL]);
  803. clk_prepare_enable(mt8173_top_clk_data->clks[CLK_TOP_CCI400_SEL]);
  804. clk_prepare_enable(mt8173_top_clk_data->clks[CLK_TOP_RTC_SEL]);
  805. }
  806. static void __init mtk_topckgen_init(struct device_node *node)
  807. {
  808. struct clk_onecell_data *clk_data;
  809. void __iomem *base;
  810. int r;
  811. base = of_iomap(node, 0);
  812. if (!base) {
  813. pr_err("%s(): ioremap failed\n", __func__);
  814. return;
  815. }
  816. mt8173_top_clk_data = clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
  817. mtk_clk_register_fixed_clks(fixed_clks, ARRAY_SIZE(fixed_clks), clk_data);
  818. mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
  819. mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
  820. &mt8173_clk_lock, clk_data);
  821. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  822. if (r)
  823. pr_err("%s(): could not register clock provider: %d\n",
  824. __func__, r);
  825. mtk_clk_enable_critical();
  826. }
  827. CLK_OF_DECLARE(mtk_topckgen, "mediatek,mt8173-topckgen", mtk_topckgen_init);
  828. static void __init mtk_infrasys_init(struct device_node *node)
  829. {
  830. struct clk_onecell_data *clk_data;
  831. int r;
  832. clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
  833. mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
  834. clk_data);
  835. mtk_clk_register_factors(infra_divs, ARRAY_SIZE(infra_divs), clk_data);
  836. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  837. if (r)
  838. pr_err("%s(): could not register clock provider: %d\n",
  839. __func__, r);
  840. mtk_register_reset_controller(node, 2, 0x30);
  841. }
  842. CLK_OF_DECLARE(mtk_infrasys, "mediatek,mt8173-infracfg", mtk_infrasys_init);
  843. static void __init mtk_pericfg_init(struct device_node *node)
  844. {
  845. struct clk_onecell_data *clk_data;
  846. int r;
  847. void __iomem *base;
  848. base = of_iomap(node, 0);
  849. if (!base) {
  850. pr_err("%s(): ioremap failed\n", __func__);
  851. return;
  852. }
  853. clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
  854. mtk_clk_register_gates(node, peri_gates, ARRAY_SIZE(peri_gates),
  855. clk_data);
  856. mtk_clk_register_composites(peri_clks, ARRAY_SIZE(peri_clks), base,
  857. &mt8173_clk_lock, clk_data);
  858. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  859. if (r)
  860. pr_err("%s(): could not register clock provider: %d\n",
  861. __func__, r);
  862. mtk_register_reset_controller(node, 2, 0);
  863. }
  864. CLK_OF_DECLARE(mtk_pericfg, "mediatek,mt8173-pericfg", mtk_pericfg_init);
  865. struct mtk_clk_usb {
  866. int id;
  867. const char *name;
  868. const char *parent;
  869. u32 reg_ofs;
  870. };
  871. #define APMIXED_USB(_id, _name, _parent, _reg_ofs) { \
  872. .id = _id, \
  873. .name = _name, \
  874. .parent = _parent, \
  875. .reg_ofs = _reg_ofs, \
  876. }
  877. static const struct mtk_clk_usb apmixed_usb[] __initconst = {
  878. APMIXED_USB(CLK_APMIXED_REF2USB_TX, "ref2usb_tx", "clk26m", 0x8),
  879. };
  880. #define MT8173_PLL_FMAX (3000UL * MHZ)
  881. #define CON0_MT8173_RST_BAR BIT(24)
  882. #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  883. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  884. _pcw_shift, _div_table) { \
  885. .id = _id, \
  886. .name = _name, \
  887. .reg = _reg, \
  888. .pwr_reg = _pwr_reg, \
  889. .en_mask = _en_mask, \
  890. .flags = _flags, \
  891. .rst_bar_mask = CON0_MT8173_RST_BAR, \
  892. .fmax = MT8173_PLL_FMAX, \
  893. .pcwbits = _pcwbits, \
  894. .pd_reg = _pd_reg, \
  895. .pd_shift = _pd_shift, \
  896. .tuner_reg = _tuner_reg, \
  897. .pcw_reg = _pcw_reg, \
  898. .pcw_shift = _pcw_shift, \
  899. .div_table = _div_table, \
  900. }
  901. #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  902. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
  903. _pcw_shift) \
  904. PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
  905. _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
  906. NULL)
  907. static const struct mtk_pll_div_table mmpll_div_table[] = {
  908. { .div = 0, .freq = MT8173_PLL_FMAX },
  909. { .div = 1, .freq = 1000000000 },
  910. { .div = 2, .freq = 702000000 },
  911. { .div = 3, .freq = 253500000 },
  912. { .div = 4, .freq = 126750000 },
  913. { } /* sentinel */
  914. };
  915. static const struct mtk_pll_data plls[] = {
  916. PLL(CLK_APMIXED_ARMCA15PLL, "armca15pll", 0x200, 0x20c, 0x00000001, 0, 21, 0x204, 24, 0x0, 0x204, 0),
  917. PLL(CLK_APMIXED_ARMCA7PLL, "armca7pll", 0x210, 0x21c, 0x00000001, 0, 21, 0x214, 24, 0x0, 0x214, 0),
  918. PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x220, 0x22c, 0xf0000101, HAVE_RST_BAR, 21, 0x220, 4, 0x0, 0x224, 0),
  919. PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x230, 0x23c, 0xfe000001, HAVE_RST_BAR, 7, 0x230, 4, 0x0, 0x234, 14),
  920. PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x240, 0x24c, 0x00000001, 0, 21, 0x244, 24, 0x0, 0x244, 0, mmpll_div_table),
  921. PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x250, 0x25c, 0x00000001, 0, 21, 0x250, 4, 0x0, 0x254, 0),
  922. PLL(CLK_APMIXED_VENCPLL, "vencpll", 0x260, 0x26c, 0x00000001, 0, 21, 0x260, 4, 0x0, 0x264, 0),
  923. PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x270, 0x27c, 0x00000001, 0, 21, 0x270, 4, 0x0, 0x274, 0),
  924. PLL(CLK_APMIXED_MPLL, "mpll", 0x280, 0x28c, 0x00000001, 0, 21, 0x280, 4, 0x0, 0x284, 0),
  925. PLL(CLK_APMIXED_VCODECPLL, "vcodecpll", 0x290, 0x29c, 0x00000001, 0, 21, 0x290, 4, 0x0, 0x294, 0),
  926. PLL(CLK_APMIXED_APLL1, "apll1", 0x2a0, 0x2b0, 0x00000001, 0, 31, 0x2a0, 4, 0x2a4, 0x2a4, 0),
  927. PLL(CLK_APMIXED_APLL2, "apll2", 0x2b4, 0x2c4, 0x00000001, 0, 31, 0x2b4, 4, 0x2b8, 0x2b8, 0),
  928. PLL(CLK_APMIXED_LVDSPLL, "lvdspll", 0x2d0, 0x2dc, 0x00000001, 0, 21, 0x2d0, 4, 0x0, 0x2d4, 0),
  929. PLL(CLK_APMIXED_MSDCPLL2, "msdcpll2", 0x2f0, 0x2fc, 0x00000001, 0, 21, 0x2f0, 4, 0x0, 0x2f4, 0),
  930. };
  931. static void __init mtk_apmixedsys_init(struct device_node *node)
  932. {
  933. struct clk_onecell_data *clk_data;
  934. void __iomem *base;
  935. struct clk *clk;
  936. int r, i;
  937. base = of_iomap(node, 0);
  938. if (!base) {
  939. pr_err("%s(): ioremap failed\n", __func__);
  940. return;
  941. }
  942. mt8173_pll_clk_data = clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
  943. if (!clk_data)
  944. return;
  945. mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
  946. for (i = 0; i < ARRAY_SIZE(apmixed_usb); i++) {
  947. const struct mtk_clk_usb *cku = &apmixed_usb[i];
  948. clk = mtk_clk_register_ref2usb_tx(cku->name, cku->parent,
  949. base + cku->reg_ofs);
  950. if (IS_ERR(clk)) {
  951. pr_err("Failed to register clk %s: %ld\n", cku->name,
  952. PTR_ERR(clk));
  953. continue;
  954. }
  955. clk_data->clks[cku->id] = clk;
  956. }
  957. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  958. if (r)
  959. pr_err("%s(): could not register clock provider: %d\n",
  960. __func__, r);
  961. mtk_clk_enable_critical();
  962. }
  963. CLK_OF_DECLARE(mtk_apmixedsys, "mediatek,mt8173-apmixedsys",
  964. mtk_apmixedsys_init);
  965. static void __init mtk_imgsys_init(struct device_node *node)
  966. {
  967. struct clk_onecell_data *clk_data;
  968. int r;
  969. clk_data = mtk_alloc_clk_data(CLK_IMG_NR_CLK);
  970. mtk_clk_register_gates(node, img_clks, ARRAY_SIZE(img_clks),
  971. clk_data);
  972. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  973. if (r)
  974. pr_err("%s(): could not register clock provider: %d\n",
  975. __func__, r);
  976. }
  977. CLK_OF_DECLARE(mtk_imgsys, "mediatek,mt8173-imgsys", mtk_imgsys_init);
  978. static void __init mtk_mmsys_init(struct device_node *node)
  979. {
  980. struct clk_onecell_data *clk_data;
  981. int r;
  982. clk_data = mtk_alloc_clk_data(CLK_MM_NR_CLK);
  983. mtk_clk_register_gates(node, mm_clks, ARRAY_SIZE(mm_clks),
  984. clk_data);
  985. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  986. if (r)
  987. pr_err("%s(): could not register clock provider: %d\n",
  988. __func__, r);
  989. }
  990. CLK_OF_DECLARE(mtk_mmsys, "mediatek,mt8173-mmsys", mtk_mmsys_init);
  991. static void __init mtk_vdecsys_init(struct device_node *node)
  992. {
  993. struct clk_onecell_data *clk_data;
  994. int r;
  995. clk_data = mtk_alloc_clk_data(CLK_VDEC_NR_CLK);
  996. mtk_clk_register_gates(node, vdec_clks, ARRAY_SIZE(vdec_clks),
  997. clk_data);
  998. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  999. if (r)
  1000. pr_err("%s(): could not register clock provider: %d\n",
  1001. __func__, r);
  1002. }
  1003. CLK_OF_DECLARE(mtk_vdecsys, "mediatek,mt8173-vdecsys", mtk_vdecsys_init);
  1004. static void __init mtk_vencsys_init(struct device_node *node)
  1005. {
  1006. struct clk_onecell_data *clk_data;
  1007. int r;
  1008. clk_data = mtk_alloc_clk_data(CLK_VENC_NR_CLK);
  1009. mtk_clk_register_gates(node, venc_clks, ARRAY_SIZE(venc_clks),
  1010. clk_data);
  1011. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  1012. if (r)
  1013. pr_err("%s(): could not register clock provider: %d\n",
  1014. __func__, r);
  1015. }
  1016. CLK_OF_DECLARE(mtk_vencsys, "mediatek,mt8173-vencsys", mtk_vencsys_init);
  1017. static void __init mtk_vencltsys_init(struct device_node *node)
  1018. {
  1019. struct clk_onecell_data *clk_data;
  1020. int r;
  1021. clk_data = mtk_alloc_clk_data(CLK_VENCLT_NR_CLK);
  1022. mtk_clk_register_gates(node, venclt_clks, ARRAY_SIZE(venclt_clks),
  1023. clk_data);
  1024. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  1025. if (r)
  1026. pr_err("%s(): could not register clock provider: %d\n",
  1027. __func__, r);
  1028. }
  1029. CLK_OF_DECLARE(mtk_vencltsys, "mediatek,mt8173-vencltsys", mtk_vencltsys_init);