diff options
author | Russell King <rmk@dyn-67.arm.linux.org.uk> | 2006-03-15 10:54:37 -0500 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2006-03-21 17:05:53 -0500 |
commit | 97d654f8eb4b8fbb6e1afef076429a4235a3a3ad (patch) | |
tree | 2d289d4e07f15254254a873a15ccb443acebe7d9 | |
parent | 824b5b5e59472c89bc508afa5c453547c91ed53b (diff) |
[ARM] Convert SA1111 to use clock architecture
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r-- | arch/arm/common/sa1111.c | 41 | ||||
-rw-r--r-- | arch/arm/mach-pxa/Makefile | 2 | ||||
-rw-r--r-- | arch/arm/mach-pxa/clock.c | 124 | ||||
-rw-r--r-- | arch/arm/mach-sa1100/Makefile | 2 | ||||
-rw-r--r-- | arch/arm/mach-sa1100/clock.c | 132 |
5 files changed, 278 insertions, 23 deletions
diff --git a/arch/arm/common/sa1111.c b/arch/arm/common/sa1111.c index 93352f6097c1..5ba1ee042349 100644 --- a/arch/arm/common/sa1111.c +++ b/arch/arm/common/sa1111.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <linux/spinlock.h> | 27 | #include <linux/spinlock.h> |
28 | #include <linux/dma-mapping.h> | 28 | #include <linux/dma-mapping.h> |
29 | #include <linux/clk.h> | ||
29 | 30 | ||
30 | #include <asm/hardware.h> | 31 | #include <asm/hardware.h> |
31 | #include <asm/mach-types.h> | 32 | #include <asm/mach-types.h> |
@@ -36,10 +37,6 @@ | |||
36 | 37 | ||
37 | #include <asm/hardware/sa1111.h> | 38 | #include <asm/hardware/sa1111.h> |
38 | 39 | ||
39 | #ifdef CONFIG_ARCH_PXA | ||
40 | #include <asm/arch/pxa-regs.h> | ||
41 | #endif | ||
42 | |||
43 | extern void __init sa1110_mb_enable(void); | 40 | extern void __init sa1110_mb_enable(void); |
44 | 41 | ||
45 | /* | 42 | /* |
@@ -51,6 +48,7 @@ extern void __init sa1110_mb_enable(void); | |||
51 | */ | 48 | */ |
52 | struct sa1111 { | 49 | struct sa1111 { |
53 | struct device *dev; | 50 | struct device *dev; |
51 | struct clk *clk; | ||
54 | unsigned long phys; | 52 | unsigned long phys; |
55 | int irq; | 53 | int irq; |
56 | spinlock_t lock; | 54 | spinlock_t lock; |
@@ -451,19 +449,7 @@ static void sa1111_wake(struct sa1111 *sachip) | |||
451 | 449 | ||
452 | spin_lock_irqsave(&sachip->lock, flags); | 450 | spin_lock_irqsave(&sachip->lock, flags); |
453 | 451 | ||
454 | #ifdef CONFIG_ARCH_SA1100 | 452 | clk_enable(sachip->clk); |
455 | /* | ||
456 | * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111: | ||
457 | * (SA-1110 Developer's Manual, section 9.1.2.1) | ||
458 | */ | ||
459 | GAFR |= GPIO_32_768kHz; | ||
460 | GPDR |= GPIO_32_768kHz; | ||
461 | TUCR = TUCR_3_6864MHz; | ||
462 | #elif CONFIG_ARCH_PXA | ||
463 | pxa_gpio_mode(GPIO11_3_6MHz_MD); | ||
464 | #else | ||
465 | #error missing clock setup | ||
466 | #endif | ||
467 | 453 | ||
468 | /* | 454 | /* |
469 | * Turn VCO on, and disable PLL Bypass. | 455 | * Turn VCO on, and disable PLL Bypass. |
@@ -641,6 +627,12 @@ __sa1111_probe(struct device *me, struct resource *mem, int irq) | |||
641 | 627 | ||
642 | memset(sachip, 0, sizeof(struct sa1111)); | 628 | memset(sachip, 0, sizeof(struct sa1111)); |
643 | 629 | ||
630 | sachip->clk = clk_get(me, "GPIO27_CLK"); | ||
631 | if (!sachip->clk) { | ||
632 | ret = PTR_ERR(sachip->clk); | ||
633 | goto err_free; | ||
634 | } | ||
635 | |||
644 | spin_lock_init(&sachip->lock); | 636 | spin_lock_init(&sachip->lock); |
645 | 637 | ||
646 | sachip->dev = me; | 638 | sachip->dev = me; |
@@ -656,7 +648,7 @@ __sa1111_probe(struct device *me, struct resource *mem, int irq) | |||
656 | sachip->base = ioremap(mem->start, PAGE_SIZE * 2); | 648 | sachip->base = ioremap(mem->start, PAGE_SIZE * 2); |
657 | if (!sachip->base) { | 649 | if (!sachip->base) { |
658 | ret = -ENOMEM; | 650 | ret = -ENOMEM; |
659 | goto out; | 651 | goto err_clkput; |
660 | } | 652 | } |
661 | 653 | ||
662 | /* | 654 | /* |
@@ -666,7 +658,7 @@ __sa1111_probe(struct device *me, struct resource *mem, int irq) | |||
666 | if ((id & SKID_ID_MASK) != SKID_SA1111_ID) { | 658 | if ((id & SKID_ID_MASK) != SKID_SA1111_ID) { |
667 | printk(KERN_DEBUG "SA1111 not detected: ID = %08lx\n", id); | 659 | printk(KERN_DEBUG "SA1111 not detected: ID = %08lx\n", id); |
668 | ret = -ENODEV; | 660 | ret = -ENODEV; |
669 | goto unmap; | 661 | goto err_unmap; |
670 | } | 662 | } |
671 | 663 | ||
672 | printk(KERN_INFO "SA1111 Microprocessor Companion Chip: " | 664 | printk(KERN_INFO "SA1111 Microprocessor Companion Chip: " |
@@ -726,9 +718,11 @@ __sa1111_probe(struct device *me, struct resource *mem, int irq) | |||
726 | 718 | ||
727 | return 0; | 719 | return 0; |
728 | 720 | ||
729 | unmap: | 721 | err_unmap: |
730 | iounmap(sachip->base); | 722 | iounmap(sachip->base); |
731 | out: | 723 | err_clkput: |
724 | clk_put(sachip->clk); | ||
725 | err_free: | ||
732 | kfree(sachip); | 726 | kfree(sachip); |
733 | return ret; | 727 | return ret; |
734 | } | 728 | } |
@@ -751,6 +745,8 @@ static void __sa1111_remove(struct sa1111 *sachip) | |||
751 | sa1111_writel(0, irqbase + SA1111_WAKEEN0); | 745 | sa1111_writel(0, irqbase + SA1111_WAKEEN0); |
752 | sa1111_writel(0, irqbase + SA1111_WAKEEN1); | 746 | sa1111_writel(0, irqbase + SA1111_WAKEEN1); |
753 | 747 | ||
748 | clk_disable(sachip->clk); | ||
749 | |||
754 | if (sachip->irq != NO_IRQ) { | 750 | if (sachip->irq != NO_IRQ) { |
755 | set_irq_chained_handler(sachip->irq, NULL); | 751 | set_irq_chained_handler(sachip->irq, NULL); |
756 | set_irq_data(sachip->irq, NULL); | 752 | set_irq_data(sachip->irq, NULL); |
@@ -759,6 +755,7 @@ static void __sa1111_remove(struct sa1111 *sachip) | |||
759 | } | 755 | } |
760 | 756 | ||
761 | iounmap(sachip->base); | 757 | iounmap(sachip->base); |
758 | clk_put(sachip->clk); | ||
762 | kfree(sachip); | 759 | kfree(sachip); |
763 | } | 760 | } |
764 | 761 | ||
@@ -857,6 +854,8 @@ static int sa1111_suspend(struct platform_device *dev, pm_message_t state) | |||
857 | sa1111_writel(0, sachip->base + SA1111_SKPWM0); | 854 | sa1111_writel(0, sachip->base + SA1111_SKPWM0); |
858 | sa1111_writel(0, sachip->base + SA1111_SKPWM1); | 855 | sa1111_writel(0, sachip->base + SA1111_SKPWM1); |
859 | 856 | ||
857 | clk_disable(sachip->clk); | ||
858 | |||
860 | spin_unlock_irqrestore(&sachip->lock, flags); | 859 | spin_unlock_irqrestore(&sachip->lock, flags); |
861 | 860 | ||
862 | return 0; | 861 | return 0; |
diff --git a/arch/arm/mach-pxa/Makefile b/arch/arm/mach-pxa/Makefile index 32526a0a6f86..382644401a4d 100644 --- a/arch/arm/mach-pxa/Makefile +++ b/arch/arm/mach-pxa/Makefile | |||
@@ -3,7 +3,7 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | # Common support (must be linked before board specific support) | 5 | # Common support (must be linked before board specific support) |
6 | obj-y += generic.o irq.o dma.o time.o | 6 | obj-y += clock.o generic.o irq.o dma.o time.o |
7 | obj-$(CONFIG_PXA25x) += pxa25x.o | 7 | obj-$(CONFIG_PXA25x) += pxa25x.o |
8 | obj-$(CONFIG_PXA27x) += pxa27x.o | 8 | obj-$(CONFIG_PXA27x) += pxa27x.o |
9 | 9 | ||
diff --git a/arch/arm/mach-pxa/clock.c b/arch/arm/mach-pxa/clock.c new file mode 100644 index 000000000000..8f7c90a0593b --- /dev/null +++ b/arch/arm/mach-pxa/clock.c | |||
@@ -0,0 +1,124 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/mach-sa1100/clock.c | ||
3 | */ | ||
4 | #include <linux/module.h> | ||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/list.h> | ||
7 | #include <linux/errno.h> | ||
8 | #include <linux/err.h> | ||
9 | #include <linux/string.h> | ||
10 | #include <linux/clk.h> | ||
11 | #include <linux/spinlock.h> | ||
12 | |||
13 | #include <asm/arch/pxa-regs.h> | ||
14 | #include <asm/hardware.h> | ||
15 | #include <asm/semaphore.h> | ||
16 | |||
17 | struct clk { | ||
18 | struct list_head node; | ||
19 | unsigned long rate; | ||
20 | struct module *owner; | ||
21 | const char *name; | ||
22 | unsigned int enabled; | ||
23 | void (*enable)(void); | ||
24 | void (*disable)(void); | ||
25 | }; | ||
26 | |||
27 | static LIST_HEAD(clocks); | ||
28 | static DECLARE_MUTEX(clocks_sem); | ||
29 | static DEFINE_SPINLOCK(clocks_lock); | ||
30 | |||
31 | struct clk *clk_get(struct device *dev, const char *id) | ||
32 | { | ||
33 | struct clk *p, *clk = ERR_PTR(-ENOENT); | ||
34 | |||
35 | down(&clocks_sem); | ||
36 | list_for_each_entry(p, &clocks, node) { | ||
37 | if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) { | ||
38 | clk = p; | ||
39 | break; | ||
40 | } | ||
41 | } | ||
42 | up(&clocks_sem); | ||
43 | |||
44 | return clk; | ||
45 | } | ||
46 | EXPORT_SYMBOL(clk_get); | ||
47 | |||
48 | void clk_put(struct clk *clk) | ||
49 | { | ||
50 | module_put(clk->owner); | ||
51 | } | ||
52 | EXPORT_SYMBOL(clk_put); | ||
53 | |||
54 | int clk_enable(struct clk *clk) | ||
55 | { | ||
56 | unsigned long flags; | ||
57 | |||
58 | spin_lock_irqsave(&clocks_lock, flags); | ||
59 | if (clk->enabled++ == 0) | ||
60 | clk->enable(); | ||
61 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
62 | return 0; | ||
63 | } | ||
64 | EXPORT_SYMBOL(clk_enable); | ||
65 | |||
66 | void clk_disable(struct clk *clk) | ||
67 | { | ||
68 | unsigned long flags; | ||
69 | |||
70 | WARN_ON(clk->enabled == 0); | ||
71 | |||
72 | spin_lock_irqsave(&clocks_lock, flags); | ||
73 | if (--clk->enabled == 0) | ||
74 | clk->disable(); | ||
75 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
76 | } | ||
77 | EXPORT_SYMBOL(clk_disable); | ||
78 | |||
79 | unsigned long clk_get_rate(struct clk *clk) | ||
80 | { | ||
81 | return clk->rate; | ||
82 | } | ||
83 | EXPORT_SYMBOL(clk_get_rate); | ||
84 | |||
85 | |||
86 | static void clk_gpio27_enable(void) | ||
87 | { | ||
88 | pxa_gpio_mode(GPIO11_3_6MHz_MD); | ||
89 | } | ||
90 | |||
91 | static void clk_gpio27_disable(void) | ||
92 | { | ||
93 | } | ||
94 | |||
95 | static struct clk clk_gpio27 = { | ||
96 | .name = "GPIO27_CLK", | ||
97 | .rate = 3686400, | ||
98 | .enable = clk_gpio27_enable, | ||
99 | .disable = clk_gpio27_disable, | ||
100 | }; | ||
101 | |||
102 | int clk_register(struct clk *clk) | ||
103 | { | ||
104 | down(&clocks_sem); | ||
105 | list_add(&clk->node, &clocks); | ||
106 | up(&clocks_sem); | ||
107 | return 0; | ||
108 | } | ||
109 | EXPORT_SYMBOL(clk_register); | ||
110 | |||
111 | void clk_unregister(struct clk *clk) | ||
112 | { | ||
113 | down(&clocks_sem); | ||
114 | list_del(&clk->node); | ||
115 | up(&clocks_sem); | ||
116 | } | ||
117 | EXPORT_SYMBOL(clk_unregister); | ||
118 | |||
119 | static int __init clk_init(void) | ||
120 | { | ||
121 | clk_register(&clk_gpio27); | ||
122 | return 0; | ||
123 | } | ||
124 | arch_initcall(clk_init); | ||
diff --git a/arch/arm/mach-sa1100/Makefile b/arch/arm/mach-sa1100/Makefile index e4a4a3e8aa8f..e27f15042a22 100644 --- a/arch/arm/mach-sa1100/Makefile +++ b/arch/arm/mach-sa1100/Makefile | |||
@@ -3,7 +3,7 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | # Common support | 5 | # Common support |
6 | obj-y := generic.o irq.o dma.o time.o | 6 | obj-y := clock.o generic.o irq.o dma.o time.o #nmi-oopser.o |
7 | obj-m := | 7 | obj-m := |
8 | obj-n := | 8 | obj-n := |
9 | obj- := | 9 | obj- := |
diff --git a/arch/arm/mach-sa1100/clock.c b/arch/arm/mach-sa1100/clock.c new file mode 100644 index 000000000000..b1e8fd766c1a --- /dev/null +++ b/arch/arm/mach-sa1100/clock.c | |||
@@ -0,0 +1,132 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/mach-sa1100/clock.c | ||
3 | */ | ||
4 | #include <linux/module.h> | ||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/list.h> | ||
7 | #include <linux/errno.h> | ||
8 | #include <linux/err.h> | ||
9 | #include <linux/string.h> | ||
10 | #include <linux/clk.h> | ||
11 | #include <linux/spinlock.h> | ||
12 | |||
13 | #include <asm/hardware.h> | ||
14 | #include <asm/semaphore.h> | ||
15 | |||
16 | struct clk { | ||
17 | struct list_head node; | ||
18 | unsigned long rate; | ||
19 | struct module *owner; | ||
20 | const char *name; | ||
21 | unsigned int enabled; | ||
22 | void (*enable)(void); | ||
23 | void (*disable)(void); | ||
24 | }; | ||
25 | |||
26 | static LIST_HEAD(clocks); | ||
27 | static DECLARE_MUTEX(clocks_sem); | ||
28 | static DEFINE_SPINLOCK(clocks_lock); | ||
29 | |||
30 | struct clk *clk_get(struct device *dev, const char *id) | ||
31 | { | ||
32 | struct clk *p, *clk = ERR_PTR(-ENOENT); | ||
33 | |||
34 | down(&clocks_sem); | ||
35 | list_for_each_entry(p, &clocks, node) { | ||
36 | if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) { | ||
37 | clk = p; | ||
38 | break; | ||
39 | } | ||
40 | } | ||
41 | up(&clocks_sem); | ||
42 | |||
43 | return clk; | ||
44 | } | ||
45 | EXPORT_SYMBOL(clk_get); | ||
46 | |||
47 | void clk_put(struct clk *clk) | ||
48 | { | ||
49 | module_put(clk->owner); | ||
50 | } | ||
51 | EXPORT_SYMBOL(clk_put); | ||
52 | |||
53 | int clk_enable(struct clk *clk) | ||
54 | { | ||
55 | unsigned long flags; | ||
56 | |||
57 | spin_lock_irqsave(&clocks_lock, flags); | ||
58 | if (clk->enabled++ == 0) | ||
59 | clk->enable(); | ||
60 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
61 | return 0; | ||
62 | } | ||
63 | EXPORT_SYMBOL(clk_enable); | ||
64 | |||
65 | void clk_disable(struct clk *clk) | ||
66 | { | ||
67 | unsigned long flags; | ||
68 | |||
69 | WARN_ON(clk->enabled == 0); | ||
70 | |||
71 | spin_lock_irqsave(&clocks_lock, flags); | ||
72 | if (--clk->enabled == 0) | ||
73 | clk->disable(); | ||
74 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
75 | } | ||
76 | EXPORT_SYMBOL(clk_disable); | ||
77 | |||
78 | unsigned long clk_get_rate(struct clk *clk) | ||
79 | { | ||
80 | return clk->rate; | ||
81 | } | ||
82 | EXPORT_SYMBOL(clk_get_rate); | ||
83 | |||
84 | |||
85 | static void clk_gpio27_enable(void) | ||
86 | { | ||
87 | /* | ||
88 | * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111: | ||
89 | * (SA-1110 Developer's Manual, section 9.1.2.1) | ||
90 | */ | ||
91 | GAFR |= GPIO_32_768kHz; | ||
92 | GPDR |= GPIO_32_768kHz; | ||
93 | TUCR = TUCR_3_6864MHz; | ||
94 | } | ||
95 | |||
96 | static void clk_gpio27_disable(void) | ||
97 | { | ||
98 | TUCR = 0; | ||
99 | GPDR &= ~GPIO_32_768kHz; | ||
100 | GAFR &= ~GPIO_32_768kHz; | ||
101 | } | ||
102 | |||
103 | static struct clk clk_gpio27 = { | ||
104 | .name = "GPIO27_CLK", | ||
105 | .rate = 3686400, | ||
106 | .enable = clk_gpio27_enable, | ||
107 | .disable = clk_gpio27_disable, | ||
108 | }; | ||
109 | |||
110 | int clk_register(struct clk *clk) | ||
111 | { | ||
112 | down(&clocks_sem); | ||
113 | list_add(&clk->node, &clocks); | ||
114 | up(&clocks_sem); | ||
115 | return 0; | ||
116 | } | ||
117 | EXPORT_SYMBOL(clk_register); | ||
118 | |||
119 | void clk_unregister(struct clk *clk) | ||
120 | { | ||
121 | down(&clocks_sem); | ||
122 | list_del(&clk->node); | ||
123 | up(&clocks_sem); | ||
124 | } | ||
125 | EXPORT_SYMBOL(clk_unregister); | ||
126 | |||
127 | static int __init clk_init(void) | ||
128 | { | ||
129 | clk_register(&clk_gpio27); | ||
130 | return 0; | ||
131 | } | ||
132 | arch_initcall(clk_init); | ||