clock-sh7723.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7723.c
  3. *
  4. * SH7723 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 <linux/clk.h>
  25. #include <asm/clkdev.h>
  26. #include <asm/clock.h>
  27. #include <asm/hwblk.h>
  28. #include <cpu/sh7723.h>
  29. /* SH7723 registers */
  30. #define FRQCR 0xa4150000
  31. #define VCLKCR 0xa4150004
  32. #define SCLKACR 0xa4150008
  33. #define SCLKBCR 0xa415000c
  34. #define IRDACLKCR 0xa4150018
  35. #define PLLCR 0xa4150024
  36. #define DLLFRQ 0xa4150050
  37. /* Fixed 32 KHz root clock for RTC and Power Management purposes */
  38. static struct clk r_clk = {
  39. .name = "rclk",
  40. .id = -1,
  41. .rate = 32768,
  42. };
  43. /*
  44. * Default rate for the root input clock, reset this with clk_set_rate()
  45. * from the platform code.
  46. */
  47. struct clk extal_clk = {
  48. .name = "extal",
  49. .id = -1,
  50. .rate = 33333333,
  51. };
  52. /* The dll multiplies the 32khz r_clk, may be used instead of extal */
  53. static unsigned long dll_recalc(struct clk *clk)
  54. {
  55. unsigned long mult;
  56. if (__raw_readl(PLLCR) & 0x1000)
  57. mult = __raw_readl(DLLFRQ);
  58. else
  59. mult = 0;
  60. return clk->parent->rate * mult;
  61. }
  62. static struct clk_ops dll_clk_ops = {
  63. .recalc = dll_recalc,
  64. };
  65. static struct clk dll_clk = {
  66. .name = "dll_clk",
  67. .id = -1,
  68. .ops = &dll_clk_ops,
  69. .parent = &r_clk,
  70. .flags = CLK_ENABLE_ON_INIT,
  71. };
  72. static unsigned long pll_recalc(struct clk *clk)
  73. {
  74. unsigned long mult = 1;
  75. unsigned long div = 1;
  76. if (__raw_readl(PLLCR) & 0x4000)
  77. mult = (((__raw_readl(FRQCR) >> 24) & 0x1f) + 1);
  78. else
  79. div = 2;
  80. return (clk->parent->rate * mult) / div;
  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. struct clk *main_clks[] = {
  92. &r_clk,
  93. &extal_clk,
  94. &dll_clk,
  95. &pll_clk,
  96. };
  97. static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  98. static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
  99. static struct clk_div_mult_table div4_div_mult_table = {
  100. .divisors = divisors,
  101. .nr_divisors = ARRAY_SIZE(divisors),
  102. .multipliers = multipliers,
  103. .nr_multipliers = ARRAY_SIZE(multipliers),
  104. };
  105. static struct clk_div4_table div4_table = {
  106. .div_mult_table = &div4_div_mult_table,
  107. };
  108. enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P, DIV4_NR };
  109. #define DIV4(_str, _reg, _bit, _mask, _flags) \
  110. SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
  111. struct clk div4_clks[DIV4_NR] = {
  112. [DIV4_I] = DIV4("cpu_clk", FRQCR, 20, 0x0dbf, CLK_ENABLE_ON_INIT),
  113. [DIV4_U] = DIV4("umem_clk", FRQCR, 16, 0x0dbf, CLK_ENABLE_ON_INIT),
  114. [DIV4_SH] = DIV4("shyway_clk", FRQCR, 12, 0x0dbf, CLK_ENABLE_ON_INIT),
  115. [DIV4_B] = DIV4("bus_clk", FRQCR, 8, 0x0dbf, CLK_ENABLE_ON_INIT),
  116. [DIV4_B3] = DIV4("b3_clk", FRQCR, 4, 0x0db4, CLK_ENABLE_ON_INIT),
  117. [DIV4_P] = DIV4("peripheral_clk", FRQCR, 0, 0x0dbf, 0),
  118. };
  119. enum { DIV4_IRDA, DIV4_ENABLE_NR };
  120. struct clk div4_enable_clks[DIV4_ENABLE_NR] = {
  121. [DIV4_IRDA] = DIV4("irda_clk", IRDACLKCR, 0, 0x0dbf, 0),
  122. };
  123. enum { DIV4_SIUA, DIV4_SIUB, DIV4_REPARENT_NR };
  124. struct clk div4_reparent_clks[DIV4_REPARENT_NR] = {
  125. [DIV4_SIUA] = DIV4("siua_clk", SCLKACR, 0, 0x0dbf, 0),
  126. [DIV4_SIUB] = DIV4("siub_clk", SCLKBCR, 0, 0x0dbf, 0),
  127. };
  128. enum { DIV6_V, DIV6_NR };
  129. struct clk div6_clks[DIV6_NR] = {
  130. [DIV6_V] = SH_CLK_DIV6("video_clk", &pll_clk, VCLKCR, 0),
  131. };
  132. static struct clk mstp_clks[] = {
  133. /* See page 60 of Datasheet V1.0: Overview -> Block Diagram */
  134. SH_HWBLK_CLK(HWBLK_TLB, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
  135. SH_HWBLK_CLK(HWBLK_IC, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
  136. SH_HWBLK_CLK(HWBLK_OC, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
  137. SH_HWBLK_CLK(HWBLK_L2C, &div4_clks[DIV4_SH], CLK_ENABLE_ON_INIT),
  138. SH_HWBLK_CLK(HWBLK_ILMEM, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
  139. SH_HWBLK_CLK(HWBLK_FPU, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
  140. SH_HWBLK_CLK(HWBLK_INTC, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
  141. SH_HWBLK_CLK(HWBLK_DMAC0, &div4_clks[DIV4_B], 0),
  142. SH_HWBLK_CLK(HWBLK_SHYWAY, &div4_clks[DIV4_SH], CLK_ENABLE_ON_INIT),
  143. SH_HWBLK_CLK(HWBLK_HUDI, &div4_clks[DIV4_P], 0),
  144. SH_HWBLK_CLK(HWBLK_UBC, &div4_clks[DIV4_I], 0),
  145. SH_HWBLK_CLK(HWBLK_TMU0, &div4_clks[DIV4_P], 0),
  146. SH_HWBLK_CLK(HWBLK_CMT, &r_clk, 0),
  147. SH_HWBLK_CLK(HWBLK_RWDT, &r_clk, 0),
  148. SH_HWBLK_CLK(HWBLK_DMAC1, &div4_clks[DIV4_B], 0),
  149. SH_HWBLK_CLK(HWBLK_TMU1, &div4_clks[DIV4_P], 0),
  150. SH_HWBLK_CLK(HWBLK_FLCTL, &div4_clks[DIV4_P], 0),
  151. SH_HWBLK_CLK(HWBLK_SCIF0, &div4_clks[DIV4_P], 0),
  152. SH_HWBLK_CLK(HWBLK_SCIF1, &div4_clks[DIV4_P], 0),
  153. SH_HWBLK_CLK(HWBLK_SCIF2, &div4_clks[DIV4_P], 0),
  154. SH_HWBLK_CLK(HWBLK_SCIF3, &div4_clks[DIV4_B], 0),
  155. SH_HWBLK_CLK(HWBLK_SCIF4, &div4_clks[DIV4_B], 0),
  156. SH_HWBLK_CLK(HWBLK_SCIF5, &div4_clks[DIV4_B], 0),
  157. SH_HWBLK_CLK(HWBLK_MSIOF0, &div4_clks[DIV4_B], 0),
  158. SH_HWBLK_CLK(HWBLK_MSIOF1, &div4_clks[DIV4_B], 0),
  159. SH_HWBLK_CLK(HWBLK_MERAM, &div4_clks[DIV4_SH], 0),
  160. SH_HWBLK_CLK(HWBLK_IIC, &div4_clks[DIV4_P], 0),
  161. SH_HWBLK_CLK(HWBLK_RTC, &r_clk, 0),
  162. SH_HWBLK_CLK(HWBLK_ATAPI, &div4_clks[DIV4_SH], 0),
  163. SH_HWBLK_CLK(HWBLK_ADC, &div4_clks[DIV4_P], 0),
  164. SH_HWBLK_CLK(HWBLK_TPU, &div4_clks[DIV4_B], 0),
  165. SH_HWBLK_CLK(HWBLK_IRDA, &div4_clks[DIV4_P], 0),
  166. SH_HWBLK_CLK(HWBLK_TSIF, &div4_clks[DIV4_B], 0),
  167. SH_HWBLK_CLK(HWBLK_ICB, &div4_clks[DIV4_B], CLK_ENABLE_ON_INIT),
  168. SH_HWBLK_CLK(HWBLK_SDHI0, &div4_clks[DIV4_B], 0),
  169. SH_HWBLK_CLK(HWBLK_SDHI1, &div4_clks[DIV4_B], 0),
  170. SH_HWBLK_CLK(HWBLK_KEYSC, &r_clk, 0),
  171. SH_HWBLK_CLK(HWBLK_USB, &div4_clks[DIV4_B], 0),
  172. SH_HWBLK_CLK(HWBLK_2DG, &div4_clks[DIV4_B], 0),
  173. SH_HWBLK_CLK(HWBLK_SIU, &div4_clks[DIV4_B], 0),
  174. SH_HWBLK_CLK(HWBLK_VEU2H1, &div4_clks[DIV4_B], 0),
  175. SH_HWBLK_CLK(HWBLK_VOU, &div4_clks[DIV4_B], 0),
  176. SH_HWBLK_CLK(HWBLK_BEU, &div4_clks[DIV4_B], 0),
  177. SH_HWBLK_CLK(HWBLK_CEU, &div4_clks[DIV4_B], 0),
  178. SH_HWBLK_CLK(HWBLK_VEU2H0, &div4_clks[DIV4_B], 0),
  179. SH_HWBLK_CLK(HWBLK_VPU, &div4_clks[DIV4_B], 0),
  180. SH_HWBLK_CLK(HWBLK_LCDC, &div4_clks[DIV4_B], 0),
  181. };
  182. #define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
  183. static struct clk_lookup lookups[] = {
  184. /* DIV6 clocks */
  185. CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),
  186. /* MSTP clocks */
  187. CLKDEV_CON_ID("tlb0", &mstp_clks[HWBLK_TLB]),
  188. CLKDEV_CON_ID("ic0", &mstp_clks[HWBLK_IC]),
  189. CLKDEV_CON_ID("oc0", &mstp_clks[HWBLK_OC]),
  190. CLKDEV_CON_ID("l2c0", &mstp_clks[HWBLK_L2C]),
  191. CLKDEV_CON_ID("ilmem0", &mstp_clks[HWBLK_ILMEM]),
  192. CLKDEV_CON_ID("fpu0", &mstp_clks[HWBLK_FPU]),
  193. CLKDEV_CON_ID("intc0", &mstp_clks[HWBLK_INTC]),
  194. CLKDEV_CON_ID("dmac0", &mstp_clks[HWBLK_DMAC0]),
  195. CLKDEV_CON_ID("sh0", &mstp_clks[HWBLK_SHYWAY]),
  196. CLKDEV_CON_ID("hudi0", &mstp_clks[HWBLK_HUDI]),
  197. CLKDEV_CON_ID("ubc0", &mstp_clks[HWBLK_UBC]),
  198. {
  199. /* TMU0 */
  200. .dev_id = "sh_tmu.0",
  201. .con_id = "tmu_fck",
  202. .clk = &mstp_clks[HWBLK_TMU0],
  203. }, {
  204. /* TMU1 */
  205. .dev_id = "sh_tmu.1",
  206. .con_id = "tmu_fck",
  207. .clk = &mstp_clks[HWBLK_TMU0],
  208. }, {
  209. /* TMU2 */
  210. .dev_id = "sh_tmu.2",
  211. .con_id = "tmu_fck",
  212. .clk = &mstp_clks[HWBLK_TMU0],
  213. },
  214. CLKDEV_CON_ID("cmt_fck", &mstp_clks[HWBLK_CMT]),
  215. CLKDEV_CON_ID("rwdt0", &mstp_clks[HWBLK_RWDT]),
  216. CLKDEV_CON_ID("dmac1", &mstp_clks[HWBLK_DMAC1]),
  217. {
  218. /* TMU3 */
  219. .dev_id = "sh_tmu.3",
  220. .con_id = "tmu_fck",
  221. .clk = &mstp_clks[HWBLK_TMU1],
  222. }, {
  223. /* TMU4 */
  224. .dev_id = "sh_tmu.4",
  225. .con_id = "tmu_fck",
  226. .clk = &mstp_clks[HWBLK_TMU1],
  227. }, {
  228. /* TMU5 */
  229. .dev_id = "sh_tmu.5",
  230. .con_id = "tmu_fck",
  231. .clk = &mstp_clks[HWBLK_TMU1],
  232. },
  233. CLKDEV_CON_ID("flctl0", &mstp_clks[HWBLK_FLCTL]),
  234. {
  235. /* SCIF0 */
  236. .dev_id = "sh-sci.0",
  237. .con_id = "sci_fck",
  238. .clk = &mstp_clks[HWBLK_SCIF0],
  239. }, {
  240. /* SCIF1 */
  241. .dev_id = "sh-sci.1",
  242. .con_id = "sci_fck",
  243. .clk = &mstp_clks[HWBLK_SCIF1],
  244. }, {
  245. /* SCIF2 */
  246. .dev_id = "sh-sci.2",
  247. .con_id = "sci_fck",
  248. .clk = &mstp_clks[HWBLK_SCIF2],
  249. }, {
  250. /* SCIF3 */
  251. .dev_id = "sh-sci.3",
  252. .con_id = "sci_fck",
  253. .clk = &mstp_clks[HWBLK_SCIF3],
  254. }, {
  255. /* SCIF4 */
  256. .dev_id = "sh-sci.4",
  257. .con_id = "sci_fck",
  258. .clk = &mstp_clks[HWBLK_SCIF4],
  259. }, {
  260. /* SCIF5 */
  261. .dev_id = "sh-sci.5",
  262. .con_id = "sci_fck",
  263. .clk = &mstp_clks[HWBLK_SCIF5],
  264. },
  265. CLKDEV_CON_ID("msiof0", &mstp_clks[HWBLK_MSIOF0]),
  266. CLKDEV_CON_ID("msiof1", &mstp_clks[HWBLK_MSIOF1]),
  267. CLKDEV_CON_ID("meram0", &mstp_clks[HWBLK_MERAM]),
  268. CLKDEV_CON_ID("i2c0", &mstp_clks[HWBLK_IIC]),
  269. CLKDEV_CON_ID("rtc0", &mstp_clks[HWBLK_RTC]),
  270. CLKDEV_CON_ID("atapi0", &mstp_clks[HWBLK_ATAPI]),
  271. CLKDEV_CON_ID("adc0", &mstp_clks[HWBLK_ADC]),
  272. CLKDEV_CON_ID("tpu0", &mstp_clks[HWBLK_TPU]),
  273. CLKDEV_CON_ID("irda0", &mstp_clks[HWBLK_IRDA]),
  274. CLKDEV_CON_ID("tsif0", &mstp_clks[HWBLK_TSIF]),
  275. CLKDEV_CON_ID("icb0", &mstp_clks[HWBLK_ICB]),
  276. CLKDEV_CON_ID("sdhi0", &mstp_clks[HWBLK_SDHI0]),
  277. CLKDEV_CON_ID("sdhi1", &mstp_clks[HWBLK_SDHI1]),
  278. CLKDEV_CON_ID("keysc0", &mstp_clks[HWBLK_KEYSC]),
  279. CLKDEV_CON_ID("usb0", &mstp_clks[HWBLK_USB]),
  280. CLKDEV_CON_ID("2dg0", &mstp_clks[HWBLK_2DG]),
  281. CLKDEV_CON_ID("siu0", &mstp_clks[HWBLK_SIU]),
  282. CLKDEV_CON_ID("veu1", &mstp_clks[HWBLK_VEU2H1]),
  283. CLKDEV_CON_ID("vou0", &mstp_clks[HWBLK_VOU]),
  284. CLKDEV_CON_ID("beu0", &mstp_clks[HWBLK_BEU]),
  285. CLKDEV_CON_ID("ceu0", &mstp_clks[HWBLK_CEU]),
  286. CLKDEV_CON_ID("veu0", &mstp_clks[HWBLK_VEU2H0]),
  287. CLKDEV_CON_ID("vpu0", &mstp_clks[HWBLK_VPU]),
  288. CLKDEV_CON_ID("lcdc0", &mstp_clks[HWBLK_LCDC]),
  289. };
  290. int __init arch_clk_init(void)
  291. {
  292. int k, ret = 0;
  293. /* autodetect extal or dll configuration */
  294. if (__raw_readl(PLLCR) & 0x1000)
  295. pll_clk.parent = &dll_clk;
  296. else
  297. pll_clk.parent = &extal_clk;
  298. for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
  299. ret |= clk_register(main_clks[k]);
  300. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  301. if (!ret)
  302. ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
  303. if (!ret)
  304. ret = sh_clk_div4_enable_register(div4_enable_clks,
  305. DIV4_ENABLE_NR, &div4_table);
  306. if (!ret)
  307. ret = sh_clk_div4_reparent_register(div4_reparent_clks,
  308. DIV4_REPARENT_NR, &div4_table);
  309. if (!ret)
  310. ret = sh_clk_div6_register(div6_clks, DIV6_NR);
  311. if (!ret)
  312. ret = sh_hwblk_clk_register(mstp_clks, HWBLK_NR);
  313. return ret;
  314. }