clk-mt7986-eth.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2021 MediaTek Inc.
  4. * Author: Sam Shih <[email protected]>
  5. * Author: Wenzhen Yu <[email protected]>
  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 <dt-bindings/clock/mt7986-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. GATE_MTK(_id, _name, _parent, &sgmii0_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  22. static const struct mtk_gate sgmii0_clks[] __initconst = {
  23. GATE_SGMII0(CLK_SGMII0_TX250M_EN, "sgmii0_tx250m_en", "top_xtal", 2),
  24. GATE_SGMII0(CLK_SGMII0_RX250M_EN, "sgmii0_rx250m_en", "top_xtal", 3),
  25. GATE_SGMII0(CLK_SGMII0_CDR_REF, "sgmii0_cdr_ref", "top_xtal", 4),
  26. GATE_SGMII0(CLK_SGMII0_CDR_FB, "sgmii0_cdr_fb", "top_xtal", 5),
  27. };
  28. static const struct mtk_gate_regs sgmii1_cg_regs = {
  29. .set_ofs = 0xe4,
  30. .clr_ofs = 0xe4,
  31. .sta_ofs = 0xe4,
  32. };
  33. #define GATE_SGMII1(_id, _name, _parent, _shift) \
  34. GATE_MTK(_id, _name, _parent, &sgmii1_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  35. static const struct mtk_gate sgmii1_clks[] __initconst = {
  36. GATE_SGMII1(CLK_SGMII1_TX250M_EN, "sgmii1_tx250m_en", "top_xtal", 2),
  37. GATE_SGMII1(CLK_SGMII1_RX250M_EN, "sgmii1_rx250m_en", "top_xtal", 3),
  38. GATE_SGMII1(CLK_SGMII1_CDR_REF, "sgmii1_cdr_ref", "top_xtal", 4),
  39. GATE_SGMII1(CLK_SGMII1_CDR_FB, "sgmii1_cdr_fb", "top_xtal", 5),
  40. };
  41. static const struct mtk_gate_regs eth_cg_regs = {
  42. .set_ofs = 0x30,
  43. .clr_ofs = 0x30,
  44. .sta_ofs = 0x30,
  45. };
  46. #define GATE_ETH(_id, _name, _parent, _shift) \
  47. GATE_MTK(_id, _name, _parent, &eth_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  48. static const struct mtk_gate eth_clks[] __initconst = {
  49. GATE_ETH(CLK_ETH_FE_EN, "eth_fe_en", "netsys_2x_sel", 6),
  50. GATE_ETH(CLK_ETH_GP2_EN, "eth_gp2_en", "sgm_325m_sel", 7),
  51. GATE_ETH(CLK_ETH_GP1_EN, "eth_gp1_en", "sgm_325m_sel", 8),
  52. GATE_ETH(CLK_ETH_WOCPU1_EN, "eth_wocpu1_en", "netsys_mcu_sel", 14),
  53. GATE_ETH(CLK_ETH_WOCPU0_EN, "eth_wocpu0_en", "netsys_mcu_sel", 15),
  54. };
  55. static void __init mtk_sgmiisys_0_init(struct device_node *node)
  56. {
  57. struct clk_hw_onecell_data *clk_data;
  58. int r;
  59. clk_data = mtk_alloc_clk_data(ARRAY_SIZE(sgmii0_clks));
  60. mtk_clk_register_gates(node, sgmii0_clks, ARRAY_SIZE(sgmii0_clks),
  61. clk_data);
  62. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  63. if (r)
  64. pr_err("%s(): could not register clock provider: %d\n",
  65. __func__, r);
  66. }
  67. CLK_OF_DECLARE(mtk_sgmiisys_0, "mediatek,mt7986-sgmiisys_0",
  68. mtk_sgmiisys_0_init);
  69. static void __init mtk_sgmiisys_1_init(struct device_node *node)
  70. {
  71. struct clk_hw_onecell_data *clk_data;
  72. int r;
  73. clk_data = mtk_alloc_clk_data(ARRAY_SIZE(sgmii1_clks));
  74. mtk_clk_register_gates(node, sgmii1_clks, ARRAY_SIZE(sgmii1_clks),
  75. clk_data);
  76. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  77. if (r)
  78. pr_err("%s(): could not register clock provider: %d\n",
  79. __func__, r);
  80. }
  81. CLK_OF_DECLARE(mtk_sgmiisys_1, "mediatek,mt7986-sgmiisys_1",
  82. mtk_sgmiisys_1_init);
  83. static void __init mtk_ethsys_init(struct device_node *node)
  84. {
  85. struct clk_hw_onecell_data *clk_data;
  86. int r;
  87. clk_data = mtk_alloc_clk_data(ARRAY_SIZE(eth_clks));
  88. mtk_clk_register_gates(node, eth_clks, ARRAY_SIZE(eth_clks), clk_data);
  89. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  90. if (r)
  91. pr_err("%s(): could not register clock provider: %d\n",
  92. __func__, r);
  93. }
  94. CLK_OF_DECLARE(mtk_ethsys, "mediatek,mt7986-ethsys", mtk_ethsys_init);