ccu-sun8i-r40.c 44 KB

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