ccu-sun20i-d1-r.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2020 [email protected]
  4. * Copyright (C) 2021 Samuel Holland <[email protected]>
  5. */
  6. #include <linux/clk-provider.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include "ccu_common.h"
  10. #include "ccu_reset.h"
  11. #include "ccu_gate.h"
  12. #include "ccu_mp.h"
  13. #include "ccu-sun20i-d1-r.h"
  14. static const struct clk_parent_data r_ahb_apb0_parents[] = {
  15. { .fw_name = "hosc" },
  16. { .fw_name = "losc" },
  17. { .fw_name = "iosc" },
  18. { .fw_name = "pll-periph" },
  19. };
  20. static SUNXI_CCU_MP_DATA_WITH_MUX(r_ahb_clk, "r-ahb",
  21. r_ahb_apb0_parents, 0x000,
  22. 0, 5, /* M */
  23. 8, 2, /* P */
  24. 24, 3, /* mux */
  25. 0);
  26. static const struct clk_hw *r_ahb_hw = &r_ahb_clk.common.hw;
  27. static SUNXI_CCU_MP_DATA_WITH_MUX(r_apb0_clk, "r-apb0",
  28. r_ahb_apb0_parents, 0x00c,
  29. 0, 5, /* M */
  30. 8, 2, /* P */
  31. 24, 3, /* mux */
  32. 0);
  33. static const struct clk_hw *r_apb0_hw = &r_apb0_clk.common.hw;
  34. static SUNXI_CCU_GATE_HWS(bus_r_timer_clk, "bus-r-timer", &r_apb0_hw,
  35. 0x11c, BIT(0), 0);
  36. static SUNXI_CCU_GATE_HWS(bus_r_twd_clk, "bus-r-twd", &r_apb0_hw,
  37. 0x12c, BIT(0), 0);
  38. static SUNXI_CCU_GATE_HWS(bus_r_ppu_clk, "bus-r-ppu", &r_apb0_hw,
  39. 0x1ac, BIT(0), 0);
  40. static const struct clk_parent_data r_ir_rx_parents[] = {
  41. { .fw_name = "losc" },
  42. { .fw_name = "hosc" },
  43. };
  44. static SUNXI_CCU_MP_DATA_WITH_MUX_GATE(r_ir_rx_clk, "r-ir-rx",
  45. r_ir_rx_parents, 0x1c0,
  46. 0, 5, /* M */
  47. 8, 2, /* P */
  48. 24, 2, /* mux */
  49. BIT(31), /* gate */
  50. 0);
  51. static SUNXI_CCU_GATE_HWS(bus_r_ir_rx_clk, "bus-r-ir-rx", &r_apb0_hw,
  52. 0x1cc, BIT(0), 0);
  53. static SUNXI_CCU_GATE_HWS(bus_r_rtc_clk, "bus-r-rtc", &r_ahb_hw,
  54. 0x20c, BIT(0), 0);
  55. static SUNXI_CCU_GATE_HWS(bus_r_cpucfg_clk, "bus-r-cpucfg", &r_apb0_hw,
  56. 0x22c, BIT(0), 0);
  57. static struct ccu_common *sun20i_d1_r_ccu_clks[] = {
  58. &r_ahb_clk.common,
  59. &r_apb0_clk.common,
  60. &bus_r_timer_clk.common,
  61. &bus_r_twd_clk.common,
  62. &bus_r_ppu_clk.common,
  63. &r_ir_rx_clk.common,
  64. &bus_r_ir_rx_clk.common,
  65. &bus_r_rtc_clk.common,
  66. &bus_r_cpucfg_clk.common,
  67. };
  68. static struct clk_hw_onecell_data sun20i_d1_r_hw_clks = {
  69. .num = CLK_NUMBER,
  70. .hws = {
  71. [CLK_R_AHB] = &r_ahb_clk.common.hw,
  72. [CLK_R_APB0] = &r_apb0_clk.common.hw,
  73. [CLK_BUS_R_TIMER] = &bus_r_timer_clk.common.hw,
  74. [CLK_BUS_R_TWD] = &bus_r_twd_clk.common.hw,
  75. [CLK_BUS_R_PPU] = &bus_r_ppu_clk.common.hw,
  76. [CLK_R_IR_RX] = &r_ir_rx_clk.common.hw,
  77. [CLK_BUS_R_IR_RX] = &bus_r_ir_rx_clk.common.hw,
  78. [CLK_BUS_R_RTC] = &bus_r_rtc_clk.common.hw,
  79. [CLK_BUS_R_CPUCFG] = &bus_r_cpucfg_clk.common.hw,
  80. },
  81. };
  82. static struct ccu_reset_map sun20i_d1_r_ccu_resets[] = {
  83. [RST_BUS_R_TIMER] = { 0x11c, BIT(16) },
  84. [RST_BUS_R_TWD] = { 0x12c, BIT(16) },
  85. [RST_BUS_R_PPU] = { 0x1ac, BIT(16) },
  86. [RST_BUS_R_IR_RX] = { 0x1cc, BIT(16) },
  87. [RST_BUS_R_RTC] = { 0x20c, BIT(16) },
  88. [RST_BUS_R_CPUCFG] = { 0x22c, BIT(16) },
  89. };
  90. static const struct sunxi_ccu_desc sun20i_d1_r_ccu_desc = {
  91. .ccu_clks = sun20i_d1_r_ccu_clks,
  92. .num_ccu_clks = ARRAY_SIZE(sun20i_d1_r_ccu_clks),
  93. .hw_clks = &sun20i_d1_r_hw_clks,
  94. .resets = sun20i_d1_r_ccu_resets,
  95. .num_resets = ARRAY_SIZE(sun20i_d1_r_ccu_resets),
  96. };
  97. static int sun20i_d1_r_ccu_probe(struct platform_device *pdev)
  98. {
  99. void __iomem *reg;
  100. reg = devm_platform_ioremap_resource(pdev, 0);
  101. if (IS_ERR(reg))
  102. return PTR_ERR(reg);
  103. return devm_sunxi_ccu_probe(&pdev->dev, reg, &sun20i_d1_r_ccu_desc);
  104. }
  105. static const struct of_device_id sun20i_d1_r_ccu_ids[] = {
  106. { .compatible = "allwinner,sun20i-d1-r-ccu" },
  107. { }
  108. };
  109. static struct platform_driver sun20i_d1_r_ccu_driver = {
  110. .probe = sun20i_d1_r_ccu_probe,
  111. .driver = {
  112. .name = "sun20i-d1-r-ccu",
  113. .suppress_bind_attrs = true,
  114. .of_match_table = sun20i_d1_r_ccu_ids,
  115. },
  116. };
  117. module_platform_driver(sun20i_d1_r_ccu_driver);
  118. MODULE_IMPORT_NS(SUNXI_CCU);
  119. MODULE_LICENSE("GPL");