apcs-msm8996.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Qualcomm APCS clock controller driver
  4. *
  5. * Copyright (c) 2022, Linaro Limited
  6. * Author: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
  7. */
  8. #include <linux/bits.h>
  9. #include <linux/bitfield.h>
  10. #include <linux/clk-provider.h>
  11. #include <linux/delay.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/regmap.h>
  15. #define APCS_AUX_OFFSET 0x50
  16. #define APCS_AUX_DIV_MASK GENMASK(17, 16)
  17. #define APCS_AUX_DIV_2 0x1
  18. static int qcom_apcs_msm8996_clk_probe(struct platform_device *pdev)
  19. {
  20. struct device *dev = &pdev->dev;
  21. struct device *parent = dev->parent;
  22. struct regmap *regmap;
  23. struct clk_hw *hw;
  24. unsigned int val;
  25. int ret = -ENODEV;
  26. regmap = dev_get_regmap(parent, NULL);
  27. if (!regmap) {
  28. dev_err(dev, "failed to get regmap: %d\n", ret);
  29. return ret;
  30. }
  31. regmap_read(regmap, APCS_AUX_OFFSET, &val);
  32. regmap_update_bits(regmap, APCS_AUX_OFFSET, APCS_AUX_DIV_MASK,
  33. FIELD_PREP(APCS_AUX_DIV_MASK, APCS_AUX_DIV_2));
  34. /*
  35. * This clock is used during CPU cluster setup while setting up CPU PLLs.
  36. * Add hardware mandated delay to make sure that the sys_apcs_aux clock
  37. * is stable (after setting the divider) before continuing
  38. * bootstrapping to keep CPUs from ending up in a weird state.
  39. */
  40. udelay(5);
  41. /*
  42. * As this clocks is a parent of the CPU cluster clocks and is actually
  43. * used as a parent during CPU clocks setup, we want for it to register
  44. * as early as possible, without letting fw_devlink to delay probing of
  45. * either of the drivers.
  46. *
  47. * The sys_apcs_aux is a child (divider) of gpll0, but we register it
  48. * as a fixed rate clock instead to ease bootstrapping procedure. By
  49. * doing this we make sure that CPU cluster clocks are able to be setup
  50. * early during the boot process (as it is recommended by Qualcomm).
  51. */
  52. hw = devm_clk_hw_register_fixed_rate(dev, "sys_apcs_aux", NULL, 0, 300000000);
  53. if (IS_ERR(hw))
  54. return PTR_ERR(hw);
  55. return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw);
  56. }
  57. static struct platform_driver qcom_apcs_msm8996_clk_driver = {
  58. .probe = qcom_apcs_msm8996_clk_probe,
  59. .driver = {
  60. .name = "qcom-apcs-msm8996-clk",
  61. },
  62. };
  63. /* Register early enough to fix the clock to be used for other cores */
  64. static int __init qcom_apcs_msm8996_clk_init(void)
  65. {
  66. return platform_driver_register(&qcom_apcs_msm8996_clk_driver);
  67. }
  68. postcore_initcall(qcom_apcs_msm8996_clk_init);
  69. static void __exit qcom_apcs_msm8996_clk_exit(void)
  70. {
  71. platform_driver_unregister(&qcom_apcs_msm8996_clk_driver);
  72. }
  73. module_exit(qcom_apcs_msm8996_clk_exit);
  74. MODULE_AUTHOR("Dmitry Baryshkov <dmitry.baryshkov@linaro.org>");
  75. MODULE_LICENSE("GPL");
  76. MODULE_DESCRIPTION("Qualcomm MSM8996 APCS clock driver");