ccu-sun50i-a64.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016 Maxime Ripard. All rights reserved.
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/io.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include "ccu_common.h"
  10. #include "ccu_reset.h"
  11. #include "ccu_div.h"
  12. #include "ccu_gate.h"
  13. #include "ccu_mp.h"
  14. #include "ccu_mult.h"
  15. #include "ccu_nk.h"
  16. #include "ccu_nkm.h"
  17. #include "ccu_nkmp.h"
  18. #include "ccu_nm.h"
  19. #include "ccu_phase.h"
  20. #include "ccu-sun50i-a64.h"
  21. static struct ccu_nkmp pll_cpux_clk = {
  22. .enable = BIT(31),
  23. .lock = BIT(28),
  24. .n = _SUNXI_CCU_MULT(8, 5),
  25. .k = _SUNXI_CCU_MULT(4, 2),
  26. .m = _SUNXI_CCU_DIV(0, 2),
  27. .p = _SUNXI_CCU_DIV_MAX(16, 2, 4),
  28. .common = {
  29. .reg = 0x000,
  30. .hw.init = CLK_HW_INIT("pll-cpux",
  31. "osc24M",
  32. &ccu_nkmp_ops,
  33. CLK_SET_RATE_UNGATE),
  34. },
  35. };
  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. * With sigma-delta modulation for fractional-N on the audio PLL,
  42. * we have to use specific dividers. This means the variable divider
  43. * can no longer be used, as the audio codec requests the exact clock
  44. * rates we support through this mechanism. So we now hard code the
  45. * variable divider to 1. This means the clock rates will no longer
  46. * match the clock names.
  47. */
  48. #define SUN50I_A64_PLL_AUDIO_REG 0x008
  49. static struct ccu_sdm_setting pll_audio_sdm_table[] = {
  50. { .rate = 22579200, .pattern = 0xc0010d84, .m = 8, .n = 7 },
  51. { .rate = 24576000, .pattern = 0xc000ac02, .m = 14, .n = 14 },
  52. };
  53. static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
  54. "osc24M", 0x008,
  55. 8, 7, /* N */
  56. 0, 5, /* M */
  57. pll_audio_sdm_table, BIT(24),
  58. 0x284, BIT(31),
  59. BIT(31), /* gate */
  60. BIT(28), /* lock */
  61. CLK_SET_RATE_UNGATE);
  62. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST(pll_video0_clk, "pll-video0",
  63. "osc24M", 0x010,
  64. 192000000, /* Minimum rate */
  65. 1008000000, /* Maximum rate */
  66. 8, 7, /* N */
  67. 0, 4, /* M */
  68. BIT(24), /* frac enable */
  69. BIT(25), /* frac select */
  70. 270000000, /* frac rate 0 */
  71. 297000000, /* frac rate 1 */
  72. BIT(31), /* gate */
  73. BIT(28), /* lock */
  74. CLK_SET_RATE_UNGATE);
  75. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve",
  76. "osc24M", 0x018,
  77. 8, 7, /* N */
  78. 0, 4, /* M */
  79. BIT(24), /* frac enable */
  80. BIT(25), /* frac select */
  81. 270000000, /* frac rate 0 */
  82. 297000000, /* frac rate 1 */
  83. BIT(31), /* gate */
  84. BIT(28), /* lock */
  85. CLK_SET_RATE_UNGATE);
  86. static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr0_clk, "pll-ddr0",
  87. "osc24M", 0x020,
  88. 8, 5, /* N */
  89. 4, 2, /* K */
  90. 0, 2, /* M */
  91. BIT(31), /* gate */
  92. BIT(28), /* lock */
  93. CLK_SET_RATE_UNGATE);
  94. static struct ccu_nk pll_periph0_clk = {
  95. .enable = BIT(31),
  96. .lock = BIT(28),
  97. .n = _SUNXI_CCU_MULT(8, 5),
  98. .k = _SUNXI_CCU_MULT_MIN(4, 2, 2),
  99. .fixed_post_div = 2,
  100. .common = {
  101. .reg = 0x028,
  102. .features = CCU_FEATURE_FIXED_POSTDIV,
  103. .hw.init = CLK_HW_INIT("pll-periph0", "osc24M",
  104. &ccu_nk_ops, CLK_SET_RATE_UNGATE),
  105. },
  106. };
  107. static struct ccu_nk pll_periph1_clk = {
  108. .enable = BIT(31),
  109. .lock = BIT(28),
  110. .n = _SUNXI_CCU_MULT(8, 5),
  111. .k = _SUNXI_CCU_MULT_MIN(4, 2, 2),
  112. .fixed_post_div = 2,
  113. .common = {
  114. .reg = 0x02c,
  115. .features = CCU_FEATURE_FIXED_POSTDIV,
  116. .hw.init = CLK_HW_INIT("pll-periph1", "osc24M",
  117. &ccu_nk_ops, CLK_SET_RATE_UNGATE),
  118. },
  119. };
  120. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video1_clk, "pll-video1",
  121. "osc24M", 0x030,
  122. 192000000, /* Minimum rate */
  123. 1008000000, /* Maximum rate */
  124. 8, 7, /* N */
  125. 0, 4, /* M */
  126. BIT(24), /* frac enable */
  127. BIT(25), /* frac select */
  128. 270000000, /* frac rate 0 */
  129. 297000000, /* frac rate 1 */
  130. BIT(31), /* gate */
  131. BIT(28), /* lock */
  132. CLK_SET_RATE_UNGATE);
  133. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_gpu_clk, "pll-gpu",
  134. "osc24M", 0x038,
  135. 8, 7, /* N */
  136. 0, 4, /* M */
  137. BIT(24), /* frac enable */
  138. BIT(25), /* frac select */
  139. 270000000, /* frac rate 0 */
  140. 297000000, /* frac rate 1 */
  141. BIT(31), /* gate */
  142. BIT(28), /* lock */
  143. CLK_SET_RATE_UNGATE);
  144. /*
  145. * The output function can be changed to something more complex that
  146. * we do not handle yet.
  147. *
  148. * Hardcode the mode so that we don't fall in that case.
  149. */
  150. #define SUN50I_A64_PLL_MIPI_REG 0x040
  151. static struct ccu_nkm pll_mipi_clk = {
  152. /*
  153. * The bit 23 and 22 are called "LDO{1,2}_EN" on the SoC's
  154. * user manual, and by experiments the PLL doesn't work without
  155. * these bits toggled.
  156. */
  157. .enable = BIT(31) | BIT(23) | BIT(22),
  158. .lock = BIT(28),
  159. .n = _SUNXI_CCU_MULT(8, 4),
  160. .k = _SUNXI_CCU_MULT_MIN(4, 2, 2),
  161. .m = _SUNXI_CCU_DIV(0, 4),
  162. .max_m_n_ratio = 3,
  163. .min_parent_m_ratio = 24000000,
  164. .common = {
  165. .reg = 0x040,
  166. .hw.init = CLK_HW_INIT("pll-mipi", "pll-video0",
  167. &ccu_nkm_ops,
  168. CLK_SET_RATE_UNGATE | CLK_SET_RATE_PARENT),
  169. .features = CCU_FEATURE_CLOSEST_RATE,
  170. .min_rate = 500000000,
  171. .max_rate = 1400000000,
  172. },
  173. };
  174. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_hsic_clk, "pll-hsic",
  175. "osc24M", 0x044,
  176. 8, 7, /* N */
  177. 0, 4, /* M */
  178. BIT(24), /* frac enable */
  179. BIT(25), /* frac select */
  180. 270000000, /* frac rate 0 */
  181. 297000000, /* frac rate 1 */
  182. BIT(31), /* gate */
  183. BIT(28), /* lock */
  184. CLK_SET_RATE_UNGATE);
  185. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_de_clk, "pll-de",
  186. "osc24M", 0x048,
  187. 8, 7, /* N */
  188. 0, 4, /* M */
  189. BIT(24), /* frac enable */
  190. BIT(25), /* frac select */
  191. 270000000, /* frac rate 0 */
  192. 297000000, /* frac rate 1 */
  193. BIT(31), /* gate */
  194. BIT(28), /* lock */
  195. CLK_SET_RATE_UNGATE);
  196. static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_ddr1_clk, "pll-ddr1",
  197. "osc24M", 0x04c,
  198. 8, 7, /* N */
  199. 0, 2, /* M */
  200. BIT(31), /* gate */
  201. BIT(28), /* lock */
  202. CLK_SET_RATE_UNGATE);
  203. static const char * const cpux_parents[] = { "osc32k", "osc24M",
  204. "pll-cpux", "pll-cpux" };
  205. static SUNXI_CCU_MUX(cpux_clk, "cpux", cpux_parents,
  206. 0x050, 16, 2, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
  207. static SUNXI_CCU_M(axi_clk, "axi", "cpux", 0x050, 0, 2, 0);
  208. static const char * const ahb1_parents[] = { "osc32k", "osc24M",
  209. "axi", "pll-periph0" };
  210. static const struct ccu_mux_var_prediv ahb1_predivs[] = {
  211. { .index = 3, .shift = 6, .width = 2 },
  212. };
  213. static struct ccu_div ahb1_clk = {
  214. .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
  215. .mux = {
  216. .shift = 12,
  217. .width = 2,
  218. .var_predivs = ahb1_predivs,
  219. .n_var_predivs = ARRAY_SIZE(ahb1_predivs),
  220. },
  221. .common = {
  222. .reg = 0x054,
  223. .features = CCU_FEATURE_VARIABLE_PREDIV,
  224. .hw.init = CLK_HW_INIT_PARENTS("ahb1",
  225. ahb1_parents,
  226. &ccu_div_ops,
  227. 0),
  228. },
  229. };
  230. static struct clk_div_table apb1_div_table[] = {
  231. { .val = 0, .div = 2 },
  232. { .val = 1, .div = 2 },
  233. { .val = 2, .div = 4 },
  234. { .val = 3, .div = 8 },
  235. { /* Sentinel */ },
  236. };
  237. static SUNXI_CCU_DIV_TABLE(apb1_clk, "apb1", "ahb1",
  238. 0x054, 8, 2, apb1_div_table, 0);
  239. static const char * const apb2_parents[] = { "osc32k", "osc24M",
  240. "pll-periph0-2x",
  241. "pll-periph0-2x" };
  242. static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", apb2_parents, 0x058,
  243. 0, 5, /* M */
  244. 16, 2, /* P */
  245. 24, 2, /* mux */
  246. 0);
  247. static const char * const ahb2_parents[] = { "ahb1", "pll-periph0" };
  248. static const struct ccu_mux_fixed_prediv ahb2_fixed_predivs[] = {
  249. { .index = 1, .div = 2 },
  250. };
  251. static struct ccu_mux ahb2_clk = {
  252. .mux = {
  253. .shift = 0,
  254. .width = 1,
  255. .fixed_predivs = ahb2_fixed_predivs,
  256. .n_predivs = ARRAY_SIZE(ahb2_fixed_predivs),
  257. },
  258. .common = {
  259. .reg = 0x05c,
  260. .features = CCU_FEATURE_FIXED_PREDIV,
  261. .hw.init = CLK_HW_INIT_PARENTS("ahb2",
  262. ahb2_parents,
  263. &ccu_mux_ops,
  264. 0),
  265. },
  266. };
  267. static SUNXI_CCU_GATE(bus_mipi_dsi_clk, "bus-mipi-dsi", "ahb1",
  268. 0x060, BIT(1), 0);
  269. static SUNXI_CCU_GATE(bus_ce_clk, "bus-ce", "ahb1",
  270. 0x060, BIT(5), 0);
  271. static SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "ahb1",
  272. 0x060, BIT(6), 0);
  273. static SUNXI_CCU_GATE(bus_mmc0_clk, "bus-mmc0", "ahb1",
  274. 0x060, BIT(8), 0);
  275. static SUNXI_CCU_GATE(bus_mmc1_clk, "bus-mmc1", "ahb1",
  276. 0x060, BIT(9), 0);
  277. static SUNXI_CCU_GATE(bus_mmc2_clk, "bus-mmc2", "ahb1",
  278. 0x060, BIT(10), 0);
  279. static SUNXI_CCU_GATE(bus_nand_clk, "bus-nand", "ahb1",
  280. 0x060, BIT(13), 0);
  281. static SUNXI_CCU_GATE(bus_dram_clk, "bus-dram", "ahb1",
  282. 0x060, BIT(14), 0);
  283. static SUNXI_CCU_GATE(bus_emac_clk, "bus-emac", "ahb2",
  284. 0x060, BIT(17), 0);
  285. static SUNXI_CCU_GATE(bus_ts_clk, "bus-ts", "ahb1",
  286. 0x060, BIT(18), 0);
  287. static SUNXI_CCU_GATE(bus_hstimer_clk, "bus-hstimer", "ahb1",
  288. 0x060, BIT(19), 0);
  289. static SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb1",
  290. 0x060, BIT(20), 0);
  291. static SUNXI_CCU_GATE(bus_spi1_clk, "bus-spi1", "ahb1",
  292. 0x060, BIT(21), 0);
  293. static SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb1",
  294. 0x060, BIT(23), 0);
  295. static SUNXI_CCU_GATE(bus_ehci0_clk, "bus-ehci0", "ahb1",
  296. 0x060, BIT(24), 0);
  297. static SUNXI_CCU_GATE(bus_ehci1_clk, "bus-ehci1", "ahb2",
  298. 0x060, BIT(25), 0);
  299. static SUNXI_CCU_GATE(bus_ohci0_clk, "bus-ohci0", "ahb1",
  300. 0x060, BIT(28), 0);
  301. static SUNXI_CCU_GATE(bus_ohci1_clk, "bus-ohci1", "ahb2",
  302. 0x060, BIT(29), 0);
  303. static SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "ahb1",
  304. 0x064, BIT(0), 0);
  305. static SUNXI_CCU_GATE(bus_tcon0_clk, "bus-tcon0", "ahb1",
  306. 0x064, BIT(3), 0);
  307. static SUNXI_CCU_GATE(bus_tcon1_clk, "bus-tcon1", "ahb1",
  308. 0x064, BIT(4), 0);
  309. static SUNXI_CCU_GATE(bus_deinterlace_clk, "bus-deinterlace", "ahb1",
  310. 0x064, BIT(5), 0);
  311. static SUNXI_CCU_GATE(bus_csi_clk, "bus-csi", "ahb1",
  312. 0x064, BIT(8), 0);
  313. static SUNXI_CCU_GATE(bus_hdmi_clk, "bus-hdmi", "ahb1",
  314. 0x064, BIT(11), 0);
  315. static SUNXI_CCU_GATE(bus_de_clk, "bus-de", "ahb1",
  316. 0x064, BIT(12), 0);
  317. static SUNXI_CCU_GATE(bus_gpu_clk, "bus-gpu", "ahb1",
  318. 0x064, BIT(20), 0);
  319. static SUNXI_CCU_GATE(bus_msgbox_clk, "bus-msgbox", "ahb1",
  320. 0x064, BIT(21), 0);
  321. static SUNXI_CCU_GATE(bus_spinlock_clk, "bus-spinlock", "ahb1",
  322. 0x064, BIT(22), 0);
  323. static SUNXI_CCU_GATE(bus_codec_clk, "bus-codec", "apb1",
  324. 0x068, BIT(0), 0);
  325. static SUNXI_CCU_GATE(bus_spdif_clk, "bus-spdif", "apb1",
  326. 0x068, BIT(1), 0);
  327. static SUNXI_CCU_GATE(bus_pio_clk, "bus-pio", "apb1",
  328. 0x068, BIT(5), 0);
  329. static SUNXI_CCU_GATE(bus_ths_clk, "bus-ths", "apb1",
  330. 0x068, BIT(8), 0);
  331. static SUNXI_CCU_GATE(bus_i2s0_clk, "bus-i2s0", "apb1",
  332. 0x068, BIT(12), 0);
  333. static SUNXI_CCU_GATE(bus_i2s1_clk, "bus-i2s1", "apb1",
  334. 0x068, BIT(13), 0);
  335. static SUNXI_CCU_GATE(bus_i2s2_clk, "bus-i2s2", "apb1",
  336. 0x068, BIT(14), 0);
  337. static SUNXI_CCU_GATE(bus_i2c0_clk, "bus-i2c0", "apb2",
  338. 0x06c, BIT(0), 0);
  339. static SUNXI_CCU_GATE(bus_i2c1_clk, "bus-i2c1", "apb2",
  340. 0x06c, BIT(1), 0);
  341. static SUNXI_CCU_GATE(bus_i2c2_clk, "bus-i2c2", "apb2",
  342. 0x06c, BIT(2), 0);
  343. static SUNXI_CCU_GATE(bus_scr_clk, "bus-scr", "apb2",
  344. 0x06c, BIT(5), 0);
  345. static SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb2",
  346. 0x06c, BIT(16), 0);
  347. static SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb2",
  348. 0x06c, BIT(17), 0);
  349. static SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb2",
  350. 0x06c, BIT(18), 0);
  351. static SUNXI_CCU_GATE(bus_uart3_clk, "bus-uart3", "apb2",
  352. 0x06c, BIT(19), 0);
  353. static SUNXI_CCU_GATE(bus_uart4_clk, "bus-uart4", "apb2",
  354. 0x06c, BIT(20), 0);
  355. static SUNXI_CCU_GATE(bus_dbg_clk, "bus-dbg", "ahb1",
  356. 0x070, BIT(7), 0);
  357. static struct clk_div_table ths_div_table[] = {
  358. { .val = 0, .div = 1 },
  359. { .val = 1, .div = 2 },
  360. { .val = 2, .div = 4 },
  361. { .val = 3, .div = 6 },
  362. { /* Sentinel */ },
  363. };
  364. static const char * const ths_parents[] = { "osc24M" };
  365. static struct ccu_div ths_clk = {
  366. .enable = BIT(31),
  367. .div = _SUNXI_CCU_DIV_TABLE(0, 2, ths_div_table),
  368. .mux = _SUNXI_CCU_MUX(24, 2),
  369. .common = {
  370. .reg = 0x074,
  371. .hw.init = CLK_HW_INIT_PARENTS("ths",
  372. ths_parents,
  373. &ccu_div_ops,
  374. 0),
  375. },
  376. };
  377. static const char * const mod0_default_parents[] = { "osc24M", "pll-periph0",
  378. "pll-periph1" };
  379. static SUNXI_CCU_MP_WITH_MUX_GATE(nand_clk, "nand", mod0_default_parents, 0x080,
  380. 0, 4, /* M */
  381. 16, 2, /* P */
  382. 24, 2, /* mux */
  383. BIT(31), /* gate */
  384. 0);
  385. /*
  386. * MMC clocks are the new timing mode (see A83T & H3) variety, but without
  387. * the mode switch. This means they have a 2x post divider between the clock
  388. * and the MMC module. This is not documented in the manual, but is taken
  389. * into consideration when setting the mmc module clocks in the BSP kernel.
  390. * Without it, MMC performance is degraded.
  391. *
  392. * We model it here to be consistent with other SoCs supporting this mode.
  393. * The alternative would be to add the 2x multiplier when setting the MMC
  394. * module clock in the MMC driver, just for the A64.
  395. */
  396. static const char * const mmc_default_parents[] = { "osc24M", "pll-periph0-2x",
  397. "pll-periph1-2x" };
  398. static SUNXI_CCU_MP_WITH_MUX_GATE_POSTDIV(mmc0_clk, "mmc0",
  399. mmc_default_parents, 0x088,
  400. 0, 4, /* M */
  401. 16, 2, /* P */
  402. 24, 2, /* mux */
  403. BIT(31), /* gate */
  404. 2, /* post-div */
  405. 0);
  406. static SUNXI_CCU_MP_WITH_MUX_GATE_POSTDIV(mmc1_clk, "mmc1",
  407. mmc_default_parents, 0x08c,
  408. 0, 4, /* M */
  409. 16, 2, /* P */
  410. 24, 2, /* mux */
  411. BIT(31), /* gate */
  412. 2, /* post-div */
  413. 0);
  414. static SUNXI_CCU_MP_WITH_MUX_GATE_POSTDIV(mmc2_clk, "mmc2",
  415. mmc_default_parents, 0x090,
  416. 0, 4, /* M */
  417. 16, 2, /* P */
  418. 24, 2, /* mux */
  419. BIT(31), /* gate */
  420. 2, /* post-div */
  421. 0);
  422. static const char * const ts_parents[] = { "osc24M", "pll-periph0", };
  423. static SUNXI_CCU_MP_WITH_MUX_GATE(ts_clk, "ts", ts_parents, 0x098,
  424. 0, 4, /* M */
  425. 16, 2, /* P */
  426. 24, 4, /* mux */
  427. BIT(31), /* gate */
  428. 0);
  429. static SUNXI_CCU_MP_WITH_MUX_GATE(ce_clk, "ce", mmc_default_parents, 0x09c,
  430. 0, 4, /* M */
  431. 16, 2, /* P */
  432. 24, 2, /* mux */
  433. BIT(31), /* gate */
  434. 0);
  435. static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0,
  436. 0, 4, /* M */
  437. 16, 2, /* P */
  438. 24, 2, /* mux */
  439. BIT(31), /* gate */
  440. 0);
  441. static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", mod0_default_parents, 0x0a4,
  442. 0, 4, /* M */
  443. 16, 2, /* P */
  444. 24, 2, /* mux */
  445. BIT(31), /* gate */
  446. 0);
  447. static const char * const i2s_parents[] = { "pll-audio-8x", "pll-audio-4x",
  448. "pll-audio-2x", "pll-audio" };
  449. static SUNXI_CCU_MUX_WITH_GATE(i2s0_clk, "i2s0", i2s_parents,
  450. 0x0b0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  451. static SUNXI_CCU_MUX_WITH_GATE(i2s1_clk, "i2s1", i2s_parents,
  452. 0x0b4, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  453. static SUNXI_CCU_MUX_WITH_GATE(i2s2_clk, "i2s2", i2s_parents,
  454. 0x0b8, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  455. static SUNXI_CCU_M_WITH_GATE(spdif_clk, "spdif", "pll-audio",
  456. 0x0c0, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  457. static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M",
  458. 0x0cc, BIT(8), 0);
  459. static SUNXI_CCU_GATE(usb_phy1_clk, "usb-phy1", "osc24M",
  460. 0x0cc, BIT(9), 0);
  461. static SUNXI_CCU_GATE(usb_hsic_clk, "usb-hsic", "pll-hsic",
  462. 0x0cc, BIT(10), 0);
  463. static SUNXI_CCU_GATE(usb_hsic_12m_clk, "usb-hsic-12M", "osc12M",
  464. 0x0cc, BIT(11), 0);
  465. static SUNXI_CCU_GATE(usb_ohci0_clk, "usb-ohci0", "osc12M",
  466. 0x0cc, BIT(16), 0);
  467. static SUNXI_CCU_GATE(usb_ohci1_clk, "usb-ohci1", "usb-ohci0",
  468. 0x0cc, BIT(17), 0);
  469. static const char * const dram_parents[] = { "pll-ddr0", "pll-ddr1" };
  470. static SUNXI_CCU_M_WITH_MUX(dram_clk, "dram", dram_parents,
  471. 0x0f4, 0, 4, 20, 2, CLK_IS_CRITICAL);
  472. static SUNXI_CCU_GATE(dram_ve_clk, "dram-ve", "dram",
  473. 0x100, BIT(0), 0);
  474. static SUNXI_CCU_GATE(dram_csi_clk, "dram-csi", "dram",
  475. 0x100, BIT(1), 0);
  476. static SUNXI_CCU_GATE(dram_deinterlace_clk, "dram-deinterlace", "dram",
  477. 0x100, BIT(2), 0);
  478. static SUNXI_CCU_GATE(dram_ts_clk, "dram-ts", "dram",
  479. 0x100, BIT(3), 0);
  480. static const char * const de_parents[] = { "pll-periph0-2x", "pll-de" };
  481. static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents,
  482. 0x104, 0, 4, 24, 3, BIT(31),
  483. CLK_SET_RATE_PARENT);
  484. /*
  485. * Experiments showed that RGB output requires pll-video0-2x, while DSI
  486. * requires pll-mipi. It will not work with incorrect clock, the screen will
  487. * be blank.
  488. * sun50i-a64.dtsi assigns pll-mipi as TCON0 parent by default
  489. */
  490. static const char * const tcon0_parents[] = { "pll-mipi", "pll-video0-2x" };
  491. static const u8 tcon0_table[] = { 0, 2, };
  492. static SUNXI_CCU_MUX_TABLE_WITH_GATE_CLOSEST(tcon0_clk, "tcon0", tcon0_parents,
  493. tcon0_table, 0x118, 24, 3, BIT(31),
  494. CLK_SET_RATE_PARENT | CLK_SET_RATE_NO_REPARENT);
  495. static const char * const tcon1_parents[] = { "pll-video0", "pll-video1" };
  496. static const u8 tcon1_table[] = { 0, 2, };
  497. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE_CLOSEST(tcon1_clk, "tcon1", tcon1_parents,
  498. tcon1_table, 0x11c,
  499. 0, 4, /* M */
  500. 24, 2, /* mux */
  501. BIT(31), /* gate */
  502. CLK_SET_RATE_PARENT);
  503. static const char * const deinterlace_parents[] = { "pll-periph0", "pll-periph1" };
  504. static SUNXI_CCU_M_WITH_MUX_GATE(deinterlace_clk, "deinterlace", deinterlace_parents,
  505. 0x124, 0, 4, 24, 3, BIT(31), 0);
  506. static SUNXI_CCU_GATE(csi_misc_clk, "csi-misc", "osc24M",
  507. 0x130, BIT(31), 0);
  508. static const char * const csi_sclk_parents[] = { "pll-periph0", "pll-periph1" };
  509. static SUNXI_CCU_M_WITH_MUX_GATE(csi_sclk_clk, "csi-sclk", csi_sclk_parents,
  510. 0x134, 16, 4, 24, 3, BIT(31), 0);
  511. static const char * const csi_mclk_parents[] = { "osc24M", "pll-video1", "pll-periph1" };
  512. static SUNXI_CCU_M_WITH_MUX_GATE(csi_mclk_clk, "csi-mclk", csi_mclk_parents,
  513. 0x134, 0, 5, 8, 3, BIT(15), 0);
  514. static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve",
  515. 0x13c, 16, 3, BIT(31), CLK_SET_RATE_PARENT);
  516. static SUNXI_CCU_GATE(ac_dig_clk, "ac-dig", "pll-audio",
  517. 0x140, BIT(31), CLK_SET_RATE_PARENT);
  518. static SUNXI_CCU_GATE(ac_dig_4x_clk, "ac-dig-4x", "pll-audio-4x",
  519. 0x140, BIT(30), CLK_SET_RATE_PARENT);
  520. static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M",
  521. 0x144, BIT(31), 0);
  522. static const char * const hdmi_parents[] = { "pll-video0", "pll-video1" };
  523. static SUNXI_CCU_M_WITH_MUX_GATE_CLOSEST(hdmi_clk, "hdmi", hdmi_parents,
  524. 0x150, 0, 4, 24, 2, BIT(31), CLK_SET_RATE_PARENT);
  525. static SUNXI_CCU_GATE(hdmi_ddc_clk, "hdmi-ddc", "osc24M",
  526. 0x154, BIT(31), 0);
  527. static const char * const mbus_parents[] = { "osc24M", "pll-periph0-2x",
  528. "pll-ddr0", "pll-ddr1" };
  529. static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents,
  530. 0x15c, 0, 3, 24, 2, BIT(31), CLK_IS_CRITICAL);
  531. static const char * const dsi_dphy_parents[] = { "pll-video0", "pll-periph0" };
  532. static const u8 dsi_dphy_table[] = { 0, 2, };
  533. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE_CLOSEST(dsi_dphy_clk, "dsi-dphy",
  534. dsi_dphy_parents, dsi_dphy_table,
  535. 0x168, 0, 4, 8, 2, BIT(15), CLK_SET_RATE_PARENT);
  536. static SUNXI_CCU_M_WITH_GATE(gpu_clk, "gpu", "pll-gpu",
  537. 0x1a0, 0, 3, BIT(31), CLK_SET_RATE_PARENT);
  538. /* Fixed Factor clocks */
  539. static CLK_FIXED_FACTOR_FW_NAME(osc12M_clk, "osc12M", "hosc", 2, 1, 0);
  540. static const struct clk_hw *clk_parent_pll_audio[] = {
  541. &pll_audio_base_clk.common.hw
  542. };
  543. /* We hardcode the divider to 1 for now */
  544. static CLK_FIXED_FACTOR_HWS(pll_audio_clk, "pll-audio",
  545. clk_parent_pll_audio,
  546. 1, 1, CLK_SET_RATE_PARENT);
  547. static CLK_FIXED_FACTOR_HWS(pll_audio_2x_clk, "pll-audio-2x",
  548. clk_parent_pll_audio,
  549. 2, 1, CLK_SET_RATE_PARENT);
  550. static CLK_FIXED_FACTOR_HWS(pll_audio_4x_clk, "pll-audio-4x",
  551. clk_parent_pll_audio,
  552. 1, 1, CLK_SET_RATE_PARENT);
  553. static CLK_FIXED_FACTOR_HWS(pll_audio_8x_clk, "pll-audio-8x",
  554. clk_parent_pll_audio,
  555. 1, 2, CLK_SET_RATE_PARENT);
  556. static CLK_FIXED_FACTOR_HW(pll_periph0_2x_clk, "pll-periph0-2x",
  557. &pll_periph0_clk.common.hw,
  558. 1, 2, 0);
  559. static CLK_FIXED_FACTOR_HW(pll_periph1_2x_clk, "pll-periph1-2x",
  560. &pll_periph1_clk.common.hw,
  561. 1, 2, 0);
  562. static CLK_FIXED_FACTOR_HW(pll_video0_2x_clk, "pll-video0-2x",
  563. &pll_video0_clk.common.hw,
  564. 1, 2, CLK_SET_RATE_PARENT);
  565. static struct ccu_common *sun50i_a64_ccu_clks[] = {
  566. &pll_cpux_clk.common,
  567. &pll_audio_base_clk.common,
  568. &pll_video0_clk.common,
  569. &pll_ve_clk.common,
  570. &pll_ddr0_clk.common,
  571. &pll_periph0_clk.common,
  572. &pll_periph1_clk.common,
  573. &pll_video1_clk.common,
  574. &pll_gpu_clk.common,
  575. &pll_mipi_clk.common,
  576. &pll_hsic_clk.common,
  577. &pll_de_clk.common,
  578. &pll_ddr1_clk.common,
  579. &cpux_clk.common,
  580. &axi_clk.common,
  581. &ahb1_clk.common,
  582. &apb1_clk.common,
  583. &apb2_clk.common,
  584. &ahb2_clk.common,
  585. &bus_mipi_dsi_clk.common,
  586. &bus_ce_clk.common,
  587. &bus_dma_clk.common,
  588. &bus_mmc0_clk.common,
  589. &bus_mmc1_clk.common,
  590. &bus_mmc2_clk.common,
  591. &bus_nand_clk.common,
  592. &bus_dram_clk.common,
  593. &bus_emac_clk.common,
  594. &bus_ts_clk.common,
  595. &bus_hstimer_clk.common,
  596. &bus_spi0_clk.common,
  597. &bus_spi1_clk.common,
  598. &bus_otg_clk.common,
  599. &bus_ehci0_clk.common,
  600. &bus_ehci1_clk.common,
  601. &bus_ohci0_clk.common,
  602. &bus_ohci1_clk.common,
  603. &bus_ve_clk.common,
  604. &bus_tcon0_clk.common,
  605. &bus_tcon1_clk.common,
  606. &bus_deinterlace_clk.common,
  607. &bus_csi_clk.common,
  608. &bus_hdmi_clk.common,
  609. &bus_de_clk.common,
  610. &bus_gpu_clk.common,
  611. &bus_msgbox_clk.common,
  612. &bus_spinlock_clk.common,
  613. &bus_codec_clk.common,
  614. &bus_spdif_clk.common,
  615. &bus_pio_clk.common,
  616. &bus_ths_clk.common,
  617. &bus_i2s0_clk.common,
  618. &bus_i2s1_clk.common,
  619. &bus_i2s2_clk.common,
  620. &bus_i2c0_clk.common,
  621. &bus_i2c1_clk.common,
  622. &bus_i2c2_clk.common,
  623. &bus_scr_clk.common,
  624. &bus_uart0_clk.common,
  625. &bus_uart1_clk.common,
  626. &bus_uart2_clk.common,
  627. &bus_uart3_clk.common,
  628. &bus_uart4_clk.common,
  629. &bus_dbg_clk.common,
  630. &ths_clk.common,
  631. &nand_clk.common,
  632. &mmc0_clk.common,
  633. &mmc1_clk.common,
  634. &mmc2_clk.common,
  635. &ts_clk.common,
  636. &ce_clk.common,
  637. &spi0_clk.common,
  638. &spi1_clk.common,
  639. &i2s0_clk.common,
  640. &i2s1_clk.common,
  641. &i2s2_clk.common,
  642. &spdif_clk.common,
  643. &usb_phy0_clk.common,
  644. &usb_phy1_clk.common,
  645. &usb_hsic_clk.common,
  646. &usb_hsic_12m_clk.common,
  647. &usb_ohci0_clk.common,
  648. &usb_ohci1_clk.common,
  649. &dram_clk.common,
  650. &dram_ve_clk.common,
  651. &dram_csi_clk.common,
  652. &dram_deinterlace_clk.common,
  653. &dram_ts_clk.common,
  654. &de_clk.common,
  655. &tcon0_clk.common,
  656. &tcon1_clk.common,
  657. &deinterlace_clk.common,
  658. &csi_misc_clk.common,
  659. &csi_sclk_clk.common,
  660. &csi_mclk_clk.common,
  661. &ve_clk.common,
  662. &ac_dig_clk.common,
  663. &ac_dig_4x_clk.common,
  664. &avs_clk.common,
  665. &hdmi_clk.common,
  666. &hdmi_ddc_clk.common,
  667. &mbus_clk.common,
  668. &dsi_dphy_clk.common,
  669. &gpu_clk.common,
  670. };
  671. static struct clk_hw_onecell_data sun50i_a64_hw_clks = {
  672. .hws = {
  673. [CLK_OSC_12M] = &osc12M_clk.hw,
  674. [CLK_PLL_CPUX] = &pll_cpux_clk.common.hw,
  675. [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
  676. [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
  677. [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
  678. [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
  679. [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw,
  680. [CLK_PLL_VIDEO0] = &pll_video0_clk.common.hw,
  681. [CLK_PLL_VIDEO0_2X] = &pll_video0_2x_clk.hw,
  682. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  683. [CLK_PLL_DDR0] = &pll_ddr0_clk.common.hw,
  684. [CLK_PLL_PERIPH0] = &pll_periph0_clk.common.hw,
  685. [CLK_PLL_PERIPH0_2X] = &pll_periph0_2x_clk.hw,
  686. [CLK_PLL_PERIPH1] = &pll_periph1_clk.common.hw,
  687. [CLK_PLL_PERIPH1_2X] = &pll_periph1_2x_clk.hw,
  688. [CLK_PLL_VIDEO1] = &pll_video1_clk.common.hw,
  689. [CLK_PLL_GPU] = &pll_gpu_clk.common.hw,
  690. [CLK_PLL_MIPI] = &pll_mipi_clk.common.hw,
  691. [CLK_PLL_HSIC] = &pll_hsic_clk.common.hw,
  692. [CLK_PLL_DE] = &pll_de_clk.common.hw,
  693. [CLK_PLL_DDR1] = &pll_ddr1_clk.common.hw,
  694. [CLK_CPUX] = &cpux_clk.common.hw,
  695. [CLK_AXI] = &axi_clk.common.hw,
  696. [CLK_AHB1] = &ahb1_clk.common.hw,
  697. [CLK_APB1] = &apb1_clk.common.hw,
  698. [CLK_APB2] = &apb2_clk.common.hw,
  699. [CLK_AHB2] = &ahb2_clk.common.hw,
  700. [CLK_BUS_MIPI_DSI] = &bus_mipi_dsi_clk.common.hw,
  701. [CLK_BUS_CE] = &bus_ce_clk.common.hw,
  702. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  703. [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw,
  704. [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw,
  705. [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw,
  706. [CLK_BUS_NAND] = &bus_nand_clk.common.hw,
  707. [CLK_BUS_DRAM] = &bus_dram_clk.common.hw,
  708. [CLK_BUS_EMAC] = &bus_emac_clk.common.hw,
  709. [CLK_BUS_TS] = &bus_ts_clk.common.hw,
  710. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  711. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  712. [CLK_BUS_SPI1] = &bus_spi1_clk.common.hw,
  713. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  714. [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw,
  715. [CLK_BUS_EHCI1] = &bus_ehci1_clk.common.hw,
  716. [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw,
  717. [CLK_BUS_OHCI1] = &bus_ohci1_clk.common.hw,
  718. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  719. [CLK_BUS_TCON0] = &bus_tcon0_clk.common.hw,
  720. [CLK_BUS_TCON1] = &bus_tcon1_clk.common.hw,
  721. [CLK_BUS_DEINTERLACE] = &bus_deinterlace_clk.common.hw,
  722. [CLK_BUS_CSI] = &bus_csi_clk.common.hw,
  723. [CLK_BUS_HDMI] = &bus_hdmi_clk.common.hw,
  724. [CLK_BUS_DE] = &bus_de_clk.common.hw,
  725. [CLK_BUS_GPU] = &bus_gpu_clk.common.hw,
  726. [CLK_BUS_MSGBOX] = &bus_msgbox_clk.common.hw,
  727. [CLK_BUS_SPINLOCK] = &bus_spinlock_clk.common.hw,
  728. [CLK_BUS_CODEC] = &bus_codec_clk.common.hw,
  729. [CLK_BUS_SPDIF] = &bus_spdif_clk.common.hw,
  730. [CLK_BUS_PIO] = &bus_pio_clk.common.hw,
  731. [CLK_BUS_THS] = &bus_ths_clk.common.hw,
  732. [CLK_BUS_I2S0] = &bus_i2s0_clk.common.hw,
  733. [CLK_BUS_I2S1] = &bus_i2s1_clk.common.hw,
  734. [CLK_BUS_I2S2] = &bus_i2s2_clk.common.hw,
  735. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  736. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  737. [CLK_BUS_I2C2] = &bus_i2c2_clk.common.hw,
  738. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  739. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  740. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  741. [CLK_BUS_UART3] = &bus_uart3_clk.common.hw,
  742. [CLK_BUS_UART4] = &bus_uart4_clk.common.hw,
  743. [CLK_BUS_SCR] = &bus_scr_clk.common.hw,
  744. [CLK_BUS_DBG] = &bus_dbg_clk.common.hw,
  745. [CLK_THS] = &ths_clk.common.hw,
  746. [CLK_NAND] = &nand_clk.common.hw,
  747. [CLK_MMC0] = &mmc0_clk.common.hw,
  748. [CLK_MMC1] = &mmc1_clk.common.hw,
  749. [CLK_MMC2] = &mmc2_clk.common.hw,
  750. [CLK_TS] = &ts_clk.common.hw,
  751. [CLK_CE] = &ce_clk.common.hw,
  752. [CLK_SPI0] = &spi0_clk.common.hw,
  753. [CLK_SPI1] = &spi1_clk.common.hw,
  754. [CLK_I2S0] = &i2s0_clk.common.hw,
  755. [CLK_I2S1] = &i2s1_clk.common.hw,
  756. [CLK_I2S2] = &i2s2_clk.common.hw,
  757. [CLK_SPDIF] = &spdif_clk.common.hw,
  758. [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
  759. [CLK_USB_PHY1] = &usb_phy1_clk.common.hw,
  760. [CLK_USB_HSIC] = &usb_hsic_clk.common.hw,
  761. [CLK_USB_HSIC_12M] = &usb_hsic_12m_clk.common.hw,
  762. [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
  763. [CLK_USB_OHCI1] = &usb_ohci1_clk.common.hw,
  764. [CLK_DRAM] = &dram_clk.common.hw,
  765. [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
  766. [CLK_DRAM_CSI] = &dram_csi_clk.common.hw,
  767. [CLK_DRAM_DEINTERLACE] = &dram_deinterlace_clk.common.hw,
  768. [CLK_DRAM_TS] = &dram_ts_clk.common.hw,
  769. [CLK_DE] = &de_clk.common.hw,
  770. [CLK_TCON0] = &tcon0_clk.common.hw,
  771. [CLK_TCON1] = &tcon1_clk.common.hw,
  772. [CLK_DEINTERLACE] = &deinterlace_clk.common.hw,
  773. [CLK_CSI_MISC] = &csi_misc_clk.common.hw,
  774. [CLK_CSI_SCLK] = &csi_sclk_clk.common.hw,
  775. [CLK_CSI_MCLK] = &csi_mclk_clk.common.hw,
  776. [CLK_VE] = &ve_clk.common.hw,
  777. [CLK_AC_DIG] = &ac_dig_clk.common.hw,
  778. [CLK_AC_DIG_4X] = &ac_dig_4x_clk.common.hw,
  779. [CLK_AVS] = &avs_clk.common.hw,
  780. [CLK_HDMI] = &hdmi_clk.common.hw,
  781. [CLK_HDMI_DDC] = &hdmi_ddc_clk.common.hw,
  782. [CLK_MBUS] = &mbus_clk.common.hw,
  783. [CLK_DSI_DPHY] = &dsi_dphy_clk.common.hw,
  784. [CLK_GPU] = &gpu_clk.common.hw,
  785. },
  786. .num = CLK_NUMBER,
  787. };
  788. static struct ccu_reset_map sun50i_a64_ccu_resets[] = {
  789. [RST_USB_PHY0] = { 0x0cc, BIT(0) },
  790. [RST_USB_PHY1] = { 0x0cc, BIT(1) },
  791. [RST_USB_HSIC] = { 0x0cc, BIT(2) },
  792. [RST_DRAM] = { 0x0f4, BIT(31) },
  793. [RST_MBUS] = { 0x0fc, BIT(31) },
  794. [RST_BUS_MIPI_DSI] = { 0x2c0, BIT(1) },
  795. [RST_BUS_CE] = { 0x2c0, BIT(5) },
  796. [RST_BUS_DMA] = { 0x2c0, BIT(6) },
  797. [RST_BUS_MMC0] = { 0x2c0, BIT(8) },
  798. [RST_BUS_MMC1] = { 0x2c0, BIT(9) },
  799. [RST_BUS_MMC2] = { 0x2c0, BIT(10) },
  800. [RST_BUS_NAND] = { 0x2c0, BIT(13) },
  801. [RST_BUS_DRAM] = { 0x2c0, BIT(14) },
  802. [RST_BUS_EMAC] = { 0x2c0, BIT(17) },
  803. [RST_BUS_TS] = { 0x2c0, BIT(18) },
  804. [RST_BUS_HSTIMER] = { 0x2c0, BIT(19) },
  805. [RST_BUS_SPI0] = { 0x2c0, BIT(20) },
  806. [RST_BUS_SPI1] = { 0x2c0, BIT(21) },
  807. [RST_BUS_OTG] = { 0x2c0, BIT(23) },
  808. [RST_BUS_EHCI0] = { 0x2c0, BIT(24) },
  809. [RST_BUS_EHCI1] = { 0x2c0, BIT(25) },
  810. [RST_BUS_OHCI0] = { 0x2c0, BIT(28) },
  811. [RST_BUS_OHCI1] = { 0x2c0, BIT(29) },
  812. [RST_BUS_VE] = { 0x2c4, BIT(0) },
  813. [RST_BUS_TCON0] = { 0x2c4, BIT(3) },
  814. [RST_BUS_TCON1] = { 0x2c4, BIT(4) },
  815. [RST_BUS_DEINTERLACE] = { 0x2c4, BIT(5) },
  816. [RST_BUS_CSI] = { 0x2c4, BIT(8) },
  817. [RST_BUS_HDMI0] = { 0x2c4, BIT(10) },
  818. [RST_BUS_HDMI1] = { 0x2c4, BIT(11) },
  819. [RST_BUS_DE] = { 0x2c4, BIT(12) },
  820. [RST_BUS_GPU] = { 0x2c4, BIT(20) },
  821. [RST_BUS_MSGBOX] = { 0x2c4, BIT(21) },
  822. [RST_BUS_SPINLOCK] = { 0x2c4, BIT(22) },
  823. [RST_BUS_DBG] = { 0x2c4, BIT(31) },
  824. [RST_BUS_LVDS] = { 0x2c8, BIT(0) },
  825. [RST_BUS_CODEC] = { 0x2d0, BIT(0) },
  826. [RST_BUS_SPDIF] = { 0x2d0, BIT(1) },
  827. [RST_BUS_THS] = { 0x2d0, BIT(8) },
  828. [RST_BUS_I2S0] = { 0x2d0, BIT(12) },
  829. [RST_BUS_I2S1] = { 0x2d0, BIT(13) },
  830. [RST_BUS_I2S2] = { 0x2d0, BIT(14) },
  831. [RST_BUS_I2C0] = { 0x2d8, BIT(0) },
  832. [RST_BUS_I2C1] = { 0x2d8, BIT(1) },
  833. [RST_BUS_I2C2] = { 0x2d8, BIT(2) },
  834. [RST_BUS_SCR] = { 0x2d8, BIT(5) },
  835. [RST_BUS_UART0] = { 0x2d8, BIT(16) },
  836. [RST_BUS_UART1] = { 0x2d8, BIT(17) },
  837. [RST_BUS_UART2] = { 0x2d8, BIT(18) },
  838. [RST_BUS_UART3] = { 0x2d8, BIT(19) },
  839. [RST_BUS_UART4] = { 0x2d8, BIT(20) },
  840. };
  841. static const struct sunxi_ccu_desc sun50i_a64_ccu_desc = {
  842. .ccu_clks = sun50i_a64_ccu_clks,
  843. .num_ccu_clks = ARRAY_SIZE(sun50i_a64_ccu_clks),
  844. .hw_clks = &sun50i_a64_hw_clks,
  845. .resets = sun50i_a64_ccu_resets,
  846. .num_resets = ARRAY_SIZE(sun50i_a64_ccu_resets),
  847. };
  848. static struct ccu_pll_nb sun50i_a64_pll_cpu_nb = {
  849. .common = &pll_cpux_clk.common,
  850. /* copy from pll_cpux_clk */
  851. .enable = BIT(31),
  852. .lock = BIT(28),
  853. };
  854. static struct ccu_mux_nb sun50i_a64_cpu_nb = {
  855. .common = &cpux_clk.common,
  856. .cm = &cpux_clk.mux,
  857. .delay_us = 1, /* > 8 clock cycles at 24 MHz */
  858. .bypass_index = 1, /* index of 24 MHz oscillator */
  859. };
  860. static int sun50i_a64_ccu_probe(struct platform_device *pdev)
  861. {
  862. void __iomem *reg;
  863. u32 val;
  864. int ret;
  865. reg = devm_platform_ioremap_resource(pdev, 0);
  866. if (IS_ERR(reg))
  867. return PTR_ERR(reg);
  868. /* Force the PLL-Audio-1x divider to 1 */
  869. val = readl(reg + SUN50I_A64_PLL_AUDIO_REG);
  870. val &= ~GENMASK(19, 16);
  871. writel(val | (0 << 16), reg + SUN50I_A64_PLL_AUDIO_REG);
  872. writel(0x515, reg + SUN50I_A64_PLL_MIPI_REG);
  873. ret = devm_sunxi_ccu_probe(&pdev->dev, reg, &sun50i_a64_ccu_desc);
  874. if (ret)
  875. return ret;
  876. /* Gate then ungate PLL CPU after any rate changes */
  877. ccu_pll_notifier_register(&sun50i_a64_pll_cpu_nb);
  878. /* Reparent CPU during PLL CPU rate changes */
  879. ccu_mux_notifier_register(pll_cpux_clk.common.hw.clk,
  880. &sun50i_a64_cpu_nb);
  881. return 0;
  882. }
  883. static const struct of_device_id sun50i_a64_ccu_ids[] = {
  884. { .compatible = "allwinner,sun50i-a64-ccu" },
  885. { }
  886. };
  887. MODULE_DEVICE_TABLE(of, sun50i_a64_ccu_ids);
  888. static struct platform_driver sun50i_a64_ccu_driver = {
  889. .probe = sun50i_a64_ccu_probe,
  890. .driver = {
  891. .name = "sun50i-a64-ccu",
  892. .suppress_bind_attrs = true,
  893. .of_match_table = sun50i_a64_ccu_ids,
  894. },
  895. };
  896. module_platform_driver(sun50i_a64_ccu_driver);
  897. MODULE_IMPORT_NS(SUNXI_CCU);
  898. MODULE_DESCRIPTION("Support for the Allwinner A64 CCU");
  899. MODULE_LICENSE("GPL");