13 #include <linux/module.h>
14 #include <linux/kernel.h>
19 #include <linux/list.h>
20 #include <linux/errno.h>
28 #include <mach/hardware.h>
32 #include <asm/proc-fns.h>
46 #define clk_is_primary(x) ((x)->type & CLK_TYPE_PRIMARY)
47 #define clk_is_programmable(x) ((x)->type & CLK_TYPE_PROGRAMMABLE)
48 #define clk_is_peripheral(x) ((x)->type & CLK_TYPE_PERIPHERAL)
49 #define clk_is_sys(x) ((x)->type & CLK_TYPE_SYSTEM)
55 #define cpu_has_utmi() ( cpu_is_at91sam9rl() \
56 || cpu_is_at91sam9g45() \
57 || cpu_is_at91sam9x5())
59 #define cpu_has_800M_plla() ( cpu_is_at91sam9g20() \
60 || cpu_is_at91sam9g45() \
61 || cpu_is_at91sam9x5() \
62 || cpu_is_at91sam9n12())
64 #define cpu_has_300M_plla() (cpu_is_at91sam9g10())
66 #define cpu_has_240M_plla() (cpu_is_at91sam9261() \
67 || cpu_is_at91sam9263() \
68 || cpu_is_at91sam9rl())
70 #define cpu_has_210M_plla() (cpu_is_at91sam9260())
72 #define cpu_has_pllb() (!(cpu_is_at91sam9rl() \
73 || cpu_is_at91sam9g45() \
74 || cpu_is_at91sam9x5() \
75 || cpu_is_at91sam9n12()))
77 #define cpu_has_upll() (cpu_is_at91sam9g45() \
78 || cpu_is_at91sam9x5())
81 #define cpu_has_uhp() (!cpu_is_at91sam9rl())
84 #define cpu_has_udpfs() (!(cpu_is_at91sam9rl() \
85 || cpu_is_at91sam9g45() \
86 || cpu_is_at91sam9x5()))
88 #define cpu_has_plladiv2() (cpu_is_at91sam9g45() \
89 || cpu_is_at91sam9x5() \
90 || cpu_is_at91sam9n12())
92 #define cpu_has_mdiv3() (cpu_is_at91sam9g45() \
93 || cpu_is_at91sam9x5() \
94 || cpu_is_at91sam9n12())
96 #define cpu_has_alt_prescaler() (cpu_is_at91sam9x5() \
97 || cpu_is_at91sam9n12())
102 static u32 at91_pllb_usb_init;
110 static struct clk clk32k = {
123 static struct clk plla = {
131 static void pllb_mode(
struct clk *
clk,
int is_on)
137 value = at91_pllb_usb_init;
149 static struct clk pllb = {
158 static void pmc_sys_mode(
struct clk *clk,
int is_on)
166 static void pmc_uckr_mode(
struct clk *clk,
int is_on)
182 static struct clk udpck = {
185 .
mode = pmc_sys_mode,
191 .mode = pmc_uckr_mode,
194 static struct clk uhpck = {
197 .mode = pmc_sys_mode,
211 static void pmc_periph_mode(
struct clk *clk,
int is_on)
219 static struct clk
__init *at91_css_to_clk(
unsigned long css)
243 static int pmc_prescaler_divider(
u32 reg)
266 spin_unlock_irqrestore(&clk_lock, flags);
286 spin_unlock_irqrestore(&clk_lock, flags);
302 spin_unlock_irqrestore(&clk_lock, flags);
309 #ifdef CONFIG_AT91_PROGRAMMABLE_CLOCKS
322 unsigned long actual;
329 actual = clk->
parent->rate_hz;
330 for (prescale = 0; prescale < 7; prescale++) {
334 if (actual && actual <= rate) {
335 if ((prev - rate) < (rate - actual)) {
344 spin_unlock_irqrestore(&clk_lock, flags);
345 return (prescale < 7) ? actual : -
ENOENT;
353 unsigned long prescale_offset, css_mask;
354 unsigned long actual;
371 actual = clk->
parent->rate_hz;
372 for (prescale = 0; prescale < 7; prescale++) {
373 if (actual && actual <= rate) {
378 pckr |= prescale << prescale_offset;
386 spin_unlock_irqrestore(&clk_lock, flags);
387 return (prescale < 7) ? actual : -
ENOENT;
415 spin_unlock_irqrestore(&clk_lock, flags);
421 static void __init init_programmable_clock(
struct clk *clk)
425 unsigned int css_mask;
433 parent = at91_css_to_clk(pckr & css_mask);
442 #ifdef CONFIG_DEBUG_FS
446 u32 scsr, pcsr, uckr = 0,
sr;
473 if (clk->
mode == pmc_sys_mode)
474 state = (scsr & clk->
pmc_mask) ?
"on" :
"off";
475 else if (clk->
mode == pmc_periph_mode)
476 state = (pcsr & clk->
pmc_mask) ?
"on" :
"off";
477 else if (clk->
mode == pmc_uckr_mode)
478 state = (uckr & clk->
pmc_mask) ?
"on" :
"off";
481 else if (clk == &clk32k || clk == &main_clk)
486 seq_printf(s,
"%-10s users=%2d %-3s %9ld Hz %s\n",
499 .
open = at91_clk_open,
505 static int __init at91_clk_debugfs_init(
void)
519 static void __init at91_clk_add(
struct clk *clk)
523 clk->
cl.con_id = clk->
name;
533 clk->
mode = pmc_periph_mode;
537 clk->
mode = pmc_sys_mode;
539 #ifdef CONFIG_AT91_PROGRAMMABLE_CLOCKS
541 clk->
mode = pmc_sys_mode;
542 init_programmable_clock(clk);
558 mul = (reg >> 16) & 0x7ff;
576 static unsigned __init at91_pll_calc(
unsigned main_freq,
unsigned out_freq)
578 unsigned i, div = 0, mul = 0, diff = 1 << 30;
579 unsigned ret = (out_freq > 155000000) ? 0xbe00 : 0x3e00;
582 if (out_freq > 240000000)
585 for (i = 1; i < 256; i++) {
587 unsigned input, mul1;
594 input = main_freq /
i;
599 if (input > 32000000)
602 mul1 = out_freq /
input;
610 diff1 = out_freq - input * mul1;
621 if (i == 256 && diff > (out_freq >> 5))
623 return ret | ((mul - 1) << 16) |
div;
628 static struct clk *
const standard_pmc_clocks[]
__initconst = {
639 static void __init at91_pllb_usbfs_clock_init(
unsigned long main_clock)
649 at91_pllb_usb_init = at91_pll_calc(main_clock, 48000000 * 2) |
AT91_PMC_USB96M;
650 pllb.
rate_hz = at91_pll_rate(&pllb, main_clock, at91_pllb_usb_init);
663 udpck.
rate_hz = at91_usb_rate(&pllb, pllb.
rate_hz, at91_pllb_usb_init);
664 uhpck.
rate_hz = at91_usb_rate(&pllb, pllb.
rate_hz, at91_pllb_usb_init);
668 static void __init at91_upll_usbfs_clock_init(
unsigned long main_clock)
687 static int __init at91_pmc_init(
unsigned long main_clock)
691 int pll_overclock =
false;
711 pll_overclock =
true;
714 pll_overclock =
true;
717 pll_overclock =
true;
720 pll_overclock =
true;
723 pll_overclock =
true;
726 pr_info(
"Clocks: PLLA overclocked, %ld MHz\n", plla.
rate_hz / 1000000);
760 at91_pllb_usbfs_clock_init(main_clock);
763 at91_upll_usbfs_clock_init(main_clock);
771 freq = mck.
parent->rate_hz;
772 freq /= pmc_prescaler_divider(mckr);
782 freq / 3 : freq / (1 << ((mckr & AT91_PMC_MDIV) >> 8));
794 for (i = 0; i <
ARRAY_SIZE(standard_pmc_clocks); i++)
795 at91_clk_add(standard_pmc_clocks[i]);
801 at91_clk_add(&uhpck);
804 at91_clk_add(&udpck);
807 at91_clk_add(&utmi_clk);
812 printk(
"Clocks: CPU %u MHz, master %u MHz, main %u.%03u MHz\n",
813 freq / 1000000, (
unsigned) mck.
rate_hz / 1000000,
814 (
unsigned) main_clock / 1000000,
815 ((
unsigned) main_clock % 1000000) / 1000);
820 #if defined(CONFIG_OF)
831 int __init at91_dt_clock_init(
void)
838 panic(
"unable to find compatible pmc node in dtb\n");
842 panic(
"unable to map pmc cpu registers\n");
850 if (!of_property_read_u32(np,
"clock-frequency", &rate))
856 return at91_pmc_init(main_clock);
866 return at91_pmc_init(main_clock);
872 static int __init at91_clock_reset(
void)
874 unsigned long pcdr = 0;
875 unsigned long scdr = 0;
882 if (clk->
mode == pmc_periph_mode)
885 if (clk->
mode == pmc_sys_mode)