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