clock-sh7734.c 8.9 KB

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