clk.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // SPDX-License-Identifier: GPL-2.0
  2. /***************************************************************************/
  3. /*
  4. * clk.c -- general ColdFire CPU kernel clk handling
  5. *
  6. * Copyright (C) 2009, Greg Ungerer (gerg@snapgear.com)
  7. */
  8. /***************************************************************************/
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/mutex.h>
  13. #include <linux/clk.h>
  14. #include <linux/io.h>
  15. #include <linux/err.h>
  16. #include <asm/coldfire.h>
  17. #include <asm/mcfsim.h>
  18. #include <asm/mcfclk.h>
  19. static DEFINE_SPINLOCK(clk_lock);
  20. #ifdef MCFPM_PPMCR0
  21. /*
  22. * For more advanced ColdFire parts that have clocks that can be enabled
  23. * we supply enable/disable functions. These must properly define their
  24. * clocks in their platform specific code.
  25. */
  26. void __clk_init_enabled(struct clk *clk)
  27. {
  28. clk->enabled = 1;
  29. clk->clk_ops->enable(clk);
  30. }
  31. void __clk_init_disabled(struct clk *clk)
  32. {
  33. clk->enabled = 0;
  34. clk->clk_ops->disable(clk);
  35. }
  36. static void __clk_enable0(struct clk *clk)
  37. {
  38. __raw_writeb(clk->slot, MCFPM_PPMCR0);
  39. }
  40. static void __clk_disable0(struct clk *clk)
  41. {
  42. __raw_writeb(clk->slot, MCFPM_PPMSR0);
  43. }
  44. struct clk_ops clk_ops0 = {
  45. .enable = __clk_enable0,
  46. .disable = __clk_disable0,
  47. };
  48. #ifdef MCFPM_PPMCR1
  49. static void __clk_enable1(struct clk *clk)
  50. {
  51. __raw_writeb(clk->slot, MCFPM_PPMCR1);
  52. }
  53. static void __clk_disable1(struct clk *clk)
  54. {
  55. __raw_writeb(clk->slot, MCFPM_PPMSR1);
  56. }
  57. struct clk_ops clk_ops1 = {
  58. .enable = __clk_enable1,
  59. .disable = __clk_disable1,
  60. };
  61. #endif /* MCFPM_PPMCR1 */
  62. #endif /* MCFPM_PPMCR0 */
  63. struct clk *clk_get(struct device *dev, const char *id)
  64. {
  65. const char *clk_name = dev ? dev_name(dev) : id ? id : NULL;
  66. struct clk *clk;
  67. unsigned i;
  68. for (i = 0; (clk = mcf_clks[i]) != NULL; ++i)
  69. if (!strcmp(clk->name, clk_name))
  70. return clk;
  71. pr_warn("clk_get: didn't find clock %s\n", clk_name);
  72. return ERR_PTR(-ENOENT);
  73. }
  74. EXPORT_SYMBOL(clk_get);
  75. int clk_enable(struct clk *clk)
  76. {
  77. unsigned long flags;
  78. spin_lock_irqsave(&clk_lock, flags);
  79. if ((clk->enabled++ == 0) && clk->clk_ops)
  80. clk->clk_ops->enable(clk);
  81. spin_unlock_irqrestore(&clk_lock, flags);
  82. return 0;
  83. }
  84. EXPORT_SYMBOL(clk_enable);
  85. void clk_disable(struct clk *clk)
  86. {
  87. unsigned long flags;
  88. if (!clk)
  89. return;
  90. spin_lock_irqsave(&clk_lock, flags);
  91. if ((--clk->enabled == 0) && clk->clk_ops)
  92. clk->clk_ops->disable(clk);
  93. spin_unlock_irqrestore(&clk_lock, flags);
  94. }
  95. EXPORT_SYMBOL(clk_disable);
  96. void clk_put(struct clk *clk)
  97. {
  98. if (clk->enabled != 0)
  99. pr_warn("clk_put %s still enabled\n", clk->name);
  100. }
  101. EXPORT_SYMBOL(clk_put);
  102. unsigned long clk_get_rate(struct clk *clk)
  103. {
  104. if (!clk)
  105. return 0;
  106. return clk->rate;
  107. }
  108. EXPORT_SYMBOL(clk_get_rate);
  109. /* dummy functions, should not be called */
  110. long clk_round_rate(struct clk *clk, unsigned long rate)
  111. {
  112. WARN_ON(clk);
  113. return 0;
  114. }
  115. EXPORT_SYMBOL(clk_round_rate);
  116. int clk_set_rate(struct clk *clk, unsigned long rate)
  117. {
  118. WARN_ON(clk);
  119. return 0;
  120. }
  121. EXPORT_SYMBOL(clk_set_rate);
  122. int clk_set_parent(struct clk *clk, struct clk *parent)
  123. {
  124. WARN_ON(clk);
  125. return 0;
  126. }
  127. EXPORT_SYMBOL(clk_set_parent);
  128. struct clk *clk_get_parent(struct clk *clk)
  129. {
  130. WARN_ON(clk);
  131. return NULL;
  132. }
  133. EXPORT_SYMBOL(clk_get_parent);
  134. /***************************************************************************/