clock-r8a7740.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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 0xe6150000
  43. #define FRQCRB 0xe6150004
  44. #define VCLKCR1 0xE6150008
  45. #define VCLKCR2 0xE615000c
  46. #define FRQCRC 0xe61500e0
  47. #define PLLC01CR 0xe6150028
  48. #define SUBCKCR 0xe6150080
  49. #define USBCKCR 0xe615008c
  50. #define MSTPSR0 0xe6150030
  51. #define MSTPSR1 0xe6150038
  52. #define MSTPSR2 0xe6150040
  53. #define MSTPSR3 0xe6150048
  54. #define MSTPSR4 0xe615004c
  55. #define HDMICKCR 0xe6150094
  56. #define SMSTPCR0 0xe6150130
  57. #define SMSTPCR1 0xe6150134
  58. #define SMSTPCR2 0xe6150138
  59. #define SMSTPCR3 0xe615013c
  60. #define SMSTPCR4 0xe6150140
  61. /* Fixed 32 KHz root clock from EXTALR pin */
  62. static struct clk extalr_clk = {
  63. .rate = 32768,
  64. };
  65. /*
  66. * 25MHz default rate for the EXTAL1 root input clock.
  67. * If needed, reset this with clk_set_rate() from the platform code.
  68. */
  69. static struct clk extal1_clk = {
  70. .rate = 25000000,
  71. };
  72. /*
  73. * 48MHz default rate for the EXTAL2 root input clock.
  74. * If needed, reset this with clk_set_rate() from the platform code.
  75. */
  76. static struct clk extal2_clk = {
  77. .rate = 48000000,
  78. };
  79. /*
  80. * 27MHz default rate for the DV_CLKI root input clock.
  81. * If needed, reset this with clk_set_rate() from the platform code.
  82. */
  83. static struct clk dv_clk = {
  84. .rate = 27000000,
  85. };
  86. static unsigned long div_recalc(struct clk *clk)
  87. {
  88. return clk->parent->rate / (int)(clk->priv);
  89. }
  90. static struct sh_clk_ops div_clk_ops = {
  91. .recalc = div_recalc,
  92. };
  93. /* extal1 / 2 */
  94. static struct clk extal1_div2_clk = {
  95. .ops = &div_clk_ops,
  96. .priv = (void *)2,
  97. .parent = &extal1_clk,
  98. };
  99. /* extal1 / 1024 */
  100. static struct clk extal1_div1024_clk = {
  101. .ops = &div_clk_ops,
  102. .priv = (void *)1024,
  103. .parent = &extal1_clk,
  104. };
  105. /* extal1 / 2 / 1024 */
  106. static struct clk extal1_div2048_clk = {
  107. .ops = &div_clk_ops,
  108. .priv = (void *)1024,
  109. .parent = &extal1_div2_clk,
  110. };
  111. /* extal2 / 2 */
  112. static struct clk extal2_div2_clk = {
  113. .ops = &div_clk_ops,
  114. .priv = (void *)2,
  115. .parent = &extal2_clk,
  116. };
  117. static struct sh_clk_ops followparent_clk_ops = {
  118. .recalc = followparent_recalc,
  119. };
  120. /* Main clock */
  121. static struct clk system_clk = {
  122. .ops = &followparent_clk_ops,
  123. };
  124. static struct clk system_div2_clk = {
  125. .ops = &div_clk_ops,
  126. .priv = (void *)2,
  127. .parent = &system_clk,
  128. };
  129. /* r_clk */
  130. static struct clk r_clk = {
  131. .ops = &followparent_clk_ops,
  132. };
  133. /* PLLC0/PLLC1 */
  134. static unsigned long pllc01_recalc(struct clk *clk)
  135. {
  136. unsigned long mult = 1;
  137. if (__raw_readl(PLLC01CR) & (1 << 14))
  138. mult = ((__raw_readl(clk->enable_reg) >> 24) & 0x7f) + 1;
  139. return clk->parent->rate * mult;
  140. }
  141. static struct sh_clk_ops pllc01_clk_ops = {
  142. .recalc = pllc01_recalc,
  143. };
  144. static struct clk pllc0_clk = {
  145. .ops = &pllc01_clk_ops,
  146. .flags = CLK_ENABLE_ON_INIT,
  147. .parent = &system_clk,
  148. .enable_reg = (void __iomem *)FRQCRC,
  149. };
  150. static struct clk pllc1_clk = {
  151. .ops = &pllc01_clk_ops,
  152. .flags = CLK_ENABLE_ON_INIT,
  153. .parent = &system_div2_clk,
  154. .enable_reg = (void __iomem *)FRQCRA,
  155. };
  156. /* PLLC1 / 2 */
  157. static struct clk pllc1_div2_clk = {
  158. .ops = &div_clk_ops,
  159. .priv = (void *)2,
  160. .parent = &pllc1_clk,
  161. };
  162. /* USB clock */
  163. static struct clk *usb24s_parents[] = {
  164. [0] = &system_clk,
  165. [1] = &extal2_clk
  166. };
  167. static int usb24s_enable(struct clk *clk)
  168. {
  169. __raw_writel(__raw_readl(USBCKCR) & ~(1 << 8), USBCKCR);
  170. return 0;
  171. }
  172. static void usb24s_disable(struct clk *clk)
  173. {
  174. __raw_writel(__raw_readl(USBCKCR) | (1 << 8), USBCKCR);
  175. }
  176. static int usb24s_set_parent(struct clk *clk, struct clk *parent)
  177. {
  178. int i, ret;
  179. u32 val;
  180. if (!clk->parent_table || !clk->parent_num)
  181. return -EINVAL;
  182. /* Search the parent */
  183. for (i = 0; i < clk->parent_num; i++)
  184. if (clk->parent_table[i] == parent)
  185. break;
  186. if (i == clk->parent_num)
  187. return -ENODEV;
  188. ret = clk_reparent(clk, parent);
  189. if (ret < 0)
  190. return ret;
  191. val = __raw_readl(USBCKCR);
  192. val &= ~(1 << 7);
  193. val |= i << 7;
  194. __raw_writel(val, USBCKCR);
  195. return 0;
  196. }
  197. static struct sh_clk_ops usb24s_clk_ops = {
  198. .recalc = followparent_recalc,
  199. .enable = usb24s_enable,
  200. .disable = usb24s_disable,
  201. .set_parent = usb24s_set_parent,
  202. };
  203. static struct clk usb24s_clk = {
  204. .ops = &usb24s_clk_ops,
  205. .parent_table = usb24s_parents,
  206. .parent_num = ARRAY_SIZE(usb24s_parents),
  207. .parent = &system_clk,
  208. };
  209. static unsigned long usb24_recalc(struct clk *clk)
  210. {
  211. return clk->parent->rate /
  212. ((__raw_readl(USBCKCR) & (1 << 6)) ? 1 : 2);
  213. };
  214. static int usb24_set_rate(struct clk *clk, unsigned long rate)
  215. {
  216. u32 val;
  217. /* closer to which ? parent->rate or parent->rate/2 */
  218. val = __raw_readl(USBCKCR);
  219. val &= ~(1 << 6);
  220. val |= (rate > (clk->parent->rate / 4) * 3) << 6;
  221. __raw_writel(val, USBCKCR);
  222. return 0;
  223. }
  224. static struct sh_clk_ops usb24_clk_ops = {
  225. .recalc = usb24_recalc,
  226. .set_rate = usb24_set_rate,
  227. };
  228. static struct clk usb24_clk = {
  229. .ops = &usb24_clk_ops,
  230. .parent = &usb24s_clk,
  231. };
  232. struct clk *main_clks[] = {
  233. &extalr_clk,
  234. &extal1_clk,
  235. &extal2_clk,
  236. &extal1_div2_clk,
  237. &extal1_div1024_clk,
  238. &extal1_div2048_clk,
  239. &extal2_div2_clk,
  240. &dv_clk,
  241. &system_clk,
  242. &system_div2_clk,
  243. &r_clk,
  244. &pllc0_clk,
  245. &pllc1_clk,
  246. &pllc1_div2_clk,
  247. &usb24s_clk,
  248. &usb24_clk,
  249. };
  250. static void div4_kick(struct clk *clk)
  251. {
  252. unsigned long value;
  253. /* set KICK bit in FRQCRB to update hardware setting */
  254. value = __raw_readl(FRQCRB);
  255. value |= (1 << 31);
  256. __raw_writel(value, FRQCRB);
  257. }
  258. static int divisors[] = { 2, 3, 4, 6, 8, 12, 16, 18,
  259. 24, 32, 36, 48, 0, 72, 96, 0 };
  260. static struct clk_div_mult_table div4_div_mult_table = {
  261. .divisors = divisors,
  262. .nr_divisors = ARRAY_SIZE(divisors),
  263. };
  264. static struct clk_div4_table div4_table = {
  265. .div_mult_table = &div4_div_mult_table,
  266. .kick = div4_kick,
  267. };
  268. /* DIV6 reparent */
  269. enum {
  270. DIV6_HDMI,
  271. DIV6_VCLK1, DIV6_VCLK2,
  272. DIV6_REPARENT_NR,
  273. };
  274. static struct clk *hdmi_parent[] = {
  275. [0] = &pllc1_div2_clk,
  276. [1] = &system_clk,
  277. [2] = &dv_clk
  278. };
  279. static struct clk *vclk_parents[8] = {
  280. [0] = &pllc1_div2_clk,
  281. [2] = &dv_clk,
  282. [3] = &usb24s_clk,
  283. [4] = &extal1_div2_clk,
  284. [5] = &extalr_clk,
  285. };
  286. static struct clk div6_reparent_clks[DIV6_REPARENT_NR] = {
  287. [DIV6_HDMI] = SH_CLK_DIV6_EXT(HDMICKCR, 0,
  288. hdmi_parent, ARRAY_SIZE(hdmi_parent), 6, 2),
  289. [DIV6_VCLK1] = SH_CLK_DIV6_EXT(VCLKCR1, 0,
  290. vclk_parents, ARRAY_SIZE(vclk_parents), 12, 3),
  291. [DIV6_VCLK2] = SH_CLK_DIV6_EXT(VCLKCR2, 0,
  292. vclk_parents, ARRAY_SIZE(vclk_parents), 12, 3),
  293. };
  294. /* HDMI1/2 clock */
  295. static unsigned long hdmi12_recalc(struct clk *clk)
  296. {
  297. u32 val = __raw_readl(HDMICKCR);
  298. int shift = (int)clk->priv;
  299. val >>= shift;
  300. val &= 0x3;
  301. return clk->parent->rate / (1 << val);
  302. };
  303. static int hdmi12_set_rate(struct clk *clk, unsigned long rate)
  304. {
  305. u32 val, mask;
  306. int i, shift;
  307. for (i = 0; i < 3; i++)
  308. if (rate == clk->parent->rate / (1 << i))
  309. goto find;
  310. return -ENODEV;
  311. find:
  312. shift = (int)clk->priv;
  313. val = __raw_readl(HDMICKCR);
  314. mask = ~(0x3 << shift);
  315. val = (val & mask) | i << shift;
  316. __raw_writel(val, HDMICKCR);
  317. return 0;
  318. };
  319. static struct sh_clk_ops hdmi12_clk_ops = {
  320. .recalc = hdmi12_recalc,
  321. .set_rate = hdmi12_set_rate,
  322. };
  323. static struct clk hdmi1_clk = {
  324. .ops = &hdmi12_clk_ops,
  325. .priv = (void *)9,
  326. .parent = &div6_reparent_clks[DIV6_HDMI], /* late install */
  327. };
  328. static struct clk hdmi2_clk = {
  329. .ops = &hdmi12_clk_ops,
  330. .priv = (void *)11,
  331. .parent = &div6_reparent_clks[DIV6_HDMI], /* late install */
  332. };
  333. static struct clk *late_main_clks[] = {
  334. &hdmi1_clk,
  335. &hdmi2_clk,
  336. };
  337. /* MSTP */
  338. enum {
  339. DIV4_I, DIV4_ZG, DIV4_B, DIV4_M1, DIV4_HP,
  340. DIV4_HPP, DIV4_USBP, DIV4_S, DIV4_ZB, DIV4_M3, DIV4_CP,
  341. DIV4_NR
  342. };
  343. struct clk div4_clks[DIV4_NR] = {
  344. [DIV4_I] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 20, 0x6fff, CLK_ENABLE_ON_INIT),
  345. [DIV4_ZG] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 16, 0x6fff, CLK_ENABLE_ON_INIT),
  346. [DIV4_B] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 8, 0x6fff, CLK_ENABLE_ON_INIT),
  347. [DIV4_M1] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 4, 0x6fff, CLK_ENABLE_ON_INIT),
  348. [DIV4_HP] = SH_CLK_DIV4(&pllc1_clk, FRQCRB, 4, 0x6fff, 0),
  349. [DIV4_HPP] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 20, 0x6fff, 0),
  350. [DIV4_USBP] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 16, 0x6fff, 0),
  351. [DIV4_S] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 12, 0x6fff, 0),
  352. [DIV4_ZB] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 8, 0x6fff, 0),
  353. [DIV4_M3] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 4, 0x6fff, 0),
  354. [DIV4_CP] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 0, 0x6fff, 0),
  355. };
  356. enum {
  357. DIV6_SUB,
  358. DIV6_NR
  359. };
  360. static struct clk div6_clks[DIV6_NR] = {
  361. [DIV6_SUB] = SH_CLK_DIV6(&pllc1_div2_clk, SUBCKCR, 0),
  362. };
  363. enum {
  364. MSTP128, MSTP127, MSTP125,
  365. MSTP116, MSTP111, MSTP100, MSTP117,
  366. MSTP230,
  367. MSTP222,
  368. MSTP207, MSTP206, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,
  369. MSTP329, MSTP328, MSTP323, MSTP320,
  370. MSTP314, MSTP313, MSTP312,
  371. MSTP309,
  372. MSTP416, MSTP415, MSTP407, MSTP406,
  373. MSTP_NR
  374. };
  375. static struct clk mstp_clks[MSTP_NR] = {
  376. [MSTP128] = SH_CLK_MSTP32(&div4_clks[DIV4_S], SMSTPCR1, 28, 0), /* CEU21 */
  377. [MSTP127] = SH_CLK_MSTP32(&div4_clks[DIV4_S], SMSTPCR1, 27, 0), /* CEU20 */
  378. [MSTP125] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 25, 0), /* TMU0 */
  379. [MSTP117] = SH_CLK_MSTP32(&div4_clks[DIV4_B], SMSTPCR1, 17, 0), /* LCDC1 */
  380. [MSTP116] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 16, 0), /* IIC0 */
  381. [MSTP111] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 11, 0), /* TMU1 */
  382. [MSTP100] = SH_CLK_MSTP32(&div4_clks[DIV4_B], SMSTPCR1, 0, 0), /* LCDC0 */
  383. [MSTP230] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 30, 0), /* SCIFA6 */
  384. [MSTP222] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 22, 0), /* SCIFA7 */
  385. [MSTP207] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 7, 0), /* SCIFA5 */
  386. [MSTP206] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 6, 0), /* SCIFB */
  387. [MSTP204] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 4, 0), /* SCIFA0 */
  388. [MSTP203] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 3, 0), /* SCIFA1 */
  389. [MSTP202] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 2, 0), /* SCIFA2 */
  390. [MSTP201] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 1, 0), /* SCIFA3 */
  391. [MSTP200] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 0, 0), /* SCIFA4 */
  392. [MSTP329] = SH_CLK_MSTP32(&r_clk, SMSTPCR3, 29, 0), /* CMT10 */
  393. [MSTP328] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 28, 0), /* FSI */
  394. [MSTP323] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR3, 23, 0), /* IIC1 */
  395. [MSTP320] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 20, 0), /* USBF */
  396. [MSTP314] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 14, 0), /* SDHI0 */
  397. [MSTP313] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 13, 0), /* SDHI1 */
  398. [MSTP312] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 12, 0), /* MMC */
  399. [MSTP309] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 9, 0), /* GEther */
  400. [MSTP416] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 16, 0), /* USBHOST */
  401. [MSTP415] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 15, 0), /* SDHI2 */
  402. [MSTP407] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 7, 0), /* USB-Func */
  403. [MSTP406] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 6, 0), /* USB Phy */
  404. };
  405. static struct clk_lookup lookups[] = {
  406. /* main clocks */
  407. CLKDEV_CON_ID("extalr", &extalr_clk),
  408. CLKDEV_CON_ID("extal1", &extal1_clk),
  409. CLKDEV_CON_ID("extal2", &extal2_clk),
  410. CLKDEV_CON_ID("extal1_div2", &extal1_div2_clk),
  411. CLKDEV_CON_ID("extal1_div1024", &extal1_div1024_clk),
  412. CLKDEV_CON_ID("extal1_div2048", &extal1_div2048_clk),
  413. CLKDEV_CON_ID("extal2_div2", &extal2_div2_clk),
  414. CLKDEV_CON_ID("dv_clk", &dv_clk),
  415. CLKDEV_CON_ID("system_clk", &system_clk),
  416. CLKDEV_CON_ID("system_div2_clk", &system_div2_clk),
  417. CLKDEV_CON_ID("r_clk", &r_clk),
  418. CLKDEV_CON_ID("pllc0_clk", &pllc0_clk),
  419. CLKDEV_CON_ID("pllc1_clk", &pllc1_clk),
  420. CLKDEV_CON_ID("pllc1_div2_clk", &pllc1_div2_clk),
  421. CLKDEV_CON_ID("usb24s", &usb24s_clk),
  422. CLKDEV_CON_ID("hdmi1", &hdmi1_clk),
  423. CLKDEV_CON_ID("hdmi2", &hdmi2_clk),
  424. CLKDEV_CON_ID("video1", &div6_reparent_clks[DIV6_VCLK1]),
  425. CLKDEV_CON_ID("video2", &div6_reparent_clks[DIV6_VCLK2]),
  426. /* DIV4 clocks */
  427. CLKDEV_CON_ID("i_clk", &div4_clks[DIV4_I]),
  428. CLKDEV_CON_ID("zg_clk", &div4_clks[DIV4_ZG]),
  429. CLKDEV_CON_ID("b_clk", &div4_clks[DIV4_B]),
  430. CLKDEV_CON_ID("m1_clk", &div4_clks[DIV4_M1]),
  431. CLKDEV_CON_ID("hp_clk", &div4_clks[DIV4_HP]),
  432. CLKDEV_CON_ID("hpp_clk", &div4_clks[DIV4_HPP]),
  433. CLKDEV_CON_ID("s_clk", &div4_clks[DIV4_S]),
  434. CLKDEV_CON_ID("zb_clk", &div4_clks[DIV4_ZB]),
  435. CLKDEV_CON_ID("m3_clk", &div4_clks[DIV4_M3]),
  436. CLKDEV_CON_ID("cp_clk", &div4_clks[DIV4_CP]),
  437. /* DIV6 clocks */
  438. CLKDEV_CON_ID("sub_clk", &div6_clks[DIV6_SUB]),
  439. /* MSTP32 clocks */
  440. CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks[MSTP100]),
  441. CLKDEV_DEV_ID("sh_tmu.1", &mstp_clks[MSTP111]),
  442. CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks[MSTP116]),
  443. CLKDEV_DEV_ID("sh_mobile_lcdc_fb.1", &mstp_clks[MSTP117]),
  444. CLKDEV_DEV_ID("sh_tmu.0", &mstp_clks[MSTP125]),
  445. CLKDEV_DEV_ID("sh_mobile_ceu.0", &mstp_clks[MSTP127]),
  446. CLKDEV_DEV_ID("sh_mobile_ceu.1", &mstp_clks[MSTP128]),
  447. CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP200]),
  448. CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP201]),
  449. CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP202]),
  450. CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]),
  451. CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]),
  452. CLKDEV_DEV_ID("sh-sci.8", &mstp_clks[MSTP206]),
  453. CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP207]),
  454. CLKDEV_DEV_ID("sh-sci.7", &mstp_clks[MSTP222]),
  455. CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP230]),
  456. CLKDEV_DEV_ID("sh_cmt.10", &mstp_clks[MSTP329]),
  457. CLKDEV_DEV_ID("sh_fsi2", &mstp_clks[MSTP328]),
  458. CLKDEV_DEV_ID("i2c-sh_mobile.1", &mstp_clks[MSTP323]),
  459. CLKDEV_DEV_ID("renesas_usbhs", &mstp_clks[MSTP320]),
  460. CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP314]),
  461. CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP313]),
  462. CLKDEV_DEV_ID("sh_mmcif", &mstp_clks[MSTP312]),
  463. CLKDEV_DEV_ID("sh-eth", &mstp_clks[MSTP309]),
  464. CLKDEV_DEV_ID("sh_mobile_sdhi.2", &mstp_clks[MSTP415]),
  465. /* ICK */
  466. CLKDEV_ICK_ID("host", "renesas_usbhs", &mstp_clks[MSTP416]),
  467. CLKDEV_ICK_ID("func", "renesas_usbhs", &mstp_clks[MSTP407]),
  468. CLKDEV_ICK_ID("phy", "renesas_usbhs", &mstp_clks[MSTP406]),
  469. CLKDEV_ICK_ID("pci", "renesas_usbhs", &div4_clks[DIV4_USBP]),
  470. CLKDEV_ICK_ID("usb24", "renesas_usbhs", &usb24_clk),
  471. CLKDEV_ICK_ID("ick", "sh-mobile-hdmi", &div6_reparent_clks[DIV6_HDMI]),
  472. };
  473. void __init r8a7740_clock_init(u8 md_ck)
  474. {
  475. int k, ret = 0;
  476. /* detect system clock parent */
  477. if (md_ck & MD_CK1)
  478. system_clk.parent = &extal1_div2_clk;
  479. else
  480. system_clk.parent = &extal1_clk;
  481. /* detect RCLK parent */
  482. switch (md_ck & (MD_CK2 | MD_CK1)) {
  483. case MD_CK2 | MD_CK1:
  484. r_clk.parent = &extal1_div2048_clk;
  485. break;
  486. case MD_CK2:
  487. r_clk.parent = &extal1_div1024_clk;
  488. break;
  489. case MD_CK1:
  490. default:
  491. r_clk.parent = &extalr_clk;
  492. break;
  493. }
  494. for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
  495. ret = clk_register(main_clks[k]);
  496. if (!ret)
  497. ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
  498. if (!ret)
  499. ret = sh_clk_div6_register(div6_clks, DIV6_NR);
  500. if (!ret)
  501. ret = sh_clk_div6_reparent_register(div6_reparent_clks,
  502. DIV6_REPARENT_NR);
  503. if (!ret)
  504. ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
  505. for (k = 0; !ret && (k < ARRAY_SIZE(late_main_clks)); k++)
  506. ret = clk_register(late_main_clks[k]);
  507. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  508. if (!ret)
  509. shmobile_clk_init();
  510. else
  511. panic("failed to setup r8a7740 clocks\n");
  512. }