initial commit with v3.6.7
[linux-3.6.7-moxart.git] / arch / arm / mach-omap2 / clockdomain2xxx_3xxx.c
blobf99e65cfb86223c77ed544d1a8fbe6a0c4ad4b51
1 /*
2 * OMAP2 and OMAP3 clockdomain control
4 * Copyright (C) 2008-2010 Texas Instruments, Inc.
5 * Copyright (C) 2008-2010 Nokia Corporation
7 * Derived from mach-omap2/clockdomain.c written by Paul Walmsley
8 * Rajendra Nayak <rnayak@ti.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/types.h>
16 #include <plat/prcm.h>
17 #include "prm.h"
18 #include "prm2xxx_3xxx.h"
19 #include "cm.h"
20 #include "cm2xxx_3xxx.h"
21 #include "cm-regbits-24xx.h"
22 #include "cm-regbits-34xx.h"
23 #include "prm-regbits-24xx.h"
24 #include "clockdomain.h"
26 static int omap2_clkdm_add_wkdep(struct clockdomain *clkdm1,
27 struct clockdomain *clkdm2)
29 omap2_prm_set_mod_reg_bits((1 << clkdm2->dep_bit),
30 clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP);
31 return 0;
34 static int omap2_clkdm_del_wkdep(struct clockdomain *clkdm1,
35 struct clockdomain *clkdm2)
37 omap2_prm_clear_mod_reg_bits((1 << clkdm2->dep_bit),
38 clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP);
39 return 0;
42 static int omap2_clkdm_read_wkdep(struct clockdomain *clkdm1,
43 struct clockdomain *clkdm2)
45 return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs,
46 PM_WKDEP, (1 << clkdm2->dep_bit));
49 static int omap2_clkdm_clear_all_wkdeps(struct clockdomain *clkdm)
51 struct clkdm_dep *cd;
52 u32 mask = 0;
54 for (cd = clkdm->wkdep_srcs; cd && cd->clkdm_name; cd++) {
55 if (!cd->clkdm)
56 continue; /* only happens if data is erroneous */
58 /* PRM accesses are slow, so minimize them */
59 mask |= 1 << cd->clkdm->dep_bit;
60 atomic_set(&cd->wkdep_usecount, 0);
63 omap2_prm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs,
64 PM_WKDEP);
65 return 0;
68 static int omap3_clkdm_add_sleepdep(struct clockdomain *clkdm1,
69 struct clockdomain *clkdm2)
71 omap2_cm_set_mod_reg_bits((1 << clkdm2->dep_bit),
72 clkdm1->pwrdm.ptr->prcm_offs,
73 OMAP3430_CM_SLEEPDEP);
74 return 0;
77 static int omap3_clkdm_del_sleepdep(struct clockdomain *clkdm1,
78 struct clockdomain *clkdm2)
80 omap2_cm_clear_mod_reg_bits((1 << clkdm2->dep_bit),
81 clkdm1->pwrdm.ptr->prcm_offs,
82 OMAP3430_CM_SLEEPDEP);
83 return 0;
86 static int omap3_clkdm_read_sleepdep(struct clockdomain *clkdm1,
87 struct clockdomain *clkdm2)
89 return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs,
90 OMAP3430_CM_SLEEPDEP, (1 << clkdm2->dep_bit));
93 static int omap3_clkdm_clear_all_sleepdeps(struct clockdomain *clkdm)
95 struct clkdm_dep *cd;
96 u32 mask = 0;
98 for (cd = clkdm->sleepdep_srcs; cd && cd->clkdm_name; cd++) {
99 if (!cd->clkdm)
100 continue; /* only happens if data is erroneous */
102 /* PRM accesses are slow, so minimize them */
103 mask |= 1 << cd->clkdm->dep_bit;
104 atomic_set(&cd->sleepdep_usecount, 0);
106 omap2_prm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs,
107 OMAP3430_CM_SLEEPDEP);
108 return 0;
111 static int omap2_clkdm_sleep(struct clockdomain *clkdm)
113 omap2_cm_set_mod_reg_bits(OMAP24XX_FORCESTATE_MASK,
114 clkdm->pwrdm.ptr->prcm_offs,
115 OMAP2_PM_PWSTCTRL);
116 return 0;
119 static int omap2_clkdm_wakeup(struct clockdomain *clkdm)
121 omap2_cm_clear_mod_reg_bits(OMAP24XX_FORCESTATE_MASK,
122 clkdm->pwrdm.ptr->prcm_offs,
123 OMAP2_PM_PWSTCTRL);
124 return 0;
127 static void omap2_clkdm_allow_idle(struct clockdomain *clkdm)
129 if (atomic_read(&clkdm->usecount) > 0)
130 _clkdm_add_autodeps(clkdm);
132 omap2xxx_cm_clkdm_enable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
133 clkdm->clktrctrl_mask);
136 static void omap2_clkdm_deny_idle(struct clockdomain *clkdm)
138 omap2xxx_cm_clkdm_disable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
139 clkdm->clktrctrl_mask);
141 if (atomic_read(&clkdm->usecount) > 0)
142 _clkdm_del_autodeps(clkdm);
145 static void _enable_hwsup(struct clockdomain *clkdm)
147 if (cpu_is_omap24xx())
148 omap2xxx_cm_clkdm_enable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
149 clkdm->clktrctrl_mask);
150 else if (cpu_is_omap34xx())
151 omap3xxx_cm_clkdm_enable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
152 clkdm->clktrctrl_mask);
155 static void _disable_hwsup(struct clockdomain *clkdm)
157 if (cpu_is_omap24xx())
158 omap2xxx_cm_clkdm_disable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
159 clkdm->clktrctrl_mask);
160 else if (cpu_is_omap34xx())
161 omap3xxx_cm_clkdm_disable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
162 clkdm->clktrctrl_mask);
166 static int omap2_clkdm_clk_enable(struct clockdomain *clkdm)
168 bool hwsup = false;
170 if (!clkdm->clktrctrl_mask)
171 return 0;
173 hwsup = omap2_cm_is_clkdm_in_hwsup(clkdm->pwrdm.ptr->prcm_offs,
174 clkdm->clktrctrl_mask);
176 if (hwsup) {
177 /* Disable HW transitions when we are changing deps */
178 _disable_hwsup(clkdm);
179 _clkdm_add_autodeps(clkdm);
180 _enable_hwsup(clkdm);
181 } else {
182 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
183 omap2_clkdm_wakeup(clkdm);
186 return 0;
189 static int omap2_clkdm_clk_disable(struct clockdomain *clkdm)
191 bool hwsup = false;
193 if (!clkdm->clktrctrl_mask)
194 return 0;
196 hwsup = omap2_cm_is_clkdm_in_hwsup(clkdm->pwrdm.ptr->prcm_offs,
197 clkdm->clktrctrl_mask);
199 if (hwsup) {
200 /* Disable HW transitions when we are changing deps */
201 _disable_hwsup(clkdm);
202 _clkdm_del_autodeps(clkdm);
203 _enable_hwsup(clkdm);
204 } else {
205 if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP)
206 omap2_clkdm_sleep(clkdm);
209 return 0;
212 static int omap3_clkdm_sleep(struct clockdomain *clkdm)
214 omap3xxx_cm_clkdm_force_sleep(clkdm->pwrdm.ptr->prcm_offs,
215 clkdm->clktrctrl_mask);
216 return 0;
219 static int omap3_clkdm_wakeup(struct clockdomain *clkdm)
221 omap3xxx_cm_clkdm_force_wakeup(clkdm->pwrdm.ptr->prcm_offs,
222 clkdm->clktrctrl_mask);
223 return 0;
226 static void omap3_clkdm_allow_idle(struct clockdomain *clkdm)
228 if (atomic_read(&clkdm->usecount) > 0)
229 _clkdm_add_autodeps(clkdm);
231 omap3xxx_cm_clkdm_enable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
232 clkdm->clktrctrl_mask);
235 static void omap3_clkdm_deny_idle(struct clockdomain *clkdm)
237 omap3xxx_cm_clkdm_disable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
238 clkdm->clktrctrl_mask);
240 if (atomic_read(&clkdm->usecount) > 0)
241 _clkdm_del_autodeps(clkdm);
244 static int omap3xxx_clkdm_clk_enable(struct clockdomain *clkdm)
246 bool hwsup = false;
248 if (!clkdm->clktrctrl_mask)
249 return 0;
251 hwsup = omap2_cm_is_clkdm_in_hwsup(clkdm->pwrdm.ptr->prcm_offs,
252 clkdm->clktrctrl_mask);
254 if (hwsup) {
255 /* Disable HW transitions when we are changing deps */
256 _disable_hwsup(clkdm);
257 _clkdm_add_autodeps(clkdm);
258 _enable_hwsup(clkdm);
259 } else {
260 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
261 omap3_clkdm_wakeup(clkdm);
264 return 0;
267 static int omap3xxx_clkdm_clk_disable(struct clockdomain *clkdm)
269 bool hwsup = false;
271 if (!clkdm->clktrctrl_mask)
272 return 0;
274 hwsup = omap2_cm_is_clkdm_in_hwsup(clkdm->pwrdm.ptr->prcm_offs,
275 clkdm->clktrctrl_mask);
277 if (hwsup) {
278 /* Disable HW transitions when we are changing deps */
279 _disable_hwsup(clkdm);
280 _clkdm_del_autodeps(clkdm);
281 _enable_hwsup(clkdm);
282 } else {
283 if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP)
284 omap3_clkdm_sleep(clkdm);
287 return 0;
290 struct clkdm_ops omap2_clkdm_operations = {
291 .clkdm_add_wkdep = omap2_clkdm_add_wkdep,
292 .clkdm_del_wkdep = omap2_clkdm_del_wkdep,
293 .clkdm_read_wkdep = omap2_clkdm_read_wkdep,
294 .clkdm_clear_all_wkdeps = omap2_clkdm_clear_all_wkdeps,
295 .clkdm_sleep = omap2_clkdm_sleep,
296 .clkdm_wakeup = omap2_clkdm_wakeup,
297 .clkdm_allow_idle = omap2_clkdm_allow_idle,
298 .clkdm_deny_idle = omap2_clkdm_deny_idle,
299 .clkdm_clk_enable = omap2_clkdm_clk_enable,
300 .clkdm_clk_disable = omap2_clkdm_clk_disable,
303 struct clkdm_ops omap3_clkdm_operations = {
304 .clkdm_add_wkdep = omap2_clkdm_add_wkdep,
305 .clkdm_del_wkdep = omap2_clkdm_del_wkdep,
306 .clkdm_read_wkdep = omap2_clkdm_read_wkdep,
307 .clkdm_clear_all_wkdeps = omap2_clkdm_clear_all_wkdeps,
308 .clkdm_add_sleepdep = omap3_clkdm_add_sleepdep,
309 .clkdm_del_sleepdep = omap3_clkdm_del_sleepdep,
310 .clkdm_read_sleepdep = omap3_clkdm_read_sleepdep,
311 .clkdm_clear_all_sleepdeps = omap3_clkdm_clear_all_sleepdeps,
312 .clkdm_sleep = omap3_clkdm_sleep,
313 .clkdm_wakeup = omap3_clkdm_wakeup,
314 .clkdm_allow_idle = omap3_clkdm_allow_idle,
315 .clkdm_deny_idle = omap3_clkdm_deny_idle,
316 .clkdm_clk_enable = omap3xxx_clkdm_clk_enable,
317 .clkdm_clk_disable = omap3xxx_clkdm_clk_disable,