clk.c 3.1 KB

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