clk-mt7622-eth.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (c) 2017 MediaTek Inc.
  3. * Author: Chen Zhong <chen.zhong@mediatek.com>
  4. * Sean Wang <sean.wang@mediatek.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/clk-provider.h>
  16. #include <linux/of.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_device.h>
  19. #include <linux/platform_device.h>
  20. #include "clk-mtk.h"
  21. #include "clk-gate.h"
  22. #include <dt-bindings/clock/mt7622-clk.h>
  23. #define GATE_ETH(_id, _name, _parent, _shift) { \
  24. .id = _id, \
  25. .name = _name, \
  26. .parent_name = _parent, \
  27. .regs = &eth_cg_regs, \
  28. .shift = _shift, \
  29. .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  30. }
  31. static const struct mtk_gate_regs eth_cg_regs = {
  32. .set_ofs = 0x30,
  33. .clr_ofs = 0x30,
  34. .sta_ofs = 0x30,
  35. };
  36. static const struct mtk_gate eth_clks[] = {
  37. GATE_ETH(CLK_ETH_HSDMA_EN, "eth_hsdma_en", "eth_sel", 5),
  38. GATE_ETH(CLK_ETH_ESW_EN, "eth_esw_en", "eth_500m", 6),
  39. GATE_ETH(CLK_ETH_GP2_EN, "eth_gp2_en", "txclk_src_pre", 7),
  40. GATE_ETH(CLK_ETH_GP1_EN, "eth_gp1_en", "txclk_src_pre", 8),
  41. GATE_ETH(CLK_ETH_GP0_EN, "eth_gp0_en", "txclk_src_pre", 9),
  42. };
  43. static const struct mtk_gate_regs sgmii_cg_regs = {
  44. .set_ofs = 0xE4,
  45. .clr_ofs = 0xE4,
  46. .sta_ofs = 0xE4,
  47. };
  48. #define GATE_SGMII(_id, _name, _parent, _shift) { \
  49. .id = _id, \
  50. .name = _name, \
  51. .parent_name = _parent, \
  52. .regs = &sgmii_cg_regs, \
  53. .shift = _shift, \
  54. .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  55. }
  56. static const struct mtk_gate sgmii_clks[] = {
  57. GATE_SGMII(CLK_SGMII_TX250M_EN, "sgmii_tx250m_en",
  58. "ssusb_tx250m", 2),
  59. GATE_SGMII(CLK_SGMII_RX250M_EN, "sgmii_rx250m_en",
  60. "ssusb_eq_rx250m", 3),
  61. GATE_SGMII(CLK_SGMII_CDR_REF, "sgmii_cdr_ref",
  62. "ssusb_cdr_ref", 4),
  63. GATE_SGMII(CLK_SGMII_CDR_FB, "sgmii_cdr_fb",
  64. "ssusb_cdr_fb", 5),
  65. };
  66. static int clk_mt7622_ethsys_init(struct platform_device *pdev)
  67. {
  68. struct clk_onecell_data *clk_data;
  69. struct device_node *node = pdev->dev.of_node;
  70. int r;
  71. clk_data = mtk_alloc_clk_data(CLK_ETH_NR_CLK);
  72. mtk_clk_register_gates(node, eth_clks, ARRAY_SIZE(eth_clks),
  73. clk_data);
  74. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  75. if (r)
  76. dev_err(&pdev->dev,
  77. "could not register clock provider: %s: %d\n",
  78. pdev->name, r);
  79. mtk_register_reset_controller(node, 1, 0x34);
  80. return r;
  81. }
  82. static int clk_mt7622_sgmiisys_init(struct platform_device *pdev)
  83. {
  84. struct clk_onecell_data *clk_data;
  85. struct device_node *node = pdev->dev.of_node;
  86. int r;
  87. clk_data = mtk_alloc_clk_data(CLK_SGMII_NR_CLK);
  88. mtk_clk_register_gates(node, sgmii_clks, ARRAY_SIZE(sgmii_clks),
  89. clk_data);
  90. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  91. if (r)
  92. dev_err(&pdev->dev,
  93. "could not register clock provider: %s: %d\n",
  94. pdev->name, r);
  95. return r;
  96. }
  97. static const struct of_device_id of_match_clk_mt7622_eth[] = {
  98. {
  99. .compatible = "mediatek,mt7622-ethsys",
  100. .data = clk_mt7622_ethsys_init,
  101. }, {
  102. .compatible = "mediatek,mt7622-sgmiisys",
  103. .data = clk_mt7622_sgmiisys_init,
  104. }, {
  105. /* sentinel */
  106. }
  107. };
  108. static int clk_mt7622_eth_probe(struct platform_device *pdev)
  109. {
  110. int (*clk_init)(struct platform_device *);
  111. int r;
  112. clk_init = of_device_get_match_data(&pdev->dev);
  113. if (!clk_init)
  114. return -EINVAL;
  115. r = clk_init(pdev);
  116. if (r)
  117. dev_err(&pdev->dev,
  118. "could not register clock provider: %s: %d\n",
  119. pdev->name, r);
  120. return r;
  121. }
  122. static struct platform_driver clk_mt7622_eth_drv = {
  123. .probe = clk_mt7622_eth_probe,
  124. .driver = {
  125. .name = "clk-mt7622-eth",
  126. .of_match_table = of_match_clk_mt7622_eth,
  127. },
  128. };
  129. builtin_platform_driver(clk_mt7622_eth_drv);