ccu-sun8i-a83t.c 29 KB

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