ccu-sun6i-a31.c 40 KB

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