clock.c 2.7 KB

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