clock.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * linux/arch/arm/mach-sa1100/clock.c
  3. */
  4. #include <linux/module.h>
  5. #include <linux/kernel.h>
  6. #include <linux/list.h>
  7. #include <linux/errno.h>
  8. #include <linux/err.h>
  9. #include <linux/string.h>
  10. #include <linux/clk.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/delay.h>
  14. #include <asm/arch/pxa-regs.h>
  15. #include <asm/hardware.h>
  16. #include "devices.h"
  17. #include "generic.h"
  18. #include "clock.h"
  19. static LIST_HEAD(clocks);
  20. static DEFINE_MUTEX(clocks_mutex);
  21. static DEFINE_SPINLOCK(clocks_lock);
  22. static struct clk *clk_lookup(struct device *dev, const char *id)
  23. {
  24. struct clk *p;
  25. list_for_each_entry(p, &clocks, node)
  26. if (strcmp(id, p->name) == 0 && p->dev == dev)
  27. return p;
  28. return NULL;
  29. }
  30. struct clk *clk_get(struct device *dev, const char *id)
  31. {
  32. struct clk *p, *clk = ERR_PTR(-ENOENT);
  33. mutex_lock(&clocks_mutex);
  34. p = clk_lookup(dev, id);
  35. if (!p)
  36. p = clk_lookup(NULL, id);
  37. if (p)
  38. clk = p;
  39. mutex_unlock(&clocks_mutex);
  40. return clk;
  41. }
  42. EXPORT_SYMBOL(clk_get);
  43. void clk_put(struct clk *clk)
  44. {
  45. }
  46. EXPORT_SYMBOL(clk_put);
  47. int clk_enable(struct clk *clk)
  48. {
  49. unsigned long flags;
  50. spin_lock_irqsave(&clocks_lock, flags);
  51. if (clk->enabled++ == 0)
  52. clk->ops->enable(clk);
  53. spin_unlock_irqrestore(&clocks_lock, flags);
  54. if (clk->delay)
  55. udelay(clk->delay);
  56. return 0;
  57. }
  58. EXPORT_SYMBOL(clk_enable);
  59. void clk_disable(struct clk *clk)
  60. {
  61. unsigned long flags;
  62. WARN_ON(clk->enabled == 0);
  63. spin_lock_irqsave(&clocks_lock, flags);
  64. if (--clk->enabled == 0)
  65. clk->ops->disable(clk);
  66. spin_unlock_irqrestore(&clocks_lock, flags);
  67. }
  68. EXPORT_SYMBOL(clk_disable);
  69. unsigned long clk_get_rate(struct clk *clk)
  70. {
  71. unsigned long rate;
  72. rate = clk->rate;
  73. if (clk->ops->getrate)
  74. rate = clk->ops->getrate(clk);
  75. return rate;
  76. }
  77. EXPORT_SYMBOL(clk_get_rate);
  78. static void clk_gpio27_enable(struct clk *clk)
  79. {
  80. pxa_gpio_mode(GPIO11_3_6MHz_MD);
  81. }
  82. static void clk_gpio27_disable(struct clk *clk)
  83. {
  84. }
  85. static const struct clkops clk_gpio27_ops = {
  86. .enable = clk_gpio27_enable,
  87. .disable = clk_gpio27_disable,
  88. };
  89. void clk_cken_enable(struct clk *clk)
  90. {
  91. CKEN |= 1 << clk->cken;
  92. }
  93. void clk_cken_disable(struct clk *clk)
  94. {
  95. CKEN &= ~(1 << clk->cken);
  96. }
  97. const struct clkops clk_cken_ops = {
  98. .enable = clk_cken_enable,
  99. .disable = clk_cken_disable,
  100. };
  101. static struct clk common_clks[] = {
  102. {
  103. .name = "GPIO27_CLK",
  104. .ops = &clk_gpio27_ops,
  105. .rate = 3686400,
  106. },
  107. };
  108. void clks_register(struct clk *clks, size_t num)
  109. {
  110. int i;
  111. mutex_lock(&clocks_mutex);
  112. for (i = 0; i < num; i++)
  113. list_add(&clks[i].node, &clocks);
  114. mutex_unlock(&clocks_mutex);
  115. }
  116. static int __init clk_init(void)
  117. {
  118. clks_register(common_clks, ARRAY_SIZE(common_clks));
  119. return 0;
  120. }
  121. arch_initcall(clk_init);