ccu-sun50i-h6-r.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2017 Icenowy Zheng <icenowy@aosc.xyz>
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/of_address.h>
  7. #include <linux/platform_device.h>
  8. #include "ccu_common.h"
  9. #include "ccu_reset.h"
  10. #include "ccu_div.h"
  11. #include "ccu_gate.h"
  12. #include "ccu_mp.h"
  13. #include "ccu_nm.h"
  14. #include "ccu-sun50i-h6-r.h"
  15. /*
  16. * Information about AR100 and AHB/APB clocks in R_CCU are gathered from
  17. * clock definitions in the BSP source code.
  18. */
  19. static const char * const ar100_r_apb2_parents[] = { "osc24M", "osc32k",
  20. "iosc", "pll-periph0" };
  21. static const struct ccu_mux_var_prediv ar100_r_apb2_predivs[] = {
  22. { .index = 3, .shift = 0, .width = 5 },
  23. };
  24. static struct ccu_div ar100_clk = {
  25. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  26. .mux = {
  27. .shift = 24,
  28. .width = 2,
  29. .var_predivs = ar100_r_apb2_predivs,
  30. .n_var_predivs = ARRAY_SIZE(ar100_r_apb2_predivs),
  31. },
  32. .common = {
  33. .reg = 0x000,
  34. .features = CCU_FEATURE_VARIABLE_PREDIV,
  35. .hw.init = CLK_HW_INIT_PARENTS("ar100",
  36. ar100_r_apb2_parents,
  37. &ccu_div_ops,
  38. 0),
  39. },
  40. };
  41. static CLK_FIXED_FACTOR(r_ahb_clk, "r-ahb", "ar100", 1, 1, 0);
  42. static struct ccu_div r_apb1_clk = {
  43. .div = _SUNXI_CCU_DIV(0, 2),
  44. .common = {
  45. .reg = 0x00c,
  46. .hw.init = CLK_HW_INIT("r-apb1",
  47. "r-ahb",
  48. &ccu_div_ops,
  49. 0),
  50. },
  51. };
  52. static struct ccu_div r_apb2_clk = {
  53. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  54. .mux = {
  55. .shift = 24,
  56. .width = 2,
  57. .var_predivs = ar100_r_apb2_predivs,
  58. .n_var_predivs = ARRAY_SIZE(ar100_r_apb2_predivs),
  59. },
  60. .common = {
  61. .reg = 0x010,
  62. .features = CCU_FEATURE_VARIABLE_PREDIV,
  63. .hw.init = CLK_HW_INIT_PARENTS("r-apb2",
  64. ar100_r_apb2_parents,
  65. &ccu_div_ops,
  66. 0),
  67. },
  68. };
  69. /*
  70. * Information about the gate/resets are gathered from the clock header file
  71. * in the BSP source code, although most of them are unused. The existence
  72. * of the hardware block is verified with "3.1 Memory Mapping" chapter in
  73. * "Allwinner H6 V200 User Manual V1.1"; and the parent APB buses are verified
  74. * with "3.3.2.1 System Bus Tree" chapter inthe same document.
  75. */
  76. static SUNXI_CCU_GATE(r_apb1_timer_clk, "r-apb1-timer", "r-apb1",
  77. 0x11c, BIT(0), 0);
  78. static SUNXI_CCU_GATE(r_apb1_twd_clk, "r-apb1-twd", "r-apb1",
  79. 0x12c, BIT(0), 0);
  80. static SUNXI_CCU_GATE(r_apb1_pwm_clk, "r-apb1-pwm", "r-apb1",
  81. 0x13c, BIT(0), 0);
  82. static SUNXI_CCU_GATE(r_apb2_uart_clk, "r-apb2-uart", "r-apb2",
  83. 0x18c, BIT(0), 0);
  84. static SUNXI_CCU_GATE(r_apb2_i2c_clk, "r-apb2-i2c", "r-apb2",
  85. 0x19c, BIT(0), 0);
  86. static SUNXI_CCU_GATE(r_apb1_ir_clk, "r-apb1-ir", "r-apb1",
  87. 0x1cc, BIT(0), 0);
  88. static SUNXI_CCU_GATE(r_apb1_w1_clk, "r-apb1-w1", "r-apb1",
  89. 0x1ec, BIT(0), 0);
  90. /* Information of IR(RX) mod clock is gathered from BSP source code */
  91. static const char * const r_mod0_default_parents[] = { "osc32k", "osc24M" };
  92. static SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk, "ir",
  93. r_mod0_default_parents, 0x1c0,
  94. 0, 5, /* M */
  95. 8, 2, /* P */
  96. 24, 1, /* mux */
  97. BIT(31), /* gate */
  98. 0);
  99. /*
  100. * BSP didn't use the 1-wire function at all now, and the information about
  101. * this mod clock is guessed from the IR mod clock above. The existence of
  102. * this mod clock is proven by BSP clock header, and the dividers are verified
  103. * by contents in the 1-wire related chapter of the User Manual.
  104. */
  105. static SUNXI_CCU_MP_WITH_MUX_GATE(w1_clk, "w1",
  106. r_mod0_default_parents, 0x1e0,
  107. 0, 5, /* M */
  108. 8, 2, /* P */
  109. 24, 1, /* mux */
  110. BIT(31), /* gate */
  111. 0);
  112. static struct ccu_common *sun50i_h6_r_ccu_clks[] = {
  113. &ar100_clk.common,
  114. &r_apb1_clk.common,
  115. &r_apb2_clk.common,
  116. &r_apb1_timer_clk.common,
  117. &r_apb1_twd_clk.common,
  118. &r_apb1_pwm_clk.common,
  119. &r_apb2_uart_clk.common,
  120. &r_apb2_i2c_clk.common,
  121. &r_apb1_ir_clk.common,
  122. &r_apb1_w1_clk.common,
  123. &ir_clk.common,
  124. &w1_clk.common,
  125. };
  126. static struct clk_hw_onecell_data sun50i_h6_r_hw_clks = {
  127. .hws = {
  128. [CLK_AR100] = &ar100_clk.common.hw,
  129. [CLK_R_AHB] = &r_ahb_clk.hw,
  130. [CLK_R_APB1] = &r_apb1_clk.common.hw,
  131. [CLK_R_APB2] = &r_apb2_clk.common.hw,
  132. [CLK_R_APB1_TIMER] = &r_apb1_timer_clk.common.hw,
  133. [CLK_R_APB1_TWD] = &r_apb1_twd_clk.common.hw,
  134. [CLK_R_APB1_PWM] = &r_apb1_pwm_clk.common.hw,
  135. [CLK_R_APB2_UART] = &r_apb2_uart_clk.common.hw,
  136. [CLK_R_APB2_I2C] = &r_apb2_i2c_clk.common.hw,
  137. [CLK_R_APB1_IR] = &r_apb1_ir_clk.common.hw,
  138. [CLK_R_APB1_W1] = &r_apb1_w1_clk.common.hw,
  139. [CLK_IR] = &ir_clk.common.hw,
  140. [CLK_W1] = &w1_clk.common.hw,
  141. },
  142. .num = CLK_NUMBER,
  143. };
  144. static struct ccu_reset_map sun50i_h6_r_ccu_resets[] = {
  145. [RST_R_APB1_TIMER] = { 0x11c, BIT(16) },
  146. [RST_R_APB1_TWD] = { 0x12c, BIT(16) },
  147. [RST_R_APB1_PWM] = { 0x13c, BIT(16) },
  148. [RST_R_APB2_UART] = { 0x18c, BIT(16) },
  149. [RST_R_APB2_I2C] = { 0x19c, BIT(16) },
  150. [RST_R_APB1_IR] = { 0x1cc, BIT(16) },
  151. [RST_R_APB1_W1] = { 0x1ec, BIT(16) },
  152. };
  153. static const struct sunxi_ccu_desc sun50i_h6_r_ccu_desc = {
  154. .ccu_clks = sun50i_h6_r_ccu_clks,
  155. .num_ccu_clks = ARRAY_SIZE(sun50i_h6_r_ccu_clks),
  156. .hw_clks = &sun50i_h6_r_hw_clks,
  157. .resets = sun50i_h6_r_ccu_resets,
  158. .num_resets = ARRAY_SIZE(sun50i_h6_r_ccu_resets),
  159. };
  160. static void __init sunxi_r_ccu_init(struct device_node *node,
  161. const struct sunxi_ccu_desc *desc)
  162. {
  163. void __iomem *reg;
  164. reg = of_io_request_and_map(node, 0, of_node_full_name(node));
  165. if (IS_ERR(reg)) {
  166. pr_err("%pOF: Could not map the clock registers\n", node);
  167. return;
  168. }
  169. sunxi_ccu_probe(node, reg, desc);
  170. }
  171. static void __init sun50i_h6_r_ccu_setup(struct device_node *node)
  172. {
  173. sunxi_r_ccu_init(node, &sun50i_h6_r_ccu_desc);
  174. }
  175. CLK_OF_DECLARE(sun50i_h6_r_ccu, "allwinner,sun50i-h6-r-ccu",
  176. sun50i_h6_r_ccu_setup);