clock.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * linux/arch/arm/mach-nuc93x/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. unsigned long clk_get_rate(struct clk *clk)
  46. {
  47. return 27000000;
  48. }
  49. EXPORT_SYMBOL(clk_get_rate);
  50. void nuc93x_clk_enable(struct clk *clk, int enable)
  51. {
  52. unsigned int clocks = clk->cken;
  53. unsigned long clken;
  54. clken = __raw_readl(NUC93X_VA_CLKPWR);
  55. if (enable)
  56. clken |= clocks;
  57. else
  58. clken &= ~clocks;
  59. __raw_writel(clken, NUC93X_VA_CLKPWR);
  60. }
  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. }