clk-mt7622-eth.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017 MediaTek Inc.
  4. * Author: Chen Zhong <[email protected]>
  5. * Sean Wang <[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/mt7622-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_HSDMA_EN, "eth_hsdma_en", "eth_sel", 5),
  24. GATE_ETH(CLK_ETH_ESW_EN, "eth_esw_en", "eth_500m", 6),
  25. GATE_ETH(CLK_ETH_GP2_EN, "eth_gp2_en", "txclk_src_pre", 7),
  26. GATE_ETH(CLK_ETH_GP1_EN, "eth_gp1_en", "txclk_src_pre", 8),
  27. GATE_ETH(CLK_ETH_GP0_EN, "eth_gp0_en", "txclk_src_pre", 9),
  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[] = {
  37. GATE_SGMII(CLK_SGMII_TX250M_EN, "sgmii_tx250m_en",
  38. "ssusb_tx250m", 2),
  39. GATE_SGMII(CLK_SGMII_RX250M_EN, "sgmii_rx250m_en",
  40. "ssusb_eq_rx250m", 3),
  41. GATE_SGMII(CLK_SGMII_CDR_REF, "sgmii_cdr_ref",
  42. "ssusb_cdr_ref", 4),
  43. GATE_SGMII(CLK_SGMII_CDR_FB, "sgmii_cdr_fb",
  44. "ssusb_cdr_fb", 5),
  45. };
  46. static u16 rst_ofs[] = { 0x34, };
  47. static const struct mtk_clk_rst_desc clk_rst_desc = {
  48. .version = MTK_RST_SIMPLE,
  49. .rst_bank_ofs = rst_ofs,
  50. .rst_bank_nr = ARRAY_SIZE(rst_ofs),
  51. };
  52. static int clk_mt7622_ethsys_init(struct platform_device *pdev)
  53. {
  54. struct clk_hw_onecell_data *clk_data;
  55. struct device_node *node = pdev->dev.of_node;
  56. int r;
  57. clk_data = mtk_alloc_clk_data(CLK_ETH_NR_CLK);
  58. mtk_clk_register_gates(node, eth_clks, ARRAY_SIZE(eth_clks),
  59. clk_data);
  60. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  61. if (r)
  62. dev_err(&pdev->dev,
  63. "could not register clock provider: %s: %d\n",
  64. pdev->name, r);
  65. mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  66. return r;
  67. }
  68. static int clk_mt7622_sgmiisys_init(struct platform_device *pdev)
  69. {
  70. struct clk_hw_onecell_data *clk_data;
  71. struct device_node *node = pdev->dev.of_node;
  72. int r;
  73. clk_data = mtk_alloc_clk_data(CLK_SGMII_NR_CLK);
  74. mtk_clk_register_gates(node, sgmii_clks, ARRAY_SIZE(sgmii_clks),
  75. clk_data);
  76. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  77. if (r)
  78. dev_err(&pdev->dev,
  79. "could not register clock provider: %s: %d\n",
  80. pdev->name, r);
  81. return r;
  82. }
  83. static const struct of_device_id of_match_clk_mt7622_eth[] = {
  84. {
  85. .compatible = "mediatek,mt7622-ethsys",
  86. .data = clk_mt7622_ethsys_init,
  87. }, {
  88. .compatible = "mediatek,mt7622-sgmiisys",
  89. .data = clk_mt7622_sgmiisys_init,
  90. }, {
  91. /* sentinel */
  92. }
  93. };
  94. static int clk_mt7622_eth_probe(struct platform_device *pdev)
  95. {
  96. int (*clk_init)(struct platform_device *);
  97. int r;
  98. clk_init = of_device_get_match_data(&pdev->dev);
  99. if (!clk_init)
  100. return -EINVAL;
  101. r = clk_init(pdev);
  102. if (r)
  103. dev_err(&pdev->dev,
  104. "could not register clock provider: %s: %d\n",
  105. pdev->name, r);
  106. return r;
  107. }
  108. static struct platform_driver clk_mt7622_eth_drv = {
  109. .probe = clk_mt7622_eth_probe,
  110. .driver = {
  111. .name = "clk-mt7622-eth",
  112. .of_match_table = of_match_clk_mt7622_eth,
  113. },
  114. };
  115. builtin_platform_driver(clk_mt7622_eth_drv);