clock-sh7264.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh2a/clock-sh7264.c
  4. *
  5. * SH7264 clock framework support
  6. *
  7. * Copyright (C) 2012 Phil Edworthy
  8. */
  9. #include <linux/init.h>
  10. #include <linux/kernel.h>
  11. #include <linux/io.h>
  12. #include <linux/clkdev.h>
  13. #include <asm/clock.h>
  14. /* SH7264 registers */
  15. #define FRQCR 0xfffe0010
  16. #define STBCR3 0xfffe0408
  17. #define STBCR4 0xfffe040c
  18. #define STBCR5 0xfffe0410
  19. #define STBCR6 0xfffe0414
  20. #define STBCR7 0xfffe0418
  21. #define STBCR8 0xfffe041c
  22. static const unsigned int pll1rate[] = {8, 12};
  23. static unsigned int pll1_div;
  24. /* Fixed 32 KHz root clock for RTC */
  25. static struct clk r_clk = {
  26. .rate = 32768,
  27. };
  28. /*
  29. * Default rate for the root input clock, reset this with clk_set_rate()
  30. * from the platform code.
  31. */
  32. static struct clk extal_clk = {
  33. .rate = 18000000,
  34. };
  35. static unsigned long pll_recalc(struct clk *clk)
  36. {
  37. unsigned long rate = clk->parent->rate / pll1_div;
  38. return rate * pll1rate[(__raw_readw(FRQCR) >> 8) & 1];
  39. }
  40. static struct sh_clk_ops pll_clk_ops = {
  41. .recalc = pll_recalc,
  42. };
  43. static struct clk pll_clk = {
  44. .ops = &pll_clk_ops,
  45. .parent = &extal_clk,
  46. .flags = CLK_ENABLE_ON_INIT,
  47. };
  48. struct clk *main_clks[] = {
  49. &r_clk,
  50. &extal_clk,
  51. &pll_clk,
  52. };
  53. static int div2[] = { 1, 2, 3, 4, 6, 8, 12 };
  54. static struct clk_div_mult_table div4_div_mult_table = {
  55. .divisors = div2,
  56. .nr_divisors = ARRAY_SIZE(div2),
  57. };
  58. static struct clk_div4_table div4_table = {
  59. .div_mult_table = &div4_div_mult_table,
  60. };
  61. enum { DIV4_I, DIV4_P,
  62. DIV4_NR };
  63. #define DIV4(_reg, _bit, _mask, _flags) \
  64. SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)
  65. /* The mask field specifies the div2 entries that are valid */
  66. struct clk div4_clks[DIV4_NR] = {
  67. [DIV4_I] = DIV4(FRQCR, 4, 0x7, CLK_ENABLE_REG_16BIT
  68. | CLK_ENABLE_ON_INIT),
  69. [DIV4_P] = DIV4(FRQCR, 0, 0x78, CLK_ENABLE_REG_16BIT),
  70. };
  71. enum { MSTP77, MSTP74, MSTP72,
  72. MSTP60,
  73. MSTP35, MSTP34, MSTP33, MSTP32, MSTP30,
  74. MSTP_NR };
  75. static struct clk mstp_clks[MSTP_NR] = {
  76. [MSTP77] = SH_CLK_MSTP8(&div4_clks[DIV4_P], STBCR7, 7, 0), /* SCIF */
  77. [MSTP74] = SH_CLK_MSTP8(&div4_clks[DIV4_P], STBCR7, 4, 0), /* VDC */
  78. [MSTP72] = SH_CLK_MSTP8(&div4_clks[DIV4_P], STBCR7, 2, 0), /* CMT */
  79. [MSTP60] = SH_CLK_MSTP8(&div4_clks[DIV4_P], STBCR6, 0, 0), /* USB */
  80. [MSTP35] = SH_CLK_MSTP8(&div4_clks[DIV4_P], STBCR3, 6, 0), /* MTU2 */
  81. [MSTP34] = SH_CLK_MSTP8(&div4_clks[DIV4_P], STBCR3, 4, 0), /* SDHI0 */
  82. [MSTP33] = SH_CLK_MSTP8(&div4_clks[DIV4_P], STBCR3, 3, 0), /* SDHI1 */
  83. [MSTP32] = SH_CLK_MSTP8(&div4_clks[DIV4_P], STBCR3, 2, 0), /* ADC */
  84. [MSTP30] = SH_CLK_MSTP8(&r_clk, STBCR3, 0, 0), /* RTC */
  85. };
  86. static struct clk_lookup lookups[] = {
  87. /* main clocks */
  88. CLKDEV_CON_ID("rclk", &r_clk),
  89. CLKDEV_CON_ID("extal", &extal_clk),
  90. CLKDEV_CON_ID("pll_clk", &pll_clk),
  91. /* DIV4 clocks */
  92. CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
  93. CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
  94. /* MSTP clocks */
  95. CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP77]),
  96. CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP77]),
  97. CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP77]),
  98. CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP77]),
  99. CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP77]),
  100. CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP77]),
  101. CLKDEV_ICK_ID("fck", "sh-sci.6", &mstp_clks[MSTP77]),
  102. CLKDEV_ICK_ID("fck", "sh-sci.7", &mstp_clks[MSTP77]),
  103. CLKDEV_CON_ID("vdc3", &mstp_clks[MSTP74]),
  104. CLKDEV_ICK_ID("fck", "sh-cmt-16.0", &mstp_clks[MSTP72]),
  105. CLKDEV_CON_ID("usb0", &mstp_clks[MSTP60]),
  106. CLKDEV_ICK_ID("fck", "sh-mtu2", &mstp_clks[MSTP35]),
  107. CLKDEV_CON_ID("sdhi0", &mstp_clks[MSTP34]),
  108. CLKDEV_CON_ID("sdhi1", &mstp_clks[MSTP33]),
  109. CLKDEV_CON_ID("adc0", &mstp_clks[MSTP32]),
  110. CLKDEV_CON_ID("rtc0", &mstp_clks[MSTP30]),
  111. };
  112. int __init arch_clk_init(void)
  113. {
  114. int k, ret = 0;
  115. if (test_mode_pin(MODE_PIN0)) {
  116. if (test_mode_pin(MODE_PIN1))
  117. pll1_div = 3;
  118. else
  119. pll1_div = 4;
  120. } else
  121. pll1_div = 1;
  122. for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
  123. ret = clk_register(main_clks[k]);
  124. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  125. if (!ret)
  126. ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
  127. if (!ret)
  128. ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);
  129. return ret;
  130. }