clock.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * linux/arch/arm/mach-sa1100/clock.c
  3. */
  4. #include <linux/module.h>
  5. #include <linux/kernel.h>
  6. #include <linux/clk.h>
  7. #include <linux/spinlock.h>
  8. #include <linux/delay.h>
  9. #include <linux/clkdev.h>
  10. #include "clock.h"
  11. static DEFINE_SPINLOCK(clocks_lock);
  12. int clk_enable(struct clk *clk)
  13. {
  14. unsigned long flags;
  15. spin_lock_irqsave(&clocks_lock, flags);
  16. if (clk->enabled++ == 0)
  17. clk->ops->enable(clk);
  18. spin_unlock_irqrestore(&clocks_lock, flags);
  19. if (clk->delay)
  20. udelay(clk->delay);
  21. return 0;
  22. }
  23. EXPORT_SYMBOL(clk_enable);
  24. void clk_disable(struct clk *clk)
  25. {
  26. unsigned long flags;
  27. WARN_ON(clk->enabled == 0);
  28. spin_lock_irqsave(&clocks_lock, flags);
  29. if (--clk->enabled == 0)
  30. clk->ops->disable(clk);
  31. spin_unlock_irqrestore(&clocks_lock, flags);
  32. }
  33. EXPORT_SYMBOL(clk_disable);
  34. unsigned long clk_get_rate(struct clk *clk)
  35. {
  36. unsigned long rate;
  37. rate = clk->rate;
  38. if (clk->ops->getrate)
  39. rate = clk->ops->getrate(clk);
  40. return rate;
  41. }
  42. EXPORT_SYMBOL(clk_get_rate);
  43. int clk_set_rate(struct clk *clk, unsigned long rate)
  44. {
  45. unsigned long flags;
  46. int ret = -EINVAL;
  47. if (clk->ops->setrate) {
  48. spin_lock_irqsave(&clocks_lock, flags);
  49. ret = clk->ops->setrate(clk, rate);
  50. spin_unlock_irqrestore(&clocks_lock, flags);
  51. }
  52. return ret;
  53. }
  54. EXPORT_SYMBOL(clk_set_rate);
  55. void clk_dummy_enable(struct clk *clk)
  56. {
  57. }
  58. void clk_dummy_disable(struct clk *clk)
  59. {
  60. }
  61. const struct clkops clk_dummy_ops = {
  62. .enable = clk_dummy_enable,
  63. .disable = clk_dummy_disable,
  64. };
  65. struct clk clk_dummy = {
  66. .ops = &clk_dummy_ops,
  67. };