clock-sh73a0.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /*
  2. * sh73a0 clock framework support
  3. *
  4. * Copyright (C) 2010 Magnus Damm
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/io.h>
  18. #include <linux/sh_clk.h>
  19. #include <linux/clkdev.h>
  20. #include <asm/processor.h>
  21. #include "clock.h"
  22. #include "common.h"
  23. #define FRQCRA IOMEM(0xe6150000)
  24. #define FRQCRB IOMEM(0xe6150004)
  25. #define FRQCRD IOMEM(0xe61500e4)
  26. #define VCLKCR1 IOMEM(0xe6150008)
  27. #define VCLKCR2 IOMEM(0xe615000C)
  28. #define VCLKCR3 IOMEM(0xe615001C)
  29. #define ZBCKCR IOMEM(0xe6150010)
  30. #define FLCKCR IOMEM(0xe6150014)
  31. #define SD0CKCR IOMEM(0xe6150074)
  32. #define SD1CKCR IOMEM(0xe6150078)
  33. #define SD2CKCR IOMEM(0xe615007C)
  34. #define FSIACKCR IOMEM(0xe6150018)
  35. #define FSIBCKCR IOMEM(0xe6150090)
  36. #define SUBCKCR IOMEM(0xe6150080)
  37. #define SPUACKCR IOMEM(0xe6150084)
  38. #define SPUVCKCR IOMEM(0xe6150094)
  39. #define MSUCKCR IOMEM(0xe6150088)
  40. #define HSICKCR IOMEM(0xe615008C)
  41. #define MFCK1CR IOMEM(0xe6150098)
  42. #define MFCK2CR IOMEM(0xe615009C)
  43. #define DSITCKCR IOMEM(0xe6150060)
  44. #define DSI0PCKCR IOMEM(0xe6150064)
  45. #define DSI1PCKCR IOMEM(0xe6150068)
  46. #define DSI0PHYCR 0xe615006C
  47. #define DSI1PHYCR 0xe6150070
  48. #define PLLECR IOMEM(0xe61500d0)
  49. #define PLL0CR IOMEM(0xe61500d8)
  50. #define PLL1CR IOMEM(0xe6150028)
  51. #define PLL2CR IOMEM(0xe615002c)
  52. #define PLL3CR IOMEM(0xe61500dc)
  53. #define SMSTPCR0 IOMEM(0xe6150130)
  54. #define SMSTPCR1 IOMEM(0xe6150134)
  55. #define SMSTPCR2 IOMEM(0xe6150138)
  56. #define SMSTPCR3 IOMEM(0xe615013c)
  57. #define SMSTPCR4 IOMEM(0xe6150140)
  58. #define SMSTPCR5 IOMEM(0xe6150144)
  59. #define CKSCR IOMEM(0xe61500c0)
  60. /* Fixed 32 KHz root clock from EXTALR pin */
  61. static struct clk r_clk = {
  62. .rate = 32768,
  63. };
  64. /*
  65. * 26MHz default rate for the EXTAL1 root input clock.
  66. * If needed, reset this with clk_set_rate() from the platform code.
  67. */
  68. struct clk sh73a0_extal1_clk = {
  69. .rate = 26000000,
  70. };
  71. /*
  72. * 48MHz default rate for the EXTAL2 root input clock.
  73. * If needed, reset this with clk_set_rate() from the platform code.
  74. */
  75. struct clk sh73a0_extal2_clk = {
  76. .rate = 48000000,
  77. };
  78. static struct sh_clk_ops main_clk_ops = {
  79. .recalc = followparent_recalc,
  80. };
  81. /* Main clock */
  82. static struct clk main_clk = {
  83. /* .parent wll be set on sh73a0_clock_init() */
  84. .ops = &main_clk_ops,
  85. };
  86. /* PLL0, PLL1, PLL2, PLL3 */
  87. static unsigned long pll_recalc(struct clk *clk)
  88. {
  89. unsigned long mult = 1;
  90. if (__raw_readl(PLLECR) & (1 << clk->enable_bit)) {
  91. mult = (((__raw_readl(clk->enable_reg) >> 24) & 0x3f) + 1);
  92. /* handle CFG bit for PLL1 and PLL2 */
  93. switch (clk->enable_bit) {
  94. case 1:
  95. case 2:
  96. if (__raw_readl(clk->enable_reg) & (1 << 20))
  97. mult *= 2;
  98. }
  99. }
  100. return clk->parent->rate * mult;
  101. }
  102. static struct sh_clk_ops pll_clk_ops = {
  103. .recalc = pll_recalc,
  104. };
  105. static struct clk pll0_clk = {
  106. .ops = &pll_clk_ops,
  107. .flags = CLK_ENABLE_ON_INIT,
  108. .parent = &main_clk,
  109. .enable_reg = (void __iomem *)PLL0CR,
  110. .enable_bit = 0,
  111. };
  112. static struct clk pll1_clk = {
  113. .ops = &pll_clk_ops,
  114. .flags = CLK_ENABLE_ON_INIT,
  115. .parent = &main_clk,
  116. .enable_reg = (void __iomem *)PLL1CR,
  117. .enable_bit = 1,
  118. };
  119. static struct clk pll2_clk = {
  120. .ops = &pll_clk_ops,
  121. .flags = CLK_ENABLE_ON_INIT,
  122. .parent = &main_clk,
  123. .enable_reg = (void __iomem *)PLL2CR,
  124. .enable_bit = 2,
  125. };
  126. static struct clk pll3_clk = {
  127. .ops = &pll_clk_ops,
  128. .flags = CLK_ENABLE_ON_INIT,
  129. .parent = &main_clk,
  130. .enable_reg = (void __iomem *)PLL3CR,
  131. .enable_bit = 3,
  132. };
  133. /* A fixed divide block */
  134. SH_CLK_RATIO(div2, 1, 2);
  135. SH_CLK_RATIO(div7, 1, 7);
  136. SH_CLK_RATIO(div13, 1, 13);
  137. SH_FIXED_RATIO_CLK(extal1_div2_clk, sh73a0_extal1_clk, div2);
  138. SH_FIXED_RATIO_CLK(extal2_div2_clk, sh73a0_extal2_clk, div2);
  139. SH_FIXED_RATIO_CLK(main_div2_clk, main_clk, div2);
  140. SH_FIXED_RATIO_CLK(pll1_div2_clk, pll1_clk, div2);
  141. SH_FIXED_RATIO_CLK(pll1_div7_clk, pll1_clk, div7);
  142. SH_FIXED_RATIO_CLK(pll1_div13_clk, pll1_clk, div13);
  143. /* External input clock */
  144. struct clk sh73a0_extcki_clk = {
  145. };
  146. struct clk sh73a0_extalr_clk = {
  147. };
  148. static struct clk *main_clks[] = {
  149. &r_clk,
  150. &sh73a0_extal1_clk,
  151. &sh73a0_extal2_clk,
  152. &extal1_div2_clk,
  153. &extal2_div2_clk,
  154. &main_clk,
  155. &main_div2_clk,
  156. &pll0_clk,
  157. &pll1_clk,
  158. &pll2_clk,
  159. &pll3_clk,
  160. &pll1_div2_clk,
  161. &pll1_div7_clk,
  162. &pll1_div13_clk,
  163. &sh73a0_extcki_clk,
  164. &sh73a0_extalr_clk,
  165. };
  166. static int frqcr_kick(void)
  167. {
  168. int i;
  169. /* set KICK bit in FRQCRB to update hardware setting, check success */
  170. __raw_writel(__raw_readl(FRQCRB) | (1 << 31), FRQCRB);
  171. for (i = 1000; i; i--)
  172. if (__raw_readl(FRQCRB) & (1 << 31))
  173. cpu_relax();
  174. else
  175. return i;
  176. return -ETIMEDOUT;
  177. }
  178. static void div4_kick(struct clk *clk)
  179. {
  180. frqcr_kick();
  181. }
  182. static int divisors[] = { 2, 3, 4, 6, 8, 12, 16, 18,
  183. 24, 0, 36, 48, 7 };
  184. static struct clk_div_mult_table div4_div_mult_table = {
  185. .divisors = divisors,
  186. .nr_divisors = ARRAY_SIZE(divisors),
  187. };
  188. static struct clk_div4_table div4_table = {
  189. .div_mult_table = &div4_div_mult_table,
  190. .kick = div4_kick,
  191. };
  192. enum { DIV4_I, DIV4_ZG, DIV4_M3, DIV4_B, DIV4_M1, DIV4_M2,
  193. DIV4_Z, DIV4_ZX, DIV4_HP, DIV4_NR };
  194. #define DIV4(_reg, _bit, _mask, _flags) \
  195. SH_CLK_DIV4(&pll1_clk, _reg, _bit, _mask, _flags)
  196. static struct clk div4_clks[DIV4_NR] = {
  197. [DIV4_I] = DIV4(FRQCRA, 20, 0xdff, CLK_ENABLE_ON_INIT),
  198. /*
  199. * ZG clock is dividing PLL0 frequency to supply SGX. Make sure not to
  200. * exceed maximum frequencies of 201.5MHz for VDD_DVFS=1.175 and
  201. * 239.2MHz for VDD_DVFS=1.315V.
  202. */
  203. [DIV4_ZG] = SH_CLK_DIV4(&pll0_clk, FRQCRA, 16, 0xd7f, CLK_ENABLE_ON_INIT),
  204. [DIV4_M3] = DIV4(FRQCRA, 12, 0x1dff, CLK_ENABLE_ON_INIT),
  205. [DIV4_B] = DIV4(FRQCRA, 8, 0xdff, CLK_ENABLE_ON_INIT),
  206. [DIV4_M1] = DIV4(FRQCRA, 4, 0x1dff, 0),
  207. [DIV4_M2] = DIV4(FRQCRA, 0, 0x1dff, 0),
  208. [DIV4_Z] = SH_CLK_DIV4(&pll0_clk, FRQCRB, 24, 0x97f, 0),
  209. [DIV4_ZX] = DIV4(FRQCRB, 12, 0xdff, 0),
  210. [DIV4_HP] = DIV4(FRQCRB, 4, 0xdff, 0),
  211. };
  212. static unsigned long twd_recalc(struct clk *clk)
  213. {
  214. return clk_get_rate(clk->parent) / 4;
  215. }
  216. static struct sh_clk_ops twd_clk_ops = {
  217. .recalc = twd_recalc,
  218. };
  219. static struct clk twd_clk = {
  220. .parent = &div4_clks[DIV4_Z],
  221. .ops = &twd_clk_ops,
  222. };
  223. static struct sh_clk_ops zclk_ops, kicker_ops;
  224. static const struct sh_clk_ops *div4_clk_ops;
  225. static int zclk_set_rate(struct clk *clk, unsigned long rate)
  226. {
  227. int ret;
  228. if (!clk->parent || !__clk_get(clk->parent))
  229. return -ENODEV;
  230. if (readl(FRQCRB) & (1 << 31))
  231. return -EBUSY;
  232. if (rate == clk_get_rate(clk->parent)) {
  233. /* 1:1 - switch off divider */
  234. __raw_writel(__raw_readl(FRQCRB) & ~(1 << 28), FRQCRB);
  235. /* nullify the divider to prepare for the next time */
  236. ret = div4_clk_ops->set_rate(clk, rate / 2);
  237. if (!ret)
  238. ret = frqcr_kick();
  239. if (ret > 0)
  240. ret = 0;
  241. } else {
  242. /* Enable the divider */
  243. __raw_writel(__raw_readl(FRQCRB) | (1 << 28), FRQCRB);
  244. ret = frqcr_kick();
  245. if (ret >= 0)
  246. /*
  247. * set the divider - call the DIV4 method, it will kick
  248. * FRQCRB too
  249. */
  250. ret = div4_clk_ops->set_rate(clk, rate);
  251. if (ret < 0)
  252. goto esetrate;
  253. }
  254. esetrate:
  255. __clk_put(clk->parent);
  256. return ret;
  257. }
  258. static long zclk_round_rate(struct clk *clk, unsigned long rate)
  259. {
  260. unsigned long div_freq = div4_clk_ops->round_rate(clk, rate),
  261. parent_freq = clk_get_rate(clk->parent);
  262. if (rate > div_freq && abs(parent_freq - rate) < rate - div_freq)
  263. return parent_freq;
  264. return div_freq;
  265. }
  266. static unsigned long zclk_recalc(struct clk *clk)
  267. {
  268. /*
  269. * Must recalculate frequencies in case PLL0 has been changed, even if
  270. * the divisor is unused ATM!
  271. */
  272. unsigned long div_freq = div4_clk_ops->recalc(clk);
  273. if (__raw_readl(FRQCRB) & (1 << 28))
  274. return div_freq;
  275. return clk_get_rate(clk->parent);
  276. }
  277. static int kicker_set_rate(struct clk *clk, unsigned long rate)
  278. {
  279. if (__raw_readl(FRQCRB) & (1 << 31))
  280. return -EBUSY;
  281. return div4_clk_ops->set_rate(clk, rate);
  282. }
  283. static void div4_clk_extend(void)
  284. {
  285. int i;
  286. div4_clk_ops = div4_clks[0].ops;
  287. /* Add a kicker-busy check before changing the rate */
  288. kicker_ops = *div4_clk_ops;
  289. /* We extend the DIV4 clock with a 1:1 pass-through case */
  290. zclk_ops = *div4_clk_ops;
  291. kicker_ops.set_rate = kicker_set_rate;
  292. zclk_ops.set_rate = zclk_set_rate;
  293. zclk_ops.round_rate = zclk_round_rate;
  294. zclk_ops.recalc = zclk_recalc;
  295. for (i = 0; i < DIV4_NR; i++)
  296. div4_clks[i].ops = i == DIV4_Z ? &zclk_ops : &kicker_ops;
  297. }
  298. enum { DIV6_VCK1, DIV6_VCK2, DIV6_VCK3, DIV6_ZB1,
  299. DIV6_FLCTL, DIV6_SDHI0, DIV6_SDHI1, DIV6_SDHI2,
  300. DIV6_FSIA, DIV6_FSIB, DIV6_SUB,
  301. DIV6_SPUA, DIV6_SPUV, DIV6_MSU,
  302. DIV6_HSI, DIV6_MFG1, DIV6_MFG2,
  303. DIV6_DSIT, DIV6_DSI0P, DIV6_DSI1P,
  304. DIV6_NR };
  305. static struct clk *vck_parent[8] = {
  306. [0] = &pll1_div2_clk,
  307. [1] = &pll2_clk,
  308. [2] = &sh73a0_extcki_clk,
  309. [3] = &sh73a0_extal2_clk,
  310. [4] = &main_div2_clk,
  311. [5] = &sh73a0_extalr_clk,
  312. [6] = &main_clk,
  313. };
  314. static struct clk *pll_parent[4] = {
  315. [0] = &pll1_div2_clk,
  316. [1] = &pll2_clk,
  317. [2] = &pll1_div13_clk,
  318. };
  319. static struct clk *hsi_parent[4] = {
  320. [0] = &pll1_div2_clk,
  321. [1] = &pll2_clk,
  322. [2] = &pll1_div7_clk,
  323. };
  324. static struct clk *pll_extal2_parent[] = {
  325. [0] = &pll1_div2_clk,
  326. [1] = &pll2_clk,
  327. [2] = &sh73a0_extal2_clk,
  328. [3] = &sh73a0_extal2_clk,
  329. };
  330. static struct clk *dsi_parent[8] = {
  331. [0] = &pll1_div2_clk,
  332. [1] = &pll2_clk,
  333. [2] = &main_clk,
  334. [3] = &sh73a0_extal2_clk,
  335. [4] = &sh73a0_extcki_clk,
  336. };
  337. static struct clk div6_clks[DIV6_NR] = {
  338. [DIV6_VCK1] = SH_CLK_DIV6_EXT(VCLKCR1, 0,
  339. vck_parent, ARRAY_SIZE(vck_parent), 12, 3),
  340. [DIV6_VCK2] = SH_CLK_DIV6_EXT(VCLKCR2, 0,
  341. vck_parent, ARRAY_SIZE(vck_parent), 12, 3),
  342. [DIV6_VCK3] = SH_CLK_DIV6_EXT(VCLKCR3, 0,
  343. vck_parent, ARRAY_SIZE(vck_parent), 12, 3),
  344. [DIV6_ZB1] = SH_CLK_DIV6_EXT(ZBCKCR, CLK_ENABLE_ON_INIT,
  345. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  346. [DIV6_FLCTL] = SH_CLK_DIV6_EXT(FLCKCR, 0,
  347. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  348. [DIV6_SDHI0] = SH_CLK_DIV6_EXT(SD0CKCR, 0,
  349. pll_parent, ARRAY_SIZE(pll_parent), 6, 2),
  350. [DIV6_SDHI1] = SH_CLK_DIV6_EXT(SD1CKCR, 0,
  351. pll_parent, ARRAY_SIZE(pll_parent), 6, 2),
  352. [DIV6_SDHI2] = SH_CLK_DIV6_EXT(SD2CKCR, 0,
  353. pll_parent, ARRAY_SIZE(pll_parent), 6, 2),
  354. [DIV6_FSIA] = SH_CLK_DIV6_EXT(FSIACKCR, 0,
  355. pll_parent, ARRAY_SIZE(pll_parent), 6, 1),
  356. [DIV6_FSIB] = SH_CLK_DIV6_EXT(FSIBCKCR, 0,
  357. pll_parent, ARRAY_SIZE(pll_parent), 6, 1),
  358. [DIV6_SUB] = SH_CLK_DIV6_EXT(SUBCKCR, 0,
  359. pll_extal2_parent, ARRAY_SIZE(pll_extal2_parent), 6, 2),
  360. [DIV6_SPUA] = SH_CLK_DIV6_EXT(SPUACKCR, 0,
  361. pll_extal2_parent, ARRAY_SIZE(pll_extal2_parent), 6, 2),
  362. [DIV6_SPUV] = SH_CLK_DIV6_EXT(SPUVCKCR, 0,
  363. pll_extal2_parent, ARRAY_SIZE(pll_extal2_parent), 6, 2),
  364. [DIV6_MSU] = SH_CLK_DIV6_EXT(MSUCKCR, 0,
  365. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  366. [DIV6_HSI] = SH_CLK_DIV6_EXT(HSICKCR, 0,
  367. hsi_parent, ARRAY_SIZE(hsi_parent), 6, 2),
  368. [DIV6_MFG1] = SH_CLK_DIV6_EXT(MFCK1CR, 0,
  369. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  370. [DIV6_MFG2] = SH_CLK_DIV6_EXT(MFCK2CR, 0,
  371. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  372. [DIV6_DSIT] = SH_CLK_DIV6_EXT(DSITCKCR, 0,
  373. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  374. [DIV6_DSI0P] = SH_CLK_DIV6_EXT(DSI0PCKCR, 0,
  375. dsi_parent, ARRAY_SIZE(dsi_parent), 12, 3),
  376. [DIV6_DSI1P] = SH_CLK_DIV6_EXT(DSI1PCKCR, 0,
  377. dsi_parent, ARRAY_SIZE(dsi_parent), 12, 3),
  378. };
  379. /* DSI DIV */
  380. static unsigned long dsiphy_recalc(struct clk *clk)
  381. {
  382. u32 value;
  383. value = __raw_readl(clk->mapping->base);
  384. /* FIXME */
  385. if (!(value & 0x000B8000))
  386. return clk->parent->rate;
  387. value &= 0x3f;
  388. value += 1;
  389. if ((value < 12) ||
  390. (value > 33)) {
  391. pr_err("DSIPHY has wrong value (%d)", value);
  392. return 0;
  393. }
  394. return clk->parent->rate / value;
  395. }
  396. static long dsiphy_round_rate(struct clk *clk, unsigned long rate)
  397. {
  398. return clk_rate_mult_range_round(clk, 12, 33, rate);
  399. }
  400. static void dsiphy_disable(struct clk *clk)
  401. {
  402. u32 value;
  403. value = __raw_readl(clk->mapping->base);
  404. value &= ~0x000B8000;
  405. __raw_writel(value , clk->mapping->base);
  406. }
  407. static int dsiphy_enable(struct clk *clk)
  408. {
  409. u32 value;
  410. int multi;
  411. value = __raw_readl(clk->mapping->base);
  412. multi = (value & 0x3f) + 1;
  413. if ((multi < 12) || (multi > 33))
  414. return -EIO;
  415. __raw_writel(value | 0x000B8000, clk->mapping->base);
  416. return 0;
  417. }
  418. static int dsiphy_set_rate(struct clk *clk, unsigned long rate)
  419. {
  420. u32 value;
  421. int idx;
  422. idx = rate / clk->parent->rate;
  423. if ((idx < 12) || (idx > 33))
  424. return -EINVAL;
  425. idx += -1;
  426. value = __raw_readl(clk->mapping->base);
  427. value = (value & ~0x3f) + idx;
  428. __raw_writel(value, clk->mapping->base);
  429. return 0;
  430. }
  431. static struct sh_clk_ops dsiphy_clk_ops = {
  432. .recalc = dsiphy_recalc,
  433. .round_rate = dsiphy_round_rate,
  434. .set_rate = dsiphy_set_rate,
  435. .enable = dsiphy_enable,
  436. .disable = dsiphy_disable,
  437. };
  438. static struct clk_mapping dsi0phy_clk_mapping = {
  439. .phys = DSI0PHYCR,
  440. .len = 4,
  441. };
  442. static struct clk_mapping dsi1phy_clk_mapping = {
  443. .phys = DSI1PHYCR,
  444. .len = 4,
  445. };
  446. static struct clk dsi0phy_clk = {
  447. .ops = &dsiphy_clk_ops,
  448. .parent = &div6_clks[DIV6_DSI0P], /* late install */
  449. .mapping = &dsi0phy_clk_mapping,
  450. };
  451. static struct clk dsi1phy_clk = {
  452. .ops = &dsiphy_clk_ops,
  453. .parent = &div6_clks[DIV6_DSI1P], /* late install */
  454. .mapping = &dsi1phy_clk_mapping,
  455. };
  456. static struct clk *late_main_clks[] = {
  457. &dsi0phy_clk,
  458. &dsi1phy_clk,
  459. &twd_clk,
  460. };
  461. enum { MSTP001,
  462. MSTP129, MSTP128, MSTP127, MSTP126, MSTP125, MSTP118, MSTP116, MSTP112, MSTP100,
  463. MSTP219, MSTP218, MSTP217,
  464. MSTP207, MSTP206, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,
  465. MSTP331, MSTP329, MSTP328, MSTP325, MSTP323, MSTP322,
  466. MSTP314, MSTP313, MSTP312, MSTP311,
  467. MSTP304, MSTP303, MSTP302, MSTP301, MSTP300,
  468. MSTP411, MSTP410, MSTP403,
  469. MSTP508,
  470. MSTP_NR };
  471. #define MSTP(_parent, _reg, _bit, _flags) \
  472. SH_CLK_MSTP32(_parent, _reg, _bit, _flags)
  473. static struct clk mstp_clks[MSTP_NR] = {
  474. [MSTP001] = MSTP(&div4_clks[DIV4_HP], SMSTPCR0, 1, 0), /* IIC2 */
  475. [MSTP129] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 29, 0), /* CEU1 */
  476. [MSTP128] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 28, 0), /* CSI2-RX1 */
  477. [MSTP127] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 27, 0), /* CEU0 */
  478. [MSTP126] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 26, 0), /* CSI2-RX0 */
  479. [MSTP125] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR1, 25, 0), /* TMU0 */
  480. [MSTP118] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 18, 0), /* DSITX0 */
  481. [MSTP116] = MSTP(&div4_clks[DIV4_HP], SMSTPCR1, 16, 0), /* IIC0 */
  482. [MSTP112] = MSTP(&div4_clks[DIV4_ZG], SMSTPCR1, 12, 0), /* SGX */
  483. [MSTP100] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 0, 0), /* LCDC0 */
  484. [MSTP219] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 19, 0), /* SCIFA7 */
  485. [MSTP218] = MSTP(&div4_clks[DIV4_HP], SMSTPCR2, 18, 0), /* SY-DMAC */
  486. [MSTP217] = MSTP(&div4_clks[DIV4_HP], SMSTPCR2, 17, 0), /* MP-DMAC */
  487. [MSTP207] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 7, 0), /* SCIFA5 */
  488. [MSTP206] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 6, 0), /* SCIFB */
  489. [MSTP204] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 4, 0), /* SCIFA0 */
  490. [MSTP203] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 3, 0), /* SCIFA1 */
  491. [MSTP202] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 2, 0), /* SCIFA2 */
  492. [MSTP201] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 1, 0), /* SCIFA3 */
  493. [MSTP200] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 0, 0), /* SCIFA4 */
  494. [MSTP331] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR3, 31, 0), /* SCIFA6 */
  495. [MSTP329] = MSTP(&r_clk, SMSTPCR3, 29, 0), /* CMT10 */
  496. [MSTP328] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 28, 0), /*FSI*/
  497. [MSTP325] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR3, 25, 0), /* IrDA */
  498. [MSTP323] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 23, 0), /* IIC1 */
  499. [MSTP322] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 22, 0), /* USB */
  500. [MSTP314] = MSTP(&div6_clks[DIV6_SDHI0], SMSTPCR3, 14, 0), /* SDHI0 */
  501. [MSTP313] = MSTP(&div6_clks[DIV6_SDHI1], SMSTPCR3, 13, 0), /* SDHI1 */
  502. [MSTP312] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 12, 0), /* MMCIF0 */
  503. [MSTP311] = MSTP(&div6_clks[DIV6_SDHI2], SMSTPCR3, 11, 0), /* SDHI2 */
  504. [MSTP304] = MSTP(&main_div2_clk, SMSTPCR3, 4, 0), /* TPU0 */
  505. [MSTP303] = MSTP(&main_div2_clk, SMSTPCR3, 3, 0), /* TPU1 */
  506. [MSTP302] = MSTP(&main_div2_clk, SMSTPCR3, 2, 0), /* TPU2 */
  507. [MSTP301] = MSTP(&main_div2_clk, SMSTPCR3, 1, 0), /* TPU3 */
  508. [MSTP300] = MSTP(&main_div2_clk, SMSTPCR3, 0, 0), /* TPU4 */
  509. [MSTP411] = MSTP(&div4_clks[DIV4_HP], SMSTPCR4, 11, 0), /* IIC3 */
  510. [MSTP410] = MSTP(&div4_clks[DIV4_HP], SMSTPCR4, 10, 0), /* IIC4 */
  511. [MSTP403] = MSTP(&r_clk, SMSTPCR4, 3, 0), /* KEYSC */
  512. [MSTP508] = MSTP(&div4_clks[DIV4_HP], SMSTPCR5, 8, 0), /* INTCA0 */
  513. };
  514. /* The lookups structure below includes duplicate entries for some clocks
  515. * with alternate names.
  516. * - The traditional name used when a device is initialised with platform data
  517. * - The name used when a device is initialised using device tree
  518. * The longer-term aim is to remove these duplicates, and indeed the
  519. * lookups table entirely, by describing clocks using device tree.
  520. */
  521. static struct clk_lookup lookups[] = {
  522. /* main clocks */
  523. CLKDEV_CON_ID("r_clk", &r_clk),
  524. CLKDEV_DEV_ID("smp_twd", &twd_clk), /* smp_twd */
  525. /* DIV4 clocks */
  526. CLKDEV_DEV_ID("cpu0", &div4_clks[DIV4_Z]),
  527. /* DIV6 clocks */
  528. CLKDEV_CON_ID("vck1_clk", &div6_clks[DIV6_VCK1]),
  529. CLKDEV_CON_ID("vck2_clk", &div6_clks[DIV6_VCK2]),
  530. CLKDEV_CON_ID("vck3_clk", &div6_clks[DIV6_VCK3]),
  531. CLKDEV_CON_ID("sdhi0_clk", &div6_clks[DIV6_SDHI0]),
  532. CLKDEV_CON_ID("sdhi1_clk", &div6_clks[DIV6_SDHI1]),
  533. CLKDEV_CON_ID("sdhi2_clk", &div6_clks[DIV6_SDHI2]),
  534. /* MSTP32 clocks */
  535. CLKDEV_DEV_ID("i2c-sh_mobile.2", &mstp_clks[MSTP001]), /* I2C2 */
  536. CLKDEV_DEV_ID("e6824000.i2c", &mstp_clks[MSTP001]), /* I2C2 */
  537. CLKDEV_DEV_ID("sh_mobile_ceu.1", &mstp_clks[MSTP129]), /* CEU1 */
  538. CLKDEV_DEV_ID("sh-mobile-csi2.1", &mstp_clks[MSTP128]), /* CSI2-RX1 */
  539. CLKDEV_DEV_ID("sh_mobile_ceu.0", &mstp_clks[MSTP127]), /* CEU0 */
  540. CLKDEV_DEV_ID("sh-mobile-csi2.0", &mstp_clks[MSTP126]), /* CSI2-RX0 */
  541. CLKDEV_DEV_ID("sh-mipi-dsi.0", &mstp_clks[MSTP118]), /* DSITX */
  542. CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks[MSTP116]), /* I2C0 */
  543. CLKDEV_DEV_ID("e6820000.i2c", &mstp_clks[MSTP116]), /* I2C0 */
  544. CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks[MSTP100]), /* LCDC0 */
  545. CLKDEV_DEV_ID("sh-sci.7", &mstp_clks[MSTP219]), /* SCIFA7 */
  546. CLKDEV_DEV_ID("e6cd0000.serial", &mstp_clks[MSTP219]), /* SCIFA7 */
  547. CLKDEV_DEV_ID("sh-dma-engine.0", &mstp_clks[MSTP218]), /* SY-DMAC */
  548. CLKDEV_DEV_ID("sh-dma-engine.1", &mstp_clks[MSTP217]), /* MP-DMAC */
  549. CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP207]), /* SCIFA5 */
  550. CLKDEV_DEV_ID("e6cb0000.serial", &mstp_clks[MSTP207]), /* SCIFA5 */
  551. CLKDEV_DEV_ID("sh-sci.8", &mstp_clks[MSTP206]), /* SCIFB */
  552. CLKDEV_DEV_ID("e6c3000.serial", &mstp_clks[MSTP206]), /* SCIFB */
  553. CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]), /* SCIFA0 */
  554. CLKDEV_DEV_ID("e6c40000.serial", &mstp_clks[MSTP204]), /* SCIFA0 */
  555. CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]), /* SCIFA1 */
  556. CLKDEV_DEV_ID("e6c50000.serial", &mstp_clks[MSTP203]), /* SCIFA1 */
  557. CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP202]), /* SCIFA2 */
  558. CLKDEV_DEV_ID("e6c60000.serial", &mstp_clks[MSTP202]), /* SCIFA2 */
  559. CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP201]), /* SCIFA3 */
  560. CLKDEV_DEV_ID("e6c70000.serial", &mstp_clks[MSTP201]), /* SCIFA3 */
  561. CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP200]), /* SCIFA4 */
  562. CLKDEV_DEV_ID("e6c80000.serial", &mstp_clks[MSTP200]), /* SCIFA4 */
  563. CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP331]), /* SCIFA6 */
  564. CLKDEV_DEV_ID("e6cc0000.serial", &mstp_clks[MSTP331]), /* SCIFA6 */
  565. CLKDEV_DEV_ID("sh_fsi2", &mstp_clks[MSTP328]), /* FSI */
  566. CLKDEV_DEV_ID("ec230000.sound", &mstp_clks[MSTP328]), /* FSI */
  567. CLKDEV_DEV_ID("sh_irda.0", &mstp_clks[MSTP325]), /* IrDA */
  568. CLKDEV_DEV_ID("i2c-sh_mobile.1", &mstp_clks[MSTP323]), /* I2C1 */
  569. CLKDEV_DEV_ID("e6822000.i2c", &mstp_clks[MSTP323]), /* I2C1 */
  570. CLKDEV_DEV_ID("renesas_usbhs", &mstp_clks[MSTP322]), /* USB */
  571. CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP314]), /* SDHI0 */
  572. CLKDEV_DEV_ID("ee100000.sd", &mstp_clks[MSTP314]), /* SDHI0 */
  573. CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP313]), /* SDHI1 */
  574. CLKDEV_DEV_ID("ee120000.sd", &mstp_clks[MSTP313]), /* SDHI1 */
  575. CLKDEV_DEV_ID("sh_mmcif.0", &mstp_clks[MSTP312]), /* MMCIF0 */
  576. CLKDEV_DEV_ID("e6bd0000.mmc", &mstp_clks[MSTP312]), /* MMCIF0 */
  577. CLKDEV_DEV_ID("sh_mobile_sdhi.2", &mstp_clks[MSTP311]), /* SDHI2 */
  578. CLKDEV_DEV_ID("ee140000.sd", &mstp_clks[MSTP311]), /* SDHI2 */
  579. CLKDEV_DEV_ID("renesas-tpu-pwm.0", &mstp_clks[MSTP304]), /* TPU0 */
  580. CLKDEV_DEV_ID("renesas-tpu-pwm.1", &mstp_clks[MSTP303]), /* TPU1 */
  581. CLKDEV_DEV_ID("renesas-tpu-pwm.2", &mstp_clks[MSTP302]), /* TPU2 */
  582. CLKDEV_DEV_ID("renesas-tpu-pwm.3", &mstp_clks[MSTP301]), /* TPU3 */
  583. CLKDEV_DEV_ID("renesas-tpu-pwm.4", &mstp_clks[MSTP300]), /* TPU4 */
  584. CLKDEV_DEV_ID("i2c-sh_mobile.3", &mstp_clks[MSTP411]), /* I2C3 */
  585. CLKDEV_DEV_ID("e6826000.i2c", &mstp_clks[MSTP411]), /* I2C3 */
  586. CLKDEV_DEV_ID("i2c-sh_mobile.4", &mstp_clks[MSTP410]), /* I2C4 */
  587. CLKDEV_DEV_ID("e6828000.i2c", &mstp_clks[MSTP410]), /* I2C4 */
  588. CLKDEV_DEV_ID("sh_keysc.0", &mstp_clks[MSTP403]), /* KEYSC */
  589. CLKDEV_DEV_ID("renesas_intc_irqpin.0", &mstp_clks[MSTP508]), /* INTCA0 */
  590. CLKDEV_DEV_ID("e6900000.irqpin", &mstp_clks[MSTP508]), /* INTCA0 */
  591. CLKDEV_DEV_ID("renesas_intc_irqpin.1", &mstp_clks[MSTP508]), /* INTCA0 */
  592. CLKDEV_DEV_ID("e6900004.irqpin", &mstp_clks[MSTP508]), /* INTCA0 */
  593. CLKDEV_DEV_ID("renesas_intc_irqpin.2", &mstp_clks[MSTP508]), /* INTCA0 */
  594. CLKDEV_DEV_ID("e6900008.irqpin", &mstp_clks[MSTP508]), /* INTCA0 */
  595. CLKDEV_DEV_ID("renesas_intc_irqpin.3", &mstp_clks[MSTP508]), /* INTCA0 */
  596. CLKDEV_DEV_ID("e690000c.irqpin", &mstp_clks[MSTP508]), /* INTCA0 */
  597. /* ICK */
  598. CLKDEV_ICK_ID("dsit_clk", "sh-mipi-dsi.0", &div6_clks[DIV6_DSIT]),
  599. CLKDEV_ICK_ID("dsit_clk", "sh-mipi-dsi.1", &div6_clks[DIV6_DSIT]),
  600. CLKDEV_ICK_ID("dsip_clk", "sh-mipi-dsi.0", &div6_clks[DIV6_DSI0P]),
  601. CLKDEV_ICK_ID("dsip_clk", "sh-mipi-dsi.1", &div6_clks[DIV6_DSI1P]),
  602. CLKDEV_ICK_ID("dsiphy_clk", "sh-mipi-dsi.0", &dsi0phy_clk),
  603. CLKDEV_ICK_ID("dsiphy_clk", "sh-mipi-dsi.1", &dsi1phy_clk),
  604. CLKDEV_ICK_ID("fck", "sh-cmt-48.1", &mstp_clks[MSTP329]), /* CMT1 */
  605. CLKDEV_ICK_ID("fck", "e6138000.timer", &mstp_clks[MSTP329]), /* CMT1 */
  606. CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[MSTP125]), /* TMU0 */
  607. };
  608. void __init sh73a0_clock_init(void)
  609. {
  610. int k, ret = 0;
  611. /* Set SDHI clocks to a known state */
  612. __raw_writel(0x108, SD0CKCR);
  613. __raw_writel(0x108, SD1CKCR);
  614. __raw_writel(0x108, SD2CKCR);
  615. /* detect main clock parent */
  616. switch ((__raw_readl(CKSCR) >> 28) & 0x03) {
  617. case 0:
  618. main_clk.parent = &sh73a0_extal1_clk;
  619. break;
  620. case 1:
  621. main_clk.parent = &extal1_div2_clk;
  622. break;
  623. case 2:
  624. main_clk.parent = &sh73a0_extal2_clk;
  625. break;
  626. case 3:
  627. main_clk.parent = &extal2_div2_clk;
  628. break;
  629. }
  630. for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
  631. ret = clk_register(main_clks[k]);
  632. if (!ret) {
  633. ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
  634. if (!ret)
  635. div4_clk_extend();
  636. }
  637. if (!ret)
  638. ret = sh_clk_div6_reparent_register(div6_clks, DIV6_NR);
  639. if (!ret)
  640. ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);
  641. for (k = 0; !ret && (k < ARRAY_SIZE(late_main_clks)); k++)
  642. ret = clk_register(late_main_clks[k]);
  643. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  644. if (!ret)
  645. shmobile_clk_init();
  646. else
  647. panic("failed to setup sh73a0 clocks\n");
  648. }