clock.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * linux/arch/arm/mach-mmp/clock.c
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/list.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/clk.h>
  13. #include <linux/io.h>
  14. #include "regs-apbc.h"
  15. #include "clock.h"
  16. static void apbc_clk_enable(struct clk *clk)
  17. {
  18. uint32_t clk_rst;
  19. clk_rst = APBC_APBCLK | APBC_FNCLK | APBC_FNCLKSEL(clk->fnclksel);
  20. __raw_writel(clk_rst, clk->clk_rst);
  21. }
  22. static void apbc_clk_disable(struct clk *clk)
  23. {
  24. __raw_writel(0, clk->clk_rst);
  25. }
  26. struct clkops apbc_clk_ops = {
  27. .enable = apbc_clk_enable,
  28. .disable = apbc_clk_disable,
  29. };
  30. static void apmu_clk_enable(struct clk *clk)
  31. {
  32. __raw_writel(clk->enable_val, clk->clk_rst);
  33. }
  34. static void apmu_clk_disable(struct clk *clk)
  35. {
  36. __raw_writel(0, clk->clk_rst);
  37. }
  38. struct clkops apmu_clk_ops = {
  39. .enable = apmu_clk_enable,
  40. .disable = apmu_clk_disable,
  41. };
  42. static DEFINE_SPINLOCK(clocks_lock);
  43. int clk_enable(struct clk *clk)
  44. {
  45. unsigned long flags;
  46. spin_lock_irqsave(&clocks_lock, flags);
  47. if (clk->enabled++ == 0)
  48. clk->ops->enable(clk);
  49. spin_unlock_irqrestore(&clocks_lock, flags);
  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. if (clk->ops->getrate)
  67. rate = clk->ops->getrate(clk);
  68. else
  69. rate = clk->rate;
  70. return rate;
  71. }
  72. EXPORT_SYMBOL(clk_get_rate);
  73. int clk_set_rate(struct clk *clk, unsigned long rate)
  74. {
  75. unsigned long flags;
  76. int ret = -EINVAL;
  77. if (clk->ops->setrate) {
  78. spin_lock_irqsave(&clocks_lock, flags);
  79. ret = clk->ops->setrate(clk, rate);
  80. spin_unlock_irqrestore(&clocks_lock, flags);
  81. }
  82. return ret;
  83. }
  84. EXPORT_SYMBOL(clk_set_rate);