clk-mt6795-infracfg.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022 Collabora Ltd.
  4. * Author: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
  5. */
  6. #include <dt-bindings/clock/mediatek,mt6795-clk.h>
  7. #include <dt-bindings/reset/mediatek,mt6795-resets.h>
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include "clk-cpumux.h"
  11. #include "clk-gate.h"
  12. #include "clk-mtk.h"
  13. #include "reset.h"
  14. #define GATE_ICG(_id, _name, _parent, _shift) \
  15. GATE_MTK(_id, _name, _parent, &infra_cg_regs, \
  16. _shift, &mtk_clk_gate_ops_no_setclr)
  17. static const struct mtk_gate_regs infra_cg_regs = {
  18. .set_ofs = 0x0040,
  19. .clr_ofs = 0x0044,
  20. .sta_ofs = 0x0048,
  21. };
  22. static const char * const ca53_c0_parents[] = {
  23. "clk26m",
  24. "armca53pll",
  25. "mainpll",
  26. "univpll"
  27. };
  28. static const char * const ca53_c1_parents[] = {
  29. "clk26m",
  30. "armca53pll",
  31. "mainpll",
  32. "univpll"
  33. };
  34. static const struct mtk_composite cpu_muxes[] = {
  35. MUX(CLK_INFRA_CA53_C0_SEL, "infra_ca53_c0_sel", ca53_c0_parents, 0x00, 0, 2),
  36. MUX(CLK_INFRA_CA53_C1_SEL, "infra_ca53_c1_sel", ca53_c1_parents, 0x00, 2, 2),
  37. };
  38. static const struct mtk_gate infra_gates[] = {
  39. GATE_ICG(CLK_INFRA_DBGCLK, "infra_dbgclk", "axi_sel", 0),
  40. GATE_ICG(CLK_INFRA_SMI, "infra_smi", "mm_sel", 1),
  41. GATE_ICG(CLK_INFRA_AUDIO, "infra_audio", "aud_intbus_sel", 5),
  42. GATE_ICG(CLK_INFRA_GCE, "infra_gce", "axi_sel", 6),
  43. GATE_ICG(CLK_INFRA_L2C_SRAM, "infra_l2c_sram", "axi_sel", 7),
  44. GATE_ICG(CLK_INFRA_M4U, "infra_m4u", "mem_sel", 8),
  45. GATE_ICG(CLK_INFRA_MD1MCU, "infra_md1mcu", "clk26m", 9),
  46. GATE_ICG(CLK_INFRA_MD1BUS, "infra_md1bus", "axi_sel", 10),
  47. GATE_ICG(CLK_INFRA_MD1DBB, "infra_dbb", "axi_sel", 11),
  48. GATE_ICG(CLK_INFRA_DEVICE_APC, "infra_devapc", "clk26m", 12),
  49. GATE_ICG(CLK_INFRA_TRNG, "infra_trng", "axi_sel", 13),
  50. GATE_ICG(CLK_INFRA_MD1LTE, "infra_md1lte", "axi_sel", 14),
  51. GATE_ICG(CLK_INFRA_CPUM, "infra_cpum", "cpum_ck", 15),
  52. GATE_ICG(CLK_INFRA_KP, "infra_kp", "axi_sel", 16),
  53. };
  54. static u16 infra_ao_rst_ofs[] = { 0x30, 0x34 };
  55. static u16 infra_ao_idx_map[] = {
  56. [MT6795_INFRA_RST0_SCPSYS_RST] = 0 * RST_NR_PER_BANK + 5,
  57. [MT6795_INFRA_RST0_PMIC_WRAP_RST] = 0 * RST_NR_PER_BANK + 7,
  58. [MT6795_INFRA_RST1_MIPI_DSI_RST] = 1 * RST_NR_PER_BANK + 4,
  59. [MT6795_INFRA_RST1_MIPI_CSI_RST] = 1 * RST_NR_PER_BANK + 7,
  60. [MT6795_INFRA_RST1_MM_IOMMU_RST] = 1 * RST_NR_PER_BANK + 15,
  61. };
  62. static const struct mtk_clk_rst_desc clk_rst_desc = {
  63. .version = MTK_RST_SET_CLR,
  64. .rst_bank_ofs = infra_ao_rst_ofs,
  65. .rst_bank_nr = ARRAY_SIZE(infra_ao_rst_ofs),
  66. .rst_idx_map = infra_ao_idx_map,
  67. .rst_idx_map_nr = ARRAY_SIZE(infra_ao_idx_map),
  68. };
  69. static const struct of_device_id of_match_clk_mt6795_infracfg[] = {
  70. { .compatible = "mediatek,mt6795-infracfg" },
  71. { /* sentinel */ }
  72. };
  73. static int clk_mt6795_infracfg_probe(struct platform_device *pdev)
  74. {
  75. struct clk_hw_onecell_data *clk_data;
  76. struct device_node *node = pdev->dev.of_node;
  77. void __iomem *base;
  78. int ret;
  79. base = devm_platform_ioremap_resource(pdev, 0);
  80. if (IS_ERR(base))
  81. return PTR_ERR(base);
  82. clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
  83. if (!clk_data)
  84. return -ENOMEM;
  85. ret = mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
  86. if (ret)
  87. goto free_clk_data;
  88. ret = mtk_clk_register_gates(node, infra_gates, ARRAY_SIZE(infra_gates), clk_data);
  89. if (ret)
  90. goto free_clk_data;
  91. ret = mtk_clk_register_cpumuxes(node, cpu_muxes, ARRAY_SIZE(cpu_muxes), clk_data);
  92. if (ret)
  93. goto unregister_gates;
  94. ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
  95. if (ret)
  96. goto unregister_cpumuxes;
  97. return 0;
  98. unregister_cpumuxes:
  99. mtk_clk_unregister_cpumuxes(cpu_muxes, ARRAY_SIZE(cpu_muxes), clk_data);
  100. unregister_gates:
  101. mtk_clk_unregister_gates(infra_gates, ARRAY_SIZE(infra_gates), clk_data);
  102. free_clk_data:
  103. mtk_free_clk_data(clk_data);
  104. return ret;
  105. }
  106. static int clk_mt6795_infracfg_remove(struct platform_device *pdev)
  107. {
  108. struct device_node *node = pdev->dev.of_node;
  109. struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
  110. of_clk_del_provider(node);
  111. mtk_clk_unregister_cpumuxes(cpu_muxes, ARRAY_SIZE(cpu_muxes), clk_data);
  112. mtk_clk_unregister_gates(infra_gates, ARRAY_SIZE(infra_gates), clk_data);
  113. mtk_free_clk_data(clk_data);
  114. return 0;
  115. }
  116. static struct platform_driver clk_mt6795_infracfg_drv = {
  117. .driver = {
  118. .name = "clk-mt6795-infracfg",
  119. .of_match_table = of_match_clk_mt6795_infracfg,
  120. },
  121. .probe = clk_mt6795_infracfg_probe,
  122. .remove = clk_mt6795_infracfg_remove,
  123. };
  124. module_platform_driver(clk_mt6795_infracfg_drv);
  125. MODULE_DESCRIPTION("MediaTek MT6795 infracfg clocks driver");
  126. MODULE_LICENSE("GPL");