abx500-clk.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * abx500 clock implementation for ux500 platform.
  3. *
  4. * Copyright (C) 2012 ST-Ericsson SA
  5. * Author: Ulf Hansson <ulf.hansson@linaro.org>
  6. *
  7. * License terms: GNU General Public License (GPL) version 2
  8. */
  9. #include <linux/err.h>
  10. #include <linux/module.h>
  11. #include <linux/device.h>
  12. #include <linux/of.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/mfd/abx500/ab8500.h>
  15. #include <linux/mfd/abx500/ab8500-sysctrl.h>
  16. #include <linux/clkdev.h>
  17. #include <linux/clk-provider.h>
  18. #include <dt-bindings/clock/ste-ab8500.h>
  19. #include "clk.h"
  20. #define AB8500_NUM_CLKS 6
  21. static struct clk *ab8500_clks[AB8500_NUM_CLKS];
  22. static struct clk_onecell_data ab8500_clk_data;
  23. /* Clock definitions for ab8500 */
  24. static int ab8500_reg_clks(struct device *dev)
  25. {
  26. int ret;
  27. struct clk *clk;
  28. struct device_node *np = dev->of_node;
  29. const char *intclk_parents[] = {"ab8500_sysclk", "ulpclk"};
  30. u16 intclk_reg_sel[] = {0 , AB8500_SYSULPCLKCTRL1};
  31. u8 intclk_reg_mask[] = {0 , AB8500_SYSULPCLKCTRL1_SYSULPCLKINTSEL_MASK};
  32. u8 intclk_reg_bits[] = {
  33. 0 ,
  34. (1 << AB8500_SYSULPCLKCTRL1_SYSULPCLKINTSEL_SHIFT)
  35. };
  36. /* Enable SWAT */
  37. ret = ab8500_sysctrl_set(AB8500_SWATCTRL, AB8500_SWATCTRL_SWATENABLE);
  38. if (ret)
  39. return ret;
  40. /* ab8500_sysclk2 */
  41. clk = clk_reg_sysctrl_gate(dev , "ab8500_sysclk2", "ab8500_sysclk",
  42. AB8500_SYSULPCLKCTRL1, AB8500_SYSULPCLKCTRL1_SYSCLKBUF2REQ,
  43. AB8500_SYSULPCLKCTRL1_SYSCLKBUF2REQ, 0, 0);
  44. ab8500_clks[AB8500_SYSCLK_BUF2] = clk;
  45. /* ab8500_sysclk3 */
  46. clk = clk_reg_sysctrl_gate(dev , "ab8500_sysclk3", "ab8500_sysclk",
  47. AB8500_SYSULPCLKCTRL1, AB8500_SYSULPCLKCTRL1_SYSCLKBUF3REQ,
  48. AB8500_SYSULPCLKCTRL1_SYSCLKBUF3REQ, 0, 0);
  49. ab8500_clks[AB8500_SYSCLK_BUF3] = clk;
  50. /* ab8500_sysclk4 */
  51. clk = clk_reg_sysctrl_gate(dev , "ab8500_sysclk4", "ab8500_sysclk",
  52. AB8500_SYSULPCLKCTRL1, AB8500_SYSULPCLKCTRL1_SYSCLKBUF4REQ,
  53. AB8500_SYSULPCLKCTRL1_SYSCLKBUF4REQ, 0, 0);
  54. ab8500_clks[AB8500_SYSCLK_BUF4] = clk;
  55. /* ab_ulpclk */
  56. clk = clk_reg_sysctrl_gate_fixed_rate(dev, "ulpclk", NULL,
  57. AB8500_SYSULPCLKCTRL1, AB8500_SYSULPCLKCTRL1_ULPCLKREQ,
  58. AB8500_SYSULPCLKCTRL1_ULPCLKREQ,
  59. 38400000, 9000, 0);
  60. ab8500_clks[AB8500_SYSCLK_ULP] = clk;
  61. /* ab8500_intclk */
  62. clk = clk_reg_sysctrl_set_parent(dev , "intclk", intclk_parents, 2,
  63. intclk_reg_sel, intclk_reg_mask, intclk_reg_bits, 0);
  64. ab8500_clks[AB8500_SYSCLK_INT] = clk;
  65. /* ab8500_audioclk */
  66. clk = clk_reg_sysctrl_gate(dev , "audioclk", "intclk",
  67. AB8500_SYSULPCLKCTRL1, AB8500_SYSULPCLKCTRL1_AUDIOCLKENA,
  68. AB8500_SYSULPCLKCTRL1_AUDIOCLKENA, 0, 0);
  69. ab8500_clks[AB8500_SYSCLK_AUDIO] = clk;
  70. ab8500_clk_data.clks = ab8500_clks;
  71. ab8500_clk_data.clk_num = ARRAY_SIZE(ab8500_clks);
  72. of_clk_add_provider(np, of_clk_src_onecell_get, &ab8500_clk_data);
  73. dev_info(dev, "registered clocks for ab850x\n");
  74. return 0;
  75. }
  76. /* Clock definitions for ab8540 */
  77. static int ab8540_reg_clks(struct device *dev)
  78. {
  79. return 0;
  80. }
  81. /* Clock definitions for ab9540 */
  82. static int ab9540_reg_clks(struct device *dev)
  83. {
  84. return 0;
  85. }
  86. static int abx500_clk_probe(struct platform_device *pdev)
  87. {
  88. struct ab8500 *parent = dev_get_drvdata(pdev->dev.parent);
  89. int ret;
  90. if (is_ab8500(parent) || is_ab8505(parent)) {
  91. ret = ab8500_reg_clks(&pdev->dev);
  92. } else if (is_ab8540(parent)) {
  93. ret = ab8540_reg_clks(&pdev->dev);
  94. } else if (is_ab9540(parent)) {
  95. ret = ab9540_reg_clks(&pdev->dev);
  96. } else {
  97. dev_err(&pdev->dev, "non supported plf id\n");
  98. return -ENODEV;
  99. }
  100. return ret;
  101. }
  102. static const struct of_device_id abx500_clk_match[] = {
  103. { .compatible = "stericsson,ab8500-clk", },
  104. {}
  105. };
  106. static struct platform_driver abx500_clk_driver = {
  107. .driver = {
  108. .name = "abx500-clk",
  109. .of_match_table = abx500_clk_match,
  110. },
  111. .probe = abx500_clk_probe,
  112. };
  113. static int __init abx500_clk_init(void)
  114. {
  115. return platform_driver_register(&abx500_clk_driver);
  116. }
  117. arch_initcall(abx500_clk_init);
  118. MODULE_AUTHOR("Ulf Hansson <ulf.hansson@linaro.org");
  119. MODULE_DESCRIPTION("ABX500 clk driver");
  120. MODULE_LICENSE("GPL v2");