clock-sh7722.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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_divisors - 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_divisors(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] && div2 <= divisors2[index])
  215. break;
  216. }
  217. if (index >= ARRAY_SIZE(divisors2))
  218. index = ARRAY_SIZE(divisors2) - 1;
  219. return divisors2[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_divisors(parent_rate, rate);
  242. if (div<0)
  243. return div;
  244. /* calculate new value of clock rate */
  245. clk->rate = parent_rate * 2 / 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_divisors(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_divisors(parent_rate, rate);
  343. if (div < 0)
  344. return clk->rate;
  345. /* calculate new value of clock rate */
  346. return parent_rate * 2 / 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_divisors(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. };
  442. static struct clk sh7722_sh_clock = {
  443. .name = "sh_clk",
  444. .ops = &sh7722_frqcr_clk_ops,
  445. };
  446. static struct clk sh7722_peripheral_clock = {
  447. .name = "peripheral_clk",
  448. .ops = &sh7722_frqcr_clk_ops,
  449. };
  450. static struct clk sh7722_sdram_clock = {
  451. .name = "sdram_clk",
  452. .ops = &sh7722_frqcr_clk_ops,
  453. };
  454. #ifndef CONFIG_CPU_SUBTYPE_SH7343
  455. /*
  456. * these three clocks - SIU A, SIU B, IrDA - share the same clk_ops
  457. * methods of clk_ops determine which register they should access by
  458. * examining clk->name field
  459. */
  460. static struct clk sh7722_siu_a_clock = {
  461. .name = "siu_a_clk",
  462. .arch_flags = SCLKACR,
  463. .ops = &sh7722_siu_clk_ops,
  464. };
  465. static struct clk sh7722_siu_b_clock = {
  466. .name = "siu_b_clk",
  467. .arch_flags = SCLKBCR,
  468. .ops = &sh7722_siu_clk_ops,
  469. };
  470. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  471. static struct clk sh7722_irda_clock = {
  472. .name = "irda_clk",
  473. .arch_flags = IrDACLKCR,
  474. .ops = &sh7722_siu_clk_ops,
  475. };
  476. #endif
  477. #endif /* CONFIG_CPU_SUBTYPE_SH7343 */
  478. static struct clk sh7722_video_clock = {
  479. .name = "video_clk",
  480. .ops = &sh7722_video_clk_ops,
  481. };
  482. static int sh7722_mstpcr_start_stop(struct clk *clk, unsigned long reg,
  483. int enable)
  484. {
  485. unsigned long bit = clk->arch_flags;
  486. unsigned long r;
  487. r = ctrl_inl(reg);
  488. if (enable)
  489. r &= ~(1 << bit);
  490. else
  491. r |= (1 << bit);
  492. ctrl_outl(r, reg);
  493. return 0;
  494. }
  495. static void sh7722_mstpcr0_enable(struct clk *clk)
  496. {
  497. sh7722_mstpcr_start_stop(clk, MSTPCR0, 1);
  498. }
  499. static void sh7722_mstpcr0_disable(struct clk *clk)
  500. {
  501. sh7722_mstpcr_start_stop(clk, MSTPCR0, 0);
  502. }
  503. static void sh7722_mstpcr1_enable(struct clk *clk)
  504. {
  505. sh7722_mstpcr_start_stop(clk, MSTPCR1, 1);
  506. }
  507. static void sh7722_mstpcr1_disable(struct clk *clk)
  508. {
  509. sh7722_mstpcr_start_stop(clk, MSTPCR1, 0);
  510. }
  511. static void sh7722_mstpcr2_enable(struct clk *clk)
  512. {
  513. sh7722_mstpcr_start_stop(clk, MSTPCR2, 1);
  514. }
  515. static void sh7722_mstpcr2_disable(struct clk *clk)
  516. {
  517. sh7722_mstpcr_start_stop(clk, MSTPCR2, 0);
  518. }
  519. static struct clk_ops sh7722_mstpcr0_clk_ops = {
  520. .enable = sh7722_mstpcr0_enable,
  521. .disable = sh7722_mstpcr0_disable,
  522. };
  523. static struct clk_ops sh7722_mstpcr1_clk_ops = {
  524. .enable = sh7722_mstpcr1_enable,
  525. .disable = sh7722_mstpcr1_disable,
  526. };
  527. static struct clk_ops sh7722_mstpcr2_clk_ops = {
  528. .enable = sh7722_mstpcr2_enable,
  529. .disable = sh7722_mstpcr2_disable,
  530. };
  531. #define DECLARE_MSTPCRN(regnr, bitnr, bitstr) \
  532. { \
  533. .name = "mstp" __stringify(regnr) bitstr, \
  534. .arch_flags = bitnr, \
  535. .ops = &sh7722_mstpcr ## regnr ## _clk_ops, \
  536. }
  537. #define DECLARE_MSTPCR(regnr) \
  538. DECLARE_MSTPCRN(regnr, 31, "31"), \
  539. DECLARE_MSTPCRN(regnr, 30, "30"), \
  540. DECLARE_MSTPCRN(regnr, 29, "29"), \
  541. DECLARE_MSTPCRN(regnr, 28, "28"), \
  542. DECLARE_MSTPCRN(regnr, 27, "27"), \
  543. DECLARE_MSTPCRN(regnr, 26, "26"), \
  544. DECLARE_MSTPCRN(regnr, 25, "25"), \
  545. DECLARE_MSTPCRN(regnr, 24, "24"), \
  546. DECLARE_MSTPCRN(regnr, 23, "23"), \
  547. DECLARE_MSTPCRN(regnr, 22, "22"), \
  548. DECLARE_MSTPCRN(regnr, 21, "21"), \
  549. DECLARE_MSTPCRN(regnr, 20, "20"), \
  550. DECLARE_MSTPCRN(regnr, 19, "19"), \
  551. DECLARE_MSTPCRN(regnr, 18, "18"), \
  552. DECLARE_MSTPCRN(regnr, 17, "17"), \
  553. DECLARE_MSTPCRN(regnr, 16, "16"), \
  554. DECLARE_MSTPCRN(regnr, 15, "15"), \
  555. DECLARE_MSTPCRN(regnr, 14, "14"), \
  556. DECLARE_MSTPCRN(regnr, 13, "13"), \
  557. DECLARE_MSTPCRN(regnr, 12, "12"), \
  558. DECLARE_MSTPCRN(regnr, 11, "11"), \
  559. DECLARE_MSTPCRN(regnr, 10, "10"), \
  560. DECLARE_MSTPCRN(regnr, 9, "09"), \
  561. DECLARE_MSTPCRN(regnr, 8, "08"), \
  562. DECLARE_MSTPCRN(regnr, 7, "07"), \
  563. DECLARE_MSTPCRN(regnr, 6, "06"), \
  564. DECLARE_MSTPCRN(regnr, 5, "05"), \
  565. DECLARE_MSTPCRN(regnr, 4, "04"), \
  566. DECLARE_MSTPCRN(regnr, 3, "03"), \
  567. DECLARE_MSTPCRN(regnr, 2, "02"), \
  568. DECLARE_MSTPCRN(regnr, 1, "01"), \
  569. DECLARE_MSTPCRN(regnr, 0, "00")
  570. static struct clk sh7722_mstpcr[] = {
  571. DECLARE_MSTPCR(0),
  572. DECLARE_MSTPCR(1),
  573. DECLARE_MSTPCR(2),
  574. };
  575. static struct clk *sh7722_clocks[] = {
  576. &sh7722_umem_clock,
  577. &sh7722_sh_clock,
  578. &sh7722_peripheral_clock,
  579. &sh7722_sdram_clock,
  580. #ifndef CONFIG_CPU_SUBTYPE_SH7343
  581. &sh7722_siu_a_clock,
  582. &sh7722_siu_b_clock,
  583. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  584. &sh7722_irda_clock,
  585. #endif
  586. #endif
  587. &sh7722_video_clock,
  588. };
  589. /*
  590. * init in order: master, module, bus, cpu
  591. */
  592. struct clk_ops *onchip_ops[] = {
  593. &sh7722_master_clk_ops,
  594. &sh7722_module_clk_ops,
  595. &sh7722_frqcr_clk_ops,
  596. &sh7722_frqcr_clk_ops,
  597. };
  598. void __init
  599. arch_init_clk_ops(struct clk_ops **ops, int type)
  600. {
  601. BUG_ON(type < 0 || type > ARRAY_SIZE(onchip_ops));
  602. *ops = onchip_ops[type];
  603. }
  604. int __init arch_clk_init(void)
  605. {
  606. struct clk *master;
  607. int i;
  608. master = clk_get(NULL, "master_clk");
  609. for (i = 0; i < ARRAY_SIZE(sh7722_clocks); i++) {
  610. pr_debug( "Registering clock '%s'\n", sh7722_clocks[i]->name);
  611. sh7722_clocks[i]->parent = master;
  612. clk_register(sh7722_clocks[i]);
  613. }
  614. clk_put(master);
  615. for (i = 0; i < ARRAY_SIZE(sh7722_mstpcr); i++) {
  616. pr_debug( "Registering mstpcr '%s'\n", sh7722_mstpcr[i].name);
  617. clk_register(&sh7722_mstpcr[i]);
  618. }
  619. return 0;
  620. }