ccu-sun50i-h6.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2017 Icenowy Zheng <icenowy@aosc.io>
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/of_address.h>
  7. #include <linux/platform_device.h>
  8. #include "ccu_common.h"
  9. #include "ccu_reset.h"
  10. #include "ccu_div.h"
  11. #include "ccu_gate.h"
  12. #include "ccu_mp.h"
  13. #include "ccu_mult.h"
  14. #include "ccu_nk.h"
  15. #include "ccu_nkm.h"
  16. #include "ccu_nkmp.h"
  17. #include "ccu_nm.h"
  18. #include "ccu-sun50i-h6.h"
  19. /*
  20. * The CPU PLL is actually NP clock, with P being /1, /2 or /4. However
  21. * P should only be used for output frequencies lower than 288 MHz.
  22. *
  23. * For now we can just model it as a multiplier clock, and force P to /1.
  24. *
  25. * The M factor is present in the register's description, but not in the
  26. * frequency formula, and it's documented as "M is only used for backdoor
  27. * testing", so it's not modelled and then force to 0.
  28. */
  29. #define SUN50I_H6_PLL_CPUX_REG 0x000
  30. static struct ccu_mult pll_cpux_clk = {
  31. .enable = BIT(31),
  32. .lock = BIT(28),
  33. .mult = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  34. .common = {
  35. .reg = 0x000,
  36. .hw.init = CLK_HW_INIT("pll-cpux", "osc24M",
  37. &ccu_mult_ops,
  38. CLK_SET_RATE_UNGATE),
  39. },
  40. };
  41. /* Some PLLs are input * N / div1 / P. Model them as NKMP with no K */
  42. #define SUN50I_H6_PLL_DDR0_REG 0x010
  43. static struct ccu_nkmp pll_ddr0_clk = {
  44. .enable = BIT(31),
  45. .lock = BIT(28),
  46. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  47. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  48. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  49. .common = {
  50. .reg = 0x010,
  51. .hw.init = CLK_HW_INIT("pll-ddr0", "osc24M",
  52. &ccu_nkmp_ops,
  53. CLK_SET_RATE_UNGATE),
  54. },
  55. };
  56. #define SUN50I_H6_PLL_PERIPH0_REG 0x020
  57. static struct ccu_nkmp pll_periph0_clk = {
  58. .enable = BIT(31),
  59. .lock = BIT(28),
  60. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  61. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  62. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  63. .fixed_post_div = 4,
  64. .common = {
  65. .reg = 0x020,
  66. .features = CCU_FEATURE_FIXED_POSTDIV,
  67. .hw.init = CLK_HW_INIT("pll-periph0", "osc24M",
  68. &ccu_nkmp_ops,
  69. CLK_SET_RATE_UNGATE),
  70. },
  71. };
  72. #define SUN50I_H6_PLL_PERIPH1_REG 0x028
  73. static struct ccu_nkmp pll_periph1_clk = {
  74. .enable = BIT(31),
  75. .lock = BIT(28),
  76. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  77. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  78. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  79. .fixed_post_div = 4,
  80. .common = {
  81. .reg = 0x028,
  82. .features = CCU_FEATURE_FIXED_POSTDIV,
  83. .hw.init = CLK_HW_INIT("pll-periph1", "osc24M",
  84. &ccu_nkmp_ops,
  85. CLK_SET_RATE_UNGATE),
  86. },
  87. };
  88. #define SUN50I_H6_PLL_GPU_REG 0x030
  89. static struct ccu_nkmp pll_gpu_clk = {
  90. .enable = BIT(31),
  91. .lock = BIT(28),
  92. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  93. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  94. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  95. .common = {
  96. .reg = 0x030,
  97. .hw.init = CLK_HW_INIT("pll-gpu", "osc24M",
  98. &ccu_nkmp_ops,
  99. CLK_SET_RATE_UNGATE),
  100. },
  101. };
  102. /*
  103. * For Video PLLs, the output divider is described as "used for testing"
  104. * in the user manual. So it's not modelled and forced to 0.
  105. */
  106. #define SUN50I_H6_PLL_VIDEO0_REG 0x040
  107. static struct ccu_nm pll_video0_clk = {
  108. .enable = BIT(31),
  109. .lock = BIT(28),
  110. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  111. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  112. .fixed_post_div = 4,
  113. .common = {
  114. .reg = 0x040,
  115. .features = CCU_FEATURE_FIXED_POSTDIV,
  116. .hw.init = CLK_HW_INIT("pll-video0", "osc24M",
  117. &ccu_nm_ops,
  118. CLK_SET_RATE_UNGATE),
  119. },
  120. };
  121. #define SUN50I_H6_PLL_VIDEO1_REG 0x048
  122. static struct ccu_nm pll_video1_clk = {
  123. .enable = BIT(31),
  124. .lock = BIT(28),
  125. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  126. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  127. .fixed_post_div = 4,
  128. .common = {
  129. .reg = 0x048,
  130. .features = CCU_FEATURE_FIXED_POSTDIV,
  131. .hw.init = CLK_HW_INIT("pll-video1", "osc24M",
  132. &ccu_nm_ops,
  133. CLK_SET_RATE_UNGATE),
  134. },
  135. };
  136. #define SUN50I_H6_PLL_VE_REG 0x058
  137. static struct ccu_nkmp pll_ve_clk = {
  138. .enable = BIT(31),
  139. .lock = BIT(28),
  140. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  141. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  142. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  143. .common = {
  144. .reg = 0x058,
  145. .hw.init = CLK_HW_INIT("pll-ve", "osc24M",
  146. &ccu_nkmp_ops,
  147. CLK_SET_RATE_UNGATE),
  148. },
  149. };
  150. #define SUN50I_H6_PLL_DE_REG 0x060
  151. static struct ccu_nkmp pll_de_clk = {
  152. .enable = BIT(31),
  153. .lock = BIT(28),
  154. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  155. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  156. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  157. .common = {
  158. .reg = 0x060,
  159. .hw.init = CLK_HW_INIT("pll-de", "osc24M",
  160. &ccu_nkmp_ops,
  161. CLK_SET_RATE_UNGATE),
  162. },
  163. };
  164. #define SUN50I_H6_PLL_HSIC_REG 0x070
  165. static struct ccu_nkmp pll_hsic_clk = {
  166. .enable = BIT(31),
  167. .lock = BIT(28),
  168. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  169. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  170. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  171. .common = {
  172. .reg = 0x070,
  173. .hw.init = CLK_HW_INIT("pll-hsic", "osc24M",
  174. &ccu_nkmp_ops,
  175. CLK_SET_RATE_UNGATE),
  176. },
  177. };
  178. /*
  179. * The Audio PLL is supposed to have 3 outputs: 2 fixed factors from
  180. * the base (2x and 4x), and one variable divider (the one true pll audio).
  181. *
  182. * We don't have any need for the variable divider for now, so we just
  183. * hardcode it to match with the clock names.
  184. */
  185. #define SUN50I_H6_PLL_AUDIO_REG 0x078
  186. static struct ccu_nm pll_audio_base_clk = {
  187. .enable = BIT(31),
  188. .lock = BIT(28),
  189. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  190. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  191. .common = {
  192. .reg = 0x078,
  193. .hw.init = CLK_HW_INIT("pll-audio-base", "osc24M",
  194. &ccu_nm_ops,
  195. CLK_SET_RATE_UNGATE),
  196. },
  197. };
  198. static const char * const cpux_parents[] = { "osc24M", "osc32k",
  199. "iosc", "pll-cpux" };
  200. static SUNXI_CCU_MUX(cpux_clk, "cpux", cpux_parents,
  201. 0x500, 24, 2, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
  202. static SUNXI_CCU_M(axi_clk, "axi", "cpux", 0x500, 0, 2, 0);
  203. static SUNXI_CCU_M(cpux_apb_clk, "cpux-apb", "cpux", 0x500, 8, 2, 0);
  204. static const char * const psi_ahb1_ahb2_parents[] = { "osc24M", "osc32k",
  205. "iosc", "pll-periph0" };
  206. static SUNXI_CCU_MP_WITH_MUX(psi_ahb1_ahb2_clk, "psi-ahb1-ahb2",
  207. psi_ahb1_ahb2_parents,
  208. 0x510,
  209. 0, 2, /* M */
  210. 8, 2, /* P */
  211. 24, 2, /* mux */
  212. 0);
  213. static const char * const ahb3_apb1_apb2_parents[] = { "osc24M", "osc32k",
  214. "psi-ahb1-ahb2",
  215. "pll-periph0" };
  216. static SUNXI_CCU_MP_WITH_MUX(ahb3_clk, "ahb3", ahb3_apb1_apb2_parents, 0x51c,
  217. 0, 2, /* M */
  218. 8, 2, /* P */
  219. 24, 2, /* mux */
  220. 0);
  221. static SUNXI_CCU_MP_WITH_MUX(apb1_clk, "apb1", ahb3_apb1_apb2_parents, 0x520,
  222. 0, 2, /* M */
  223. 8, 2, /* P */
  224. 24, 2, /* mux */
  225. 0);
  226. static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", ahb3_apb1_apb2_parents, 0x524,
  227. 0, 2, /* M */
  228. 8, 2, /* P */
  229. 24, 2, /* mux */
  230. 0);
  231. static const char * const mbus_parents[] = { "osc24M", "pll-periph0-2x",
  232. "pll-ddr0", "pll-periph0-4x" };
  233. static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents, 0x540,
  234. 0, 3, /* M */
  235. 24, 2, /* mux */
  236. BIT(31), /* gate */
  237. CLK_IS_CRITICAL);
  238. static const char * const de_parents[] = { "pll-de", "pll-periph0-2x" };
  239. static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents, 0x600,
  240. 0, 4, /* M */
  241. 24, 1, /* mux */
  242. BIT(31), /* gate */
  243. 0);
  244. static SUNXI_CCU_GATE(bus_de_clk, "bus-de", "psi-ahb1-ahb2",
  245. 0x60c, BIT(0), 0);
  246. static const char * const deinterlace_parents[] = { "pll-periph0",
  247. "pll-periph1" };
  248. static SUNXI_CCU_M_WITH_MUX_GATE(deinterlace_clk, "deinterlace",
  249. deinterlace_parents,
  250. 0x620,
  251. 0, 4, /* M */
  252. 24, 1, /* mux */
  253. BIT(31), /* gate */
  254. 0);
  255. static SUNXI_CCU_GATE(bus_deinterlace_clk, "bus-deinterlace", "psi-ahb1-ahb2",
  256. 0x62c, BIT(0), 0);
  257. static const char * const gpu_parents[] = { "pll-gpu" };
  258. static SUNXI_CCU_M_WITH_MUX_GATE(gpu_clk, "gpu", gpu_parents, 0x670,
  259. 0, 3, /* M */
  260. 24, 1, /* mux */
  261. BIT(31), /* gate */
  262. 0);
  263. static SUNXI_CCU_GATE(bus_gpu_clk, "bus-gpu", "psi-ahb1-ahb2",
  264. 0x67c, BIT(0), 0);
  265. /* Also applies to EMCE */
  266. static const char * const ce_parents[] = { "osc24M", "pll-periph0-2x" };
  267. static SUNXI_CCU_MP_WITH_MUX_GATE(ce_clk, "ce", ce_parents, 0x680,
  268. 0, 4, /* M */
  269. 8, 2, /* N */
  270. 24, 1, /* mux */
  271. BIT(31),/* gate */
  272. 0);
  273. static SUNXI_CCU_GATE(bus_ce_clk, "bus-ce", "psi-ahb1-ahb2",
  274. 0x68c, BIT(0), 0);
  275. static const char * const ve_parents[] = { "pll-ve" };
  276. static SUNXI_CCU_M_WITH_MUX_GATE(ve_clk, "ve", ve_parents, 0x690,
  277. 0, 3, /* M */
  278. 24, 1, /* mux */
  279. BIT(31), /* gate */
  280. 0);
  281. static SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "psi-ahb1-ahb2",
  282. 0x69c, BIT(0), 0);
  283. static SUNXI_CCU_MP_WITH_MUX_GATE(emce_clk, "emce", ce_parents, 0x6b0,
  284. 0, 4, /* M */
  285. 8, 2, /* N */
  286. 24, 1, /* mux */
  287. BIT(31),/* gate */
  288. 0);
  289. static SUNXI_CCU_GATE(bus_emce_clk, "bus-emce", "psi-ahb1-ahb2",
  290. 0x6bc, BIT(0), 0);
  291. static const char * const vp9_parents[] = { "pll-ve", "pll-periph0-2x" };
  292. static SUNXI_CCU_M_WITH_MUX_GATE(vp9_clk, "vp9", vp9_parents, 0x6c0,
  293. 0, 3, /* M */
  294. 24, 1, /* mux */
  295. BIT(31), /* gate */
  296. 0);
  297. static SUNXI_CCU_GATE(bus_vp9_clk, "bus-vp9", "psi-ahb1-ahb2",
  298. 0x6cc, BIT(0), 0);
  299. static SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "psi-ahb1-ahb2",
  300. 0x70c, BIT(0), 0);
  301. static SUNXI_CCU_GATE(bus_msgbox_clk, "bus-msgbox", "psi-ahb1-ahb2",
  302. 0x71c, BIT(0), 0);
  303. static SUNXI_CCU_GATE(bus_spinlock_clk, "bus-spinlock", "psi-ahb1-ahb2",
  304. 0x72c, BIT(0), 0);
  305. static SUNXI_CCU_GATE(bus_hstimer_clk, "bus-hstimer", "psi-ahb1-ahb2",
  306. 0x73c, BIT(0), 0);
  307. static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M", 0x740, BIT(31), 0);
  308. static SUNXI_CCU_GATE(bus_dbg_clk, "bus-dbg", "psi-ahb1-ahb2",
  309. 0x78c, BIT(0), 0);
  310. static SUNXI_CCU_GATE(bus_psi_clk, "bus-psi", "psi-ahb1-ahb2",
  311. 0x79c, BIT(0), 0);
  312. static SUNXI_CCU_GATE(bus_pwm_clk, "bus-pwm", "apb1", 0x7ac, BIT(0), 0);
  313. static SUNXI_CCU_GATE(bus_iommu_clk, "bus-iommu", "apb1", 0x7bc, BIT(0), 0);
  314. static const char * const dram_parents[] = { "pll-ddr0" };
  315. static struct ccu_div dram_clk = {
  316. .div = _SUNXI_CCU_DIV(0, 2),
  317. .mux = _SUNXI_CCU_MUX(24, 2),
  318. .common = {
  319. .reg = 0x800,
  320. .hw.init = CLK_HW_INIT_PARENTS("dram",
  321. dram_parents,
  322. &ccu_div_ops,
  323. CLK_IS_CRITICAL),
  324. },
  325. };
  326. static SUNXI_CCU_GATE(mbus_dma_clk, "mbus-dma", "mbus",
  327. 0x804, BIT(0), 0);
  328. static SUNXI_CCU_GATE(mbus_ve_clk, "mbus-ve", "mbus",
  329. 0x804, BIT(1), 0);
  330. static SUNXI_CCU_GATE(mbus_ce_clk, "mbus-ce", "mbus",
  331. 0x804, BIT(2), 0);
  332. static SUNXI_CCU_GATE(mbus_ts_clk, "mbus-ts", "mbus",
  333. 0x804, BIT(3), 0);
  334. static SUNXI_CCU_GATE(mbus_nand_clk, "mbus-nand", "mbus",
  335. 0x804, BIT(5), 0);
  336. static SUNXI_CCU_GATE(mbus_csi_clk, "mbus-csi", "mbus",
  337. 0x804, BIT(8), 0);
  338. static SUNXI_CCU_GATE(mbus_deinterlace_clk, "mbus-deinterlace", "mbus",
  339. 0x804, BIT(11), 0);
  340. static SUNXI_CCU_GATE(bus_dram_clk, "bus-dram", "psi-ahb1-ahb2",
  341. 0x80c, BIT(0), CLK_IS_CRITICAL);
  342. static const char * const nand_spi_parents[] = { "osc24M", "pll-periph0",
  343. "pll-periph1", "pll-periph0-2x",
  344. "pll-periph1-2x" };
  345. static SUNXI_CCU_MP_WITH_MUX_GATE(nand0_clk, "nand0", nand_spi_parents, 0x810,
  346. 0, 4, /* M */
  347. 8, 2, /* N */
  348. 24, 3, /* mux */
  349. BIT(31),/* gate */
  350. 0);
  351. static SUNXI_CCU_MP_WITH_MUX_GATE(nand1_clk, "nand1", nand_spi_parents, 0x814,
  352. 0, 4, /* M */
  353. 8, 2, /* N */
  354. 24, 3, /* mux */
  355. BIT(31),/* gate */
  356. 0);
  357. static SUNXI_CCU_GATE(bus_nand_clk, "bus-nand", "ahb3", 0x82c, BIT(0), 0);
  358. static const char * const mmc_parents[] = { "osc24M", "pll-periph0-2x",
  359. "pll-periph1-2x" };
  360. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mmc_parents, 0x830,
  361. 0, 4, /* M */
  362. 8, 2, /* N */
  363. 24, 3, /* mux */
  364. BIT(31),/* gate */
  365. 0);
  366. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mmc_parents, 0x834,
  367. 0, 4, /* M */
  368. 8, 2, /* N */
  369. 24, 3, /* mux */
  370. BIT(31),/* gate */
  371. 0);
  372. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mmc_parents, 0x838,
  373. 0, 4, /* M */
  374. 8, 2, /* N */
  375. 24, 3, /* mux */
  376. BIT(31),/* gate */
  377. 0);
  378. static SUNXI_CCU_GATE(bus_mmc0_clk, "bus-mmc0", "ahb3", 0x84c, BIT(0), 0);
  379. static SUNXI_CCU_GATE(bus_mmc1_clk, "bus-mmc1", "ahb3", 0x84c, BIT(1), 0);
  380. static SUNXI_CCU_GATE(bus_mmc2_clk, "bus-mmc2", "ahb3", 0x84c, BIT(2), 0);
  381. static SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb2", 0x90c, BIT(0), 0);
  382. static SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb2", 0x90c, BIT(1), 0);
  383. static SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb2", 0x90c, BIT(2), 0);
  384. static SUNXI_CCU_GATE(bus_uart3_clk, "bus-uart3", "apb2", 0x90c, BIT(3), 0);
  385. static SUNXI_CCU_GATE(bus_i2c0_clk, "bus-i2c0", "apb2", 0x91c, BIT(0), 0);
  386. static SUNXI_CCU_GATE(bus_i2c1_clk, "bus-i2c1", "apb2", 0x91c, BIT(1), 0);
  387. static SUNXI_CCU_GATE(bus_i2c2_clk, "bus-i2c2", "apb2", 0x91c, BIT(2), 0);
  388. static SUNXI_CCU_GATE(bus_i2c3_clk, "bus-i2c3", "apb2", 0x91c, BIT(3), 0);
  389. static SUNXI_CCU_GATE(bus_scr0_clk, "bus-scr0", "apb2", 0x93c, BIT(0), 0);
  390. static SUNXI_CCU_GATE(bus_scr1_clk, "bus-scr1", "apb2", 0x93c, BIT(1), 0);
  391. static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", nand_spi_parents, 0x940,
  392. 0, 4, /* M */
  393. 8, 2, /* N */
  394. 24, 3, /* mux */
  395. BIT(31),/* gate */
  396. 0);
  397. static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", nand_spi_parents, 0x944,
  398. 0, 4, /* M */
  399. 8, 2, /* N */
  400. 24, 3, /* mux */
  401. BIT(31),/* gate */
  402. 0);
  403. static SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb3", 0x96c, BIT(0), 0);
  404. static SUNXI_CCU_GATE(bus_spi1_clk, "bus-spi1", "ahb3", 0x96c, BIT(1), 0);
  405. static SUNXI_CCU_GATE(bus_emac_clk, "bus-emac", "ahb3", 0x97c, BIT(0), 0);
  406. static const char * const ts_parents[] = { "osc24M", "pll-periph0" };
  407. static SUNXI_CCU_MP_WITH_MUX_GATE(ts_clk, "ts", ts_parents, 0x9b0,
  408. 0, 4, /* M */
  409. 8, 2, /* N */
  410. 24, 1, /* mux */
  411. BIT(31),/* gate */
  412. 0);
  413. static SUNXI_CCU_GATE(bus_ts_clk, "bus-ts", "ahb3", 0x9bc, BIT(0), 0);
  414. static const char * const ir_tx_parents[] = { "osc32k", "osc24M" };
  415. static SUNXI_CCU_MP_WITH_MUX_GATE(ir_tx_clk, "ir-tx", ir_tx_parents, 0x9c0,
  416. 0, 4, /* M */
  417. 8, 2, /* N */
  418. 24, 1, /* mux */
  419. BIT(31),/* gate */
  420. 0);
  421. static SUNXI_CCU_GATE(bus_ir_tx_clk, "bus-ir-tx", "apb1", 0x9cc, BIT(0), 0);
  422. static SUNXI_CCU_GATE(bus_ths_clk, "bus-ths", "apb1", 0x9fc, BIT(0), 0);
  423. static const char * const audio_parents[] = { "pll-audio", "pll-audio-2x", "pll-audio-4x" };
  424. static struct ccu_div i2s3_clk = {
  425. .enable = BIT(31),
  426. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  427. .mux = _SUNXI_CCU_MUX(24, 2),
  428. .common = {
  429. .reg = 0xa0c,
  430. .hw.init = CLK_HW_INIT_PARENTS("i2s3",
  431. audio_parents,
  432. &ccu_div_ops,
  433. 0),
  434. },
  435. };
  436. static struct ccu_div i2s0_clk = {
  437. .enable = BIT(31),
  438. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  439. .mux = _SUNXI_CCU_MUX(24, 2),
  440. .common = {
  441. .reg = 0xa10,
  442. .hw.init = CLK_HW_INIT_PARENTS("i2s0",
  443. audio_parents,
  444. &ccu_div_ops,
  445. 0),
  446. },
  447. };
  448. static struct ccu_div i2s1_clk = {
  449. .enable = BIT(31),
  450. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  451. .mux = _SUNXI_CCU_MUX(24, 2),
  452. .common = {
  453. .reg = 0xa14,
  454. .hw.init = CLK_HW_INIT_PARENTS("i2s1",
  455. audio_parents,
  456. &ccu_div_ops,
  457. 0),
  458. },
  459. };
  460. static struct ccu_div i2s2_clk = {
  461. .enable = BIT(31),
  462. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  463. .mux = _SUNXI_CCU_MUX(24, 2),
  464. .common = {
  465. .reg = 0xa18,
  466. .hw.init = CLK_HW_INIT_PARENTS("i2s2",
  467. audio_parents,
  468. &ccu_div_ops,
  469. 0),
  470. },
  471. };
  472. static SUNXI_CCU_GATE(bus_i2s0_clk, "bus-i2s0", "apb1", 0xa1c, BIT(0), 0);
  473. static SUNXI_CCU_GATE(bus_i2s1_clk, "bus-i2s1", "apb1", 0xa1c, BIT(1), 0);
  474. static SUNXI_CCU_GATE(bus_i2s2_clk, "bus-i2s2", "apb1", 0xa1c, BIT(2), 0);
  475. static SUNXI_CCU_GATE(bus_i2s3_clk, "bus-i2s3", "apb1", 0xa1c, BIT(3), 0);
  476. static struct ccu_div spdif_clk = {
  477. .enable = BIT(31),
  478. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  479. .mux = _SUNXI_CCU_MUX(24, 2),
  480. .common = {
  481. .reg = 0xa20,
  482. .hw.init = CLK_HW_INIT_PARENTS("spdif",
  483. audio_parents,
  484. &ccu_div_ops,
  485. 0),
  486. },
  487. };
  488. static SUNXI_CCU_GATE(bus_spdif_clk, "bus-spdif", "apb1", 0xa2c, BIT(0), 0);
  489. static struct ccu_div dmic_clk = {
  490. .enable = BIT(31),
  491. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  492. .mux = _SUNXI_CCU_MUX(24, 2),
  493. .common = {
  494. .reg = 0xa40,
  495. .hw.init = CLK_HW_INIT_PARENTS("dmic",
  496. audio_parents,
  497. &ccu_div_ops,
  498. 0),
  499. },
  500. };
  501. static SUNXI_CCU_GATE(bus_dmic_clk, "bus-dmic", "apb1", 0xa4c, BIT(0), 0);
  502. static struct ccu_div audio_hub_clk = {
  503. .enable = BIT(31),
  504. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  505. .mux = _SUNXI_CCU_MUX(24, 2),
  506. .common = {
  507. .reg = 0xa60,
  508. .hw.init = CLK_HW_INIT_PARENTS("audio-hub",
  509. audio_parents,
  510. &ccu_div_ops,
  511. 0),
  512. },
  513. };
  514. static SUNXI_CCU_GATE(bus_audio_hub_clk, "bus-audio-hub", "apb1", 0xa6c, BIT(0), 0);
  515. /*
  516. * There are OHCI 12M clock source selection bits for 2 USB 2.0 ports.
  517. * We will force them to 0 (12M divided from 48M).
  518. */
  519. #define SUN50I_H6_USB0_CLK_REG 0xa70
  520. #define SUN50I_H6_USB3_CLK_REG 0xa7c
  521. static SUNXI_CCU_GATE(usb_ohci0_clk, "usb-ohci0", "osc12M", 0xa70, BIT(31), 0);
  522. static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M", 0xa70, BIT(29), 0);
  523. static SUNXI_CCU_GATE(usb_phy1_clk, "usb-phy1", "osc24M", 0xa74, BIT(29), 0);
  524. static SUNXI_CCU_GATE(usb_ohci3_clk, "usb-ohci3", "osc12M", 0xa7c, BIT(31), 0);
  525. static SUNXI_CCU_GATE(usb_phy3_clk, "usb-phy3", "osc12M", 0xa7c, BIT(29), 0);
  526. static SUNXI_CCU_GATE(usb_hsic_12m_clk, "usb-hsic-12M", "osc12M", 0xa7c, BIT(27), 0);
  527. static SUNXI_CCU_GATE(usb_hsic_clk, "usb-hsic", "pll-hsic", 0xa7c, BIT(26), 0);
  528. static SUNXI_CCU_GATE(bus_ohci0_clk, "bus-ohci0", "ahb3", 0xa8c, BIT(0), 0);
  529. static SUNXI_CCU_GATE(bus_ohci3_clk, "bus-ohci3", "ahb3", 0xa8c, BIT(3), 0);
  530. static SUNXI_CCU_GATE(bus_ehci0_clk, "bus-ehci0", "ahb3", 0xa8c, BIT(4), 0);
  531. static SUNXI_CCU_GATE(bus_xhci_clk, "bus-xhci", "ahb3", 0xa8c, BIT(5), 0);
  532. static SUNXI_CCU_GATE(bus_ehci3_clk, "bus-ehci3", "ahb3", 0xa8c, BIT(7), 0);
  533. static SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb3", 0xa8c, BIT(8), 0);
  534. static CLK_FIXED_FACTOR(pcie_ref_100m_clk, "pcie-ref-100M",
  535. "pll-periph0-4x", 24, 1, 0);
  536. static SUNXI_CCU_GATE(pcie_ref_clk, "pcie-ref", "pcie-ref-100M",
  537. 0xab0, BIT(31), 0);
  538. static SUNXI_CCU_GATE(pcie_ref_out_clk, "pcie-ref-out", "pcie-ref",
  539. 0xab0, BIT(30), 0);
  540. static SUNXI_CCU_M_WITH_GATE(pcie_maxi_clk, "pcie-maxi",
  541. "pll-periph0", 0xab4,
  542. 0, 4, /* M */
  543. BIT(31), /* gate */
  544. 0);
  545. static SUNXI_CCU_M_WITH_GATE(pcie_aux_clk, "pcie-aux", "osc24M", 0xab8,
  546. 0, 5, /* M */
  547. BIT(31), /* gate */
  548. 0);
  549. static SUNXI_CCU_GATE(bus_pcie_clk, "bus-pcie", "psi-ahb1-ahb2",
  550. 0xabc, BIT(0), 0);
  551. static const char * const hdmi_parents[] = { "pll-video0", "pll-video1",
  552. "pll-video1-4x" };
  553. static SUNXI_CCU_M_WITH_MUX_GATE(hdmi_clk, "hdmi", hdmi_parents, 0xb00,
  554. 0, 4, /* M */
  555. 24, 2, /* mux */
  556. BIT(31), /* gate */
  557. 0);
  558. static SUNXI_CCU_GATE(hdmi_slow_clk, "hdmi-slow", "osc24M", 0xb04, BIT(31), 0);
  559. static const char * const hdmi_cec_parents[] = { "osc32k", "pll-periph0-2x" };
  560. static const struct ccu_mux_fixed_prediv hdmi_cec_predivs[] = {
  561. { .index = 1, .div = 36621 },
  562. };
  563. static struct ccu_mux hdmi_cec_clk = {
  564. .enable = BIT(31),
  565. .mux = {
  566. .shift = 24,
  567. .width = 2,
  568. .fixed_predivs = hdmi_cec_predivs,
  569. .n_predivs = ARRAY_SIZE(hdmi_cec_predivs),
  570. },
  571. .common = {
  572. .reg = 0xb10,
  573. .features = CCU_FEATURE_FIXED_PREDIV,
  574. .hw.init = CLK_HW_INIT_PARENTS("hdmi-cec",
  575. hdmi_cec_parents,
  576. &ccu_mux_ops,
  577. 0),
  578. },
  579. };
  580. static SUNXI_CCU_GATE(bus_hdmi_clk, "bus-hdmi", "ahb3", 0xb1c, BIT(0), 0);
  581. static SUNXI_CCU_GATE(bus_tcon_top_clk, "bus-tcon-top", "ahb3",
  582. 0xb5c, BIT(0), 0);
  583. static const char * const tcon_lcd0_parents[] = { "pll-video0",
  584. "pll-video0-4x",
  585. "pll-video1" };
  586. static SUNXI_CCU_MUX_WITH_GATE(tcon_lcd0_clk, "tcon-lcd0",
  587. tcon_lcd0_parents, 0xb60,
  588. 24, 3, /* mux */
  589. BIT(31), /* gate */
  590. 0);
  591. static SUNXI_CCU_GATE(bus_tcon_lcd0_clk, "bus-tcon-lcd0", "ahb3",
  592. 0xb7c, BIT(0), 0);
  593. static const char * const tcon_tv0_parents[] = { "pll-video0",
  594. "pll-video0-4x",
  595. "pll-video1",
  596. "pll-video1-4x" };
  597. static SUNXI_CCU_MP_WITH_MUX_GATE(tcon_tv0_clk, "tcon-tv0",
  598. tcon_tv0_parents, 0xb80,
  599. 0, 4, /* M */
  600. 8, 2, /* P */
  601. 24, 3, /* mux */
  602. BIT(31), /* gate */
  603. 0);
  604. static SUNXI_CCU_GATE(bus_tcon_tv0_clk, "bus-tcon-tv0", "ahb3",
  605. 0xb9c, BIT(0), 0);
  606. static SUNXI_CCU_GATE(csi_cci_clk, "csi-cci", "osc24M", 0xc00, BIT(0), 0);
  607. static const char * const csi_top_parents[] = { "pll-video0", "pll-ve",
  608. "pll-periph0" };
  609. static const u8 csi_top_table[] = { 0, 2, 3 };
  610. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(csi_top_clk, "csi-top",
  611. csi_top_parents, csi_top_table, 0xc04,
  612. 0, 4, /* M */
  613. 24, 3, /* mux */
  614. BIT(31), /* gate */
  615. 0);
  616. static const char * const csi_mclk_parents[] = { "osc24M", "pll-video0",
  617. "pll-periph0", "pll-periph1" };
  618. static SUNXI_CCU_M_WITH_MUX_GATE(csi_mclk_clk, "csi-mclk",
  619. csi_mclk_parents, 0xc08,
  620. 0, 5, /* M */
  621. 24, 3, /* mux */
  622. BIT(31), /* gate */
  623. 0);
  624. static SUNXI_CCU_GATE(bus_csi_clk, "bus-csi", "ahb3", 0xc2c, BIT(0), 0);
  625. static const char * const hdcp_parents[] = { "pll-periph0", "pll-periph1" };
  626. static SUNXI_CCU_M_WITH_MUX_GATE(hdcp_clk, "hdcp", hdcp_parents, 0xc40,
  627. 0, 4, /* M */
  628. 24, 2, /* mux */
  629. BIT(31), /* gate */
  630. 0);
  631. static SUNXI_CCU_GATE(bus_hdcp_clk, "bus-hdcp", "ahb3", 0xc4c, BIT(0), 0);
  632. /* Fixed factor clocks */
  633. static CLK_FIXED_FACTOR(osc12M_clk, "osc12M", "osc24M", 2, 1, 0);
  634. /*
  635. * The divider of pll-audio is fixed to 8 now, as pll-audio-4x has a
  636. * fixed post-divider 2.
  637. */
  638. static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio",
  639. "pll-audio-base", 8, 1, CLK_SET_RATE_PARENT);
  640. static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x",
  641. "pll-audio-base", 4, 1, CLK_SET_RATE_PARENT);
  642. static CLK_FIXED_FACTOR(pll_audio_4x_clk, "pll-audio-4x",
  643. "pll-audio-base", 2, 1, CLK_SET_RATE_PARENT);
  644. static CLK_FIXED_FACTOR(pll_periph0_4x_clk, "pll-periph0-4x",
  645. "pll-periph0", 1, 4, 0);
  646. static CLK_FIXED_FACTOR(pll_periph0_2x_clk, "pll-periph0-2x",
  647. "pll-periph0", 1, 2, 0);
  648. static CLK_FIXED_FACTOR(pll_periph1_4x_clk, "pll-periph1-4x",
  649. "pll-periph1", 1, 4, 0);
  650. static CLK_FIXED_FACTOR(pll_periph1_2x_clk, "pll-periph1-2x",
  651. "pll-periph1", 1, 2, 0);
  652. static CLK_FIXED_FACTOR(pll_video0_4x_clk, "pll-video0-4x",
  653. "pll-video0", 1, 4, CLK_SET_RATE_PARENT);
  654. static CLK_FIXED_FACTOR(pll_video1_4x_clk, "pll-video1-4x",
  655. "pll-video1", 1, 4, CLK_SET_RATE_PARENT);
  656. static struct ccu_common *sun50i_h6_ccu_clks[] = {
  657. &pll_cpux_clk.common,
  658. &pll_ddr0_clk.common,
  659. &pll_periph0_clk.common,
  660. &pll_periph1_clk.common,
  661. &pll_gpu_clk.common,
  662. &pll_video0_clk.common,
  663. &pll_video1_clk.common,
  664. &pll_ve_clk.common,
  665. &pll_de_clk.common,
  666. &pll_hsic_clk.common,
  667. &pll_audio_base_clk.common,
  668. &cpux_clk.common,
  669. &axi_clk.common,
  670. &cpux_apb_clk.common,
  671. &psi_ahb1_ahb2_clk.common,
  672. &ahb3_clk.common,
  673. &apb1_clk.common,
  674. &apb2_clk.common,
  675. &mbus_clk.common,
  676. &de_clk.common,
  677. &bus_de_clk.common,
  678. &deinterlace_clk.common,
  679. &bus_deinterlace_clk.common,
  680. &gpu_clk.common,
  681. &bus_gpu_clk.common,
  682. &ce_clk.common,
  683. &bus_ce_clk.common,
  684. &ve_clk.common,
  685. &bus_ve_clk.common,
  686. &emce_clk.common,
  687. &bus_emce_clk.common,
  688. &vp9_clk.common,
  689. &bus_vp9_clk.common,
  690. &bus_dma_clk.common,
  691. &bus_msgbox_clk.common,
  692. &bus_spinlock_clk.common,
  693. &bus_hstimer_clk.common,
  694. &avs_clk.common,
  695. &bus_dbg_clk.common,
  696. &bus_psi_clk.common,
  697. &bus_pwm_clk.common,
  698. &bus_iommu_clk.common,
  699. &dram_clk.common,
  700. &mbus_dma_clk.common,
  701. &mbus_ve_clk.common,
  702. &mbus_ce_clk.common,
  703. &mbus_ts_clk.common,
  704. &mbus_nand_clk.common,
  705. &mbus_csi_clk.common,
  706. &mbus_deinterlace_clk.common,
  707. &bus_dram_clk.common,
  708. &nand0_clk.common,
  709. &nand1_clk.common,
  710. &bus_nand_clk.common,
  711. &mmc0_clk.common,
  712. &mmc1_clk.common,
  713. &mmc2_clk.common,
  714. &bus_mmc0_clk.common,
  715. &bus_mmc1_clk.common,
  716. &bus_mmc2_clk.common,
  717. &bus_uart0_clk.common,
  718. &bus_uart1_clk.common,
  719. &bus_uart2_clk.common,
  720. &bus_uart3_clk.common,
  721. &bus_i2c0_clk.common,
  722. &bus_i2c1_clk.common,
  723. &bus_i2c2_clk.common,
  724. &bus_i2c3_clk.common,
  725. &bus_scr0_clk.common,
  726. &bus_scr1_clk.common,
  727. &spi0_clk.common,
  728. &spi1_clk.common,
  729. &bus_spi0_clk.common,
  730. &bus_spi1_clk.common,
  731. &bus_emac_clk.common,
  732. &ts_clk.common,
  733. &bus_ts_clk.common,
  734. &ir_tx_clk.common,
  735. &bus_ir_tx_clk.common,
  736. &bus_ths_clk.common,
  737. &i2s3_clk.common,
  738. &i2s0_clk.common,
  739. &i2s1_clk.common,
  740. &i2s2_clk.common,
  741. &bus_i2s0_clk.common,
  742. &bus_i2s1_clk.common,
  743. &bus_i2s2_clk.common,
  744. &bus_i2s3_clk.common,
  745. &spdif_clk.common,
  746. &bus_spdif_clk.common,
  747. &dmic_clk.common,
  748. &bus_dmic_clk.common,
  749. &audio_hub_clk.common,
  750. &bus_audio_hub_clk.common,
  751. &usb_ohci0_clk.common,
  752. &usb_phy0_clk.common,
  753. &usb_phy1_clk.common,
  754. &usb_ohci3_clk.common,
  755. &usb_phy3_clk.common,
  756. &usb_hsic_12m_clk.common,
  757. &usb_hsic_clk.common,
  758. &bus_ohci0_clk.common,
  759. &bus_ohci3_clk.common,
  760. &bus_ehci0_clk.common,
  761. &bus_xhci_clk.common,
  762. &bus_ehci3_clk.common,
  763. &bus_otg_clk.common,
  764. &pcie_ref_clk.common,
  765. &pcie_ref_out_clk.common,
  766. &pcie_maxi_clk.common,
  767. &pcie_aux_clk.common,
  768. &bus_pcie_clk.common,
  769. &hdmi_clk.common,
  770. &hdmi_slow_clk.common,
  771. &hdmi_cec_clk.common,
  772. &bus_hdmi_clk.common,
  773. &bus_tcon_top_clk.common,
  774. &tcon_lcd0_clk.common,
  775. &bus_tcon_lcd0_clk.common,
  776. &tcon_tv0_clk.common,
  777. &bus_tcon_tv0_clk.common,
  778. &csi_cci_clk.common,
  779. &csi_top_clk.common,
  780. &csi_mclk_clk.common,
  781. &bus_csi_clk.common,
  782. &hdcp_clk.common,
  783. &bus_hdcp_clk.common,
  784. };
  785. static struct clk_hw_onecell_data sun50i_h6_hw_clks = {
  786. .hws = {
  787. [CLK_OSC12M] = &osc12M_clk.hw,
  788. [CLK_PLL_CPUX] = &pll_cpux_clk.common.hw,
  789. [CLK_PLL_DDR0] = &pll_ddr0_clk.common.hw,
  790. [CLK_PLL_PERIPH0] = &pll_periph0_clk.common.hw,
  791. [CLK_PLL_PERIPH0_2X] = &pll_periph0_2x_clk.hw,
  792. [CLK_PLL_PERIPH0_4X] = &pll_periph0_4x_clk.hw,
  793. [CLK_PLL_PERIPH1] = &pll_periph1_clk.common.hw,
  794. [CLK_PLL_PERIPH1_2X] = &pll_periph1_2x_clk.hw,
  795. [CLK_PLL_PERIPH1_4X] = &pll_periph1_4x_clk.hw,
  796. [CLK_PLL_GPU] = &pll_gpu_clk.common.hw,
  797. [CLK_PLL_VIDEO0] = &pll_video0_clk.common.hw,
  798. [CLK_PLL_VIDEO0_4X] = &pll_video0_4x_clk.hw,
  799. [CLK_PLL_VIDEO1] = &pll_video1_clk.common.hw,
  800. [CLK_PLL_VIDEO1_4X] = &pll_video1_4x_clk.hw,
  801. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  802. [CLK_PLL_DE] = &pll_de_clk.common.hw,
  803. [CLK_PLL_HSIC] = &pll_hsic_clk.common.hw,
  804. [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
  805. [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
  806. [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
  807. [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
  808. [CLK_CPUX] = &cpux_clk.common.hw,
  809. [CLK_AXI] = &axi_clk.common.hw,
  810. [CLK_CPUX_APB] = &cpux_apb_clk.common.hw,
  811. [CLK_PSI_AHB1_AHB2] = &psi_ahb1_ahb2_clk.common.hw,
  812. [CLK_AHB3] = &ahb3_clk.common.hw,
  813. [CLK_APB1] = &apb1_clk.common.hw,
  814. [CLK_APB2] = &apb2_clk.common.hw,
  815. [CLK_MBUS] = &mbus_clk.common.hw,
  816. [CLK_DE] = &de_clk.common.hw,
  817. [CLK_BUS_DE] = &bus_de_clk.common.hw,
  818. [CLK_DEINTERLACE] = &deinterlace_clk.common.hw,
  819. [CLK_BUS_DEINTERLACE] = &bus_deinterlace_clk.common.hw,
  820. [CLK_GPU] = &gpu_clk.common.hw,
  821. [CLK_BUS_GPU] = &bus_gpu_clk.common.hw,
  822. [CLK_CE] = &ce_clk.common.hw,
  823. [CLK_BUS_CE] = &bus_ce_clk.common.hw,
  824. [CLK_VE] = &ve_clk.common.hw,
  825. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  826. [CLK_EMCE] = &emce_clk.common.hw,
  827. [CLK_BUS_EMCE] = &bus_emce_clk.common.hw,
  828. [CLK_VP9] = &vp9_clk.common.hw,
  829. [CLK_BUS_VP9] = &bus_vp9_clk.common.hw,
  830. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  831. [CLK_BUS_MSGBOX] = &bus_msgbox_clk.common.hw,
  832. [CLK_BUS_SPINLOCK] = &bus_spinlock_clk.common.hw,
  833. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  834. [CLK_AVS] = &avs_clk.common.hw,
  835. [CLK_BUS_DBG] = &bus_dbg_clk.common.hw,
  836. [CLK_BUS_PSI] = &bus_psi_clk.common.hw,
  837. [CLK_BUS_PWM] = &bus_pwm_clk.common.hw,
  838. [CLK_BUS_IOMMU] = &bus_iommu_clk.common.hw,
  839. [CLK_DRAM] = &dram_clk.common.hw,
  840. [CLK_MBUS_DMA] = &mbus_dma_clk.common.hw,
  841. [CLK_MBUS_VE] = &mbus_ve_clk.common.hw,
  842. [CLK_MBUS_CE] = &mbus_ce_clk.common.hw,
  843. [CLK_MBUS_TS] = &mbus_ts_clk.common.hw,
  844. [CLK_MBUS_NAND] = &mbus_nand_clk.common.hw,
  845. [CLK_MBUS_CSI] = &mbus_csi_clk.common.hw,
  846. [CLK_MBUS_DEINTERLACE] = &mbus_deinterlace_clk.common.hw,
  847. [CLK_BUS_DRAM] = &bus_dram_clk.common.hw,
  848. [CLK_NAND0] = &nand0_clk.common.hw,
  849. [CLK_NAND1] = &nand1_clk.common.hw,
  850. [CLK_BUS_NAND] = &bus_nand_clk.common.hw,
  851. [CLK_MMC0] = &mmc0_clk.common.hw,
  852. [CLK_MMC1] = &mmc1_clk.common.hw,
  853. [CLK_MMC2] = &mmc2_clk.common.hw,
  854. [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw,
  855. [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw,
  856. [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw,
  857. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  858. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  859. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  860. [CLK_BUS_UART3] = &bus_uart3_clk.common.hw,
  861. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  862. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  863. [CLK_BUS_I2C2] = &bus_i2c2_clk.common.hw,
  864. [CLK_BUS_I2C3] = &bus_i2c3_clk.common.hw,
  865. [CLK_BUS_SCR0] = &bus_scr0_clk.common.hw,
  866. [CLK_BUS_SCR1] = &bus_scr1_clk.common.hw,
  867. [CLK_SPI0] = &spi0_clk.common.hw,
  868. [CLK_SPI1] = &spi1_clk.common.hw,
  869. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  870. [CLK_BUS_SPI1] = &bus_spi1_clk.common.hw,
  871. [CLK_BUS_EMAC] = &bus_emac_clk.common.hw,
  872. [CLK_TS] = &ts_clk.common.hw,
  873. [CLK_BUS_TS] = &bus_ts_clk.common.hw,
  874. [CLK_IR_TX] = &ir_tx_clk.common.hw,
  875. [CLK_BUS_IR_TX] = &bus_ir_tx_clk.common.hw,
  876. [CLK_BUS_THS] = &bus_ths_clk.common.hw,
  877. [CLK_I2S3] = &i2s3_clk.common.hw,
  878. [CLK_I2S0] = &i2s0_clk.common.hw,
  879. [CLK_I2S1] = &i2s1_clk.common.hw,
  880. [CLK_I2S2] = &i2s2_clk.common.hw,
  881. [CLK_BUS_I2S0] = &bus_i2s0_clk.common.hw,
  882. [CLK_BUS_I2S1] = &bus_i2s1_clk.common.hw,
  883. [CLK_BUS_I2S2] = &bus_i2s2_clk.common.hw,
  884. [CLK_BUS_I2S3] = &bus_i2s3_clk.common.hw,
  885. [CLK_SPDIF] = &spdif_clk.common.hw,
  886. [CLK_BUS_SPDIF] = &bus_spdif_clk.common.hw,
  887. [CLK_DMIC] = &dmic_clk.common.hw,
  888. [CLK_BUS_DMIC] = &bus_dmic_clk.common.hw,
  889. [CLK_AUDIO_HUB] = &audio_hub_clk.common.hw,
  890. [CLK_BUS_AUDIO_HUB] = &bus_audio_hub_clk.common.hw,
  891. [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
  892. [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
  893. [CLK_USB_PHY1] = &usb_phy1_clk.common.hw,
  894. [CLK_USB_OHCI3] = &usb_ohci3_clk.common.hw,
  895. [CLK_USB_PHY3] = &usb_phy3_clk.common.hw,
  896. [CLK_USB_HSIC_12M] = &usb_hsic_12m_clk.common.hw,
  897. [CLK_USB_HSIC] = &usb_hsic_clk.common.hw,
  898. [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw,
  899. [CLK_BUS_OHCI3] = &bus_ohci3_clk.common.hw,
  900. [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw,
  901. [CLK_BUS_XHCI] = &bus_xhci_clk.common.hw,
  902. [CLK_BUS_EHCI3] = &bus_ehci3_clk.common.hw,
  903. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  904. [CLK_PCIE_REF_100M] = &pcie_ref_100m_clk.hw,
  905. [CLK_PCIE_REF] = &pcie_ref_clk.common.hw,
  906. [CLK_PCIE_REF_OUT] = &pcie_ref_out_clk.common.hw,
  907. [CLK_PCIE_MAXI] = &pcie_maxi_clk.common.hw,
  908. [CLK_PCIE_AUX] = &pcie_aux_clk.common.hw,
  909. [CLK_BUS_PCIE] = &bus_pcie_clk.common.hw,
  910. [CLK_HDMI] = &hdmi_clk.common.hw,
  911. [CLK_HDMI_SLOW] = &hdmi_slow_clk.common.hw,
  912. [CLK_HDMI_CEC] = &hdmi_cec_clk.common.hw,
  913. [CLK_BUS_HDMI] = &bus_hdmi_clk.common.hw,
  914. [CLK_BUS_TCON_TOP] = &bus_tcon_top_clk.common.hw,
  915. [CLK_TCON_LCD0] = &tcon_lcd0_clk.common.hw,
  916. [CLK_BUS_TCON_LCD0] = &bus_tcon_lcd0_clk.common.hw,
  917. [CLK_TCON_TV0] = &tcon_tv0_clk.common.hw,
  918. [CLK_BUS_TCON_TV0] = &bus_tcon_tv0_clk.common.hw,
  919. [CLK_CSI_CCI] = &csi_cci_clk.common.hw,
  920. [CLK_CSI_TOP] = &csi_top_clk.common.hw,
  921. [CLK_CSI_MCLK] = &csi_mclk_clk.common.hw,
  922. [CLK_BUS_CSI] = &bus_csi_clk.common.hw,
  923. [CLK_HDCP] = &hdcp_clk.common.hw,
  924. [CLK_BUS_HDCP] = &bus_hdcp_clk.common.hw,
  925. },
  926. .num = CLK_NUMBER,
  927. };
  928. static struct ccu_reset_map sun50i_h6_ccu_resets[] = {
  929. [RST_MBUS] = { 0x540, BIT(30) },
  930. [RST_BUS_DE] = { 0x60c, BIT(16) },
  931. [RST_BUS_DEINTERLACE] = { 0x62c, BIT(16) },
  932. [RST_BUS_GPU] = { 0x67c, BIT(16) },
  933. [RST_BUS_CE] = { 0x68c, BIT(16) },
  934. [RST_BUS_VE] = { 0x69c, BIT(16) },
  935. [RST_BUS_EMCE] = { 0x6bc, BIT(16) },
  936. [RST_BUS_VP9] = { 0x6cc, BIT(16) },
  937. [RST_BUS_DMA] = { 0x70c, BIT(16) },
  938. [RST_BUS_MSGBOX] = { 0x71c, BIT(16) },
  939. [RST_BUS_SPINLOCK] = { 0x72c, BIT(16) },
  940. [RST_BUS_HSTIMER] = { 0x73c, BIT(16) },
  941. [RST_BUS_DBG] = { 0x78c, BIT(16) },
  942. [RST_BUS_PSI] = { 0x79c, BIT(16) },
  943. [RST_BUS_PWM] = { 0x7ac, BIT(16) },
  944. [RST_BUS_IOMMU] = { 0x7bc, BIT(16) },
  945. [RST_BUS_DRAM] = { 0x80c, BIT(16) },
  946. [RST_BUS_NAND] = { 0x82c, BIT(16) },
  947. [RST_BUS_MMC0] = { 0x84c, BIT(16) },
  948. [RST_BUS_MMC1] = { 0x84c, BIT(17) },
  949. [RST_BUS_MMC2] = { 0x84c, BIT(18) },
  950. [RST_BUS_UART0] = { 0x90c, BIT(16) },
  951. [RST_BUS_UART1] = { 0x90c, BIT(17) },
  952. [RST_BUS_UART2] = { 0x90c, BIT(18) },
  953. [RST_BUS_UART3] = { 0x90c, BIT(19) },
  954. [RST_BUS_I2C0] = { 0x91c, BIT(16) },
  955. [RST_BUS_I2C1] = { 0x91c, BIT(17) },
  956. [RST_BUS_I2C2] = { 0x91c, BIT(18) },
  957. [RST_BUS_I2C3] = { 0x91c, BIT(19) },
  958. [RST_BUS_SCR0] = { 0x93c, BIT(16) },
  959. [RST_BUS_SCR1] = { 0x93c, BIT(17) },
  960. [RST_BUS_SPI0] = { 0x96c, BIT(16) },
  961. [RST_BUS_SPI1] = { 0x96c, BIT(17) },
  962. [RST_BUS_EMAC] = { 0x97c, BIT(16) },
  963. [RST_BUS_TS] = { 0x9bc, BIT(16) },
  964. [RST_BUS_IR_TX] = { 0x9cc, BIT(16) },
  965. [RST_BUS_THS] = { 0x9fc, BIT(16) },
  966. [RST_BUS_I2S0] = { 0xa1c, BIT(16) },
  967. [RST_BUS_I2S1] = { 0xa1c, BIT(17) },
  968. [RST_BUS_I2S2] = { 0xa1c, BIT(18) },
  969. [RST_BUS_I2S3] = { 0xa1c, BIT(19) },
  970. [RST_BUS_SPDIF] = { 0xa2c, BIT(16) },
  971. [RST_BUS_DMIC] = { 0xa4c, BIT(16) },
  972. [RST_BUS_AUDIO_HUB] = { 0xa6c, BIT(16) },
  973. [RST_USB_PHY0] = { 0xa70, BIT(30) },
  974. [RST_USB_PHY1] = { 0xa74, BIT(30) },
  975. [RST_USB_PHY3] = { 0xa7c, BIT(30) },
  976. [RST_USB_HSIC] = { 0xa7c, BIT(28) },
  977. [RST_BUS_OHCI0] = { 0xa8c, BIT(16) },
  978. [RST_BUS_OHCI3] = { 0xa8c, BIT(19) },
  979. [RST_BUS_EHCI0] = { 0xa8c, BIT(20) },
  980. [RST_BUS_XHCI] = { 0xa8c, BIT(21) },
  981. [RST_BUS_EHCI3] = { 0xa8c, BIT(23) },
  982. [RST_BUS_OTG] = { 0xa8c, BIT(24) },
  983. [RST_BUS_PCIE] = { 0xabc, BIT(16) },
  984. [RST_PCIE_POWERUP] = { 0xabc, BIT(17) },
  985. [RST_BUS_HDMI] = { 0xb1c, BIT(16) },
  986. [RST_BUS_HDMI_SUB] = { 0xb1c, BIT(17) },
  987. [RST_BUS_TCON_TOP] = { 0xb5c, BIT(16) },
  988. [RST_BUS_TCON_LCD0] = { 0xb7c, BIT(16) },
  989. [RST_BUS_TCON_TV0] = { 0xb9c, BIT(16) },
  990. [RST_BUS_CSI] = { 0xc2c, BIT(16) },
  991. [RST_BUS_HDCP] = { 0xc4c, BIT(16) },
  992. };
  993. static const struct sunxi_ccu_desc sun50i_h6_ccu_desc = {
  994. .ccu_clks = sun50i_h6_ccu_clks,
  995. .num_ccu_clks = ARRAY_SIZE(sun50i_h6_ccu_clks),
  996. .hw_clks = &sun50i_h6_hw_clks,
  997. .resets = sun50i_h6_ccu_resets,
  998. .num_resets = ARRAY_SIZE(sun50i_h6_ccu_resets),
  999. };
  1000. static const u32 pll_regs[] = {
  1001. SUN50I_H6_PLL_CPUX_REG,
  1002. SUN50I_H6_PLL_DDR0_REG,
  1003. SUN50I_H6_PLL_PERIPH0_REG,
  1004. SUN50I_H6_PLL_PERIPH1_REG,
  1005. SUN50I_H6_PLL_GPU_REG,
  1006. SUN50I_H6_PLL_VIDEO0_REG,
  1007. SUN50I_H6_PLL_VIDEO1_REG,
  1008. SUN50I_H6_PLL_VE_REG,
  1009. SUN50I_H6_PLL_DE_REG,
  1010. SUN50I_H6_PLL_HSIC_REG,
  1011. SUN50I_H6_PLL_AUDIO_REG,
  1012. };
  1013. static const u32 pll_video_regs[] = {
  1014. SUN50I_H6_PLL_VIDEO0_REG,
  1015. SUN50I_H6_PLL_VIDEO1_REG,
  1016. };
  1017. static const u32 usb2_clk_regs[] = {
  1018. SUN50I_H6_USB0_CLK_REG,
  1019. SUN50I_H6_USB3_CLK_REG,
  1020. };
  1021. static int sun50i_h6_ccu_probe(struct platform_device *pdev)
  1022. {
  1023. struct resource *res;
  1024. void __iomem *reg;
  1025. u32 val;
  1026. int i;
  1027. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1028. reg = devm_ioremap_resource(&pdev->dev, res);
  1029. if (IS_ERR(reg))
  1030. return PTR_ERR(reg);
  1031. /* Enable the lock bits on all PLLs */
  1032. for (i = 0; i < ARRAY_SIZE(pll_regs); i++) {
  1033. val = readl(reg + pll_regs[i]);
  1034. val |= BIT(29);
  1035. writel(val, reg + pll_regs[i]);
  1036. }
  1037. /*
  1038. * Force the output divider of video PLLs to 0.
  1039. *
  1040. * See the comment before pll-video0 definition for the reason.
  1041. */
  1042. for (i = 0; i < ARRAY_SIZE(pll_video_regs); i++) {
  1043. val = readl(reg + pll_video_regs[i]);
  1044. val &= ~BIT(0);
  1045. writel(val, reg + pll_video_regs[i]);
  1046. }
  1047. /*
  1048. * Force OHCI 12M clock sources to 00 (12MHz divided from 48MHz)
  1049. *
  1050. * This clock mux is still mysterious, and the code just enforces
  1051. * it to have a valid clock parent.
  1052. */
  1053. for (i = 0; i < ARRAY_SIZE(usb2_clk_regs); i++) {
  1054. val = readl(reg + usb2_clk_regs[i]);
  1055. val &= ~GENMASK(25, 24);
  1056. writel (val, reg + usb2_clk_regs[i]);
  1057. }
  1058. /*
  1059. * Force the post-divider of pll-audio to 8 and the output divider
  1060. * of it to 1, to make the clock name represents the real frequency.
  1061. */
  1062. val = readl(reg + SUN50I_H6_PLL_AUDIO_REG);
  1063. val &= ~(GENMASK(21, 16) | BIT(0));
  1064. writel(val | (7 << 16), reg + SUN50I_H6_PLL_AUDIO_REG);
  1065. return sunxi_ccu_probe(pdev->dev.of_node, reg, &sun50i_h6_ccu_desc);
  1066. }
  1067. static const struct of_device_id sun50i_h6_ccu_ids[] = {
  1068. { .compatible = "allwinner,sun50i-h6-ccu" },
  1069. { }
  1070. };
  1071. static struct platform_driver sun50i_h6_ccu_driver = {
  1072. .probe = sun50i_h6_ccu_probe,
  1073. .driver = {
  1074. .name = "sun50i-h6-ccu",
  1075. .of_match_table = sun50i_h6_ccu_ids,
  1076. },
  1077. };
  1078. builtin_platform_driver(sun50i_h6_ccu_driver);