hfpll.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (c) 2018, The Linux Foundation. All rights reserved.
  3. #include <linux/kernel.h>
  4. #include <linux/init.h>
  5. #include <linux/module.h>
  6. #include <linux/platform_device.h>
  7. #include <linux/of.h>
  8. #include <linux/of_device.h>
  9. #include <linux/clk.h>
  10. #include <linux/clk-provider.h>
  11. #include <linux/regmap.h>
  12. #include "clk-regmap.h"
  13. #include "clk-hfpll.h"
  14. static const struct hfpll_data qcs404 = {
  15. .mode_reg = 0x00,
  16. .l_reg = 0x04,
  17. .m_reg = 0x08,
  18. .n_reg = 0x0c,
  19. .user_reg = 0x10,
  20. .config_reg = 0x14,
  21. .config_val = 0x430405d,
  22. .status_reg = 0x1c,
  23. .lock_bit = 16,
  24. .user_val = 0x8,
  25. .user_vco_mask = 0x100000,
  26. .low_vco_max_rate = 1248000000,
  27. .min_rate = 537600000UL,
  28. .max_rate = 2900000000UL,
  29. };
  30. static const struct hfpll_data msm8976_a53 = {
  31. .mode_reg = 0x00,
  32. .l_reg = 0x04,
  33. .m_reg = 0x08,
  34. .n_reg = 0x0c,
  35. .user_reg = 0x10,
  36. .config_reg = 0x14,
  37. .config_val = 0x341600,
  38. .status_reg = 0x1c,
  39. .lock_bit = 16,
  40. .l_val = 0x35,
  41. .user_val = 0x109,
  42. .min_rate = 902400000UL,
  43. .max_rate = 1478400000UL,
  44. };
  45. static const struct hfpll_data msm8976_a72 = {
  46. .mode_reg = 0x00,
  47. .l_reg = 0x04,
  48. .m_reg = 0x08,
  49. .n_reg = 0x0c,
  50. .user_reg = 0x10,
  51. .config_reg = 0x14,
  52. .config_val = 0x4e0405d,
  53. .status_reg = 0x1c,
  54. .lock_bit = 16,
  55. .l_val = 0x3e,
  56. .user_val = 0x100109,
  57. .min_rate = 940800000UL,
  58. .max_rate = 2016000000UL,
  59. };
  60. static const struct hfpll_data msm8976_cci = {
  61. .mode_reg = 0x00,
  62. .l_reg = 0x04,
  63. .m_reg = 0x08,
  64. .n_reg = 0x0c,
  65. .user_reg = 0x10,
  66. .config_reg = 0x14,
  67. .config_val = 0x141400,
  68. .status_reg = 0x1c,
  69. .lock_bit = 16,
  70. .l_val = 0x20,
  71. .user_val = 0x100109,
  72. .min_rate = 556800000UL,
  73. .max_rate = 902400000UL,
  74. };
  75. static const struct of_device_id qcom_hfpll_match_table[] = {
  76. { .compatible = "qcom,msm8976-hfpll-a53", .data = &msm8976_a53 },
  77. { .compatible = "qcom,msm8976-hfpll-a72", .data = &msm8976_a72 },
  78. { .compatible = "qcom,msm8976-hfpll-cci", .data = &msm8976_cci },
  79. { .compatible = "qcom,qcs404-hfpll", .data = &qcs404 },
  80. /* Deprecated in bindings */
  81. { .compatible = "qcom,hfpll", .data = &qcs404 },
  82. { }
  83. };
  84. MODULE_DEVICE_TABLE(of, qcom_hfpll_match_table);
  85. static const struct regmap_config hfpll_regmap_config = {
  86. .reg_bits = 32,
  87. .reg_stride = 4,
  88. .val_bits = 32,
  89. .max_register = 0x30,
  90. .fast_io = true,
  91. };
  92. static int qcom_hfpll_probe(struct platform_device *pdev)
  93. {
  94. struct device *dev = &pdev->dev;
  95. void __iomem *base;
  96. struct regmap *regmap;
  97. struct clk_hfpll *h;
  98. struct clk_init_data init = {
  99. .num_parents = 1,
  100. .ops = &clk_ops_hfpll,
  101. /*
  102. * rather than marking the clock critical and forcing the clock
  103. * to be always enabled, we make sure that the clock is not
  104. * disabled: the firmware remains responsible of enabling this
  105. * clock (for more info check the commit log)
  106. */
  107. .flags = CLK_IGNORE_UNUSED,
  108. };
  109. int ret;
  110. struct clk_parent_data pdata = { .index = 0 };
  111. h = devm_kzalloc(dev, sizeof(*h), GFP_KERNEL);
  112. if (!h)
  113. return -ENOMEM;
  114. base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
  115. if (IS_ERR(base))
  116. return PTR_ERR(base);
  117. regmap = devm_regmap_init_mmio(&pdev->dev, base, &hfpll_regmap_config);
  118. if (IS_ERR(regmap))
  119. return PTR_ERR(regmap);
  120. if (of_property_read_string_index(dev->of_node, "clock-output-names",
  121. 0, &init.name))
  122. return -ENODEV;
  123. init.parent_data = &pdata;
  124. h->d = of_device_get_match_data(&pdev->dev);
  125. h->clkr.hw.init = &init;
  126. spin_lock_init(&h->lock);
  127. ret = devm_clk_register_regmap(dev, &h->clkr);
  128. if (ret) {
  129. dev_err(dev, "failed to register regmap clock: %d\n", ret);
  130. return ret;
  131. }
  132. return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get,
  133. &h->clkr.hw);
  134. }
  135. static struct platform_driver qcom_hfpll_driver = {
  136. .probe = qcom_hfpll_probe,
  137. .driver = {
  138. .name = "qcom-hfpll",
  139. .of_match_table = qcom_hfpll_match_table,
  140. },
  141. };
  142. module_platform_driver(qcom_hfpll_driver);
  143. MODULE_DESCRIPTION("QCOM HFPLL Clock Driver");
  144. MODULE_LICENSE("GPL v2");
  145. MODULE_ALIAS("platform:qcom-hfpll");