|
2 | 2 | /*
|
3 | 3 | * linux/arch/arm/mach-sa1100/clock.c
|
4 | 4 | */
|
5 |
| -#include <linux/module.h> |
6 | 5 | #include <linux/kernel.h>
|
7 |
| -#include <linux/device.h> |
8 |
| -#include <linux/list.h> |
9 | 6 | #include <linux/errno.h>
|
10 | 7 | #include <linux/err.h>
|
11 |
| -#include <linux/string.h> |
12 | 8 | #include <linux/clk.h>
|
13 |
| -#include <linux/spinlock.h> |
14 |
| -#include <linux/mutex.h> |
15 |
| -#include <linux/io.h> |
16 | 9 | #include <linux/clkdev.h>
|
| 10 | +#include <linux/clk-provider.h> |
| 11 | +#include <linux/io.h> |
| 12 | +#include <linux/spinlock.h> |
17 | 13 |
|
18 | 14 | #include <mach/hardware.h>
|
19 | 15 | #include <mach/generic.h>
|
20 | 16 |
|
21 |
| -struct clkops { |
22 |
| - void (*enable)(struct clk *); |
23 |
| - void (*disable)(struct clk *); |
24 |
| - unsigned long (*get_rate)(struct clk *); |
| 17 | +static const char * const clk_tucr_parents[] = { |
| 18 | + "clk32768", "clk3686400", |
25 | 19 | };
|
26 | 20 |
|
27 |
| -struct clk { |
28 |
| - const struct clkops *ops; |
29 |
| - unsigned int enabled; |
30 |
| -}; |
31 |
| - |
32 |
| -#define DEFINE_CLK(_name, _ops) \ |
33 |
| -struct clk clk_##_name = { \ |
34 |
| - .ops = _ops, \ |
35 |
| - } |
36 |
| - |
37 |
| -static DEFINE_SPINLOCK(clocks_lock); |
38 |
| - |
39 |
| -/* Dummy clk routine to build generic kernel parts that may be using them */ |
40 |
| -long clk_round_rate(struct clk *clk, unsigned long rate) |
41 |
| -{ |
42 |
| - return clk_get_rate(clk); |
43 |
| -} |
44 |
| -EXPORT_SYMBOL(clk_round_rate); |
45 |
| - |
46 |
| -int clk_set_rate(struct clk *clk, unsigned long rate) |
47 |
| -{ |
48 |
| - return 0; |
49 |
| -} |
50 |
| -EXPORT_SYMBOL(clk_set_rate); |
51 |
| - |
52 |
| -int clk_set_parent(struct clk *clk, struct clk *parent) |
53 |
| -{ |
54 |
| - return 0; |
55 |
| -} |
56 |
| -EXPORT_SYMBOL(clk_set_parent); |
| 21 | +static DEFINE_SPINLOCK(tucr_lock); |
57 | 22 |
|
58 |
| -struct clk *clk_get_parent(struct clk *clk) |
| 23 | +static int clk_gpio27_enable(struct clk_hw *hw) |
59 | 24 | {
|
60 |
| - return NULL; |
61 |
| -} |
62 |
| -EXPORT_SYMBOL(clk_get_parent); |
| 25 | + unsigned long flags; |
63 | 26 |
|
64 |
| -static void clk_gpio27_enable(struct clk *clk) |
65 |
| -{ |
66 | 27 | /*
|
67 | 28 | * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111:
|
68 | 29 | * (SA-1110 Developer's Manual, section 9.1.2.1)
|
69 | 30 | */
|
| 31 | + local_irq_save(flags); |
70 | 32 | GAFR |= GPIO_32_768kHz;
|
71 | 33 | GPDR |= GPIO_32_768kHz;
|
72 |
| - TUCR = TUCR_3_6864MHz; |
| 34 | + local_irq_restore(flags); |
| 35 | + |
| 36 | + return 0; |
73 | 37 | }
|
74 | 38 |
|
75 |
| -static void clk_gpio27_disable(struct clk *clk) |
| 39 | +static void clk_gpio27_disable(struct clk_hw *hw) |
76 | 40 | {
|
77 |
| - TUCR = 0; |
| 41 | + unsigned long flags; |
| 42 | + |
| 43 | + local_irq_save(flags); |
78 | 44 | GPDR &= ~GPIO_32_768kHz;
|
79 | 45 | GAFR &= ~GPIO_32_768kHz;
|
| 46 | + local_irq_restore(flags); |
80 | 47 | }
|
81 | 48 |
|
82 |
| -static void clk_cpu_enable(struct clk *clk) |
83 |
| -{ |
84 |
| -} |
| 49 | +static const struct clk_ops clk_gpio27_ops = { |
| 50 | + .enable = clk_gpio27_enable, |
| 51 | + .disable = clk_gpio27_disable, |
| 52 | +}; |
85 | 53 |
|
86 |
| -static void clk_cpu_disable(struct clk *clk) |
87 |
| -{ |
88 |
| -} |
| 54 | +static const char * const clk_gpio27_parents[] = { |
| 55 | + "tucr-mux", |
| 56 | +}; |
89 | 57 |
|
90 |
| -static unsigned long clk_cpu_get_rate(struct clk *clk) |
| 58 | +static const struct clk_init_data clk_gpio27_init_data __initconst = { |
| 59 | + .name = "gpio27", |
| 60 | + .ops = &clk_gpio27_ops, |
| 61 | + .parent_names = clk_gpio27_parents, |
| 62 | + .num_parents = ARRAY_SIZE(clk_gpio27_parents), |
| 63 | +}; |
| 64 | + |
| 65 | +/* |
| 66 | + * Derived from the table 8-1 in the SA1110 manual, the MPLL appears to |
| 67 | + * multiply its input rate by 4 x (4 + PPCR). This calculation gives |
| 68 | + * the exact rate. The figures given in the table are the rates rounded |
| 69 | + * to 100kHz. Stick with sa11x0_getspeed() for the time being. |
| 70 | + */ |
| 71 | +static unsigned long clk_mpll_recalc_rate(struct clk_hw *hw, |
| 72 | + unsigned long prate) |
91 | 73 | {
|
92 | 74 | return sa11x0_getspeed(0) * 1000;
|
93 | 75 | }
|
94 | 76 |
|
95 |
| -int clk_enable(struct clk *clk) |
96 |
| -{ |
97 |
| - unsigned long flags; |
98 |
| - |
99 |
| - if (clk) { |
100 |
| - spin_lock_irqsave(&clocks_lock, flags); |
101 |
| - if (clk->enabled++ == 0) |
102 |
| - clk->ops->enable(clk); |
103 |
| - spin_unlock_irqrestore(&clocks_lock, flags); |
104 |
| - } |
105 |
| - |
106 |
| - return 0; |
107 |
| -} |
108 |
| -EXPORT_SYMBOL(clk_enable); |
| 77 | +static const struct clk_ops clk_mpll_ops = { |
| 78 | + .recalc_rate = clk_mpll_recalc_rate, |
| 79 | +}; |
109 | 80 |
|
110 |
| -void clk_disable(struct clk *clk) |
111 |
| -{ |
112 |
| - unsigned long flags; |
| 81 | +static const char * const clk_mpll_parents[] = { |
| 82 | + "clk3686400", |
| 83 | +}; |
113 | 84 |
|
114 |
| - if (clk) { |
115 |
| - WARN_ON(clk->enabled == 0); |
116 |
| - spin_lock_irqsave(&clocks_lock, flags); |
117 |
| - if (--clk->enabled == 0) |
118 |
| - clk->ops->disable(clk); |
119 |
| - spin_unlock_irqrestore(&clocks_lock, flags); |
120 |
| - } |
121 |
| -} |
122 |
| -EXPORT_SYMBOL(clk_disable); |
| 85 | +static const struct clk_init_data clk_mpll_init_data __initconst = { |
| 86 | + .name = "mpll", |
| 87 | + .ops = &clk_mpll_ops, |
| 88 | + .parent_names = clk_mpll_parents, |
| 89 | + .num_parents = ARRAY_SIZE(clk_mpll_parents), |
| 90 | + .flags = CLK_GET_RATE_NOCACHE | CLK_IS_CRITICAL, |
| 91 | +}; |
123 | 92 |
|
124 |
| -unsigned long clk_get_rate(struct clk *clk) |
| 93 | +int __init sa11xx_clk_init(void) |
125 | 94 | {
|
126 |
| - if (clk && clk->ops && clk->ops->get_rate) |
127 |
| - return clk->ops->get_rate(clk); |
128 |
| - |
129 |
| - return 0; |
130 |
| -} |
131 |
| -EXPORT_SYMBOL(clk_get_rate); |
| 95 | + struct clk_hw *hw; |
| 96 | + int ret; |
132 | 97 |
|
133 |
| -const struct clkops clk_gpio27_ops = { |
134 |
| - .enable = clk_gpio27_enable, |
135 |
| - .disable = clk_gpio27_disable, |
136 |
| -}; |
| 98 | + hw = clk_hw_register_fixed_rate(NULL, "clk32768", NULL, 0, 32768); |
| 99 | + if (IS_ERR(hw)) |
| 100 | + return PTR_ERR(hw); |
137 | 101 |
|
138 |
| -const struct clkops clk_cpu_ops = { |
139 |
| - .enable = clk_cpu_enable, |
140 |
| - .disable = clk_cpu_disable, |
141 |
| - .get_rate = clk_cpu_get_rate, |
142 |
| -}; |
| 102 | + clk_hw_register_clkdev(hw, NULL, "sa1100-rtc"); |
143 | 103 |
|
144 |
| -static DEFINE_CLK(gpio27, &clk_gpio27_ops); |
| 104 | + hw = clk_hw_register_fixed_rate(NULL, "clk3686400", NULL, 0, 3686400); |
| 105 | + if (IS_ERR(hw)) |
| 106 | + return PTR_ERR(hw); |
145 | 107 |
|
146 |
| -static DEFINE_CLK(cpu, &clk_cpu_ops); |
| 108 | + clk_hw_register_clkdev(hw, "OSTIMER0", NULL); |
147 | 109 |
|
148 |
| -static unsigned long clk_36864_get_rate(struct clk *clk) |
149 |
| -{ |
150 |
| - return 3686400; |
151 |
| -} |
| 110 | + hw = kzalloc(sizeof(*hw), GFP_KERNEL); |
| 111 | + if (!hw) |
| 112 | + return -ENOMEM; |
| 113 | + hw->init = &clk_mpll_init_data; |
| 114 | + ret = clk_hw_register(NULL, hw); |
| 115 | + if (ret) { |
| 116 | + kfree(hw); |
| 117 | + return ret; |
| 118 | + } |
152 | 119 |
|
153 |
| -static struct clkops clk_36864_ops = { |
154 |
| - .enable = clk_cpu_enable, |
155 |
| - .disable = clk_cpu_disable, |
156 |
| - .get_rate = clk_36864_get_rate, |
157 |
| -}; |
| 120 | + clk_hw_register_clkdev(hw, NULL, "sa11x0-fb"); |
| 121 | + clk_hw_register_clkdev(hw, NULL, "sa11x0-pcmcia"); |
| 122 | + clk_hw_register_clkdev(hw, NULL, "sa11x0-pcmcia.0"); |
| 123 | + clk_hw_register_clkdev(hw, NULL, "sa11x0-pcmcia.1"); |
| 124 | + clk_hw_register_clkdev(hw, NULL, "1800"); |
| 125 | + |
| 126 | + hw = clk_hw_register_mux(NULL, "tucr-mux", clk_tucr_parents, |
| 127 | + ARRAY_SIZE(clk_tucr_parents), 0, |
| 128 | + (void __iomem *)&TUCR, FShft(TUCR_TSEL), |
| 129 | + FAlnMsk(TUCR_TSEL), 0, &tucr_lock); |
| 130 | + clk_set_rate(hw->clk, 3686400); |
| 131 | + |
| 132 | + hw = kzalloc(sizeof(*hw), GFP_KERNEL); |
| 133 | + if (!hw) |
| 134 | + return -ENOMEM; |
| 135 | + hw->init = &clk_gpio27_init_data; |
| 136 | + ret = clk_hw_register(NULL, hw); |
| 137 | + if (ret) { |
| 138 | + kfree(hw); |
| 139 | + return ret; |
| 140 | + } |
158 | 141 |
|
159 |
| -static DEFINE_CLK(36864, &clk_36864_ops); |
160 |
| - |
161 |
| -static struct clk_lookup sa11xx_clkregs[] = { |
162 |
| - CLKDEV_INIT("sa1111.0", NULL, &clk_gpio27), |
163 |
| - CLKDEV_INIT("sa1100-rtc", NULL, NULL), |
164 |
| - CLKDEV_INIT("sa11x0-fb", NULL, &clk_cpu), |
165 |
| - CLKDEV_INIT("sa11x0-pcmcia", NULL, &clk_cpu), |
166 |
| - CLKDEV_INIT("sa11x0-pcmcia.0", NULL, &clk_cpu), |
167 |
| - CLKDEV_INIT("sa11x0-pcmcia.1", NULL, &clk_cpu), |
168 |
| - /* sa1111 names devices using internal offsets, PCMCIA is at 0x1800 */ |
169 |
| - CLKDEV_INIT("1800", NULL, &clk_cpu), |
170 |
| - CLKDEV_INIT(NULL, "OSTIMER0", &clk_36864), |
171 |
| -}; |
| 142 | + clk_hw_register_clkdev(hw, NULL, "sa1111.0"); |
172 | 143 |
|
173 |
| -int __init sa11xx_clk_init(void) |
174 |
| -{ |
175 |
| - clkdev_add_table(sa11xx_clkregs, ARRAY_SIZE(sa11xx_clkregs)); |
176 | 144 | return 0;
|
177 | 145 | }
|
0 commit comments