clock-sh7722.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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. #if defined(CONFIG_CPU_SUBTYPE_SH7724)
  117. #define STCPLL(frqcr) ((((frqcr >> 24) & 0x3f) + 1) * 2)
  118. #else
  119. #define STCPLL(frqcr) (((frqcr >> 24) & 0x1f) + 1)
  120. #endif
  121. /*
  122. * Instead of having two separate multipliers/divisors set, like this:
  123. *
  124. * static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  125. * static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
  126. *
  127. * I created the divisors2 array, which is used to calculate rate like
  128. * rate = parent * 2 / divisors2[ divisor ];
  129. */
  130. #if defined(CONFIG_CPU_SUBTYPE_SH7724)
  131. static int divisors2[] = { 4, 1, 8, 12, 16, 24, 32, 1, 48, 64, 72, 96, 1, 144 };
  132. #else
  133. static int divisors2[] = { 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32, 40 };
  134. #endif
  135. static unsigned long master_clk_recalc(struct clk *clk)
  136. {
  137. unsigned frqcr = ctrl_inl(FRQCR);
  138. return CONFIG_SH_PCLK_FREQ * STCPLL(frqcr);
  139. }
  140. static void master_clk_init(struct clk *clk)
  141. {
  142. clk->parent = NULL;
  143. clk->rate = master_clk_recalc(clk);
  144. }
  145. static unsigned long module_clk_recalc(struct clk *clk)
  146. {
  147. unsigned long frqcr = ctrl_inl(FRQCR);
  148. return clk->parent->rate / STCPLL(frqcr);
  149. }
  150. #if defined(CONFIG_CPU_SUBTYPE_SH7724)
  151. #define MASTERDIVS { 12, 16, 24, 30, 32, 36, 48 }
  152. #define STCMASK 0x3f
  153. #define DIVCALC(div) (div/2-1)
  154. #define FRQCRKICK 0x80000000
  155. #elif defined(CONFIG_CPU_SUBTYPE_SH7723)
  156. #define MASTERDIVS { 6, 8, 12, 16 }
  157. #define STCMASK 0x1f
  158. #define DIVCALC(div) (div-1)
  159. #define FRQCRKICK 0x00000000
  160. #else
  161. #define MASTERDIVS { 2, 3, 4, 6, 8, 16 }
  162. #define STCMASK 0x1f
  163. #define DIVCALC(div) (div-1)
  164. #define FRQCRKICK 0x00000000
  165. #endif
  166. static int master_clk_setrate(struct clk *clk, unsigned long rate, int id)
  167. {
  168. int div = rate / clk->rate;
  169. int master_divs[] = MASTERDIVS;
  170. int index;
  171. unsigned long frqcr;
  172. for (index = 1; index < ARRAY_SIZE(master_divs); index++)
  173. if (div >= master_divs[index - 1] && div < master_divs[index])
  174. break;
  175. if (index >= ARRAY_SIZE(master_divs))
  176. index = ARRAY_SIZE(master_divs);
  177. div = master_divs[index - 1];
  178. frqcr = ctrl_inl(FRQCR);
  179. frqcr &= ~(STCMASK << 24);
  180. frqcr |= (DIVCALC(div) << 24);
  181. frqcr |= FRQCRKICK;
  182. ctrl_outl(frqcr, FRQCR);
  183. return 0;
  184. }
  185. static struct clk_ops sh7722_master_clk_ops = {
  186. .init = master_clk_init,
  187. .recalc = master_clk_recalc,
  188. .set_rate = master_clk_setrate,
  189. };
  190. static struct clk_ops sh7722_module_clk_ops = {
  191. .recalc = module_clk_recalc,
  192. };
  193. struct frqcr_context {
  194. unsigned mask;
  195. unsigned shift;
  196. };
  197. struct frqcr_context sh7722_get_clk_context(const char *name)
  198. {
  199. struct frqcr_context ctx = { 0, };
  200. if (!strcmp(name, "peripheral_clk")) {
  201. ctx.shift = 0;
  202. ctx.mask = 0xF;
  203. } else if (!strcmp(name, "sdram_clk")) {
  204. ctx.shift = 4;
  205. ctx.mask = 0xF;
  206. } else if (!strcmp(name, "bus_clk")) {
  207. ctx.shift = 8;
  208. ctx.mask = 0xF;
  209. } else if (!strcmp(name, "sh_clk")) {
  210. ctx.shift = 12;
  211. ctx.mask = 0xF;
  212. } else if (!strcmp(name, "umem_clk")) {
  213. ctx.shift = 16;
  214. ctx.mask = 0xF;
  215. } else if (!strcmp(name, "cpu_clk")) {
  216. ctx.shift = 20;
  217. ctx.mask = 7;
  218. }
  219. return ctx;
  220. }
  221. /**
  222. * sh7722_find_div_index - find divisor for setting rate
  223. *
  224. * All sh7722 clocks use the same set of multipliers/divisors. This function
  225. * chooses correct divisor to set the rate of clock with parent clock that
  226. * generates frequency of 'parent_rate'
  227. *
  228. * @parent_rate: rate of parent clock
  229. * @rate: requested rate to be set
  230. */
  231. static int sh7722_find_div_index(unsigned long parent_rate, unsigned rate)
  232. {
  233. unsigned div2 = parent_rate * 2 / rate;
  234. int index;
  235. if (rate > parent_rate)
  236. return -EINVAL;
  237. for (index = 1; index < ARRAY_SIZE(divisors2); index++) {
  238. if (div2 > divisors2[index - 1] && div2 <= divisors2[index])
  239. break;
  240. }
  241. if (index >= ARRAY_SIZE(divisors2))
  242. index = ARRAY_SIZE(divisors2) - 1;
  243. return index;
  244. }
  245. static unsigned long sh7722_frqcr_recalc(struct clk *clk)
  246. {
  247. struct frqcr_context ctx = sh7722_get_clk_context(clk->name);
  248. unsigned long frqcr = ctrl_inl(FRQCR);
  249. int index;
  250. index = (frqcr >> ctx.shift) & ctx.mask;
  251. return clk->parent->rate * 2 / divisors2[index];
  252. }
  253. static int sh7722_frqcr_set_rate(struct clk *clk, unsigned long rate,
  254. int algo_id)
  255. {
  256. struct frqcr_context ctx = sh7722_get_clk_context(clk->name);
  257. unsigned long parent_rate = clk->parent->rate;
  258. int div;
  259. unsigned long frqcr;
  260. int err = 0;
  261. /* pretty invalid */
  262. if (parent_rate < rate)
  263. return -EINVAL;
  264. /* look for multiplier/divisor pair */
  265. div = sh7722_find_div_index(parent_rate, rate);
  266. if (div<0)
  267. return div;
  268. /* calculate new value of clock rate */
  269. clk->rate = parent_rate * 2 / divisors2[div];
  270. frqcr = ctrl_inl(FRQCR);
  271. /* FIXME: adjust as algo_id specifies */
  272. if (algo_id != NO_CHANGE) {
  273. int originator;
  274. char *algo_group_1[] = { "cpu_clk", "umem_clk", "sh_clk" };
  275. char *algo_group_2[] = { "sh_clk", "bus_clk" };
  276. char *algo_group_3[] = { "sh_clk", "sdram_clk" };
  277. char *algo_group_4[] = { "bus_clk", "peripheral_clk" };
  278. char *algo_group_5[] = { "cpu_clk", "peripheral_clk" };
  279. char **algo_current = NULL;
  280. /* 3 is the maximum number of clocks in relation */
  281. struct clk *ck[3];
  282. unsigned long values[3]; /* the same comment as above */
  283. int part_length = -1;
  284. int i;
  285. /*
  286. * all the steps below only required if adjustion was
  287. * requested
  288. */
  289. if (algo_id == IUS_N1_N1 ||
  290. algo_id == IUS_322 ||
  291. algo_id == IUS_522 ||
  292. algo_id == IUS_N11) {
  293. algo_current = algo_group_1;
  294. part_length = 3;
  295. }
  296. if (algo_id == SB_N1) {
  297. algo_current = algo_group_2;
  298. part_length = 2;
  299. }
  300. if (algo_id == SB3_N1 ||
  301. algo_id == SB3_32 ||
  302. algo_id == SB3_43 ||
  303. algo_id == SB3_54) {
  304. algo_current = algo_group_3;
  305. part_length = 2;
  306. }
  307. if (algo_id == BP_N1) {
  308. algo_current = algo_group_4;
  309. part_length = 2;
  310. }
  311. if (algo_id == IP_N1) {
  312. algo_current = algo_group_5;
  313. part_length = 2;
  314. }
  315. if (!algo_current)
  316. goto incorrect_algo_id;
  317. originator = -1;
  318. for (i = 0; i < part_length; i ++ ) {
  319. if (originator >= 0 && !strcmp(clk->name,
  320. algo_current[i]))
  321. originator = i;
  322. ck[i] = clk_get(NULL, algo_current[i]);
  323. values[i] = clk_get_rate(ck[i]);
  324. }
  325. if (originator >= 0)
  326. adjust_clocks(originator, adjust_algos[algo_id],
  327. values, part_length);
  328. for (i = 0; i < part_length; i ++ ) {
  329. struct frqcr_context part_ctx;
  330. int part_div;
  331. if (likely(!err)) {
  332. part_div = sh7722_find_div_index(parent_rate,
  333. rate);
  334. if (part_div > 0) {
  335. part_ctx = sh7722_get_clk_context(
  336. ck[i]->name);
  337. frqcr &= ~(part_ctx.mask <<
  338. part_ctx.shift);
  339. frqcr |= part_div << part_ctx.shift;
  340. } else
  341. err = part_div;
  342. }
  343. ck[i]->ops->recalc(ck[i]);
  344. clk_put(ck[i]);
  345. }
  346. }
  347. /* was there any error during recalculation ? If so, bail out.. */
  348. if (unlikely(err!=0))
  349. goto out_err;
  350. /* clear FRQCR bits */
  351. frqcr &= ~(ctx.mask << ctx.shift);
  352. frqcr |= div << ctx.shift;
  353. frqcr |= FRQCRKICK;
  354. /* ...and perform actual change */
  355. ctrl_outl(frqcr, FRQCR);
  356. return 0;
  357. incorrect_algo_id:
  358. return -EINVAL;
  359. out_err:
  360. return err;
  361. }
  362. static long sh7722_frqcr_round_rate(struct clk *clk, unsigned long rate)
  363. {
  364. unsigned long parent_rate = clk->parent->rate;
  365. int div;
  366. /* look for multiplier/divisor pair */
  367. div = sh7722_find_div_index(parent_rate, rate);
  368. if (div < 0)
  369. return clk->rate;
  370. /* calculate new value of clock rate */
  371. return parent_rate * 2 / divisors2[div];
  372. }
  373. static struct clk_ops sh7722_frqcr_clk_ops = {
  374. .recalc = sh7722_frqcr_recalc,
  375. .set_rate = sh7722_frqcr_set_rate,
  376. .round_rate = sh7722_frqcr_round_rate,
  377. };
  378. /*
  379. * clock ops methods for SIU A/B and IrDA clock
  380. */
  381. #ifndef CONFIG_CPU_SUBTYPE_SH7343
  382. static int sh7722_siu_set_rate(struct clk *clk, unsigned long rate, int algo_id)
  383. {
  384. unsigned long r;
  385. int div;
  386. r = ctrl_inl(clk->arch_flags);
  387. div = sh7722_find_div_index(clk->parent->rate, rate);
  388. if (div < 0)
  389. return div;
  390. r = (r & ~0xF) | div;
  391. ctrl_outl(r, clk->arch_flags);
  392. return 0;
  393. }
  394. static unsigned long sh7722_siu_recalc(struct clk *clk)
  395. {
  396. unsigned long r;
  397. r = ctrl_inl(clk->arch_flags);
  398. return clk->parent->rate * 2 / divisors2[r & 0xF];
  399. }
  400. static int sh7722_siu_start_stop(struct clk *clk, int enable)
  401. {
  402. unsigned long r;
  403. r = ctrl_inl(clk->arch_flags);
  404. if (enable)
  405. ctrl_outl(r & ~(1 << 8), clk->arch_flags);
  406. else
  407. ctrl_outl(r | (1 << 8), clk->arch_flags);
  408. return 0;
  409. }
  410. static void sh7722_siu_enable(struct clk *clk)
  411. {
  412. sh7722_siu_start_stop(clk, 1);
  413. }
  414. static void sh7722_siu_disable(struct clk *clk)
  415. {
  416. sh7722_siu_start_stop(clk, 0);
  417. }
  418. static struct clk_ops sh7722_siu_clk_ops = {
  419. .recalc = sh7722_siu_recalc,
  420. .set_rate = sh7722_siu_set_rate,
  421. .enable = sh7722_siu_enable,
  422. .disable = sh7722_siu_disable,
  423. };
  424. #endif /* CONFIG_CPU_SUBTYPE_SH7343 */
  425. static void sh7722_video_enable(struct clk *clk)
  426. {
  427. unsigned long r;
  428. r = ctrl_inl(VCLKCR);
  429. ctrl_outl( r & ~(1<<8), VCLKCR);
  430. }
  431. static void sh7722_video_disable(struct clk *clk)
  432. {
  433. unsigned long r;
  434. r = ctrl_inl(VCLKCR);
  435. ctrl_outl( r | (1<<8), VCLKCR);
  436. }
  437. static int sh7722_video_set_rate(struct clk *clk, unsigned long rate,
  438. int algo_id)
  439. {
  440. unsigned long r;
  441. r = ctrl_inl(VCLKCR);
  442. r &= ~0x3F;
  443. r |= ((clk->parent->rate / rate - 1) & 0x3F);
  444. ctrl_outl(r, VCLKCR);
  445. return 0;
  446. }
  447. static unsigned long sh7722_video_recalc(struct clk *clk)
  448. {
  449. unsigned long r;
  450. r = ctrl_inl(VCLKCR);
  451. return clk->parent->rate / ((r & 0x3F) + 1);
  452. }
  453. static struct clk_ops sh7722_video_clk_ops = {
  454. .recalc = sh7722_video_recalc,
  455. .set_rate = sh7722_video_set_rate,
  456. .enable = sh7722_video_enable,
  457. .disable = sh7722_video_disable,
  458. };
  459. /*
  460. * and at last, clock definitions themselves
  461. */
  462. static struct clk sh7722_umem_clock = {
  463. .name = "umem_clk",
  464. .ops = &sh7722_frqcr_clk_ops,
  465. };
  466. static struct clk sh7722_sh_clock = {
  467. .name = "sh_clk",
  468. .ops = &sh7722_frqcr_clk_ops,
  469. };
  470. static struct clk sh7722_peripheral_clock = {
  471. .name = "peripheral_clk",
  472. .ops = &sh7722_frqcr_clk_ops,
  473. };
  474. static struct clk sh7722_sdram_clock = {
  475. .name = "sdram_clk",
  476. .ops = &sh7722_frqcr_clk_ops,
  477. };
  478. static struct clk sh7722_r_clock = {
  479. .name = "r_clk",
  480. .rate = 32768,
  481. };
  482. #if !defined(CONFIG_CPU_SUBTYPE_SH7343) &&\
  483. !defined(CONFIG_CPU_SUBTYPE_SH7724)
  484. /*
  485. * these three clocks - SIU A, SIU B, IrDA - share the same clk_ops
  486. * methods of clk_ops determine which register they should access by
  487. * examining clk->name field
  488. */
  489. static struct clk sh7722_siu_a_clock = {
  490. .name = "siu_a_clk",
  491. .arch_flags = SCLKACR,
  492. .ops = &sh7722_siu_clk_ops,
  493. };
  494. static struct clk sh7722_siu_b_clock = {
  495. .name = "siu_b_clk",
  496. .arch_flags = SCLKBCR,
  497. .ops = &sh7722_siu_clk_ops,
  498. };
  499. #endif /* CONFIG_CPU_SUBTYPE_SH7343, SH7724 */
  500. #if defined(CONFIG_CPU_SUBTYPE_SH7722) ||\
  501. defined(CONFIG_CPU_SUBTYPE_SH7724)
  502. static struct clk sh7722_irda_clock = {
  503. .name = "irda_clk",
  504. .arch_flags = IrDACLKCR,
  505. .ops = &sh7722_siu_clk_ops,
  506. };
  507. #endif
  508. static struct clk sh7722_video_clock = {
  509. .name = "video_clk",
  510. .ops = &sh7722_video_clk_ops,
  511. };
  512. #define MSTPCR_ARCH_FLAGS(reg, bit) (((reg) << 8) | (bit))
  513. #define MSTPCR_ARCH_FLAGS_REG(value) ((value) >> 8)
  514. #define MSTPCR_ARCH_FLAGS_BIT(value) ((value) & 0xff)
  515. static int sh7722_mstpcr_start_stop(struct clk *clk, int enable)
  516. {
  517. unsigned long bit = MSTPCR_ARCH_FLAGS_BIT(clk->arch_flags);
  518. unsigned long reg;
  519. unsigned long r;
  520. switch(MSTPCR_ARCH_FLAGS_REG(clk->arch_flags)) {
  521. case 0:
  522. reg = MSTPCR0;
  523. break;
  524. case 1:
  525. reg = MSTPCR1;
  526. break;
  527. case 2:
  528. reg = MSTPCR2;
  529. break;
  530. default:
  531. return -EINVAL;
  532. }
  533. r = ctrl_inl(reg);
  534. if (enable)
  535. r &= ~(1 << bit);
  536. else
  537. r |= (1 << bit);
  538. ctrl_outl(r, reg);
  539. return 0;
  540. }
  541. static void sh7722_mstpcr_enable(struct clk *clk)
  542. {
  543. sh7722_mstpcr_start_stop(clk, 1);
  544. }
  545. static void sh7722_mstpcr_disable(struct clk *clk)
  546. {
  547. sh7722_mstpcr_start_stop(clk, 0);
  548. }
  549. static struct clk_ops sh7722_mstpcr_clk_ops = {
  550. .enable = sh7722_mstpcr_enable,
  551. .disable = sh7722_mstpcr_disable,
  552. .recalc = followparent_recalc,
  553. };
  554. #define MSTPCR(_name, _parent, regnr, bitnr, _flags) \
  555. { \
  556. .name = _name, \
  557. .flags = _flags, \
  558. .arch_flags = MSTPCR_ARCH_FLAGS(regnr, bitnr), \
  559. .ops = (void *)_parent, \
  560. }
  561. static struct clk sh7722_mstpcr_clocks[] = {
  562. #if defined(CONFIG_CPU_SUBTYPE_SH7722)
  563. MSTPCR("uram0", "umem_clk", 0, 28, CLK_ENABLE_ON_INIT),
  564. MSTPCR("xymem0", "bus_clk", 0, 26, CLK_ENABLE_ON_INIT),
  565. MSTPCR("tmu0", "peripheral_clk", 0, 15, 0),
  566. MSTPCR("cmt0", "r_clk", 0, 14, 0),
  567. MSTPCR("rwdt0", "r_clk", 0, 13, 0),
  568. MSTPCR("flctl0", "peripheral_clk", 0, 10, 0),
  569. MSTPCR("scif0", "peripheral_clk", 0, 7, 0),
  570. MSTPCR("scif1", "peripheral_clk", 0, 6, 0),
  571. MSTPCR("scif2", "peripheral_clk", 0, 5, 0),
  572. MSTPCR("i2c0", "peripheral_clk", 1, 9, 0),
  573. MSTPCR("rtc0", "r_clk", 1, 8, 0),
  574. MSTPCR("sdhi0", "peripheral_clk", 2, 18, 0),
  575. MSTPCR("keysc0", "r_clk", 2, 14, 0),
  576. MSTPCR("usbf0", "peripheral_clk", 2, 11, 0),
  577. MSTPCR("2dg0", "bus_clk", 2, 9, 0),
  578. MSTPCR("siu0", "bus_clk", 2, 8, 0),
  579. MSTPCR("vou0", "bus_clk", 2, 5, 0),
  580. MSTPCR("jpu0", "bus_clk", 2, 6, CLK_ENABLE_ON_INIT),
  581. MSTPCR("beu0", "bus_clk", 2, 4, 0),
  582. MSTPCR("ceu0", "bus_clk", 2, 3, 0),
  583. MSTPCR("veu0", "bus_clk", 2, 2, CLK_ENABLE_ON_INIT),
  584. MSTPCR("vpu0", "bus_clk", 2, 1, CLK_ENABLE_ON_INIT),
  585. MSTPCR("lcdc0", "bus_clk", 2, 0, 0),
  586. #endif
  587. #if defined(CONFIG_CPU_SUBTYPE_SH7723)
  588. /* See page 60 of Datasheet V1.0: Overview -> Block Diagram */
  589. MSTPCR("tlb0", "cpu_clk", 0, 31, 0),
  590. MSTPCR("ic0", "cpu_clk", 0, 30, 0),
  591. MSTPCR("oc0", "cpu_clk", 0, 29, 0),
  592. MSTPCR("l2c0", "sh_clk", 0, 28, 0),
  593. MSTPCR("ilmem0", "cpu_clk", 0, 27, 0),
  594. MSTPCR("fpu0", "cpu_clk", 0, 24, 0),
  595. MSTPCR("intc0", "cpu_clk", 0, 22, 0),
  596. MSTPCR("dmac0", "bus_clk", 0, 21, 0),
  597. MSTPCR("sh0", "sh_clk", 0, 20, 0),
  598. MSTPCR("hudi0", "peripheral_clk", 0, 19, 0),
  599. MSTPCR("ubc0", "cpu_clk", 0, 17, 0),
  600. MSTPCR("tmu0", "peripheral_clk", 0, 15, 0),
  601. MSTPCR("cmt0", "r_clk", 0, 14, 0),
  602. MSTPCR("rwdt0", "r_clk", 0, 13, 0),
  603. MSTPCR("dmac1", "bus_clk", 0, 12, 0),
  604. MSTPCR("tmu1", "peripheral_clk", 0, 11, 0),
  605. MSTPCR("flctl0", "peripheral_clk", 0, 10, 0),
  606. MSTPCR("scif0", "peripheral_clk", 0, 9, 0),
  607. MSTPCR("scif1", "peripheral_clk", 0, 8, 0),
  608. MSTPCR("scif2", "peripheral_clk", 0, 7, 0),
  609. MSTPCR("scif3", "bus_clk", 0, 6, 0),
  610. MSTPCR("scif4", "bus_clk", 0, 5, 0),
  611. MSTPCR("scif5", "bus_clk", 0, 4, 0),
  612. MSTPCR("msiof0", "bus_clk", 0, 2, 0),
  613. MSTPCR("msiof1", "bus_clk", 0, 1, 0),
  614. MSTPCR("meram0", "sh_clk", 0, 0, CLK_ENABLE_ON_INIT),
  615. MSTPCR("i2c0", "peripheral_clk", 1, 9, 0),
  616. MSTPCR("rtc0", "r_clk", 1, 8, 0),
  617. MSTPCR("atapi0", "sh_clk", 2, 28, 0),
  618. MSTPCR("adc0", "peripheral_clk", 2, 28, 0),
  619. MSTPCR("tpu0", "bus_clk", 2, 25, 0),
  620. MSTPCR("irda0", "peripheral_clk", 2, 24, 0),
  621. MSTPCR("tsif0", "bus_clk", 2, 22, 0),
  622. MSTPCR("icb0", "bus_clk", 2, 21, 0),
  623. MSTPCR("sdhi0", "bus_clk", 2, 18, 0),
  624. MSTPCR("sdhi1", "bus_clk", 2, 17, 0),
  625. MSTPCR("keysc0", "r_clk", 2, 14, 0),
  626. MSTPCR("usb0", "bus_clk", 2, 11, 0),
  627. MSTPCR("2dg0", "bus_clk", 2, 10, 0),
  628. MSTPCR("siu0", "bus_clk", 2, 8, 0),
  629. MSTPCR("veu1", "bus_clk", 2, 6, CLK_ENABLE_ON_INIT),
  630. MSTPCR("vou0", "bus_clk", 2, 5, 0),
  631. MSTPCR("beu0", "bus_clk", 2, 4, 0),
  632. MSTPCR("ceu0", "bus_clk", 2, 3, 0),
  633. MSTPCR("veu0", "bus_clk", 2, 2, CLK_ENABLE_ON_INIT),
  634. MSTPCR("vpu0", "bus_clk", 2, 1, CLK_ENABLE_ON_INIT),
  635. MSTPCR("lcdc0", "bus_clk", 2, 0, 0),
  636. #endif
  637. #if defined(CONFIG_CPU_SUBTYPE_SH7724)
  638. /* See Datasheet : Overview -> Block Diagram */
  639. MSTPCR("tlb0", "cpu_clk", 0, 31, 0),
  640. MSTPCR("ic0", "cpu_clk", 0, 30, 0),
  641. MSTPCR("oc0", "cpu_clk", 0, 29, 0),
  642. MSTPCR("rs0", "bus_clk", 0, 28, 0),
  643. MSTPCR("ilmem0", "cpu_clk", 0, 27, 0),
  644. MSTPCR("l2c0", "sh_clk", 0, 26, 0),
  645. MSTPCR("fpu0", "cpu_clk", 0, 24, 0),
  646. MSTPCR("intc0", "peripheral_clk", 0, 22, 0),
  647. MSTPCR("dmac0", "bus_clk", 0, 21, 0),
  648. MSTPCR("sh0", "sh_clk", 0, 20, 0),
  649. MSTPCR("hudi0", "peripheral_clk", 0, 19, 0),
  650. MSTPCR("ubc0", "cpu_clk", 0, 17, 0),
  651. MSTPCR("tmu0", "peripheral_clk", 0, 15, 0),
  652. MSTPCR("cmt0", "r_clk", 0, 14, 0),
  653. MSTPCR("rwdt0", "r_clk", 0, 13, 0),
  654. MSTPCR("dmac1", "bus_clk", 0, 12, 0),
  655. MSTPCR("tmu1", "peripheral_clk", 0, 10, 0),
  656. MSTPCR("scif0", "peripheral_clk", 0, 9, 0),
  657. MSTPCR("scif1", "peripheral_clk", 0, 8, 0),
  658. MSTPCR("scif2", "peripheral_clk", 0, 7, 0),
  659. MSTPCR("scif3", "bus_clk", 0, 6, 0),
  660. MSTPCR("scif4", "bus_clk", 0, 5, 0),
  661. MSTPCR("scif5", "bus_clk", 0, 4, 0),
  662. MSTPCR("msiof0", "bus_clk", 0, 2, 0),
  663. MSTPCR("msiof1", "bus_clk", 0, 1, 0),
  664. MSTPCR("keysc0", "r_clk", 1, 12, 0),
  665. MSTPCR("rtc0", "r_clk", 1, 11, 0),
  666. MSTPCR("i2c0", "peripheral_clk", 1, 9, 0),
  667. MSTPCR("i2c1", "peripheral_clk", 1, 8, 0),
  668. MSTPCR("mmc0", "bus_clk", 2, 29, 0),
  669. MSTPCR("eth0", "bus_clk", 2, 28, 0),
  670. MSTPCR("atapi0", "bus_clk", 2, 26, 0),
  671. MSTPCR("tpu0", "bus_clk", 2, 25, 0),
  672. MSTPCR("irda0", "peripheral_clk", 2, 24, 0),
  673. MSTPCR("tsif0", "bus_clk", 2, 22, 0),
  674. MSTPCR("usb1", "bus_clk", 2, 21, 0),
  675. MSTPCR("usb0", "bus_clk", 2, 20, 0),
  676. MSTPCR("2dg0", "bus_clk", 2, 19, 0),
  677. MSTPCR("sdhi0", "bus_clk", 2, 18, 0),
  678. MSTPCR("sdhi1", "bus_clk", 2, 17, 0),
  679. MSTPCR("veu1", "bus_clk", 2, 15, CLK_ENABLE_ON_INIT),
  680. MSTPCR("ceu1", "bus_clk", 2, 13, 0),
  681. MSTPCR("beu1", "bus_clk", 2, 12, 0),
  682. MSTPCR("2ddmac0", "sh_clk", 2, 10, 0),
  683. MSTPCR("spu0", "bus_clk", 2, 9, 0),
  684. MSTPCR("jpu0", "bus_clk", 2, 6, 0),
  685. MSTPCR("vou0", "bus_clk", 2, 5, 0),
  686. MSTPCR("beu0", "bus_clk", 2, 4, 0),
  687. MSTPCR("ceu0", "bus_clk", 2, 3, 0),
  688. MSTPCR("veu0", "bus_clk", 2, 2, CLK_ENABLE_ON_INIT),
  689. MSTPCR("vpu0", "bus_clk", 2, 1, CLK_ENABLE_ON_INIT),
  690. MSTPCR("lcdc0", "bus_clk", 2, 0, 0),
  691. #endif
  692. #if defined(CONFIG_CPU_SUBTYPE_SH7343)
  693. MSTPCR("uram0", "umem_clk", 0, 28, CLK_ENABLE_ON_INIT),
  694. MSTPCR("xymem0", "bus_clk", 0, 26, CLK_ENABLE_ON_INIT),
  695. MSTPCR("tmu0", "peripheral_clk", 0, 15, 0),
  696. MSTPCR("cmt0", "r_clk", 0, 14, 0),
  697. MSTPCR("rwdt0", "r_clk", 0, 13, 0),
  698. MSTPCR("scif0", "peripheral_clk", 0, 7, 0),
  699. MSTPCR("scif1", "peripheral_clk", 0, 6, 0),
  700. MSTPCR("scif2", "peripheral_clk", 0, 5, 0),
  701. MSTPCR("scif3", "peripheral_clk", 0, 4, 0),
  702. MSTPCR("i2c0", "peripheral_clk", 1, 9, 0),
  703. MSTPCR("i2c1", "peripheral_clk", 1, 8, 0),
  704. MSTPCR("sdhi0", "peripheral_clk", 2, 18, 0),
  705. MSTPCR("keysc0", "r_clk", 2, 14, 0),
  706. MSTPCR("usbf0", "peripheral_clk", 2, 11, 0),
  707. MSTPCR("siu0", "bus_clk", 2, 8, 0),
  708. MSTPCR("jpu0", "bus_clk", 2, 6, CLK_ENABLE_ON_INIT),
  709. MSTPCR("vou0", "bus_clk", 2, 5, 0),
  710. MSTPCR("beu0", "bus_clk", 2, 4, 0),
  711. MSTPCR("ceu0", "bus_clk", 2, 3, 0),
  712. MSTPCR("veu0", "bus_clk", 2, 2, CLK_ENABLE_ON_INIT),
  713. MSTPCR("vpu0", "bus_clk", 2, 1, CLK_ENABLE_ON_INIT),
  714. MSTPCR("lcdc0", "bus_clk", 2, 0, 0),
  715. #endif
  716. #if defined(CONFIG_CPU_SUBTYPE_SH7366)
  717. /* See page 52 of Datasheet V0.40: Overview -> Block Diagram */
  718. MSTPCR("tlb0", "cpu_clk", 0, 31, 0),
  719. MSTPCR("ic0", "cpu_clk", 0, 30, 0),
  720. MSTPCR("oc0", "cpu_clk", 0, 29, 0),
  721. MSTPCR("rsmem0", "sh_clk", 0, 28, CLK_ENABLE_ON_INIT),
  722. MSTPCR("xymem0", "cpu_clk", 0, 26, CLK_ENABLE_ON_INIT),
  723. MSTPCR("intc30", "peripheral_clk", 0, 23, 0),
  724. MSTPCR("intc0", "peripheral_clk", 0, 22, 0),
  725. MSTPCR("dmac0", "bus_clk", 0, 21, 0),
  726. MSTPCR("sh0", "sh_clk", 0, 20, 0),
  727. MSTPCR("hudi0", "peripheral_clk", 0, 19, 0),
  728. MSTPCR("ubc0", "cpu_clk", 0, 17, 0),
  729. MSTPCR("tmu0", "peripheral_clk", 0, 15, 0),
  730. MSTPCR("cmt0", "r_clk", 0, 14, 0),
  731. MSTPCR("rwdt0", "r_clk", 0, 13, 0),
  732. MSTPCR("flctl0", "peripheral_clk", 0, 10, 0),
  733. MSTPCR("scif0", "peripheral_clk", 0, 7, 0),
  734. MSTPCR("scif1", "bus_clk", 0, 6, 0),
  735. MSTPCR("scif2", "bus_clk", 0, 5, 0),
  736. MSTPCR("msiof0", "peripheral_clk", 0, 2, 0),
  737. MSTPCR("sbr0", "peripheral_clk", 0, 1, 0),
  738. MSTPCR("i2c0", "peripheral_clk", 1, 9, 0),
  739. MSTPCR("icb0", "bus_clk", 2, 27, 0),
  740. MSTPCR("meram0", "sh_clk", 2, 26, 0),
  741. MSTPCR("dacc0", "peripheral_clk", 2, 24, 0),
  742. MSTPCR("dacy0", "peripheral_clk", 2, 23, 0),
  743. MSTPCR("tsif0", "bus_clk", 2, 22, 0),
  744. MSTPCR("sdhi0", "bus_clk", 2, 18, 0),
  745. MSTPCR("mmcif0", "bus_clk", 2, 17, 0),
  746. MSTPCR("usb0", "bus_clk", 2, 11, 0),
  747. MSTPCR("siu0", "bus_clk", 2, 8, 0),
  748. MSTPCR("veu1", "bus_clk", 2, 7, CLK_ENABLE_ON_INIT),
  749. MSTPCR("vou0", "bus_clk", 2, 5, 0),
  750. MSTPCR("beu0", "bus_clk", 2, 4, 0),
  751. MSTPCR("ceu0", "bus_clk", 2, 3, 0),
  752. MSTPCR("veu0", "bus_clk", 2, 2, CLK_ENABLE_ON_INIT),
  753. MSTPCR("vpu0", "bus_clk", 2, 1, CLK_ENABLE_ON_INIT),
  754. MSTPCR("lcdc0", "bus_clk", 2, 0, 0),
  755. #endif
  756. };
  757. static struct clk *sh7722_clocks[] = {
  758. &sh7722_umem_clock,
  759. &sh7722_sh_clock,
  760. &sh7722_peripheral_clock,
  761. &sh7722_sdram_clock,
  762. #if !defined(CONFIG_CPU_SUBTYPE_SH7343) &&\
  763. !defined(CONFIG_CPU_SUBTYPE_SH7724)
  764. &sh7722_siu_a_clock,
  765. &sh7722_siu_b_clock,
  766. #endif
  767. /* 7724 should support FSI clock */
  768. #if defined(CONFIG_CPU_SUBTYPE_SH7722) || \
  769. defined(CONFIG_CPU_SUBTYPE_SH7724)
  770. &sh7722_irda_clock,
  771. #endif
  772. &sh7722_video_clock,
  773. };
  774. /*
  775. * init in order: master, module, bus, cpu
  776. */
  777. struct clk_ops *onchip_ops[] = {
  778. &sh7722_master_clk_ops,
  779. &sh7722_module_clk_ops,
  780. &sh7722_frqcr_clk_ops,
  781. &sh7722_frqcr_clk_ops,
  782. };
  783. void __init
  784. arch_init_clk_ops(struct clk_ops **ops, int type)
  785. {
  786. BUG_ON(type < 0 || type > ARRAY_SIZE(onchip_ops));
  787. *ops = onchip_ops[type];
  788. }
  789. int __init arch_clk_init(void)
  790. {
  791. struct clk *clk;
  792. int i;
  793. clk = clk_get(NULL, "master_clk");
  794. for (i = 0; i < ARRAY_SIZE(sh7722_clocks); i++) {
  795. pr_debug( "Registering clock '%s'\n", sh7722_clocks[i]->name);
  796. sh7722_clocks[i]->parent = clk;
  797. clk_register(sh7722_clocks[i]);
  798. }
  799. clk_put(clk);
  800. clk_register(&sh7722_r_clock);
  801. for (i = 0; i < ARRAY_SIZE(sh7722_mstpcr_clocks); i++) {
  802. pr_debug( "Registering mstpcr clock '%s'\n",
  803. sh7722_mstpcr_clocks[i].name);
  804. clk = clk_get(NULL, (void *) sh7722_mstpcr_clocks[i].ops);
  805. sh7722_mstpcr_clocks[i].parent = clk;
  806. sh7722_mstpcr_clocks[i].ops = &sh7722_mstpcr_clk_ops;
  807. clk_register(&sh7722_mstpcr_clocks[i]);
  808. clk_put(clk);
  809. }
  810. clk_recalc_rate(&sh7722_r_clock); /* make sure rate gets propagated */
  811. return 0;
  812. }