ccu-sun8i-r.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * Copyright (c) 2016 Icenowy Zheng <icenowy@aosc.xyz>
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/clk-provider.h>
  14. #include <linux/of_address.h>
  15. #include <linux/platform_device.h>
  16. #include "ccu_common.h"
  17. #include "ccu_reset.h"
  18. #include "ccu_div.h"
  19. #include "ccu_gate.h"
  20. #include "ccu_mp.h"
  21. #include "ccu_nm.h"
  22. #include "ccu-sun8i-r.h"
  23. static const char * const ar100_parents[] = { "osc32k", "osc24M",
  24. "pll-periph0", "iosc" };
  25. static const char * const a83t_ar100_parents[] = { "osc16M-d512", "osc24M",
  26. "pll-periph0", "iosc" };
  27. static const struct ccu_mux_var_prediv ar100_predivs[] = {
  28. { .index = 2, .shift = 8, .width = 5 },
  29. };
  30. static struct ccu_div ar100_clk = {
  31. .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
  32. .mux = {
  33. .shift = 16,
  34. .width = 2,
  35. .var_predivs = ar100_predivs,
  36. .n_var_predivs = ARRAY_SIZE(ar100_predivs),
  37. },
  38. .common = {
  39. .reg = 0x00,
  40. .features = CCU_FEATURE_VARIABLE_PREDIV,
  41. .hw.init = CLK_HW_INIT_PARENTS("ar100",
  42. ar100_parents,
  43. &ccu_div_ops,
  44. 0),
  45. },
  46. };
  47. static struct ccu_div a83t_ar100_clk = {
  48. .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
  49. .mux = {
  50. .shift = 16,
  51. .width = 2,
  52. .var_predivs = ar100_predivs,
  53. .n_var_predivs = ARRAY_SIZE(ar100_predivs),
  54. },
  55. .common = {
  56. .reg = 0x00,
  57. .features = CCU_FEATURE_VARIABLE_PREDIV,
  58. .hw.init = CLK_HW_INIT_PARENTS("ar100",
  59. a83t_ar100_parents,
  60. &ccu_div_ops,
  61. 0),
  62. },
  63. };
  64. static CLK_FIXED_FACTOR(ahb0_clk, "ahb0", "ar100", 1, 1, 0);
  65. static struct ccu_div apb0_clk = {
  66. .div = _SUNXI_CCU_DIV_FLAGS(0, 2, CLK_DIVIDER_POWER_OF_TWO),
  67. .common = {
  68. .reg = 0x0c,
  69. .hw.init = CLK_HW_INIT("apb0",
  70. "ahb0",
  71. &ccu_div_ops,
  72. 0),
  73. },
  74. };
  75. static SUNXI_CCU_M(a83t_apb0_clk, "apb0", "ahb0", 0x0c, 0, 2, 0);
  76. static SUNXI_CCU_GATE(apb0_pio_clk, "apb0-pio", "apb0",
  77. 0x28, BIT(0), 0);
  78. static SUNXI_CCU_GATE(apb0_ir_clk, "apb0-ir", "apb0",
  79. 0x28, BIT(1), 0);
  80. static SUNXI_CCU_GATE(apb0_timer_clk, "apb0-timer", "apb0",
  81. 0x28, BIT(2), 0);
  82. static SUNXI_CCU_GATE(apb0_rsb_clk, "apb0-rsb", "apb0",
  83. 0x28, BIT(3), 0);
  84. static SUNXI_CCU_GATE(apb0_uart_clk, "apb0-uart", "apb0",
  85. 0x28, BIT(4), 0);
  86. static SUNXI_CCU_GATE(apb0_i2c_clk, "apb0-i2c", "apb0",
  87. 0x28, BIT(6), 0);
  88. static SUNXI_CCU_GATE(apb0_twd_clk, "apb0-twd", "apb0",
  89. 0x28, BIT(7), 0);
  90. static const char * const r_mod0_default_parents[] = { "osc32k", "osc24M" };
  91. static SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk, "ir",
  92. r_mod0_default_parents, 0x54,
  93. 0, 4, /* M */
  94. 16, 2, /* P */
  95. 24, 2, /* mux */
  96. BIT(31), /* gate */
  97. 0);
  98. static const char *const a83t_r_mod0_parents[] = { "osc16M", "osc24M" };
  99. static const struct ccu_mux_fixed_prediv a83t_ir_predivs[] = {
  100. { .index = 0, .div = 16 },
  101. };
  102. static struct ccu_mp a83t_ir_clk = {
  103. .enable = BIT(31),
  104. .m = _SUNXI_CCU_DIV(0, 4),
  105. .p = _SUNXI_CCU_DIV(16, 2),
  106. .mux = {
  107. .shift = 24,
  108. .width = 2,
  109. .fixed_predivs = a83t_ir_predivs,
  110. .n_predivs = ARRAY_SIZE(a83t_ir_predivs),
  111. },
  112. .common = {
  113. .reg = 0x54,
  114. .features = CCU_FEATURE_VARIABLE_PREDIV,
  115. .hw.init = CLK_HW_INIT_PARENTS("ir",
  116. a83t_r_mod0_parents,
  117. &ccu_mp_ops,
  118. 0),
  119. },
  120. };
  121. static struct ccu_common *sun8i_a83t_r_ccu_clks[] = {
  122. &a83t_ar100_clk.common,
  123. &a83t_apb0_clk.common,
  124. &apb0_pio_clk.common,
  125. &apb0_ir_clk.common,
  126. &apb0_timer_clk.common,
  127. &apb0_rsb_clk.common,
  128. &apb0_uart_clk.common,
  129. &apb0_i2c_clk.common,
  130. &apb0_twd_clk.common,
  131. &a83t_ir_clk.common,
  132. };
  133. static struct ccu_common *sun8i_h3_r_ccu_clks[] = {
  134. &ar100_clk.common,
  135. &apb0_clk.common,
  136. &apb0_pio_clk.common,
  137. &apb0_ir_clk.common,
  138. &apb0_timer_clk.common,
  139. &apb0_uart_clk.common,
  140. &apb0_i2c_clk.common,
  141. &apb0_twd_clk.common,
  142. &ir_clk.common,
  143. };
  144. static struct ccu_common *sun50i_a64_r_ccu_clks[] = {
  145. &ar100_clk.common,
  146. &apb0_clk.common,
  147. &apb0_pio_clk.common,
  148. &apb0_ir_clk.common,
  149. &apb0_timer_clk.common,
  150. &apb0_rsb_clk.common,
  151. &apb0_uart_clk.common,
  152. &apb0_i2c_clk.common,
  153. &apb0_twd_clk.common,
  154. &ir_clk.common,
  155. };
  156. static struct clk_hw_onecell_data sun8i_a83t_r_hw_clks = {
  157. .hws = {
  158. [CLK_AR100] = &a83t_ar100_clk.common.hw,
  159. [CLK_AHB0] = &ahb0_clk.hw,
  160. [CLK_APB0] = &a83t_apb0_clk.common.hw,
  161. [CLK_APB0_PIO] = &apb0_pio_clk.common.hw,
  162. [CLK_APB0_IR] = &apb0_ir_clk.common.hw,
  163. [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw,
  164. [CLK_APB0_RSB] = &apb0_rsb_clk.common.hw,
  165. [CLK_APB0_UART] = &apb0_uart_clk.common.hw,
  166. [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw,
  167. [CLK_APB0_TWD] = &apb0_twd_clk.common.hw,
  168. [CLK_IR] = &a83t_ir_clk.common.hw,
  169. },
  170. .num = CLK_NUMBER,
  171. };
  172. static struct clk_hw_onecell_data sun8i_h3_r_hw_clks = {
  173. .hws = {
  174. [CLK_AR100] = &ar100_clk.common.hw,
  175. [CLK_AHB0] = &ahb0_clk.hw,
  176. [CLK_APB0] = &apb0_clk.common.hw,
  177. [CLK_APB0_PIO] = &apb0_pio_clk.common.hw,
  178. [CLK_APB0_IR] = &apb0_ir_clk.common.hw,
  179. [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw,
  180. [CLK_APB0_UART] = &apb0_uart_clk.common.hw,
  181. [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw,
  182. [CLK_APB0_TWD] = &apb0_twd_clk.common.hw,
  183. [CLK_IR] = &ir_clk.common.hw,
  184. },
  185. .num = CLK_NUMBER,
  186. };
  187. static struct clk_hw_onecell_data sun50i_a64_r_hw_clks = {
  188. .hws = {
  189. [CLK_AR100] = &ar100_clk.common.hw,
  190. [CLK_AHB0] = &ahb0_clk.hw,
  191. [CLK_APB0] = &apb0_clk.common.hw,
  192. [CLK_APB0_PIO] = &apb0_pio_clk.common.hw,
  193. [CLK_APB0_IR] = &apb0_ir_clk.common.hw,
  194. [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw,
  195. [CLK_APB0_RSB] = &apb0_rsb_clk.common.hw,
  196. [CLK_APB0_UART] = &apb0_uart_clk.common.hw,
  197. [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw,
  198. [CLK_APB0_TWD] = &apb0_twd_clk.common.hw,
  199. [CLK_IR] = &ir_clk.common.hw,
  200. },
  201. .num = CLK_NUMBER,
  202. };
  203. static struct ccu_reset_map sun8i_a83t_r_ccu_resets[] = {
  204. [RST_APB0_IR] = { 0xb0, BIT(1) },
  205. [RST_APB0_TIMER] = { 0xb0, BIT(2) },
  206. [RST_APB0_RSB] = { 0xb0, BIT(3) },
  207. [RST_APB0_UART] = { 0xb0, BIT(4) },
  208. [RST_APB0_I2C] = { 0xb0, BIT(6) },
  209. };
  210. static struct ccu_reset_map sun8i_h3_r_ccu_resets[] = {
  211. [RST_APB0_IR] = { 0xb0, BIT(1) },
  212. [RST_APB0_TIMER] = { 0xb0, BIT(2) },
  213. [RST_APB0_UART] = { 0xb0, BIT(4) },
  214. [RST_APB0_I2C] = { 0xb0, BIT(6) },
  215. };
  216. static struct ccu_reset_map sun50i_a64_r_ccu_resets[] = {
  217. [RST_APB0_IR] = { 0xb0, BIT(1) },
  218. [RST_APB0_TIMER] = { 0xb0, BIT(2) },
  219. [RST_APB0_RSB] = { 0xb0, BIT(3) },
  220. [RST_APB0_UART] = { 0xb0, BIT(4) },
  221. [RST_APB0_I2C] = { 0xb0, BIT(6) },
  222. };
  223. static const struct sunxi_ccu_desc sun8i_a83t_r_ccu_desc = {
  224. .ccu_clks = sun8i_a83t_r_ccu_clks,
  225. .num_ccu_clks = ARRAY_SIZE(sun8i_a83t_r_ccu_clks),
  226. .hw_clks = &sun8i_a83t_r_hw_clks,
  227. .resets = sun8i_a83t_r_ccu_resets,
  228. .num_resets = ARRAY_SIZE(sun8i_a83t_r_ccu_resets),
  229. };
  230. static const struct sunxi_ccu_desc sun8i_h3_r_ccu_desc = {
  231. .ccu_clks = sun8i_h3_r_ccu_clks,
  232. .num_ccu_clks = ARRAY_SIZE(sun8i_h3_r_ccu_clks),
  233. .hw_clks = &sun8i_h3_r_hw_clks,
  234. .resets = sun8i_h3_r_ccu_resets,
  235. .num_resets = ARRAY_SIZE(sun8i_h3_r_ccu_resets),
  236. };
  237. static const struct sunxi_ccu_desc sun50i_a64_r_ccu_desc = {
  238. .ccu_clks = sun50i_a64_r_ccu_clks,
  239. .num_ccu_clks = ARRAY_SIZE(sun50i_a64_r_ccu_clks),
  240. .hw_clks = &sun50i_a64_r_hw_clks,
  241. .resets = sun50i_a64_r_ccu_resets,
  242. .num_resets = ARRAY_SIZE(sun50i_a64_r_ccu_resets),
  243. };
  244. static void __init sunxi_r_ccu_init(struct device_node *node,
  245. const struct sunxi_ccu_desc *desc)
  246. {
  247. void __iomem *reg;
  248. reg = of_io_request_and_map(node, 0, of_node_full_name(node));
  249. if (IS_ERR(reg)) {
  250. pr_err("%pOF: Could not map the clock registers\n", node);
  251. return;
  252. }
  253. sunxi_ccu_probe(node, reg, desc);
  254. }
  255. static void __init sun8i_a83t_r_ccu_setup(struct device_node *node)
  256. {
  257. sunxi_r_ccu_init(node, &sun8i_a83t_r_ccu_desc);
  258. }
  259. CLK_OF_DECLARE(sun8i_a83t_r_ccu, "allwinner,sun8i-a83t-r-ccu",
  260. sun8i_a83t_r_ccu_setup);
  261. static void __init sun8i_h3_r_ccu_setup(struct device_node *node)
  262. {
  263. sunxi_r_ccu_init(node, &sun8i_h3_r_ccu_desc);
  264. }
  265. CLK_OF_DECLARE(sun8i_h3_r_ccu, "allwinner,sun8i-h3-r-ccu",
  266. sun8i_h3_r_ccu_setup);
  267. static void __init sun50i_a64_r_ccu_setup(struct device_node *node)
  268. {
  269. sunxi_r_ccu_init(node, &sun50i_a64_r_ccu_desc);
  270. }
  271. CLK_OF_DECLARE(sun50i_a64_r_ccu, "allwinner,sun50i-a64-r-ccu",
  272. sun50i_a64_r_ccu_setup);