clk-mt7988-eth.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2023 MediaTek Inc.
  4. * Author: Sam Shih <sam.shih@mediatek.com>
  5. * Author: Xiufeng Li <Xiufeng.Li@mediatek.com>
  6. */
  7. #include <linux/clk-provider.h>
  8. #include <linux/of.h>
  9. #include <linux/of_address.h>
  10. #include <linux/of_device.h>
  11. #include <linux/platform_device.h>
  12. #include "clk-mtk.h"
  13. #include "clk-gate.h"
  14. #include "reset.h"
  15. #include <dt-bindings/clock/mediatek,mt7988-clk.h>
  16. #include <dt-bindings/reset/mediatek,mt7988-resets.h>
  17. static const struct mtk_gate_regs ethdma_cg_regs = {
  18. .set_ofs = 0x30,
  19. .clr_ofs = 0x30,
  20. .sta_ofs = 0x30,
  21. };
  22. #define GATE_ETHDMA(_id, _name, _parent, _shift) \
  23. { \
  24. .id = _id, \
  25. .name = _name, \
  26. .parent_name = _parent, \
  27. .regs = &ethdma_cg_regs, \
  28. .shift = _shift, \
  29. .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  30. }
  31. static const struct mtk_gate ethdma_clks[] = {
  32. GATE_ETHDMA(CLK_ETHDMA_XGP1_EN, "ethdma_xgp1_en", "top_xtal", 0),
  33. GATE_ETHDMA(CLK_ETHDMA_XGP2_EN, "ethdma_xgp2_en", "top_xtal", 1),
  34. GATE_ETHDMA(CLK_ETHDMA_XGP3_EN, "ethdma_xgp3_en", "top_xtal", 2),
  35. GATE_ETHDMA(CLK_ETHDMA_FE_EN, "ethdma_fe_en", "netsys_2x_sel", 6),
  36. GATE_ETHDMA(CLK_ETHDMA_GP2_EN, "ethdma_gp2_en", "top_xtal", 7),
  37. GATE_ETHDMA(CLK_ETHDMA_GP1_EN, "ethdma_gp1_en", "top_xtal", 8),
  38. GATE_ETHDMA(CLK_ETHDMA_GP3_EN, "ethdma_gp3_en", "top_xtal", 10),
  39. GATE_ETHDMA(CLK_ETHDMA_ESW_EN, "ethdma_esw_en", "netsys_gsw_sel", 16),
  40. GATE_ETHDMA(CLK_ETHDMA_CRYPT0_EN, "ethdma_crypt0_en", "eip197_sel", 29),
  41. };
  42. static const struct mtk_clk_desc ethdma_desc = {
  43. .clks = ethdma_clks,
  44. .num_clks = ARRAY_SIZE(ethdma_clks),
  45. };
  46. static const struct mtk_gate_regs sgmii_cg_regs = {
  47. .set_ofs = 0xe4,
  48. .clr_ofs = 0xe4,
  49. .sta_ofs = 0xe4,
  50. };
  51. #define GATE_SGMII(_id, _name, _parent, _shift) \
  52. { \
  53. .id = _id, \
  54. .name = _name, \
  55. .parent_name = _parent, \
  56. .regs = &sgmii_cg_regs, \
  57. .shift = _shift, \
  58. .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  59. }
  60. static const struct mtk_gate sgmii0_clks[] = {
  61. GATE_SGMII(CLK_SGM0_TX_EN, "sgm0_tx_en", "top_xtal", 2),
  62. GATE_SGMII(CLK_SGM0_RX_EN, "sgm0_rx_en", "top_xtal", 3),
  63. };
  64. static const struct mtk_clk_desc sgmii0_desc = {
  65. .clks = sgmii0_clks,
  66. .num_clks = ARRAY_SIZE(sgmii0_clks),
  67. };
  68. static const struct mtk_gate sgmii1_clks[] = {
  69. GATE_SGMII(CLK_SGM1_TX_EN, "sgm1_tx_en", "top_xtal", 2),
  70. GATE_SGMII(CLK_SGM1_RX_EN, "sgm1_rx_en", "top_xtal", 3),
  71. };
  72. static const struct mtk_clk_desc sgmii1_desc = {
  73. .clks = sgmii1_clks,
  74. .num_clks = ARRAY_SIZE(sgmii1_clks),
  75. };
  76. static const struct mtk_gate_regs ethwarp_cg_regs = {
  77. .set_ofs = 0x14,
  78. .clr_ofs = 0x14,
  79. .sta_ofs = 0x14,
  80. };
  81. #define GATE_ETHWARP(_id, _name, _parent, _shift) \
  82. { \
  83. .id = _id, \
  84. .name = _name, \
  85. .parent_name = _parent, \
  86. .regs = &ethwarp_cg_regs, \
  87. .shift = _shift, \
  88. .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  89. }
  90. static const struct mtk_gate ethwarp_clks[] = {
  91. GATE_ETHWARP(CLK_ETHWARP_WOCPU2_EN, "ethwarp_wocpu2_en", "netsys_mcu_sel", 13),
  92. GATE_ETHWARP(CLK_ETHWARP_WOCPU1_EN, "ethwarp_wocpu1_en", "netsys_mcu_sel", 14),
  93. GATE_ETHWARP(CLK_ETHWARP_WOCPU0_EN, "ethwarp_wocpu0_en", "netsys_mcu_sel", 15),
  94. };
  95. static u16 ethwarp_rst_ofs[] = { 0x8 };
  96. static u16 ethwarp_idx_map[] = {
  97. [MT7988_ETHWARP_RST_SWITCH] = 9,
  98. };
  99. static const struct mtk_clk_rst_desc ethwarp_rst_desc = {
  100. .version = MTK_RST_SIMPLE,
  101. .rst_bank_ofs = ethwarp_rst_ofs,
  102. .rst_bank_nr = ARRAY_SIZE(ethwarp_rst_ofs),
  103. .rst_idx_map = ethwarp_idx_map,
  104. .rst_idx_map_nr = ARRAY_SIZE(ethwarp_idx_map),
  105. };
  106. static const struct mtk_clk_desc ethwarp_desc = {
  107. .clks = ethwarp_clks,
  108. .num_clks = ARRAY_SIZE(ethwarp_clks),
  109. .rst_desc = &ethwarp_rst_desc,
  110. };
  111. static const struct of_device_id of_match_clk_mt7988_eth[] = {
  112. { .compatible = "mediatek,mt7988-ethsys", .data = &ethdma_desc },
  113. { .compatible = "mediatek,mt7988-sgmiisys0", .data = &sgmii0_desc },
  114. { .compatible = "mediatek,mt7988-sgmiisys1", .data = &sgmii1_desc },
  115. { .compatible = "mediatek,mt7988-ethwarp", .data = &ethwarp_desc },
  116. { /* sentinel */ }
  117. };
  118. MODULE_DEVICE_TABLE(of, of_match_clk_mt7988_eth);
  119. static struct platform_driver clk_mt7988_eth_drv = {
  120. .driver = {
  121. .name = "clk-mt7988-eth",
  122. .of_match_table = of_match_clk_mt7988_eth,
  123. },
  124. .probe = mtk_clk_simple_probe,
  125. .remove = mtk_clk_simple_remove,
  126. };
  127. module_platform_driver(clk_mt7988_eth_drv);
  128. MODULE_DESCRIPTION("MediaTek MT7988 Ethernet clocks driver");
  129. MODULE_LICENSE("GPL");