clocks.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* arch/arm/mach-lh7a40x/clocks.c
  2. *
  3. * Copyright (C) 2004 Marc Singer
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * version 2 as published by the Free Software Foundation.
  8. *
  9. */
  10. #include <linux/cpufreq.h>
  11. #include <asm/hardware.h>
  12. #include <asm/arch/clocks.h>
  13. #include <linux/err.h>
  14. struct module;
  15. struct icst525_params;
  16. struct clk {
  17. struct list_head node;
  18. unsigned long rate;
  19. struct module *owner;
  20. const char *name;
  21. // void *data;
  22. // const struct icst525_params *params;
  23. // void (*setvco)(struct clk *, struct icst525_vco vco);
  24. };
  25. int clk_register(struct clk *clk);
  26. void clk_unregister(struct clk *clk);
  27. /* ----- */
  28. #define MAINDIV1(c) (((c) >> 7) & 0x0f)
  29. #define MAINDIV2(c) (((c) >> 11) & 0x1f)
  30. #define PS(c) (((c) >> 18) & 0x03)
  31. #define PREDIV(c) (((c) >> 2) & 0x1f)
  32. #define HCLKDIV(c) (((c) >> 0) & 0x02)
  33. #define PCLKDIV(c) (((c) >> 16) & 0x03)
  34. unsigned int cpufreq_get (unsigned int cpu) /* in kHz */
  35. {
  36. return fclkfreq_get ()/1000;
  37. }
  38. EXPORT_SYMBOL(cpufreq_get);
  39. unsigned int fclkfreq_get (void)
  40. {
  41. unsigned int clkset = CSC_CLKSET;
  42. unsigned int gclk
  43. = XTAL_IN
  44. / (1 << PS(clkset))
  45. * (MAINDIV1(clkset) + 2)
  46. / (PREDIV(clkset) + 2)
  47. * (MAINDIV2(clkset) + 2)
  48. ;
  49. return gclk;
  50. }
  51. unsigned int hclkfreq_get (void)
  52. {
  53. unsigned int clkset = CSC_CLKSET;
  54. unsigned int hclk = fclkfreq_get () / (HCLKDIV(clkset) + 1);
  55. return hclk;
  56. }
  57. unsigned int pclkfreq_get (void)
  58. {
  59. unsigned int clkset = CSC_CLKSET;
  60. int pclkdiv = PCLKDIV(clkset);
  61. unsigned int pclk;
  62. if (pclkdiv == 0x3)
  63. pclkdiv = 0x2;
  64. pclk = hclkfreq_get () / (1 << pclkdiv);
  65. return pclk;
  66. }
  67. /* ----- */
  68. static LIST_HEAD(clocks);
  69. static DECLARE_MUTEX(clocks_sem);
  70. struct clk *clk_get (struct device *dev, const char *id)
  71. {
  72. struct clk *p;
  73. struct clk *clk = ERR_PTR(-ENOENT);
  74. down (&clocks_sem);
  75. list_for_each_entry (p, &clocks, node) {
  76. if (strcmp (id, p->name) == 0
  77. && try_module_get(p->owner)) {
  78. clk = p;
  79. break;
  80. }
  81. }
  82. up (&clocks_sem);
  83. return clk;
  84. }
  85. EXPORT_SYMBOL(clk_get);
  86. void clk_put (struct clk *clk)
  87. {
  88. module_put(clk->owner);
  89. }
  90. EXPORT_SYMBOL(clk_put);
  91. int clk_enable (struct clk *clk)
  92. {
  93. return 0;
  94. }
  95. EXPORT_SYMBOL(clk_enable);
  96. void clk_disable (struct clk *clk)
  97. {
  98. }
  99. EXPORT_SYMBOL(clk_disable);
  100. int clk_use (struct clk *clk)
  101. {
  102. return 0;
  103. }
  104. EXPORT_SYMBOL(clk_use);
  105. void clk_unuse (struct clk *clk)
  106. {
  107. }
  108. EXPORT_SYMBOL(clk_unuse);
  109. unsigned long clk_get_rate (struct clk *clk)
  110. {
  111. return clk->rate;
  112. }
  113. EXPORT_SYMBOL(clk_get_rate);
  114. long clk_round_rate (struct clk *clk, unsigned long rate)
  115. {
  116. return rate;
  117. }
  118. EXPORT_SYMBOL(clk_round_rate);
  119. int clk_set_rate (struct clk *clk, unsigned long rate)
  120. {
  121. int ret = -EIO;
  122. return ret;
  123. }
  124. EXPORT_SYMBOL(clk_set_rate);
  125. #if 0
  126. /*
  127. * These are fixed clocks.
  128. */
  129. static struct clk kmi_clk = {
  130. .name = "KMIREFCLK",
  131. .rate = 24000000,
  132. };
  133. static struct clk uart_clk = {
  134. .name = "UARTCLK",
  135. .rate = 24000000,
  136. };
  137. static struct clk mmci_clk = {
  138. .name = "MCLK",
  139. .rate = 33000000,
  140. };
  141. #endif
  142. static struct clk clcd_clk = {
  143. .name = "CLCDCLK",
  144. .rate = 0,
  145. };
  146. int clk_register (struct clk *clk)
  147. {
  148. down (&clocks_sem);
  149. list_add (&clk->node, &clocks);
  150. up (&clocks_sem);
  151. return 0;
  152. }
  153. EXPORT_SYMBOL(clk_register);
  154. void clk_unregister (struct clk *clk)
  155. {
  156. down (&clocks_sem);
  157. list_del (&clk->node);
  158. up (&clocks_sem);
  159. }
  160. EXPORT_SYMBOL(clk_unregister);
  161. static int __init clk_init (void)
  162. {
  163. clk_register(&clcd_clk);
  164. return 0;
  165. }
  166. arch_initcall(clk_init);