clk-mt7622-hif.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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_PCIE(_id, _name, _parent, _shift) \
  16. GATE_MTK(_id, _name, _parent, &pcie_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  17. #define GATE_SSUSB(_id, _name, _parent, _shift) \
  18. GATE_MTK(_id, _name, _parent, &ssusb_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
  19. static const struct mtk_gate_regs pcie_cg_regs = {
  20. .set_ofs = 0x30,
  21. .clr_ofs = 0x30,
  22. .sta_ofs = 0x30,
  23. };
  24. static const struct mtk_gate_regs ssusb_cg_regs = {
  25. .set_ofs = 0x30,
  26. .clr_ofs = 0x30,
  27. .sta_ofs = 0x30,
  28. };
  29. static const struct mtk_gate ssusb_clks[] = {
  30. GATE_SSUSB(CLK_SSUSB_U2_PHY_1P_EN, "ssusb_u2_phy_1p",
  31. "to_u2_phy_1p", 0),
  32. GATE_SSUSB(CLK_SSUSB_U2_PHY_EN, "ssusb_u2_phy_en", "to_u2_phy", 1),
  33. GATE_SSUSB(CLK_SSUSB_REF_EN, "ssusb_ref_en", "to_usb3_ref", 5),
  34. GATE_SSUSB(CLK_SSUSB_SYS_EN, "ssusb_sys_en", "to_usb3_sys", 6),
  35. GATE_SSUSB(CLK_SSUSB_MCU_EN, "ssusb_mcu_en", "axi_sel", 7),
  36. GATE_SSUSB(CLK_SSUSB_DMA_EN, "ssusb_dma_en", "hif_sel", 8),
  37. };
  38. static const struct mtk_gate pcie_clks[] = {
  39. GATE_PCIE(CLK_PCIE_P1_AUX_EN, "pcie_p1_aux_en", "p1_1mhz", 12),
  40. GATE_PCIE(CLK_PCIE_P1_OBFF_EN, "pcie_p1_obff_en", "free_run_4mhz", 13),
  41. GATE_PCIE(CLK_PCIE_P1_AHB_EN, "pcie_p1_ahb_en", "axi_sel", 14),
  42. GATE_PCIE(CLK_PCIE_P1_AXI_EN, "pcie_p1_axi_en", "hif_sel", 15),
  43. GATE_PCIE(CLK_PCIE_P1_MAC_EN, "pcie_p1_mac_en", "pcie1_mac_en", 16),
  44. GATE_PCIE(CLK_PCIE_P1_PIPE_EN, "pcie_p1_pipe_en", "pcie1_pipe_en", 17),
  45. GATE_PCIE(CLK_PCIE_P0_AUX_EN, "pcie_p0_aux_en", "p0_1mhz", 18),
  46. GATE_PCIE(CLK_PCIE_P0_OBFF_EN, "pcie_p0_obff_en", "free_run_4mhz", 19),
  47. GATE_PCIE(CLK_PCIE_P0_AHB_EN, "pcie_p0_ahb_en", "axi_sel", 20),
  48. GATE_PCIE(CLK_PCIE_P0_AXI_EN, "pcie_p0_axi_en", "hif_sel", 21),
  49. GATE_PCIE(CLK_PCIE_P0_MAC_EN, "pcie_p0_mac_en", "pcie0_mac_en", 22),
  50. GATE_PCIE(CLK_PCIE_P0_PIPE_EN, "pcie_p0_pipe_en", "pcie0_pipe_en", 23),
  51. GATE_PCIE(CLK_SATA_AHB_EN, "sata_ahb_en", "axi_sel", 26),
  52. GATE_PCIE(CLK_SATA_AXI_EN, "sata_axi_en", "hif_sel", 27),
  53. GATE_PCIE(CLK_SATA_ASIC_EN, "sata_asic_en", "sata_asic", 28),
  54. GATE_PCIE(CLK_SATA_RBC_EN, "sata_rbc_en", "sata_rbc", 29),
  55. GATE_PCIE(CLK_SATA_PM_EN, "sata_pm_en", "univpll2_d4", 30),
  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_mt7622_ssusbsys_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_SSUSB_NR_CLK);
  69. mtk_clk_register_gates(node, ssusb_clks, ARRAY_SIZE(ssusb_clks),
  70. clk_data);
  71. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  72. if (r)
  73. dev_err(&pdev->dev,
  74. "could not register clock provider: %s: %d\n",
  75. pdev->name, r);
  76. mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  77. return r;
  78. }
  79. static int clk_mt7622_pciesys_init(struct platform_device *pdev)
  80. {
  81. struct clk_hw_onecell_data *clk_data;
  82. struct device_node *node = pdev->dev.of_node;
  83. int r;
  84. clk_data = mtk_alloc_clk_data(CLK_PCIE_NR_CLK);
  85. mtk_clk_register_gates(node, pcie_clks, ARRAY_SIZE(pcie_clks),
  86. clk_data);
  87. r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  88. if (r)
  89. dev_err(&pdev->dev,
  90. "could not register clock provider: %s: %d\n",
  91. pdev->name, r);
  92. mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  93. return r;
  94. }
  95. static const struct of_device_id of_match_clk_mt7622_hif[] = {
  96. {
  97. .compatible = "mediatek,mt7622-pciesys",
  98. .data = clk_mt7622_pciesys_init,
  99. }, {
  100. .compatible = "mediatek,mt7622-ssusbsys",
  101. .data = clk_mt7622_ssusbsys_init,
  102. }, {
  103. /* sentinel */
  104. }
  105. };
  106. static int clk_mt7622_hif_probe(struct platform_device *pdev)
  107. {
  108. int (*clk_init)(struct platform_device *);
  109. int r;
  110. clk_init = of_device_get_match_data(&pdev->dev);
  111. if (!clk_init)
  112. return -EINVAL;
  113. r = clk_init(pdev);
  114. if (r)
  115. dev_err(&pdev->dev,
  116. "could not register clock provider: %s: %d\n",
  117. pdev->name, r);
  118. return r;
  119. }
  120. static struct platform_driver clk_mt7622_hif_drv = {
  121. .probe = clk_mt7622_hif_probe,
  122. .driver = {
  123. .name = "clk-mt7622-hif",
  124. .of_match_table = of_match_clk_mt7622_hif,
  125. },
  126. };
  127. builtin_platform_driver(clk_mt7622_hif_drv);