ccu-sun8i-a83t.c 29 KB

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