hfpll.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/clk.h>
  9. #include <linux/clk-provider.h>
  10. #include <linux/regmap.h>
  11. #include "clk-regmap.h"
  12. #include "clk-hfpll.h"
  13. static const struct hfpll_data hdata = {
  14. .mode_reg = 0x00,
  15. .l_reg = 0x04,
  16. .m_reg = 0x08,
  17. .n_reg = 0x0c,
  18. .user_reg = 0x10,
  19. .config_reg = 0x14,
  20. .config_val = 0x430405d,
  21. .status_reg = 0x1c,
  22. .lock_bit = 16,
  23. .user_val = 0x8,
  24. .user_vco_mask = 0x100000,
  25. .low_vco_max_rate = 1248000000,
  26. .min_rate = 537600000UL,
  27. .max_rate = 2900000000UL,
  28. };
  29. static const struct of_device_id qcom_hfpll_match_table[] = {
  30. { .compatible = "qcom,hfpll" },
  31. { }
  32. };
  33. MODULE_DEVICE_TABLE(of, qcom_hfpll_match_table);
  34. static const struct regmap_config hfpll_regmap_config = {
  35. .reg_bits = 32,
  36. .reg_stride = 4,
  37. .val_bits = 32,
  38. .max_register = 0x30,
  39. .fast_io = true,
  40. };
  41. static int qcom_hfpll_probe(struct platform_device *pdev)
  42. {
  43. struct resource *res;
  44. struct device *dev = &pdev->dev;
  45. void __iomem *base;
  46. struct regmap *regmap;
  47. struct clk_hfpll *h;
  48. struct clk_init_data init = {
  49. .num_parents = 1,
  50. .ops = &clk_ops_hfpll,
  51. /*
  52. * rather than marking the clock critical and forcing the clock
  53. * to be always enabled, we make sure that the clock is not
  54. * disabled: the firmware remains responsible of enabling this
  55. * clock (for more info check the commit log)
  56. */
  57. .flags = CLK_IGNORE_UNUSED,
  58. };
  59. int ret;
  60. struct clk_parent_data pdata = { .index = 0 };
  61. h = devm_kzalloc(dev, sizeof(*h), GFP_KERNEL);
  62. if (!h)
  63. return -ENOMEM;
  64. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  65. base = devm_ioremap_resource(dev, res);
  66. if (IS_ERR(base))
  67. return PTR_ERR(base);
  68. regmap = devm_regmap_init_mmio(&pdev->dev, base, &hfpll_regmap_config);
  69. if (IS_ERR(regmap))
  70. return PTR_ERR(regmap);
  71. if (of_property_read_string_index(dev->of_node, "clock-output-names",
  72. 0, &init.name))
  73. return -ENODEV;
  74. init.parent_data = &pdata;
  75. h->d = &hdata;
  76. h->clkr.hw.init = &init;
  77. spin_lock_init(&h->lock);
  78. ret = devm_clk_register_regmap(dev, &h->clkr);
  79. if (ret) {
  80. dev_err(dev, "failed to register regmap clock: %d\n", ret);
  81. return ret;
  82. }
  83. return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get,
  84. &h->clkr.hw);
  85. }
  86. static struct platform_driver qcom_hfpll_driver = {
  87. .probe = qcom_hfpll_probe,
  88. .driver = {
  89. .name = "qcom-hfpll",
  90. .of_match_table = qcom_hfpll_match_table,
  91. },
  92. };
  93. module_platform_driver(qcom_hfpll_driver);
  94. MODULE_DESCRIPTION("QCOM HFPLL Clock Driver");
  95. MODULE_LICENSE("GPL v2");
  96. MODULE_ALIAS("platform:qcom-hfpll");