ccu-sun50i-a100-r.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2020 Yangtao Li <[email protected]>
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/module.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-a100-r.h"
  15. static const char * const cpus_r_apb2_parents[] = { "dcxo24M", "osc32k",
  16. "iosc", "pll-periph0" };
  17. static const struct ccu_mux_var_prediv cpus_r_apb2_predivs[] = {
  18. { .index = 3, .shift = 0, .width = 5 },
  19. };
  20. static struct ccu_div r_cpus_clk = {
  21. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  22. .mux = {
  23. .shift = 24,
  24. .width = 2,
  25. .var_predivs = cpus_r_apb2_predivs,
  26. .n_var_predivs = ARRAY_SIZE(cpus_r_apb2_predivs),
  27. },
  28. .common = {
  29. .reg = 0x000,
  30. .features = CCU_FEATURE_VARIABLE_PREDIV,
  31. .hw.init = CLK_HW_INIT_PARENTS("cpus",
  32. cpus_r_apb2_parents,
  33. &ccu_div_ops,
  34. 0),
  35. },
  36. };
  37. static CLK_FIXED_FACTOR_HW(r_ahb_clk, "r-ahb", &r_cpus_clk.common.hw, 1, 1, 0);
  38. static struct ccu_div r_apb1_clk = {
  39. .div = _SUNXI_CCU_DIV(0, 2),
  40. .common = {
  41. .reg = 0x00c,
  42. .hw.init = CLK_HW_INIT("r-apb1",
  43. "r-ahb",
  44. &ccu_div_ops,
  45. 0),
  46. },
  47. };
  48. static struct ccu_div r_apb2_clk = {
  49. .div = _SUNXI_CCU_DIV_FLAGS(8, 2, CLK_DIVIDER_POWER_OF_TWO),
  50. .mux = {
  51. .shift = 24,
  52. .width = 2,
  53. .var_predivs = cpus_r_apb2_predivs,
  54. .n_var_predivs = ARRAY_SIZE(cpus_r_apb2_predivs),
  55. },
  56. .common = {
  57. .reg = 0x010,
  58. .features = CCU_FEATURE_VARIABLE_PREDIV,
  59. .hw.init = CLK_HW_INIT_PARENTS("r-apb2",
  60. cpus_r_apb2_parents,
  61. &ccu_div_ops,
  62. 0),
  63. },
  64. };
  65. static const struct clk_parent_data clk_parent_r_apb1[] = {
  66. { .hw = &r_apb1_clk.common.hw },
  67. };
  68. static const struct clk_parent_data clk_parent_r_apb2[] = {
  69. { .hw = &r_apb2_clk.common.hw },
  70. };
  71. static SUNXI_CCU_GATE_DATA(r_apb1_timer_clk, "r-apb1-timer", clk_parent_r_apb1,
  72. 0x11c, BIT(0), 0);
  73. static SUNXI_CCU_GATE_DATA(r_apb1_twd_clk, "r-apb1-twd", clk_parent_r_apb1,
  74. 0x12c, BIT(0), 0);
  75. static const char * const r_apb1_pwm_clk_parents[] = { "dcxo24M", "osc32k",
  76. "iosc" };
  77. static SUNXI_CCU_MUX(r_apb1_pwm_clk, "r-apb1-pwm", r_apb1_pwm_clk_parents,
  78. 0x130, 24, 2, 0);
  79. static SUNXI_CCU_GATE_DATA(r_apb1_bus_pwm_clk, "r-apb1-bus-pwm",
  80. clk_parent_r_apb1, 0x13c, BIT(0), 0);
  81. static SUNXI_CCU_GATE_DATA(r_apb1_ppu_clk, "r-apb1-ppu", clk_parent_r_apb1,
  82. 0x17c, BIT(0), 0);
  83. static SUNXI_CCU_GATE_DATA(r_apb2_uart_clk, "r-apb2-uart", clk_parent_r_apb2,
  84. 0x18c, BIT(0), 0);
  85. static SUNXI_CCU_GATE_DATA(r_apb2_i2c0_clk, "r-apb2-i2c0", clk_parent_r_apb2,
  86. 0x19c, BIT(0), 0);
  87. static SUNXI_CCU_GATE_DATA(r_apb2_i2c1_clk, "r-apb2-i2c1", clk_parent_r_apb2,
  88. 0x19c, BIT(1), 0);
  89. static const char * const r_apb1_ir_rx_parents[] = { "osc32k", "dcxo24M" };
  90. static SUNXI_CCU_MP_WITH_MUX_GATE(r_apb1_ir_rx_clk, "r-apb1-ir-rx",
  91. r_apb1_ir_rx_parents, 0x1c0,
  92. 0, 5, /* M */
  93. 8, 2, /* P */
  94. 24, 1, /* mux */
  95. BIT(31), /* gate */
  96. 0);
  97. static SUNXI_CCU_GATE_DATA(r_apb1_bus_ir_rx_clk, "r-apb1-bus-ir-rx",
  98. clk_parent_r_apb1, 0x1cc, BIT(0), 0);
  99. static SUNXI_CCU_GATE(r_ahb_bus_rtc_clk, "r-ahb-rtc", "r-ahb",
  100. 0x20c, BIT(0), 0);
  101. static struct ccu_common *sun50i_a100_r_ccu_clks[] = {
  102. &r_cpus_clk.common,
  103. &r_apb1_clk.common,
  104. &r_apb2_clk.common,
  105. &r_apb1_timer_clk.common,
  106. &r_apb1_twd_clk.common,
  107. &r_apb1_pwm_clk.common,
  108. &r_apb1_bus_pwm_clk.common,
  109. &r_apb1_ppu_clk.common,
  110. &r_apb2_uart_clk.common,
  111. &r_apb2_i2c0_clk.common,
  112. &r_apb2_i2c1_clk.common,
  113. &r_apb1_ir_rx_clk.common,
  114. &r_apb1_bus_ir_rx_clk.common,
  115. &r_ahb_bus_rtc_clk.common,
  116. };
  117. static struct clk_hw_onecell_data sun50i_a100_r_hw_clks = {
  118. .hws = {
  119. [CLK_R_CPUS] = &r_cpus_clk.common.hw,
  120. [CLK_R_AHB] = &r_ahb_clk.hw,
  121. [CLK_R_APB1] = &r_apb1_clk.common.hw,
  122. [CLK_R_APB2] = &r_apb2_clk.common.hw,
  123. [CLK_R_APB1_TIMER] = &r_apb1_timer_clk.common.hw,
  124. [CLK_R_APB1_TWD] = &r_apb1_twd_clk.common.hw,
  125. [CLK_R_APB1_PWM] = &r_apb1_pwm_clk.common.hw,
  126. [CLK_R_APB1_BUS_PWM] = &r_apb1_bus_pwm_clk.common.hw,
  127. [CLK_R_APB1_PPU] = &r_apb1_ppu_clk.common.hw,
  128. [CLK_R_APB2_UART] = &r_apb2_uart_clk.common.hw,
  129. [CLK_R_APB2_I2C0] = &r_apb2_i2c0_clk.common.hw,
  130. [CLK_R_APB2_I2C1] = &r_apb2_i2c1_clk.common.hw,
  131. [CLK_R_APB1_IR] = &r_apb1_ir_rx_clk.common.hw,
  132. [CLK_R_APB1_BUS_IR] = &r_apb1_bus_ir_rx_clk.common.hw,
  133. [CLK_R_AHB_BUS_RTC] = &r_ahb_bus_rtc_clk.common.hw,
  134. },
  135. .num = CLK_NUMBER,
  136. };
  137. static struct ccu_reset_map sun50i_a100_r_ccu_resets[] = {
  138. [RST_R_APB1_TIMER] = { 0x11c, BIT(16) },
  139. [RST_R_APB1_BUS_PWM] = { 0x13c, BIT(16) },
  140. [RST_R_APB1_PPU] = { 0x17c, BIT(16) },
  141. [RST_R_APB2_UART] = { 0x18c, BIT(16) },
  142. [RST_R_APB2_I2C0] = { 0x19c, BIT(16) },
  143. [RST_R_APB2_I2C1] = { 0x19c, BIT(17) },
  144. [RST_R_APB1_BUS_IR] = { 0x1cc, BIT(16) },
  145. [RST_R_AHB_BUS_RTC] = { 0x20c, BIT(16) },
  146. };
  147. static const struct sunxi_ccu_desc sun50i_a100_r_ccu_desc = {
  148. .ccu_clks = sun50i_a100_r_ccu_clks,
  149. .num_ccu_clks = ARRAY_SIZE(sun50i_a100_r_ccu_clks),
  150. .hw_clks = &sun50i_a100_r_hw_clks,
  151. .resets = sun50i_a100_r_ccu_resets,
  152. .num_resets = ARRAY_SIZE(sun50i_a100_r_ccu_resets),
  153. };
  154. static int sun50i_a100_r_ccu_probe(struct platform_device *pdev)
  155. {
  156. void __iomem *reg;
  157. reg = devm_platform_ioremap_resource(pdev, 0);
  158. if (IS_ERR(reg))
  159. return PTR_ERR(reg);
  160. return devm_sunxi_ccu_probe(&pdev->dev, reg, &sun50i_a100_r_ccu_desc);
  161. }
  162. static const struct of_device_id sun50i_a100_r_ccu_ids[] = {
  163. { .compatible = "allwinner,sun50i-a100-r-ccu" },
  164. { }
  165. };
  166. static struct platform_driver sun50i_a100_r_ccu_driver = {
  167. .probe = sun50i_a100_r_ccu_probe,
  168. .driver = {
  169. .name = "sun50i-a100-r-ccu",
  170. .suppress_bind_attrs = true,
  171. .of_match_table = sun50i_a100_r_ccu_ids,
  172. },
  173. };
  174. module_platform_driver(sun50i_a100_r_ccu_driver);
  175. MODULE_IMPORT_NS(SUNXI_CCU);
  176. MODULE_LICENSE("GPL");