clock-r8a7740.c 20 KB

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