clock-sh7366.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh4a/clock-sh7366.c
  4. *
  5. * SH7366 clock framework support
  6. *
  7. * Copyright (C) 2009 Magnus Damm
  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. /* SH7366 registers */
  15. #define FRQCR 0xa4150000
  16. #define VCLKCR 0xa4150004
  17. #define SCLKACR 0xa4150008
  18. #define SCLKBCR 0xa415000c
  19. #define PLLCR 0xa4150024
  20. #define MSTPCR0 0xa4150030
  21. #define MSTPCR1 0xa4150034
  22. #define MSTPCR2 0xa4150038
  23. #define DLLFRQ 0xa4150050
  24. /* Fixed 32 KHz root clock for RTC and Power Management purposes */
  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. struct clk extal_clk = {
  33. .rate = 33333333,
  34. };
  35. /* The dll block multiplies the 32khz r_clk, may be used instead of extal */
  36. static unsigned long dll_recalc(struct clk *clk)
  37. {
  38. unsigned long mult;
  39. if (__raw_readl(PLLCR) & 0x1000)
  40. mult = __raw_readl(DLLFRQ);
  41. else
  42. mult = 0;
  43. return clk->parent->rate * mult;
  44. }
  45. static struct sh_clk_ops dll_clk_ops = {
  46. .recalc = dll_recalc,
  47. };
  48. static struct clk dll_clk = {
  49. .ops = &dll_clk_ops,
  50. .parent = &r_clk,
  51. .flags = CLK_ENABLE_ON_INIT,
  52. };
  53. static unsigned long pll_recalc(struct clk *clk)
  54. {
  55. unsigned long mult = 1;
  56. unsigned long div = 1;
  57. if (__raw_readl(PLLCR) & 0x4000)
  58. mult = (((__raw_readl(FRQCR) >> 24) & 0x1f) + 1);
  59. else
  60. div = 2;
  61. return (clk->parent->rate * mult) / div;
  62. }
  63. static struct sh_clk_ops pll_clk_ops = {
  64. .recalc = pll_recalc,
  65. };
  66. static struct clk pll_clk = {
  67. .ops = &pll_clk_ops,
  68. .flags = CLK_ENABLE_ON_INIT,
  69. };
  70. struct clk *main_clks[] = {
  71. &r_clk,
  72. &extal_clk,
  73. &dll_clk,
  74. &pll_clk,
  75. };
  76. static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  77. static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
  78. static struct clk_div_mult_table div4_div_mult_table = {
  79. .divisors = divisors,
  80. .nr_divisors = ARRAY_SIZE(divisors),
  81. .multipliers = multipliers,
  82. .nr_multipliers = ARRAY_SIZE(multipliers),
  83. };
  84. static struct clk_div4_table div4_table = {
  85. .div_mult_table = &div4_div_mult_table,
  86. };
  87. enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P,
  88. DIV4_SIUA, DIV4_SIUB, DIV4_NR };
  89. #define DIV4(_reg, _bit, _mask, _flags) \
  90. SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)
  91. struct clk div4_clks[DIV4_NR] = {
  92. [DIV4_I] = DIV4(FRQCR, 20, 0x1fef, CLK_ENABLE_ON_INIT),
  93. [DIV4_U] = DIV4(FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),
  94. [DIV4_SH] = DIV4(FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),
  95. [DIV4_B] = DIV4(FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),
  96. [DIV4_B3] = DIV4(FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),
  97. [DIV4_P] = DIV4(FRQCR, 0, 0x1fff, 0),
  98. [DIV4_SIUA] = DIV4(SCLKACR, 0, 0x1fff, 0),
  99. [DIV4_SIUB] = DIV4(SCLKBCR, 0, 0x1fff, 0),
  100. };
  101. enum { DIV6_V, DIV6_NR };
  102. struct clk div6_clks[DIV6_NR] = {
  103. [DIV6_V] = SH_CLK_DIV6(&pll_clk, VCLKCR, 0),
  104. };
  105. #define MSTP(_parent, _reg, _bit, _flags) \
  106. SH_CLK_MSTP32(_parent, _reg, _bit, _flags)
  107. enum { MSTP031, MSTP030, MSTP029, MSTP028, MSTP026,
  108. MSTP023, MSTP022, MSTP021, MSTP020, MSTP019, MSTP018, MSTP017, MSTP016,
  109. MSTP015, MSTP014, MSTP013, MSTP012, MSTP011, MSTP010,
  110. MSTP007, MSTP006, MSTP005, MSTP002, MSTP001,
  111. MSTP109, MSTP100,
  112. MSTP227, MSTP226, MSTP224, MSTP223, MSTP222, MSTP218, MSTP217,
  113. MSTP211, MSTP207, MSTP205, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,
  114. MSTP_NR };
  115. static struct clk mstp_clks[MSTP_NR] = {
  116. /* See page 52 of Datasheet V0.40: Overview -> Block Diagram */
  117. [MSTP031] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 31, CLK_ENABLE_ON_INIT),
  118. [MSTP030] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 30, CLK_ENABLE_ON_INIT),
  119. [MSTP029] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 29, CLK_ENABLE_ON_INIT),
  120. [MSTP028] = MSTP(&div4_clks[DIV4_SH], MSTPCR0, 28, CLK_ENABLE_ON_INIT),
  121. [MSTP026] = MSTP(&div4_clks[DIV4_B], MSTPCR0, 26, CLK_ENABLE_ON_INIT),
  122. [MSTP023] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 23, 0),
  123. [MSTP022] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 22, 0),
  124. [MSTP021] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 21, 0),
  125. [MSTP020] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 20, 0),
  126. [MSTP019] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 19, 0),
  127. [MSTP017] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 17, 0),
  128. [MSTP015] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 15, 0),
  129. [MSTP014] = MSTP(&r_clk, MSTPCR0, 14, 0),
  130. [MSTP013] = MSTP(&r_clk, MSTPCR0, 13, 0),
  131. [MSTP011] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 11, 0),
  132. [MSTP010] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 10, 0),
  133. [MSTP007] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 7, 0),
  134. [MSTP006] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 6, 0),
  135. [MSTP005] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 5, 0),
  136. [MSTP002] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 2, 0),
  137. [MSTP001] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 1, 0),
  138. [MSTP109] = MSTP(&div4_clks[DIV4_P], MSTPCR1, 9, 0),
  139. [MSTP227] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 27, 0),
  140. [MSTP226] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 26, 0),
  141. [MSTP224] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 24, 0),
  142. [MSTP223] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 23, 0),
  143. [MSTP222] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 22, 0),
  144. [MSTP218] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 18, 0),
  145. [MSTP217] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 17, 0),
  146. [MSTP211] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 11, 0),
  147. [MSTP207] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 7, CLK_ENABLE_ON_INIT),
  148. [MSTP205] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 5, 0),
  149. [MSTP204] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 4, 0),
  150. [MSTP203] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 3, 0),
  151. [MSTP202] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 2, CLK_ENABLE_ON_INIT),
  152. [MSTP201] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 1, CLK_ENABLE_ON_INIT),
  153. [MSTP200] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 0, 0),
  154. };
  155. static struct clk_lookup lookups[] = {
  156. /* main clocks */
  157. CLKDEV_CON_ID("rclk", &r_clk),
  158. CLKDEV_CON_ID("extal", &extal_clk),
  159. CLKDEV_CON_ID("dll_clk", &dll_clk),
  160. CLKDEV_CON_ID("pll_clk", &pll_clk),
  161. /* DIV4 clocks */
  162. CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
  163. CLKDEV_CON_ID("umem_clk", &div4_clks[DIV4_U]),
  164. CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
  165. CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
  166. CLKDEV_CON_ID("b3_clk", &div4_clks[DIV4_B3]),
  167. CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
  168. CLKDEV_CON_ID("siua_clk", &div4_clks[DIV4_SIUA]),
  169. CLKDEV_CON_ID("siub_clk", &div4_clks[DIV4_SIUB]),
  170. /* DIV6 clocks */
  171. CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),
  172. /* MSTP32 clocks */
  173. CLKDEV_CON_ID("tlb0", &mstp_clks[MSTP031]),
  174. CLKDEV_CON_ID("ic0", &mstp_clks[MSTP030]),
  175. CLKDEV_CON_ID("oc0", &mstp_clks[MSTP029]),
  176. CLKDEV_CON_ID("rsmem0", &mstp_clks[MSTP028]),
  177. CLKDEV_CON_ID("xymem0", &mstp_clks[MSTP026]),
  178. CLKDEV_CON_ID("intc3", &mstp_clks[MSTP023]),
  179. CLKDEV_CON_ID("intc0", &mstp_clks[MSTP022]),
  180. CLKDEV_CON_ID("dmac0", &mstp_clks[MSTP021]),
  181. CLKDEV_CON_ID("sh0", &mstp_clks[MSTP020]),
  182. CLKDEV_CON_ID("hudi0", &mstp_clks[MSTP019]),
  183. CLKDEV_CON_ID("ubc0", &mstp_clks[MSTP017]),
  184. CLKDEV_CON_ID("tmu_fck", &mstp_clks[MSTP015]),
  185. CLKDEV_ICK_ID("fck", "sh-cmt-32.0", &mstp_clks[MSTP014]),
  186. CLKDEV_CON_ID("rwdt0", &mstp_clks[MSTP013]),
  187. CLKDEV_CON_ID("mfi0", &mstp_clks[MSTP011]),
  188. CLKDEV_CON_ID("flctl0", &mstp_clks[MSTP010]),
  189. CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP007]),
  190. CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP006]),
  191. CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP005]),
  192. CLKDEV_CON_ID("msiof0", &mstp_clks[MSTP002]),
  193. CLKDEV_CON_ID("sbr0", &mstp_clks[MSTP001]),
  194. CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks[MSTP109]),
  195. CLKDEV_CON_ID("icb0", &mstp_clks[MSTP227]),
  196. CLKDEV_CON_ID("meram0", &mstp_clks[MSTP226]),
  197. CLKDEV_CON_ID("dacy1", &mstp_clks[MSTP224]),
  198. CLKDEV_CON_ID("dacy0", &mstp_clks[MSTP223]),
  199. CLKDEV_CON_ID("tsif0", &mstp_clks[MSTP222]),
  200. CLKDEV_CON_ID("sdhi0", &mstp_clks[MSTP218]),
  201. CLKDEV_CON_ID("mmcif0", &mstp_clks[MSTP217]),
  202. CLKDEV_CON_ID("usbf0", &mstp_clks[MSTP211]),
  203. CLKDEV_CON_ID("veu1", &mstp_clks[MSTP207]),
  204. CLKDEV_CON_ID("vou0", &mstp_clks[MSTP205]),
  205. CLKDEV_CON_ID("beu0", &mstp_clks[MSTP204]),
  206. CLKDEV_CON_ID("ceu0", &mstp_clks[MSTP203]),
  207. CLKDEV_CON_ID("veu0", &mstp_clks[MSTP202]),
  208. CLKDEV_CON_ID("vpu0", &mstp_clks[MSTP201]),
  209. CLKDEV_CON_ID("lcdc0", &mstp_clks[MSTP200]),
  210. };
  211. int __init arch_clk_init(void)
  212. {
  213. int k, ret = 0;
  214. /* autodetect extal or dll configuration */
  215. if (__raw_readl(PLLCR) & 0x1000)
  216. pll_clk.parent = &dll_clk;
  217. else
  218. pll_clk.parent = &extal_clk;
  219. for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
  220. ret = clk_register(main_clks[k]);
  221. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  222. if (!ret)
  223. ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
  224. if (!ret)
  225. ret = sh_clk_div6_register(div6_clks, DIV6_NR);
  226. if (!ret)
  227. ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);
  228. return ret;
  229. }