clock-sh7785.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7785.c
  3. *
  4. * SH7785 support for the clock framework
  5. *
  6. * Copyright (C) 2007 - 2009 Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/clk.h>
  15. #include <linux/io.h>
  16. #include <linux/cpufreq.h>
  17. #include <asm/clock.h>
  18. #include <asm/freq.h>
  19. static unsigned int div2[] = { 1, 2, 4, 6, 8, 12, 16, 18,
  20. 24, 32, 36, 48 };
  21. static struct clk_div_mult_table cpg_div = {
  22. .divisors = div2,
  23. .nr_divisors = ARRAY_SIZE(div2),
  24. };
  25. struct clk_priv {
  26. unsigned int shift;
  27. /* allowable divisor bitmap */
  28. unsigned long div_bitmap;
  29. /* Supportable frequencies + termination entry */
  30. struct cpufreq_frequency_table freq_table[ARRAY_SIZE(div2)+1];
  31. };
  32. #define FRQMR_CLK_DATA(_name, _shift, _div_bitmap) \
  33. static struct clk_priv _name##_data = { \
  34. .shift = _shift, \
  35. .div_bitmap = _div_bitmap, \
  36. \
  37. .freq_table[0] = { \
  38. .index = 0, \
  39. .frequency = CPUFREQ_TABLE_END, \
  40. }, \
  41. }
  42. FRQMR_CLK_DATA(pfc, 0, 0x0f80);
  43. FRQMR_CLK_DATA(s3fc, 4, 0x0ff0);
  44. FRQMR_CLK_DATA(s2fc, 8, 0x0030);
  45. FRQMR_CLK_DATA(mfc, 12, 0x000c);
  46. FRQMR_CLK_DATA(bfc, 16, 0x0fe0);
  47. FRQMR_CLK_DATA(sfc, 20, 0x000c);
  48. FRQMR_CLK_DATA(ufc, 24, 0x000c);
  49. FRQMR_CLK_DATA(ifc, 28, 0x000e);
  50. static unsigned long frqmr_recalc(struct clk *clk)
  51. {
  52. struct clk_priv *data = clk->priv;
  53. unsigned int idx = (__raw_readl(FRQMR1) >> data->shift) & 0x000f;
  54. clk_rate_table_build(clk, data->freq_table, ARRAY_SIZE(div2),
  55. &cpg_div, &data->div_bitmap);
  56. return data->freq_table[idx].frequency;
  57. }
  58. static long frqmr_round_rate(struct clk *clk, unsigned long rate)
  59. {
  60. struct clk_priv *data = clk->priv;
  61. return clk_rate_table_round(clk, data->freq_table, rate);
  62. }
  63. static struct clk_ops frqmr_clk_ops = {
  64. .recalc = frqmr_recalc,
  65. .round_rate = frqmr_round_rate,
  66. };
  67. static unsigned long pll_recalc(struct clk *clk)
  68. {
  69. /*
  70. * XXX: PLL1 multiplier is locked for the default clock mode,
  71. * when mode pin detection and configuration support is added,
  72. * select the multiplier dynamically.
  73. */
  74. return clk->parent->rate * 36;
  75. }
  76. static struct clk_ops pll_clk_ops = {
  77. .recalc = pll_recalc,
  78. };
  79. /*
  80. * Default rate for the root input clock, reset this with clk_set_rate()
  81. * from the platform code.
  82. */
  83. static struct clk extal_clk = {
  84. .name = "extal",
  85. .id = -1,
  86. .rate = 33333333,
  87. };
  88. static struct clk pll_clk = {
  89. .name = "pll_clk",
  90. .id = -1,
  91. .ops = &pll_clk_ops,
  92. .parent = &extal_clk,
  93. .flags = CLK_ENABLE_ON_INIT,
  94. };
  95. static struct clk cpu_clk = {
  96. .name = "cpu_clk", /* Ick */
  97. .id = -1,
  98. .ops = &frqmr_clk_ops,
  99. .parent = &pll_clk,
  100. .flags = CLK_ENABLE_ON_INIT,
  101. .priv = &ifc_data,
  102. };
  103. static struct clk shyway_clk = {
  104. .name = "shyway_clk", /* SHck */
  105. .id = -1,
  106. .ops = &frqmr_clk_ops,
  107. .parent = &pll_clk,
  108. .flags = CLK_ENABLE_ON_INIT,
  109. .priv = &sfc_data,
  110. };
  111. static struct clk peripheral_clk = {
  112. .name = "peripheral_clk", /* Pck */
  113. .id = -1,
  114. .ops = &frqmr_clk_ops,
  115. .parent = &pll_clk,
  116. .flags = CLK_ENABLE_ON_INIT,
  117. .priv = &pfc_data,
  118. };
  119. static struct clk ddr_clk = {
  120. .name = "ddr_clk", /* DDRck */
  121. .id = -1,
  122. .ops = &frqmr_clk_ops,
  123. .parent = &pll_clk,
  124. .flags = CLK_ENABLE_ON_INIT,
  125. .priv = &mfc_data,
  126. };
  127. static struct clk bus_clk = {
  128. .name = "bus_clk", /* Bck */
  129. .id = -1,
  130. .ops = &frqmr_clk_ops,
  131. .parent = &pll_clk,
  132. .flags = CLK_ENABLE_ON_INIT,
  133. .priv = &bfc_data,
  134. };
  135. static struct clk ga_clk = {
  136. .name = "ga_clk", /* GAck */
  137. .id = -1,
  138. .ops = &frqmr_clk_ops,
  139. .parent = &pll_clk,
  140. .priv = &s2fc_data,
  141. };
  142. static struct clk du_clk = {
  143. .name = "du_clk", /* DUck */
  144. .id = -1,
  145. .ops = &frqmr_clk_ops,
  146. .parent = &pll_clk,
  147. .priv = &s3fc_data,
  148. };
  149. static struct clk umem_clk = {
  150. .name = "umem_clk", /* uck */
  151. .id = -1,
  152. .ops = &frqmr_clk_ops,
  153. .parent = &pll_clk,
  154. .flags = CLK_ENABLE_ON_INIT,
  155. .priv = &ufc_data,
  156. };
  157. static struct clk *clks[] = {
  158. &extal_clk,
  159. &pll_clk,
  160. &cpu_clk,
  161. &shyway_clk,
  162. &peripheral_clk,
  163. &ddr_clk,
  164. &bus_clk,
  165. &ga_clk,
  166. &du_clk,
  167. &umem_clk,
  168. };
  169. static int mstpcr_clk_enable(struct clk *clk)
  170. {
  171. __raw_writel(__raw_readl(clk->enable_reg) & ~(1 << clk->enable_bit),
  172. clk->enable_reg);
  173. return 0;
  174. }
  175. static void mstpcr_clk_disable(struct clk *clk)
  176. {
  177. __raw_writel(__raw_readl(clk->enable_reg) | (1 << clk->enable_bit),
  178. clk->enable_reg);
  179. }
  180. static struct clk_ops mstpcr_clk_ops = {
  181. .enable = mstpcr_clk_enable,
  182. .disable = mstpcr_clk_disable,
  183. .recalc = followparent_recalc,
  184. };
  185. #define MSTPCR0 0xffc80030
  186. #define MSTPCR1 0xffc80034
  187. #define CLK(_name, _id, _parent, _enable_reg, \
  188. _enable_bit, _flags) \
  189. { \
  190. .name = _name, \
  191. .id = _id, \
  192. .parent = _parent, \
  193. .enable_reg = (void __iomem *)_enable_reg, \
  194. .enable_bit = _enable_bit, \
  195. .flags = _flags, \
  196. .ops = &mstpcr_clk_ops, \
  197. }
  198. static struct clk mstpcr_clks[] = {
  199. /* MSTPCR0 */
  200. CLK("scif_fck", 5, &peripheral_clk, MSTPCR0, 29, 0),
  201. CLK("scif_fck", 4, &peripheral_clk, MSTPCR0, 28, 0),
  202. CLK("scif_fck", 3, &peripheral_clk, MSTPCR0, 27, 0),
  203. CLK("scif_fck", 2, &peripheral_clk, MSTPCR0, 26, 0),
  204. CLK("scif_fck", 1, &peripheral_clk, MSTPCR0, 25, 0),
  205. CLK("scif_fck", 0, &peripheral_clk, MSTPCR0, 24, 0),
  206. CLK("ssi_fck", 1, &peripheral_clk, MSTPCR0, 21, 0),
  207. CLK("ssi_fck", 0, &peripheral_clk, MSTPCR0, 20, 0),
  208. CLK("hac_fck", 1, &peripheral_clk, MSTPCR0, 17, 0),
  209. CLK("hac_fck", 0, &peripheral_clk, MSTPCR0, 16, 0),
  210. CLK("mmcif_fck", -1, &peripheral_clk, MSTPCR0, 13, 0),
  211. CLK("flctl_fck", -1, &peripheral_clk, MSTPCR0, 12, 0),
  212. CLK("tmu345_fck", -1, &peripheral_clk, MSTPCR0, 9, 0),
  213. CLK("tmu012_fck", -1, &peripheral_clk, MSTPCR0, 8, 0),
  214. CLK("siof_fck", -1, &peripheral_clk, MSTPCR0, 3, 0),
  215. CLK("hspi_fck", -1, &peripheral_clk, MSTPCR0, 2, 0),
  216. /* MSTPCR1 */
  217. CLK("hudi_fck", -1, NULL, MSTPCR1, 19, 0),
  218. CLK("ubc_fck", -1, NULL, MSTPCR1, 17, 0),
  219. CLK("dmac_11_6_fck", -1, NULL, MSTPCR1, 5, 0),
  220. CLK("dmac_5_0_fck", -1, NULL, MSTPCR1, 4, 0),
  221. CLK("gdta_fck", -1, NULL, MSTPCR1, 0, 0),
  222. };
  223. int __init arch_clk_init(void)
  224. {
  225. int i, ret = 0;
  226. for (i = 0; i < ARRAY_SIZE(clks); i++)
  227. ret |= clk_register(clks[i]);
  228. for (i = 0; i < ARRAY_SIZE(mstpcr_clks); i++)
  229. ret |= clk_register(&mstpcr_clks[i]);
  230. return ret;
  231. }