ccu-sun50i-h6-r.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2017 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-sun50i-h6-r.h"
  16. /*
  17. * Information about AR100 and AHB/APB clocks in R_CCU are gathered from
  18. * clock definitions in the BSP source code.
  19. */
  20. static const char * const ar100_r_apb2_parents[] = { "osc24M", "osc32k",
  21. "iosc", "pll-periph0" };
  22. static const struct ccu_mux_var_prediv ar100_r_apb2_predivs[] = {
  23. { .index = 3, .shift = 0, .width = 5 },
  24. };
  25. static struct ccu_div ar100_clk = {
  26. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  27. .mux = {
  28. .shift = 24,
  29. .width = 2,
  30. .var_predivs = ar100_r_apb2_predivs,
  31. .n_var_predivs = ARRAY_SIZE(ar100_r_apb2_predivs),
  32. },
  33. .common = {
  34. .reg = 0x000,
  35. .features = CCU_FEATURE_VARIABLE_PREDIV,
  36. .hw.init = CLK_HW_INIT_PARENTS("ar100",
  37. ar100_r_apb2_parents,
  38. &ccu_div_ops,
  39. 0),
  40. },
  41. };
  42. static CLK_FIXED_FACTOR_HW(r_ahb_clk, "r-ahb", &ar100_clk.common.hw, 1, 1, 0);
  43. static SUNXI_CCU_M(r_apb1_clk, "r-apb1", "r-ahb", 0x00c, 0, 2, 0);
  44. static struct ccu_div r_apb2_clk = {
  45. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  46. .mux = {
  47. .shift = 24,
  48. .width = 2,
  49. .var_predivs = ar100_r_apb2_predivs,
  50. .n_var_predivs = ARRAY_SIZE(ar100_r_apb2_predivs),
  51. },
  52. .common = {
  53. .reg = 0x010,
  54. .features = CCU_FEATURE_VARIABLE_PREDIV,
  55. .hw.init = CLK_HW_INIT_PARENTS("r-apb2",
  56. ar100_r_apb2_parents,
  57. &ccu_div_ops,
  58. 0),
  59. },
  60. };
  61. /*
  62. * Information about the gate/resets are gathered from the clock header file
  63. * in the BSP source code, although most of them are unused. The existence
  64. * of the hardware block is verified with "3.1 Memory Mapping" chapter in
  65. * "Allwinner H6 V200 User Manual V1.1"; and the parent APB buses are verified
  66. * with "3.3.2.1 System Bus Tree" chapter inthe same document.
  67. */
  68. static SUNXI_CCU_GATE(r_apb1_timer_clk, "r-apb1-timer", "r-apb1",
  69. 0x11c, BIT(0), 0);
  70. static SUNXI_CCU_GATE(r_apb1_twd_clk, "r-apb1-twd", "r-apb1",
  71. 0x12c, BIT(0), 0);
  72. static SUNXI_CCU_GATE(r_apb1_pwm_clk, "r-apb1-pwm", "r-apb1",
  73. 0x13c, BIT(0), 0);
  74. static SUNXI_CCU_GATE(r_apb2_uart_clk, "r-apb2-uart", "r-apb2",
  75. 0x18c, BIT(0), 0);
  76. static SUNXI_CCU_GATE(r_apb2_i2c_clk, "r-apb2-i2c", "r-apb2",
  77. 0x19c, BIT(0), 0);
  78. static SUNXI_CCU_GATE(r_apb2_rsb_clk, "r-apb2-rsb", "r-apb2",
  79. 0x1bc, BIT(0), 0);
  80. static SUNXI_CCU_GATE(r_apb1_ir_clk, "r-apb1-ir", "r-apb1",
  81. 0x1cc, BIT(0), 0);
  82. static SUNXI_CCU_GATE(r_apb1_w1_clk, "r-apb1-w1", "r-apb1",
  83. 0x1ec, BIT(0), 0);
  84. static SUNXI_CCU_GATE(r_apb1_rtc_clk, "r-apb1-rtc", "r-apb1",
  85. 0x20c, BIT(0), CLK_IGNORE_UNUSED);
  86. /* Information of IR(RX) mod clock is gathered from BSP source code */
  87. static const char * const r_mod0_default_parents[] = { "osc32k", "osc24M" };
  88. static SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk, "ir",
  89. r_mod0_default_parents, 0x1c0,
  90. 0, 5, /* M */
  91. 8, 2, /* P */
  92. 24, 1, /* mux */
  93. BIT(31), /* gate */
  94. 0);
  95. /*
  96. * BSP didn't use the 1-wire function at all now, and the information about
  97. * this mod clock is guessed from the IR mod clock above. The existence of
  98. * this mod clock is proven by BSP clock header, and the dividers are verified
  99. * by contents in the 1-wire related chapter of the User Manual.
  100. */
  101. static SUNXI_CCU_MP_WITH_MUX_GATE(w1_clk, "w1",
  102. r_mod0_default_parents, 0x1e0,
  103. 0, 5, /* M */
  104. 8, 2, /* P */
  105. 24, 1, /* mux */
  106. BIT(31), /* gate */
  107. 0);
  108. static struct ccu_common *sun50i_h6_r_ccu_clks[] = {
  109. &ar100_clk.common,
  110. &r_apb1_clk.common,
  111. &r_apb2_clk.common,
  112. &r_apb1_timer_clk.common,
  113. &r_apb1_twd_clk.common,
  114. &r_apb1_pwm_clk.common,
  115. &r_apb2_uart_clk.common,
  116. &r_apb2_i2c_clk.common,
  117. &r_apb2_rsb_clk.common,
  118. &r_apb1_ir_clk.common,
  119. &r_apb1_w1_clk.common,
  120. &r_apb1_rtc_clk.common,
  121. &ir_clk.common,
  122. &w1_clk.common,
  123. };
  124. static struct clk_hw_onecell_data sun50i_h6_r_hw_clks = {
  125. .hws = {
  126. [CLK_AR100] = &ar100_clk.common.hw,
  127. [CLK_R_AHB] = &r_ahb_clk.hw,
  128. [CLK_R_APB1] = &r_apb1_clk.common.hw,
  129. [CLK_R_APB2] = &r_apb2_clk.common.hw,
  130. [CLK_R_APB1_TIMER] = &r_apb1_timer_clk.common.hw,
  131. [CLK_R_APB1_TWD] = &r_apb1_twd_clk.common.hw,
  132. [CLK_R_APB1_PWM] = &r_apb1_pwm_clk.common.hw,
  133. [CLK_R_APB2_UART] = &r_apb2_uart_clk.common.hw,
  134. [CLK_R_APB2_I2C] = &r_apb2_i2c_clk.common.hw,
  135. [CLK_R_APB2_RSB] = &r_apb2_rsb_clk.common.hw,
  136. [CLK_R_APB1_IR] = &r_apb1_ir_clk.common.hw,
  137. [CLK_R_APB1_W1] = &r_apb1_w1_clk.common.hw,
  138. [CLK_R_APB1_RTC] = &r_apb1_rtc_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 clk_hw_onecell_data sun50i_h616_r_hw_clks = {
  145. .hws = {
  146. [CLK_R_AHB] = &r_ahb_clk.hw,
  147. [CLK_R_APB1] = &r_apb1_clk.common.hw,
  148. [CLK_R_APB2] = &r_apb2_clk.common.hw,
  149. [CLK_R_APB1_TWD] = &r_apb1_twd_clk.common.hw,
  150. [CLK_R_APB2_I2C] = &r_apb2_i2c_clk.common.hw,
  151. [CLK_R_APB2_RSB] = &r_apb2_rsb_clk.common.hw,
  152. [CLK_R_APB1_IR] = &r_apb1_ir_clk.common.hw,
  153. [CLK_R_APB1_RTC] = &r_apb1_rtc_clk.common.hw,
  154. [CLK_IR] = &ir_clk.common.hw,
  155. },
  156. .num = CLK_NUMBER,
  157. };
  158. static struct ccu_reset_map sun50i_h6_r_ccu_resets[] = {
  159. [RST_R_APB1_TIMER] = { 0x11c, BIT(16) },
  160. [RST_R_APB1_TWD] = { 0x12c, BIT(16) },
  161. [RST_R_APB1_PWM] = { 0x13c, BIT(16) },
  162. [RST_R_APB2_UART] = { 0x18c, BIT(16) },
  163. [RST_R_APB2_I2C] = { 0x19c, BIT(16) },
  164. [RST_R_APB2_RSB] = { 0x1bc, BIT(16) },
  165. [RST_R_APB1_IR] = { 0x1cc, BIT(16) },
  166. [RST_R_APB1_W1] = { 0x1ec, BIT(16) },
  167. };
  168. static struct ccu_reset_map sun50i_h616_r_ccu_resets[] = {
  169. [RST_R_APB1_TWD] = { 0x12c, BIT(16) },
  170. [RST_R_APB2_I2C] = { 0x19c, BIT(16) },
  171. [RST_R_APB2_RSB] = { 0x1bc, BIT(16) },
  172. [RST_R_APB1_IR] = { 0x1cc, BIT(16) },
  173. };
  174. static const struct sunxi_ccu_desc sun50i_h6_r_ccu_desc = {
  175. .ccu_clks = sun50i_h6_r_ccu_clks,
  176. .num_ccu_clks = ARRAY_SIZE(sun50i_h6_r_ccu_clks),
  177. .hw_clks = &sun50i_h6_r_hw_clks,
  178. .resets = sun50i_h6_r_ccu_resets,
  179. .num_resets = ARRAY_SIZE(sun50i_h6_r_ccu_resets),
  180. };
  181. static const struct sunxi_ccu_desc sun50i_h616_r_ccu_desc = {
  182. .ccu_clks = sun50i_h6_r_ccu_clks,
  183. .num_ccu_clks = ARRAY_SIZE(sun50i_h6_r_ccu_clks),
  184. .hw_clks = &sun50i_h616_r_hw_clks,
  185. .resets = sun50i_h616_r_ccu_resets,
  186. .num_resets = ARRAY_SIZE(sun50i_h616_r_ccu_resets),
  187. };
  188. static int sun50i_h6_r_ccu_probe(struct platform_device *pdev)
  189. {
  190. const struct sunxi_ccu_desc *desc;
  191. void __iomem *reg;
  192. desc = of_device_get_match_data(&pdev->dev);
  193. if (!desc)
  194. return -EINVAL;
  195. reg = devm_platform_ioremap_resource(pdev, 0);
  196. if (IS_ERR(reg))
  197. return PTR_ERR(reg);
  198. return devm_sunxi_ccu_probe(&pdev->dev, reg, desc);
  199. }
  200. static const struct of_device_id sun50i_h6_r_ccu_ids[] = {
  201. {
  202. .compatible = "allwinner,sun50i-h6-r-ccu",
  203. .data = &sun50i_h6_r_ccu_desc,
  204. },
  205. {
  206. .compatible = "allwinner,sun50i-h616-r-ccu",
  207. .data = &sun50i_h616_r_ccu_desc,
  208. },
  209. { }
  210. };
  211. static struct platform_driver sun50i_h6_r_ccu_driver = {
  212. .probe = sun50i_h6_r_ccu_probe,
  213. .driver = {
  214. .name = "sun50i-h6-r-ccu",
  215. .suppress_bind_attrs = true,
  216. .of_match_table = sun50i_h6_r_ccu_ids,
  217. },
  218. };
  219. module_platform_driver(sun50i_h6_r_ccu_driver);
  220. MODULE_IMPORT_NS(SUNXI_CCU);
  221. MODULE_LICENSE("GPL");