ccu-sun6i-a31.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. /*
  2. * Copyright (c) 2016 Chen-Yu Tsai
  3. *
  4. * Chen-Yu Tsai <wens@csie.org>
  5. *
  6. * Based on ccu-sun8i-h3.c by Maxime Ripard.
  7. *
  8. * This software is licensed under the terms of the GNU General Public
  9. * License version 2, as published by the Free Software Foundation, and
  10. * may be copied, distributed, and modified under those terms.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/clk-provider.h>
  18. #include <linux/of_address.h>
  19. #include "ccu_common.h"
  20. #include "ccu_reset.h"
  21. #include "ccu_div.h"
  22. #include "ccu_gate.h"
  23. #include "ccu_mp.h"
  24. #include "ccu_mult.h"
  25. #include "ccu_mux.h"
  26. #include "ccu_nk.h"
  27. #include "ccu_nkm.h"
  28. #include "ccu_nkmp.h"
  29. #include "ccu_nm.h"
  30. #include "ccu_phase.h"
  31. #include "ccu-sun6i-a31.h"
  32. static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_cpu_clk, "pll-cpu",
  33. "osc24M", 0x000,
  34. 8, 5, /* N */
  35. 4, 2, /* K */
  36. 0, 2, /* M */
  37. BIT(31), /* gate */
  38. BIT(28), /* lock */
  39. 0);
  40. /*
  41. * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from
  42. * the base (2x, 4x and 8x), and one variable divider (the one true
  43. * pll audio).
  44. *
  45. * We don't have any need for the variable divider for now, so we just
  46. * hardcode it to match with the clock names
  47. */
  48. #define SUN6I_A31_PLL_AUDIO_REG 0x008
  49. static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
  50. "osc24M", 0x008,
  51. 8, 7, /* N */
  52. 0, 5, /* M */
  53. BIT(31), /* gate */
  54. BIT(28), /* lock */
  55. CLK_SET_RATE_UNGATE);
  56. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video0_clk, "pll-video0",
  57. "osc24M", 0x010,
  58. 8, 7, /* N */
  59. 0, 4, /* M */
  60. BIT(24), /* frac enable */
  61. BIT(25), /* frac select */
  62. 270000000, /* frac rate 0 */
  63. 297000000, /* frac rate 1 */
  64. BIT(31), /* gate */
  65. BIT(28), /* lock */
  66. CLK_SET_RATE_UNGATE);
  67. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve",
  68. "osc24M", 0x018,
  69. 8, 7, /* N */
  70. 0, 4, /* M */
  71. BIT(24), /* frac enable */
  72. BIT(25), /* frac select */
  73. 270000000, /* frac rate 0 */
  74. 297000000, /* frac rate 1 */
  75. BIT(31), /* gate */
  76. BIT(28), /* lock */
  77. CLK_SET_RATE_UNGATE);
  78. static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr_clk, "pll-ddr",
  79. "osc24M", 0x020,
  80. 8, 5, /* N */
  81. 4, 2, /* K */
  82. 0, 2, /* M */
  83. BIT(31), /* gate */
  84. BIT(28), /* lock */
  85. CLK_SET_RATE_UNGATE);
  86. static SUNXI_CCU_NK_WITH_GATE_LOCK_POSTDIV(pll_periph_clk, "pll-periph",
  87. "osc24M", 0x028,
  88. 8, 5, /* N */
  89. 4, 2, /* K */
  90. BIT(31), /* gate */
  91. BIT(28), /* lock */
  92. 2, /* post-div */
  93. CLK_SET_RATE_UNGATE);
  94. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video1_clk, "pll-video1",
  95. "osc24M", 0x030,
  96. 8, 7, /* N */
  97. 0, 4, /* M */
  98. BIT(24), /* frac enable */
  99. BIT(25), /* frac select */
  100. 270000000, /* frac rate 0 */
  101. 297000000, /* frac rate 1 */
  102. BIT(31), /* gate */
  103. BIT(28), /* lock */
  104. CLK_SET_RATE_UNGATE);
  105. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_gpu_clk, "pll-gpu",
  106. "osc24M", 0x038,
  107. 8, 7, /* N */
  108. 0, 4, /* M */
  109. BIT(24), /* frac enable */
  110. BIT(25), /* frac select */
  111. 270000000, /* frac rate 0 */
  112. 297000000, /* frac rate 1 */
  113. BIT(31), /* gate */
  114. BIT(28), /* lock */
  115. CLK_SET_RATE_UNGATE);
  116. /*
  117. * The MIPI PLL has 2 modes: "MIPI" and "HDMI".
  118. *
  119. * The MIPI mode is a standard NKM-style clock. The HDMI mode is an
  120. * integer / fractional clock with switchable multipliers and dividers.
  121. * This is not supported here. We hardcode the PLL to MIPI mode.
  122. */
  123. #define SUN6I_A31_PLL_MIPI_REG 0x040
  124. static const char * const pll_mipi_parents[] = { "pll-video0", "pll-video1" };
  125. static SUNXI_CCU_NKM_WITH_MUX_GATE_LOCK(pll_mipi_clk, "pll-mipi",
  126. pll_mipi_parents, 0x040,
  127. 8, 4, /* N */
  128. 4, 2, /* K */
  129. 0, 4, /* M */
  130. 21, 0, /* mux */
  131. BIT(31) | BIT(23) | BIT(22), /* gate */
  132. BIT(28), /* lock */
  133. CLK_SET_RATE_UNGATE);
  134. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll9_clk, "pll9",
  135. "osc24M", 0x044,
  136. 8, 7, /* N */
  137. 0, 4, /* M */
  138. BIT(24), /* frac enable */
  139. BIT(25), /* frac select */
  140. 270000000, /* frac rate 0 */
  141. 297000000, /* frac rate 1 */
  142. BIT(31), /* gate */
  143. BIT(28), /* lock */
  144. CLK_SET_RATE_UNGATE);
  145. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll10_clk, "pll10",
  146. "osc24M", 0x048,
  147. 8, 7, /* N */
  148. 0, 4, /* M */
  149. BIT(24), /* frac enable */
  150. BIT(25), /* frac select */
  151. 270000000, /* frac rate 0 */
  152. 297000000, /* frac rate 1 */
  153. BIT(31), /* gate */
  154. BIT(28), /* lock */
  155. CLK_SET_RATE_UNGATE);
  156. static const char * const cpux_parents[] = { "osc32k", "osc24M",
  157. "pll-cpu", "pll-cpu" };
  158. static SUNXI_CCU_MUX(cpu_clk, "cpu", cpux_parents,
  159. 0x050, 16, 2, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
  160. static struct clk_div_table axi_div_table[] = {
  161. { .val = 0, .div = 1 },
  162. { .val = 1, .div = 2 },
  163. { .val = 2, .div = 3 },
  164. { .val = 3, .div = 4 },
  165. { .val = 4, .div = 4 },
  166. { .val = 5, .div = 4 },
  167. { .val = 6, .div = 4 },
  168. { .val = 7, .div = 4 },
  169. { /* Sentinel */ },
  170. };
  171. static SUNXI_CCU_DIV_TABLE(axi_clk, "axi", "cpu",
  172. 0x050, 0, 3, axi_div_table, 0);
  173. #define SUN6I_A31_AHB1_REG 0x054
  174. static const char * const ahb1_parents[] = { "osc32k", "osc24M",
  175. "axi", "pll-periph" };
  176. static struct ccu_div ahb1_clk = {
  177. .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
  178. .mux = {
  179. .shift = 12,
  180. .width = 2,
  181. .variable_prediv = {
  182. .index = 3,
  183. .shift = 6,
  184. .width = 2,
  185. },
  186. },
  187. .common = {
  188. .reg = 0x054,
  189. .features = CCU_FEATURE_VARIABLE_PREDIV,
  190. .hw.init = CLK_HW_INIT_PARENTS("ahb1",
  191. ahb1_parents,
  192. &ccu_div_ops,
  193. 0),
  194. },
  195. };
  196. static struct clk_div_table apb1_div_table[] = {
  197. { .val = 0, .div = 2 },
  198. { .val = 1, .div = 2 },
  199. { .val = 2, .div = 4 },
  200. { .val = 3, .div = 8 },
  201. { /* Sentinel */ },
  202. };
  203. static SUNXI_CCU_DIV_TABLE(apb1_clk, "apb1", "ahb1",
  204. 0x054, 8, 2, apb1_div_table, 0);
  205. static const char * const apb2_parents[] = { "osc32k", "osc24M",
  206. "pll-periph", "pll-periph" };
  207. static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", apb2_parents, 0x058,
  208. 0, 5, /* M */
  209. 16, 2, /* P */
  210. 24, 2, /* mux */
  211. 0);
  212. static SUNXI_CCU_GATE(ahb1_mipidsi_clk, "ahb1-mipidsi", "ahb1",
  213. 0x060, BIT(1), 0);
  214. static SUNXI_CCU_GATE(ahb1_ss_clk, "ahb1-ss", "ahb1",
  215. 0x060, BIT(5), 0);
  216. static SUNXI_CCU_GATE(ahb1_dma_clk, "ahb1-dma", "ahb1",
  217. 0x060, BIT(6), 0);
  218. static SUNXI_CCU_GATE(ahb1_mmc0_clk, "ahb1-mmc0", "ahb1",
  219. 0x060, BIT(8), 0);
  220. static SUNXI_CCU_GATE(ahb1_mmc1_clk, "ahb1-mmc1", "ahb1",
  221. 0x060, BIT(9), 0);
  222. static SUNXI_CCU_GATE(ahb1_mmc2_clk, "ahb1-mmc2", "ahb1",
  223. 0x060, BIT(10), 0);
  224. static SUNXI_CCU_GATE(ahb1_mmc3_clk, "ahb1-mmc3", "ahb1",
  225. 0x060, BIT(12), 0);
  226. static SUNXI_CCU_GATE(ahb1_nand1_clk, "ahb1-nand1", "ahb1",
  227. 0x060, BIT(13), 0);
  228. static SUNXI_CCU_GATE(ahb1_nand0_clk, "ahb1-nand0", "ahb1",
  229. 0x060, BIT(13), 0);
  230. static SUNXI_CCU_GATE(ahb1_sdram_clk, "ahb1-sdram", "ahb1",
  231. 0x060, BIT(14), 0);
  232. static SUNXI_CCU_GATE(ahb1_emac_clk, "ahb1-emac", "ahb1",
  233. 0x060, BIT(17), 0);
  234. static SUNXI_CCU_GATE(ahb1_ts_clk, "ahb1-ts", "ahb1",
  235. 0x060, BIT(18), 0);
  236. static SUNXI_CCU_GATE(ahb1_hstimer_clk, "ahb1-hstimer", "ahb1",
  237. 0x060, BIT(19), 0);
  238. static SUNXI_CCU_GATE(ahb1_spi0_clk, "ahb1-spi0", "ahb1",
  239. 0x060, BIT(20), 0);
  240. static SUNXI_CCU_GATE(ahb1_spi1_clk, "ahb1-spi1", "ahb1",
  241. 0x060, BIT(21), 0);
  242. static SUNXI_CCU_GATE(ahb1_spi2_clk, "ahb1-spi2", "ahb1",
  243. 0x060, BIT(22), 0);
  244. static SUNXI_CCU_GATE(ahb1_spi3_clk, "ahb1-spi3", "ahb1",
  245. 0x060, BIT(23), 0);
  246. static SUNXI_CCU_GATE(ahb1_otg_clk, "ahb1-otg", "ahb1",
  247. 0x060, BIT(24), 0);
  248. static SUNXI_CCU_GATE(ahb1_ehci0_clk, "ahb1-ehci0", "ahb1",
  249. 0x060, BIT(26), 0);
  250. static SUNXI_CCU_GATE(ahb1_ehci1_clk, "ahb1-ehci1", "ahb1",
  251. 0x060, BIT(27), 0);
  252. static SUNXI_CCU_GATE(ahb1_ohci0_clk, "ahb1-ohci0", "ahb1",
  253. 0x060, BIT(29), 0);
  254. static SUNXI_CCU_GATE(ahb1_ohci1_clk, "ahb1-ohci1", "ahb1",
  255. 0x060, BIT(30), 0);
  256. static SUNXI_CCU_GATE(ahb1_ohci2_clk, "ahb1-ohci2", "ahb1",
  257. 0x060, BIT(31), 0);
  258. static SUNXI_CCU_GATE(ahb1_ve_clk, "ahb1-ve", "ahb1",
  259. 0x064, BIT(0), 0);
  260. static SUNXI_CCU_GATE(ahb1_lcd0_clk, "ahb1-lcd0", "ahb1",
  261. 0x064, BIT(4), 0);
  262. static SUNXI_CCU_GATE(ahb1_lcd1_clk, "ahb1-lcd1", "ahb1",
  263. 0x064, BIT(5), 0);
  264. static SUNXI_CCU_GATE(ahb1_csi_clk, "ahb1-csi", "ahb1",
  265. 0x064, BIT(8), 0);
  266. static SUNXI_CCU_GATE(ahb1_hdmi_clk, "ahb1-hdmi", "ahb1",
  267. 0x064, BIT(11), 0);
  268. static SUNXI_CCU_GATE(ahb1_be0_clk, "ahb1-be0", "ahb1",
  269. 0x064, BIT(12), 0);
  270. static SUNXI_CCU_GATE(ahb1_be1_clk, "ahb1-be1", "ahb1",
  271. 0x064, BIT(13), 0);
  272. static SUNXI_CCU_GATE(ahb1_fe0_clk, "ahb1-fe0", "ahb1",
  273. 0x064, BIT(14), 0);
  274. static SUNXI_CCU_GATE(ahb1_fe1_clk, "ahb1-fe1", "ahb1",
  275. 0x064, BIT(15), 0);
  276. static SUNXI_CCU_GATE(ahb1_mp_clk, "ahb1-mp", "ahb1",
  277. 0x064, BIT(18), 0);
  278. static SUNXI_CCU_GATE(ahb1_gpu_clk, "ahb1-gpu", "ahb1",
  279. 0x064, BIT(20), 0);
  280. static SUNXI_CCU_GATE(ahb1_deu0_clk, "ahb1-deu0", "ahb1",
  281. 0x064, BIT(23), 0);
  282. static SUNXI_CCU_GATE(ahb1_deu1_clk, "ahb1-deu1", "ahb1",
  283. 0x064, BIT(24), 0);
  284. static SUNXI_CCU_GATE(ahb1_drc0_clk, "ahb1-drc0", "ahb1",
  285. 0x064, BIT(25), 0);
  286. static SUNXI_CCU_GATE(ahb1_drc1_clk, "ahb1-drc1", "ahb1",
  287. 0x064, BIT(26), 0);
  288. static SUNXI_CCU_GATE(apb1_codec_clk, "apb1-codec", "apb1",
  289. 0x068, BIT(0), 0);
  290. static SUNXI_CCU_GATE(apb1_spdif_clk, "apb1-spdif", "apb1",
  291. 0x068, BIT(1), 0);
  292. static SUNXI_CCU_GATE(apb1_digital_mic_clk, "apb1-digital-mic", "apb1",
  293. 0x068, BIT(4), 0);
  294. static SUNXI_CCU_GATE(apb1_pio_clk, "apb1-pio", "apb1",
  295. 0x068, BIT(5), 0);
  296. static SUNXI_CCU_GATE(apb1_daudio0_clk, "apb1-daudio0", "apb1",
  297. 0x068, BIT(12), 0);
  298. static SUNXI_CCU_GATE(apb1_daudio1_clk, "apb1-daudio1", "apb1",
  299. 0x068, BIT(13), 0);
  300. static SUNXI_CCU_GATE(apb2_i2c0_clk, "apb2-i2c0", "apb2",
  301. 0x06c, BIT(0), 0);
  302. static SUNXI_CCU_GATE(apb2_i2c1_clk, "apb2-i2c1", "apb2",
  303. 0x06c, BIT(1), 0);
  304. static SUNXI_CCU_GATE(apb2_i2c2_clk, "apb2-i2c2", "apb2",
  305. 0x06c, BIT(2), 0);
  306. static SUNXI_CCU_GATE(apb2_i2c3_clk, "apb2-i2c3", "apb2",
  307. 0x06c, BIT(3), 0);
  308. static SUNXI_CCU_GATE(apb2_uart0_clk, "apb2-uart0", "apb2",
  309. 0x06c, BIT(16), 0);
  310. static SUNXI_CCU_GATE(apb2_uart1_clk, "apb2-uart1", "apb2",
  311. 0x06c, BIT(17), 0);
  312. static SUNXI_CCU_GATE(apb2_uart2_clk, "apb2-uart2", "apb2",
  313. 0x06c, BIT(18), 0);
  314. static SUNXI_CCU_GATE(apb2_uart3_clk, "apb2-uart3", "apb2",
  315. 0x06c, BIT(19), 0);
  316. static SUNXI_CCU_GATE(apb2_uart4_clk, "apb2-uart4", "apb2",
  317. 0x06c, BIT(20), 0);
  318. static SUNXI_CCU_GATE(apb2_uart5_clk, "apb2-uart5", "apb2",
  319. 0x06c, BIT(21), 0);
  320. static const char * const mod0_default_parents[] = { "osc24M", "pll-periph" };
  321. static SUNXI_CCU_MP_WITH_MUX_GATE(nand0_clk, "nand0", mod0_default_parents,
  322. 0x080,
  323. 0, 4, /* M */
  324. 16, 2, /* P */
  325. 24, 2, /* mux */
  326. BIT(31), /* gate */
  327. 0);
  328. static SUNXI_CCU_MP_WITH_MUX_GATE(nand1_clk, "nand1", mod0_default_parents,
  329. 0x084,
  330. 0, 4, /* M */
  331. 16, 2, /* P */
  332. 24, 2, /* mux */
  333. BIT(31), /* gate */
  334. 0);
  335. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents,
  336. 0x088,
  337. 0, 4, /* M */
  338. 16, 2, /* P */
  339. 24, 2, /* mux */
  340. BIT(31), /* gate */
  341. 0);
  342. static SUNXI_CCU_PHASE(mmc0_sample_clk, "mmc0_sample", "mmc0",
  343. 0x088, 20, 3, 0);
  344. static SUNXI_CCU_PHASE(mmc0_output_clk, "mmc0_output", "mmc0",
  345. 0x088, 8, 3, 0);
  346. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents,
  347. 0x08c,
  348. 0, 4, /* M */
  349. 16, 2, /* P */
  350. 24, 2, /* mux */
  351. BIT(31), /* gate */
  352. 0);
  353. static SUNXI_CCU_PHASE(mmc1_sample_clk, "mmc1_sample", "mmc1",
  354. 0x08c, 20, 3, 0);
  355. static SUNXI_CCU_PHASE(mmc1_output_clk, "mmc1_output", "mmc1",
  356. 0x08c, 8, 3, 0);
  357. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents,
  358. 0x090,
  359. 0, 4, /* M */
  360. 16, 2, /* P */
  361. 24, 2, /* mux */
  362. BIT(31), /* gate */
  363. 0);
  364. static SUNXI_CCU_PHASE(mmc2_sample_clk, "mmc2_sample", "mmc2",
  365. 0x090, 20, 3, 0);
  366. static SUNXI_CCU_PHASE(mmc2_output_clk, "mmc2_output", "mmc2",
  367. 0x090, 8, 3, 0);
  368. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc3_clk, "mmc3", mod0_default_parents,
  369. 0x094,
  370. 0, 4, /* M */
  371. 16, 2, /* P */
  372. 24, 2, /* mux */
  373. BIT(31), /* gate */
  374. 0);
  375. static SUNXI_CCU_PHASE(mmc3_sample_clk, "mmc3_sample", "mmc3",
  376. 0x094, 20, 3, 0);
  377. static SUNXI_CCU_PHASE(mmc3_output_clk, "mmc3_output", "mmc3",
  378. 0x094, 8, 3, 0);
  379. static SUNXI_CCU_MP_WITH_MUX_GATE(ts_clk, "ts", mod0_default_parents, 0x098,
  380. 0, 4, /* M */
  381. 16, 2, /* P */
  382. 24, 2, /* mux */
  383. BIT(31), /* gate */
  384. 0);
  385. static SUNXI_CCU_MP_WITH_MUX_GATE(ss_clk, "ss", mod0_default_parents, 0x09c,
  386. 0, 4, /* M */
  387. 16, 2, /* P */
  388. 24, 2, /* mux */
  389. BIT(31), /* gate */
  390. 0);
  391. static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0,
  392. 0, 4, /* M */
  393. 16, 2, /* P */
  394. 24, 2, /* mux */
  395. BIT(31), /* gate */
  396. 0);
  397. static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", mod0_default_parents, 0x0a4,
  398. 0, 4, /* M */
  399. 16, 2, /* P */
  400. 24, 2, /* mux */
  401. BIT(31), /* gate */
  402. 0);
  403. static SUNXI_CCU_MP_WITH_MUX_GATE(spi2_clk, "spi2", mod0_default_parents, 0x0a8,
  404. 0, 4, /* M */
  405. 16, 2, /* P */
  406. 24, 2, /* mux */
  407. BIT(31), /* gate */
  408. 0);
  409. static SUNXI_CCU_MP_WITH_MUX_GATE(spi3_clk, "spi3", mod0_default_parents, 0x0ac,
  410. 0, 4, /* M */
  411. 16, 2, /* P */
  412. 24, 2, /* mux */
  413. BIT(31), /* gate */
  414. 0);
  415. static const char * const daudio_parents[] = { "pll-audio-8x", "pll-audio-4x",
  416. "pll-audio-2x", "pll-audio" };
  417. static SUNXI_CCU_MUX_WITH_GATE(daudio0_clk, "daudio0", daudio_parents,
  418. 0x0b0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  419. static SUNXI_CCU_MUX_WITH_GATE(daudio1_clk, "daudio1", daudio_parents,
  420. 0x0b4, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  421. static SUNXI_CCU_MUX_WITH_GATE(spdif_clk, "spdif", daudio_parents,
  422. 0x0c0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  423. static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M",
  424. 0x0cc, BIT(8), 0);
  425. static SUNXI_CCU_GATE(usb_phy1_clk, "usb-phy1", "osc24M",
  426. 0x0cc, BIT(9), 0);
  427. static SUNXI_CCU_GATE(usb_phy2_clk, "usb-phy2", "osc24M",
  428. 0x0cc, BIT(10), 0);
  429. static SUNXI_CCU_GATE(usb_ohci0_clk, "usb-ohci0", "osc24M",
  430. 0x0cc, BIT(16), 0);
  431. static SUNXI_CCU_GATE(usb_ohci1_clk, "usb-ohci1", "osc24M",
  432. 0x0cc, BIT(17), 0);
  433. static SUNXI_CCU_GATE(usb_ohci2_clk, "usb-ohci2", "osc24M",
  434. 0x0cc, BIT(18), 0);
  435. /* TODO emac clk not supported yet */
  436. static const char * const dram_parents[] = { "pll-ddr", "pll-periph" };
  437. static SUNXI_CCU_MP_WITH_MUX_GATE(mdfs_clk, "mdfs", dram_parents, 0x0f0,
  438. 0, 4, /* M */
  439. 16, 2, /* P */
  440. 24, 2, /* mux */
  441. BIT(31), /* gate */
  442. CLK_IS_CRITICAL);
  443. static SUNXI_CCU_M_WITH_MUX(sdram0_clk, "sdram0", dram_parents,
  444. 0x0f4, 0, 4, 4, 1, CLK_IS_CRITICAL);
  445. static SUNXI_CCU_M_WITH_MUX(sdram1_clk, "sdram1", dram_parents,
  446. 0x0f4, 8, 4, 12, 1, CLK_IS_CRITICAL);
  447. static SUNXI_CCU_GATE(dram_ve_clk, "dram-ve", "mdfs",
  448. 0x100, BIT(0), 0);
  449. static SUNXI_CCU_GATE(dram_csi_isp_clk, "dram-csi-isp", "mdfs",
  450. 0x100, BIT(1), 0);
  451. static SUNXI_CCU_GATE(dram_ts_clk, "dram-ts", "mdfs",
  452. 0x100, BIT(3), 0);
  453. static SUNXI_CCU_GATE(dram_drc0_clk, "dram-drc0", "mdfs",
  454. 0x100, BIT(16), 0);
  455. static SUNXI_CCU_GATE(dram_drc1_clk, "dram-drc1", "mdfs",
  456. 0x100, BIT(17), 0);
  457. static SUNXI_CCU_GATE(dram_deu0_clk, "dram-deu0", "mdfs",
  458. 0x100, BIT(18), 0);
  459. static SUNXI_CCU_GATE(dram_deu1_clk, "dram-deu1", "mdfs",
  460. 0x100, BIT(19), 0);
  461. static SUNXI_CCU_GATE(dram_fe0_clk, "dram-fe0", "mdfs",
  462. 0x100, BIT(24), 0);
  463. static SUNXI_CCU_GATE(dram_fe1_clk, "dram-fe1", "mdfs",
  464. 0x100, BIT(25), 0);
  465. static SUNXI_CCU_GATE(dram_be0_clk, "dram-be0", "mdfs",
  466. 0x100, BIT(26), 0);
  467. static SUNXI_CCU_GATE(dram_be1_clk, "dram-be1", "mdfs",
  468. 0x100, BIT(27), 0);
  469. static SUNXI_CCU_GATE(dram_mp_clk, "dram-mp", "mdfs",
  470. 0x100, BIT(28), 0);
  471. static const char * const de_parents[] = { "pll-video0", "pll-video1",
  472. "pll-periph-2x", "pll-gpu",
  473. "pll9", "pll10" };
  474. static SUNXI_CCU_M_WITH_MUX_GATE(be0_clk, "be0", de_parents,
  475. 0x104, 0, 4, 24, 3, BIT(31), 0);
  476. static SUNXI_CCU_M_WITH_MUX_GATE(be1_clk, "be1", de_parents,
  477. 0x108, 0, 4, 24, 3, BIT(31), 0);
  478. static SUNXI_CCU_M_WITH_MUX_GATE(fe0_clk, "fe0", de_parents,
  479. 0x10c, 0, 4, 24, 3, BIT(31), 0);
  480. static SUNXI_CCU_M_WITH_MUX_GATE(fe1_clk, "fe1", de_parents,
  481. 0x110, 0, 4, 24, 3, BIT(31), 0);
  482. static const char * const mp_parents[] = { "pll-video0", "pll-video1",
  483. "pll9", "pll10" };
  484. static SUNXI_CCU_M_WITH_MUX_GATE(mp_clk, "mp", mp_parents,
  485. 0x114, 0, 4, 24, 3, BIT(31), 0);
  486. static const char * const lcd_ch0_parents[] = { "pll-video0", "pll-video1",
  487. "pll-video0-2x",
  488. "pll-video1-2x", "pll-mipi" };
  489. static SUNXI_CCU_MUX_WITH_GATE(lcd0_ch0_clk, "lcd0-ch0", lcd_ch0_parents,
  490. 0x118, 24, 2, BIT(31), CLK_SET_RATE_PARENT);
  491. static SUNXI_CCU_MUX_WITH_GATE(lcd1_ch0_clk, "lcd1-ch0", lcd_ch0_parents,
  492. 0x11c, 24, 2, BIT(31), CLK_SET_RATE_PARENT);
  493. static const char * const lcd_ch1_parents[] = { "pll-video0", "pll-video1",
  494. "pll-video0-2x",
  495. "pll-video1-2x" };
  496. static SUNXI_CCU_M_WITH_MUX_GATE(lcd0_ch1_clk, "lcd0-ch1", lcd_ch1_parents,
  497. 0x12c, 0, 4, 24, 3, BIT(31),
  498. CLK_SET_RATE_PARENT);
  499. static SUNXI_CCU_M_WITH_MUX_GATE(lcd1_ch1_clk, "lcd1-ch1", lcd_ch1_parents,
  500. 0x130, 0, 4, 24, 3, BIT(31),
  501. CLK_SET_RATE_PARENT);
  502. static const char * const csi_sclk_parents[] = { "pll-video0", "pll-video1",
  503. "pll9", "pll10", "pll-mipi",
  504. "pll-ve" };
  505. static SUNXI_CCU_M_WITH_MUX_GATE(csi0_sclk_clk, "csi0-sclk", csi_sclk_parents,
  506. 0x134, 16, 4, 24, 3, BIT(31), 0);
  507. static const char * const csi_mclk_parents[] = { "pll-video0", "pll-video1",
  508. "osc24M" };
  509. static const u8 csi_mclk_table[] = { 0, 1, 5 };
  510. static struct ccu_div csi0_mclk_clk = {
  511. .enable = BIT(15),
  512. .div = _SUNXI_CCU_DIV(0, 4),
  513. .mux = _SUNXI_CCU_MUX_TABLE(8, 3, csi_mclk_table),
  514. .common = {
  515. .reg = 0x134,
  516. .hw.init = CLK_HW_INIT_PARENTS("csi0-mclk",
  517. csi_mclk_parents,
  518. &ccu_div_ops,
  519. 0),
  520. },
  521. };
  522. static struct ccu_div csi1_mclk_clk = {
  523. .enable = BIT(15),
  524. .div = _SUNXI_CCU_DIV(0, 4),
  525. .mux = _SUNXI_CCU_MUX_TABLE(8, 3, csi_mclk_table),
  526. .common = {
  527. .reg = 0x138,
  528. .hw.init = CLK_HW_INIT_PARENTS("csi1-mclk",
  529. csi_mclk_parents,
  530. &ccu_div_ops,
  531. 0),
  532. },
  533. };
  534. static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve",
  535. 0x13c, 16, 3, BIT(31), 0);
  536. static SUNXI_CCU_GATE(codec_clk, "codec", "pll-audio",
  537. 0x140, BIT(31), CLK_SET_RATE_PARENT);
  538. static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M",
  539. 0x144, BIT(31), 0);
  540. static SUNXI_CCU_GATE(digital_mic_clk, "digital-mic", "pll-audio",
  541. 0x148, BIT(31), CLK_SET_RATE_PARENT);
  542. static SUNXI_CCU_M_WITH_MUX_GATE(hdmi_clk, "hdmi", lcd_ch1_parents,
  543. 0x150, 0, 4, 24, 2, BIT(31),
  544. CLK_SET_RATE_PARENT);
  545. static SUNXI_CCU_GATE(hdmi_ddc_clk, "ddc", "osc24M", 0x150, BIT(30), 0);
  546. static SUNXI_CCU_GATE(ps_clk, "ps", "lcd1-ch1", 0x140, BIT(31), 0);
  547. static const char * const mbus_parents[] = { "osc24M", "pll-periph",
  548. "pll-ddr" };
  549. static SUNXI_CCU_MP_WITH_MUX_GATE(mbus0_clk, "mbus0", mbus_parents, 0x15c,
  550. 0, 3, /* M */
  551. 16, 2, /* P */
  552. 24, 2, /* mux */
  553. BIT(31), /* gate */
  554. CLK_IS_CRITICAL);
  555. static SUNXI_CCU_MP_WITH_MUX_GATE(mbus1_clk, "mbus1", mbus_parents, 0x160,
  556. 0, 3, /* M */
  557. 16, 2, /* P */
  558. 24, 2, /* mux */
  559. BIT(31), /* gate */
  560. CLK_IS_CRITICAL);
  561. static SUNXI_CCU_M_WITH_MUX_GATE(mipi_dsi_clk, "mipi-dsi", lcd_ch1_parents,
  562. 0x168, 16, 3, 24, 2, BIT(31),
  563. CLK_SET_RATE_PARENT);
  564. static SUNXI_CCU_M_WITH_MUX_GATE(mipi_dsi_dphy_clk, "mipi-dsi-dphy",
  565. lcd_ch1_parents, 0x168, 0, 3, 8, 2,
  566. BIT(15), CLK_SET_RATE_PARENT);
  567. static SUNXI_CCU_M_WITH_MUX_GATE(mipi_csi_dphy_clk, "mipi-csi-dphy",
  568. lcd_ch1_parents, 0x16c, 0, 3, 8, 2,
  569. BIT(15), 0);
  570. static SUNXI_CCU_M_WITH_MUX_GATE(iep_drc0_clk, "iep-drc0", de_parents,
  571. 0x180, 0, 3, 24, 2, BIT(31), 0);
  572. static SUNXI_CCU_M_WITH_MUX_GATE(iep_drc1_clk, "iep-drc1", de_parents,
  573. 0x184, 0, 3, 24, 2, BIT(31), 0);
  574. static SUNXI_CCU_M_WITH_MUX_GATE(iep_deu0_clk, "iep-deu0", de_parents,
  575. 0x188, 0, 3, 24, 2, BIT(31), 0);
  576. static SUNXI_CCU_M_WITH_MUX_GATE(iep_deu1_clk, "iep-deu1", de_parents,
  577. 0x18c, 0, 3, 24, 2, BIT(31), 0);
  578. static const char * const gpu_parents[] = { "pll-gpu", "pll-periph-2x",
  579. "pll-video0", "pll-video1",
  580. "pll9", "pll10" };
  581. static const struct ccu_mux_fixed_prediv gpu_predivs[] = {
  582. { .index = 1, .div = 3, },
  583. };
  584. static struct ccu_div gpu_core_clk = {
  585. .enable = BIT(31),
  586. .div = _SUNXI_CCU_DIV(0, 3),
  587. .mux = {
  588. .shift = 24,
  589. .width = 3,
  590. .fixed_predivs = gpu_predivs,
  591. .n_predivs = ARRAY_SIZE(gpu_predivs),
  592. },
  593. .common = {
  594. .reg = 0x1a0,
  595. .features = CCU_FEATURE_FIXED_PREDIV,
  596. .hw.init = CLK_HW_INIT_PARENTS("gpu-core",
  597. gpu_parents,
  598. &ccu_div_ops,
  599. 0),
  600. },
  601. };
  602. static struct ccu_div gpu_memory_clk = {
  603. .enable = BIT(31),
  604. .div = _SUNXI_CCU_DIV(0, 3),
  605. .mux = {
  606. .shift = 24,
  607. .width = 3,
  608. .fixed_predivs = gpu_predivs,
  609. .n_predivs = ARRAY_SIZE(gpu_predivs),
  610. },
  611. .common = {
  612. .reg = 0x1a4,
  613. .features = CCU_FEATURE_FIXED_PREDIV,
  614. .hw.init = CLK_HW_INIT_PARENTS("gpu-memory",
  615. gpu_parents,
  616. &ccu_div_ops,
  617. 0),
  618. },
  619. };
  620. static struct ccu_div gpu_hyd_clk = {
  621. .enable = BIT(31),
  622. .div = _SUNXI_CCU_DIV(0, 3),
  623. .mux = {
  624. .shift = 24,
  625. .width = 3,
  626. .fixed_predivs = gpu_predivs,
  627. .n_predivs = ARRAY_SIZE(gpu_predivs),
  628. },
  629. .common = {
  630. .reg = 0x1a8,
  631. .features = CCU_FEATURE_FIXED_PREDIV,
  632. .hw.init = CLK_HW_INIT_PARENTS("gpu-hyd",
  633. gpu_parents,
  634. &ccu_div_ops,
  635. 0),
  636. },
  637. };
  638. static SUNXI_CCU_M_WITH_MUX_GATE(ats_clk, "ats", mod0_default_parents, 0x1b0,
  639. 0, 3, /* M */
  640. 24, 2, /* mux */
  641. BIT(31), /* gate */
  642. 0);
  643. static SUNXI_CCU_M_WITH_MUX_GATE(trace_clk, "trace", mod0_default_parents,
  644. 0x1b0,
  645. 0, 3, /* M */
  646. 24, 2, /* mux */
  647. BIT(31), /* gate */
  648. 0);
  649. static const char * const clk_out_parents[] = { "osc24M", "osc32k", "osc24M",
  650. "axi", "ahb1" };
  651. static const u8 clk_out_table[] = { 0, 1, 2, 11, 13 };
  652. static const struct ccu_mux_fixed_prediv clk_out_predivs[] = {
  653. { .index = 0, .div = 750, },
  654. { .index = 3, .div = 4, },
  655. { .index = 4, .div = 4, },
  656. };
  657. static struct ccu_mp out_a_clk = {
  658. .enable = BIT(31),
  659. .m = _SUNXI_CCU_DIV(8, 5),
  660. .p = _SUNXI_CCU_DIV(20, 2),
  661. .mux = {
  662. .shift = 24,
  663. .width = 4,
  664. .table = clk_out_table,
  665. .fixed_predivs = clk_out_predivs,
  666. .n_predivs = ARRAY_SIZE(clk_out_predivs),
  667. },
  668. .common = {
  669. .reg = 0x300,
  670. .features = CCU_FEATURE_FIXED_PREDIV,
  671. .hw.init = CLK_HW_INIT_PARENTS("out-a",
  672. clk_out_parents,
  673. &ccu_mp_ops,
  674. 0),
  675. },
  676. };
  677. static struct ccu_mp out_b_clk = {
  678. .enable = BIT(31),
  679. .m = _SUNXI_CCU_DIV(8, 5),
  680. .p = _SUNXI_CCU_DIV(20, 2),
  681. .mux = {
  682. .shift = 24,
  683. .width = 4,
  684. .table = clk_out_table,
  685. .fixed_predivs = clk_out_predivs,
  686. .n_predivs = ARRAY_SIZE(clk_out_predivs),
  687. },
  688. .common = {
  689. .reg = 0x304,
  690. .features = CCU_FEATURE_FIXED_PREDIV,
  691. .hw.init = CLK_HW_INIT_PARENTS("out-b",
  692. clk_out_parents,
  693. &ccu_mp_ops,
  694. 0),
  695. },
  696. };
  697. static struct ccu_mp out_c_clk = {
  698. .enable = BIT(31),
  699. .m = _SUNXI_CCU_DIV(8, 5),
  700. .p = _SUNXI_CCU_DIV(20, 2),
  701. .mux = {
  702. .shift = 24,
  703. .width = 4,
  704. .table = clk_out_table,
  705. .fixed_predivs = clk_out_predivs,
  706. .n_predivs = ARRAY_SIZE(clk_out_predivs),
  707. },
  708. .common = {
  709. .reg = 0x308,
  710. .features = CCU_FEATURE_FIXED_PREDIV,
  711. .hw.init = CLK_HW_INIT_PARENTS("out-c",
  712. clk_out_parents,
  713. &ccu_mp_ops,
  714. 0),
  715. },
  716. };
  717. static struct ccu_common *sun6i_a31_ccu_clks[] = {
  718. &pll_cpu_clk.common,
  719. &pll_audio_base_clk.common,
  720. &pll_video0_clk.common,
  721. &pll_ve_clk.common,
  722. &pll_ddr_clk.common,
  723. &pll_periph_clk.common,
  724. &pll_video1_clk.common,
  725. &pll_gpu_clk.common,
  726. &pll_mipi_clk.common,
  727. &pll9_clk.common,
  728. &pll10_clk.common,
  729. &cpu_clk.common,
  730. &axi_clk.common,
  731. &ahb1_clk.common,
  732. &apb1_clk.common,
  733. &apb2_clk.common,
  734. &ahb1_mipidsi_clk.common,
  735. &ahb1_ss_clk.common,
  736. &ahb1_dma_clk.common,
  737. &ahb1_mmc0_clk.common,
  738. &ahb1_mmc1_clk.common,
  739. &ahb1_mmc2_clk.common,
  740. &ahb1_mmc3_clk.common,
  741. &ahb1_nand1_clk.common,
  742. &ahb1_nand0_clk.common,
  743. &ahb1_sdram_clk.common,
  744. &ahb1_emac_clk.common,
  745. &ahb1_ts_clk.common,
  746. &ahb1_hstimer_clk.common,
  747. &ahb1_spi0_clk.common,
  748. &ahb1_spi1_clk.common,
  749. &ahb1_spi2_clk.common,
  750. &ahb1_spi3_clk.common,
  751. &ahb1_otg_clk.common,
  752. &ahb1_ehci0_clk.common,
  753. &ahb1_ehci1_clk.common,
  754. &ahb1_ohci0_clk.common,
  755. &ahb1_ohci1_clk.common,
  756. &ahb1_ohci2_clk.common,
  757. &ahb1_ve_clk.common,
  758. &ahb1_lcd0_clk.common,
  759. &ahb1_lcd1_clk.common,
  760. &ahb1_csi_clk.common,
  761. &ahb1_hdmi_clk.common,
  762. &ahb1_be0_clk.common,
  763. &ahb1_be1_clk.common,
  764. &ahb1_fe0_clk.common,
  765. &ahb1_fe1_clk.common,
  766. &ahb1_mp_clk.common,
  767. &ahb1_gpu_clk.common,
  768. &ahb1_deu0_clk.common,
  769. &ahb1_deu1_clk.common,
  770. &ahb1_drc0_clk.common,
  771. &ahb1_drc1_clk.common,
  772. &apb1_codec_clk.common,
  773. &apb1_spdif_clk.common,
  774. &apb1_digital_mic_clk.common,
  775. &apb1_pio_clk.common,
  776. &apb1_daudio0_clk.common,
  777. &apb1_daudio1_clk.common,
  778. &apb2_i2c0_clk.common,
  779. &apb2_i2c1_clk.common,
  780. &apb2_i2c2_clk.common,
  781. &apb2_i2c3_clk.common,
  782. &apb2_uart0_clk.common,
  783. &apb2_uart1_clk.common,
  784. &apb2_uart2_clk.common,
  785. &apb2_uart3_clk.common,
  786. &apb2_uart4_clk.common,
  787. &apb2_uart5_clk.common,
  788. &nand0_clk.common,
  789. &nand1_clk.common,
  790. &mmc0_clk.common,
  791. &mmc0_sample_clk.common,
  792. &mmc0_output_clk.common,
  793. &mmc1_clk.common,
  794. &mmc1_sample_clk.common,
  795. &mmc1_output_clk.common,
  796. &mmc2_clk.common,
  797. &mmc2_sample_clk.common,
  798. &mmc2_output_clk.common,
  799. &mmc3_clk.common,
  800. &mmc3_sample_clk.common,
  801. &mmc3_output_clk.common,
  802. &ts_clk.common,
  803. &ss_clk.common,
  804. &spi0_clk.common,
  805. &spi1_clk.common,
  806. &spi2_clk.common,
  807. &spi3_clk.common,
  808. &daudio0_clk.common,
  809. &daudio1_clk.common,
  810. &spdif_clk.common,
  811. &usb_phy0_clk.common,
  812. &usb_phy1_clk.common,
  813. &usb_phy2_clk.common,
  814. &usb_ohci0_clk.common,
  815. &usb_ohci1_clk.common,
  816. &usb_ohci2_clk.common,
  817. &mdfs_clk.common,
  818. &sdram0_clk.common,
  819. &sdram1_clk.common,
  820. &dram_ve_clk.common,
  821. &dram_csi_isp_clk.common,
  822. &dram_ts_clk.common,
  823. &dram_drc0_clk.common,
  824. &dram_drc1_clk.common,
  825. &dram_deu0_clk.common,
  826. &dram_deu1_clk.common,
  827. &dram_fe0_clk.common,
  828. &dram_fe1_clk.common,
  829. &dram_be0_clk.common,
  830. &dram_be1_clk.common,
  831. &dram_mp_clk.common,
  832. &be0_clk.common,
  833. &be1_clk.common,
  834. &fe0_clk.common,
  835. &fe1_clk.common,
  836. &mp_clk.common,
  837. &lcd0_ch0_clk.common,
  838. &lcd1_ch0_clk.common,
  839. &lcd0_ch1_clk.common,
  840. &lcd1_ch1_clk.common,
  841. &csi0_sclk_clk.common,
  842. &csi0_mclk_clk.common,
  843. &csi1_mclk_clk.common,
  844. &ve_clk.common,
  845. &codec_clk.common,
  846. &avs_clk.common,
  847. &digital_mic_clk.common,
  848. &hdmi_clk.common,
  849. &hdmi_ddc_clk.common,
  850. &ps_clk.common,
  851. &mbus0_clk.common,
  852. &mbus1_clk.common,
  853. &mipi_dsi_clk.common,
  854. &mipi_dsi_dphy_clk.common,
  855. &mipi_csi_dphy_clk.common,
  856. &iep_drc0_clk.common,
  857. &iep_drc1_clk.common,
  858. &iep_deu0_clk.common,
  859. &iep_deu1_clk.common,
  860. &gpu_core_clk.common,
  861. &gpu_memory_clk.common,
  862. &gpu_hyd_clk.common,
  863. &ats_clk.common,
  864. &trace_clk.common,
  865. &out_a_clk.common,
  866. &out_b_clk.common,
  867. &out_c_clk.common,
  868. };
  869. /* We hardcode the divider to 4 for now */
  870. static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio",
  871. "pll-audio-base", 4, 1, CLK_SET_RATE_PARENT);
  872. static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x",
  873. "pll-audio-base", 2, 1, CLK_SET_RATE_PARENT);
  874. static CLK_FIXED_FACTOR(pll_audio_4x_clk, "pll-audio-4x",
  875. "pll-audio-base", 1, 1, CLK_SET_RATE_PARENT);
  876. static CLK_FIXED_FACTOR(pll_audio_8x_clk, "pll-audio-8x",
  877. "pll-audio-base", 1, 2, CLK_SET_RATE_PARENT);
  878. static CLK_FIXED_FACTOR(pll_periph_2x_clk, "pll-periph-2x",
  879. "pll-periph", 1, 2, 0);
  880. static CLK_FIXED_FACTOR(pll_video0_2x_clk, "pll-video0-2x",
  881. "pll-video0", 1, 2, CLK_SET_RATE_PARENT);
  882. static CLK_FIXED_FACTOR(pll_video1_2x_clk, "pll-video1-2x",
  883. "pll-video1", 1, 2, CLK_SET_RATE_PARENT);
  884. static struct clk_hw_onecell_data sun6i_a31_hw_clks = {
  885. .hws = {
  886. [CLK_PLL_CPU] = &pll_cpu_clk.common.hw,
  887. [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
  888. [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
  889. [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
  890. [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
  891. [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw,
  892. [CLK_PLL_VIDEO0] = &pll_video0_clk.common.hw,
  893. [CLK_PLL_VIDEO0_2X] = &pll_video0_2x_clk.hw,
  894. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  895. [CLK_PLL_DDR] = &pll_ddr_clk.common.hw,
  896. [CLK_PLL_PERIPH] = &pll_periph_clk.common.hw,
  897. [CLK_PLL_PERIPH_2X] = &pll_periph_2x_clk.hw,
  898. [CLK_PLL_VIDEO1] = &pll_video1_clk.common.hw,
  899. [CLK_PLL_VIDEO1_2X] = &pll_video1_2x_clk.hw,
  900. [CLK_PLL_GPU] = &pll_gpu_clk.common.hw,
  901. [CLK_PLL_MIPI] = &pll_mipi_clk.common.hw,
  902. [CLK_PLL9] = &pll9_clk.common.hw,
  903. [CLK_PLL10] = &pll10_clk.common.hw,
  904. [CLK_CPU] = &cpu_clk.common.hw,
  905. [CLK_AXI] = &axi_clk.common.hw,
  906. [CLK_AHB1] = &ahb1_clk.common.hw,
  907. [CLK_APB1] = &apb1_clk.common.hw,
  908. [CLK_APB2] = &apb2_clk.common.hw,
  909. [CLK_AHB1_MIPIDSI] = &ahb1_mipidsi_clk.common.hw,
  910. [CLK_AHB1_SS] = &ahb1_ss_clk.common.hw,
  911. [CLK_AHB1_DMA] = &ahb1_dma_clk.common.hw,
  912. [CLK_AHB1_MMC0] = &ahb1_mmc0_clk.common.hw,
  913. [CLK_AHB1_MMC1] = &ahb1_mmc1_clk.common.hw,
  914. [CLK_AHB1_MMC2] = &ahb1_mmc2_clk.common.hw,
  915. [CLK_AHB1_MMC3] = &ahb1_mmc3_clk.common.hw,
  916. [CLK_AHB1_NAND1] = &ahb1_nand1_clk.common.hw,
  917. [CLK_AHB1_NAND0] = &ahb1_nand0_clk.common.hw,
  918. [CLK_AHB1_SDRAM] = &ahb1_sdram_clk.common.hw,
  919. [CLK_AHB1_EMAC] = &ahb1_emac_clk.common.hw,
  920. [CLK_AHB1_TS] = &ahb1_ts_clk.common.hw,
  921. [CLK_AHB1_HSTIMER] = &ahb1_hstimer_clk.common.hw,
  922. [CLK_AHB1_SPI0] = &ahb1_spi0_clk.common.hw,
  923. [CLK_AHB1_SPI1] = &ahb1_spi1_clk.common.hw,
  924. [CLK_AHB1_SPI2] = &ahb1_spi2_clk.common.hw,
  925. [CLK_AHB1_SPI3] = &ahb1_spi3_clk.common.hw,
  926. [CLK_AHB1_OTG] = &ahb1_otg_clk.common.hw,
  927. [CLK_AHB1_EHCI0] = &ahb1_ehci0_clk.common.hw,
  928. [CLK_AHB1_EHCI1] = &ahb1_ehci1_clk.common.hw,
  929. [CLK_AHB1_OHCI0] = &ahb1_ohci0_clk.common.hw,
  930. [CLK_AHB1_OHCI1] = &ahb1_ohci1_clk.common.hw,
  931. [CLK_AHB1_OHCI2] = &ahb1_ohci2_clk.common.hw,
  932. [CLK_AHB1_VE] = &ahb1_ve_clk.common.hw,
  933. [CLK_AHB1_LCD0] = &ahb1_lcd0_clk.common.hw,
  934. [CLK_AHB1_LCD1] = &ahb1_lcd1_clk.common.hw,
  935. [CLK_AHB1_CSI] = &ahb1_csi_clk.common.hw,
  936. [CLK_AHB1_HDMI] = &ahb1_hdmi_clk.common.hw,
  937. [CLK_AHB1_BE0] = &ahb1_be0_clk.common.hw,
  938. [CLK_AHB1_BE1] = &ahb1_be1_clk.common.hw,
  939. [CLK_AHB1_FE0] = &ahb1_fe0_clk.common.hw,
  940. [CLK_AHB1_FE1] = &ahb1_fe1_clk.common.hw,
  941. [CLK_AHB1_MP] = &ahb1_mp_clk.common.hw,
  942. [CLK_AHB1_GPU] = &ahb1_gpu_clk.common.hw,
  943. [CLK_AHB1_DEU0] = &ahb1_deu0_clk.common.hw,
  944. [CLK_AHB1_DEU1] = &ahb1_deu1_clk.common.hw,
  945. [CLK_AHB1_DRC0] = &ahb1_drc0_clk.common.hw,
  946. [CLK_AHB1_DRC1] = &ahb1_drc1_clk.common.hw,
  947. [CLK_APB1_CODEC] = &apb1_codec_clk.common.hw,
  948. [CLK_APB1_SPDIF] = &apb1_spdif_clk.common.hw,
  949. [CLK_APB1_DIGITAL_MIC] = &apb1_digital_mic_clk.common.hw,
  950. [CLK_APB1_PIO] = &apb1_pio_clk.common.hw,
  951. [CLK_APB1_DAUDIO0] = &apb1_daudio0_clk.common.hw,
  952. [CLK_APB1_DAUDIO1] = &apb1_daudio1_clk.common.hw,
  953. [CLK_APB2_I2C0] = &apb2_i2c0_clk.common.hw,
  954. [CLK_APB2_I2C1] = &apb2_i2c1_clk.common.hw,
  955. [CLK_APB2_I2C2] = &apb2_i2c2_clk.common.hw,
  956. [CLK_APB2_I2C3] = &apb2_i2c3_clk.common.hw,
  957. [CLK_APB2_UART0] = &apb2_uart0_clk.common.hw,
  958. [CLK_APB2_UART1] = &apb2_uart1_clk.common.hw,
  959. [CLK_APB2_UART2] = &apb2_uart2_clk.common.hw,
  960. [CLK_APB2_UART3] = &apb2_uart3_clk.common.hw,
  961. [CLK_APB2_UART4] = &apb2_uart4_clk.common.hw,
  962. [CLK_APB2_UART5] = &apb2_uart5_clk.common.hw,
  963. [CLK_NAND0] = &nand0_clk.common.hw,
  964. [CLK_NAND1] = &nand1_clk.common.hw,
  965. [CLK_MMC0] = &mmc0_clk.common.hw,
  966. [CLK_MMC0_SAMPLE] = &mmc0_sample_clk.common.hw,
  967. [CLK_MMC0_OUTPUT] = &mmc0_output_clk.common.hw,
  968. [CLK_MMC1] = &mmc1_clk.common.hw,
  969. [CLK_MMC1_SAMPLE] = &mmc1_sample_clk.common.hw,
  970. [CLK_MMC1_OUTPUT] = &mmc1_output_clk.common.hw,
  971. [CLK_MMC2] = &mmc2_clk.common.hw,
  972. [CLK_MMC2_SAMPLE] = &mmc2_sample_clk.common.hw,
  973. [CLK_MMC2_OUTPUT] = &mmc2_output_clk.common.hw,
  974. [CLK_MMC3] = &mmc3_clk.common.hw,
  975. [CLK_MMC3_SAMPLE] = &mmc3_sample_clk.common.hw,
  976. [CLK_MMC3_OUTPUT] = &mmc3_output_clk.common.hw,
  977. [CLK_TS] = &ts_clk.common.hw,
  978. [CLK_SS] = &ss_clk.common.hw,
  979. [CLK_SPI0] = &spi0_clk.common.hw,
  980. [CLK_SPI1] = &spi1_clk.common.hw,
  981. [CLK_SPI2] = &spi2_clk.common.hw,
  982. [CLK_SPI3] = &spi3_clk.common.hw,
  983. [CLK_DAUDIO0] = &daudio0_clk.common.hw,
  984. [CLK_DAUDIO1] = &daudio1_clk.common.hw,
  985. [CLK_SPDIF] = &spdif_clk.common.hw,
  986. [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
  987. [CLK_USB_PHY1] = &usb_phy1_clk.common.hw,
  988. [CLK_USB_PHY2] = &usb_phy2_clk.common.hw,
  989. [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
  990. [CLK_USB_OHCI1] = &usb_ohci1_clk.common.hw,
  991. [CLK_USB_OHCI2] = &usb_ohci2_clk.common.hw,
  992. [CLK_MDFS] = &mdfs_clk.common.hw,
  993. [CLK_SDRAM0] = &sdram0_clk.common.hw,
  994. [CLK_SDRAM1] = &sdram1_clk.common.hw,
  995. [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
  996. [CLK_DRAM_CSI_ISP] = &dram_csi_isp_clk.common.hw,
  997. [CLK_DRAM_TS] = &dram_ts_clk.common.hw,
  998. [CLK_DRAM_DRC0] = &dram_drc0_clk.common.hw,
  999. [CLK_DRAM_DRC1] = &dram_drc1_clk.common.hw,
  1000. [CLK_DRAM_DEU0] = &dram_deu0_clk.common.hw,
  1001. [CLK_DRAM_DEU1] = &dram_deu1_clk.common.hw,
  1002. [CLK_DRAM_FE0] = &dram_fe0_clk.common.hw,
  1003. [CLK_DRAM_FE1] = &dram_fe1_clk.common.hw,
  1004. [CLK_DRAM_BE0] = &dram_be0_clk.common.hw,
  1005. [CLK_DRAM_BE1] = &dram_be1_clk.common.hw,
  1006. [CLK_DRAM_MP] = &dram_mp_clk.common.hw,
  1007. [CLK_BE0] = &be0_clk.common.hw,
  1008. [CLK_BE1] = &be1_clk.common.hw,
  1009. [CLK_FE0] = &fe0_clk.common.hw,
  1010. [CLK_FE1] = &fe1_clk.common.hw,
  1011. [CLK_MP] = &mp_clk.common.hw,
  1012. [CLK_LCD0_CH0] = &lcd0_ch0_clk.common.hw,
  1013. [CLK_LCD1_CH0] = &lcd1_ch0_clk.common.hw,
  1014. [CLK_LCD0_CH1] = &lcd0_ch1_clk.common.hw,
  1015. [CLK_LCD1_CH1] = &lcd1_ch1_clk.common.hw,
  1016. [CLK_CSI0_SCLK] = &csi0_sclk_clk.common.hw,
  1017. [CLK_CSI0_MCLK] = &csi0_mclk_clk.common.hw,
  1018. [CLK_CSI1_MCLK] = &csi1_mclk_clk.common.hw,
  1019. [CLK_VE] = &ve_clk.common.hw,
  1020. [CLK_CODEC] = &codec_clk.common.hw,
  1021. [CLK_AVS] = &avs_clk.common.hw,
  1022. [CLK_DIGITAL_MIC] = &digital_mic_clk.common.hw,
  1023. [CLK_HDMI] = &hdmi_clk.common.hw,
  1024. [CLK_HDMI_DDC] = &hdmi_ddc_clk.common.hw,
  1025. [CLK_PS] = &ps_clk.common.hw,
  1026. [CLK_MBUS0] = &mbus0_clk.common.hw,
  1027. [CLK_MBUS1] = &mbus1_clk.common.hw,
  1028. [CLK_MIPI_DSI] = &mipi_dsi_clk.common.hw,
  1029. [CLK_MIPI_DSI_DPHY] = &mipi_dsi_dphy_clk.common.hw,
  1030. [CLK_MIPI_CSI_DPHY] = &mipi_csi_dphy_clk.common.hw,
  1031. [CLK_IEP_DRC0] = &iep_drc0_clk.common.hw,
  1032. [CLK_IEP_DRC1] = &iep_drc1_clk.common.hw,
  1033. [CLK_IEP_DEU0] = &iep_deu0_clk.common.hw,
  1034. [CLK_IEP_DEU1] = &iep_deu1_clk.common.hw,
  1035. [CLK_GPU_CORE] = &gpu_core_clk.common.hw,
  1036. [CLK_GPU_MEMORY] = &gpu_memory_clk.common.hw,
  1037. [CLK_GPU_HYD] = &gpu_hyd_clk.common.hw,
  1038. [CLK_ATS] = &ats_clk.common.hw,
  1039. [CLK_TRACE] = &trace_clk.common.hw,
  1040. [CLK_OUT_A] = &out_a_clk.common.hw,
  1041. [CLK_OUT_B] = &out_b_clk.common.hw,
  1042. [CLK_OUT_C] = &out_c_clk.common.hw,
  1043. },
  1044. .num = CLK_NUMBER,
  1045. };
  1046. static struct ccu_reset_map sun6i_a31_ccu_resets[] = {
  1047. [RST_USB_PHY0] = { 0x0cc, BIT(0) },
  1048. [RST_USB_PHY1] = { 0x0cc, BIT(1) },
  1049. [RST_USB_PHY2] = { 0x0cc, BIT(2) },
  1050. [RST_AHB1_MIPI_DSI] = { 0x2c0, BIT(1) },
  1051. [RST_AHB1_SS] = { 0x2c0, BIT(5) },
  1052. [RST_AHB1_DMA] = { 0x2c0, BIT(6) },
  1053. [RST_AHB1_MMC0] = { 0x2c0, BIT(8) },
  1054. [RST_AHB1_MMC1] = { 0x2c0, BIT(9) },
  1055. [RST_AHB1_MMC2] = { 0x2c0, BIT(10) },
  1056. [RST_AHB1_MMC3] = { 0x2c0, BIT(11) },
  1057. [RST_AHB1_NAND1] = { 0x2c0, BIT(12) },
  1058. [RST_AHB1_NAND0] = { 0x2c0, BIT(13) },
  1059. [RST_AHB1_SDRAM] = { 0x2c0, BIT(14) },
  1060. [RST_AHB1_EMAC] = { 0x2c0, BIT(17) },
  1061. [RST_AHB1_TS] = { 0x2c0, BIT(18) },
  1062. [RST_AHB1_HSTIMER] = { 0x2c0, BIT(19) },
  1063. [RST_AHB1_SPI0] = { 0x2c0, BIT(20) },
  1064. [RST_AHB1_SPI1] = { 0x2c0, BIT(21) },
  1065. [RST_AHB1_SPI2] = { 0x2c0, BIT(22) },
  1066. [RST_AHB1_SPI3] = { 0x2c0, BIT(23) },
  1067. [RST_AHB1_OTG] = { 0x2c0, BIT(24) },
  1068. [RST_AHB1_EHCI0] = { 0x2c0, BIT(26) },
  1069. [RST_AHB1_EHCI1] = { 0x2c0, BIT(27) },
  1070. [RST_AHB1_OHCI0] = { 0x2c0, BIT(29) },
  1071. [RST_AHB1_OHCI1] = { 0x2c0, BIT(30) },
  1072. [RST_AHB1_OHCI2] = { 0x2c0, BIT(31) },
  1073. [RST_AHB1_VE] = { 0x2c4, BIT(0) },
  1074. [RST_AHB1_LCD0] = { 0x2c4, BIT(4) },
  1075. [RST_AHB1_LCD1] = { 0x2c4, BIT(5) },
  1076. [RST_AHB1_CSI] = { 0x2c4, BIT(8) },
  1077. [RST_AHB1_HDMI] = { 0x2c4, BIT(11) },
  1078. [RST_AHB1_BE0] = { 0x2c4, BIT(12) },
  1079. [RST_AHB1_BE1] = { 0x2c4, BIT(13) },
  1080. [RST_AHB1_FE0] = { 0x2c4, BIT(14) },
  1081. [RST_AHB1_FE1] = { 0x2c4, BIT(15) },
  1082. [RST_AHB1_MP] = { 0x2c4, BIT(18) },
  1083. [RST_AHB1_GPU] = { 0x2c4, BIT(20) },
  1084. [RST_AHB1_DEU0] = { 0x2c4, BIT(23) },
  1085. [RST_AHB1_DEU1] = { 0x2c4, BIT(24) },
  1086. [RST_AHB1_DRC0] = { 0x2c4, BIT(25) },
  1087. [RST_AHB1_DRC1] = { 0x2c4, BIT(26) },
  1088. [RST_AHB1_LVDS] = { 0x2c8, BIT(0) },
  1089. [RST_APB1_CODEC] = { 0x2d0, BIT(0) },
  1090. [RST_APB1_SPDIF] = { 0x2d0, BIT(1) },
  1091. [RST_APB1_DIGITAL_MIC] = { 0x2d0, BIT(4) },
  1092. [RST_APB1_DAUDIO0] = { 0x2d0, BIT(12) },
  1093. [RST_APB1_DAUDIO1] = { 0x2d0, BIT(13) },
  1094. [RST_APB2_I2C0] = { 0x2d8, BIT(0) },
  1095. [RST_APB2_I2C1] = { 0x2d8, BIT(1) },
  1096. [RST_APB2_I2C2] = { 0x2d8, BIT(2) },
  1097. [RST_APB2_I2C3] = { 0x2d8, BIT(3) },
  1098. [RST_APB2_UART0] = { 0x2d8, BIT(16) },
  1099. [RST_APB2_UART1] = { 0x2d8, BIT(17) },
  1100. [RST_APB2_UART2] = { 0x2d8, BIT(18) },
  1101. [RST_APB2_UART3] = { 0x2d8, BIT(19) },
  1102. [RST_APB2_UART4] = { 0x2d8, BIT(20) },
  1103. [RST_APB2_UART5] = { 0x2d8, BIT(21) },
  1104. };
  1105. static const struct sunxi_ccu_desc sun6i_a31_ccu_desc = {
  1106. .ccu_clks = sun6i_a31_ccu_clks,
  1107. .num_ccu_clks = ARRAY_SIZE(sun6i_a31_ccu_clks),
  1108. .hw_clks = &sun6i_a31_hw_clks,
  1109. .resets = sun6i_a31_ccu_resets,
  1110. .num_resets = ARRAY_SIZE(sun6i_a31_ccu_resets),
  1111. };
  1112. static struct ccu_mux_nb sun6i_a31_cpu_nb = {
  1113. .common = &cpu_clk.common,
  1114. .cm = &cpu_clk.mux,
  1115. .delay_us = 1, /* > 8 clock cycles at 24 MHz */
  1116. .bypass_index = 1, /* index of 24 MHz oscillator */
  1117. };
  1118. static void __init sun6i_a31_ccu_setup(struct device_node *node)
  1119. {
  1120. void __iomem *reg;
  1121. u32 val;
  1122. reg = of_io_request_and_map(node, 0, of_node_full_name(node));
  1123. if (IS_ERR(reg)) {
  1124. pr_err("%s: Could not map the clock registers\n",
  1125. of_node_full_name(node));
  1126. return;
  1127. }
  1128. /* Force the PLL-Audio-1x divider to 4 */
  1129. val = readl(reg + SUN6I_A31_PLL_AUDIO_REG);
  1130. val &= ~GENMASK(19, 16);
  1131. writel(val | (3 << 16), reg + SUN6I_A31_PLL_AUDIO_REG);
  1132. /* Force PLL-MIPI to MIPI mode */
  1133. val = readl(reg + SUN6I_A31_PLL_MIPI_REG);
  1134. val &= BIT(16);
  1135. writel(val, reg + SUN6I_A31_PLL_MIPI_REG);
  1136. /* Force AHB1 to PLL6 / 3 */
  1137. val = readl(reg + SUN6I_A31_AHB1_REG);
  1138. /* set PLL6 pre-div = 3 */
  1139. val &= ~GENMASK(7, 6);
  1140. val |= 0x2 << 6;
  1141. /* select PLL6 / pre-div */
  1142. val &= ~GENMASK(13, 12);
  1143. val |= 0x3 << 12;
  1144. writel(val, reg + SUN6I_A31_AHB1_REG);
  1145. sunxi_ccu_probe(node, reg, &sun6i_a31_ccu_desc);
  1146. ccu_mux_notifier_register(pll_cpu_clk.common.hw.clk,
  1147. &sun6i_a31_cpu_nb);
  1148. }
  1149. CLK_OF_DECLARE(sun6i_a31_ccu, "allwinner,sun6i-a31-ccu",
  1150. sun6i_a31_ccu_setup);