clock-sh7722.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7722.c
  3. *
  4. * SH7343, SH7722, SH7723 & SH7366 support for the clock framework
  5. *
  6. * Copyright (c) 2006-2007 Nomad Global Solutions Inc
  7. * Based on code for sh7343 by Paul Mundt
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/io.h>
  16. #include <linux/errno.h>
  17. #include <linux/stringify.h>
  18. #include <asm/clock.h>
  19. #include <asm/freq.h>
  20. #define N (-1)
  21. #define NM (-2)
  22. #define ROUND_NEAREST 0
  23. #define ROUND_DOWN -1
  24. #define ROUND_UP +1
  25. static int adjust_algos[][3] = {
  26. {}, /* NO_CHANGE */
  27. { NM, N, 1 }, /* N:1, N:1 */
  28. { 3, 2, 2 }, /* 3:2:2 */
  29. { 5, 2, 2 }, /* 5:2:2 */
  30. { N, 1, 1 }, /* N:1:1 */
  31. { N, 1 }, /* N:1 */
  32. { N, 1 }, /* N:1 */
  33. { 3, 2 },
  34. { 4, 3 },
  35. { 5, 4 },
  36. { N, 1 }
  37. };
  38. static unsigned long adjust_pair_of_clocks(unsigned long r1, unsigned long r2,
  39. int m1, int m2, int round_flag)
  40. {
  41. unsigned long rem, div;
  42. int the_one = 0;
  43. pr_debug( "Actual values: r1 = %ld\n", r1);
  44. pr_debug( "...............r2 = %ld\n", r2);
  45. if (m1 == m2) {
  46. r2 = r1;
  47. pr_debug( "setting equal rates: r2 now %ld\n", r2);
  48. } else if ((m2 == N && m1 == 1) ||
  49. (m2 == NM && m1 == N)) { /* N:1 or NM:N */
  50. pr_debug( "Setting rates as 1:N (N:N*M)\n");
  51. rem = r2 % r1;
  52. pr_debug( "...remainder = %ld\n", rem);
  53. if (rem) {
  54. div = r2 / r1;
  55. pr_debug( "...div = %ld\n", div);
  56. switch (round_flag) {
  57. case ROUND_NEAREST:
  58. the_one = rem >= r1/2 ? 1 : 0; break;
  59. case ROUND_UP:
  60. the_one = 1; break;
  61. case ROUND_DOWN:
  62. the_one = 0; break;
  63. }
  64. r2 = r1 * (div + the_one);
  65. pr_debug( "...setting r2 to %ld\n", r2);
  66. }
  67. } else if ((m2 == 1 && m1 == N) ||
  68. (m2 == N && m1 == NM)) { /* 1:N or N:NM */
  69. pr_debug( "Setting rates as N:1 (N*M:N)\n");
  70. rem = r1 % r2;
  71. pr_debug( "...remainder = %ld\n", rem);
  72. if (rem) {
  73. div = r1 / r2;
  74. pr_debug( "...div = %ld\n", div);
  75. switch (round_flag) {
  76. case ROUND_NEAREST:
  77. the_one = rem > r2/2 ? 1 : 0; break;
  78. case ROUND_UP:
  79. the_one = 0; break;
  80. case ROUND_DOWN:
  81. the_one = 1; break;
  82. }
  83. r2 = r1 / (div + the_one);
  84. pr_debug( "...setting r2 to %ld\n", r2);
  85. }
  86. } else { /* value:value */
  87. pr_debug( "Setting rates as %d:%d\n", m1, m2);
  88. div = r1 / m1;
  89. r2 = div * m2;
  90. pr_debug( "...div = %ld\n", div);
  91. pr_debug( "...setting r2 to %ld\n", r2);
  92. }
  93. return r2;
  94. }
  95. static void adjust_clocks(int originate, int *l, unsigned long v[],
  96. int n_in_line)
  97. {
  98. int x;
  99. pr_debug( "Go down from %d...\n", originate);
  100. /* go up recalculation clocks */
  101. for (x = originate; x>0; x -- )
  102. v[x-1] = adjust_pair_of_clocks(v[x], v[x-1],
  103. l[x], l[x-1],
  104. ROUND_UP);
  105. pr_debug( "Go up from %d...\n", originate);
  106. /* go down recalculation clocks */
  107. for (x = originate; x<n_in_line - 1; x ++ )
  108. v[x+1] = adjust_pair_of_clocks(v[x], v[x+1],
  109. l[x], l[x+1],
  110. ROUND_UP);
  111. }
  112. /*
  113. * SH7722 uses a common set of multipliers and divisors, so this
  114. * is quite simple..
  115. */
  116. /*
  117. * Instead of having two separate multipliers/divisors set, like this:
  118. *
  119. * static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  120. * static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
  121. *
  122. * I created the divisors2 array, which is used to calculate rate like
  123. * rate = parent * 2 / divisors2[ divisor ];
  124. */
  125. static int divisors2[] = { 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32, 40 };
  126. static void master_clk_recalc(struct clk *clk)
  127. {
  128. unsigned frqcr = ctrl_inl(FRQCR);
  129. clk->rate = CONFIG_SH_PCLK_FREQ * (((frqcr >> 24) & 0x1f) + 1);
  130. }
  131. static void master_clk_init(struct clk *clk)
  132. {
  133. clk->parent = NULL;
  134. clk->flags |= CLK_RATE_PROPAGATES;
  135. clk->rate = CONFIG_SH_PCLK_FREQ;
  136. master_clk_recalc(clk);
  137. }
  138. static void module_clk_recalc(struct clk *clk)
  139. {
  140. unsigned long frqcr = ctrl_inl(FRQCR);
  141. clk->rate = clk->parent->rate / (((frqcr >> 24) & 0x1f) + 1);
  142. }
  143. static int master_clk_setrate(struct clk *clk, unsigned long rate, int id)
  144. {
  145. int div = rate / clk->rate;
  146. int master_divs[] = { 2, 3, 4, 6, 8, 16 };
  147. int index;
  148. unsigned long frqcr;
  149. for (index = 1; index < ARRAY_SIZE(master_divs); index++)
  150. if (div >= master_divs[index - 1] && div < master_divs[index])
  151. break;
  152. if (index >= ARRAY_SIZE(master_divs))
  153. index = ARRAY_SIZE(master_divs);
  154. div = master_divs[index - 1];
  155. frqcr = ctrl_inl(FRQCR);
  156. frqcr &= ~(0xF << 24);
  157. frqcr |= ( (div-1) << 24);
  158. ctrl_outl(frqcr, FRQCR);
  159. return 0;
  160. }
  161. static struct clk_ops sh7722_master_clk_ops = {
  162. .init = master_clk_init,
  163. .recalc = master_clk_recalc,
  164. .set_rate = master_clk_setrate,
  165. };
  166. static struct clk_ops sh7722_module_clk_ops = {
  167. .recalc = module_clk_recalc,
  168. };
  169. struct frqcr_context {
  170. unsigned mask;
  171. unsigned shift;
  172. };
  173. struct frqcr_context sh7722_get_clk_context(const char *name)
  174. {
  175. struct frqcr_context ctx = { 0, };
  176. if (!strcmp(name, "peripheral_clk")) {
  177. ctx.shift = 0;
  178. ctx.mask = 0xF;
  179. } else if (!strcmp(name, "sdram_clk")) {
  180. ctx.shift = 4;
  181. ctx.mask = 0xF;
  182. } else if (!strcmp(name, "bus_clk")) {
  183. ctx.shift = 8;
  184. ctx.mask = 0xF;
  185. } else if (!strcmp(name, "sh_clk")) {
  186. ctx.shift = 12;
  187. ctx.mask = 0xF;
  188. } else if (!strcmp(name, "umem_clk")) {
  189. ctx.shift = 16;
  190. ctx.mask = 0xF;
  191. } else if (!strcmp(name, "cpu_clk")) {
  192. ctx.shift = 20;
  193. ctx.mask = 7;
  194. }
  195. return ctx;
  196. }
  197. /**
  198. * sh7722_find_div_index - find divisor for setting rate
  199. *
  200. * All sh7722 clocks use the same set of multipliers/divisors. This function
  201. * chooses correct divisor to set the rate of clock with parent clock that
  202. * generates frequency of 'parent_rate'
  203. *
  204. * @parent_rate: rate of parent clock
  205. * @rate: requested rate to be set
  206. */
  207. static int sh7722_find_div_index(unsigned long parent_rate, unsigned rate)
  208. {
  209. unsigned div2 = parent_rate * 2 / rate;
  210. int index;
  211. if (rate > parent_rate)
  212. return -EINVAL;
  213. for (index = 1; index < ARRAY_SIZE(divisors2); index++) {
  214. if (div2 > divisors2[index - 1] && div2 <= divisors2[index])
  215. break;
  216. }
  217. if (index >= ARRAY_SIZE(divisors2))
  218. index = ARRAY_SIZE(divisors2) - 1;
  219. return index;
  220. }
  221. static void sh7722_frqcr_recalc(struct clk *clk)
  222. {
  223. struct frqcr_context ctx = sh7722_get_clk_context(clk->name);
  224. unsigned long frqcr = ctrl_inl(FRQCR);
  225. int index;
  226. index = (frqcr >> ctx.shift) & ctx.mask;
  227. clk->rate = clk->parent->rate * 2 / divisors2[index];
  228. }
  229. static int sh7722_frqcr_set_rate(struct clk *clk, unsigned long rate,
  230. int algo_id)
  231. {
  232. struct frqcr_context ctx = sh7722_get_clk_context(clk->name);
  233. unsigned long parent_rate = clk->parent->rate;
  234. int div;
  235. unsigned long frqcr;
  236. int err = 0;
  237. /* pretty invalid */
  238. if (parent_rate < rate)
  239. return -EINVAL;
  240. /* look for multiplier/divisor pair */
  241. div = sh7722_find_div_index(parent_rate, rate);
  242. if (div<0)
  243. return div;
  244. /* calculate new value of clock rate */
  245. clk->rate = parent_rate * 2 / divisors2[div];
  246. frqcr = ctrl_inl(FRQCR);
  247. /* FIXME: adjust as algo_id specifies */
  248. if (algo_id != NO_CHANGE) {
  249. int originator;
  250. char *algo_group_1[] = { "cpu_clk", "umem_clk", "sh_clk" };
  251. char *algo_group_2[] = { "sh_clk", "bus_clk" };
  252. char *algo_group_3[] = { "sh_clk", "sdram_clk" };
  253. char *algo_group_4[] = { "bus_clk", "peripheral_clk" };
  254. char *algo_group_5[] = { "cpu_clk", "peripheral_clk" };
  255. char **algo_current = NULL;
  256. /* 3 is the maximum number of clocks in relation */
  257. struct clk *ck[3];
  258. unsigned long values[3]; /* the same comment as above */
  259. int part_length = -1;
  260. int i;
  261. /*
  262. * all the steps below only required if adjustion was
  263. * requested
  264. */
  265. if (algo_id == IUS_N1_N1 ||
  266. algo_id == IUS_322 ||
  267. algo_id == IUS_522 ||
  268. algo_id == IUS_N11) {
  269. algo_current = algo_group_1;
  270. part_length = 3;
  271. }
  272. if (algo_id == SB_N1) {
  273. algo_current = algo_group_2;
  274. part_length = 2;
  275. }
  276. if (algo_id == SB3_N1 ||
  277. algo_id == SB3_32 ||
  278. algo_id == SB3_43 ||
  279. algo_id == SB3_54) {
  280. algo_current = algo_group_3;
  281. part_length = 2;
  282. }
  283. if (algo_id == BP_N1) {
  284. algo_current = algo_group_4;
  285. part_length = 2;
  286. }
  287. if (algo_id == IP_N1) {
  288. algo_current = algo_group_5;
  289. part_length = 2;
  290. }
  291. if (!algo_current)
  292. goto incorrect_algo_id;
  293. originator = -1;
  294. for (i = 0; i < part_length; i ++ ) {
  295. if (originator >= 0 && !strcmp(clk->name,
  296. algo_current[i]))
  297. originator = i;
  298. ck[i] = clk_get(NULL, algo_current[i]);
  299. values[i] = clk_get_rate(ck[i]);
  300. }
  301. if (originator >= 0)
  302. adjust_clocks(originator, adjust_algos[algo_id],
  303. values, part_length);
  304. for (i = 0; i < part_length; i ++ ) {
  305. struct frqcr_context part_ctx;
  306. int part_div;
  307. if (likely(!err)) {
  308. part_div = sh7722_find_div_index(parent_rate,
  309. rate);
  310. if (part_div > 0) {
  311. part_ctx = sh7722_get_clk_context(
  312. ck[i]->name);
  313. frqcr &= ~(part_ctx.mask <<
  314. part_ctx.shift);
  315. frqcr |= part_div << part_ctx.shift;
  316. } else
  317. err = part_div;
  318. }
  319. ck[i]->ops->recalc(ck[i]);
  320. clk_put(ck[i]);
  321. }
  322. }
  323. /* was there any error during recalculation ? If so, bail out.. */
  324. if (unlikely(err!=0))
  325. goto out_err;
  326. /* clear FRQCR bits */
  327. frqcr &= ~(ctx.mask << ctx.shift);
  328. frqcr |= div << ctx.shift;
  329. /* ...and perform actual change */
  330. ctrl_outl(frqcr, FRQCR);
  331. return 0;
  332. incorrect_algo_id:
  333. return -EINVAL;
  334. out_err:
  335. return err;
  336. }
  337. static long sh7722_frqcr_round_rate(struct clk *clk, unsigned long rate)
  338. {
  339. unsigned long parent_rate = clk->parent->rate;
  340. int div;
  341. /* look for multiplier/divisor pair */
  342. div = sh7722_find_div_index(parent_rate, rate);
  343. if (div < 0)
  344. return clk->rate;
  345. /* calculate new value of clock rate */
  346. return parent_rate * 2 / divisors2[div];
  347. }
  348. static struct clk_ops sh7722_frqcr_clk_ops = {
  349. .recalc = sh7722_frqcr_recalc,
  350. .set_rate = sh7722_frqcr_set_rate,
  351. .round_rate = sh7722_frqcr_round_rate,
  352. };
  353. /*
  354. * clock ops methods for SIU A/B and IrDA clock
  355. *
  356. */
  357. #ifndef CONFIG_CPU_SUBTYPE_SH7343
  358. static int sh7722_siu_set_rate(struct clk *clk, unsigned long rate, int algo_id)
  359. {
  360. unsigned long r;
  361. int div;
  362. r = ctrl_inl(clk->arch_flags);
  363. div = sh7722_find_div_index(clk->parent->rate, rate);
  364. if (div < 0)
  365. return div;
  366. r = (r & ~0xF) | div;
  367. ctrl_outl(r, clk->arch_flags);
  368. return 0;
  369. }
  370. static void sh7722_siu_recalc(struct clk *clk)
  371. {
  372. unsigned long r;
  373. r = ctrl_inl(clk->arch_flags);
  374. clk->rate = clk->parent->rate * 2 / divisors2[r & 0xF];
  375. }
  376. static int sh7722_siu_start_stop(struct clk *clk, int enable)
  377. {
  378. unsigned long r;
  379. r = ctrl_inl(clk->arch_flags);
  380. if (enable)
  381. ctrl_outl(r & ~(1 << 8), clk->arch_flags);
  382. else
  383. ctrl_outl(r | (1 << 8), clk->arch_flags);
  384. return 0;
  385. }
  386. static void sh7722_siu_enable(struct clk *clk)
  387. {
  388. sh7722_siu_start_stop(clk, 1);
  389. }
  390. static void sh7722_siu_disable(struct clk *clk)
  391. {
  392. sh7722_siu_start_stop(clk, 0);
  393. }
  394. static struct clk_ops sh7722_siu_clk_ops = {
  395. .recalc = sh7722_siu_recalc,
  396. .set_rate = sh7722_siu_set_rate,
  397. .enable = sh7722_siu_enable,
  398. .disable = sh7722_siu_disable,
  399. };
  400. #endif /* CONFIG_CPU_SUBTYPE_SH7343 */
  401. static void sh7722_video_enable(struct clk *clk)
  402. {
  403. unsigned long r;
  404. r = ctrl_inl(VCLKCR);
  405. ctrl_outl( r & ~(1<<8), VCLKCR);
  406. }
  407. static void sh7722_video_disable(struct clk *clk)
  408. {
  409. unsigned long r;
  410. r = ctrl_inl(VCLKCR);
  411. ctrl_outl( r | (1<<8), VCLKCR);
  412. }
  413. static int sh7722_video_set_rate(struct clk *clk, unsigned long rate,
  414. int algo_id)
  415. {
  416. unsigned long r;
  417. r = ctrl_inl(VCLKCR);
  418. r &= ~0x3F;
  419. r |= ((clk->parent->rate / rate - 1) & 0x3F);
  420. ctrl_outl(r, VCLKCR);
  421. return 0;
  422. }
  423. static void sh7722_video_recalc(struct clk *clk)
  424. {
  425. unsigned long r;
  426. r = ctrl_inl(VCLKCR);
  427. clk->rate = clk->parent->rate / ((r & 0x3F) + 1);
  428. }
  429. static struct clk_ops sh7722_video_clk_ops = {
  430. .recalc = sh7722_video_recalc,
  431. .set_rate = sh7722_video_set_rate,
  432. .enable = sh7722_video_enable,
  433. .disable = sh7722_video_disable,
  434. };
  435. /*
  436. * and at last, clock definitions themselves
  437. */
  438. static struct clk sh7722_umem_clock = {
  439. .name = "umem_clk",
  440. .ops = &sh7722_frqcr_clk_ops,
  441. .flags = CLK_RATE_PROPAGATES,
  442. };
  443. static struct clk sh7722_sh_clock = {
  444. .name = "sh_clk",
  445. .ops = &sh7722_frqcr_clk_ops,
  446. .flags = CLK_RATE_PROPAGATES,
  447. };
  448. static struct clk sh7722_peripheral_clock = {
  449. .name = "peripheral_clk",
  450. .ops = &sh7722_frqcr_clk_ops,
  451. .flags = CLK_RATE_PROPAGATES,
  452. };
  453. static struct clk sh7722_sdram_clock = {
  454. .name = "sdram_clk",
  455. .ops = &sh7722_frqcr_clk_ops,
  456. };
  457. static struct clk sh7722_r_clock = {
  458. .name = "r_clk",
  459. .rate = 32768,
  460. .flags = CLK_RATE_PROPAGATES,
  461. };
  462. #ifndef CONFIG_CPU_SUBTYPE_SH7343
  463. /*
  464. * these three clocks - SIU A, SIU B, IrDA - share the same clk_ops
  465. * methods of clk_ops determine which register they should access by
  466. * examining clk->name field
  467. */
  468. static struct clk sh7722_siu_a_clock = {
  469. .name = "siu_a_clk",
  470. .arch_flags = SCLKACR,
  471. .ops = &sh7722_siu_clk_ops,
  472. };
  473. static struct clk sh7722_siu_b_clock = {
  474. .name = "siu_b_clk",
  475. .arch_flags = SCLKBCR,
  476. .ops = &sh7722_siu_clk_ops,
  477. };
  478. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  479. static struct clk sh7722_irda_clock = {
  480. .name = "irda_clk",
  481. .arch_flags = IrDACLKCR,
  482. .ops = &sh7722_siu_clk_ops,
  483. };
  484. #endif
  485. #endif /* CONFIG_CPU_SUBTYPE_SH7343 */
  486. static struct clk sh7722_video_clock = {
  487. .name = "video_clk",
  488. .ops = &sh7722_video_clk_ops,
  489. };
  490. #define MSTPCR_ARCH_FLAGS(reg, bit) (((reg) << 8) | (bit))
  491. #define MSTPCR_ARCH_FLAGS_REG(value) ((value) >> 8)
  492. #define MSTPCR_ARCH_FLAGS_BIT(value) ((value) & 0xff)
  493. static int sh7722_mstpcr_start_stop(struct clk *clk, int enable)
  494. {
  495. unsigned long bit = MSTPCR_ARCH_FLAGS_BIT(clk->arch_flags);
  496. unsigned long reg;
  497. unsigned long r;
  498. switch(MSTPCR_ARCH_FLAGS_REG(clk->arch_flags)) {
  499. case 0:
  500. reg = MSTPCR0;
  501. break;
  502. case 1:
  503. reg = MSTPCR1;
  504. break;
  505. case 2:
  506. reg = MSTPCR2;
  507. break;
  508. default:
  509. return -EINVAL;
  510. }
  511. r = ctrl_inl(reg);
  512. if (enable)
  513. r &= ~(1 << bit);
  514. else
  515. r |= (1 << bit);
  516. ctrl_outl(r, reg);
  517. return 0;
  518. }
  519. static void sh7722_mstpcr_enable(struct clk *clk)
  520. {
  521. sh7722_mstpcr_start_stop(clk, 1);
  522. }
  523. static void sh7722_mstpcr_disable(struct clk *clk)
  524. {
  525. sh7722_mstpcr_start_stop(clk, 0);
  526. }
  527. static void sh7722_mstpcr_recalc(struct clk *clk)
  528. {
  529. if (clk->parent)
  530. clk->rate = clk->parent->rate;
  531. }
  532. static struct clk_ops sh7722_mstpcr_clk_ops = {
  533. .enable = sh7722_mstpcr_enable,
  534. .disable = sh7722_mstpcr_disable,
  535. .recalc = sh7722_mstpcr_recalc,
  536. };
  537. #define MSTPCR(_name, _parent, regnr, bitnr) \
  538. { \
  539. .name = _name, \
  540. .arch_flags = MSTPCR_ARCH_FLAGS(regnr, bitnr), \
  541. .ops = (void *)_parent, \
  542. }
  543. static struct clk sh7722_mstpcr_clocks[] = {
  544. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  545. MSTPCR("uram0", "umem_clk", 0, 28),
  546. MSTPCR("xymem0", "bus_clk", 0, 26),
  547. MSTPCR("tmu0", "peripheral_clk", 0, 15),
  548. MSTPCR("cmt0", "r_clk", 0, 14),
  549. MSTPCR("rwdt0", "r_clk", 0, 13),
  550. MSTPCR("flctl0", "peripheral_clk", 0, 10),
  551. MSTPCR("scif0", "peripheral_clk", 0, 7),
  552. MSTPCR("scif1", "peripheral_clk", 0, 6),
  553. MSTPCR("scif2", "peripheral_clk", 0, 5),
  554. MSTPCR("i2c0", "peripheral_clk", 1, 9),
  555. MSTPCR("rtc0", "r_clk", 1, 8),
  556. MSTPCR("sdhi0", "peripheral_clk", 2, 18),
  557. MSTPCR("keysc0", "r_clk", 2, 14),
  558. MSTPCR("usbf0", "peripheral_clk", 2, 11),
  559. MSTPCR("2dg0", "bus_clk", 2, 9),
  560. MSTPCR("siu0", "bus_clk", 2, 8),
  561. MSTPCR("vou0", "bus_clk", 2, 5),
  562. MSTPCR("jpu0", "bus_clk", 2, 6),
  563. MSTPCR("beu0", "bus_clk", 2, 4),
  564. MSTPCR("ceu0", "bus_clk", 2, 3),
  565. MSTPCR("veu0", "bus_clk", 2, 2),
  566. MSTPCR("vpu0", "bus_clk", 2, 1),
  567. MSTPCR("lcdc0", "bus_clk", 2, 0),
  568. #endif
  569. #if defined(CONFIG_CPU_SUBTYPE_SH7723)
  570. /* See page 60 of Datasheet V1.0: Overview -> Block Diagram */
  571. MSTPCR("tlb0", "cpu_clk", 0, 31),
  572. MSTPCR("ic0", "cpu_clk", 0, 30),
  573. MSTPCR("oc0", "cpu_clk", 0, 29),
  574. MSTPCR("l2c0", "sh_clk", 0, 28),
  575. MSTPCR("ilmem0", "cpu_clk", 0, 27),
  576. MSTPCR("fpu0", "cpu_clk", 0, 24),
  577. MSTPCR("intc0", "cpu_clk", 0, 22),
  578. MSTPCR("dmac0", "bus_clk", 0, 21),
  579. MSTPCR("sh0", "sh_clk", 0, 20),
  580. MSTPCR("hudi0", "peripheral_clk", 0, 19),
  581. MSTPCR("ubc0", "cpu_clk", 0, 17),
  582. MSTPCR("tmu0", "peripheral_clk", 0, 15),
  583. MSTPCR("cmt0", "r_clk", 0, 14),
  584. MSTPCR("rwdt0", "r_clk", 0, 13),
  585. MSTPCR("dmac1", "bus_clk", 0, 12),
  586. MSTPCR("tmu1", "peripheral_clk", 0, 11),
  587. MSTPCR("flctl0", "peripheral_clk", 0, 10),
  588. MSTPCR("scif0", "peripheral_clk", 0, 9),
  589. MSTPCR("scif1", "peripheral_clk", 0, 8),
  590. MSTPCR("scif2", "peripheral_clk", 0, 7),
  591. MSTPCR("scif3", "bus_clk", 0, 6),
  592. MSTPCR("scif4", "bus_clk", 0, 5),
  593. MSTPCR("scif5", "bus_clk", 0, 4),
  594. MSTPCR("msiof0", "bus_clk", 0, 2),
  595. MSTPCR("msiof1", "bus_clk", 0, 1),
  596. MSTPCR("meram0", "sh_clk", 0, 0),
  597. MSTPCR("i2c0", "peripheral_clk", 1, 9),
  598. MSTPCR("rtc0", "r_clk", 1, 8),
  599. MSTPCR("atapi0", "sh_clk", 2, 28),
  600. MSTPCR("adc0", "peripheral_clk", 2, 28),
  601. MSTPCR("tpu0", "bus_clk", 2, 25),
  602. MSTPCR("irda0", "peripheral_clk", 2, 24),
  603. MSTPCR("tsif0", "bus_clk", 2, 22),
  604. MSTPCR("icb0", "bus_clk", 2, 21),
  605. MSTPCR("sdhi0", "bus_clk", 2, 18),
  606. MSTPCR("sdhi1", "bus_clk", 2, 17),
  607. MSTPCR("keysc0", "r_clk", 2, 14),
  608. MSTPCR("usb0", "bus_clk", 2, 11),
  609. MSTPCR("2dg0", "bus_clk", 2, 10),
  610. MSTPCR("siu0", "bus_clk", 2, 8),
  611. MSTPCR("veu1", "bus_clk", 2, 6),
  612. MSTPCR("vou0", "bus_clk", 2, 5),
  613. MSTPCR("beu0", "bus_clk", 2, 4),
  614. MSTPCR("ceu0", "bus_clk", 2, 3),
  615. MSTPCR("veu0", "bus_clk", 2, 2),
  616. MSTPCR("vpu0", "bus_clk", 2, 1),
  617. MSTPCR("lcdc0", "bus_clk", 2, 0),
  618. #endif
  619. #if defined(CONFIG_CPU_SUBTYPE_SH7343)
  620. MSTPCR("uram0", "umem_clk", 0, 28),
  621. MSTPCR("xymem0", "bus_clk", 0, 26),
  622. MSTPCR("tmu0", "peripheral_clk", 0, 15),
  623. MSTPCR("cmt0", "r_clk", 0, 14),
  624. MSTPCR("rwdt0", "r_clk", 0, 13),
  625. MSTPCR("scif0", "peripheral_clk", 0, 7),
  626. MSTPCR("scif1", "peripheral_clk", 0, 6),
  627. MSTPCR("scif2", "peripheral_clk", 0, 5),
  628. MSTPCR("scif3", "peripheral_clk", 0, 4),
  629. MSTPCR("i2c0", "peripheral_clk", 1, 9),
  630. MSTPCR("i2c1", "peripheral_clk", 1, 8),
  631. MSTPCR("sdhi0", "peripheral_clk", 2, 18),
  632. MSTPCR("keysc0", "r_clk", 2, 14),
  633. MSTPCR("usbf0", "peripheral_clk", 2, 11),
  634. MSTPCR("siu0", "bus_clk", 2, 8),
  635. MSTPCR("jpu0", "bus_clk", 2, 6),
  636. MSTPCR("vou0", "bus_clk", 2, 5),
  637. MSTPCR("beu0", "bus_clk", 2, 4),
  638. MSTPCR("ceu0", "bus_clk", 2, 3),
  639. MSTPCR("veu0", "bus_clk", 2, 2),
  640. MSTPCR("vpu0", "bus_clk", 2, 1),
  641. MSTPCR("lcdc0", "bus_clk", 2, 0),
  642. #endif
  643. #if defined(CONFIG_CPU_SUBTYPE_SH7366)
  644. /* See page 52 of Datasheet V0.40: Overview -> Block Diagram */
  645. MSTPCR("tlb0", "cpu_clk", 0, 31),
  646. MSTPCR("ic0", "cpu_clk", 0, 30),
  647. MSTPCR("oc0", "cpu_clk", 0, 29),
  648. MSTPCR("rsmem0", "sh_clk", 0, 28),
  649. MSTPCR("xymem0", "cpu_clk", 0, 26),
  650. MSTPCR("intc30", "peripheral_clk", 0, 23),
  651. MSTPCR("intc0", "peripheral_clk", 0, 22),
  652. MSTPCR("dmac0", "bus_clk", 0, 21),
  653. MSTPCR("sh0", "sh_clk", 0, 20),
  654. MSTPCR("hudi0", "peripheral_clk", 0, 19),
  655. MSTPCR("ubc0", "cpu_clk", 0, 17),
  656. MSTPCR("tmu0", "peripheral_clk", 0, 15),
  657. MSTPCR("cmt0", "r_clk", 0, 14),
  658. MSTPCR("rwdt0", "r_clk", 0, 13),
  659. MSTPCR("flctl0", "peripheral_clk", 0, 10),
  660. MSTPCR("scif0", "peripheral_clk", 0, 7),
  661. MSTPCR("scif1", "bus_clk", 0, 6),
  662. MSTPCR("scif2", "bus_clk", 0, 5),
  663. MSTPCR("msiof0", "peripheral_clk", 0, 2),
  664. MSTPCR("sbr0", "peripheral_clk", 0, 1),
  665. MSTPCR("i2c0", "peripheral_clk", 1, 9),
  666. MSTPCR("icb0", "bus_clk", 2, 27),
  667. MSTPCR("meram0", "sh_clk", 2, 26),
  668. MSTPCR("dacc0", "peripheral_clk", 2, 24),
  669. MSTPCR("dacy0", "peripheral_clk", 2, 23),
  670. MSTPCR("tsif0", "bus_clk", 2, 22),
  671. MSTPCR("sdhi0", "bus_clk", 2, 18),
  672. MSTPCR("mmcif0", "bus_clk", 2, 17),
  673. MSTPCR("usb0", "bus_clk", 2, 11),
  674. MSTPCR("siu0", "bus_clk", 2, 8),
  675. MSTPCR("veu1", "bus_clk", 2, 7),
  676. MSTPCR("vou0", "bus_clk", 2, 5),
  677. MSTPCR("beu0", "bus_clk", 2, 4),
  678. MSTPCR("ceu0", "bus_clk", 2, 3),
  679. MSTPCR("veu0", "bus_clk", 2, 2),
  680. MSTPCR("vpu0", "bus_clk", 2, 1),
  681. MSTPCR("lcdc0", "bus_clk", 2, 0),
  682. #endif
  683. };
  684. static struct clk *sh7722_clocks[] = {
  685. &sh7722_umem_clock,
  686. &sh7722_sh_clock,
  687. &sh7722_peripheral_clock,
  688. &sh7722_sdram_clock,
  689. #ifndef CONFIG_CPU_SUBTYPE_SH7343
  690. &sh7722_siu_a_clock,
  691. &sh7722_siu_b_clock,
  692. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  693. &sh7722_irda_clock,
  694. #endif
  695. #endif
  696. &sh7722_video_clock,
  697. };
  698. /*
  699. * init in order: master, module, bus, cpu
  700. */
  701. struct clk_ops *onchip_ops[] = {
  702. &sh7722_master_clk_ops,
  703. &sh7722_module_clk_ops,
  704. &sh7722_frqcr_clk_ops,
  705. &sh7722_frqcr_clk_ops,
  706. };
  707. void __init
  708. arch_init_clk_ops(struct clk_ops **ops, int type)
  709. {
  710. BUG_ON(type < 0 || type > ARRAY_SIZE(onchip_ops));
  711. *ops = onchip_ops[type];
  712. }
  713. int __init arch_clk_init(void)
  714. {
  715. struct clk *clk;
  716. int i;
  717. clk = clk_get(NULL, "master_clk");
  718. for (i = 0; i < ARRAY_SIZE(sh7722_clocks); i++) {
  719. pr_debug( "Registering clock '%s'\n", sh7722_clocks[i]->name);
  720. sh7722_clocks[i]->parent = clk;
  721. clk_register(sh7722_clocks[i]);
  722. }
  723. clk_put(clk);
  724. clk_register(&sh7722_r_clock);
  725. for (i = 0; i < ARRAY_SIZE(sh7722_mstpcr_clocks); i++) {
  726. pr_debug( "Registering mstpcr clock '%s'\n",
  727. sh7722_mstpcr_clocks[i].name);
  728. clk = clk_get(NULL, (void *) sh7722_mstpcr_clocks[i].ops);
  729. sh7722_mstpcr_clocks[i].parent = clk;
  730. sh7722_mstpcr_clocks[i].ops = &sh7722_mstpcr_clk_ops;
  731. clk_register(&sh7722_mstpcr_clocks[i]);
  732. clk_put(clk);
  733. }
  734. clk_recalc_rate(&sh7722_r_clock); /* make sure rate gets propagated */
  735. return 0;
  736. }