clock-sh7722.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /*
  2. * arch/sh/kernel/cpu/sh4a/clock-sh7722.c
  3. *
  4. * SH7722 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. #define STCPLL(frqcr) (((frqcr >> 24) & 0x1f) + 1)
  117. /*
  118. * Instead of having two separate multipliers/divisors set, like this:
  119. *
  120. * static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  121. * static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
  122. *
  123. * I created the divisors2 array, which is used to calculate rate like
  124. * rate = parent * 2 / divisors2[ divisor ];
  125. */
  126. static int divisors2[] = { 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32, 40 };
  127. static unsigned long master_clk_recalc(struct clk *clk)
  128. {
  129. unsigned frqcr = ctrl_inl(FRQCR);
  130. return CONFIG_SH_PCLK_FREQ * STCPLL(frqcr);
  131. }
  132. static void master_clk_init(struct clk *clk)
  133. {
  134. clk->parent = NULL;
  135. clk->rate = master_clk_recalc(clk);
  136. }
  137. static unsigned long module_clk_recalc(struct clk *clk)
  138. {
  139. unsigned long frqcr = ctrl_inl(FRQCR);
  140. return clk->parent->rate / STCPLL(frqcr);
  141. }
  142. #define MASTERDIVS { 2, 3, 4, 6, 8, 16 }
  143. #define STCMASK 0x1f
  144. #define DIVCALC(div) (div-1)
  145. #define FRQCRKICK 0x00000000
  146. static int master_clk_setrate(struct clk *clk, unsigned long rate, int id)
  147. {
  148. int div = rate / clk->rate;
  149. int master_divs[] = MASTERDIVS;
  150. int index;
  151. unsigned long frqcr;
  152. for (index = 1; index < ARRAY_SIZE(master_divs); index++)
  153. if (div >= master_divs[index - 1] && div < master_divs[index])
  154. break;
  155. if (index >= ARRAY_SIZE(master_divs))
  156. index = ARRAY_SIZE(master_divs);
  157. div = master_divs[index - 1];
  158. frqcr = ctrl_inl(FRQCR);
  159. frqcr &= ~(STCMASK << 24);
  160. frqcr |= (DIVCALC(div) << 24);
  161. frqcr |= FRQCRKICK;
  162. ctrl_outl(frqcr, FRQCR);
  163. return 0;
  164. }
  165. static struct clk_ops sh7722_master_clk_ops = {
  166. .init = master_clk_init,
  167. .recalc = master_clk_recalc,
  168. .set_rate = master_clk_setrate,
  169. };
  170. static struct clk_ops sh7722_module_clk_ops = {
  171. .recalc = module_clk_recalc,
  172. };
  173. struct frqcr_context {
  174. unsigned mask;
  175. unsigned shift;
  176. };
  177. struct frqcr_context sh7722_get_clk_context(const char *name)
  178. {
  179. struct frqcr_context ctx = { 0, };
  180. if (!strcmp(name, "peripheral_clk")) {
  181. ctx.shift = 0;
  182. ctx.mask = 0xF;
  183. } else if (!strcmp(name, "sdram_clk")) {
  184. ctx.shift = 4;
  185. ctx.mask = 0xF;
  186. } else if (!strcmp(name, "bus_clk")) {
  187. ctx.shift = 8;
  188. ctx.mask = 0xF;
  189. } else if (!strcmp(name, "sh_clk")) {
  190. ctx.shift = 12;
  191. ctx.mask = 0xF;
  192. } else if (!strcmp(name, "umem_clk")) {
  193. ctx.shift = 16;
  194. ctx.mask = 0xF;
  195. } else if (!strcmp(name, "cpu_clk")) {
  196. ctx.shift = 20;
  197. ctx.mask = 7;
  198. }
  199. return ctx;
  200. }
  201. /**
  202. * sh7722_find_div_index - find divisor for setting rate
  203. *
  204. * All sh7722 clocks use the same set of multipliers/divisors. This function
  205. * chooses correct divisor to set the rate of clock with parent clock that
  206. * generates frequency of 'parent_rate'
  207. *
  208. * @parent_rate: rate of parent clock
  209. * @rate: requested rate to be set
  210. */
  211. static int sh7722_find_div_index(unsigned long parent_rate, unsigned rate)
  212. {
  213. unsigned div2 = parent_rate * 2 / rate;
  214. int index;
  215. if (rate > parent_rate)
  216. return -EINVAL;
  217. for (index = 1; index < ARRAY_SIZE(divisors2); index++) {
  218. if (div2 > divisors2[index - 1] && div2 <= divisors2[index])
  219. break;
  220. }
  221. if (index >= ARRAY_SIZE(divisors2))
  222. index = ARRAY_SIZE(divisors2) - 1;
  223. return index;
  224. }
  225. static unsigned long sh7722_frqcr_recalc(struct clk *clk)
  226. {
  227. struct frqcr_context ctx = sh7722_get_clk_context(clk->name);
  228. unsigned long frqcr = ctrl_inl(FRQCR);
  229. int index;
  230. index = (frqcr >> ctx.shift) & ctx.mask;
  231. return clk->parent->rate * 2 / divisors2[index];
  232. }
  233. static int sh7722_frqcr_set_rate(struct clk *clk, unsigned long rate,
  234. int algo_id)
  235. {
  236. struct frqcr_context ctx = sh7722_get_clk_context(clk->name);
  237. unsigned long parent_rate = clk->parent->rate;
  238. int div;
  239. unsigned long frqcr;
  240. int err = 0;
  241. /* pretty invalid */
  242. if (parent_rate < rate)
  243. return -EINVAL;
  244. /* look for multiplier/divisor pair */
  245. div = sh7722_find_div_index(parent_rate, rate);
  246. if (div<0)
  247. return div;
  248. /* calculate new value of clock rate */
  249. clk->rate = parent_rate * 2 / divisors2[div];
  250. frqcr = ctrl_inl(FRQCR);
  251. /* FIXME: adjust as algo_id specifies */
  252. if (algo_id != NO_CHANGE) {
  253. int originator;
  254. char *algo_group_1[] = { "cpu_clk", "umem_clk", "sh_clk" };
  255. char *algo_group_2[] = { "sh_clk", "bus_clk" };
  256. char *algo_group_3[] = { "sh_clk", "sdram_clk" };
  257. char *algo_group_4[] = { "bus_clk", "peripheral_clk" };
  258. char *algo_group_5[] = { "cpu_clk", "peripheral_clk" };
  259. char **algo_current = NULL;
  260. /* 3 is the maximum number of clocks in relation */
  261. struct clk *ck[3];
  262. unsigned long values[3]; /* the same comment as above */
  263. int part_length = -1;
  264. int i;
  265. /*
  266. * all the steps below only required if adjustion was
  267. * requested
  268. */
  269. if (algo_id == IUS_N1_N1 ||
  270. algo_id == IUS_322 ||
  271. algo_id == IUS_522 ||
  272. algo_id == IUS_N11) {
  273. algo_current = algo_group_1;
  274. part_length = 3;
  275. }
  276. if (algo_id == SB_N1) {
  277. algo_current = algo_group_2;
  278. part_length = 2;
  279. }
  280. if (algo_id == SB3_N1 ||
  281. algo_id == SB3_32 ||
  282. algo_id == SB3_43 ||
  283. algo_id == SB3_54) {
  284. algo_current = algo_group_3;
  285. part_length = 2;
  286. }
  287. if (algo_id == BP_N1) {
  288. algo_current = algo_group_4;
  289. part_length = 2;
  290. }
  291. if (algo_id == IP_N1) {
  292. algo_current = algo_group_5;
  293. part_length = 2;
  294. }
  295. if (!algo_current)
  296. goto incorrect_algo_id;
  297. originator = -1;
  298. for (i = 0; i < part_length; i ++ ) {
  299. if (originator >= 0 && !strcmp(clk->name,
  300. algo_current[i]))
  301. originator = i;
  302. ck[i] = clk_get(NULL, algo_current[i]);
  303. values[i] = clk_get_rate(ck[i]);
  304. }
  305. if (originator >= 0)
  306. adjust_clocks(originator, adjust_algos[algo_id],
  307. values, part_length);
  308. for (i = 0; i < part_length; i ++ ) {
  309. struct frqcr_context part_ctx;
  310. int part_div;
  311. if (likely(!err)) {
  312. part_div = sh7722_find_div_index(parent_rate,
  313. rate);
  314. if (part_div > 0) {
  315. part_ctx = sh7722_get_clk_context(
  316. ck[i]->name);
  317. frqcr &= ~(part_ctx.mask <<
  318. part_ctx.shift);
  319. frqcr |= part_div << part_ctx.shift;
  320. } else
  321. err = part_div;
  322. }
  323. ck[i]->ops->recalc(ck[i]);
  324. clk_put(ck[i]);
  325. }
  326. }
  327. /* was there any error during recalculation ? If so, bail out.. */
  328. if (unlikely(err!=0))
  329. goto out_err;
  330. /* clear FRQCR bits */
  331. frqcr &= ~(ctx.mask << ctx.shift);
  332. frqcr |= div << ctx.shift;
  333. frqcr |= FRQCRKICK;
  334. /* ...and perform actual change */
  335. ctrl_outl(frqcr, FRQCR);
  336. return 0;
  337. incorrect_algo_id:
  338. return -EINVAL;
  339. out_err:
  340. return err;
  341. }
  342. static long sh7722_frqcr_round_rate(struct clk *clk, unsigned long rate)
  343. {
  344. unsigned long parent_rate = clk->parent->rate;
  345. int div;
  346. /* look for multiplier/divisor pair */
  347. div = sh7722_find_div_index(parent_rate, rate);
  348. if (div < 0)
  349. return clk->rate;
  350. /* calculate new value of clock rate */
  351. return parent_rate * 2 / divisors2[div];
  352. }
  353. static struct clk_ops sh7722_frqcr_clk_ops = {
  354. .recalc = sh7722_frqcr_recalc,
  355. .set_rate = sh7722_frqcr_set_rate,
  356. .round_rate = sh7722_frqcr_round_rate,
  357. };
  358. /*
  359. * clock ops methods for SIU A/B and IrDA clock
  360. */
  361. static int sh7722_siu_set_rate(struct clk *clk, unsigned long rate, int algo_id)
  362. {
  363. unsigned long r;
  364. int div;
  365. r = ctrl_inl(clk->arch_flags);
  366. div = sh7722_find_div_index(clk->parent->rate, rate);
  367. if (div < 0)
  368. return div;
  369. r = (r & ~0xF) | div;
  370. ctrl_outl(r, clk->arch_flags);
  371. return 0;
  372. }
  373. static unsigned long sh7722_siu_recalc(struct clk *clk)
  374. {
  375. unsigned long r;
  376. r = ctrl_inl(clk->arch_flags);
  377. return clk->parent->rate * 2 / divisors2[r & 0xF];
  378. }
  379. static int sh7722_siu_start_stop(struct clk *clk, int enable)
  380. {
  381. unsigned long r;
  382. r = ctrl_inl(clk->arch_flags);
  383. if (enable)
  384. ctrl_outl(r & ~(1 << 8), clk->arch_flags);
  385. else
  386. ctrl_outl(r | (1 << 8), clk->arch_flags);
  387. return 0;
  388. }
  389. static int sh7722_siu_enable(struct clk *clk)
  390. {
  391. return sh7722_siu_start_stop(clk, 1);
  392. }
  393. static void sh7722_siu_disable(struct clk *clk)
  394. {
  395. sh7722_siu_start_stop(clk, 0);
  396. }
  397. static struct clk_ops sh7722_siu_clk_ops = {
  398. .recalc = sh7722_siu_recalc,
  399. .set_rate = sh7722_siu_set_rate,
  400. .enable = sh7722_siu_enable,
  401. .disable = sh7722_siu_disable,
  402. };
  403. static int sh7722_video_enable(struct clk *clk)
  404. {
  405. unsigned long r;
  406. r = ctrl_inl(VCLKCR);
  407. ctrl_outl( r & ~(1<<8), VCLKCR);
  408. return 0;
  409. }
  410. static void sh7722_video_disable(struct clk *clk)
  411. {
  412. unsigned long r;
  413. r = ctrl_inl(VCLKCR);
  414. ctrl_outl( r | (1<<8), VCLKCR);
  415. }
  416. static int sh7722_video_set_rate(struct clk *clk, unsigned long rate,
  417. int algo_id)
  418. {
  419. unsigned long r;
  420. r = ctrl_inl(VCLKCR);
  421. r &= ~0x3F;
  422. r |= ((clk->parent->rate / rate - 1) & 0x3F);
  423. ctrl_outl(r, VCLKCR);
  424. return 0;
  425. }
  426. static unsigned long sh7722_video_recalc(struct clk *clk)
  427. {
  428. unsigned long r;
  429. r = ctrl_inl(VCLKCR);
  430. return clk->parent->rate / ((r & 0x3F) + 1);
  431. }
  432. static struct clk_ops sh7722_video_clk_ops = {
  433. .recalc = sh7722_video_recalc,
  434. .set_rate = sh7722_video_set_rate,
  435. .enable = sh7722_video_enable,
  436. .disable = sh7722_video_disable,
  437. };
  438. /*
  439. * and at last, clock definitions themselves
  440. */
  441. static struct clk sh7722_umem_clock = {
  442. .name = "umem_clk",
  443. .ops = &sh7722_frqcr_clk_ops,
  444. };
  445. static struct clk sh7722_sh_clock = {
  446. .name = "sh_clk",
  447. .ops = &sh7722_frqcr_clk_ops,
  448. };
  449. static struct clk sh7722_peripheral_clock = {
  450. .name = "peripheral_clk",
  451. .ops = &sh7722_frqcr_clk_ops,
  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. };
  461. /*
  462. * these three clocks - SIU A, SIU B, IrDA - share the same clk_ops
  463. * methods of clk_ops determine which register they should access by
  464. * examining clk->name field
  465. */
  466. static struct clk sh7722_siu_a_clock = {
  467. .name = "siu_a_clk",
  468. .arch_flags = SCLKACR,
  469. .ops = &sh7722_siu_clk_ops,
  470. };
  471. static struct clk sh7722_siu_b_clock = {
  472. .name = "siu_b_clk",
  473. .arch_flags = SCLKBCR,
  474. .ops = &sh7722_siu_clk_ops,
  475. };
  476. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  477. static struct clk sh7722_irda_clock = {
  478. .name = "irda_clk",
  479. .arch_flags = IrDACLKCR,
  480. .ops = &sh7722_siu_clk_ops,
  481. };
  482. #endif
  483. static struct clk sh7722_video_clock = {
  484. .name = "video_clk",
  485. .ops = &sh7722_video_clk_ops,
  486. };
  487. #define MSTPCR_ARCH_FLAGS(reg, bit) (((reg) << 8) | (bit))
  488. #define MSTPCR_ARCH_FLAGS_REG(value) ((value) >> 8)
  489. #define MSTPCR_ARCH_FLAGS_BIT(value) ((value) & 0xff)
  490. static int sh7722_mstpcr_start_stop(struct clk *clk, int enable)
  491. {
  492. unsigned long bit = MSTPCR_ARCH_FLAGS_BIT(clk->arch_flags);
  493. unsigned long reg;
  494. unsigned long r;
  495. switch(MSTPCR_ARCH_FLAGS_REG(clk->arch_flags)) {
  496. case 0:
  497. reg = MSTPCR0;
  498. break;
  499. case 1:
  500. reg = MSTPCR1;
  501. break;
  502. case 2:
  503. reg = MSTPCR2;
  504. break;
  505. default:
  506. return -EINVAL;
  507. }
  508. r = ctrl_inl(reg);
  509. if (enable)
  510. r &= ~(1 << bit);
  511. else
  512. r |= (1 << bit);
  513. ctrl_outl(r, reg);
  514. return 0;
  515. }
  516. static int sh7722_mstpcr_enable(struct clk *clk)
  517. {
  518. return sh7722_mstpcr_start_stop(clk, 1);
  519. }
  520. static void sh7722_mstpcr_disable(struct clk *clk)
  521. {
  522. sh7722_mstpcr_start_stop(clk, 0);
  523. }
  524. static struct clk_ops sh7722_mstpcr_clk_ops = {
  525. .enable = sh7722_mstpcr_enable,
  526. .disable = sh7722_mstpcr_disable,
  527. .recalc = followparent_recalc,
  528. };
  529. #define MSTPCR(_name, _parent, regnr, bitnr, _flags) \
  530. { \
  531. .name = _name, \
  532. .flags = _flags, \
  533. .arch_flags = MSTPCR_ARCH_FLAGS(regnr, bitnr), \
  534. .ops = (void *)_parent, \
  535. }
  536. static struct clk sh7722_mstpcr_clocks[] = {
  537. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  538. MSTPCR("uram0", "umem_clk", 0, 28, CLK_ENABLE_ON_INIT),
  539. MSTPCR("xymem0", "bus_clk", 0, 26, CLK_ENABLE_ON_INIT),
  540. MSTPCR("tmu0", "peripheral_clk", 0, 15, 0),
  541. MSTPCR("cmt0", "r_clk", 0, 14, 0),
  542. MSTPCR("rwdt0", "r_clk", 0, 13, 0),
  543. MSTPCR("flctl0", "peripheral_clk", 0, 10, 0),
  544. MSTPCR("scif0", "peripheral_clk", 0, 7, 0),
  545. MSTPCR("scif1", "peripheral_clk", 0, 6, 0),
  546. MSTPCR("scif2", "peripheral_clk", 0, 5, 0),
  547. MSTPCR("i2c0", "peripheral_clk", 1, 9, 0),
  548. MSTPCR("rtc0", "r_clk", 1, 8, 0),
  549. MSTPCR("sdhi0", "peripheral_clk", 2, 18, 0),
  550. MSTPCR("keysc0", "r_clk", 2, 14, 0),
  551. MSTPCR("usbf0", "peripheral_clk", 2, 11, 0),
  552. MSTPCR("2dg0", "bus_clk", 2, 9, 0),
  553. MSTPCR("siu0", "bus_clk", 2, 8, 0),
  554. MSTPCR("vou0", "bus_clk", 2, 5, 0),
  555. MSTPCR("jpu0", "bus_clk", 2, 6, CLK_ENABLE_ON_INIT),
  556. MSTPCR("beu0", "bus_clk", 2, 4, 0),
  557. MSTPCR("ceu0", "bus_clk", 2, 3, 0),
  558. MSTPCR("veu0", "bus_clk", 2, 2, CLK_ENABLE_ON_INIT),
  559. MSTPCR("vpu0", "bus_clk", 2, 1, CLK_ENABLE_ON_INIT),
  560. MSTPCR("lcdc0", "bus_clk", 2, 0, 0),
  561. #endif
  562. };
  563. static struct clk *sh7722_clocks[] = {
  564. &sh7722_umem_clock,
  565. &sh7722_sh_clock,
  566. &sh7722_peripheral_clock,
  567. &sh7722_sdram_clock,
  568. &sh7722_siu_a_clock,
  569. &sh7722_siu_b_clock,
  570. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  571. &sh7722_irda_clock,
  572. #endif
  573. &sh7722_video_clock,
  574. };
  575. /*
  576. * init in order: master, module, bus, cpu
  577. */
  578. struct clk_ops *onchip_ops[] = {
  579. &sh7722_master_clk_ops,
  580. &sh7722_module_clk_ops,
  581. &sh7722_frqcr_clk_ops,
  582. &sh7722_frqcr_clk_ops,
  583. };
  584. void __init
  585. arch_init_clk_ops(struct clk_ops **ops, int type)
  586. {
  587. BUG_ON(type < 0 || type >= ARRAY_SIZE(onchip_ops));
  588. *ops = onchip_ops[type];
  589. }
  590. int __init arch_clk_init(void)
  591. {
  592. struct clk *clk;
  593. int i;
  594. cpg_clk_init();
  595. clk = clk_get(NULL, "master_clk");
  596. for (i = 0; i < ARRAY_SIZE(sh7722_clocks); i++) {
  597. pr_debug( "Registering clock '%s'\n", sh7722_clocks[i]->name);
  598. sh7722_clocks[i]->parent = clk;
  599. clk_register(sh7722_clocks[i]);
  600. }
  601. clk_put(clk);
  602. clk_register(&sh7722_r_clock);
  603. for (i = 0; i < ARRAY_SIZE(sh7722_mstpcr_clocks); i++) {
  604. pr_debug( "Registering mstpcr clock '%s'\n",
  605. sh7722_mstpcr_clocks[i].name);
  606. clk = clk_get(NULL, (void *) sh7722_mstpcr_clocks[i].ops);
  607. sh7722_mstpcr_clocks[i].parent = clk;
  608. sh7722_mstpcr_clocks[i].ops = &sh7722_mstpcr_clk_ops;
  609. clk_register(&sh7722_mstpcr_clocks[i]);
  610. clk_put(clk);
  611. }
  612. propagate_rate(&sh7722_r_clock); /* make sure rate gets propagated */
  613. return 0;
  614. }