clock-sh7757.c 4.1 KB

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