clock-shx3.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 sh_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. static struct clk_lookup lookups[] = {
  88. /* main clocks */
  89. CLKDEV_CON_ID("extal", &extal_clk),
  90. CLKDEV_CON_ID("pll_clk", &pll_clk),
  91. /* DIV4 clocks */
  92. CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
  93. CLKDEV_CON_ID("shywaya_clk", &div4_clks[DIV4_SHA]),
  94. CLKDEV_CON_ID("ddr_clk", &div4_clks[DIV4_DDR]),
  95. CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
  96. CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
  97. CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
  98. /* MSTP32 clocks */
  99. CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[MSTP027]),
  100. CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[MSTP026]),
  101. CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[MSTP025]),
  102. CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[MSTP024]),
  103. CLKDEV_CON_ID("h8ex_fck", &mstp_clks[MSTP003]),
  104. CLKDEV_CON_ID("csm_fck", &mstp_clks[MSTP002]),
  105. CLKDEV_CON_ID("fe1_fck", &mstp_clks[MSTP001]),
  106. CLKDEV_CON_ID("fe0_fck", &mstp_clks[MSTP000]),
  107. CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[MSTP008]),
  108. CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[MSTP009]),
  109. CLKDEV_CON_ID("hudi_fck", &mstp_clks[MSTP119]),
  110. CLKDEV_CON_ID("dmac_11_6_fck", &mstp_clks[MSTP105]),
  111. CLKDEV_CON_ID("dmac_5_0_fck", &mstp_clks[MSTP104]),
  112. };
  113. int __init arch_clk_init(void)
  114. {
  115. int i, ret = 0;
  116. for (i = 0; i < ARRAY_SIZE(clks); i++)
  117. ret |= clk_register(clks[i]);
  118. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  119. if (!ret)
  120. ret = sh_clk_div4_register(div4_clks, ARRAY_SIZE(div4_clks),
  121. &div4_table);
  122. if (!ret)
  123. ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);
  124. return ret;
  125. }