ccu-sun8i-h3.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. /*
  2. * Copyright (c) 2016 Maxime Ripard. All rights reserved.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/clk-provider.h>
  14. #include <linux/of_address.h>
  15. #include "ccu_common.h"
  16. #include "ccu_reset.h"
  17. #include "ccu_div.h"
  18. #include "ccu_gate.h"
  19. #include "ccu_mp.h"
  20. #include "ccu_mult.h"
  21. #include "ccu_nk.h"
  22. #include "ccu_nkm.h"
  23. #include "ccu_nkmp.h"
  24. #include "ccu_nm.h"
  25. #include "ccu_phase.h"
  26. #include "ccu-sun8i-h3.h"
  27. static SUNXI_CCU_NKMP_WITH_GATE_LOCK(pll_cpux_clk, "pll-cpux",
  28. "osc24M", 0x000,
  29. 8, 5, /* N */
  30. 4, 2, /* K */
  31. 0, 2, /* M */
  32. 16, 2, /* P */
  33. BIT(31), /* gate */
  34. BIT(28), /* lock */
  35. 0);
  36. /*
  37. * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from
  38. * the base (2x, 4x and 8x), and one variable divider (the one true
  39. * pll audio).
  40. *
  41. * We don't have any need for the variable divider for now, so we just
  42. * hardcode it to match with the clock names
  43. */
  44. #define SUN8I_H3_PLL_AUDIO_REG 0x008
  45. static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
  46. "osc24M", 0x008,
  47. 8, 7, /* N */
  48. 0, 5, /* M */
  49. BIT(31), /* gate */
  50. BIT(28), /* lock */
  51. 0);
  52. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video_clk, "pll-video",
  53. "osc24M", 0x0010,
  54. 8, 7, /* N */
  55. 0, 4, /* M */
  56. BIT(24), /* frac enable */
  57. BIT(25), /* frac select */
  58. 270000000, /* frac rate 0 */
  59. 297000000, /* frac rate 1 */
  60. BIT(31), /* gate */
  61. BIT(28), /* lock */
  62. 0);
  63. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve",
  64. "osc24M", 0x0018,
  65. 8, 7, /* N */
  66. 0, 4, /* M */
  67. BIT(24), /* frac enable */
  68. BIT(25), /* frac select */
  69. 270000000, /* frac rate 0 */
  70. 297000000, /* frac rate 1 */
  71. BIT(31), /* gate */
  72. BIT(28), /* lock */
  73. 0);
  74. static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr_clk, "pll-ddr",
  75. "osc24M", 0x020,
  76. 8, 5, /* N */
  77. 4, 2, /* K */
  78. 0, 2, /* M */
  79. BIT(31), /* gate */
  80. BIT(28), /* lock */
  81. 0);
  82. static SUNXI_CCU_NK_WITH_GATE_LOCK_POSTDIV(pll_periph0_clk, "pll-periph0",
  83. "osc24M", 0x028,
  84. 8, 5, /* N */
  85. 4, 2, /* K */
  86. BIT(31), /* gate */
  87. BIT(28), /* lock */
  88. 2, /* post-div */
  89. 0);
  90. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_gpu_clk, "pll-gpu",
  91. "osc24M", 0x0038,
  92. 8, 7, /* N */
  93. 0, 4, /* M */
  94. BIT(24), /* frac enable */
  95. BIT(25), /* frac select */
  96. 270000000, /* frac rate 0 */
  97. 297000000, /* frac rate 1 */
  98. BIT(31), /* gate */
  99. BIT(28), /* lock */
  100. 0);
  101. static SUNXI_CCU_NK_WITH_GATE_LOCK_POSTDIV(pll_periph1_clk, "pll-periph1",
  102. "osc24M", 0x044,
  103. 8, 5, /* N */
  104. 4, 2, /* K */
  105. BIT(31), /* gate */
  106. BIT(28), /* lock */
  107. 2, /* post-div */
  108. 0);
  109. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_de_clk, "pll-de",
  110. "osc24M", 0x0048,
  111. 8, 7, /* N */
  112. 0, 4, /* M */
  113. BIT(24), /* frac enable */
  114. BIT(25), /* frac select */
  115. 270000000, /* frac rate 0 */
  116. 297000000, /* frac rate 1 */
  117. BIT(31), /* gate */
  118. BIT(28), /* lock */
  119. 0);
  120. static const char * const cpux_parents[] = { "osc32k", "osc24M",
  121. "pll-cpux" , "pll-cpux" };
  122. static SUNXI_CCU_MUX(cpux_clk, "cpux", cpux_parents,
  123. 0x050, 16, 2, CLK_IS_CRITICAL);
  124. static SUNXI_CCU_M(axi_clk, "axi", "cpux", 0x050, 0, 2, 0);
  125. static const char * const ahb1_parents[] = { "osc32k", "osc24M",
  126. "axi" , "pll-periph0" };
  127. static struct ccu_div ahb1_clk = {
  128. .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
  129. .mux = {
  130. .shift = 12,
  131. .width = 2,
  132. .variable_prediv = {
  133. .index = 3,
  134. .shift = 6,
  135. .width = 2,
  136. },
  137. },
  138. .common = {
  139. .reg = 0x054,
  140. .features = CCU_FEATURE_VARIABLE_PREDIV,
  141. .hw.init = CLK_HW_INIT_PARENTS("ahb1",
  142. ahb1_parents,
  143. &ccu_div_ops,
  144. 0),
  145. },
  146. };
  147. static struct clk_div_table apb1_div_table[] = {
  148. { .val = 0, .div = 2 },
  149. { .val = 1, .div = 2 },
  150. { .val = 2, .div = 4 },
  151. { .val = 3, .div = 8 },
  152. { /* Sentinel */ },
  153. };
  154. static SUNXI_CCU_DIV_TABLE(apb1_clk, "apb1", "ahb1",
  155. 0x054, 8, 2, apb1_div_table, 0);
  156. static const char * const apb2_parents[] = { "osc32k", "osc24M",
  157. "pll-periph0" , "pll-periph0" };
  158. static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", apb2_parents, 0x058,
  159. 0, 5, /* M */
  160. 16, 2, /* P */
  161. 24, 2, /* mux */
  162. 0);
  163. static const char * const ahb2_parents[] = { "ahb1" , "pll-periph0" };
  164. static const struct ccu_mux_fixed_prediv ahb2_fixed_predivs[] = {
  165. { .index = 1, .div = 2 },
  166. };
  167. static struct ccu_mux ahb2_clk = {
  168. .mux = {
  169. .shift = 0,
  170. .width = 1,
  171. .fixed_predivs = ahb2_fixed_predivs,
  172. .n_predivs = ARRAY_SIZE(ahb2_fixed_predivs),
  173. },
  174. .common = {
  175. .reg = 0x05c,
  176. .features = CCU_FEATURE_FIXED_PREDIV,
  177. .hw.init = CLK_HW_INIT_PARENTS("ahb2",
  178. ahb2_parents,
  179. &ccu_mux_ops,
  180. 0),
  181. },
  182. };
  183. static SUNXI_CCU_GATE(bus_ce_clk, "bus-ce", "ahb1",
  184. 0x060, BIT(5), 0);
  185. static SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "ahb1",
  186. 0x060, BIT(6), 0);
  187. static SUNXI_CCU_GATE(bus_mmc0_clk, "bus-mmc0", "ahb1",
  188. 0x060, BIT(8), 0);
  189. static SUNXI_CCU_GATE(bus_mmc1_clk, "bus-mmc1", "ahb1",
  190. 0x060, BIT(9), 0);
  191. static SUNXI_CCU_GATE(bus_mmc2_clk, "bus-mmc2", "ahb1",
  192. 0x060, BIT(10), 0);
  193. static SUNXI_CCU_GATE(bus_nand_clk, "bus-nand", "ahb1",
  194. 0x060, BIT(13), 0);
  195. static SUNXI_CCU_GATE(bus_dram_clk, "bus-dram", "ahb1",
  196. 0x060, BIT(14), 0);
  197. static SUNXI_CCU_GATE(bus_emac_clk, "bus-emac", "ahb2",
  198. 0x060, BIT(17), 0);
  199. static SUNXI_CCU_GATE(bus_ts_clk, "bus-ts", "ahb1",
  200. 0x060, BIT(18), 0);
  201. static SUNXI_CCU_GATE(bus_hstimer_clk, "bus-hstimer", "ahb1",
  202. 0x060, BIT(19), 0);
  203. static SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb1",
  204. 0x060, BIT(20), 0);
  205. static SUNXI_CCU_GATE(bus_spi1_clk, "bus-spi1", "ahb1",
  206. 0x060, BIT(21), 0);
  207. static SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb1",
  208. 0x060, BIT(23), 0);
  209. static SUNXI_CCU_GATE(bus_ehci0_clk, "bus-ehci0", "ahb1",
  210. 0x060, BIT(24), 0);
  211. static SUNXI_CCU_GATE(bus_ehci1_clk, "bus-ehci1", "ahb2",
  212. 0x060, BIT(25), 0);
  213. static SUNXI_CCU_GATE(bus_ehci2_clk, "bus-ehci2", "ahb2",
  214. 0x060, BIT(26), 0);
  215. static SUNXI_CCU_GATE(bus_ehci3_clk, "bus-ehci3", "ahb2",
  216. 0x060, BIT(27), 0);
  217. static SUNXI_CCU_GATE(bus_ohci0_clk, "bus-ohci0", "ahb1",
  218. 0x060, BIT(28), 0);
  219. static SUNXI_CCU_GATE(bus_ohci1_clk, "bus-ohci1", "ahb2",
  220. 0x060, BIT(29), 0);
  221. static SUNXI_CCU_GATE(bus_ohci2_clk, "bus-ohci2", "ahb2",
  222. 0x060, BIT(30), 0);
  223. static SUNXI_CCU_GATE(bus_ohci3_clk, "bus-ohci3", "ahb2",
  224. 0x060, BIT(31), 0);
  225. static SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "ahb1",
  226. 0x064, BIT(0), 0);
  227. static SUNXI_CCU_GATE(bus_tcon0_clk, "bus-tcon0", "ahb1",
  228. 0x064, BIT(3), 0);
  229. static SUNXI_CCU_GATE(bus_tcon1_clk, "bus-tcon1", "ahb1",
  230. 0x064, BIT(4), 0);
  231. static SUNXI_CCU_GATE(bus_deinterlace_clk, "bus-deinterlace", "ahb1",
  232. 0x064, BIT(5), 0);
  233. static SUNXI_CCU_GATE(bus_csi_clk, "bus-csi", "ahb1",
  234. 0x064, BIT(8), 0);
  235. static SUNXI_CCU_GATE(bus_tve_clk, "bus-tve", "ahb1",
  236. 0x064, BIT(9), 0);
  237. static SUNXI_CCU_GATE(bus_hdmi_clk, "bus-hdmi", "ahb1",
  238. 0x064, BIT(11), 0);
  239. static SUNXI_CCU_GATE(bus_de_clk, "bus-de", "ahb1",
  240. 0x064, BIT(12), 0);
  241. static SUNXI_CCU_GATE(bus_gpu_clk, "bus-gpu", "ahb1",
  242. 0x064, BIT(20), 0);
  243. static SUNXI_CCU_GATE(bus_msgbox_clk, "bus-msgbox", "ahb1",
  244. 0x064, BIT(21), 0);
  245. static SUNXI_CCU_GATE(bus_spinlock_clk, "bus-spinlock", "ahb1",
  246. 0x064, BIT(22), 0);
  247. static SUNXI_CCU_GATE(bus_codec_clk, "bus-codec", "apb1",
  248. 0x068, BIT(0), 0);
  249. static SUNXI_CCU_GATE(bus_spdif_clk, "bus-spdif", "apb1",
  250. 0x068, BIT(1), 0);
  251. static SUNXI_CCU_GATE(bus_pio_clk, "bus-pio", "apb1",
  252. 0x068, BIT(5), 0);
  253. static SUNXI_CCU_GATE(bus_ths_clk, "bus-ths", "apb1",
  254. 0x068, BIT(8), 0);
  255. static SUNXI_CCU_GATE(bus_i2s0_clk, "bus-i2s0", "apb1",
  256. 0x068, BIT(12), 0);
  257. static SUNXI_CCU_GATE(bus_i2s1_clk, "bus-i2s1", "apb1",
  258. 0x068, BIT(13), 0);
  259. static SUNXI_CCU_GATE(bus_i2s2_clk, "bus-i2s2", "apb1",
  260. 0x068, BIT(14), 0);
  261. static SUNXI_CCU_GATE(bus_i2c0_clk, "bus-i2c0", "apb2",
  262. 0x06c, BIT(0), 0);
  263. static SUNXI_CCU_GATE(bus_i2c1_clk, "bus-i2c1", "apb2",
  264. 0x06c, BIT(1), 0);
  265. static SUNXI_CCU_GATE(bus_i2c2_clk, "bus-i2c2", "apb2",
  266. 0x06c, BIT(2), 0);
  267. static SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb2",
  268. 0x06c, BIT(16), 0);
  269. static SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb2",
  270. 0x06c, BIT(17), 0);
  271. static SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb2",
  272. 0x06c, BIT(18), 0);
  273. static SUNXI_CCU_GATE(bus_uart3_clk, "bus-uart3", "apb2",
  274. 0x06c, BIT(19), 0);
  275. static SUNXI_CCU_GATE(bus_scr_clk, "bus-scr", "apb2",
  276. 0x06c, BIT(20), 0);
  277. static SUNXI_CCU_GATE(bus_ephy_clk, "bus-ephy", "ahb1",
  278. 0x070, BIT(0), 0);
  279. static SUNXI_CCU_GATE(bus_dbg_clk, "bus-dbg", "ahb1",
  280. 0x070, BIT(7), 0);
  281. static struct clk_div_table ths_div_table[] = {
  282. { .val = 0, .div = 1 },
  283. { .val = 1, .div = 2 },
  284. { .val = 2, .div = 4 },
  285. { .val = 3, .div = 6 },
  286. };
  287. static SUNXI_CCU_DIV_TABLE_WITH_GATE(ths_clk, "ths", "osc24M",
  288. 0x074, 0, 2, ths_div_table, BIT(31), 0);
  289. static const char * const mod0_default_parents[] = { "osc24M", "pll-periph0",
  290. "pll-periph1" };
  291. static SUNXI_CCU_MP_WITH_MUX_GATE(nand_clk, "nand", mod0_default_parents, 0x080,
  292. 0, 4, /* M */
  293. 16, 2, /* P */
  294. 24, 2, /* mux */
  295. BIT(31), /* gate */
  296. 0);
  297. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents, 0x088,
  298. 0, 4, /* M */
  299. 16, 2, /* P */
  300. 24, 2, /* mux */
  301. BIT(31), /* gate */
  302. 0);
  303. static SUNXI_CCU_PHASE(mmc0_sample_clk, "mmc0_sample", "mmc0",
  304. 0x088, 20, 3, 0);
  305. static SUNXI_CCU_PHASE(mmc0_output_clk, "mmc0_output", "mmc0",
  306. 0x088, 8, 3, 0);
  307. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents, 0x08c,
  308. 0, 4, /* M */
  309. 16, 2, /* P */
  310. 24, 2, /* mux */
  311. BIT(31), /* gate */
  312. 0);
  313. static SUNXI_CCU_PHASE(mmc1_sample_clk, "mmc1_sample", "mmc1",
  314. 0x08c, 20, 3, 0);
  315. static SUNXI_CCU_PHASE(mmc1_output_clk, "mmc1_output", "mmc1",
  316. 0x08c, 8, 3, 0);
  317. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents, 0x090,
  318. 0, 4, /* M */
  319. 16, 2, /* P */
  320. 24, 2, /* mux */
  321. BIT(31), /* gate */
  322. 0);
  323. static SUNXI_CCU_PHASE(mmc2_sample_clk, "mmc2_sample", "mmc2",
  324. 0x090, 20, 3, 0);
  325. static SUNXI_CCU_PHASE(mmc2_output_clk, "mmc2_output", "mmc2",
  326. 0x090, 8, 3, 0);
  327. static const char * const ts_parents[] = { "osc24M", "pll-periph0", };
  328. static SUNXI_CCU_MP_WITH_MUX_GATE(ts_clk, "ts", ts_parents, 0x098,
  329. 0, 4, /* M */
  330. 16, 2, /* P */
  331. 24, 2, /* mux */
  332. BIT(31), /* gate */
  333. 0);
  334. static SUNXI_CCU_MP_WITH_MUX_GATE(ce_clk, "ce", mod0_default_parents, 0x09c,
  335. 0, 4, /* M */
  336. 16, 2, /* P */
  337. 24, 2, /* mux */
  338. BIT(31), /* gate */
  339. 0);
  340. static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0,
  341. 0, 4, /* M */
  342. 16, 2, /* P */
  343. 24, 2, /* mux */
  344. BIT(31), /* gate */
  345. 0);
  346. static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", mod0_default_parents, 0x0a4,
  347. 0, 4, /* M */
  348. 16, 2, /* P */
  349. 24, 2, /* mux */
  350. BIT(31), /* gate */
  351. 0);
  352. static const char * const i2s_parents[] = { "pll-audio-8x", "pll-audio-4x",
  353. "pll-audio-2x", "pll-audio" };
  354. static SUNXI_CCU_MUX_WITH_GATE(i2s0_clk, "i2s0", i2s_parents,
  355. 0x0b0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  356. static SUNXI_CCU_MUX_WITH_GATE(i2s1_clk, "i2s1", i2s_parents,
  357. 0x0b4, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  358. static SUNXI_CCU_MUX_WITH_GATE(i2s2_clk, "i2s2", i2s_parents,
  359. 0x0b8, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  360. static SUNXI_CCU_M_WITH_GATE(spdif_clk, "spdif", "pll-audio",
  361. 0x0c0, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  362. static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M",
  363. 0x0cc, BIT(8), 0);
  364. static SUNXI_CCU_GATE(usb_phy1_clk, "usb-phy1", "osc24M",
  365. 0x0cc, BIT(9), 0);
  366. static SUNXI_CCU_GATE(usb_phy2_clk, "usb-phy2", "osc24M",
  367. 0x0cc, BIT(10), 0);
  368. static SUNXI_CCU_GATE(usb_phy3_clk, "usb-phy3", "osc24M",
  369. 0x0cc, BIT(11), 0);
  370. static SUNXI_CCU_GATE(usb_ohci0_clk, "usb-ohci0", "osc24M",
  371. 0x0cc, BIT(16), 0);
  372. static SUNXI_CCU_GATE(usb_ohci1_clk, "usb-ohci1", "osc24M",
  373. 0x0cc, BIT(17), 0);
  374. static SUNXI_CCU_GATE(usb_ohci2_clk, "usb-ohci2", "osc24M",
  375. 0x0cc, BIT(18), 0);
  376. static SUNXI_CCU_GATE(usb_ohci3_clk, "usb-ohci3", "osc24M",
  377. 0x0cc, BIT(19), 0);
  378. static const char * const dram_parents[] = { "pll-ddr", "pll-periph0-2x" };
  379. static SUNXI_CCU_M_WITH_MUX(dram_clk, "dram", dram_parents,
  380. 0x0f4, 0, 4, 20, 2, CLK_IS_CRITICAL);
  381. static SUNXI_CCU_GATE(dram_ve_clk, "dram-ve", "dram",
  382. 0x100, BIT(0), 0);
  383. static SUNXI_CCU_GATE(dram_csi_clk, "dram-csi", "dram",
  384. 0x100, BIT(1), 0);
  385. static SUNXI_CCU_GATE(dram_deinterlace_clk, "dram-deinterlace", "dram",
  386. 0x100, BIT(2), 0);
  387. static SUNXI_CCU_GATE(dram_ts_clk, "dram-ts", "dram",
  388. 0x100, BIT(3), 0);
  389. static const char * const de_parents[] = { "pll-periph0-2x", "pll-de" };
  390. static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents,
  391. 0x104, 0, 4, 24, 3, BIT(31), 0);
  392. static const char * const tcon_parents[] = { "pll-video" };
  393. static SUNXI_CCU_M_WITH_MUX_GATE(tcon_clk, "tcon", tcon_parents,
  394. 0x118, 0, 4, 24, 3, BIT(31), 0);
  395. static const char * const tve_parents[] = { "pll-de", "pll-periph1" };
  396. static SUNXI_CCU_M_WITH_MUX_GATE(tve_clk, "tve", tve_parents,
  397. 0x120, 0, 4, 24, 3, BIT(31), 0);
  398. static const char * const deinterlace_parents[] = { "pll-periph0", "pll-periph1" };
  399. static SUNXI_CCU_M_WITH_MUX_GATE(deinterlace_clk, "deinterlace", deinterlace_parents,
  400. 0x124, 0, 4, 24, 3, BIT(31), 0);
  401. static SUNXI_CCU_GATE(csi_misc_clk, "csi-misc", "osc24M",
  402. 0x130, BIT(31), 0);
  403. static const char * const csi_sclk_parents[] = { "pll-periph0", "pll-periph1" };
  404. static SUNXI_CCU_M_WITH_MUX_GATE(csi_sclk_clk, "csi-sclk", csi_sclk_parents,
  405. 0x134, 16, 4, 24, 3, BIT(31), 0);
  406. static const char * const csi_mclk_parents[] = { "osc24M", "pll-video", "pll-periph0" };
  407. static SUNXI_CCU_M_WITH_MUX_GATE(csi_mclk_clk, "csi-mclk", csi_mclk_parents,
  408. 0x134, 0, 5, 8, 3, BIT(15), 0);
  409. static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve",
  410. 0x13c, 16, 3, BIT(31), 0);
  411. static SUNXI_CCU_GATE(ac_dig_clk, "ac-dig", "pll-audio",
  412. 0x140, BIT(31), CLK_SET_RATE_PARENT);
  413. static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M",
  414. 0x144, BIT(31), 0);
  415. static const char * const hdmi_parents[] = { "pll-video" };
  416. static SUNXI_CCU_M_WITH_MUX_GATE(hdmi_clk, "hdmi", hdmi_parents,
  417. 0x150, 0, 4, 24, 2, BIT(31), 0);
  418. static SUNXI_CCU_GATE(hdmi_ddc_clk, "hdmi-ddc", "osc24M",
  419. 0x154, BIT(31), 0);
  420. static const char * const mbus_parents[] = { "osc24M", "pll-periph0-2x", "pll-ddr" };
  421. static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents,
  422. 0x15c, 0, 3, 24, 2, BIT(31), CLK_IS_CRITICAL);
  423. static SUNXI_CCU_M_WITH_GATE(gpu_clk, "gpu", "pll-gpu",
  424. 0x1a0, 0, 3, BIT(31), 0);
  425. static struct ccu_common *sun8i_h3_ccu_clks[] = {
  426. &pll_cpux_clk.common,
  427. &pll_audio_base_clk.common,
  428. &pll_video_clk.common,
  429. &pll_ve_clk.common,
  430. &pll_ddr_clk.common,
  431. &pll_periph0_clk.common,
  432. &pll_gpu_clk.common,
  433. &pll_periph1_clk.common,
  434. &pll_de_clk.common,
  435. &cpux_clk.common,
  436. &axi_clk.common,
  437. &ahb1_clk.common,
  438. &apb1_clk.common,
  439. &apb2_clk.common,
  440. &ahb2_clk.common,
  441. &bus_ce_clk.common,
  442. &bus_dma_clk.common,
  443. &bus_mmc0_clk.common,
  444. &bus_mmc1_clk.common,
  445. &bus_mmc2_clk.common,
  446. &bus_nand_clk.common,
  447. &bus_dram_clk.common,
  448. &bus_emac_clk.common,
  449. &bus_ts_clk.common,
  450. &bus_hstimer_clk.common,
  451. &bus_spi0_clk.common,
  452. &bus_spi1_clk.common,
  453. &bus_otg_clk.common,
  454. &bus_ehci0_clk.common,
  455. &bus_ehci1_clk.common,
  456. &bus_ehci2_clk.common,
  457. &bus_ehci3_clk.common,
  458. &bus_ohci0_clk.common,
  459. &bus_ohci1_clk.common,
  460. &bus_ohci2_clk.common,
  461. &bus_ohci3_clk.common,
  462. &bus_ve_clk.common,
  463. &bus_tcon0_clk.common,
  464. &bus_tcon1_clk.common,
  465. &bus_deinterlace_clk.common,
  466. &bus_csi_clk.common,
  467. &bus_tve_clk.common,
  468. &bus_hdmi_clk.common,
  469. &bus_de_clk.common,
  470. &bus_gpu_clk.common,
  471. &bus_msgbox_clk.common,
  472. &bus_spinlock_clk.common,
  473. &bus_codec_clk.common,
  474. &bus_spdif_clk.common,
  475. &bus_pio_clk.common,
  476. &bus_ths_clk.common,
  477. &bus_i2s0_clk.common,
  478. &bus_i2s1_clk.common,
  479. &bus_i2s2_clk.common,
  480. &bus_i2c0_clk.common,
  481. &bus_i2c1_clk.common,
  482. &bus_i2c2_clk.common,
  483. &bus_uart0_clk.common,
  484. &bus_uart1_clk.common,
  485. &bus_uart2_clk.common,
  486. &bus_uart3_clk.common,
  487. &bus_scr_clk.common,
  488. &bus_ephy_clk.common,
  489. &bus_dbg_clk.common,
  490. &ths_clk.common,
  491. &nand_clk.common,
  492. &mmc0_clk.common,
  493. &mmc0_sample_clk.common,
  494. &mmc0_output_clk.common,
  495. &mmc1_clk.common,
  496. &mmc1_sample_clk.common,
  497. &mmc1_output_clk.common,
  498. &mmc2_clk.common,
  499. &mmc2_sample_clk.common,
  500. &mmc2_output_clk.common,
  501. &ts_clk.common,
  502. &ce_clk.common,
  503. &spi0_clk.common,
  504. &spi1_clk.common,
  505. &i2s0_clk.common,
  506. &i2s1_clk.common,
  507. &i2s2_clk.common,
  508. &spdif_clk.common,
  509. &usb_phy0_clk.common,
  510. &usb_phy1_clk.common,
  511. &usb_phy2_clk.common,
  512. &usb_phy3_clk.common,
  513. &usb_ohci0_clk.common,
  514. &usb_ohci1_clk.common,
  515. &usb_ohci2_clk.common,
  516. &usb_ohci3_clk.common,
  517. &dram_clk.common,
  518. &dram_ve_clk.common,
  519. &dram_csi_clk.common,
  520. &dram_deinterlace_clk.common,
  521. &dram_ts_clk.common,
  522. &de_clk.common,
  523. &tcon_clk.common,
  524. &tve_clk.common,
  525. &deinterlace_clk.common,
  526. &csi_misc_clk.common,
  527. &csi_sclk_clk.common,
  528. &csi_mclk_clk.common,
  529. &ve_clk.common,
  530. &ac_dig_clk.common,
  531. &avs_clk.common,
  532. &hdmi_clk.common,
  533. &hdmi_ddc_clk.common,
  534. &mbus_clk.common,
  535. &gpu_clk.common,
  536. };
  537. /* We hardcode the divider to 4 for now */
  538. static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio",
  539. "pll-audio-base", 4, 1, CLK_SET_RATE_PARENT);
  540. static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x",
  541. "pll-audio-base", 2, 1, CLK_SET_RATE_PARENT);
  542. static CLK_FIXED_FACTOR(pll_audio_4x_clk, "pll-audio-4x",
  543. "pll-audio-base", 1, 1, CLK_SET_RATE_PARENT);
  544. static CLK_FIXED_FACTOR(pll_audio_8x_clk, "pll-audio-8x",
  545. "pll-audio-base", 1, 2, CLK_SET_RATE_PARENT);
  546. static CLK_FIXED_FACTOR(pll_periph0_2x_clk, "pll-periph0-2x",
  547. "pll-periph0", 1, 2, 0);
  548. static struct clk_hw_onecell_data sun8i_h3_hw_clks = {
  549. .hws = {
  550. [CLK_PLL_CPUX] = &pll_cpux_clk.common.hw,
  551. [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
  552. [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
  553. [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
  554. [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
  555. [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw,
  556. [CLK_PLL_VIDEO] = &pll_video_clk.common.hw,
  557. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  558. [CLK_PLL_DDR] = &pll_ddr_clk.common.hw,
  559. [CLK_PLL_PERIPH0] = &pll_periph0_clk.common.hw,
  560. [CLK_PLL_PERIPH0_2X] = &pll_periph0_2x_clk.hw,
  561. [CLK_PLL_GPU] = &pll_gpu_clk.common.hw,
  562. [CLK_PLL_PERIPH1] = &pll_periph1_clk.common.hw,
  563. [CLK_PLL_DE] = &pll_de_clk.common.hw,
  564. [CLK_CPUX] = &cpux_clk.common.hw,
  565. [CLK_AXI] = &axi_clk.common.hw,
  566. [CLK_AHB1] = &ahb1_clk.common.hw,
  567. [CLK_APB1] = &apb1_clk.common.hw,
  568. [CLK_APB2] = &apb2_clk.common.hw,
  569. [CLK_AHB2] = &ahb2_clk.common.hw,
  570. [CLK_BUS_CE] = &bus_ce_clk.common.hw,
  571. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  572. [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw,
  573. [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw,
  574. [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw,
  575. [CLK_BUS_NAND] = &bus_nand_clk.common.hw,
  576. [CLK_BUS_DRAM] = &bus_dram_clk.common.hw,
  577. [CLK_BUS_EMAC] = &bus_emac_clk.common.hw,
  578. [CLK_BUS_TS] = &bus_ts_clk.common.hw,
  579. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  580. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  581. [CLK_BUS_SPI1] = &bus_spi1_clk.common.hw,
  582. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  583. [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw,
  584. [CLK_BUS_EHCI1] = &bus_ehci1_clk.common.hw,
  585. [CLK_BUS_EHCI2] = &bus_ehci2_clk.common.hw,
  586. [CLK_BUS_EHCI3] = &bus_ehci3_clk.common.hw,
  587. [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw,
  588. [CLK_BUS_OHCI1] = &bus_ohci1_clk.common.hw,
  589. [CLK_BUS_OHCI2] = &bus_ohci2_clk.common.hw,
  590. [CLK_BUS_OHCI3] = &bus_ohci3_clk.common.hw,
  591. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  592. [CLK_BUS_TCON0] = &bus_tcon0_clk.common.hw,
  593. [CLK_BUS_TCON1] = &bus_tcon1_clk.common.hw,
  594. [CLK_BUS_DEINTERLACE] = &bus_deinterlace_clk.common.hw,
  595. [CLK_BUS_CSI] = &bus_csi_clk.common.hw,
  596. [CLK_BUS_TVE] = &bus_tve_clk.common.hw,
  597. [CLK_BUS_HDMI] = &bus_hdmi_clk.common.hw,
  598. [CLK_BUS_DE] = &bus_de_clk.common.hw,
  599. [CLK_BUS_GPU] = &bus_gpu_clk.common.hw,
  600. [CLK_BUS_MSGBOX] = &bus_msgbox_clk.common.hw,
  601. [CLK_BUS_SPINLOCK] = &bus_spinlock_clk.common.hw,
  602. [CLK_BUS_CODEC] = &bus_codec_clk.common.hw,
  603. [CLK_BUS_SPDIF] = &bus_spdif_clk.common.hw,
  604. [CLK_BUS_PIO] = &bus_pio_clk.common.hw,
  605. [CLK_BUS_THS] = &bus_ths_clk.common.hw,
  606. [CLK_BUS_I2S0] = &bus_i2s0_clk.common.hw,
  607. [CLK_BUS_I2S1] = &bus_i2s1_clk.common.hw,
  608. [CLK_BUS_I2S2] = &bus_i2s2_clk.common.hw,
  609. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  610. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  611. [CLK_BUS_I2C2] = &bus_i2c2_clk.common.hw,
  612. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  613. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  614. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  615. [CLK_BUS_UART3] = &bus_uart3_clk.common.hw,
  616. [CLK_BUS_SCR] = &bus_scr_clk.common.hw,
  617. [CLK_BUS_EPHY] = &bus_ephy_clk.common.hw,
  618. [CLK_BUS_DBG] = &bus_dbg_clk.common.hw,
  619. [CLK_THS] = &ths_clk.common.hw,
  620. [CLK_NAND] = &nand_clk.common.hw,
  621. [CLK_MMC0] = &mmc0_clk.common.hw,
  622. [CLK_MMC0_SAMPLE] = &mmc0_sample_clk.common.hw,
  623. [CLK_MMC0_OUTPUT] = &mmc0_output_clk.common.hw,
  624. [CLK_MMC1] = &mmc1_clk.common.hw,
  625. [CLK_MMC1_SAMPLE] = &mmc1_sample_clk.common.hw,
  626. [CLK_MMC1_OUTPUT] = &mmc1_output_clk.common.hw,
  627. [CLK_MMC2] = &mmc2_clk.common.hw,
  628. [CLK_MMC2_SAMPLE] = &mmc2_sample_clk.common.hw,
  629. [CLK_MMC2_OUTPUT] = &mmc2_output_clk.common.hw,
  630. [CLK_TS] = &ts_clk.common.hw,
  631. [CLK_CE] = &ce_clk.common.hw,
  632. [CLK_SPI0] = &spi0_clk.common.hw,
  633. [CLK_SPI1] = &spi1_clk.common.hw,
  634. [CLK_I2S0] = &i2s0_clk.common.hw,
  635. [CLK_I2S1] = &i2s1_clk.common.hw,
  636. [CLK_I2S2] = &i2s2_clk.common.hw,
  637. [CLK_SPDIF] = &spdif_clk.common.hw,
  638. [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
  639. [CLK_USB_PHY1] = &usb_phy1_clk.common.hw,
  640. [CLK_USB_PHY2] = &usb_phy2_clk.common.hw,
  641. [CLK_USB_PHY3] = &usb_phy3_clk.common.hw,
  642. [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
  643. [CLK_USB_OHCI1] = &usb_ohci1_clk.common.hw,
  644. [CLK_USB_OHCI2] = &usb_ohci2_clk.common.hw,
  645. [CLK_USB_OHCI3] = &usb_ohci3_clk.common.hw,
  646. [CLK_DRAM] = &dram_clk.common.hw,
  647. [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
  648. [CLK_DRAM_CSI] = &dram_csi_clk.common.hw,
  649. [CLK_DRAM_DEINTERLACE] = &dram_deinterlace_clk.common.hw,
  650. [CLK_DRAM_TS] = &dram_ts_clk.common.hw,
  651. [CLK_DE] = &de_clk.common.hw,
  652. [CLK_TCON0] = &tcon_clk.common.hw,
  653. [CLK_TVE] = &tve_clk.common.hw,
  654. [CLK_DEINTERLACE] = &deinterlace_clk.common.hw,
  655. [CLK_CSI_MISC] = &csi_misc_clk.common.hw,
  656. [CLK_CSI_SCLK] = &csi_sclk_clk.common.hw,
  657. [CLK_CSI_MCLK] = &csi_mclk_clk.common.hw,
  658. [CLK_VE] = &ve_clk.common.hw,
  659. [CLK_AC_DIG] = &ac_dig_clk.common.hw,
  660. [CLK_AVS] = &avs_clk.common.hw,
  661. [CLK_HDMI] = &hdmi_clk.common.hw,
  662. [CLK_HDMI_DDC] = &hdmi_ddc_clk.common.hw,
  663. [CLK_MBUS] = &mbus_clk.common.hw,
  664. [CLK_GPU] = &gpu_clk.common.hw,
  665. },
  666. .num = CLK_NUMBER,
  667. };
  668. static struct ccu_reset_map sun8i_h3_ccu_resets[] = {
  669. [RST_USB_PHY0] = { 0x0cc, BIT(0) },
  670. [RST_USB_PHY1] = { 0x0cc, BIT(1) },
  671. [RST_USB_PHY2] = { 0x0cc, BIT(2) },
  672. [RST_USB_PHY3] = { 0x0cc, BIT(3) },
  673. [RST_MBUS] = { 0x0fc, BIT(31) },
  674. [RST_BUS_CE] = { 0x2c0, BIT(5) },
  675. [RST_BUS_DMA] = { 0x2c0, BIT(6) },
  676. [RST_BUS_MMC0] = { 0x2c0, BIT(8) },
  677. [RST_BUS_MMC1] = { 0x2c0, BIT(9) },
  678. [RST_BUS_MMC2] = { 0x2c0, BIT(10) },
  679. [RST_BUS_NAND] = { 0x2c0, BIT(13) },
  680. [RST_BUS_DRAM] = { 0x2c0, BIT(14) },
  681. [RST_BUS_EMAC] = { 0x2c0, BIT(17) },
  682. [RST_BUS_TS] = { 0x2c0, BIT(18) },
  683. [RST_BUS_HSTIMER] = { 0x2c0, BIT(19) },
  684. [RST_BUS_SPI0] = { 0x2c0, BIT(20) },
  685. [RST_BUS_SPI1] = { 0x2c0, BIT(21) },
  686. [RST_BUS_OTG] = { 0x2c0, BIT(23) },
  687. [RST_BUS_EHCI0] = { 0x2c0, BIT(24) },
  688. [RST_BUS_EHCI1] = { 0x2c0, BIT(25) },
  689. [RST_BUS_EHCI2] = { 0x2c0, BIT(26) },
  690. [RST_BUS_EHCI3] = { 0x2c0, BIT(27) },
  691. [RST_BUS_OHCI0] = { 0x2c0, BIT(28) },
  692. [RST_BUS_OHCI1] = { 0x2c0, BIT(29) },
  693. [RST_BUS_OHCI2] = { 0x2c0, BIT(30) },
  694. [RST_BUS_OHCI3] = { 0x2c0, BIT(31) },
  695. [RST_BUS_VE] = { 0x2c4, BIT(0) },
  696. [RST_BUS_TCON0] = { 0x2c4, BIT(3) },
  697. [RST_BUS_TCON1] = { 0x2c4, BIT(4) },
  698. [RST_BUS_DEINTERLACE] = { 0x2c4, BIT(5) },
  699. [RST_BUS_CSI] = { 0x2c4, BIT(8) },
  700. [RST_BUS_TVE] = { 0x2c4, BIT(9) },
  701. [RST_BUS_HDMI0] = { 0x2c4, BIT(10) },
  702. [RST_BUS_HDMI1] = { 0x2c4, BIT(11) },
  703. [RST_BUS_DE] = { 0x2c4, BIT(12) },
  704. [RST_BUS_GPU] = { 0x2c4, BIT(20) },
  705. [RST_BUS_MSGBOX] = { 0x2c4, BIT(21) },
  706. [RST_BUS_SPINLOCK] = { 0x2c4, BIT(22) },
  707. [RST_BUS_DBG] = { 0x2c4, BIT(31) },
  708. [RST_BUS_EPHY] = { 0x2c8, BIT(2) },
  709. [RST_BUS_CODEC] = { 0x2d0, BIT(0) },
  710. [RST_BUS_SPDIF] = { 0x2d0, BIT(1) },
  711. [RST_BUS_THS] = { 0x2d0, BIT(8) },
  712. [RST_BUS_I2S0] = { 0x2d0, BIT(12) },
  713. [RST_BUS_I2S1] = { 0x2d0, BIT(13) },
  714. [RST_BUS_I2S2] = { 0x2d0, BIT(14) },
  715. [RST_BUS_I2C0] = { 0x2d8, BIT(0) },
  716. [RST_BUS_I2C1] = { 0x2d8, BIT(1) },
  717. [RST_BUS_I2C2] = { 0x2d8, BIT(2) },
  718. [RST_BUS_UART0] = { 0x2d8, BIT(16) },
  719. [RST_BUS_UART1] = { 0x2d8, BIT(17) },
  720. [RST_BUS_UART2] = { 0x2d8, BIT(18) },
  721. [RST_BUS_UART3] = { 0x2d8, BIT(19) },
  722. [RST_BUS_SCR] = { 0x2d8, BIT(20) },
  723. };
  724. static const struct sunxi_ccu_desc sun8i_h3_ccu_desc = {
  725. .ccu_clks = sun8i_h3_ccu_clks,
  726. .num_ccu_clks = ARRAY_SIZE(sun8i_h3_ccu_clks),
  727. .hw_clks = &sun8i_h3_hw_clks,
  728. .resets = sun8i_h3_ccu_resets,
  729. .num_resets = ARRAY_SIZE(sun8i_h3_ccu_resets),
  730. };
  731. static struct ccu_mux_nb sun8i_h3_cpu_nb = {
  732. .common = &cpux_clk.common,
  733. .cm = &cpux_clk.mux,
  734. .delay_us = 1, /* > 8 clock cycles at 24 MHz */
  735. .bypass_index = 1, /* index of 24 MHz oscillator */
  736. };
  737. static void __init sun8i_h3_ccu_setup(struct device_node *node)
  738. {
  739. void __iomem *reg;
  740. u32 val;
  741. reg = of_io_request_and_map(node, 0, of_node_full_name(node));
  742. if (IS_ERR(reg)) {
  743. pr_err("%s: Could not map the clock registers\n",
  744. of_node_full_name(node));
  745. return;
  746. }
  747. /* Force the PLL-Audio-1x divider to 4 */
  748. val = readl(reg + SUN8I_H3_PLL_AUDIO_REG);
  749. val &= ~GENMASK(19, 16);
  750. writel(val | (3 << 16), reg + SUN8I_H3_PLL_AUDIO_REG);
  751. sunxi_ccu_probe(node, reg, &sun8i_h3_ccu_desc);
  752. ccu_mux_notifier_register(pll_cpux_clk.common.hw.clk,
  753. &sun8i_h3_cpu_nb);
  754. }
  755. CLK_OF_DECLARE(sun8i_h3_ccu, "allwinner,sun8i-h3-ccu",
  756. sun8i_h3_ccu_setup);