clk.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. struct clk *devm_clk_get(struct device *dev, const char *id)
  44. {
  45. return NULL;
  46. }
  47. EXPORT_SYMBOL(devm_clk_get);
  48. #else
  49. static DEFINE_SPINLOCK(clk_lock);
  50. struct clk *clk_get(struct device *dev, const char *id)
  51. {
  52. const char *clk_name = dev ? dev_name(dev) : id ? id : NULL;
  53. struct clk *clk;
  54. unsigned i;
  55. for (i = 0; (clk = mcf_clks[i]) != NULL; ++i)
  56. if (!strcmp(clk->name, clk_name))
  57. return clk;
  58. pr_warn("clk_get: didn't find clock %s\n", clk_name);
  59. return ERR_PTR(-ENOENT);
  60. }
  61. EXPORT_SYMBOL(clk_get);
  62. int clk_enable(struct clk *clk)
  63. {
  64. unsigned long flags;
  65. spin_lock_irqsave(&clk_lock, flags);
  66. if ((clk->enabled++ == 0) && clk->clk_ops)
  67. clk->clk_ops->enable(clk);
  68. spin_unlock_irqrestore(&clk_lock, flags);
  69. return 0;
  70. }
  71. EXPORT_SYMBOL(clk_enable);
  72. void clk_disable(struct clk *clk)
  73. {
  74. unsigned long flags;
  75. spin_lock_irqsave(&clk_lock, flags);
  76. if ((--clk->enabled == 0) && clk->clk_ops)
  77. clk->clk_ops->disable(clk);
  78. spin_unlock_irqrestore(&clk_lock, flags);
  79. }
  80. EXPORT_SYMBOL(clk_disable);
  81. void clk_put(struct clk *clk)
  82. {
  83. if (clk->enabled != 0)
  84. pr_warn("clk_put %s still enabled\n", clk->name);
  85. }
  86. EXPORT_SYMBOL(clk_put);
  87. unsigned long clk_get_rate(struct clk *clk)
  88. {
  89. return clk->rate;
  90. }
  91. EXPORT_SYMBOL(clk_get_rate);
  92. /***************************************************************************/
  93. void __clk_init_enabled(struct clk *clk)
  94. {
  95. clk->enabled = 1;
  96. clk->clk_ops->enable(clk);
  97. }
  98. void __clk_init_disabled(struct clk *clk)
  99. {
  100. clk->enabled = 0;
  101. clk->clk_ops->disable(clk);
  102. }
  103. static void __clk_enable0(struct clk *clk)
  104. {
  105. __raw_writeb(clk->slot, MCFPM_PPMCR0);
  106. }
  107. static void __clk_disable0(struct clk *clk)
  108. {
  109. __raw_writeb(clk->slot, MCFPM_PPMSR0);
  110. }
  111. struct clk_ops clk_ops0 = {
  112. .enable = __clk_enable0,
  113. .disable = __clk_disable0,
  114. };
  115. #ifdef MCFPM_PPMCR1
  116. static void __clk_enable1(struct clk *clk)
  117. {
  118. __raw_writeb(clk->slot, MCFPM_PPMCR1);
  119. }
  120. static void __clk_disable1(struct clk *clk)
  121. {
  122. __raw_writeb(clk->slot, MCFPM_PPMSR1);
  123. }
  124. struct clk_ops clk_ops1 = {
  125. .enable = __clk_enable1,
  126. .disable = __clk_disable1,
  127. };
  128. #endif /* MCFPM_PPMCR1 */
  129. #endif /* MCFPM_PPMCR0 */