clock-sh73a0.c 19 KB

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