clock-r8a7740.c 18 KB

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