clock-sh73a0.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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 int (*div4_set_rate)(struct clk *clk, unsigned long rate);
  228. static unsigned long (*div4_recalc)(struct clk *clk);
  229. static long (*div4_round_rate)(struct clk *clk, unsigned long rate);
  230. static int zclk_set_rate(struct clk *clk, unsigned long rate)
  231. {
  232. int ret;
  233. if (!clk->parent || !__clk_get(clk->parent))
  234. return -ENODEV;
  235. if (readl(FRQCRB) & (1 << 31))
  236. return -EBUSY;
  237. if (rate == clk_get_rate(clk->parent)) {
  238. /* 1:1 - switch off divider */
  239. __raw_writel(__raw_readl(FRQCRB) & ~(1 << 28), FRQCRB);
  240. /* nullify the divider to prepare for the next time */
  241. ret = div4_set_rate(clk, rate / 2);
  242. if (!ret)
  243. ret = frqcr_kick();
  244. if (ret > 0)
  245. ret = 0;
  246. } else {
  247. /* Enable the divider */
  248. __raw_writel(__raw_readl(FRQCRB) | (1 << 28), FRQCRB);
  249. ret = frqcr_kick();
  250. if (ret >= 0)
  251. /*
  252. * set the divider - call the DIV4 method, it will kick
  253. * FRQCRB too
  254. */
  255. ret = div4_set_rate(clk, rate);
  256. if (ret < 0)
  257. goto esetrate;
  258. }
  259. esetrate:
  260. __clk_put(clk->parent);
  261. return ret;
  262. }
  263. static long zclk_round_rate(struct clk *clk, unsigned long rate)
  264. {
  265. unsigned long div_freq = div4_round_rate(clk, rate),
  266. parent_freq = clk_get_rate(clk->parent);
  267. if (rate > div_freq && abs(parent_freq - rate) < rate - div_freq)
  268. return parent_freq;
  269. return div_freq;
  270. }
  271. static unsigned long zclk_recalc(struct clk *clk)
  272. {
  273. /*
  274. * Must recalculate frequencies in case PLL0 has been changed, even if
  275. * the divisor is unused ATM!
  276. */
  277. unsigned long div_freq = div4_recalc(clk);
  278. if (__raw_readl(FRQCRB) & (1 << 28))
  279. return div_freq;
  280. return clk_get_rate(clk->parent);
  281. }
  282. static void zclk_extend(void)
  283. {
  284. /* We extend the DIV4 clock with a 1:1 pass-through case */
  285. div4_set_rate = div4_clks[DIV4_Z].ops->set_rate;
  286. div4_round_rate = div4_clks[DIV4_Z].ops->round_rate;
  287. div4_recalc = div4_clks[DIV4_Z].ops->recalc;
  288. div4_clks[DIV4_Z].ops->set_rate = zclk_set_rate;
  289. div4_clks[DIV4_Z].ops->round_rate = zclk_round_rate;
  290. div4_clks[DIV4_Z].ops->recalc = zclk_recalc;
  291. }
  292. enum { DIV6_VCK1, DIV6_VCK2, DIV6_VCK3, DIV6_ZB1,
  293. DIV6_FLCTL, DIV6_SDHI0, DIV6_SDHI1, DIV6_SDHI2,
  294. DIV6_FSIA, DIV6_FSIB, DIV6_SUB,
  295. DIV6_SPUA, DIV6_SPUV, DIV6_MSU,
  296. DIV6_HSI, DIV6_MFG1, DIV6_MFG2,
  297. DIV6_DSIT, DIV6_DSI0P, DIV6_DSI1P,
  298. DIV6_NR };
  299. static struct clk *vck_parent[8] = {
  300. [0] = &pll1_div2_clk,
  301. [1] = &pll2_clk,
  302. [2] = &sh73a0_extcki_clk,
  303. [3] = &sh73a0_extal2_clk,
  304. [4] = &main_div2_clk,
  305. [5] = &sh73a0_extalr_clk,
  306. [6] = &main_clk,
  307. };
  308. static struct clk *pll_parent[4] = {
  309. [0] = &pll1_div2_clk,
  310. [1] = &pll2_clk,
  311. [2] = &pll1_div13_clk,
  312. };
  313. static struct clk *hsi_parent[4] = {
  314. [0] = &pll1_div2_clk,
  315. [1] = &pll2_clk,
  316. [2] = &pll1_div7_clk,
  317. };
  318. static struct clk *pll_extal2_parent[] = {
  319. [0] = &pll1_div2_clk,
  320. [1] = &pll2_clk,
  321. [2] = &sh73a0_extal2_clk,
  322. [3] = &sh73a0_extal2_clk,
  323. };
  324. static struct clk *dsi_parent[8] = {
  325. [0] = &pll1_div2_clk,
  326. [1] = &pll2_clk,
  327. [2] = &main_clk,
  328. [3] = &sh73a0_extal2_clk,
  329. [4] = &sh73a0_extcki_clk,
  330. };
  331. static struct clk div6_clks[DIV6_NR] = {
  332. [DIV6_VCK1] = SH_CLK_DIV6_EXT(VCLKCR1, 0,
  333. vck_parent, ARRAY_SIZE(vck_parent), 12, 3),
  334. [DIV6_VCK2] = SH_CLK_DIV6_EXT(VCLKCR2, 0,
  335. vck_parent, ARRAY_SIZE(vck_parent), 12, 3),
  336. [DIV6_VCK3] = SH_CLK_DIV6_EXT(VCLKCR3, 0,
  337. vck_parent, ARRAY_SIZE(vck_parent), 12, 3),
  338. [DIV6_ZB1] = SH_CLK_DIV6_EXT(ZBCKCR, CLK_ENABLE_ON_INIT,
  339. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  340. [DIV6_FLCTL] = SH_CLK_DIV6_EXT(FLCKCR, 0,
  341. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  342. [DIV6_SDHI0] = SH_CLK_DIV6_EXT(SD0CKCR, 0,
  343. pll_parent, ARRAY_SIZE(pll_parent), 6, 2),
  344. [DIV6_SDHI1] = SH_CLK_DIV6_EXT(SD1CKCR, 0,
  345. pll_parent, ARRAY_SIZE(pll_parent), 6, 2),
  346. [DIV6_SDHI2] = SH_CLK_DIV6_EXT(SD2CKCR, 0,
  347. pll_parent, ARRAY_SIZE(pll_parent), 6, 2),
  348. [DIV6_FSIA] = SH_CLK_DIV6_EXT(FSIACKCR, 0,
  349. pll_parent, ARRAY_SIZE(pll_parent), 6, 1),
  350. [DIV6_FSIB] = SH_CLK_DIV6_EXT(FSIBCKCR, 0,
  351. pll_parent, ARRAY_SIZE(pll_parent), 6, 1),
  352. [DIV6_SUB] = SH_CLK_DIV6_EXT(SUBCKCR, 0,
  353. pll_extal2_parent, ARRAY_SIZE(pll_extal2_parent), 6, 2),
  354. [DIV6_SPUA] = SH_CLK_DIV6_EXT(SPUACKCR, 0,
  355. pll_extal2_parent, ARRAY_SIZE(pll_extal2_parent), 6, 2),
  356. [DIV6_SPUV] = SH_CLK_DIV6_EXT(SPUVCKCR, 0,
  357. pll_extal2_parent, ARRAY_SIZE(pll_extal2_parent), 6, 2),
  358. [DIV6_MSU] = SH_CLK_DIV6_EXT(MSUCKCR, 0,
  359. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  360. [DIV6_HSI] = SH_CLK_DIV6_EXT(HSICKCR, 0,
  361. hsi_parent, ARRAY_SIZE(hsi_parent), 6, 2),
  362. [DIV6_MFG1] = SH_CLK_DIV6_EXT(MFCK1CR, 0,
  363. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  364. [DIV6_MFG2] = SH_CLK_DIV6_EXT(MFCK2CR, 0,
  365. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  366. [DIV6_DSIT] = SH_CLK_DIV6_EXT(DSITCKCR, 0,
  367. pll_parent, ARRAY_SIZE(pll_parent), 7, 1),
  368. [DIV6_DSI0P] = SH_CLK_DIV6_EXT(DSI0PCKCR, 0,
  369. dsi_parent, ARRAY_SIZE(dsi_parent), 12, 3),
  370. [DIV6_DSI1P] = SH_CLK_DIV6_EXT(DSI1PCKCR, 0,
  371. dsi_parent, ARRAY_SIZE(dsi_parent), 12, 3),
  372. };
  373. /* DSI DIV */
  374. static unsigned long dsiphy_recalc(struct clk *clk)
  375. {
  376. u32 value;
  377. value = __raw_readl(clk->mapping->base);
  378. /* FIXME */
  379. if (!(value & 0x000B8000))
  380. return clk->parent->rate;
  381. value &= 0x3f;
  382. value += 1;
  383. if ((value < 12) ||
  384. (value > 33)) {
  385. pr_err("DSIPHY has wrong value (%d)", value);
  386. return 0;
  387. }
  388. return clk->parent->rate / value;
  389. }
  390. static long dsiphy_round_rate(struct clk *clk, unsigned long rate)
  391. {
  392. return clk_rate_mult_range_round(clk, 12, 33, rate);
  393. }
  394. static void dsiphy_disable(struct clk *clk)
  395. {
  396. u32 value;
  397. value = __raw_readl(clk->mapping->base);
  398. value &= ~0x000B8000;
  399. __raw_writel(value , clk->mapping->base);
  400. }
  401. static int dsiphy_enable(struct clk *clk)
  402. {
  403. u32 value;
  404. int multi;
  405. value = __raw_readl(clk->mapping->base);
  406. multi = (value & 0x3f) + 1;
  407. if ((multi < 12) || (multi > 33))
  408. return -EIO;
  409. __raw_writel(value | 0x000B8000, clk->mapping->base);
  410. return 0;
  411. }
  412. static int dsiphy_set_rate(struct clk *clk, unsigned long rate)
  413. {
  414. u32 value;
  415. int idx;
  416. idx = rate / clk->parent->rate;
  417. if ((idx < 12) || (idx > 33))
  418. return -EINVAL;
  419. idx += -1;
  420. value = __raw_readl(clk->mapping->base);
  421. value = (value & ~0x3f) + idx;
  422. __raw_writel(value, clk->mapping->base);
  423. return 0;
  424. }
  425. static struct sh_clk_ops dsiphy_clk_ops = {
  426. .recalc = dsiphy_recalc,
  427. .round_rate = dsiphy_round_rate,
  428. .set_rate = dsiphy_set_rate,
  429. .enable = dsiphy_enable,
  430. .disable = dsiphy_disable,
  431. };
  432. static struct clk_mapping dsi0phy_clk_mapping = {
  433. .phys = DSI0PHYCR,
  434. .len = 4,
  435. };
  436. static struct clk_mapping dsi1phy_clk_mapping = {
  437. .phys = DSI1PHYCR,
  438. .len = 4,
  439. };
  440. static struct clk dsi0phy_clk = {
  441. .ops = &dsiphy_clk_ops,
  442. .parent = &div6_clks[DIV6_DSI0P], /* late install */
  443. .mapping = &dsi0phy_clk_mapping,
  444. };
  445. static struct clk dsi1phy_clk = {
  446. .ops = &dsiphy_clk_ops,
  447. .parent = &div6_clks[DIV6_DSI1P], /* late install */
  448. .mapping = &dsi1phy_clk_mapping,
  449. };
  450. static struct clk *late_main_clks[] = {
  451. &dsi0phy_clk,
  452. &dsi1phy_clk,
  453. &twd_clk,
  454. };
  455. enum { MSTP001,
  456. MSTP129, MSTP128, MSTP127, MSTP126, MSTP125, MSTP118, MSTP116, MSTP112, MSTP100,
  457. MSTP219, MSTP218, MSTP217,
  458. MSTP207, MSTP206, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,
  459. MSTP331, MSTP329, MSTP328, MSTP325, MSTP323, MSTP322,
  460. MSTP314, MSTP313, MSTP312, MSTP311,
  461. MSTP303, MSTP302, MSTP301, MSTP300,
  462. MSTP411, MSTP410, MSTP403,
  463. MSTP_NR };
  464. #define MSTP(_parent, _reg, _bit, _flags) \
  465. SH_CLK_MSTP32(_parent, _reg, _bit, _flags)
  466. static struct clk mstp_clks[MSTP_NR] = {
  467. [MSTP001] = MSTP(&div4_clks[DIV4_HP], SMSTPCR0, 1, 0), /* IIC2 */
  468. [MSTP129] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 29, 0), /* CEU1 */
  469. [MSTP128] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 28, 0), /* CSI2-RX1 */
  470. [MSTP127] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 27, 0), /* CEU0 */
  471. [MSTP126] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 26, 0), /* CSI2-RX0 */
  472. [MSTP125] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR1, 25, 0), /* TMU0 */
  473. [MSTP118] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 18, 0), /* DSITX0 */
  474. [MSTP116] = MSTP(&div4_clks[DIV4_HP], SMSTPCR1, 16, 0), /* IIC0 */
  475. [MSTP112] = MSTP(&div4_clks[DIV4_ZG], SMSTPCR1, 12, 0), /* SGX */
  476. [MSTP100] = MSTP(&div4_clks[DIV4_B], SMSTPCR1, 0, 0), /* LCDC0 */
  477. [MSTP219] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 19, 0), /* SCIFA7 */
  478. [MSTP218] = MSTP(&div4_clks[DIV4_HP], SMSTPCR2, 18, 0), /* SY-DMAC */
  479. [MSTP217] = MSTP(&div4_clks[DIV4_HP], SMSTPCR2, 17, 0), /* MP-DMAC */
  480. [MSTP207] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 7, 0), /* SCIFA5 */
  481. [MSTP206] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 6, 0), /* SCIFB */
  482. [MSTP204] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 4, 0), /* SCIFA0 */
  483. [MSTP203] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 3, 0), /* SCIFA1 */
  484. [MSTP202] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 2, 0), /* SCIFA2 */
  485. [MSTP201] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 1, 0), /* SCIFA3 */
  486. [MSTP200] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR2, 0, 0), /* SCIFA4 */
  487. [MSTP331] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR3, 31, 0), /* SCIFA6 */
  488. [MSTP329] = MSTP(&r_clk, SMSTPCR3, 29, 0), /* CMT10 */
  489. [MSTP328] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 28, 0), /*FSI*/
  490. [MSTP325] = MSTP(&div6_clks[DIV6_SUB], SMSTPCR3, 25, 0), /* IrDA */
  491. [MSTP323] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 23, 0), /* IIC1 */
  492. [MSTP322] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 22, 0), /* USB */
  493. [MSTP314] = MSTP(&div6_clks[DIV6_SDHI0], SMSTPCR3, 14, 0), /* SDHI0 */
  494. [MSTP313] = MSTP(&div6_clks[DIV6_SDHI1], SMSTPCR3, 13, 0), /* SDHI1 */
  495. [MSTP312] = MSTP(&div4_clks[DIV4_HP], SMSTPCR3, 12, 0), /* MMCIF0 */
  496. [MSTP311] = MSTP(&div6_clks[DIV6_SDHI2], SMSTPCR3, 11, 0), /* SDHI2 */
  497. [MSTP303] = MSTP(&main_div2_clk, SMSTPCR3, 3, 0), /* TPU1 */
  498. [MSTP302] = MSTP(&main_div2_clk, SMSTPCR3, 2, 0), /* TPU2 */
  499. [MSTP301] = MSTP(&main_div2_clk, SMSTPCR3, 1, 0), /* TPU3 */
  500. [MSTP300] = MSTP(&main_div2_clk, SMSTPCR3, 0, 0), /* TPU4 */
  501. [MSTP411] = MSTP(&div4_clks[DIV4_HP], SMSTPCR4, 11, 0), /* IIC3 */
  502. [MSTP410] = MSTP(&div4_clks[DIV4_HP], SMSTPCR4, 10, 0), /* IIC4 */
  503. [MSTP403] = MSTP(&r_clk, SMSTPCR4, 3, 0), /* KEYSC */
  504. };
  505. /* The lookups structure below includes duplicate entries for some clocks
  506. * with alternate names.
  507. * - The traditional name used when a device is initialised with platform data
  508. * - The name used when a device is initialised using device tree
  509. * The longer-term aim is to remove these duplicates, and indeed the
  510. * lookups table entirely, by describing clocks using device tree.
  511. */
  512. static struct clk_lookup lookups[] = {
  513. /* main clocks */
  514. CLKDEV_CON_ID("r_clk", &r_clk),
  515. CLKDEV_DEV_ID("smp_twd", &twd_clk), /* smp_twd */
  516. /* DIV4 clocks */
  517. CLKDEV_DEV_ID("cpufreq-cpu0", &div4_clks[DIV4_Z]),
  518. /* DIV6 clocks */
  519. CLKDEV_CON_ID("vck1_clk", &div6_clks[DIV6_VCK1]),
  520. CLKDEV_CON_ID("vck2_clk", &div6_clks[DIV6_VCK2]),
  521. CLKDEV_CON_ID("vck3_clk", &div6_clks[DIV6_VCK3]),
  522. CLKDEV_CON_ID("sdhi0_clk", &div6_clks[DIV6_SDHI0]),
  523. CLKDEV_CON_ID("sdhi1_clk", &div6_clks[DIV6_SDHI1]),
  524. CLKDEV_CON_ID("sdhi2_clk", &div6_clks[DIV6_SDHI2]),
  525. CLKDEV_ICK_ID("dsit_clk", "sh-mipi-dsi.0", &div6_clks[DIV6_DSIT]),
  526. CLKDEV_ICK_ID("dsit_clk", "sh-mipi-dsi.1", &div6_clks[DIV6_DSIT]),
  527. CLKDEV_ICK_ID("dsip_clk", "sh-mipi-dsi.0", &div6_clks[DIV6_DSI0P]),
  528. CLKDEV_ICK_ID("dsip_clk", "sh-mipi-dsi.1", &div6_clks[DIV6_DSI1P]),
  529. CLKDEV_ICK_ID("dsiphy_clk", "sh-mipi-dsi.0", &dsi0phy_clk),
  530. CLKDEV_ICK_ID("dsiphy_clk", "sh-mipi-dsi.1", &dsi1phy_clk),
  531. /* MSTP32 clocks */
  532. CLKDEV_DEV_ID("i2c-sh_mobile.2", &mstp_clks[MSTP001]), /* I2C2 */
  533. CLKDEV_DEV_ID("e6824000.i2c", &mstp_clks[MSTP001]), /* I2C2 */
  534. CLKDEV_DEV_ID("sh_mobile_ceu.1", &mstp_clks[MSTP129]), /* CEU1 */
  535. CLKDEV_DEV_ID("sh-mobile-csi2.1", &mstp_clks[MSTP128]), /* CSI2-RX1 */
  536. CLKDEV_DEV_ID("sh_mobile_ceu.0", &mstp_clks[MSTP127]), /* CEU0 */
  537. CLKDEV_DEV_ID("sh-mobile-csi2.0", &mstp_clks[MSTP126]), /* CSI2-RX0 */
  538. CLKDEV_DEV_ID("sh_tmu.0", &mstp_clks[MSTP125]), /* TMU00 */
  539. CLKDEV_DEV_ID("sh_tmu.1", &mstp_clks[MSTP125]), /* TMU01 */
  540. CLKDEV_DEV_ID("sh-mipi-dsi.0", &mstp_clks[MSTP118]), /* DSITX */
  541. CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks[MSTP116]), /* I2C0 */
  542. CLKDEV_DEV_ID("e6820000.i2c", &mstp_clks[MSTP116]), /* I2C0 */
  543. CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks[MSTP100]), /* LCDC0 */
  544. CLKDEV_DEV_ID("sh-sci.7", &mstp_clks[MSTP219]), /* SCIFA7 */
  545. CLKDEV_DEV_ID("sh-dma-engine.0", &mstp_clks[MSTP218]), /* SY-DMAC */
  546. CLKDEV_DEV_ID("sh-dma-engine.1", &mstp_clks[MSTP217]), /* MP-DMAC */
  547. CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP207]), /* SCIFA5 */
  548. CLKDEV_DEV_ID("sh-sci.8", &mstp_clks[MSTP206]), /* SCIFB */
  549. CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]), /* SCIFA0 */
  550. CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]), /* SCIFA1 */
  551. CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP202]), /* SCIFA2 */
  552. CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP201]), /* SCIFA3 */
  553. CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP200]), /* SCIFA4 */
  554. CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP331]), /* SCIFA6 */
  555. CLKDEV_DEV_ID("sh_cmt.10", &mstp_clks[MSTP329]), /* CMT10 */
  556. CLKDEV_DEV_ID("sh_fsi2", &mstp_clks[MSTP328]), /* FSI */
  557. CLKDEV_DEV_ID("sh_irda.0", &mstp_clks[MSTP325]), /* IrDA */
  558. CLKDEV_DEV_ID("i2c-sh_mobile.1", &mstp_clks[MSTP323]), /* I2C1 */
  559. CLKDEV_DEV_ID("e6822000.i2c", &mstp_clks[MSTP323]), /* I2C1 */
  560. CLKDEV_DEV_ID("renesas_usbhs", &mstp_clks[MSTP322]), /* USB */
  561. CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP314]), /* SDHI0 */
  562. CLKDEV_DEV_ID("ee100000.sdhi", &mstp_clks[MSTP314]), /* SDHI0 */
  563. CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP313]), /* SDHI1 */
  564. CLKDEV_DEV_ID("ee120000.sdhi", &mstp_clks[MSTP313]), /* SDHI1 */
  565. CLKDEV_DEV_ID("sh_mmcif.0", &mstp_clks[MSTP312]), /* MMCIF0 */
  566. CLKDEV_DEV_ID("e6bd0000.mmcif", &mstp_clks[MSTP312]), /* MMCIF0 */
  567. CLKDEV_DEV_ID("sh_mobile_sdhi.2", &mstp_clks[MSTP311]), /* SDHI2 */
  568. CLKDEV_DEV_ID("ee140000.sdhi", &mstp_clks[MSTP311]), /* SDHI2 */
  569. CLKDEV_DEV_ID("leds-renesas-tpu.12", &mstp_clks[MSTP303]), /* TPU1 */
  570. CLKDEV_DEV_ID("leds-renesas-tpu.21", &mstp_clks[MSTP302]), /* TPU2 */
  571. CLKDEV_DEV_ID("leds-renesas-tpu.30", &mstp_clks[MSTP301]), /* TPU3 */
  572. CLKDEV_DEV_ID("leds-renesas-tpu.41", &mstp_clks[MSTP300]), /* TPU4 */
  573. CLKDEV_DEV_ID("i2c-sh_mobile.3", &mstp_clks[MSTP411]), /* I2C3 */
  574. CLKDEV_DEV_ID("e6826000.i2c", &mstp_clks[MSTP411]), /* I2C3 */
  575. CLKDEV_DEV_ID("i2c-sh_mobile.4", &mstp_clks[MSTP410]), /* I2C4 */
  576. CLKDEV_DEV_ID("e6828000.i2c", &mstp_clks[MSTP410]), /* I2C4 */
  577. CLKDEV_DEV_ID("sh_keysc.0", &mstp_clks[MSTP403]), /* KEYSC */
  578. };
  579. void __init sh73a0_clock_init(void)
  580. {
  581. int k, ret = 0;
  582. /* Set SDHI clocks to a known state */
  583. __raw_writel(0x108, SD0CKCR);
  584. __raw_writel(0x108, SD1CKCR);
  585. __raw_writel(0x108, SD2CKCR);
  586. /* detect main clock parent */
  587. switch ((__raw_readl(CKSCR) >> 28) & 0x03) {
  588. case 0:
  589. main_clk.parent = &sh73a0_extal1_clk;
  590. break;
  591. case 1:
  592. main_clk.parent = &extal1_div2_clk;
  593. break;
  594. case 2:
  595. main_clk.parent = &sh73a0_extal2_clk;
  596. break;
  597. case 3:
  598. main_clk.parent = &extal2_div2_clk;
  599. break;
  600. }
  601. for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
  602. ret = clk_register(main_clks[k]);
  603. if (!ret) {
  604. ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
  605. if (!ret)
  606. zclk_extend();
  607. }
  608. if (!ret)
  609. ret = sh_clk_div6_reparent_register(div6_clks, DIV6_NR);
  610. if (!ret)
  611. ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);
  612. for (k = 0; !ret && (k < ARRAY_SIZE(late_main_clks)); k++)
  613. ret = clk_register(late_main_clks[k]);
  614. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  615. if (!ret)
  616. shmobile_clk_init();
  617. else
  618. panic("failed to setup sh73a0 clocks\n");
  619. }