clocks.c 3.4 KB

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