ccu-sun50i-h6.c 39 KB

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