clock-r8a73a4.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. * r8a73a4 clock framework support
  3. *
  4. * Copyright (C) 2013 Renesas Solutions Corp.
  5. * Copyright (C) 2013 Magnus Damm
  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; 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/init.h>
  21. #include <linux/io.h>
  22. #include <linux/kernel.h>
  23. #include <linux/sh_clk.h>
  24. #include <linux/clkdev.h>
  25. #include <mach/clock.h>
  26. #include <mach/common.h>
  27. #define CPG_BASE 0xe6150000
  28. #define CPG_LEN 0x270
  29. #define SMSTPCR2 0xe6150138
  30. #define SMSTPCR3 0xe615013c
  31. #define SMSTPCR4 0xe6150140
  32. #define SMSTPCR5 0xe6150144
  33. #define FRQCRA 0xE6150000
  34. #define FRQCRB 0xE6150004
  35. #define FRQCRC 0xE61500E0
  36. #define VCLKCR1 0xE6150008
  37. #define VCLKCR2 0xE615000C
  38. #define VCLKCR3 0xE615001C
  39. #define VCLKCR4 0xE6150014
  40. #define VCLKCR5 0xE6150034
  41. #define ZBCKCR 0xE6150010
  42. #define SD0CKCR 0xE6150074
  43. #define SD1CKCR 0xE6150078
  44. #define SD2CKCR 0xE615007C
  45. #define MMC0CKCR 0xE6150240
  46. #define MMC1CKCR 0xE6150244
  47. #define FSIACKCR 0xE6150018
  48. #define FSIBCKCR 0xE6150090
  49. #define MPCKCR 0xe6150080
  50. #define SPUVCKCR 0xE6150094
  51. #define HSICKCR 0xE615026C
  52. #define M4CKCR 0xE6150098
  53. #define PLLECR 0xE61500D0
  54. #define PLL0CR 0xE61500D8
  55. #define PLL1CR 0xE6150028
  56. #define PLL2CR 0xE615002C
  57. #define PLL2SCR 0xE61501F4
  58. #define PLL2HCR 0xE61501E4
  59. #define CKSCR 0xE61500C0
  60. #define CPG_MAP(o) ((o - CPG_BASE) + cpg_mapping.base)
  61. static struct clk_mapping cpg_mapping = {
  62. .phys = CPG_BASE,
  63. .len = CPG_LEN,
  64. };
  65. static struct clk extalr_clk = {
  66. .rate = 32768,
  67. .mapping = &cpg_mapping,
  68. };
  69. static struct clk extal1_clk = {
  70. .rate = 26000000,
  71. .mapping = &cpg_mapping,
  72. };
  73. static struct clk extal2_clk = {
  74. .rate = 48000000,
  75. .mapping = &cpg_mapping,
  76. };
  77. static struct sh_clk_ops followparent_clk_ops = {
  78. .recalc = followparent_recalc,
  79. };
  80. static struct clk main_clk = {
  81. /* .parent will be set r8a73a4_clock_init */
  82. .ops = &followparent_clk_ops,
  83. };
  84. SH_CLK_RATIO(div2, 1, 2);
  85. SH_CLK_RATIO(div4, 1, 4);
  86. SH_FIXED_RATIO_CLK(main_div2_clk, main_clk, div2);
  87. SH_FIXED_RATIO_CLK(extal1_div2_clk, extal1_clk, div2);
  88. SH_FIXED_RATIO_CLK(extal2_div2_clk, extal2_clk, div2);
  89. SH_FIXED_RATIO_CLK(extal2_div4_clk, extal2_clk, div4);
  90. /* External FSIACK/FSIBCK clock */
  91. static struct clk fsiack_clk = {
  92. };
  93. static struct clk fsibck_clk = {
  94. };
  95. /*
  96. * PLL clocks
  97. */
  98. static struct clk *pll_parent_main[] = {
  99. [0] = &main_clk,
  100. [1] = &main_div2_clk
  101. };
  102. static struct clk *pll_parent_main_extal[8] = {
  103. [0] = &main_div2_clk,
  104. [1] = &extal2_div2_clk,
  105. [3] = &extal2_div4_clk,
  106. [4] = &main_clk,
  107. [5] = &extal2_clk,
  108. };
  109. static unsigned long pll_recalc(struct clk *clk)
  110. {
  111. unsigned long mult = 1;
  112. if (ioread32(CPG_MAP(PLLECR)) & (1 << clk->enable_bit))
  113. mult = (((ioread32(clk->mapped_reg) >> 24) & 0x7f) + 1);
  114. return clk->parent->rate * mult;
  115. }
  116. static int pll_set_parent(struct clk *clk, struct clk *parent)
  117. {
  118. u32 val;
  119. int i, ret;
  120. if (!clk->parent_table || !clk->parent_num)
  121. return -EINVAL;
  122. /* Search the parent */
  123. for (i = 0; i < clk->parent_num; i++)
  124. if (clk->parent_table[i] == parent)
  125. break;
  126. if (i == clk->parent_num)
  127. return -ENODEV;
  128. ret = clk_reparent(clk, parent);
  129. if (ret < 0)
  130. return ret;
  131. val = ioread32(clk->mapped_reg) &
  132. ~(((1 << clk->src_width) - 1) << clk->src_shift);
  133. iowrite32(val | i << clk->src_shift, clk->mapped_reg);
  134. return 0;
  135. }
  136. static struct sh_clk_ops pll_clk_ops = {
  137. .recalc = pll_recalc,
  138. .set_parent = pll_set_parent,
  139. };
  140. #define PLL_CLOCK(name, p, pt, w, s, reg, e) \
  141. static struct clk name = { \
  142. .ops = &pll_clk_ops, \
  143. .flags = CLK_ENABLE_ON_INIT, \
  144. .parent = p, \
  145. .parent_table = pt, \
  146. .parent_num = ARRAY_SIZE(pt), \
  147. .src_width = w, \
  148. .src_shift = s, \
  149. .enable_reg = (void __iomem *)reg, \
  150. .enable_bit = e, \
  151. .mapping = &cpg_mapping, \
  152. }
  153. PLL_CLOCK(pll0_clk, &main_clk, pll_parent_main, 1, 20, PLL0CR, 0);
  154. PLL_CLOCK(pll1_clk, &main_clk, pll_parent_main, 1, 7, PLL1CR, 1);
  155. PLL_CLOCK(pll2_clk, &main_div2_clk, pll_parent_main_extal, 3, 5, PLL2CR, 2);
  156. PLL_CLOCK(pll2s_clk, &main_div2_clk, pll_parent_main_extal, 3, 5, PLL2SCR, 4);
  157. PLL_CLOCK(pll2h_clk, &main_div2_clk, pll_parent_main_extal, 3, 5, PLL2HCR, 5);
  158. SH_FIXED_RATIO_CLK(pll1_div2_clk, pll1_clk, div2);
  159. static atomic_t frqcr_lock;
  160. /* Several clocks need to access FRQCRB, have to lock */
  161. static bool frqcr_kick_check(struct clk *clk)
  162. {
  163. return !(ioread32(CPG_MAP(FRQCRB)) & BIT(31));
  164. }
  165. static int frqcr_kick_do(struct clk *clk)
  166. {
  167. int i;
  168. /* set KICK bit in FRQCRB to update hardware setting, check success */
  169. iowrite32(ioread32(CPG_MAP(FRQCRB)) | BIT(31), CPG_MAP(FRQCRB));
  170. for (i = 1000; i; i--)
  171. if (ioread32(CPG_MAP(FRQCRB)) & BIT(31))
  172. cpu_relax();
  173. else
  174. return 0;
  175. return -ETIMEDOUT;
  176. }
  177. static int zclk_set_rate(struct clk *clk, unsigned long rate)
  178. {
  179. void __iomem *frqcrc;
  180. int ret;
  181. unsigned long step, p_rate;
  182. u32 val;
  183. if (!clk->parent || !__clk_get(clk->parent))
  184. return -ENODEV;
  185. if (!atomic_inc_and_test(&frqcr_lock) || !frqcr_kick_check(clk)) {
  186. ret = -EBUSY;
  187. goto done;
  188. }
  189. /*
  190. * Users are supposed to first call clk_set_rate() only with
  191. * clk_round_rate() results. So, we don't fix wrong rates here, but
  192. * guard against them anyway
  193. */
  194. p_rate = clk_get_rate(clk->parent);
  195. if (rate == p_rate) {
  196. val = 0;
  197. } else {
  198. step = DIV_ROUND_CLOSEST(p_rate, 32);
  199. if (rate > p_rate || rate < step) {
  200. ret = -EINVAL;
  201. goto done;
  202. }
  203. val = 32 - rate / step;
  204. }
  205. frqcrc = clk->mapped_reg + (FRQCRC - (u32)clk->enable_reg);
  206. iowrite32((ioread32(frqcrc) & ~(clk->div_mask << clk->enable_bit)) |
  207. (val << clk->enable_bit), frqcrc);
  208. ret = frqcr_kick_do(clk);
  209. done:
  210. atomic_dec(&frqcr_lock);
  211. __clk_put(clk->parent);
  212. return ret;
  213. }
  214. static long zclk_round_rate(struct clk *clk, unsigned long rate)
  215. {
  216. /*
  217. * theoretical rate = parent rate * multiplier / 32,
  218. * where 1 <= multiplier <= 32. Therefore we should do
  219. * multiplier = rate * 32 / parent rate
  220. * rounded rate = parent rate * multiplier / 32.
  221. * However, multiplication before division won't fit in 32 bits, so
  222. * we sacrifice some precision by first dividing and then multiplying.
  223. * To find the nearest divisor we calculate both and pick up the best
  224. * one. This avoids 64-bit arithmetics.
  225. */
  226. unsigned long step, mul_min, mul_max, rate_min, rate_max;
  227. rate_max = clk_get_rate(clk->parent);
  228. /* output freq <= parent */
  229. if (rate >= rate_max)
  230. return rate_max;
  231. step = DIV_ROUND_CLOSEST(rate_max, 32);
  232. /* output freq >= parent / 32 */
  233. if (step >= rate)
  234. return step;
  235. mul_min = rate / step;
  236. mul_max = DIV_ROUND_UP(rate, step);
  237. rate_min = step * mul_min;
  238. if (mul_max == mul_min)
  239. return rate_min;
  240. rate_max = step * mul_max;
  241. if (rate_max - rate < rate - rate_min)
  242. return rate_max;
  243. return rate_min;
  244. }
  245. static unsigned long zclk_recalc(struct clk *clk)
  246. {
  247. void __iomem *frqcrc = FRQCRC - (u32)clk->enable_reg + clk->mapped_reg;
  248. unsigned int max = clk->div_mask + 1;
  249. unsigned long val = ((ioread32(frqcrc) >> clk->enable_bit) &
  250. clk->div_mask);
  251. return DIV_ROUND_CLOSEST(clk_get_rate(clk->parent), max) *
  252. (max - val);
  253. }
  254. static struct sh_clk_ops zclk_ops = {
  255. .recalc = zclk_recalc,
  256. .set_rate = zclk_set_rate,
  257. .round_rate = zclk_round_rate,
  258. };
  259. static struct clk z_clk = {
  260. .parent = &pll0_clk,
  261. .div_mask = 0x1f,
  262. .enable_bit = 8,
  263. /* We'll need to access FRQCRB and FRQCRC */
  264. .enable_reg = (void __iomem *)FRQCRB,
  265. .ops = &zclk_ops,
  266. };
  267. /*
  268. * It seems only 1/2 divider is usable in manual mode. 1/2 / 2/3
  269. * switching is only available in auto-DVFS mode
  270. */
  271. SH_FIXED_RATIO_CLK(pll0_div2_clk, pll0_clk, div2);
  272. static struct clk z2_clk = {
  273. .parent = &pll0_div2_clk,
  274. .div_mask = 0x1f,
  275. .enable_bit = 0,
  276. /* We'll need to access FRQCRB and FRQCRC */
  277. .enable_reg = (void __iomem *)FRQCRB,
  278. .ops = &zclk_ops,
  279. };
  280. static struct clk *main_clks[] = {
  281. &extalr_clk,
  282. &extal1_clk,
  283. &extal1_div2_clk,
  284. &extal2_clk,
  285. &extal2_div2_clk,
  286. &extal2_div4_clk,
  287. &main_clk,
  288. &main_div2_clk,
  289. &fsiack_clk,
  290. &fsibck_clk,
  291. &pll0_clk,
  292. &pll1_clk,
  293. &pll1_div2_clk,
  294. &pll2_clk,
  295. &pll2s_clk,
  296. &pll2h_clk,
  297. &z_clk,
  298. &pll0_div2_clk,
  299. &z2_clk,
  300. };
  301. /* DIV4 */
  302. static void div4_kick(struct clk *clk)
  303. {
  304. if (!WARN(!atomic_inc_and_test(&frqcr_lock), "FRQCR* lock broken!\n"))
  305. frqcr_kick_do(clk);
  306. atomic_dec(&frqcr_lock);
  307. }
  308. static int divisors[] = { 2, 3, 4, 6, 8, 12, 16, 18, 24, 0, 36, 48, 10};
  309. static struct clk_div_mult_table div4_div_mult_table = {
  310. .divisors = divisors,
  311. .nr_divisors = ARRAY_SIZE(divisors),
  312. };
  313. static struct clk_div4_table div4_table = {
  314. .div_mult_table = &div4_div_mult_table,
  315. .kick = div4_kick,
  316. };
  317. enum {
  318. DIV4_I, DIV4_M3, DIV4_B, DIV4_M1, DIV4_M2,
  319. DIV4_ZX, DIV4_ZS, DIV4_HP,
  320. DIV4_NR };
  321. static struct clk div4_clks[DIV4_NR] = {
  322. [DIV4_I] = SH_CLK_DIV4(&pll1_clk, FRQCRA, 20, 0x0dff, CLK_ENABLE_ON_INIT),
  323. [DIV4_M3] = SH_CLK_DIV4(&pll1_clk, FRQCRA, 12, 0x1dff, CLK_ENABLE_ON_INIT),
  324. [DIV4_B] = SH_CLK_DIV4(&pll1_clk, FRQCRA, 8, 0x0dff, CLK_ENABLE_ON_INIT),
  325. [DIV4_M1] = SH_CLK_DIV4(&pll1_clk, FRQCRA, 4, 0x1dff, 0),
  326. [DIV4_M2] = SH_CLK_DIV4(&pll1_clk, FRQCRA, 0, 0x1dff, 0),
  327. [DIV4_ZX] = SH_CLK_DIV4(&pll1_clk, FRQCRB, 12, 0x0dff, 0),
  328. [DIV4_ZS] = SH_CLK_DIV4(&pll1_clk, FRQCRB, 8, 0x0dff, 0),
  329. [DIV4_HP] = SH_CLK_DIV4(&pll1_clk, FRQCRB, 4, 0x0dff, 0),
  330. };
  331. enum {
  332. DIV6_ZB,
  333. DIV6_SDHI0, DIV6_SDHI1, DIV6_SDHI2,
  334. DIV6_MMC0, DIV6_MMC1,
  335. DIV6_VCK1, DIV6_VCK2, DIV6_VCK3, DIV6_VCK4, DIV6_VCK5,
  336. DIV6_FSIA, DIV6_FSIB,
  337. DIV6_MP, DIV6_M4, DIV6_HSI, DIV6_SPUV,
  338. DIV6_NR };
  339. static struct clk *div6_parents[8] = {
  340. [0] = &pll1_div2_clk,
  341. [1] = &pll2s_clk,
  342. [3] = &extal2_clk,
  343. [4] = &main_div2_clk,
  344. [6] = &extalr_clk,
  345. };
  346. static struct clk *fsia_parents[4] = {
  347. [0] = &pll1_div2_clk,
  348. [1] = &pll2s_clk,
  349. [2] = &fsiack_clk,
  350. };
  351. static struct clk *fsib_parents[4] = {
  352. [0] = &pll1_div2_clk,
  353. [1] = &pll2s_clk,
  354. [2] = &fsibck_clk,
  355. };
  356. static struct clk *mp_parents[4] = {
  357. [0] = &pll1_div2_clk,
  358. [1] = &pll2s_clk,
  359. [2] = &extal2_clk,
  360. [3] = &extal2_clk,
  361. };
  362. static struct clk *m4_parents[2] = {
  363. [0] = &pll2s_clk,
  364. };
  365. static struct clk *hsi_parents[4] = {
  366. [0] = &pll2h_clk,
  367. [1] = &pll1_div2_clk,
  368. [3] = &pll2s_clk,
  369. };
  370. /*** FIXME ***
  371. * SH_CLK_DIV6_EXT() macro doesn't care .mapping
  372. * but, it is necessary on R-Car (= ioremap() base CPG)
  373. * The difference between
  374. * SH_CLK_DIV6_EXT() <--> SH_CLK_MAP_DIV6_EXT()
  375. * is only .mapping
  376. */
  377. #define SH_CLK_MAP_DIV6_EXT(_reg, _flags, _parents, \
  378. _num_parents, _src_shift, _src_width) \
  379. { \
  380. .enable_reg = (void __iomem *)_reg, \
  381. .enable_bit = 0, /* unused */ \
  382. .flags = _flags | CLK_MASK_DIV_ON_DISABLE, \
  383. .div_mask = SH_CLK_DIV6_MSK, \
  384. .parent_table = _parents, \
  385. .parent_num = _num_parents, \
  386. .src_shift = _src_shift, \
  387. .src_width = _src_width, \
  388. .mapping = &cpg_mapping, \
  389. }
  390. static struct clk div6_clks[DIV6_NR] = {
  391. [DIV6_ZB] = SH_CLK_MAP_DIV6_EXT(ZBCKCR, CLK_ENABLE_ON_INIT,
  392. div6_parents, 2, 7, 1),
  393. [DIV6_SDHI0] = SH_CLK_MAP_DIV6_EXT(SD0CKCR, 0,
  394. div6_parents, 2, 6, 2),
  395. [DIV6_SDHI1] = SH_CLK_MAP_DIV6_EXT(SD1CKCR, 0,
  396. div6_parents, 2, 6, 2),
  397. [DIV6_SDHI2] = SH_CLK_MAP_DIV6_EXT(SD2CKCR, 0,
  398. div6_parents, 2, 6, 2),
  399. [DIV6_MMC0] = SH_CLK_MAP_DIV6_EXT(MMC0CKCR, 0,
  400. div6_parents, 2, 6, 2),
  401. [DIV6_MMC1] = SH_CLK_MAP_DIV6_EXT(MMC1CKCR, 0,
  402. div6_parents, 2, 6, 2),
  403. [DIV6_VCK1] = SH_CLK_MAP_DIV6_EXT(VCLKCR1, 0, /* didn't care bit[6-7] */
  404. div6_parents, ARRAY_SIZE(div6_parents), 12, 3),
  405. [DIV6_VCK2] = SH_CLK_MAP_DIV6_EXT(VCLKCR2, 0, /* didn't care bit[6-7] */
  406. div6_parents, ARRAY_SIZE(div6_parents), 12, 3),
  407. [DIV6_VCK3] = SH_CLK_MAP_DIV6_EXT(VCLKCR3, 0, /* didn't care bit[6-7] */
  408. div6_parents, ARRAY_SIZE(div6_parents), 12, 3),
  409. [DIV6_VCK4] = SH_CLK_MAP_DIV6_EXT(VCLKCR4, 0, /* didn't care bit[6-7] */
  410. div6_parents, ARRAY_SIZE(div6_parents), 12, 3),
  411. [DIV6_VCK5] = SH_CLK_MAP_DIV6_EXT(VCLKCR5, 0, /* didn't care bit[6-7] */
  412. div6_parents, ARRAY_SIZE(div6_parents), 12, 3),
  413. [DIV6_FSIA] = SH_CLK_MAP_DIV6_EXT(FSIACKCR, 0,
  414. fsia_parents, ARRAY_SIZE(fsia_parents), 6, 2),
  415. [DIV6_FSIB] = SH_CLK_MAP_DIV6_EXT(FSIBCKCR, 0,
  416. fsib_parents, ARRAY_SIZE(fsib_parents), 6, 2),
  417. [DIV6_MP] = SH_CLK_MAP_DIV6_EXT(MPCKCR, 0, /* it needs bit[9-11] control */
  418. mp_parents, ARRAY_SIZE(mp_parents), 6, 2),
  419. /* pll2s will be selected always for M4 */
  420. [DIV6_M4] = SH_CLK_MAP_DIV6_EXT(M4CKCR, 0, /* it needs bit[9] control */
  421. m4_parents, ARRAY_SIZE(m4_parents), 6, 1),
  422. [DIV6_HSI] = SH_CLK_MAP_DIV6_EXT(HSICKCR, 0, /* it needs bit[9] control */
  423. hsi_parents, ARRAY_SIZE(hsi_parents), 6, 2),
  424. [DIV6_SPUV] = SH_CLK_MAP_DIV6_EXT(SPUVCKCR, 0,
  425. mp_parents, ARRAY_SIZE(mp_parents), 6, 2),
  426. };
  427. /* MSTP */
  428. enum {
  429. MSTP217, MSTP216, MSTP207, MSTP206, MSTP204, MSTP203,
  430. MSTP329, MSTP323, MSTP318, MSTP317, MSTP316,
  431. MSTP315, MSTP314, MSTP313, MSTP312, MSTP305, MSTP300,
  432. MSTP411, MSTP410, MSTP409,
  433. MSTP522, MSTP515,
  434. MSTP_NR
  435. };
  436. static struct clk mstp_clks[MSTP_NR] = {
  437. [MSTP204] = SH_CLK_MSTP32(&div6_clks[DIV6_MP], SMSTPCR2, 4, 0), /* SCIFA0 */
  438. [MSTP203] = SH_CLK_MSTP32(&div6_clks[DIV6_MP], SMSTPCR2, 3, 0), /* SCIFA1 */
  439. [MSTP206] = SH_CLK_MSTP32(&div6_clks[DIV6_MP], SMSTPCR2, 6, 0), /* SCIFB0 */
  440. [MSTP207] = SH_CLK_MSTP32(&div6_clks[DIV6_MP], SMSTPCR2, 7, 0), /* SCIFB1 */
  441. [MSTP216] = SH_CLK_MSTP32(&div6_clks[DIV6_MP], SMSTPCR2, 16, 0), /* SCIFB2 */
  442. [MSTP217] = SH_CLK_MSTP32(&div6_clks[DIV6_MP], SMSTPCR2, 17, 0), /* SCIFB3 */
  443. [MSTP300] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 0, 0), /* IIC2 */
  444. [MSTP305] = SH_CLK_MSTP32(&div6_clks[DIV6_MMC1],SMSTPCR3, 5, 0), /* MMCIF1 */
  445. [MSTP312] = SH_CLK_MSTP32(&div6_clks[DIV6_SDHI2],SMSTPCR3, 12, 0), /* SDHI2 */
  446. [MSTP313] = SH_CLK_MSTP32(&div6_clks[DIV6_SDHI1],SMSTPCR3, 13, 0), /* SDHI1 */
  447. [MSTP314] = SH_CLK_MSTP32(&div6_clks[DIV6_SDHI0],SMSTPCR3, 14, 0), /* SDHI0 */
  448. [MSTP315] = SH_CLK_MSTP32(&div6_clks[DIV6_MMC0],SMSTPCR3, 15, 0), /* MMCIF0 */
  449. [MSTP316] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 16, 0), /* IIC6 */
  450. [MSTP317] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 17, 0), /* IIC7 */
  451. [MSTP318] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 18, 0), /* IIC0 */
  452. [MSTP323] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 23, 0), /* IIC1 */
  453. [MSTP329] = SH_CLK_MSTP32(&extalr_clk, SMSTPCR3, 29, 0), /* CMT10 */
  454. [MSTP409] = SH_CLK_MSTP32(&main_div2_clk, SMSTPCR4, 9, 0), /* IIC5 */
  455. [MSTP410] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 10, 0), /* IIC4 */
  456. [MSTP411] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 11, 0), /* IIC3 */
  457. [MSTP522] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR5, 22, 0), /* Thermal */
  458. [MSTP515] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR5, 15, 0), /* IIC8 */
  459. };
  460. static struct clk_lookup lookups[] = {
  461. /* main clock */
  462. CLKDEV_CON_ID("extal1", &extal1_clk),
  463. CLKDEV_CON_ID("extal1_div2", &extal1_div2_clk),
  464. CLKDEV_CON_ID("extal2", &extal2_clk),
  465. CLKDEV_CON_ID("extal2_div2", &extal2_div2_clk),
  466. CLKDEV_CON_ID("extal2_div4", &extal2_div4_clk),
  467. CLKDEV_CON_ID("fsiack", &fsiack_clk),
  468. CLKDEV_CON_ID("fsibck", &fsibck_clk),
  469. /* pll clock */
  470. CLKDEV_CON_ID("pll1", &pll1_clk),
  471. CLKDEV_CON_ID("pll1_div2", &pll1_div2_clk),
  472. CLKDEV_CON_ID("pll2", &pll2_clk),
  473. CLKDEV_CON_ID("pll2s", &pll2s_clk),
  474. CLKDEV_CON_ID("pll2h", &pll2h_clk),
  475. /* CPU clock */
  476. CLKDEV_DEV_ID("cpu0", &z_clk),
  477. /* DIV6 */
  478. CLKDEV_CON_ID("zb", &div6_clks[DIV6_ZB]),
  479. CLKDEV_CON_ID("vck1", &div6_clks[DIV6_VCK1]),
  480. CLKDEV_CON_ID("vck2", &div6_clks[DIV6_VCK2]),
  481. CLKDEV_CON_ID("vck3", &div6_clks[DIV6_VCK3]),
  482. CLKDEV_CON_ID("vck4", &div6_clks[DIV6_VCK4]),
  483. CLKDEV_CON_ID("vck5", &div6_clks[DIV6_VCK5]),
  484. CLKDEV_CON_ID("fsia", &div6_clks[DIV6_FSIA]),
  485. CLKDEV_CON_ID("fsib", &div6_clks[DIV6_FSIB]),
  486. CLKDEV_CON_ID("mp", &div6_clks[DIV6_MP]),
  487. CLKDEV_CON_ID("m4", &div6_clks[DIV6_M4]),
  488. CLKDEV_CON_ID("hsi", &div6_clks[DIV6_HSI]),
  489. CLKDEV_CON_ID("spuv", &div6_clks[DIV6_SPUV]),
  490. /* MSTP */
  491. CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]),
  492. CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]),
  493. CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP206]),
  494. CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP207]),
  495. CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP216]),
  496. CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP217]),
  497. CLKDEV_DEV_ID("rcar_thermal", &mstp_clks[MSTP522]),
  498. CLKDEV_DEV_ID("e6520000.i2c", &mstp_clks[MSTP300]),
  499. CLKDEV_DEV_ID("sh_mmcif.1", &mstp_clks[MSTP305]),
  500. CLKDEV_DEV_ID("ee220000.mmcif", &mstp_clks[MSTP305]),
  501. CLKDEV_DEV_ID("sh_mobile_sdhi.2", &mstp_clks[MSTP312]),
  502. CLKDEV_DEV_ID("ee140000.sdhi", &mstp_clks[MSTP312]),
  503. CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP313]),
  504. CLKDEV_DEV_ID("ee120000.sdhi", &mstp_clks[MSTP313]),
  505. CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP314]),
  506. CLKDEV_DEV_ID("ee100000.sdhi", &mstp_clks[MSTP314]),
  507. CLKDEV_DEV_ID("sh_mmcif.0", &mstp_clks[MSTP315]),
  508. CLKDEV_DEV_ID("ee200000.mmcif", &mstp_clks[MSTP315]),
  509. CLKDEV_DEV_ID("e6550000.i2c", &mstp_clks[MSTP316]),
  510. CLKDEV_DEV_ID("e6560000.i2c", &mstp_clks[MSTP317]),
  511. CLKDEV_DEV_ID("e6500000.i2c", &mstp_clks[MSTP318]),
  512. CLKDEV_DEV_ID("e6510000.i2c", &mstp_clks[MSTP323]),
  513. CLKDEV_DEV_ID("sh_cmt.10", &mstp_clks[MSTP329]),
  514. CLKDEV_DEV_ID("e60b0000.i2c", &mstp_clks[MSTP409]),
  515. CLKDEV_DEV_ID("e6540000.i2c", &mstp_clks[MSTP410]),
  516. CLKDEV_DEV_ID("e6530000.i2c", &mstp_clks[MSTP411]),
  517. CLKDEV_DEV_ID("e6570000.i2c", &mstp_clks[MSTP515]),
  518. /* for DT */
  519. CLKDEV_DEV_ID("e61f0000.thermal", &mstp_clks[MSTP522]),
  520. };
  521. void __init r8a73a4_clock_init(void)
  522. {
  523. void __iomem *reg;
  524. int k, ret = 0;
  525. u32 ckscr;
  526. atomic_set(&frqcr_lock, -1);
  527. reg = ioremap_nocache(CKSCR, PAGE_SIZE);
  528. BUG_ON(!reg);
  529. ckscr = ioread32(reg);
  530. iounmap(reg);
  531. switch ((ckscr >> 28) & 0x3) {
  532. case 0:
  533. main_clk.parent = &extal1_clk;
  534. break;
  535. case 1:
  536. main_clk.parent = &extal1_div2_clk;
  537. break;
  538. case 2:
  539. main_clk.parent = &extal2_clk;
  540. break;
  541. case 3:
  542. main_clk.parent = &extal2_div2_clk;
  543. break;
  544. }
  545. for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
  546. ret = clk_register(main_clks[k]);
  547. if (!ret)
  548. ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
  549. if (!ret)
  550. ret = sh_clk_div6_reparent_register(div6_clks, DIV6_NR);
  551. if (!ret)
  552. ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);
  553. clkdev_add_table(lookups, ARRAY_SIZE(lookups));
  554. if (!ret)
  555. shmobile_clk_init();
  556. else
  557. panic("failed to setup r8a73a4 clocks\n");
  558. }