clk-mt7622-hif.c 4.8 KB

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