clock-sh7786.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7786.c
  3. *
  4. * SH7786 support for the clock framework
  5. *
  6. * Copyright (C) 2010 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/clk.h>
  17. #include <asm/clkdev.h>
  18. #include <asm/clock.h>
  19. #include <asm/freq.h>
  20. /*
  21. * Default rate for the root input clock, reset this with clk_set_rate()
  22. * from the platform code.
  23. */
  24. static struct clk extal_clk = {
  25. .name = "extal",
  26. .id = -1,
  27. .rate = 33333333,
  28. };
  29. static unsigned long pll_recalc(struct clk *clk)
  30. {
  31. int multiplier;
  32. /*
  33. * Clock modes 0, 1, and 2 use an x64 multiplier against PLL1,
  34. * while modes 3, 4, and 5 use an x32.
  35. */
  36. multiplier = (sh_mv.mv_mode_pins() & 0xf) < 3 ? 64 : 32;
  37. return clk->parent->rate * multiplier;
  38. }
  39. static struct clk_ops pll_clk_ops = {
  40. .recalc = pll_recalc,
  41. };
  42. static struct clk pll_clk = {
  43. .name = "pll_clk",
  44. .id = -1,
  45. .ops = &pll_clk_ops,
  46. .parent = &extal_clk,
  47. .flags = CLK_ENABLE_ON_INIT,
  48. };
  49. static struct clk *clks[] = {
  50. &extal_clk,
  51. &pll_clk,
  52. };
  53. static unsigned int div2[] = { 1, 2, 4, 6, 8, 12, 16, 18,
  54. 24, 32, 36, 48 };
  55. static struct clk_div_mult_table div4_div_mult_table = {
  56. .divisors = div2,
  57. .nr_divisors = ARRAY_SIZE(div2),
  58. };
  59. static struct clk_div4_table div4_table = {
  60. .div_mult_table = &div4_div_mult_table,
  61. };
  62. enum { DIV4_I, DIV4_SH, DIV4_B, DIV4_DDR, DIV4_DU, DIV4_P, DIV4_NR };
  63. #define DIV4(_str, _bit, _mask, _flags) \
  64. SH_CLK_DIV4(_str, &pll_clk, FRQMR1, _bit, _mask, _flags)
  65. struct clk div4_clks[DIV4_NR] = {
  66. [DIV4_P] = DIV4("peripheral_clk", 0, 0x0b40, 0),
  67. [DIV4_DU] = DIV4("du_clk", 4, 0x0010, 0),
  68. [DIV4_DDR] = DIV4("ddr_clk", 12, 0x0002, CLK_ENABLE_ON_INIT),
  69. [DIV4_B] = DIV4("bus_clk", 16, 0x0360, CLK_ENABLE_ON_INIT),
  70. [DIV4_SH] = DIV4("shyway_clk", 20, 0x0002, CLK_ENABLE_ON_INIT),
  71. [DIV4_I] = DIV4("cpu_clk", 28, 0x0006, CLK_ENABLE_ON_INIT),
  72. };
  73. #define MSTPCR0 0xffc40030
  74. #define MSTPCR1 0xffc40034
  75. static struct clk mstp_clks[] = {
  76. /* MSTPCR0 */
  77. SH_CLK_MSTP32("sci_fck", 5, &div4_clks[DIV4_P], MSTPCR0, 29, 0),
  78. SH_CLK_MSTP32("sci_fck", 4, &div4_clks[DIV4_P], MSTPCR0, 28, 0),
  79. SH_CLK_MSTP32("sci_fck", 3, &div4_clks[DIV4_P], MSTPCR0, 27, 0),
  80. SH_CLK_MSTP32("sci_fck", 2, &div4_clks[DIV4_P], MSTPCR0, 26, 0),
  81. SH_CLK_MSTP32("sci_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 25, 0),
  82. SH_CLK_MSTP32("sci_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 24, 0),
  83. SH_CLK_MSTP32("ssi_fck", 3, &div4_clks[DIV4_P], MSTPCR0, 23, 0),
  84. SH_CLK_MSTP32("ssi_fck", 2, &div4_clks[DIV4_P], MSTPCR0, 22, 0),
  85. SH_CLK_MSTP32("ssi_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 21, 0),
  86. SH_CLK_MSTP32("ssi_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 20, 0),
  87. SH_CLK_MSTP32("hac_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 17, 0),
  88. SH_CLK_MSTP32("hac_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 16, 0),
  89. SH_CLK_MSTP32("i2c_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 15, 0),
  90. SH_CLK_MSTP32("i2c_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 14, 0),
  91. SH_CLK_MSTP32("tmu9_11_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 11, 0),
  92. SH_CLK_MSTP32("tmu678_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 10, 0),
  93. SH_CLK_MSTP32("tmu345_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 9, 0),
  94. SH_CLK_MSTP32("tmu012_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 8, 0),
  95. SH_CLK_MSTP32("sdif_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 5, 0),
  96. SH_CLK_MSTP32("sdif_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 4, 0),
  97. SH_CLK_MSTP32("hspi_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 2, 0),
  98. /* MSTPCR1 */
  99. SH_CLK_MSTP32("usb_fck", -1, NULL, MSTPCR1, 12, 0),
  100. SH_CLK_MSTP32("pcie_fck", 2, NULL, MSTPCR1, 10, 0),
  101. SH_CLK_MSTP32("pcie_fck", 1, NULL, MSTPCR1, 9, 0),
  102. SH_CLK_MSTP32("pcie_fck", 0, NULL, MSTPCR1, 8, 0),
  103. SH_CLK_MSTP32("dmac_11_6_fck", -1, NULL, MSTPCR1, 5, 0),
  104. SH_CLK_MSTP32("dmac_5_0_fck", -1, NULL, MSTPCR1, 4, 0),
  105. SH_CLK_MSTP32("du_fck", -1, NULL, MSTPCR1, 3, 0),
  106. SH_CLK_MSTP32("ether_fck", -1, NULL, MSTPCR1, 2, 0),
  107. };
  108. static struct clk_lookup lookups[] = {
  109. {
  110. /* TMU0 */
  111. .dev_id = "sh_tmu.0",
  112. .con_id = "tmu_fck",
  113. .clk = &mstp_clks[17], /* tmu012_fck */
  114. }, {
  115. /* TMU1 */
  116. .dev_id = "sh_tmu.1",
  117. .con_id = "tmu_fck",
  118. .clk = &mstp_clks[17],
  119. }, {
  120. /* TMU2 */
  121. .dev_id = "sh_tmu.2",
  122. .con_id = "tmu_fck",
  123. .clk = &mstp_clks[17],
  124. }, {
  125. /* TMU3 */
  126. .dev_id = "sh_tmu.3",
  127. .con_id = "tmu_fck",
  128. .clk = &mstp_clks[16], /* tmu345_fck */
  129. }, {
  130. /* TMU4 */
  131. .dev_id = "sh_tmu.4",
  132. .con_id = "tmu_fck",
  133. .clk = &mstp_clks[16],
  134. }, {
  135. /* TMU5 */
  136. .dev_id = "sh_tmu.5",
  137. .con_id = "tmu_fck",
  138. .clk = &mstp_clks[16],
  139. }, {
  140. /* TMU6 */
  141. .dev_id = "sh_tmu.6",
  142. .con_id = "tmu_fck",
  143. .clk = &mstp_clks[15], /* tmu678_fck */
  144. }, {
  145. /* TMU7 */
  146. .dev_id = "sh_tmu.7",
  147. .con_id = "tmu_fck",
  148. .clk = &mstp_clks[15],
  149. }, {
  150. /* TMU8 */
  151. .dev_id = "sh_tmu.8",
  152. .con_id = "tmu_fck",
  153. .clk = &mstp_clks[15],
  154. }, {
  155. /* TMU9 */
  156. .dev_id = "sh_tmu.9",
  157. .con_id = "tmu_fck",
  158. .clk = &mstp_clks[14], /* tmu9_11_fck */
  159. }, {
  160. /* TMU10 */
  161. .dev_id = "sh_tmu.10",
  162. .con_id = "tmu_fck",
  163. .clk = &mstp_clks[14],
  164. }, {
  165. /* TMU11 */
  166. .dev_id = "sh_tmu.11",
  167. .con_id = "tmu_fck",
  168. .clk = &mstp_clks[14],
  169. }
  170. };
  171. int __init arch_clk_init(void)
  172. {
  173. int i, ret = 0;
  174. for (i = 0; i < ARRAY_SIZE(clks); i++)
  175. ret |= clk_register(clks[i]);
  176. for (i = 0; i < ARRAY_SIZE(lookups); i++)
  177. clkdev_add(&lookups[i]);
  178. if (!ret)
  179. ret = sh_clk_div4_register(div4_clks, ARRAY_SIZE(div4_clks),
  180. &div4_table);
  181. if (!ret)
  182. ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
  183. return ret;
  184. }