clock-sh7734.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh4a/clock-sh7734.c
  4. *
  5. * Clock framework for SH7734
  6. *
  7. * Copyright (C) 2011, 2012 Nobuhiro Iwamatsu <[email protected]>
  8. * Copyright (C) 2011, 2012 Renesas Solutions Corp.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/io.h>
  13. #include <linux/clkdev.h>
  14. #include <linux/delay.h>
  15. #include <asm/clock.h>
  16. #include <asm/freq.h>
  17. static struct clk extal_clk = {
  18. .rate = 33333333,
  19. };
  20. #define MODEMR (0xFFCC0020)
  21. #define MODEMR_MASK (0x6)
  22. #define MODEMR_533MHZ (0x2)
  23. static unsigned long pll_recalc(struct clk *clk)
  24. {
  25. int mode = 12;
  26. u32 r = __raw_readl(MODEMR);
  27. if ((r & MODEMR_MASK) & MODEMR_533MHZ)
  28. mode = 16;
  29. return clk->parent->rate * mode;
  30. }
  31. static struct sh_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 *main_clks[] = {
  40. &extal_clk,
  41. &pll_clk,
  42. };
  43. static int multipliers[] = { 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  44. static int divisors[] = { 1, 3, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24 };
  45. static struct clk_div_mult_table div4_div_mult_table = {
  46. .divisors = divisors,
  47. .nr_divisors = ARRAY_SIZE(divisors),
  48. .multipliers = multipliers,
  49. .nr_multipliers = ARRAY_SIZE(multipliers),
  50. };
  51. static struct clk_div4_table div4_table = {
  52. .div_mult_table = &div4_div_mult_table,
  53. };
  54. enum { DIV4_I, DIV4_S, DIV4_B, DIV4_M, DIV4_S1, DIV4_P, DIV4_NR };
  55. #define DIV4(_reg, _bit, _mask, _flags) \
  56. SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)
  57. struct clk div4_clks[DIV4_NR] = {
  58. [DIV4_I] = DIV4(FRQMR1, 28, 0x0003, CLK_ENABLE_ON_INIT),
  59. [DIV4_S] = DIV4(FRQMR1, 20, 0x000C, CLK_ENABLE_ON_INIT),
  60. [DIV4_B] = DIV4(FRQMR1, 16, 0x0140, CLK_ENABLE_ON_INIT),
  61. [DIV4_M] = DIV4(FRQMR1, 12, 0x0004, CLK_ENABLE_ON_INIT),
  62. [DIV4_S1] = DIV4(FRQMR1, 4, 0x0030, CLK_ENABLE_ON_INIT),
  63. [DIV4_P] = DIV4(FRQMR1, 0, 0x0140, CLK_ENABLE_ON_INIT),
  64. };
  65. #define MSTPCR0 0xFFC80030
  66. #define MSTPCR1 0xFFC80034
  67. #define MSTPCR3 0xFFC8003C
  68. enum {
  69. MSTP030, MSTP029, /* IIC */
  70. MSTP026, MSTP025, MSTP024, /* SCIF */
  71. MSTP023,
  72. MSTP022, MSTP021,
  73. MSTP019, /* HSCIF */
  74. MSTP016, MSTP015, MSTP014, /* TMU / TIMER */
  75. MSTP012, MSTP011, MSTP010, MSTP009, MSTP008, /* SSI */
  76. MSTP007, /* HSPI */
  77. MSTP115, /* ADMAC */
  78. MSTP114, /* GETHER */
  79. MSTP111, /* DMAC */
  80. MSTP109, /* VIDEOIN1 */
  81. MSTP108, /* VIDEOIN0 */
  82. MSTP107, /* RGPVBG */
  83. MSTP106, /* 2DG */
  84. MSTP103, /* VIEW */
  85. MSTP100, /* USB */
  86. MSTP331, /* MMC */
  87. MSTP330, /* MIMLB */
  88. MSTP323, /* SDHI0 */
  89. MSTP322, /* SDHI1 */
  90. MSTP321, /* SDHI2 */
  91. MSTP320, /* RQSPI */
  92. MSTP319, /* SRC0 */
  93. MSTP318, /* SRC1 */
  94. MSTP317, /* RSPI */
  95. MSTP316, /* RCAN0 */
  96. MSTP315, /* RCAN1 */
  97. MSTP314, /* FLTCL */
  98. MSTP313, /* ADC */
  99. MSTP312, /* MTU */
  100. MSTP304, /* IE-BUS */
  101. MSTP303, /* RTC */
  102. MSTP302, /* HIF */
  103. MSTP301, /* STIF0 */
  104. MSTP300, /* STIF1 */
  105. MSTP_NR };
  106. static struct clk mstp_clks[MSTP_NR] = {
  107. /* MSTPCR0 */
  108. [MSTP030] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 30, 0),
  109. [MSTP029] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 29, 0),
  110. [MSTP026] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 26, 0),
  111. [MSTP025] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 25, 0),
  112. [MSTP024] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 24, 0),
  113. [MSTP023] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 23, 0),
  114. [MSTP022] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 22, 0),
  115. [MSTP021] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 21, 0),
  116. [MSTP019] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 19, 0),
  117. [MSTP016] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 16, 0),
  118. [MSTP015] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 15, 0),
  119. [MSTP014] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 14, 0),
  120. [MSTP012] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 12, 0),
  121. [MSTP011] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 11, 0),
  122. [MSTP010] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 10, 0),
  123. [MSTP009] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 9, 0),
  124. [MSTP008] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 8, 0),
  125. [MSTP007] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 7, 0),
  126. /* MSTPCR1 */
  127. [MSTP115] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 15, 0),
  128. [MSTP114] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 14, 0),
  129. [MSTP111] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 11, 0),
  130. [MSTP109] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 9, 0),
  131. [MSTP108] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 8, 0),
  132. [MSTP107] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 7, 0),
  133. [MSTP106] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 6, 0),
  134. [MSTP103] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 3, 0),
  135. [MSTP100] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 0, 0),
  136. /* MSTPCR3 */
  137. [MSTP331] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 31, 0),
  138. [MSTP330] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 30, 0),
  139. [MSTP323] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 23, 0),
  140. [MSTP322] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 22, 0),
  141. [MSTP321] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 21, 0),
  142. [MSTP320] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 20, 0),
  143. [MSTP319] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 19, 0),
  144. [MSTP318] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 18, 0),
  145. [MSTP317] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 17, 0),
  146. [MSTP316] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 16, 0),
  147. [MSTP315] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 15, 0),
  148. [MSTP314] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 14, 0),
  149. [MSTP313] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 13, 0),
  150. [MSTP312] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 12, 0),
  151. [MSTP304] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 4, 0),
  152. [MSTP303] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 3, 0),
  153. [MSTP302] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 2, 0),
  154. [MSTP301] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 1, 0),
  155. [MSTP300] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 0, 0),
  156. };
  157. static struct clk_lookup lookups[] = {
  158. /* main clocks */
  159. CLKDEV_CON_ID("extal", &extal_clk),
  160. CLKDEV_CON_ID("pll_clk", &pll_clk),
  161. /* clocks */
  162. CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
  163. CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_S]),
  164. CLKDEV_CON_ID("ddr_clk", &div4_clks[DIV4_M]),
  165. CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
  166. CLKDEV_CON_ID("shyway_clk1", &div4_clks[DIV4_S1]),
  167. CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
  168. /* MSTP32 clocks */
  169. CLKDEV_DEV_ID("i2c-sh7734.0", &mstp_clks[MSTP030]),
  170. CLKDEV_DEV_ID("i2c-sh7734.1", &mstp_clks[MSTP029]),
  171. CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP026]),
  172. CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]),
  173. CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP024]),
  174. CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP023]),
  175. CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP022]),
  176. CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP021]),
  177. CLKDEV_CON_ID("hscif", &mstp_clks[MSTP019]),
  178. CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[MSTP016]),
  179. CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[MSTP015]),
  180. CLKDEV_ICK_ID("fck", "sh-tmu.2", &mstp_clks[MSTP014]),
  181. CLKDEV_CON_ID("ssi0", &mstp_clks[MSTP012]),
  182. CLKDEV_CON_ID("ssi1", &mstp_clks[MSTP011]),
  183. CLKDEV_CON_ID("ssi2", &mstp_clks[MSTP010]),
  184. CLKDEV_CON_ID("ssi3", &mstp_clks[MSTP009]),
  185. CLKDEV_CON_ID("sss", &mstp_clks[MSTP008]),
  186. CLKDEV_CON_ID("hspi", &mstp_clks[MSTP007]),
  187. CLKDEV_CON_ID("usb_fck", &mstp_clks[MSTP100]),
  188. CLKDEV_CON_ID("videoin0", &mstp_clks[MSTP109]),
  189. CLKDEV_CON_ID("videoin1", &mstp_clks[MSTP108]),
  190. CLKDEV_CON_ID("rgpvg", &mstp_clks[MSTP107]),
  191. CLKDEV_CON_ID("2dg", &mstp_clks[MSTP106]),
  192. CLKDEV_CON_ID("view", &mstp_clks[MSTP103]),
  193. CLKDEV_CON_ID("mmc0", &mstp_clks[MSTP331]),
  194. CLKDEV_CON_ID("mimlb0", &mstp_clks[MSTP330]),
  195. CLKDEV_CON_ID("sdhi0", &mstp_clks[MSTP323]),
  196. CLKDEV_CON_ID("sdhi1", &mstp_clks[MSTP322]),
  197. CLKDEV_CON_ID("sdhi2", &mstp_clks[MSTP321]),
  198. CLKDEV_CON_ID("rqspi0", &mstp_clks[MSTP320]),
  199. CLKDEV_CON_ID("src0", &mstp_clks[MSTP319]),
  200. CLKDEV_CON_ID("src1", &mstp_clks[MSTP318]),
  201. CLKDEV_CON_ID("rsp0", &mstp_clks[MSTP317]),
  202. CLKDEV_CON_ID("rcan0", &mstp_clks[MSTP316]),
  203. CLKDEV_CON_ID("rcan1", &mstp_clks[MSTP315]),
  204. CLKDEV_CON_ID("fltcl0", &mstp_clks[MSTP314]),
  205. CLKDEV_CON_ID("adc0", &mstp_clks[MSTP313]),
  206. CLKDEV_CON_ID("mtu0", &mstp_clks[MSTP312]),
  207. CLKDEV_CON_ID("iebus0", &mstp_clks[MSTP304]),
  208. CLKDEV_DEV_ID("sh7734-gether.0", &mstp_clks[MSTP114]),
  209. CLKDEV_CON_ID("rtc0", &mstp_clks[MSTP303]),
  210. CLKDEV_CON_ID("hif0", &mstp_clks[MSTP302]),
  211. CLKDEV_CON_ID("stif0", &mstp_clks[MSTP301]),
  212. CLKDEV_CON_ID("stif1", &mstp_clks[MSTP300]),
  213. };
  214. int __init arch_clk_init(void)
  215. {
  216. int i, ret = 0;
  217. for (i = 0; i < ARRAY_SIZE(main_clks); i++)
  218. ret |= clk_register(main_clks[i]);
  219. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  220. if (!ret)
  221. ret = sh_clk_div4_register(div4_clks, ARRAY_SIZE(div4_clks),
  222. &div4_table);
  223. if (!ret)
  224. ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);
  225. return ret;
  226. }