clock-r8a7740.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * R8A7740 processor support
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/init.h>
  21. #include <linux/kernel.h>
  22. #include <linux/io.h>
  23. #include <linux/sh_clk.h>
  24. #include <linux/clkdev.h>
  25. #include <mach/common.h>
  26. #include <mach/r8a7740.h>
  27. /*
  28. * | MDx | XTAL1/EXTAL1 | System | EXTALR |
  29. * Clock |-------+-----------------+ clock | 32.768 | RCLK
  30. * Mode | 2/1/0 | src MHz | source | KHz | source
  31. * -------+-------+-----------------+-----------+--------+----------
  32. * 0 | 0 0 0 | External 20~50 | XTAL1 | O | EXTALR
  33. * 1 | 0 0 1 | Crystal 20~30 | XTAL1 | O | EXTALR
  34. * 2 | 0 1 0 | External 40~50 | XTAL1 / 2 | O | EXTALR
  35. * 3 | 0 1 1 | Crystal 40~50 | XTAL1 / 2 | O | EXTALR
  36. * 4 | 1 0 0 | External 20~50 | XTAL1 | x | XTAL1 / 1024
  37. * 5 | 1 0 1 | Crystal 20~30 | XTAL1 | x | XTAL1 / 1024
  38. * 6 | 1 1 0 | External 40~50 | XTAL1 / 2 | x | XTAL1 / 2048
  39. * 7 | 1 1 1 | Crystal 40~50 | XTAL1 / 2 | x | XTAL1 / 2048
  40. */
  41. /* CPG registers */
  42. #define FRQCRA IOMEM(0xe6150000)
  43. #define FRQCRB IOMEM(0xe6150004)
  44. #define VCLKCR1 IOMEM(0xE6150008)
  45. #define VCLKCR2 IOMEM(0xE615000c)
  46. #define FRQCRC IOMEM(0xe61500e0)
  47. #define FSIACKCR IOMEM(0xe6150018)
  48. #define PLLC01CR IOMEM(0xe6150028)
  49. #define SUBCKCR IOMEM(0xe6150080)
  50. #define USBCKCR IOMEM(0xe615008c)
  51. #define MSTPSR0 IOMEM(0xe6150030)
  52. #define MSTPSR1 IOMEM(0xe6150038)
  53. #define MSTPSR2 IOMEM(0xe6150040)
  54. #define MSTPSR3 IOMEM(0xe6150048)
  55. #define MSTPSR4 IOMEM(0xe615004c)
  56. #define FSIBCKCR IOMEM(0xe6150090)
  57. #define HDMICKCR IOMEM(0xe6150094)
  58. #define SMSTPCR0 IOMEM(0xe6150130)
  59. #define SMSTPCR1 IOMEM(0xe6150134)
  60. #define SMSTPCR2 IOMEM(0xe6150138)
  61. #define SMSTPCR3 IOMEM(0xe615013c)
  62. #define SMSTPCR4 IOMEM(0xe6150140)
  63. #define FSIDIVA IOMEM(0xFE1F8000)
  64. #define FSIDIVB IOMEM(0xFE1F8008)
  65. /* Fixed 32 KHz root clock from EXTALR pin */
  66. static struct clk extalr_clk = {
  67. .rate = 32768,
  68. };
  69. /*
  70. * 25MHz default rate for the EXTAL1 root input clock.
  71. * If needed, reset this with clk_set_rate() from the platform code.
  72. */
  73. static struct clk extal1_clk = {
  74. .rate = 25000000,
  75. };
  76. /*
  77. * 48MHz default rate for the EXTAL2 root input clock.
  78. * If needed, reset this with clk_set_rate() from the platform code.
  79. */
  80. static struct clk extal2_clk = {
  81. .rate = 48000000,
  82. };
  83. /*
  84. * 27MHz default rate for the DV_CLKI root input clock.
  85. * If needed, reset this with clk_set_rate() from the platform code.
  86. */
  87. static struct clk dv_clk = {
  88. .rate = 27000000,
  89. };
  90. static unsigned long div_recalc(struct clk *clk)
  91. {
  92. return clk->parent->rate / (int)(clk->priv);
  93. }
  94. static struct sh_clk_ops div_clk_ops = {
  95. .recalc = div_recalc,
  96. };
  97. /* extal1 / 2 */
  98. static struct clk extal1_div2_clk = {
  99. .ops = &div_clk_ops,
  100. .priv = (void *)2,
  101. .parent = &extal1_clk,
  102. };
  103. /* extal1 / 1024 */
  104. static struct clk extal1_div1024_clk = {
  105. .ops = &div_clk_ops,
  106. .priv = (void *)1024,
  107. .parent = &extal1_clk,
  108. };
  109. /* extal1 / 2 / 1024 */
  110. static struct clk extal1_div2048_clk = {
  111. .ops = &div_clk_ops,
  112. .priv = (void *)1024,
  113. .parent = &extal1_div2_clk,
  114. };
  115. /* extal2 / 2 */
  116. static struct clk extal2_div2_clk = {
  117. .ops = &div_clk_ops,
  118. .priv = (void *)2,
  119. .parent = &extal2_clk,
  120. };
  121. static struct sh_clk_ops followparent_clk_ops = {
  122. .recalc = followparent_recalc,
  123. };
  124. /* Main clock */
  125. static struct clk system_clk = {
  126. .ops = &followparent_clk_ops,
  127. };
  128. static struct clk system_div2_clk = {
  129. .ops = &div_clk_ops,
  130. .priv = (void *)2,
  131. .parent = &system_clk,
  132. };
  133. /* r_clk */
  134. static struct clk r_clk = {
  135. .ops = &followparent_clk_ops,
  136. };
  137. /* PLLC0/PLLC1 */
  138. static unsigned long pllc01_recalc(struct clk *clk)
  139. {
  140. unsigned long mult = 1;
  141. if (__raw_readl(PLLC01CR) & (1 << 14))
  142. mult = ((__raw_readl(clk->enable_reg) >> 24) & 0x7f) + 1;
  143. return clk->parent->rate * mult;
  144. }
  145. static struct sh_clk_ops pllc01_clk_ops = {
  146. .recalc = pllc01_recalc,
  147. };
  148. static struct clk pllc0_clk = {
  149. .ops = &pllc01_clk_ops,
  150. .flags = CLK_ENABLE_ON_INIT,
  151. .parent = &system_clk,
  152. .enable_reg = (void __iomem *)FRQCRC,
  153. };
  154. static struct clk pllc1_clk = {
  155. .ops = &pllc01_clk_ops,
  156. .flags = CLK_ENABLE_ON_INIT,
  157. .parent = &system_div2_clk,
  158. .enable_reg = (void __iomem *)FRQCRA,
  159. };
  160. /* PLLC1 / 2 */
  161. static struct clk pllc1_div2_clk = {
  162. .ops = &div_clk_ops,
  163. .priv = (void *)2,
  164. .parent = &pllc1_clk,
  165. };
  166. /* USB clock */
  167. /*
  168. * USBCKCR is controlling usb24 clock
  169. * bit[7] : parent clock
  170. * bit[6] : clock divide rate
  171. * And this bit[7] is used as a "usb24s" from other devices.
  172. * (Video clock / Sub clock / SPU clock)
  173. * You can controll this clock as a below.
  174. *
  175. * struct clk *usb24 = clk_get(dev, "usb24");
  176. * struct clk *usb24s = clk_get(NULL, "usb24s");
  177. * struct clk *system = clk_get(NULL, "system_clk");
  178. * int rate = clk_get_rate(system);
  179. *
  180. * clk_set_parent(usb24s, system); // for bit[7]
  181. * clk_set_rate(usb24, rate / 2); // for bit[6]
  182. */
  183. static struct clk *usb24s_parents[] = {
  184. [0] = &system_clk,
  185. [1] = &extal2_clk
  186. };
  187. static int usb24s_enable(struct clk *clk)
  188. {
  189. __raw_writel(__raw_readl(USBCKCR) & ~(1 << 8), USBCKCR);
  190. return 0;
  191. }
  192. static void usb24s_disable(struct clk *clk)
  193. {
  194. __raw_writel(__raw_readl(USBCKCR) | (1 << 8), USBCKCR);
  195. }
  196. static int usb24s_set_parent(struct clk *clk, struct clk *parent)
  197. {
  198. int i, ret;
  199. u32 val;
  200. if (!clk->parent_table || !clk->parent_num)
  201. return -EINVAL;
  202. /* Search the parent */
  203. for (i = 0; i < clk->parent_num; i++)
  204. if (clk->parent_table[i] == parent)
  205. break;
  206. if (i == clk->parent_num)
  207. return -ENODEV;
  208. ret = clk_reparent(clk, parent);
  209. if (ret < 0)
  210. return ret;
  211. val = __raw_readl(USBCKCR);
  212. val &= ~(1 << 7);
  213. val |= i << 7;
  214. __raw_writel(val, USBCKCR);
  215. return 0;
  216. }
  217. static struct sh_clk_ops usb24s_clk_ops = {
  218. .recalc = followparent_recalc,
  219. .enable = usb24s_enable,
  220. .disable = usb24s_disable,
  221. .set_parent = usb24s_set_parent,
  222. };
  223. static struct clk usb24s_clk = {
  224. .ops = &usb24s_clk_ops,
  225. .parent_table = usb24s_parents,
  226. .parent_num = ARRAY_SIZE(usb24s_parents),
  227. .parent = &system_clk,
  228. };
  229. static unsigned long usb24_recalc(struct clk *clk)
  230. {
  231. return clk->parent->rate /
  232. ((__raw_readl(USBCKCR) & (1 << 6)) ? 1 : 2);
  233. };
  234. static int usb24_set_rate(struct clk *clk, unsigned long rate)
  235. {
  236. u32 val;
  237. /* closer to which ? parent->rate or parent->rate/2 */
  238. val = __raw_readl(USBCKCR);
  239. val &= ~(1 << 6);
  240. val |= (rate > (clk->parent->rate / 4) * 3) << 6;
  241. __raw_writel(val, USBCKCR);
  242. return 0;
  243. }
  244. static struct sh_clk_ops usb24_clk_ops = {
  245. .recalc = usb24_recalc,
  246. .set_rate = usb24_set_rate,
  247. };
  248. static struct clk usb24_clk = {
  249. .ops = &usb24_clk_ops,
  250. .parent = &usb24s_clk,
  251. };
  252. /* External FSIACK/FSIBCK clock */
  253. static struct clk fsiack_clk = {
  254. };
  255. static struct clk fsibck_clk = {
  256. };
  257. struct clk *main_clks[] = {
  258. &extalr_clk,
  259. &extal1_clk,
  260. &extal2_clk,
  261. &extal1_div2_clk,
  262. &extal1_div1024_clk,
  263. &extal1_div2048_clk,
  264. &extal2_div2_clk,
  265. &dv_clk,
  266. &system_clk,
  267. &system_div2_clk,
  268. &r_clk,
  269. &pllc0_clk,
  270. &pllc1_clk,
  271. &pllc1_div2_clk,
  272. &usb24s_clk,
  273. &usb24_clk,
  274. &fsiack_clk,
  275. &fsibck_clk,
  276. };
  277. static void div4_kick(struct clk *clk)
  278. {
  279. unsigned long value;
  280. /* set KICK bit in FRQCRB to update hardware setting */
  281. value = __raw_readl(FRQCRB);
  282. value |= (1 << 31);
  283. __raw_writel(value, FRQCRB);
  284. }
  285. static int divisors[] = { 2, 3, 4, 6, 8, 12, 16, 18,
  286. 24, 32, 36, 48, 0, 72, 96, 0 };
  287. static struct clk_div_mult_table div4_div_mult_table = {
  288. .divisors = divisors,
  289. .nr_divisors = ARRAY_SIZE(divisors),
  290. };
  291. static struct clk_div4_table div4_table = {
  292. .div_mult_table = &div4_div_mult_table,
  293. .kick = div4_kick,
  294. };
  295. /* DIV6 reparent */
  296. enum {
  297. DIV6_HDMI,
  298. DIV6_VCLK1, DIV6_VCLK2,
  299. DIV6_FSIA, DIV6_FSIB,
  300. DIV6_REPARENT_NR,
  301. };
  302. static struct clk *hdmi_parent[] = {
  303. [0] = &pllc1_div2_clk,
  304. [1] = &system_clk,
  305. [2] = &dv_clk
  306. };
  307. static struct clk *vclk_parents[8] = {
  308. [0] = &pllc1_div2_clk,
  309. [2] = &dv_clk,
  310. [3] = &usb24s_clk,
  311. [4] = &extal1_div2_clk,
  312. [5] = &extalr_clk,
  313. };
  314. static struct clk *fsia_parents[] = {
  315. [0] = &pllc1_div2_clk,
  316. [1] = &fsiack_clk, /* external clock */
  317. };
  318. static struct clk *fsib_parents[] = {
  319. [0] = &pllc1_div2_clk,
  320. [1] = &fsibck_clk, /* external clock */
  321. };
  322. static struct clk div6_reparent_clks[DIV6_REPARENT_NR] = {
  323. [DIV6_HDMI] = SH_CLK_DIV6_EXT(HDMICKCR, 0,
  324. hdmi_parent, ARRAY_SIZE(hdmi_parent), 6, 2),
  325. [DIV6_VCLK1] = SH_CLK_DIV6_EXT(VCLKCR1, 0,
  326. vclk_parents, ARRAY_SIZE(vclk_parents), 12, 3),
  327. [DIV6_VCLK2] = SH_CLK_DIV6_EXT(VCLKCR2, 0,
  328. vclk_parents, ARRAY_SIZE(vclk_parents), 12, 3),
  329. [DIV6_FSIA] = SH_CLK_DIV6_EXT(FSIACKCR, 0,
  330. fsia_parents, ARRAY_SIZE(fsia_parents), 6, 2),
  331. [DIV6_FSIB] = SH_CLK_DIV6_EXT(FSIBCKCR, 0,
  332. fsib_parents, ARRAY_SIZE(fsib_parents), 6, 2),
  333. };
  334. /* HDMI1/2 clock */
  335. static unsigned long hdmi12_recalc(struct clk *clk)
  336. {
  337. u32 val = __raw_readl(HDMICKCR);
  338. int shift = (int)clk->priv;
  339. val >>= shift;
  340. val &= 0x3;
  341. return clk->parent->rate / (1 << val);
  342. };
  343. static int hdmi12_set_rate(struct clk *clk, unsigned long rate)
  344. {
  345. u32 val, mask;
  346. int i, shift;
  347. for (i = 0; i < 3; i++)
  348. if (rate == clk->parent->rate / (1 << i))
  349. goto find;
  350. return -ENODEV;
  351. find:
  352. shift = (int)clk->priv;
  353. val = __raw_readl(HDMICKCR);
  354. mask = ~(0x3 << shift);
  355. val = (val & mask) | i << shift;
  356. __raw_writel(val, HDMICKCR);
  357. return 0;
  358. };
  359. static struct sh_clk_ops hdmi12_clk_ops = {
  360. .recalc = hdmi12_recalc,
  361. .set_rate = hdmi12_set_rate,
  362. };
  363. static struct clk hdmi1_clk = {
  364. .ops = &hdmi12_clk_ops,
  365. .priv = (void *)9,
  366. .parent = &div6_reparent_clks[DIV6_HDMI], /* late install */
  367. };
  368. static struct clk hdmi2_clk = {
  369. .ops = &hdmi12_clk_ops,
  370. .priv = (void *)11,
  371. .parent = &div6_reparent_clks[DIV6_HDMI], /* late install */
  372. };
  373. static struct clk *late_main_clks[] = {
  374. &hdmi1_clk,
  375. &hdmi2_clk,
  376. };
  377. /* FSI DIV */
  378. enum { FSIDIV_A, FSIDIV_B, FSIDIV_REPARENT_NR };
  379. static struct clk fsidivs[] = {
  380. [FSIDIV_A] = SH_CLK_FSIDIV(FSIDIVA, &div6_reparent_clks[DIV6_FSIA]),
  381. [FSIDIV_B] = SH_CLK_FSIDIV(FSIDIVB, &div6_reparent_clks[DIV6_FSIB]),
  382. };
  383. /* MSTP */
  384. enum {
  385. DIV4_I, DIV4_ZG, DIV4_B, DIV4_M1, DIV4_HP,
  386. DIV4_HPP, DIV4_USBP, DIV4_S, DIV4_ZB, DIV4_M3, DIV4_CP,
  387. DIV4_NR
  388. };
  389. struct clk div4_clks[DIV4_NR] = {
  390. [DIV4_I] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 20, 0x6fff, CLK_ENABLE_ON_INIT),
  391. [DIV4_ZG] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 16, 0x6fff, CLK_ENABLE_ON_INIT),
  392. [DIV4_B] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 8, 0x6fff, CLK_ENABLE_ON_INIT),
  393. [DIV4_M1] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 4, 0x6fff, CLK_ENABLE_ON_INIT),
  394. [DIV4_HP] = SH_CLK_DIV4(&pllc1_clk, FRQCRB, 4, 0x6fff, 0),
  395. [DIV4_HPP] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 20, 0x6fff, 0),
  396. [DIV4_USBP] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 16, 0x6fff, 0),
  397. [DIV4_S] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 12, 0x6fff, 0),
  398. [DIV4_ZB] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 8, 0x6fff, 0),
  399. [DIV4_M3] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 4, 0x6fff, 0),
  400. [DIV4_CP] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 0, 0x6fff, 0),
  401. };
  402. enum {
  403. DIV6_SUB,
  404. DIV6_NR
  405. };
  406. static struct clk div6_clks[DIV6_NR] = {
  407. [DIV6_SUB] = SH_CLK_DIV6(&pllc1_div2_clk, SUBCKCR, 0),
  408. };
  409. enum {
  410. MSTP128, MSTP127, MSTP125,
  411. MSTP116, MSTP111, MSTP100, MSTP117,
  412. MSTP230,
  413. MSTP222,
  414. MSTP218, MSTP217, MSTP216, MSTP214,
  415. MSTP207, MSTP206, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,
  416. MSTP329, MSTP328, MSTP323, MSTP320,
  417. MSTP314, MSTP313, MSTP312,
  418. MSTP309,
  419. MSTP416, MSTP415, MSTP407, MSTP406,
  420. MSTP_NR
  421. };
  422. static struct clk mstp_clks[MSTP_NR] = {
  423. [MSTP128] = SH_CLK_MSTP32(&div4_clks[DIV4_S], SMSTPCR1, 28, 0), /* CEU21 */
  424. [MSTP127] = SH_CLK_MSTP32(&div4_clks[DIV4_S], SMSTPCR1, 27, 0), /* CEU20 */
  425. [MSTP125] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 25, 0), /* TMU0 */
  426. [MSTP117] = SH_CLK_MSTP32(&div4_clks[DIV4_B], SMSTPCR1, 17, 0), /* LCDC1 */
  427. [MSTP116] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 16, 0), /* IIC0 */
  428. [MSTP111] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 11, 0), /* TMU1 */
  429. [MSTP100] = SH_CLK_MSTP32(&div4_clks[DIV4_B], SMSTPCR1, 0, 0), /* LCDC0 */
  430. [MSTP230] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 30, 0), /* SCIFA6 */
  431. [MSTP222] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 22, 0), /* SCIFA7 */
  432. [MSTP218] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR2, 18, 0), /* DMAC1 */
  433. [MSTP217] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR2, 17, 0), /* DMAC2 */
  434. [MSTP216] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR2, 16, 0), /* DMAC3 */
  435. [MSTP214] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR2, 14, 0), /* USBDMAC */
  436. [MSTP207] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 7, 0), /* SCIFA5 */
  437. [MSTP206] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 6, 0), /* SCIFB */
  438. [MSTP204] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 4, 0), /* SCIFA0 */
  439. [MSTP203] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 3, 0), /* SCIFA1 */
  440. [MSTP202] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 2, 0), /* SCIFA2 */
  441. [MSTP201] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 1, 0), /* SCIFA3 */
  442. [MSTP200] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 0, 0), /* SCIFA4 */
  443. [MSTP329] = SH_CLK_MSTP32(&r_clk, SMSTPCR3, 29, 0), /* CMT10 */
  444. [MSTP328] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 28, 0), /* FSI */
  445. [MSTP323] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR3, 23, 0), /* IIC1 */
  446. [MSTP320] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 20, 0), /* USBF */
  447. [MSTP314] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 14, 0), /* SDHI0 */
  448. [MSTP313] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 13, 0), /* SDHI1 */
  449. [MSTP312] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 12, 0), /* MMC */
  450. [MSTP309] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 9, 0), /* GEther */
  451. [MSTP416] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 16, 0), /* USBHOST */
  452. [MSTP415] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 15, 0), /* SDHI2 */
  453. [MSTP407] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 7, 0), /* USB-Func */
  454. [MSTP406] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 6, 0), /* USB Phy */
  455. };
  456. static struct clk_lookup lookups[] = {
  457. /* main clocks */
  458. CLKDEV_CON_ID("extalr", &extalr_clk),
  459. CLKDEV_CON_ID("extal1", &extal1_clk),
  460. CLKDEV_CON_ID("extal2", &extal2_clk),
  461. CLKDEV_CON_ID("extal1_div2", &extal1_div2_clk),
  462. CLKDEV_CON_ID("extal1_div1024", &extal1_div1024_clk),
  463. CLKDEV_CON_ID("extal1_div2048", &extal1_div2048_clk),
  464. CLKDEV_CON_ID("extal2_div2", &extal2_div2_clk),
  465. CLKDEV_CON_ID("dv_clk", &dv_clk),
  466. CLKDEV_CON_ID("system_clk", &system_clk),
  467. CLKDEV_CON_ID("system_div2_clk", &system_div2_clk),
  468. CLKDEV_CON_ID("r_clk", &r_clk),
  469. CLKDEV_CON_ID("pllc0_clk", &pllc0_clk),
  470. CLKDEV_CON_ID("pllc1_clk", &pllc1_clk),
  471. CLKDEV_CON_ID("pllc1_div2_clk", &pllc1_div2_clk),
  472. CLKDEV_CON_ID("usb24s", &usb24s_clk),
  473. CLKDEV_CON_ID("hdmi1", &hdmi1_clk),
  474. CLKDEV_CON_ID("hdmi2", &hdmi2_clk),
  475. CLKDEV_CON_ID("video1", &div6_reparent_clks[DIV6_VCLK1]),
  476. CLKDEV_CON_ID("video2", &div6_reparent_clks[DIV6_VCLK2]),
  477. CLKDEV_CON_ID("fsiack", &fsiack_clk),
  478. CLKDEV_CON_ID("fsibck", &fsibck_clk),
  479. /* DIV4 clocks */
  480. CLKDEV_CON_ID("i_clk", &div4_clks[DIV4_I]),
  481. CLKDEV_CON_ID("zg_clk", &div4_clks[DIV4_ZG]),
  482. CLKDEV_CON_ID("b_clk", &div4_clks[DIV4_B]),
  483. CLKDEV_CON_ID("m1_clk", &div4_clks[DIV4_M1]),
  484. CLKDEV_CON_ID("hp_clk", &div4_clks[DIV4_HP]),
  485. CLKDEV_CON_ID("hpp_clk", &div4_clks[DIV4_HPP]),
  486. CLKDEV_CON_ID("s_clk", &div4_clks[DIV4_S]),
  487. CLKDEV_CON_ID("zb_clk", &div4_clks[DIV4_ZB]),
  488. CLKDEV_CON_ID("m3_clk", &div4_clks[DIV4_M3]),
  489. CLKDEV_CON_ID("cp_clk", &div4_clks[DIV4_CP]),
  490. /* DIV6 clocks */
  491. CLKDEV_CON_ID("sub_clk", &div6_clks[DIV6_SUB]),
  492. /* MSTP32 clocks */
  493. CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks[MSTP100]),
  494. CLKDEV_DEV_ID("sh_tmu.3", &mstp_clks[MSTP111]),
  495. CLKDEV_DEV_ID("sh_tmu.4", &mstp_clks[MSTP111]),
  496. CLKDEV_DEV_ID("sh_tmu.5", &mstp_clks[MSTP111]),
  497. CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks[MSTP116]),
  498. CLKDEV_DEV_ID("sh_mobile_lcdc_fb.1", &mstp_clks[MSTP117]),
  499. CLKDEV_DEV_ID("sh_tmu.0", &mstp_clks[MSTP125]),
  500. CLKDEV_DEV_ID("sh_tmu.1", &mstp_clks[MSTP125]),
  501. CLKDEV_DEV_ID("sh_tmu.2", &mstp_clks[MSTP125]),
  502. CLKDEV_DEV_ID("sh_mobile_ceu.0", &mstp_clks[MSTP127]),
  503. CLKDEV_DEV_ID("sh_mobile_ceu.1", &mstp_clks[MSTP128]),
  504. CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP200]),
  505. CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP201]),
  506. CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP202]),
  507. CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]),
  508. CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]),
  509. CLKDEV_DEV_ID("sh-sci.8", &mstp_clks[MSTP206]),
  510. CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP207]),
  511. CLKDEV_DEV_ID("sh-dma-engine.3", &mstp_clks[MSTP214]),
  512. CLKDEV_DEV_ID("sh-dma-engine.2", &mstp_clks[MSTP216]),
  513. CLKDEV_DEV_ID("sh-dma-engine.1", &mstp_clks[MSTP217]),
  514. CLKDEV_DEV_ID("sh-dma-engine.0", &mstp_clks[MSTP218]),
  515. CLKDEV_DEV_ID("sh-sci.7", &mstp_clks[MSTP222]),
  516. CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP230]),
  517. CLKDEV_DEV_ID("sh_cmt.10", &mstp_clks[MSTP329]),
  518. CLKDEV_DEV_ID("sh_fsi2", &mstp_clks[MSTP328]),
  519. CLKDEV_DEV_ID("i2c-sh_mobile.1", &mstp_clks[MSTP323]),
  520. CLKDEV_DEV_ID("renesas_usbhs", &mstp_clks[MSTP320]),
  521. CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP314]),
  522. CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP313]),
  523. CLKDEV_DEV_ID("sh_mmcif", &mstp_clks[MSTP312]),
  524. CLKDEV_DEV_ID("sh-eth", &mstp_clks[MSTP309]),
  525. CLKDEV_DEV_ID("sh_mobile_sdhi.2", &mstp_clks[MSTP415]),
  526. /* ICK */
  527. CLKDEV_ICK_ID("host", "renesas_usbhs", &mstp_clks[MSTP416]),
  528. CLKDEV_ICK_ID("func", "renesas_usbhs", &mstp_clks[MSTP407]),
  529. CLKDEV_ICK_ID("phy", "renesas_usbhs", &mstp_clks[MSTP406]),
  530. CLKDEV_ICK_ID("pci", "renesas_usbhs", &div4_clks[DIV4_USBP]),
  531. CLKDEV_ICK_ID("usb24", "renesas_usbhs", &usb24_clk),
  532. CLKDEV_ICK_ID("ick", "sh-mobile-hdmi", &div6_reparent_clks[DIV6_HDMI]),
  533. CLKDEV_ICK_ID("icka", "sh_fsi2", &div6_reparent_clks[DIV6_FSIA]),
  534. CLKDEV_ICK_ID("ickb", "sh_fsi2", &div6_reparent_clks[DIV6_FSIB]),
  535. CLKDEV_ICK_ID("diva", "sh_fsi2", &fsidivs[FSIDIV_A]),
  536. CLKDEV_ICK_ID("divb", "sh_fsi2", &fsidivs[FSIDIV_B]),
  537. CLKDEV_ICK_ID("xcka", "sh_fsi2", &fsiack_clk),
  538. CLKDEV_ICK_ID("xckb", "sh_fsi2", &fsibck_clk),
  539. };
  540. void __init r8a7740_clock_init(u8 md_ck)
  541. {
  542. int k, ret = 0;
  543. /* detect system clock parent */
  544. if (md_ck & MD_CK1)
  545. system_clk.parent = &extal1_div2_clk;
  546. else
  547. system_clk.parent = &extal1_clk;
  548. /* detect RCLK parent */
  549. switch (md_ck & (MD_CK2 | MD_CK1)) {
  550. case MD_CK2 | MD_CK1:
  551. r_clk.parent = &extal1_div2048_clk;
  552. break;
  553. case MD_CK2:
  554. r_clk.parent = &extal1_div1024_clk;
  555. break;
  556. case MD_CK1:
  557. default:
  558. r_clk.parent = &extalr_clk;
  559. break;
  560. }
  561. for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
  562. ret = clk_register(main_clks[k]);
  563. if (!ret)
  564. ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
  565. if (!ret)
  566. ret = sh_clk_div6_register(div6_clks, DIV6_NR);
  567. if (!ret)
  568. ret = sh_clk_div6_reparent_register(div6_reparent_clks,
  569. DIV6_REPARENT_NR);
  570. if (!ret)
  571. ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);
  572. for (k = 0; !ret && (k < ARRAY_SIZE(late_main_clks)); k++)
  573. ret = clk_register(late_main_clks[k]);
  574. if (!ret)
  575. ret = sh_clk_fsidiv_register(fsidivs, FSIDIV_REPARENT_NR);
  576. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  577. if (!ret)
  578. shmobile_clk_init();
  579. else
  580. panic("failed to setup r8a7740 clocks\n");
  581. }