blob: f70b06ae866451d607de4c4757dd559e99768257 [file] [log] [blame]
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001/*
Abhijit Pagare8a3ddc72010-01-26 20:12:54 -07002 * OMAP2/3/4 clockdomain framework functions
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03003 *
Abhijit Pagare91808a82010-02-22 22:09:07 -07004 * Copyright (C) 2008-2010 Texas Instruments, Inc.
5 * Copyright (C) 2008-2010 Nokia Corporation
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03006 *
7 * Written by Paul Walmsley and Jouni Högander
Abhijit Pagare8a3ddc72010-01-26 20:12:54 -07008 * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com>
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03009 *
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.
13 */
Paul Walmsley33903eb2009-12-08 16:33:10 -070014#undef DEBUG
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030015
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030016#include <linux/kernel.h>
17#include <linux/device.h>
18#include <linux/list.h>
19#include <linux/errno.h>
20#include <linux/delay.h>
21#include <linux/clk.h>
22#include <linux/limits.h>
Paul Walmsley5b74c672009-02-03 02:10:03 -070023#include <linux/err.h>
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030024
25#include <linux/io.h>
26
27#include <linux/bitops.h>
28
Paul Walmsley59fb6592010-12-21 15:30:55 -070029#include "prm2xxx_3xxx.h"
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030030#include "prm-regbits-24xx.h"
Paul Walmsley59fb6592010-12-21 15:30:55 -070031#include "cm2xxx_3xxx.h"
Paul Walmsley55ae3502010-12-21 21:05:15 -070032#include "cm-regbits-24xx.h"
Paul Walmsleybd2122c2010-12-21 21:05:15 -070033#include "cminst44xx.h"
34#include "prcm44xx.h"
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030035
Paul Walmsley55ed9692010-01-26 20:12:59 -070036#include <plat/clock.h>
Paul Walmsley72e06d02010-12-21 21:05:16 -070037#include "powerdomain.h"
Paul Walmsley1540f2142010-12-21 21:05:15 -070038#include "clockdomain.h"
Paul Walmsley55ed9692010-01-26 20:12:59 -070039#include <plat/prcm.h>
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030040
41/* clkdm_list contains all registered struct clockdomains */
42static LIST_HEAD(clkdm_list);
43
Paul Walmsley55ed9692010-01-26 20:12:59 -070044/* array of clockdomain deps to be added/removed when clkdm in hwsup mode */
45static struct clkdm_autodep *autodeps;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030046
Rajendra Nayak32d40342011-02-25 16:06:47 -070047static struct clkdm_ops *arch_clkdm;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +030048
49/* Private functions */
50
Paul Walmsley55ed9692010-01-26 20:12:59 -070051static struct clockdomain *_clkdm_lookup(const char *name)
52{
53 struct clockdomain *clkdm, *temp_clkdm;
54
55 if (!name)
56 return NULL;
57
58 clkdm = NULL;
59
60 list_for_each_entry(temp_clkdm, &clkdm_list, node) {
61 if (!strcmp(name, temp_clkdm->name)) {
62 clkdm = temp_clkdm;
63 break;
64 }
65 }
66
67 return clkdm;
68}
69
Paul Walmsleye909d622010-01-26 20:13:00 -070070/**
71 * _clkdm_register - register a clockdomain
72 * @clkdm: struct clockdomain * to register
73 *
74 * Adds a clockdomain to the internal clockdomain list.
75 * Returns -EINVAL if given a null pointer, -EEXIST if a clockdomain is
76 * already registered by the provided name, or 0 upon success.
77 */
78static int _clkdm_register(struct clockdomain *clkdm)
79{
80 struct powerdomain *pwrdm;
81
82 if (!clkdm || !clkdm->name)
83 return -EINVAL;
84
85 if (!omap_chip_is(clkdm->omap_chip))
86 return -EINVAL;
87
88 pwrdm = pwrdm_lookup(clkdm->pwrdm.name);
89 if (!pwrdm) {
90 pr_err("clockdomain: %s: powerdomain %s does not exist\n",
91 clkdm->name, clkdm->pwrdm.name);
92 return -EINVAL;
93 }
94 clkdm->pwrdm.ptr = pwrdm;
95
96 /* Verify that the clockdomain is not already registered */
97 if (_clkdm_lookup(clkdm->name))
98 return -EEXIST;
99
100 list_add(&clkdm->node, &clkdm_list);
101
102 pwrdm_add_clkdm(pwrdm, clkdm);
103
104 pr_debug("clockdomain: registered %s\n", clkdm->name);
105
106 return 0;
107}
108
Paul Walmsley55ed9692010-01-26 20:12:59 -0700109/* _clkdm_deps_lookup - look up the specified clockdomain in a clkdm list */
110static struct clkdm_dep *_clkdm_deps_lookup(struct clockdomain *clkdm,
111 struct clkdm_dep *deps)
112{
113 struct clkdm_dep *cd;
114
115 if (!clkdm || !deps || !omap_chip_is(clkdm->omap_chip))
116 return ERR_PTR(-EINVAL);
117
118 for (cd = deps; cd->clkdm_name; cd++) {
Paul Walmsley55ed9692010-01-26 20:12:59 -0700119 if (!omap_chip_is(cd->omap_chip))
120 continue;
121
122 if (!cd->clkdm && cd->clkdm_name)
123 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
124
125 if (cd->clkdm == clkdm)
126 break;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700127 }
128
129 if (!cd->clkdm_name)
130 return ERR_PTR(-ENOENT);
131
132 return cd;
133}
134
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300135/*
Paul Walmsley55ed9692010-01-26 20:12:59 -0700136 * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store
137 * @autodep: struct clkdm_autodep * to resolve
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300138 *
Paul Walmsley55ed9692010-01-26 20:12:59 -0700139 * Resolve autodep clockdomain names to clockdomain pointers via
140 * clkdm_lookup() and store the pointers in the autodep structure. An
141 * "autodep" is a clockdomain sleep/wakeup dependency that is
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300142 * automatically added and removed whenever clocks in the associated
143 * clockdomain are enabled or disabled (respectively) when the
144 * clockdomain is in hardware-supervised mode. Meant to be called
145 * once at clockdomain layer initialization, since these should remain
146 * fixed for a particular architecture. No return value.
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700147 *
148 * XXX autodeps are deprecated and should be removed at the earliest
149 * opportunity
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300150 */
Paul Walmsley55ed9692010-01-26 20:12:59 -0700151static void _autodep_lookup(struct clkdm_autodep *autodep)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300152{
Paul Walmsley55ed9692010-01-26 20:12:59 -0700153 struct clockdomain *clkdm;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300154
155 if (!autodep)
156 return;
157
158 if (!omap_chip_is(autodep->omap_chip))
159 return;
160
Paul Walmsley55ed9692010-01-26 20:12:59 -0700161 clkdm = clkdm_lookup(autodep->clkdm.name);
162 if (!clkdm) {
163 pr_err("clockdomain: autodeps: clockdomain %s does not exist\n",
164 autodep->clkdm.name);
165 clkdm = ERR_PTR(-ENOENT);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300166 }
Paul Walmsley55ed9692010-01-26 20:12:59 -0700167 autodep->clkdm.ptr = clkdm;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300168}
169
170/*
171 * _clkdm_add_autodeps - add auto sleepdeps/wkdeps to clkdm upon clock enable
172 * @clkdm: struct clockdomain *
173 *
174 * Add the "autodep" sleep & wakeup dependencies to clockdomain 'clkdm'
175 * in hardware-supervised mode. Meant to be called from clock framework
176 * when a clock inside clockdomain 'clkdm' is enabled. No return value.
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700177 *
178 * XXX autodeps are deprecated and should be removed at the earliest
179 * opportunity
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300180 */
181static void _clkdm_add_autodeps(struct clockdomain *clkdm)
182{
Paul Walmsley55ed9692010-01-26 20:12:59 -0700183 struct clkdm_autodep *autodep;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300184
Paul Walmsleyad956162010-02-22 22:09:35 -0700185 if (!autodeps)
186 return;
187
Paul Walmsley55ed9692010-01-26 20:12:59 -0700188 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
189 if (IS_ERR(autodep->clkdm.ptr))
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300190 continue;
191
Paul Walmsleyd96df002009-01-27 19:44:35 -0700192 if (!omap_chip_is(autodep->omap_chip))
193 continue;
194
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300195 pr_debug("clockdomain: adding %s sleepdep/wkdep for "
Paul Walmsley55ed9692010-01-26 20:12:59 -0700196 "clkdm %s\n", autodep->clkdm.ptr->name,
197 clkdm->name);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300198
Paul Walmsley55ed9692010-01-26 20:12:59 -0700199 clkdm_add_sleepdep(clkdm, autodep->clkdm.ptr);
200 clkdm_add_wkdep(clkdm, autodep->clkdm.ptr);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300201 }
202}
203
204/*
205 * _clkdm_add_autodeps - remove auto sleepdeps/wkdeps from clkdm
206 * @clkdm: struct clockdomain *
207 *
208 * Remove the "autodep" sleep & wakeup dependencies from clockdomain 'clkdm'
209 * in hardware-supervised mode. Meant to be called from clock framework
210 * when a clock inside clockdomain 'clkdm' is disabled. No return value.
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700211 *
212 * XXX autodeps are deprecated and should be removed at the earliest
213 * opportunity
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300214 */
215static void _clkdm_del_autodeps(struct clockdomain *clkdm)
216{
Paul Walmsley55ed9692010-01-26 20:12:59 -0700217 struct clkdm_autodep *autodep;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300218
Paul Walmsleyad956162010-02-22 22:09:35 -0700219 if (!autodeps)
220 return;
221
Paul Walmsley55ed9692010-01-26 20:12:59 -0700222 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
223 if (IS_ERR(autodep->clkdm.ptr))
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300224 continue;
225
Paul Walmsleyd96df002009-01-27 19:44:35 -0700226 if (!omap_chip_is(autodep->omap_chip))
227 continue;
228
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300229 pr_debug("clockdomain: removing %s sleepdep/wkdep for "
Paul Walmsley55ed9692010-01-26 20:12:59 -0700230 "clkdm %s\n", autodep->clkdm.ptr->name,
231 clkdm->name);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300232
Paul Walmsley55ed9692010-01-26 20:12:59 -0700233 clkdm_del_sleepdep(clkdm, autodep->clkdm.ptr);
234 clkdm_del_wkdep(clkdm, autodep->clkdm.ptr);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300235 }
236}
237
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700238/**
239 * _enable_hwsup - place a clockdomain into hardware-supervised idle
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600240 * @clkdm: struct clockdomain *
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600241 *
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700242 * Place the clockdomain into hardware-supervised idle mode. No return
243 * value.
244 *
245 * XXX Should this return an error if the clockdomain does not support
246 * hardware-supervised idle mode?
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600247 */
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700248static void _enable_hwsup(struct clockdomain *clkdm)
249{
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700250 if (cpu_is_omap24xx())
Paul Walmsley55ae3502010-12-21 21:05:15 -0700251 omap2xxx_cm_clkdm_enable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
252 clkdm->clktrctrl_mask);
Paul Walmsleybd2122c2010-12-21 21:05:15 -0700253 else if (cpu_is_omap34xx())
Paul Walmsley55ae3502010-12-21 21:05:15 -0700254 omap3xxx_cm_clkdm_enable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
255 clkdm->clktrctrl_mask);
Paul Walmsleybd2122c2010-12-21 21:05:15 -0700256 else if (cpu_is_omap44xx())
257 return omap4_cminst_clkdm_enable_hwsup(clkdm->prcm_partition,
258 clkdm->cm_inst,
259 clkdm->clkdm_offs);
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700260 else
261 BUG();
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700262}
263
264/**
265 * _disable_hwsup - place a clockdomain into software-supervised idle
266 * @clkdm: struct clockdomain *
267 *
268 * Place the clockdomain @clkdm into software-supervised idle mode.
269 * No return value.
270 *
271 * XXX Should this return an error if the clockdomain does not support
272 * software-supervised idle mode?
273 */
274static void _disable_hwsup(struct clockdomain *clkdm)
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600275{
Paul Walmsleybd2122c2010-12-21 21:05:15 -0700276 if (cpu_is_omap24xx())
Paul Walmsley55ae3502010-12-21 21:05:15 -0700277 omap2xxx_cm_clkdm_disable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
278 clkdm->clktrctrl_mask);
Paul Walmsleybd2122c2010-12-21 21:05:15 -0700279 else if (cpu_is_omap34xx())
Paul Walmsley55ae3502010-12-21 21:05:15 -0700280 omap3xxx_cm_clkdm_disable_hwsup(clkdm->pwrdm.ptr->prcm_offs,
281 clkdm->clktrctrl_mask);
Paul Walmsleybd2122c2010-12-21 21:05:15 -0700282 else if (cpu_is_omap44xx())
283 return omap4_cminst_clkdm_disable_hwsup(clkdm->prcm_partition,
284 clkdm->cm_inst,
285 clkdm->clkdm_offs);
286 else
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600287 BUG();
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600288}
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300289
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300290/* Public functions */
291
292/**
293 * clkdm_init - set up the clockdomain layer
294 * @clkdms: optional pointer to an array of clockdomains to register
295 * @init_autodeps: optional pointer to an array of autodeps to register
Rajendra Nayak32d40342011-02-25 16:06:47 -0700296 * @custom_funcs: func pointers for arch specfic implementations
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300297 *
298 * Set up internal state. If a pointer to an array of clockdomains
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700299 * @clkdms was supplied, loop through the list of clockdomains,
300 * register all that are available on the current platform. Similarly,
301 * if a pointer to an array of clockdomain autodependencies
302 * @init_autodeps was provided, register those. No return value.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300303 */
304void clkdm_init(struct clockdomain **clkdms,
Rajendra Nayak32d40342011-02-25 16:06:47 -0700305 struct clkdm_autodep *init_autodeps,
306 struct clkdm_ops *custom_funcs)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300307{
308 struct clockdomain **c = NULL;
Paul Walmsley369d5612010-01-26 20:13:01 -0700309 struct clockdomain *clkdm;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700310 struct clkdm_autodep *autodep = NULL;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300311
Rajendra Nayak32d40342011-02-25 16:06:47 -0700312 if (!custom_funcs)
313 WARN(1, "No custom clkdm functions registered\n");
314 else
315 arch_clkdm = custom_funcs;
316
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300317 if (clkdms)
318 for (c = clkdms; *c; c++)
Paul Walmsleye909d622010-01-26 20:13:00 -0700319 _clkdm_register(*c);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300320
Paul Walmsley55ed9692010-01-26 20:12:59 -0700321 autodeps = init_autodeps;
322 if (autodeps)
323 for (autodep = autodeps; autodep->clkdm.ptr; autodep++)
324 _autodep_lookup(autodep);
Paul Walmsley369d5612010-01-26 20:13:01 -0700325
326 /*
Paul Walmsley6f7f63c2010-09-14 15:56:53 -0600327 * Put all clockdomains into software-supervised mode; PM code
328 * should later enable hardware-supervised mode as appropriate
Paul Walmsley369d5612010-01-26 20:13:01 -0700329 */
330 list_for_each_entry(clkdm, &clkdm_list, node) {
Paul Walmsley6f7f63c2010-09-14 15:56:53 -0600331 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
332 omap2_clkdm_wakeup(clkdm);
333 else if (clkdm->flags & CLKDM_CAN_DISABLE_AUTO)
334 omap2_clkdm_deny_idle(clkdm);
335
336 clkdm_clear_all_wkdeps(clkdm);
337 clkdm_clear_all_sleepdeps(clkdm);
Paul Walmsley369d5612010-01-26 20:13:01 -0700338 }
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300339}
340
341/**
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300342 * clkdm_lookup - look up a clockdomain by name, return a pointer
343 * @name: name of clockdomain
344 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700345 * Find a registered clockdomain by its name @name. Returns a pointer
346 * to the struct clockdomain if found, or NULL otherwise.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300347 */
348struct clockdomain *clkdm_lookup(const char *name)
349{
350 struct clockdomain *clkdm, *temp_clkdm;
351
352 if (!name)
353 return NULL;
354
355 clkdm = NULL;
356
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300357 list_for_each_entry(temp_clkdm, &clkdm_list, node) {
358 if (!strcmp(name, temp_clkdm->name)) {
359 clkdm = temp_clkdm;
360 break;
361 }
362 }
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300363
364 return clkdm;
365}
366
367/**
368 * clkdm_for_each - call function on each registered clockdomain
369 * @fn: callback function *
370 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700371 * Call the supplied function @fn for each registered clockdomain.
372 * The callback function @fn can return anything but 0 to bail
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300373 * out early from the iterator. The callback function is called with
374 * the clkdm_mutex held, so no clockdomain structure manipulation
375 * functions should be called from the callback, although hardware
376 * clockdomain control functions are fine. Returns the last return
377 * value of the callback function, which should be 0 for success or
378 * anything else to indicate failure; or -EINVAL if the function pointer
379 * is null.
380 */
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300381int clkdm_for_each(int (*fn)(struct clockdomain *clkdm, void *user),
382 void *user)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300383{
384 struct clockdomain *clkdm;
385 int ret = 0;
386
387 if (!fn)
388 return -EINVAL;
389
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300390 list_for_each_entry(clkdm, &clkdm_list, node) {
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300391 ret = (*fn)(clkdm, user);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300392 if (ret)
393 break;
394 }
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300395
396 return ret;
397}
398
399
Paul Walmsleye89087c2008-05-20 18:41:35 -0600400/**
401 * clkdm_get_pwrdm - return a ptr to the pwrdm that this clkdm resides in
402 * @clkdm: struct clockdomain *
403 *
404 * Return a pointer to the struct powerdomain that the specified clockdomain
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700405 * @clkdm exists in, or returns NULL if @clkdm is NULL.
Paul Walmsleye89087c2008-05-20 18:41:35 -0600406 */
407struct powerdomain *clkdm_get_pwrdm(struct clockdomain *clkdm)
408{
409 if (!clkdm)
410 return NULL;
411
Paul Walmsley5b74c672009-02-03 02:10:03 -0700412 return clkdm->pwrdm.ptr;
Paul Walmsleye89087c2008-05-20 18:41:35 -0600413}
414
415
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300416/* Hardware clockdomain control */
417
418/**
Paul Walmsley55ed9692010-01-26 20:12:59 -0700419 * clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1
420 * @clkdm1: wake this struct clockdomain * up (dependent)
421 * @clkdm2: when this struct clockdomain * wakes up (source)
422 *
423 * When the clockdomain represented by @clkdm2 wakes up, wake up
424 * @clkdm1. Implemented in hardware on the OMAP, this feature is
425 * designed to reduce wakeup latency of the dependent clockdomain @clkdm1.
426 * Returns -EINVAL if presented with invalid clockdomain pointers,
427 * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon
428 * success.
429 */
430int clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
431{
432 struct clkdm_dep *cd;
433
Paul Walmsley56bc78d2011-01-17 13:28:17 -0700434 if (!cpu_is_omap24xx() && !cpu_is_omap34xx()) {
435 pr_err("clockdomain: %s/%s: %s: not yet implemented\n",
436 clkdm1->name, clkdm2->name, __func__);
437 return -EINVAL;
438 }
439
Paul Walmsley55ed9692010-01-26 20:12:59 -0700440 if (!clkdm1 || !clkdm2)
441 return -EINVAL;
442
443 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
444 if (IS_ERR(cd)) {
445 pr_debug("clockdomain: hardware cannot set/clear wake up of "
446 "%s when %s wakes up\n", clkdm1->name, clkdm2->name);
447 return PTR_ERR(cd);
448 }
449
Paul Walmsley369d5612010-01-26 20:13:01 -0700450 if (atomic_inc_return(&cd->wkdep_usecount) == 1) {
451 pr_debug("clockdomain: hardware will wake up %s when %s wakes "
452 "up\n", clkdm1->name, clkdm2->name);
Paul Walmsley55ed9692010-01-26 20:12:59 -0700453
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700454 omap2_prm_set_mod_reg_bits((1 << clkdm2->dep_bit),
Paul Walmsley369d5612010-01-26 20:13:01 -0700455 clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP);
456 }
Paul Walmsley55ed9692010-01-26 20:12:59 -0700457
458 return 0;
459}
460
461/**
462 * clkdm_del_wkdep - remove a wakeup dependency from clkdm2 to clkdm1
463 * @clkdm1: wake this struct clockdomain * up (dependent)
464 * @clkdm2: when this struct clockdomain * wakes up (source)
465 *
466 * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2
467 * wakes up. Returns -EINVAL if presented with invalid clockdomain
468 * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or
469 * 0 upon success.
470 */
471int clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
472{
473 struct clkdm_dep *cd;
474
Paul Walmsley56bc78d2011-01-17 13:28:17 -0700475 if (!cpu_is_omap24xx() && !cpu_is_omap34xx()) {
476 pr_err("clockdomain: %s/%s: %s: not yet implemented\n",
477 clkdm1->name, clkdm2->name, __func__);
478 return -EINVAL;
479 }
480
Paul Walmsley55ed9692010-01-26 20:12:59 -0700481 if (!clkdm1 || !clkdm2)
482 return -EINVAL;
483
484 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
485 if (IS_ERR(cd)) {
486 pr_debug("clockdomain: hardware cannot set/clear wake up of "
487 "%s when %s wakes up\n", clkdm1->name, clkdm2->name);
488 return PTR_ERR(cd);
489 }
490
Paul Walmsley369d5612010-01-26 20:13:01 -0700491 if (atomic_dec_return(&cd->wkdep_usecount) == 0) {
492 pr_debug("clockdomain: hardware will no longer wake up %s "
493 "after %s wakes up\n", clkdm1->name, clkdm2->name);
Paul Walmsley55ed9692010-01-26 20:12:59 -0700494
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700495 omap2_prm_clear_mod_reg_bits((1 << clkdm2->dep_bit),
Paul Walmsley369d5612010-01-26 20:13:01 -0700496 clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP);
497 }
Paul Walmsley55ed9692010-01-26 20:12:59 -0700498
499 return 0;
500}
501
502/**
503 * clkdm_read_wkdep - read wakeup dependency state from clkdm2 to clkdm1
504 * @clkdm1: wake this struct clockdomain * up (dependent)
505 * @clkdm2: when this struct clockdomain * wakes up (source)
506 *
507 * Return 1 if a hardware wakeup dependency exists wherein @clkdm1 will be
508 * awoken when @clkdm2 wakes up; 0 if dependency is not set; -EINVAL
509 * if either clockdomain pointer is invalid; or -ENOENT if the hardware
510 * is incapable.
511 *
512 * REVISIT: Currently this function only represents software-controllable
513 * wakeup dependencies. Wakeup dependencies fixed in hardware are not
514 * yet handled here.
515 */
516int clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
517{
518 struct clkdm_dep *cd;
519
520 if (!clkdm1 || !clkdm2)
521 return -EINVAL;
522
Paul Walmsley56bc78d2011-01-17 13:28:17 -0700523 if (!cpu_is_omap24xx() && !cpu_is_omap34xx()) {
524 pr_err("clockdomain: %s/%s: %s: not yet implemented\n",
525 clkdm1->name, clkdm2->name, __func__);
526 return -EINVAL;
527 }
528
Paul Walmsley55ed9692010-01-26 20:12:59 -0700529 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
530 if (IS_ERR(cd)) {
531 pr_debug("clockdomain: hardware cannot set/clear wake up of "
532 "%s when %s wakes up\n", clkdm1->name, clkdm2->name);
533 return PTR_ERR(cd);
534 }
535
Paul Walmsley369d5612010-01-26 20:13:01 -0700536 /* XXX It's faster to return the atomic wkdep_usecount */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700537 return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP,
Paul Walmsley55ed9692010-01-26 20:12:59 -0700538 (1 << clkdm2->dep_bit));
539}
540
541/**
Paul Walmsley369d5612010-01-26 20:13:01 -0700542 * clkdm_clear_all_wkdeps - remove all wakeup dependencies from target clkdm
543 * @clkdm: struct clockdomain * to remove all wakeup dependencies from
544 *
545 * Remove all inter-clockdomain wakeup dependencies that could cause
546 * @clkdm to wake. Intended to be used during boot to initialize the
547 * PRCM to a known state, after all clockdomains are put into swsup idle
548 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
549 * 0 upon success.
550 */
551int clkdm_clear_all_wkdeps(struct clockdomain *clkdm)
552{
553 struct clkdm_dep *cd;
554 u32 mask = 0;
555
Paul Walmsley56bc78d2011-01-17 13:28:17 -0700556 if (!cpu_is_omap24xx() && !cpu_is_omap34xx()) {
557 pr_err("clockdomain: %s: %s: not yet implemented\n",
558 clkdm->name, __func__);
559 return -EINVAL;
560 }
561
Paul Walmsley369d5612010-01-26 20:13:01 -0700562 if (!clkdm)
563 return -EINVAL;
564
565 for (cd = clkdm->wkdep_srcs; cd && cd->clkdm_name; cd++) {
566 if (!omap_chip_is(cd->omap_chip))
567 continue;
568
Paul Walmsley6f7f63c2010-09-14 15:56:53 -0600569 if (!cd->clkdm && cd->clkdm_name)
570 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
571
Paul Walmsley369d5612010-01-26 20:13:01 -0700572 /* PRM accesses are slow, so minimize them */
573 mask |= 1 << cd->clkdm->dep_bit;
574 atomic_set(&cd->wkdep_usecount, 0);
575 }
576
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700577 omap2_prm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs, PM_WKDEP);
Paul Walmsley369d5612010-01-26 20:13:01 -0700578
579 return 0;
580}
581
582/**
Paul Walmsley55ed9692010-01-26 20:12:59 -0700583 * clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1
584 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
585 * @clkdm2: when this struct clockdomain * is active (source)
586 *
587 * Prevent @clkdm1 from automatically going inactive (and then to
588 * retention or off) if @clkdm2 is active. Returns -EINVAL if
589 * presented with invalid clockdomain pointers or called on a machine
590 * that does not support software-configurable hardware sleep
591 * dependencies, -ENOENT if the specified dependency cannot be set in
592 * hardware, or 0 upon success.
593 */
594int clkdm_add_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
595{
596 struct clkdm_dep *cd;
597
598 if (!cpu_is_omap34xx())
599 return -EINVAL;
600
601 if (!clkdm1 || !clkdm2)
602 return -EINVAL;
603
604 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
605 if (IS_ERR(cd)) {
606 pr_debug("clockdomain: hardware cannot set/clear sleep "
607 "dependency affecting %s from %s\n", clkdm1->name,
608 clkdm2->name);
609 return PTR_ERR(cd);
610 }
611
Paul Walmsley369d5612010-01-26 20:13:01 -0700612 if (atomic_inc_return(&cd->sleepdep_usecount) == 1) {
613 pr_debug("clockdomain: will prevent %s from sleeping if %s "
614 "is active\n", clkdm1->name, clkdm2->name);
Paul Walmsley55ed9692010-01-26 20:12:59 -0700615
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700616 omap2_cm_set_mod_reg_bits((1 << clkdm2->dep_bit),
Paul Walmsley369d5612010-01-26 20:13:01 -0700617 clkdm1->pwrdm.ptr->prcm_offs,
618 OMAP3430_CM_SLEEPDEP);
619 }
Paul Walmsley55ed9692010-01-26 20:12:59 -0700620
621 return 0;
622}
623
624/**
625 * clkdm_del_sleepdep - remove a sleep dependency from clkdm2 to clkdm1
626 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
627 * @clkdm2: when this struct clockdomain * is active (source)
628 *
629 * Allow @clkdm1 to automatically go inactive (and then to retention or
630 * off), independent of the activity state of @clkdm2. Returns -EINVAL
631 * if presented with invalid clockdomain pointers or called on a machine
632 * that does not support software-configurable hardware sleep dependencies,
633 * -ENOENT if the specified dependency cannot be cleared in hardware, or
634 * 0 upon success.
635 */
636int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
637{
638 struct clkdm_dep *cd;
639
640 if (!cpu_is_omap34xx())
641 return -EINVAL;
642
643 if (!clkdm1 || !clkdm2)
644 return -EINVAL;
645
646 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
647 if (IS_ERR(cd)) {
648 pr_debug("clockdomain: hardware cannot set/clear sleep "
649 "dependency affecting %s from %s\n", clkdm1->name,
650 clkdm2->name);
651 return PTR_ERR(cd);
652 }
653
Paul Walmsley369d5612010-01-26 20:13:01 -0700654 if (atomic_dec_return(&cd->sleepdep_usecount) == 0) {
655 pr_debug("clockdomain: will no longer prevent %s from "
656 "sleeping if %s is active\n", clkdm1->name,
657 clkdm2->name);
Paul Walmsley55ed9692010-01-26 20:12:59 -0700658
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700659 omap2_cm_clear_mod_reg_bits((1 << clkdm2->dep_bit),
Paul Walmsley369d5612010-01-26 20:13:01 -0700660 clkdm1->pwrdm.ptr->prcm_offs,
661 OMAP3430_CM_SLEEPDEP);
662 }
Paul Walmsley55ed9692010-01-26 20:12:59 -0700663
664 return 0;
665}
666
667/**
668 * clkdm_read_sleepdep - read sleep dependency state from clkdm2 to clkdm1
669 * @clkdm1: prevent this struct clockdomain * from sleeping (dependent)
670 * @clkdm2: when this struct clockdomain * is active (source)
671 *
672 * Return 1 if a hardware sleep dependency exists wherein @clkdm1 will
673 * not be allowed to automatically go inactive if @clkdm2 is active;
674 * 0 if @clkdm1's automatic power state inactivity transition is independent
675 * of @clkdm2's; -EINVAL if either clockdomain pointer is invalid or called
676 * on a machine that does not support software-configurable hardware sleep
677 * dependencies; or -ENOENT if the hardware is incapable.
678 *
679 * REVISIT: Currently this function only represents software-controllable
680 * sleep dependencies. Sleep dependencies fixed in hardware are not
681 * yet handled here.
682 */
683int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
684{
685 struct clkdm_dep *cd;
686
687 if (!cpu_is_omap34xx())
688 return -EINVAL;
689
690 if (!clkdm1 || !clkdm2)
691 return -EINVAL;
692
693 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
694 if (IS_ERR(cd)) {
695 pr_debug("clockdomain: hardware cannot set/clear sleep "
696 "dependency affecting %s from %s\n", clkdm1->name,
697 clkdm2->name);
698 return PTR_ERR(cd);
699 }
700
Paul Walmsley369d5612010-01-26 20:13:01 -0700701 /* XXX It's faster to return the atomic sleepdep_usecount */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700702 return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs,
Paul Walmsley55ed9692010-01-26 20:12:59 -0700703 OMAP3430_CM_SLEEPDEP,
704 (1 << clkdm2->dep_bit));
705}
706
Paul Walmsley369d5612010-01-26 20:13:01 -0700707/**
708 * clkdm_clear_all_sleepdeps - remove all sleep dependencies from target clkdm
709 * @clkdm: struct clockdomain * to remove all sleep dependencies from
710 *
711 * Remove all inter-clockdomain sleep dependencies that could prevent
712 * @clkdm from idling. Intended to be used during boot to initialize the
713 * PRCM to a known state, after all clockdomains are put into swsup idle
714 * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or
715 * 0 upon success.
716 */
717int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm)
718{
719 struct clkdm_dep *cd;
720 u32 mask = 0;
721
722 if (!cpu_is_omap34xx())
723 return -EINVAL;
724
725 if (!clkdm)
726 return -EINVAL;
727
728 for (cd = clkdm->sleepdep_srcs; cd && cd->clkdm_name; cd++) {
729 if (!omap_chip_is(cd->omap_chip))
730 continue;
731
Paul Walmsley6f7f63c2010-09-14 15:56:53 -0600732 if (!cd->clkdm && cd->clkdm_name)
733 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
734
Paul Walmsley369d5612010-01-26 20:13:01 -0700735 /* PRM accesses are slow, so minimize them */
736 mask |= 1 << cd->clkdm->dep_bit;
737 atomic_set(&cd->sleepdep_usecount, 0);
738 }
739
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700740 omap2_prm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs,
Paul Walmsley369d5612010-01-26 20:13:01 -0700741 OMAP3430_CM_SLEEPDEP);
742
743 return 0;
744}
Paul Walmsley55ed9692010-01-26 20:12:59 -0700745
746/**
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300747 * omap2_clkdm_sleep - force clockdomain sleep transition
748 * @clkdm: struct clockdomain *
749 *
750 * Instruct the CM to force a sleep transition on the specified
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700751 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300752 * clockdomain does not support software-initiated sleep; 0 upon
753 * success.
754 */
755int omap2_clkdm_sleep(struct clockdomain *clkdm)
756{
757 if (!clkdm)
758 return -EINVAL;
759
760 if (!(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) {
761 pr_debug("clockdomain: %s does not support forcing "
762 "sleep via software\n", clkdm->name);
763 return -EINVAL;
764 }
765
766 pr_debug("clockdomain: forcing sleep on %s\n", clkdm->name);
767
768 if (cpu_is_omap24xx()) {
769
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700770 omap2_cm_set_mod_reg_bits(OMAP24XX_FORCESTATE_MASK,
Abhijit Pagare37903002010-01-26 20:12:51 -0700771 clkdm->pwrdm.ptr->prcm_offs, OMAP2_PM_PWSTCTRL);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300772
Paul Walmsleybd2122c2010-12-21 21:05:15 -0700773 } else if (cpu_is_omap34xx()) {
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300774
Paul Walmsley55ae3502010-12-21 21:05:15 -0700775 omap3xxx_cm_clkdm_force_sleep(clkdm->pwrdm.ptr->prcm_offs,
776 clkdm->clktrctrl_mask);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300777
Paul Walmsleybd2122c2010-12-21 21:05:15 -0700778 } else if (cpu_is_omap44xx()) {
779
780 omap4_cminst_clkdm_force_sleep(clkdm->prcm_partition,
781 clkdm->cm_inst,
782 clkdm->clkdm_offs);
783
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300784 } else {
785 BUG();
786 };
787
788 return 0;
789}
790
791/**
792 * omap2_clkdm_wakeup - force clockdomain wakeup transition
793 * @clkdm: struct clockdomain *
794 *
795 * Instruct the CM to force a wakeup transition on the specified
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700796 * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if the
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300797 * clockdomain does not support software-controlled wakeup; 0 upon
798 * success.
799 */
800int omap2_clkdm_wakeup(struct clockdomain *clkdm)
801{
802 if (!clkdm)
803 return -EINVAL;
804
805 if (!(clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)) {
806 pr_debug("clockdomain: %s does not support forcing "
807 "wakeup via software\n", clkdm->name);
808 return -EINVAL;
809 }
810
811 pr_debug("clockdomain: forcing wakeup on %s\n", clkdm->name);
812
813 if (cpu_is_omap24xx()) {
814
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700815 omap2_cm_clear_mod_reg_bits(OMAP24XX_FORCESTATE_MASK,
Abhijit Pagare37903002010-01-26 20:12:51 -0700816 clkdm->pwrdm.ptr->prcm_offs, OMAP2_PM_PWSTCTRL);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300817
Paul Walmsleybd2122c2010-12-21 21:05:15 -0700818 } else if (cpu_is_omap34xx()) {
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300819
Paul Walmsley55ae3502010-12-21 21:05:15 -0700820 omap3xxx_cm_clkdm_force_wakeup(clkdm->pwrdm.ptr->prcm_offs,
821 clkdm->clktrctrl_mask);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300822
Paul Walmsleybd2122c2010-12-21 21:05:15 -0700823 } else if (cpu_is_omap44xx()) {
824
825 omap4_cminst_clkdm_force_wakeup(clkdm->prcm_partition,
826 clkdm->cm_inst,
827 clkdm->clkdm_offs);
828
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300829 } else {
830 BUG();
831 };
832
833 return 0;
834}
835
836/**
837 * omap2_clkdm_allow_idle - enable hwsup idle transitions for clkdm
838 * @clkdm: struct clockdomain *
839 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700840 * Allow the hardware to automatically switch the clockdomain @clkdm into
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300841 * active or idle states, as needed by downstream clocks. If the
842 * clockdomain has any downstream clocks enabled in the clock
843 * framework, wkdep/sleepdep autodependencies are added; this is so
844 * device drivers can read and write to the device. No return value.
845 */
846void omap2_clkdm_allow_idle(struct clockdomain *clkdm)
847{
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300848 if (!clkdm)
849 return;
850
851 if (!(clkdm->flags & CLKDM_CAN_ENABLE_AUTO)) {
852 pr_debug("clock: automatic idle transitions cannot be enabled "
853 "on clockdomain %s\n", clkdm->name);
854 return;
855 }
856
857 pr_debug("clockdomain: enabling automatic idle transitions for %s\n",
858 clkdm->name);
859
Abhijit Pagare91808a82010-02-22 22:09:07 -0700860 /*
861 * XXX This should be removed once TI adds wakeup/sleep
862 * dependency code and data for OMAP4.
863 */
864 if (cpu_is_omap44xx()) {
Paul Walmsley56bc78d2011-01-17 13:28:17 -0700865 pr_err("clockdomain: %s: OMAP4 wakeup/sleep dependency support: not yet implemented\n", clkdm->name);
Abhijit Pagare91808a82010-02-22 22:09:07 -0700866 } else {
867 if (atomic_read(&clkdm->usecount) > 0)
868 _clkdm_add_autodeps(clkdm);
869 }
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300870
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700871 _enable_hwsup(clkdm);
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +0300872
873 pwrdm_clkdm_state_switch(clkdm);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300874}
875
876/**
877 * omap2_clkdm_deny_idle - disable hwsup idle transitions for clkdm
878 * @clkdm: struct clockdomain *
879 *
880 * Prevent the hardware from automatically switching the clockdomain
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700881 * @clkdm into inactive or idle states. If the clockdomain has
882 * downstream clocks enabled in the clock framework, wkdep/sleepdep
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300883 * autodependencies are removed. No return value.
884 */
885void omap2_clkdm_deny_idle(struct clockdomain *clkdm)
886{
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300887 if (!clkdm)
888 return;
889
890 if (!(clkdm->flags & CLKDM_CAN_DISABLE_AUTO)) {
891 pr_debug("clockdomain: automatic idle transitions cannot be "
892 "disabled on %s\n", clkdm->name);
893 return;
894 }
895
896 pr_debug("clockdomain: disabling automatic idle transitions for %s\n",
897 clkdm->name);
898
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700899 _disable_hwsup(clkdm);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300900
Abhijit Pagare91808a82010-02-22 22:09:07 -0700901 /*
902 * XXX This should be removed once TI adds wakeup/sleep
903 * dependency code and data for OMAP4.
904 */
905 if (cpu_is_omap44xx()) {
Paul Walmsley56bc78d2011-01-17 13:28:17 -0700906 pr_err("clockdomain: %s: OMAP4 wakeup/sleep dependency support: not yet implemented\n", clkdm->name);
Abhijit Pagare91808a82010-02-22 22:09:07 -0700907 } else {
908 if (atomic_read(&clkdm->usecount) > 0)
909 _clkdm_del_autodeps(clkdm);
910 }
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300911}
912
913
914/* Clockdomain-to-clock framework interface code */
915
916/**
917 * omap2_clkdm_clk_enable - add an enabled downstream clock to this clkdm
918 * @clkdm: struct clockdomain *
919 * @clk: struct clk * of the enabled downstream clock
920 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700921 * Increment the usecount of the clockdomain @clkdm and ensure that it
922 * is awake before @clk is enabled. Intended to be called by
923 * clk_enable() code. If the clockdomain is in software-supervised
924 * idle mode, force the clockdomain to wake. If the clockdomain is in
925 * hardware-supervised idle mode, add clkdm-pwrdm autodependencies, to
926 * ensure that devices in the clockdomain can be read from/written to
927 * by on-chip processors. Returns -EINVAL if passed null pointers;
928 * returns 0 upon success or if the clockdomain is in hwsup idle mode.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300929 */
930int omap2_clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk)
931{
Paul Walmsley55ae3502010-12-21 21:05:15 -0700932 bool hwsup = false;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300933
934 /*
935 * XXX Rewrite this code to maintain a list of enabled
936 * downstream clocks for debugging purposes?
937 */
938
Paul Walmsley30962d92010-02-22 22:09:38 -0700939 if (!clkdm || !clk)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300940 return -EINVAL;
941
942 if (atomic_inc_return(&clkdm->usecount) > 1)
943 return 0;
944
945 /* Clockdomain now has one enabled downstream clock */
946
947 pr_debug("clockdomain: clkdm %s: clk %s now enabled\n", clkdm->name,
948 clk->name);
949
Paul Walmsley55ae3502010-12-21 21:05:15 -0700950 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
Paul Walmsley30962d92010-02-22 22:09:38 -0700951
Paul Walmsley55ae3502010-12-21 21:05:15 -0700952 if (!clkdm->clktrctrl_mask)
953 return 0;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300954
Paul Walmsley55ae3502010-12-21 21:05:15 -0700955 hwsup = omap2_cm_is_clkdm_in_hwsup(clkdm->pwrdm.ptr->prcm_offs,
956 clkdm->clktrctrl_mask);
957
958 } else if (cpu_is_omap44xx()) {
959
960 hwsup = omap4_cminst_is_clkdm_in_hwsup(clkdm->prcm_partition,
961 clkdm->cm_inst,
962 clkdm->clkdm_offs);
963
964 }
965
966 if (hwsup) {
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600967 /* Disable HW transitions when we are changing deps */
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700968 _disable_hwsup(clkdm);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300969 _clkdm_add_autodeps(clkdm);
Paul Walmsleyb170fbe2010-12-21 21:05:15 -0700970 _enable_hwsup(clkdm);
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600971 } else {
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300972 omap2_clkdm_wakeup(clkdm);
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -0600973 }
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300974
Tomi Valkeinen054ce502009-01-27 19:44:31 -0700975 pwrdm_wait_transition(clkdm->pwrdm.ptr);
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300976 pwrdm_clkdm_state_switch(clkdm);
Tomi Valkeinen054ce502009-01-27 19:44:31 -0700977
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300978 return 0;
979}
980
981/**
982 * omap2_clkdm_clk_disable - remove an enabled downstream clock from this clkdm
983 * @clkdm: struct clockdomain *
984 * @clk: struct clk * of the disabled downstream clock
985 *
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700986 * Decrement the usecount of this clockdomain @clkdm when @clk is
987 * disabled. Intended to be called by clk_disable() code. If the
988 * clockdomain usecount goes to 0, put the clockdomain to sleep
989 * (software-supervised mode) or remove the clkdm autodependencies
990 * (hardware-supervised mode). Returns -EINVAL if passed null
991 * pointers; -ERANGE if the @clkdm usecount underflows and debugging
992 * is enabled; or returns 0 upon success or if the clockdomain is in
993 * hwsup idle mode.
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300994 */
995int omap2_clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk)
996{
Paul Walmsley55ae3502010-12-21 21:05:15 -0700997 bool hwsup = false;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +0300998
999 /*
1000 * XXX Rewrite this code to maintain a list of enabled
1001 * downstream clocks for debugging purposes?
1002 */
1003
Paul Walmsley30962d92010-02-22 22:09:38 -07001004 if (!clkdm || !clk)
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001005 return -EINVAL;
1006
1007#ifdef DEBUG
1008 if (atomic_read(&clkdm->usecount) == 0) {
1009 WARN_ON(1); /* underflow */
1010 return -ERANGE;
1011 }
1012#endif
1013
1014 if (atomic_dec_return(&clkdm->usecount) > 0)
1015 return 0;
1016
1017 /* All downstream clocks of this clockdomain are now disabled */
1018
1019 pr_debug("clockdomain: clkdm %s: clk %s now disabled\n", clkdm->name,
1020 clk->name);
1021
Paul Walmsley55ae3502010-12-21 21:05:15 -07001022 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
Paul Walmsley30962d92010-02-22 22:09:38 -07001023
Paul Walmsley55ae3502010-12-21 21:05:15 -07001024 if (!clkdm->clktrctrl_mask)
1025 return 0;
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001026
Paul Walmsley55ae3502010-12-21 21:05:15 -07001027 hwsup = omap2_cm_is_clkdm_in_hwsup(clkdm->pwrdm.ptr->prcm_offs,
1028 clkdm->clktrctrl_mask);
1029
1030 } else if (cpu_is_omap44xx()) {
1031
1032 hwsup = omap4_cminst_is_clkdm_in_hwsup(clkdm->prcm_partition,
1033 clkdm->cm_inst,
1034 clkdm->clkdm_offs);
1035
1036 }
1037
1038 if (hwsup) {
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -06001039 /* Disable HW transitions when we are changing deps */
Paul Walmsleyb170fbe2010-12-21 21:05:15 -07001040 _disable_hwsup(clkdm);
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001041 _clkdm_del_autodeps(clkdm);
Paul Walmsleyb170fbe2010-12-21 21:05:15 -07001042 _enable_hwsup(clkdm);
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -06001043 } else {
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001044 omap2_clkdm_sleep(clkdm);
Kalle Jokiniemia0219fb2009-10-14 16:40:37 -06001045 }
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001046
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +03001047 pwrdm_clkdm_state_switch(clkdm);
1048
Paul Walmsleyd459bfe2008-08-19 11:08:43 +03001049 return 0;
1050}
1051