clock-sh7757.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * arch/sh/kernel/cpu/sh4/clock-sh7757.c
  3. *
  4. * SH7757 support for the clock framework
  5. *
  6. * Copyright (C) 2009-2010 Renesas Solutions Corp.
  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/io.h>
  15. #include <linux/clkdev.h>
  16. #include <asm/clock.h>
  17. #include <asm/freq.h>
  18. /*
  19. * Default rate for the root input clock, reset this with clk_set_rate()
  20. * from the platform code.
  21. */
  22. static struct clk extal_clk = {
  23. .rate = 48000000,
  24. };
  25. static unsigned long pll_recalc(struct clk *clk)
  26. {
  27. int multiplier;
  28. multiplier = test_mode_pin(MODE_PIN0) ? 24 : 16;
  29. return clk->parent->rate * multiplier;
  30. }
  31. static struct clk_ops pll_clk_ops = {
  32. .recalc = pll_recalc,
  33. };
  34. static struct clk pll_clk = {
  35. .ops = &pll_clk_ops,
  36. .parent = &extal_clk,
  37. .flags = CLK_ENABLE_ON_INIT,
  38. };
  39. static struct clk *clks[] = {
  40. &extal_clk,
  41. &pll_clk,
  42. };
  43. static unsigned int div2[] = { 1, 1, 2, 1, 1, 4, 1, 6,
  44. 1, 1, 1, 16, 1, 24, 1, 1 };
  45. static struct clk_div_mult_table div4_div_mult_table = {
  46. .divisors = div2,
  47. .nr_divisors = ARRAY_SIZE(div2),
  48. };
  49. static struct clk_div4_table div4_table = {
  50. .div_mult_table = &div4_div_mult_table,
  51. };
  52. enum { DIV4_I, DIV4_SH, DIV4_P, DIV4_NR };
  53. #define DIV4(_bit, _mask, _flags) \
  54. SH_CLK_DIV4(&pll_clk, FRQCR, _bit, _mask, _flags)
  55. struct clk div4_clks[DIV4_NR] = {
  56. /*
  57. * P clock is always enable, because some P clock modules is used
  58. * by Host PC.
  59. */
  60. [DIV4_P] = DIV4(0, 0x2800, CLK_ENABLE_ON_INIT),
  61. [DIV4_SH] = DIV4(12, 0x00a0, CLK_ENABLE_ON_INIT),
  62. [DIV4_I] = DIV4(20, 0x0004, CLK_ENABLE_ON_INIT),
  63. };
  64. #define MSTPCR0 0xffc80030
  65. #define MSTPCR1 0xffc80034
  66. #define MSTPCR2 0xffc10028
  67. enum { MSTP004, MSTP000, MSTP114, MSTP113, MSTP112,
  68. MSTP111, MSTP110, MSTP103, MSTP102, MSTP220,
  69. MSTP_NR };
  70. static struct clk mstp_clks[MSTP_NR] = {
  71. /* MSTPCR0 */
  72. [MSTP004] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 4, 0),
  73. [MSTP000] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 0, 0),
  74. /* MSTPCR1 */
  75. [MSTP114] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 14, 0),
  76. [MSTP113] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 13, 0),
  77. [MSTP112] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 12, 0),
  78. [MSTP111] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 11, 0),
  79. [MSTP110] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 10, 0),
  80. [MSTP103] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 3, 0),
  81. [MSTP102] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 2, 0),
  82. /* MSTPCR2 */
  83. [MSTP220] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR2, 20, 0),
  84. };
  85. #define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
  86. static struct clk_lookup lookups[] = {
  87. /* main clocks */
  88. CLKDEV_CON_ID("extal", &extal_clk),
  89. CLKDEV_CON_ID("pll_clk", &pll_clk),
  90. /* DIV4 clocks */
  91. CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
  92. CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
  93. CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
  94. /* MSTP32 clocks */
  95. CLKDEV_CON_ID("sdhi0", &mstp_clks[MSTP004]),
  96. CLKDEV_CON_ID("riic", &mstp_clks[MSTP000]),
  97. {
  98. /* TMU0 */
  99. .dev_id = "sh_tmu.0",
  100. .con_id = "tmu_fck",
  101. .clk = &mstp_clks[MSTP113],
  102. }, {
  103. /* TMU1 */
  104. .dev_id = "sh_tmu.1",
  105. .con_id = "tmu_fck",
  106. .clk = &mstp_clks[MSTP114],
  107. },
  108. {
  109. /* SCIF4 (But, ID is 2) */
  110. .dev_id = "sh-sci.2",
  111. .con_id = "sci_fck",
  112. .clk = &mstp_clks[MSTP112],
  113. }, {
  114. /* SCIF3 */
  115. .dev_id = "sh-sci.1",
  116. .con_id = "sci_fck",
  117. .clk = &mstp_clks[MSTP111],
  118. }, {
  119. /* SCIF2 */
  120. .dev_id = "sh-sci.0",
  121. .con_id = "sci_fck",
  122. .clk = &mstp_clks[MSTP110],
  123. },
  124. CLKDEV_CON_ID("usb0", &mstp_clks[MSTP102]),
  125. CLKDEV_CON_ID("mmc0", &mstp_clks[MSTP220]),
  126. };
  127. int __init arch_clk_init(void)
  128. {
  129. int i, ret = 0;
  130. for (i = 0; i < ARRAY_SIZE(clks); i++)
  131. ret |= clk_register(clks[i]);
  132. for (i = 0; i < ARRAY_SIZE(lookups); i++)
  133. clkdev_add(&lookups[i]);
  134. if (!ret)
  135. ret = sh_clk_div4_register(div4_clks, ARRAY_SIZE(div4_clks),
  136. &div4_table);
  137. if (!ret)
  138. ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
  139. return ret;
  140. }