clock-sh73a0.c 22 KB

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