aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-at91/clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-at91/clock.c')
-rw-r--r--arch/arm/mach-at91/clock.c224
1 files changed, 165 insertions, 59 deletions
diff --git a/arch/arm/mach-at91/clock.c b/arch/arm/mach-at91/clock.c
index 61873f3aa92d..a0f4d7424cdc 100644
--- a/arch/arm/mach-at91/clock.c
+++ b/arch/arm/mach-at91/clock.c
@@ -23,14 +23,18 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/clk.h> 24#include <linux/clk.h>
25#include <linux/io.h> 25#include <linux/io.h>
26#include <linux/of_address.h>
26 27
27#include <mach/hardware.h> 28#include <mach/hardware.h>
28#include <mach/at91_pmc.h> 29#include <mach/at91_pmc.h>
29#include <mach/cpu.h> 30#include <mach/cpu.h>
30 31
32#include <asm/proc-fns.h>
33
31#include "clock.h" 34#include "clock.h"
32#include "generic.h" 35#include "generic.h"
33 36
37void __iomem *at91_pmc_base;
34 38
35/* 39/*
36 * There's a lot more which can be done with clocks, including cpufreq 40 * There's a lot more which can be done with clocks, including cpufreq
@@ -47,26 +51,38 @@
47/* 51/*
48 * Chips have some kind of clocks : group them by functionality 52 * Chips have some kind of clocks : group them by functionality
49 */ 53 */
50#define cpu_has_utmi() ( cpu_is_at91cap9() \ 54#define cpu_has_utmi() ( cpu_is_at91sam9rl() \
51 || cpu_is_at91sam9rl() \ 55 || cpu_is_at91sam9g45() \
52 || cpu_is_at91sam9g45()) 56 || cpu_is_at91sam9x5())
53 57
54#define cpu_has_800M_plla() ( cpu_is_at91sam9g20() \ 58#define cpu_has_800M_plla() ( cpu_is_at91sam9g20() \
55 || cpu_is_at91sam9g45()) 59 || cpu_is_at91sam9g45() \
60 || cpu_is_at91sam9x5())
56 61
57#define cpu_has_300M_plla() (cpu_is_at91sam9g10()) 62#define cpu_has_300M_plla() (cpu_is_at91sam9g10())
58 63
59#define cpu_has_pllb() (!(cpu_is_at91sam9rl() \ 64#define cpu_has_pllb() (!(cpu_is_at91sam9rl() \
60 || cpu_is_at91sam9g45())) 65 || cpu_is_at91sam9g45() \
66 || cpu_is_at91sam9x5()))
61 67
62#define cpu_has_upll() (cpu_is_at91sam9g45()) 68#define cpu_has_upll() (cpu_is_at91sam9g45() \
69 || cpu_is_at91sam9x5())
63 70
64/* USB host HS & FS */ 71/* USB host HS & FS */
65#define cpu_has_uhp() (!cpu_is_at91sam9rl()) 72#define cpu_has_uhp() (!cpu_is_at91sam9rl())
66 73
67/* USB device FS only */ 74/* USB device FS only */
68#define cpu_has_udpfs() (!(cpu_is_at91sam9rl() \ 75#define cpu_has_udpfs() (!(cpu_is_at91sam9rl() \
69 || cpu_is_at91sam9g45())) 76 || cpu_is_at91sam9g45() \
77 || cpu_is_at91sam9x5()))
78
79#define cpu_has_plladiv2() (cpu_is_at91sam9g45() \
80 || cpu_is_at91sam9x5())
81
82#define cpu_has_mdiv3() (cpu_is_at91sam9g45() \
83 || cpu_is_at91sam9x5())
84
85#define cpu_has_alt_prescaler() (cpu_is_at91sam9x5())
70 86
71static LIST_HEAD(clocks); 87static LIST_HEAD(clocks);
72static DEFINE_SPINLOCK(clk_lock); 88static DEFINE_SPINLOCK(clk_lock);
@@ -111,11 +127,11 @@ static void pllb_mode(struct clk *clk, int is_on)
111 value = 0; 127 value = 0;
112 128
113 // REVISIT: Add work-around for AT91RM9200 Errata #26 ? 129 // REVISIT: Add work-around for AT91RM9200 Errata #26 ?
114 at91_sys_write(AT91_CKGR_PLLBR, value); 130 at91_pmc_write(AT91_CKGR_PLLBR, value);
115 131
116 do { 132 do {
117 cpu_relax(); 133 cpu_relax();
118 } while ((at91_sys_read(AT91_PMC_SR) & AT91_PMC_LOCKB) != is_on); 134 } while ((at91_pmc_read(AT91_PMC_SR) & AT91_PMC_LOCKB) != is_on);
119} 135}
120 136
121static struct clk pllb = { 137static struct clk pllb = {
@@ -130,31 +146,24 @@ static struct clk pllb = {
130static void pmc_sys_mode(struct clk *clk, int is_on) 146static void pmc_sys_mode(struct clk *clk, int is_on)
131{ 147{
132 if (is_on) 148 if (is_on)
133 at91_sys_write(AT91_PMC_SCER, clk->pmc_mask); 149 at91_pmc_write(AT91_PMC_SCER, clk->pmc_mask);
134 else 150 else
135 at91_sys_write(AT91_PMC_SCDR, clk->pmc_mask); 151 at91_pmc_write(AT91_PMC_SCDR, clk->pmc_mask);
136} 152}
137 153
138static void pmc_uckr_mode(struct clk *clk, int is_on) 154static void pmc_uckr_mode(struct clk *clk, int is_on)
139{ 155{
140 unsigned int uckr = at91_sys_read(AT91_CKGR_UCKR); 156 unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
141
142 if (cpu_is_at91sam9g45()) {
143 if (is_on)
144 uckr |= AT91_PMC_BIASEN;
145 else
146 uckr &= ~AT91_PMC_BIASEN;
147 }
148 157
149 if (is_on) { 158 if (is_on) {
150 is_on = AT91_PMC_LOCKU; 159 is_on = AT91_PMC_LOCKU;
151 at91_sys_write(AT91_CKGR_UCKR, uckr | clk->pmc_mask); 160 at91_pmc_write(AT91_CKGR_UCKR, uckr | clk->pmc_mask);
152 } else 161 } else
153 at91_sys_write(AT91_CKGR_UCKR, uckr & ~(clk->pmc_mask)); 162 at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(clk->pmc_mask));
154 163
155 do { 164 do {
156 cpu_relax(); 165 cpu_relax();
157 } while ((at91_sys_read(AT91_PMC_SR) & AT91_PMC_LOCKU) != is_on); 166 } while ((at91_pmc_read(AT91_PMC_SR) & AT91_PMC_LOCKU) != is_on);
158} 167}
159 168
160/* USB function clocks (PLLB must be 48 MHz) */ 169/* USB function clocks (PLLB must be 48 MHz) */
@@ -190,9 +199,9 @@ struct clk mck = {
190static void pmc_periph_mode(struct clk *clk, int is_on) 199static void pmc_periph_mode(struct clk *clk, int is_on)
191{ 200{
192 if (is_on) 201 if (is_on)
193 at91_sys_write(AT91_PMC_PCER, clk->pmc_mask); 202 at91_pmc_write(AT91_PMC_PCER, clk->pmc_mask);
194 else 203 else
195 at91_sys_write(AT91_PMC_PCDR, clk->pmc_mask); 204 at91_pmc_write(AT91_PMC_PCDR, clk->pmc_mask);
196} 205}
197 206
198static struct clk __init *at91_css_to_clk(unsigned long css) 207static struct clk __init *at91_css_to_clk(unsigned long css)
@@ -210,11 +219,24 @@ static struct clk __init *at91_css_to_clk(unsigned long css)
210 return &utmi_clk; 219 return &utmi_clk;
211 else if (cpu_has_pllb()) 220 else if (cpu_has_pllb())
212 return &pllb; 221 return &pllb;
222 break;
223 /* alternate PMC: can use master clock */
224 case AT91_PMC_CSS_MASTER:
225 return &mck;
213 } 226 }
214 227
215 return NULL; 228 return NULL;
216} 229}
217 230
231static int pmc_prescaler_divider(u32 reg)
232{
233 if (cpu_has_alt_prescaler()) {
234 return 1 << ((reg & AT91_PMC_ALT_PRES) >> PMC_ALT_PRES_OFFSET);
235 } else {
236 return 1 << ((reg & AT91_PMC_PRES) >> PMC_PRES_OFFSET);
237 }
238}
239
218static void __clk_enable(struct clk *clk) 240static void __clk_enable(struct clk *clk)
219{ 241{
220 if (clk->parent) 242 if (clk->parent)
@@ -316,12 +338,22 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
316{ 338{
317 unsigned long flags; 339 unsigned long flags;
318 unsigned prescale; 340 unsigned prescale;
341 unsigned long prescale_offset, css_mask;
319 unsigned long actual; 342 unsigned long actual;
320 343
321 if (!clk_is_programmable(clk)) 344 if (!clk_is_programmable(clk))
322 return -EINVAL; 345 return -EINVAL;
323 if (clk->users) 346 if (clk->users)
324 return -EBUSY; 347 return -EBUSY;
348
349 if (cpu_has_alt_prescaler()) {
350 prescale_offset = PMC_ALT_PRES_OFFSET;
351 css_mask = AT91_PMC_ALT_PCKR_CSS;
352 } else {
353 prescale_offset = PMC_PRES_OFFSET;
354 css_mask = AT91_PMC_CSS;
355 }
356
325 spin_lock_irqsave(&clk_lock, flags); 357 spin_lock_irqsave(&clk_lock, flags);
326 358
327 actual = clk->parent->rate_hz; 359 actual = clk->parent->rate_hz;
@@ -329,10 +361,10 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
329 if (actual && actual <= rate) { 361 if (actual && actual <= rate) {
330 u32 pckr; 362 u32 pckr;
331 363
332 pckr = at91_sys_read(AT91_PMC_PCKR(clk->id)); 364 pckr = at91_pmc_read(AT91_PMC_PCKR(clk->id));
333 pckr &= AT91_PMC_CSS; /* clock selection */ 365 pckr &= css_mask; /* keep clock selection */
334 pckr |= prescale << 2; 366 pckr |= prescale << prescale_offset;
335 at91_sys_write(AT91_PMC_PCKR(clk->id), pckr); 367 at91_pmc_write(AT91_PMC_PCKR(clk->id), pckr);
336 clk->rate_hz = actual; 368 clk->rate_hz = actual;
337 break; 369 break;
338 } 370 }
@@ -366,7 +398,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
366 398
367 clk->rate_hz = parent->rate_hz; 399 clk->rate_hz = parent->rate_hz;
368 clk->parent = parent; 400 clk->parent = parent;
369 at91_sys_write(AT91_PMC_PCKR(clk->id), parent->id); 401 at91_pmc_write(AT91_PMC_PCKR(clk->id), parent->id);
370 402
371 spin_unlock_irqrestore(&clk_lock, flags); 403 spin_unlock_irqrestore(&clk_lock, flags);
372 return 0; 404 return 0;
@@ -378,11 +410,17 @@ static void __init init_programmable_clock(struct clk *clk)
378{ 410{
379 struct clk *parent; 411 struct clk *parent;
380 u32 pckr; 412 u32 pckr;
413 unsigned int css_mask;
414
415 if (cpu_has_alt_prescaler())
416 css_mask = AT91_PMC_ALT_PCKR_CSS;
417 else
418 css_mask = AT91_PMC_CSS;
381 419
382 pckr = at91_sys_read(AT91_PMC_PCKR(clk->id)); 420 pckr = at91_pmc_read(AT91_PMC_PCKR(clk->id));
383 parent = at91_css_to_clk(pckr & AT91_PMC_CSS); 421 parent = at91_css_to_clk(pckr & css_mask);
384 clk->parent = parent; 422 clk->parent = parent;
385 clk->rate_hz = parent->rate_hz / (1 << ((pckr & AT91_PMC_PRES) >> 2)); 423 clk->rate_hz = parent->rate_hz / pmc_prescaler_divider(pckr);
386} 424}
387 425
388#endif /* CONFIG_AT91_PROGRAMMABLE_CLOCKS */ 426#endif /* CONFIG_AT91_PROGRAMMABLE_CLOCKS */
@@ -396,19 +434,24 @@ static int at91_clk_show(struct seq_file *s, void *unused)
396 u32 scsr, pcsr, uckr = 0, sr; 434 u32 scsr, pcsr, uckr = 0, sr;
397 struct clk *clk; 435 struct clk *clk;
398 436
399 seq_printf(s, "SCSR = %8x\n", scsr = at91_sys_read(AT91_PMC_SCSR)); 437 scsr = at91_pmc_read(AT91_PMC_SCSR);
400 seq_printf(s, "PCSR = %8x\n", pcsr = at91_sys_read(AT91_PMC_PCSR)); 438 pcsr = at91_pmc_read(AT91_PMC_PCSR);
401 seq_printf(s, "MOR = %8x\n", at91_sys_read(AT91_CKGR_MOR)); 439 sr = at91_pmc_read(AT91_PMC_SR);
402 seq_printf(s, "MCFR = %8x\n", at91_sys_read(AT91_CKGR_MCFR)); 440 seq_printf(s, "SCSR = %8x\n", scsr);
403 seq_printf(s, "PLLA = %8x\n", at91_sys_read(AT91_CKGR_PLLAR)); 441 seq_printf(s, "PCSR = %8x\n", pcsr);
442 seq_printf(s, "MOR = %8x\n", at91_pmc_read(AT91_CKGR_MOR));
443 seq_printf(s, "MCFR = %8x\n", at91_pmc_read(AT91_CKGR_MCFR));
444 seq_printf(s, "PLLA = %8x\n", at91_pmc_read(AT91_CKGR_PLLAR));
404 if (cpu_has_pllb()) 445 if (cpu_has_pllb())
405 seq_printf(s, "PLLB = %8x\n", at91_sys_read(AT91_CKGR_PLLBR)); 446 seq_printf(s, "PLLB = %8x\n", at91_pmc_read(AT91_CKGR_PLLBR));
406 if (cpu_has_utmi()) 447 if (cpu_has_utmi()) {
407 seq_printf(s, "UCKR = %8x\n", uckr = at91_sys_read(AT91_CKGR_UCKR)); 448 uckr = at91_pmc_read(AT91_CKGR_UCKR);
408 seq_printf(s, "MCKR = %8x\n", at91_sys_read(AT91_PMC_MCKR)); 449 seq_printf(s, "UCKR = %8x\n", uckr);
450 }
451 seq_printf(s, "MCKR = %8x\n", at91_pmc_read(AT91_PMC_MCKR));
409 if (cpu_has_upll()) 452 if (cpu_has_upll())
410 seq_printf(s, "USB = %8x\n", at91_sys_read(AT91_PMC_USB)); 453 seq_printf(s, "USB = %8x\n", at91_pmc_read(AT91_PMC_USB));
411 seq_printf(s, "SR = %8x\n", sr = at91_sys_read(AT91_PMC_SR)); 454 seq_printf(s, "SR = %8x\n", sr);
412 455
413 seq_printf(s, "\n"); 456 seq_printf(s, "\n");
414 457
@@ -596,16 +639,14 @@ static void __init at91_pllb_usbfs_clock_init(unsigned long main_clock)
596 if (cpu_is_at91rm9200()) { 639 if (cpu_is_at91rm9200()) {
597 uhpck.pmc_mask = AT91RM9200_PMC_UHP; 640 uhpck.pmc_mask = AT91RM9200_PMC_UHP;
598 udpck.pmc_mask = AT91RM9200_PMC_UDP; 641 udpck.pmc_mask = AT91RM9200_PMC_UDP;
599 at91_sys_write(AT91_PMC_SCER, AT91RM9200_PMC_MCKUDP); 642 at91_pmc_write(AT91_PMC_SCER, AT91RM9200_PMC_MCKUDP);
600 } else if (cpu_is_at91sam9260() || cpu_is_at91sam9261() || 643 } else if (cpu_is_at91sam9260() || cpu_is_at91sam9261() ||
601 cpu_is_at91sam9263() || cpu_is_at91sam9g20() || 644 cpu_is_at91sam9263() || cpu_is_at91sam9g20() ||
602 cpu_is_at91sam9g10()) { 645 cpu_is_at91sam9g10()) {
603 uhpck.pmc_mask = AT91SAM926x_PMC_UHP; 646 uhpck.pmc_mask = AT91SAM926x_PMC_UHP;
604 udpck.pmc_mask = AT91SAM926x_PMC_UDP; 647 udpck.pmc_mask = AT91SAM926x_PMC_UDP;
605 } else if (cpu_is_at91cap9()) {
606 uhpck.pmc_mask = AT91CAP9_PMC_UHP;
607 } 648 }
608 at91_sys_write(AT91_CKGR_PLLBR, 0); 649 at91_pmc_write(AT91_CKGR_PLLBR, 0);
609 650
610 udpck.rate_hz = at91_usb_rate(&pllb, pllb.rate_hz, at91_pllb_usb_init); 651 udpck.rate_hz = at91_usb_rate(&pllb, pllb.rate_hz, at91_pllb_usb_init);
611 uhpck.rate_hz = at91_usb_rate(&pllb, pllb.rate_hz, at91_pllb_usb_init); 652 uhpck.rate_hz = at91_usb_rate(&pllb, pllb.rate_hz, at91_pllb_usb_init);
@@ -622,16 +663,16 @@ static void __init at91_upll_usbfs_clock_init(unsigned long main_clock)
622 /* Setup divider by 10 to reach 48 MHz */ 663 /* Setup divider by 10 to reach 48 MHz */
623 usbr |= ((10 - 1) << 8) & AT91_PMC_OHCIUSBDIV; 664 usbr |= ((10 - 1) << 8) & AT91_PMC_OHCIUSBDIV;
624 665
625 at91_sys_write(AT91_PMC_USB, usbr); 666 at91_pmc_write(AT91_PMC_USB, usbr);
626 667
627 /* Now set uhpck values */ 668 /* Now set uhpck values */
628 uhpck.parent = &utmi_clk; 669 uhpck.parent = &utmi_clk;
629 uhpck.pmc_mask = AT91SAM926x_PMC_UHP; 670 uhpck.pmc_mask = AT91SAM926x_PMC_UHP;
630 uhpck.rate_hz = utmi_clk.rate_hz; 671 uhpck.rate_hz = utmi_clk.rate_hz;
631 uhpck.rate_hz /= 1 + ((at91_sys_read(AT91_PMC_USB) & AT91_PMC_OHCIUSBDIV) >> 8); 672 uhpck.rate_hz /= 1 + ((at91_pmc_read(AT91_PMC_USB) & AT91_PMC_OHCIUSBDIV) >> 8);
632} 673}
633 674
634int __init at91_clock_init(unsigned long main_clock) 675static int __init at91_pmc_init(unsigned long main_clock)
635{ 676{
636 unsigned tmp, freq, mckr; 677 unsigned tmp, freq, mckr;
637 int i; 678 int i;
@@ -645,14 +686,14 @@ int __init at91_clock_init(unsigned long main_clock)
645 */ 686 */
646 if (!main_clock) { 687 if (!main_clock) {
647 do { 688 do {
648 tmp = at91_sys_read(AT91_CKGR_MCFR); 689 tmp = at91_pmc_read(AT91_CKGR_MCFR);
649 } while (!(tmp & AT91_PMC_MAINRDY)); 690 } while (!(tmp & AT91_PMC_MAINRDY));
650 main_clock = (tmp & AT91_PMC_MAINF) * (AT91_SLOW_CLOCK / 16); 691 main_clock = (tmp & AT91_PMC_MAINF) * (AT91_SLOW_CLOCK / 16);
651 } 692 }
652 main_clk.rate_hz = main_clock; 693 main_clk.rate_hz = main_clock;
653 694
654 /* report if PLLA is more than mildly overclocked */ 695 /* report if PLLA is more than mildly overclocked */
655 plla.rate_hz = at91_pll_rate(&plla, main_clock, at91_sys_read(AT91_CKGR_PLLAR)); 696 plla.rate_hz = at91_pll_rate(&plla, main_clock, at91_pmc_read(AT91_CKGR_PLLAR));
656 if (cpu_has_300M_plla()) { 697 if (cpu_has_300M_plla()) {
657 if (plla.rate_hz > 300000000) 698 if (plla.rate_hz > 300000000)
658 pll_overclock = true; 699 pll_overclock = true;
@@ -666,8 +707,8 @@ int __init at91_clock_init(unsigned long main_clock)
666 if (pll_overclock) 707 if (pll_overclock)
667 pr_info("Clocks: PLLA overclocked, %ld MHz\n", plla.rate_hz / 1000000); 708 pr_info("Clocks: PLLA overclocked, %ld MHz\n", plla.rate_hz / 1000000);
668 709
669 if (cpu_is_at91sam9g45()) { 710 if (cpu_has_plladiv2()) {
670 mckr = at91_sys_read(AT91_PMC_MCKR); 711 mckr = at91_pmc_read(AT91_PMC_MCKR);
671 plla.rate_hz /= (1 << ((mckr & AT91_PMC_PLLADIV2) >> 12)); /* plla divisor by 2 */ 712 plla.rate_hz /= (1 << ((mckr & AT91_PMC_PLLADIV2) >> 12)); /* plla divisor by 2 */
672 } 713 }
673 714
@@ -688,6 +729,10 @@ int __init at91_clock_init(unsigned long main_clock)
688 * (obtain the USB High Speed 480 MHz when input is 12 MHz) 729 * (obtain the USB High Speed 480 MHz when input is 12 MHz)
689 */ 730 */
690 utmi_clk.rate_hz = 40 * utmi_clk.parent->rate_hz; 731 utmi_clk.rate_hz = 40 * utmi_clk.parent->rate_hz;
732
733 /* UTMI bias and PLL are managed at the same time */
734 if (cpu_has_upll())
735 utmi_clk.pmc_mask |= AT91_PMC_BIASEN;
691 } 736 }
692 737
693 /* 738 /*
@@ -703,10 +748,10 @@ int __init at91_clock_init(unsigned long main_clock)
703 * MCK and CPU derive from one of those primary clocks. 748 * MCK and CPU derive from one of those primary clocks.
704 * For now, assume this parentage won't change. 749 * For now, assume this parentage won't change.
705 */ 750 */
706 mckr = at91_sys_read(AT91_PMC_MCKR); 751 mckr = at91_pmc_read(AT91_PMC_MCKR);
707 mck.parent = at91_css_to_clk(mckr & AT91_PMC_CSS); 752 mck.parent = at91_css_to_clk(mckr & AT91_PMC_CSS);
708 freq = mck.parent->rate_hz; 753 freq = mck.parent->rate_hz;
709 freq /= (1 << ((mckr & AT91_PMC_PRES) >> 2)); /* prescale */ 754 freq /= pmc_prescaler_divider(mckr); /* prescale */
710 if (cpu_is_at91rm9200()) { 755 if (cpu_is_at91rm9200()) {
711 mck.rate_hz = freq / (1 + ((mckr & AT91_PMC_MDIV) >> 8)); /* mdiv */ 756 mck.rate_hz = freq / (1 + ((mckr & AT91_PMC_MDIV) >> 8)); /* mdiv */
712 } else if (cpu_is_at91sam9g20()) { 757 } else if (cpu_is_at91sam9g20()) {
@@ -714,13 +759,19 @@ int __init at91_clock_init(unsigned long main_clock)
714 freq / ((mckr & AT91_PMC_MDIV) >> 7) : freq; /* mdiv ; (x >> 7) = ((x >> 8) * 2) */ 759 freq / ((mckr & AT91_PMC_MDIV) >> 7) : freq; /* mdiv ; (x >> 7) = ((x >> 8) * 2) */
715 if (mckr & AT91_PMC_PDIV) 760 if (mckr & AT91_PMC_PDIV)
716 freq /= 2; /* processor clock division */ 761 freq /= 2; /* processor clock division */
717 } else if (cpu_is_at91sam9g45()) { 762 } else if (cpu_has_mdiv3()) {
718 mck.rate_hz = (mckr & AT91_PMC_MDIV) == AT91SAM9_PMC_MDIV_3 ? 763 mck.rate_hz = (mckr & AT91_PMC_MDIV) == AT91SAM9_PMC_MDIV_3 ?
719 freq / 3 : freq / (1 << ((mckr & AT91_PMC_MDIV) >> 8)); /* mdiv */ 764 freq / 3 : freq / (1 << ((mckr & AT91_PMC_MDIV) >> 8)); /* mdiv */
720 } else { 765 } else {
721 mck.rate_hz = freq / (1 << ((mckr & AT91_PMC_MDIV) >> 8)); /* mdiv */ 766 mck.rate_hz = freq / (1 << ((mckr & AT91_PMC_MDIV) >> 8)); /* mdiv */
722 } 767 }
723 768
769 if (cpu_has_alt_prescaler()) {
770 /* Programmable clocks can use MCK */
771 mck.type |= CLK_TYPE_PRIMARY;
772 mck.id = 4;
773 }
774
724 /* Register the PMC's standard clocks */ 775 /* Register the PMC's standard clocks */
725 for (i = 0; i < ARRAY_SIZE(standard_pmc_clocks); i++) 776 for (i = 0; i < ARRAY_SIZE(standard_pmc_clocks); i++)
726 at91_clk_add(standard_pmc_clocks[i]); 777 at91_clk_add(standard_pmc_clocks[i]);
@@ -748,6 +799,55 @@ int __init at91_clock_init(unsigned long main_clock)
748 return 0; 799 return 0;
749} 800}
750 801
802#if defined(CONFIG_OF)
803static struct of_device_id pmc_ids[] = {
804 { .compatible = "atmel,at91rm9200-pmc" },
805 { /*sentinel*/ }
806};
807
808static struct of_device_id osc_ids[] = {
809 { .compatible = "atmel,osc" },
810 { /*sentinel*/ }
811};
812
813int __init at91_dt_clock_init(void)
814{
815 struct device_node *np;
816 u32 main_clock = 0;
817
818 np = of_find_matching_node(NULL, pmc_ids);
819 if (!np)
820 panic("unable to find compatible pmc node in dtb\n");
821
822 at91_pmc_base = of_iomap(np, 0);
823 if (!at91_pmc_base)
824 panic("unable to map pmc cpu registers\n");
825
826 of_node_put(np);
827
828 /* retrieve the freqency of fixed clocks from device tree */
829 np = of_find_matching_node(NULL, osc_ids);
830 if (np) {
831 u32 rate;
832 if (!of_property_read_u32(np, "clock-frequency", &rate))
833 main_clock = rate;
834 }
835
836 of_node_put(np);
837
838 return at91_pmc_init(main_clock);
839}
840#endif
841
842int __init at91_clock_init(unsigned long main_clock)
843{
844 at91_pmc_base = ioremap(AT91_PMC, 256);
845 if (!at91_pmc_base)
846 panic("Impossible to ioremap AT91_PMC 0x%x\n", AT91_PMC);
847
848 return at91_pmc_init(main_clock);
849}
850
751/* 851/*
752 * Several unused clocks may be active. Turn them off. 852 * Several unused clocks may be active. Turn them off.
753 */ 853 */
@@ -770,9 +870,15 @@ static int __init at91_clock_reset(void)
770 pr_debug("Clocks: disable unused %s\n", clk->name); 870 pr_debug("Clocks: disable unused %s\n", clk->name);
771 } 871 }
772 872
773 at91_sys_write(AT91_PMC_PCDR, pcdr); 873 at91_pmc_write(AT91_PMC_PCDR, pcdr);
774 at91_sys_write(AT91_PMC_SCDR, scdr); 874 at91_pmc_write(AT91_PMC_SCDR, scdr);
775 875
776 return 0; 876 return 0;
777} 877}
778late_initcall(at91_clock_reset); 878late_initcall(at91_clock_reset);
879
880void at91sam9_idle(void)
881{
882 at91_pmc_write(AT91_PMC_SCDR, AT91_PMC_PCK);
883 cpu_do_idle();
884}