ccu-sun8i-v3s.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016 Icenowy Zheng <[email protected]>
  4. *
  5. * Based on ccu-sun8i-h3.c, which is:
  6. * Copyright (c) 2016 Maxime Ripard. All rights reserved.
  7. */
  8. #include <linux/clk-provider.h>
  9. #include <linux/io.h>
  10. #include <linux/module.h>
  11. #include <linux/of_device.h>
  12. #include <linux/platform_device.h>
  13. #include "ccu_common.h"
  14. #include "ccu_reset.h"
  15. #include "ccu_div.h"
  16. #include "ccu_gate.h"
  17. #include "ccu_mp.h"
  18. #include "ccu_mult.h"
  19. #include "ccu_nk.h"
  20. #include "ccu_nkm.h"
  21. #include "ccu_nkmp.h"
  22. #include "ccu_nm.h"
  23. #include "ccu_phase.h"
  24. #include "ccu-sun8i-v3s.h"
  25. static SUNXI_CCU_NKMP_WITH_GATE_LOCK(pll_cpu_clk, "pll-cpu",
  26. "osc24M", 0x000,
  27. 8, 5, /* N */
  28. 4, 2, /* K */
  29. 0, 2, /* M */
  30. 16, 2, /* P */
  31. BIT(31), /* gate */
  32. BIT(28), /* lock */
  33. 0);
  34. /*
  35. * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from
  36. * the base (2x, 4x and 8x), and one variable divider (the one true
  37. * pll audio).
  38. *
  39. * With sigma-delta modulation for fractional-N on the audio PLL,
  40. * we have to use specific dividers. This means the variable divider
  41. * can no longer be used, as the audio codec requests the exact clock
  42. * rates we support through this mechanism. So we now hard code the
  43. * variable divider to 1. This means the clock rates will no longer
  44. * match the clock names.
  45. */
  46. #define SUN8I_V3S_PLL_AUDIO_REG 0x008
  47. static struct ccu_sdm_setting pll_audio_sdm_table[] = {
  48. { .rate = 22579200, .pattern = 0xc0010d84, .m = 8, .n = 7 },
  49. { .rate = 24576000, .pattern = 0xc000ac02, .m = 14, .n = 14 },
  50. };
  51. static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
  52. "osc24M", 0x008,
  53. 8, 7, /* N */
  54. 0, 5, /* M */
  55. pll_audio_sdm_table, BIT(24),
  56. 0x284, BIT(31),
  57. BIT(31), /* gate */
  58. BIT(28), /* lock */
  59. CLK_SET_RATE_UNGATE);
  60. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video_clk, "pll-video",
  61. "osc24M", 0x0010,
  62. 8, 7, /* N */
  63. 0, 4, /* M */
  64. BIT(24), /* frac enable */
  65. BIT(25), /* frac select */
  66. 270000000, /* frac rate 0 */
  67. 297000000, /* frac rate 1 */
  68. BIT(31), /* gate */
  69. BIT(28), /* lock */
  70. 0);
  71. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve",
  72. "osc24M", 0x0018,
  73. 8, 7, /* N */
  74. 0, 4, /* M */
  75. BIT(24), /* frac enable */
  76. BIT(25), /* frac select */
  77. 270000000, /* frac rate 0 */
  78. 297000000, /* frac rate 1 */
  79. BIT(31), /* gate */
  80. BIT(28), /* lock */
  81. 0);
  82. static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr0_clk, "pll-ddr0",
  83. "osc24M", 0x020,
  84. 8, 5, /* N */
  85. 4, 2, /* K */
  86. 0, 2, /* M */
  87. BIT(31), /* gate */
  88. BIT(28), /* lock */
  89. 0);
  90. static SUNXI_CCU_NK_WITH_GATE_LOCK_POSTDIV(pll_periph0_clk, "pll-periph0",
  91. "osc24M", 0x028,
  92. 8, 5, /* N */
  93. 4, 2, /* K */
  94. BIT(31), /* gate */
  95. BIT(28), /* lock */
  96. 2, /* post-div */
  97. 0);
  98. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_isp_clk, "pll-isp",
  99. "osc24M", 0x002c,
  100. 8, 7, /* N */
  101. 0, 4, /* M */
  102. BIT(24), /* frac enable */
  103. BIT(25), /* frac select */
  104. 270000000, /* frac rate 0 */
  105. 297000000, /* frac rate 1 */
  106. BIT(31), /* gate */
  107. BIT(28), /* lock */
  108. 0);
  109. static SUNXI_CCU_NK_WITH_GATE_LOCK_POSTDIV(pll_periph1_clk, "pll-periph1",
  110. "osc24M", 0x044,
  111. 8, 5, /* N */
  112. 4, 2, /* K */
  113. BIT(31), /* gate */
  114. BIT(28), /* lock */
  115. 2, /* post-div */
  116. 0);
  117. static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_ddr1_clk, "pll-ddr1",
  118. "osc24M", 0x04c,
  119. 8, 7, /* N */
  120. 0, 2, /* M */
  121. BIT(31), /* gate */
  122. BIT(28), /* lock */
  123. 0);
  124. static const char * const cpu_parents[] = { "osc32k", "osc24M",
  125. "pll-cpu", "pll-cpu" };
  126. static SUNXI_CCU_MUX(cpu_clk, "cpu", cpu_parents,
  127. 0x050, 16, 2, CLK_IS_CRITICAL);
  128. static SUNXI_CCU_M(axi_clk, "axi", "cpu", 0x050, 0, 2, 0);
  129. static const char * const ahb1_parents[] = { "osc32k", "osc24M",
  130. "axi", "pll-periph0" };
  131. static const struct ccu_mux_var_prediv ahb1_predivs[] = {
  132. { .index = 3, .shift = 6, .width = 2 },
  133. };
  134. static struct ccu_div ahb1_clk = {
  135. .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
  136. .mux = {
  137. .shift = 12,
  138. .width = 2,
  139. .var_predivs = ahb1_predivs,
  140. .n_var_predivs = ARRAY_SIZE(ahb1_predivs),
  141. },
  142. .common = {
  143. .reg = 0x054,
  144. .features = CCU_FEATURE_VARIABLE_PREDIV,
  145. .hw.init = CLK_HW_INIT_PARENTS("ahb1",
  146. ahb1_parents,
  147. &ccu_div_ops,
  148. 0),
  149. },
  150. };
  151. static struct clk_div_table apb1_div_table[] = {
  152. { .val = 0, .div = 2 },
  153. { .val = 1, .div = 2 },
  154. { .val = 2, .div = 4 },
  155. { .val = 3, .div = 8 },
  156. { /* Sentinel */ },
  157. };
  158. static SUNXI_CCU_DIV_TABLE(apb1_clk, "apb1", "ahb1",
  159. 0x054, 8, 2, apb1_div_table, 0);
  160. static const char * const apb2_parents[] = { "osc32k", "osc24M",
  161. "pll-periph0", "pll-periph0" };
  162. static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", apb2_parents, 0x058,
  163. 0, 5, /* M */
  164. 16, 2, /* P */
  165. 24, 2, /* mux */
  166. 0);
  167. static const char * const ahb2_parents[] = { "ahb1", "pll-periph0" };
  168. static const struct ccu_mux_fixed_prediv ahb2_fixed_predivs[] = {
  169. { .index = 1, .div = 2 },
  170. };
  171. static struct ccu_mux ahb2_clk = {
  172. .mux = {
  173. .shift = 0,
  174. .width = 1,
  175. .fixed_predivs = ahb2_fixed_predivs,
  176. .n_predivs = ARRAY_SIZE(ahb2_fixed_predivs),
  177. },
  178. .common = {
  179. .reg = 0x05c,
  180. .features = CCU_FEATURE_FIXED_PREDIV,
  181. .hw.init = CLK_HW_INIT_PARENTS("ahb2",
  182. ahb2_parents,
  183. &ccu_mux_ops,
  184. 0),
  185. },
  186. };
  187. static SUNXI_CCU_GATE(bus_ce_clk, "bus-ce", "ahb1",
  188. 0x060, BIT(5), 0);
  189. static SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "ahb1",
  190. 0x060, BIT(6), 0);
  191. static SUNXI_CCU_GATE(bus_mmc0_clk, "bus-mmc0", "ahb1",
  192. 0x060, BIT(8), 0);
  193. static SUNXI_CCU_GATE(bus_mmc1_clk, "bus-mmc1", "ahb1",
  194. 0x060, BIT(9), 0);
  195. static SUNXI_CCU_GATE(bus_mmc2_clk, "bus-mmc2", "ahb1",
  196. 0x060, BIT(10), 0);
  197. static SUNXI_CCU_GATE(bus_dram_clk, "bus-dram", "ahb1",
  198. 0x060, BIT(14), 0);
  199. static SUNXI_CCU_GATE(bus_emac_clk, "bus-emac", "ahb2",
  200. 0x060, BIT(17), 0);
  201. static SUNXI_CCU_GATE(bus_hstimer_clk, "bus-hstimer", "ahb1",
  202. 0x060, BIT(19), 0);
  203. static SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb1",
  204. 0x060, BIT(20), 0);
  205. static SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb1",
  206. 0x060, BIT(24), 0);
  207. static SUNXI_CCU_GATE(bus_ehci0_clk, "bus-ehci0", "ahb1",
  208. 0x060, BIT(26), 0);
  209. static SUNXI_CCU_GATE(bus_ohci0_clk, "bus-ohci0", "ahb1",
  210. 0x060, BIT(29), 0);
  211. static SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "ahb1",
  212. 0x064, BIT(0), 0);
  213. static SUNXI_CCU_GATE(bus_tcon0_clk, "bus-tcon0", "ahb1",
  214. 0x064, BIT(4), 0);
  215. static SUNXI_CCU_GATE(bus_csi_clk, "bus-csi", "ahb1",
  216. 0x064, BIT(8), 0);
  217. static SUNXI_CCU_GATE(bus_de_clk, "bus-de", "ahb1",
  218. 0x064, BIT(12), 0);
  219. static SUNXI_CCU_GATE(bus_codec_clk, "bus-codec", "apb1",
  220. 0x068, BIT(0), 0);
  221. static SUNXI_CCU_GATE(bus_pio_clk, "bus-pio", "apb1",
  222. 0x068, BIT(5), 0);
  223. static SUNXI_CCU_GATE(bus_i2s0_clk, "bus-i2s0", "apb1",
  224. 0x068, BIT(12), 0);
  225. static SUNXI_CCU_GATE(bus_i2c0_clk, "bus-i2c0", "apb2",
  226. 0x06c, BIT(0), 0);
  227. static SUNXI_CCU_GATE(bus_i2c1_clk, "bus-i2c1", "apb2",
  228. 0x06c, BIT(1), 0);
  229. static SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb2",
  230. 0x06c, BIT(16), 0);
  231. static SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb2",
  232. 0x06c, BIT(17), 0);
  233. static SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb2",
  234. 0x06c, BIT(18), 0);
  235. static SUNXI_CCU_GATE(bus_ephy_clk, "bus-ephy", "ahb1",
  236. 0x070, BIT(0), 0);
  237. static SUNXI_CCU_GATE(bus_dbg_clk, "bus-dbg", "ahb1",
  238. 0x070, BIT(7), 0);
  239. static const char * const mod0_default_parents[] = { "osc24M", "pll-periph0",
  240. "pll-periph1" };
  241. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents, 0x088,
  242. 0, 4, /* M */
  243. 16, 2, /* P */
  244. 24, 2, /* mux */
  245. BIT(31), /* gate */
  246. 0);
  247. static SUNXI_CCU_PHASE(mmc0_sample_clk, "mmc0_sample", "mmc0",
  248. 0x088, 20, 3, 0);
  249. static SUNXI_CCU_PHASE(mmc0_output_clk, "mmc0_output", "mmc0",
  250. 0x088, 8, 3, 0);
  251. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents, 0x08c,
  252. 0, 4, /* M */
  253. 16, 2, /* P */
  254. 24, 2, /* mux */
  255. BIT(31), /* gate */
  256. 0);
  257. static SUNXI_CCU_PHASE(mmc1_sample_clk, "mmc1_sample", "mmc1",
  258. 0x08c, 20, 3, 0);
  259. static SUNXI_CCU_PHASE(mmc1_output_clk, "mmc1_output", "mmc1",
  260. 0x08c, 8, 3, 0);
  261. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents, 0x090,
  262. 0, 4, /* M */
  263. 16, 2, /* P */
  264. 24, 2, /* mux */
  265. BIT(31), /* gate */
  266. 0);
  267. static SUNXI_CCU_PHASE(mmc2_sample_clk, "mmc2_sample", "mmc2",
  268. 0x090, 20, 3, 0);
  269. static SUNXI_CCU_PHASE(mmc2_output_clk, "mmc2_output", "mmc2",
  270. 0x090, 8, 3, 0);
  271. static const char * const ce_parents[] = { "osc24M", "pll-periph0", };
  272. static SUNXI_CCU_MP_WITH_MUX_GATE(ce_clk, "ce", ce_parents, 0x09c,
  273. 0, 4, /* M */
  274. 16, 2, /* P */
  275. 24, 2, /* mux */
  276. BIT(31), /* gate */
  277. 0);
  278. static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0,
  279. 0, 4, /* M */
  280. 16, 2, /* P */
  281. 24, 2, /* mux */
  282. BIT(31), /* gate */
  283. 0);
  284. static const char * const i2s_parents[] = { "pll-audio-8x", "pll-audio-4x",
  285. "pll-audio-2x", "pll-audio" };
  286. static SUNXI_CCU_MUX_WITH_GATE(i2s0_clk, "i2s0", i2s_parents,
  287. 0x0b0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  288. static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M",
  289. 0x0cc, BIT(8), 0);
  290. static SUNXI_CCU_GATE(usb_ohci0_clk, "usb-ohci0", "osc24M",
  291. 0x0cc, BIT(16), 0);
  292. static const char * const dram_parents[] = { "pll-ddr0", "pll-ddr1",
  293. "pll-periph0-2x" };
  294. static SUNXI_CCU_M_WITH_MUX(dram_clk, "dram", dram_parents,
  295. 0x0f4, 0, 4, 20, 2, CLK_IS_CRITICAL);
  296. static SUNXI_CCU_GATE(dram_ve_clk, "dram-ve", "dram",
  297. 0x100, BIT(0), 0);
  298. static SUNXI_CCU_GATE(dram_csi_clk, "dram-csi", "dram",
  299. 0x100, BIT(1), 0);
  300. static SUNXI_CCU_GATE(dram_ehci_clk, "dram-ehci", "dram",
  301. 0x100, BIT(17), 0);
  302. static SUNXI_CCU_GATE(dram_ohci_clk, "dram-ohci", "dram",
  303. 0x100, BIT(18), 0);
  304. static const char * const de_parents[] = { "pll-video", "pll-periph0" };
  305. static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents,
  306. 0x104, 0, 4, 24, 2, BIT(31),
  307. CLK_SET_RATE_PARENT);
  308. static const char * const tcon_parents[] = { "pll-video" };
  309. static SUNXI_CCU_M_WITH_MUX_GATE(tcon_clk, "tcon", tcon_parents,
  310. 0x118, 0, 4, 24, 3, BIT(31), 0);
  311. static SUNXI_CCU_GATE(csi_misc_clk, "csi-misc", "osc24M",
  312. 0x130, BIT(31), 0);
  313. static const char * const csi_mclk_parents[] = { "osc24M", "pll-video",
  314. "pll-periph0", "pll-periph1" };
  315. static SUNXI_CCU_M_WITH_MUX_GATE(csi0_mclk_clk, "csi0-mclk", csi_mclk_parents,
  316. 0x130, 0, 5, 8, 3, BIT(15), 0);
  317. static const char * const csi1_sclk_parents[] = { "pll-video", "pll-isp" };
  318. static SUNXI_CCU_M_WITH_MUX_GATE(csi1_sclk_clk, "csi-sclk", csi1_sclk_parents,
  319. 0x134, 16, 4, 24, 3, BIT(31), 0);
  320. static SUNXI_CCU_M_WITH_MUX_GATE(csi1_mclk_clk, "csi-mclk", csi_mclk_parents,
  321. 0x134, 0, 5, 8, 3, BIT(15), 0);
  322. static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve",
  323. 0x13c, 16, 3, BIT(31), 0);
  324. static SUNXI_CCU_GATE(ac_dig_clk, "ac-dig", "pll-audio",
  325. 0x140, BIT(31), CLK_SET_RATE_PARENT);
  326. static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M",
  327. 0x144, BIT(31), 0);
  328. static const char * const mbus_parents[] = { "osc24M", "pll-periph0-2x",
  329. "pll-ddr" };
  330. static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents,
  331. 0x15c, 0, 3, 24, 2, BIT(31), CLK_IS_CRITICAL);
  332. static const char * const mipi_csi_parents[] = { "pll-video", "pll-periph0",
  333. "pll-isp" };
  334. static SUNXI_CCU_M_WITH_MUX_GATE(mipi_csi_clk, "mipi-csi", mipi_csi_parents,
  335. 0x16c, 0, 3, 24, 2, BIT(31), 0);
  336. static struct ccu_common *sun8i_v3s_ccu_clks[] = {
  337. &pll_cpu_clk.common,
  338. &pll_audio_base_clk.common,
  339. &pll_video_clk.common,
  340. &pll_ve_clk.common,
  341. &pll_ddr0_clk.common,
  342. &pll_periph0_clk.common,
  343. &pll_isp_clk.common,
  344. &pll_periph1_clk.common,
  345. &pll_ddr1_clk.common,
  346. &cpu_clk.common,
  347. &axi_clk.common,
  348. &ahb1_clk.common,
  349. &apb1_clk.common,
  350. &apb2_clk.common,
  351. &ahb2_clk.common,
  352. &bus_ce_clk.common,
  353. &bus_dma_clk.common,
  354. &bus_mmc0_clk.common,
  355. &bus_mmc1_clk.common,
  356. &bus_mmc2_clk.common,
  357. &bus_dram_clk.common,
  358. &bus_emac_clk.common,
  359. &bus_hstimer_clk.common,
  360. &bus_spi0_clk.common,
  361. &bus_otg_clk.common,
  362. &bus_ehci0_clk.common,
  363. &bus_ohci0_clk.common,
  364. &bus_ve_clk.common,
  365. &bus_tcon0_clk.common,
  366. &bus_csi_clk.common,
  367. &bus_de_clk.common,
  368. &bus_codec_clk.common,
  369. &bus_pio_clk.common,
  370. &bus_i2s0_clk.common,
  371. &bus_i2c0_clk.common,
  372. &bus_i2c1_clk.common,
  373. &bus_uart0_clk.common,
  374. &bus_uart1_clk.common,
  375. &bus_uart2_clk.common,
  376. &bus_ephy_clk.common,
  377. &bus_dbg_clk.common,
  378. &mmc0_clk.common,
  379. &mmc0_sample_clk.common,
  380. &mmc0_output_clk.common,
  381. &mmc1_clk.common,
  382. &mmc1_sample_clk.common,
  383. &mmc1_output_clk.common,
  384. &mmc2_clk.common,
  385. &mmc2_sample_clk.common,
  386. &mmc2_output_clk.common,
  387. &ce_clk.common,
  388. &spi0_clk.common,
  389. &i2s0_clk.common,
  390. &usb_phy0_clk.common,
  391. &usb_ohci0_clk.common,
  392. &dram_clk.common,
  393. &dram_ve_clk.common,
  394. &dram_csi_clk.common,
  395. &dram_ohci_clk.common,
  396. &dram_ehci_clk.common,
  397. &de_clk.common,
  398. &tcon_clk.common,
  399. &csi_misc_clk.common,
  400. &csi0_mclk_clk.common,
  401. &csi1_sclk_clk.common,
  402. &csi1_mclk_clk.common,
  403. &ve_clk.common,
  404. &ac_dig_clk.common,
  405. &avs_clk.common,
  406. &mbus_clk.common,
  407. &mipi_csi_clk.common,
  408. };
  409. static const struct clk_hw *clk_parent_pll_audio[] = {
  410. &pll_audio_base_clk.common.hw
  411. };
  412. /* We hardcode the divider to 1 for SDM support */
  413. static CLK_FIXED_FACTOR_HWS(pll_audio_clk, "pll-audio",
  414. clk_parent_pll_audio,
  415. 1, 1, CLK_SET_RATE_PARENT);
  416. static CLK_FIXED_FACTOR_HWS(pll_audio_2x_clk, "pll-audio-2x",
  417. clk_parent_pll_audio,
  418. 2, 1, CLK_SET_RATE_PARENT);
  419. static CLK_FIXED_FACTOR_HWS(pll_audio_4x_clk, "pll-audio-4x",
  420. clk_parent_pll_audio,
  421. 1, 1, CLK_SET_RATE_PARENT);
  422. static CLK_FIXED_FACTOR_HWS(pll_audio_8x_clk, "pll-audio-8x",
  423. clk_parent_pll_audio,
  424. 1, 2, CLK_SET_RATE_PARENT);
  425. static CLK_FIXED_FACTOR_HW(pll_periph0_2x_clk, "pll-periph0-2x",
  426. &pll_periph0_clk.common.hw,
  427. 1, 2, 0);
  428. static struct clk_hw_onecell_data sun8i_v3s_hw_clks = {
  429. .hws = {
  430. [CLK_PLL_CPU] = &pll_cpu_clk.common.hw,
  431. [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
  432. [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
  433. [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
  434. [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
  435. [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw,
  436. [CLK_PLL_VIDEO] = &pll_video_clk.common.hw,
  437. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  438. [CLK_PLL_DDR0] = &pll_ddr0_clk.common.hw,
  439. [CLK_PLL_PERIPH0] = &pll_periph0_clk.common.hw,
  440. [CLK_PLL_PERIPH0_2X] = &pll_periph0_2x_clk.hw,
  441. [CLK_PLL_ISP] = &pll_isp_clk.common.hw,
  442. [CLK_PLL_PERIPH1] = &pll_periph1_clk.common.hw,
  443. [CLK_PLL_DDR1] = &pll_ddr1_clk.common.hw,
  444. [CLK_CPU] = &cpu_clk.common.hw,
  445. [CLK_AXI] = &axi_clk.common.hw,
  446. [CLK_AHB1] = &ahb1_clk.common.hw,
  447. [CLK_APB1] = &apb1_clk.common.hw,
  448. [CLK_APB2] = &apb2_clk.common.hw,
  449. [CLK_AHB2] = &ahb2_clk.common.hw,
  450. [CLK_BUS_CE] = &bus_ce_clk.common.hw,
  451. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  452. [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw,
  453. [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw,
  454. [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw,
  455. [CLK_BUS_DRAM] = &bus_dram_clk.common.hw,
  456. [CLK_BUS_EMAC] = &bus_emac_clk.common.hw,
  457. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  458. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  459. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  460. [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw,
  461. [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw,
  462. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  463. [CLK_BUS_TCON0] = &bus_tcon0_clk.common.hw,
  464. [CLK_BUS_CSI] = &bus_csi_clk.common.hw,
  465. [CLK_BUS_DE] = &bus_de_clk.common.hw,
  466. [CLK_BUS_CODEC] = &bus_codec_clk.common.hw,
  467. [CLK_BUS_PIO] = &bus_pio_clk.common.hw,
  468. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  469. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  470. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  471. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  472. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  473. [CLK_BUS_EPHY] = &bus_ephy_clk.common.hw,
  474. [CLK_BUS_DBG] = &bus_dbg_clk.common.hw,
  475. [CLK_MMC0] = &mmc0_clk.common.hw,
  476. [CLK_MMC0_SAMPLE] = &mmc0_sample_clk.common.hw,
  477. [CLK_MMC0_OUTPUT] = &mmc0_output_clk.common.hw,
  478. [CLK_MMC1] = &mmc1_clk.common.hw,
  479. [CLK_MMC1_SAMPLE] = &mmc1_sample_clk.common.hw,
  480. [CLK_MMC1_OUTPUT] = &mmc1_output_clk.common.hw,
  481. [CLK_MMC2] = &mmc2_clk.common.hw,
  482. [CLK_MMC2_SAMPLE] = &mmc2_sample_clk.common.hw,
  483. [CLK_MMC2_OUTPUT] = &mmc2_output_clk.common.hw,
  484. [CLK_CE] = &ce_clk.common.hw,
  485. [CLK_SPI0] = &spi0_clk.common.hw,
  486. [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
  487. [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
  488. [CLK_DRAM] = &dram_clk.common.hw,
  489. [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
  490. [CLK_DRAM_CSI] = &dram_csi_clk.common.hw,
  491. [CLK_DRAM_EHCI] = &dram_ehci_clk.common.hw,
  492. [CLK_DRAM_OHCI] = &dram_ohci_clk.common.hw,
  493. [CLK_DE] = &de_clk.common.hw,
  494. [CLK_TCON0] = &tcon_clk.common.hw,
  495. [CLK_CSI_MISC] = &csi_misc_clk.common.hw,
  496. [CLK_CSI0_MCLK] = &csi0_mclk_clk.common.hw,
  497. [CLK_CSI1_SCLK] = &csi1_sclk_clk.common.hw,
  498. [CLK_CSI1_MCLK] = &csi1_mclk_clk.common.hw,
  499. [CLK_VE] = &ve_clk.common.hw,
  500. [CLK_AC_DIG] = &ac_dig_clk.common.hw,
  501. [CLK_AVS] = &avs_clk.common.hw,
  502. [CLK_MBUS] = &mbus_clk.common.hw,
  503. [CLK_MIPI_CSI] = &mipi_csi_clk.common.hw,
  504. },
  505. .num = CLK_PLL_DDR1 + 1,
  506. };
  507. static struct clk_hw_onecell_data sun8i_v3_hw_clks = {
  508. .hws = {
  509. [CLK_PLL_CPU] = &pll_cpu_clk.common.hw,
  510. [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
  511. [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
  512. [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
  513. [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
  514. [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw,
  515. [CLK_PLL_VIDEO] = &pll_video_clk.common.hw,
  516. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  517. [CLK_PLL_DDR0] = &pll_ddr0_clk.common.hw,
  518. [CLK_PLL_PERIPH0] = &pll_periph0_clk.common.hw,
  519. [CLK_PLL_PERIPH0_2X] = &pll_periph0_2x_clk.hw,
  520. [CLK_PLL_ISP] = &pll_isp_clk.common.hw,
  521. [CLK_PLL_PERIPH1] = &pll_periph1_clk.common.hw,
  522. [CLK_PLL_DDR1] = &pll_ddr1_clk.common.hw,
  523. [CLK_CPU] = &cpu_clk.common.hw,
  524. [CLK_AXI] = &axi_clk.common.hw,
  525. [CLK_AHB1] = &ahb1_clk.common.hw,
  526. [CLK_APB1] = &apb1_clk.common.hw,
  527. [CLK_APB2] = &apb2_clk.common.hw,
  528. [CLK_AHB2] = &ahb2_clk.common.hw,
  529. [CLK_BUS_CE] = &bus_ce_clk.common.hw,
  530. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  531. [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw,
  532. [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw,
  533. [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw,
  534. [CLK_BUS_DRAM] = &bus_dram_clk.common.hw,
  535. [CLK_BUS_EMAC] = &bus_emac_clk.common.hw,
  536. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  537. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  538. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  539. [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw,
  540. [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw,
  541. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  542. [CLK_BUS_TCON0] = &bus_tcon0_clk.common.hw,
  543. [CLK_BUS_CSI] = &bus_csi_clk.common.hw,
  544. [CLK_BUS_DE] = &bus_de_clk.common.hw,
  545. [CLK_BUS_CODEC] = &bus_codec_clk.common.hw,
  546. [CLK_BUS_PIO] = &bus_pio_clk.common.hw,
  547. [CLK_BUS_I2S0] = &bus_i2s0_clk.common.hw,
  548. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  549. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  550. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  551. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  552. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  553. [CLK_BUS_EPHY] = &bus_ephy_clk.common.hw,
  554. [CLK_BUS_DBG] = &bus_dbg_clk.common.hw,
  555. [CLK_MMC0] = &mmc0_clk.common.hw,
  556. [CLK_MMC0_SAMPLE] = &mmc0_sample_clk.common.hw,
  557. [CLK_MMC0_OUTPUT] = &mmc0_output_clk.common.hw,
  558. [CLK_MMC1] = &mmc1_clk.common.hw,
  559. [CLK_MMC1_SAMPLE] = &mmc1_sample_clk.common.hw,
  560. [CLK_MMC1_OUTPUT] = &mmc1_output_clk.common.hw,
  561. [CLK_MMC2] = &mmc2_clk.common.hw,
  562. [CLK_MMC2_SAMPLE] = &mmc2_sample_clk.common.hw,
  563. [CLK_MMC2_OUTPUT] = &mmc2_output_clk.common.hw,
  564. [CLK_CE] = &ce_clk.common.hw,
  565. [CLK_SPI0] = &spi0_clk.common.hw,
  566. [CLK_I2S0] = &i2s0_clk.common.hw,
  567. [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
  568. [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
  569. [CLK_DRAM] = &dram_clk.common.hw,
  570. [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
  571. [CLK_DRAM_CSI] = &dram_csi_clk.common.hw,
  572. [CLK_DRAM_EHCI] = &dram_ehci_clk.common.hw,
  573. [CLK_DRAM_OHCI] = &dram_ohci_clk.common.hw,
  574. [CLK_DE] = &de_clk.common.hw,
  575. [CLK_TCON0] = &tcon_clk.common.hw,
  576. [CLK_CSI_MISC] = &csi_misc_clk.common.hw,
  577. [CLK_CSI0_MCLK] = &csi0_mclk_clk.common.hw,
  578. [CLK_CSI1_SCLK] = &csi1_sclk_clk.common.hw,
  579. [CLK_CSI1_MCLK] = &csi1_mclk_clk.common.hw,
  580. [CLK_VE] = &ve_clk.common.hw,
  581. [CLK_AC_DIG] = &ac_dig_clk.common.hw,
  582. [CLK_AVS] = &avs_clk.common.hw,
  583. [CLK_MBUS] = &mbus_clk.common.hw,
  584. [CLK_MIPI_CSI] = &mipi_csi_clk.common.hw,
  585. },
  586. .num = CLK_I2S0 + 1,
  587. };
  588. static struct ccu_reset_map sun8i_v3s_ccu_resets[] = {
  589. [RST_USB_PHY0] = { 0x0cc, BIT(0) },
  590. [RST_MBUS] = { 0x0fc, BIT(31) },
  591. [RST_BUS_CE] = { 0x2c0, BIT(5) },
  592. [RST_BUS_DMA] = { 0x2c0, BIT(6) },
  593. [RST_BUS_MMC0] = { 0x2c0, BIT(8) },
  594. [RST_BUS_MMC1] = { 0x2c0, BIT(9) },
  595. [RST_BUS_MMC2] = { 0x2c0, BIT(10) },
  596. [RST_BUS_DRAM] = { 0x2c0, BIT(14) },
  597. [RST_BUS_EMAC] = { 0x2c0, BIT(17) },
  598. [RST_BUS_HSTIMER] = { 0x2c0, BIT(19) },
  599. [RST_BUS_SPI0] = { 0x2c0, BIT(20) },
  600. [RST_BUS_OTG] = { 0x2c0, BIT(24) },
  601. [RST_BUS_EHCI0] = { 0x2c0, BIT(26) },
  602. [RST_BUS_OHCI0] = { 0x2c0, BIT(29) },
  603. [RST_BUS_VE] = { 0x2c4, BIT(0) },
  604. [RST_BUS_TCON0] = { 0x2c4, BIT(4) },
  605. [RST_BUS_CSI] = { 0x2c4, BIT(8) },
  606. [RST_BUS_DE] = { 0x2c4, BIT(12) },
  607. [RST_BUS_DBG] = { 0x2c4, BIT(31) },
  608. [RST_BUS_EPHY] = { 0x2c8, BIT(2) },
  609. [RST_BUS_CODEC] = { 0x2d0, BIT(0) },
  610. [RST_BUS_I2C0] = { 0x2d8, BIT(0) },
  611. [RST_BUS_I2C1] = { 0x2d8, BIT(1) },
  612. [RST_BUS_UART0] = { 0x2d8, BIT(16) },
  613. [RST_BUS_UART1] = { 0x2d8, BIT(17) },
  614. [RST_BUS_UART2] = { 0x2d8, BIT(18) },
  615. };
  616. static struct ccu_reset_map sun8i_v3_ccu_resets[] = {
  617. [RST_USB_PHY0] = { 0x0cc, BIT(0) },
  618. [RST_MBUS] = { 0x0fc, BIT(31) },
  619. [RST_BUS_CE] = { 0x2c0, BIT(5) },
  620. [RST_BUS_DMA] = { 0x2c0, BIT(6) },
  621. [RST_BUS_MMC0] = { 0x2c0, BIT(8) },
  622. [RST_BUS_MMC1] = { 0x2c0, BIT(9) },
  623. [RST_BUS_MMC2] = { 0x2c0, BIT(10) },
  624. [RST_BUS_DRAM] = { 0x2c0, BIT(14) },
  625. [RST_BUS_EMAC] = { 0x2c0, BIT(17) },
  626. [RST_BUS_HSTIMER] = { 0x2c0, BIT(19) },
  627. [RST_BUS_SPI0] = { 0x2c0, BIT(20) },
  628. [RST_BUS_OTG] = { 0x2c0, BIT(24) },
  629. [RST_BUS_EHCI0] = { 0x2c0, BIT(26) },
  630. [RST_BUS_OHCI0] = { 0x2c0, BIT(29) },
  631. [RST_BUS_VE] = { 0x2c4, BIT(0) },
  632. [RST_BUS_TCON0] = { 0x2c4, BIT(4) },
  633. [RST_BUS_CSI] = { 0x2c4, BIT(8) },
  634. [RST_BUS_DE] = { 0x2c4, BIT(12) },
  635. [RST_BUS_DBG] = { 0x2c4, BIT(31) },
  636. [RST_BUS_EPHY] = { 0x2c8, BIT(2) },
  637. [RST_BUS_CODEC] = { 0x2d0, BIT(0) },
  638. [RST_BUS_I2S0] = { 0x2d0, BIT(12) },
  639. [RST_BUS_I2C0] = { 0x2d8, BIT(0) },
  640. [RST_BUS_I2C1] = { 0x2d8, BIT(1) },
  641. [RST_BUS_UART0] = { 0x2d8, BIT(16) },
  642. [RST_BUS_UART1] = { 0x2d8, BIT(17) },
  643. [RST_BUS_UART2] = { 0x2d8, BIT(18) },
  644. };
  645. static const struct sunxi_ccu_desc sun8i_v3s_ccu_desc = {
  646. .ccu_clks = sun8i_v3s_ccu_clks,
  647. .num_ccu_clks = ARRAY_SIZE(sun8i_v3s_ccu_clks),
  648. .hw_clks = &sun8i_v3s_hw_clks,
  649. .resets = sun8i_v3s_ccu_resets,
  650. .num_resets = ARRAY_SIZE(sun8i_v3s_ccu_resets),
  651. };
  652. static const struct sunxi_ccu_desc sun8i_v3_ccu_desc = {
  653. .ccu_clks = sun8i_v3s_ccu_clks,
  654. .num_ccu_clks = ARRAY_SIZE(sun8i_v3s_ccu_clks),
  655. .hw_clks = &sun8i_v3_hw_clks,
  656. .resets = sun8i_v3_ccu_resets,
  657. .num_resets = ARRAY_SIZE(sun8i_v3_ccu_resets),
  658. };
  659. static int sun8i_v3s_ccu_probe(struct platform_device *pdev)
  660. {
  661. const struct sunxi_ccu_desc *desc;
  662. void __iomem *reg;
  663. u32 val;
  664. desc = of_device_get_match_data(&pdev->dev);
  665. if (!desc)
  666. return -EINVAL;
  667. reg = devm_platform_ioremap_resource(pdev, 0);
  668. if (IS_ERR(reg))
  669. return PTR_ERR(reg);
  670. /* Force the PLL-Audio-1x divider to 1 */
  671. val = readl(reg + SUN8I_V3S_PLL_AUDIO_REG);
  672. val &= ~GENMASK(19, 16);
  673. writel(val, reg + SUN8I_V3S_PLL_AUDIO_REG);
  674. return devm_sunxi_ccu_probe(&pdev->dev, reg, desc);
  675. }
  676. static const struct of_device_id sun8i_v3s_ccu_ids[] = {
  677. {
  678. .compatible = "allwinner,sun8i-v3-ccu",
  679. .data = &sun8i_v3_ccu_desc,
  680. },
  681. {
  682. .compatible = "allwinner,sun8i-v3s-ccu",
  683. .data = &sun8i_v3s_ccu_desc,
  684. },
  685. { }
  686. };
  687. static struct platform_driver sun8i_v3s_ccu_driver = {
  688. .probe = sun8i_v3s_ccu_probe,
  689. .driver = {
  690. .name = "sun8i-v3s-ccu",
  691. .suppress_bind_attrs = true,
  692. .of_match_table = sun8i_v3s_ccu_ids,
  693. },
  694. };
  695. module_platform_driver(sun8i_v3s_ccu_driver);
  696. MODULE_IMPORT_NS(SUNXI_CCU);
  697. MODULE_LICENSE("GPL");