clock-sh7724.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7724.c
  3. *
  4. * SH7724 clock framework support
  5. *
  6. * Copyright (C) 2009 Magnus Damm
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/init.h>
  22. #include <linux/kernel.h>
  23. #include <linux/io.h>
  24. #include <asm/clock.h>
  25. /* SH7724 registers */
  26. #define FRQCRA 0xa4150000
  27. #define FRQCRB 0xa4150004
  28. #define VCLKCR 0xa4150048
  29. #define FCLKACR 0xa4150008
  30. #define FCLKBCR 0xa415000c
  31. #define IRDACLKCR 0xa4150018
  32. #define PLLCR 0xa4150024
  33. #define MSTPCR0 0xa4150030
  34. #define MSTPCR1 0xa4150034
  35. #define MSTPCR2 0xa4150038
  36. #define SPUCLKCR 0xa415003c
  37. #define FLLFRQ 0xa4150050
  38. #define LSTATS 0xa4150060
  39. /* Fixed 32 KHz root clock for RTC and Power Management purposes */
  40. static struct clk r_clk = {
  41. .name = "rclk",
  42. .id = -1,
  43. .rate = 32768,
  44. };
  45. /*
  46. * Default rate for the root input clock, reset this with clk_set_rate()
  47. * from the platform code.
  48. */
  49. struct clk extal_clk = {
  50. .name = "extal",
  51. .id = -1,
  52. .rate = 33333333,
  53. };
  54. /* The fll multiplies the 32khz r_clk, may be used instead of extal */
  55. static unsigned long fll_recalc(struct clk *clk)
  56. {
  57. unsigned long mult = 0;
  58. unsigned long div = 1;
  59. if (__raw_readl(PLLCR) & 0x1000)
  60. mult = __raw_readl(FLLFRQ) & 0x3ff;
  61. if (__raw_readl(FLLFRQ) & 0x4000)
  62. div = 2;
  63. return (clk->parent->rate * mult) / div;
  64. }
  65. static struct clk_ops fll_clk_ops = {
  66. .recalc = fll_recalc,
  67. };
  68. static struct clk fll_clk = {
  69. .name = "fll_clk",
  70. .id = -1,
  71. .ops = &fll_clk_ops,
  72. .parent = &r_clk,
  73. .flags = CLK_ENABLE_ON_INIT,
  74. };
  75. static unsigned long pll_recalc(struct clk *clk)
  76. {
  77. unsigned long mult = 1;
  78. if (__raw_readl(PLLCR) & 0x4000)
  79. mult = (((__raw_readl(FRQCRA) >> 24) & 0x3f) + 1) * 2;
  80. return clk->parent->rate * mult;
  81. }
  82. static struct clk_ops pll_clk_ops = {
  83. .recalc = pll_recalc,
  84. };
  85. static struct clk pll_clk = {
  86. .name = "pll_clk",
  87. .id = -1,
  88. .ops = &pll_clk_ops,
  89. .flags = CLK_ENABLE_ON_INIT,
  90. };
  91. /* A fixed divide-by-3 block use by the div6 clocks */
  92. static unsigned long div3_recalc(struct clk *clk)
  93. {
  94. return clk->parent->rate / 3;
  95. }
  96. static struct clk_ops div3_clk_ops = {
  97. .recalc = div3_recalc,
  98. };
  99. static struct clk div3_clk = {
  100. .name = "div3_clk",
  101. .id = -1,
  102. .ops = &div3_clk_ops,
  103. .parent = &pll_clk,
  104. };
  105. struct clk *main_clks[] = {
  106. &r_clk,
  107. &extal_clk,
  108. &fll_clk,
  109. &pll_clk,
  110. &div3_clk,
  111. };
  112. static int divisors[] = { 2, 0, 4, 6, 8, 12, 16, 0, 24, 32, 36, 48, 0, 72 };
  113. static struct clk_div_mult_table div4_table = {
  114. .divisors = divisors,
  115. .nr_divisors = ARRAY_SIZE(divisors),
  116. };
  117. enum { DIV4_I, DIV4_SH, DIV4_B, DIV4_P, DIV4_M1, DIV4_NR };
  118. #define DIV4(_str, _reg, _bit, _mask, _flags) \
  119. SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
  120. struct clk div4_clks[DIV4_NR] = {
  121. [DIV4_I] = DIV4("cpu_clk", FRQCRA, 20, 0x2f7d, CLK_ENABLE_ON_INIT),
  122. [DIV4_SH] = DIV4("shyway_clk", FRQCRA, 12, 0x2f7c, CLK_ENABLE_ON_INIT),
  123. [DIV4_B] = DIV4("bus_clk", FRQCRA, 8, 0x2f7c, CLK_ENABLE_ON_INIT),
  124. [DIV4_P] = DIV4("peripheral_clk", FRQCRA, 0, 0x2f7c, 0),
  125. [DIV4_M1] = DIV4("vpu_clk", FRQCRB, 4, 0x2f7c, 0),
  126. };
  127. struct clk div6_clks[] = {
  128. SH_CLK_DIV6("video_clk", &div3_clk, VCLKCR, 0),
  129. SH_CLK_DIV6("fsia_clk", &div3_clk, FCLKACR, 0),
  130. SH_CLK_DIV6("fsib_clk", &div3_clk, FCLKBCR, 0),
  131. SH_CLK_DIV6("irda_clk", &div3_clk, IRDACLKCR, 0),
  132. SH_CLK_DIV6("spu_clk", &div3_clk, SPUCLKCR, 0),
  133. };
  134. #define MSTP(_str, _parent, _reg, _bit, _force_on, _need_cpg, _need_ram) \
  135. SH_CLK_MSTP32(_str, -1, _parent, _reg, _bit, _force_on * CLK_ENABLE_ON_INIT)
  136. static struct clk mstp_clks[] = {
  137. MSTP("tlb0", &div4_clks[DIV4_I], MSTPCR0, 31, 1, 1, 0),
  138. MSTP("ic0", &div4_clks[DIV4_I], MSTPCR0, 30, 1, 1, 0),
  139. MSTP("oc0", &div4_clks[DIV4_I], MSTPCR0, 29, 1, 1, 0),
  140. MSTP("rs0", &div4_clks[DIV4_B], MSTPCR0, 28, 1, 1, 0),
  141. MSTP("ilmem0", &div4_clks[DIV4_I], MSTPCR0, 27, 1, 1, 0),
  142. MSTP("l2c0", &div4_clks[DIV4_SH], MSTPCR0, 26, 1, 1, 0),
  143. MSTP("fpu0", &div4_clks[DIV4_I], MSTPCR0, 24, 1, 1, 0),
  144. MSTP("intc0", &div4_clks[DIV4_P], MSTPCR0, 22, 1, 1, 0),
  145. MSTP("dmac0", &div4_clks[DIV4_B], MSTPCR0, 21, 0, 1, 1),
  146. MSTP("sh0", &div4_clks[DIV4_SH], MSTPCR0, 20, 0, 1, 0),
  147. MSTP("hudi0", &div4_clks[DIV4_P], MSTPCR0, 19, 0, 1, 0),
  148. MSTP("ubc0", &div4_clks[DIV4_I], MSTPCR0, 17, 0, 1, 0),
  149. MSTP("tmu0", &div4_clks[DIV4_P], MSTPCR0, 15, 0, 1, 0),
  150. MSTP("cmt0", &r_clk, MSTPCR0, 14, 0, 0, 0),
  151. MSTP("rwdt0", &r_clk, MSTPCR0, 13, 0, 0, 0),
  152. MSTP("dmac1", &div4_clks[DIV4_B], MSTPCR0, 12, 0, 1, 1),
  153. MSTP("tmu1", &div4_clks[DIV4_P], MSTPCR0, 10, 0, 1, 0),
  154. MSTP("scif0", &div4_clks[DIV4_P], MSTPCR0, 9, 0, 1, 0),
  155. MSTP("scif1", &div4_clks[DIV4_P], MSTPCR0, 8, 0, 1, 0),
  156. MSTP("scif2", &div4_clks[DIV4_P], MSTPCR0, 7, 0, 1, 0),
  157. MSTP("scif3", &div4_clks[DIV4_B], MSTPCR0, 6, 0, 1, 0),
  158. MSTP("scif4", &div4_clks[DIV4_B], MSTPCR0, 5, 0, 1, 0),
  159. MSTP("scif5", &div4_clks[DIV4_B], MSTPCR0, 4, 0, 1, 0),
  160. MSTP("msiof0", &div4_clks[DIV4_B], MSTPCR0, 2, 0, 1, 0),
  161. MSTP("msiof1", &div4_clks[DIV4_B], MSTPCR0, 1, 0, 1, 0),
  162. MSTP("keysc0", &r_clk, MSTPCR1, 12, 0, 0, 0),
  163. MSTP("rtc0", &r_clk, MSTPCR1, 11, 0, 0, 0),
  164. MSTP("i2c0", &div4_clks[DIV4_P], MSTPCR1, 9, 0, 1, 0),
  165. MSTP("i2c1", &div4_clks[DIV4_P], MSTPCR1, 8, 0, 1, 0),
  166. MSTP("mmc0", &div4_clks[DIV4_B], MSTPCR2, 29, 0, 1, 0),
  167. MSTP("eth0", &div4_clks[DIV4_B], MSTPCR2, 28, 0, 1, 0),
  168. MSTP("atapi0", &div4_clks[DIV4_B], MSTPCR2, 26, 0, 1, 0),
  169. MSTP("tpu0", &div4_clks[DIV4_B], MSTPCR2, 25, 0, 1, 0),
  170. MSTP("irda0", &div4_clks[DIV4_P], MSTPCR2, 24, 0, 1, 0),
  171. MSTP("tsif0", &div4_clks[DIV4_B], MSTPCR2, 22, 0, 1, 0),
  172. MSTP("usb1", &div4_clks[DIV4_B], MSTPCR2, 21, 0, 1, 1),
  173. MSTP("usb0", &div4_clks[DIV4_B], MSTPCR2, 20, 0, 1, 1),
  174. MSTP("2dg0", &div4_clks[DIV4_B], MSTPCR2, 19, 0, 1, 1),
  175. MSTP("sdhi0", &div4_clks[DIV4_B], MSTPCR2, 18, 0, 1, 0),
  176. MSTP("sdhi1", &div4_clks[DIV4_B], MSTPCR2, 17, 0, 1, 0),
  177. MSTP("veu1", &div4_clks[DIV4_B], MSTPCR2, 15, 1, 1, 1),
  178. MSTP("ceu1", &div4_clks[DIV4_B], MSTPCR2, 13, 0, 1, 1),
  179. MSTP("beu1", &div4_clks[DIV4_B], MSTPCR2, 12, 0, 1, 1),
  180. MSTP("2ddmac0", &div4_clks[DIV4_SH], MSTPCR2, 10, 0, 1, 1),
  181. MSTP("spu0", &div4_clks[DIV4_B], MSTPCR2, 9, 0, 1, 0),
  182. MSTP("jpu0", &div4_clks[DIV4_B], MSTPCR2, 6, 1, 1, 1),
  183. MSTP("vou0", &div4_clks[DIV4_B], MSTPCR2, 5, 0, 1, 1),
  184. MSTP("beu0", &div4_clks[DIV4_B], MSTPCR2, 4, 0, 1, 1),
  185. MSTP("ceu0", &div4_clks[DIV4_B], MSTPCR2, 3, 0, 1, 1),
  186. MSTP("veu0", &div4_clks[DIV4_B], MSTPCR2, 2, 1, 1, 1),
  187. MSTP("vpu0", &div4_clks[DIV4_B], MSTPCR2, 1, 1, 1, 1),
  188. MSTP("lcdc0", &div4_clks[DIV4_B], MSTPCR2, 0, 0, 1, 1),
  189. };
  190. int __init arch_clk_init(void)
  191. {
  192. int k, ret = 0;
  193. /* autodetect extal or fll configuration */
  194. if (__raw_readl(PLLCR) & 0x1000)
  195. pll_clk.parent = &fll_clk;
  196. else
  197. pll_clk.parent = &extal_clk;
  198. for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
  199. ret = clk_register(main_clks[k]);
  200. if (!ret)
  201. ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
  202. if (!ret)
  203. ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
  204. if (!ret)
  205. ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
  206. return ret;
  207. }