clock.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * linux/arch/arm/mach-sa1100/clock.c
  3. */
  4. #include <linux/module.h>
  5. #include <linux/kernel.h>
  6. #include <linux/device.h>
  7. #include <linux/list.h>
  8. #include <linux/errno.h>
  9. #include <linux/err.h>
  10. #include <linux/string.h>
  11. #include <linux/clk.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/mutex.h>
  14. #include <linux/io.h>
  15. #include <linux/clkdev.h>
  16. #include <mach/hardware.h>
  17. struct clkops {
  18. void (*enable)(struct clk *);
  19. void (*disable)(struct clk *);
  20. };
  21. struct clk {
  22. const struct clkops *ops;
  23. unsigned int enabled;
  24. };
  25. #define DEFINE_CLK(_name, _ops) \
  26. struct clk clk_##_name = { \
  27. .ops = _ops, \
  28. }
  29. static DEFINE_SPINLOCK(clocks_lock);
  30. static void clk_gpio27_enable(struct clk *clk)
  31. {
  32. /*
  33. * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111:
  34. * (SA-1110 Developer's Manual, section 9.1.2.1)
  35. */
  36. GAFR |= GPIO_32_768kHz;
  37. GPDR |= GPIO_32_768kHz;
  38. TUCR = TUCR_3_6864MHz;
  39. }
  40. static void clk_gpio27_disable(struct clk *clk)
  41. {
  42. TUCR = 0;
  43. GPDR &= ~GPIO_32_768kHz;
  44. GAFR &= ~GPIO_32_768kHz;
  45. }
  46. int clk_enable(struct clk *clk)
  47. {
  48. unsigned long flags;
  49. if (clk) {
  50. spin_lock_irqsave(&clocks_lock, flags);
  51. if (clk->enabled++ == 0)
  52. clk->ops->enable(clk);
  53. spin_unlock_irqrestore(&clocks_lock, flags);
  54. }
  55. return 0;
  56. }
  57. EXPORT_SYMBOL(clk_enable);
  58. void clk_disable(struct clk *clk)
  59. {
  60. unsigned long flags;
  61. if (clk) {
  62. WARN_ON(clk->enabled == 0);
  63. spin_lock_irqsave(&clocks_lock, flags);
  64. if (--clk->enabled == 0)
  65. clk->ops->disable(clk);
  66. spin_unlock_irqrestore(&clocks_lock, flags);
  67. }
  68. }
  69. EXPORT_SYMBOL(clk_disable);
  70. const struct clkops clk_gpio27_ops = {
  71. .enable = clk_gpio27_enable,
  72. .disable = clk_gpio27_disable,
  73. };
  74. static DEFINE_CLK(gpio27, &clk_gpio27_ops);
  75. static struct clk_lookup sa11xx_clkregs[] = {
  76. CLKDEV_INIT("sa1111.0", NULL, &clk_gpio27),
  77. CLKDEV_INIT("sa1100-rtc", NULL, NULL),
  78. };
  79. static int __init sa11xx_clk_init(void)
  80. {
  81. clkdev_add_table(sa11xx_clkregs, ARRAY_SIZE(sa11xx_clkregs));
  82. return 0;
  83. }
  84. core_initcall(sa11xx_clk_init);