clk-mt7986-eth.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. */
  7. #include <linux/clk-provider.h>
  8. #include <linux/mod_devicetable.h>
  9. #include <linux/platform_device.h>
  10. #include "clk-mtk.h"
  11. #include "clk-gate.h"
  12. #include <dt-bindings/clock/mt7986-clk.h>
  13. static const struct mtk_gate_regs sgmii0_cg_regs = {
  14. .set_ofs = 0xe4,
  15. .clr_ofs = 0xe4,
  16. .sta_ofs = 0xe4,
  17. };
  18. #define GATE_SGMII0(_id, _name, _parent, _shift) \
  19. GATE_MTK(_id, _name, _parent, &sgmii0_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  20. static const struct mtk_gate sgmii0_clks[] = {
  21. GATE_SGMII0(CLK_SGMII0_TX250M_EN, "sgmii0_tx250m_en", "top_xtal", 2),
  22. GATE_SGMII0(CLK_SGMII0_RX250M_EN, "sgmii0_rx250m_en", "top_xtal", 3),
  23. GATE_SGMII0(CLK_SGMII0_CDR_REF, "sgmii0_cdr_ref", "top_xtal", 4),
  24. GATE_SGMII0(CLK_SGMII0_CDR_FB, "sgmii0_cdr_fb", "top_xtal", 5),
  25. };
  26. static const struct mtk_gate_regs sgmii1_cg_regs = {
  27. .set_ofs = 0xe4,
  28. .clr_ofs = 0xe4,
  29. .sta_ofs = 0xe4,
  30. };
  31. #define GATE_SGMII1(_id, _name, _parent, _shift) \
  32. GATE_MTK(_id, _name, _parent, &sgmii1_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  33. static const struct mtk_gate sgmii1_clks[] = {
  34. GATE_SGMII1(CLK_SGMII1_TX250M_EN, "sgmii1_tx250m_en", "top_xtal", 2),
  35. GATE_SGMII1(CLK_SGMII1_RX250M_EN, "sgmii1_rx250m_en", "top_xtal", 3),
  36. GATE_SGMII1(CLK_SGMII1_CDR_REF, "sgmii1_cdr_ref", "top_xtal", 4),
  37. GATE_SGMII1(CLK_SGMII1_CDR_FB, "sgmii1_cdr_fb", "top_xtal", 5),
  38. };
  39. static const struct mtk_gate_regs eth_cg_regs = {
  40. .set_ofs = 0x30,
  41. .clr_ofs = 0x30,
  42. .sta_ofs = 0x30,
  43. };
  44. #define GATE_ETH(_id, _name, _parent, _shift) \
  45. GATE_MTK(_id, _name, _parent, &eth_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  46. static const struct mtk_gate eth_clks[] = {
  47. GATE_ETH(CLK_ETH_FE_EN, "eth_fe_en", "netsys_2x_sel", 6),
  48. GATE_ETH(CLK_ETH_GP2_EN, "eth_gp2_en", "sgm_325m_sel", 7),
  49. GATE_ETH(CLK_ETH_GP1_EN, "eth_gp1_en", "sgm_325m_sel", 8),
  50. GATE_ETH(CLK_ETH_WOCPU1_EN, "eth_wocpu1_en", "netsys_mcu_sel", 14),
  51. GATE_ETH(CLK_ETH_WOCPU0_EN, "eth_wocpu0_en", "netsys_mcu_sel", 15),
  52. };
  53. static const struct mtk_clk_desc eth_desc = {
  54. .clks = eth_clks,
  55. .num_clks = ARRAY_SIZE(eth_clks),
  56. };
  57. static const struct mtk_clk_desc sgmii0_desc = {
  58. .clks = sgmii0_clks,
  59. .num_clks = ARRAY_SIZE(sgmii0_clks),
  60. };
  61. static const struct mtk_clk_desc sgmii1_desc = {
  62. .clks = sgmii1_clks,
  63. .num_clks = ARRAY_SIZE(sgmii1_clks),
  64. };
  65. static const struct of_device_id of_match_clk_mt7986_eth[] = {
  66. { .compatible = "mediatek,mt7986-ethsys", .data = &eth_desc },
  67. { .compatible = "mediatek,mt7986-sgmiisys_0", .data = &sgmii0_desc },
  68. { .compatible = "mediatek,mt7986-sgmiisys_1", .data = &sgmii1_desc },
  69. { /* sentinel */ }
  70. };
  71. MODULE_DEVICE_TABLE(of, of_match_clk_mt7986_eth);
  72. static struct platform_driver clk_mt7986_eth_drv = {
  73. .driver = {
  74. .name = "clk-mt7986-eth",
  75. .of_match_table = of_match_clk_mt7986_eth,
  76. },
  77. .probe = mtk_clk_simple_probe,
  78. .remove = mtk_clk_simple_remove,
  79. };
  80. module_platform_driver(clk_mt7986_eth_drv);
  81. MODULE_DESCRIPTION("MediaTek MT7986 Ethernet clocks driver");
  82. MODULE_LICENSE("GPL");