ccu-sun9i-a80.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. /*
  2. * Copyright (c) 2016 Chen-Yu Tsai. All rights reserved.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/clk-provider.h>
  14. #include <linux/of_address.h>
  15. #include <linux/platform_device.h>
  16. #include "ccu_common.h"
  17. #include "ccu_reset.h"
  18. #include "ccu_div.h"
  19. #include "ccu_gate.h"
  20. #include "ccu_mp.h"
  21. #include "ccu_nkmp.h"
  22. #include "ccu_nm.h"
  23. #include "ccu_phase.h"
  24. #include "ccu-sun9i-a80.h"
  25. #define CCU_SUN9I_LOCK_REG 0x09c
  26. /*
  27. * The CPU PLLs are actually NP clocks, with P being /1 or /4. However
  28. * P should only be used for output frequencies lower than 228 MHz.
  29. * Neither mainline Linux, U-boot, nor the vendor BSPs use these.
  30. *
  31. * For now we can just model it as a multiplier clock, and force P to /1.
  32. */
  33. #define SUN9I_A80_PLL_C0CPUX_REG 0x000
  34. #define SUN9I_A80_PLL_C1CPUX_REG 0x004
  35. static struct ccu_mult pll_c0cpux_clk = {
  36. .enable = BIT(31),
  37. .lock = BIT(0),
  38. .mult = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  39. .common = {
  40. .reg = SUN9I_A80_PLL_C0CPUX_REG,
  41. .lock_reg = CCU_SUN9I_LOCK_REG,
  42. .features = CCU_FEATURE_LOCK_REG,
  43. .hw.init = CLK_HW_INIT("pll-c0cpux", "osc24M",
  44. &ccu_mult_ops,
  45. CLK_SET_RATE_UNGATE),
  46. },
  47. };
  48. static struct ccu_mult pll_c1cpux_clk = {
  49. .enable = BIT(31),
  50. .lock = BIT(1),
  51. .mult = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  52. .common = {
  53. .reg = SUN9I_A80_PLL_C1CPUX_REG,
  54. .lock_reg = CCU_SUN9I_LOCK_REG,
  55. .features = CCU_FEATURE_LOCK_REG,
  56. .hw.init = CLK_HW_INIT("pll-c1cpux", "osc24M",
  57. &ccu_mult_ops,
  58. CLK_SET_RATE_UNGATE),
  59. },
  60. };
  61. /*
  62. * The Audio PLL has d1, d2 dividers in addition to the usual N, M
  63. * factors. Since we only need 2 frequencies from this PLL: 22.5792 MHz
  64. * and 24.576 MHz, ignore them for now. Enforce d1 = 0 and d2 = 0.
  65. */
  66. #define SUN9I_A80_PLL_AUDIO_REG 0x008
  67. static struct ccu_nm pll_audio_clk = {
  68. .enable = BIT(31),
  69. .lock = BIT(2),
  70. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  71. .m = _SUNXI_CCU_DIV_OFFSET(0, 6, 0),
  72. .common = {
  73. .reg = 0x008,
  74. .lock_reg = CCU_SUN9I_LOCK_REG,
  75. .features = CCU_FEATURE_LOCK_REG,
  76. .hw.init = CLK_HW_INIT("pll-audio", "osc24M",
  77. &ccu_nm_ops, CLK_SET_RATE_UNGATE),
  78. },
  79. };
  80. /* Some PLLs are input * N / div1 / div2. Model them as NKMP with no K */
  81. static struct ccu_nkmp pll_periph0_clk = {
  82. .enable = BIT(31),
  83. .lock = BIT(3),
  84. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  85. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  86. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  87. .common = {
  88. .reg = 0x00c,
  89. .lock_reg = CCU_SUN9I_LOCK_REG,
  90. .features = CCU_FEATURE_LOCK_REG,
  91. .hw.init = CLK_HW_INIT("pll-periph0", "osc24M",
  92. &ccu_nkmp_ops,
  93. CLK_SET_RATE_UNGATE),
  94. },
  95. };
  96. static struct ccu_nkmp pll_ve_clk = {
  97. .enable = BIT(31),
  98. .lock = BIT(4),
  99. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  100. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  101. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  102. .common = {
  103. .reg = 0x010,
  104. .lock_reg = CCU_SUN9I_LOCK_REG,
  105. .features = CCU_FEATURE_LOCK_REG,
  106. .hw.init = CLK_HW_INIT("pll-ve", "osc24M",
  107. &ccu_nkmp_ops,
  108. CLK_SET_RATE_UNGATE),
  109. },
  110. };
  111. static struct ccu_nkmp pll_ddr_clk = {
  112. .enable = BIT(31),
  113. .lock = BIT(5),
  114. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  115. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  116. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  117. .common = {
  118. .reg = 0x014,
  119. .lock_reg = CCU_SUN9I_LOCK_REG,
  120. .features = CCU_FEATURE_LOCK_REG,
  121. .hw.init = CLK_HW_INIT("pll-ddr", "osc24M",
  122. &ccu_nkmp_ops,
  123. CLK_SET_RATE_UNGATE),
  124. },
  125. };
  126. static struct ccu_nm pll_video0_clk = {
  127. .enable = BIT(31),
  128. .lock = BIT(6),
  129. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  130. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  131. .common = {
  132. .reg = 0x018,
  133. .lock_reg = CCU_SUN9I_LOCK_REG,
  134. .features = CCU_FEATURE_LOCK_REG,
  135. .hw.init = CLK_HW_INIT("pll-video0", "osc24M",
  136. &ccu_nm_ops,
  137. CLK_SET_RATE_UNGATE),
  138. },
  139. };
  140. static struct ccu_nkmp pll_video1_clk = {
  141. .enable = BIT(31),
  142. .lock = BIT(7),
  143. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  144. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  145. .p = _SUNXI_CCU_DIV(0, 2), /* external divider p */
  146. .common = {
  147. .reg = 0x01c,
  148. .lock_reg = CCU_SUN9I_LOCK_REG,
  149. .features = CCU_FEATURE_LOCK_REG,
  150. .hw.init = CLK_HW_INIT("pll-video1", "osc24M",
  151. &ccu_nkmp_ops,
  152. CLK_SET_RATE_UNGATE),
  153. },
  154. };
  155. static struct ccu_nkmp pll_gpu_clk = {
  156. .enable = BIT(31),
  157. .lock = BIT(8),
  158. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  159. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  160. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  161. .common = {
  162. .reg = 0x020,
  163. .lock_reg = CCU_SUN9I_LOCK_REG,
  164. .features = CCU_FEATURE_LOCK_REG,
  165. .hw.init = CLK_HW_INIT("pll-gpu", "osc24M",
  166. &ccu_nkmp_ops,
  167. CLK_SET_RATE_UNGATE),
  168. },
  169. };
  170. static struct ccu_nkmp pll_de_clk = {
  171. .enable = BIT(31),
  172. .lock = BIT(9),
  173. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  174. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  175. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  176. .common = {
  177. .reg = 0x024,
  178. .lock_reg = CCU_SUN9I_LOCK_REG,
  179. .features = CCU_FEATURE_LOCK_REG,
  180. .hw.init = CLK_HW_INIT("pll-de", "osc24M",
  181. &ccu_nkmp_ops,
  182. CLK_SET_RATE_UNGATE),
  183. },
  184. };
  185. static struct ccu_nkmp pll_isp_clk = {
  186. .enable = BIT(31),
  187. .lock = BIT(10),
  188. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  189. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  190. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  191. .common = {
  192. .reg = 0x028,
  193. .lock_reg = CCU_SUN9I_LOCK_REG,
  194. .features = CCU_FEATURE_LOCK_REG,
  195. .hw.init = CLK_HW_INIT("pll-isp", "osc24M",
  196. &ccu_nkmp_ops,
  197. CLK_SET_RATE_UNGATE),
  198. },
  199. };
  200. static struct ccu_nkmp pll_periph1_clk = {
  201. .enable = BIT(31),
  202. .lock = BIT(11),
  203. .n = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(8, 8, 0, 12, 0),
  204. .m = _SUNXI_CCU_DIV(16, 1), /* input divider */
  205. .p = _SUNXI_CCU_DIV(18, 1), /* output divider */
  206. .common = {
  207. .reg = 0x028,
  208. .lock_reg = CCU_SUN9I_LOCK_REG,
  209. .features = CCU_FEATURE_LOCK_REG,
  210. .hw.init = CLK_HW_INIT("pll-periph1", "osc24M",
  211. &ccu_nkmp_ops,
  212. CLK_SET_RATE_UNGATE),
  213. },
  214. };
  215. static const char * const c0cpux_parents[] = { "osc24M", "pll-c0cpux" };
  216. static SUNXI_CCU_MUX(c0cpux_clk, "c0cpux", c0cpux_parents,
  217. 0x50, 0, 1, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
  218. static const char * const c1cpux_parents[] = { "osc24M", "pll-c1cpux" };
  219. static SUNXI_CCU_MUX(c1cpux_clk, "c1cpux", c1cpux_parents,
  220. 0x50, 8, 1, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
  221. static struct clk_div_table axi_div_table[] = {
  222. { .val = 0, .div = 1 },
  223. { .val = 1, .div = 2 },
  224. { .val = 2, .div = 3 },
  225. { .val = 3, .div = 4 },
  226. { .val = 4, .div = 4 },
  227. { .val = 5, .div = 4 },
  228. { .val = 6, .div = 4 },
  229. { .val = 7, .div = 4 },
  230. { /* Sentinel */ },
  231. };
  232. static SUNXI_CCU_M(atb0_clk, "atb0", "c0cpux", 0x054, 8, 2, 0);
  233. static SUNXI_CCU_DIV_TABLE(axi0_clk, "axi0", "c0cpux",
  234. 0x054, 0, 3, axi_div_table, 0);
  235. static SUNXI_CCU_M(atb1_clk, "atb1", "c1cpux", 0x058, 8, 2, 0);
  236. static SUNXI_CCU_DIV_TABLE(axi1_clk, "axi1", "c1cpux",
  237. 0x058, 0, 3, axi_div_table, 0);
  238. static const char * const gtbus_parents[] = { "osc24M", "pll-periph0",
  239. "pll-periph1", "pll-periph1" };
  240. static SUNXI_CCU_M_WITH_MUX(gtbus_clk, "gtbus", gtbus_parents,
  241. 0x05c, 0, 2, 24, 2, CLK_IS_CRITICAL);
  242. static const char * const ahb_parents[] = { "gtbus", "pll-periph0",
  243. "pll-periph1", "pll-periph1" };
  244. static struct ccu_div ahb0_clk = {
  245. .div = _SUNXI_CCU_DIV_FLAGS(0, 2, CLK_DIVIDER_POWER_OF_TWO),
  246. .mux = _SUNXI_CCU_MUX(24, 2),
  247. .common = {
  248. .reg = 0x060,
  249. .hw.init = CLK_HW_INIT_PARENTS("ahb0",
  250. ahb_parents,
  251. &ccu_div_ops,
  252. 0),
  253. },
  254. };
  255. static struct ccu_div ahb1_clk = {
  256. .div = _SUNXI_CCU_DIV_FLAGS(0, 2, CLK_DIVIDER_POWER_OF_TWO),
  257. .mux = _SUNXI_CCU_MUX(24, 2),
  258. .common = {
  259. .reg = 0x064,
  260. .hw.init = CLK_HW_INIT_PARENTS("ahb1",
  261. ahb_parents,
  262. &ccu_div_ops,
  263. 0),
  264. },
  265. };
  266. static struct ccu_div ahb2_clk = {
  267. .div = _SUNXI_CCU_DIV_FLAGS(0, 2, CLK_DIVIDER_POWER_OF_TWO),
  268. .mux = _SUNXI_CCU_MUX(24, 2),
  269. .common = {
  270. .reg = 0x068,
  271. .hw.init = CLK_HW_INIT_PARENTS("ahb2",
  272. ahb_parents,
  273. &ccu_div_ops,
  274. 0),
  275. },
  276. };
  277. static const char * const apb_parents[] = { "osc24M", "pll-periph0" };
  278. static struct ccu_div apb0_clk = {
  279. .div = _SUNXI_CCU_DIV_FLAGS(0, 2, CLK_DIVIDER_POWER_OF_TWO),
  280. .mux = _SUNXI_CCU_MUX(24, 1),
  281. .common = {
  282. .reg = 0x070,
  283. .hw.init = CLK_HW_INIT_PARENTS("apb0",
  284. apb_parents,
  285. &ccu_div_ops,
  286. 0),
  287. },
  288. };
  289. static struct ccu_div apb1_clk = {
  290. .div = _SUNXI_CCU_DIV_FLAGS(0, 2, CLK_DIVIDER_POWER_OF_TWO),
  291. .mux = _SUNXI_CCU_MUX(24, 1),
  292. .common = {
  293. .reg = 0x074,
  294. .hw.init = CLK_HW_INIT_PARENTS("apb1",
  295. apb_parents,
  296. &ccu_div_ops,
  297. 0),
  298. },
  299. };
  300. static struct ccu_div cci400_clk = {
  301. .div = _SUNXI_CCU_DIV_FLAGS(0, 2, CLK_DIVIDER_POWER_OF_TWO),
  302. .mux = _SUNXI_CCU_MUX(24, 2),
  303. .common = {
  304. .reg = 0x078,
  305. .hw.init = CLK_HW_INIT_PARENTS("cci400",
  306. ahb_parents,
  307. &ccu_div_ops,
  308. CLK_IS_CRITICAL),
  309. },
  310. };
  311. static SUNXI_CCU_M_WITH_MUX_GATE(ats_clk, "ats", apb_parents,
  312. 0x080, 0, 3, 24, 2, BIT(31), 0);
  313. static SUNXI_CCU_M_WITH_MUX_GATE(trace_clk, "trace", apb_parents,
  314. 0x084, 0, 3, 24, 2, BIT(31), 0);
  315. static const char * const out_parents[] = { "osc24M", "osc32k", "osc24M" };
  316. static const struct ccu_mux_fixed_prediv out_prediv = {
  317. .index = 0, .div = 750
  318. };
  319. static struct ccu_mp out_a_clk = {
  320. .enable = BIT(31),
  321. .m = _SUNXI_CCU_DIV(8, 5),
  322. .p = _SUNXI_CCU_DIV(20, 2),
  323. .mux = {
  324. .shift = 24,
  325. .width = 4,
  326. .fixed_predivs = &out_prediv,
  327. .n_predivs = 1,
  328. },
  329. .common = {
  330. .reg = 0x180,
  331. .features = CCU_FEATURE_FIXED_PREDIV,
  332. .hw.init = CLK_HW_INIT_PARENTS("out-a",
  333. out_parents,
  334. &ccu_mp_ops,
  335. 0),
  336. },
  337. };
  338. static struct ccu_mp out_b_clk = {
  339. .enable = BIT(31),
  340. .m = _SUNXI_CCU_DIV(8, 5),
  341. .p = _SUNXI_CCU_DIV(20, 2),
  342. .mux = {
  343. .shift = 24,
  344. .width = 4,
  345. .fixed_predivs = &out_prediv,
  346. .n_predivs = 1,
  347. },
  348. .common = {
  349. .reg = 0x184,
  350. .features = CCU_FEATURE_FIXED_PREDIV,
  351. .hw.init = CLK_HW_INIT_PARENTS("out-b",
  352. out_parents,
  353. &ccu_mp_ops,
  354. 0),
  355. },
  356. };
  357. static const char * const mod0_default_parents[] = { "osc24M", "pll-periph0" };
  358. static SUNXI_CCU_MP_WITH_MUX_GATE(nand0_0_clk, "nand0-0", mod0_default_parents,
  359. 0x400,
  360. 0, 4, /* M */
  361. 16, 2, /* P */
  362. 24, 4, /* mux */
  363. BIT(31), /* gate */
  364. 0);
  365. static SUNXI_CCU_MP_WITH_MUX_GATE(nand0_1_clk, "nand0-1", mod0_default_parents,
  366. 0x404,
  367. 0, 4, /* M */
  368. 16, 2, /* P */
  369. 24, 4, /* mux */
  370. BIT(31), /* gate */
  371. 0);
  372. static SUNXI_CCU_MP_WITH_MUX_GATE(nand1_0_clk, "nand1-0", mod0_default_parents,
  373. 0x408,
  374. 0, 4, /* M */
  375. 16, 2, /* P */
  376. 24, 4, /* mux */
  377. BIT(31), /* gate */
  378. 0);
  379. static SUNXI_CCU_MP_WITH_MUX_GATE(nand1_1_clk, "nand1-1", mod0_default_parents,
  380. 0x40c,
  381. 0, 4, /* M */
  382. 16, 2, /* P */
  383. 24, 4, /* mux */
  384. BIT(31), /* gate */
  385. 0);
  386. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents,
  387. 0x410,
  388. 0, 4, /* M */
  389. 16, 2, /* P */
  390. 24, 4, /* mux */
  391. BIT(31), /* gate */
  392. 0);
  393. static SUNXI_CCU_PHASE(mmc0_sample_clk, "mmc0-sample", "mmc0",
  394. 0x410, 20, 3, 0);
  395. static SUNXI_CCU_PHASE(mmc0_output_clk, "mmc0-output", "mmc0",
  396. 0x410, 8, 3, 0);
  397. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents,
  398. 0x414,
  399. 0, 4, /* M */
  400. 16, 2, /* P */
  401. 24, 4, /* mux */
  402. BIT(31), /* gate */
  403. 0);
  404. static SUNXI_CCU_PHASE(mmc1_sample_clk, "mmc1-sample", "mmc1",
  405. 0x414, 20, 3, 0);
  406. static SUNXI_CCU_PHASE(mmc1_output_clk, "mmc1-output", "mmc1",
  407. 0x414, 8, 3, 0);
  408. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents,
  409. 0x418,
  410. 0, 4, /* M */
  411. 16, 2, /* P */
  412. 24, 4, /* mux */
  413. BIT(31), /* gate */
  414. 0);
  415. static SUNXI_CCU_PHASE(mmc2_sample_clk, "mmc2-sample", "mmc2",
  416. 0x418, 20, 3, 0);
  417. static SUNXI_CCU_PHASE(mmc2_output_clk, "mmc2-output", "mmc2",
  418. 0x418, 8, 3, 0);
  419. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc3_clk, "mmc3", mod0_default_parents,
  420. 0x41c,
  421. 0, 4, /* M */
  422. 16, 2, /* P */
  423. 24, 4, /* mux */
  424. BIT(31), /* gate */
  425. 0);
  426. static SUNXI_CCU_PHASE(mmc3_sample_clk, "mmc3-sample", "mmc3",
  427. 0x41c, 20, 3, 0);
  428. static SUNXI_CCU_PHASE(mmc3_output_clk, "mmc3-output", "mmc3",
  429. 0x41c, 8, 3, 0);
  430. static SUNXI_CCU_MP_WITH_MUX_GATE(ts_clk, "ts", mod0_default_parents,
  431. 0x428,
  432. 0, 4, /* M */
  433. 16, 2, /* P */
  434. 24, 4, /* mux */
  435. BIT(31), /* gate */
  436. 0);
  437. static const char * const ss_parents[] = { "osc24M", "pll-periph",
  438. "pll-periph1" };
  439. static const u8 ss_table[] = { 0, 1, 13 };
  440. static struct ccu_mp ss_clk = {
  441. .enable = BIT(31),
  442. .m = _SUNXI_CCU_DIV(0, 4),
  443. .p = _SUNXI_CCU_DIV(16, 2),
  444. .mux = _SUNXI_CCU_MUX_TABLE(24, 4, ss_table),
  445. .common = {
  446. .reg = 0x42c,
  447. .hw.init = CLK_HW_INIT_PARENTS("ss",
  448. ss_parents,
  449. &ccu_mp_ops,
  450. 0),
  451. },
  452. };
  453. static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents,
  454. 0x430,
  455. 0, 4, /* M */
  456. 16, 2, /* P */
  457. 24, 4, /* mux */
  458. BIT(31), /* gate */
  459. 0);
  460. static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", mod0_default_parents,
  461. 0x434,
  462. 0, 4, /* M */
  463. 16, 2, /* P */
  464. 24, 4, /* mux */
  465. BIT(31), /* gate */
  466. 0);
  467. static SUNXI_CCU_MP_WITH_MUX_GATE(spi2_clk, "spi2", mod0_default_parents,
  468. 0x438,
  469. 0, 4, /* M */
  470. 16, 2, /* P */
  471. 24, 4, /* mux */
  472. BIT(31), /* gate */
  473. 0);
  474. static SUNXI_CCU_MP_WITH_MUX_GATE(spi3_clk, "spi3", mod0_default_parents,
  475. 0x43c,
  476. 0, 4, /* M */
  477. 16, 2, /* P */
  478. 24, 4, /* mux */
  479. BIT(31), /* gate */
  480. 0);
  481. static SUNXI_CCU_M_WITH_GATE(i2s0_clk, "i2s0", "pll-audio",
  482. 0x440, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  483. static SUNXI_CCU_M_WITH_GATE(i2s1_clk, "i2s1", "pll-audio",
  484. 0x444, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  485. static SUNXI_CCU_M_WITH_GATE(spdif_clk, "spdif", "pll-audio",
  486. 0x44c, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  487. static const char * const sdram_parents[] = { "pll-periph0", "pll-ddr" };
  488. static const u8 sdram_table[] = { 0, 3 };
  489. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(sdram_clk, "sdram",
  490. sdram_parents, sdram_table,
  491. 0x484,
  492. 8, 4, /* M */
  493. 12, 4, /* mux */
  494. 0, /* no gate */
  495. CLK_IS_CRITICAL);
  496. static SUNXI_CCU_M_WITH_GATE(de_clk, "de", "pll-de", 0x490,
  497. 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  498. static SUNXI_CCU_GATE(edp_clk, "edp", "osc24M", 0x494, BIT(31), 0);
  499. static const char * const mp_parents[] = { "pll-video1", "pll-gpu", "pll-de" };
  500. static const u8 mp_table[] = { 9, 10, 11 };
  501. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(mp_clk, "mp", mp_parents, mp_table,
  502. 0x498,
  503. 0, 4, /* M */
  504. 24, 4, /* mux */
  505. BIT(31), /* gate */
  506. 0);
  507. static const char * const display_parents[] = { "pll-video0", "pll-video1" };
  508. static const u8 display_table[] = { 8, 9 };
  509. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(lcd0_clk, "lcd0",
  510. display_parents, display_table,
  511. 0x49c,
  512. 0, 4, /* M */
  513. 24, 4, /* mux */
  514. BIT(31), /* gate */
  515. CLK_SET_RATE_NO_REPARENT |
  516. CLK_SET_RATE_PARENT);
  517. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(lcd1_clk, "lcd1",
  518. display_parents, display_table,
  519. 0x4a0,
  520. 0, 4, /* M */
  521. 24, 4, /* mux */
  522. BIT(31), /* gate */
  523. CLK_SET_RATE_NO_REPARENT |
  524. CLK_SET_RATE_PARENT);
  525. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(mipi_dsi0_clk, "mipi-dsi0",
  526. display_parents, display_table,
  527. 0x4a8,
  528. 0, 4, /* M */
  529. 24, 4, /* mux */
  530. BIT(31), /* gate */
  531. CLK_SET_RATE_PARENT);
  532. static const char * const mipi_dsi1_parents[] = { "osc24M", "pll-video1" };
  533. static const u8 mipi_dsi1_table[] = { 0, 9 };
  534. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(mipi_dsi1_clk, "mipi-dsi1",
  535. mipi_dsi1_parents, mipi_dsi1_table,
  536. 0x4ac,
  537. 0, 4, /* M */
  538. 24, 4, /* mux */
  539. BIT(31), /* gate */
  540. CLK_SET_RATE_PARENT);
  541. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(hdmi_clk, "hdmi",
  542. display_parents, display_table,
  543. 0x4b0,
  544. 0, 4, /* M */
  545. 24, 4, /* mux */
  546. BIT(31), /* gate */
  547. CLK_SET_RATE_NO_REPARENT |
  548. CLK_SET_RATE_PARENT);
  549. static SUNXI_CCU_GATE(hdmi_slow_clk, "hdmi-slow", "osc24M", 0x4b4, BIT(31), 0);
  550. static SUNXI_CCU_M_WITH_GATE(mipi_csi_clk, "mipi-csi", "osc24M", 0x4bc,
  551. 0, 4, BIT(31), 0);
  552. static SUNXI_CCU_M_WITH_GATE(csi_isp_clk, "csi-isp", "pll-isp", 0x4c0,
  553. 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  554. static SUNXI_CCU_GATE(csi_misc_clk, "csi-misc", "osc24M", 0x4c0, BIT(16), 0);
  555. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(csi0_mclk_clk, "csi0-mclk",
  556. mipi_dsi1_parents, mipi_dsi1_table,
  557. 0x4c4,
  558. 0, 4, /* M */
  559. 24, 4, /* mux */
  560. BIT(31), /* gate */
  561. CLK_SET_RATE_PARENT);
  562. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(csi1_mclk_clk, "csi1-mclk",
  563. mipi_dsi1_parents, mipi_dsi1_table,
  564. 0x4c8,
  565. 0, 4, /* M */
  566. 24, 4, /* mux */
  567. BIT(31), /* gate */
  568. CLK_SET_RATE_PARENT);
  569. static const char * const fd_parents[] = { "pll-periph0", "pll-isp" };
  570. static const u8 fd_table[] = { 1, 12 };
  571. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(fd_clk, "fd", fd_parents, fd_table,
  572. 0x4cc,
  573. 0, 4, /* M */
  574. 24, 4, /* mux */
  575. BIT(31), /* gate */
  576. 0);
  577. static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve", 0x4d0,
  578. 16, 3, BIT(31), CLK_SET_RATE_PARENT);
  579. static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M", 0x4d4, BIT(31), 0);
  580. static SUNXI_CCU_M_WITH_GATE(gpu_core_clk, "gpu-core", "pll-gpu", 0x4f0,
  581. 0, 3, BIT(31), CLK_SET_RATE_PARENT);
  582. static SUNXI_CCU_M_WITH_GATE(gpu_memory_clk, "gpu-memory", "pll-gpu", 0x4f4,
  583. 0, 3, BIT(31), CLK_SET_RATE_PARENT);
  584. static const char * const gpu_axi_parents[] = { "pll-periph0", "pll-gpu" };
  585. static const u8 gpu_axi_table[] = { 1, 10 };
  586. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(gpu_axi_clk, "gpu-axi",
  587. gpu_axi_parents, gpu_axi_table,
  588. 0x4f8,
  589. 0, 4, /* M */
  590. 24, 4, /* mux */
  591. BIT(31), /* gate */
  592. CLK_SET_RATE_PARENT);
  593. static SUNXI_CCU_M_WITH_GATE(sata_clk, "sata", "pll-periph0", 0x500,
  594. 0, 4, BIT(31), 0);
  595. static SUNXI_CCU_M_WITH_GATE(ac97_clk, "ac97", "pll-audio",
  596. 0x504, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
  597. static SUNXI_CCU_M_WITH_MUX_GATE(mipi_hsi_clk, "mipi-hsi",
  598. mod0_default_parents, 0x508,
  599. 0, 4, /* M */
  600. 24, 4, /* mux */
  601. BIT(31), /* gate */
  602. 0);
  603. static const char * const gpadc_parents[] = { "osc24M", "pll-audio", "osc32k" };
  604. static const u8 gpadc_table[] = { 0, 4, 7 };
  605. static struct ccu_mp gpadc_clk = {
  606. .enable = BIT(31),
  607. .m = _SUNXI_CCU_DIV(0, 4),
  608. .p = _SUNXI_CCU_DIV(16, 2),
  609. .mux = _SUNXI_CCU_MUX_TABLE(24, 4, gpadc_table),
  610. .common = {
  611. .reg = 0x50c,
  612. .hw.init = CLK_HW_INIT_PARENTS("gpadc",
  613. gpadc_parents,
  614. &ccu_mp_ops,
  615. 0),
  616. },
  617. };
  618. static const char * const cir_tx_parents[] = { "osc24M", "osc32k" };
  619. static const u8 cir_tx_table[] = { 0, 7 };
  620. static struct ccu_mp cir_tx_clk = {
  621. .enable = BIT(31),
  622. .m = _SUNXI_CCU_DIV(0, 4),
  623. .p = _SUNXI_CCU_DIV(16, 2),
  624. .mux = _SUNXI_CCU_MUX_TABLE(24, 4, cir_tx_table),
  625. .common = {
  626. .reg = 0x510,
  627. .hw.init = CLK_HW_INIT_PARENTS("cir-tx",
  628. cir_tx_parents,
  629. &ccu_mp_ops,
  630. 0),
  631. },
  632. };
  633. /* AHB0 bus gates */
  634. static SUNXI_CCU_GATE(bus_fd_clk, "bus-fd", "ahb0",
  635. 0x580, BIT(0), 0);
  636. static SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "ahb0",
  637. 0x580, BIT(1), 0);
  638. static SUNXI_CCU_GATE(bus_gpu_ctrl_clk, "bus-gpu-ctrl", "ahb0",
  639. 0x580, BIT(3), 0);
  640. static SUNXI_CCU_GATE(bus_ss_clk, "bus-ss", "ahb0",
  641. 0x580, BIT(5), 0);
  642. static SUNXI_CCU_GATE(bus_mmc_clk, "bus-mmc", "ahb0",
  643. 0x580, BIT(8), 0);
  644. static SUNXI_CCU_GATE(bus_nand0_clk, "bus-nand0", "ahb0",
  645. 0x580, BIT(12), 0);
  646. static SUNXI_CCU_GATE(bus_nand1_clk, "bus-nand1", "ahb0",
  647. 0x580, BIT(13), 0);
  648. static SUNXI_CCU_GATE(bus_sdram_clk, "bus-sdram", "ahb0",
  649. 0x580, BIT(14), 0);
  650. static SUNXI_CCU_GATE(bus_mipi_hsi_clk, "bus-mipi-hsi", "ahb0",
  651. 0x580, BIT(15), 0);
  652. static SUNXI_CCU_GATE(bus_sata_clk, "bus-sata", "ahb0",
  653. 0x580, BIT(16), 0);
  654. static SUNXI_CCU_GATE(bus_ts_clk, "bus-ts", "ahb0",
  655. 0x580, BIT(18), 0);
  656. static SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb0",
  657. 0x580, BIT(20), 0);
  658. static SUNXI_CCU_GATE(bus_spi1_clk, "bus-spi1", "ahb0",
  659. 0x580, BIT(21), 0);
  660. static SUNXI_CCU_GATE(bus_spi2_clk, "bus-spi2", "ahb0",
  661. 0x580, BIT(22), 0);
  662. static SUNXI_CCU_GATE(bus_spi3_clk, "bus-spi3", "ahb0",
  663. 0x580, BIT(23), 0);
  664. /* AHB1 bus gates */
  665. static SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb1",
  666. 0x584, BIT(0), 0);
  667. static SUNXI_CCU_GATE(bus_usb_clk, "bus-usb", "ahb1",
  668. 0x584, BIT(1), 0);
  669. static SUNXI_CCU_GATE(bus_gmac_clk, "bus-gmac", "ahb1",
  670. 0x584, BIT(17), 0);
  671. static SUNXI_CCU_GATE(bus_msgbox_clk, "bus-msgbox", "ahb1",
  672. 0x584, BIT(21), 0);
  673. static SUNXI_CCU_GATE(bus_spinlock_clk, "bus-spinlock", "ahb1",
  674. 0x584, BIT(22), 0);
  675. static SUNXI_CCU_GATE(bus_hstimer_clk, "bus-hstimer", "ahb1",
  676. 0x584, BIT(23), 0);
  677. static SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "ahb1",
  678. 0x584, BIT(24), 0);
  679. /* AHB2 bus gates */
  680. static SUNXI_CCU_GATE(bus_lcd0_clk, "bus-lcd0", "ahb2",
  681. 0x588, BIT(0), 0);
  682. static SUNXI_CCU_GATE(bus_lcd1_clk, "bus-lcd1", "ahb2",
  683. 0x588, BIT(1), 0);
  684. static SUNXI_CCU_GATE(bus_edp_clk, "bus-edp", "ahb2",
  685. 0x588, BIT(2), 0);
  686. static SUNXI_CCU_GATE(bus_csi_clk, "bus-csi", "ahb2",
  687. 0x588, BIT(4), 0);
  688. static SUNXI_CCU_GATE(bus_hdmi_clk, "bus-hdmi", "ahb2",
  689. 0x588, BIT(5), 0);
  690. static SUNXI_CCU_GATE(bus_de_clk, "bus-de", "ahb2",
  691. 0x588, BIT(7), 0);
  692. static SUNXI_CCU_GATE(bus_mp_clk, "bus-mp", "ahb2",
  693. 0x588, BIT(8), 0);
  694. static SUNXI_CCU_GATE(bus_mipi_dsi_clk, "bus-mipi-dsi", "ahb2",
  695. 0x588, BIT(11), 0);
  696. /* APB0 bus gates */
  697. static SUNXI_CCU_GATE(bus_spdif_clk, "bus-spdif", "apb0",
  698. 0x590, BIT(1), 0);
  699. static SUNXI_CCU_GATE(bus_pio_clk, "bus-pio", "apb0",
  700. 0x590, BIT(5), 0);
  701. static SUNXI_CCU_GATE(bus_ac97_clk, "bus-ac97", "apb0",
  702. 0x590, BIT(11), 0);
  703. static SUNXI_CCU_GATE(bus_i2s0_clk, "bus-i2s0", "apb0",
  704. 0x590, BIT(12), 0);
  705. static SUNXI_CCU_GATE(bus_i2s1_clk, "bus-i2s1", "apb0",
  706. 0x590, BIT(13), 0);
  707. static SUNXI_CCU_GATE(bus_lradc_clk, "bus-lradc", "apb0",
  708. 0x590, BIT(15), 0);
  709. static SUNXI_CCU_GATE(bus_gpadc_clk, "bus-gpadc", "apb0",
  710. 0x590, BIT(17), 0);
  711. static SUNXI_CCU_GATE(bus_twd_clk, "bus-twd", "apb0",
  712. 0x590, BIT(18), 0);
  713. static SUNXI_CCU_GATE(bus_cir_tx_clk, "bus-cir-tx", "apb0",
  714. 0x590, BIT(19), 0);
  715. /* APB1 bus gates */
  716. static SUNXI_CCU_GATE(bus_i2c0_clk, "bus-i2c0", "apb1",
  717. 0x594, BIT(0), 0);
  718. static SUNXI_CCU_GATE(bus_i2c1_clk, "bus-i2c1", "apb1",
  719. 0x594, BIT(1), 0);
  720. static SUNXI_CCU_GATE(bus_i2c2_clk, "bus-i2c2", "apb1",
  721. 0x594, BIT(2), 0);
  722. static SUNXI_CCU_GATE(bus_i2c3_clk, "bus-i2c3", "apb1",
  723. 0x594, BIT(3), 0);
  724. static SUNXI_CCU_GATE(bus_i2c4_clk, "bus-i2c4", "apb1",
  725. 0x594, BIT(4), 0);
  726. static SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb1",
  727. 0x594, BIT(16), 0);
  728. static SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb1",
  729. 0x594, BIT(17), 0);
  730. static SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb1",
  731. 0x594, BIT(18), 0);
  732. static SUNXI_CCU_GATE(bus_uart3_clk, "bus-uart3", "apb1",
  733. 0x594, BIT(19), 0);
  734. static SUNXI_CCU_GATE(bus_uart4_clk, "bus-uart4", "apb1",
  735. 0x594, BIT(20), 0);
  736. static SUNXI_CCU_GATE(bus_uart5_clk, "bus-uart5", "apb1",
  737. 0x594, BIT(21), 0);
  738. static struct ccu_common *sun9i_a80_ccu_clks[] = {
  739. &pll_c0cpux_clk.common,
  740. &pll_c1cpux_clk.common,
  741. &pll_audio_clk.common,
  742. &pll_periph0_clk.common,
  743. &pll_ve_clk.common,
  744. &pll_ddr_clk.common,
  745. &pll_video0_clk.common,
  746. &pll_video1_clk.common,
  747. &pll_gpu_clk.common,
  748. &pll_de_clk.common,
  749. &pll_isp_clk.common,
  750. &pll_periph1_clk.common,
  751. &c0cpux_clk.common,
  752. &c1cpux_clk.common,
  753. &atb0_clk.common,
  754. &axi0_clk.common,
  755. &atb1_clk.common,
  756. &axi1_clk.common,
  757. &gtbus_clk.common,
  758. &ahb0_clk.common,
  759. &ahb1_clk.common,
  760. &ahb2_clk.common,
  761. &apb0_clk.common,
  762. &apb1_clk.common,
  763. &cci400_clk.common,
  764. &ats_clk.common,
  765. &trace_clk.common,
  766. &out_a_clk.common,
  767. &out_b_clk.common,
  768. /* module clocks */
  769. &nand0_0_clk.common,
  770. &nand0_1_clk.common,
  771. &nand1_0_clk.common,
  772. &nand1_1_clk.common,
  773. &mmc0_clk.common,
  774. &mmc0_sample_clk.common,
  775. &mmc0_output_clk.common,
  776. &mmc1_clk.common,
  777. &mmc1_sample_clk.common,
  778. &mmc1_output_clk.common,
  779. &mmc2_clk.common,
  780. &mmc2_sample_clk.common,
  781. &mmc2_output_clk.common,
  782. &mmc3_clk.common,
  783. &mmc3_sample_clk.common,
  784. &mmc3_output_clk.common,
  785. &ts_clk.common,
  786. &ss_clk.common,
  787. &spi0_clk.common,
  788. &spi1_clk.common,
  789. &spi2_clk.common,
  790. &spi3_clk.common,
  791. &i2s0_clk.common,
  792. &i2s1_clk.common,
  793. &spdif_clk.common,
  794. &sdram_clk.common,
  795. &de_clk.common,
  796. &edp_clk.common,
  797. &mp_clk.common,
  798. &lcd0_clk.common,
  799. &lcd1_clk.common,
  800. &mipi_dsi0_clk.common,
  801. &mipi_dsi1_clk.common,
  802. &hdmi_clk.common,
  803. &hdmi_slow_clk.common,
  804. &mipi_csi_clk.common,
  805. &csi_isp_clk.common,
  806. &csi_misc_clk.common,
  807. &csi0_mclk_clk.common,
  808. &csi1_mclk_clk.common,
  809. &fd_clk.common,
  810. &ve_clk.common,
  811. &avs_clk.common,
  812. &gpu_core_clk.common,
  813. &gpu_memory_clk.common,
  814. &gpu_axi_clk.common,
  815. &sata_clk.common,
  816. &ac97_clk.common,
  817. &mipi_hsi_clk.common,
  818. &gpadc_clk.common,
  819. &cir_tx_clk.common,
  820. /* AHB0 bus gates */
  821. &bus_fd_clk.common,
  822. &bus_ve_clk.common,
  823. &bus_gpu_ctrl_clk.common,
  824. &bus_ss_clk.common,
  825. &bus_mmc_clk.common,
  826. &bus_nand0_clk.common,
  827. &bus_nand1_clk.common,
  828. &bus_sdram_clk.common,
  829. &bus_mipi_hsi_clk.common,
  830. &bus_sata_clk.common,
  831. &bus_ts_clk.common,
  832. &bus_spi0_clk.common,
  833. &bus_spi1_clk.common,
  834. &bus_spi2_clk.common,
  835. &bus_spi3_clk.common,
  836. /* AHB1 bus gates */
  837. &bus_otg_clk.common,
  838. &bus_usb_clk.common,
  839. &bus_gmac_clk.common,
  840. &bus_msgbox_clk.common,
  841. &bus_spinlock_clk.common,
  842. &bus_hstimer_clk.common,
  843. &bus_dma_clk.common,
  844. /* AHB2 bus gates */
  845. &bus_lcd0_clk.common,
  846. &bus_lcd1_clk.common,
  847. &bus_edp_clk.common,
  848. &bus_csi_clk.common,
  849. &bus_hdmi_clk.common,
  850. &bus_de_clk.common,
  851. &bus_mp_clk.common,
  852. &bus_mipi_dsi_clk.common,
  853. /* APB0 bus gates */
  854. &bus_spdif_clk.common,
  855. &bus_pio_clk.common,
  856. &bus_ac97_clk.common,
  857. &bus_i2s0_clk.common,
  858. &bus_i2s1_clk.common,
  859. &bus_lradc_clk.common,
  860. &bus_gpadc_clk.common,
  861. &bus_twd_clk.common,
  862. &bus_cir_tx_clk.common,
  863. /* APB1 bus gates */
  864. &bus_i2c0_clk.common,
  865. &bus_i2c1_clk.common,
  866. &bus_i2c2_clk.common,
  867. &bus_i2c3_clk.common,
  868. &bus_i2c4_clk.common,
  869. &bus_uart0_clk.common,
  870. &bus_uart1_clk.common,
  871. &bus_uart2_clk.common,
  872. &bus_uart3_clk.common,
  873. &bus_uart4_clk.common,
  874. &bus_uart5_clk.common,
  875. };
  876. static struct clk_hw_onecell_data sun9i_a80_hw_clks = {
  877. .hws = {
  878. [CLK_PLL_C0CPUX] = &pll_c0cpux_clk.common.hw,
  879. [CLK_PLL_C1CPUX] = &pll_c1cpux_clk.common.hw,
  880. [CLK_PLL_AUDIO] = &pll_audio_clk.common.hw,
  881. [CLK_PLL_PERIPH0] = &pll_periph0_clk.common.hw,
  882. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  883. [CLK_PLL_DDR] = &pll_ddr_clk.common.hw,
  884. [CLK_PLL_VIDEO0] = &pll_video0_clk.common.hw,
  885. [CLK_PLL_VIDEO1] = &pll_video1_clk.common.hw,
  886. [CLK_PLL_GPU] = &pll_gpu_clk.common.hw,
  887. [CLK_PLL_DE] = &pll_de_clk.common.hw,
  888. [CLK_PLL_ISP] = &pll_isp_clk.common.hw,
  889. [CLK_PLL_PERIPH1] = &pll_periph1_clk.common.hw,
  890. [CLK_C0CPUX] = &c0cpux_clk.common.hw,
  891. [CLK_C1CPUX] = &c1cpux_clk.common.hw,
  892. [CLK_ATB0] = &atb0_clk.common.hw,
  893. [CLK_AXI0] = &axi0_clk.common.hw,
  894. [CLK_ATB1] = &atb1_clk.common.hw,
  895. [CLK_AXI1] = &axi1_clk.common.hw,
  896. [CLK_GTBUS] = &gtbus_clk.common.hw,
  897. [CLK_AHB0] = &ahb0_clk.common.hw,
  898. [CLK_AHB1] = &ahb1_clk.common.hw,
  899. [CLK_AHB2] = &ahb2_clk.common.hw,
  900. [CLK_APB0] = &apb0_clk.common.hw,
  901. [CLK_APB1] = &apb1_clk.common.hw,
  902. [CLK_CCI400] = &cci400_clk.common.hw,
  903. [CLK_ATS] = &ats_clk.common.hw,
  904. [CLK_TRACE] = &trace_clk.common.hw,
  905. [CLK_OUT_A] = &out_a_clk.common.hw,
  906. [CLK_OUT_B] = &out_b_clk.common.hw,
  907. [CLK_NAND0_0] = &nand0_0_clk.common.hw,
  908. [CLK_NAND0_1] = &nand0_1_clk.common.hw,
  909. [CLK_NAND1_0] = &nand1_0_clk.common.hw,
  910. [CLK_NAND1_1] = &nand1_1_clk.common.hw,
  911. [CLK_MMC0] = &mmc0_clk.common.hw,
  912. [CLK_MMC0_SAMPLE] = &mmc0_sample_clk.common.hw,
  913. [CLK_MMC0_OUTPUT] = &mmc0_output_clk.common.hw,
  914. [CLK_MMC1] = &mmc1_clk.common.hw,
  915. [CLK_MMC1_SAMPLE] = &mmc1_sample_clk.common.hw,
  916. [CLK_MMC1_OUTPUT] = &mmc1_output_clk.common.hw,
  917. [CLK_MMC2] = &mmc2_clk.common.hw,
  918. [CLK_MMC2_SAMPLE] = &mmc2_sample_clk.common.hw,
  919. [CLK_MMC2_OUTPUT] = &mmc2_output_clk.common.hw,
  920. [CLK_MMC3] = &mmc3_clk.common.hw,
  921. [CLK_MMC3_SAMPLE] = &mmc3_sample_clk.common.hw,
  922. [CLK_MMC3_OUTPUT] = &mmc3_output_clk.common.hw,
  923. [CLK_TS] = &ts_clk.common.hw,
  924. [CLK_SS] = &ss_clk.common.hw,
  925. [CLK_SPI0] = &spi0_clk.common.hw,
  926. [CLK_SPI1] = &spi1_clk.common.hw,
  927. [CLK_SPI2] = &spi2_clk.common.hw,
  928. [CLK_SPI3] = &spi3_clk.common.hw,
  929. [CLK_I2S0] = &i2s0_clk.common.hw,
  930. [CLK_I2S1] = &i2s1_clk.common.hw,
  931. [CLK_SPDIF] = &spdif_clk.common.hw,
  932. [CLK_SDRAM] = &sdram_clk.common.hw,
  933. [CLK_DE] = &de_clk.common.hw,
  934. [CLK_EDP] = &edp_clk.common.hw,
  935. [CLK_MP] = &mp_clk.common.hw,
  936. [CLK_LCD0] = &lcd0_clk.common.hw,
  937. [CLK_LCD1] = &lcd1_clk.common.hw,
  938. [CLK_MIPI_DSI0] = &mipi_dsi0_clk.common.hw,
  939. [CLK_MIPI_DSI1] = &mipi_dsi1_clk.common.hw,
  940. [CLK_HDMI] = &hdmi_clk.common.hw,
  941. [CLK_HDMI_SLOW] = &hdmi_slow_clk.common.hw,
  942. [CLK_MIPI_CSI] = &mipi_csi_clk.common.hw,
  943. [CLK_CSI_ISP] = &csi_isp_clk.common.hw,
  944. [CLK_CSI_MISC] = &csi_misc_clk.common.hw,
  945. [CLK_CSI0_MCLK] = &csi0_mclk_clk.common.hw,
  946. [CLK_CSI1_MCLK] = &csi1_mclk_clk.common.hw,
  947. [CLK_FD] = &fd_clk.common.hw,
  948. [CLK_VE] = &ve_clk.common.hw,
  949. [CLK_AVS] = &avs_clk.common.hw,
  950. [CLK_GPU_CORE] = &gpu_core_clk.common.hw,
  951. [CLK_GPU_MEMORY] = &gpu_memory_clk.common.hw,
  952. [CLK_GPU_AXI] = &gpu_axi_clk.common.hw,
  953. [CLK_SATA] = &sata_clk.common.hw,
  954. [CLK_AC97] = &ac97_clk.common.hw,
  955. [CLK_MIPI_HSI] = &mipi_hsi_clk.common.hw,
  956. [CLK_GPADC] = &gpadc_clk.common.hw,
  957. [CLK_CIR_TX] = &cir_tx_clk.common.hw,
  958. [CLK_BUS_FD] = &bus_fd_clk.common.hw,
  959. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  960. [CLK_BUS_GPU_CTRL] = &bus_gpu_ctrl_clk.common.hw,
  961. [CLK_BUS_SS] = &bus_ss_clk.common.hw,
  962. [CLK_BUS_MMC] = &bus_mmc_clk.common.hw,
  963. [CLK_BUS_NAND0] = &bus_nand0_clk.common.hw,
  964. [CLK_BUS_NAND1] = &bus_nand1_clk.common.hw,
  965. [CLK_BUS_SDRAM] = &bus_sdram_clk.common.hw,
  966. [CLK_BUS_MIPI_HSI] = &bus_mipi_hsi_clk.common.hw,
  967. [CLK_BUS_SATA] = &bus_sata_clk.common.hw,
  968. [CLK_BUS_TS] = &bus_ts_clk.common.hw,
  969. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  970. [CLK_BUS_SPI1] = &bus_spi1_clk.common.hw,
  971. [CLK_BUS_SPI2] = &bus_spi2_clk.common.hw,
  972. [CLK_BUS_SPI3] = &bus_spi3_clk.common.hw,
  973. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  974. [CLK_BUS_USB] = &bus_usb_clk.common.hw,
  975. [CLK_BUS_GMAC] = &bus_gmac_clk.common.hw,
  976. [CLK_BUS_MSGBOX] = &bus_msgbox_clk.common.hw,
  977. [CLK_BUS_SPINLOCK] = &bus_spinlock_clk.common.hw,
  978. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  979. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  980. [CLK_BUS_LCD0] = &bus_lcd0_clk.common.hw,
  981. [CLK_BUS_LCD1] = &bus_lcd1_clk.common.hw,
  982. [CLK_BUS_EDP] = &bus_edp_clk.common.hw,
  983. [CLK_BUS_CSI] = &bus_csi_clk.common.hw,
  984. [CLK_BUS_HDMI] = &bus_hdmi_clk.common.hw,
  985. [CLK_BUS_DE] = &bus_de_clk.common.hw,
  986. [CLK_BUS_MP] = &bus_mp_clk.common.hw,
  987. [CLK_BUS_MIPI_DSI] = &bus_mipi_dsi_clk.common.hw,
  988. [CLK_BUS_SPDIF] = &bus_spdif_clk.common.hw,
  989. [CLK_BUS_PIO] = &bus_pio_clk.common.hw,
  990. [CLK_BUS_AC97] = &bus_ac97_clk.common.hw,
  991. [CLK_BUS_I2S0] = &bus_i2s0_clk.common.hw,
  992. [CLK_BUS_I2S1] = &bus_i2s1_clk.common.hw,
  993. [CLK_BUS_LRADC] = &bus_lradc_clk.common.hw,
  994. [CLK_BUS_GPADC] = &bus_gpadc_clk.common.hw,
  995. [CLK_BUS_TWD] = &bus_twd_clk.common.hw,
  996. [CLK_BUS_CIR_TX] = &bus_cir_tx_clk.common.hw,
  997. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  998. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  999. [CLK_BUS_I2C2] = &bus_i2c2_clk.common.hw,
  1000. [CLK_BUS_I2C3] = &bus_i2c3_clk.common.hw,
  1001. [CLK_BUS_I2C4] = &bus_i2c4_clk.common.hw,
  1002. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  1003. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  1004. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  1005. [CLK_BUS_UART3] = &bus_uart3_clk.common.hw,
  1006. [CLK_BUS_UART4] = &bus_uart4_clk.common.hw,
  1007. [CLK_BUS_UART5] = &bus_uart5_clk.common.hw,
  1008. },
  1009. .num = CLK_NUMBER,
  1010. };
  1011. static struct ccu_reset_map sun9i_a80_ccu_resets[] = {
  1012. /* AHB0 reset controls */
  1013. [RST_BUS_FD] = { 0x5a0, BIT(0) },
  1014. [RST_BUS_VE] = { 0x5a0, BIT(1) },
  1015. [RST_BUS_GPU_CTRL] = { 0x5a0, BIT(3) },
  1016. [RST_BUS_SS] = { 0x5a0, BIT(5) },
  1017. [RST_BUS_MMC] = { 0x5a0, BIT(8) },
  1018. [RST_BUS_NAND0] = { 0x5a0, BIT(12) },
  1019. [RST_BUS_NAND1] = { 0x5a0, BIT(13) },
  1020. [RST_BUS_SDRAM] = { 0x5a0, BIT(14) },
  1021. [RST_BUS_SATA] = { 0x5a0, BIT(16) },
  1022. [RST_BUS_TS] = { 0x5a0, BIT(18) },
  1023. [RST_BUS_SPI0] = { 0x5a0, BIT(20) },
  1024. [RST_BUS_SPI1] = { 0x5a0, BIT(21) },
  1025. [RST_BUS_SPI2] = { 0x5a0, BIT(22) },
  1026. [RST_BUS_SPI3] = { 0x5a0, BIT(23) },
  1027. /* AHB1 reset controls */
  1028. [RST_BUS_OTG] = { 0x5a4, BIT(0) },
  1029. [RST_BUS_OTG_PHY] = { 0x5a4, BIT(1) },
  1030. [RST_BUS_MIPI_HSI] = { 0x5a4, BIT(9) },
  1031. [RST_BUS_GMAC] = { 0x5a4, BIT(17) },
  1032. [RST_BUS_MSGBOX] = { 0x5a4, BIT(21) },
  1033. [RST_BUS_SPINLOCK] = { 0x5a4, BIT(22) },
  1034. [RST_BUS_HSTIMER] = { 0x5a4, BIT(23) },
  1035. [RST_BUS_DMA] = { 0x5a4, BIT(24) },
  1036. /* AHB2 reset controls */
  1037. [RST_BUS_LCD0] = { 0x5a8, BIT(0) },
  1038. [RST_BUS_LCD1] = { 0x5a8, BIT(1) },
  1039. [RST_BUS_EDP] = { 0x5a8, BIT(2) },
  1040. [RST_BUS_LVDS] = { 0x5a8, BIT(3) },
  1041. [RST_BUS_CSI] = { 0x5a8, BIT(4) },
  1042. [RST_BUS_HDMI0] = { 0x5a8, BIT(5) },
  1043. [RST_BUS_HDMI1] = { 0x5a8, BIT(6) },
  1044. [RST_BUS_DE] = { 0x5a8, BIT(7) },
  1045. [RST_BUS_MP] = { 0x5a8, BIT(8) },
  1046. [RST_BUS_GPU] = { 0x5a8, BIT(9) },
  1047. [RST_BUS_MIPI_DSI] = { 0x5a8, BIT(11) },
  1048. /* APB0 reset controls */
  1049. [RST_BUS_SPDIF] = { 0x5b0, BIT(1) },
  1050. [RST_BUS_AC97] = { 0x5b0, BIT(11) },
  1051. [RST_BUS_I2S0] = { 0x5b0, BIT(12) },
  1052. [RST_BUS_I2S1] = { 0x5b0, BIT(13) },
  1053. [RST_BUS_LRADC] = { 0x5b0, BIT(15) },
  1054. [RST_BUS_GPADC] = { 0x5b0, BIT(17) },
  1055. [RST_BUS_CIR_TX] = { 0x5b0, BIT(19) },
  1056. /* APB1 reset controls */
  1057. [RST_BUS_I2C0] = { 0x5b4, BIT(0) },
  1058. [RST_BUS_I2C1] = { 0x5b4, BIT(1) },
  1059. [RST_BUS_I2C2] = { 0x5b4, BIT(2) },
  1060. [RST_BUS_I2C3] = { 0x5b4, BIT(3) },
  1061. [RST_BUS_I2C4] = { 0x5b4, BIT(4) },
  1062. [RST_BUS_UART0] = { 0x5b4, BIT(16) },
  1063. [RST_BUS_UART1] = { 0x5b4, BIT(17) },
  1064. [RST_BUS_UART2] = { 0x5b4, BIT(18) },
  1065. [RST_BUS_UART3] = { 0x5b4, BIT(19) },
  1066. [RST_BUS_UART4] = { 0x5b4, BIT(20) },
  1067. [RST_BUS_UART5] = { 0x5b4, BIT(21) },
  1068. };
  1069. static const struct sunxi_ccu_desc sun9i_a80_ccu_desc = {
  1070. .ccu_clks = sun9i_a80_ccu_clks,
  1071. .num_ccu_clks = ARRAY_SIZE(sun9i_a80_ccu_clks),
  1072. .hw_clks = &sun9i_a80_hw_clks,
  1073. .resets = sun9i_a80_ccu_resets,
  1074. .num_resets = ARRAY_SIZE(sun9i_a80_ccu_resets),
  1075. };
  1076. #define SUN9I_A80_PLL_P_SHIFT 16
  1077. #define SUN9I_A80_PLL_N_SHIFT 8
  1078. #define SUN9I_A80_PLL_N_WIDTH 8
  1079. static void sun9i_a80_cpu_pll_fixup(void __iomem *reg)
  1080. {
  1081. u32 val = readl(reg);
  1082. /* bail out if P divider is not used */
  1083. if (!(val & BIT(SUN9I_A80_PLL_P_SHIFT)))
  1084. return;
  1085. /*
  1086. * If P is used, output should be less than 288 MHz. When we
  1087. * set P to 1, we should also decrease the multiplier so the
  1088. * output doesn't go out of range, but not too much such that
  1089. * the multiplier stays above 12, the minimal operation value.
  1090. *
  1091. * To keep it simple, set the multiplier to 17, the reset value.
  1092. */
  1093. val &= ~GENMASK(SUN9I_A80_PLL_N_SHIFT + SUN9I_A80_PLL_N_WIDTH - 1,
  1094. SUN9I_A80_PLL_N_SHIFT);
  1095. val |= 17 << SUN9I_A80_PLL_N_SHIFT;
  1096. /* And clear P */
  1097. val &= ~BIT(SUN9I_A80_PLL_P_SHIFT);
  1098. writel(val, reg);
  1099. }
  1100. static int sun9i_a80_ccu_probe(struct platform_device *pdev)
  1101. {
  1102. struct resource *res;
  1103. void __iomem *reg;
  1104. u32 val;
  1105. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1106. reg = devm_ioremap_resource(&pdev->dev, res);
  1107. if (IS_ERR(reg))
  1108. return PTR_ERR(reg);
  1109. /* Enforce d1 = 0, d2 = 0 for Audio PLL */
  1110. val = readl(reg + SUN9I_A80_PLL_AUDIO_REG);
  1111. val &= ~(BIT(16) | BIT(18));
  1112. writel(val, reg + SUN9I_A80_PLL_AUDIO_REG);
  1113. /* Enforce P = 1 for both CPU cluster PLLs */
  1114. sun9i_a80_cpu_pll_fixup(reg + SUN9I_A80_PLL_C0CPUX_REG);
  1115. sun9i_a80_cpu_pll_fixup(reg + SUN9I_A80_PLL_C1CPUX_REG);
  1116. return sunxi_ccu_probe(pdev->dev.of_node, reg, &sun9i_a80_ccu_desc);
  1117. }
  1118. static const struct of_device_id sun9i_a80_ccu_ids[] = {
  1119. { .compatible = "allwinner,sun9i-a80-ccu" },
  1120. { }
  1121. };
  1122. static struct platform_driver sun9i_a80_ccu_driver = {
  1123. .probe = sun9i_a80_ccu_probe,
  1124. .driver = {
  1125. .name = "sun9i-a80-ccu",
  1126. .of_match_table = sun9i_a80_ccu_ids,
  1127. },
  1128. };
  1129. builtin_platform_driver(sun9i_a80_ccu_driver);