clk-mt7981-eth.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2021 MediaTek Inc.
  4. * Author: Sam Shih <sam.shih@mediatek.com>
  5. * Author: Wenzhen Yu <wenzhen.yu@mediatek.com>
  6. * Author: Jianhui Zhao <zhaojh329@gmail.com>
  7. * Author: Daniel Golle <daniel@makrotopia.org>
  8. */
  9. #include <linux/clk-provider.h>
  10. #include <linux/mod_devicetable.h>
  11. #include <linux/platform_device.h>
  12. #include "clk-mtk.h"
  13. #include "clk-gate.h"
  14. #include <dt-bindings/clock/mediatek,mt7981-clk.h>
  15. static const struct mtk_gate_regs sgmii0_cg_regs = {
  16. .set_ofs = 0xE4,
  17. .clr_ofs = 0xE4,
  18. .sta_ofs = 0xE4,
  19. };
  20. #define GATE_SGMII0(_id, _name, _parent, _shift) { \
  21. .id = _id, \
  22. .name = _name, \
  23. .parent_name = _parent, \
  24. .regs = &sgmii0_cg_regs, \
  25. .shift = _shift, \
  26. .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  27. }
  28. static const struct mtk_gate sgmii0_clks[] __initconst = {
  29. GATE_SGMII0(CLK_SGM0_TX_EN, "sgm0_tx_en", "usb_tx250m", 2),
  30. GATE_SGMII0(CLK_SGM0_RX_EN, "sgm0_rx_en", "usb_eq_rx250m", 3),
  31. GATE_SGMII0(CLK_SGM0_CK0_EN, "sgm0_ck0_en", "usb_ln0", 4),
  32. GATE_SGMII0(CLK_SGM0_CDR_CK0_EN, "sgm0_cdr_ck0_en", "usb_cdr", 5),
  33. };
  34. static const struct mtk_gate_regs sgmii1_cg_regs = {
  35. .set_ofs = 0xE4,
  36. .clr_ofs = 0xE4,
  37. .sta_ofs = 0xE4,
  38. };
  39. #define GATE_SGMII1(_id, _name, _parent, _shift) { \
  40. .id = _id, \
  41. .name = _name, \
  42. .parent_name = _parent, \
  43. .regs = &sgmii1_cg_regs, \
  44. .shift = _shift, \
  45. .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  46. }
  47. static const struct mtk_gate sgmii1_clks[] __initconst = {
  48. GATE_SGMII1(CLK_SGM1_TX_EN, "sgm1_tx_en", "usb_tx250m", 2),
  49. GATE_SGMII1(CLK_SGM1_RX_EN, "sgm1_rx_en", "usb_eq_rx250m", 3),
  50. GATE_SGMII1(CLK_SGM1_CK1_EN, "sgm1_ck1_en", "usb_ln0", 4),
  51. GATE_SGMII1(CLK_SGM1_CDR_CK1_EN, "sgm1_cdr_ck1_en", "usb_cdr", 5),
  52. };
  53. static const struct mtk_gate_regs eth_cg_regs = {
  54. .set_ofs = 0x30,
  55. .clr_ofs = 0x30,
  56. .sta_ofs = 0x30,
  57. };
  58. #define GATE_ETH(_id, _name, _parent, _shift) { \
  59. .id = _id, \
  60. .name = _name, \
  61. .parent_name = _parent, \
  62. .regs = &eth_cg_regs, \
  63. .shift = _shift, \
  64. .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  65. }
  66. static const struct mtk_gate eth_clks[] __initconst = {
  67. GATE_ETH(CLK_ETH_FE_EN, "eth_fe_en", "netsys_2x", 6),
  68. GATE_ETH(CLK_ETH_GP2_EN, "eth_gp2_en", "sgm_325m", 7),
  69. GATE_ETH(CLK_ETH_GP1_EN, "eth_gp1_en", "sgm_325m", 8),
  70. GATE_ETH(CLK_ETH_WOCPU0_EN, "eth_wocpu0_en", "netsys_wed_mcu", 15),
  71. };
  72. static const struct mtk_clk_desc eth_desc = {
  73. .clks = eth_clks,
  74. .num_clks = ARRAY_SIZE(eth_clks),
  75. };
  76. static const struct mtk_clk_desc sgmii0_desc = {
  77. .clks = sgmii0_clks,
  78. .num_clks = ARRAY_SIZE(sgmii0_clks),
  79. };
  80. static const struct mtk_clk_desc sgmii1_desc = {
  81. .clks = sgmii1_clks,
  82. .num_clks = ARRAY_SIZE(sgmii1_clks),
  83. };
  84. static const struct of_device_id of_match_clk_mt7981_eth[] = {
  85. { .compatible = "mediatek,mt7981-ethsys", .data = &eth_desc },
  86. { .compatible = "mediatek,mt7981-sgmiisys_0", .data = &sgmii0_desc },
  87. { .compatible = "mediatek,mt7981-sgmiisys_1", .data = &sgmii1_desc },
  88. { /* sentinel */ }
  89. };
  90. MODULE_DEVICE_TABLE(of, of_match_clk_mt7981_eth);
  91. static struct platform_driver clk_mt7981_eth_drv = {
  92. .probe = mtk_clk_simple_probe,
  93. .remove = mtk_clk_simple_remove,
  94. .driver = {
  95. .name = "clk-mt7981-eth",
  96. .of_match_table = of_match_clk_mt7981_eth,
  97. },
  98. };
  99. module_platform_driver(clk_mt7981_eth_drv);
  100. MODULE_DESCRIPTION("MediaTek MT7981 Ethernet clocks driver");
  101. MODULE_LICENSE("GPL");