clock.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * linux/arch/arm/mach-w90x900/clock.c
  3. *
  4. * Copyright (c) 2008 Nuvoton technology corporation
  5. *
  6. * Wan ZongShun <mcuos.com@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/list.h>
  15. #include <linux/errno.h>
  16. #include <linux/err.h>
  17. #include <linux/string.h>
  18. #include <linux/clk.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/io.h>
  22. #include <mach/hardware.h>
  23. #include "clock.h"
  24. static DEFINE_SPINLOCK(clocks_lock);
  25. int clk_enable(struct clk *clk)
  26. {
  27. unsigned long flags;
  28. spin_lock_irqsave(&clocks_lock, flags);
  29. if (clk->enabled++ == 0)
  30. (clk->enable)(clk, 1);
  31. spin_unlock_irqrestore(&clocks_lock, flags);
  32. return 0;
  33. }
  34. EXPORT_SYMBOL(clk_enable);
  35. void clk_disable(struct clk *clk)
  36. {
  37. unsigned long flags;
  38. WARN_ON(clk->enabled == 0);
  39. spin_lock_irqsave(&clocks_lock, flags);
  40. if (--clk->enabled == 0)
  41. (clk->enable)(clk, 0);
  42. spin_unlock_irqrestore(&clocks_lock, flags);
  43. }
  44. EXPORT_SYMBOL(clk_disable);
  45. void w90x900_clk_enable(struct clk *clk, int enable)
  46. {
  47. unsigned int clocks = clk->cken;
  48. unsigned long clken;
  49. clken = __raw_readl(W90X900_VA_CLKPWR);
  50. if (enable)
  51. clken |= clocks;
  52. else
  53. clken &= ~clocks;
  54. __raw_writel(clken, W90X900_VA_CLKPWR);
  55. }
  56. void clks_register(struct clk_lookup *clks, size_t num)
  57. {
  58. int i;
  59. for (i = 0; i < num; i++)
  60. clkdev_add(&clks[i]);
  61. }