hfpll.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. .parent_names = (const char *[]){ "xo" },
  50. .num_parents = 1,
  51. .ops = &clk_ops_hfpll,
  52. };
  53. h = devm_kzalloc(dev, sizeof(*h), GFP_KERNEL);
  54. if (!h)
  55. return -ENOMEM;
  56. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  57. base = devm_ioremap_resource(dev, res);
  58. if (IS_ERR(base))
  59. return PTR_ERR(base);
  60. regmap = devm_regmap_init_mmio(&pdev->dev, base, &hfpll_regmap_config);
  61. if (IS_ERR(regmap))
  62. return PTR_ERR(regmap);
  63. if (of_property_read_string_index(dev->of_node, "clock-output-names",
  64. 0, &init.name))
  65. return -ENODEV;
  66. h->d = &hdata;
  67. h->clkr.hw.init = &init;
  68. spin_lock_init(&h->lock);
  69. return devm_clk_register_regmap(&pdev->dev, &h->clkr);
  70. }
  71. static struct platform_driver qcom_hfpll_driver = {
  72. .probe = qcom_hfpll_probe,
  73. .driver = {
  74. .name = "qcom-hfpll",
  75. .of_match_table = qcom_hfpll_match_table,
  76. },
  77. };
  78. module_platform_driver(qcom_hfpll_driver);
  79. MODULE_DESCRIPTION("QCOM HFPLL Clock Driver");
  80. MODULE_LICENSE("GPL v2");
  81. MODULE_ALIAS("platform:qcom-hfpll");