clk-mt7629-eth.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2018 MediaTek Inc.
  4. * Author: Wenzhen Yu <Wenzhen [email protected]>
  5. * Ryder Lee <[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/mt7629-clk.h>
  15. #define GATE_ETH(_id, _name, _parent, _shift) \
  16. GATE_MTK(_id, _name, _parent, &eth_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  17. static const struct mtk_gate_regs eth_cg_regs = {
  18. .set_ofs = 0x30,
  19. .clr_ofs = 0x30,
  20. .sta_ofs = 0x30,
  21. };
  22. static const struct mtk_gate eth_clks[] = {
  23. GATE_ETH(CLK_ETH_FE_EN, "eth_fe_en", "eth2pll", 6),
  24. GATE_ETH(CLK_ETH_GP2_EN, "eth_gp2_en", "txclk_src_pre", 7),
  25. GATE_ETH(CLK_ETH_GP1_EN, "eth_gp1_en", "txclk_src_pre", 8),
  26. GATE_ETH(CLK_ETH_GP0_EN, "eth_gp0_en", "txclk_src_pre", 9),
  27. GATE_ETH(CLK_ETH_ESW_EN, "eth_esw_en", "eth_500m", 16),
  28. };
  29. static const struct mtk_gate_regs sgmii_cg_regs = {
  30. .set_ofs = 0xE4,
  31. .clr_ofs = 0xE4,
  32. .sta_ofs = 0xE4,
  33. };
  34. #define GATE_SGMII(_id, _name, _parent, _shift) \
  35. GATE_MTK(_id, _name, _parent, &sgmii_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  36. static const struct mtk_gate sgmii_clks[2][4] = {
  37. {
  38. GATE_SGMII(CLK_SGMII_TX_EN, "sgmii_tx_en",
  39. "ssusb_tx250m", 2),
  40. GATE_SGMII(CLK_SGMII_RX_EN, "sgmii_rx_en",
  41. "ssusb_eq_rx250m", 3),
  42. GATE_SGMII(CLK_SGMII_CDR_REF, "sgmii_cdr_ref",
  43. "ssusb_cdr_ref", 4),
  44. GATE_SGMII(CLK_SGMII_CDR_FB, "sgmii_cdr_fb",
  45. "ssusb_cdr_fb", 5),
  46. }, {
  47. GATE_SGMII(CLK_SGMII_TX_EN, "sgmii_tx_en1",
  48. "ssusb_tx250m", 2),
  49. GATE_SGMII(CLK_SGMII_RX_EN, "sgmii_rx_en1",
  50. "ssusb_eq_rx250m", 3),
  51. GATE_SGMII(CLK_SGMII_CDR_REF, "sgmii_cdr_ref1",
  52. "ssusb_cdr_ref", 4),
  53. GATE_SGMII(CLK_SGMII_CDR_FB, "sgmii_cdr_fb1",
  54. "ssusb_cdr_fb", 5),
  55. }
  56. };
  57. static u16 rst_ofs[] = { 0x34, };
  58. static const struct mtk_clk_rst_desc clk_rst_desc = {
  59. .version = MTK_RST_SIMPLE,
  60. .rst_bank_ofs = rst_ofs,
  61. .rst_bank_nr = ARRAY_SIZE(rst_ofs),
  62. };
  63. static int clk_mt7629_ethsys_init(struct platform_device *pdev)
  64. {
  65. struct clk_hw_onecell_data *clk_data;
  66. struct device_node *node = pdev->dev.of_node;
  67. int r;
  68. clk_data = mtk_alloc_clk_data(CLK_ETH_NR_CLK);
  69. if (!clk_data)
  70. return -ENOMEM;
  71. mtk_clk_register_gates(node, eth_clks, CLK_ETH_NR_CLK, clk_data);
  72. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  73. if (r)
  74. dev_err(&pdev->dev,
  75. "could not register clock provider: %s: %d\n",
  76. pdev->name, r);
  77. mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  78. return r;
  79. }
  80. static int clk_mt7629_sgmiisys_init(struct platform_device *pdev)
  81. {
  82. struct clk_hw_onecell_data *clk_data;
  83. struct device_node *node = pdev->dev.of_node;
  84. static int id;
  85. int r;
  86. clk_data = mtk_alloc_clk_data(CLK_SGMII_NR_CLK);
  87. if (!clk_data)
  88. return -ENOMEM;
  89. mtk_clk_register_gates(node, sgmii_clks[id++], CLK_SGMII_NR_CLK,
  90. clk_data);
  91. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  92. if (r)
  93. dev_err(&pdev->dev,
  94. "could not register clock provider: %s: %d\n",
  95. pdev->name, r);
  96. return r;
  97. }
  98. static const struct of_device_id of_match_clk_mt7629_eth[] = {
  99. {
  100. .compatible = "mediatek,mt7629-ethsys",
  101. .data = clk_mt7629_ethsys_init,
  102. }, {
  103. .compatible = "mediatek,mt7629-sgmiisys",
  104. .data = clk_mt7629_sgmiisys_init,
  105. }, {
  106. /* sentinel */
  107. }
  108. };
  109. static int clk_mt7629_eth_probe(struct platform_device *pdev)
  110. {
  111. int (*clk_init)(struct platform_device *);
  112. int r;
  113. clk_init = of_device_get_match_data(&pdev->dev);
  114. if (!clk_init)
  115. return -EINVAL;
  116. r = clk_init(pdev);
  117. if (r)
  118. dev_err(&pdev->dev,
  119. "could not register clock provider: %s: %d\n",
  120. pdev->name, r);
  121. return r;
  122. }
  123. static struct platform_driver clk_mt7629_eth_drv = {
  124. .probe = clk_mt7629_eth_probe,
  125. .driver = {
  126. .name = "clk-mt7629-eth",
  127. .of_match_table = of_match_clk_mt7629_eth,
  128. },
  129. };
  130. builtin_platform_driver(clk_mt7629_eth_drv);