ccu-sun20i-d1.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2020 [email protected]
  4. * Copyright (C) 2021 Samuel Holland <[email protected]>
  5. */
  6. #include <linux/clk-provider.h>
  7. #include <linux/io.h>
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include "../clk.h"
  11. #include "ccu_common.h"
  12. #include "ccu_reset.h"
  13. #include "ccu_div.h"
  14. #include "ccu_gate.h"
  15. #include "ccu_mp.h"
  16. #include "ccu_mult.h"
  17. #include "ccu_nk.h"
  18. #include "ccu_nkm.h"
  19. #include "ccu_nkmp.h"
  20. #include "ccu_nm.h"
  21. #include "ccu-sun20i-d1.h"
  22. static const struct clk_parent_data osc24M[] = {
  23. { .fw_name = "hosc" }
  24. };
  25. /*
  26. * For the CPU PLL, the output divider is described as "only for testing"
  27. * in the user manual. So it's not modelled and forced to 0.
  28. */
  29. #define SUN20I_D1_PLL_CPUX_REG 0x000
  30. static struct ccu_mult pll_cpux_clk = {
  31. .enable = BIT(27),
  32. .lock = BIT(28),
  33. .mult = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  34. .common = {
  35. .reg = 0x000,
  36. .hw.init = CLK_HW_INIT_PARENTS_DATA("pll-cpux", osc24M,
  37. &ccu_mult_ops,
  38. CLK_SET_RATE_UNGATE),
  39. },
  40. };
  41. /* Some PLLs are input * N / div1 / P. Model them as NKMP with no K */
  42. #define SUN20I_D1_PLL_DDR0_REG 0x010
  43. static struct ccu_nkmp pll_ddr0_clk = {
  44. .enable = BIT(27),
  45. .lock = BIT(28),
  46. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  47. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  48. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  49. .common = {
  50. .reg = 0x010,
  51. .hw.init = CLK_HW_INIT_PARENTS_DATA("pll-ddr0", osc24M,
  52. &ccu_nkmp_ops,
  53. CLK_SET_RATE_UNGATE),
  54. },
  55. };
  56. #define SUN20I_D1_PLL_PERIPH0_REG 0x020
  57. static struct ccu_nm pll_periph0_4x_clk = {
  58. .enable = BIT(27),
  59. .lock = BIT(28),
  60. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  61. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  62. .common = {
  63. .reg = 0x020,
  64. .hw.init = CLK_HW_INIT_PARENTS_DATA("pll-periph0-4x", osc24M,
  65. &ccu_nm_ops,
  66. CLK_SET_RATE_UNGATE),
  67. },
  68. };
  69. static const struct clk_hw *pll_periph0_4x_hws[] = {
  70. &pll_periph0_4x_clk.common.hw
  71. };
  72. static SUNXI_CCU_M_HWS(pll_periph0_2x_clk, "pll-periph0-2x",
  73. pll_periph0_4x_hws, 0x020, 16, 3, 0);
  74. static SUNXI_CCU_M_HWS(pll_periph0_800M_clk, "pll-periph0-800M",
  75. pll_periph0_4x_hws, 0x020, 20, 3, 0);
  76. static const struct clk_hw *pll_periph0_2x_hws[] = {
  77. &pll_periph0_2x_clk.common.hw
  78. };
  79. static CLK_FIXED_FACTOR_HWS(pll_periph0_clk, "pll-periph0",
  80. pll_periph0_2x_hws, 2, 1, 0);
  81. static const struct clk_hw *pll_periph0_hws[] = { &pll_periph0_clk.hw };
  82. static CLK_FIXED_FACTOR_HWS(pll_periph0_div3_clk, "pll-periph0-div3",
  83. pll_periph0_2x_hws, 6, 1, 0);
  84. /*
  85. * For Video PLLs, the output divider is described as "only for testing"
  86. * in the user manual. So it's not modelled and forced to 0.
  87. */
  88. #define SUN20I_D1_PLL_VIDEO0_REG 0x040
  89. static struct ccu_nm pll_video0_4x_clk = {
  90. .enable = BIT(27),
  91. .lock = BIT(28),
  92. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  93. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  94. .min_rate = 252000000U,
  95. .max_rate = 2400000000U,
  96. .common = {
  97. .reg = 0x040,
  98. .hw.init = CLK_HW_INIT_PARENTS_DATA("pll-video0-4x", osc24M,
  99. &ccu_nm_ops,
  100. CLK_SET_RATE_UNGATE),
  101. },
  102. };
  103. static const struct clk_hw *pll_video0_4x_hws[] = {
  104. &pll_video0_4x_clk.common.hw
  105. };
  106. static CLK_FIXED_FACTOR_HWS(pll_video0_2x_clk, "pll-video0-2x",
  107. pll_video0_4x_hws, 2, 1, CLK_SET_RATE_PARENT);
  108. static CLK_FIXED_FACTOR_HWS(pll_video0_clk, "pll-video0",
  109. pll_video0_4x_hws, 4, 1, CLK_SET_RATE_PARENT);
  110. #define SUN20I_D1_PLL_VIDEO1_REG 0x048
  111. static struct ccu_nm pll_video1_4x_clk = {
  112. .enable = BIT(27),
  113. .lock = BIT(28),
  114. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  115. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  116. .min_rate = 252000000U,
  117. .max_rate = 2400000000U,
  118. .common = {
  119. .reg = 0x048,
  120. .hw.init = CLK_HW_INIT_PARENTS_DATA("pll-video1-4x", osc24M,
  121. &ccu_nm_ops,
  122. CLK_SET_RATE_UNGATE),
  123. },
  124. };
  125. static const struct clk_hw *pll_video1_4x_hws[] = {
  126. &pll_video1_4x_clk.common.hw
  127. };
  128. static CLK_FIXED_FACTOR_HWS(pll_video1_2x_clk, "pll-video1-2x",
  129. pll_video1_4x_hws, 2, 1, CLK_SET_RATE_PARENT);
  130. static CLK_FIXED_FACTOR_HWS(pll_video1_clk, "pll-video1",
  131. pll_video1_4x_hws, 4, 1, CLK_SET_RATE_PARENT);
  132. #define SUN20I_D1_PLL_VE_REG 0x058
  133. static struct ccu_nkmp pll_ve_clk = {
  134. .enable = BIT(27),
  135. .lock = BIT(28),
  136. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  137. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  138. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  139. .common = {
  140. .reg = 0x058,
  141. .hw.init = CLK_HW_INIT_PARENTS_DATA("pll-ve", osc24M,
  142. &ccu_nkmp_ops,
  143. CLK_SET_RATE_UNGATE),
  144. },
  145. };
  146. /*
  147. * PLL_AUDIO0 has m0, m1 dividers in addition to the usual N, M factors.
  148. * Since we only need one frequency from this PLL (22.5792 x 4 == 90.3168 MHz),
  149. * ignore them for now. Enforce the default for them, which is m1 = 0, m0 = 0.
  150. * The M factor must be an even number to produce a 50% duty cycle output.
  151. */
  152. #define SUN20I_D1_PLL_AUDIO0_REG 0x078
  153. static struct ccu_sdm_setting pll_audio0_sdm_table[] = {
  154. { .rate = 90316800, .pattern = 0xc001288d, .m = 6, .n = 22 },
  155. };
  156. static struct ccu_nm pll_audio0_4x_clk = {
  157. .enable = BIT(27),
  158. .lock = BIT(28),
  159. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  160. .m = _SUNXI_CCU_DIV(16, 6),
  161. .sdm = _SUNXI_CCU_SDM(pll_audio0_sdm_table, BIT(24),
  162. 0x178, BIT(31)),
  163. .min_rate = 180000000U,
  164. .max_rate = 3000000000U,
  165. .common = {
  166. .reg = 0x078,
  167. .features = CCU_FEATURE_SIGMA_DELTA_MOD,
  168. .hw.init = CLK_HW_INIT_PARENTS_DATA("pll-audio0-4x", osc24M,
  169. &ccu_nm_ops,
  170. CLK_SET_RATE_UNGATE),
  171. },
  172. };
  173. static const struct clk_hw *pll_audio0_4x_hws[] = {
  174. &pll_audio0_4x_clk.common.hw
  175. };
  176. static CLK_FIXED_FACTOR_HWS(pll_audio0_2x_clk, "pll-audio0-2x",
  177. pll_audio0_4x_hws, 2, 1, 0);
  178. static CLK_FIXED_FACTOR_HWS(pll_audio0_clk, "pll-audio0",
  179. pll_audio0_4x_hws, 4, 1, 0);
  180. /*
  181. * PLL_AUDIO1 doesn't need Fractional-N. The output is usually 614.4 MHz for
  182. * audio. The ADC or DAC should divide the PLL output further to 24.576 MHz.
  183. */
  184. #define SUN20I_D1_PLL_AUDIO1_REG 0x080
  185. static struct ccu_nm pll_audio1_clk = {
  186. .enable = BIT(27),
  187. .lock = BIT(28),
  188. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  189. .m = _SUNXI_CCU_DIV(1, 1),
  190. .min_rate = 180000000U,
  191. .max_rate = 3000000000U,
  192. .common = {
  193. .reg = 0x080,
  194. .hw.init = CLK_HW_INIT_PARENTS_DATA("pll-audio1", osc24M,
  195. &ccu_nm_ops,
  196. CLK_SET_RATE_UNGATE),
  197. },
  198. };
  199. static const struct clk_hw *pll_audio1_hws[] = {
  200. &pll_audio1_clk.common.hw
  201. };
  202. static SUNXI_CCU_M_HWS(pll_audio1_div2_clk, "pll-audio1-div2",
  203. pll_audio1_hws, 0x080, 16, 3, 0);
  204. static SUNXI_CCU_M_HWS(pll_audio1_div5_clk, "pll-audio1-div5",
  205. pll_audio1_hws, 0x080, 20, 3, 0);
  206. /*
  207. * The CPUX gate is not modelled - it is in a separate register (0x504)
  208. * and has a special key field. The clock does not need to be ungated anyway.
  209. */
  210. static const struct clk_parent_data cpux_parents[] = {
  211. { .fw_name = "hosc" },
  212. { .fw_name = "losc" },
  213. { .fw_name = "iosc" },
  214. { .hw = &pll_cpux_clk.common.hw },
  215. { .hw = &pll_periph0_clk.hw },
  216. { .hw = &pll_periph0_2x_clk.common.hw },
  217. { .hw = &pll_periph0_800M_clk.common.hw },
  218. };
  219. static SUNXI_CCU_MUX_DATA(cpux_clk, "cpux", cpux_parents,
  220. 0x500, 24, 3, CLK_SET_RATE_PARENT);
  221. static const struct clk_hw *cpux_hws[] = { &cpux_clk.common.hw };
  222. static SUNXI_CCU_M_HWS(cpux_axi_clk, "cpux-axi",
  223. cpux_hws, 0x500, 0, 2, 0);
  224. static SUNXI_CCU_M_HWS(cpux_apb_clk, "cpux-apb",
  225. cpux_hws, 0x500, 8, 2, 0);
  226. static const struct clk_parent_data psi_ahb_parents[] = {
  227. { .fw_name = "hosc" },
  228. { .fw_name = "losc" },
  229. { .fw_name = "iosc" },
  230. { .hw = &pll_periph0_clk.hw },
  231. };
  232. static SUNXI_CCU_MP_DATA_WITH_MUX(psi_ahb_clk, "psi-ahb", psi_ahb_parents, 0x510,
  233. 0, 2, /* M */
  234. 8, 2, /* P */
  235. 24, 2, /* mux */
  236. 0);
  237. static const struct clk_parent_data apb0_apb1_parents[] = {
  238. { .fw_name = "hosc" },
  239. { .fw_name = "losc" },
  240. { .hw = &psi_ahb_clk.common.hw },
  241. { .hw = &pll_periph0_clk.hw },
  242. };
  243. static SUNXI_CCU_MP_DATA_WITH_MUX(apb0_clk, "apb0", apb0_apb1_parents, 0x520,
  244. 0, 5, /* M */
  245. 8, 2, /* P */
  246. 24, 2, /* mux */
  247. 0);
  248. static SUNXI_CCU_MP_DATA_WITH_MUX(apb1_clk, "apb1", apb0_apb1_parents, 0x524,
  249. 0, 5, /* M */
  250. 8, 2, /* P */
  251. 24, 2, /* mux */
  252. 0);
  253. static const struct clk_hw *psi_ahb_hws[] = { &psi_ahb_clk.common.hw };
  254. static const struct clk_hw *apb0_hws[] = { &apb0_clk.common.hw };
  255. static const struct clk_hw *apb1_hws[] = { &apb1_clk.common.hw };
  256. static const struct clk_hw *de_di_g2d_parents[] = {
  257. &pll_periph0_2x_clk.common.hw,
  258. &pll_video0_4x_clk.common.hw,
  259. &pll_video1_4x_clk.common.hw,
  260. &pll_audio1_div2_clk.common.hw,
  261. };
  262. static SUNXI_CCU_M_HW_WITH_MUX_GATE(de_clk, "de", de_di_g2d_parents, 0x600,
  263. 0, 5, /* M */
  264. 24, 3, /* mux */
  265. BIT(31), /* gate */
  266. CLK_SET_RATE_PARENT);
  267. static SUNXI_CCU_GATE_HWS(bus_de_clk, "bus-de", psi_ahb_hws,
  268. 0x60c, BIT(0), 0);
  269. static SUNXI_CCU_M_HW_WITH_MUX_GATE(di_clk, "di", de_di_g2d_parents, 0x620,
  270. 0, 5, /* M */
  271. 24, 3, /* mux */
  272. BIT(31), /* gate */
  273. CLK_SET_RATE_PARENT);
  274. static SUNXI_CCU_GATE_HWS(bus_di_clk, "bus-di", psi_ahb_hws,
  275. 0x62c, BIT(0), 0);
  276. static SUNXI_CCU_M_HW_WITH_MUX_GATE(g2d_clk, "g2d", de_di_g2d_parents, 0x630,
  277. 0, 5, /* M */
  278. 24, 3, /* mux */
  279. BIT(31), /* gate */
  280. 0);
  281. static SUNXI_CCU_GATE_HWS(bus_g2d_clk, "bus-g2d", psi_ahb_hws,
  282. 0x63c, BIT(0), 0);
  283. static const struct clk_parent_data ce_parents[] = {
  284. { .fw_name = "hosc" },
  285. { .hw = &pll_periph0_2x_clk.common.hw },
  286. { .hw = &pll_periph0_clk.hw },
  287. };
  288. static SUNXI_CCU_MP_DATA_WITH_MUX_GATE(ce_clk, "ce", ce_parents, 0x680,
  289. 0, 4, /* M */
  290. 8, 2, /* P */
  291. 24, 3, /* mux */
  292. BIT(31), /* gate */
  293. 0);
  294. static SUNXI_CCU_GATE_HWS(bus_ce_clk, "bus-ce", psi_ahb_hws,
  295. 0x68c, BIT(0), 0);
  296. static const struct clk_hw *ve_parents[] = {
  297. &pll_ve_clk.common.hw,
  298. &pll_periph0_2x_clk.common.hw,
  299. };
  300. static SUNXI_CCU_M_HW_WITH_MUX_GATE(ve_clk, "ve", ve_parents, 0x690,
  301. 0, 5, /* M */
  302. 24, 1, /* mux */
  303. BIT(31), /* gate */
  304. CLK_SET_RATE_PARENT);
  305. static SUNXI_CCU_GATE_HWS(bus_ve_clk, "bus-ve", psi_ahb_hws,
  306. 0x69c, BIT(0), 0);
  307. static SUNXI_CCU_GATE_HWS(bus_dma_clk, "bus-dma", psi_ahb_hws,
  308. 0x70c, BIT(0), 0);
  309. static SUNXI_CCU_GATE_HWS(bus_msgbox0_clk, "bus-msgbox0", psi_ahb_hws,
  310. 0x71c, BIT(0), 0);
  311. static SUNXI_CCU_GATE_HWS(bus_msgbox1_clk, "bus-msgbox1", psi_ahb_hws,
  312. 0x71c, BIT(1), 0);
  313. static SUNXI_CCU_GATE_HWS(bus_msgbox2_clk, "bus-msgbox2", psi_ahb_hws,
  314. 0x71c, BIT(2), 0);
  315. static SUNXI_CCU_GATE_HWS(bus_spinlock_clk, "bus-spinlock", psi_ahb_hws,
  316. 0x72c, BIT(0), 0);
  317. static SUNXI_CCU_GATE_HWS(bus_hstimer_clk, "bus-hstimer", psi_ahb_hws,
  318. 0x73c, BIT(0), 0);
  319. static SUNXI_CCU_GATE_DATA(avs_clk, "avs", osc24M,
  320. 0x740, BIT(31), 0);
  321. static SUNXI_CCU_GATE_HWS(bus_dbg_clk, "bus-dbg", psi_ahb_hws,
  322. 0x78c, BIT(0), 0);
  323. static SUNXI_CCU_GATE_HWS(bus_pwm_clk, "bus-pwm", apb0_hws,
  324. 0x7ac, BIT(0), 0);
  325. static SUNXI_CCU_GATE_HWS(bus_iommu_clk, "bus-iommu", apb0_hws,
  326. 0x7bc, BIT(0), 0);
  327. static const struct clk_hw *dram_parents[] = {
  328. &pll_ddr0_clk.common.hw,
  329. &pll_audio1_div2_clk.common.hw,
  330. &pll_periph0_2x_clk.common.hw,
  331. &pll_periph0_800M_clk.common.hw,
  332. };
  333. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(dram_clk, "dram", dram_parents, 0x800,
  334. 0, 2, /* M */
  335. 8, 2, /* P */
  336. 24, 2, /* mux */
  337. BIT(31), CLK_IS_CRITICAL);
  338. static CLK_FIXED_FACTOR_HW(mbus_clk, "mbus",
  339. &dram_clk.common.hw, 4, 1, 0);
  340. static const struct clk_hw *mbus_hws[] = { &mbus_clk.hw };
  341. static SUNXI_CCU_GATE_HWS(mbus_dma_clk, "mbus-dma", mbus_hws,
  342. 0x804, BIT(0), 0);
  343. static SUNXI_CCU_GATE_HWS(mbus_ve_clk, "mbus-ve", mbus_hws,
  344. 0x804, BIT(1), 0);
  345. static SUNXI_CCU_GATE_HWS(mbus_ce_clk, "mbus-ce", mbus_hws,
  346. 0x804, BIT(2), 0);
  347. static SUNXI_CCU_GATE_HWS(mbus_tvin_clk, "mbus-tvin", mbus_hws,
  348. 0x804, BIT(7), 0);
  349. static SUNXI_CCU_GATE_HWS(mbus_csi_clk, "mbus-csi", mbus_hws,
  350. 0x804, BIT(8), 0);
  351. static SUNXI_CCU_GATE_HWS(mbus_g2d_clk, "mbus-g2d", mbus_hws,
  352. 0x804, BIT(10), 0);
  353. static SUNXI_CCU_GATE_HWS(mbus_riscv_clk, "mbus-riscv", mbus_hws,
  354. 0x804, BIT(11), 0);
  355. static SUNXI_CCU_GATE_HWS(bus_dram_clk, "bus-dram", psi_ahb_hws,
  356. 0x80c, BIT(0), CLK_IS_CRITICAL);
  357. static const struct clk_parent_data mmc0_mmc1_parents[] = {
  358. { .fw_name = "hosc" },
  359. { .hw = &pll_periph0_clk.hw },
  360. { .hw = &pll_periph0_2x_clk.common.hw },
  361. { .hw = &pll_audio1_div2_clk.common.hw },
  362. };
  363. static SUNXI_CCU_MP_DATA_WITH_MUX_GATE(mmc0_clk, "mmc0", mmc0_mmc1_parents, 0x830,
  364. 0, 4, /* M */
  365. 8, 2, /* P */
  366. 24, 3, /* mux */
  367. BIT(31), /* gate */
  368. 0);
  369. static SUNXI_CCU_MP_DATA_WITH_MUX_GATE(mmc1_clk, "mmc1", mmc0_mmc1_parents, 0x834,
  370. 0, 4, /* M */
  371. 8, 2, /* P */
  372. 24, 3, /* mux */
  373. BIT(31), /* gate */
  374. 0);
  375. static const struct clk_parent_data mmc2_parents[] = {
  376. { .fw_name = "hosc" },
  377. { .hw = &pll_periph0_clk.hw },
  378. { .hw = &pll_periph0_2x_clk.common.hw },
  379. { .hw = &pll_periph0_800M_clk.common.hw },
  380. { .hw = &pll_audio1_div2_clk.common.hw },
  381. };
  382. static SUNXI_CCU_MP_DATA_WITH_MUX_GATE(mmc2_clk, "mmc2", mmc2_parents, 0x838,
  383. 0, 4, /* M */
  384. 8, 2, /* P */
  385. 24, 3, /* mux */
  386. BIT(31), /* gate */
  387. 0);
  388. static SUNXI_CCU_GATE_HWS(bus_mmc0_clk, "bus-mmc0", psi_ahb_hws,
  389. 0x84c, BIT(0), 0);
  390. static SUNXI_CCU_GATE_HWS(bus_mmc1_clk, "bus-mmc1", psi_ahb_hws,
  391. 0x84c, BIT(1), 0);
  392. static SUNXI_CCU_GATE_HWS(bus_mmc2_clk, "bus-mmc2", psi_ahb_hws,
  393. 0x84c, BIT(2), 0);
  394. static SUNXI_CCU_GATE_HWS(bus_uart0_clk, "bus-uart0", apb1_hws,
  395. 0x90c, BIT(0), 0);
  396. static SUNXI_CCU_GATE_HWS(bus_uart1_clk, "bus-uart1", apb1_hws,
  397. 0x90c, BIT(1), 0);
  398. static SUNXI_CCU_GATE_HWS(bus_uart2_clk, "bus-uart2", apb1_hws,
  399. 0x90c, BIT(2), 0);
  400. static SUNXI_CCU_GATE_HWS(bus_uart3_clk, "bus-uart3", apb1_hws,
  401. 0x90c, BIT(3), 0);
  402. static SUNXI_CCU_GATE_HWS(bus_uart4_clk, "bus-uart4", apb1_hws,
  403. 0x90c, BIT(4), 0);
  404. static SUNXI_CCU_GATE_HWS(bus_uart5_clk, "bus-uart5", apb1_hws,
  405. 0x90c, BIT(5), 0);
  406. static SUNXI_CCU_GATE_HWS(bus_i2c0_clk, "bus-i2c0", apb1_hws,
  407. 0x91c, BIT(0), 0);
  408. static SUNXI_CCU_GATE_HWS(bus_i2c1_clk, "bus-i2c1", apb1_hws,
  409. 0x91c, BIT(1), 0);
  410. static SUNXI_CCU_GATE_HWS(bus_i2c2_clk, "bus-i2c2", apb1_hws,
  411. 0x91c, BIT(2), 0);
  412. static SUNXI_CCU_GATE_HWS(bus_i2c3_clk, "bus-i2c3", apb1_hws,
  413. 0x91c, BIT(3), 0);
  414. static const struct clk_parent_data spi_parents[] = {
  415. { .fw_name = "hosc" },
  416. { .hw = &pll_periph0_clk.hw },
  417. { .hw = &pll_periph0_2x_clk.common.hw },
  418. { .hw = &pll_audio1_div2_clk.common.hw },
  419. { .hw = &pll_audio1_div5_clk.common.hw },
  420. };
  421. static SUNXI_CCU_MP_DATA_WITH_MUX_GATE(spi0_clk, "spi0", spi_parents, 0x940,
  422. 0, 4, /* M */
  423. 8, 2, /* P */
  424. 24, 3, /* mux */
  425. BIT(31), /* gate */
  426. 0);
  427. static SUNXI_CCU_MP_DATA_WITH_MUX_GATE(spi1_clk, "spi1", spi_parents, 0x944,
  428. 0, 4, /* M */
  429. 8, 2, /* P */
  430. 24, 3, /* mux */
  431. BIT(31), /* gate */
  432. 0);
  433. static SUNXI_CCU_GATE_HWS(bus_spi0_clk, "bus-spi0", psi_ahb_hws,
  434. 0x96c, BIT(0), 0);
  435. static SUNXI_CCU_GATE_HWS(bus_spi1_clk, "bus-spi1", psi_ahb_hws,
  436. 0x96c, BIT(1), 0);
  437. static SUNXI_CCU_GATE_HWS_WITH_PREDIV(emac_25M_clk, "emac-25M", pll_periph0_hws,
  438. 0x970, BIT(31) | BIT(30), 24, 0);
  439. static SUNXI_CCU_GATE_HWS(bus_emac_clk, "bus-emac", psi_ahb_hws,
  440. 0x97c, BIT(0), 0);
  441. static const struct clk_parent_data ir_tx_ledc_parents[] = {
  442. { .fw_name = "hosc" },
  443. { .hw = &pll_periph0_clk.hw },
  444. };
  445. static SUNXI_CCU_MP_DATA_WITH_MUX_GATE(ir_tx_clk, "ir-tx", ir_tx_ledc_parents, 0x9c0,
  446. 0, 4, /* M */
  447. 8, 2, /* P */
  448. 24, 3, /* mux */
  449. BIT(31), /* gate */
  450. 0);
  451. static SUNXI_CCU_GATE_HWS(bus_ir_tx_clk, "bus-ir-tx", apb0_hws,
  452. 0x9cc, BIT(0), 0);
  453. static SUNXI_CCU_GATE_HWS(bus_gpadc_clk, "bus-gpadc", apb0_hws,
  454. 0x9ec, BIT(0), 0);
  455. static SUNXI_CCU_GATE_HWS(bus_ths_clk, "bus-ths", apb0_hws,
  456. 0x9fc, BIT(0), 0);
  457. static const struct clk_hw *i2s_spdif_tx_parents[] = {
  458. &pll_audio0_clk.hw,
  459. &pll_audio0_4x_clk.common.hw,
  460. &pll_audio1_div2_clk.common.hw,
  461. &pll_audio1_div5_clk.common.hw,
  462. };
  463. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(i2s0_clk, "i2s0", i2s_spdif_tx_parents, 0xa10,
  464. 0, 5, /* M */
  465. 8, 2, /* P */
  466. 24, 3, /* mux */
  467. BIT(31), /* gate */
  468. 0);
  469. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(i2s1_clk, "i2s1", i2s_spdif_tx_parents, 0xa14,
  470. 0, 5, /* M */
  471. 8, 2, /* P */
  472. 24, 3, /* mux */
  473. BIT(31), /* gate */
  474. 0);
  475. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(i2s2_clk, "i2s2", i2s_spdif_tx_parents, 0xa18,
  476. 0, 5, /* M */
  477. 8, 2, /* P */
  478. 24, 3, /* mux */
  479. BIT(31), /* gate */
  480. 0);
  481. static const struct clk_hw *i2s2_asrc_parents[] = {
  482. &pll_audio0_4x_clk.common.hw,
  483. &pll_periph0_clk.hw,
  484. &pll_audio1_div2_clk.common.hw,
  485. &pll_audio1_div5_clk.common.hw,
  486. };
  487. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(i2s2_asrc_clk, "i2s2-asrc", i2s2_asrc_parents, 0xa1c,
  488. 0, 5, /* M */
  489. 8, 2, /* P */
  490. 24, 3, /* mux */
  491. BIT(31), /* gate */
  492. 0);
  493. static SUNXI_CCU_GATE_HWS(bus_i2s0_clk, "bus-i2s0", apb0_hws,
  494. 0xa20, BIT(0), 0);
  495. static SUNXI_CCU_GATE_HWS(bus_i2s1_clk, "bus-i2s1", apb0_hws,
  496. 0xa20, BIT(1), 0);
  497. static SUNXI_CCU_GATE_HWS(bus_i2s2_clk, "bus-i2s2", apb0_hws,
  498. 0xa20, BIT(2), 0);
  499. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(spdif_tx_clk, "spdif-tx", i2s_spdif_tx_parents, 0xa24,
  500. 0, 5, /* M */
  501. 8, 2, /* P */
  502. 24, 3, /* mux */
  503. BIT(31), /* gate */
  504. 0);
  505. static const struct clk_hw *spdif_rx_parents[] = {
  506. &pll_periph0_clk.hw,
  507. &pll_audio1_div2_clk.common.hw,
  508. &pll_audio1_div5_clk.common.hw,
  509. };
  510. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(spdif_rx_clk, "spdif-rx", spdif_rx_parents, 0xa28,
  511. 0, 5, /* M */
  512. 8, 2, /* P */
  513. 24, 3, /* mux */
  514. BIT(31), /* gate */
  515. 0);
  516. static SUNXI_CCU_GATE_HWS(bus_spdif_clk, "bus-spdif", apb0_hws,
  517. 0xa2c, BIT(0), 0);
  518. static const struct clk_hw *dmic_codec_parents[] = {
  519. &pll_audio0_clk.hw,
  520. &pll_audio1_div2_clk.common.hw,
  521. &pll_audio1_div5_clk.common.hw,
  522. };
  523. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(dmic_clk, "dmic", dmic_codec_parents, 0xa40,
  524. 0, 5, /* M */
  525. 8, 2, /* P */
  526. 24, 3, /* mux */
  527. BIT(31), /* gate */
  528. 0);
  529. static SUNXI_CCU_GATE_HWS(bus_dmic_clk, "bus-dmic", apb0_hws,
  530. 0xa4c, BIT(0), 0);
  531. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(audio_dac_clk, "audio-dac", dmic_codec_parents, 0xa50,
  532. 0, 5, /* M */
  533. 8, 2, /* P */
  534. 24, 3, /* mux */
  535. BIT(31), /* gate */
  536. 0);
  537. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(audio_adc_clk, "audio-adc", dmic_codec_parents, 0xa54,
  538. 0, 5, /* M */
  539. 8, 2, /* P */
  540. 24, 3, /* mux */
  541. BIT(31), /* gate */
  542. 0);
  543. static SUNXI_CCU_GATE_HWS(bus_audio_clk, "bus-audio", apb0_hws,
  544. 0xa5c, BIT(0), 0);
  545. /*
  546. * The first parent is a 48 MHz input clock divided by 4. That 48 MHz clock is
  547. * a 2x multiplier from osc24M synchronized by pll-periph0, and is also used by
  548. * the OHCI module.
  549. */
  550. static const struct clk_parent_data usb_ohci_parents[] = {
  551. { .hw = &pll_periph0_clk.hw },
  552. { .fw_name = "hosc" },
  553. { .fw_name = "losc" },
  554. };
  555. static const struct ccu_mux_fixed_prediv usb_ohci_predivs[] = {
  556. { .index = 0, .div = 50 },
  557. { .index = 1, .div = 2 },
  558. };
  559. static struct ccu_mux usb_ohci0_clk = {
  560. .enable = BIT(31),
  561. .mux = {
  562. .shift = 24,
  563. .width = 2,
  564. .fixed_predivs = usb_ohci_predivs,
  565. .n_predivs = ARRAY_SIZE(usb_ohci_predivs),
  566. },
  567. .common = {
  568. .reg = 0xa70,
  569. .features = CCU_FEATURE_FIXED_PREDIV,
  570. .hw.init = CLK_HW_INIT_PARENTS_DATA("usb-ohci0",
  571. usb_ohci_parents,
  572. &ccu_mux_ops,
  573. 0),
  574. },
  575. };
  576. static struct ccu_mux usb_ohci1_clk = {
  577. .enable = BIT(31),
  578. .mux = {
  579. .shift = 24,
  580. .width = 2,
  581. .fixed_predivs = usb_ohci_predivs,
  582. .n_predivs = ARRAY_SIZE(usb_ohci_predivs),
  583. },
  584. .common = {
  585. .reg = 0xa74,
  586. .features = CCU_FEATURE_FIXED_PREDIV,
  587. .hw.init = CLK_HW_INIT_PARENTS_DATA("usb-ohci1",
  588. usb_ohci_parents,
  589. &ccu_mux_ops,
  590. 0),
  591. },
  592. };
  593. static SUNXI_CCU_GATE_HWS(bus_ohci0_clk, "bus-ohci0", psi_ahb_hws,
  594. 0xa8c, BIT(0), 0);
  595. static SUNXI_CCU_GATE_HWS(bus_ohci1_clk, "bus-ohci1", psi_ahb_hws,
  596. 0xa8c, BIT(1), 0);
  597. static SUNXI_CCU_GATE_HWS(bus_ehci0_clk, "bus-ehci0", psi_ahb_hws,
  598. 0xa8c, BIT(4), 0);
  599. static SUNXI_CCU_GATE_HWS(bus_ehci1_clk, "bus-ehci1", psi_ahb_hws,
  600. 0xa8c, BIT(5), 0);
  601. static SUNXI_CCU_GATE_HWS(bus_otg_clk, "bus-otg", psi_ahb_hws,
  602. 0xa8c, BIT(8), 0);
  603. static SUNXI_CCU_GATE_HWS(bus_lradc_clk, "bus-lradc", apb0_hws,
  604. 0xa9c, BIT(0), 0);
  605. static SUNXI_CCU_GATE_HWS(bus_dpss_top_clk, "bus-dpss-top", psi_ahb_hws,
  606. 0xabc, BIT(0), 0);
  607. static SUNXI_CCU_GATE_DATA(hdmi_24M_clk, "hdmi-24M", osc24M,
  608. 0xb04, BIT(31), 0);
  609. static SUNXI_CCU_GATE_HWS_WITH_PREDIV(hdmi_cec_32k_clk, "hdmi-cec-32k",
  610. pll_periph0_2x_hws,
  611. 0xb10, BIT(30), 36621, 0);
  612. static const struct clk_parent_data hdmi_cec_parents[] = {
  613. { .fw_name = "losc" },
  614. { .hw = &hdmi_cec_32k_clk.common.hw },
  615. };
  616. static SUNXI_CCU_MUX_DATA_WITH_GATE(hdmi_cec_clk, "hdmi-cec", hdmi_cec_parents, 0xb10,
  617. 24, 1, /* mux */
  618. BIT(31), /* gate */
  619. 0);
  620. static SUNXI_CCU_GATE_HWS(bus_hdmi_clk, "bus-hdmi", psi_ahb_hws,
  621. 0xb1c, BIT(0), 0);
  622. static const struct clk_parent_data mipi_dsi_parents[] = {
  623. { .fw_name = "hosc" },
  624. { .hw = &pll_periph0_clk.hw },
  625. { .hw = &pll_video0_2x_clk.hw },
  626. { .hw = &pll_video1_2x_clk.hw },
  627. { .hw = &pll_audio1_div2_clk.common.hw },
  628. };
  629. static SUNXI_CCU_M_DATA_WITH_MUX_GATE(mipi_dsi_clk, "mipi-dsi", mipi_dsi_parents, 0xb24,
  630. 0, 4, /* M */
  631. 24, 3, /* mux */
  632. BIT(31), /* gate */
  633. CLK_SET_RATE_PARENT);
  634. static SUNXI_CCU_GATE_HWS(bus_mipi_dsi_clk, "bus-mipi-dsi", psi_ahb_hws,
  635. 0xb4c, BIT(0), 0);
  636. static const struct clk_hw *tcon_tve_parents[] = {
  637. &pll_video0_clk.hw,
  638. &pll_video0_4x_clk.common.hw,
  639. &pll_video1_clk.hw,
  640. &pll_video1_4x_clk.common.hw,
  641. &pll_periph0_2x_clk.common.hw,
  642. &pll_audio1_div2_clk.common.hw,
  643. };
  644. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(tcon_lcd0_clk, "tcon-lcd0", tcon_tve_parents, 0xb60,
  645. 0, 4, /* M */
  646. 8, 2, /* P */
  647. 24, 3, /* mux */
  648. BIT(31), /* gate */
  649. CLK_SET_RATE_PARENT);
  650. static SUNXI_CCU_GATE_HWS(bus_tcon_lcd0_clk, "bus-tcon-lcd0", psi_ahb_hws,
  651. 0xb7c, BIT(0), 0);
  652. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(tcon_tv_clk, "tcon-tv", tcon_tve_parents, 0xb80,
  653. 0, 4, /* M */
  654. 8, 2, /* P */
  655. 24, 3, /* mux */
  656. BIT(31), /* gate */
  657. CLK_SET_RATE_PARENT);
  658. static SUNXI_CCU_GATE_HWS(bus_tcon_tv_clk, "bus-tcon-tv", psi_ahb_hws,
  659. 0xb9c, BIT(0), 0);
  660. static SUNXI_CCU_MP_HW_WITH_MUX_GATE(tve_clk, "tve", tcon_tve_parents, 0xbb0,
  661. 0, 4, /* M */
  662. 8, 2, /* P */
  663. 24, 3, /* mux */
  664. BIT(31), /* gate */
  665. 0);
  666. static SUNXI_CCU_GATE_HWS(bus_tve_top_clk, "bus-tve-top", psi_ahb_hws,
  667. 0xbbc, BIT(0), 0);
  668. static SUNXI_CCU_GATE_HWS(bus_tve_clk, "bus-tve", psi_ahb_hws,
  669. 0xbbc, BIT(1), 0);
  670. static const struct clk_parent_data tvd_parents[] = {
  671. { .fw_name = "hosc" },
  672. { .hw = &pll_video0_clk.hw },
  673. { .hw = &pll_video1_clk.hw },
  674. { .hw = &pll_periph0_clk.hw },
  675. };
  676. static SUNXI_CCU_M_DATA_WITH_MUX_GATE(tvd_clk, "tvd", tvd_parents, 0xbc0,
  677. 0, 5, /* M */
  678. 24, 3, /* mux */
  679. BIT(31), /* gate */
  680. 0);
  681. static SUNXI_CCU_GATE_HWS(bus_tvd_top_clk, "bus-tvd-top", psi_ahb_hws,
  682. 0xbdc, BIT(0), 0);
  683. static SUNXI_CCU_GATE_HWS(bus_tvd_clk, "bus-tvd", psi_ahb_hws,
  684. 0xbdc, BIT(1), 0);
  685. static SUNXI_CCU_MP_DATA_WITH_MUX_GATE(ledc_clk, "ledc", ir_tx_ledc_parents, 0xbf0,
  686. 0, 4, /* M */
  687. 8, 2, /* P */
  688. 24, 1, /* mux */
  689. BIT(31), /* gate */
  690. 0);
  691. static SUNXI_CCU_GATE_HWS(bus_ledc_clk, "bus-ledc", psi_ahb_hws,
  692. 0xbfc, BIT(0), 0);
  693. static const struct clk_hw *csi_top_parents[] = {
  694. &pll_periph0_2x_clk.common.hw,
  695. &pll_video0_2x_clk.hw,
  696. &pll_video1_2x_clk.hw,
  697. };
  698. static SUNXI_CCU_M_HW_WITH_MUX_GATE(csi_top_clk, "csi-top", csi_top_parents, 0xc04,
  699. 0, 4, /* M */
  700. 24, 3, /* mux */
  701. BIT(31), /* gate */
  702. 0);
  703. static const struct clk_parent_data csi_mclk_parents[] = {
  704. { .fw_name = "hosc" },
  705. { .hw = &pll_periph0_clk.hw },
  706. { .hw = &pll_video0_clk.hw },
  707. { .hw = &pll_video1_clk.hw },
  708. { .hw = &pll_audio1_div2_clk.common.hw },
  709. { .hw = &pll_audio1_div5_clk.common.hw },
  710. };
  711. static SUNXI_CCU_M_DATA_WITH_MUX_GATE(csi_mclk_clk, "csi-mclk", csi_mclk_parents, 0xc08,
  712. 0, 5, /* M */
  713. 24, 3, /* mux */
  714. BIT(31), /* gate */
  715. 0);
  716. static SUNXI_CCU_GATE_HWS(bus_csi_clk, "bus-csi", psi_ahb_hws,
  717. 0xc1c, BIT(0), 0);
  718. static const struct clk_parent_data tpadc_parents[] = {
  719. { .fw_name = "hosc" },
  720. { .hw = &pll_audio0_clk.hw },
  721. };
  722. static SUNXI_CCU_MUX_DATA_WITH_GATE(tpadc_clk, "tpadc", tpadc_parents, 0xc50,
  723. 24, 3, /* mux */
  724. BIT(31), /* gate */
  725. 0);
  726. static SUNXI_CCU_GATE_HWS(bus_tpadc_clk, "bus-tpadc", apb0_hws,
  727. 0xc5c, BIT(0), 0);
  728. static SUNXI_CCU_GATE_HWS(bus_tzma_clk, "bus-tzma", apb0_hws,
  729. 0xc6c, BIT(0), 0);
  730. static const struct clk_parent_data dsp_parents[] = {
  731. { .fw_name = "hosc" },
  732. { .fw_name = "losc" },
  733. { .fw_name = "iosc" },
  734. { .hw = &pll_periph0_2x_clk.common.hw },
  735. { .hw = &pll_audio1_div2_clk.common.hw },
  736. };
  737. static SUNXI_CCU_M_DATA_WITH_MUX_GATE(dsp_clk, "dsp", dsp_parents, 0xc70,
  738. 0, 5, /* M */
  739. 24, 3, /* mux */
  740. BIT(31), /* gate */
  741. 0);
  742. static SUNXI_CCU_GATE_HWS(bus_dsp_cfg_clk, "bus-dsp-cfg", psi_ahb_hws,
  743. 0xc7c, BIT(1), 0);
  744. /*
  745. * The RISC-V gate is not modelled - it is in a separate register (0xd04)
  746. * and has a special key field. The clock is critical anyway.
  747. */
  748. static const struct clk_parent_data riscv_parents[] = {
  749. { .fw_name = "hosc" },
  750. { .fw_name = "losc" },
  751. { .fw_name = "iosc" },
  752. { .hw = &pll_periph0_800M_clk.common.hw },
  753. { .hw = &pll_periph0_clk.hw },
  754. { .hw = &pll_cpux_clk.common.hw },
  755. { .hw = &pll_audio1_div2_clk.common.hw },
  756. };
  757. static SUNXI_CCU_M_DATA_WITH_MUX(riscv_clk, "riscv", riscv_parents, 0xd00,
  758. 0, 5, /* M */
  759. 24, 3, /* mux */
  760. CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
  761. /* The riscv-axi clk must be divided by at least 2. */
  762. static struct clk_div_table riscv_axi_table[] = {
  763. { .val = 1, .div = 2 },
  764. { .val = 2, .div = 3 },
  765. { .val = 3, .div = 4 },
  766. { /* Sentinel */ }
  767. };
  768. static SUNXI_CCU_DIV_TABLE_HW(riscv_axi_clk, "riscv-axi", &riscv_clk.common.hw,
  769. 0xd00, 8, 2, riscv_axi_table, 0);
  770. static SUNXI_CCU_GATE_HWS(bus_riscv_cfg_clk, "bus-riscv-cfg", psi_ahb_hws,
  771. 0xd0c, BIT(0), CLK_IS_CRITICAL);
  772. static SUNXI_CCU_GATE_DATA(fanout_24M_clk, "fanout-24M", osc24M,
  773. 0xf30, BIT(0), 0);
  774. static SUNXI_CCU_GATE_DATA_WITH_PREDIV(fanout_12M_clk, "fanout-12M", osc24M,
  775. 0xf30, BIT(1), 2, 0);
  776. static SUNXI_CCU_GATE_HWS_WITH_PREDIV(fanout_16M_clk, "fanout-16M", pll_periph0_2x_hws,
  777. 0xf30, BIT(2), 75, 0);
  778. static SUNXI_CCU_GATE_HWS_WITH_PREDIV(fanout_25M_clk, "fanout-25M", pll_periph0_hws,
  779. 0xf30, BIT(3), 24, 0);
  780. static SUNXI_CCU_GATE_HWS_WITH_PREDIV(fanout_32k_clk, "fanout-32k", pll_periph0_2x_hws,
  781. 0xf30, BIT(4), 36621, 0);
  782. /* This clock has a second divider that is not modelled and forced to 0. */
  783. #define SUN20I_D1_FANOUT_27M_REG 0xf34
  784. static const struct clk_hw *fanout_27M_parents[] = {
  785. &pll_video0_clk.hw,
  786. &pll_video1_clk.hw,
  787. };
  788. static SUNXI_CCU_M_HW_WITH_MUX_GATE(fanout_27M_clk, "fanout-27M", fanout_27M_parents, 0xf34,
  789. 0, 5, /* M */
  790. 24, 2, /* mux */
  791. BIT(31), /* gate */
  792. 0);
  793. static SUNXI_CCU_M_HWS_WITH_GATE(fanout_pclk_clk, "fanout-pclk", apb0_hws, 0xf38,
  794. 0, 5, /* M */
  795. BIT(31), /* gate */
  796. 0);
  797. static const struct clk_hw *fanout_parents[] = {
  798. &fanout_32k_clk.common.hw,
  799. &fanout_12M_clk.common.hw,
  800. &fanout_16M_clk.common.hw,
  801. &fanout_24M_clk.common.hw,
  802. &fanout_25M_clk.common.hw,
  803. &fanout_27M_clk.common.hw,
  804. &fanout_pclk_clk.common.hw,
  805. };
  806. static SUNXI_CCU_MUX_HW_WITH_GATE(fanout0_clk, "fanout0", fanout_parents, 0xf3c,
  807. 0, 3, /* mux */
  808. BIT(21), /* gate */
  809. 0);
  810. static SUNXI_CCU_MUX_HW_WITH_GATE(fanout1_clk, "fanout1", fanout_parents, 0xf3c,
  811. 3, 3, /* mux */
  812. BIT(22), /* gate */
  813. 0);
  814. static SUNXI_CCU_MUX_HW_WITH_GATE(fanout2_clk, "fanout2", fanout_parents, 0xf3c,
  815. 6, 3, /* mux */
  816. BIT(23), /* gate */
  817. 0);
  818. static struct ccu_common *sun20i_d1_ccu_clks[] = {
  819. &pll_cpux_clk.common,
  820. &pll_ddr0_clk.common,
  821. &pll_periph0_4x_clk.common,
  822. &pll_periph0_2x_clk.common,
  823. &pll_periph0_800M_clk.common,
  824. &pll_video0_4x_clk.common,
  825. &pll_video1_4x_clk.common,
  826. &pll_ve_clk.common,
  827. &pll_audio0_4x_clk.common,
  828. &pll_audio1_clk.common,
  829. &pll_audio1_div2_clk.common,
  830. &pll_audio1_div5_clk.common,
  831. &cpux_clk.common,
  832. &cpux_axi_clk.common,
  833. &cpux_apb_clk.common,
  834. &psi_ahb_clk.common,
  835. &apb0_clk.common,
  836. &apb1_clk.common,
  837. &de_clk.common,
  838. &bus_de_clk.common,
  839. &di_clk.common,
  840. &bus_di_clk.common,
  841. &g2d_clk.common,
  842. &bus_g2d_clk.common,
  843. &ce_clk.common,
  844. &bus_ce_clk.common,
  845. &ve_clk.common,
  846. &bus_ve_clk.common,
  847. &bus_dma_clk.common,
  848. &bus_msgbox0_clk.common,
  849. &bus_msgbox1_clk.common,
  850. &bus_msgbox2_clk.common,
  851. &bus_spinlock_clk.common,
  852. &bus_hstimer_clk.common,
  853. &avs_clk.common,
  854. &bus_dbg_clk.common,
  855. &bus_pwm_clk.common,
  856. &bus_iommu_clk.common,
  857. &dram_clk.common,
  858. &mbus_dma_clk.common,
  859. &mbus_ve_clk.common,
  860. &mbus_ce_clk.common,
  861. &mbus_tvin_clk.common,
  862. &mbus_csi_clk.common,
  863. &mbus_g2d_clk.common,
  864. &mbus_riscv_clk.common,
  865. &bus_dram_clk.common,
  866. &mmc0_clk.common,
  867. &mmc1_clk.common,
  868. &mmc2_clk.common,
  869. &bus_mmc0_clk.common,
  870. &bus_mmc1_clk.common,
  871. &bus_mmc2_clk.common,
  872. &bus_uart0_clk.common,
  873. &bus_uart1_clk.common,
  874. &bus_uart2_clk.common,
  875. &bus_uart3_clk.common,
  876. &bus_uart4_clk.common,
  877. &bus_uart5_clk.common,
  878. &bus_i2c0_clk.common,
  879. &bus_i2c1_clk.common,
  880. &bus_i2c2_clk.common,
  881. &bus_i2c3_clk.common,
  882. &spi0_clk.common,
  883. &spi1_clk.common,
  884. &bus_spi0_clk.common,
  885. &bus_spi1_clk.common,
  886. &emac_25M_clk.common,
  887. &bus_emac_clk.common,
  888. &ir_tx_clk.common,
  889. &bus_ir_tx_clk.common,
  890. &bus_gpadc_clk.common,
  891. &bus_ths_clk.common,
  892. &i2s0_clk.common,
  893. &i2s1_clk.common,
  894. &i2s2_clk.common,
  895. &i2s2_asrc_clk.common,
  896. &bus_i2s0_clk.common,
  897. &bus_i2s1_clk.common,
  898. &bus_i2s2_clk.common,
  899. &spdif_tx_clk.common,
  900. &spdif_rx_clk.common,
  901. &bus_spdif_clk.common,
  902. &dmic_clk.common,
  903. &bus_dmic_clk.common,
  904. &audio_dac_clk.common,
  905. &audio_adc_clk.common,
  906. &bus_audio_clk.common,
  907. &usb_ohci0_clk.common,
  908. &usb_ohci1_clk.common,
  909. &bus_ohci0_clk.common,
  910. &bus_ohci1_clk.common,
  911. &bus_ehci0_clk.common,
  912. &bus_ehci1_clk.common,
  913. &bus_otg_clk.common,
  914. &bus_lradc_clk.common,
  915. &bus_dpss_top_clk.common,
  916. &hdmi_24M_clk.common,
  917. &hdmi_cec_32k_clk.common,
  918. &hdmi_cec_clk.common,
  919. &bus_hdmi_clk.common,
  920. &mipi_dsi_clk.common,
  921. &bus_mipi_dsi_clk.common,
  922. &tcon_lcd0_clk.common,
  923. &bus_tcon_lcd0_clk.common,
  924. &tcon_tv_clk.common,
  925. &bus_tcon_tv_clk.common,
  926. &tve_clk.common,
  927. &bus_tve_top_clk.common,
  928. &bus_tve_clk.common,
  929. &tvd_clk.common,
  930. &bus_tvd_top_clk.common,
  931. &bus_tvd_clk.common,
  932. &ledc_clk.common,
  933. &bus_ledc_clk.common,
  934. &csi_top_clk.common,
  935. &csi_mclk_clk.common,
  936. &bus_csi_clk.common,
  937. &tpadc_clk.common,
  938. &bus_tpadc_clk.common,
  939. &bus_tzma_clk.common,
  940. &dsp_clk.common,
  941. &bus_dsp_cfg_clk.common,
  942. &riscv_clk.common,
  943. &riscv_axi_clk.common,
  944. &bus_riscv_cfg_clk.common,
  945. &fanout_24M_clk.common,
  946. &fanout_12M_clk.common,
  947. &fanout_16M_clk.common,
  948. &fanout_25M_clk.common,
  949. &fanout_32k_clk.common,
  950. &fanout_27M_clk.common,
  951. &fanout_pclk_clk.common,
  952. &fanout0_clk.common,
  953. &fanout1_clk.common,
  954. &fanout2_clk.common,
  955. };
  956. static struct clk_hw_onecell_data sun20i_d1_hw_clks = {
  957. .num = CLK_NUMBER,
  958. .hws = {
  959. [CLK_PLL_CPUX] = &pll_cpux_clk.common.hw,
  960. [CLK_PLL_DDR0] = &pll_ddr0_clk.common.hw,
  961. [CLK_PLL_PERIPH0_4X] = &pll_periph0_4x_clk.common.hw,
  962. [CLK_PLL_PERIPH0_2X] = &pll_periph0_2x_clk.common.hw,
  963. [CLK_PLL_PERIPH0_800M] = &pll_periph0_800M_clk.common.hw,
  964. [CLK_PLL_PERIPH0] = &pll_periph0_clk.hw,
  965. [CLK_PLL_PERIPH0_DIV3] = &pll_periph0_div3_clk.hw,
  966. [CLK_PLL_VIDEO0_4X] = &pll_video0_4x_clk.common.hw,
  967. [CLK_PLL_VIDEO0_2X] = &pll_video0_2x_clk.hw,
  968. [CLK_PLL_VIDEO0] = &pll_video0_clk.hw,
  969. [CLK_PLL_VIDEO1_4X] = &pll_video1_4x_clk.common.hw,
  970. [CLK_PLL_VIDEO1_2X] = &pll_video1_2x_clk.hw,
  971. [CLK_PLL_VIDEO1] = &pll_video1_clk.hw,
  972. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  973. [CLK_PLL_AUDIO0_4X] = &pll_audio0_4x_clk.common.hw,
  974. [CLK_PLL_AUDIO0_2X] = &pll_audio0_2x_clk.hw,
  975. [CLK_PLL_AUDIO0] = &pll_audio0_clk.hw,
  976. [CLK_PLL_AUDIO1] = &pll_audio1_clk.common.hw,
  977. [CLK_PLL_AUDIO1_DIV2] = &pll_audio1_div2_clk.common.hw,
  978. [CLK_PLL_AUDIO1_DIV5] = &pll_audio1_div5_clk.common.hw,
  979. [CLK_CPUX] = &cpux_clk.common.hw,
  980. [CLK_CPUX_AXI] = &cpux_axi_clk.common.hw,
  981. [CLK_CPUX_APB] = &cpux_apb_clk.common.hw,
  982. [CLK_PSI_AHB] = &psi_ahb_clk.common.hw,
  983. [CLK_APB0] = &apb0_clk.common.hw,
  984. [CLK_APB1] = &apb1_clk.common.hw,
  985. [CLK_MBUS] = &mbus_clk.hw,
  986. [CLK_DE] = &de_clk.common.hw,
  987. [CLK_BUS_DE] = &bus_de_clk.common.hw,
  988. [CLK_DI] = &di_clk.common.hw,
  989. [CLK_BUS_DI] = &bus_di_clk.common.hw,
  990. [CLK_G2D] = &g2d_clk.common.hw,
  991. [CLK_BUS_G2D] = &bus_g2d_clk.common.hw,
  992. [CLK_CE] = &ce_clk.common.hw,
  993. [CLK_BUS_CE] = &bus_ce_clk.common.hw,
  994. [CLK_VE] = &ve_clk.common.hw,
  995. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  996. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  997. [CLK_BUS_MSGBOX0] = &bus_msgbox0_clk.common.hw,
  998. [CLK_BUS_MSGBOX1] = &bus_msgbox1_clk.common.hw,
  999. [CLK_BUS_MSGBOX2] = &bus_msgbox2_clk.common.hw,
  1000. [CLK_BUS_SPINLOCK] = &bus_spinlock_clk.common.hw,
  1001. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  1002. [CLK_AVS] = &avs_clk.common.hw,
  1003. [CLK_BUS_DBG] = &bus_dbg_clk.common.hw,
  1004. [CLK_BUS_PWM] = &bus_pwm_clk.common.hw,
  1005. [CLK_BUS_IOMMU] = &bus_iommu_clk.common.hw,
  1006. [CLK_DRAM] = &dram_clk.common.hw,
  1007. [CLK_MBUS_DMA] = &mbus_dma_clk.common.hw,
  1008. [CLK_MBUS_VE] = &mbus_ve_clk.common.hw,
  1009. [CLK_MBUS_CE] = &mbus_ce_clk.common.hw,
  1010. [CLK_MBUS_TVIN] = &mbus_tvin_clk.common.hw,
  1011. [CLK_MBUS_CSI] = &mbus_csi_clk.common.hw,
  1012. [CLK_MBUS_G2D] = &mbus_g2d_clk.common.hw,
  1013. [CLK_MBUS_RISCV] = &mbus_riscv_clk.common.hw,
  1014. [CLK_BUS_DRAM] = &bus_dram_clk.common.hw,
  1015. [CLK_MMC0] = &mmc0_clk.common.hw,
  1016. [CLK_MMC1] = &mmc1_clk.common.hw,
  1017. [CLK_MMC2] = &mmc2_clk.common.hw,
  1018. [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw,
  1019. [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw,
  1020. [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw,
  1021. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  1022. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  1023. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  1024. [CLK_BUS_UART3] = &bus_uart3_clk.common.hw,
  1025. [CLK_BUS_UART4] = &bus_uart4_clk.common.hw,
  1026. [CLK_BUS_UART5] = &bus_uart5_clk.common.hw,
  1027. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  1028. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  1029. [CLK_BUS_I2C2] = &bus_i2c2_clk.common.hw,
  1030. [CLK_BUS_I2C3] = &bus_i2c3_clk.common.hw,
  1031. [CLK_SPI0] = &spi0_clk.common.hw,
  1032. [CLK_SPI1] = &spi1_clk.common.hw,
  1033. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  1034. [CLK_BUS_SPI1] = &bus_spi1_clk.common.hw,
  1035. [CLK_EMAC_25M] = &emac_25M_clk.common.hw,
  1036. [CLK_BUS_EMAC] = &bus_emac_clk.common.hw,
  1037. [CLK_IR_TX] = &ir_tx_clk.common.hw,
  1038. [CLK_BUS_IR_TX] = &bus_ir_tx_clk.common.hw,
  1039. [CLK_BUS_GPADC] = &bus_gpadc_clk.common.hw,
  1040. [CLK_BUS_THS] = &bus_ths_clk.common.hw,
  1041. [CLK_I2S0] = &i2s0_clk.common.hw,
  1042. [CLK_I2S1] = &i2s1_clk.common.hw,
  1043. [CLK_I2S2] = &i2s2_clk.common.hw,
  1044. [CLK_I2S2_ASRC] = &i2s2_asrc_clk.common.hw,
  1045. [CLK_BUS_I2S0] = &bus_i2s0_clk.common.hw,
  1046. [CLK_BUS_I2S1] = &bus_i2s1_clk.common.hw,
  1047. [CLK_BUS_I2S2] = &bus_i2s2_clk.common.hw,
  1048. [CLK_SPDIF_TX] = &spdif_tx_clk.common.hw,
  1049. [CLK_SPDIF_RX] = &spdif_rx_clk.common.hw,
  1050. [CLK_BUS_SPDIF] = &bus_spdif_clk.common.hw,
  1051. [CLK_DMIC] = &dmic_clk.common.hw,
  1052. [CLK_BUS_DMIC] = &bus_dmic_clk.common.hw,
  1053. [CLK_AUDIO_DAC] = &audio_dac_clk.common.hw,
  1054. [CLK_AUDIO_ADC] = &audio_adc_clk.common.hw,
  1055. [CLK_BUS_AUDIO] = &bus_audio_clk.common.hw,
  1056. [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
  1057. [CLK_USB_OHCI1] = &usb_ohci1_clk.common.hw,
  1058. [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw,
  1059. [CLK_BUS_OHCI1] = &bus_ohci1_clk.common.hw,
  1060. [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw,
  1061. [CLK_BUS_EHCI1] = &bus_ehci1_clk.common.hw,
  1062. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  1063. [CLK_BUS_LRADC] = &bus_lradc_clk.common.hw,
  1064. [CLK_BUS_DPSS_TOP] = &bus_dpss_top_clk.common.hw,
  1065. [CLK_HDMI_24M] = &hdmi_24M_clk.common.hw,
  1066. [CLK_HDMI_CEC_32K] = &hdmi_cec_32k_clk.common.hw,
  1067. [CLK_HDMI_CEC] = &hdmi_cec_clk.common.hw,
  1068. [CLK_BUS_HDMI] = &bus_hdmi_clk.common.hw,
  1069. [CLK_MIPI_DSI] = &mipi_dsi_clk.common.hw,
  1070. [CLK_BUS_MIPI_DSI] = &bus_mipi_dsi_clk.common.hw,
  1071. [CLK_TCON_LCD0] = &tcon_lcd0_clk.common.hw,
  1072. [CLK_BUS_TCON_LCD0] = &bus_tcon_lcd0_clk.common.hw,
  1073. [CLK_TCON_TV] = &tcon_tv_clk.common.hw,
  1074. [CLK_BUS_TCON_TV] = &bus_tcon_tv_clk.common.hw,
  1075. [CLK_TVE] = &tve_clk.common.hw,
  1076. [CLK_BUS_TVE_TOP] = &bus_tve_top_clk.common.hw,
  1077. [CLK_BUS_TVE] = &bus_tve_clk.common.hw,
  1078. [CLK_TVD] = &tvd_clk.common.hw,
  1079. [CLK_BUS_TVD_TOP] = &bus_tvd_top_clk.common.hw,
  1080. [CLK_BUS_TVD] = &bus_tvd_clk.common.hw,
  1081. [CLK_LEDC] = &ledc_clk.common.hw,
  1082. [CLK_BUS_LEDC] = &bus_ledc_clk.common.hw,
  1083. [CLK_CSI_TOP] = &csi_top_clk.common.hw,
  1084. [CLK_CSI_MCLK] = &csi_mclk_clk.common.hw,
  1085. [CLK_BUS_CSI] = &bus_csi_clk.common.hw,
  1086. [CLK_TPADC] = &tpadc_clk.common.hw,
  1087. [CLK_BUS_TPADC] = &bus_tpadc_clk.common.hw,
  1088. [CLK_BUS_TZMA] = &bus_tzma_clk.common.hw,
  1089. [CLK_DSP] = &dsp_clk.common.hw,
  1090. [CLK_BUS_DSP_CFG] = &bus_dsp_cfg_clk.common.hw,
  1091. [CLK_RISCV] = &riscv_clk.common.hw,
  1092. [CLK_RISCV_AXI] = &riscv_axi_clk.common.hw,
  1093. [CLK_BUS_RISCV_CFG] = &bus_riscv_cfg_clk.common.hw,
  1094. [CLK_FANOUT_24M] = &fanout_24M_clk.common.hw,
  1095. [CLK_FANOUT_12M] = &fanout_12M_clk.common.hw,
  1096. [CLK_FANOUT_16M] = &fanout_16M_clk.common.hw,
  1097. [CLK_FANOUT_25M] = &fanout_25M_clk.common.hw,
  1098. [CLK_FANOUT_32K] = &fanout_32k_clk.common.hw,
  1099. [CLK_FANOUT_27M] = &fanout_27M_clk.common.hw,
  1100. [CLK_FANOUT_PCLK] = &fanout_pclk_clk.common.hw,
  1101. [CLK_FANOUT0] = &fanout0_clk.common.hw,
  1102. [CLK_FANOUT1] = &fanout1_clk.common.hw,
  1103. [CLK_FANOUT2] = &fanout2_clk.common.hw,
  1104. },
  1105. };
  1106. static struct ccu_reset_map sun20i_d1_ccu_resets[] = {
  1107. [RST_MBUS] = { 0x540, BIT(30) },
  1108. [RST_BUS_DE] = { 0x60c, BIT(16) },
  1109. [RST_BUS_DI] = { 0x62c, BIT(16) },
  1110. [RST_BUS_G2D] = { 0x63c, BIT(16) },
  1111. [RST_BUS_CE] = { 0x68c, BIT(16) },
  1112. [RST_BUS_VE] = { 0x69c, BIT(16) },
  1113. [RST_BUS_DMA] = { 0x70c, BIT(16) },
  1114. [RST_BUS_MSGBOX0] = { 0x71c, BIT(16) },
  1115. [RST_BUS_MSGBOX1] = { 0x71c, BIT(17) },
  1116. [RST_BUS_MSGBOX2] = { 0x71c, BIT(18) },
  1117. [RST_BUS_SPINLOCK] = { 0x72c, BIT(16) },
  1118. [RST_BUS_HSTIMER] = { 0x73c, BIT(16) },
  1119. [RST_BUS_DBG] = { 0x78c, BIT(16) },
  1120. [RST_BUS_PWM] = { 0x7ac, BIT(16) },
  1121. [RST_BUS_DRAM] = { 0x80c, BIT(16) },
  1122. [RST_BUS_MMC0] = { 0x84c, BIT(16) },
  1123. [RST_BUS_MMC1] = { 0x84c, BIT(17) },
  1124. [RST_BUS_MMC2] = { 0x84c, BIT(18) },
  1125. [RST_BUS_UART0] = { 0x90c, BIT(16) },
  1126. [RST_BUS_UART1] = { 0x90c, BIT(17) },
  1127. [RST_BUS_UART2] = { 0x90c, BIT(18) },
  1128. [RST_BUS_UART3] = { 0x90c, BIT(19) },
  1129. [RST_BUS_UART4] = { 0x90c, BIT(20) },
  1130. [RST_BUS_UART5] = { 0x90c, BIT(21) },
  1131. [RST_BUS_I2C0] = { 0x91c, BIT(16) },
  1132. [RST_BUS_I2C1] = { 0x91c, BIT(17) },
  1133. [RST_BUS_I2C2] = { 0x91c, BIT(18) },
  1134. [RST_BUS_I2C3] = { 0x91c, BIT(19) },
  1135. [RST_BUS_SPI0] = { 0x96c, BIT(16) },
  1136. [RST_BUS_SPI1] = { 0x96c, BIT(17) },
  1137. [RST_BUS_EMAC] = { 0x97c, BIT(16) },
  1138. [RST_BUS_IR_TX] = { 0x9cc, BIT(16) },
  1139. [RST_BUS_GPADC] = { 0x9ec, BIT(16) },
  1140. [RST_BUS_THS] = { 0x9fc, BIT(16) },
  1141. [RST_BUS_I2S0] = { 0xa20, BIT(16) },
  1142. [RST_BUS_I2S1] = { 0xa20, BIT(17) },
  1143. [RST_BUS_I2S2] = { 0xa20, BIT(18) },
  1144. [RST_BUS_SPDIF] = { 0xa2c, BIT(16) },
  1145. [RST_BUS_DMIC] = { 0xa4c, BIT(16) },
  1146. [RST_BUS_AUDIO] = { 0xa5c, BIT(16) },
  1147. [RST_USB_PHY0] = { 0xa70, BIT(30) },
  1148. [RST_USB_PHY1] = { 0xa74, BIT(30) },
  1149. [RST_BUS_OHCI0] = { 0xa8c, BIT(16) },
  1150. [RST_BUS_OHCI1] = { 0xa8c, BIT(17) },
  1151. [RST_BUS_EHCI0] = { 0xa8c, BIT(20) },
  1152. [RST_BUS_EHCI1] = { 0xa8c, BIT(21) },
  1153. [RST_BUS_OTG] = { 0xa8c, BIT(24) },
  1154. [RST_BUS_LRADC] = { 0xa9c, BIT(16) },
  1155. [RST_BUS_DPSS_TOP] = { 0xabc, BIT(16) },
  1156. [RST_BUS_HDMI_MAIN] = { 0xb1c, BIT(16) },
  1157. [RST_BUS_HDMI_SUB] = { 0xb1c, BIT(17) },
  1158. [RST_BUS_MIPI_DSI] = { 0xb4c, BIT(16) },
  1159. [RST_BUS_TCON_LCD0] = { 0xb7c, BIT(16) },
  1160. [RST_BUS_TCON_TV] = { 0xb9c, BIT(16) },
  1161. [RST_BUS_LVDS0] = { 0xbac, BIT(16) },
  1162. [RST_BUS_TVE_TOP] = { 0xbbc, BIT(16) },
  1163. [RST_BUS_TVE] = { 0xbbc, BIT(17) },
  1164. [RST_BUS_TVD_TOP] = { 0xbdc, BIT(16) },
  1165. [RST_BUS_TVD] = { 0xbdc, BIT(17) },
  1166. [RST_BUS_LEDC] = { 0xbfc, BIT(16) },
  1167. [RST_BUS_CSI] = { 0xc1c, BIT(16) },
  1168. [RST_BUS_TPADC] = { 0xc5c, BIT(16) },
  1169. [RST_DSP] = { 0xc7c, BIT(16) },
  1170. [RST_BUS_DSP_CFG] = { 0xc7c, BIT(17) },
  1171. [RST_BUS_DSP_DBG] = { 0xc7c, BIT(18) },
  1172. [RST_BUS_RISCV_CFG] = { 0xd0c, BIT(16) },
  1173. };
  1174. static const struct sunxi_ccu_desc sun20i_d1_ccu_desc = {
  1175. .ccu_clks = sun20i_d1_ccu_clks,
  1176. .num_ccu_clks = ARRAY_SIZE(sun20i_d1_ccu_clks),
  1177. .hw_clks = &sun20i_d1_hw_clks,
  1178. .resets = sun20i_d1_ccu_resets,
  1179. .num_resets = ARRAY_SIZE(sun20i_d1_ccu_resets),
  1180. };
  1181. static const u32 pll_regs[] = {
  1182. SUN20I_D1_PLL_CPUX_REG,
  1183. SUN20I_D1_PLL_DDR0_REG,
  1184. SUN20I_D1_PLL_PERIPH0_REG,
  1185. SUN20I_D1_PLL_VIDEO0_REG,
  1186. SUN20I_D1_PLL_VIDEO1_REG,
  1187. SUN20I_D1_PLL_VE_REG,
  1188. SUN20I_D1_PLL_AUDIO0_REG,
  1189. SUN20I_D1_PLL_AUDIO1_REG,
  1190. };
  1191. static const u32 pll_video_regs[] = {
  1192. SUN20I_D1_PLL_VIDEO0_REG,
  1193. SUN20I_D1_PLL_VIDEO1_REG,
  1194. };
  1195. static struct ccu_mux_nb sun20i_d1_riscv_nb = {
  1196. .common = &riscv_clk.common,
  1197. .cm = &riscv_clk.mux,
  1198. .delay_us = 1,
  1199. .bypass_index = 4, /* index of pll-periph0 */
  1200. };
  1201. static int sun20i_d1_ccu_probe(struct platform_device *pdev)
  1202. {
  1203. void __iomem *reg;
  1204. u32 val;
  1205. int i, ret;
  1206. reg = devm_platform_ioremap_resource(pdev, 0);
  1207. if (IS_ERR(reg))
  1208. return PTR_ERR(reg);
  1209. /* Enable the enable, LDO, and lock bits on all PLLs. */
  1210. for (i = 0; i < ARRAY_SIZE(pll_regs); i++) {
  1211. val = readl(reg + pll_regs[i]);
  1212. val |= BIT(31) | BIT(30) | BIT(29);
  1213. writel(val, reg + pll_regs[i]);
  1214. }
  1215. /* Force PLL_CPUX factor M to 0. */
  1216. val = readl(reg + SUN20I_D1_PLL_CPUX_REG);
  1217. val &= ~GENMASK(1, 0);
  1218. writel(val, reg + SUN20I_D1_PLL_CPUX_REG);
  1219. /*
  1220. * Force the output divider of video PLLs to 0.
  1221. *
  1222. * See the comment before pll-video0 definition for the reason.
  1223. */
  1224. for (i = 0; i < ARRAY_SIZE(pll_video_regs); i++) {
  1225. val = readl(reg + pll_video_regs[i]);
  1226. val &= ~BIT(0);
  1227. writel(val, reg + pll_video_regs[i]);
  1228. }
  1229. /* Enforce m1 = 0, m0 = 0 for PLL_AUDIO0 */
  1230. val = readl(reg + SUN20I_D1_PLL_AUDIO0_REG);
  1231. val &= ~BIT(1) | BIT(0);
  1232. writel(val, reg + SUN20I_D1_PLL_AUDIO0_REG);
  1233. /* Force fanout-27M factor N to 0. */
  1234. val = readl(reg + SUN20I_D1_FANOUT_27M_REG);
  1235. val &= ~GENMASK(9, 8);
  1236. writel(val, reg + SUN20I_D1_FANOUT_27M_REG);
  1237. ret = devm_sunxi_ccu_probe(&pdev->dev, reg, &sun20i_d1_ccu_desc);
  1238. if (ret)
  1239. return ret;
  1240. /* Reparent CPU during PLL CPUX rate changes */
  1241. ccu_mux_notifier_register(pll_cpux_clk.common.hw.clk,
  1242. &sun20i_d1_riscv_nb);
  1243. return 0;
  1244. }
  1245. static const struct of_device_id sun20i_d1_ccu_ids[] = {
  1246. { .compatible = "allwinner,sun20i-d1-ccu" },
  1247. { }
  1248. };
  1249. static struct platform_driver sun20i_d1_ccu_driver = {
  1250. .probe = sun20i_d1_ccu_probe,
  1251. .driver = {
  1252. .name = "sun20i-d1-ccu",
  1253. .suppress_bind_attrs = true,
  1254. .of_match_table = sun20i_d1_ccu_ids,
  1255. },
  1256. };
  1257. module_platform_driver(sun20i_d1_ccu_driver);
  1258. MODULE_IMPORT_NS(SUNXI_CCU);
  1259. MODULE_LICENSE("GPL");