ccu-sun8i-a83t.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017 Chen-Yu Tsai. 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_mux.h"
  15. #include "ccu_nkmp.h"
  16. #include "ccu_nm.h"
  17. #include "ccu_phase.h"
  18. #include "ccu-sun8i-a83t.h"
  19. #define CCU_SUN8I_A83T_LOCK_REG 0x20c
  20. /*
  21. * The CPU PLLs are actually NP clocks, with P being /1 or /4. However
  22. * P should only be used for output frequencies lower than 228 MHz.
  23. * Neither mainline Linux, U-boot, nor the vendor BSPs use these.
  24. *
  25. * For now we can just model it as a multiplier clock, and force P to /1.
  26. */
  27. #define SUN8I_A83T_PLL_C0CPUX_REG 0x000
  28. #define SUN8I_A83T_PLL_C1CPUX_REG 0x004
  29. static struct ccu_mult pll_c0cpux_clk = {
  30. .enable = BIT(31),
  31. .lock = BIT(0),
  32. .mult = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  33. .common = {
  34. .reg = SUN8I_A83T_PLL_C0CPUX_REG,
  35. .lock_reg = CCU_SUN8I_A83T_LOCK_REG,
  36. .features = CCU_FEATURE_LOCK_REG,
  37. .hw.init = CLK_HW_INIT("pll-c0cpux", "osc24M",
  38. &ccu_mult_ops,
  39. CLK_SET_RATE_UNGATE),
  40. },
  41. };
  42. static struct ccu_mult pll_c1cpux_clk = {
  43. .enable = BIT(31),
  44. .lock = BIT(1),
  45. .mult = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  46. .common = {
  47. .reg = SUN8I_A83T_PLL_C1CPUX_REG,
  48. .lock_reg = CCU_SUN8I_A83T_LOCK_REG,
  49. .features = CCU_FEATURE_LOCK_REG,
  50. .hw.init = CLK_HW_INIT("pll-c1cpux", "osc24M",
  51. &ccu_mult_ops,
  52. CLK_SET_RATE_UNGATE),
  53. },
  54. };
  55. /*
  56. * The Audio PLL has d1, d2 dividers in addition to the usual N, M
  57. * factors. Since we only need 2 frequencies from this PLL: 22.5792 MHz
  58. * and 24.576 MHz, ignore them for now. Enforce the default for them,
  59. * which is d1 = 0, d2 = 1.
  60. */
  61. #define SUN8I_A83T_PLL_AUDIO_REG 0x008
  62. /* clock rates doubled for post divider */
  63. static struct ccu_sdm_setting pll_audio_sdm_table[] = {
  64. { .rate = 45158400, .pattern = 0xc00121ff, .m = 29, .n = 54 },
  65. { .rate = 49152000, .pattern = 0xc000e147, .m = 30, .n = 61 },
  66. };
  67. static struct ccu_nm pll_audio_clk = {
  68. .enable = BIT(31),
  69. .lock = BIT(2),
  70. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  71. .m = _SUNXI_CCU_DIV(0, 6),
  72. .fixed_post_div = 2,
  73. .sdm = _SUNXI_CCU_SDM(pll_audio_sdm_table, BIT(24),
  74. 0x284, BIT(31)),
  75. .common = {
  76. .reg = SUN8I_A83T_PLL_AUDIO_REG,
  77. .lock_reg = CCU_SUN8I_A83T_LOCK_REG,
  78. .features = CCU_FEATURE_LOCK_REG |
  79. CCU_FEATURE_FIXED_POSTDIV |
  80. CCU_FEATURE_SIGMA_DELTA_MOD,
  81. .hw.init = CLK_HW_INIT("pll-audio", "osc24M",
  82. &ccu_nm_ops, CLK_SET_RATE_UNGATE),
  83. },
  84. };
  85. /* Some PLLs are input * N / div1 / P. Model them as NKMP with no K */
  86. static struct ccu_nkmp pll_video0_clk = {
  87. .enable = BIT(31),
  88. .lock = BIT(3),
  89. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  90. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  91. .p = _SUNXI_CCU_DIV(0, 2), /* output divider */
  92. .max_rate = 3000000000UL,
  93. .common = {
  94. .reg = 0x010,
  95. .lock_reg = CCU_SUN8I_A83T_LOCK_REG,
  96. .features = CCU_FEATURE_LOCK_REG,
  97. .hw.init = CLK_HW_INIT("pll-video0", "osc24M",
  98. &ccu_nkmp_ops,
  99. CLK_SET_RATE_UNGATE),
  100. },
  101. };
  102. static struct ccu_nkmp pll_ve_clk = {
  103. .enable = BIT(31),
  104. .lock = BIT(4),
  105. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  106. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  107. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  108. .common = {
  109. .reg = 0x018,
  110. .lock_reg = CCU_SUN8I_A83T_LOCK_REG,
  111. .features = CCU_FEATURE_LOCK_REG,
  112. .hw.init = CLK_HW_INIT("pll-ve", "osc24M",
  113. &ccu_nkmp_ops,
  114. CLK_SET_RATE_UNGATE),
  115. },
  116. };
  117. static struct ccu_nkmp pll_ddr_clk = {
  118. .enable = BIT(31),
  119. .lock = BIT(5),
  120. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  121. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  122. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  123. .common = {
  124. .reg = 0x020,
  125. .lock_reg = CCU_SUN8I_A83T_LOCK_REG,
  126. .features = CCU_FEATURE_LOCK_REG,
  127. .hw.init = CLK_HW_INIT("pll-ddr", "osc24M",
  128. &ccu_nkmp_ops,
  129. CLK_SET_RATE_UNGATE),
  130. },
  131. };
  132. static struct ccu_nkmp pll_periph_clk = {
  133. .enable = BIT(31),
  134. .lock = BIT(6),
  135. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  136. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  137. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  138. .common = {
  139. .reg = 0x028,
  140. .lock_reg = CCU_SUN8I_A83T_LOCK_REG,
  141. .features = CCU_FEATURE_LOCK_REG,
  142. .hw.init = CLK_HW_INIT("pll-periph", "osc24M",
  143. &ccu_nkmp_ops,
  144. CLK_SET_RATE_UNGATE),
  145. },
  146. };
  147. static struct ccu_nkmp pll_gpu_clk = {
  148. .enable = BIT(31),
  149. .lock = BIT(7),
  150. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  151. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  152. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  153. .common = {
  154. .reg = 0x038,
  155. .lock_reg = CCU_SUN8I_A83T_LOCK_REG,
  156. .features = CCU_FEATURE_LOCK_REG,
  157. .hw.init = CLK_HW_INIT("pll-gpu", "osc24M",
  158. &ccu_nkmp_ops,
  159. CLK_SET_RATE_UNGATE),
  160. },
  161. };
  162. static struct ccu_nkmp pll_hsic_clk = {
  163. .enable = BIT(31),
  164. .lock = BIT(8),
  165. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  166. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  167. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  168. .common = {
  169. .reg = 0x044,
  170. .lock_reg = CCU_SUN8I_A83T_LOCK_REG,
  171. .features = CCU_FEATURE_LOCK_REG,
  172. .hw.init = CLK_HW_INIT("pll-hsic", "osc24M",
  173. &ccu_nkmp_ops,
  174. CLK_SET_RATE_UNGATE),
  175. },
  176. };
  177. static struct ccu_nkmp pll_de_clk = {
  178. .enable = BIT(31),
  179. .lock = BIT(9),
  180. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  181. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  182. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  183. .common = {
  184. .reg = 0x048,
  185. .lock_reg = CCU_SUN8I_A83T_LOCK_REG,
  186. .features = CCU_FEATURE_LOCK_REG,
  187. .hw.init = CLK_HW_INIT("pll-de", "osc24M",
  188. &ccu_nkmp_ops,
  189. CLK_SET_RATE_UNGATE),
  190. },
  191. };
  192. static struct ccu_nkmp pll_video1_clk = {
  193. .enable = BIT(31),
  194. .lock = BIT(10),
  195. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  196. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  197. .p = _SUNXI_CCU_DIV(0, 2), /* external divider p */
  198. .max_rate = 3000000000UL,
  199. .common = {
  200. .reg = 0x04c,
  201. .lock_reg = CCU_SUN8I_A83T_LOCK_REG,
  202. .features = CCU_FEATURE_LOCK_REG,
  203. .hw.init = CLK_HW_INIT("pll-video1", "osc24M",
  204. &ccu_nkmp_ops,
  205. CLK_SET_RATE_UNGATE),
  206. },
  207. };
  208. static const char * const c0cpux_parents[] = { "osc24M", "pll-c0cpux" };
  209. static SUNXI_CCU_MUX(c0cpux_clk, "c0cpux", c0cpux_parents,
  210. 0x50, 12, 1, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
  211. static const char * const c1cpux_parents[] = { "osc24M", "pll-c1cpux" };
  212. static SUNXI_CCU_MUX(c1cpux_clk, "c1cpux", c1cpux_parents,
  213. 0x50, 28, 1, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
  214. static SUNXI_CCU_M(axi0_clk, "axi0", "c0cpux", 0x050, 0, 2, 0);
  215. static SUNXI_CCU_M(axi1_clk, "axi1", "c1cpux", 0x050, 16, 2, 0);
  216. static const char * const ahb1_parents[] = { "osc16M-d512", "osc24M",
  217. "pll-periph",
  218. "pll-periph" };
  219. static const struct ccu_mux_var_prediv ahb1_predivs[] = {
  220. { .index = 2, .shift = 6, .width = 2 },
  221. { .index = 3, .shift = 6, .width = 2 },
  222. };
  223. static struct ccu_div ahb1_clk = {
  224. .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
  225. .mux = {
  226. .shift = 12,
  227. .width = 2,
  228. .var_predivs = ahb1_predivs,
  229. .n_var_predivs = ARRAY_SIZE(ahb1_predivs),
  230. },
  231. .common = {
  232. .reg = 0x054,
  233. .hw.init = CLK_HW_INIT_PARENTS("ahb1",
  234. ahb1_parents,
  235. &ccu_div_ops,
  236. 0),
  237. },
  238. };
  239. static SUNXI_CCU_M(apb1_clk, "apb1", "ahb1", 0x054, 8, 2, 0);
  240. static const char * const apb2_parents[] = { "osc16M-d512", "osc24M",
  241. "pll-periph", "pll-periph" };
  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-periph" };
  248. static const struct ccu_mux_fixed_prediv ahb2_prediv = {
  249. .index = 1, .div = 2
  250. };
  251. static struct ccu_mux ahb2_clk = {
  252. .mux = {
  253. .shift = 0,
  254. .width = 2,
  255. .fixed_predivs = &ahb2_prediv,
  256. .n_predivs = 1,
  257. },
  258. .common = {
  259. .reg = 0x05c,
  260. .hw.init = CLK_HW_INIT_PARENTS("ahb2",
  261. ahb2_parents,
  262. &ccu_mux_ops,
  263. 0),
  264. },
  265. };
  266. static SUNXI_CCU_GATE(bus_mipi_dsi_clk, "bus-mipi-dsi", "ahb1",
  267. 0x060, BIT(1), 0);
  268. static SUNXI_CCU_GATE(bus_ss_clk, "bus-ss", "ahb1",
  269. 0x060, BIT(5), 0);
  270. static SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "ahb1",
  271. 0x060, BIT(6), 0);
  272. static SUNXI_CCU_GATE(bus_mmc0_clk, "bus-mmc0", "ahb1",
  273. 0x060, BIT(8), 0);
  274. static SUNXI_CCU_GATE(bus_mmc1_clk, "bus-mmc1", "ahb1",
  275. 0x060, BIT(9), 0);
  276. static SUNXI_CCU_GATE(bus_mmc2_clk, "bus-mmc2", "ahb1",
  277. 0x060, BIT(10), 0);
  278. static SUNXI_CCU_GATE(bus_nand_clk, "bus-nand", "ahb1",
  279. 0x060, BIT(13), 0);
  280. static SUNXI_CCU_GATE(bus_dram_clk, "bus-dram", "ahb1",
  281. 0x060, BIT(14), 0);
  282. static SUNXI_CCU_GATE(bus_emac_clk, "bus-emac", "ahb2",
  283. 0x060, BIT(17), 0);
  284. static SUNXI_CCU_GATE(bus_hstimer_clk, "bus-hstimer", "ahb1",
  285. 0x060, BIT(19), 0);
  286. static SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb1",
  287. 0x060, BIT(20), 0);
  288. static SUNXI_CCU_GATE(bus_spi1_clk, "bus-spi1", "ahb1",
  289. 0x060, BIT(21), 0);
  290. static SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb1",
  291. 0x060, BIT(24), 0);
  292. static SUNXI_CCU_GATE(bus_ehci0_clk, "bus-ehci0", "ahb2",
  293. 0x060, BIT(26), 0);
  294. static SUNXI_CCU_GATE(bus_ehci1_clk, "bus-ehci1", "ahb2",
  295. 0x060, BIT(27), 0);
  296. static SUNXI_CCU_GATE(bus_ohci0_clk, "bus-ohci0", "ahb2",
  297. 0x060, BIT(29), 0);
  298. static SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "ahb1",
  299. 0x064, BIT(0), 0);
  300. static SUNXI_CCU_GATE(bus_tcon0_clk, "bus-tcon0", "ahb1",
  301. 0x064, BIT(4), 0);
  302. static SUNXI_CCU_GATE(bus_tcon1_clk, "bus-tcon1", "ahb1",
  303. 0x064, BIT(5), 0);
  304. static SUNXI_CCU_GATE(bus_csi_clk, "bus-csi", "ahb1",
  305. 0x064, BIT(8), 0);
  306. static SUNXI_CCU_GATE(bus_hdmi_clk, "bus-hdmi", "ahb1",
  307. 0x064, BIT(11), 0);
  308. static SUNXI_CCU_GATE(bus_de_clk, "bus-de", "ahb1",
  309. 0x064, BIT(12), 0);
  310. static SUNXI_CCU_GATE(bus_gpu_clk, "bus-gpu", "ahb1",
  311. 0x064, BIT(20), 0);
  312. static SUNXI_CCU_GATE(bus_msgbox_clk, "bus-msgbox", "ahb1",
  313. 0x064, BIT(21), 0);
  314. static SUNXI_CCU_GATE(bus_spinlock_clk, "bus-spinlock", "ahb1",
  315. 0x064, BIT(22), 0);
  316. static SUNXI_CCU_GATE(bus_spdif_clk, "bus-spdif", "apb1",
  317. 0x068, BIT(1), 0);
  318. static SUNXI_CCU_GATE(bus_pio_clk, "bus-pio", "apb1",
  319. 0x068, BIT(5), 0);
  320. static SUNXI_CCU_GATE(bus_i2s0_clk, "bus-i2s0", "apb1",
  321. 0x068, BIT(12), 0);
  322. static SUNXI_CCU_GATE(bus_i2s1_clk, "bus-i2s1", "apb1",
  323. 0x068, BIT(13), 0);
  324. static SUNXI_CCU_GATE(bus_i2s2_clk, "bus-i2s2", "apb1",
  325. 0x068, BIT(14), 0);
  326. static SUNXI_CCU_GATE(bus_tdm_clk, "bus-tdm", "apb1",
  327. 0x068, BIT(15), 0);
  328. static SUNXI_CCU_GATE(bus_i2c0_clk, "bus-i2c0", "apb2",
  329. 0x06c, BIT(0), 0);
  330. static SUNXI_CCU_GATE(bus_i2c1_clk, "bus-i2c1", "apb2",
  331. 0x06c, BIT(1), 0);
  332. static SUNXI_CCU_GATE(bus_i2c2_clk, "bus-i2c2", "apb2",
  333. 0x06c, BIT(2), 0);
  334. static SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb2",
  335. 0x06c, BIT(16), 0);
  336. static SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb2",
  337. 0x06c, BIT(17), 0);
  338. static SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb2",
  339. 0x06c, BIT(18), 0);
  340. static SUNXI_CCU_GATE(bus_uart3_clk, "bus-uart3", "apb2",
  341. 0x06c, BIT(19), 0);
  342. static SUNXI_CCU_GATE(bus_uart4_clk, "bus-uart4", "apb2",
  343. 0x06c, BIT(20), 0);
  344. static const char * const cci400_parents[] = { "osc24M", "pll-periph",
  345. "pll-hsic" };
  346. static struct ccu_div cci400_clk = {
  347. .div = _SUNXI_CCU_DIV_FLAGS(0, 2, 0),
  348. .mux = _SUNXI_CCU_MUX(24, 2),
  349. .common = {
  350. .reg = 0x078,
  351. .hw.init = CLK_HW_INIT_PARENTS("cci400",
  352. cci400_parents,
  353. &ccu_div_ops,
  354. CLK_IS_CRITICAL),
  355. },
  356. };
  357. static const char * const mod0_default_parents[] = { "osc24M", "pll-periph" };
  358. static SUNXI_CCU_MP_WITH_MUX_GATE(nand_clk, "nand", mod0_default_parents,
  359. 0x080,
  360. 0, 4, /* M */
  361. 16, 2, /* P */
  362. 24, 2, /* mux */
  363. BIT(31), /* gate */
  364. 0);
  365. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents,
  366. 0x088,
  367. 0, 4, /* M */
  368. 16, 2, /* P */
  369. 24, 2, /* mux */
  370. BIT(31), /* gate */
  371. 0);
  372. static SUNXI_CCU_PHASE(mmc0_sample_clk, "mmc0-sample", "mmc0",
  373. 0x088, 20, 3, 0);
  374. static SUNXI_CCU_PHASE(mmc0_output_clk, "mmc0-output", "mmc0",
  375. 0x088, 8, 3, 0);
  376. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents,
  377. 0x08c,
  378. 0, 4, /* M */
  379. 16, 2, /* P */
  380. 24, 2, /* mux */
  381. BIT(31), /* gate */
  382. 0);
  383. static SUNXI_CCU_PHASE(mmc1_sample_clk, "mmc1-sample", "mmc1",
  384. 0x08c, 20, 3, 0);
  385. static SUNXI_CCU_PHASE(mmc1_output_clk, "mmc1-output", "mmc1",
  386. 0x08c, 8, 3, 0);
  387. static SUNXI_CCU_MP_MMC_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents,
  388. 0x090, 0);
  389. static SUNXI_CCU_PHASE(mmc2_sample_clk, "mmc2-sample", "mmc2",
  390. 0x090, 20, 3, 0);
  391. static SUNXI_CCU_PHASE(mmc2_output_clk, "mmc2-output", "mmc2",
  392. 0x090, 8, 3, 0);
  393. static SUNXI_CCU_MP_WITH_MUX_GATE(ss_clk, "ss", mod0_default_parents,
  394. 0x09c,
  395. 0, 4, /* M */
  396. 16, 2, /* P */
  397. 24, 2, /* mux */
  398. BIT(31), /* gate */
  399. 0);
  400. static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents,
  401. 0x0a0,
  402. 0, 4, /* M */
  403. 16, 2, /* P */
  404. 24, 4, /* mux */
  405. BIT(31), /* gate */
  406. 0);
  407. static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", mod0_default_parents,
  408. 0x0a4,
  409. 0, 4, /* M */
  410. 16, 2, /* P */
  411. 24, 4, /* mux */
  412. BIT(31), /* gate */
  413. 0);
  414. static SUNXI_CCU_M_WITH_GATE(i2s0_clk, "i2s0", "pll-audio",
  415. 0x0b0, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  416. static SUNXI_CCU_M_WITH_GATE(i2s1_clk, "i2s1", "pll-audio",
  417. 0x0b4, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  418. static SUNXI_CCU_M_WITH_GATE(i2s2_clk, "i2s2", "pll-audio",
  419. 0x0b8, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  420. static SUNXI_CCU_M_WITH_GATE(tdm_clk, "tdm", "pll-audio",
  421. 0x0bc, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  422. static SUNXI_CCU_M_WITH_GATE(spdif_clk, "spdif", "pll-audio",
  423. 0x0c0, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  424. static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M",
  425. 0x0cc, BIT(8), 0);
  426. static SUNXI_CCU_GATE(usb_phy1_clk, "usb-phy1", "osc24M",
  427. 0x0cc, BIT(9), 0);
  428. static SUNXI_CCU_GATE(usb_hsic_clk, "usb-hsic", "pll-hsic",
  429. 0x0cc, BIT(10), 0);
  430. static struct ccu_gate usb_hsic_12m_clk = {
  431. .enable = BIT(11),
  432. .common = {
  433. .reg = 0x0cc,
  434. .prediv = 2,
  435. .features = CCU_FEATURE_ALL_PREDIV,
  436. .hw.init = CLK_HW_INIT("usb-hsic-12m", "osc24M",
  437. &ccu_gate_ops, 0),
  438. }
  439. };
  440. static SUNXI_CCU_GATE(usb_ohci0_clk, "usb-ohci0", "osc24M",
  441. 0x0cc, BIT(16), 0);
  442. /* TODO divider has minimum of 2 */
  443. static SUNXI_CCU_M(dram_clk, "dram", "pll-ddr", 0x0f4, 0, 4, CLK_IS_CRITICAL);
  444. static SUNXI_CCU_GATE(dram_ve_clk, "dram-ve", "dram",
  445. 0x100, BIT(0), 0);
  446. static SUNXI_CCU_GATE(dram_csi_clk, "dram-csi", "dram",
  447. 0x100, BIT(1), 0);
  448. static const char * const tcon0_parents[] = { "pll-video0" };
  449. static SUNXI_CCU_MUX_WITH_GATE(tcon0_clk, "tcon0", tcon0_parents,
  450. 0x118, 24, 3, BIT(31), CLK_SET_RATE_PARENT);
  451. static const char * const tcon1_parents[] = { "pll-video1" };
  452. static SUNXI_CCU_M_WITH_MUX_GATE(tcon1_clk, "tcon1", tcon1_parents,
  453. 0x11c, 0, 4, 24, 2, BIT(31), CLK_SET_RATE_PARENT);
  454. static SUNXI_CCU_GATE(csi_misc_clk, "csi-misc", "osc24M", 0x130, BIT(16), 0);
  455. static SUNXI_CCU_GATE(mipi_csi_clk, "mipi-csi", "osc24M", 0x130, BIT(31), 0);
  456. static const char * const csi_mclk_parents[] = { "pll-video0", "pll-de",
  457. "osc24M" };
  458. static const u8 csi_mclk_table[] = { 0, 3, 5 };
  459. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(csi_mclk_clk, "csi-mclk",
  460. csi_mclk_parents, csi_mclk_table,
  461. 0x134,
  462. 0, 5, /* M */
  463. 8, 3, /* mux */
  464. BIT(15), /* gate */
  465. 0);
  466. static const char * const csi_sclk_parents[] = { "pll-periph", "pll-ve" };
  467. static const u8 csi_sclk_table[] = { 0, 5 };
  468. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(csi_sclk_clk, "csi-sclk",
  469. csi_sclk_parents, csi_sclk_table,
  470. 0x134,
  471. 16, 4, /* M */
  472. 24, 3, /* mux */
  473. BIT(31), /* gate */
  474. 0);
  475. static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve", 0x13c,
  476. 16, 3, BIT(31), CLK_SET_RATE_PARENT);
  477. static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M", 0x144, BIT(31), 0);
  478. static const char * const hdmi_parents[] = { "pll-video1" };
  479. static SUNXI_CCU_M_WITH_MUX_GATE(hdmi_clk, "hdmi", hdmi_parents,
  480. 0x150,
  481. 0, 4, /* M */
  482. 24, 2, /* mux */
  483. BIT(31), /* gate */
  484. CLK_SET_RATE_PARENT);
  485. static SUNXI_CCU_GATE(hdmi_slow_clk, "hdmi-slow", "osc24M", 0x154, BIT(31), 0);
  486. static const char * const mbus_parents[] = { "osc24M", "pll-periph",
  487. "pll-ddr" };
  488. static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents,
  489. 0x15c,
  490. 0, 3, /* M */
  491. 24, 2, /* mux */
  492. BIT(31), /* gate */
  493. CLK_IS_CRITICAL);
  494. static const char * const mipi_dsi0_parents[] = { "pll-video0" };
  495. static const u8 mipi_dsi0_table[] = { 8 };
  496. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(mipi_dsi0_clk, "mipi-dsi0",
  497. mipi_dsi0_parents, mipi_dsi0_table,
  498. 0x168,
  499. 0, 4, /* M */
  500. 24, 4, /* mux */
  501. BIT(31), /* gate */
  502. CLK_SET_RATE_PARENT);
  503. static const char * const mipi_dsi1_parents[] = { "osc24M", "pll-video0" };
  504. static const u8 mipi_dsi1_table[] = { 0, 9 };
  505. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(mipi_dsi1_clk, "mipi-dsi1",
  506. mipi_dsi1_parents, mipi_dsi1_table,
  507. 0x16c,
  508. 0, 4, /* M */
  509. 24, 4, /* mux */
  510. BIT(31), /* gate */
  511. CLK_SET_RATE_PARENT);
  512. static SUNXI_CCU_M_WITH_GATE(gpu_core_clk, "gpu-core", "pll-gpu", 0x1a0,
  513. 0, 3, BIT(31), CLK_SET_RATE_PARENT);
  514. static const char * const gpu_memory_parents[] = { "pll-gpu", "pll-ddr" };
  515. static SUNXI_CCU_M_WITH_MUX_GATE(gpu_memory_clk, "gpu-memory",
  516. gpu_memory_parents,
  517. 0x1a4,
  518. 0, 3, /* M */
  519. 24, 1, /* mux */
  520. BIT(31), /* gate */
  521. CLK_SET_RATE_PARENT);
  522. static SUNXI_CCU_M_WITH_GATE(gpu_hyd_clk, "gpu-hyd", "pll-gpu", 0x1a8,
  523. 0, 3, BIT(31), CLK_SET_RATE_PARENT);
  524. static struct ccu_common *sun8i_a83t_ccu_clks[] = {
  525. &pll_c0cpux_clk.common,
  526. &pll_c1cpux_clk.common,
  527. &pll_audio_clk.common,
  528. &pll_video0_clk.common,
  529. &pll_ve_clk.common,
  530. &pll_ddr_clk.common,
  531. &pll_periph_clk.common,
  532. &pll_gpu_clk.common,
  533. &pll_hsic_clk.common,
  534. &pll_de_clk.common,
  535. &pll_video1_clk.common,
  536. &c0cpux_clk.common,
  537. &c1cpux_clk.common,
  538. &axi0_clk.common,
  539. &axi1_clk.common,
  540. &ahb1_clk.common,
  541. &ahb2_clk.common,
  542. &apb1_clk.common,
  543. &apb2_clk.common,
  544. &bus_mipi_dsi_clk.common,
  545. &bus_ss_clk.common,
  546. &bus_dma_clk.common,
  547. &bus_mmc0_clk.common,
  548. &bus_mmc1_clk.common,
  549. &bus_mmc2_clk.common,
  550. &bus_nand_clk.common,
  551. &bus_dram_clk.common,
  552. &bus_emac_clk.common,
  553. &bus_hstimer_clk.common,
  554. &bus_spi0_clk.common,
  555. &bus_spi1_clk.common,
  556. &bus_otg_clk.common,
  557. &bus_ehci0_clk.common,
  558. &bus_ehci1_clk.common,
  559. &bus_ohci0_clk.common,
  560. &bus_ve_clk.common,
  561. &bus_tcon0_clk.common,
  562. &bus_tcon1_clk.common,
  563. &bus_csi_clk.common,
  564. &bus_hdmi_clk.common,
  565. &bus_de_clk.common,
  566. &bus_gpu_clk.common,
  567. &bus_msgbox_clk.common,
  568. &bus_spinlock_clk.common,
  569. &bus_spdif_clk.common,
  570. &bus_pio_clk.common,
  571. &bus_i2s0_clk.common,
  572. &bus_i2s1_clk.common,
  573. &bus_i2s2_clk.common,
  574. &bus_tdm_clk.common,
  575. &bus_i2c0_clk.common,
  576. &bus_i2c1_clk.common,
  577. &bus_i2c2_clk.common,
  578. &bus_uart0_clk.common,
  579. &bus_uart1_clk.common,
  580. &bus_uart2_clk.common,
  581. &bus_uart3_clk.common,
  582. &bus_uart4_clk.common,
  583. &cci400_clk.common,
  584. &nand_clk.common,
  585. &mmc0_clk.common,
  586. &mmc0_sample_clk.common,
  587. &mmc0_output_clk.common,
  588. &mmc1_clk.common,
  589. &mmc1_sample_clk.common,
  590. &mmc1_output_clk.common,
  591. &mmc2_clk.common,
  592. &mmc2_sample_clk.common,
  593. &mmc2_output_clk.common,
  594. &ss_clk.common,
  595. &spi0_clk.common,
  596. &spi1_clk.common,
  597. &i2s0_clk.common,
  598. &i2s1_clk.common,
  599. &i2s2_clk.common,
  600. &tdm_clk.common,
  601. &spdif_clk.common,
  602. &usb_phy0_clk.common,
  603. &usb_phy1_clk.common,
  604. &usb_hsic_clk.common,
  605. &usb_hsic_12m_clk.common,
  606. &usb_ohci0_clk.common,
  607. &dram_clk.common,
  608. &dram_ve_clk.common,
  609. &dram_csi_clk.common,
  610. &tcon0_clk.common,
  611. &tcon1_clk.common,
  612. &csi_misc_clk.common,
  613. &mipi_csi_clk.common,
  614. &csi_mclk_clk.common,
  615. &csi_sclk_clk.common,
  616. &ve_clk.common,
  617. &avs_clk.common,
  618. &hdmi_clk.common,
  619. &hdmi_slow_clk.common,
  620. &mbus_clk.common,
  621. &mipi_dsi0_clk.common,
  622. &mipi_dsi1_clk.common,
  623. &gpu_core_clk.common,
  624. &gpu_memory_clk.common,
  625. &gpu_hyd_clk.common,
  626. };
  627. static struct clk_hw_onecell_data sun8i_a83t_hw_clks = {
  628. .hws = {
  629. [CLK_PLL_C0CPUX] = &pll_c0cpux_clk.common.hw,
  630. [CLK_PLL_C1CPUX] = &pll_c1cpux_clk.common.hw,
  631. [CLK_PLL_AUDIO] = &pll_audio_clk.common.hw,
  632. [CLK_PLL_VIDEO0] = &pll_video0_clk.common.hw,
  633. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  634. [CLK_PLL_DDR] = &pll_ddr_clk.common.hw,
  635. [CLK_PLL_PERIPH] = &pll_periph_clk.common.hw,
  636. [CLK_PLL_GPU] = &pll_gpu_clk.common.hw,
  637. [CLK_PLL_HSIC] = &pll_hsic_clk.common.hw,
  638. [CLK_PLL_DE] = &pll_de_clk.common.hw,
  639. [CLK_PLL_VIDEO1] = &pll_video1_clk.common.hw,
  640. [CLK_C0CPUX] = &c0cpux_clk.common.hw,
  641. [CLK_C1CPUX] = &c1cpux_clk.common.hw,
  642. [CLK_AXI0] = &axi0_clk.common.hw,
  643. [CLK_AXI1] = &axi1_clk.common.hw,
  644. [CLK_AHB1] = &ahb1_clk.common.hw,
  645. [CLK_AHB2] = &ahb2_clk.common.hw,
  646. [CLK_APB1] = &apb1_clk.common.hw,
  647. [CLK_APB2] = &apb2_clk.common.hw,
  648. [CLK_BUS_MIPI_DSI] = &bus_mipi_dsi_clk.common.hw,
  649. [CLK_BUS_SS] = &bus_ss_clk.common.hw,
  650. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  651. [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw,
  652. [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw,
  653. [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw,
  654. [CLK_BUS_NAND] = &bus_nand_clk.common.hw,
  655. [CLK_BUS_DRAM] = &bus_dram_clk.common.hw,
  656. [CLK_BUS_EMAC] = &bus_emac_clk.common.hw,
  657. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  658. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  659. [CLK_BUS_SPI1] = &bus_spi1_clk.common.hw,
  660. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  661. [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw,
  662. [CLK_BUS_EHCI1] = &bus_ehci1_clk.common.hw,
  663. [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw,
  664. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  665. [CLK_BUS_TCON0] = &bus_tcon0_clk.common.hw,
  666. [CLK_BUS_TCON1] = &bus_tcon1_clk.common.hw,
  667. [CLK_BUS_CSI] = &bus_csi_clk.common.hw,
  668. [CLK_BUS_HDMI] = &bus_hdmi_clk.common.hw,
  669. [CLK_BUS_DE] = &bus_de_clk.common.hw,
  670. [CLK_BUS_GPU] = &bus_gpu_clk.common.hw,
  671. [CLK_BUS_MSGBOX] = &bus_msgbox_clk.common.hw,
  672. [CLK_BUS_SPINLOCK] = &bus_spinlock_clk.common.hw,
  673. [CLK_BUS_SPDIF] = &bus_spdif_clk.common.hw,
  674. [CLK_BUS_PIO] = &bus_pio_clk.common.hw,
  675. [CLK_BUS_I2S0] = &bus_i2s0_clk.common.hw,
  676. [CLK_BUS_I2S1] = &bus_i2s1_clk.common.hw,
  677. [CLK_BUS_I2S2] = &bus_i2s2_clk.common.hw,
  678. [CLK_BUS_TDM] = &bus_tdm_clk.common.hw,
  679. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  680. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  681. [CLK_BUS_I2C2] = &bus_i2c2_clk.common.hw,
  682. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  683. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  684. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  685. [CLK_BUS_UART3] = &bus_uart3_clk.common.hw,
  686. [CLK_BUS_UART4] = &bus_uart4_clk.common.hw,
  687. [CLK_CCI400] = &cci400_clk.common.hw,
  688. [CLK_NAND] = &nand_clk.common.hw,
  689. [CLK_MMC0] = &mmc0_clk.common.hw,
  690. [CLK_MMC0_SAMPLE] = &mmc0_sample_clk.common.hw,
  691. [CLK_MMC0_OUTPUT] = &mmc0_output_clk.common.hw,
  692. [CLK_MMC1] = &mmc1_clk.common.hw,
  693. [CLK_MMC1_SAMPLE] = &mmc1_sample_clk.common.hw,
  694. [CLK_MMC1_OUTPUT] = &mmc1_output_clk.common.hw,
  695. [CLK_MMC2] = &mmc2_clk.common.hw,
  696. [CLK_MMC2_SAMPLE] = &mmc2_sample_clk.common.hw,
  697. [CLK_MMC2_OUTPUT] = &mmc2_output_clk.common.hw,
  698. [CLK_SS] = &ss_clk.common.hw,
  699. [CLK_SPI0] = &spi0_clk.common.hw,
  700. [CLK_SPI1] = &spi1_clk.common.hw,
  701. [CLK_I2S0] = &i2s0_clk.common.hw,
  702. [CLK_I2S1] = &i2s1_clk.common.hw,
  703. [CLK_I2S2] = &i2s2_clk.common.hw,
  704. [CLK_TDM] = &tdm_clk.common.hw,
  705. [CLK_SPDIF] = &spdif_clk.common.hw,
  706. [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
  707. [CLK_USB_PHY1] = &usb_phy1_clk.common.hw,
  708. [CLK_USB_HSIC] = &usb_hsic_clk.common.hw,
  709. [CLK_USB_HSIC_12M] = &usb_hsic_12m_clk.common.hw,
  710. [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
  711. [CLK_DRAM] = &dram_clk.common.hw,
  712. [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
  713. [CLK_DRAM_CSI] = &dram_csi_clk.common.hw,
  714. [CLK_TCON0] = &tcon0_clk.common.hw,
  715. [CLK_TCON1] = &tcon1_clk.common.hw,
  716. [CLK_CSI_MISC] = &csi_misc_clk.common.hw,
  717. [CLK_MIPI_CSI] = &mipi_csi_clk.common.hw,
  718. [CLK_CSI_MCLK] = &csi_mclk_clk.common.hw,
  719. [CLK_CSI_SCLK] = &csi_sclk_clk.common.hw,
  720. [CLK_VE] = &ve_clk.common.hw,
  721. [CLK_AVS] = &avs_clk.common.hw,
  722. [CLK_HDMI] = &hdmi_clk.common.hw,
  723. [CLK_HDMI_SLOW] = &hdmi_slow_clk.common.hw,
  724. [CLK_MBUS] = &mbus_clk.common.hw,
  725. [CLK_MIPI_DSI0] = &mipi_dsi0_clk.common.hw,
  726. [CLK_MIPI_DSI1] = &mipi_dsi1_clk.common.hw,
  727. [CLK_GPU_CORE] = &gpu_core_clk.common.hw,
  728. [CLK_GPU_MEMORY] = &gpu_memory_clk.common.hw,
  729. [CLK_GPU_HYD] = &gpu_hyd_clk.common.hw,
  730. },
  731. .num = CLK_NUMBER,
  732. };
  733. static struct ccu_reset_map sun8i_a83t_ccu_resets[] = {
  734. [RST_USB_PHY0] = { 0x0cc, BIT(0) },
  735. [RST_USB_PHY1] = { 0x0cc, BIT(1) },
  736. [RST_USB_HSIC] = { 0x0cc, BIT(2) },
  737. [RST_DRAM] = { 0x0f4, BIT(31) },
  738. [RST_MBUS] = { 0x0fc, BIT(31) },
  739. [RST_BUS_MIPI_DSI] = { 0x2c0, BIT(1) },
  740. [RST_BUS_SS] = { 0x2c0, BIT(5) },
  741. [RST_BUS_DMA] = { 0x2c0, BIT(6) },
  742. [RST_BUS_MMC0] = { 0x2c0, BIT(8) },
  743. [RST_BUS_MMC1] = { 0x2c0, BIT(9) },
  744. [RST_BUS_MMC2] = { 0x2c0, BIT(10) },
  745. [RST_BUS_NAND] = { 0x2c0, BIT(13) },
  746. [RST_BUS_DRAM] = { 0x2c0, BIT(14) },
  747. [RST_BUS_EMAC] = { 0x2c0, BIT(17) },
  748. [RST_BUS_HSTIMER] = { 0x2c0, BIT(19) },
  749. [RST_BUS_SPI0] = { 0x2c0, BIT(20) },
  750. [RST_BUS_SPI1] = { 0x2c0, BIT(21) },
  751. [RST_BUS_OTG] = { 0x2c0, BIT(24) },
  752. [RST_BUS_EHCI0] = { 0x2c0, BIT(26) },
  753. [RST_BUS_EHCI1] = { 0x2c0, BIT(27) },
  754. [RST_BUS_OHCI0] = { 0x2c0, BIT(29) },
  755. [RST_BUS_VE] = { 0x2c4, BIT(0) },
  756. [RST_BUS_TCON0] = { 0x2c4, BIT(4) },
  757. [RST_BUS_TCON1] = { 0x2c4, BIT(5) },
  758. [RST_BUS_CSI] = { 0x2c4, BIT(8) },
  759. [RST_BUS_HDMI0] = { 0x2c4, BIT(10) },
  760. [RST_BUS_HDMI1] = { 0x2c4, BIT(11) },
  761. [RST_BUS_DE] = { 0x2c4, BIT(12) },
  762. [RST_BUS_GPU] = { 0x2c4, BIT(20) },
  763. [RST_BUS_MSGBOX] = { 0x2c4, BIT(21) },
  764. [RST_BUS_SPINLOCK] = { 0x2c4, BIT(22) },
  765. [RST_BUS_LVDS] = { 0x2c8, BIT(0) },
  766. [RST_BUS_SPDIF] = { 0x2d0, BIT(1) },
  767. [RST_BUS_I2S0] = { 0x2d0, BIT(12) },
  768. [RST_BUS_I2S1] = { 0x2d0, BIT(13) },
  769. [RST_BUS_I2S2] = { 0x2d0, BIT(14) },
  770. [RST_BUS_TDM] = { 0x2d0, BIT(15) },
  771. [RST_BUS_I2C0] = { 0x2d8, BIT(0) },
  772. [RST_BUS_I2C1] = { 0x2d8, BIT(1) },
  773. [RST_BUS_I2C2] = { 0x2d8, BIT(2) },
  774. [RST_BUS_UART0] = { 0x2d8, BIT(16) },
  775. [RST_BUS_UART1] = { 0x2d8, BIT(17) },
  776. [RST_BUS_UART2] = { 0x2d8, BIT(18) },
  777. [RST_BUS_UART3] = { 0x2d8, BIT(19) },
  778. [RST_BUS_UART4] = { 0x2d8, BIT(20) },
  779. };
  780. static const struct sunxi_ccu_desc sun8i_a83t_ccu_desc = {
  781. .ccu_clks = sun8i_a83t_ccu_clks,
  782. .num_ccu_clks = ARRAY_SIZE(sun8i_a83t_ccu_clks),
  783. .hw_clks = &sun8i_a83t_hw_clks,
  784. .resets = sun8i_a83t_ccu_resets,
  785. .num_resets = ARRAY_SIZE(sun8i_a83t_ccu_resets),
  786. };
  787. #define SUN8I_A83T_PLL_P_SHIFT 16
  788. #define SUN8I_A83T_PLL_N_SHIFT 8
  789. #define SUN8I_A83T_PLL_N_WIDTH 8
  790. static void sun8i_a83t_cpu_pll_fixup(void __iomem *reg)
  791. {
  792. u32 val = readl(reg);
  793. /* bail out if P divider is not used */
  794. if (!(val & BIT(SUN8I_A83T_PLL_P_SHIFT)))
  795. return;
  796. /*
  797. * If P is used, output should be less than 288 MHz. When we
  798. * set P to 1, we should also decrease the multiplier so the
  799. * output doesn't go out of range, but not too much such that
  800. * the multiplier stays above 12, the minimal operation value.
  801. *
  802. * To keep it simple, set the multiplier to 17, the reset value.
  803. */
  804. val &= ~GENMASK(SUN8I_A83T_PLL_N_SHIFT + SUN8I_A83T_PLL_N_WIDTH - 1,
  805. SUN8I_A83T_PLL_N_SHIFT);
  806. val |= 17 << SUN8I_A83T_PLL_N_SHIFT;
  807. /* And clear P */
  808. val &= ~BIT(SUN8I_A83T_PLL_P_SHIFT);
  809. writel(val, reg);
  810. }
  811. static int sun8i_a83t_ccu_probe(struct platform_device *pdev)
  812. {
  813. void __iomem *reg;
  814. u32 val;
  815. reg = devm_platform_ioremap_resource(pdev, 0);
  816. if (IS_ERR(reg))
  817. return PTR_ERR(reg);
  818. /* Enforce d1 = 0, d2 = 1 for Audio PLL */
  819. val = readl(reg + SUN8I_A83T_PLL_AUDIO_REG);
  820. val &= ~BIT(16);
  821. val |= BIT(18);
  822. writel(val, reg + SUN8I_A83T_PLL_AUDIO_REG);
  823. /* Enforce P = 1 for both CPU cluster PLLs */
  824. sun8i_a83t_cpu_pll_fixup(reg + SUN8I_A83T_PLL_C0CPUX_REG);
  825. sun8i_a83t_cpu_pll_fixup(reg + SUN8I_A83T_PLL_C1CPUX_REG);
  826. return devm_sunxi_ccu_probe(&pdev->dev, reg, &sun8i_a83t_ccu_desc);
  827. }
  828. static const struct of_device_id sun8i_a83t_ccu_ids[] = {
  829. { .compatible = "allwinner,sun8i-a83t-ccu" },
  830. { }
  831. };
  832. static struct platform_driver sun8i_a83t_ccu_driver = {
  833. .probe = sun8i_a83t_ccu_probe,
  834. .driver = {
  835. .name = "sun8i-a83t-ccu",
  836. .suppress_bind_attrs = true,
  837. .of_match_table = sun8i_a83t_ccu_ids,
  838. },
  839. };
  840. module_platform_driver(sun8i_a83t_ccu_driver);
  841. MODULE_IMPORT_NS(SUNXI_CCU);
  842. MODULE_LICENSE("GPL");