clock-sh7785.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. #include <cpu/sh7785.h>
  20. static unsigned int div2[] = { 1, 2, 4, 6, 8, 12, 16, 18,
  21. 24, 32, 36, 48 };
  22. static struct clk_div_mult_table cpg_div = {
  23. .divisors = div2,
  24. .nr_divisors = ARRAY_SIZE(div2),
  25. };
  26. struct clk_priv {
  27. unsigned int shift;
  28. /* allowable divisor bitmap */
  29. unsigned long div_bitmap;
  30. /* Supportable frequencies + termination entry */
  31. struct cpufreq_frequency_table freq_table[ARRAY_SIZE(div2)+1];
  32. };
  33. #define FRQMR_CLK_DATA(_name, _shift, _div_bitmap) \
  34. static struct clk_priv _name##_data = { \
  35. .shift = _shift, \
  36. .div_bitmap = _div_bitmap, \
  37. \
  38. .freq_table[0] = { \
  39. .index = 0, \
  40. .frequency = CPUFREQ_TABLE_END, \
  41. }, \
  42. }
  43. FRQMR_CLK_DATA(pfc, 0, 0x0f80);
  44. FRQMR_CLK_DATA(s3fc, 4, 0x0ff0);
  45. FRQMR_CLK_DATA(s2fc, 8, 0x0030);
  46. FRQMR_CLK_DATA(mfc, 12, 0x000c);
  47. FRQMR_CLK_DATA(bfc, 16, 0x0fe0);
  48. FRQMR_CLK_DATA(sfc, 20, 0x000c);
  49. FRQMR_CLK_DATA(ufc, 24, 0x000c);
  50. FRQMR_CLK_DATA(ifc, 28, 0x000e);
  51. static unsigned long frqmr_recalc(struct clk *clk)
  52. {
  53. struct clk_priv *data = clk->priv;
  54. unsigned int idx = (__raw_readl(FRQMR1) >> data->shift) & 0x000f;
  55. clk_rate_table_build(clk, data->freq_table, ARRAY_SIZE(div2),
  56. &cpg_div, &data->div_bitmap);
  57. return data->freq_table[idx].frequency;
  58. }
  59. static long frqmr_round_rate(struct clk *clk, unsigned long rate)
  60. {
  61. struct clk_priv *data = clk->priv;
  62. return clk_rate_table_round(clk, data->freq_table, rate);
  63. }
  64. static struct clk_ops frqmr_clk_ops = {
  65. .recalc = frqmr_recalc,
  66. .round_rate = frqmr_round_rate,
  67. };
  68. static unsigned long pll_recalc(struct clk *clk)
  69. {
  70. int multiplier;
  71. multiplier = test_mode_pin(MODE_PIN_MODE4) ? 36 : 72;
  72. return clk->parent->rate * multiplier;
  73. }
  74. static struct clk_ops pll_clk_ops = {
  75. .recalc = pll_recalc,
  76. };
  77. /*
  78. * Default rate for the root input clock, reset this with clk_set_rate()
  79. * from the platform code.
  80. */
  81. static struct clk extal_clk = {
  82. .name = "extal",
  83. .id = -1,
  84. .rate = 33333333,
  85. };
  86. static struct clk pll_clk = {
  87. .name = "pll_clk",
  88. .id = -1,
  89. .ops = &pll_clk_ops,
  90. .parent = &extal_clk,
  91. .flags = CLK_ENABLE_ON_INIT,
  92. };
  93. static struct clk cpu_clk = {
  94. .name = "cpu_clk", /* Ick */
  95. .id = -1,
  96. .ops = &frqmr_clk_ops,
  97. .parent = &pll_clk,
  98. .flags = CLK_ENABLE_ON_INIT,
  99. .priv = &ifc_data,
  100. };
  101. static struct clk shyway_clk = {
  102. .name = "shyway_clk", /* SHck */
  103. .id = -1,
  104. .ops = &frqmr_clk_ops,
  105. .parent = &pll_clk,
  106. .flags = CLK_ENABLE_ON_INIT,
  107. .priv = &sfc_data,
  108. };
  109. static struct clk peripheral_clk = {
  110. .name = "peripheral_clk", /* Pck */
  111. .id = -1,
  112. .ops = &frqmr_clk_ops,
  113. .parent = &pll_clk,
  114. .flags = CLK_ENABLE_ON_INIT,
  115. .priv = &pfc_data,
  116. };
  117. static struct clk ddr_clk = {
  118. .name = "ddr_clk", /* DDRck */
  119. .id = -1,
  120. .ops = &frqmr_clk_ops,
  121. .parent = &pll_clk,
  122. .flags = CLK_ENABLE_ON_INIT,
  123. .priv = &mfc_data,
  124. };
  125. static struct clk bus_clk = {
  126. .name = "bus_clk", /* Bck */
  127. .id = -1,
  128. .ops = &frqmr_clk_ops,
  129. .parent = &pll_clk,
  130. .flags = CLK_ENABLE_ON_INIT,
  131. .priv = &bfc_data,
  132. };
  133. static struct clk ga_clk = {
  134. .name = "ga_clk", /* GAck */
  135. .id = -1,
  136. .ops = &frqmr_clk_ops,
  137. .parent = &pll_clk,
  138. .priv = &s2fc_data,
  139. };
  140. static struct clk du_clk = {
  141. .name = "du_clk", /* DUck */
  142. .id = -1,
  143. .ops = &frqmr_clk_ops,
  144. .parent = &pll_clk,
  145. .priv = &s3fc_data,
  146. };
  147. static struct clk umem_clk = {
  148. .name = "umem_clk", /* uck */
  149. .id = -1,
  150. .ops = &frqmr_clk_ops,
  151. .parent = &pll_clk,
  152. .flags = CLK_ENABLE_ON_INIT,
  153. .priv = &ufc_data,
  154. };
  155. static struct clk *clks[] = {
  156. &extal_clk,
  157. &pll_clk,
  158. &cpu_clk,
  159. &shyway_clk,
  160. &peripheral_clk,
  161. &ddr_clk,
  162. &bus_clk,
  163. &ga_clk,
  164. &du_clk,
  165. &umem_clk,
  166. };
  167. #define MSTPCR0 0xffc80030
  168. #define MSTPCR1 0xffc80034
  169. static struct clk mstp_clks[] = {
  170. /* MSTPCR0 */
  171. SH_CLK_MSTP32("scif_fck", 5, &peripheral_clk, MSTPCR0, 29, 0),
  172. SH_CLK_MSTP32("scif_fck", 4, &peripheral_clk, MSTPCR0, 28, 0),
  173. SH_CLK_MSTP32("scif_fck", 3, &peripheral_clk, MSTPCR0, 27, 0),
  174. SH_CLK_MSTP32("scif_fck", 2, &peripheral_clk, MSTPCR0, 26, 0),
  175. SH_CLK_MSTP32("scif_fck", 1, &peripheral_clk, MSTPCR0, 25, 0),
  176. SH_CLK_MSTP32("scif_fck", 0, &peripheral_clk, MSTPCR0, 24, 0),
  177. SH_CLK_MSTP32("ssi_fck", 1, &peripheral_clk, MSTPCR0, 21, 0),
  178. SH_CLK_MSTP32("ssi_fck", 0, &peripheral_clk, MSTPCR0, 20, 0),
  179. SH_CLK_MSTP32("hac_fck", 1, &peripheral_clk, MSTPCR0, 17, 0),
  180. SH_CLK_MSTP32("hac_fck", 0, &peripheral_clk, MSTPCR0, 16, 0),
  181. SH_CLK_MSTP32("mmcif_fck", -1, &peripheral_clk, MSTPCR0, 13, 0),
  182. SH_CLK_MSTP32("flctl_fck", -1, &peripheral_clk, MSTPCR0, 12, 0),
  183. SH_CLK_MSTP32("tmu345_fck", -1, &peripheral_clk, MSTPCR0, 9, 0),
  184. SH_CLK_MSTP32("tmu012_fck", -1, &peripheral_clk, MSTPCR0, 8, 0),
  185. SH_CLK_MSTP32("siof_fck", -1, &peripheral_clk, MSTPCR0, 3, 0),
  186. SH_CLK_MSTP32("hspi_fck", -1, &peripheral_clk, MSTPCR0, 2, 0),
  187. /* MSTPCR1 */
  188. SH_CLK_MSTP32("hudi_fck", -1, NULL, MSTPCR1, 19, 0),
  189. SH_CLK_MSTP32("ubc_fck", -1, NULL, MSTPCR1, 17, 0),
  190. SH_CLK_MSTP32("dmac_11_6_fck", -1, NULL, MSTPCR1, 5, 0),
  191. SH_CLK_MSTP32("dmac_5_0_fck", -1, NULL, MSTPCR1, 4, 0),
  192. SH_CLK_MSTP32("gdta_fck", -1, NULL, MSTPCR1, 0, 0),
  193. };
  194. int __init arch_clk_init(void)
  195. {
  196. int i, ret = 0;
  197. for (i = 0; i < ARRAY_SIZE(clks); i++)
  198. ret |= clk_register(clks[i]);
  199. if (!ret)
  200. ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
  201. return ret;
  202. }