clk-zx296702.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. /*
  2. * Copyright 2014 Linaro Ltd.
  3. * Copyright (C) 2014 ZTE Corporation.
  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. #include <linux/clk-provider.h>
  10. #include <linux/of_address.h>
  11. #include <dt-bindings/clock/zx296702-clock.h>
  12. #include "clk.h"
  13. static DEFINE_SPINLOCK(reg_lock);
  14. static void __iomem *topcrm_base;
  15. static void __iomem *lsp0crpm_base;
  16. static void __iomem *lsp1crpm_base;
  17. static struct clk *topclk[ZX296702_TOPCLK_END];
  18. static struct clk *lsp0clk[ZX296702_LSP0CLK_END];
  19. static struct clk *lsp1clk[ZX296702_LSP1CLK_END];
  20. static struct clk_onecell_data topclk_data;
  21. static struct clk_onecell_data lsp0clk_data;
  22. static struct clk_onecell_data lsp1clk_data;
  23. #define CLK_MUX (topcrm_base + 0x04)
  24. #define CLK_DIV (topcrm_base + 0x08)
  25. #define CLK_EN0 (topcrm_base + 0x0c)
  26. #define CLK_EN1 (topcrm_base + 0x10)
  27. #define VOU_LOCAL_CLKEN (topcrm_base + 0x68)
  28. #define VOU_LOCAL_CLKSEL (topcrm_base + 0x70)
  29. #define VOU_LOCAL_DIV2_SET (topcrm_base + 0x74)
  30. #define CLK_MUX1 (topcrm_base + 0x8c)
  31. #define CLK_SDMMC1 (lsp0crpm_base + 0x0c)
  32. #define CLK_GPIO (lsp0crpm_base + 0x2c)
  33. #define CLK_SPDIF0 (lsp0crpm_base + 0x10)
  34. #define SPDIF0_DIV (lsp0crpm_base + 0x14)
  35. #define CLK_I2S0 (lsp0crpm_base + 0x18)
  36. #define I2S0_DIV (lsp0crpm_base + 0x1c)
  37. #define CLK_I2S1 (lsp0crpm_base + 0x20)
  38. #define I2S1_DIV (lsp0crpm_base + 0x24)
  39. #define CLK_I2S2 (lsp0crpm_base + 0x34)
  40. #define I2S2_DIV (lsp0crpm_base + 0x38)
  41. #define CLK_UART0 (lsp1crpm_base + 0x20)
  42. #define CLK_UART1 (lsp1crpm_base + 0x24)
  43. #define CLK_SDMMC0 (lsp1crpm_base + 0x2c)
  44. #define CLK_SPDIF1 (lsp1crpm_base + 0x30)
  45. #define SPDIF1_DIV (lsp1crpm_base + 0x34)
  46. static const struct zx_pll_config pll_a9_config[] = {
  47. { .rate = 700000000, .cfg0 = 0x800405d1, .cfg1 = 0x04555555 },
  48. { .rate = 800000000, .cfg0 = 0x80040691, .cfg1 = 0x04aaaaaa },
  49. { .rate = 900000000, .cfg0 = 0x80040791, .cfg1 = 0x04000000 },
  50. { .rate = 1000000000, .cfg0 = 0x80040851, .cfg1 = 0x04555555 },
  51. { .rate = 1100000000, .cfg0 = 0x80040911, .cfg1 = 0x04aaaaaa },
  52. { .rate = 1200000000, .cfg0 = 0x80040a11, .cfg1 = 0x04000000 },
  53. };
  54. static const struct clk_div_table main_hlk_div[] = {
  55. { .val = 1, .div = 2, },
  56. { .val = 3, .div = 4, },
  57. { /* sentinel */ }
  58. };
  59. static const struct clk_div_table a9_as1_aclk_divider[] = {
  60. { .val = 0, .div = 1, },
  61. { .val = 1, .div = 2, },
  62. { .val = 3, .div = 4, },
  63. { /* sentinel */ }
  64. };
  65. static const struct clk_div_table sec_wclk_divider[] = {
  66. { .val = 0, .div = 1, },
  67. { .val = 1, .div = 2, },
  68. { .val = 3, .div = 4, },
  69. { .val = 5, .div = 6, },
  70. { .val = 7, .div = 8, },
  71. { /* sentinel */ }
  72. };
  73. static const char * const matrix_aclk_sel[] = {
  74. "pll_mm0_198M",
  75. "osc",
  76. "clk_148M5",
  77. "pll_lsp_104M",
  78. };
  79. static const char * const a9_wclk_sel[] = {
  80. "pll_a9",
  81. "osc",
  82. "clk_500",
  83. "clk_250",
  84. };
  85. static const char * const a9_as1_aclk_sel[] = {
  86. "clk_250",
  87. "osc",
  88. "pll_mm0_396M",
  89. "pll_mac_333M",
  90. };
  91. static const char * const a9_trace_clkin_sel[] = {
  92. "clk_74M25",
  93. "pll_mm1_108M",
  94. "clk_125",
  95. "clk_148M5",
  96. };
  97. static const char * const decppu_aclk_sel[] = {
  98. "clk_250",
  99. "pll_mm0_198M",
  100. "pll_lsp_104M",
  101. "pll_audio_294M912",
  102. };
  103. static const char * const vou_main_wclk_sel[] = {
  104. "clk_148M5",
  105. "clk_74M25",
  106. "clk_27",
  107. "pll_mm1_54M",
  108. };
  109. static const char * const vou_scaler_wclk_sel[] = {
  110. "clk_250",
  111. "pll_mac_333M",
  112. "pll_audio_294M912",
  113. "pll_mm0_198M",
  114. };
  115. static const char * const r2d_wclk_sel[] = {
  116. "pll_audio_294M912",
  117. "pll_mac_333M",
  118. "pll_a9_350M",
  119. "pll_mm0_396M",
  120. };
  121. static const char * const ddr_wclk_sel[] = {
  122. "pll_mac_333M",
  123. "pll_ddr_266M",
  124. "pll_audio_294M912",
  125. "pll_mm0_198M",
  126. };
  127. static const char * const nand_wclk_sel[] = {
  128. "pll_lsp_104M",
  129. "osc",
  130. };
  131. static const char * const lsp_26_wclk_sel[] = {
  132. "pll_lsp_26M",
  133. "osc",
  134. };
  135. static const char * const vl0_sel[] = {
  136. "vou_main_channel_div",
  137. "vou_aux_channel_div",
  138. };
  139. static const char * const hdmi_sel[] = {
  140. "vou_main_channel_wclk",
  141. "vou_aux_channel_wclk",
  142. };
  143. static const char * const sdmmc0_wclk_sel[] = {
  144. "lsp1_104M_wclk",
  145. "lsp1_26M_wclk",
  146. };
  147. static const char * const sdmmc1_wclk_sel[] = {
  148. "lsp0_104M_wclk",
  149. "lsp0_26M_wclk",
  150. };
  151. static const char * const uart_wclk_sel[] = {
  152. "lsp1_104M_wclk",
  153. "lsp1_26M_wclk",
  154. };
  155. static const char * const spdif0_wclk_sel[] = {
  156. "lsp0_104M_wclk",
  157. "lsp0_26M_wclk",
  158. };
  159. static const char * const spdif1_wclk_sel[] = {
  160. "lsp1_104M_wclk",
  161. "lsp1_26M_wclk",
  162. };
  163. static const char * const i2s_wclk_sel[] = {
  164. "lsp0_104M_wclk",
  165. "lsp0_26M_wclk",
  166. };
  167. static inline struct clk *zx_divtbl(const char *name, const char *parent,
  168. void __iomem *reg, u8 shift, u8 width,
  169. const struct clk_div_table *table)
  170. {
  171. return clk_register_divider_table(NULL, name, parent, 0, reg, shift,
  172. width, 0, table, &reg_lock);
  173. }
  174. static inline struct clk *zx_div(const char *name, const char *parent,
  175. void __iomem *reg, u8 shift, u8 width)
  176. {
  177. return clk_register_divider(NULL, name, parent, 0,
  178. reg, shift, width, 0, &reg_lock);
  179. }
  180. static inline struct clk *zx_mux(const char *name, const char * const *parents,
  181. int num_parents, void __iomem *reg, u8 shift, u8 width)
  182. {
  183. return clk_register_mux(NULL, name, parents, num_parents,
  184. 0, reg, shift, width, 0, &reg_lock);
  185. }
  186. static inline struct clk *zx_gate(const char *name, const char *parent,
  187. void __iomem *reg, u8 shift)
  188. {
  189. return clk_register_gate(NULL, name, parent, CLK_IGNORE_UNUSED,
  190. reg, shift, CLK_SET_RATE_PARENT, &reg_lock);
  191. }
  192. static void __init zx296702_top_clocks_init(struct device_node *np)
  193. {
  194. struct clk **clk = topclk;
  195. int i;
  196. topcrm_base = of_iomap(np, 0);
  197. WARN_ON(!topcrm_base);
  198. clk[ZX296702_OSC] =
  199. clk_register_fixed_rate(NULL, "osc", NULL, 0, 30000000);
  200. clk[ZX296702_PLL_A9] =
  201. clk_register_zx_pll("pll_a9", "osc", 0, topcrm_base
  202. + 0x01c, pll_a9_config,
  203. ARRAY_SIZE(pll_a9_config), &reg_lock);
  204. /* TODO: pll_a9_350M look like changeble follow a9 pll */
  205. clk[ZX296702_PLL_A9_350M] =
  206. clk_register_fixed_rate(NULL, "pll_a9_350M", "osc", 0,
  207. 350000000);
  208. clk[ZX296702_PLL_MAC_1000M] =
  209. clk_register_fixed_rate(NULL, "pll_mac_1000M", "osc", 0,
  210. 1000000000);
  211. clk[ZX296702_PLL_MAC_333M] =
  212. clk_register_fixed_rate(NULL, "pll_mac_333M", "osc", 0,
  213. 333000000);
  214. clk[ZX296702_PLL_MM0_1188M] =
  215. clk_register_fixed_rate(NULL, "pll_mm0_1188M", "osc", 0,
  216. 1188000000);
  217. clk[ZX296702_PLL_MM0_396M] =
  218. clk_register_fixed_rate(NULL, "pll_mm0_396M", "osc", 0,
  219. 396000000);
  220. clk[ZX296702_PLL_MM0_198M] =
  221. clk_register_fixed_rate(NULL, "pll_mm0_198M", "osc", 0,
  222. 198000000);
  223. clk[ZX296702_PLL_MM1_108M] =
  224. clk_register_fixed_rate(NULL, "pll_mm1_108M", "osc", 0,
  225. 108000000);
  226. clk[ZX296702_PLL_MM1_72M] =
  227. clk_register_fixed_rate(NULL, "pll_mm1_72M", "osc", 0,
  228. 72000000);
  229. clk[ZX296702_PLL_MM1_54M] =
  230. clk_register_fixed_rate(NULL, "pll_mm1_54M", "osc", 0,
  231. 54000000);
  232. clk[ZX296702_PLL_LSP_104M] =
  233. clk_register_fixed_rate(NULL, "pll_lsp_104M", "osc", 0,
  234. 104000000);
  235. clk[ZX296702_PLL_LSP_26M] =
  236. clk_register_fixed_rate(NULL, "pll_lsp_26M", "osc", 0,
  237. 26000000);
  238. clk[ZX296702_PLL_DDR_266M] =
  239. clk_register_fixed_rate(NULL, "pll_ddr_266M", "osc", 0,
  240. 266000000);
  241. clk[ZX296702_PLL_AUDIO_294M912] =
  242. clk_register_fixed_rate(NULL, "pll_audio_294M912", "osc", 0,
  243. 294912000);
  244. /* bus clock */
  245. clk[ZX296702_MATRIX_ACLK] =
  246. zx_mux("matrix_aclk", matrix_aclk_sel,
  247. ARRAY_SIZE(matrix_aclk_sel), CLK_MUX, 2, 2);
  248. clk[ZX296702_MAIN_HCLK] =
  249. zx_divtbl("main_hclk", "matrix_aclk", CLK_DIV, 0, 2,
  250. main_hlk_div);
  251. clk[ZX296702_MAIN_PCLK] =
  252. zx_divtbl("main_pclk", "matrix_aclk", CLK_DIV, 2, 2,
  253. main_hlk_div);
  254. /* cpu clock */
  255. clk[ZX296702_CLK_500] =
  256. clk_register_fixed_factor(NULL, "clk_500", "pll_mac_1000M", 0,
  257. 1, 2);
  258. clk[ZX296702_CLK_250] =
  259. clk_register_fixed_factor(NULL, "clk_250", "pll_mac_1000M", 0,
  260. 1, 4);
  261. clk[ZX296702_CLK_125] =
  262. clk_register_fixed_factor(NULL, "clk_125", "clk_250", 0, 1, 2);
  263. clk[ZX296702_CLK_148M5] =
  264. clk_register_fixed_factor(NULL, "clk_148M5", "pll_mm0_1188M", 0,
  265. 1, 8);
  266. clk[ZX296702_CLK_74M25] =
  267. clk_register_fixed_factor(NULL, "clk_74M25", "pll_mm0_1188M", 0,
  268. 1, 16);
  269. clk[ZX296702_A9_WCLK] =
  270. zx_mux("a9_wclk", a9_wclk_sel, ARRAY_SIZE(a9_wclk_sel), CLK_MUX,
  271. 0, 2);
  272. clk[ZX296702_A9_AS1_ACLK_MUX] =
  273. zx_mux("a9_as1_aclk_mux", a9_as1_aclk_sel,
  274. ARRAY_SIZE(a9_as1_aclk_sel), CLK_MUX, 4, 2);
  275. clk[ZX296702_A9_TRACE_CLKIN_MUX] =
  276. zx_mux("a9_trace_clkin_mux", a9_trace_clkin_sel,
  277. ARRAY_SIZE(a9_trace_clkin_sel), CLK_MUX1, 0, 2);
  278. clk[ZX296702_A9_AS1_ACLK_DIV] =
  279. zx_divtbl("a9_as1_aclk_div", "a9_as1_aclk_mux", CLK_DIV, 4, 2,
  280. a9_as1_aclk_divider);
  281. /* multi-media clock */
  282. clk[ZX296702_CLK_2] =
  283. clk_register_fixed_factor(NULL, "clk_2", "pll_mm1_72M", 0,
  284. 1, 36);
  285. clk[ZX296702_CLK_27] =
  286. clk_register_fixed_factor(NULL, "clk_27", "pll_mm1_54M", 0,
  287. 1, 2);
  288. clk[ZX296702_DECPPU_ACLK_MUX] =
  289. zx_mux("decppu_aclk_mux", decppu_aclk_sel,
  290. ARRAY_SIZE(decppu_aclk_sel), CLK_MUX, 6, 2);
  291. clk[ZX296702_PPU_ACLK_MUX] =
  292. zx_mux("ppu_aclk_mux", decppu_aclk_sel,
  293. ARRAY_SIZE(decppu_aclk_sel), CLK_MUX, 8, 2);
  294. clk[ZX296702_MALI400_ACLK_MUX] =
  295. zx_mux("mali400_aclk_mux", decppu_aclk_sel,
  296. ARRAY_SIZE(decppu_aclk_sel), CLK_MUX, 12, 2);
  297. clk[ZX296702_VOU_ACLK_MUX] =
  298. zx_mux("vou_aclk_mux", decppu_aclk_sel,
  299. ARRAY_SIZE(decppu_aclk_sel), CLK_MUX, 10, 2);
  300. clk[ZX296702_VOU_MAIN_WCLK_MUX] =
  301. zx_mux("vou_main_wclk_mux", vou_main_wclk_sel,
  302. ARRAY_SIZE(vou_main_wclk_sel), CLK_MUX, 14, 2);
  303. clk[ZX296702_VOU_AUX_WCLK_MUX] =
  304. zx_mux("vou_aux_wclk_mux", vou_main_wclk_sel,
  305. ARRAY_SIZE(vou_main_wclk_sel), CLK_MUX, 16, 2);
  306. clk[ZX296702_VOU_SCALER_WCLK_MUX] =
  307. zx_mux("vou_scaler_wclk_mux", vou_scaler_wclk_sel,
  308. ARRAY_SIZE(vou_scaler_wclk_sel), CLK_MUX,
  309. 18, 2);
  310. clk[ZX296702_R2D_ACLK_MUX] =
  311. zx_mux("r2d_aclk_mux", decppu_aclk_sel,
  312. ARRAY_SIZE(decppu_aclk_sel), CLK_MUX, 20, 2);
  313. clk[ZX296702_R2D_WCLK_MUX] =
  314. zx_mux("r2d_wclk_mux", r2d_wclk_sel,
  315. ARRAY_SIZE(r2d_wclk_sel), CLK_MUX, 22, 2);
  316. /* other clock */
  317. clk[ZX296702_CLK_50] =
  318. clk_register_fixed_factor(NULL, "clk_50", "pll_mac_1000M",
  319. 0, 1, 20);
  320. clk[ZX296702_CLK_25] =
  321. clk_register_fixed_factor(NULL, "clk_25", "pll_mac_1000M",
  322. 0, 1, 40);
  323. clk[ZX296702_CLK_12] =
  324. clk_register_fixed_factor(NULL, "clk_12", "pll_mm1_72M",
  325. 0, 1, 6);
  326. clk[ZX296702_CLK_16M384] =
  327. clk_register_fixed_factor(NULL, "clk_16M384",
  328. "pll_audio_294M912", 0, 1, 18);
  329. clk[ZX296702_CLK_32K768] =
  330. clk_register_fixed_factor(NULL, "clk_32K768", "clk_16M384",
  331. 0, 1, 500);
  332. clk[ZX296702_SEC_WCLK_DIV] =
  333. zx_divtbl("sec_wclk_div", "pll_lsp_104M", CLK_DIV, 6, 3,
  334. sec_wclk_divider);
  335. clk[ZX296702_DDR_WCLK_MUX] =
  336. zx_mux("ddr_wclk_mux", ddr_wclk_sel,
  337. ARRAY_SIZE(ddr_wclk_sel), CLK_MUX, 24, 2);
  338. clk[ZX296702_NAND_WCLK_MUX] =
  339. zx_mux("nand_wclk_mux", nand_wclk_sel,
  340. ARRAY_SIZE(nand_wclk_sel), CLK_MUX, 24, 2);
  341. clk[ZX296702_LSP_26_WCLK_MUX] =
  342. zx_mux("lsp_26_wclk_mux", lsp_26_wclk_sel,
  343. ARRAY_SIZE(lsp_26_wclk_sel), CLK_MUX, 27, 1);
  344. /* gates */
  345. clk[ZX296702_A9_AS0_ACLK] =
  346. zx_gate("a9_as0_aclk", "matrix_aclk", CLK_EN0, 0);
  347. clk[ZX296702_A9_AS1_ACLK] =
  348. zx_gate("a9_as1_aclk", "a9_as1_aclk_div", CLK_EN0, 1);
  349. clk[ZX296702_A9_TRACE_CLKIN] =
  350. zx_gate("a9_trace_clkin", "a9_trace_clkin_mux", CLK_EN0, 2);
  351. clk[ZX296702_DECPPU_AXI_M_ACLK] =
  352. zx_gate("decppu_axi_m_aclk", "decppu_aclk_mux", CLK_EN0, 3);
  353. clk[ZX296702_DECPPU_AHB_S_HCLK] =
  354. zx_gate("decppu_ahb_s_hclk", "main_hclk", CLK_EN0, 4);
  355. clk[ZX296702_PPU_AXI_M_ACLK] =
  356. zx_gate("ppu_axi_m_aclk", "ppu_aclk_mux", CLK_EN0, 5);
  357. clk[ZX296702_PPU_AHB_S_HCLK] =
  358. zx_gate("ppu_ahb_s_hclk", "main_hclk", CLK_EN0, 6);
  359. clk[ZX296702_VOU_AXI_M_ACLK] =
  360. zx_gate("vou_axi_m_aclk", "vou_aclk_mux", CLK_EN0, 7);
  361. clk[ZX296702_VOU_APB_PCLK] =
  362. zx_gate("vou_apb_pclk", "main_pclk", CLK_EN0, 8);
  363. clk[ZX296702_VOU_MAIN_CHANNEL_WCLK] =
  364. zx_gate("vou_main_channel_wclk", "vou_main_wclk_mux",
  365. CLK_EN0, 9);
  366. clk[ZX296702_VOU_AUX_CHANNEL_WCLK] =
  367. zx_gate("vou_aux_channel_wclk", "vou_aux_wclk_mux",
  368. CLK_EN0, 10);
  369. clk[ZX296702_VOU_HDMI_OSCLK_CEC] =
  370. zx_gate("vou_hdmi_osclk_cec", "clk_2", CLK_EN0, 11);
  371. clk[ZX296702_VOU_SCALER_WCLK] =
  372. zx_gate("vou_scaler_wclk", "vou_scaler_wclk_mux", CLK_EN0, 12);
  373. clk[ZX296702_MALI400_AXI_M_ACLK] =
  374. zx_gate("mali400_axi_m_aclk", "mali400_aclk_mux", CLK_EN0, 13);
  375. clk[ZX296702_MALI400_APB_PCLK] =
  376. zx_gate("mali400_apb_pclk", "main_pclk", CLK_EN0, 14);
  377. clk[ZX296702_R2D_WCLK] =
  378. zx_gate("r2d_wclk", "r2d_wclk_mux", CLK_EN0, 15);
  379. clk[ZX296702_R2D_AXI_M_ACLK] =
  380. zx_gate("r2d_axi_m_aclk", "r2d_aclk_mux", CLK_EN0, 16);
  381. clk[ZX296702_R2D_AHB_HCLK] =
  382. zx_gate("r2d_ahb_hclk", "main_hclk", CLK_EN0, 17);
  383. clk[ZX296702_DDR3_AXI_S0_ACLK] =
  384. zx_gate("ddr3_axi_s0_aclk", "matrix_aclk", CLK_EN0, 18);
  385. clk[ZX296702_DDR3_APB_PCLK] =
  386. zx_gate("ddr3_apb_pclk", "main_pclk", CLK_EN0, 19);
  387. clk[ZX296702_DDR3_WCLK] =
  388. zx_gate("ddr3_wclk", "ddr_wclk_mux", CLK_EN0, 20);
  389. clk[ZX296702_USB20_0_AHB_HCLK] =
  390. zx_gate("usb20_0_ahb_hclk", "main_hclk", CLK_EN0, 21);
  391. clk[ZX296702_USB20_0_EXTREFCLK] =
  392. zx_gate("usb20_0_extrefclk", "clk_12", CLK_EN0, 22);
  393. clk[ZX296702_USB20_1_AHB_HCLK] =
  394. zx_gate("usb20_1_ahb_hclk", "main_hclk", CLK_EN0, 23);
  395. clk[ZX296702_USB20_1_EXTREFCLK] =
  396. zx_gate("usb20_1_extrefclk", "clk_12", CLK_EN0, 24);
  397. clk[ZX296702_USB20_2_AHB_HCLK] =
  398. zx_gate("usb20_2_ahb_hclk", "main_hclk", CLK_EN0, 25);
  399. clk[ZX296702_USB20_2_EXTREFCLK] =
  400. zx_gate("usb20_2_extrefclk", "clk_12", CLK_EN0, 26);
  401. clk[ZX296702_GMAC_AXI_M_ACLK] =
  402. zx_gate("gmac_axi_m_aclk", "matrix_aclk", CLK_EN0, 27);
  403. clk[ZX296702_GMAC_APB_PCLK] =
  404. zx_gate("gmac_apb_pclk", "main_pclk", CLK_EN0, 28);
  405. clk[ZX296702_GMAC_125_CLKIN] =
  406. zx_gate("gmac_125_clkin", "clk_125", CLK_EN0, 29);
  407. clk[ZX296702_GMAC_RMII_CLKIN] =
  408. zx_gate("gmac_rmii_clkin", "clk_50", CLK_EN0, 30);
  409. clk[ZX296702_GMAC_25M_CLK] =
  410. zx_gate("gmac_25M_clk", "clk_25", CLK_EN0, 31);
  411. clk[ZX296702_NANDFLASH_AHB_HCLK] =
  412. zx_gate("nandflash_ahb_hclk", "main_hclk", CLK_EN1, 0);
  413. clk[ZX296702_NANDFLASH_WCLK] =
  414. zx_gate("nandflash_wclk", "nand_wclk_mux", CLK_EN1, 1);
  415. clk[ZX296702_LSP0_APB_PCLK] =
  416. zx_gate("lsp0_apb_pclk", "main_pclk", CLK_EN1, 2);
  417. clk[ZX296702_LSP0_AHB_HCLK] =
  418. zx_gate("lsp0_ahb_hclk", "main_hclk", CLK_EN1, 3);
  419. clk[ZX296702_LSP0_26M_WCLK] =
  420. zx_gate("lsp0_26M_wclk", "lsp_26_wclk_mux", CLK_EN1, 4);
  421. clk[ZX296702_LSP0_104M_WCLK] =
  422. zx_gate("lsp0_104M_wclk", "pll_lsp_104M", CLK_EN1, 5);
  423. clk[ZX296702_LSP0_16M384_WCLK] =
  424. zx_gate("lsp0_16M384_wclk", "clk_16M384", CLK_EN1, 6);
  425. clk[ZX296702_LSP1_APB_PCLK] =
  426. zx_gate("lsp1_apb_pclk", "main_pclk", CLK_EN1, 7);
  427. /* FIXME: wclk enable bit is bit8. We hack it as reserved 31 for
  428. * UART does not work after parent clk is disabled/enabled */
  429. clk[ZX296702_LSP1_26M_WCLK] =
  430. zx_gate("lsp1_26M_wclk", "lsp_26_wclk_mux", CLK_EN1, 31);
  431. clk[ZX296702_LSP1_104M_WCLK] =
  432. zx_gate("lsp1_104M_wclk", "pll_lsp_104M", CLK_EN1, 9);
  433. clk[ZX296702_LSP1_32K_CLK] =
  434. zx_gate("lsp1_32K_clk", "clk_32K768", CLK_EN1, 10);
  435. clk[ZX296702_AON_HCLK] =
  436. zx_gate("aon_hclk", "main_hclk", CLK_EN1, 11);
  437. clk[ZX296702_SYS_CTRL_PCLK] =
  438. zx_gate("sys_ctrl_pclk", "main_pclk", CLK_EN1, 12);
  439. clk[ZX296702_DMA_PCLK] =
  440. zx_gate("dma_pclk", "main_pclk", CLK_EN1, 13);
  441. clk[ZX296702_DMA_ACLK] =
  442. zx_gate("dma_aclk", "matrix_aclk", CLK_EN1, 14);
  443. clk[ZX296702_SEC_HCLK] =
  444. zx_gate("sec_hclk", "main_hclk", CLK_EN1, 15);
  445. clk[ZX296702_AES_WCLK] =
  446. zx_gate("aes_wclk", "sec_wclk_div", CLK_EN1, 16);
  447. clk[ZX296702_DES_WCLK] =
  448. zx_gate("des_wclk", "sec_wclk_div", CLK_EN1, 17);
  449. clk[ZX296702_IRAM_ACLK] =
  450. zx_gate("iram_aclk", "matrix_aclk", CLK_EN1, 18);
  451. clk[ZX296702_IROM_ACLK] =
  452. zx_gate("irom_aclk", "matrix_aclk", CLK_EN1, 19);
  453. clk[ZX296702_BOOT_CTRL_HCLK] =
  454. zx_gate("boot_ctrl_hclk", "main_hclk", CLK_EN1, 20);
  455. clk[ZX296702_EFUSE_CLK_30] =
  456. zx_gate("efuse_clk_30", "osc", CLK_EN1, 21);
  457. /* TODO: add VOU Local clocks */
  458. clk[ZX296702_VOU_MAIN_CHANNEL_DIV] =
  459. zx_div("vou_main_channel_div", "vou_main_channel_wclk",
  460. VOU_LOCAL_DIV2_SET, 1, 1);
  461. clk[ZX296702_VOU_AUX_CHANNEL_DIV] =
  462. zx_div("vou_aux_channel_div", "vou_aux_channel_wclk",
  463. VOU_LOCAL_DIV2_SET, 0, 1);
  464. clk[ZX296702_VOU_TV_ENC_HD_DIV] =
  465. zx_div("vou_tv_enc_hd_div", "vou_tv_enc_hd_mux",
  466. VOU_LOCAL_DIV2_SET, 3, 1);
  467. clk[ZX296702_VOU_TV_ENC_SD_DIV] =
  468. zx_div("vou_tv_enc_sd_div", "vou_tv_enc_sd_mux",
  469. VOU_LOCAL_DIV2_SET, 2, 1);
  470. clk[ZX296702_VL0_MUX] =
  471. zx_mux("vl0_mux", vl0_sel, ARRAY_SIZE(vl0_sel),
  472. VOU_LOCAL_CLKSEL, 8, 1);
  473. clk[ZX296702_VL1_MUX] =
  474. zx_mux("vl1_mux", vl0_sel, ARRAY_SIZE(vl0_sel),
  475. VOU_LOCAL_CLKSEL, 9, 1);
  476. clk[ZX296702_VL2_MUX] =
  477. zx_mux("vl2_mux", vl0_sel, ARRAY_SIZE(vl0_sel),
  478. VOU_LOCAL_CLKSEL, 10, 1);
  479. clk[ZX296702_GL0_MUX] =
  480. zx_mux("gl0_mux", vl0_sel, ARRAY_SIZE(vl0_sel),
  481. VOU_LOCAL_CLKSEL, 5, 1);
  482. clk[ZX296702_GL1_MUX] =
  483. zx_mux("gl1_mux", vl0_sel, ARRAY_SIZE(vl0_sel),
  484. VOU_LOCAL_CLKSEL, 6, 1);
  485. clk[ZX296702_GL2_MUX] =
  486. zx_mux("gl2_mux", vl0_sel, ARRAY_SIZE(vl0_sel),
  487. VOU_LOCAL_CLKSEL, 7, 1);
  488. clk[ZX296702_WB_MUX] =
  489. zx_mux("wb_mux", vl0_sel, ARRAY_SIZE(vl0_sel),
  490. VOU_LOCAL_CLKSEL, 11, 1);
  491. clk[ZX296702_HDMI_MUX] =
  492. zx_mux("hdmi_mux", hdmi_sel, ARRAY_SIZE(hdmi_sel),
  493. VOU_LOCAL_CLKSEL, 4, 1);
  494. clk[ZX296702_VOU_TV_ENC_HD_MUX] =
  495. zx_mux("vou_tv_enc_hd_mux", hdmi_sel, ARRAY_SIZE(hdmi_sel),
  496. VOU_LOCAL_CLKSEL, 3, 1);
  497. clk[ZX296702_VOU_TV_ENC_SD_MUX] =
  498. zx_mux("vou_tv_enc_sd_mux", hdmi_sel, ARRAY_SIZE(hdmi_sel),
  499. VOU_LOCAL_CLKSEL, 2, 1);
  500. clk[ZX296702_VL0_CLK] =
  501. zx_gate("vl0_clk", "vl0_mux", VOU_LOCAL_CLKEN, 8);
  502. clk[ZX296702_VL1_CLK] =
  503. zx_gate("vl1_clk", "vl1_mux", VOU_LOCAL_CLKEN, 9);
  504. clk[ZX296702_VL2_CLK] =
  505. zx_gate("vl2_clk", "vl2_mux", VOU_LOCAL_CLKEN, 10);
  506. clk[ZX296702_GL0_CLK] =
  507. zx_gate("gl0_clk", "gl0_mux", VOU_LOCAL_CLKEN, 5);
  508. clk[ZX296702_GL1_CLK] =
  509. zx_gate("gl1_clk", "gl1_mux", VOU_LOCAL_CLKEN, 6);
  510. clk[ZX296702_GL2_CLK] =
  511. zx_gate("gl2_clk", "gl2_mux", VOU_LOCAL_CLKEN, 7);
  512. clk[ZX296702_WB_CLK] =
  513. zx_gate("wb_clk", "wb_mux", VOU_LOCAL_CLKEN, 11);
  514. clk[ZX296702_CL_CLK] =
  515. zx_gate("cl_clk", "vou_main_channel_div", VOU_LOCAL_CLKEN, 12);
  516. clk[ZX296702_MAIN_MIX_CLK] =
  517. zx_gate("main_mix_clk", "vou_main_channel_div",
  518. VOU_LOCAL_CLKEN, 4);
  519. clk[ZX296702_AUX_MIX_CLK] =
  520. zx_gate("aux_mix_clk", "vou_aux_channel_div",
  521. VOU_LOCAL_CLKEN, 3);
  522. clk[ZX296702_HDMI_CLK] =
  523. zx_gate("hdmi_clk", "hdmi_mux", VOU_LOCAL_CLKEN, 2);
  524. clk[ZX296702_VOU_TV_ENC_HD_DAC_CLK] =
  525. zx_gate("vou_tv_enc_hd_dac_clk", "vou_tv_enc_hd_div",
  526. VOU_LOCAL_CLKEN, 1);
  527. clk[ZX296702_VOU_TV_ENC_SD_DAC_CLK] =
  528. zx_gate("vou_tv_enc_sd_dac_clk", "vou_tv_enc_sd_div",
  529. VOU_LOCAL_CLKEN, 0);
  530. /* CA9 PERIPHCLK = a9_wclk / 2 */
  531. clk[ZX296702_A9_PERIPHCLK] =
  532. clk_register_fixed_factor(NULL, "a9_periphclk", "a9_wclk",
  533. 0, 1, 2);
  534. for (i = 0; i < ARRAY_SIZE(topclk); i++) {
  535. if (IS_ERR(clk[i])) {
  536. pr_err("zx296702 clk %d: register failed with %ld\n",
  537. i, PTR_ERR(clk[i]));
  538. return;
  539. }
  540. }
  541. topclk_data.clks = topclk;
  542. topclk_data.clk_num = ARRAY_SIZE(topclk);
  543. of_clk_add_provider(np, of_clk_src_onecell_get, &topclk_data);
  544. }
  545. CLK_OF_DECLARE(zx296702_top_clk, "zte,zx296702-topcrm-clk",
  546. zx296702_top_clocks_init);
  547. static void __init zx296702_lsp0_clocks_init(struct device_node *np)
  548. {
  549. struct clk **clk = lsp0clk;
  550. int i;
  551. lsp0crpm_base = of_iomap(np, 0);
  552. WARN_ON(!lsp0crpm_base);
  553. /* SDMMC1 */
  554. clk[ZX296702_SDMMC1_WCLK_MUX] =
  555. zx_mux("sdmmc1_wclk_mux", sdmmc1_wclk_sel,
  556. ARRAY_SIZE(sdmmc1_wclk_sel), CLK_SDMMC1, 4, 1);
  557. clk[ZX296702_SDMMC1_WCLK_DIV] =
  558. zx_div("sdmmc1_wclk_div", "sdmmc1_wclk_mux", CLK_SDMMC1, 12, 4);
  559. clk[ZX296702_SDMMC1_WCLK] =
  560. zx_gate("sdmmc1_wclk", "sdmmc1_wclk_div", CLK_SDMMC1, 1);
  561. clk[ZX296702_SDMMC1_PCLK] =
  562. zx_gate("sdmmc1_pclk", "lsp0_apb_pclk", CLK_SDMMC1, 0);
  563. clk[ZX296702_GPIO_CLK] =
  564. zx_gate("gpio_clk", "lsp0_apb_pclk", CLK_GPIO, 0);
  565. /* SPDIF */
  566. clk[ZX296702_SPDIF0_WCLK_MUX] =
  567. zx_mux("spdif0_wclk_mux", spdif0_wclk_sel,
  568. ARRAY_SIZE(spdif0_wclk_sel), CLK_SPDIF0, 4, 1);
  569. clk[ZX296702_SPDIF0_WCLK] =
  570. zx_gate("spdif0_wclk", "spdif0_wclk_mux", CLK_SPDIF0, 1);
  571. clk[ZX296702_SPDIF0_PCLK] =
  572. zx_gate("spdif0_pclk", "lsp0_apb_pclk", CLK_SPDIF0, 0);
  573. clk[ZX296702_SPDIF0_DIV] =
  574. clk_register_zx_audio("spdif0_div", "spdif0_wclk", 0,
  575. SPDIF0_DIV);
  576. /* I2S */
  577. clk[ZX296702_I2S0_WCLK_MUX] =
  578. zx_mux("i2s0_wclk_mux", i2s_wclk_sel,
  579. ARRAY_SIZE(i2s_wclk_sel), CLK_I2S0, 4, 1);
  580. clk[ZX296702_I2S0_WCLK] =
  581. zx_gate("i2s0_wclk", "i2s0_wclk_mux", CLK_I2S0, 1);
  582. clk[ZX296702_I2S0_PCLK] =
  583. zx_gate("i2s0_pclk", "lsp0_apb_pclk", CLK_I2S0, 0);
  584. clk[ZX296702_I2S0_DIV] =
  585. clk_register_zx_audio("i2s0_div", "i2s0_wclk", 0, I2S0_DIV);
  586. clk[ZX296702_I2S1_WCLK_MUX] =
  587. zx_mux("i2s1_wclk_mux", i2s_wclk_sel,
  588. ARRAY_SIZE(i2s_wclk_sel), CLK_I2S1, 4, 1);
  589. clk[ZX296702_I2S1_WCLK] =
  590. zx_gate("i2s1_wclk", "i2s1_wclk_mux", CLK_I2S1, 1);
  591. clk[ZX296702_I2S1_PCLK] =
  592. zx_gate("i2s1_pclk", "lsp0_apb_pclk", CLK_I2S1, 0);
  593. clk[ZX296702_I2S1_DIV] =
  594. clk_register_zx_audio("i2s1_div", "i2s1_wclk", 0, I2S1_DIV);
  595. clk[ZX296702_I2S2_WCLK_MUX] =
  596. zx_mux("i2s2_wclk_mux", i2s_wclk_sel,
  597. ARRAY_SIZE(i2s_wclk_sel), CLK_I2S2, 4, 1);
  598. clk[ZX296702_I2S2_WCLK] =
  599. zx_gate("i2s2_wclk", "i2s2_wclk_mux", CLK_I2S2, 1);
  600. clk[ZX296702_I2S2_PCLK] =
  601. zx_gate("i2s2_pclk", "lsp0_apb_pclk", CLK_I2S2, 0);
  602. clk[ZX296702_I2S2_DIV] =
  603. clk_register_zx_audio("i2s2_div", "i2s2_wclk", 0, I2S2_DIV);
  604. for (i = 0; i < ARRAY_SIZE(lsp0clk); i++) {
  605. if (IS_ERR(clk[i])) {
  606. pr_err("zx296702 clk %d: register failed with %ld\n",
  607. i, PTR_ERR(clk[i]));
  608. return;
  609. }
  610. }
  611. lsp0clk_data.clks = lsp0clk;
  612. lsp0clk_data.clk_num = ARRAY_SIZE(lsp0clk);
  613. of_clk_add_provider(np, of_clk_src_onecell_get, &lsp0clk_data);
  614. }
  615. CLK_OF_DECLARE(zx296702_lsp0_clk, "zte,zx296702-lsp0crpm-clk",
  616. zx296702_lsp0_clocks_init);
  617. static void __init zx296702_lsp1_clocks_init(struct device_node *np)
  618. {
  619. struct clk **clk = lsp1clk;
  620. int i;
  621. lsp1crpm_base = of_iomap(np, 0);
  622. WARN_ON(!lsp1crpm_base);
  623. /* UART0 */
  624. clk[ZX296702_UART0_WCLK_MUX] =
  625. zx_mux("uart0_wclk_mux", uart_wclk_sel,
  626. ARRAY_SIZE(uart_wclk_sel), CLK_UART0, 4, 1);
  627. /* FIXME: uart wclk enable bit is bit1 in. We hack it as reserved 31 for
  628. * UART does not work after parent clk is disabled/enabled */
  629. clk[ZX296702_UART0_WCLK] =
  630. zx_gate("uart0_wclk", "uart0_wclk_mux", CLK_UART0, 31);
  631. clk[ZX296702_UART0_PCLK] =
  632. zx_gate("uart0_pclk", "lsp1_apb_pclk", CLK_UART0, 0);
  633. /* UART1 */
  634. clk[ZX296702_UART1_WCLK_MUX] =
  635. zx_mux("uart1_wclk_mux", uart_wclk_sel,
  636. ARRAY_SIZE(uart_wclk_sel), CLK_UART1, 4, 1);
  637. clk[ZX296702_UART1_WCLK] =
  638. zx_gate("uart1_wclk", "uart1_wclk_mux", CLK_UART1, 1);
  639. clk[ZX296702_UART1_PCLK] =
  640. zx_gate("uart1_pclk", "lsp1_apb_pclk", CLK_UART1, 0);
  641. /* SDMMC0 */
  642. clk[ZX296702_SDMMC0_WCLK_MUX] =
  643. zx_mux("sdmmc0_wclk_mux", sdmmc0_wclk_sel,
  644. ARRAY_SIZE(sdmmc0_wclk_sel), CLK_SDMMC0, 4, 1);
  645. clk[ZX296702_SDMMC0_WCLK_DIV] =
  646. zx_div("sdmmc0_wclk_div", "sdmmc0_wclk_mux", CLK_SDMMC0, 12, 4);
  647. clk[ZX296702_SDMMC0_WCLK] =
  648. zx_gate("sdmmc0_wclk", "sdmmc0_wclk_div", CLK_SDMMC0, 1);
  649. clk[ZX296702_SDMMC0_PCLK] =
  650. zx_gate("sdmmc0_pclk", "lsp1_apb_pclk", CLK_SDMMC0, 0);
  651. clk[ZX296702_SPDIF1_WCLK_MUX] =
  652. zx_mux("spdif1_wclk_mux", spdif1_wclk_sel,
  653. ARRAY_SIZE(spdif1_wclk_sel), CLK_SPDIF1, 4, 1);
  654. clk[ZX296702_SPDIF1_WCLK] =
  655. zx_gate("spdif1_wclk", "spdif1_wclk_mux", CLK_SPDIF1, 1);
  656. clk[ZX296702_SPDIF1_PCLK] =
  657. zx_gate("spdif1_pclk", "lsp1_apb_pclk", CLK_SPDIF1, 0);
  658. clk[ZX296702_SPDIF1_DIV] =
  659. clk_register_zx_audio("spdif1_div", "spdif1_wclk", 0,
  660. SPDIF1_DIV);
  661. for (i = 0; i < ARRAY_SIZE(lsp1clk); i++) {
  662. if (IS_ERR(clk[i])) {
  663. pr_err("zx296702 clk %d: register failed with %ld\n",
  664. i, PTR_ERR(clk[i]));
  665. return;
  666. }
  667. }
  668. lsp1clk_data.clks = lsp1clk;
  669. lsp1clk_data.clk_num = ARRAY_SIZE(lsp1clk);
  670. of_clk_add_provider(np, of_clk_src_onecell_get, &lsp1clk_data);
  671. }
  672. CLK_OF_DECLARE(zx296702_lsp1_clk, "zte,zx296702-lsp1crpm-clk",
  673. zx296702_lsp1_clocks_init);