clock.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 DEFINE_SPINLOCK(clocks_lock);
  31. int clk_enable(struct clk *clk)
  32. {
  33. unsigned long flags;
  34. spin_lock_irqsave(&clocks_lock, flags);
  35. if (clk->enabled++ == 0)
  36. clk->ops->enable(clk);
  37. spin_unlock_irqrestore(&clocks_lock, flags);
  38. return 0;
  39. }
  40. EXPORT_SYMBOL(clk_enable);
  41. void clk_disable(struct clk *clk)
  42. {
  43. unsigned long flags;
  44. WARN_ON(clk->enabled == 0);
  45. spin_lock_irqsave(&clocks_lock, flags);
  46. if (--clk->enabled == 0)
  47. clk->ops->disable(clk);
  48. spin_unlock_irqrestore(&clocks_lock, flags);
  49. }
  50. EXPORT_SYMBOL(clk_disable);
  51. unsigned long clk_get_rate(struct clk *clk)
  52. {
  53. unsigned long rate;
  54. if (clk->ops->getrate)
  55. rate = clk->ops->getrate(clk);
  56. else
  57. rate = clk->rate;
  58. return rate;
  59. }
  60. EXPORT_SYMBOL(clk_get_rate);
  61. void clks_register(struct clk_lookup *clks, size_t num)
  62. {
  63. int i;
  64. for (i = 0; i < num; i++)
  65. clkdev_add(&clks[i]);
  66. }