ccu-sun50i-h616.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2020 Arm Ltd.
  4. * Based on the H6 CCU driver, which is:
  5. * Copyright (c) 2017 Icenowy Zheng <[email protected]>
  6. */
  7. #include <linux/clk-provider.h>
  8. #include <linux/io.h>
  9. #include <linux/module.h>
  10. #include <linux/platform_device.h>
  11. #include "ccu_common.h"
  12. #include "ccu_reset.h"
  13. #include "ccu_div.h"
  14. #include "ccu_gate.h"
  15. #include "ccu_mp.h"
  16. #include "ccu_mult.h"
  17. #include "ccu_nk.h"
  18. #include "ccu_nkm.h"
  19. #include "ccu_nkmp.h"
  20. #include "ccu_nm.h"
  21. #include "ccu-sun50i-h616.h"
  22. /*
  23. * The CPU PLL is actually NP clock, with P being /1, /2 or /4. However
  24. * P should only be used for output frequencies lower than 288 MHz.
  25. *
  26. * For now we can just model it as a multiplier clock, and force P to /1.
  27. *
  28. * The M factor is present in the register's description, but not in the
  29. * frequency formula, and it's documented as "M is only used for backdoor
  30. * testing", so it's not modelled and then force to 0.
  31. */
  32. #define SUN50I_H616_PLL_CPUX_REG 0x000
  33. static struct ccu_mult pll_cpux_clk = {
  34. .enable = BIT(31),
  35. .lock = BIT(28),
  36. .mult = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  37. .common = {
  38. .reg = 0x000,
  39. .hw.init = CLK_HW_INIT("pll-cpux", "osc24M",
  40. &ccu_mult_ops,
  41. CLK_SET_RATE_UNGATE),
  42. },
  43. };
  44. /* Some PLLs are input * N / div1 / P. Model them as NKMP with no K */
  45. #define SUN50I_H616_PLL_DDR0_REG 0x010
  46. static struct ccu_nkmp pll_ddr0_clk = {
  47. .enable = BIT(31),
  48. .lock = BIT(28),
  49. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  50. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  51. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  52. .common = {
  53. .reg = 0x010,
  54. .hw.init = CLK_HW_INIT("pll-ddr0", "osc24M",
  55. &ccu_nkmp_ops,
  56. CLK_SET_RATE_UNGATE),
  57. },
  58. };
  59. #define SUN50I_H616_PLL_DDR1_REG 0x018
  60. static struct ccu_nkmp pll_ddr1_clk = {
  61. .enable = BIT(31),
  62. .lock = BIT(28),
  63. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  64. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  65. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  66. .common = {
  67. .reg = 0x018,
  68. .hw.init = CLK_HW_INIT("pll-ddr1", "osc24M",
  69. &ccu_nkmp_ops,
  70. CLK_SET_RATE_UNGATE),
  71. },
  72. };
  73. #define SUN50I_H616_PLL_PERIPH0_REG 0x020
  74. static struct ccu_nkmp pll_periph0_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 = 2,
  81. .common = {
  82. .reg = 0x020,
  83. .features = CCU_FEATURE_FIXED_POSTDIV,
  84. .hw.init = CLK_HW_INIT("pll-periph0", "osc24M",
  85. &ccu_nkmp_ops,
  86. CLK_SET_RATE_UNGATE),
  87. },
  88. };
  89. #define SUN50I_H616_PLL_PERIPH1_REG 0x028
  90. static struct ccu_nkmp pll_periph1_clk = {
  91. .enable = BIT(31),
  92. .lock = BIT(28),
  93. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  94. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  95. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  96. .fixed_post_div = 2,
  97. .common = {
  98. .reg = 0x028,
  99. .features = CCU_FEATURE_FIXED_POSTDIV,
  100. .hw.init = CLK_HW_INIT("pll-periph1", "osc24M",
  101. &ccu_nkmp_ops,
  102. CLK_SET_RATE_UNGATE),
  103. },
  104. };
  105. #define SUN50I_H616_PLL_GPU_REG 0x030
  106. static struct ccu_nkmp pll_gpu_clk = {
  107. .enable = BIT(31),
  108. .lock = BIT(28),
  109. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  110. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  111. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  112. .common = {
  113. .reg = 0x030,
  114. .hw.init = CLK_HW_INIT("pll-gpu", "osc24M",
  115. &ccu_nkmp_ops,
  116. CLK_SET_RATE_UNGATE),
  117. },
  118. };
  119. /*
  120. * For Video PLLs, the output divider is described as "used for testing"
  121. * in the user manual. So it's not modelled and forced to 0.
  122. */
  123. #define SUN50I_H616_PLL_VIDEO0_REG 0x040
  124. static struct ccu_nm pll_video0_clk = {
  125. .enable = BIT(31),
  126. .lock = BIT(28),
  127. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  128. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  129. .fixed_post_div = 4,
  130. .min_rate = 288000000,
  131. .max_rate = 2400000000UL,
  132. .common = {
  133. .reg = 0x040,
  134. .features = CCU_FEATURE_FIXED_POSTDIV,
  135. .hw.init = CLK_HW_INIT("pll-video0", "osc24M",
  136. &ccu_nm_ops,
  137. CLK_SET_RATE_UNGATE),
  138. },
  139. };
  140. #define SUN50I_H616_PLL_VIDEO1_REG 0x048
  141. static struct ccu_nm pll_video1_clk = {
  142. .enable = BIT(31),
  143. .lock = BIT(28),
  144. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  145. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  146. .fixed_post_div = 4,
  147. .min_rate = 288000000,
  148. .max_rate = 2400000000UL,
  149. .common = {
  150. .reg = 0x048,
  151. .features = CCU_FEATURE_FIXED_POSTDIV,
  152. .hw.init = CLK_HW_INIT("pll-video1", "osc24M",
  153. &ccu_nm_ops,
  154. CLK_SET_RATE_UNGATE),
  155. },
  156. };
  157. #define SUN50I_H616_PLL_VIDEO2_REG 0x050
  158. static struct ccu_nm pll_video2_clk = {
  159. .enable = BIT(31),
  160. .lock = BIT(28),
  161. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  162. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  163. .fixed_post_div = 4,
  164. .min_rate = 288000000,
  165. .max_rate = 2400000000UL,
  166. .common = {
  167. .reg = 0x050,
  168. .features = CCU_FEATURE_FIXED_POSTDIV,
  169. .hw.init = CLK_HW_INIT("pll-video2", "osc24M",
  170. &ccu_nm_ops,
  171. CLK_SET_RATE_UNGATE),
  172. },
  173. };
  174. #define SUN50I_H616_PLL_VE_REG 0x058
  175. static struct ccu_nkmp pll_ve_clk = {
  176. .enable = BIT(31),
  177. .lock = BIT(28),
  178. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  179. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  180. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  181. .common = {
  182. .reg = 0x058,
  183. .hw.init = CLK_HW_INIT("pll-ve", "osc24M",
  184. &ccu_nkmp_ops,
  185. CLK_SET_RATE_UNGATE),
  186. },
  187. };
  188. #define SUN50I_H616_PLL_DE_REG 0x060
  189. static struct ccu_nkmp pll_de_clk = {
  190. .enable = BIT(31),
  191. .lock = BIT(28),
  192. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  193. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  194. .p = _SUNXI_CCU_DIV(0, 1), /* output divider */
  195. .common = {
  196. .reg = 0x060,
  197. .hw.init = CLK_HW_INIT("pll-de", "osc24M",
  198. &ccu_nkmp_ops,
  199. CLK_SET_RATE_UNGATE),
  200. },
  201. };
  202. /*
  203. * TODO: Determine SDM settings for the audio PLL. The manual suggests
  204. * PLL_FACTOR_N=16, PLL_POST_DIV_P=2, OUTPUT_DIV=2, pattern=0xe000c49b
  205. * for 24.576 MHz, and PLL_FACTOR_N=22, PLL_POST_DIV_P=3, OUTPUT_DIV=2,
  206. * pattern=0xe001288c for 22.5792 MHz.
  207. * This clashes with our fixed PLL_POST_DIV_P.
  208. */
  209. #define SUN50I_H616_PLL_AUDIO_REG 0x078
  210. static struct ccu_nm pll_audio_hs_clk = {
  211. .enable = BIT(31),
  212. .lock = BIT(28),
  213. .n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
  214. .m = _SUNXI_CCU_DIV(1, 1), /* input divider */
  215. .common = {
  216. .reg = 0x078,
  217. .hw.init = CLK_HW_INIT("pll-audio-hs", "osc24M",
  218. &ccu_nm_ops,
  219. CLK_SET_RATE_UNGATE),
  220. },
  221. };
  222. static const char * const cpux_parents[] = { "osc24M", "osc32k",
  223. "iosc", "pll-cpux", "pll-periph0" };
  224. static SUNXI_CCU_MUX(cpux_clk, "cpux", cpux_parents,
  225. 0x500, 24, 3, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
  226. static SUNXI_CCU_M(axi_clk, "axi", "cpux", 0x500, 0, 2, 0);
  227. static SUNXI_CCU_M(cpux_apb_clk, "cpux-apb", "cpux", 0x500, 8, 2, 0);
  228. static const char * const psi_ahb1_ahb2_parents[] = { "osc24M", "osc32k",
  229. "iosc", "pll-periph0" };
  230. static SUNXI_CCU_MP_WITH_MUX(psi_ahb1_ahb2_clk, "psi-ahb1-ahb2",
  231. psi_ahb1_ahb2_parents,
  232. 0x510,
  233. 0, 2, /* M */
  234. 8, 2, /* P */
  235. 24, 2, /* mux */
  236. 0);
  237. static const char * const ahb3_apb1_apb2_parents[] = { "osc24M", "osc32k",
  238. "psi-ahb1-ahb2",
  239. "pll-periph0" };
  240. static SUNXI_CCU_MP_WITH_MUX(ahb3_clk, "ahb3", ahb3_apb1_apb2_parents, 0x51c,
  241. 0, 2, /* M */
  242. 8, 2, /* P */
  243. 24, 2, /* mux */
  244. 0);
  245. static SUNXI_CCU_MP_WITH_MUX(apb1_clk, "apb1", ahb3_apb1_apb2_parents, 0x520,
  246. 0, 2, /* M */
  247. 8, 2, /* P */
  248. 24, 2, /* mux */
  249. 0);
  250. static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", ahb3_apb1_apb2_parents, 0x524,
  251. 0, 2, /* M */
  252. 8, 2, /* P */
  253. 24, 2, /* mux */
  254. 0);
  255. static const char * const mbus_parents[] = { "osc24M", "pll-periph0-2x",
  256. "pll-ddr0", "pll-ddr1" };
  257. static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents, 0x540,
  258. 0, 3, /* M */
  259. 24, 2, /* mux */
  260. BIT(31), /* gate */
  261. CLK_IS_CRITICAL);
  262. static const char * const de_parents[] = { "pll-de", "pll-periph0-2x" };
  263. static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents, 0x600,
  264. 0, 4, /* M */
  265. 24, 1, /* mux */
  266. BIT(31), /* gate */
  267. CLK_SET_RATE_PARENT);
  268. static SUNXI_CCU_GATE(bus_de_clk, "bus-de", "psi-ahb1-ahb2",
  269. 0x60c, BIT(0), 0);
  270. static SUNXI_CCU_M_WITH_MUX_GATE(deinterlace_clk, "deinterlace",
  271. de_parents,
  272. 0x620,
  273. 0, 4, /* M */
  274. 24, 1, /* mux */
  275. BIT(31), /* gate */
  276. 0);
  277. static SUNXI_CCU_GATE(bus_deinterlace_clk, "bus-deinterlace", "psi-ahb1-ahb2",
  278. 0x62c, BIT(0), 0);
  279. static SUNXI_CCU_M_WITH_MUX_GATE(g2d_clk, "g2d", de_parents, 0x630,
  280. 0, 4, /* M */
  281. 24, 1, /* mux */
  282. BIT(31), /* gate */
  283. 0);
  284. static SUNXI_CCU_GATE(bus_g2d_clk, "bus-g2d", "psi-ahb1-ahb2",
  285. 0x63c, BIT(0), 0);
  286. static const char * const gpu0_parents[] = { "pll-gpu", "gpu1" };
  287. static SUNXI_CCU_M_WITH_MUX_GATE(gpu0_clk, "gpu0", gpu0_parents, 0x670,
  288. 0, 2, /* M */
  289. 24, 1, /* mux */
  290. BIT(31), /* gate */
  291. CLK_SET_RATE_PARENT);
  292. static SUNXI_CCU_M_WITH_GATE(gpu1_clk, "gpu1", "pll-periph0-2x", 0x674,
  293. 0, 2, /* M */
  294. BIT(31),/* gate */
  295. 0);
  296. static SUNXI_CCU_GATE(bus_gpu_clk, "bus-gpu", "psi-ahb1-ahb2",
  297. 0x67c, BIT(0), 0);
  298. static const char * const ce_parents[] = { "osc24M", "pll-periph0-2x" };
  299. static SUNXI_CCU_MP_WITH_MUX_GATE(ce_clk, "ce", ce_parents, 0x680,
  300. 0, 4, /* M */
  301. 8, 2, /* N */
  302. 24, 1, /* mux */
  303. BIT(31),/* gate */
  304. 0);
  305. static SUNXI_CCU_GATE(bus_ce_clk, "bus-ce", "psi-ahb1-ahb2",
  306. 0x68c, BIT(0), 0);
  307. static const char * const ve_parents[] = { "pll-ve" };
  308. static SUNXI_CCU_M_WITH_MUX_GATE(ve_clk, "ve", ve_parents, 0x690,
  309. 0, 3, /* M */
  310. 24, 1, /* mux */
  311. BIT(31), /* gate */
  312. CLK_SET_RATE_PARENT);
  313. static SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "psi-ahb1-ahb2",
  314. 0x69c, BIT(0), 0);
  315. static SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "psi-ahb1-ahb2",
  316. 0x70c, 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", "pll-ddr1" };
  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_g2d_clk, "mbus-g2d", "mbus",
  349. 0x804, BIT(10), 0);
  350. static SUNXI_CCU_GATE(bus_dram_clk, "bus-dram", "psi-ahb1-ahb2",
  351. 0x80c, BIT(0), CLK_IS_CRITICAL);
  352. static const char * const nand_spi_parents[] = { "osc24M", "pll-periph0",
  353. "pll-periph1", "pll-periph0-2x",
  354. "pll-periph1-2x" };
  355. static SUNXI_CCU_MP_WITH_MUX_GATE(nand0_clk, "nand0", nand_spi_parents, 0x810,
  356. 0, 4, /* M */
  357. 8, 2, /* N */
  358. 24, 3, /* mux */
  359. BIT(31),/* gate */
  360. 0);
  361. static SUNXI_CCU_MP_WITH_MUX_GATE(nand1_clk, "nand1", nand_spi_parents, 0x814,
  362. 0, 4, /* M */
  363. 8, 2, /* N */
  364. 24, 3, /* mux */
  365. BIT(31),/* gate */
  366. 0);
  367. static SUNXI_CCU_GATE(bus_nand_clk, "bus-nand", "ahb3", 0x82c, BIT(0), 0);
  368. static const char * const mmc_parents[] = { "osc24M", "pll-periph0-2x",
  369. "pll-periph1-2x" };
  370. static SUNXI_CCU_MP_WITH_MUX_GATE_POSTDIV(mmc0_clk, "mmc0", mmc_parents, 0x830,
  371. 0, 4, /* M */
  372. 8, 2, /* N */
  373. 24, 2, /* mux */
  374. BIT(31), /* gate */
  375. 2, /* post-div */
  376. 0);
  377. static SUNXI_CCU_MP_WITH_MUX_GATE_POSTDIV(mmc1_clk, "mmc1", mmc_parents, 0x834,
  378. 0, 4, /* M */
  379. 8, 2, /* N */
  380. 24, 2, /* mux */
  381. BIT(31), /* gate */
  382. 2, /* post-div */
  383. 0);
  384. static SUNXI_CCU_MP_WITH_MUX_GATE_POSTDIV(mmc2_clk, "mmc2", mmc_parents, 0x838,
  385. 0, 4, /* M */
  386. 8, 2, /* N */
  387. 24, 2, /* mux */
  388. BIT(31), /* gate */
  389. 2, /* post-div */
  390. 0);
  391. static SUNXI_CCU_GATE(bus_mmc0_clk, "bus-mmc0", "ahb3", 0x84c, BIT(0), 0);
  392. static SUNXI_CCU_GATE(bus_mmc1_clk, "bus-mmc1", "ahb3", 0x84c, BIT(1), 0);
  393. static SUNXI_CCU_GATE(bus_mmc2_clk, "bus-mmc2", "ahb3", 0x84c, BIT(2), 0);
  394. static SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb2", 0x90c, BIT(0), 0);
  395. static SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb2", 0x90c, BIT(1), 0);
  396. static SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb2", 0x90c, BIT(2), 0);
  397. static SUNXI_CCU_GATE(bus_uart3_clk, "bus-uart3", "apb2", 0x90c, BIT(3), 0);
  398. static SUNXI_CCU_GATE(bus_uart4_clk, "bus-uart4", "apb2", 0x90c, BIT(4), 0);
  399. static SUNXI_CCU_GATE(bus_uart5_clk, "bus-uart5", "apb2", 0x90c, BIT(5), 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_i2c4_clk, "bus-i2c4", "apb2", 0x91c, BIT(4), 0);
  405. static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", nand_spi_parents, 0x940,
  406. 0, 4, /* M */
  407. 8, 2, /* N */
  408. 24, 3, /* mux */
  409. BIT(31),/* gate */
  410. 0);
  411. static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", nand_spi_parents, 0x944,
  412. 0, 4, /* M */
  413. 8, 2, /* N */
  414. 24, 3, /* mux */
  415. BIT(31),/* gate */
  416. 0);
  417. static SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb3", 0x96c, BIT(0), 0);
  418. static SUNXI_CCU_GATE(bus_spi1_clk, "bus-spi1", "ahb3", 0x96c, BIT(1), 0);
  419. static SUNXI_CCU_GATE(emac_25m_clk, "emac-25m", "ahb3", 0x970,
  420. BIT(31) | BIT(30), 0);
  421. static SUNXI_CCU_GATE(bus_emac0_clk, "bus-emac0", "ahb3", 0x97c, BIT(0), 0);
  422. static SUNXI_CCU_GATE(bus_emac1_clk, "bus-emac1", "ahb3", 0x97c, BIT(1), 0);
  423. static const char * const ts_parents[] = { "osc24M", "pll-periph0" };
  424. static SUNXI_CCU_MP_WITH_MUX_GATE(ts_clk, "ts", ts_parents, 0x9b0,
  425. 0, 4, /* M */
  426. 8, 2, /* N */
  427. 24, 1, /* mux */
  428. BIT(31),/* gate */
  429. 0);
  430. static SUNXI_CCU_GATE(bus_ts_clk, "bus-ts", "ahb3", 0x9bc, BIT(0), 0);
  431. static SUNXI_CCU_GATE(bus_ths_clk, "bus-ths", "apb1", 0x9fc, BIT(0), 0);
  432. static const char * const audio_parents[] = { "pll-audio-1x", "pll-audio-2x",
  433. "pll-audio-4x", "pll-audio-hs" };
  434. static struct ccu_div spdif_clk = {
  435. .enable = BIT(31),
  436. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  437. .mux = _SUNXI_CCU_MUX(24, 2),
  438. .common = {
  439. .reg = 0xa20,
  440. .hw.init = CLK_HW_INIT_PARENTS("spdif",
  441. audio_parents,
  442. &ccu_div_ops,
  443. 0),
  444. },
  445. };
  446. static SUNXI_CCU_GATE(bus_spdif_clk, "bus-spdif", "apb1", 0xa2c, BIT(0), 0);
  447. static struct ccu_div dmic_clk = {
  448. .enable = BIT(31),
  449. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  450. .mux = _SUNXI_CCU_MUX(24, 2),
  451. .common = {
  452. .reg = 0xa40,
  453. .hw.init = CLK_HW_INIT_PARENTS("dmic",
  454. audio_parents,
  455. &ccu_div_ops,
  456. 0),
  457. },
  458. };
  459. static SUNXI_CCU_GATE(bus_dmic_clk, "bus-dmic", "apb1", 0xa4c, BIT(0), 0);
  460. static SUNXI_CCU_M_WITH_MUX_GATE(audio_codec_1x_clk, "audio-codec-1x",
  461. audio_parents, 0xa50,
  462. 0, 4, /* M */
  463. 24, 2, /* mux */
  464. BIT(31), /* gate */
  465. CLK_SET_RATE_PARENT);
  466. static SUNXI_CCU_M_WITH_MUX_GATE(audio_codec_4x_clk, "audio-codec-4x",
  467. audio_parents, 0xa54,
  468. 0, 4, /* M */
  469. 24, 2, /* mux */
  470. BIT(31), /* gate */
  471. CLK_SET_RATE_PARENT);
  472. static SUNXI_CCU_GATE(bus_audio_codec_clk, "bus-audio-codec", "apb1", 0xa5c,
  473. BIT(0), 0);
  474. static struct ccu_div audio_hub_clk = {
  475. .enable = BIT(31),
  476. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  477. .mux = _SUNXI_CCU_MUX(24, 2),
  478. .common = {
  479. .reg = 0xa60,
  480. .hw.init = CLK_HW_INIT_PARENTS("audio-hub",
  481. audio_parents,
  482. &ccu_div_ops,
  483. 0),
  484. },
  485. };
  486. static SUNXI_CCU_GATE(bus_audio_hub_clk, "bus-audio-hub", "apb1", 0xa6c, BIT(0), 0);
  487. /*
  488. * There are OHCI 12M clock source selection bits for the four USB 2.0 ports.
  489. * We will force them to 0 (12M divided from 48M).
  490. */
  491. #define SUN50I_H616_USB0_CLK_REG 0xa70
  492. #define SUN50I_H616_USB1_CLK_REG 0xa74
  493. #define SUN50I_H616_USB2_CLK_REG 0xa78
  494. #define SUN50I_H616_USB3_CLK_REG 0xa7c
  495. static SUNXI_CCU_GATE(usb_ohci0_clk, "usb-ohci0", "osc12M", 0xa70, BIT(31), 0);
  496. static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M", 0xa70, BIT(29), 0);
  497. static SUNXI_CCU_GATE(usb_ohci1_clk, "usb-ohci1", "osc12M", 0xa74, BIT(31), 0);
  498. static SUNXI_CCU_GATE(usb_phy1_clk, "usb-phy1", "osc24M", 0xa74, BIT(29), 0);
  499. static SUNXI_CCU_GATE(usb_ohci2_clk, "usb-ohci2", "osc12M", 0xa78, BIT(31), 0);
  500. static SUNXI_CCU_GATE(usb_phy2_clk, "usb-phy2", "osc24M", 0xa78, BIT(29), 0);
  501. static SUNXI_CCU_GATE(usb_ohci3_clk, "usb-ohci3", "osc12M", 0xa7c, BIT(31), 0);
  502. static SUNXI_CCU_GATE(usb_phy3_clk, "usb-phy3", "osc24M", 0xa7c, BIT(29), 0);
  503. static SUNXI_CCU_GATE(bus_ohci0_clk, "bus-ohci0", "ahb3", 0xa8c, BIT(0), 0);
  504. static SUNXI_CCU_GATE(bus_ohci1_clk, "bus-ohci1", "ahb3", 0xa8c, BIT(1), 0);
  505. static SUNXI_CCU_GATE(bus_ohci2_clk, "bus-ohci2", "ahb3", 0xa8c, BIT(2), 0);
  506. static SUNXI_CCU_GATE(bus_ohci3_clk, "bus-ohci3", "ahb3", 0xa8c, BIT(3), 0);
  507. static SUNXI_CCU_GATE(bus_ehci0_clk, "bus-ehci0", "ahb3", 0xa8c, BIT(4), 0);
  508. static SUNXI_CCU_GATE(bus_ehci1_clk, "bus-ehci1", "ahb3", 0xa8c, BIT(5), 0);
  509. static SUNXI_CCU_GATE(bus_ehci2_clk, "bus-ehci2", "ahb3", 0xa8c, BIT(6), 0);
  510. static SUNXI_CCU_GATE(bus_ehci3_clk, "bus-ehci3", "ahb3", 0xa8c, BIT(7), 0);
  511. static SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb3", 0xa8c, BIT(8), 0);
  512. static SUNXI_CCU_GATE(bus_keyadc_clk, "bus-keyadc", "apb1", 0xa9c, BIT(0), 0);
  513. static const char * const hdmi_parents[] = { "pll-video0", "pll-video0-4x",
  514. "pll-video2", "pll-video2-4x" };
  515. static SUNXI_CCU_M_WITH_MUX_GATE(hdmi_clk, "hdmi", hdmi_parents, 0xb00,
  516. 0, 4, /* M */
  517. 24, 2, /* mux */
  518. BIT(31), /* gate */
  519. 0);
  520. static SUNXI_CCU_GATE(hdmi_slow_clk, "hdmi-slow", "osc24M", 0xb04, BIT(31), 0);
  521. static const char * const hdmi_cec_parents[] = { "osc32k", "pll-periph0-2x" };
  522. static const struct ccu_mux_fixed_prediv hdmi_cec_predivs[] = {
  523. { .index = 1, .div = 36621 },
  524. };
  525. #define SUN50I_H616_HDMI_CEC_CLK_REG 0xb10
  526. static struct ccu_mux hdmi_cec_clk = {
  527. .enable = BIT(31) | BIT(30),
  528. .mux = {
  529. .shift = 24,
  530. .width = 2,
  531. .fixed_predivs = hdmi_cec_predivs,
  532. .n_predivs = ARRAY_SIZE(hdmi_cec_predivs),
  533. },
  534. .common = {
  535. .reg = 0xb10,
  536. .features = CCU_FEATURE_FIXED_PREDIV,
  537. .hw.init = CLK_HW_INIT_PARENTS("hdmi-cec",
  538. hdmi_cec_parents,
  539. &ccu_mux_ops,
  540. 0),
  541. },
  542. };
  543. static SUNXI_CCU_GATE(bus_hdmi_clk, "bus-hdmi", "ahb3", 0xb1c, BIT(0), 0);
  544. static SUNXI_CCU_GATE(bus_tcon_top_clk, "bus-tcon-top", "ahb3",
  545. 0xb5c, BIT(0), 0);
  546. static const char * const tcon_tv_parents[] = { "pll-video0",
  547. "pll-video0-4x",
  548. "pll-video1",
  549. "pll-video1-4x" };
  550. static SUNXI_CCU_MP_WITH_MUX_GATE(tcon_tv0_clk, "tcon-tv0",
  551. tcon_tv_parents, 0xb80,
  552. 0, 4, /* M */
  553. 8, 2, /* P */
  554. 24, 3, /* mux */
  555. BIT(31), /* gate */
  556. CLK_SET_RATE_PARENT);
  557. static SUNXI_CCU_MP_WITH_MUX_GATE(tcon_tv1_clk, "tcon-tv1",
  558. tcon_tv_parents, 0xb84,
  559. 0, 4, /* M */
  560. 8, 2, /* P */
  561. 24, 3, /* mux */
  562. BIT(31), /* gate */
  563. CLK_SET_RATE_PARENT);
  564. static SUNXI_CCU_GATE(bus_tcon_tv0_clk, "bus-tcon-tv0", "ahb3",
  565. 0xb9c, BIT(0), 0);
  566. static SUNXI_CCU_GATE(bus_tcon_tv1_clk, "bus-tcon-tv1", "ahb3",
  567. 0xb9c, BIT(1), 0);
  568. static SUNXI_CCU_MP_WITH_MUX_GATE(tve0_clk, "tve0",
  569. tcon_tv_parents, 0xbb0,
  570. 0, 4, /* M */
  571. 8, 2, /* P */
  572. 24, 3, /* mux */
  573. BIT(31), /* gate */
  574. CLK_SET_RATE_PARENT);
  575. static SUNXI_CCU_GATE(bus_tve_top_clk, "bus-tve-top", "ahb3",
  576. 0xbbc, BIT(0), 0);
  577. static SUNXI_CCU_GATE(bus_tve0_clk, "bus-tve0", "ahb3",
  578. 0xbbc, BIT(1), 0);
  579. static const char * const hdcp_parents[] = { "pll-periph0", "pll-periph1" };
  580. static SUNXI_CCU_M_WITH_MUX_GATE(hdcp_clk, "hdcp", hdcp_parents, 0xc40,
  581. 0, 4, /* M */
  582. 24, 2, /* mux */
  583. BIT(31), /* gate */
  584. 0);
  585. static SUNXI_CCU_GATE(bus_hdcp_clk, "bus-hdcp", "ahb3", 0xc4c, BIT(0), 0);
  586. /* Fixed factor clocks */
  587. static CLK_FIXED_FACTOR_FW_NAME(osc12M_clk, "osc12M", "hosc", 2, 1, 0);
  588. static const struct clk_hw *clk_parent_pll_audio[] = {
  589. &pll_audio_hs_clk.common.hw
  590. };
  591. /*
  592. * The divider of pll-audio is fixed to 24 for now, so 24576000 and 22579200
  593. * rates can be set exactly in conjunction with sigma-delta modulation.
  594. */
  595. static CLK_FIXED_FACTOR_HWS(pll_audio_1x_clk, "pll-audio-1x",
  596. clk_parent_pll_audio,
  597. 96, 1, CLK_SET_RATE_PARENT);
  598. static CLK_FIXED_FACTOR_HWS(pll_audio_2x_clk, "pll-audio-2x",
  599. clk_parent_pll_audio,
  600. 48, 1, CLK_SET_RATE_PARENT);
  601. static CLK_FIXED_FACTOR_HWS(pll_audio_4x_clk, "pll-audio-4x",
  602. clk_parent_pll_audio,
  603. 24, 1, CLK_SET_RATE_PARENT);
  604. static const struct clk_hw *pll_periph0_parents[] = {
  605. &pll_periph0_clk.common.hw
  606. };
  607. static CLK_FIXED_FACTOR_HWS(pll_periph0_2x_clk, "pll-periph0-2x",
  608. pll_periph0_parents,
  609. 1, 2, 0);
  610. static const struct clk_hw *pll_periph0_2x_hws[] = {
  611. &pll_periph0_2x_clk.hw
  612. };
  613. static CLK_FIXED_FACTOR_HWS(pll_system_32k_clk, "pll-system-32k",
  614. pll_periph0_2x_hws, 36621, 1, 0);
  615. static const struct clk_hw *pll_periph1_parents[] = {
  616. &pll_periph1_clk.common.hw
  617. };
  618. static CLK_FIXED_FACTOR_HWS(pll_periph1_2x_clk, "pll-periph1-2x",
  619. pll_periph1_parents,
  620. 1, 2, 0);
  621. static CLK_FIXED_FACTOR_HW(pll_video0_4x_clk, "pll-video0-4x",
  622. &pll_video0_clk.common.hw,
  623. 1, 4, CLK_SET_RATE_PARENT);
  624. static CLK_FIXED_FACTOR_HW(pll_video1_4x_clk, "pll-video1-4x",
  625. &pll_video1_clk.common.hw,
  626. 1, 4, CLK_SET_RATE_PARENT);
  627. static CLK_FIXED_FACTOR_HW(pll_video2_4x_clk, "pll-video2-4x",
  628. &pll_video2_clk.common.hw,
  629. 1, 4, CLK_SET_RATE_PARENT);
  630. static struct ccu_common *sun50i_h616_ccu_clks[] = {
  631. &pll_cpux_clk.common,
  632. &pll_ddr0_clk.common,
  633. &pll_ddr1_clk.common,
  634. &pll_periph0_clk.common,
  635. &pll_periph1_clk.common,
  636. &pll_gpu_clk.common,
  637. &pll_video0_clk.common,
  638. &pll_video1_clk.common,
  639. &pll_video2_clk.common,
  640. &pll_ve_clk.common,
  641. &pll_de_clk.common,
  642. &pll_audio_hs_clk.common,
  643. &cpux_clk.common,
  644. &axi_clk.common,
  645. &cpux_apb_clk.common,
  646. &psi_ahb1_ahb2_clk.common,
  647. &ahb3_clk.common,
  648. &apb1_clk.common,
  649. &apb2_clk.common,
  650. &mbus_clk.common,
  651. &de_clk.common,
  652. &bus_de_clk.common,
  653. &deinterlace_clk.common,
  654. &bus_deinterlace_clk.common,
  655. &g2d_clk.common,
  656. &bus_g2d_clk.common,
  657. &gpu0_clk.common,
  658. &bus_gpu_clk.common,
  659. &gpu1_clk.common,
  660. &ce_clk.common,
  661. &bus_ce_clk.common,
  662. &ve_clk.common,
  663. &bus_ve_clk.common,
  664. &bus_dma_clk.common,
  665. &bus_hstimer_clk.common,
  666. &avs_clk.common,
  667. &bus_dbg_clk.common,
  668. &bus_psi_clk.common,
  669. &bus_pwm_clk.common,
  670. &bus_iommu_clk.common,
  671. &dram_clk.common,
  672. &mbus_dma_clk.common,
  673. &mbus_ve_clk.common,
  674. &mbus_ce_clk.common,
  675. &mbus_ts_clk.common,
  676. &mbus_nand_clk.common,
  677. &mbus_g2d_clk.common,
  678. &bus_dram_clk.common,
  679. &nand0_clk.common,
  680. &nand1_clk.common,
  681. &bus_nand_clk.common,
  682. &mmc0_clk.common,
  683. &mmc1_clk.common,
  684. &mmc2_clk.common,
  685. &bus_mmc0_clk.common,
  686. &bus_mmc1_clk.common,
  687. &bus_mmc2_clk.common,
  688. &bus_uart0_clk.common,
  689. &bus_uart1_clk.common,
  690. &bus_uart2_clk.common,
  691. &bus_uart3_clk.common,
  692. &bus_uart4_clk.common,
  693. &bus_uart5_clk.common,
  694. &bus_i2c0_clk.common,
  695. &bus_i2c1_clk.common,
  696. &bus_i2c2_clk.common,
  697. &bus_i2c3_clk.common,
  698. &bus_i2c4_clk.common,
  699. &spi0_clk.common,
  700. &spi1_clk.common,
  701. &bus_spi0_clk.common,
  702. &bus_spi1_clk.common,
  703. &emac_25m_clk.common,
  704. &bus_emac0_clk.common,
  705. &bus_emac1_clk.common,
  706. &ts_clk.common,
  707. &bus_ts_clk.common,
  708. &bus_ths_clk.common,
  709. &spdif_clk.common,
  710. &bus_spdif_clk.common,
  711. &dmic_clk.common,
  712. &bus_dmic_clk.common,
  713. &audio_codec_1x_clk.common,
  714. &audio_codec_4x_clk.common,
  715. &bus_audio_codec_clk.common,
  716. &audio_hub_clk.common,
  717. &bus_audio_hub_clk.common,
  718. &usb_ohci0_clk.common,
  719. &usb_phy0_clk.common,
  720. &usb_ohci1_clk.common,
  721. &usb_phy1_clk.common,
  722. &usb_ohci2_clk.common,
  723. &usb_phy2_clk.common,
  724. &usb_ohci3_clk.common,
  725. &usb_phy3_clk.common,
  726. &bus_ohci0_clk.common,
  727. &bus_ohci1_clk.common,
  728. &bus_ohci2_clk.common,
  729. &bus_ohci3_clk.common,
  730. &bus_ehci0_clk.common,
  731. &bus_ehci1_clk.common,
  732. &bus_ehci2_clk.common,
  733. &bus_ehci3_clk.common,
  734. &bus_otg_clk.common,
  735. &bus_keyadc_clk.common,
  736. &hdmi_clk.common,
  737. &hdmi_slow_clk.common,
  738. &hdmi_cec_clk.common,
  739. &bus_hdmi_clk.common,
  740. &bus_tcon_top_clk.common,
  741. &tcon_tv0_clk.common,
  742. &tcon_tv1_clk.common,
  743. &bus_tcon_tv0_clk.common,
  744. &bus_tcon_tv1_clk.common,
  745. &tve0_clk.common,
  746. &bus_tve_top_clk.common,
  747. &bus_tve0_clk.common,
  748. &hdcp_clk.common,
  749. &bus_hdcp_clk.common,
  750. };
  751. static struct clk_hw_onecell_data sun50i_h616_hw_clks = {
  752. .hws = {
  753. [CLK_OSC12M] = &osc12M_clk.hw,
  754. [CLK_PLL_CPUX] = &pll_cpux_clk.common.hw,
  755. [CLK_PLL_DDR0] = &pll_ddr0_clk.common.hw,
  756. [CLK_PLL_DDR1] = &pll_ddr1_clk.common.hw,
  757. [CLK_PLL_PERIPH0] = &pll_periph0_clk.common.hw,
  758. [CLK_PLL_PERIPH0_2X] = &pll_periph0_2x_clk.hw,
  759. [CLK_PLL_SYSTEM_32K] = &pll_system_32k_clk.hw,
  760. [CLK_PLL_PERIPH1] = &pll_periph1_clk.common.hw,
  761. [CLK_PLL_PERIPH1_2X] = &pll_periph1_2x_clk.hw,
  762. [CLK_PLL_GPU] = &pll_gpu_clk.common.hw,
  763. [CLK_PLL_VIDEO0] = &pll_video0_clk.common.hw,
  764. [CLK_PLL_VIDEO0_4X] = &pll_video0_4x_clk.hw,
  765. [CLK_PLL_VIDEO1] = &pll_video1_clk.common.hw,
  766. [CLK_PLL_VIDEO1_4X] = &pll_video1_4x_clk.hw,
  767. [CLK_PLL_VIDEO2] = &pll_video2_clk.common.hw,
  768. [CLK_PLL_VIDEO2_4X] = &pll_video2_4x_clk.hw,
  769. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  770. [CLK_PLL_DE] = &pll_de_clk.common.hw,
  771. [CLK_PLL_AUDIO_HS] = &pll_audio_hs_clk.common.hw,
  772. [CLK_PLL_AUDIO_1X] = &pll_audio_1x_clk.hw,
  773. [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
  774. [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
  775. [CLK_CPUX] = &cpux_clk.common.hw,
  776. [CLK_AXI] = &axi_clk.common.hw,
  777. [CLK_CPUX_APB] = &cpux_apb_clk.common.hw,
  778. [CLK_PSI_AHB1_AHB2] = &psi_ahb1_ahb2_clk.common.hw,
  779. [CLK_AHB3] = &ahb3_clk.common.hw,
  780. [CLK_APB1] = &apb1_clk.common.hw,
  781. [CLK_APB2] = &apb2_clk.common.hw,
  782. [CLK_MBUS] = &mbus_clk.common.hw,
  783. [CLK_DE] = &de_clk.common.hw,
  784. [CLK_BUS_DE] = &bus_de_clk.common.hw,
  785. [CLK_DEINTERLACE] = &deinterlace_clk.common.hw,
  786. [CLK_BUS_DEINTERLACE] = &bus_deinterlace_clk.common.hw,
  787. [CLK_G2D] = &g2d_clk.common.hw,
  788. [CLK_BUS_G2D] = &bus_g2d_clk.common.hw,
  789. [CLK_GPU0] = &gpu0_clk.common.hw,
  790. [CLK_BUS_GPU] = &bus_gpu_clk.common.hw,
  791. [CLK_GPU1] = &gpu1_clk.common.hw,
  792. [CLK_CE] = &ce_clk.common.hw,
  793. [CLK_BUS_CE] = &bus_ce_clk.common.hw,
  794. [CLK_VE] = &ve_clk.common.hw,
  795. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  796. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  797. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  798. [CLK_AVS] = &avs_clk.common.hw,
  799. [CLK_BUS_DBG] = &bus_dbg_clk.common.hw,
  800. [CLK_BUS_PSI] = &bus_psi_clk.common.hw,
  801. [CLK_BUS_PWM] = &bus_pwm_clk.common.hw,
  802. [CLK_BUS_IOMMU] = &bus_iommu_clk.common.hw,
  803. [CLK_DRAM] = &dram_clk.common.hw,
  804. [CLK_MBUS_DMA] = &mbus_dma_clk.common.hw,
  805. [CLK_MBUS_VE] = &mbus_ve_clk.common.hw,
  806. [CLK_MBUS_CE] = &mbus_ce_clk.common.hw,
  807. [CLK_MBUS_TS] = &mbus_ts_clk.common.hw,
  808. [CLK_MBUS_NAND] = &mbus_nand_clk.common.hw,
  809. [CLK_MBUS_G2D] = &mbus_g2d_clk.common.hw,
  810. [CLK_BUS_DRAM] = &bus_dram_clk.common.hw,
  811. [CLK_NAND0] = &nand0_clk.common.hw,
  812. [CLK_NAND1] = &nand1_clk.common.hw,
  813. [CLK_BUS_NAND] = &bus_nand_clk.common.hw,
  814. [CLK_MMC0] = &mmc0_clk.common.hw,
  815. [CLK_MMC1] = &mmc1_clk.common.hw,
  816. [CLK_MMC2] = &mmc2_clk.common.hw,
  817. [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw,
  818. [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw,
  819. [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw,
  820. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  821. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  822. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  823. [CLK_BUS_UART3] = &bus_uart3_clk.common.hw,
  824. [CLK_BUS_UART4] = &bus_uart4_clk.common.hw,
  825. [CLK_BUS_UART5] = &bus_uart5_clk.common.hw,
  826. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  827. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  828. [CLK_BUS_I2C2] = &bus_i2c2_clk.common.hw,
  829. [CLK_BUS_I2C3] = &bus_i2c3_clk.common.hw,
  830. [CLK_BUS_I2C4] = &bus_i2c4_clk.common.hw,
  831. [CLK_SPI0] = &spi0_clk.common.hw,
  832. [CLK_SPI1] = &spi1_clk.common.hw,
  833. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  834. [CLK_BUS_SPI1] = &bus_spi1_clk.common.hw,
  835. [CLK_EMAC_25M] = &emac_25m_clk.common.hw,
  836. [CLK_BUS_EMAC0] = &bus_emac0_clk.common.hw,
  837. [CLK_BUS_EMAC1] = &bus_emac1_clk.common.hw,
  838. [CLK_TS] = &ts_clk.common.hw,
  839. [CLK_BUS_TS] = &bus_ts_clk.common.hw,
  840. [CLK_BUS_THS] = &bus_ths_clk.common.hw,
  841. [CLK_SPDIF] = &spdif_clk.common.hw,
  842. [CLK_BUS_SPDIF] = &bus_spdif_clk.common.hw,
  843. [CLK_DMIC] = &dmic_clk.common.hw,
  844. [CLK_BUS_DMIC] = &bus_dmic_clk.common.hw,
  845. [CLK_AUDIO_CODEC_1X] = &audio_codec_1x_clk.common.hw,
  846. [CLK_AUDIO_CODEC_4X] = &audio_codec_4x_clk.common.hw,
  847. [CLK_BUS_AUDIO_CODEC] = &bus_audio_codec_clk.common.hw,
  848. [CLK_AUDIO_HUB] = &audio_hub_clk.common.hw,
  849. [CLK_BUS_AUDIO_HUB] = &bus_audio_hub_clk.common.hw,
  850. [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
  851. [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
  852. [CLK_USB_OHCI1] = &usb_ohci1_clk.common.hw,
  853. [CLK_USB_PHY1] = &usb_phy1_clk.common.hw,
  854. [CLK_USB_OHCI2] = &usb_ohci2_clk.common.hw,
  855. [CLK_USB_PHY2] = &usb_phy2_clk.common.hw,
  856. [CLK_USB_OHCI3] = &usb_ohci3_clk.common.hw,
  857. [CLK_USB_PHY3] = &usb_phy3_clk.common.hw,
  858. [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw,
  859. [CLK_BUS_OHCI1] = &bus_ohci1_clk.common.hw,
  860. [CLK_BUS_OHCI2] = &bus_ohci2_clk.common.hw,
  861. [CLK_BUS_OHCI3] = &bus_ohci3_clk.common.hw,
  862. [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw,
  863. [CLK_BUS_EHCI1] = &bus_ehci1_clk.common.hw,
  864. [CLK_BUS_EHCI2] = &bus_ehci2_clk.common.hw,
  865. [CLK_BUS_EHCI3] = &bus_ehci3_clk.common.hw,
  866. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  867. [CLK_BUS_KEYADC] = &bus_keyadc_clk.common.hw,
  868. [CLK_HDMI] = &hdmi_clk.common.hw,
  869. [CLK_HDMI_SLOW] = &hdmi_slow_clk.common.hw,
  870. [CLK_HDMI_CEC] = &hdmi_cec_clk.common.hw,
  871. [CLK_BUS_HDMI] = &bus_hdmi_clk.common.hw,
  872. [CLK_BUS_TCON_TOP] = &bus_tcon_top_clk.common.hw,
  873. [CLK_TCON_TV0] = &tcon_tv0_clk.common.hw,
  874. [CLK_TCON_TV1] = &tcon_tv1_clk.common.hw,
  875. [CLK_BUS_TCON_TV0] = &bus_tcon_tv0_clk.common.hw,
  876. [CLK_BUS_TCON_TV1] = &bus_tcon_tv1_clk.common.hw,
  877. [CLK_TVE0] = &tve0_clk.common.hw,
  878. [CLK_BUS_TVE_TOP] = &bus_tve_top_clk.common.hw,
  879. [CLK_BUS_TVE0] = &bus_tve0_clk.common.hw,
  880. [CLK_HDCP] = &hdcp_clk.common.hw,
  881. [CLK_BUS_HDCP] = &bus_hdcp_clk.common.hw,
  882. },
  883. .num = CLK_NUMBER,
  884. };
  885. static struct ccu_reset_map sun50i_h616_ccu_resets[] = {
  886. [RST_MBUS] = { 0x540, BIT(30) },
  887. [RST_BUS_DE] = { 0x60c, BIT(16) },
  888. [RST_BUS_DEINTERLACE] = { 0x62c, BIT(16) },
  889. [RST_BUS_GPU] = { 0x67c, BIT(16) },
  890. [RST_BUS_CE] = { 0x68c, BIT(16) },
  891. [RST_BUS_VE] = { 0x69c, BIT(16) },
  892. [RST_BUS_DMA] = { 0x70c, BIT(16) },
  893. [RST_BUS_HSTIMER] = { 0x73c, BIT(16) },
  894. [RST_BUS_DBG] = { 0x78c, BIT(16) },
  895. [RST_BUS_PSI] = { 0x79c, BIT(16) },
  896. [RST_BUS_PWM] = { 0x7ac, BIT(16) },
  897. [RST_BUS_IOMMU] = { 0x7bc, BIT(16) },
  898. [RST_BUS_DRAM] = { 0x80c, BIT(16) },
  899. [RST_BUS_NAND] = { 0x82c, BIT(16) },
  900. [RST_BUS_MMC0] = { 0x84c, BIT(16) },
  901. [RST_BUS_MMC1] = { 0x84c, BIT(17) },
  902. [RST_BUS_MMC2] = { 0x84c, BIT(18) },
  903. [RST_BUS_UART0] = { 0x90c, BIT(16) },
  904. [RST_BUS_UART1] = { 0x90c, BIT(17) },
  905. [RST_BUS_UART2] = { 0x90c, BIT(18) },
  906. [RST_BUS_UART3] = { 0x90c, BIT(19) },
  907. [RST_BUS_UART4] = { 0x90c, BIT(20) },
  908. [RST_BUS_UART5] = { 0x90c, BIT(21) },
  909. [RST_BUS_I2C0] = { 0x91c, BIT(16) },
  910. [RST_BUS_I2C1] = { 0x91c, BIT(17) },
  911. [RST_BUS_I2C2] = { 0x91c, BIT(18) },
  912. [RST_BUS_I2C3] = { 0x91c, BIT(19) },
  913. [RST_BUS_I2C4] = { 0x91c, BIT(20) },
  914. [RST_BUS_SPI0] = { 0x96c, BIT(16) },
  915. [RST_BUS_SPI1] = { 0x96c, BIT(17) },
  916. [RST_BUS_EMAC0] = { 0x97c, BIT(16) },
  917. [RST_BUS_EMAC1] = { 0x97c, BIT(17) },
  918. [RST_BUS_TS] = { 0x9bc, BIT(16) },
  919. [RST_BUS_THS] = { 0x9fc, BIT(16) },
  920. [RST_BUS_SPDIF] = { 0xa2c, BIT(16) },
  921. [RST_BUS_DMIC] = { 0xa4c, BIT(16) },
  922. [RST_BUS_AUDIO_CODEC] = { 0xa5c, BIT(16) },
  923. [RST_BUS_AUDIO_HUB] = { 0xa6c, BIT(16) },
  924. [RST_USB_PHY0] = { 0xa70, BIT(30) },
  925. [RST_USB_PHY1] = { 0xa74, BIT(30) },
  926. [RST_USB_PHY2] = { 0xa78, BIT(30) },
  927. [RST_USB_PHY3] = { 0xa7c, BIT(30) },
  928. [RST_BUS_OHCI0] = { 0xa8c, BIT(16) },
  929. [RST_BUS_OHCI1] = { 0xa8c, BIT(17) },
  930. [RST_BUS_OHCI2] = { 0xa8c, BIT(18) },
  931. [RST_BUS_OHCI3] = { 0xa8c, BIT(19) },
  932. [RST_BUS_EHCI0] = { 0xa8c, BIT(20) },
  933. [RST_BUS_EHCI1] = { 0xa8c, BIT(21) },
  934. [RST_BUS_EHCI2] = { 0xa8c, BIT(22) },
  935. [RST_BUS_EHCI3] = { 0xa8c, BIT(23) },
  936. [RST_BUS_OTG] = { 0xa8c, BIT(24) },
  937. [RST_BUS_KEYADC] = { 0xa9c, BIT(16) },
  938. [RST_BUS_HDMI] = { 0xb1c, BIT(16) },
  939. [RST_BUS_HDMI_SUB] = { 0xb1c, BIT(17) },
  940. [RST_BUS_TCON_TOP] = { 0xb5c, BIT(16) },
  941. [RST_BUS_TCON_TV0] = { 0xb9c, BIT(16) },
  942. [RST_BUS_TCON_TV1] = { 0xb9c, BIT(17) },
  943. [RST_BUS_TVE_TOP] = { 0xbbc, BIT(16) },
  944. [RST_BUS_TVE0] = { 0xbbc, BIT(17) },
  945. [RST_BUS_HDCP] = { 0xc4c, BIT(16) },
  946. };
  947. static const struct sunxi_ccu_desc sun50i_h616_ccu_desc = {
  948. .ccu_clks = sun50i_h616_ccu_clks,
  949. .num_ccu_clks = ARRAY_SIZE(sun50i_h616_ccu_clks),
  950. .hw_clks = &sun50i_h616_hw_clks,
  951. .resets = sun50i_h616_ccu_resets,
  952. .num_resets = ARRAY_SIZE(sun50i_h616_ccu_resets),
  953. };
  954. static const u32 pll_regs[] = {
  955. SUN50I_H616_PLL_CPUX_REG,
  956. SUN50I_H616_PLL_DDR0_REG,
  957. SUN50I_H616_PLL_DDR1_REG,
  958. SUN50I_H616_PLL_PERIPH0_REG,
  959. SUN50I_H616_PLL_PERIPH1_REG,
  960. SUN50I_H616_PLL_GPU_REG,
  961. SUN50I_H616_PLL_VIDEO0_REG,
  962. SUN50I_H616_PLL_VIDEO1_REG,
  963. SUN50I_H616_PLL_VIDEO2_REG,
  964. SUN50I_H616_PLL_VE_REG,
  965. SUN50I_H616_PLL_DE_REG,
  966. SUN50I_H616_PLL_AUDIO_REG,
  967. };
  968. static const u32 pll_video_regs[] = {
  969. SUN50I_H616_PLL_VIDEO0_REG,
  970. SUN50I_H616_PLL_VIDEO1_REG,
  971. SUN50I_H616_PLL_VIDEO2_REG,
  972. };
  973. static const u32 usb2_clk_regs[] = {
  974. SUN50I_H616_USB0_CLK_REG,
  975. SUN50I_H616_USB1_CLK_REG,
  976. SUN50I_H616_USB2_CLK_REG,
  977. SUN50I_H616_USB3_CLK_REG,
  978. };
  979. static int sun50i_h616_ccu_probe(struct platform_device *pdev)
  980. {
  981. void __iomem *reg;
  982. u32 val;
  983. int i;
  984. reg = devm_platform_ioremap_resource(pdev, 0);
  985. if (IS_ERR(reg))
  986. return PTR_ERR(reg);
  987. /* Enable the lock bits and the output enable bits on all PLLs */
  988. for (i = 0; i < ARRAY_SIZE(pll_regs); i++) {
  989. val = readl(reg + pll_regs[i]);
  990. val |= BIT(29) | BIT(27);
  991. writel(val, reg + pll_regs[i]);
  992. }
  993. /*
  994. * Force the output divider of video PLLs to 0.
  995. *
  996. * See the comment before pll-video0 definition for the reason.
  997. */
  998. for (i = 0; i < ARRAY_SIZE(pll_video_regs); i++) {
  999. val = readl(reg + pll_video_regs[i]);
  1000. val &= ~BIT(0);
  1001. writel(val, reg + pll_video_regs[i]);
  1002. }
  1003. /*
  1004. * Force OHCI 12M clock sources to 00 (12MHz divided from 48MHz)
  1005. *
  1006. * This clock mux is still mysterious, and the code just enforces
  1007. * it to have a valid clock parent.
  1008. */
  1009. for (i = 0; i < ARRAY_SIZE(usb2_clk_regs); i++) {
  1010. val = readl(reg + usb2_clk_regs[i]);
  1011. val &= ~GENMASK(25, 24);
  1012. writel(val, reg + usb2_clk_regs[i]);
  1013. }
  1014. /*
  1015. * Force the post-divider of pll-audio to 12 and the output divider
  1016. * of it to 2, so 24576000 and 22579200 rates can be set exactly.
  1017. */
  1018. val = readl(reg + SUN50I_H616_PLL_AUDIO_REG);
  1019. val &= ~(GENMASK(21, 16) | BIT(0));
  1020. writel(val | (11 << 16) | BIT(0), reg + SUN50I_H616_PLL_AUDIO_REG);
  1021. /*
  1022. * First clock parent (osc32K) is unusable for CEC. But since there
  1023. * is no good way to force parent switch (both run with same frequency),
  1024. * just set second clock parent here.
  1025. */
  1026. val = readl(reg + SUN50I_H616_HDMI_CEC_CLK_REG);
  1027. val |= BIT(24);
  1028. writel(val, reg + SUN50I_H616_HDMI_CEC_CLK_REG);
  1029. return devm_sunxi_ccu_probe(&pdev->dev, reg, &sun50i_h616_ccu_desc);
  1030. }
  1031. static const struct of_device_id sun50i_h616_ccu_ids[] = {
  1032. { .compatible = "allwinner,sun50i-h616-ccu" },
  1033. { }
  1034. };
  1035. static struct platform_driver sun50i_h616_ccu_driver = {
  1036. .probe = sun50i_h616_ccu_probe,
  1037. .driver = {
  1038. .name = "sun50i-h616-ccu",
  1039. .suppress_bind_attrs = true,
  1040. .of_match_table = sun50i_h616_ccu_ids,
  1041. },
  1042. };
  1043. module_platform_driver(sun50i_h616_ccu_driver);
  1044. MODULE_IMPORT_NS(SUNXI_CCU);
  1045. MODULE_LICENSE("GPL");