ccu-sun8i-r40.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  1. /*
  2. * Copyright (c) 2017 Icenowy Zheng <icenowy@aosc.io>
  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/platform_device.h>
  15. #include <linux/regmap.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_mult.h"
  22. #include "ccu_nk.h"
  23. #include "ccu_nkm.h"
  24. #include "ccu_nkmp.h"
  25. #include "ccu_nm.h"
  26. #include "ccu_phase.h"
  27. #include "ccu-sun8i-r40.h"
  28. /* TODO: The result of N*K is required to be in [10, 88] range. */
  29. static struct ccu_nkmp pll_cpu_clk = {
  30. .enable = BIT(31),
  31. .lock = BIT(28),
  32. .n = _SUNXI_CCU_MULT(8, 5),
  33. .k = _SUNXI_CCU_MULT(4, 2),
  34. .m = _SUNXI_CCU_DIV(0, 2),
  35. .p = _SUNXI_CCU_DIV_MAX(16, 2, 4),
  36. .common = {
  37. .reg = 0x000,
  38. .hw.init = CLK_HW_INIT("pll-cpu",
  39. "osc24M",
  40. &ccu_nkmp_ops,
  41. CLK_SET_RATE_UNGATE),
  42. },
  43. };
  44. /*
  45. * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from
  46. * the base (2x, 4x and 8x), and one variable divider (the one true
  47. * pll audio).
  48. *
  49. * We don't have any need for the variable divider for now, so we just
  50. * hardcode it to match with the clock names
  51. */
  52. #define SUN8I_R40_PLL_AUDIO_REG 0x008
  53. static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
  54. "osc24M", 0x008,
  55. 8, 7, /* N */
  56. 0, 5, /* M */
  57. BIT(31), /* gate */
  58. BIT(28), /* lock */
  59. CLK_SET_RATE_UNGATE);
  60. /* TODO: The result of N/M is required to be in [8, 25] range. */
  61. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN(pll_video0_clk, "pll-video0",
  62. "osc24M", 0x0010,
  63. 192000000, /* Minimum rate */
  64. 8, 7, /* N */
  65. 0, 4, /* M */
  66. BIT(24), /* frac enable */
  67. BIT(25), /* frac select */
  68. 270000000, /* frac rate 0 */
  69. 297000000, /* frac rate 1 */
  70. BIT(31), /* gate */
  71. BIT(28), /* lock */
  72. CLK_SET_RATE_UNGATE);
  73. /* TODO: The result of N/M is required to be in [8, 25] range. */
  74. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve",
  75. "osc24M", 0x0018,
  76. 8, 7, /* N */
  77. 0, 4, /* M */
  78. BIT(24), /* frac enable */
  79. BIT(25), /* frac select */
  80. 270000000, /* frac rate 0 */
  81. 297000000, /* frac rate 1 */
  82. BIT(31), /* gate */
  83. BIT(28), /* lock */
  84. CLK_SET_RATE_UNGATE);
  85. /* TODO: The result of N*K is required to be in [10, 77] range. */
  86. static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr0_clk, "pll-ddr0",
  87. "osc24M", 0x020,
  88. 8, 5, /* N */
  89. 4, 2, /* K */
  90. 0, 2, /* M */
  91. BIT(31), /* gate */
  92. BIT(28), /* lock */
  93. CLK_SET_RATE_UNGATE);
  94. /* TODO: The result of N*K is required to be in [21, 58] range. */
  95. static struct ccu_nk pll_periph0_clk = {
  96. .enable = BIT(31),
  97. .lock = BIT(28),
  98. .n = _SUNXI_CCU_MULT(8, 5),
  99. .k = _SUNXI_CCU_MULT(4, 2),
  100. .fixed_post_div = 2,
  101. .common = {
  102. .reg = 0x028,
  103. .features = CCU_FEATURE_FIXED_POSTDIV,
  104. .hw.init = CLK_HW_INIT("pll-periph0", "osc24M",
  105. &ccu_nk_ops,
  106. CLK_SET_RATE_UNGATE),
  107. },
  108. };
  109. static struct ccu_div pll_periph0_sata_clk = {
  110. .enable = BIT(24),
  111. .div = _SUNXI_CCU_DIV(0, 2),
  112. /*
  113. * The formula of pll-periph0 (1x) is 24MHz*N*K/2, and the formula
  114. * of pll-periph0-sata is 24MHz*N*K/M/6, so the postdiv here is
  115. * 6/2 = 3.
  116. */
  117. .fixed_post_div = 3,
  118. .common = {
  119. .reg = 0x028,
  120. .features = CCU_FEATURE_FIXED_POSTDIV,
  121. .hw.init = CLK_HW_INIT("pll-periph0-sata",
  122. "pll-periph0",
  123. &ccu_div_ops, 0),
  124. },
  125. };
  126. /* TODO: The result of N*K is required to be in [21, 58] range. */
  127. static struct ccu_nk pll_periph1_clk = {
  128. .enable = BIT(31),
  129. .lock = BIT(28),
  130. .n = _SUNXI_CCU_MULT(8, 5),
  131. .k = _SUNXI_CCU_MULT(4, 2),
  132. .fixed_post_div = 2,
  133. .common = {
  134. .reg = 0x02c,
  135. .features = CCU_FEATURE_FIXED_POSTDIV,
  136. .hw.init = CLK_HW_INIT("pll-periph1", "osc24M",
  137. &ccu_nk_ops,
  138. CLK_SET_RATE_UNGATE),
  139. },
  140. };
  141. /* TODO: The result of N/M is required to be in [8, 25] range. */
  142. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN(pll_video1_clk, "pll-video1",
  143. "osc24M", 0x030,
  144. 192000000, /* Minimum rate */
  145. 8, 7, /* N */
  146. 0, 4, /* M */
  147. BIT(24), /* frac enable */
  148. BIT(25), /* frac select */
  149. 270000000, /* frac rate 0 */
  150. 297000000, /* frac rate 1 */
  151. BIT(31), /* gate */
  152. BIT(28), /* lock */
  153. CLK_SET_RATE_UNGATE);
  154. static struct ccu_nkm pll_sata_clk = {
  155. .enable = BIT(31),
  156. .lock = BIT(28),
  157. .n = _SUNXI_CCU_MULT(8, 5),
  158. .k = _SUNXI_CCU_MULT(4, 2),
  159. .m = _SUNXI_CCU_DIV(0, 2),
  160. .fixed_post_div = 6,
  161. .common = {
  162. .reg = 0x034,
  163. .features = CCU_FEATURE_FIXED_POSTDIV,
  164. .hw.init = CLK_HW_INIT("pll-sata", "osc24M",
  165. &ccu_nkm_ops,
  166. CLK_SET_RATE_UNGATE),
  167. },
  168. };
  169. static const char * const pll_sata_out_parents[] = { "pll-sata",
  170. "pll-periph0-sata" };
  171. static SUNXI_CCU_MUX_WITH_GATE(pll_sata_out_clk, "pll-sata-out",
  172. pll_sata_out_parents, 0x034,
  173. 30, 1, /* mux */
  174. BIT(14), /* gate */
  175. CLK_SET_RATE_PARENT);
  176. /* TODO: The result of N/M is required to be in [8, 25] range. */
  177. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_gpu_clk, "pll-gpu",
  178. "osc24M", 0x038,
  179. 8, 7, /* N */
  180. 0, 4, /* M */
  181. BIT(24), /* frac enable */
  182. BIT(25), /* frac select */
  183. 270000000, /* frac rate 0 */
  184. 297000000, /* frac rate 1 */
  185. BIT(31), /* gate */
  186. BIT(28), /* lock */
  187. CLK_SET_RATE_UNGATE);
  188. /*
  189. * The MIPI PLL has 2 modes: "MIPI" and "HDMI".
  190. *
  191. * The MIPI mode is a standard NKM-style clock. The HDMI mode is an
  192. * integer / fractional clock with switchable multipliers and dividers.
  193. * This is not supported here. We hardcode the PLL to MIPI mode.
  194. *
  195. * TODO: In the MIPI mode, M/N is required to be equal or lesser than 3,
  196. * which cannot be implemented now.
  197. */
  198. #define SUN8I_R40_PLL_MIPI_REG 0x040
  199. static const char * const pll_mipi_parents[] = { "pll-video0" };
  200. static struct ccu_nkm pll_mipi_clk = {
  201. .enable = BIT(31) | BIT(23) | BIT(22),
  202. .lock = BIT(28),
  203. .n = _SUNXI_CCU_MULT(8, 4),
  204. .k = _SUNXI_CCU_MULT_MIN(4, 2, 2),
  205. .m = _SUNXI_CCU_DIV(0, 4),
  206. .mux = _SUNXI_CCU_MUX(21, 1),
  207. .common = {
  208. .reg = 0x040,
  209. .hw.init = CLK_HW_INIT_PARENTS("pll-mipi",
  210. pll_mipi_parents,
  211. &ccu_nkm_ops,
  212. CLK_SET_RATE_UNGATE)
  213. },
  214. };
  215. /* TODO: The result of N/M is required to be in [8, 25] range. */
  216. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_de_clk, "pll-de",
  217. "osc24M", 0x048,
  218. 8, 7, /* N */
  219. 0, 4, /* M */
  220. BIT(24), /* frac enable */
  221. BIT(25), /* frac select */
  222. 270000000, /* frac rate 0 */
  223. 297000000, /* frac rate 1 */
  224. BIT(31), /* gate */
  225. BIT(28), /* lock */
  226. CLK_SET_RATE_UNGATE);
  227. /* TODO: The N factor is required to be in [16, 75] range. */
  228. static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_ddr1_clk, "pll-ddr1",
  229. "osc24M", 0x04c,
  230. 8, 7, /* N */
  231. 0, 2, /* M */
  232. BIT(31), /* gate */
  233. BIT(28), /* lock */
  234. CLK_SET_RATE_UNGATE);
  235. static const char * const cpu_parents[] = { "osc32k", "osc24M",
  236. "pll-cpu", "pll-cpu" };
  237. static SUNXI_CCU_MUX(cpu_clk, "cpu", cpu_parents,
  238. 0x050, 16, 2, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT);
  239. static SUNXI_CCU_M(axi_clk, "axi", "cpu", 0x050, 0, 2, 0);
  240. static const char * const ahb1_parents[] = { "osc32k", "osc24M",
  241. "axi", "pll-periph0" };
  242. static const struct ccu_mux_var_prediv ahb1_predivs[] = {
  243. { .index = 3, .shift = 6, .width = 2 },
  244. };
  245. static struct ccu_div ahb1_clk = {
  246. .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
  247. .mux = {
  248. .shift = 12,
  249. .width = 2,
  250. .var_predivs = ahb1_predivs,
  251. .n_var_predivs = ARRAY_SIZE(ahb1_predivs),
  252. },
  253. .common = {
  254. .reg = 0x054,
  255. .features = CCU_FEATURE_VARIABLE_PREDIV,
  256. .hw.init = CLK_HW_INIT_PARENTS("ahb1",
  257. ahb1_parents,
  258. &ccu_div_ops,
  259. 0),
  260. },
  261. };
  262. static struct clk_div_table apb1_div_table[] = {
  263. { .val = 0, .div = 2 },
  264. { .val = 1, .div = 2 },
  265. { .val = 2, .div = 4 },
  266. { .val = 3, .div = 8 },
  267. { /* Sentinel */ },
  268. };
  269. static SUNXI_CCU_DIV_TABLE(apb1_clk, "apb1", "ahb1",
  270. 0x054, 8, 2, apb1_div_table, 0);
  271. static const char * const apb2_parents[] = { "osc32k", "osc24M",
  272. "pll-periph0-2x",
  273. "pll-periph0-2x" };
  274. static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", apb2_parents, 0x058,
  275. 0, 5, /* M */
  276. 16, 2, /* P */
  277. 24, 2, /* mux */
  278. 0);
  279. static SUNXI_CCU_GATE(bus_mipi_dsi_clk, "bus-mipi-dsi", "ahb1",
  280. 0x060, BIT(1), 0);
  281. static SUNXI_CCU_GATE(bus_ce_clk, "bus-ce", "ahb1",
  282. 0x060, BIT(5), 0);
  283. static SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "ahb1",
  284. 0x060, BIT(6), 0);
  285. static SUNXI_CCU_GATE(bus_mmc0_clk, "bus-mmc0", "ahb1",
  286. 0x060, BIT(8), 0);
  287. static SUNXI_CCU_GATE(bus_mmc1_clk, "bus-mmc1", "ahb1",
  288. 0x060, BIT(9), 0);
  289. static SUNXI_CCU_GATE(bus_mmc2_clk, "bus-mmc2", "ahb1",
  290. 0x060, BIT(10), 0);
  291. static SUNXI_CCU_GATE(bus_mmc3_clk, "bus-mmc3", "ahb1",
  292. 0x060, BIT(11), 0);
  293. static SUNXI_CCU_GATE(bus_nand_clk, "bus-nand", "ahb1",
  294. 0x060, BIT(13), 0);
  295. static SUNXI_CCU_GATE(bus_dram_clk, "bus-dram", "ahb1",
  296. 0x060, BIT(14), 0);
  297. static SUNXI_CCU_GATE(bus_emac_clk, "bus-emac", "ahb1",
  298. 0x060, BIT(17), 0);
  299. static SUNXI_CCU_GATE(bus_ts_clk, "bus-ts", "ahb1",
  300. 0x060, BIT(18), 0);
  301. static SUNXI_CCU_GATE(bus_hstimer_clk, "bus-hstimer", "ahb1",
  302. 0x060, BIT(19), 0);
  303. static SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb1",
  304. 0x060, BIT(20), 0);
  305. static SUNXI_CCU_GATE(bus_spi1_clk, "bus-spi1", "ahb1",
  306. 0x060, BIT(21), 0);
  307. static SUNXI_CCU_GATE(bus_spi2_clk, "bus-spi2", "ahb1",
  308. 0x060, BIT(22), 0);
  309. static SUNXI_CCU_GATE(bus_spi3_clk, "bus-spi3", "ahb1",
  310. 0x060, BIT(23), 0);
  311. static SUNXI_CCU_GATE(bus_sata_clk, "bus-sata", "ahb1",
  312. 0x060, BIT(24), 0);
  313. static SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb1",
  314. 0x060, BIT(25), 0);
  315. static SUNXI_CCU_GATE(bus_ehci0_clk, "bus-ehci0", "ahb1",
  316. 0x060, BIT(26), 0);
  317. static SUNXI_CCU_GATE(bus_ehci1_clk, "bus-ehci1", "ahb1",
  318. 0x060, BIT(27), 0);
  319. static SUNXI_CCU_GATE(bus_ehci2_clk, "bus-ehci2", "ahb1",
  320. 0x060, BIT(28), 0);
  321. static SUNXI_CCU_GATE(bus_ohci0_clk, "bus-ohci0", "ahb1",
  322. 0x060, BIT(29), 0);
  323. static SUNXI_CCU_GATE(bus_ohci1_clk, "bus-ohci1", "ahb1",
  324. 0x060, BIT(30), 0);
  325. static SUNXI_CCU_GATE(bus_ohci2_clk, "bus-ohci2", "ahb1",
  326. 0x060, BIT(31), 0);
  327. static SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "ahb1",
  328. 0x064, BIT(0), 0);
  329. static SUNXI_CCU_GATE(bus_mp_clk, "bus-mp", "ahb1",
  330. 0x064, BIT(2), 0);
  331. static SUNXI_CCU_GATE(bus_deinterlace_clk, "bus-deinterlace", "ahb1",
  332. 0x064, BIT(5), 0);
  333. static SUNXI_CCU_GATE(bus_csi0_clk, "bus-csi0", "ahb1",
  334. 0x064, BIT(8), 0);
  335. static SUNXI_CCU_GATE(bus_csi1_clk, "bus-csi1", "ahb1",
  336. 0x064, BIT(9), 0);
  337. static SUNXI_CCU_GATE(bus_hdmi0_clk, "bus-hdmi0", "ahb1",
  338. 0x064, BIT(10), 0);
  339. static SUNXI_CCU_GATE(bus_hdmi1_clk, "bus-hdmi1", "ahb1",
  340. 0x064, BIT(11), 0);
  341. static SUNXI_CCU_GATE(bus_de_clk, "bus-de", "ahb1",
  342. 0x064, BIT(12), 0);
  343. static SUNXI_CCU_GATE(bus_tve0_clk, "bus-tve0", "ahb1",
  344. 0x064, BIT(13), 0);
  345. static SUNXI_CCU_GATE(bus_tve1_clk, "bus-tve1", "ahb1",
  346. 0x064, BIT(14), 0);
  347. static SUNXI_CCU_GATE(bus_tve_top_clk, "bus-tve-top", "ahb1",
  348. 0x064, BIT(15), 0);
  349. static SUNXI_CCU_GATE(bus_gmac_clk, "bus-gmac", "ahb1",
  350. 0x064, BIT(17), 0);
  351. static SUNXI_CCU_GATE(bus_gpu_clk, "bus-gpu", "ahb1",
  352. 0x064, BIT(20), 0);
  353. static SUNXI_CCU_GATE(bus_tvd0_clk, "bus-tvd0", "ahb1",
  354. 0x064, BIT(21), 0);
  355. static SUNXI_CCU_GATE(bus_tvd1_clk, "bus-tvd1", "ahb1",
  356. 0x064, BIT(22), 0);
  357. static SUNXI_CCU_GATE(bus_tvd2_clk, "bus-tvd2", "ahb1",
  358. 0x064, BIT(23), 0);
  359. static SUNXI_CCU_GATE(bus_tvd3_clk, "bus-tvd3", "ahb1",
  360. 0x064, BIT(24), 0);
  361. static SUNXI_CCU_GATE(bus_tvd_top_clk, "bus-tvd-top", "ahb1",
  362. 0x064, BIT(25), 0);
  363. static SUNXI_CCU_GATE(bus_tcon_lcd0_clk, "bus-tcon-lcd0", "ahb1",
  364. 0x064, BIT(26), 0);
  365. static SUNXI_CCU_GATE(bus_tcon_lcd1_clk, "bus-tcon-lcd1", "ahb1",
  366. 0x064, BIT(27), 0);
  367. static SUNXI_CCU_GATE(bus_tcon_tv0_clk, "bus-tcon-tv0", "ahb1",
  368. 0x064, BIT(28), 0);
  369. static SUNXI_CCU_GATE(bus_tcon_tv1_clk, "bus-tcon-tv1", "ahb1",
  370. 0x064, BIT(29), 0);
  371. static SUNXI_CCU_GATE(bus_tcon_top_clk, "bus-tcon-top", "ahb1",
  372. 0x064, BIT(30), 0);
  373. static SUNXI_CCU_GATE(bus_codec_clk, "bus-codec", "apb1",
  374. 0x068, BIT(0), 0);
  375. static SUNXI_CCU_GATE(bus_spdif_clk, "bus-spdif", "apb1",
  376. 0x068, BIT(1), 0);
  377. static SUNXI_CCU_GATE(bus_ac97_clk, "bus-ac97", "apb1",
  378. 0x068, BIT(2), 0);
  379. static SUNXI_CCU_GATE(bus_pio_clk, "bus-pio", "apb1",
  380. 0x068, BIT(5), 0);
  381. static SUNXI_CCU_GATE(bus_ir0_clk, "bus-ir0", "apb1",
  382. 0x068, BIT(6), 0);
  383. static SUNXI_CCU_GATE(bus_ir1_clk, "bus-ir1", "apb1",
  384. 0x068, BIT(7), 0);
  385. static SUNXI_CCU_GATE(bus_ths_clk, "bus-ths", "apb1",
  386. 0x068, BIT(8), 0);
  387. static SUNXI_CCU_GATE(bus_keypad_clk, "bus-keypad", "apb1",
  388. 0x068, BIT(10), 0);
  389. static SUNXI_CCU_GATE(bus_i2s0_clk, "bus-i2s0", "apb1",
  390. 0x068, BIT(12), 0);
  391. static SUNXI_CCU_GATE(bus_i2s1_clk, "bus-i2s1", "apb1",
  392. 0x068, BIT(13), 0);
  393. static SUNXI_CCU_GATE(bus_i2s2_clk, "bus-i2s2", "apb1",
  394. 0x068, BIT(14), 0);
  395. static SUNXI_CCU_GATE(bus_i2c0_clk, "bus-i2c0", "apb2",
  396. 0x06c, BIT(0), 0);
  397. static SUNXI_CCU_GATE(bus_i2c1_clk, "bus-i2c1", "apb2",
  398. 0x06c, BIT(1), 0);
  399. static SUNXI_CCU_GATE(bus_i2c2_clk, "bus-i2c2", "apb2",
  400. 0x06c, BIT(2), 0);
  401. static SUNXI_CCU_GATE(bus_i2c3_clk, "bus-i2c3", "apb2",
  402. 0x06c, BIT(3), 0);
  403. /*
  404. * In datasheet here's "Reserved", however the gate exists in BSP soucre
  405. * code.
  406. */
  407. static SUNXI_CCU_GATE(bus_can_clk, "bus-can", "apb2",
  408. 0x06c, BIT(4), 0);
  409. static SUNXI_CCU_GATE(bus_scr_clk, "bus-scr", "apb2",
  410. 0x06c, BIT(5), 0);
  411. static SUNXI_CCU_GATE(bus_ps20_clk, "bus-ps20", "apb2",
  412. 0x06c, BIT(6), 0);
  413. static SUNXI_CCU_GATE(bus_ps21_clk, "bus-ps21", "apb2",
  414. 0x06c, BIT(7), 0);
  415. static SUNXI_CCU_GATE(bus_i2c4_clk, "bus-i2c4", "apb2",
  416. 0x06c, BIT(15), 0);
  417. static SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb2",
  418. 0x06c, BIT(16), 0);
  419. static SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb2",
  420. 0x06c, BIT(17), 0);
  421. static SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb2",
  422. 0x06c, BIT(18), 0);
  423. static SUNXI_CCU_GATE(bus_uart3_clk, "bus-uart3", "apb2",
  424. 0x06c, BIT(19), 0);
  425. static SUNXI_CCU_GATE(bus_uart4_clk, "bus-uart4", "apb2",
  426. 0x06c, BIT(20), 0);
  427. static SUNXI_CCU_GATE(bus_uart5_clk, "bus-uart5", "apb2",
  428. 0x06c, BIT(21), 0);
  429. static SUNXI_CCU_GATE(bus_uart6_clk, "bus-uart6", "apb2",
  430. 0x06c, BIT(22), 0);
  431. static SUNXI_CCU_GATE(bus_uart7_clk, "bus-uart7", "apb2",
  432. 0x06c, BIT(23), 0);
  433. static SUNXI_CCU_GATE(bus_dbg_clk, "bus-dbg", "ahb1",
  434. 0x070, BIT(7), 0);
  435. static const char * const ths_parents[] = { "osc24M" };
  436. static struct ccu_div ths_clk = {
  437. .enable = BIT(31),
  438. .div = _SUNXI_CCU_DIV_FLAGS(0, 2, CLK_DIVIDER_POWER_OF_TWO),
  439. .mux = _SUNXI_CCU_MUX(24, 2),
  440. .common = {
  441. .reg = 0x074,
  442. .hw.init = CLK_HW_INIT_PARENTS("ths",
  443. ths_parents,
  444. &ccu_div_ops,
  445. 0),
  446. },
  447. };
  448. static const char * const mod0_default_parents[] = { "osc24M", "pll-periph0",
  449. "pll-periph1" };
  450. static SUNXI_CCU_MP_WITH_MUX_GATE(nand_clk, "nand", mod0_default_parents, 0x080,
  451. 0, 4, /* M */
  452. 16, 2, /* P */
  453. 24, 2, /* mux */
  454. BIT(31), /* gate */
  455. 0);
  456. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents, 0x088,
  457. 0, 4, /* M */
  458. 16, 2, /* P */
  459. 24, 2, /* mux */
  460. BIT(31), /* gate */
  461. 0);
  462. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents, 0x08c,
  463. 0, 4, /* M */
  464. 16, 2, /* P */
  465. 24, 2, /* mux */
  466. BIT(31), /* gate */
  467. 0);
  468. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents, 0x090,
  469. 0, 4, /* M */
  470. 16, 2, /* P */
  471. 24, 2, /* mux */
  472. BIT(31), /* gate */
  473. 0);
  474. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc3_clk, "mmc3", mod0_default_parents, 0x094,
  475. 0, 4, /* M */
  476. 16, 2, /* P */
  477. 24, 2, /* mux */
  478. BIT(31), /* gate */
  479. 0);
  480. static const char * const ts_parents[] = { "osc24M", "pll-periph0", };
  481. static SUNXI_CCU_MP_WITH_MUX_GATE(ts_clk, "ts", ts_parents, 0x098,
  482. 0, 4, /* M */
  483. 16, 2, /* P */
  484. 24, 4, /* mux */
  485. BIT(31), /* gate */
  486. 0);
  487. static const char * const ce_parents[] = { "osc24M", "pll-periph0-2x",
  488. "pll-periph1-2x" };
  489. static SUNXI_CCU_MP_WITH_MUX_GATE(ce_clk, "ce", ce_parents, 0x09c,
  490. 0, 4, /* M */
  491. 16, 2, /* P */
  492. 24, 2, /* mux */
  493. BIT(31), /* gate */
  494. 0);
  495. static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0,
  496. 0, 4, /* M */
  497. 16, 2, /* P */
  498. 24, 2, /* mux */
  499. BIT(31), /* gate */
  500. 0);
  501. static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", mod0_default_parents, 0x0a4,
  502. 0, 4, /* M */
  503. 16, 2, /* P */
  504. 24, 2, /* mux */
  505. BIT(31), /* gate */
  506. 0);
  507. static SUNXI_CCU_MP_WITH_MUX_GATE(spi2_clk, "spi2", mod0_default_parents, 0x0a8,
  508. 0, 4, /* M */
  509. 16, 2, /* P */
  510. 24, 2, /* mux */
  511. BIT(31), /* gate */
  512. 0);
  513. static SUNXI_CCU_MP_WITH_MUX_GATE(spi3_clk, "spi3", mod0_default_parents, 0x0ac,
  514. 0, 4, /* M */
  515. 16, 2, /* P */
  516. 24, 2, /* mux */
  517. BIT(31), /* gate */
  518. 0);
  519. static const char * const i2s_parents[] = { "pll-audio-8x", "pll-audio-4x",
  520. "pll-audio-2x", "pll-audio" };
  521. static SUNXI_CCU_MUX_WITH_GATE(i2s0_clk, "i2s0", i2s_parents,
  522. 0x0b0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  523. static SUNXI_CCU_MUX_WITH_GATE(i2s1_clk, "i2s1", i2s_parents,
  524. 0x0b4, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  525. static SUNXI_CCU_MUX_WITH_GATE(i2s2_clk, "i2s2", i2s_parents,
  526. 0x0b8, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  527. static SUNXI_CCU_MUX_WITH_GATE(ac97_clk, "ac97", i2s_parents,
  528. 0x0bc, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  529. static SUNXI_CCU_MUX_WITH_GATE(spdif_clk, "spdif", i2s_parents,
  530. 0x0c0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  531. static const char * const keypad_parents[] = { "osc24M", "osc32k" };
  532. static const u8 keypad_table[] = { 0, 2 };
  533. static struct ccu_mp keypad_clk = {
  534. .enable = BIT(31),
  535. .m = _SUNXI_CCU_DIV(0, 5),
  536. .p = _SUNXI_CCU_DIV(16, 2),
  537. .mux = _SUNXI_CCU_MUX_TABLE(24, 2, keypad_table),
  538. .common = {
  539. .reg = 0x0c4,
  540. .hw.init = CLK_HW_INIT_PARENTS("keypad",
  541. keypad_parents,
  542. &ccu_mp_ops,
  543. 0),
  544. }
  545. };
  546. static const char * const sata_parents[] = { "pll-sata-out", "sata-ext" };
  547. static SUNXI_CCU_MUX_WITH_GATE(sata_clk, "sata", sata_parents,
  548. 0x0c8, 24, 1, BIT(31), CLK_SET_RATE_PARENT);
  549. /*
  550. * There are 3 OHCI 12M clock source selection bits in this register.
  551. * We will force them to 0 (12M divided from 48M).
  552. */
  553. #define SUN8I_R40_USB_CLK_REG 0x0cc
  554. static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M",
  555. 0x0cc, BIT(8), 0);
  556. static SUNXI_CCU_GATE(usb_phy1_clk, "usb-phy1", "osc24M",
  557. 0x0cc, BIT(9), 0);
  558. static SUNXI_CCU_GATE(usb_phy2_clk, "usb-phy2", "osc24M",
  559. 0x0cc, BIT(10), 0);
  560. static SUNXI_CCU_GATE(usb_ohci0_clk, "usb-ohci0", "osc12M",
  561. 0x0cc, BIT(16), 0);
  562. static SUNXI_CCU_GATE(usb_ohci1_clk, "usb-ohci1", "osc12M",
  563. 0x0cc, BIT(17), 0);
  564. static SUNXI_CCU_GATE(usb_ohci2_clk, "usb-ohci2", "osc12M",
  565. 0x0cc, BIT(18), 0);
  566. static const char * const ir_parents[] = { "osc24M", "pll-periph0",
  567. "pll-periph1", "osc32k" };
  568. static SUNXI_CCU_MP_WITH_MUX_GATE(ir0_clk, "ir0", ir_parents, 0x0d0,
  569. 0, 4, /* M */
  570. 16, 2, /* P */
  571. 24, 2, /* mux */
  572. BIT(31), /* gate */
  573. 0);
  574. static SUNXI_CCU_MP_WITH_MUX_GATE(ir1_clk, "ir1", ir_parents, 0x0d4,
  575. 0, 4, /* M */
  576. 16, 2, /* P */
  577. 24, 2, /* mux */
  578. BIT(31), /* gate */
  579. 0);
  580. static const char * const dram_parents[] = { "pll-ddr0", "pll-ddr1" };
  581. static SUNXI_CCU_M_WITH_MUX(dram_clk, "dram", dram_parents,
  582. 0x0f4, 0, 2, 20, 2, CLK_IS_CRITICAL);
  583. static SUNXI_CCU_GATE(dram_ve_clk, "dram-ve", "dram",
  584. 0x100, BIT(0), 0);
  585. static SUNXI_CCU_GATE(dram_csi0_clk, "dram-csi0", "dram",
  586. 0x100, BIT(1), 0);
  587. static SUNXI_CCU_GATE(dram_csi1_clk, "dram-csi1", "dram",
  588. 0x100, BIT(2), 0);
  589. static SUNXI_CCU_GATE(dram_ts_clk, "dram-ts", "dram",
  590. 0x100, BIT(3), 0);
  591. static SUNXI_CCU_GATE(dram_tvd_clk, "dram-tvd", "dram",
  592. 0x100, BIT(4), 0);
  593. static SUNXI_CCU_GATE(dram_mp_clk, "dram-mp", "dram",
  594. 0x100, BIT(5), 0);
  595. static SUNXI_CCU_GATE(dram_deinterlace_clk, "dram-deinterlace", "dram",
  596. 0x100, BIT(6), 0);
  597. static const char * const de_parents[] = { "pll-periph0-2x", "pll-de" };
  598. static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents,
  599. 0x104, 0, 4, 24, 3, BIT(31),
  600. CLK_SET_RATE_PARENT);
  601. static SUNXI_CCU_M_WITH_MUX_GATE(mp_clk, "mp", de_parents,
  602. 0x108, 0, 4, 24, 3, BIT(31), 0);
  603. static const char * const tcon_parents[] = { "pll-video0", "pll-video1",
  604. "pll-video0-2x", "pll-video1-2x",
  605. "pll-mipi" };
  606. static SUNXI_CCU_MUX_WITH_GATE(tcon_lcd0_clk, "tcon-lcd0", tcon_parents,
  607. 0x110, 24, 3, BIT(31), CLK_SET_RATE_PARENT);
  608. static SUNXI_CCU_MUX_WITH_GATE(tcon_lcd1_clk, "tcon-lcd1", tcon_parents,
  609. 0x114, 24, 3, BIT(31), CLK_SET_RATE_PARENT);
  610. static SUNXI_CCU_M_WITH_MUX_GATE(tcon_tv0_clk, "tcon-tv0", tcon_parents,
  611. 0x118, 0, 4, 24, 3, BIT(31),
  612. CLK_SET_RATE_PARENT);
  613. static SUNXI_CCU_M_WITH_MUX_GATE(tcon_tv1_clk, "tcon-tv1", tcon_parents,
  614. 0x11c, 0, 4, 24, 3, BIT(31),
  615. CLK_SET_RATE_PARENT);
  616. static const char * const deinterlace_parents[] = { "pll-periph0",
  617. "pll-periph1" };
  618. static SUNXI_CCU_M_WITH_MUX_GATE(deinterlace_clk, "deinterlace",
  619. deinterlace_parents, 0x124, 0, 4, 24, 3,
  620. BIT(31), 0);
  621. static const char * const csi_mclk_parents[] = { "osc24M", "pll-video1",
  622. "pll-periph1" };
  623. static SUNXI_CCU_M_WITH_MUX_GATE(csi1_mclk_clk, "csi1-mclk", csi_mclk_parents,
  624. 0x130, 0, 5, 8, 3, BIT(15), 0);
  625. static const char * const csi_sclk_parents[] = { "pll-periph0", "pll-periph1" };
  626. static SUNXI_CCU_M_WITH_MUX_GATE(csi_sclk_clk, "csi-sclk", csi_sclk_parents,
  627. 0x134, 16, 4, 24, 3, BIT(31), 0);
  628. static SUNXI_CCU_M_WITH_MUX_GATE(csi0_mclk_clk, "csi0-mclk", csi_mclk_parents,
  629. 0x134, 0, 5, 8, 3, BIT(15), 0);
  630. static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve",
  631. 0x13c, 16, 3, BIT(31), CLK_SET_RATE_PARENT);
  632. static SUNXI_CCU_GATE(codec_clk, "codec", "pll-audio",
  633. 0x140, BIT(31), CLK_SET_RATE_PARENT);
  634. static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M",
  635. 0x144, BIT(31), 0);
  636. static const char * const hdmi_parents[] = { "pll-video0", "pll-video1" };
  637. static SUNXI_CCU_M_WITH_MUX_GATE(hdmi_clk, "hdmi", hdmi_parents,
  638. 0x150, 0, 4, 24, 2, BIT(31),
  639. CLK_SET_RATE_PARENT);
  640. static SUNXI_CCU_GATE(hdmi_slow_clk, "hdmi-slow", "osc24M",
  641. 0x154, BIT(31), 0);
  642. /*
  643. * In the SoC's user manual, the P factor is mentioned, but not used in
  644. * the frequency formula.
  645. *
  646. * Here the factor is included, according to the BSP kernel source,
  647. * which contains the P factor of this clock.
  648. */
  649. static const char * const mbus_parents[] = { "osc24M", "pll-periph0-2x",
  650. "pll-ddr0" };
  651. static SUNXI_CCU_MP_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents, 0x15c,
  652. 0, 4, /* M */
  653. 16, 2, /* P */
  654. 24, 2, /* mux */
  655. BIT(31), /* gate */
  656. CLK_IS_CRITICAL);
  657. static const char * const dsi_dphy_parents[] = { "pll-video0", "pll-video1",
  658. "pll-periph0" };
  659. static SUNXI_CCU_M_WITH_MUX_GATE(dsi_dphy_clk, "dsi-dphy", dsi_dphy_parents,
  660. 0x168, 0, 4, 8, 2, BIT(15), 0);
  661. static SUNXI_CCU_M_WITH_MUX_GATE(tve0_clk, "tve0", tcon_parents,
  662. 0x180, 0, 4, 24, 3, BIT(31), 0);
  663. static SUNXI_CCU_M_WITH_MUX_GATE(tve1_clk, "tve1", tcon_parents,
  664. 0x184, 0, 4, 24, 3, BIT(31), 0);
  665. static const char * const tvd_parents[] = { "pll-video0", "pll-video1",
  666. "pll-video0-2x", "pll-video1-2x" };
  667. static SUNXI_CCU_M_WITH_MUX_GATE(tvd0_clk, "tvd0", tvd_parents,
  668. 0x188, 0, 4, 24, 3, BIT(31), 0);
  669. static SUNXI_CCU_M_WITH_MUX_GATE(tvd1_clk, "tvd1", tvd_parents,
  670. 0x18c, 0, 4, 24, 3, BIT(31), 0);
  671. static SUNXI_CCU_M_WITH_MUX_GATE(tvd2_clk, "tvd2", tvd_parents,
  672. 0x190, 0, 4, 24, 3, BIT(31), 0);
  673. static SUNXI_CCU_M_WITH_MUX_GATE(tvd3_clk, "tvd3", tvd_parents,
  674. 0x194, 0, 4, 24, 3, BIT(31), 0);
  675. static SUNXI_CCU_M_WITH_GATE(gpu_clk, "gpu", "pll-gpu",
  676. 0x1a0, 0, 3, BIT(31), CLK_SET_RATE_PARENT);
  677. static const char * const out_parents[] = { "osc24M", "osc32k", "osc24M" };
  678. static const struct ccu_mux_fixed_prediv out_predivs[] = {
  679. { .index = 0, .div = 750, },
  680. };
  681. static struct ccu_mp outa_clk = {
  682. .enable = BIT(31),
  683. .m = _SUNXI_CCU_DIV(8, 5),
  684. .p = _SUNXI_CCU_DIV(20, 2),
  685. .mux = {
  686. .shift = 24,
  687. .width = 2,
  688. .fixed_predivs = out_predivs,
  689. .n_predivs = ARRAY_SIZE(out_predivs),
  690. },
  691. .common = {
  692. .reg = 0x1f0,
  693. .features = CCU_FEATURE_FIXED_PREDIV,
  694. .hw.init = CLK_HW_INIT_PARENTS("outa", out_parents,
  695. &ccu_mp_ops, 0),
  696. }
  697. };
  698. static struct ccu_mp outb_clk = {
  699. .enable = BIT(31),
  700. .m = _SUNXI_CCU_DIV(8, 5),
  701. .p = _SUNXI_CCU_DIV(20, 2),
  702. .mux = {
  703. .shift = 24,
  704. .width = 2,
  705. .fixed_predivs = out_predivs,
  706. .n_predivs = ARRAY_SIZE(out_predivs),
  707. },
  708. .common = {
  709. .reg = 0x1f4,
  710. .features = CCU_FEATURE_FIXED_PREDIV,
  711. .hw.init = CLK_HW_INIT_PARENTS("outb", out_parents,
  712. &ccu_mp_ops, 0),
  713. }
  714. };
  715. static struct ccu_common *sun8i_r40_ccu_clks[] = {
  716. &pll_cpu_clk.common,
  717. &pll_audio_base_clk.common,
  718. &pll_video0_clk.common,
  719. &pll_ve_clk.common,
  720. &pll_ddr0_clk.common,
  721. &pll_periph0_clk.common,
  722. &pll_periph0_sata_clk.common,
  723. &pll_periph1_clk.common,
  724. &pll_video1_clk.common,
  725. &pll_sata_clk.common,
  726. &pll_sata_out_clk.common,
  727. &pll_gpu_clk.common,
  728. &pll_mipi_clk.common,
  729. &pll_de_clk.common,
  730. &pll_ddr1_clk.common,
  731. &cpu_clk.common,
  732. &axi_clk.common,
  733. &ahb1_clk.common,
  734. &apb1_clk.common,
  735. &apb2_clk.common,
  736. &bus_mipi_dsi_clk.common,
  737. &bus_ce_clk.common,
  738. &bus_dma_clk.common,
  739. &bus_mmc0_clk.common,
  740. &bus_mmc1_clk.common,
  741. &bus_mmc2_clk.common,
  742. &bus_mmc3_clk.common,
  743. &bus_nand_clk.common,
  744. &bus_dram_clk.common,
  745. &bus_emac_clk.common,
  746. &bus_ts_clk.common,
  747. &bus_hstimer_clk.common,
  748. &bus_spi0_clk.common,
  749. &bus_spi1_clk.common,
  750. &bus_spi2_clk.common,
  751. &bus_spi3_clk.common,
  752. &bus_sata_clk.common,
  753. &bus_otg_clk.common,
  754. &bus_ehci0_clk.common,
  755. &bus_ehci1_clk.common,
  756. &bus_ehci2_clk.common,
  757. &bus_ohci0_clk.common,
  758. &bus_ohci1_clk.common,
  759. &bus_ohci2_clk.common,
  760. &bus_ve_clk.common,
  761. &bus_mp_clk.common,
  762. &bus_deinterlace_clk.common,
  763. &bus_csi0_clk.common,
  764. &bus_csi1_clk.common,
  765. &bus_hdmi0_clk.common,
  766. &bus_hdmi1_clk.common,
  767. &bus_de_clk.common,
  768. &bus_tve0_clk.common,
  769. &bus_tve1_clk.common,
  770. &bus_tve_top_clk.common,
  771. &bus_gmac_clk.common,
  772. &bus_gpu_clk.common,
  773. &bus_tvd0_clk.common,
  774. &bus_tvd1_clk.common,
  775. &bus_tvd2_clk.common,
  776. &bus_tvd3_clk.common,
  777. &bus_tvd_top_clk.common,
  778. &bus_tcon_lcd0_clk.common,
  779. &bus_tcon_lcd1_clk.common,
  780. &bus_tcon_tv0_clk.common,
  781. &bus_tcon_tv1_clk.common,
  782. &bus_tcon_top_clk.common,
  783. &bus_codec_clk.common,
  784. &bus_spdif_clk.common,
  785. &bus_ac97_clk.common,
  786. &bus_pio_clk.common,
  787. &bus_ir0_clk.common,
  788. &bus_ir1_clk.common,
  789. &bus_ths_clk.common,
  790. &bus_keypad_clk.common,
  791. &bus_i2s0_clk.common,
  792. &bus_i2s1_clk.common,
  793. &bus_i2s2_clk.common,
  794. &bus_i2c0_clk.common,
  795. &bus_i2c1_clk.common,
  796. &bus_i2c2_clk.common,
  797. &bus_i2c3_clk.common,
  798. &bus_can_clk.common,
  799. &bus_scr_clk.common,
  800. &bus_ps20_clk.common,
  801. &bus_ps21_clk.common,
  802. &bus_i2c4_clk.common,
  803. &bus_uart0_clk.common,
  804. &bus_uart1_clk.common,
  805. &bus_uart2_clk.common,
  806. &bus_uart3_clk.common,
  807. &bus_uart4_clk.common,
  808. &bus_uart5_clk.common,
  809. &bus_uart6_clk.common,
  810. &bus_uart7_clk.common,
  811. &bus_dbg_clk.common,
  812. &ths_clk.common,
  813. &nand_clk.common,
  814. &mmc0_clk.common,
  815. &mmc1_clk.common,
  816. &mmc2_clk.common,
  817. &mmc3_clk.common,
  818. &ts_clk.common,
  819. &ce_clk.common,
  820. &spi0_clk.common,
  821. &spi1_clk.common,
  822. &spi2_clk.common,
  823. &spi3_clk.common,
  824. &i2s0_clk.common,
  825. &i2s1_clk.common,
  826. &i2s2_clk.common,
  827. &ac97_clk.common,
  828. &spdif_clk.common,
  829. &keypad_clk.common,
  830. &sata_clk.common,
  831. &usb_phy0_clk.common,
  832. &usb_phy1_clk.common,
  833. &usb_phy2_clk.common,
  834. &usb_ohci0_clk.common,
  835. &usb_ohci1_clk.common,
  836. &usb_ohci2_clk.common,
  837. &ir0_clk.common,
  838. &ir1_clk.common,
  839. &dram_clk.common,
  840. &dram_ve_clk.common,
  841. &dram_csi0_clk.common,
  842. &dram_csi1_clk.common,
  843. &dram_ts_clk.common,
  844. &dram_tvd_clk.common,
  845. &dram_mp_clk.common,
  846. &dram_deinterlace_clk.common,
  847. &de_clk.common,
  848. &mp_clk.common,
  849. &tcon_lcd0_clk.common,
  850. &tcon_lcd1_clk.common,
  851. &tcon_tv0_clk.common,
  852. &tcon_tv1_clk.common,
  853. &deinterlace_clk.common,
  854. &csi1_mclk_clk.common,
  855. &csi_sclk_clk.common,
  856. &csi0_mclk_clk.common,
  857. &ve_clk.common,
  858. &codec_clk.common,
  859. &avs_clk.common,
  860. &hdmi_clk.common,
  861. &hdmi_slow_clk.common,
  862. &mbus_clk.common,
  863. &dsi_dphy_clk.common,
  864. &tve0_clk.common,
  865. &tve1_clk.common,
  866. &tvd0_clk.common,
  867. &tvd1_clk.common,
  868. &tvd2_clk.common,
  869. &tvd3_clk.common,
  870. &gpu_clk.common,
  871. &outa_clk.common,
  872. &outb_clk.common,
  873. };
  874. /* Fixed Factor clocks */
  875. static CLK_FIXED_FACTOR(osc12M_clk, "osc12M", "osc24M", 2, 1, 0);
  876. /* We hardcode the divider to 4 for now */
  877. static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio",
  878. "pll-audio-base", 4, 1, CLK_SET_RATE_PARENT);
  879. static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x",
  880. "pll-audio-base", 2, 1, CLK_SET_RATE_PARENT);
  881. static CLK_FIXED_FACTOR(pll_audio_4x_clk, "pll-audio-4x",
  882. "pll-audio-base", 1, 1, CLK_SET_RATE_PARENT);
  883. static CLK_FIXED_FACTOR(pll_audio_8x_clk, "pll-audio-8x",
  884. "pll-audio-base", 1, 2, CLK_SET_RATE_PARENT);
  885. static CLK_FIXED_FACTOR(pll_periph0_2x_clk, "pll-periph0-2x",
  886. "pll-periph0", 1, 2, 0);
  887. static CLK_FIXED_FACTOR(pll_periph1_2x_clk, "pll-periph1-2x",
  888. "pll-periph1", 1, 2, 0);
  889. static CLK_FIXED_FACTOR(pll_video0_2x_clk, "pll-video0-2x",
  890. "pll-video0", 1, 2, 0);
  891. static CLK_FIXED_FACTOR(pll_video1_2x_clk, "pll-video1-2x",
  892. "pll-video1", 1, 2, 0);
  893. static struct clk_hw_onecell_data sun8i_r40_hw_clks = {
  894. .hws = {
  895. [CLK_OSC_12M] = &osc12M_clk.hw,
  896. [CLK_PLL_CPU] = &pll_cpu_clk.common.hw,
  897. [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
  898. [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
  899. [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
  900. [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
  901. [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw,
  902. [CLK_PLL_VIDEO0] = &pll_video0_clk.common.hw,
  903. [CLK_PLL_VIDEO0_2X] = &pll_video0_2x_clk.hw,
  904. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  905. [CLK_PLL_DDR0] = &pll_ddr0_clk.common.hw,
  906. [CLK_PLL_PERIPH0] = &pll_periph0_clk.common.hw,
  907. [CLK_PLL_PERIPH0_SATA] = &pll_periph0_sata_clk.common.hw,
  908. [CLK_PLL_PERIPH0_2X] = &pll_periph0_2x_clk.hw,
  909. [CLK_PLL_PERIPH1] = &pll_periph1_clk.common.hw,
  910. [CLK_PLL_PERIPH1_2X] = &pll_periph1_2x_clk.hw,
  911. [CLK_PLL_VIDEO1] = &pll_video1_clk.common.hw,
  912. [CLK_PLL_VIDEO1_2X] = &pll_video1_2x_clk.hw,
  913. [CLK_PLL_SATA] = &pll_sata_clk.common.hw,
  914. [CLK_PLL_SATA_OUT] = &pll_sata_out_clk.common.hw,
  915. [CLK_PLL_GPU] = &pll_gpu_clk.common.hw,
  916. [CLK_PLL_MIPI] = &pll_mipi_clk.common.hw,
  917. [CLK_PLL_DE] = &pll_de_clk.common.hw,
  918. [CLK_PLL_DDR1] = &pll_ddr1_clk.common.hw,
  919. [CLK_CPU] = &cpu_clk.common.hw,
  920. [CLK_AXI] = &axi_clk.common.hw,
  921. [CLK_AHB1] = &ahb1_clk.common.hw,
  922. [CLK_APB1] = &apb1_clk.common.hw,
  923. [CLK_APB2] = &apb2_clk.common.hw,
  924. [CLK_BUS_MIPI_DSI] = &bus_mipi_dsi_clk.common.hw,
  925. [CLK_BUS_CE] = &bus_ce_clk.common.hw,
  926. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  927. [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw,
  928. [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw,
  929. [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw,
  930. [CLK_BUS_MMC3] = &bus_mmc3_clk.common.hw,
  931. [CLK_BUS_NAND] = &bus_nand_clk.common.hw,
  932. [CLK_BUS_DRAM] = &bus_dram_clk.common.hw,
  933. [CLK_BUS_EMAC] = &bus_emac_clk.common.hw,
  934. [CLK_BUS_TS] = &bus_ts_clk.common.hw,
  935. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  936. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  937. [CLK_BUS_SPI1] = &bus_spi1_clk.common.hw,
  938. [CLK_BUS_SPI2] = &bus_spi2_clk.common.hw,
  939. [CLK_BUS_SPI3] = &bus_spi3_clk.common.hw,
  940. [CLK_BUS_SATA] = &bus_sata_clk.common.hw,
  941. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  942. [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw,
  943. [CLK_BUS_EHCI1] = &bus_ehci1_clk.common.hw,
  944. [CLK_BUS_EHCI2] = &bus_ehci2_clk.common.hw,
  945. [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw,
  946. [CLK_BUS_OHCI1] = &bus_ohci1_clk.common.hw,
  947. [CLK_BUS_OHCI2] = &bus_ohci2_clk.common.hw,
  948. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  949. [CLK_BUS_MP] = &bus_mp_clk.common.hw,
  950. [CLK_BUS_DEINTERLACE] = &bus_deinterlace_clk.common.hw,
  951. [CLK_BUS_CSI0] = &bus_csi0_clk.common.hw,
  952. [CLK_BUS_CSI1] = &bus_csi1_clk.common.hw,
  953. [CLK_BUS_HDMI0] = &bus_hdmi0_clk.common.hw,
  954. [CLK_BUS_HDMI1] = &bus_hdmi1_clk.common.hw,
  955. [CLK_BUS_DE] = &bus_de_clk.common.hw,
  956. [CLK_BUS_TVE0] = &bus_tve0_clk.common.hw,
  957. [CLK_BUS_TVE1] = &bus_tve1_clk.common.hw,
  958. [CLK_BUS_TVE_TOP] = &bus_tve_top_clk.common.hw,
  959. [CLK_BUS_GMAC] = &bus_gmac_clk.common.hw,
  960. [CLK_BUS_GPU] = &bus_gpu_clk.common.hw,
  961. [CLK_BUS_TVD0] = &bus_tvd0_clk.common.hw,
  962. [CLK_BUS_TVD1] = &bus_tvd1_clk.common.hw,
  963. [CLK_BUS_TVD2] = &bus_tvd2_clk.common.hw,
  964. [CLK_BUS_TVD3] = &bus_tvd3_clk.common.hw,
  965. [CLK_BUS_TVD_TOP] = &bus_tvd_top_clk.common.hw,
  966. [CLK_BUS_TCON_LCD0] = &bus_tcon_lcd0_clk.common.hw,
  967. [CLK_BUS_TCON_LCD1] = &bus_tcon_lcd1_clk.common.hw,
  968. [CLK_BUS_TCON_TV0] = &bus_tcon_tv0_clk.common.hw,
  969. [CLK_BUS_TCON_TV1] = &bus_tcon_tv1_clk.common.hw,
  970. [CLK_BUS_TCON_TOP] = &bus_tcon_top_clk.common.hw,
  971. [CLK_BUS_CODEC] = &bus_codec_clk.common.hw,
  972. [CLK_BUS_SPDIF] = &bus_spdif_clk.common.hw,
  973. [CLK_BUS_AC97] = &bus_ac97_clk.common.hw,
  974. [CLK_BUS_PIO] = &bus_pio_clk.common.hw,
  975. [CLK_BUS_IR0] = &bus_ir0_clk.common.hw,
  976. [CLK_BUS_IR1] = &bus_ir1_clk.common.hw,
  977. [CLK_BUS_THS] = &bus_ths_clk.common.hw,
  978. [CLK_BUS_KEYPAD] = &bus_keypad_clk.common.hw,
  979. [CLK_BUS_I2S0] = &bus_i2s0_clk.common.hw,
  980. [CLK_BUS_I2S1] = &bus_i2s1_clk.common.hw,
  981. [CLK_BUS_I2S2] = &bus_i2s2_clk.common.hw,
  982. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  983. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  984. [CLK_BUS_I2C2] = &bus_i2c2_clk.common.hw,
  985. [CLK_BUS_I2C3] = &bus_i2c3_clk.common.hw,
  986. [CLK_BUS_CAN] = &bus_can_clk.common.hw,
  987. [CLK_BUS_SCR] = &bus_scr_clk.common.hw,
  988. [CLK_BUS_PS20] = &bus_ps20_clk.common.hw,
  989. [CLK_BUS_PS21] = &bus_ps21_clk.common.hw,
  990. [CLK_BUS_I2C4] = &bus_i2c4_clk.common.hw,
  991. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  992. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  993. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  994. [CLK_BUS_UART3] = &bus_uart3_clk.common.hw,
  995. [CLK_BUS_UART4] = &bus_uart4_clk.common.hw,
  996. [CLK_BUS_UART5] = &bus_uart5_clk.common.hw,
  997. [CLK_BUS_UART6] = &bus_uart6_clk.common.hw,
  998. [CLK_BUS_UART7] = &bus_uart7_clk.common.hw,
  999. [CLK_BUS_DBG] = &bus_dbg_clk.common.hw,
  1000. [CLK_THS] = &ths_clk.common.hw,
  1001. [CLK_NAND] = &nand_clk.common.hw,
  1002. [CLK_MMC0] = &mmc0_clk.common.hw,
  1003. [CLK_MMC1] = &mmc1_clk.common.hw,
  1004. [CLK_MMC2] = &mmc2_clk.common.hw,
  1005. [CLK_MMC3] = &mmc3_clk.common.hw,
  1006. [CLK_TS] = &ts_clk.common.hw,
  1007. [CLK_CE] = &ce_clk.common.hw,
  1008. [CLK_SPI0] = &spi0_clk.common.hw,
  1009. [CLK_SPI1] = &spi1_clk.common.hw,
  1010. [CLK_SPI2] = &spi2_clk.common.hw,
  1011. [CLK_SPI3] = &spi3_clk.common.hw,
  1012. [CLK_I2S0] = &i2s0_clk.common.hw,
  1013. [CLK_I2S1] = &i2s1_clk.common.hw,
  1014. [CLK_I2S2] = &i2s2_clk.common.hw,
  1015. [CLK_AC97] = &ac97_clk.common.hw,
  1016. [CLK_SPDIF] = &spdif_clk.common.hw,
  1017. [CLK_KEYPAD] = &keypad_clk.common.hw,
  1018. [CLK_SATA] = &sata_clk.common.hw,
  1019. [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
  1020. [CLK_USB_PHY1] = &usb_phy1_clk.common.hw,
  1021. [CLK_USB_PHY2] = &usb_phy2_clk.common.hw,
  1022. [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
  1023. [CLK_USB_OHCI1] = &usb_ohci1_clk.common.hw,
  1024. [CLK_USB_OHCI2] = &usb_ohci2_clk.common.hw,
  1025. [CLK_IR0] = &ir0_clk.common.hw,
  1026. [CLK_IR1] = &ir1_clk.common.hw,
  1027. [CLK_DRAM] = &dram_clk.common.hw,
  1028. [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
  1029. [CLK_DRAM_CSI0] = &dram_csi0_clk.common.hw,
  1030. [CLK_DRAM_CSI1] = &dram_csi1_clk.common.hw,
  1031. [CLK_DRAM_TS] = &dram_ts_clk.common.hw,
  1032. [CLK_DRAM_TVD] = &dram_tvd_clk.common.hw,
  1033. [CLK_DRAM_MP] = &dram_mp_clk.common.hw,
  1034. [CLK_DRAM_DEINTERLACE] = &dram_deinterlace_clk.common.hw,
  1035. [CLK_DE] = &de_clk.common.hw,
  1036. [CLK_MP] = &mp_clk.common.hw,
  1037. [CLK_TCON_LCD0] = &tcon_lcd0_clk.common.hw,
  1038. [CLK_TCON_LCD1] = &tcon_lcd1_clk.common.hw,
  1039. [CLK_TCON_TV0] = &tcon_tv0_clk.common.hw,
  1040. [CLK_TCON_TV1] = &tcon_tv1_clk.common.hw,
  1041. [CLK_DEINTERLACE] = &deinterlace_clk.common.hw,
  1042. [CLK_CSI1_MCLK] = &csi1_mclk_clk.common.hw,
  1043. [CLK_CSI_SCLK] = &csi_sclk_clk.common.hw,
  1044. [CLK_CSI0_MCLK] = &csi0_mclk_clk.common.hw,
  1045. [CLK_VE] = &ve_clk.common.hw,
  1046. [CLK_CODEC] = &codec_clk.common.hw,
  1047. [CLK_AVS] = &avs_clk.common.hw,
  1048. [CLK_HDMI] = &hdmi_clk.common.hw,
  1049. [CLK_HDMI_SLOW] = &hdmi_slow_clk.common.hw,
  1050. [CLK_MBUS] = &mbus_clk.common.hw,
  1051. [CLK_DSI_DPHY] = &dsi_dphy_clk.common.hw,
  1052. [CLK_TVE0] = &tve0_clk.common.hw,
  1053. [CLK_TVE1] = &tve1_clk.common.hw,
  1054. [CLK_TVD0] = &tvd0_clk.common.hw,
  1055. [CLK_TVD1] = &tvd1_clk.common.hw,
  1056. [CLK_TVD2] = &tvd2_clk.common.hw,
  1057. [CLK_TVD3] = &tvd3_clk.common.hw,
  1058. [CLK_GPU] = &gpu_clk.common.hw,
  1059. [CLK_OUTA] = &outa_clk.common.hw,
  1060. [CLK_OUTB] = &outb_clk.common.hw,
  1061. },
  1062. .num = CLK_NUMBER,
  1063. };
  1064. static struct ccu_reset_map sun8i_r40_ccu_resets[] = {
  1065. [RST_USB_PHY0] = { 0x0cc, BIT(0) },
  1066. [RST_USB_PHY1] = { 0x0cc, BIT(1) },
  1067. [RST_USB_PHY2] = { 0x0cc, BIT(2) },
  1068. [RST_DRAM] = { 0x0f4, BIT(31) },
  1069. [RST_MBUS] = { 0x0fc, BIT(31) },
  1070. [RST_BUS_MIPI_DSI] = { 0x2c0, BIT(1) },
  1071. [RST_BUS_CE] = { 0x2c0, BIT(5) },
  1072. [RST_BUS_DMA] = { 0x2c0, BIT(6) },
  1073. [RST_BUS_MMC0] = { 0x2c0, BIT(8) },
  1074. [RST_BUS_MMC1] = { 0x2c0, BIT(9) },
  1075. [RST_BUS_MMC2] = { 0x2c0, BIT(10) },
  1076. [RST_BUS_MMC3] = { 0x2c0, BIT(11) },
  1077. [RST_BUS_NAND] = { 0x2c0, BIT(13) },
  1078. [RST_BUS_DRAM] = { 0x2c0, BIT(14) },
  1079. [RST_BUS_EMAC] = { 0x2c0, BIT(17) },
  1080. [RST_BUS_TS] = { 0x2c0, BIT(18) },
  1081. [RST_BUS_HSTIMER] = { 0x2c0, BIT(19) },
  1082. [RST_BUS_SPI0] = { 0x2c0, BIT(20) },
  1083. [RST_BUS_SPI1] = { 0x2c0, BIT(21) },
  1084. [RST_BUS_SPI2] = { 0x2c0, BIT(22) },
  1085. [RST_BUS_SPI3] = { 0x2c0, BIT(23) },
  1086. [RST_BUS_SATA] = { 0x2c0, BIT(24) },
  1087. [RST_BUS_OTG] = { 0x2c0, BIT(25) },
  1088. [RST_BUS_EHCI0] = { 0x2c0, BIT(26) },
  1089. [RST_BUS_EHCI1] = { 0x2c0, BIT(27) },
  1090. [RST_BUS_EHCI2] = { 0x2c0, BIT(28) },
  1091. [RST_BUS_OHCI0] = { 0x2c0, BIT(29) },
  1092. [RST_BUS_OHCI1] = { 0x2c0, BIT(30) },
  1093. [RST_BUS_OHCI2] = { 0x2c0, BIT(31) },
  1094. [RST_BUS_VE] = { 0x2c4, BIT(0) },
  1095. [RST_BUS_MP] = { 0x2c4, BIT(2) },
  1096. [RST_BUS_DEINTERLACE] = { 0x2c4, BIT(5) },
  1097. [RST_BUS_CSI0] = { 0x2c4, BIT(8) },
  1098. [RST_BUS_CSI1] = { 0x2c4, BIT(9) },
  1099. [RST_BUS_HDMI0] = { 0x2c4, BIT(10) },
  1100. [RST_BUS_HDMI1] = { 0x2c4, BIT(11) },
  1101. [RST_BUS_DE] = { 0x2c4, BIT(12) },
  1102. [RST_BUS_TVE0] = { 0x2c4, BIT(13) },
  1103. [RST_BUS_TVE1] = { 0x2c4, BIT(14) },
  1104. [RST_BUS_TVE_TOP] = { 0x2c4, BIT(15) },
  1105. [RST_BUS_GMAC] = { 0x2c4, BIT(17) },
  1106. [RST_BUS_GPU] = { 0x2c4, BIT(20) },
  1107. [RST_BUS_TVD0] = { 0x2c4, BIT(21) },
  1108. [RST_BUS_TVD1] = { 0x2c4, BIT(22) },
  1109. [RST_BUS_TVD2] = { 0x2c4, BIT(23) },
  1110. [RST_BUS_TVD3] = { 0x2c4, BIT(24) },
  1111. [RST_BUS_TVD_TOP] = { 0x2c4, BIT(25) },
  1112. [RST_BUS_TCON_LCD0] = { 0x2c4, BIT(26) },
  1113. [RST_BUS_TCON_LCD1] = { 0x2c4, BIT(27) },
  1114. [RST_BUS_TCON_TV0] = { 0x2c4, BIT(28) },
  1115. [RST_BUS_TCON_TV1] = { 0x2c4, BIT(29) },
  1116. [RST_BUS_TCON_TOP] = { 0x2c4, BIT(30) },
  1117. [RST_BUS_DBG] = { 0x2c4, BIT(31) },
  1118. [RST_BUS_LVDS] = { 0x2c8, BIT(0) },
  1119. [RST_BUS_CODEC] = { 0x2d0, BIT(0) },
  1120. [RST_BUS_SPDIF] = { 0x2d0, BIT(1) },
  1121. [RST_BUS_AC97] = { 0x2d0, BIT(2) },
  1122. [RST_BUS_IR0] = { 0x2d0, BIT(6) },
  1123. [RST_BUS_IR1] = { 0x2d0, BIT(7) },
  1124. [RST_BUS_THS] = { 0x2d0, BIT(8) },
  1125. [RST_BUS_KEYPAD] = { 0x2d0, BIT(10) },
  1126. [RST_BUS_I2S0] = { 0x2d0, BIT(12) },
  1127. [RST_BUS_I2S1] = { 0x2d0, BIT(13) },
  1128. [RST_BUS_I2S2] = { 0x2d0, BIT(14) },
  1129. [RST_BUS_I2C0] = { 0x2d8, BIT(0) },
  1130. [RST_BUS_I2C1] = { 0x2d8, BIT(1) },
  1131. [RST_BUS_I2C2] = { 0x2d8, BIT(2) },
  1132. [RST_BUS_I2C3] = { 0x2d8, BIT(3) },
  1133. [RST_BUS_CAN] = { 0x2d8, BIT(4) },
  1134. [RST_BUS_SCR] = { 0x2d8, BIT(5) },
  1135. [RST_BUS_PS20] = { 0x2d8, BIT(6) },
  1136. [RST_BUS_PS21] = { 0x2d8, BIT(7) },
  1137. [RST_BUS_I2C4] = { 0x2d8, BIT(15) },
  1138. [RST_BUS_UART0] = { 0x2d8, BIT(16) },
  1139. [RST_BUS_UART1] = { 0x2d8, BIT(17) },
  1140. [RST_BUS_UART2] = { 0x2d8, BIT(18) },
  1141. [RST_BUS_UART3] = { 0x2d8, BIT(19) },
  1142. [RST_BUS_UART4] = { 0x2d8, BIT(20) },
  1143. [RST_BUS_UART5] = { 0x2d8, BIT(21) },
  1144. [RST_BUS_UART6] = { 0x2d8, BIT(22) },
  1145. [RST_BUS_UART7] = { 0x2d8, BIT(23) },
  1146. };
  1147. static const struct sunxi_ccu_desc sun8i_r40_ccu_desc = {
  1148. .ccu_clks = sun8i_r40_ccu_clks,
  1149. .num_ccu_clks = ARRAY_SIZE(sun8i_r40_ccu_clks),
  1150. .hw_clks = &sun8i_r40_hw_clks,
  1151. .resets = sun8i_r40_ccu_resets,
  1152. .num_resets = ARRAY_SIZE(sun8i_r40_ccu_resets),
  1153. };
  1154. static struct ccu_pll_nb sun8i_r40_pll_cpu_nb = {
  1155. .common = &pll_cpu_clk.common,
  1156. /* copy from pll_cpu_clk */
  1157. .enable = BIT(31),
  1158. .lock = BIT(28),
  1159. };
  1160. static struct ccu_mux_nb sun8i_r40_cpu_nb = {
  1161. .common = &cpu_clk.common,
  1162. .cm = &cpu_clk.mux,
  1163. .delay_us = 1, /* > 8 clock cycles at 24 MHz */
  1164. .bypass_index = 1, /* index of 24 MHz oscillator */
  1165. };
  1166. /*
  1167. * Add a regmap for the GMAC driver (dwmac-sun8i) to access the
  1168. * GMAC configuration register.
  1169. * Only this register is allowed to be written, in order to
  1170. * prevent overriding critical clock configuration.
  1171. */
  1172. #define SUN8I_R40_GMAC_CFG_REG 0x164
  1173. static bool sun8i_r40_ccu_regmap_accessible_reg(struct device *dev,
  1174. unsigned int reg)
  1175. {
  1176. if (reg == SUN8I_R40_GMAC_CFG_REG)
  1177. return true;
  1178. return false;
  1179. }
  1180. static struct regmap_config sun8i_r40_ccu_regmap_config = {
  1181. .reg_bits = 32,
  1182. .val_bits = 32,
  1183. .reg_stride = 4,
  1184. .max_register = 0x320, /* PLL_LOCK_CTRL_REG */
  1185. /* other devices have no business accessing other registers */
  1186. .readable_reg = sun8i_r40_ccu_regmap_accessible_reg,
  1187. .writeable_reg = sun8i_r40_ccu_regmap_accessible_reg,
  1188. };
  1189. static int sun8i_r40_ccu_probe(struct platform_device *pdev)
  1190. {
  1191. struct resource *res;
  1192. struct regmap *regmap;
  1193. void __iomem *reg;
  1194. u32 val;
  1195. int ret;
  1196. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1197. reg = devm_ioremap_resource(&pdev->dev, res);
  1198. if (IS_ERR(reg))
  1199. return PTR_ERR(reg);
  1200. /* Force the PLL-Audio-1x divider to 4 */
  1201. val = readl(reg + SUN8I_R40_PLL_AUDIO_REG);
  1202. val &= ~GENMASK(19, 16);
  1203. writel(val | (3 << 16), reg + SUN8I_R40_PLL_AUDIO_REG);
  1204. /* Force PLL-MIPI to MIPI mode */
  1205. val = readl(reg + SUN8I_R40_PLL_MIPI_REG);
  1206. val &= ~BIT(16);
  1207. writel(val, reg + SUN8I_R40_PLL_MIPI_REG);
  1208. /* Force OHCI 12M parent to 12M divided from 48M */
  1209. val = readl(reg + SUN8I_R40_USB_CLK_REG);
  1210. val &= ~GENMASK(25, 20);
  1211. writel(val, reg + SUN8I_R40_USB_CLK_REG);
  1212. regmap = devm_regmap_init_mmio(&pdev->dev, reg,
  1213. &sun8i_r40_ccu_regmap_config);
  1214. if (IS_ERR(regmap))
  1215. return PTR_ERR(regmap);
  1216. ret = sunxi_ccu_probe(pdev->dev.of_node, reg, &sun8i_r40_ccu_desc);
  1217. if (ret)
  1218. return ret;
  1219. /* Gate then ungate PLL CPU after any rate changes */
  1220. ccu_pll_notifier_register(&sun8i_r40_pll_cpu_nb);
  1221. /* Reparent CPU during PLL CPU rate changes */
  1222. ccu_mux_notifier_register(pll_cpu_clk.common.hw.clk,
  1223. &sun8i_r40_cpu_nb);
  1224. return 0;
  1225. }
  1226. static const struct of_device_id sun8i_r40_ccu_ids[] = {
  1227. { .compatible = "allwinner,sun8i-r40-ccu" },
  1228. { }
  1229. };
  1230. static struct platform_driver sun8i_r40_ccu_driver = {
  1231. .probe = sun8i_r40_ccu_probe,
  1232. .driver = {
  1233. .name = "sun8i-r40-ccu",
  1234. .of_match_table = sun8i_r40_ccu_ids,
  1235. },
  1236. };
  1237. builtin_platform_driver(sun8i_r40_ccu_driver);