ccu-sun8i-a23.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016 Maxime Ripard. All rights reserved.
  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 "ccu_common.h"
  10. #include "ccu_reset.h"
  11. #include "ccu_div.h"
  12. #include "ccu_gate.h"
  13. #include "ccu_mp.h"
  14. #include "ccu_mult.h"
  15. #include "ccu_nk.h"
  16. #include "ccu_nkm.h"
  17. #include "ccu_nkmp.h"
  18. #include "ccu_nm.h"
  19. #include "ccu_phase.h"
  20. #include "ccu_sdm.h"
  21. #include "ccu-sun8i-a23-a33.h"
  22. static struct ccu_nkmp pll_cpux_clk = {
  23. .enable = BIT(31),
  24. .lock = BIT(28),
  25. .n = _SUNXI_CCU_MULT(8, 5),
  26. .k = _SUNXI_CCU_MULT(4, 2),
  27. .m = _SUNXI_CCU_DIV(0, 2),
  28. .p = _SUNXI_CCU_DIV_MAX(16, 2, 4),
  29. .common = {
  30. .reg = 0x000,
  31. .hw.init = CLK_HW_INIT("pll-cpux", "osc24M",
  32. &ccu_nkmp_ops,
  33. 0),
  34. },
  35. };
  36. /*
  37. * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from
  38. * the base (2x, 4x and 8x), and one variable divider (the one true
  39. * pll audio).
  40. *
  41. * With sigma-delta modulation for fractional-N on the audio PLL,
  42. * we have to use specific dividers. This means the variable divider
  43. * can no longer be used, as the audio codec requests the exact clock
  44. * rates we support through this mechanism. So we now hard code the
  45. * variable divider to 1. This means the clock rates will no longer
  46. * match the clock names.
  47. */
  48. #define SUN8I_A23_PLL_AUDIO_REG 0x008
  49. static struct ccu_sdm_setting pll_audio_sdm_table[] = {
  50. { .rate = 22579200, .pattern = 0xc0010d84, .m = 8, .n = 7 },
  51. { .rate = 24576000, .pattern = 0xc000ac02, .m = 14, .n = 14 },
  52. };
  53. static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
  54. "osc24M", 0x008,
  55. 8, 7, /* N */
  56. 0, 5, /* M */
  57. pll_audio_sdm_table, BIT(24),
  58. 0x284, BIT(31),
  59. BIT(31), /* gate */
  60. BIT(28), /* lock */
  61. CLK_SET_RATE_UNGATE);
  62. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video_clk, "pll-video",
  63. "osc24M", 0x010,
  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. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve",
  74. "osc24M", 0x018,
  75. 8, 7, /* N */
  76. 0, 4, /* M */
  77. BIT(24), /* frac enable */
  78. BIT(25), /* frac select */
  79. 270000000, /* frac rate 0 */
  80. 297000000, /* frac rate 1 */
  81. BIT(31), /* gate */
  82. BIT(28), /* lock */
  83. CLK_SET_RATE_UNGATE);
  84. static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr_clk, "pll-ddr",
  85. "osc24M", 0x020,
  86. 8, 5, /* N */
  87. 4, 2, /* K */
  88. 0, 2, /* M */
  89. BIT(31), /* gate */
  90. BIT(28), /* lock */
  91. 0);
  92. static SUNXI_CCU_NK_WITH_GATE_LOCK_POSTDIV(pll_periph_clk, "pll-periph",
  93. "osc24M", 0x028,
  94. 8, 5, /* N */
  95. 4, 2, /* K */
  96. BIT(31), /* gate */
  97. BIT(28), /* lock */
  98. 2, /* post-div */
  99. CLK_SET_RATE_UNGATE);
  100. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_gpu_clk, "pll-gpu",
  101. "osc24M", 0x038,
  102. 8, 7, /* N */
  103. 0, 4, /* M */
  104. BIT(24), /* frac enable */
  105. BIT(25), /* frac select */
  106. 270000000, /* frac rate 0 */
  107. 297000000, /* frac rate 1 */
  108. BIT(31), /* gate */
  109. BIT(28), /* lock */
  110. CLK_SET_RATE_UNGATE);
  111. /*
  112. * The MIPI PLL has 2 modes: "MIPI" and "HDMI".
  113. *
  114. * The MIPI mode is a standard NKM-style clock. The HDMI mode is an
  115. * integer / fractional clock with switchable multipliers and dividers.
  116. * This is not supported here. We hardcode the PLL to MIPI mode.
  117. */
  118. #define SUN8I_A23_PLL_MIPI_REG 0x040
  119. static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_mipi_clk, "pll-mipi",
  120. "pll-video", 0x040,
  121. 8, 4, /* N */
  122. 4, 2, /* K */
  123. 0, 4, /* M */
  124. BIT(31) | BIT(23) | BIT(22), /* gate */
  125. BIT(28), /* lock */
  126. CLK_SET_RATE_UNGATE);
  127. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_hsic_clk, "pll-hsic",
  128. "osc24M", 0x044,
  129. 8, 7, /* N */
  130. 0, 4, /* M */
  131. BIT(24), /* frac enable */
  132. BIT(25), /* frac select */
  133. 270000000, /* frac rate 0 */
  134. 297000000, /* frac rate 1 */
  135. BIT(31), /* gate */
  136. BIT(28), /* lock */
  137. CLK_SET_RATE_UNGATE);
  138. static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_de_clk, "pll-de",
  139. "osc24M", 0x048,
  140. 8, 7, /* N */
  141. 0, 4, /* M */
  142. BIT(24), /* frac enable */
  143. BIT(25), /* frac select */
  144. 270000000, /* frac rate 0 */
  145. 297000000, /* frac rate 1 */
  146. BIT(31), /* gate */
  147. BIT(28), /* lock */
  148. CLK_SET_RATE_UNGATE);
  149. static const char * const cpux_parents[] = { "osc32k", "osc24M",
  150. "pll-cpux" , "pll-cpux" };
  151. static SUNXI_CCU_MUX(cpux_clk, "cpux", cpux_parents,
  152. 0x050, 16, 2, CLK_IS_CRITICAL);
  153. static SUNXI_CCU_M(axi_clk, "axi", "cpux", 0x050, 0, 2, 0);
  154. static const char * const ahb1_parents[] = { "osc32k", "osc24M",
  155. "axi" , "pll-periph" };
  156. static const struct ccu_mux_var_prediv ahb1_predivs[] = {
  157. { .index = 3, .shift = 6, .width = 2 },
  158. };
  159. static struct ccu_div ahb1_clk = {
  160. .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
  161. .mux = {
  162. .shift = 12,
  163. .width = 2,
  164. .var_predivs = ahb1_predivs,
  165. .n_var_predivs = ARRAY_SIZE(ahb1_predivs),
  166. },
  167. .common = {
  168. .reg = 0x054,
  169. .features = CCU_FEATURE_VARIABLE_PREDIV,
  170. .hw.init = CLK_HW_INIT_PARENTS("ahb1",
  171. ahb1_parents,
  172. &ccu_div_ops,
  173. 0),
  174. },
  175. };
  176. static struct clk_div_table apb1_div_table[] = {
  177. { .val = 0, .div = 2 },
  178. { .val = 1, .div = 2 },
  179. { .val = 2, .div = 4 },
  180. { .val = 3, .div = 8 },
  181. { /* Sentinel */ },
  182. };
  183. static SUNXI_CCU_DIV_TABLE(apb1_clk, "apb1", "ahb1",
  184. 0x054, 8, 2, apb1_div_table, 0);
  185. static const char * const apb2_parents[] = { "osc32k", "osc24M",
  186. "pll-periph" , "pll-periph" };
  187. static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", apb2_parents, 0x058,
  188. 0, 5, /* M */
  189. 16, 2, /* P */
  190. 24, 2, /* mux */
  191. 0);
  192. static SUNXI_CCU_GATE(bus_mipi_dsi_clk, "bus-mipi-dsi", "ahb1",
  193. 0x060, BIT(1), 0);
  194. static SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "ahb1",
  195. 0x060, BIT(6), 0);
  196. static SUNXI_CCU_GATE(bus_mmc0_clk, "bus-mmc0", "ahb1",
  197. 0x060, BIT(8), 0);
  198. static SUNXI_CCU_GATE(bus_mmc1_clk, "bus-mmc1", "ahb1",
  199. 0x060, BIT(9), 0);
  200. static SUNXI_CCU_GATE(bus_mmc2_clk, "bus-mmc2", "ahb1",
  201. 0x060, BIT(10), 0);
  202. static SUNXI_CCU_GATE(bus_nand_clk, "bus-nand", "ahb1",
  203. 0x060, BIT(13), 0);
  204. static SUNXI_CCU_GATE(bus_dram_clk, "bus-dram", "ahb1",
  205. 0x060, BIT(14), 0);
  206. static SUNXI_CCU_GATE(bus_hstimer_clk, "bus-hstimer", "ahb1",
  207. 0x060, BIT(19), 0);
  208. static SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb1",
  209. 0x060, BIT(20), 0);
  210. static SUNXI_CCU_GATE(bus_spi1_clk, "bus-spi1", "ahb1",
  211. 0x060, BIT(21), 0);
  212. static SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb1",
  213. 0x060, BIT(24), 0);
  214. static SUNXI_CCU_GATE(bus_ehci_clk, "bus-ehci", "ahb1",
  215. 0x060, BIT(26), 0);
  216. static SUNXI_CCU_GATE(bus_ohci_clk, "bus-ohci", "ahb1",
  217. 0x060, BIT(29), 0);
  218. static SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "ahb1",
  219. 0x064, BIT(0), 0);
  220. static SUNXI_CCU_GATE(bus_lcd_clk, "bus-lcd", "ahb1",
  221. 0x064, BIT(4), 0);
  222. static SUNXI_CCU_GATE(bus_csi_clk, "bus-csi", "ahb1",
  223. 0x064, BIT(8), 0);
  224. static SUNXI_CCU_GATE(bus_de_be_clk, "bus-de-be", "ahb1",
  225. 0x064, BIT(12), 0);
  226. static SUNXI_CCU_GATE(bus_de_fe_clk, "bus-de-fe", "ahb1",
  227. 0x064, BIT(14), 0);
  228. static SUNXI_CCU_GATE(bus_gpu_clk, "bus-gpu", "ahb1",
  229. 0x064, BIT(20), 0);
  230. static SUNXI_CCU_GATE(bus_msgbox_clk, "bus-msgbox", "ahb1",
  231. 0x064, BIT(21), 0);
  232. static SUNXI_CCU_GATE(bus_spinlock_clk, "bus-spinlock", "ahb1",
  233. 0x064, BIT(22), 0);
  234. static SUNXI_CCU_GATE(bus_drc_clk, "bus-drc", "ahb1",
  235. 0x064, BIT(25), 0);
  236. static SUNXI_CCU_GATE(bus_codec_clk, "bus-codec", "apb1",
  237. 0x068, BIT(0), 0);
  238. static SUNXI_CCU_GATE(bus_pio_clk, "bus-pio", "apb1",
  239. 0x068, BIT(5), 0);
  240. static SUNXI_CCU_GATE(bus_i2s0_clk, "bus-i2s0", "apb1",
  241. 0x068, BIT(12), 0);
  242. static SUNXI_CCU_GATE(bus_i2s1_clk, "bus-i2s1", "apb1",
  243. 0x068, BIT(13), 0);
  244. static SUNXI_CCU_GATE(bus_i2c0_clk, "bus-i2c0", "apb2",
  245. 0x06c, BIT(0), 0);
  246. static SUNXI_CCU_GATE(bus_i2c1_clk, "bus-i2c1", "apb2",
  247. 0x06c, BIT(1), 0);
  248. static SUNXI_CCU_GATE(bus_i2c2_clk, "bus-i2c2", "apb2",
  249. 0x06c, BIT(2), 0);
  250. static SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb2",
  251. 0x06c, BIT(16), 0);
  252. static SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb2",
  253. 0x06c, BIT(17), 0);
  254. static SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb2",
  255. 0x06c, BIT(18), 0);
  256. static SUNXI_CCU_GATE(bus_uart3_clk, "bus-uart3", "apb2",
  257. 0x06c, BIT(19), 0);
  258. static SUNXI_CCU_GATE(bus_uart4_clk, "bus-uart4", "apb2",
  259. 0x06c, BIT(20), 0);
  260. static const char * const mod0_default_parents[] = { "osc24M", "pll-periph" };
  261. static SUNXI_CCU_MP_WITH_MUX_GATE(nand_clk, "nand", mod0_default_parents, 0x080,
  262. 0, 4, /* M */
  263. 16, 2, /* P */
  264. 24, 2, /* mux */
  265. BIT(31), /* gate */
  266. 0);
  267. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents, 0x088,
  268. 0, 4, /* M */
  269. 16, 2, /* P */
  270. 24, 2, /* mux */
  271. BIT(31), /* gate */
  272. 0);
  273. static SUNXI_CCU_PHASE(mmc0_sample_clk, "mmc0_sample", "mmc0",
  274. 0x088, 20, 3, 0);
  275. static SUNXI_CCU_PHASE(mmc0_output_clk, "mmc0_output", "mmc0",
  276. 0x088, 8, 3, 0);
  277. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents, 0x08c,
  278. 0, 4, /* M */
  279. 16, 2, /* P */
  280. 24, 2, /* mux */
  281. BIT(31), /* gate */
  282. 0);
  283. static SUNXI_CCU_PHASE(mmc1_sample_clk, "mmc1_sample", "mmc1",
  284. 0x08c, 20, 3, 0);
  285. static SUNXI_CCU_PHASE(mmc1_output_clk, "mmc1_output", "mmc1",
  286. 0x08c, 8, 3, 0);
  287. static SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents, 0x090,
  288. 0, 4, /* M */
  289. 16, 2, /* P */
  290. 24, 2, /* mux */
  291. BIT(31), /* gate */
  292. 0);
  293. static SUNXI_CCU_PHASE(mmc2_sample_clk, "mmc2_sample", "mmc2",
  294. 0x090, 20, 3, 0);
  295. static SUNXI_CCU_PHASE(mmc2_output_clk, "mmc2_output", "mmc2",
  296. 0x090, 8, 3, 0);
  297. static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0,
  298. 0, 4, /* M */
  299. 16, 2, /* P */
  300. 24, 2, /* mux */
  301. BIT(31), /* gate */
  302. 0);
  303. static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", mod0_default_parents, 0x0a4,
  304. 0, 4, /* M */
  305. 16, 2, /* P */
  306. 24, 2, /* mux */
  307. BIT(31), /* gate */
  308. 0);
  309. static const char * const i2s_parents[] = { "pll-audio-8x", "pll-audio-4x",
  310. "pll-audio-2x", "pll-audio" };
  311. static SUNXI_CCU_MUX_WITH_GATE(i2s0_clk, "i2s0", i2s_parents,
  312. 0x0b0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  313. static SUNXI_CCU_MUX_WITH_GATE(i2s1_clk, "i2s1", i2s_parents,
  314. 0x0b4, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
  315. /* TODO: the parent for most of the USB clocks is not known */
  316. static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M",
  317. 0x0cc, BIT(8), 0);
  318. static SUNXI_CCU_GATE(usb_phy1_clk, "usb-phy1", "osc24M",
  319. 0x0cc, BIT(9), 0);
  320. static SUNXI_CCU_GATE(usb_hsic_clk, "usb-hsic", "pll-hsic",
  321. 0x0cc, BIT(10), 0);
  322. static SUNXI_CCU_GATE(usb_hsic_12M_clk, "usb-hsic-12M", "osc24M",
  323. 0x0cc, BIT(11), 0);
  324. static SUNXI_CCU_GATE(usb_ohci_clk, "usb-ohci", "osc24M",
  325. 0x0cc, BIT(16), 0);
  326. static SUNXI_CCU_GATE(dram_ve_clk, "dram-ve", "pll-ddr",
  327. 0x100, BIT(0), 0);
  328. static SUNXI_CCU_GATE(dram_csi_clk, "dram-csi", "pll-ddr",
  329. 0x100, BIT(1), 0);
  330. static SUNXI_CCU_GATE(dram_drc_clk, "dram-drc", "pll-ddr",
  331. 0x100, BIT(16), 0);
  332. static SUNXI_CCU_GATE(dram_de_fe_clk, "dram-de-fe", "pll-ddr",
  333. 0x100, BIT(24), 0);
  334. static SUNXI_CCU_GATE(dram_de_be_clk, "dram-de-be", "pll-ddr",
  335. 0x100, BIT(26), 0);
  336. static const char * const de_parents[] = { "pll-video", "pll-periph-2x",
  337. "pll-gpu", "pll-de" };
  338. static const u8 de_table[] = { 0, 2, 3, 5 };
  339. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(de_be_clk, "de-be",
  340. de_parents, de_table,
  341. 0x104, 0, 4, 24, 3, BIT(31), 0);
  342. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(de_fe_clk, "de-fe",
  343. de_parents, de_table,
  344. 0x10c, 0, 4, 24, 3, BIT(31), 0);
  345. static const char * const lcd_ch0_parents[] = { "pll-video", "pll-video-2x",
  346. "pll-mipi" };
  347. static const u8 lcd_ch0_table[] = { 0, 2, 4 };
  348. static SUNXI_CCU_MUX_TABLE_WITH_GATE(lcd_ch0_clk, "lcd-ch0",
  349. lcd_ch0_parents, lcd_ch0_table,
  350. 0x118, 24, 3, BIT(31),
  351. CLK_SET_RATE_PARENT);
  352. static const char * const lcd_ch1_parents[] = { "pll-video", "pll-video-2x" };
  353. static const u8 lcd_ch1_table[] = { 0, 2 };
  354. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(lcd_ch1_clk, "lcd-ch1",
  355. lcd_ch1_parents, lcd_ch1_table,
  356. 0x12c, 0, 4, 24, 2, BIT(31), 0);
  357. static const char * const csi_sclk_parents[] = { "pll-video", "pll-de",
  358. "pll-mipi", "pll-ve" };
  359. static const u8 csi_sclk_table[] = { 0, 3, 4, 5 };
  360. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(csi_sclk_clk, "csi-sclk",
  361. csi_sclk_parents, csi_sclk_table,
  362. 0x134, 16, 4, 24, 3, BIT(31), 0);
  363. static const char * const csi_mclk_parents[] = { "pll-video", "pll-de",
  364. "osc24M" };
  365. static const u8 csi_mclk_table[] = { 0, 3, 5 };
  366. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(csi_mclk_clk, "csi-mclk",
  367. csi_mclk_parents, csi_mclk_table,
  368. 0x134, 0, 5, 8, 3, BIT(15), 0);
  369. static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve",
  370. 0x13c, 16, 3, BIT(31), CLK_SET_RATE_PARENT);
  371. static SUNXI_CCU_GATE(ac_dig_clk, "ac-dig", "pll-audio",
  372. 0x140, BIT(31), CLK_SET_RATE_PARENT);
  373. static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M",
  374. 0x144, BIT(31), 0);
  375. static const char * const mbus_parents[] = { "osc24M", "pll-periph-2x",
  376. "pll-ddr" };
  377. static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents,
  378. 0x15c, 0, 3, 24, 2, BIT(31), CLK_IS_CRITICAL);
  379. static const char * const dsi_sclk_parents[] = { "pll-video", "pll-video-2x" };
  380. static const u8 dsi_sclk_table[] = { 0, 2 };
  381. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(dsi_sclk_clk, "dsi-sclk",
  382. dsi_sclk_parents, dsi_sclk_table,
  383. 0x168, 16, 4, 24, 2, BIT(31), 0);
  384. static const char * const dsi_dphy_parents[] = { "pll-video", "pll-periph" };
  385. static const u8 dsi_dphy_table[] = { 0, 2 };
  386. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(dsi_dphy_clk, "dsi-dphy",
  387. dsi_dphy_parents, dsi_dphy_table,
  388. 0x168, 0, 4, 8, 2, BIT(15), 0);
  389. static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(drc_clk, "drc",
  390. de_parents, de_table,
  391. 0x180, 0, 4, 24, 3, BIT(31), 0);
  392. static SUNXI_CCU_M_WITH_GATE(gpu_clk, "gpu", "pll-gpu",
  393. 0x1a0, 0, 3, BIT(31), 0);
  394. static const char * const ats_parents[] = { "osc24M", "pll-periph" };
  395. static SUNXI_CCU_M_WITH_MUX_GATE(ats_clk, "ats", ats_parents,
  396. 0x1b0, 0, 3, 24, 2, BIT(31), 0);
  397. static struct ccu_common *sun8i_a23_ccu_clks[] = {
  398. &pll_cpux_clk.common,
  399. &pll_audio_base_clk.common,
  400. &pll_video_clk.common,
  401. &pll_ve_clk.common,
  402. &pll_ddr_clk.common,
  403. &pll_periph_clk.common,
  404. &pll_gpu_clk.common,
  405. &pll_mipi_clk.common,
  406. &pll_hsic_clk.common,
  407. &pll_de_clk.common,
  408. &cpux_clk.common,
  409. &axi_clk.common,
  410. &ahb1_clk.common,
  411. &apb1_clk.common,
  412. &apb2_clk.common,
  413. &bus_mipi_dsi_clk.common,
  414. &bus_dma_clk.common,
  415. &bus_mmc0_clk.common,
  416. &bus_mmc1_clk.common,
  417. &bus_mmc2_clk.common,
  418. &bus_nand_clk.common,
  419. &bus_dram_clk.common,
  420. &bus_hstimer_clk.common,
  421. &bus_spi0_clk.common,
  422. &bus_spi1_clk.common,
  423. &bus_otg_clk.common,
  424. &bus_ehci_clk.common,
  425. &bus_ohci_clk.common,
  426. &bus_ve_clk.common,
  427. &bus_lcd_clk.common,
  428. &bus_csi_clk.common,
  429. &bus_de_fe_clk.common,
  430. &bus_de_be_clk.common,
  431. &bus_gpu_clk.common,
  432. &bus_msgbox_clk.common,
  433. &bus_spinlock_clk.common,
  434. &bus_drc_clk.common,
  435. &bus_codec_clk.common,
  436. &bus_pio_clk.common,
  437. &bus_i2s0_clk.common,
  438. &bus_i2s1_clk.common,
  439. &bus_i2c0_clk.common,
  440. &bus_i2c1_clk.common,
  441. &bus_i2c2_clk.common,
  442. &bus_uart0_clk.common,
  443. &bus_uart1_clk.common,
  444. &bus_uart2_clk.common,
  445. &bus_uart3_clk.common,
  446. &bus_uart4_clk.common,
  447. &nand_clk.common,
  448. &mmc0_clk.common,
  449. &mmc0_sample_clk.common,
  450. &mmc0_output_clk.common,
  451. &mmc1_clk.common,
  452. &mmc1_sample_clk.common,
  453. &mmc1_output_clk.common,
  454. &mmc2_clk.common,
  455. &mmc2_sample_clk.common,
  456. &mmc2_output_clk.common,
  457. &spi0_clk.common,
  458. &spi1_clk.common,
  459. &i2s0_clk.common,
  460. &i2s1_clk.common,
  461. &usb_phy0_clk.common,
  462. &usb_phy1_clk.common,
  463. &usb_hsic_clk.common,
  464. &usb_hsic_12M_clk.common,
  465. &usb_ohci_clk.common,
  466. &dram_ve_clk.common,
  467. &dram_csi_clk.common,
  468. &dram_drc_clk.common,
  469. &dram_de_fe_clk.common,
  470. &dram_de_be_clk.common,
  471. &de_be_clk.common,
  472. &de_fe_clk.common,
  473. &lcd_ch0_clk.common,
  474. &lcd_ch1_clk.common,
  475. &csi_sclk_clk.common,
  476. &csi_mclk_clk.common,
  477. &ve_clk.common,
  478. &ac_dig_clk.common,
  479. &avs_clk.common,
  480. &mbus_clk.common,
  481. &dsi_sclk_clk.common,
  482. &dsi_dphy_clk.common,
  483. &drc_clk.common,
  484. &gpu_clk.common,
  485. &ats_clk.common,
  486. };
  487. static const struct clk_hw *clk_parent_pll_audio[] = {
  488. &pll_audio_base_clk.common.hw
  489. };
  490. /* We hardcode the divider to 1 for now */
  491. static CLK_FIXED_FACTOR_HWS(pll_audio_clk, "pll-audio",
  492. clk_parent_pll_audio,
  493. 1, 1, CLK_SET_RATE_PARENT);
  494. static CLK_FIXED_FACTOR_HWS(pll_audio_2x_clk, "pll-audio-2x",
  495. clk_parent_pll_audio,
  496. 2, 1, CLK_SET_RATE_PARENT);
  497. static CLK_FIXED_FACTOR_HWS(pll_audio_4x_clk, "pll-audio-4x",
  498. clk_parent_pll_audio,
  499. 1, 1, CLK_SET_RATE_PARENT);
  500. static CLK_FIXED_FACTOR_HWS(pll_audio_8x_clk, "pll-audio-8x",
  501. clk_parent_pll_audio,
  502. 1, 2, CLK_SET_RATE_PARENT);
  503. static CLK_FIXED_FACTOR_HW(pll_periph_2x_clk, "pll-periph-2x",
  504. &pll_periph_clk.common.hw,
  505. 1, 2, 0);
  506. static CLK_FIXED_FACTOR_HW(pll_video_2x_clk, "pll-video-2x",
  507. &pll_video_clk.common.hw,
  508. 1, 2, 0);
  509. static struct clk_hw_onecell_data sun8i_a23_hw_clks = {
  510. .hws = {
  511. [CLK_PLL_CPUX] = &pll_cpux_clk.common.hw,
  512. [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
  513. [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
  514. [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
  515. [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
  516. [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw,
  517. [CLK_PLL_VIDEO] = &pll_video_clk.common.hw,
  518. [CLK_PLL_VIDEO_2X] = &pll_video_2x_clk.hw,
  519. [CLK_PLL_VE] = &pll_ve_clk.common.hw,
  520. [CLK_PLL_DDR0] = &pll_ddr_clk.common.hw,
  521. [CLK_PLL_PERIPH] = &pll_periph_clk.common.hw,
  522. [CLK_PLL_PERIPH_2X] = &pll_periph_2x_clk.hw,
  523. [CLK_PLL_GPU] = &pll_gpu_clk.common.hw,
  524. [CLK_PLL_MIPI] = &pll_mipi_clk.common.hw,
  525. [CLK_PLL_HSIC] = &pll_hsic_clk.common.hw,
  526. [CLK_PLL_DE] = &pll_de_clk.common.hw,
  527. [CLK_CPUX] = &cpux_clk.common.hw,
  528. [CLK_AXI] = &axi_clk.common.hw,
  529. [CLK_AHB1] = &ahb1_clk.common.hw,
  530. [CLK_APB1] = &apb1_clk.common.hw,
  531. [CLK_APB2] = &apb2_clk.common.hw,
  532. [CLK_BUS_MIPI_DSI] = &bus_mipi_dsi_clk.common.hw,
  533. [CLK_BUS_DMA] = &bus_dma_clk.common.hw,
  534. [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw,
  535. [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw,
  536. [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw,
  537. [CLK_BUS_NAND] = &bus_nand_clk.common.hw,
  538. [CLK_BUS_DRAM] = &bus_dram_clk.common.hw,
  539. [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw,
  540. [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw,
  541. [CLK_BUS_SPI1] = &bus_spi1_clk.common.hw,
  542. [CLK_BUS_OTG] = &bus_otg_clk.common.hw,
  543. [CLK_BUS_EHCI] = &bus_ehci_clk.common.hw,
  544. [CLK_BUS_OHCI] = &bus_ohci_clk.common.hw,
  545. [CLK_BUS_VE] = &bus_ve_clk.common.hw,
  546. [CLK_BUS_LCD] = &bus_lcd_clk.common.hw,
  547. [CLK_BUS_CSI] = &bus_csi_clk.common.hw,
  548. [CLK_BUS_DE_BE] = &bus_de_be_clk.common.hw,
  549. [CLK_BUS_DE_FE] = &bus_de_fe_clk.common.hw,
  550. [CLK_BUS_GPU] = &bus_gpu_clk.common.hw,
  551. [CLK_BUS_MSGBOX] = &bus_msgbox_clk.common.hw,
  552. [CLK_BUS_SPINLOCK] = &bus_spinlock_clk.common.hw,
  553. [CLK_BUS_DRC] = &bus_drc_clk.common.hw,
  554. [CLK_BUS_CODEC] = &bus_codec_clk.common.hw,
  555. [CLK_BUS_PIO] = &bus_pio_clk.common.hw,
  556. [CLK_BUS_I2S0] = &bus_i2s0_clk.common.hw,
  557. [CLK_BUS_I2S1] = &bus_i2s1_clk.common.hw,
  558. [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw,
  559. [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw,
  560. [CLK_BUS_I2C2] = &bus_i2c2_clk.common.hw,
  561. [CLK_BUS_UART0] = &bus_uart0_clk.common.hw,
  562. [CLK_BUS_UART1] = &bus_uart1_clk.common.hw,
  563. [CLK_BUS_UART2] = &bus_uart2_clk.common.hw,
  564. [CLK_BUS_UART3] = &bus_uart3_clk.common.hw,
  565. [CLK_BUS_UART4] = &bus_uart4_clk.common.hw,
  566. [CLK_NAND] = &nand_clk.common.hw,
  567. [CLK_MMC0] = &mmc0_clk.common.hw,
  568. [CLK_MMC0_SAMPLE] = &mmc0_sample_clk.common.hw,
  569. [CLK_MMC0_OUTPUT] = &mmc0_output_clk.common.hw,
  570. [CLK_MMC1] = &mmc1_clk.common.hw,
  571. [CLK_MMC1_SAMPLE] = &mmc1_sample_clk.common.hw,
  572. [CLK_MMC1_OUTPUT] = &mmc1_output_clk.common.hw,
  573. [CLK_MMC2] = &mmc2_clk.common.hw,
  574. [CLK_MMC2_SAMPLE] = &mmc2_sample_clk.common.hw,
  575. [CLK_MMC2_OUTPUT] = &mmc2_output_clk.common.hw,
  576. [CLK_SPI0] = &spi0_clk.common.hw,
  577. [CLK_SPI1] = &spi1_clk.common.hw,
  578. [CLK_I2S0] = &i2s0_clk.common.hw,
  579. [CLK_I2S1] = &i2s1_clk.common.hw,
  580. [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
  581. [CLK_USB_PHY1] = &usb_phy1_clk.common.hw,
  582. [CLK_USB_HSIC] = &usb_hsic_clk.common.hw,
  583. [CLK_USB_HSIC_12M] = &usb_hsic_12M_clk.common.hw,
  584. [CLK_USB_OHCI] = &usb_ohci_clk.common.hw,
  585. [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
  586. [CLK_DRAM_CSI] = &dram_csi_clk.common.hw,
  587. [CLK_DRAM_DRC] = &dram_drc_clk.common.hw,
  588. [CLK_DRAM_DE_FE] = &dram_de_fe_clk.common.hw,
  589. [CLK_DRAM_DE_BE] = &dram_de_be_clk.common.hw,
  590. [CLK_DE_BE] = &de_be_clk.common.hw,
  591. [CLK_DE_FE] = &de_fe_clk.common.hw,
  592. [CLK_LCD_CH0] = &lcd_ch0_clk.common.hw,
  593. [CLK_LCD_CH1] = &lcd_ch1_clk.common.hw,
  594. [CLK_CSI_SCLK] = &csi_sclk_clk.common.hw,
  595. [CLK_CSI_MCLK] = &csi_mclk_clk.common.hw,
  596. [CLK_VE] = &ve_clk.common.hw,
  597. [CLK_AC_DIG] = &ac_dig_clk.common.hw,
  598. [CLK_AVS] = &avs_clk.common.hw,
  599. [CLK_MBUS] = &mbus_clk.common.hw,
  600. [CLK_DSI_SCLK] = &dsi_sclk_clk.common.hw,
  601. [CLK_DSI_DPHY] = &dsi_dphy_clk.common.hw,
  602. [CLK_DRC] = &drc_clk.common.hw,
  603. [CLK_GPU] = &gpu_clk.common.hw,
  604. [CLK_ATS] = &ats_clk.common.hw,
  605. },
  606. .num = CLK_NUMBER,
  607. };
  608. static struct ccu_reset_map sun8i_a23_ccu_resets[] = {
  609. [RST_USB_PHY0] = { 0x0cc, BIT(0) },
  610. [RST_USB_PHY1] = { 0x0cc, BIT(1) },
  611. [RST_USB_HSIC] = { 0x0cc, BIT(2) },
  612. [RST_MBUS] = { 0x0fc, BIT(31) },
  613. [RST_BUS_MIPI_DSI] = { 0x2c0, BIT(1) },
  614. [RST_BUS_DMA] = { 0x2c0, BIT(6) },
  615. [RST_BUS_MMC0] = { 0x2c0, BIT(8) },
  616. [RST_BUS_MMC1] = { 0x2c0, BIT(9) },
  617. [RST_BUS_MMC2] = { 0x2c0, BIT(10) },
  618. [RST_BUS_NAND] = { 0x2c0, BIT(13) },
  619. [RST_BUS_DRAM] = { 0x2c0, BIT(14) },
  620. [RST_BUS_HSTIMER] = { 0x2c0, BIT(19) },
  621. [RST_BUS_SPI0] = { 0x2c0, BIT(20) },
  622. [RST_BUS_SPI1] = { 0x2c0, BIT(21) },
  623. [RST_BUS_OTG] = { 0x2c0, BIT(24) },
  624. [RST_BUS_EHCI] = { 0x2c0, BIT(26) },
  625. [RST_BUS_OHCI] = { 0x2c0, BIT(29) },
  626. [RST_BUS_VE] = { 0x2c4, BIT(0) },
  627. [RST_BUS_LCD] = { 0x2c4, BIT(4) },
  628. [RST_BUS_CSI] = { 0x2c4, BIT(8) },
  629. [RST_BUS_DE_BE] = { 0x2c4, BIT(12) },
  630. [RST_BUS_DE_FE] = { 0x2c4, BIT(14) },
  631. [RST_BUS_GPU] = { 0x2c4, BIT(20) },
  632. [RST_BUS_MSGBOX] = { 0x2c4, BIT(21) },
  633. [RST_BUS_SPINLOCK] = { 0x2c4, BIT(22) },
  634. [RST_BUS_DRC] = { 0x2c4, BIT(25) },
  635. [RST_BUS_LVDS] = { 0x2c8, BIT(0) },
  636. [RST_BUS_CODEC] = { 0x2d0, BIT(0) },
  637. [RST_BUS_I2S0] = { 0x2d0, BIT(12) },
  638. [RST_BUS_I2S1] = { 0x2d0, BIT(13) },
  639. [RST_BUS_I2C0] = { 0x2d8, BIT(0) },
  640. [RST_BUS_I2C1] = { 0x2d8, BIT(1) },
  641. [RST_BUS_I2C2] = { 0x2d8, BIT(2) },
  642. [RST_BUS_UART0] = { 0x2d8, BIT(16) },
  643. [RST_BUS_UART1] = { 0x2d8, BIT(17) },
  644. [RST_BUS_UART2] = { 0x2d8, BIT(18) },
  645. [RST_BUS_UART3] = { 0x2d8, BIT(19) },
  646. [RST_BUS_UART4] = { 0x2d8, BIT(20) },
  647. };
  648. static const struct sunxi_ccu_desc sun8i_a23_ccu_desc = {
  649. .ccu_clks = sun8i_a23_ccu_clks,
  650. .num_ccu_clks = ARRAY_SIZE(sun8i_a23_ccu_clks),
  651. .hw_clks = &sun8i_a23_hw_clks,
  652. .resets = sun8i_a23_ccu_resets,
  653. .num_resets = ARRAY_SIZE(sun8i_a23_ccu_resets),
  654. };
  655. static int sun8i_a23_ccu_probe(struct platform_device *pdev)
  656. {
  657. void __iomem *reg;
  658. u32 val;
  659. reg = devm_platform_ioremap_resource(pdev, 0);
  660. if (IS_ERR(reg))
  661. return PTR_ERR(reg);
  662. /* Force the PLL-Audio-1x divider to 1 */
  663. val = readl(reg + SUN8I_A23_PLL_AUDIO_REG);
  664. val &= ~GENMASK(19, 16);
  665. writel(val | (0 << 16), reg + SUN8I_A23_PLL_AUDIO_REG);
  666. /* Force PLL-MIPI to MIPI mode */
  667. val = readl(reg + SUN8I_A23_PLL_MIPI_REG);
  668. val &= ~BIT(16);
  669. writel(val, reg + SUN8I_A23_PLL_MIPI_REG);
  670. return devm_sunxi_ccu_probe(&pdev->dev, reg, &sun8i_a23_ccu_desc);
  671. }
  672. static const struct of_device_id sun8i_a23_ccu_ids[] = {
  673. { .compatible = "allwinner,sun8i-a23-ccu" },
  674. { }
  675. };
  676. static struct platform_driver sun8i_a23_ccu_driver = {
  677. .probe = sun8i_a23_ccu_probe,
  678. .driver = {
  679. .name = "sun8i-a23-ccu",
  680. .suppress_bind_attrs = true,
  681. .of_match_table = sun8i_a23_ccu_ids,
  682. },
  683. };
  684. module_platform_driver(sun8i_a23_ccu_driver);
  685. MODULE_IMPORT_NS(SUNXI_CCU);
  686. MODULE_LICENSE("GPL");