clock.c 2.5 KB

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