clock-shx3.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * arch/sh/kernel/cpu/sh4/clock-shx3.c
  3. *
  4. * SH-X3 support for the clock framework
  5. *
  6. * Copyright (C) 2006-2007 Renesas Technology Corp.
  7. * Copyright (C) 2006-2007 Renesas Solutions Corp.
  8. * Copyright (C) 2006-2010 Paul Mundt
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file "COPYING" in the main directory of this archive
  12. * for more details.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/io.h>
  17. #include <linux/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. .rate = 16666666,
  26. };
  27. static unsigned long pll_recalc(struct clk *clk)
  28. {
  29. /* PLL1 has a fixed x72 multiplier. */
  30. return clk->parent->rate * 72;
  31. }
  32. static struct clk_ops pll_clk_ops = {
  33. .recalc = pll_recalc,
  34. };
  35. static struct clk pll_clk = {
  36. .ops = &pll_clk_ops,
  37. .parent = &extal_clk,
  38. .flags = CLK_ENABLE_ON_INIT,
  39. };
  40. static struct clk *clks[] = {
  41. &extal_clk,
  42. &pll_clk,
  43. };
  44. static unsigned int div2[] = { 1, 2, 4, 6, 8, 12, 16, 18,
  45. 24, 32, 36, 48 };
  46. static struct clk_div_mult_table div4_div_mult_table = {
  47. .divisors = div2,
  48. .nr_divisors = ARRAY_SIZE(div2),
  49. };
  50. static struct clk_div4_table div4_table = {
  51. .div_mult_table = &div4_div_mult_table,
  52. };
  53. enum { DIV4_I, DIV4_SH, DIV4_B, DIV4_DDR, DIV4_SHA, DIV4_P, DIV4_NR };
  54. #define DIV4(_bit, _mask, _flags) \
  55. SH_CLK_DIV4(&pll_clk, FRQMR1, _bit, _mask, _flags)
  56. struct clk div4_clks[DIV4_NR] = {
  57. [DIV4_P] = DIV4(0, 0x0f80, 0),
  58. [DIV4_SHA] = DIV4(4, 0x0ff0, 0),
  59. [DIV4_DDR] = DIV4(12, 0x000c, CLK_ENABLE_ON_INIT),
  60. [DIV4_B] = DIV4(16, 0x0fe0, CLK_ENABLE_ON_INIT),
  61. [DIV4_SH] = DIV4(20, 0x000c, CLK_ENABLE_ON_INIT),
  62. [DIV4_I] = DIV4(28, 0x000e, CLK_ENABLE_ON_INIT),
  63. };
  64. #define MSTPCR0 0xffc00030
  65. #define MSTPCR1 0xffc00034
  66. enum { MSTP027, MSTP026, MSTP025, MSTP024,
  67. MSTP009, MSTP008, MSTP003, MSTP002,
  68. MSTP001, MSTP000, MSTP119, MSTP105,
  69. MSTP104, MSTP_NR };
  70. static struct clk mstp_clks[MSTP_NR] = {
  71. /* MSTPCR0 */
  72. [MSTP027] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 27, 0),
  73. [MSTP026] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 26, 0),
  74. [MSTP025] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 25, 0),
  75. [MSTP024] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 24, 0),
  76. [MSTP009] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 9, 0),
  77. [MSTP008] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 8, 0),
  78. [MSTP003] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 3, 0),
  79. [MSTP002] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 2, 0),
  80. [MSTP001] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 1, 0),
  81. [MSTP000] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 0, 0),
  82. /* MSTPCR1 */
  83. [MSTP119] = SH_CLK_MSTP32(NULL, MSTPCR1, 19, 0),
  84. [MSTP105] = SH_CLK_MSTP32(NULL, MSTPCR1, 5, 0),
  85. [MSTP104] = SH_CLK_MSTP32(NULL, MSTPCR1, 4, 0),
  86. };
  87. #define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
  88. static struct clk_lookup lookups[] = {
  89. /* main clocks */
  90. CLKDEV_CON_ID("extal", &extal_clk),
  91. CLKDEV_CON_ID("pll_clk", &pll_clk),
  92. /* DIV4 clocks */
  93. CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
  94. CLKDEV_CON_ID("shywaya_clk", &div4_clks[DIV4_SHA]),
  95. CLKDEV_CON_ID("ddr_clk", &div4_clks[DIV4_DDR]),
  96. CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
  97. CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
  98. CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
  99. /* MSTP32 clocks */
  100. {
  101. /* SCIF3 */
  102. .dev_id = "sh-sci.3",
  103. .con_id = "sci_fck",
  104. .clk = &mstp_clks[MSTP027],
  105. }, {
  106. /* SCIF2 */
  107. .dev_id = "sh-sci.2",
  108. .con_id = "sci_fck",
  109. .clk = &mstp_clks[MSTP026],
  110. }, {
  111. /* SCIF1 */
  112. .dev_id = "sh-sci.1",
  113. .con_id = "sci_fck",
  114. .clk = &mstp_clks[MSTP025],
  115. }, {
  116. /* SCIF0 */
  117. .dev_id = "sh-sci.0",
  118. .con_id = "sci_fck",
  119. .clk = &mstp_clks[MSTP024],
  120. },
  121. CLKDEV_CON_ID("h8ex_fck", &mstp_clks[MSTP003]),
  122. CLKDEV_CON_ID("csm_fck", &mstp_clks[MSTP002]),
  123. CLKDEV_CON_ID("fe1_fck", &mstp_clks[MSTP001]),
  124. CLKDEV_CON_ID("fe0_fck", &mstp_clks[MSTP000]),
  125. {
  126. /* TMU0 */
  127. .dev_id = "sh_tmu.0",
  128. .con_id = "tmu_fck",
  129. .clk = &mstp_clks[MSTP008],
  130. }, {
  131. /* TMU1 */
  132. .dev_id = "sh_tmu.1",
  133. .con_id = "tmu_fck",
  134. .clk = &mstp_clks[MSTP008],
  135. }, {
  136. /* TMU2 */
  137. .dev_id = "sh_tmu.2",
  138. .con_id = "tmu_fck",
  139. .clk = &mstp_clks[MSTP008],
  140. }, {
  141. /* TMU3 */
  142. .dev_id = "sh_tmu.3",
  143. .con_id = "tmu_fck",
  144. .clk = &mstp_clks[MSTP009],
  145. }, {
  146. /* TMU4 */
  147. .dev_id = "sh_tmu.4",
  148. .con_id = "tmu_fck",
  149. .clk = &mstp_clks[MSTP009],
  150. }, {
  151. /* TMU5 */
  152. .dev_id = "sh_tmu.5",
  153. .con_id = "tmu_fck",
  154. .clk = &mstp_clks[MSTP009],
  155. },
  156. CLKDEV_CON_ID("hudi_fck", &mstp_clks[MSTP119]),
  157. CLKDEV_CON_ID("dmac_11_6_fck", &mstp_clks[MSTP105]),
  158. CLKDEV_CON_ID("dmac_5_0_fck", &mstp_clks[MSTP104]),
  159. };
  160. int __init arch_clk_init(void)
  161. {
  162. int i, ret = 0;
  163. for (i = 0; i < ARRAY_SIZE(clks); i++)
  164. ret |= clk_register(clks[i]);
  165. for (i = 0; i < ARRAY_SIZE(lookups); i++)
  166. clkdev_add(&lookups[i]);
  167. if (!ret)
  168. ret = sh_clk_div4_register(div4_clks, ARRAY_SIZE(div4_clks),
  169. &div4_table);
  170. if (!ret)
  171. ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
  172. return ret;
  173. }