clk-rk3188.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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_alt = 1,
  150. .mux_core_main = 0,
  151. .mux_core_shift = 8,
  152. .mux_core_mask = 0x1,
  153. };
  154. #define RK3188_DIV_ACLK_CORE_MASK 0x7
  155. #define RK3188_DIV_ACLK_CORE_SHIFT 3
  156. #define RK3188_CLKSEL1(_aclk_core) \
  157. { \
  158. .reg = RK2928_CLKSEL_CON(1), \
  159. .val = HIWORD_UPDATE(_aclk_core, RK3188_DIV_ACLK_CORE_MASK,\
  160. RK3188_DIV_ACLK_CORE_SHIFT) \
  161. }
  162. #define RK3188_CPUCLK_RATE(_prate, _core_peri, _aclk_core) \
  163. { \
  164. .prate = _prate, \
  165. .divs = { \
  166. RK3066_CLKSEL0(_core_peri), \
  167. RK3188_CLKSEL1(_aclk_core), \
  168. }, \
  169. }
  170. static struct rockchip_cpuclk_rate_table rk3188_cpuclk_rates[] __initdata = {
  171. RK3188_CPUCLK_RATE(1608000000, 2, 3),
  172. RK3188_CPUCLK_RATE(1416000000, 2, 3),
  173. RK3188_CPUCLK_RATE(1200000000, 2, 3),
  174. RK3188_CPUCLK_RATE(1008000000, 2, 3),
  175. RK3188_CPUCLK_RATE( 816000000, 2, 3),
  176. RK3188_CPUCLK_RATE( 600000000, 1, 3),
  177. RK3188_CPUCLK_RATE( 504000000, 1, 3),
  178. RK3188_CPUCLK_RATE( 312000000, 0, 1),
  179. };
  180. static const struct rockchip_cpuclk_reg_data rk3188_cpuclk_data = {
  181. .core_reg = RK2928_CLKSEL_CON(0),
  182. .div_core_shift = 9,
  183. .div_core_mask = 0x1f,
  184. .mux_core_alt = 1,
  185. .mux_core_main = 0,
  186. .mux_core_shift = 8,
  187. .mux_core_mask = 0x1,
  188. };
  189. PNAME(mux_pll_p) = { "xin24m", "xin32k" };
  190. PNAME(mux_armclk_p) = { "apll", "gpll_armclk" };
  191. PNAME(mux_ddrphy_p) = { "dpll", "gpll_ddr" };
  192. PNAME(mux_pll_src_gpll_cpll_p) = { "gpll", "cpll" };
  193. PNAME(mux_pll_src_cpll_gpll_p) = { "cpll", "gpll" };
  194. PNAME(mux_aclk_cpu_p) = { "apll", "gpll" };
  195. PNAME(mux_sclk_cif0_p) = { "cif0_pre", "xin24m" };
  196. PNAME(mux_sclk_i2s0_p) = { "i2s0_pre", "i2s0_frac", "xin12m" };
  197. PNAME(mux_sclk_spdif_p) = { "spdif_pre", "spdif_frac", "xin12m" };
  198. PNAME(mux_sclk_uart0_p) = { "uart0_pre", "uart0_frac", "xin24m" };
  199. PNAME(mux_sclk_uart1_p) = { "uart1_pre", "uart1_frac", "xin24m" };
  200. PNAME(mux_sclk_uart2_p) = { "uart2_pre", "uart2_frac", "xin24m" };
  201. PNAME(mux_sclk_uart3_p) = { "uart3_pre", "uart3_frac", "xin24m" };
  202. PNAME(mux_sclk_hsadc_p) = { "hsadc_src", "hsadc_frac", "ext_hsadc" };
  203. PNAME(mux_mac_p) = { "gpll", "dpll" };
  204. PNAME(mux_sclk_macref_p) = { "mac_src", "ext_rmii" };
  205. static struct rockchip_pll_clock rk3066_pll_clks[] __initdata = {
  206. [apll] = PLL(pll_rk3066, PLL_APLL, "apll", mux_pll_p, 0, RK2928_PLL_CON(0),
  207. RK2928_MODE_CON, 0, 5, 0, rk3188_pll_rates),
  208. [dpll] = PLL(pll_rk3066, PLL_DPLL, "dpll", mux_pll_p, 0, RK2928_PLL_CON(4),
  209. RK2928_MODE_CON, 4, 4, 0, NULL),
  210. [cpll] = PLL(pll_rk3066, PLL_CPLL, "cpll", mux_pll_p, 0, RK2928_PLL_CON(8),
  211. RK2928_MODE_CON, 8, 6, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
  212. [gpll] = PLL(pll_rk3066, PLL_GPLL, "gpll", mux_pll_p, 0, RK2928_PLL_CON(12),
  213. RK2928_MODE_CON, 12, 7, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
  214. };
  215. static struct rockchip_pll_clock rk3188_pll_clks[] __initdata = {
  216. [apll] = PLL(pll_rk3066, PLL_APLL, "apll", mux_pll_p, 0, RK2928_PLL_CON(0),
  217. RK2928_MODE_CON, 0, 6, 0, rk3188_pll_rates),
  218. [dpll] = PLL(pll_rk3066, PLL_DPLL, "dpll", mux_pll_p, 0, RK2928_PLL_CON(4),
  219. RK2928_MODE_CON, 4, 5, 0, NULL),
  220. [cpll] = PLL(pll_rk3066, PLL_CPLL, "cpll", mux_pll_p, 0, RK2928_PLL_CON(8),
  221. RK2928_MODE_CON, 8, 7, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
  222. [gpll] = PLL(pll_rk3066, PLL_GPLL, "gpll", mux_pll_p, 0, RK2928_PLL_CON(12),
  223. RK2928_MODE_CON, 12, 8, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
  224. };
  225. #define MFLAGS CLK_MUX_HIWORD_MASK
  226. #define DFLAGS CLK_DIVIDER_HIWORD_MASK
  227. #define GFLAGS (CLK_GATE_HIWORD_MASK | CLK_GATE_SET_TO_DISABLE)
  228. #define IFLAGS ROCKCHIP_INVERTER_HIWORD_MASK
  229. /* 2 ^ (val + 1) */
  230. static struct clk_div_table div_core_peri_t[] = {
  231. { .val = 0, .div = 2 },
  232. { .val = 1, .div = 4 },
  233. { .val = 2, .div = 8 },
  234. { .val = 3, .div = 16 },
  235. { /* sentinel */ },
  236. };
  237. static struct rockchip_clk_branch common_hsadc_out_fracmux __initdata =
  238. MUX(0, "sclk_hsadc_out", mux_sclk_hsadc_p, 0,
  239. RK2928_CLKSEL_CON(22), 4, 2, MFLAGS);
  240. static struct rockchip_clk_branch common_spdif_fracmux __initdata =
  241. MUX(SCLK_SPDIF, "sclk_spdif", mux_sclk_spdif_p, CLK_SET_RATE_PARENT,
  242. RK2928_CLKSEL_CON(5), 8, 2, MFLAGS);
  243. static struct rockchip_clk_branch common_uart0_fracmux __initdata =
  244. MUX(SCLK_UART0, "sclk_uart0", mux_sclk_uart0_p, 0,
  245. RK2928_CLKSEL_CON(13), 8, 2, MFLAGS);
  246. static struct rockchip_clk_branch common_uart1_fracmux __initdata =
  247. MUX(SCLK_UART1, "sclk_uart1", mux_sclk_uart1_p, 0,
  248. RK2928_CLKSEL_CON(14), 8, 2, MFLAGS);
  249. static struct rockchip_clk_branch common_uart2_fracmux __initdata =
  250. MUX(SCLK_UART2, "sclk_uart2", mux_sclk_uart2_p, 0,
  251. RK2928_CLKSEL_CON(15), 8, 2, MFLAGS);
  252. static struct rockchip_clk_branch common_uart3_fracmux __initdata =
  253. MUX(SCLK_UART3, "sclk_uart3", mux_sclk_uart3_p, 0,
  254. RK2928_CLKSEL_CON(16), 8, 2, MFLAGS);
  255. static struct rockchip_clk_branch common_clk_branches[] __initdata = {
  256. /*
  257. * Clock-Architecture Diagram 2
  258. */
  259. GATE(0, "gpll_armclk", "gpll", 0, RK2928_CLKGATE_CON(0), 1, GFLAGS),
  260. /* these two are set by the cpuclk and should not be changed */
  261. COMPOSITE_NOMUX_DIVTBL(CORE_PERI, "core_peri", "armclk", 0,
  262. RK2928_CLKSEL_CON(0), 6, 2, DFLAGS | CLK_DIVIDER_READ_ONLY,
  263. div_core_peri_t, RK2928_CLKGATE_CON(0), 0, GFLAGS),
  264. COMPOSITE(0, "aclk_vepu", mux_pll_src_cpll_gpll_p, 0,
  265. RK2928_CLKSEL_CON(32), 7, 1, MFLAGS, 0, 5, DFLAGS,
  266. RK2928_CLKGATE_CON(3), 9, GFLAGS),
  267. GATE(0, "hclk_vepu", "aclk_vepu", 0,
  268. RK2928_CLKGATE_CON(3), 10, GFLAGS),
  269. COMPOSITE(0, "aclk_vdpu", mux_pll_src_cpll_gpll_p, 0,
  270. RK2928_CLKSEL_CON(32), 15, 1, MFLAGS, 8, 5, DFLAGS,
  271. RK2928_CLKGATE_CON(3), 11, GFLAGS),
  272. GATE(0, "hclk_vdpu", "aclk_vdpu", 0,
  273. RK2928_CLKGATE_CON(3), 12, GFLAGS),
  274. GATE(0, "gpll_ddr", "gpll", CLK_IGNORE_UNUSED,
  275. RK2928_CLKGATE_CON(1), 7, GFLAGS),
  276. COMPOSITE(0, "ddrphy", mux_ddrphy_p, CLK_IGNORE_UNUSED,
  277. RK2928_CLKSEL_CON(26), 8, 1, MFLAGS, 0, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
  278. RK2928_CLKGATE_CON(0), 2, GFLAGS),
  279. GATE(0, "aclk_cpu", "aclk_cpu_pre", 0,
  280. RK2928_CLKGATE_CON(0), 3, GFLAGS),
  281. GATE(0, "atclk_cpu", "pclk_cpu_pre", 0,
  282. RK2928_CLKGATE_CON(0), 6, GFLAGS),
  283. GATE(0, "pclk_cpu", "pclk_cpu_pre", 0,
  284. RK2928_CLKGATE_CON(0), 5, GFLAGS),
  285. GATE(0, "hclk_cpu", "hclk_cpu_pre", CLK_IGNORE_UNUSED,
  286. RK2928_CLKGATE_CON(0), 4, GFLAGS),
  287. COMPOSITE(0, "aclk_lcdc0_pre", mux_pll_src_cpll_gpll_p, CLK_IGNORE_UNUSED,
  288. RK2928_CLKSEL_CON(31), 7, 1, MFLAGS, 0, 5, DFLAGS,
  289. RK2928_CLKGATE_CON(3), 0, GFLAGS),
  290. COMPOSITE(0, "aclk_lcdc1_pre", mux_pll_src_cpll_gpll_p, 0,
  291. RK2928_CLKSEL_CON(31), 15, 1, MFLAGS, 8, 5, DFLAGS,
  292. RK2928_CLKGATE_CON(1), 4, GFLAGS),
  293. GATE(0, "aclk_peri", "aclk_peri_pre", 0,
  294. RK2928_CLKGATE_CON(2), 1, GFLAGS),
  295. COMPOSITE_NOMUX(0, "hclk_peri", "aclk_peri_pre", 0,
  296. RK2928_CLKSEL_CON(10), 8, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
  297. RK2928_CLKGATE_CON(2), 2, GFLAGS),
  298. COMPOSITE_NOMUX(0, "pclk_peri", "aclk_peri_pre", 0,
  299. RK2928_CLKSEL_CON(10), 12, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
  300. RK2928_CLKGATE_CON(2), 3, GFLAGS),
  301. MUX(0, "cif_src", mux_pll_src_cpll_gpll_p, 0,
  302. RK2928_CLKSEL_CON(29), 0, 1, MFLAGS),
  303. COMPOSITE_NOMUX(0, "cif0_pre", "cif_src", 0,
  304. RK2928_CLKSEL_CON(29), 1, 5, DFLAGS,
  305. RK2928_CLKGATE_CON(3), 7, GFLAGS),
  306. MUX(SCLK_CIF0, "sclk_cif0", mux_sclk_cif0_p, 0,
  307. RK2928_CLKSEL_CON(29), 7, 1, MFLAGS),
  308. GATE(0, "pclkin_cif0", "ext_cif0", 0,
  309. RK2928_CLKGATE_CON(3), 3, GFLAGS),
  310. INVERTER(0, "pclk_cif0", "pclkin_cif0",
  311. RK2928_CLKSEL_CON(30), 8, IFLAGS),
  312. FACTOR(0, "xin12m", "xin24m", 0, 1, 2),
  313. /*
  314. * the 480m are generated inside the usb block from these clocks,
  315. * but they are also a source for the hsicphy clock.
  316. */
  317. GATE(SCLK_OTGPHY0, "sclk_otgphy0", "xin24m", CLK_IGNORE_UNUSED,
  318. RK2928_CLKGATE_CON(1), 5, GFLAGS),
  319. GATE(SCLK_OTGPHY1, "sclk_otgphy1", "xin24m", CLK_IGNORE_UNUSED,
  320. RK2928_CLKGATE_CON(1), 6, GFLAGS),
  321. COMPOSITE(0, "mac_src", mux_mac_p, 0,
  322. RK2928_CLKSEL_CON(21), 0, 1, MFLAGS, 8, 5, DFLAGS,
  323. RK2928_CLKGATE_CON(2), 5, GFLAGS),
  324. MUX(SCLK_MAC, "sclk_macref", mux_sclk_macref_p, CLK_SET_RATE_PARENT,
  325. RK2928_CLKSEL_CON(21), 4, 1, MFLAGS),
  326. GATE(0, "sclk_mac_lbtest", "sclk_macref",
  327. RK2928_CLKGATE_CON(2), 12, 0, GFLAGS),
  328. COMPOSITE(0, "hsadc_src", mux_pll_src_gpll_cpll_p, 0,
  329. RK2928_CLKSEL_CON(22), 0, 1, MFLAGS, 8, 8, DFLAGS,
  330. RK2928_CLKGATE_CON(2), 6, GFLAGS),
  331. COMPOSITE_FRACMUX(0, "hsadc_frac", "hsadc_src", 0,
  332. RK2928_CLKSEL_CON(23), 0,
  333. RK2928_CLKGATE_CON(2), 7, GFLAGS,
  334. &common_hsadc_out_fracmux),
  335. INVERTER(SCLK_HSADC, "sclk_hsadc", "sclk_hsadc_out",
  336. RK2928_CLKSEL_CON(22), 7, IFLAGS),
  337. COMPOSITE_NOMUX(SCLK_SARADC, "sclk_saradc", "xin24m", 0,
  338. RK2928_CLKSEL_CON(24), 8, 8, DFLAGS,
  339. RK2928_CLKGATE_CON(2), 8, GFLAGS),
  340. COMPOSITE_NOMUX(0, "spdif_pre", "i2s_src", 0,
  341. RK2928_CLKSEL_CON(5), 0, 7, DFLAGS,
  342. RK2928_CLKGATE_CON(0), 13, GFLAGS),
  343. COMPOSITE_FRACMUX(0, "spdif_frac", "spdif_pll", CLK_SET_RATE_PARENT,
  344. RK2928_CLKSEL_CON(9), 0,
  345. RK2928_CLKGATE_CON(0), 14, GFLAGS,
  346. &common_spdif_fracmux),
  347. /*
  348. * Clock-Architecture Diagram 4
  349. */
  350. GATE(SCLK_SMC, "sclk_smc", "hclk_peri",
  351. RK2928_CLKGATE_CON(2), 4, 0, GFLAGS),
  352. COMPOSITE_NOMUX(SCLK_SPI0, "sclk_spi0", "pclk_peri", 0,
  353. RK2928_CLKSEL_CON(25), 0, 7, DFLAGS,
  354. RK2928_CLKGATE_CON(2), 9, GFLAGS),
  355. COMPOSITE_NOMUX(SCLK_SPI1, "sclk_spi1", "pclk_peri", 0,
  356. RK2928_CLKSEL_CON(25), 8, 7, DFLAGS,
  357. RK2928_CLKGATE_CON(2), 10, GFLAGS),
  358. COMPOSITE_NOMUX(SCLK_SDMMC, "sclk_sdmmc", "hclk_peri", 0,
  359. RK2928_CLKSEL_CON(11), 0, 6, DFLAGS,
  360. RK2928_CLKGATE_CON(2), 11, GFLAGS),
  361. COMPOSITE_NOMUX(SCLK_SDIO, "sclk_sdio", "hclk_peri", 0,
  362. RK2928_CLKSEL_CON(12), 0, 6, DFLAGS,
  363. RK2928_CLKGATE_CON(2), 13, GFLAGS),
  364. COMPOSITE_NOMUX(SCLK_EMMC, "sclk_emmc", "hclk_peri", 0,
  365. RK2928_CLKSEL_CON(12), 8, 6, DFLAGS,
  366. RK2928_CLKGATE_CON(2), 14, GFLAGS),
  367. MUX(0, "uart_src", mux_pll_src_gpll_cpll_p, 0,
  368. RK2928_CLKSEL_CON(12), 15, 1, MFLAGS),
  369. COMPOSITE_NOMUX(0, "uart0_pre", "uart_src", 0,
  370. RK2928_CLKSEL_CON(13), 0, 7, DFLAGS,
  371. RK2928_CLKGATE_CON(1), 8, GFLAGS),
  372. COMPOSITE_FRACMUX(0, "uart0_frac", "uart0_pre", 0,
  373. RK2928_CLKSEL_CON(17), 0,
  374. RK2928_CLKGATE_CON(1), 9, GFLAGS,
  375. &common_uart0_fracmux),
  376. COMPOSITE_NOMUX(0, "uart1_pre", "uart_src", 0,
  377. RK2928_CLKSEL_CON(14), 0, 7, DFLAGS,
  378. RK2928_CLKGATE_CON(1), 10, GFLAGS),
  379. COMPOSITE_FRACMUX(0, "uart1_frac", "uart1_pre", 0,
  380. RK2928_CLKSEL_CON(18), 0,
  381. RK2928_CLKGATE_CON(1), 11, GFLAGS,
  382. &common_uart1_fracmux),
  383. COMPOSITE_NOMUX(0, "uart2_pre", "uart_src", 0,
  384. RK2928_CLKSEL_CON(15), 0, 7, DFLAGS,
  385. RK2928_CLKGATE_CON(1), 12, GFLAGS),
  386. COMPOSITE_FRACMUX(0, "uart2_frac", "uart2_pre", 0,
  387. RK2928_CLKSEL_CON(19), 0,
  388. RK2928_CLKGATE_CON(1), 13, GFLAGS,
  389. &common_uart2_fracmux),
  390. COMPOSITE_NOMUX(0, "uart3_pre", "uart_src", 0,
  391. RK2928_CLKSEL_CON(16), 0, 7, DFLAGS,
  392. RK2928_CLKGATE_CON(1), 14, GFLAGS),
  393. COMPOSITE_FRACMUX(0, "uart3_frac", "uart3_pre", 0,
  394. RK2928_CLKSEL_CON(20), 0,
  395. RK2928_CLKGATE_CON(1), 15, GFLAGS,
  396. &common_uart3_fracmux),
  397. GATE(SCLK_JTAG, "jtag", "ext_jtag", 0, RK2928_CLKGATE_CON(1), 3, GFLAGS),
  398. GATE(SCLK_TIMER0, "timer0", "xin24m", 0, RK2928_CLKGATE_CON(1), 0, GFLAGS),
  399. GATE(SCLK_TIMER1, "timer1", "xin24m", 0, RK2928_CLKGATE_CON(1), 1, GFLAGS),
  400. /* clk_core_pre gates */
  401. GATE(0, "core_dbg", "armclk", 0, RK2928_CLKGATE_CON(9), 0, GFLAGS),
  402. /* aclk_cpu gates */
  403. GATE(ACLK_DMA1, "aclk_dma1", "aclk_cpu", 0, RK2928_CLKGATE_CON(5), 0, GFLAGS),
  404. GATE(0, "aclk_intmem", "aclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 12, GFLAGS),
  405. GATE(0, "aclk_strc_sys", "aclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 10, GFLAGS),
  406. /* hclk_cpu gates */
  407. GATE(HCLK_ROM, "hclk_rom", "hclk_cpu", 0, RK2928_CLKGATE_CON(5), 6, GFLAGS),
  408. GATE(HCLK_I2S0, "hclk_i2s0", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 2, GFLAGS),
  409. GATE(HCLK_SPDIF, "hclk_spdif", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 1, GFLAGS),
  410. GATE(0, "hclk_cpubus", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 8, GFLAGS),
  411. /* hclk_ahb2apb is part of a clk branch */
  412. GATE(0, "hclk_vio_bus", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 12, GFLAGS),
  413. GATE(HCLK_LCDC0, "hclk_lcdc0", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 1, GFLAGS),
  414. GATE(HCLK_LCDC1, "hclk_lcdc1", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 2, GFLAGS),
  415. GATE(HCLK_CIF0, "hclk_cif0", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 4, GFLAGS),
  416. GATE(HCLK_IPP, "hclk_ipp", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 9, GFLAGS),
  417. GATE(HCLK_RGA, "hclk_rga", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 10, GFLAGS),
  418. /* hclk_peri gates */
  419. GATE(0, "hclk_peri_axi_matrix", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 0, GFLAGS),
  420. GATE(0, "hclk_peri_ahb_arbi", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 6, GFLAGS),
  421. GATE(0, "hclk_emem_peri", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 7, GFLAGS),
  422. GATE(HCLK_EMAC, "hclk_emac", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 0, GFLAGS),
  423. GATE(HCLK_NANDC0, "hclk_nandc0", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 9, GFLAGS),
  424. GATE(0, "hclk_usb_peri", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 5, GFLAGS),
  425. GATE(HCLK_OTG0, "hclk_usbotg0", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(5), 13, GFLAGS),
  426. GATE(HCLK_HSADC, "hclk_hsadc", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 5, GFLAGS),
  427. GATE(HCLK_PIDF, "hclk_pidfilter", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 6, GFLAGS),
  428. GATE(HCLK_SDMMC, "hclk_sdmmc", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 10, GFLAGS),
  429. GATE(HCLK_SDIO, "hclk_sdio", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 11, GFLAGS),
  430. GATE(HCLK_EMMC, "hclk_emmc", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 12, GFLAGS),
  431. /* aclk_lcdc0_pre gates */
  432. GATE(0, "aclk_vio0", "aclk_lcdc0_pre", 0, RK2928_CLKGATE_CON(6), 13, GFLAGS),
  433. GATE(ACLK_LCDC0, "aclk_lcdc0", "aclk_vio0", 0, RK2928_CLKGATE_CON(6), 0, GFLAGS),
  434. GATE(ACLK_CIF0, "aclk_cif0", "aclk_vio0", 0, RK2928_CLKGATE_CON(6), 5, GFLAGS),
  435. GATE(ACLK_IPP, "aclk_ipp", "aclk_vio0", 0, RK2928_CLKGATE_CON(6), 8, GFLAGS),
  436. /* aclk_lcdc1_pre gates */
  437. GATE(0, "aclk_vio1", "aclk_lcdc1_pre", 0, RK2928_CLKGATE_CON(9), 5, GFLAGS),
  438. GATE(ACLK_LCDC1, "aclk_lcdc1", "aclk_vio1", 0, RK2928_CLKGATE_CON(6), 3, GFLAGS),
  439. GATE(ACLK_RGA, "aclk_rga", "aclk_vio1", 0, RK2928_CLKGATE_CON(6), 11, GFLAGS),
  440. /* atclk_cpu gates */
  441. GATE(0, "atclk", "atclk_cpu", 0, RK2928_CLKGATE_CON(9), 3, GFLAGS),
  442. GATE(0, "trace", "atclk_cpu", 0, RK2928_CLKGATE_CON(9), 2, GFLAGS),
  443. /* pclk_cpu gates */
  444. GATE(PCLK_PWM01, "pclk_pwm01", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 10, GFLAGS),
  445. GATE(PCLK_TIMER0, "pclk_timer0", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 7, GFLAGS),
  446. GATE(PCLK_I2C0, "pclk_i2c0", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 4, GFLAGS),
  447. GATE(PCLK_I2C1, "pclk_i2c1", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 5, GFLAGS),
  448. GATE(PCLK_GPIO0, "pclk_gpio0", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 9, GFLAGS),
  449. GATE(PCLK_GPIO1, "pclk_gpio1", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 10, GFLAGS),
  450. GATE(PCLK_GPIO2, "pclk_gpio2", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 11, GFLAGS),
  451. GATE(PCLK_EFUSE, "pclk_efuse", "pclk_cpu", 0, RK2928_CLKGATE_CON(5), 2, GFLAGS),
  452. GATE(PCLK_TZPC, "pclk_tzpc", "pclk_cpu", 0, RK2928_CLKGATE_CON(5), 3, GFLAGS),
  453. GATE(0, "pclk_ddrupctl", "pclk_cpu", 0, RK2928_CLKGATE_CON(5), 7, GFLAGS),
  454. GATE(0, "pclk_ddrpubl", "pclk_cpu", 0, RK2928_CLKGATE_CON(9), 6, GFLAGS),
  455. GATE(0, "pclk_dbg", "pclk_cpu", 0, RK2928_CLKGATE_CON(9), 1, GFLAGS),
  456. GATE(PCLK_GRF, "pclk_grf", "pclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(5), 4, GFLAGS),
  457. GATE(PCLK_PMU, "pclk_pmu", "pclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(5), 5, GFLAGS),
  458. /* aclk_peri */
  459. GATE(ACLK_DMA2, "aclk_dma2", "aclk_peri", 0, RK2928_CLKGATE_CON(5), 1, GFLAGS),
  460. GATE(ACLK_SMC, "aclk_smc", "aclk_peri", 0, RK2928_CLKGATE_CON(5), 8, GFLAGS),
  461. GATE(0, "aclk_peri_niu", "aclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 4, GFLAGS),
  462. GATE(0, "aclk_cpu_peri", "aclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 2, GFLAGS),
  463. GATE(0, "aclk_peri_axi_matrix", "aclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 3, GFLAGS),
  464. /* pclk_peri gates */
  465. GATE(0, "pclk_peri_axi_matrix", "pclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 1, GFLAGS),
  466. GATE(PCLK_PWM23, "pclk_pwm23", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 11, GFLAGS),
  467. GATE(PCLK_WDT, "pclk_wdt", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 15, GFLAGS),
  468. GATE(PCLK_SPI0, "pclk_spi0", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 12, GFLAGS),
  469. GATE(PCLK_SPI1, "pclk_spi1", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 13, GFLAGS),
  470. GATE(PCLK_UART2, "pclk_uart2", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 2, GFLAGS),
  471. GATE(PCLK_UART3, "pclk_uart3", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 3, GFLAGS),
  472. GATE(PCLK_I2C2, "pclk_i2c2", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 6, GFLAGS),
  473. GATE(PCLK_I2C3, "pclk_i2c3", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 7, GFLAGS),
  474. GATE(PCLK_I2C4, "pclk_i2c4", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 8, GFLAGS),
  475. GATE(PCLK_GPIO3, "pclk_gpio3", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 12, GFLAGS),
  476. GATE(PCLK_SARADC, "pclk_saradc", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 14, GFLAGS),
  477. };
  478. PNAME(mux_rk3066_lcdc0_p) = { "dclk_lcdc0_src", "xin27m" };
  479. PNAME(mux_rk3066_lcdc1_p) = { "dclk_lcdc1_src", "xin27m" };
  480. PNAME(mux_sclk_cif1_p) = { "cif1_pre", "xin24m" };
  481. PNAME(mux_sclk_i2s1_p) = { "i2s1_pre", "i2s1_frac", "xin12m" };
  482. PNAME(mux_sclk_i2s2_p) = { "i2s2_pre", "i2s2_frac", "xin12m" };
  483. static struct clk_div_table div_aclk_cpu_t[] = {
  484. { .val = 0, .div = 1 },
  485. { .val = 1, .div = 2 },
  486. { .val = 2, .div = 3 },
  487. { .val = 3, .div = 4 },
  488. { .val = 4, .div = 8 },
  489. { /* sentinel */ },
  490. };
  491. static struct rockchip_clk_branch rk3066a_i2s0_fracmux __initdata =
  492. MUX(SCLK_I2S0, "sclk_i2s0", mux_sclk_i2s0_p, 0,
  493. RK2928_CLKSEL_CON(2), 8, 2, MFLAGS);
  494. static struct rockchip_clk_branch rk3066a_i2s1_fracmux __initdata =
  495. MUX(SCLK_I2S1, "sclk_i2s1", mux_sclk_i2s1_p, 0,
  496. RK2928_CLKSEL_CON(3), 8, 2, MFLAGS);
  497. static struct rockchip_clk_branch rk3066a_i2s2_fracmux __initdata =
  498. MUX(SCLK_I2S2, "sclk_i2s2", mux_sclk_i2s2_p, 0,
  499. RK2928_CLKSEL_CON(4), 8, 2, MFLAGS);
  500. static struct rockchip_clk_branch rk3066a_clk_branches[] __initdata = {
  501. DIVTBL(0, "aclk_cpu_pre", "armclk", 0,
  502. RK2928_CLKSEL_CON(1), 0, 3, DFLAGS | CLK_DIVIDER_READ_ONLY, div_aclk_cpu_t),
  503. DIV(0, "pclk_cpu_pre", "aclk_cpu_pre", 0,
  504. RK2928_CLKSEL_CON(1), 12, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO
  505. | CLK_DIVIDER_READ_ONLY),
  506. DIV(0, "hclk_cpu_pre", "aclk_cpu_pre", 0,
  507. RK2928_CLKSEL_CON(1), 8, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO
  508. | CLK_DIVIDER_READ_ONLY),
  509. COMPOSITE_NOMUX(0, "hclk_ahb2apb", "hclk_cpu_pre", 0,
  510. RK2928_CLKSEL_CON(1), 14, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO
  511. | CLK_DIVIDER_READ_ONLY,
  512. RK2928_CLKGATE_CON(4), 9, GFLAGS),
  513. GATE(CORE_L2C, "core_l2c", "aclk_cpu", CLK_IGNORE_UNUSED,
  514. RK2928_CLKGATE_CON(9), 4, GFLAGS),
  515. COMPOSITE(0, "aclk_peri_pre", mux_pll_src_gpll_cpll_p, 0,
  516. RK2928_CLKSEL_CON(10), 15, 1, MFLAGS, 0, 5, DFLAGS,
  517. RK2928_CLKGATE_CON(2), 0, GFLAGS),
  518. COMPOSITE(0, "dclk_lcdc0_src", mux_pll_src_cpll_gpll_p, 0,
  519. RK2928_CLKSEL_CON(27), 0, 1, MFLAGS, 8, 8, DFLAGS,
  520. RK2928_CLKGATE_CON(3), 1, GFLAGS),
  521. MUX(DCLK_LCDC0, "dclk_lcdc0", mux_rk3066_lcdc0_p, 0,
  522. RK2928_CLKSEL_CON(27), 4, 1, MFLAGS),
  523. COMPOSITE(0, "dclk_lcdc1_src", mux_pll_src_cpll_gpll_p, 0,
  524. RK2928_CLKSEL_CON(28), 0, 1, MFLAGS, 8, 8, DFLAGS,
  525. RK2928_CLKGATE_CON(3), 2, GFLAGS),
  526. MUX(DCLK_LCDC1, "dclk_lcdc1", mux_rk3066_lcdc1_p, 0,
  527. RK2928_CLKSEL_CON(28), 4, 1, MFLAGS),
  528. COMPOSITE_NOMUX(0, "cif1_pre", "cif_src", 0,
  529. RK2928_CLKSEL_CON(29), 8, 5, DFLAGS,
  530. RK2928_CLKGATE_CON(3), 8, GFLAGS),
  531. MUX(SCLK_CIF1, "sclk_cif1", mux_sclk_cif1_p, 0,
  532. RK2928_CLKSEL_CON(29), 15, 1, MFLAGS),
  533. GATE(0, "pclkin_cif1", "ext_cif1", 0,
  534. RK2928_CLKGATE_CON(3), 4, GFLAGS),
  535. INVERTER(0, "pclk_cif1", "pclkin_cif1",
  536. RK2928_CLKSEL_CON(30), 12, IFLAGS),
  537. COMPOSITE(0, "aclk_gpu_src", mux_pll_src_cpll_gpll_p, 0,
  538. RK2928_CLKSEL_CON(33), 8, 1, MFLAGS, 0, 5, DFLAGS,
  539. RK2928_CLKGATE_CON(3), 13, GFLAGS),
  540. GATE(ACLK_GPU, "aclk_gpu", "aclk_gpu_src", 0,
  541. RK2928_CLKGATE_CON(5), 15, GFLAGS),
  542. GATE(SCLK_TIMER2, "timer2", "xin24m", 0,
  543. RK2928_CLKGATE_CON(3), 2, GFLAGS),
  544. COMPOSITE_NOMUX(SCLK_TSADC, "sclk_tsadc", "xin24m", 0,
  545. RK2928_CLKSEL_CON(34), 0, 16, DFLAGS,
  546. RK2928_CLKGATE_CON(2), 15, GFLAGS),
  547. MUX(0, "i2s_src", mux_pll_src_gpll_cpll_p, 0,
  548. RK2928_CLKSEL_CON(2), 15, 1, MFLAGS),
  549. COMPOSITE_NOMUX(0, "i2s0_pre", "i2s_src", 0,
  550. RK2928_CLKSEL_CON(2), 0, 7, DFLAGS,
  551. RK2928_CLKGATE_CON(0), 7, GFLAGS),
  552. COMPOSITE_FRACMUX(0, "i2s0_frac", "i2s0_pre", 0,
  553. RK2928_CLKSEL_CON(6), 0,
  554. RK2928_CLKGATE_CON(0), 8, GFLAGS,
  555. &rk3066a_i2s0_fracmux),
  556. COMPOSITE_NOMUX(0, "i2s1_pre", "i2s_src", 0,
  557. RK2928_CLKSEL_CON(3), 0, 7, DFLAGS,
  558. RK2928_CLKGATE_CON(0), 9, GFLAGS),
  559. COMPOSITE_FRACMUX(0, "i2s1_frac", "i2s1_pre", 0,
  560. RK2928_CLKSEL_CON(7), 0,
  561. RK2928_CLKGATE_CON(0), 10, GFLAGS,
  562. &rk3066a_i2s1_fracmux),
  563. COMPOSITE_NOMUX(0, "i2s2_pre", "i2s_src", 0,
  564. RK2928_CLKSEL_CON(4), 0, 7, DFLAGS,
  565. RK2928_CLKGATE_CON(0), 11, GFLAGS),
  566. COMPOSITE_FRACMUX(0, "i2s2_frac", "i2s2_pre", 0,
  567. RK2928_CLKSEL_CON(8), 0,
  568. RK2928_CLKGATE_CON(0), 12, GFLAGS,
  569. &rk3066a_i2s2_fracmux),
  570. GATE(HCLK_I2S1, "hclk_i2s1", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 3, GFLAGS),
  571. GATE(HCLK_I2S2, "hclk_i2s2", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 4, GFLAGS),
  572. GATE(0, "hclk_cif1", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 6, GFLAGS),
  573. GATE(0, "hclk_hdmi", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 14, GFLAGS),
  574. GATE(HCLK_OTG1, "hclk_usbotg1", "hclk_peri", CLK_IGNORE_UNUSED,
  575. RK2928_CLKGATE_CON(5), 14, GFLAGS),
  576. GATE(0, "aclk_cif1", "aclk_vio1", 0, RK2928_CLKGATE_CON(6), 7, GFLAGS),
  577. GATE(PCLK_TIMER1, "pclk_timer1", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 8, GFLAGS),
  578. GATE(PCLK_TIMER2, "pclk_timer2", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 9, GFLAGS),
  579. GATE(PCLK_GPIO6, "pclk_gpio6", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 15, GFLAGS),
  580. GATE(PCLK_UART0, "pclk_uart0", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 0, GFLAGS),
  581. GATE(PCLK_UART1, "pclk_uart1", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 1, GFLAGS),
  582. GATE(PCLK_GPIO4, "pclk_gpio4", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 13, GFLAGS),
  583. GATE(PCLK_TSADC, "pclk_tsadc", "pclk_peri", 0, RK2928_CLKGATE_CON(4), 13, GFLAGS),
  584. };
  585. static struct clk_div_table div_rk3188_aclk_core_t[] = {
  586. { .val = 0, .div = 1 },
  587. { .val = 1, .div = 2 },
  588. { .val = 2, .div = 3 },
  589. { .val = 3, .div = 4 },
  590. { .val = 4, .div = 8 },
  591. { /* sentinel */ },
  592. };
  593. PNAME(mux_hsicphy_p) = { "sclk_otgphy0_480m", "sclk_otgphy1_480m",
  594. "gpll", "cpll" };
  595. static struct rockchip_clk_branch rk3188_i2s0_fracmux __initdata =
  596. MUX(SCLK_I2S0, "sclk_i2s0", mux_sclk_i2s0_p, CLK_SET_RATE_PARENT,
  597. RK2928_CLKSEL_CON(3), 8, 2, MFLAGS);
  598. static struct rockchip_clk_branch rk3188_clk_branches[] __initdata = {
  599. COMPOSITE_NOMUX_DIVTBL(0, "aclk_core", "armclk", CLK_IGNORE_UNUSED,
  600. RK2928_CLKSEL_CON(1), 3, 3, DFLAGS | CLK_DIVIDER_READ_ONLY,
  601. div_rk3188_aclk_core_t, RK2928_CLKGATE_CON(0), 7, GFLAGS),
  602. /* do not source aclk_cpu_pre from the apll, to keep complexity down */
  603. COMPOSITE_NOGATE(0, "aclk_cpu_pre", mux_aclk_cpu_p, CLK_SET_RATE_NO_REPARENT,
  604. RK2928_CLKSEL_CON(0), 5, 1, MFLAGS, 0, 5, DFLAGS),
  605. DIV(0, "pclk_cpu_pre", "aclk_cpu_pre", 0,
  606. RK2928_CLKSEL_CON(1), 12, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO),
  607. DIV(0, "hclk_cpu_pre", "aclk_cpu_pre", 0,
  608. RK2928_CLKSEL_CON(1), 8, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO),
  609. COMPOSITE_NOMUX(0, "hclk_ahb2apb", "hclk_cpu_pre", 0,
  610. RK2928_CLKSEL_CON(1), 14, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
  611. RK2928_CLKGATE_CON(4), 9, GFLAGS),
  612. GATE(CORE_L2C, "core_l2c", "armclk", CLK_IGNORE_UNUSED,
  613. RK2928_CLKGATE_CON(9), 4, GFLAGS),
  614. COMPOSITE(0, "aclk_peri_pre", mux_pll_src_cpll_gpll_p, 0,
  615. RK2928_CLKSEL_CON(10), 15, 1, MFLAGS, 0, 5, DFLAGS,
  616. RK2928_CLKGATE_CON(2), 0, GFLAGS),
  617. COMPOSITE(DCLK_LCDC0, "dclk_lcdc0", mux_pll_src_cpll_gpll_p, 0,
  618. RK2928_CLKSEL_CON(27), 0, 1, MFLAGS, 8, 8, DFLAGS,
  619. RK2928_CLKGATE_CON(3), 1, GFLAGS),
  620. COMPOSITE(DCLK_LCDC1, "dclk_lcdc1", mux_pll_src_cpll_gpll_p, 0,
  621. RK2928_CLKSEL_CON(28), 0, 1, MFLAGS, 8, 8, DFLAGS,
  622. RK2928_CLKGATE_CON(3), 2, GFLAGS),
  623. COMPOSITE(0, "aclk_gpu_src", mux_pll_src_cpll_gpll_p, 0,
  624. RK2928_CLKSEL_CON(34), 7, 1, MFLAGS, 0, 5, DFLAGS,
  625. RK2928_CLKGATE_CON(3), 15, GFLAGS),
  626. GATE(ACLK_GPU, "aclk_gpu", "aclk_gpu_src", 0,
  627. RK2928_CLKGATE_CON(9), 7, GFLAGS),
  628. GATE(SCLK_TIMER2, "timer2", "xin24m", 0, RK2928_CLKGATE_CON(3), 4, GFLAGS),
  629. GATE(SCLK_TIMER3, "timer3", "xin24m", 0, RK2928_CLKGATE_CON(1), 2, GFLAGS),
  630. GATE(SCLK_TIMER4, "timer4", "xin24m", 0, RK2928_CLKGATE_CON(3), 5, GFLAGS),
  631. GATE(SCLK_TIMER5, "timer5", "xin24m", 0, RK2928_CLKGATE_CON(3), 8, GFLAGS),
  632. GATE(SCLK_TIMER6, "timer6", "xin24m", 0, RK2928_CLKGATE_CON(3), 14, GFLAGS),
  633. COMPOSITE_NODIV(0, "sclk_hsicphy_480m", mux_hsicphy_p, 0,
  634. RK2928_CLKSEL_CON(30), 0, 2, DFLAGS,
  635. RK2928_CLKGATE_CON(3), 6, GFLAGS),
  636. DIV(0, "sclk_hsicphy_12m", "sclk_hsicphy_480m", 0,
  637. RK2928_CLKSEL_CON(11), 8, 6, DFLAGS),
  638. MUX(0, "i2s_src", mux_pll_src_gpll_cpll_p, 0,
  639. RK2928_CLKSEL_CON(2), 15, 1, MFLAGS),
  640. COMPOSITE_NOMUX(0, "i2s0_pre", "i2s_src", 0,
  641. RK2928_CLKSEL_CON(3), 0, 7, DFLAGS,
  642. RK2928_CLKGATE_CON(0), 9, GFLAGS),
  643. COMPOSITE_FRACMUX(0, "i2s0_frac", "i2s0_pre", CLK_SET_RATE_PARENT,
  644. RK2928_CLKSEL_CON(7), 0,
  645. RK2928_CLKGATE_CON(0), 10, GFLAGS,
  646. &rk3188_i2s0_fracmux),
  647. GATE(0, "hclk_imem0", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 14, GFLAGS),
  648. GATE(0, "hclk_imem1", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 15, GFLAGS),
  649. GATE(HCLK_OTG1, "hclk_usbotg1", "hclk_peri", CLK_IGNORE_UNUSED,
  650. RK2928_CLKGATE_CON(7), 3, GFLAGS),
  651. GATE(HCLK_HSIC, "hclk_hsic", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 4, GFLAGS),
  652. GATE(PCLK_TIMER3, "pclk_timer3", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 9, GFLAGS),
  653. GATE(PCLK_UART0, "pclk_uart0", "hclk_ahb2apb", 0, RK2928_CLKGATE_CON(8), 0, GFLAGS),
  654. GATE(PCLK_UART1, "pclk_uart1", "hclk_ahb2apb", 0, RK2928_CLKGATE_CON(8), 1, GFLAGS),
  655. GATE(ACLK_GPS, "aclk_gps", "aclk_peri", 0, RK2928_CLKGATE_CON(8), 13, GFLAGS),
  656. };
  657. static const char *const rk3188_critical_clocks[] __initconst = {
  658. "aclk_cpu",
  659. "aclk_peri",
  660. "hclk_peri",
  661. "pclk_cpu",
  662. "pclk_peri",
  663. "hclk_cpubus"
  664. };
  665. static struct rockchip_clk_provider *__init rk3188_common_clk_init(struct device_node *np)
  666. {
  667. struct rockchip_clk_provider *ctx;
  668. void __iomem *reg_base;
  669. reg_base = of_iomap(np, 0);
  670. if (!reg_base) {
  671. pr_err("%s: could not map cru region\n", __func__);
  672. return ERR_PTR(-ENOMEM);
  673. }
  674. ctx = rockchip_clk_init(np, reg_base, CLK_NR_CLKS);
  675. if (IS_ERR(ctx)) {
  676. pr_err("%s: rockchip clk init failed\n", __func__);
  677. iounmap(reg_base);
  678. return ERR_PTR(-ENOMEM);
  679. }
  680. rockchip_clk_register_branches(ctx, common_clk_branches,
  681. ARRAY_SIZE(common_clk_branches));
  682. rockchip_register_softrst(np, 9, reg_base + RK2928_SOFTRST_CON(0),
  683. ROCKCHIP_SOFTRST_HIWORD_MASK);
  684. rockchip_register_restart_notifier(ctx, RK2928_GLB_SRST_FST, NULL);
  685. return ctx;
  686. }
  687. static void __init rk3066a_clk_init(struct device_node *np)
  688. {
  689. struct rockchip_clk_provider *ctx;
  690. ctx = rk3188_common_clk_init(np);
  691. if (IS_ERR(ctx))
  692. return;
  693. rockchip_clk_register_plls(ctx, rk3066_pll_clks,
  694. ARRAY_SIZE(rk3066_pll_clks),
  695. RK3066_GRF_SOC_STATUS);
  696. rockchip_clk_register_branches(ctx, rk3066a_clk_branches,
  697. ARRAY_SIZE(rk3066a_clk_branches));
  698. rockchip_clk_register_armclk(ctx, ARMCLK, "armclk",
  699. mux_armclk_p, ARRAY_SIZE(mux_armclk_p),
  700. &rk3066_cpuclk_data, rk3066_cpuclk_rates,
  701. ARRAY_SIZE(rk3066_cpuclk_rates));
  702. rockchip_clk_protect_critical(rk3188_critical_clocks,
  703. ARRAY_SIZE(rk3188_critical_clocks));
  704. rockchip_clk_of_add_provider(np, ctx);
  705. }
  706. CLK_OF_DECLARE(rk3066a_cru, "rockchip,rk3066a-cru", rk3066a_clk_init);
  707. static void __init rk3188a_clk_init(struct device_node *np)
  708. {
  709. struct rockchip_clk_provider *ctx;
  710. struct clk *clk1, *clk2;
  711. unsigned long rate;
  712. int ret;
  713. ctx = rk3188_common_clk_init(np);
  714. if (IS_ERR(ctx))
  715. return;
  716. rockchip_clk_register_plls(ctx, rk3188_pll_clks,
  717. ARRAY_SIZE(rk3188_pll_clks),
  718. RK3188_GRF_SOC_STATUS);
  719. rockchip_clk_register_branches(ctx, rk3188_clk_branches,
  720. ARRAY_SIZE(rk3188_clk_branches));
  721. rockchip_clk_register_armclk(ctx, ARMCLK, "armclk",
  722. mux_armclk_p, ARRAY_SIZE(mux_armclk_p),
  723. &rk3188_cpuclk_data, rk3188_cpuclk_rates,
  724. ARRAY_SIZE(rk3188_cpuclk_rates));
  725. /* reparent aclk_cpu_pre from apll */
  726. clk1 = __clk_lookup("aclk_cpu_pre");
  727. clk2 = __clk_lookup("gpll");
  728. if (clk1 && clk2) {
  729. rate = clk_get_rate(clk1);
  730. ret = clk_set_parent(clk1, clk2);
  731. if (ret < 0)
  732. pr_warn("%s: could not reparent aclk_cpu_pre to gpll\n",
  733. __func__);
  734. clk_set_rate(clk1, rate);
  735. } else {
  736. pr_warn("%s: missing clocks to reparent aclk_cpu_pre to gpll\n",
  737. __func__);
  738. }
  739. rockchip_clk_protect_critical(rk3188_critical_clocks,
  740. ARRAY_SIZE(rk3188_critical_clocks));
  741. rockchip_clk_of_add_provider(np, ctx);
  742. }
  743. CLK_OF_DECLARE(rk3188a_cru, "rockchip,rk3188a-cru", rk3188a_clk_init);
  744. static void __init rk3188_clk_init(struct device_node *np)
  745. {
  746. int i;
  747. for (i = 0; i < ARRAY_SIZE(rk3188_pll_clks); i++) {
  748. struct rockchip_pll_clock *pll = &rk3188_pll_clks[i];
  749. struct rockchip_pll_rate_table *rate;
  750. if (!pll->rate_table)
  751. continue;
  752. rate = pll->rate_table;
  753. while (rate->rate > 0) {
  754. rate->nb = 1;
  755. rate++;
  756. }
  757. }
  758. rk3188a_clk_init(np);
  759. }
  760. CLK_OF_DECLARE(rk3188_cru, "rockchip,rk3188-cru", rk3188_clk_init);