ccu-sun8i-v3s.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*
  2. * Copyright (c) 2016 Icenowy Zheng <icenowy@aosc.xyz>
  3. *
  4. * Based on ccu-sun8i-h3.c, which is:
  5. * Copyright (c) 2016 Maxime Ripard. All rights reserved.
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <linux/clk-provider.h>
  17. #include <linux/of_address.h>
  18. #include "ccu_common.h"
  19. #include "ccu_reset.h"
  20. #include "ccu_div.h"
  21. #include "ccu_gate.h"
  22. #include "ccu_mp.h"
  23. #include "ccu_mult.h"
  24. #include "ccu_nk.h"
  25. #include "ccu_nkm.h"
  26. #include "ccu_nkmp.h"
  27. #include "ccu_nm.h"
  28. #include "ccu_phase.h"
  29. #include "ccu-sun8i-v3s.h"
  30. static SUNXI_CCU_NKMP_WITH_GATE_LOCK(pll_cpu_clk, "pll-cpu",
  31. "osc24M", 0x000,
  32. 8, 5, /* N */
  33. 4, 2, /* K */
  34. 0, 2, /* M */
  35. 16, 2, /* P */
  36. BIT(31), /* gate */
  37. BIT(28), /* lock */
  38. 0);
  39. /*
  40. * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from
  41. * the base (2x, 4x and 8x), and one variable divider (the one true
  42. * pll audio).
  43. *
  44. * We don't have any need for the variable divider for now, so we just
  45. * hardcode it to match with the clock names
  46. */
  47. #define SUN8I_V3S_PLL_AUDIO_REG 0x008
  48. static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
  49. "osc24M", 0x008,
  50. 8, 7, /* N */
  51. 0, 5, /* M */
  52. BIT(31), /* gate */
  53. BIT(28), /* lock */
  54. 0);
  55. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video_clk, "pll-video",
  56. "osc24M", 0x0010,
  57. 8, 7, /* N */
  58. 0, 4, /* M */
  59. BIT(24), /* frac enable */
  60. BIT(25), /* frac select */
  61. 270000000, /* frac rate 0 */
  62. 297000000, /* frac rate 1 */
  63. BIT(31), /* gate */
  64. BIT(28), /* lock */
  65. 0);
  66. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve",
  67. "osc24M", 0x0018,
  68. 8, 7, /* N */
  69. 0, 4, /* M */
  70. BIT(24), /* frac enable */
  71. BIT(25), /* frac select */
  72. 270000000, /* frac rate 0 */
  73. 297000000, /* frac rate 1 */
  74. BIT(31), /* gate */
  75. BIT(28), /* lock */
  76. 0);
  77. static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr_clk, "pll-ddr",
  78. "osc24M", 0x020,
  79. 8, 5, /* N */
  80. 4, 2, /* K */
  81. 0, 2, /* M */
  82. BIT(31), /* gate */
  83. BIT(28), /* lock */
  84. 0);
  85. static SUNXI_CCU_NK_WITH_GATE_LOCK_POSTDIV(pll_periph0_clk, "pll-periph0",
  86. "osc24M", 0x028,
  87. 8, 5, /* N */
  88. 4, 2, /* K */
  89. BIT(31), /* gate */
  90. BIT(28), /* lock */
  91. 2, /* post-div */
  92. 0);
  93. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_isp_clk, "pll-isp",
  94. "osc24M", 0x002c,
  95. 8, 7, /* N */
  96. 0, 4, /* M */
  97. BIT(24), /* frac enable */
  98. BIT(25), /* frac select */
  99. 270000000, /* frac rate 0 */
  100. 297000000, /* frac rate 1 */
  101. BIT(31), /* gate */
  102. BIT(28), /* lock */
  103. 0);
  104. static SUNXI_CCU_NK_WITH_GATE_LOCK_POSTDIV(pll_periph1_clk, "pll-periph1",
  105. "osc24M", 0x044,
  106. 8, 5, /* N */
  107. 4, 2, /* K */
  108. BIT(31), /* gate */
  109. BIT(28), /* lock */
  110. 2, /* post-div */
  111. 0);
  112. static const char * const cpu_parents[] = { "osc32k", "osc24M",
  113. "pll-cpu", "pll-cpu" };
  114. static SUNXI_CCU_MUX(cpu_clk, "cpu", cpu_parents,
  115. 0x050, 16, 2, CLK_IS_CRITICAL);
  116. static SUNXI_CCU_M(axi_clk, "axi", "cpu", 0x050, 0, 2, 0);
  117. static const char * const ahb1_parents[] = { "osc32k", "osc24M",
  118. "axi", "pll-periph0" };
  119. static struct ccu_div ahb1_clk = {
  120. .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
  121. .mux = {
  122. .shift = 12,
  123. .width = 2,
  124. .variable_prediv = {
  125. .index = 3,
  126. .shift = 6,
  127. .width = 2,
  128. },
  129. },
  130. .common = {
  131. .reg = 0x054,
  132. .features = CCU_FEATURE_VARIABLE_PREDIV,
  133. .hw.init = CLK_HW_INIT_PARENTS("ahb1",
  134. ahb1_parents,
  135. &ccu_div_ops,
  136. 0),
  137. },
  138. };
  139. static struct clk_div_table apb1_div_table[] = {
  140. { .val = 0, .div = 2 },
  141. { .val = 1, .div = 2 },
  142. { .val = 2, .div = 4 },
  143. { .val = 3, .div = 8 },
  144. { /* Sentinel */ },
  145. };
  146. static SUNXI_CCU_DIV_TABLE(apb1_clk, "apb1", "ahb1",
  147. 0x054, 8, 2, apb1_div_table, 0);
  148. static const char * const apb2_parents[] = { "osc32k", "osc24M",
  149. "pll-periph0", "pll-periph0" };
  150. static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", apb2_parents, 0x058,
  151. 0, 5, /* M */
  152. 16, 2, /* P */
  153. 24, 2, /* mux */
  154. 0);
  155. static const char * const ahb2_parents[] = { "ahb1", "pll-periph0" };
  156. static const struct ccu_mux_fixed_prediv ahb2_fixed_predivs[] = {
  157. { .index = 1, .div = 2 },
  158. };
  159. static struct ccu_mux ahb2_clk = {
  160. .mux = {
  161. .shift = 0,
  162. .width = 1,
  163. .fixed_predivs = ahb2_fixed_predivs,
  164. .n_predivs = ARRAY_SIZE(ahb2_fixed_predivs),
  165. },
  166. .common = {
  167. .reg = 0x05c,
  168. .features = CCU_FEATURE_FIXED_PREDIV,
  169. .hw.init = CLK_HW_INIT_PARENTS("ahb2",
  170. ahb2_parents,
  171. &ccu_mux_ops,
  172. 0),
  173. },
  174. };
  175. static SUNXI_CCU_GATE(bus_ce_clk, "bus-ce", "ahb1",
  176. 0x060, BIT(5), 0);
  177. static SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "ahb1",
  178. 0x060, BIT(6), 0);
  179. static SUNXI_CCU_GATE(bus_mmc0_clk, "bus-mmc0", "ahb1",
  180. 0x060, BIT(8), 0);
  181. static SUNXI_CCU_GATE(bus_mmc1_clk, "bus-mmc1", "ahb1",
  182. 0x060, BIT(9), 0);
  183. static SUNXI_CCU_GATE(bus_mmc2_clk, "bus-mmc2", "ahb1",
  184. 0x060, BIT(10), 0);
  185. static SUNXI_CCU_GATE(bus_dram_clk, "bus-dram", "ahb1",
  186. 0x060, BIT(14), 0);
  187. static SUNXI_CCU_GATE(bus_emac_clk, "bus-emac", "ahb2",
  188. 0x060, BIT(17), 0);
  189. static SUNXI_CCU_GATE(bus_hstimer_clk, "bus-hstimer", "ahb1",
  190. 0x060, BIT(19), 0);
  191. static SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb1",
  192. 0x060, BIT(20), 0);
  193. static SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb1",
  194. 0x060, BIT(24), 0);
  195. static SUNXI_CCU_GATE(bus_ehci0_clk, "bus-ehci0", "ahb1",
  196. 0x060, BIT(26), 0);
  197. static SUNXI_CCU_GATE(bus_ohci0_clk, "bus-ohci0", "ahb1",
  198. 0x060, BIT(29), 0);
  199. static SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "ahb1",
  200. 0x064, BIT(0), 0);
  201. static SUNXI_CCU_GATE(bus_tcon0_clk, "bus-tcon0", "ahb1",
  202. 0x064, BIT(4), 0);
  203. static SUNXI_CCU_GATE(bus_csi_clk, "bus-csi", "ahb1",
  204. 0x064, BIT(8), 0);
  205. static SUNXI_CCU_GATE(bus_de_clk, "bus-de", "ahb1",
  206. 0x064, BIT(12), 0);
  207. static SUNXI_CCU_GATE(bus_codec_clk, "bus-codec", "apb1",
  208. 0x068, BIT(0), 0);
  209. static SUNXI_CCU_GATE(bus_pio_clk, "bus-pio", "apb1",
  210. 0x068, BIT(5), 0);
  211. static SUNXI_CCU_GATE(bus_i2c0_clk, "bus-i2c0", "apb2",
  212. 0x06c, BIT(0), 0);
  213. static SUNXI_CCU_GATE(bus_i2c1_clk, "bus-i2c1", "apb2",
  214. 0x06c, BIT(1), 0);
  215. static SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb2",
  216. 0x06c, BIT(16), 0);
  217. static SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb2",
  218. 0x06c, BIT(17), 0);
  219. static SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb2",
  220. 0x06c, BIT(18), 0);
  221. static SUNXI_CCU_GATE(bus_ephy_clk, "bus-ephy", "ahb1",
  222. 0x070, BIT(0), 0);
  223. static SUNXI_CCU_GATE(bus_dbg_clk, "bus-dbg", "ahb1",
  224. 0x070, BIT(7), 0);
  225. static const char * const mod0_default_parents[] = { "osc24M", "pll-periph0",
  226. "pll-periph1" };
  227. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents, 0x088,
  228. 0, 4, /* M */
  229. 16, 2, /* P */
  230. 24, 2, /* mux */
  231. BIT(31), /* gate */
  232. 0);
  233. static SUNXI_CCU_PHASE(mmc0_sample_clk, "mmc0_sample", "mmc0",
  234. 0x088, 20, 3, 0);
  235. static SUNXI_CCU_PHASE(mmc0_output_clk, "mmc0_output", "mmc0",
  236. 0x088, 8, 3, 0);
  237. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents, 0x08c,
  238. 0, 4, /* M */
  239. 16, 2, /* P */
  240. 24, 2, /* mux */
  241. BIT(31), /* gate */
  242. 0);
  243. static SUNXI_CCU_PHASE(mmc1_sample_clk, "mmc1_sample", "mmc1",
  244. 0x08c, 20, 3, 0);
  245. static SUNXI_CCU_PHASE(mmc1_output_clk, "mmc1_output", "mmc1",
  246. 0x08c, 8, 3, 0);
  247. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents, 0x090,
  248. 0, 4, /* M */
  249. 16, 2, /* P */
  250. 24, 2, /* mux */
  251. BIT(31), /* gate */
  252. 0);
  253. static SUNXI_CCU_PHASE(mmc2_sample_clk, "mmc2_sample", "mmc2",
  254. 0x090, 20, 3, 0);
  255. static SUNXI_CCU_PHASE(mmc2_output_clk, "mmc2_output", "mmc2",
  256. 0x090, 8, 3, 0);
  257. static const char * const ce_parents[] = { "osc24M", "pll-periph0", };
  258. static SUNXI_CCU_MP_WITH_MUX_GATE(ce_clk, "ce", ce_parents, 0x09c,
  259. 0, 4, /* M */
  260. 16, 2, /* P */
  261. 24, 2, /* mux */
  262. BIT(31), /* gate */
  263. 0);
  264. static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0,
  265. 0, 4, /* M */
  266. 16, 2, /* P */
  267. 24, 2, /* mux */
  268. BIT(31), /* gate */
  269. 0);
  270. static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M",
  271. 0x0cc, BIT(8), 0);
  272. static SUNXI_CCU_GATE(usb_ohci0_clk, "usb-ohci0", "osc24M",
  273. 0x0cc, BIT(16), 0);
  274. static const char * const dram_parents[] = { "pll-ddr", "pll-periph0-2x" };
  275. static SUNXI_CCU_M_WITH_MUX(dram_clk, "dram", dram_parents,
  276. 0x0f4, 0, 4, 20, 2, CLK_IS_CRITICAL);
  277. static SUNXI_CCU_GATE(dram_ve_clk, "dram-ve", "dram",
  278. 0x100, BIT(0), 0);
  279. static SUNXI_CCU_GATE(dram_csi_clk, "dram-csi", "dram",
  280. 0x100, BIT(1), 0);
  281. static SUNXI_CCU_GATE(dram_ehci_clk, "dram-ehci", "dram",
  282. 0x100, BIT(17), 0);
  283. static SUNXI_CCU_GATE(dram_ohci_clk, "dram-ohci", "dram",
  284. 0x100, BIT(18), 0);
  285. static const char * const de_parents[] = { "pll-video", "pll-periph0" };
  286. static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents,
  287. 0x104, 0, 4, 24, 2, BIT(31), 0);
  288. static const char * const tcon_parents[] = { "pll-video" };
  289. static SUNXI_CCU_M_WITH_MUX_GATE(tcon_clk, "tcon", tcon_parents,
  290. 0x118, 0, 4, 24, 3, BIT(31), 0);
  291. static SUNXI_CCU_GATE(csi_misc_clk, "csi-misc", "osc24M",
  292. 0x130, BIT(31), 0);
  293. static const char * const csi_mclk_parents[] = { "osc24M", "pll-video",
  294. "pll-periph0", "pll-periph1" };
  295. static SUNXI_CCU_M_WITH_MUX_GATE(csi0_mclk_clk, "csi0-mclk", csi_mclk_parents,
  296. 0x130, 0, 5, 8, 3, BIT(15), 0);
  297. static const char * const csi1_sclk_parents[] = { "pll-video", "pll-isp" };
  298. static SUNXI_CCU_M_WITH_MUX_GATE(csi1_sclk_clk, "csi-sclk", csi1_sclk_parents,
  299. 0x134, 16, 4, 24, 3, BIT(31), 0);
  300. static SUNXI_CCU_M_WITH_MUX_GATE(csi1_mclk_clk, "csi-mclk", csi_mclk_parents,
  301. 0x134, 0, 5, 8, 3, BIT(15), 0);
  302. static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve",
  303. 0x13c, 16, 3, BIT(31), 0);
  304. static SUNXI_CCU_GATE(ac_dig_clk, "ac-dig", "pll-audio",
  305. 0x140, BIT(31), CLK_SET_RATE_PARENT);
  306. static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M",
  307. 0x144, BIT(31), 0);
  308. static const char * const mbus_parents[] = { "osc24M", "pll-periph0-2x",
  309. "pll-ddr" };
  310. static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents,
  311. 0x15c, 0, 3, 24, 2, BIT(31), CLK_IS_CRITICAL);
  312. static const char * const mipi_csi_parents[] = { "pll-video", "pll-periph0",
  313. "pll-isp" };
  314. static SUNXI_CCU_M_WITH_MUX_GATE(mipi_csi_clk, "mipi-csi", mipi_csi_parents,
  315. 0x16c, 0, 3, 24, 2, BIT(31), 0);
  316. static struct ccu_common *sun8i_v3s_ccu_clks[] = {
  317. &pll_cpu_clk.common,
  318. &pll_audio_base_clk.common,
  319. &pll_video_clk.common,
  320. &pll_ve_clk.common,
  321. &pll_ddr_clk.common,
  322. &pll_periph0_clk.common,
  323. &pll_isp_clk.common,
  324. &pll_periph1_clk.common,
  325. &cpu_clk.common,
  326. &axi_clk.common,
  327. &ahb1_clk.common,
  328. &apb1_clk.common,
  329. &apb2_clk.common,
  330. &ahb2_clk.common,
  331. &bus_ce_clk.common,
  332. &bus_dma_clk.common,
  333. &bus_mmc0_clk.common,
  334. &bus_mmc1_clk.common,
  335. &bus_mmc2_clk.common,
  336. &bus_dram_clk.common,
  337. &bus_emac_clk.common,
  338. &bus_hstimer_clk.common,
  339. &bus_spi0_clk.common,
  340. &bus_otg_clk.common,
  341. &bus_ehci0_clk.common,
  342. &bus_ohci0_clk.common,
  343. &bus_ve_clk.common,
  344. &bus_tcon0_clk.common,
  345. &bus_csi_clk.common,
  346. &bus_de_clk.common,
  347. &bus_codec_clk.common,
  348. &bus_pio_clk.common,
  349. &bus_i2c0_clk.common,
  350. &bus_i2c1_clk.common,
  351. &bus_uart0_clk.common,
  352. &bus_uart1_clk.common,
  353. &bus_uart2_clk.common,
  354. &bus_ephy_clk.common,
  355. &bus_dbg_clk.common,
  356. &mmc0_clk.common,
  357. &mmc0_sample_clk.common,
  358. &mmc0_output_clk.common,
  359. &mmc1_clk.common,
  360. &mmc1_sample_clk.common,
  361. &mmc1_output_clk.common,
  362. &mmc2_clk.common,
  363. &mmc2_sample_clk.common,
  364. &mmc2_output_clk.common,
  365. &ce_clk.common,
  366. &spi0_clk.common,
  367. &usb_phy0_clk.common,
  368. &usb_ohci0_clk.common,
  369. &dram_clk.common,
  370. &dram_ve_clk.common,
  371. &dram_csi_clk.common,
  372. &dram_ohci_clk.common,
  373. &dram_ehci_clk.common,
  374. &de_clk.common,
  375. &tcon_clk.common,
  376. &csi_misc_clk.common,
  377. &csi0_mclk_clk.common,
  378. &csi1_sclk_clk.common,
  379. &csi1_mclk_clk.common,
  380. &ve_clk.common,
  381. &ac_dig_clk.common,
  382. &avs_clk.common,
  383. &mbus_clk.common,
  384. &mipi_csi_clk.common,
  385. };
  386. /* We hardcode the divider to 4 for now */
  387. static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio",
  388. "pll-audio-base", 4, 1, CLK_SET_RATE_PARENT);
  389. static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x",
  390. "pll-audio-base", 2, 1, CLK_SET_RATE_PARENT);
  391. static CLK_FIXED_FACTOR(pll_audio_4x_clk, "pll-audio-4x",
  392. "pll-audio-base", 1, 1, CLK_SET_RATE_PARENT);
  393. static CLK_FIXED_FACTOR(pll_audio_8x_clk, "pll-audio-8x",
  394. "pll-audio-base", 1, 2, CLK_SET_RATE_PARENT);
  395. static CLK_FIXED_FACTOR(pll_periph0_2x_clk, "pll-periph0-2x",
  396. "pll-periph0", 1, 2, 0);
  397. static struct clk_hw_onecell_data sun8i_v3s_hw_clks = {
  398. .hws = {
  399. [CLK_PLL_CPU] = &pll_cpu_clk.common.hw,
  400. [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
  401. [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
  402. [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
  403. [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
  404. [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw,
  405. [CLK_PLL_VIDEO] = &pll_video_clk.common.hw,
  406. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  407. [CLK_PLL_DDR] = &pll_ddr_clk.common.hw,
  408. [CLK_PLL_PERIPH0] = &pll_periph0_clk.common.hw,
  409. [CLK_PLL_PERIPH0_2X] = &pll_periph0_2x_clk.hw,
  410. [CLK_PLL_ISP] = &pll_isp_clk.common.hw,
  411. [CLK_PLL_PERIPH1] = &pll_periph1_clk.common.hw,
  412. [CLK_CPU] = &cpu_clk.common.hw,
  413. [CLK_AXI] = &axi_clk.common.hw,
  414. [CLK_AHB1] = &ahb1_clk.common.hw,
  415. [CLK_APB1] = &apb1_clk.common.hw,
  416. [CLK_APB2] = &apb2_clk.common.hw,
  417. [CLK_AHB2] = &ahb2_clk.common.hw,
  418. [CLK_BUS_CE] = &bus_ce_clk.common.hw,
  419. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  420. [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw,
  421. [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw,
  422. [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw,
  423. [CLK_BUS_DRAM] = &bus_dram_clk.common.hw,
  424. [CLK_BUS_EMAC] = &bus_emac_clk.common.hw,
  425. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  426. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  427. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  428. [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw,
  429. [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw,
  430. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  431. [CLK_BUS_TCON0] = &bus_tcon0_clk.common.hw,
  432. [CLK_BUS_CSI] = &bus_csi_clk.common.hw,
  433. [CLK_BUS_DE] = &bus_de_clk.common.hw,
  434. [CLK_BUS_CODEC] = &bus_codec_clk.common.hw,
  435. [CLK_BUS_PIO] = &bus_pio_clk.common.hw,
  436. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  437. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  438. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  439. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  440. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  441. [CLK_BUS_EPHY] = &bus_ephy_clk.common.hw,
  442. [CLK_BUS_DBG] = &bus_dbg_clk.common.hw,
  443. [CLK_MMC0] = &mmc0_clk.common.hw,
  444. [CLK_MMC0_SAMPLE] = &mmc0_sample_clk.common.hw,
  445. [CLK_MMC0_OUTPUT] = &mmc0_output_clk.common.hw,
  446. [CLK_MMC1] = &mmc1_clk.common.hw,
  447. [CLK_MMC1_SAMPLE] = &mmc1_sample_clk.common.hw,
  448. [CLK_MMC1_OUTPUT] = &mmc1_output_clk.common.hw,
  449. [CLK_CE] = &ce_clk.common.hw,
  450. [CLK_SPI0] = &spi0_clk.common.hw,
  451. [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
  452. [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
  453. [CLK_DRAM] = &dram_clk.common.hw,
  454. [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
  455. [CLK_DRAM_CSI] = &dram_csi_clk.common.hw,
  456. [CLK_DRAM_EHCI] = &dram_ehci_clk.common.hw,
  457. [CLK_DRAM_OHCI] = &dram_ohci_clk.common.hw,
  458. [CLK_DE] = &de_clk.common.hw,
  459. [CLK_TCON0] = &tcon_clk.common.hw,
  460. [CLK_CSI_MISC] = &csi_misc_clk.common.hw,
  461. [CLK_CSI0_MCLK] = &csi0_mclk_clk.common.hw,
  462. [CLK_CSI1_SCLK] = &csi1_sclk_clk.common.hw,
  463. [CLK_CSI1_MCLK] = &csi1_mclk_clk.common.hw,
  464. [CLK_VE] = &ve_clk.common.hw,
  465. [CLK_AC_DIG] = &ac_dig_clk.common.hw,
  466. [CLK_AVS] = &avs_clk.common.hw,
  467. [CLK_MBUS] = &mbus_clk.common.hw,
  468. [CLK_MIPI_CSI] = &mipi_csi_clk.common.hw,
  469. },
  470. .num = CLK_NUMBER,
  471. };
  472. static struct ccu_reset_map sun8i_v3s_ccu_resets[] = {
  473. [RST_USB_PHY0] = { 0x0cc, BIT(0) },
  474. [RST_MBUS] = { 0x0fc, BIT(31) },
  475. [RST_BUS_CE] = { 0x2c0, BIT(5) },
  476. [RST_BUS_DMA] = { 0x2c0, BIT(6) },
  477. [RST_BUS_MMC0] = { 0x2c0, BIT(8) },
  478. [RST_BUS_MMC1] = { 0x2c0, BIT(9) },
  479. [RST_BUS_MMC2] = { 0x2c0, BIT(10) },
  480. [RST_BUS_DRAM] = { 0x2c0, BIT(14) },
  481. [RST_BUS_EMAC] = { 0x2c0, BIT(17) },
  482. [RST_BUS_HSTIMER] = { 0x2c0, BIT(19) },
  483. [RST_BUS_SPI0] = { 0x2c0, BIT(20) },
  484. [RST_BUS_OTG] = { 0x2c0, BIT(23) },
  485. [RST_BUS_EHCI0] = { 0x2c0, BIT(26) },
  486. [RST_BUS_OHCI0] = { 0x2c0, BIT(29) },
  487. [RST_BUS_VE] = { 0x2c4, BIT(0) },
  488. [RST_BUS_TCON0] = { 0x2c4, BIT(3) },
  489. [RST_BUS_CSI] = { 0x2c4, BIT(8) },
  490. [RST_BUS_DE] = { 0x2c4, BIT(12) },
  491. [RST_BUS_DBG] = { 0x2c4, BIT(31) },
  492. [RST_BUS_EPHY] = { 0x2c8, BIT(2) },
  493. [RST_BUS_CODEC] = { 0x2d0, BIT(0) },
  494. [RST_BUS_I2C0] = { 0x2d8, BIT(0) },
  495. [RST_BUS_I2C1] = { 0x2d8, BIT(1) },
  496. [RST_BUS_UART0] = { 0x2d8, BIT(16) },
  497. [RST_BUS_UART1] = { 0x2d8, BIT(17) },
  498. [RST_BUS_UART2] = { 0x2d8, BIT(18) },
  499. };
  500. static const struct sunxi_ccu_desc sun8i_v3s_ccu_desc = {
  501. .ccu_clks = sun8i_v3s_ccu_clks,
  502. .num_ccu_clks = ARRAY_SIZE(sun8i_v3s_ccu_clks),
  503. .hw_clks = &sun8i_v3s_hw_clks,
  504. .resets = sun8i_v3s_ccu_resets,
  505. .num_resets = ARRAY_SIZE(sun8i_v3s_ccu_resets),
  506. };
  507. static void __init sun8i_v3s_ccu_setup(struct device_node *node)
  508. {
  509. void __iomem *reg;
  510. u32 val;
  511. reg = of_io_request_and_map(node, 0, of_node_full_name(node));
  512. if (IS_ERR(reg)) {
  513. pr_err("%s: Could not map the clock registers\n",
  514. of_node_full_name(node));
  515. return;
  516. }
  517. /* Force the PLL-Audio-1x divider to 4 */
  518. val = readl(reg + SUN8I_V3S_PLL_AUDIO_REG);
  519. val &= ~GENMASK(19, 16);
  520. writel(val | (3 << 16), reg + SUN8I_V3S_PLL_AUDIO_REG);
  521. sunxi_ccu_probe(node, reg, &sun8i_v3s_ccu_desc);
  522. }
  523. CLK_OF_DECLARE(sun8i_v3s_ccu, "allwinner,sun8i-v3s-ccu",
  524. sun8i_v3s_ccu_setup);