1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/clk-provider.h>
19#include <linux/slab.h>
20#include <linux/io.h>
21#include <linux/of.h>
22#include <linux/of_address.h>
23#include <linux/clk/ti.h>
24
25#include "clock.h"
26
27struct clk_ti_autoidle {
28 struct clk_omap_reg reg;
29 u8 shift;
30 u8 flags;
31 const char *name;
32 struct list_head node;
33};
34
35#define AUTOIDLE_LOW 0x1
36
37static LIST_HEAD(autoidle_clks);
38static LIST_HEAD(clk_hw_omap_clocks);
39
40
41
42
43
44
45
46int omap2_clk_deny_idle(struct clk *clk)
47{
48 struct clk_hw_omap *c;
49
50 c = to_clk_hw_omap(__clk_get_hw(clk));
51 if (c->ops && c->ops->deny_idle)
52 c->ops->deny_idle(c);
53 return 0;
54}
55
56
57
58
59
60
61
62int omap2_clk_allow_idle(struct clk *clk)
63{
64 struct clk_hw_omap *c;
65
66 c = to_clk_hw_omap(__clk_get_hw(clk));
67 if (c->ops && c->ops->allow_idle)
68 c->ops->allow_idle(c);
69 return 0;
70}
71
72static void _allow_autoidle(struct clk_ti_autoidle *clk)
73{
74 u32 val;
75
76 val = ti_clk_ll_ops->clk_readl(&clk->reg);
77
78 if (clk->flags & AUTOIDLE_LOW)
79 val &= ~(1 << clk->shift);
80 else
81 val |= (1 << clk->shift);
82
83 ti_clk_ll_ops->clk_writel(val, &clk->reg);
84}
85
86static void _deny_autoidle(struct clk_ti_autoidle *clk)
87{
88 u32 val;
89
90 val = ti_clk_ll_ops->clk_readl(&clk->reg);
91
92 if (clk->flags & AUTOIDLE_LOW)
93 val |= (1 << clk->shift);
94 else
95 val &= ~(1 << clk->shift);
96
97 ti_clk_ll_ops->clk_writel(val, &clk->reg);
98}
99
100
101
102
103
104
105
106static void _clk_generic_allow_autoidle_all(void)
107{
108 struct clk_ti_autoidle *c;
109
110 list_for_each_entry(c, &autoidle_clks, node)
111 _allow_autoidle(c);
112}
113
114
115
116
117
118
119
120static void _clk_generic_deny_autoidle_all(void)
121{
122 struct clk_ti_autoidle *c;
123
124 list_for_each_entry(c, &autoidle_clks, node)
125 _deny_autoidle(c);
126}
127
128
129
130
131
132
133
134
135
136
137
138
139int __init of_ti_clk_autoidle_setup(struct device_node *node)
140{
141 u32 shift;
142 struct clk_ti_autoidle *clk;
143 int ret;
144
145
146 if (of_property_read_u32(node, "ti,autoidle-shift", &shift))
147 return 0;
148
149 clk = kzalloc(sizeof(*clk), GFP_KERNEL);
150
151 if (!clk)
152 return -ENOMEM;
153
154 clk->shift = shift;
155 clk->name = node->name;
156 ret = ti_clk_get_reg_addr(node, 0, &clk->reg);
157 if (ret) {
158 kfree(clk);
159 return ret;
160 }
161
162 if (of_property_read_bool(node, "ti,invert-autoidle-bit"))
163 clk->flags |= AUTOIDLE_LOW;
164
165 list_add(&clk->node, &autoidle_clks);
166
167 return 0;
168}
169
170
171
172
173
174
175
176
177
178
179void omap2_init_clk_hw_omap_clocks(struct clk_hw *hw)
180{
181 struct clk_hw_omap *c;
182
183 if (clk_hw_get_flags(hw) & CLK_IS_BASIC)
184 return;
185
186 c = to_clk_hw_omap(hw);
187 list_add(&c->node, &clk_hw_omap_clocks);
188}
189
190
191
192
193
194
195
196
197
198
199int omap2_clk_enable_autoidle_all(void)
200{
201 struct clk_hw_omap *c;
202
203 list_for_each_entry(c, &clk_hw_omap_clocks, node)
204 if (c->ops && c->ops->allow_idle)
205 c->ops->allow_idle(c);
206
207 _clk_generic_allow_autoidle_all();
208
209 return 0;
210}
211
212
213
214
215
216
217
218
219
220
221int omap2_clk_disable_autoidle_all(void)
222{
223 struct clk_hw_omap *c;
224
225 list_for_each_entry(c, &clk_hw_omap_clocks, node)
226 if (c->ops && c->ops->deny_idle)
227 c->ops->deny_idle(c);
228
229 _clk_generic_deny_autoidle_all();
230
231 return 0;
232}
233