clock.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*
  2. * linux/arch/arm/mach-at91rm9200/clock.c
  3. *
  4. * Copyright (C) 2005 David Brownell
  5. * Copyright (C) 2005 Ivan Kokshaysky
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/fs.h>
  16. #include <linux/debugfs.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/list.h>
  19. #include <linux/errno.h>
  20. #include <linux/err.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/delay.h>
  23. #include <linux/clk.h>
  24. #include <asm/semaphore.h>
  25. #include <asm/io.h>
  26. #include <asm/mach-types.h>
  27. #include <asm/arch/hardware.h>
  28. #include <asm/arch/board.h> /* for master clock global */
  29. #include "generic.h"
  30. #undef DEBUG
  31. /*
  32. * There's a lot more which can be done with clocks, including cpufreq
  33. * integration, slow clock mode support (for system suspend), letting
  34. * PLLB be used at other rates (on boards that don't need USB), etc.
  35. */
  36. struct clk {
  37. const char *name;
  38. unsigned long rate_hz;
  39. struct clk *parent;
  40. u32 pmc_mask;
  41. void (*mode)(struct clk *, int);
  42. unsigned id:2; /* PCK0..3, or 32k/main/a/b */
  43. unsigned primary:1;
  44. unsigned pll:1;
  45. unsigned programmable:1;
  46. u16 users;
  47. };
  48. static spinlock_t clk_lock;
  49. static u32 at91_pllb_usb_init;
  50. /*
  51. * Four primary clock sources: two crystal oscillators (32K, main), and
  52. * two PLLs. PLLA usually runs the master clock; and PLLB must run at
  53. * 48 MHz (unless no USB function clocks are needed). The main clock and
  54. * both PLLs are turned off to run in "slow clock mode" (system suspend).
  55. */
  56. static struct clk clk32k = {
  57. .name = "clk32k",
  58. .rate_hz = AT91_SLOW_CLOCK,
  59. .users = 1, /* always on */
  60. .id = 0,
  61. .primary = 1,
  62. };
  63. static struct clk main_clk = {
  64. .name = "main",
  65. .pmc_mask = 1 << 0, /* in PMC_SR */
  66. .users = 1,
  67. .id = 1,
  68. .primary = 1,
  69. };
  70. static struct clk plla = {
  71. .name = "plla",
  72. .parent = &main_clk,
  73. .pmc_mask = 1 << 1, /* in PMC_SR */
  74. .id = 2,
  75. .primary = 1,
  76. .pll = 1,
  77. };
  78. static void pllb_mode(struct clk *clk, int is_on)
  79. {
  80. u32 value;
  81. if (is_on) {
  82. is_on = AT91_PMC_LOCKB;
  83. value = at91_pllb_usb_init;
  84. } else
  85. value = 0;
  86. at91_sys_write(AT91_CKGR_PLLBR, value);
  87. do {
  88. cpu_relax();
  89. } while ((at91_sys_read(AT91_PMC_SR) & AT91_PMC_LOCKB) != is_on);
  90. }
  91. static struct clk pllb = {
  92. .name = "pllb",
  93. .parent = &main_clk,
  94. .pmc_mask = 1 << 2, /* in PMC_SR */
  95. .mode = pllb_mode,
  96. .id = 3,
  97. .primary = 1,
  98. .pll = 1,
  99. };
  100. static void pmc_sys_mode(struct clk *clk, int is_on)
  101. {
  102. if (is_on)
  103. at91_sys_write(AT91_PMC_SCER, clk->pmc_mask);
  104. else
  105. at91_sys_write(AT91_PMC_SCDR, clk->pmc_mask);
  106. }
  107. /* USB function clocks (PLLB must be 48 MHz) */
  108. static struct clk udpck = {
  109. .name = "udpck",
  110. .parent = &pllb,
  111. .pmc_mask = AT91_PMC_UDP,
  112. .mode = pmc_sys_mode,
  113. };
  114. static struct clk uhpck = {
  115. .name = "uhpck",
  116. .parent = &pllb,
  117. .pmc_mask = AT91_PMC_UHP,
  118. .mode = pmc_sys_mode,
  119. };
  120. #ifdef CONFIG_AT91_PROGRAMMABLE_CLOCKS
  121. /*
  122. * The four programmable clocks can be parented by any primary clock.
  123. * You must configure pin multiplexing to bring these signals out.
  124. */
  125. static struct clk pck0 = {
  126. .name = "pck0",
  127. .pmc_mask = AT91_PMC_PCK0,
  128. .mode = pmc_sys_mode,
  129. .programmable = 1,
  130. .id = 0,
  131. };
  132. static struct clk pck1 = {
  133. .name = "pck1",
  134. .pmc_mask = AT91_PMC_PCK1,
  135. .mode = pmc_sys_mode,
  136. .programmable = 1,
  137. .id = 1,
  138. };
  139. static struct clk pck2 = {
  140. .name = "pck2",
  141. .pmc_mask = AT91_PMC_PCK2,
  142. .mode = pmc_sys_mode,
  143. .programmable = 1,
  144. .id = 2,
  145. };
  146. static struct clk pck3 = {
  147. .name = "pck3",
  148. .pmc_mask = AT91_PMC_PCK3,
  149. .mode = pmc_sys_mode,
  150. .programmable = 1,
  151. .id = 3,
  152. };
  153. #endif /* CONFIG_AT91_PROGRAMMABLE_CLOCKS */
  154. /*
  155. * The master clock is divided from the CPU clock (by 1-4). It's used for
  156. * memory, interfaces to on-chip peripherals, the AIC, and sometimes more
  157. * (e.g baud rate generation). It's sourced from one of the primary clocks.
  158. */
  159. static struct clk mck = {
  160. .name = "mck",
  161. .pmc_mask = 1 << 3, /* in PMC_SR */
  162. .users = 1, /* (must be) always on */
  163. };
  164. static void pmc_periph_mode(struct clk *clk, int is_on)
  165. {
  166. if (is_on)
  167. at91_sys_write(AT91_PMC_PCER, clk->pmc_mask);
  168. else
  169. at91_sys_write(AT91_PMC_PCDR, clk->pmc_mask);
  170. }
  171. static struct clk udc_clk = {
  172. .name = "udc_clk",
  173. .parent = &mck,
  174. .pmc_mask = 1 << AT91_ID_UDP,
  175. .mode = pmc_periph_mode,
  176. };
  177. static struct clk ohci_clk = {
  178. .name = "ohci_clk",
  179. .parent = &mck,
  180. .pmc_mask = 1 << AT91_ID_UHP,
  181. .mode = pmc_periph_mode,
  182. };
  183. static struct clk ether_clk = {
  184. .name = "ether_clk",
  185. .parent = &mck,
  186. .pmc_mask = 1 << AT91_ID_EMAC,
  187. .mode = pmc_periph_mode,
  188. };
  189. static struct clk mmc_clk = {
  190. .name = "mci_clk",
  191. .parent = &mck,
  192. .pmc_mask = 1 << AT91_ID_MCI,
  193. .mode = pmc_periph_mode,
  194. };
  195. static struct clk twi_clk = {
  196. .name = "twi_clk",
  197. .parent = &mck,
  198. .pmc_mask = 1 << AT91_ID_TWI,
  199. .mode = pmc_periph_mode,
  200. };
  201. static struct clk usart0_clk = {
  202. .name = "usart0_clk",
  203. .parent = &mck,
  204. .pmc_mask = 1 << AT91_ID_US0,
  205. .mode = pmc_periph_mode,
  206. };
  207. static struct clk usart1_clk = {
  208. .name = "usart1_clk",
  209. .parent = &mck,
  210. .pmc_mask = 1 << AT91_ID_US1,
  211. .mode = pmc_periph_mode,
  212. };
  213. static struct clk usart2_clk = {
  214. .name = "usart2_clk",
  215. .parent = &mck,
  216. .pmc_mask = 1 << AT91_ID_US2,
  217. .mode = pmc_periph_mode,
  218. };
  219. static struct clk usart3_clk = {
  220. .name = "usart3_clk",
  221. .parent = &mck,
  222. .pmc_mask = 1 << AT91_ID_US3,
  223. .mode = pmc_periph_mode,
  224. };
  225. static struct clk spi_clk = {
  226. .name = "spi0_clk",
  227. .parent = &mck,
  228. .pmc_mask = 1 << AT91_ID_SPI,
  229. .mode = pmc_periph_mode,
  230. };
  231. static struct clk *const clock_list[] = {
  232. /* four primary clocks -- MUST BE FIRST! */
  233. &clk32k,
  234. &main_clk,
  235. &plla,
  236. &pllb,
  237. /* PLLB children (USB) */
  238. &udpck,
  239. &uhpck,
  240. #ifdef CONFIG_AT91_PROGRAMMABLE_CLOCKS
  241. /* programmable clocks */
  242. &pck0,
  243. &pck1,
  244. &pck2,
  245. &pck3,
  246. #endif /* CONFIG_AT91_PROGRAMMABLE_CLOCKS */
  247. /* MCK and peripherals */
  248. &mck,
  249. &usart0_clk,
  250. &usart1_clk,
  251. &usart2_clk,
  252. &usart3_clk,
  253. &mmc_clk,
  254. &udc_clk,
  255. &twi_clk,
  256. &spi_clk,
  257. // ssc0..ssc2
  258. // tc0..tc5
  259. &ohci_clk,
  260. &ether_clk,
  261. };
  262. /* clocks are all static for now; no refcounting necessary */
  263. struct clk *clk_get(struct device *dev, const char *id)
  264. {
  265. int i;
  266. for (i = 0; i < ARRAY_SIZE(clock_list); i++) {
  267. if (strcmp(id, clock_list[i]->name) == 0)
  268. return clock_list[i];
  269. }
  270. return ERR_PTR(-ENOENT);
  271. }
  272. EXPORT_SYMBOL(clk_get);
  273. void clk_put(struct clk *clk)
  274. {
  275. }
  276. EXPORT_SYMBOL(clk_put);
  277. static void __clk_enable(struct clk *clk)
  278. {
  279. if (clk->parent)
  280. __clk_enable(clk->parent);
  281. if (clk->users++ == 0 && clk->mode)
  282. clk->mode(clk, 1);
  283. }
  284. int clk_enable(struct clk *clk)
  285. {
  286. unsigned long flags;
  287. spin_lock_irqsave(&clk_lock, flags);
  288. __clk_enable(clk);
  289. spin_unlock_irqrestore(&clk_lock, flags);
  290. return 0;
  291. }
  292. EXPORT_SYMBOL(clk_enable);
  293. static void __clk_disable(struct clk *clk)
  294. {
  295. BUG_ON(clk->users == 0);
  296. if (--clk->users == 0 && clk->mode)
  297. clk->mode(clk, 0);
  298. if (clk->parent)
  299. __clk_disable(clk->parent);
  300. }
  301. void clk_disable(struct clk *clk)
  302. {
  303. unsigned long flags;
  304. spin_lock_irqsave(&clk_lock, flags);
  305. __clk_disable(clk);
  306. spin_unlock_irqrestore(&clk_lock, flags);
  307. }
  308. EXPORT_SYMBOL(clk_disable);
  309. unsigned long clk_get_rate(struct clk *clk)
  310. {
  311. unsigned long flags;
  312. unsigned long rate;
  313. spin_lock_irqsave(&clk_lock, flags);
  314. for (;;) {
  315. rate = clk->rate_hz;
  316. if (rate || !clk->parent)
  317. break;
  318. clk = clk->parent;
  319. }
  320. spin_unlock_irqrestore(&clk_lock, flags);
  321. return rate;
  322. }
  323. EXPORT_SYMBOL(clk_get_rate);
  324. /*------------------------------------------------------------------------*/
  325. #ifdef CONFIG_AT91_PROGRAMMABLE_CLOCKS
  326. /*
  327. * For now, only the programmable clocks support reparenting (MCK could
  328. * do this too, with care) or rate changing (the PLLs could do this too,
  329. * ditto MCK but that's more for cpufreq). Drivers may reparent to get
  330. * a better rate match; we don't.
  331. */
  332. long clk_round_rate(struct clk *clk, unsigned long rate)
  333. {
  334. unsigned long flags;
  335. unsigned prescale;
  336. unsigned long actual;
  337. if (!clk->programmable)
  338. return -EINVAL;
  339. spin_lock_irqsave(&clk_lock, flags);
  340. actual = clk->parent->rate_hz;
  341. for (prescale = 0; prescale < 7; prescale++) {
  342. if (actual && actual <= rate)
  343. break;
  344. actual >>= 1;
  345. }
  346. spin_unlock_irqrestore(&clk_lock, flags);
  347. return (prescale < 7) ? actual : -ENOENT;
  348. }
  349. EXPORT_SYMBOL(clk_round_rate);
  350. int clk_set_rate(struct clk *clk, unsigned long rate)
  351. {
  352. unsigned long flags;
  353. unsigned prescale;
  354. unsigned long actual;
  355. if (!clk->programmable)
  356. return -EINVAL;
  357. if (clk->users)
  358. return -EBUSY;
  359. spin_lock_irqsave(&clk_lock, flags);
  360. actual = clk->parent->rate_hz;
  361. for (prescale = 0; prescale < 7; prescale++) {
  362. if (actual && actual <= rate) {
  363. u32 pckr;
  364. pckr = at91_sys_read(AT91_PMC_PCKR(clk->id));
  365. pckr &= AT91_PMC_CSS_PLLB; /* clock selection */
  366. pckr |= prescale << 2;
  367. at91_sys_write(AT91_PMC_PCKR(clk->id), pckr);
  368. clk->rate_hz = actual;
  369. break;
  370. }
  371. actual >>= 1;
  372. }
  373. spin_unlock_irqrestore(&clk_lock, flags);
  374. return (prescale < 7) ? actual : -ENOENT;
  375. }
  376. EXPORT_SYMBOL(clk_set_rate);
  377. struct clk *clk_get_parent(struct clk *clk)
  378. {
  379. return clk->parent;
  380. }
  381. EXPORT_SYMBOL(clk_get_parent);
  382. int clk_set_parent(struct clk *clk, struct clk *parent)
  383. {
  384. unsigned long flags;
  385. if (clk->users)
  386. return -EBUSY;
  387. if (!parent->primary || !clk->programmable)
  388. return -EINVAL;
  389. spin_lock_irqsave(&clk_lock, flags);
  390. clk->rate_hz = parent->rate_hz;
  391. clk->parent = parent;
  392. at91_sys_write(AT91_PMC_PCKR(clk->id), parent->id);
  393. spin_unlock_irqrestore(&clk_lock, flags);
  394. return 0;
  395. }
  396. EXPORT_SYMBOL(clk_set_parent);
  397. #endif /* CONFIG_AT91_PROGRAMMABLE_CLOCKS */
  398. /*------------------------------------------------------------------------*/
  399. #ifdef CONFIG_DEBUG_FS
  400. static int at91_clk_show(struct seq_file *s, void *unused)
  401. {
  402. u32 scsr, pcsr, sr;
  403. unsigned i;
  404. seq_printf(s, "SCSR = %8x\n", scsr = at91_sys_read(AT91_PMC_SCSR));
  405. seq_printf(s, "PCSR = %8x\n", pcsr = at91_sys_read(AT91_PMC_PCSR));
  406. seq_printf(s, "MOR = %8x\n", at91_sys_read(AT91_CKGR_MOR));
  407. seq_printf(s, "MCFR = %8x\n", at91_sys_read(AT91_CKGR_MCFR));
  408. seq_printf(s, "PLLA = %8x\n", at91_sys_read(AT91_CKGR_PLLAR));
  409. seq_printf(s, "PLLB = %8x\n", at91_sys_read(AT91_CKGR_PLLBR));
  410. seq_printf(s, "MCKR = %8x\n", at91_sys_read(AT91_PMC_MCKR));
  411. for (i = 0; i < 4; i++)
  412. seq_printf(s, "PCK%d = %8x\n", i, at91_sys_read(AT91_PMC_PCKR(i)));
  413. seq_printf(s, "SR = %8x\n", sr = at91_sys_read(AT91_PMC_SR));
  414. seq_printf(s, "\n");
  415. for (i = 0; i < ARRAY_SIZE(clock_list); i++) {
  416. char *state;
  417. struct clk *clk = clock_list[i];
  418. if (clk->mode == pmc_sys_mode)
  419. state = (scsr & clk->pmc_mask) ? "on" : "off";
  420. else if (clk->mode == pmc_periph_mode)
  421. state = (pcsr & clk->pmc_mask) ? "on" : "off";
  422. else if (clk->pmc_mask)
  423. state = (sr & clk->pmc_mask) ? "on" : "off";
  424. else if (clk == &clk32k || clk == &main_clk)
  425. state = "on";
  426. else
  427. state = "";
  428. seq_printf(s, "%-10s users=%2d %-3s %9ld Hz %s\n",
  429. clk->name, clk->users, state, clk_get_rate(clk),
  430. clk->parent ? clk->parent->name : "");
  431. }
  432. return 0;
  433. }
  434. static int at91_clk_open(struct inode *inode, struct file *file)
  435. {
  436. return single_open(file, at91_clk_show, NULL);
  437. }
  438. static struct file_operations at91_clk_operations = {
  439. .open = at91_clk_open,
  440. .read = seq_read,
  441. .llseek = seq_lseek,
  442. .release = single_release,
  443. };
  444. static int __init at91_clk_debugfs_init(void)
  445. {
  446. /* /sys/kernel/debug/at91_clk */
  447. (void) debugfs_create_file("at91_clk", S_IFREG | S_IRUGO, NULL, NULL, &at91_clk_operations);
  448. return 0;
  449. }
  450. postcore_initcall(at91_clk_debugfs_init);
  451. #endif
  452. /*------------------------------------------------------------------------*/
  453. static u32 __init at91_pll_rate(struct clk *pll, u32 freq, u32 reg)
  454. {
  455. unsigned mul, div;
  456. div = reg & 0xff;
  457. mul = (reg >> 16) & 0x7ff;
  458. if (div && mul) {
  459. freq /= div;
  460. freq *= mul + 1;
  461. } else
  462. freq = 0;
  463. return freq;
  464. }
  465. static u32 __init at91_usb_rate(struct clk *pll, u32 freq, u32 reg)
  466. {
  467. if (pll == &pllb && (reg & AT91_PMC_USB96M))
  468. return freq / 2;
  469. else
  470. return freq;
  471. }
  472. static unsigned __init at91_pll_calc(unsigned main_freq, unsigned out_freq)
  473. {
  474. unsigned i, div = 0, mul = 0, diff = 1 << 30;
  475. unsigned ret = (out_freq > 155000000) ? 0xbe00 : 0x3e00;
  476. /* PLL output max 240 MHz (or 180 MHz per errata) */
  477. if (out_freq > 240000000)
  478. goto fail;
  479. for (i = 1; i < 256; i++) {
  480. int diff1;
  481. unsigned input, mul1;
  482. /*
  483. * PLL input between 1MHz and 32MHz per spec, but lower
  484. * frequences seem necessary in some cases so allow 100K.
  485. */
  486. input = main_freq / i;
  487. if (input < 100000)
  488. continue;
  489. if (input > 32000000)
  490. continue;
  491. mul1 = out_freq / input;
  492. if (mul1 > 2048)
  493. continue;
  494. if (mul1 < 2)
  495. goto fail;
  496. diff1 = out_freq - input * mul1;
  497. if (diff1 < 0)
  498. diff1 = -diff1;
  499. if (diff > diff1) {
  500. diff = diff1;
  501. div = i;
  502. mul = mul1;
  503. if (diff == 0)
  504. break;
  505. }
  506. }
  507. if (i == 256 && diff > (out_freq >> 5))
  508. goto fail;
  509. return ret | ((mul - 1) << 16) | div;
  510. fail:
  511. return 0;
  512. }
  513. int __init at91_clock_init(unsigned long main_clock)
  514. {
  515. unsigned tmp, freq, mckr;
  516. spin_lock_init(&clk_lock);
  517. /*
  518. * When the bootloader initialized the main oscillator correctly,
  519. * there's no problem using the cycle counter. But if it didn't,
  520. * or when using oscillator bypass mode, we must be told the speed
  521. * of the main clock.
  522. */
  523. if (!main_clock) {
  524. do {
  525. tmp = at91_sys_read(AT91_CKGR_MCFR);
  526. } while (!(tmp & AT91_PMC_MAINRDY));
  527. main_clock = (tmp & AT91_PMC_MAINF) * (AT91_SLOW_CLOCK / 16);
  528. }
  529. main_clk.rate_hz = main_clock;
  530. /* report if PLLA is more than mildly overclocked */
  531. plla.rate_hz = at91_pll_rate(&plla, main_clock, at91_sys_read(AT91_CKGR_PLLAR));
  532. if (plla.rate_hz > 209000000)
  533. pr_info("Clocks: PLLA overclocked, %ld MHz\n", plla.rate_hz / 1000000);
  534. /*
  535. * USB clock init: choose 48 MHz PLLB value, turn all clocks off,
  536. * disable 48MHz clock during usb peripheral suspend.
  537. *
  538. * REVISIT: assumes MCK doesn't derive from PLLB!
  539. */
  540. at91_pllb_usb_init = at91_pll_calc(main_clock, 48000000 * 2) | AT91_PMC_USB96M;
  541. pllb.rate_hz = at91_pll_rate(&pllb, main_clock, at91_pllb_usb_init);
  542. at91_sys_write(AT91_PMC_PCDR, (1 << AT91_ID_UHP) | (1 << AT91_ID_UDP));
  543. at91_sys_write(AT91_PMC_SCDR, AT91_PMC_UHP | AT91_PMC_UDP);
  544. at91_sys_write(AT91_CKGR_PLLBR, 0);
  545. at91_sys_write(AT91_PMC_SCER, AT91_PMC_MCKUDP);
  546. udpck.rate_hz = at91_usb_rate(&pllb, pllb.rate_hz, at91_pllb_usb_init);
  547. uhpck.rate_hz = at91_usb_rate(&pllb, pllb.rate_hz, at91_pllb_usb_init);
  548. /*
  549. * MCK and CPU derive from one of those primary clocks.
  550. * For now, assume this parentage won't change.
  551. */
  552. mckr = at91_sys_read(AT91_PMC_MCKR);
  553. mck.parent = clock_list[mckr & AT91_PMC_CSS];
  554. mck.parent->users++;
  555. freq = mck.parent->rate_hz;
  556. freq /= (1 << ((mckr >> 2) & 3)); /* prescale */
  557. mck.rate_hz = freq / (1 + ((mckr >> 8) & 3)); /* mdiv */
  558. printk("Clocks: CPU %u MHz, master %u MHz, main %u.%03u MHz\n",
  559. freq / 1000000, (unsigned) mck.rate_hz / 1000000,
  560. (unsigned) main_clock / 1000000,
  561. ((unsigned) main_clock % 1000000) / 1000);
  562. /* FIXME get rid of master_clock global */
  563. at91_master_clock = mck.rate_hz;
  564. #ifdef CONFIG_AT91_PROGRAMMABLE_CLOCKS
  565. /* establish PCK0..PCK3 parentage */
  566. for (tmp = 0; tmp < ARRAY_SIZE(clock_list); tmp++) {
  567. struct clk *clk = clock_list[tmp], *parent;
  568. u32 pckr;
  569. if (!clk->programmable)
  570. continue;
  571. pckr = at91_sys_read(AT91_PMC_PCKR(clk->id));
  572. parent = clock_list[pckr & 3];
  573. clk->parent = parent;
  574. clk->rate_hz = parent->rate_hz / (1 << ((pckr >> 2) & 3));
  575. }
  576. #else
  577. /* disable unused clocks */
  578. at91_sys_write(AT91_PMC_SCDR, AT91_PMC_PCK0 | AT91_PMC_PCK1 | AT91_PMC_PCK2 | AT91_PMC_PCK3);
  579. #endif /* CONFIG_AT91_PROGRAMMABLE_CLOCKS */
  580. /* FIXME several unused clocks may still be active... provide
  581. * a CONFIG option to turn off all unused clocks at some point
  582. * before driver init starts.
  583. */
  584. return 0;
  585. }