clk-mt7629-hif.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2018 MediaTek Inc.
  4. * Author: Wenzhen Yu <Wenzhen Yu@mediatek.com>
  5. * Ryder Lee <ryder.lee@mediatek.com>
  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_PCIE(_id, _name, _parent, _shift) { \
  16. .id = _id, \
  17. .name = _name, \
  18. .parent_name = _parent, \
  19. .regs = &pcie_cg_regs, \
  20. .shift = _shift, \
  21. .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  22. }
  23. #define GATE_SSUSB(_id, _name, _parent, _shift) { \
  24. .id = _id, \
  25. .name = _name, \
  26. .parent_name = _parent, \
  27. .regs = &ssusb_cg_regs, \
  28. .shift = _shift, \
  29. .ops = &mtk_clk_gate_ops_no_setclr_inv, \
  30. }
  31. static const struct mtk_gate_regs pcie_cg_regs = {
  32. .set_ofs = 0x30,
  33. .clr_ofs = 0x30,
  34. .sta_ofs = 0x30,
  35. };
  36. static const struct mtk_gate_regs ssusb_cg_regs = {
  37. .set_ofs = 0x30,
  38. .clr_ofs = 0x30,
  39. .sta_ofs = 0x30,
  40. };
  41. static const struct mtk_gate ssusb_clks[] = {
  42. GATE_SSUSB(CLK_SSUSB_U2_PHY_1P_EN, "ssusb_u2_phy_1p",
  43. "to_u2_phy_1p", 0),
  44. GATE_SSUSB(CLK_SSUSB_U2_PHY_EN, "ssusb_u2_phy_en", "to_u2_phy", 1),
  45. GATE_SSUSB(CLK_SSUSB_REF_EN, "ssusb_ref_en", "to_usb3_ref", 5),
  46. GATE_SSUSB(CLK_SSUSB_SYS_EN, "ssusb_sys_en", "to_usb3_sys", 6),
  47. GATE_SSUSB(CLK_SSUSB_MCU_EN, "ssusb_mcu_en", "to_usb3_mcu", 7),
  48. GATE_SSUSB(CLK_SSUSB_DMA_EN, "ssusb_dma_en", "to_usb3_dma", 8),
  49. };
  50. static const struct mtk_gate pcie_clks[] = {
  51. GATE_PCIE(CLK_PCIE_P1_AUX_EN, "pcie_p1_aux_en", "p1_1mhz", 12),
  52. GATE_PCIE(CLK_PCIE_P1_OBFF_EN, "pcie_p1_obff_en", "free_run_4mhz", 13),
  53. GATE_PCIE(CLK_PCIE_P1_AHB_EN, "pcie_p1_ahb_en", "from_top_ahb", 14),
  54. GATE_PCIE(CLK_PCIE_P1_AXI_EN, "pcie_p1_axi_en", "from_top_axi", 15),
  55. GATE_PCIE(CLK_PCIE_P1_MAC_EN, "pcie_p1_mac_en", "pcie1_mac_en", 16),
  56. GATE_PCIE(CLK_PCIE_P1_PIPE_EN, "pcie_p1_pipe_en", "pcie1_pipe_en", 17),
  57. GATE_PCIE(CLK_PCIE_P0_AUX_EN, "pcie_p0_aux_en", "p0_1mhz", 18),
  58. GATE_PCIE(CLK_PCIE_P0_OBFF_EN, "pcie_p0_obff_en", "free_run_4mhz", 19),
  59. GATE_PCIE(CLK_PCIE_P0_AHB_EN, "pcie_p0_ahb_en", "from_top_ahb", 20),
  60. GATE_PCIE(CLK_PCIE_P0_AXI_EN, "pcie_p0_axi_en", "from_top_axi", 21),
  61. GATE_PCIE(CLK_PCIE_P0_MAC_EN, "pcie_p0_mac_en", "pcie0_mac_en", 22),
  62. GATE_PCIE(CLK_PCIE_P0_PIPE_EN, "pcie_p0_pipe_en", "pcie0_pipe_en", 23),
  63. };
  64. static int clk_mt7629_ssusbsys_init(struct platform_device *pdev)
  65. {
  66. struct clk_onecell_data *clk_data;
  67. struct device_node *node = pdev->dev.of_node;
  68. int r;
  69. clk_data = mtk_alloc_clk_data(CLK_SSUSB_NR_CLK);
  70. mtk_clk_register_gates(node, ssusb_clks, ARRAY_SIZE(ssusb_clks),
  71. clk_data);
  72. r = of_clk_add_provider(node, of_clk_src_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(node, 1, 0x34);
  78. return r;
  79. }
  80. static int clk_mt7629_pciesys_init(struct platform_device *pdev)
  81. {
  82. struct clk_onecell_data *clk_data;
  83. struct device_node *node = pdev->dev.of_node;
  84. int r;
  85. clk_data = mtk_alloc_clk_data(CLK_PCIE_NR_CLK);
  86. mtk_clk_register_gates(node, pcie_clks, ARRAY_SIZE(pcie_clks),
  87. clk_data);
  88. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  89. if (r)
  90. dev_err(&pdev->dev,
  91. "could not register clock provider: %s: %d\n",
  92. pdev->name, r);
  93. mtk_register_reset_controller(node, 1, 0x34);
  94. return r;
  95. }
  96. static const struct of_device_id of_match_clk_mt7629_hif[] = {
  97. {
  98. .compatible = "mediatek,mt7629-pciesys",
  99. .data = clk_mt7629_pciesys_init,
  100. }, {
  101. .compatible = "mediatek,mt7629-ssusbsys",
  102. .data = clk_mt7629_ssusbsys_init,
  103. }, {
  104. /* sentinel */
  105. }
  106. };
  107. static int clk_mt7629_hif_probe(struct platform_device *pdev)
  108. {
  109. int (*clk_init)(struct platform_device *);
  110. int r;
  111. clk_init = of_device_get_match_data(&pdev->dev);
  112. if (!clk_init)
  113. return -EINVAL;
  114. r = clk_init(pdev);
  115. if (r)
  116. dev_err(&pdev->dev,
  117. "could not register clock provider: %s: %d\n",
  118. pdev->name, r);
  119. return r;
  120. }
  121. static struct platform_driver clk_mt7629_hif_drv = {
  122. .probe = clk_mt7629_hif_probe,
  123. .driver = {
  124. .name = "clk-mt7629-hif",
  125. .of_match_table = of_match_clk_mt7629_hif,
  126. },
  127. };
  128. builtin_platform_driver(clk_mt7629_hif_drv);