clock.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <mach/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);