clk-rk3188.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. /*
  2. * Copyright (c) 2014 MundoReader S.L.
  3. * Author: Heiko Stuebner <heiko@sntech.de>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/clk.h>
  16. #include <linux/clk-provider.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include <dt-bindings/clock/rk3188-cru-common.h>
  20. #include "clk.h"
  21. #define RK3066_GRF_SOC_STATUS 0x15c
  22. #define RK3188_GRF_SOC_STATUS 0xac
  23. enum rk3188_plls {
  24. apll, cpll, dpll, gpll,
  25. };
  26. static struct rockchip_pll_rate_table rk3188_pll_rates[] = {
  27. RK3066_PLL_RATE(2208000000, 1, 92, 1),
  28. RK3066_PLL_RATE(2184000000, 1, 91, 1),
  29. RK3066_PLL_RATE(2160000000, 1, 90, 1),
  30. RK3066_PLL_RATE(2136000000, 1, 89, 1),
  31. RK3066_PLL_RATE(2112000000, 1, 88, 1),
  32. RK3066_PLL_RATE(2088000000, 1, 87, 1),
  33. RK3066_PLL_RATE(2064000000, 1, 86, 1),
  34. RK3066_PLL_RATE(2040000000, 1, 85, 1),
  35. RK3066_PLL_RATE(2016000000, 1, 84, 1),
  36. RK3066_PLL_RATE(1992000000, 1, 83, 1),
  37. RK3066_PLL_RATE(1968000000, 1, 82, 1),
  38. RK3066_PLL_RATE(1944000000, 1, 81, 1),
  39. RK3066_PLL_RATE(1920000000, 1, 80, 1),
  40. RK3066_PLL_RATE(1896000000, 1, 79, 1),
  41. RK3066_PLL_RATE(1872000000, 1, 78, 1),
  42. RK3066_PLL_RATE(1848000000, 1, 77, 1),
  43. RK3066_PLL_RATE(1824000000, 1, 76, 1),
  44. RK3066_PLL_RATE(1800000000, 1, 75, 1),
  45. RK3066_PLL_RATE(1776000000, 1, 74, 1),
  46. RK3066_PLL_RATE(1752000000, 1, 73, 1),
  47. RK3066_PLL_RATE(1728000000, 1, 72, 1),
  48. RK3066_PLL_RATE(1704000000, 1, 71, 1),
  49. RK3066_PLL_RATE(1680000000, 1, 70, 1),
  50. RK3066_PLL_RATE(1656000000, 1, 69, 1),
  51. RK3066_PLL_RATE(1632000000, 1, 68, 1),
  52. RK3066_PLL_RATE(1608000000, 1, 67, 1),
  53. RK3066_PLL_RATE(1560000000, 1, 65, 1),
  54. RK3066_PLL_RATE(1512000000, 1, 63, 1),
  55. RK3066_PLL_RATE(1488000000, 1, 62, 1),
  56. RK3066_PLL_RATE(1464000000, 1, 61, 1),
  57. RK3066_PLL_RATE(1440000000, 1, 60, 1),
  58. RK3066_PLL_RATE(1416000000, 1, 59, 1),
  59. RK3066_PLL_RATE(1392000000, 1, 58, 1),
  60. RK3066_PLL_RATE(1368000000, 1, 57, 1),
  61. RK3066_PLL_RATE(1344000000, 1, 56, 1),
  62. RK3066_PLL_RATE(1320000000, 1, 55, 1),
  63. RK3066_PLL_RATE(1296000000, 1, 54, 1),
  64. RK3066_PLL_RATE(1272000000, 1, 53, 1),
  65. RK3066_PLL_RATE(1248000000, 1, 52, 1),
  66. RK3066_PLL_RATE(1224000000, 1, 51, 1),
  67. RK3066_PLL_RATE(1200000000, 1, 50, 1),
  68. RK3066_PLL_RATE(1188000000, 2, 99, 1),
  69. RK3066_PLL_RATE(1176000000, 1, 49, 1),
  70. RK3066_PLL_RATE(1128000000, 1, 47, 1),
  71. RK3066_PLL_RATE(1104000000, 1, 46, 1),
  72. RK3066_PLL_RATE(1008000000, 1, 84, 2),
  73. RK3066_PLL_RATE( 912000000, 1, 76, 2),
  74. RK3066_PLL_RATE( 891000000, 8, 594, 2),
  75. RK3066_PLL_RATE( 888000000, 1, 74, 2),
  76. RK3066_PLL_RATE( 816000000, 1, 68, 2),
  77. RK3066_PLL_RATE( 798000000, 2, 133, 2),
  78. RK3066_PLL_RATE( 792000000, 1, 66, 2),
  79. RK3066_PLL_RATE( 768000000, 1, 64, 2),
  80. RK3066_PLL_RATE( 742500000, 8, 495, 2),
  81. RK3066_PLL_RATE( 696000000, 1, 58, 2),
  82. RK3066_PLL_RATE( 600000000, 1, 50, 2),
  83. RK3066_PLL_RATE( 594000000, 2, 198, 4),
  84. RK3066_PLL_RATE( 552000000, 1, 46, 2),
  85. RK3066_PLL_RATE( 504000000, 1, 84, 4),
  86. RK3066_PLL_RATE( 456000000, 1, 76, 4),
  87. RK3066_PLL_RATE( 408000000, 1, 68, 4),
  88. RK3066_PLL_RATE( 384000000, 2, 128, 4),
  89. RK3066_PLL_RATE( 360000000, 1, 60, 4),
  90. RK3066_PLL_RATE( 312000000, 1, 52, 4),
  91. RK3066_PLL_RATE( 300000000, 1, 50, 4),
  92. RK3066_PLL_RATE( 297000000, 2, 198, 8),
  93. RK3066_PLL_RATE( 252000000, 1, 84, 8),
  94. RK3066_PLL_RATE( 216000000, 1, 72, 8),
  95. RK3066_PLL_RATE( 148500000, 2, 99, 8),
  96. RK3066_PLL_RATE( 126000000, 1, 84, 16),
  97. RK3066_PLL_RATE( 48000000, 1, 64, 32),
  98. { /* sentinel */ },
  99. };
  100. #define RK3066_DIV_CORE_PERIPH_MASK 0x3
  101. #define RK3066_DIV_CORE_PERIPH_SHIFT 6
  102. #define RK3066_DIV_ACLK_CORE_MASK 0x7
  103. #define RK3066_DIV_ACLK_CORE_SHIFT 0
  104. #define RK3066_DIV_ACLK_HCLK_MASK 0x3
  105. #define RK3066_DIV_ACLK_HCLK_SHIFT 8
  106. #define RK3066_DIV_ACLK_PCLK_MASK 0x3
  107. #define RK3066_DIV_ACLK_PCLK_SHIFT 12
  108. #define RK3066_DIV_AHB2APB_MASK 0x3
  109. #define RK3066_DIV_AHB2APB_SHIFT 14
  110. #define RK3066_CLKSEL0(_core_peri) \
  111. { \
  112. .reg = RK2928_CLKSEL_CON(0), \
  113. .val = HIWORD_UPDATE(_core_peri, RK3066_DIV_CORE_PERIPH_MASK, \
  114. RK3066_DIV_CORE_PERIPH_SHIFT) \
  115. }
  116. #define RK3066_CLKSEL1(_aclk_core, _aclk_hclk, _aclk_pclk, _ahb2apb) \
  117. { \
  118. .reg = RK2928_CLKSEL_CON(1), \
  119. .val = HIWORD_UPDATE(_aclk_core, RK3066_DIV_ACLK_CORE_MASK, \
  120. RK3066_DIV_ACLK_CORE_SHIFT) | \
  121. HIWORD_UPDATE(_aclk_hclk, RK3066_DIV_ACLK_HCLK_MASK, \
  122. RK3066_DIV_ACLK_HCLK_SHIFT) | \
  123. HIWORD_UPDATE(_aclk_pclk, RK3066_DIV_ACLK_PCLK_MASK, \
  124. RK3066_DIV_ACLK_PCLK_SHIFT) | \
  125. HIWORD_UPDATE(_ahb2apb, RK3066_DIV_AHB2APB_MASK, \
  126. RK3066_DIV_AHB2APB_SHIFT), \
  127. }
  128. #define RK3066_CPUCLK_RATE(_prate, _core_peri, _acore, _ahclk, _apclk, _h2p) \
  129. { \
  130. .prate = _prate, \
  131. .divs = { \
  132. RK3066_CLKSEL0(_core_peri), \
  133. RK3066_CLKSEL1(_acore, _ahclk, _apclk, _h2p), \
  134. }, \
  135. }
  136. static struct rockchip_cpuclk_rate_table rk3066_cpuclk_rates[] __initdata = {
  137. RK3066_CPUCLK_RATE(1416000000, 2, 3, 1, 2, 1),
  138. RK3066_CPUCLK_RATE(1200000000, 2, 3, 1, 2, 1),
  139. RK3066_CPUCLK_RATE(1008000000, 2, 2, 1, 2, 1),
  140. RK3066_CPUCLK_RATE( 816000000, 2, 2, 1, 2, 1),
  141. RK3066_CPUCLK_RATE( 600000000, 1, 2, 1, 2, 1),
  142. RK3066_CPUCLK_RATE( 504000000, 1, 1, 1, 2, 1),
  143. RK3066_CPUCLK_RATE( 312000000, 0, 1, 1, 1, 0),
  144. };
  145. static const struct rockchip_cpuclk_reg_data rk3066_cpuclk_data = {
  146. .core_reg = RK2928_CLKSEL_CON(0),
  147. .div_core_shift = 0,
  148. .div_core_mask = 0x1f,
  149. .mux_core_shift = 8,
  150. };
  151. #define RK3188_DIV_ACLK_CORE_MASK 0x7
  152. #define RK3188_DIV_ACLK_CORE_SHIFT 3
  153. #define RK3188_CLKSEL1(_aclk_core) \
  154. { \
  155. .reg = RK2928_CLKSEL_CON(1), \
  156. .val = HIWORD_UPDATE(_aclk_core, RK3188_DIV_ACLK_CORE_MASK,\
  157. RK3188_DIV_ACLK_CORE_SHIFT) \
  158. }
  159. #define RK3188_CPUCLK_RATE(_prate, _core_peri, _aclk_core) \
  160. { \
  161. .prate = _prate, \
  162. .divs = { \
  163. RK3066_CLKSEL0(_core_peri), \
  164. RK3188_CLKSEL1(_aclk_core), \
  165. }, \
  166. }
  167. static struct rockchip_cpuclk_rate_table rk3188_cpuclk_rates[] __initdata = {
  168. RK3188_CPUCLK_RATE(1608000000, 2, 3),
  169. RK3188_CPUCLK_RATE(1416000000, 2, 3),
  170. RK3188_CPUCLK_RATE(1200000000, 2, 3),
  171. RK3188_CPUCLK_RATE(1008000000, 2, 3),
  172. RK3188_CPUCLK_RATE( 816000000, 2, 3),
  173. RK3188_CPUCLK_RATE( 600000000, 1, 3),
  174. RK3188_CPUCLK_RATE( 504000000, 1, 3),
  175. RK3188_CPUCLK_RATE( 312000000, 0, 1),
  176. };
  177. static const struct rockchip_cpuclk_reg_data rk3188_cpuclk_data = {
  178. .core_reg = RK2928_CLKSEL_CON(0),
  179. .div_core_shift = 9,
  180. .div_core_mask = 0x1f,
  181. .mux_core_shift = 8,
  182. };
  183. PNAME(mux_pll_p) = { "xin24m", "xin32k" };
  184. PNAME(mux_armclk_p) = { "apll", "gpll_armclk" };
  185. PNAME(mux_ddrphy_p) = { "dpll", "gpll_ddr" };
  186. PNAME(mux_pll_src_gpll_cpll_p) = { "gpll", "cpll" };
  187. PNAME(mux_pll_src_cpll_gpll_p) = { "cpll", "gpll" };
  188. PNAME(mux_aclk_cpu_p) = { "apll", "gpll" };
  189. PNAME(mux_sclk_cif0_p) = { "cif0_pre", "xin24m" };
  190. PNAME(mux_sclk_i2s0_p) = { "i2s0_pre", "i2s0_frac", "xin12m" };
  191. PNAME(mux_sclk_spdif_p) = { "spdif_pre", "spdif_frac", "xin12m" };
  192. PNAME(mux_sclk_uart0_p) = { "uart0_pre", "uart0_frac", "xin24m" };
  193. PNAME(mux_sclk_uart1_p) = { "uart1_pre", "uart1_frac", "xin24m" };
  194. PNAME(mux_sclk_uart2_p) = { "uart2_pre", "uart2_frac", "xin24m" };
  195. PNAME(mux_sclk_uart3_p) = { "uart3_pre", "uart3_frac", "xin24m" };
  196. PNAME(mux_sclk_hsadc_p) = { "hsadc_src", "hsadc_frac", "ext_hsadc" };
  197. PNAME(mux_mac_p) = { "gpll", "dpll" };
  198. PNAME(mux_sclk_macref_p) = { "mac_src", "ext_rmii" };
  199. static struct rockchip_pll_clock rk3066_pll_clks[] __initdata = {
  200. [apll] = PLL(pll_rk3066, PLL_APLL, "apll", mux_pll_p, 0, RK2928_PLL_CON(0),
  201. RK2928_MODE_CON, 0, 5, 0, rk3188_pll_rates),
  202. [dpll] = PLL(pll_rk3066, PLL_DPLL, "dpll", mux_pll_p, 0, RK2928_PLL_CON(4),
  203. RK2928_MODE_CON, 4, 4, 0, NULL),
  204. [cpll] = PLL(pll_rk3066, PLL_CPLL, "cpll", mux_pll_p, 0, RK2928_PLL_CON(8),
  205. RK2928_MODE_CON, 8, 6, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
  206. [gpll] = PLL(pll_rk3066, PLL_GPLL, "gpll", mux_pll_p, 0, RK2928_PLL_CON(12),
  207. RK2928_MODE_CON, 12, 7, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
  208. };
  209. static struct rockchip_pll_clock rk3188_pll_clks[] __initdata = {
  210. [apll] = PLL(pll_rk3066, PLL_APLL, "apll", mux_pll_p, 0, RK2928_PLL_CON(0),
  211. RK2928_MODE_CON, 0, 6, 0, rk3188_pll_rates),
  212. [dpll] = PLL(pll_rk3066, PLL_DPLL, "dpll", mux_pll_p, 0, RK2928_PLL_CON(4),
  213. RK2928_MODE_CON, 4, 5, 0, NULL),
  214. [cpll] = PLL(pll_rk3066, PLL_CPLL, "cpll", mux_pll_p, 0, RK2928_PLL_CON(8),
  215. RK2928_MODE_CON, 8, 7, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
  216. [gpll] = PLL(pll_rk3066, PLL_GPLL, "gpll", mux_pll_p, 0, RK2928_PLL_CON(12),
  217. RK2928_MODE_CON, 12, 8, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
  218. };
  219. #define MFLAGS CLK_MUX_HIWORD_MASK
  220. #define DFLAGS CLK_DIVIDER_HIWORD_MASK
  221. #define GFLAGS (CLK_GATE_HIWORD_MASK | CLK_GATE_SET_TO_DISABLE)
  222. #define IFLAGS ROCKCHIP_INVERTER_HIWORD_MASK
  223. /* 2 ^ (val + 1) */
  224. static struct clk_div_table div_core_peri_t[] = {
  225. { .val = 0, .div = 2 },
  226. { .val = 1, .div = 4 },
  227. { .val = 2, .div = 8 },
  228. { .val = 3, .div = 16 },
  229. { /* sentinel */ },
  230. };
  231. static struct rockchip_clk_branch common_clk_branches[] __initdata = {
  232. /*
  233. * Clock-Architecture Diagram 2
  234. */
  235. GATE(0, "gpll_armclk", "gpll", 0, RK2928_CLKGATE_CON(0), 1, GFLAGS),
  236. /* these two are set by the cpuclk and should not be changed */
  237. COMPOSITE_NOMUX_DIVTBL(CORE_PERI, "core_peri", "armclk", 0,
  238. RK2928_CLKSEL_CON(0), 6, 2, DFLAGS | CLK_DIVIDER_READ_ONLY,
  239. div_core_peri_t, RK2928_CLKGATE_CON(0), 0, GFLAGS),
  240. COMPOSITE(0, "aclk_vepu", mux_pll_src_cpll_gpll_p, 0,
  241. RK2928_CLKSEL_CON(32), 7, 1, MFLAGS, 0, 5, DFLAGS,
  242. RK2928_CLKGATE_CON(3), 9, GFLAGS),
  243. GATE(0, "hclk_vepu", "aclk_vepu", 0,
  244. RK2928_CLKGATE_CON(3), 10, GFLAGS),
  245. COMPOSITE(0, "aclk_vdpu", mux_pll_src_cpll_gpll_p, 0,
  246. RK2928_CLKSEL_CON(32), 15, 1, MFLAGS, 8, 5, DFLAGS,
  247. RK2928_CLKGATE_CON(3), 11, GFLAGS),
  248. GATE(0, "hclk_vdpu", "aclk_vdpu", 0,
  249. RK2928_CLKGATE_CON(3), 12, GFLAGS),
  250. GATE(0, "gpll_ddr", "gpll", CLK_IGNORE_UNUSED,
  251. RK2928_CLKGATE_CON(1), 7, GFLAGS),
  252. COMPOSITE(0, "ddrphy", mux_ddrphy_p, CLK_IGNORE_UNUSED,
  253. RK2928_CLKSEL_CON(26), 8, 1, MFLAGS, 0, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
  254. RK2928_CLKGATE_CON(0), 2, GFLAGS),
  255. GATE(0, "aclk_cpu", "aclk_cpu_pre", 0,
  256. RK2928_CLKGATE_CON(0), 3, GFLAGS),
  257. GATE(0, "atclk_cpu", "pclk_cpu_pre", 0,
  258. RK2928_CLKGATE_CON(0), 6, GFLAGS),
  259. GATE(0, "pclk_cpu", "pclk_cpu_pre", 0,
  260. RK2928_CLKGATE_CON(0), 5, GFLAGS),
  261. GATE(0, "hclk_cpu", "hclk_cpu_pre", CLK_IGNORE_UNUSED,
  262. RK2928_CLKGATE_CON(0), 4, GFLAGS),
  263. COMPOSITE(0, "aclk_lcdc0_pre", mux_pll_src_cpll_gpll_p, CLK_IGNORE_UNUSED,
  264. RK2928_CLKSEL_CON(31), 7, 1, MFLAGS, 0, 5, DFLAGS,
  265. RK2928_CLKGATE_CON(3), 0, GFLAGS),
  266. COMPOSITE(0, "aclk_lcdc1_pre", mux_pll_src_cpll_gpll_p, 0,
  267. RK2928_CLKSEL_CON(31), 15, 1, MFLAGS, 8, 5, DFLAGS,
  268. RK2928_CLKGATE_CON(1), 4, GFLAGS),
  269. GATE(0, "aclk_peri", "aclk_peri_pre", 0,
  270. RK2928_CLKGATE_CON(2), 1, GFLAGS),
  271. COMPOSITE_NOMUX(0, "hclk_peri", "aclk_peri_pre", 0,
  272. RK2928_CLKSEL_CON(10), 8, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
  273. RK2928_CLKGATE_CON(2), 2, GFLAGS),
  274. COMPOSITE_NOMUX(0, "pclk_peri", "aclk_peri_pre", 0,
  275. RK2928_CLKSEL_CON(10), 12, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
  276. RK2928_CLKGATE_CON(2), 3, GFLAGS),
  277. MUX(0, "cif_src", mux_pll_src_cpll_gpll_p, 0,
  278. RK2928_CLKSEL_CON(29), 0, 1, MFLAGS),
  279. COMPOSITE_NOMUX(0, "cif0_pre", "cif_src", 0,
  280. RK2928_CLKSEL_CON(29), 1, 5, DFLAGS,
  281. RK2928_CLKGATE_CON(3), 7, GFLAGS),
  282. MUX(SCLK_CIF0, "sclk_cif0", mux_sclk_cif0_p, 0,
  283. RK2928_CLKSEL_CON(29), 7, 1, MFLAGS),
  284. GATE(0, "pclkin_cif0", "ext_cif0", 0,
  285. RK2928_CLKGATE_CON(3), 3, GFLAGS),
  286. INVERTER(0, "pclk_cif0", "pclkin_cif0",
  287. RK2928_CLKSEL_CON(30), 8, IFLAGS),
  288. /*
  289. * the 480m are generated inside the usb block from these clocks,
  290. * but they are also a source for the hsicphy clock.
  291. */
  292. GATE(SCLK_OTGPHY0, "sclk_otgphy0", "usb480m", CLK_IGNORE_UNUSED,
  293. RK2928_CLKGATE_CON(1), 5, GFLAGS),
  294. GATE(SCLK_OTGPHY1, "sclk_otgphy1", "usb480m", CLK_IGNORE_UNUSED,
  295. RK2928_CLKGATE_CON(1), 6, GFLAGS),
  296. COMPOSITE(0, "mac_src", mux_mac_p, 0,
  297. RK2928_CLKSEL_CON(21), 0, 1, MFLAGS, 8, 5, DFLAGS,
  298. RK2928_CLKGATE_CON(2), 5, GFLAGS),
  299. MUX(SCLK_MAC, "sclk_macref", mux_sclk_macref_p, CLK_SET_RATE_PARENT,
  300. RK2928_CLKSEL_CON(21), 4, 1, MFLAGS),
  301. GATE(0, "sclk_mac_lbtest", "sclk_macref",
  302. RK2928_CLKGATE_CON(2), 12, 0, GFLAGS),
  303. COMPOSITE(0, "hsadc_src", mux_pll_src_gpll_cpll_p, 0,
  304. RK2928_CLKSEL_CON(22), 0, 1, MFLAGS, 8, 8, DFLAGS,
  305. RK2928_CLKGATE_CON(2), 6, GFLAGS),
  306. COMPOSITE_FRAC(0, "hsadc_frac", "hsadc_src", 0,
  307. RK2928_CLKSEL_CON(23), 0,
  308. RK2928_CLKGATE_CON(2), 7, GFLAGS),
  309. MUX(0, "sclk_hsadc_out", mux_sclk_hsadc_p, 0,
  310. RK2928_CLKSEL_CON(22), 4, 2, MFLAGS),
  311. INVERTER(SCLK_HSADC, "sclk_hsadc", "sclk_hsadc_out",
  312. RK2928_CLKSEL_CON(22), 7, IFLAGS),
  313. COMPOSITE_NOMUX(SCLK_SARADC, "sclk_saradc", "xin24m", 0,
  314. RK2928_CLKSEL_CON(24), 8, 8, DFLAGS,
  315. RK2928_CLKGATE_CON(2), 8, GFLAGS),
  316. COMPOSITE_NOMUX(0, "spdif_pre", "i2s_src", 0,
  317. RK2928_CLKSEL_CON(5), 0, 7, DFLAGS,
  318. RK2928_CLKGATE_CON(0), 13, GFLAGS),
  319. COMPOSITE_FRAC(0, "spdif_frac", "spdif_pre", CLK_SET_RATE_PARENT,
  320. RK2928_CLKSEL_CON(9), 0,
  321. RK2928_CLKGATE_CON(0), 14, GFLAGS),
  322. MUX(SCLK_SPDIF, "sclk_spdif", mux_sclk_spdif_p, CLK_SET_RATE_PARENT,
  323. RK2928_CLKSEL_CON(5), 8, 2, MFLAGS),
  324. /*
  325. * Clock-Architecture Diagram 4
  326. */
  327. GATE(SCLK_SMC, "sclk_smc", "hclk_peri",
  328. RK2928_CLKGATE_CON(2), 4, 0, GFLAGS),
  329. COMPOSITE_NOMUX(SCLK_SPI0, "sclk_spi0", "pclk_peri", 0,
  330. RK2928_CLKSEL_CON(25), 0, 7, DFLAGS,
  331. RK2928_CLKGATE_CON(2), 9, GFLAGS),
  332. COMPOSITE_NOMUX(SCLK_SPI1, "sclk_spi1", "pclk_peri", 0,
  333. RK2928_CLKSEL_CON(25), 8, 7, DFLAGS,
  334. RK2928_CLKGATE_CON(2), 10, GFLAGS),
  335. COMPOSITE_NOMUX(SCLK_SDMMC, "sclk_sdmmc", "hclk_peri", 0,
  336. RK2928_CLKSEL_CON(11), 0, 6, DFLAGS,
  337. RK2928_CLKGATE_CON(2), 11, GFLAGS),
  338. COMPOSITE_NOMUX(SCLK_SDIO, "sclk_sdio", "hclk_peri", 0,
  339. RK2928_CLKSEL_CON(12), 0, 6, DFLAGS,
  340. RK2928_CLKGATE_CON(2), 13, GFLAGS),
  341. COMPOSITE_NOMUX(SCLK_EMMC, "sclk_emmc", "hclk_peri", 0,
  342. RK2928_CLKSEL_CON(12), 8, 6, DFLAGS,
  343. RK2928_CLKGATE_CON(2), 14, GFLAGS),
  344. MUX(0, "uart_src", mux_pll_src_gpll_cpll_p, 0,
  345. RK2928_CLKSEL_CON(12), 15, 1, MFLAGS),
  346. COMPOSITE_NOMUX(0, "uart0_pre", "uart_src", 0,
  347. RK2928_CLKSEL_CON(13), 0, 7, DFLAGS,
  348. RK2928_CLKGATE_CON(1), 8, GFLAGS),
  349. COMPOSITE_FRAC(0, "uart0_frac", "uart0_pre", 0,
  350. RK2928_CLKSEL_CON(17), 0,
  351. RK2928_CLKGATE_CON(1), 9, GFLAGS),
  352. MUX(SCLK_UART0, "sclk_uart0", mux_sclk_uart0_p, 0,
  353. RK2928_CLKSEL_CON(13), 8, 2, MFLAGS),
  354. COMPOSITE_NOMUX(0, "uart1_pre", "uart_src", 0,
  355. RK2928_CLKSEL_CON(14), 0, 7, DFLAGS,
  356. RK2928_CLKGATE_CON(1), 10, GFLAGS),
  357. COMPOSITE_FRAC(0, "uart1_frac", "uart1_pre", 0,
  358. RK2928_CLKSEL_CON(18), 0,
  359. RK2928_CLKGATE_CON(1), 11, GFLAGS),
  360. MUX(SCLK_UART1, "sclk_uart1", mux_sclk_uart1_p, 0,
  361. RK2928_CLKSEL_CON(14), 8, 2, MFLAGS),
  362. COMPOSITE_NOMUX(0, "uart2_pre", "uart_src", 0,
  363. RK2928_CLKSEL_CON(15), 0, 7, DFLAGS,
  364. RK2928_CLKGATE_CON(1), 12, GFLAGS),
  365. COMPOSITE_FRAC(0, "uart2_frac", "uart2_pre", 0,
  366. RK2928_CLKSEL_CON(19), 0,
  367. RK2928_CLKGATE_CON(1), 13, GFLAGS),
  368. MUX(SCLK_UART2, "sclk_uart2", mux_sclk_uart2_p, 0,
  369. RK2928_CLKSEL_CON(15), 8, 2, MFLAGS),
  370. COMPOSITE_NOMUX(0, "uart3_pre", "uart_src", 0,
  371. RK2928_CLKSEL_CON(16), 0, 7, DFLAGS,
  372. RK2928_CLKGATE_CON(1), 14, GFLAGS),
  373. COMPOSITE_FRAC(0, "uart3_frac", "uart3_pre", 0,
  374. RK2928_CLKSEL_CON(20), 0,
  375. RK2928_CLKGATE_CON(1), 15, GFLAGS),
  376. MUX(SCLK_UART3, "sclk_uart3", mux_sclk_uart3_p, 0,
  377. RK2928_CLKSEL_CON(16), 8, 2, MFLAGS),
  378. GATE(SCLK_JTAG, "jtag", "ext_jtag", 0, RK2928_CLKGATE_CON(1), 3, GFLAGS),
  379. GATE(SCLK_TIMER0, "timer0", "xin24m", 0, RK2928_CLKGATE_CON(1), 0, GFLAGS),
  380. GATE(SCLK_TIMER1, "timer1", "xin24m", 0, RK2928_CLKGATE_CON(1), 1, GFLAGS),
  381. /* clk_core_pre gates */
  382. GATE(0, "core_dbg", "armclk", 0, RK2928_CLKGATE_CON(9), 0, GFLAGS),
  383. /* aclk_cpu gates */
  384. GATE(ACLK_DMA1, "aclk_dma1", "aclk_cpu", 0, RK2928_CLKGATE_CON(5), 0, GFLAGS),
  385. GATE(0, "aclk_intmem", "aclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 12, GFLAGS),
  386. GATE(0, "aclk_strc_sys", "aclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 10, GFLAGS),
  387. /* hclk_cpu gates */
  388. GATE(HCLK_ROM, "hclk_rom", "hclk_cpu", 0, RK2928_CLKGATE_CON(5), 6, GFLAGS),
  389. GATE(HCLK_I2S0, "hclk_i2s0", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 2, GFLAGS),
  390. GATE(HCLK_SPDIF, "hclk_spdif", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 1, GFLAGS),
  391. GATE(0, "hclk_cpubus", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 8, GFLAGS),
  392. /* hclk_ahb2apb is part of a clk branch */
  393. GATE(0, "hclk_vio_bus", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 12, GFLAGS),
  394. GATE(HCLK_LCDC0, "hclk_lcdc0", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 1, GFLAGS),
  395. GATE(HCLK_LCDC1, "hclk_lcdc1", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 2, GFLAGS),
  396. GATE(HCLK_CIF0, "hclk_cif0", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 4, GFLAGS),
  397. GATE(HCLK_IPP, "hclk_ipp", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 9, GFLAGS),
  398. GATE(HCLK_RGA, "hclk_rga", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 10, GFLAGS),
  399. /* hclk_peri gates */
  400. GATE(0, "hclk_peri_axi_matrix", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 0, GFLAGS),
  401. GATE(0, "hclk_peri_ahb_arbi", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 6, GFLAGS),
  402. GATE(0, "hclk_emem_peri", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 7, GFLAGS),
  403. GATE(HCLK_EMAC, "hclk_emac", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 0, GFLAGS),
  404. GATE(HCLK_NANDC0, "hclk_nandc0", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 9, GFLAGS),
  405. GATE(0, "hclk_usb_peri", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 5, GFLAGS),
  406. GATE(HCLK_OTG0, "hclk_usbotg0", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(5), 13, GFLAGS),
  407. GATE(HCLK_HSADC, "hclk_hsadc", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 5, GFLAGS),
  408. GATE(HCLK_PIDF, "hclk_pidfilter", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 6, GFLAGS),
  409. GATE(HCLK_SDMMC, "hclk_sdmmc", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 10, GFLAGS),
  410. GATE(HCLK_SDIO, "hclk_sdio", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 11, GFLAGS),
  411. GATE(HCLK_EMMC, "hclk_emmc", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 12, GFLAGS),
  412. /* aclk_lcdc0_pre gates */
  413. GATE(0, "aclk_vio0", "aclk_lcdc0_pre", 0, RK2928_CLKGATE_CON(6), 13, GFLAGS),
  414. GATE(ACLK_LCDC0, "aclk_lcdc0", "aclk_vio0", 0, RK2928_CLKGATE_CON(6), 0, GFLAGS),
  415. GATE(ACLK_CIF0, "aclk_cif0", "aclk_vio0", 0, RK2928_CLKGATE_CON(6), 5, GFLAGS),
  416. GATE(ACLK_IPP, "aclk_ipp", "aclk_vio0", 0, RK2928_CLKGATE_CON(6), 8, GFLAGS),
  417. /* aclk_lcdc1_pre gates */
  418. GATE(0, "aclk_vio1", "aclk_lcdc1_pre", 0, RK2928_CLKGATE_CON(9), 5, GFLAGS),
  419. GATE(ACLK_LCDC1, "aclk_lcdc1", "aclk_vio1", 0, RK2928_CLKGATE_CON(6), 3, GFLAGS),
  420. GATE(ACLK_RGA, "aclk_rga", "aclk_vio1", 0, RK2928_CLKGATE_CON(6), 11, GFLAGS),
  421. /* atclk_cpu gates */
  422. GATE(0, "atclk", "atclk_cpu", 0, RK2928_CLKGATE_CON(9), 3, GFLAGS),
  423. GATE(0, "trace", "atclk_cpu", 0, RK2928_CLKGATE_CON(9), 2, GFLAGS),
  424. /* pclk_cpu gates */
  425. GATE(PCLK_PWM01, "pclk_pwm01", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 10, GFLAGS),
  426. GATE(PCLK_TIMER0, "pclk_timer0", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 7, GFLAGS),
  427. GATE(PCLK_I2C0, "pclk_i2c0", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 4, GFLAGS),
  428. GATE(PCLK_I2C1, "pclk_i2c1", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 5, GFLAGS),
  429. GATE(PCLK_GPIO0, "pclk_gpio0", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 9, GFLAGS),
  430. GATE(PCLK_GPIO1, "pclk_gpio1", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 10, GFLAGS),
  431. GATE(PCLK_GPIO2, "pclk_gpio2", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 11, GFLAGS),
  432. GATE(PCLK_EFUSE, "pclk_efuse", "pclk_cpu", 0, RK2928_CLKGATE_CON(5), 2, GFLAGS),
  433. GATE(PCLK_TZPC, "pclk_tzpc", "pclk_cpu", 0, RK2928_CLKGATE_CON(5), 3, GFLAGS),
  434. GATE(0, "pclk_ddrupctl", "pclk_cpu", 0, RK2928_CLKGATE_CON(5), 7, GFLAGS),
  435. GATE(0, "pclk_ddrpubl", "pclk_cpu", 0, RK2928_CLKGATE_CON(9), 6, GFLAGS),
  436. GATE(0, "pclk_dbg", "pclk_cpu", 0, RK2928_CLKGATE_CON(9), 1, GFLAGS),
  437. GATE(PCLK_GRF, "pclk_grf", "pclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(5), 4, GFLAGS),
  438. GATE(PCLK_PMU, "pclk_pmu", "pclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(5), 5, GFLAGS),
  439. /* aclk_peri */
  440. GATE(ACLK_DMA2, "aclk_dma2", "aclk_peri", 0, RK2928_CLKGATE_CON(5), 1, GFLAGS),
  441. GATE(ACLK_SMC, "aclk_smc", "aclk_peri", 0, RK2928_CLKGATE_CON(5), 8, GFLAGS),
  442. GATE(0, "aclk_peri_niu", "aclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 4, GFLAGS),
  443. GATE(0, "aclk_cpu_peri", "aclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 2, GFLAGS),
  444. GATE(0, "aclk_peri_axi_matrix", "aclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 3, GFLAGS),
  445. /* pclk_peri gates */
  446. GATE(0, "pclk_peri_axi_matrix", "pclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 1, GFLAGS),
  447. GATE(PCLK_PWM23, "pclk_pwm23", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 11, GFLAGS),
  448. GATE(PCLK_WDT, "pclk_wdt", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 15, GFLAGS),
  449. GATE(PCLK_SPI0, "pclk_spi0", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 12, GFLAGS),
  450. GATE(PCLK_SPI1, "pclk_spi1", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 13, GFLAGS),
  451. GATE(PCLK_UART2, "pclk_uart2", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 2, GFLAGS),
  452. GATE(PCLK_UART3, "pclk_uart3", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 3, GFLAGS),
  453. GATE(PCLK_I2C2, "pclk_i2c2", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 6, GFLAGS),
  454. GATE(PCLK_I2C3, "pclk_i2c3", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 7, GFLAGS),
  455. GATE(PCLK_I2C4, "pclk_i2c4", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 8, GFLAGS),
  456. GATE(PCLK_GPIO3, "pclk_gpio3", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 12, GFLAGS),
  457. GATE(PCLK_SARADC, "pclk_saradc", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 14, GFLAGS),
  458. };
  459. PNAME(mux_rk3066_lcdc0_p) = { "dclk_lcdc0_src", "xin27m" };
  460. PNAME(mux_rk3066_lcdc1_p) = { "dclk_lcdc1_src", "xin27m" };
  461. PNAME(mux_sclk_cif1_p) = { "cif1_pre", "xin24m" };
  462. PNAME(mux_sclk_i2s1_p) = { "i2s1_pre", "i2s1_frac", "xin12m" };
  463. PNAME(mux_sclk_i2s2_p) = { "i2s2_pre", "i2s2_frac", "xin12m" };
  464. static struct clk_div_table div_aclk_cpu_t[] = {
  465. { .val = 0, .div = 1 },
  466. { .val = 1, .div = 2 },
  467. { .val = 2, .div = 3 },
  468. { .val = 3, .div = 4 },
  469. { .val = 4, .div = 8 },
  470. { /* sentinel */ },
  471. };
  472. static struct rockchip_clk_branch rk3066a_clk_branches[] __initdata = {
  473. DIVTBL(0, "aclk_cpu_pre", "armclk", 0,
  474. RK2928_CLKSEL_CON(1), 0, 3, DFLAGS | CLK_DIVIDER_READ_ONLY, div_aclk_cpu_t),
  475. DIV(0, "pclk_cpu_pre", "aclk_cpu_pre", 0,
  476. RK2928_CLKSEL_CON(1), 12, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO
  477. | CLK_DIVIDER_READ_ONLY),
  478. DIV(0, "hclk_cpu_pre", "aclk_cpu_pre", 0,
  479. RK2928_CLKSEL_CON(1), 8, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO
  480. | CLK_DIVIDER_READ_ONLY),
  481. COMPOSITE_NOMUX(0, "hclk_ahb2apb", "hclk_cpu_pre", 0,
  482. RK2928_CLKSEL_CON(1), 14, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO
  483. | CLK_DIVIDER_READ_ONLY,
  484. RK2928_CLKGATE_CON(4), 9, GFLAGS),
  485. GATE(CORE_L2C, "core_l2c", "aclk_cpu", CLK_IGNORE_UNUSED,
  486. RK2928_CLKGATE_CON(9), 4, GFLAGS),
  487. COMPOSITE(0, "aclk_peri_pre", mux_pll_src_gpll_cpll_p, 0,
  488. RK2928_CLKSEL_CON(10), 15, 1, MFLAGS, 0, 5, DFLAGS,
  489. RK2928_CLKGATE_CON(2), 0, GFLAGS),
  490. COMPOSITE(0, "dclk_lcdc0_src", mux_pll_src_cpll_gpll_p, 0,
  491. RK2928_CLKSEL_CON(27), 0, 1, MFLAGS, 8, 8, DFLAGS,
  492. RK2928_CLKGATE_CON(3), 1, GFLAGS),
  493. MUX(DCLK_LCDC0, "dclk_lcdc0", mux_rk3066_lcdc0_p, 0,
  494. RK2928_CLKSEL_CON(27), 4, 1, MFLAGS),
  495. COMPOSITE(0, "dclk_lcdc1_src", mux_pll_src_cpll_gpll_p, 0,
  496. RK2928_CLKSEL_CON(28), 0, 1, MFLAGS, 8, 8, DFLAGS,
  497. RK2928_CLKGATE_CON(3), 2, GFLAGS),
  498. MUX(DCLK_LCDC1, "dclk_lcdc1", mux_rk3066_lcdc1_p, 0,
  499. RK2928_CLKSEL_CON(28), 4, 1, MFLAGS),
  500. COMPOSITE_NOMUX(0, "cif1_pre", "cif_src", 0,
  501. RK2928_CLKSEL_CON(29), 8, 5, DFLAGS,
  502. RK2928_CLKGATE_CON(3), 8, GFLAGS),
  503. MUX(SCLK_CIF1, "sclk_cif1", mux_sclk_cif1_p, 0,
  504. RK2928_CLKSEL_CON(29), 15, 1, MFLAGS),
  505. GATE(0, "pclkin_cif1", "ext_cif1", 0,
  506. RK2928_CLKGATE_CON(3), 4, GFLAGS),
  507. INVERTER(0, "pclk_cif1", "pclkin_cif1",
  508. RK2928_CLKSEL_CON(30), 12, IFLAGS),
  509. COMPOSITE(0, "aclk_gpu_src", mux_pll_src_cpll_gpll_p, 0,
  510. RK2928_CLKSEL_CON(33), 8, 1, MFLAGS, 0, 5, DFLAGS,
  511. RK2928_CLKGATE_CON(3), 13, GFLAGS),
  512. GATE(ACLK_GPU, "aclk_gpu", "aclk_gpu_src", 0,
  513. RK2928_CLKGATE_CON(5), 15, GFLAGS),
  514. GATE(SCLK_TIMER2, "timer2", "xin24m", 0,
  515. RK2928_CLKGATE_CON(3), 2, GFLAGS),
  516. COMPOSITE_NOMUX(0, "sclk_tsadc", "xin24m", 0,
  517. RK2928_CLKSEL_CON(34), 0, 16, DFLAGS,
  518. RK2928_CLKGATE_CON(2), 15, GFLAGS),
  519. MUX(0, "i2s_src", mux_pll_src_gpll_cpll_p, 0,
  520. RK2928_CLKSEL_CON(2), 15, 1, MFLAGS),
  521. COMPOSITE_NOMUX(0, "i2s0_pre", "i2s_src", 0,
  522. RK2928_CLKSEL_CON(2), 0, 7, DFLAGS,
  523. RK2928_CLKGATE_CON(0), 7, GFLAGS),
  524. COMPOSITE_FRAC(0, "i2s0_frac", "i2s0_pre", 0,
  525. RK2928_CLKSEL_CON(6), 0,
  526. RK2928_CLKGATE_CON(0), 8, GFLAGS),
  527. MUX(SCLK_I2S0, "sclk_i2s0", mux_sclk_i2s0_p, 0,
  528. RK2928_CLKSEL_CON(2), 8, 2, MFLAGS),
  529. COMPOSITE_NOMUX(0, "i2s1_pre", "i2s_src", 0,
  530. RK2928_CLKSEL_CON(3), 0, 7, DFLAGS,
  531. RK2928_CLKGATE_CON(0), 9, GFLAGS),
  532. COMPOSITE_FRAC(0, "i2s1_frac", "i2s1_pre", 0,
  533. RK2928_CLKSEL_CON(7), 0,
  534. RK2928_CLKGATE_CON(0), 10, GFLAGS),
  535. MUX(SCLK_I2S1, "sclk_i2s1", mux_sclk_i2s1_p, 0,
  536. RK2928_CLKSEL_CON(3), 8, 2, MFLAGS),
  537. COMPOSITE_NOMUX(0, "i2s2_pre", "i2s_src", 0,
  538. RK2928_CLKSEL_CON(4), 0, 7, DFLAGS,
  539. RK2928_CLKGATE_CON(0), 11, GFLAGS),
  540. COMPOSITE_FRAC(0, "i2s2_frac", "i2s2_pre", 0,
  541. RK2928_CLKSEL_CON(8), 0,
  542. RK2928_CLKGATE_CON(0), 12, GFLAGS),
  543. MUX(SCLK_I2S2, "sclk_i2s2", mux_sclk_i2s2_p, 0,
  544. RK2928_CLKSEL_CON(4), 8, 2, MFLAGS),
  545. GATE(HCLK_I2S1, "hclk_i2s1", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 3, GFLAGS),
  546. GATE(HCLK_I2S2, "hclk_i2s2", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 4, GFLAGS),
  547. GATE(0, "hclk_cif1", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 6, GFLAGS),
  548. GATE(0, "hclk_hdmi", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 14, GFLAGS),
  549. GATE(HCLK_OTG1, "hclk_usbotg1", "hclk_peri", CLK_IGNORE_UNUSED,
  550. RK2928_CLKGATE_CON(5), 14, GFLAGS),
  551. GATE(0, "aclk_cif1", "aclk_vio1", 0, RK2928_CLKGATE_CON(6), 7, GFLAGS),
  552. GATE(PCLK_TIMER1, "pclk_timer1", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 8, GFLAGS),
  553. GATE(PCLK_TIMER2, "pclk_timer2", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 9, GFLAGS),
  554. GATE(PCLK_GPIO6, "pclk_gpio6", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 15, GFLAGS),
  555. GATE(PCLK_UART0, "pclk_uart0", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 0, GFLAGS),
  556. GATE(PCLK_UART1, "pclk_uart1", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 1, GFLAGS),
  557. GATE(PCLK_GPIO4, "pclk_gpio4", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 13, GFLAGS),
  558. GATE(PCLK_TSADC, "pclk_tsadc", "pclk_peri", 0, RK2928_CLKGATE_CON(4), 13, GFLAGS),
  559. };
  560. static struct clk_div_table div_rk3188_aclk_core_t[] = {
  561. { .val = 0, .div = 1 },
  562. { .val = 1, .div = 2 },
  563. { .val = 2, .div = 3 },
  564. { .val = 3, .div = 4 },
  565. { .val = 4, .div = 8 },
  566. { /* sentinel */ },
  567. };
  568. PNAME(mux_hsicphy_p) = { "sclk_otgphy0", "sclk_otgphy1",
  569. "gpll", "cpll" };
  570. static struct rockchip_clk_branch rk3188_clk_branches[] __initdata = {
  571. COMPOSITE_NOMUX_DIVTBL(0, "aclk_core", "armclk", CLK_IGNORE_UNUSED,
  572. RK2928_CLKSEL_CON(1), 3, 3, DFLAGS | CLK_DIVIDER_READ_ONLY,
  573. div_rk3188_aclk_core_t, RK2928_CLKGATE_CON(0), 7, GFLAGS),
  574. /* do not source aclk_cpu_pre from the apll, to keep complexity down */
  575. COMPOSITE_NOGATE(0, "aclk_cpu_pre", mux_aclk_cpu_p, CLK_SET_RATE_NO_REPARENT,
  576. RK2928_CLKSEL_CON(0), 5, 1, MFLAGS, 0, 5, DFLAGS),
  577. DIV(0, "pclk_cpu_pre", "aclk_cpu_pre", 0,
  578. RK2928_CLKSEL_CON(1), 12, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO),
  579. DIV(0, "hclk_cpu_pre", "aclk_cpu_pre", 0,
  580. RK2928_CLKSEL_CON(1), 8, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO),
  581. COMPOSITE_NOMUX(0, "hclk_ahb2apb", "hclk_cpu_pre", 0,
  582. RK2928_CLKSEL_CON(1), 14, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
  583. RK2928_CLKGATE_CON(4), 9, GFLAGS),
  584. GATE(CORE_L2C, "core_l2c", "armclk", CLK_IGNORE_UNUSED,
  585. RK2928_CLKGATE_CON(9), 4, GFLAGS),
  586. COMPOSITE(0, "aclk_peri_pre", mux_pll_src_cpll_gpll_p, 0,
  587. RK2928_CLKSEL_CON(10), 15, 1, MFLAGS, 0, 5, DFLAGS,
  588. RK2928_CLKGATE_CON(2), 0, GFLAGS),
  589. COMPOSITE(DCLK_LCDC0, "dclk_lcdc0", mux_pll_src_cpll_gpll_p, 0,
  590. RK2928_CLKSEL_CON(27), 0, 1, MFLAGS, 8, 8, DFLAGS,
  591. RK2928_CLKGATE_CON(3), 1, GFLAGS),
  592. COMPOSITE(DCLK_LCDC1, "dclk_lcdc1", mux_pll_src_cpll_gpll_p, 0,
  593. RK2928_CLKSEL_CON(28), 0, 1, MFLAGS, 8, 8, DFLAGS,
  594. RK2928_CLKGATE_CON(3), 2, GFLAGS),
  595. COMPOSITE(0, "aclk_gpu_src", mux_pll_src_cpll_gpll_p, 0,
  596. RK2928_CLKSEL_CON(34), 7, 1, MFLAGS, 0, 5, DFLAGS,
  597. RK2928_CLKGATE_CON(3), 15, GFLAGS),
  598. GATE(ACLK_GPU, "aclk_gpu", "aclk_gpu_src", 0,
  599. RK2928_CLKGATE_CON(9), 7, GFLAGS),
  600. GATE(SCLK_TIMER2, "timer2", "xin24m", 0, RK2928_CLKGATE_CON(3), 4, GFLAGS),
  601. GATE(SCLK_TIMER3, "timer3", "xin24m", 0, RK2928_CLKGATE_CON(1), 2, GFLAGS),
  602. GATE(SCLK_TIMER4, "timer4", "xin24m", 0, RK2928_CLKGATE_CON(3), 5, GFLAGS),
  603. GATE(SCLK_TIMER5, "timer5", "xin24m", 0, RK2928_CLKGATE_CON(3), 8, GFLAGS),
  604. GATE(SCLK_TIMER6, "timer6", "xin24m", 0, RK2928_CLKGATE_CON(3), 14, GFLAGS),
  605. COMPOSITE_NODIV(0, "sclk_hsicphy_480m", mux_hsicphy_p, 0,
  606. RK2928_CLKSEL_CON(30), 0, 2, DFLAGS,
  607. RK2928_CLKGATE_CON(3), 6, GFLAGS),
  608. DIV(0, "sclk_hsicphy_12m", "sclk_hsicphy_480m", 0,
  609. RK2928_CLKSEL_CON(11), 8, 6, DFLAGS),
  610. MUX(0, "i2s_src", mux_pll_src_gpll_cpll_p, 0,
  611. RK2928_CLKSEL_CON(2), 15, 1, MFLAGS),
  612. COMPOSITE_NOMUX(0, "i2s0_pre", "i2s_src", 0,
  613. RK2928_CLKSEL_CON(3), 0, 7, DFLAGS,
  614. RK2928_CLKGATE_CON(0), 9, GFLAGS),
  615. COMPOSITE_FRAC(0, "i2s0_frac", "i2s0_pre", 0,
  616. RK2928_CLKSEL_CON(7), 0,
  617. RK2928_CLKGATE_CON(0), 10, GFLAGS),
  618. MUX(SCLK_I2S0, "sclk_i2s0", mux_sclk_i2s0_p, 0,
  619. RK2928_CLKSEL_CON(3), 8, 2, MFLAGS),
  620. GATE(0, "hclk_imem0", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 14, GFLAGS),
  621. GATE(0, "hclk_imem1", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 15, GFLAGS),
  622. GATE(HCLK_OTG1, "hclk_usbotg1", "hclk_peri", CLK_IGNORE_UNUSED,
  623. RK2928_CLKGATE_CON(7), 3, GFLAGS),
  624. GATE(HCLK_HSIC, "hclk_hsic", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 4, GFLAGS),
  625. GATE(PCLK_TIMER3, "pclk_timer3", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 9, GFLAGS),
  626. GATE(PCLK_UART0, "pclk_uart0", "hclk_ahb2apb", 0, RK2928_CLKGATE_CON(8), 0, GFLAGS),
  627. GATE(PCLK_UART1, "pclk_uart1", "hclk_ahb2apb", 0, RK2928_CLKGATE_CON(8), 1, GFLAGS),
  628. GATE(ACLK_GPS, "aclk_gps", "aclk_peri", 0, RK2928_CLKGATE_CON(8), 13, GFLAGS),
  629. };
  630. static const char *const rk3188_critical_clocks[] __initconst = {
  631. "aclk_cpu",
  632. "aclk_peri",
  633. "hclk_peri",
  634. "pclk_cpu",
  635. "pclk_peri",
  636. "hclk_cpubus"
  637. };
  638. static void __init rk3188_common_clk_init(struct device_node *np)
  639. {
  640. void __iomem *reg_base;
  641. struct clk *clk;
  642. reg_base = of_iomap(np, 0);
  643. if (!reg_base) {
  644. pr_err("%s: could not map cru region\n", __func__);
  645. return;
  646. }
  647. rockchip_clk_init(np, reg_base, CLK_NR_CLKS);
  648. /* xin12m is created by an cru-internal divider */
  649. clk = clk_register_fixed_factor(NULL, "xin12m", "xin24m", 0, 1, 2);
  650. if (IS_ERR(clk))
  651. pr_warn("%s: could not register clock xin12m: %ld\n",
  652. __func__, PTR_ERR(clk));
  653. clk = clk_register_fixed_factor(NULL, "usb480m", "xin24m", 0, 20, 1);
  654. if (IS_ERR(clk))
  655. pr_warn("%s: could not register clock usb480m: %ld\n",
  656. __func__, PTR_ERR(clk));
  657. rockchip_clk_register_branches(common_clk_branches,
  658. ARRAY_SIZE(common_clk_branches));
  659. rockchip_register_softrst(np, 9, reg_base + RK2928_SOFTRST_CON(0),
  660. ROCKCHIP_SOFTRST_HIWORD_MASK);
  661. rockchip_register_restart_notifier(RK2928_GLB_SRST_FST);
  662. }
  663. static void __init rk3066a_clk_init(struct device_node *np)
  664. {
  665. rk3188_common_clk_init(np);
  666. rockchip_clk_register_plls(rk3066_pll_clks,
  667. ARRAY_SIZE(rk3066_pll_clks),
  668. RK3066_GRF_SOC_STATUS);
  669. rockchip_clk_register_branches(rk3066a_clk_branches,
  670. ARRAY_SIZE(rk3066a_clk_branches));
  671. rockchip_clk_register_armclk(ARMCLK, "armclk",
  672. mux_armclk_p, ARRAY_SIZE(mux_armclk_p),
  673. &rk3066_cpuclk_data, rk3066_cpuclk_rates,
  674. ARRAY_SIZE(rk3066_cpuclk_rates));
  675. rockchip_clk_protect_critical(rk3188_critical_clocks,
  676. ARRAY_SIZE(rk3188_critical_clocks));
  677. }
  678. CLK_OF_DECLARE(rk3066a_cru, "rockchip,rk3066a-cru", rk3066a_clk_init);
  679. static void __init rk3188a_clk_init(struct device_node *np)
  680. {
  681. struct clk *clk1, *clk2;
  682. unsigned long rate;
  683. int ret;
  684. rk3188_common_clk_init(np);
  685. rockchip_clk_register_plls(rk3188_pll_clks,
  686. ARRAY_SIZE(rk3188_pll_clks),
  687. RK3188_GRF_SOC_STATUS);
  688. rockchip_clk_register_branches(rk3188_clk_branches,
  689. ARRAY_SIZE(rk3188_clk_branches));
  690. rockchip_clk_register_armclk(ARMCLK, "armclk",
  691. mux_armclk_p, ARRAY_SIZE(mux_armclk_p),
  692. &rk3188_cpuclk_data, rk3188_cpuclk_rates,
  693. ARRAY_SIZE(rk3188_cpuclk_rates));
  694. /* reparent aclk_cpu_pre from apll */
  695. clk1 = __clk_lookup("aclk_cpu_pre");
  696. clk2 = __clk_lookup("gpll");
  697. if (clk1 && clk2) {
  698. rate = clk_get_rate(clk1);
  699. ret = clk_set_parent(clk1, clk2);
  700. if (ret < 0)
  701. pr_warn("%s: could not reparent aclk_cpu_pre to gpll\n",
  702. __func__);
  703. clk_set_rate(clk1, rate);
  704. } else {
  705. pr_warn("%s: missing clocks to reparent aclk_cpu_pre to gpll\n",
  706. __func__);
  707. }
  708. rockchip_clk_protect_critical(rk3188_critical_clocks,
  709. ARRAY_SIZE(rk3188_critical_clocks));
  710. }
  711. CLK_OF_DECLARE(rk3188a_cru, "rockchip,rk3188a-cru", rk3188a_clk_init);
  712. static void __init rk3188_clk_init(struct device_node *np)
  713. {
  714. int i;
  715. for (i = 0; i < ARRAY_SIZE(rk3188_pll_clks); i++) {
  716. struct rockchip_pll_clock *pll = &rk3188_pll_clks[i];
  717. struct rockchip_pll_rate_table *rate;
  718. if (!pll->rate_table)
  719. continue;
  720. rate = pll->rate_table;
  721. while (rate->rate > 0) {
  722. rate->nb = 1;
  723. rate++;
  724. }
  725. }
  726. rk3188a_clk_init(np);
  727. }
  728. CLK_OF_DECLARE(rk3188_cru, "rockchip,rk3188-cru", rk3188_clk_init);