ccu-sun8i-r.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016 Icenowy Zheng <[email protected]>
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/module.h>
  7. #include <linux/of_device.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_nm.h"
  15. #include "ccu-sun8i-r.h"
  16. static const struct clk_parent_data ar100_parents[] = {
  17. { .fw_name = "losc" },
  18. { .fw_name = "hosc" },
  19. { .fw_name = "pll-periph" },
  20. { .fw_name = "iosc" },
  21. };
  22. static const struct ccu_mux_var_prediv ar100_predivs[] = {
  23. { .index = 2, .shift = 8, .width = 5 },
  24. };
  25. static struct ccu_div ar100_clk = {
  26. .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
  27. .mux = {
  28. .shift = 16,
  29. .width = 2,
  30. .var_predivs = ar100_predivs,
  31. .n_var_predivs = ARRAY_SIZE(ar100_predivs),
  32. },
  33. .common = {
  34. .reg = 0x00,
  35. .features = CCU_FEATURE_VARIABLE_PREDIV,
  36. .hw.init = CLK_HW_INIT_PARENTS_DATA("ar100",
  37. ar100_parents,
  38. &ccu_div_ops,
  39. 0),
  40. },
  41. };
  42. static CLK_FIXED_FACTOR_HW(ahb0_clk, "ahb0", &ar100_clk.common.hw, 1, 1, 0);
  43. static SUNXI_CCU_M(apb0_clk, "apb0", "ahb0", 0x0c, 0, 2, 0);
  44. /*
  45. * Define the parent as an array that can be reused to save space
  46. * instead of having compound literals for each gate. Also have it
  47. * non-const so we can change it on the A83T.
  48. */
  49. static const struct clk_hw *apb0_gate_parent[] = { &apb0_clk.common.hw };
  50. static SUNXI_CCU_GATE_HWS(apb0_pio_clk, "apb0-pio",
  51. apb0_gate_parent, 0x28, BIT(0), 0);
  52. static SUNXI_CCU_GATE_HWS(apb0_ir_clk, "apb0-ir",
  53. apb0_gate_parent, 0x28, BIT(1), 0);
  54. static SUNXI_CCU_GATE_HWS(apb0_timer_clk, "apb0-timer",
  55. apb0_gate_parent, 0x28, BIT(2), 0);
  56. static SUNXI_CCU_GATE_HWS(apb0_rsb_clk, "apb0-rsb",
  57. apb0_gate_parent, 0x28, BIT(3), 0);
  58. static SUNXI_CCU_GATE_HWS(apb0_uart_clk, "apb0-uart",
  59. apb0_gate_parent, 0x28, BIT(4), 0);
  60. static SUNXI_CCU_GATE_HWS(apb0_i2c_clk, "apb0-i2c",
  61. apb0_gate_parent, 0x28, BIT(6), 0);
  62. static SUNXI_CCU_GATE_HWS(apb0_twd_clk, "apb0-twd",
  63. apb0_gate_parent, 0x28, BIT(7), 0);
  64. static const char * const r_mod0_default_parents[] = { "osc32k", "osc24M" };
  65. static SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk, "ir",
  66. r_mod0_default_parents, 0x54,
  67. 0, 4, /* M */
  68. 16, 2, /* P */
  69. 24, 2, /* mux */
  70. BIT(31), /* gate */
  71. 0);
  72. static const struct clk_parent_data a83t_r_mod0_parents[] = {
  73. { .fw_name = "iosc" },
  74. { .fw_name = "hosc" },
  75. };
  76. static const struct ccu_mux_fixed_prediv a83t_ir_predivs[] = {
  77. { .index = 0, .div = 16 },
  78. };
  79. static struct ccu_mp a83t_ir_clk = {
  80. .enable = BIT(31),
  81. .m = _SUNXI_CCU_DIV(0, 4),
  82. .p = _SUNXI_CCU_DIV(16, 2),
  83. .mux = {
  84. .shift = 24,
  85. .width = 2,
  86. .fixed_predivs = a83t_ir_predivs,
  87. .n_predivs = ARRAY_SIZE(a83t_ir_predivs),
  88. },
  89. .common = {
  90. .reg = 0x54,
  91. .features = CCU_FEATURE_VARIABLE_PREDIV,
  92. .hw.init = CLK_HW_INIT_PARENTS_DATA("ir",
  93. a83t_r_mod0_parents,
  94. &ccu_mp_ops,
  95. 0),
  96. },
  97. };
  98. static struct ccu_common *sun8i_r_ccu_clks[] = {
  99. &ar100_clk.common,
  100. &apb0_clk.common,
  101. &apb0_pio_clk.common,
  102. &apb0_ir_clk.common,
  103. &apb0_timer_clk.common,
  104. &apb0_rsb_clk.common,
  105. &apb0_uart_clk.common,
  106. &apb0_i2c_clk.common,
  107. &apb0_twd_clk.common,
  108. &ir_clk.common,
  109. &a83t_ir_clk.common,
  110. };
  111. static struct clk_hw_onecell_data sun8i_a83t_r_hw_clks = {
  112. .hws = {
  113. [CLK_AR100] = &ar100_clk.common.hw,
  114. [CLK_AHB0] = &ahb0_clk.hw,
  115. [CLK_APB0] = &apb0_clk.common.hw,
  116. [CLK_APB0_PIO] = &apb0_pio_clk.common.hw,
  117. [CLK_APB0_IR] = &apb0_ir_clk.common.hw,
  118. [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw,
  119. [CLK_APB0_RSB] = &apb0_rsb_clk.common.hw,
  120. [CLK_APB0_UART] = &apb0_uart_clk.common.hw,
  121. [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw,
  122. [CLK_APB0_TWD] = &apb0_twd_clk.common.hw,
  123. [CLK_IR] = &a83t_ir_clk.common.hw,
  124. },
  125. .num = CLK_NUMBER,
  126. };
  127. static struct clk_hw_onecell_data sun8i_h3_r_hw_clks = {
  128. .hws = {
  129. [CLK_AR100] = &ar100_clk.common.hw,
  130. [CLK_AHB0] = &ahb0_clk.hw,
  131. [CLK_APB0] = &apb0_clk.common.hw,
  132. [CLK_APB0_PIO] = &apb0_pio_clk.common.hw,
  133. [CLK_APB0_IR] = &apb0_ir_clk.common.hw,
  134. [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw,
  135. [CLK_APB0_UART] = &apb0_uart_clk.common.hw,
  136. [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw,
  137. [CLK_APB0_TWD] = &apb0_twd_clk.common.hw,
  138. [CLK_IR] = &ir_clk.common.hw,
  139. },
  140. .num = CLK_NUMBER,
  141. };
  142. static struct clk_hw_onecell_data sun50i_a64_r_hw_clks = {
  143. .hws = {
  144. [CLK_AR100] = &ar100_clk.common.hw,
  145. [CLK_AHB0] = &ahb0_clk.hw,
  146. [CLK_APB0] = &apb0_clk.common.hw,
  147. [CLK_APB0_PIO] = &apb0_pio_clk.common.hw,
  148. [CLK_APB0_IR] = &apb0_ir_clk.common.hw,
  149. [CLK_APB0_TIMER] = &apb0_timer_clk.common.hw,
  150. [CLK_APB0_RSB] = &apb0_rsb_clk.common.hw,
  151. [CLK_APB0_UART] = &apb0_uart_clk.common.hw,
  152. [CLK_APB0_I2C] = &apb0_i2c_clk.common.hw,
  153. [CLK_APB0_TWD] = &apb0_twd_clk.common.hw,
  154. [CLK_IR] = &ir_clk.common.hw,
  155. },
  156. .num = CLK_NUMBER,
  157. };
  158. static struct ccu_reset_map sun8i_a83t_r_ccu_resets[] = {
  159. [RST_APB0_IR] = { 0xb0, BIT(1) },
  160. [RST_APB0_TIMER] = { 0xb0, BIT(2) },
  161. [RST_APB0_RSB] = { 0xb0, BIT(3) },
  162. [RST_APB0_UART] = { 0xb0, BIT(4) },
  163. [RST_APB0_I2C] = { 0xb0, BIT(6) },
  164. };
  165. static struct ccu_reset_map sun8i_h3_r_ccu_resets[] = {
  166. [RST_APB0_IR] = { 0xb0, BIT(1) },
  167. [RST_APB0_TIMER] = { 0xb0, BIT(2) },
  168. [RST_APB0_UART] = { 0xb0, BIT(4) },
  169. [RST_APB0_I2C] = { 0xb0, BIT(6) },
  170. };
  171. static struct ccu_reset_map sun50i_a64_r_ccu_resets[] = {
  172. [RST_APB0_IR] = { 0xb0, BIT(1) },
  173. [RST_APB0_TIMER] = { 0xb0, BIT(2) },
  174. [RST_APB0_RSB] = { 0xb0, BIT(3) },
  175. [RST_APB0_UART] = { 0xb0, BIT(4) },
  176. [RST_APB0_I2C] = { 0xb0, BIT(6) },
  177. };
  178. static const struct sunxi_ccu_desc sun8i_a83t_r_ccu_desc = {
  179. .ccu_clks = sun8i_r_ccu_clks,
  180. .num_ccu_clks = ARRAY_SIZE(sun8i_r_ccu_clks),
  181. .hw_clks = &sun8i_a83t_r_hw_clks,
  182. .resets = sun8i_a83t_r_ccu_resets,
  183. .num_resets = ARRAY_SIZE(sun8i_a83t_r_ccu_resets),
  184. };
  185. static const struct sunxi_ccu_desc sun8i_h3_r_ccu_desc = {
  186. .ccu_clks = sun8i_r_ccu_clks,
  187. .num_ccu_clks = ARRAY_SIZE(sun8i_r_ccu_clks),
  188. .hw_clks = &sun8i_h3_r_hw_clks,
  189. .resets = sun8i_h3_r_ccu_resets,
  190. .num_resets = ARRAY_SIZE(sun8i_h3_r_ccu_resets),
  191. };
  192. static const struct sunxi_ccu_desc sun50i_a64_r_ccu_desc = {
  193. .ccu_clks = sun8i_r_ccu_clks,
  194. .num_ccu_clks = ARRAY_SIZE(sun8i_r_ccu_clks),
  195. .hw_clks = &sun50i_a64_r_hw_clks,
  196. .resets = sun50i_a64_r_ccu_resets,
  197. .num_resets = ARRAY_SIZE(sun50i_a64_r_ccu_resets),
  198. };
  199. static int sun8i_r_ccu_probe(struct platform_device *pdev)
  200. {
  201. const struct sunxi_ccu_desc *desc;
  202. void __iomem *reg;
  203. desc = of_device_get_match_data(&pdev->dev);
  204. if (!desc)
  205. return -EINVAL;
  206. reg = devm_platform_ioremap_resource(pdev, 0);
  207. if (IS_ERR(reg))
  208. return PTR_ERR(reg);
  209. return devm_sunxi_ccu_probe(&pdev->dev, reg, desc);
  210. }
  211. static const struct of_device_id sun8i_r_ccu_ids[] = {
  212. {
  213. .compatible = "allwinner,sun8i-a83t-r-ccu",
  214. .data = &sun8i_a83t_r_ccu_desc,
  215. },
  216. {
  217. .compatible = "allwinner,sun8i-h3-r-ccu",
  218. .data = &sun8i_h3_r_ccu_desc,
  219. },
  220. {
  221. .compatible = "allwinner,sun50i-a64-r-ccu",
  222. .data = &sun50i_a64_r_ccu_desc,
  223. },
  224. { }
  225. };
  226. static struct platform_driver sun8i_r_ccu_driver = {
  227. .probe = sun8i_r_ccu_probe,
  228. .driver = {
  229. .name = "sun8i-r-ccu",
  230. .suppress_bind_attrs = true,
  231. .of_match_table = sun8i_r_ccu_ids,
  232. },
  233. };
  234. module_platform_driver(sun8i_r_ccu_driver);
  235. MODULE_IMPORT_NS(SUNXI_CCU);
  236. MODULE_LICENSE("GPL");