Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 1 | /* |
Abhijit Pagare | 8a3ddc7 | 2010-01-26 20:12:54 -0700 | [diff] [blame] | 2 | * OMAP2/3/4 clockdomain framework functions |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 3 | * |
Abhijit Pagare | 91808a8 | 2010-02-22 22:09:07 -0700 | [diff] [blame] | 4 | * Copyright (C) 2008-2010 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2008-2010 Nokia Corporation |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 6 | * |
| 7 | * Written by Paul Walmsley and Jouni Högander |
Abhijit Pagare | 8a3ddc7 | 2010-01-26 20:12:54 -0700 | [diff] [blame] | 8 | * Added OMAP4 specific support by Abhijit Pagare <abhijitpagare@ti.com> |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 9 | * |
| 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 Walmsley | 33903eb | 2009-12-08 16:33:10 -0700 | [diff] [blame] | 14 | #undef DEBUG |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 15 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 16 | #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 Walmsley | 5b74c67 | 2009-02-03 02:10:03 -0700 | [diff] [blame] | 23 | #include <linux/err.h> |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 24 | |
| 25 | #include <linux/io.h> |
| 26 | |
| 27 | #include <linux/bitops.h> |
| 28 | |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 29 | #include "prm2xxx_3xxx.h" |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 30 | #include "prm-regbits-24xx.h" |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 31 | #include "cm2xxx_3xxx.h" |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 32 | #include "cm-regbits-34xx.h" |
| 33 | #include "cminst44xx.h" |
| 34 | #include "prcm44xx.h" |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 35 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 36 | #include <plat/clock.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 37 | #include <plat/powerdomain.h> |
| 38 | #include <plat/clockdomain.h> |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 39 | #include <plat/prcm.h> |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 40 | |
| 41 | /* clkdm_list contains all registered struct clockdomains */ |
| 42 | static LIST_HEAD(clkdm_list); |
| 43 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 44 | /* array of clockdomain deps to be added/removed when clkdm in hwsup mode */ |
| 45 | static struct clkdm_autodep *autodeps; |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 46 | |
| 47 | |
| 48 | /* Private functions */ |
| 49 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 50 | static struct clockdomain *_clkdm_lookup(const char *name) |
| 51 | { |
| 52 | struct clockdomain *clkdm, *temp_clkdm; |
| 53 | |
| 54 | if (!name) |
| 55 | return NULL; |
| 56 | |
| 57 | clkdm = NULL; |
| 58 | |
| 59 | list_for_each_entry(temp_clkdm, &clkdm_list, node) { |
| 60 | if (!strcmp(name, temp_clkdm->name)) { |
| 61 | clkdm = temp_clkdm; |
| 62 | break; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return clkdm; |
| 67 | } |
| 68 | |
Paul Walmsley | e909d62 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 69 | /** |
| 70 | * _clkdm_register - register a clockdomain |
| 71 | * @clkdm: struct clockdomain * to register |
| 72 | * |
| 73 | * Adds a clockdomain to the internal clockdomain list. |
| 74 | * Returns -EINVAL if given a null pointer, -EEXIST if a clockdomain is |
| 75 | * already registered by the provided name, or 0 upon success. |
| 76 | */ |
| 77 | static int _clkdm_register(struct clockdomain *clkdm) |
| 78 | { |
| 79 | struct powerdomain *pwrdm; |
| 80 | |
| 81 | if (!clkdm || !clkdm->name) |
| 82 | return -EINVAL; |
| 83 | |
| 84 | if (!omap_chip_is(clkdm->omap_chip)) |
| 85 | return -EINVAL; |
| 86 | |
| 87 | pwrdm = pwrdm_lookup(clkdm->pwrdm.name); |
| 88 | if (!pwrdm) { |
| 89 | pr_err("clockdomain: %s: powerdomain %s does not exist\n", |
| 90 | clkdm->name, clkdm->pwrdm.name); |
| 91 | return -EINVAL; |
| 92 | } |
| 93 | clkdm->pwrdm.ptr = pwrdm; |
| 94 | |
| 95 | /* Verify that the clockdomain is not already registered */ |
| 96 | if (_clkdm_lookup(clkdm->name)) |
| 97 | return -EEXIST; |
| 98 | |
| 99 | list_add(&clkdm->node, &clkdm_list); |
| 100 | |
| 101 | pwrdm_add_clkdm(pwrdm, clkdm); |
| 102 | |
| 103 | pr_debug("clockdomain: registered %s\n", clkdm->name); |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 108 | /* _clkdm_deps_lookup - look up the specified clockdomain in a clkdm list */ |
| 109 | static struct clkdm_dep *_clkdm_deps_lookup(struct clockdomain *clkdm, |
| 110 | struct clkdm_dep *deps) |
| 111 | { |
| 112 | struct clkdm_dep *cd; |
| 113 | |
| 114 | if (!clkdm || !deps || !omap_chip_is(clkdm->omap_chip)) |
| 115 | return ERR_PTR(-EINVAL); |
| 116 | |
| 117 | for (cd = deps; cd->clkdm_name; cd++) { |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 118 | if (!omap_chip_is(cd->omap_chip)) |
| 119 | continue; |
| 120 | |
| 121 | if (!cd->clkdm && cd->clkdm_name) |
| 122 | cd->clkdm = _clkdm_lookup(cd->clkdm_name); |
| 123 | |
| 124 | if (cd->clkdm == clkdm) |
| 125 | break; |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | if (!cd->clkdm_name) |
| 129 | return ERR_PTR(-ENOENT); |
| 130 | |
| 131 | return cd; |
| 132 | } |
| 133 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 134 | /* |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 135 | * _autodep_lookup - resolve autodep clkdm names to clkdm pointers; store |
| 136 | * @autodep: struct clkdm_autodep * to resolve |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 137 | * |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 138 | * Resolve autodep clockdomain names to clockdomain pointers via |
| 139 | * clkdm_lookup() and store the pointers in the autodep structure. An |
| 140 | * "autodep" is a clockdomain sleep/wakeup dependency that is |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 141 | * automatically added and removed whenever clocks in the associated |
| 142 | * clockdomain are enabled or disabled (respectively) when the |
| 143 | * clockdomain is in hardware-supervised mode. Meant to be called |
| 144 | * once at clockdomain layer initialization, since these should remain |
| 145 | * fixed for a particular architecture. No return value. |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 146 | * |
| 147 | * XXX autodeps are deprecated and should be removed at the earliest |
| 148 | * opportunity |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 149 | */ |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 150 | static void _autodep_lookup(struct clkdm_autodep *autodep) |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 151 | { |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 152 | struct clockdomain *clkdm; |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 153 | |
| 154 | if (!autodep) |
| 155 | return; |
| 156 | |
| 157 | if (!omap_chip_is(autodep->omap_chip)) |
| 158 | return; |
| 159 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 160 | clkdm = clkdm_lookup(autodep->clkdm.name); |
| 161 | if (!clkdm) { |
| 162 | pr_err("clockdomain: autodeps: clockdomain %s does not exist\n", |
| 163 | autodep->clkdm.name); |
| 164 | clkdm = ERR_PTR(-ENOENT); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 165 | } |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 166 | autodep->clkdm.ptr = clkdm; |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /* |
| 170 | * _clkdm_add_autodeps - add auto sleepdeps/wkdeps to clkdm upon clock enable |
| 171 | * @clkdm: struct clockdomain * |
| 172 | * |
| 173 | * Add the "autodep" sleep & wakeup dependencies to clockdomain 'clkdm' |
| 174 | * in hardware-supervised mode. Meant to be called from clock framework |
| 175 | * when a clock inside clockdomain 'clkdm' is enabled. No return value. |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 176 | * |
| 177 | * XXX autodeps are deprecated and should be removed at the earliest |
| 178 | * opportunity |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 179 | */ |
| 180 | static void _clkdm_add_autodeps(struct clockdomain *clkdm) |
| 181 | { |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 182 | struct clkdm_autodep *autodep; |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 183 | |
Paul Walmsley | ad95616 | 2010-02-22 22:09:35 -0700 | [diff] [blame] | 184 | if (!autodeps) |
| 185 | return; |
| 186 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 187 | for (autodep = autodeps; autodep->clkdm.ptr; autodep++) { |
| 188 | if (IS_ERR(autodep->clkdm.ptr)) |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 189 | continue; |
| 190 | |
Paul Walmsley | d96df00 | 2009-01-27 19:44:35 -0700 | [diff] [blame] | 191 | if (!omap_chip_is(autodep->omap_chip)) |
| 192 | continue; |
| 193 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 194 | pr_debug("clockdomain: adding %s sleepdep/wkdep for " |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 195 | "clkdm %s\n", autodep->clkdm.ptr->name, |
| 196 | clkdm->name); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 197 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 198 | clkdm_add_sleepdep(clkdm, autodep->clkdm.ptr); |
| 199 | clkdm_add_wkdep(clkdm, autodep->clkdm.ptr); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * _clkdm_add_autodeps - remove auto sleepdeps/wkdeps from clkdm |
| 205 | * @clkdm: struct clockdomain * |
| 206 | * |
| 207 | * Remove the "autodep" sleep & wakeup dependencies from clockdomain 'clkdm' |
| 208 | * in hardware-supervised mode. Meant to be called from clock framework |
| 209 | * when a clock inside clockdomain 'clkdm' is disabled. No return value. |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 210 | * |
| 211 | * XXX autodeps are deprecated and should be removed at the earliest |
| 212 | * opportunity |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 213 | */ |
| 214 | static void _clkdm_del_autodeps(struct clockdomain *clkdm) |
| 215 | { |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 216 | struct clkdm_autodep *autodep; |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 217 | |
Paul Walmsley | ad95616 | 2010-02-22 22:09:35 -0700 | [diff] [blame] | 218 | if (!autodeps) |
| 219 | return; |
| 220 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 221 | for (autodep = autodeps; autodep->clkdm.ptr; autodep++) { |
| 222 | if (IS_ERR(autodep->clkdm.ptr)) |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 223 | continue; |
| 224 | |
Paul Walmsley | d96df00 | 2009-01-27 19:44:35 -0700 | [diff] [blame] | 225 | if (!omap_chip_is(autodep->omap_chip)) |
| 226 | continue; |
| 227 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 228 | pr_debug("clockdomain: removing %s sleepdep/wkdep for " |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 229 | "clkdm %s\n", autodep->clkdm.ptr->name, |
| 230 | clkdm->name); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 231 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 232 | clkdm_del_sleepdep(clkdm, autodep->clkdm.ptr); |
| 233 | clkdm_del_wkdep(clkdm, autodep->clkdm.ptr); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 237 | /** |
| 238 | * _enable_hwsup - place a clockdomain into hardware-supervised idle |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 239 | * @clkdm: struct clockdomain * |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 240 | * |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 241 | * Place the clockdomain into hardware-supervised idle mode. No return |
| 242 | * value. |
| 243 | * |
| 244 | * XXX Should this return an error if the clockdomain does not support |
| 245 | * hardware-supervised idle mode? |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 246 | */ |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 247 | static void _enable_hwsup(struct clockdomain *clkdm) |
| 248 | { |
| 249 | u32 bits, v; |
| 250 | |
| 251 | if (cpu_is_omap24xx()) |
| 252 | bits = OMAP24XX_CLKSTCTRL_ENABLE_AUTO; |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 253 | else if (cpu_is_omap34xx()) |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 254 | bits = OMAP34XX_CLKSTCTRL_ENABLE_AUTO; |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 255 | else if (cpu_is_omap44xx()) |
| 256 | return omap4_cminst_clkdm_enable_hwsup(clkdm->prcm_partition, |
| 257 | clkdm->cm_inst, |
| 258 | clkdm->clkdm_offs); |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 259 | else |
| 260 | BUG(); |
| 261 | |
| 262 | bits = bits << __ffs(clkdm->clktrctrl_mask); |
| 263 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 264 | /* |
| 265 | * XXX clkstctrl_reg is known on OMAP2 - this clkdm |
| 266 | * field is not needed |
| 267 | */ |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 268 | v = __raw_readl(clkdm->clkstctrl_reg); |
| 269 | v &= ~(clkdm->clktrctrl_mask); |
| 270 | v |= bits; |
| 271 | __raw_writel(v, clkdm->clkstctrl_reg); |
| 272 | |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * _disable_hwsup - place a clockdomain into software-supervised idle |
| 277 | * @clkdm: struct clockdomain * |
| 278 | * |
| 279 | * Place the clockdomain @clkdm into software-supervised idle mode. |
| 280 | * No return value. |
| 281 | * |
| 282 | * XXX Should this return an error if the clockdomain does not support |
| 283 | * software-supervised idle mode? |
| 284 | */ |
| 285 | static void _disable_hwsup(struct clockdomain *clkdm) |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 286 | { |
Abhijit Pagare | b099474 | 2010-01-26 20:12:53 -0700 | [diff] [blame] | 287 | u32 bits, v; |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 288 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 289 | if (cpu_is_omap24xx()) |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 290 | bits = OMAP24XX_CLKSTCTRL_DISABLE_AUTO; |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 291 | else if (cpu_is_omap34xx()) |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 292 | bits = OMAP34XX_CLKSTCTRL_DISABLE_AUTO; |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 293 | else if (cpu_is_omap44xx()) |
| 294 | return omap4_cminst_clkdm_disable_hwsup(clkdm->prcm_partition, |
| 295 | clkdm->cm_inst, |
| 296 | clkdm->clkdm_offs); |
| 297 | else |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 298 | BUG(); |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 299 | |
Abhijit Pagare | b099474 | 2010-01-26 20:12:53 -0700 | [diff] [blame] | 300 | bits = bits << __ffs(clkdm->clktrctrl_mask); |
| 301 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 302 | /* |
| 303 | * XXX clkstctrl_reg is known on OMAP2 - this clkdm |
| 304 | * field is not needed |
| 305 | */ |
Abhijit Pagare | b099474 | 2010-01-26 20:12:53 -0700 | [diff] [blame] | 306 | v = __raw_readl(clkdm->clkstctrl_reg); |
| 307 | v &= ~(clkdm->clktrctrl_mask); |
| 308 | v |= bits; |
| 309 | __raw_writel(v, clkdm->clkstctrl_reg); |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 310 | } |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 311 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 312 | /* Public functions */ |
| 313 | |
| 314 | /** |
| 315 | * clkdm_init - set up the clockdomain layer |
| 316 | * @clkdms: optional pointer to an array of clockdomains to register |
| 317 | * @init_autodeps: optional pointer to an array of autodeps to register |
| 318 | * |
| 319 | * Set up internal state. If a pointer to an array of clockdomains |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 320 | * @clkdms was supplied, loop through the list of clockdomains, |
| 321 | * register all that are available on the current platform. Similarly, |
| 322 | * if a pointer to an array of clockdomain autodependencies |
| 323 | * @init_autodeps was provided, register those. No return value. |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 324 | */ |
| 325 | void clkdm_init(struct clockdomain **clkdms, |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 326 | struct clkdm_autodep *init_autodeps) |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 327 | { |
| 328 | struct clockdomain **c = NULL; |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 329 | struct clockdomain *clkdm; |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 330 | struct clkdm_autodep *autodep = NULL; |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 331 | |
| 332 | if (clkdms) |
| 333 | for (c = clkdms; *c; c++) |
Paul Walmsley | e909d62 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 334 | _clkdm_register(*c); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 335 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 336 | autodeps = init_autodeps; |
| 337 | if (autodeps) |
| 338 | for (autodep = autodeps; autodep->clkdm.ptr; autodep++) |
| 339 | _autodep_lookup(autodep); |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 340 | |
| 341 | /* |
Paul Walmsley | 6f7f63c | 2010-09-14 15:56:53 -0600 | [diff] [blame] | 342 | * Put all clockdomains into software-supervised mode; PM code |
| 343 | * should later enable hardware-supervised mode as appropriate |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 344 | */ |
| 345 | list_for_each_entry(clkdm, &clkdm_list, node) { |
Paul Walmsley | 6f7f63c | 2010-09-14 15:56:53 -0600 | [diff] [blame] | 346 | if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP) |
| 347 | omap2_clkdm_wakeup(clkdm); |
| 348 | else if (clkdm->flags & CLKDM_CAN_DISABLE_AUTO) |
| 349 | omap2_clkdm_deny_idle(clkdm); |
| 350 | |
| 351 | clkdm_clear_all_wkdeps(clkdm); |
| 352 | clkdm_clear_all_sleepdeps(clkdm); |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 353 | } |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /** |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 357 | * clkdm_lookup - look up a clockdomain by name, return a pointer |
| 358 | * @name: name of clockdomain |
| 359 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 360 | * Find a registered clockdomain by its name @name. Returns a pointer |
| 361 | * to the struct clockdomain if found, or NULL otherwise. |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 362 | */ |
| 363 | struct clockdomain *clkdm_lookup(const char *name) |
| 364 | { |
| 365 | struct clockdomain *clkdm, *temp_clkdm; |
| 366 | |
| 367 | if (!name) |
| 368 | return NULL; |
| 369 | |
| 370 | clkdm = NULL; |
| 371 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 372 | list_for_each_entry(temp_clkdm, &clkdm_list, node) { |
| 373 | if (!strcmp(name, temp_clkdm->name)) { |
| 374 | clkdm = temp_clkdm; |
| 375 | break; |
| 376 | } |
| 377 | } |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 378 | |
| 379 | return clkdm; |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * clkdm_for_each - call function on each registered clockdomain |
| 384 | * @fn: callback function * |
| 385 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 386 | * Call the supplied function @fn for each registered clockdomain. |
| 387 | * The callback function @fn can return anything but 0 to bail |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 388 | * out early from the iterator. The callback function is called with |
| 389 | * the clkdm_mutex held, so no clockdomain structure manipulation |
| 390 | * functions should be called from the callback, although hardware |
| 391 | * clockdomain control functions are fine. Returns the last return |
| 392 | * value of the callback function, which should be 0 for success or |
| 393 | * anything else to indicate failure; or -EINVAL if the function pointer |
| 394 | * is null. |
| 395 | */ |
Peter 'p2' De Schrijver | a23456e | 2008-10-15 18:13:47 +0300 | [diff] [blame] | 396 | int clkdm_for_each(int (*fn)(struct clockdomain *clkdm, void *user), |
| 397 | void *user) |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 398 | { |
| 399 | struct clockdomain *clkdm; |
| 400 | int ret = 0; |
| 401 | |
| 402 | if (!fn) |
| 403 | return -EINVAL; |
| 404 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 405 | list_for_each_entry(clkdm, &clkdm_list, node) { |
Peter 'p2' De Schrijver | a23456e | 2008-10-15 18:13:47 +0300 | [diff] [blame] | 406 | ret = (*fn)(clkdm, user); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 407 | if (ret) |
| 408 | break; |
| 409 | } |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 410 | |
| 411 | return ret; |
| 412 | } |
| 413 | |
| 414 | |
Paul Walmsley | e89087c | 2008-05-20 18:41:35 -0600 | [diff] [blame] | 415 | /** |
| 416 | * clkdm_get_pwrdm - return a ptr to the pwrdm that this clkdm resides in |
| 417 | * @clkdm: struct clockdomain * |
| 418 | * |
| 419 | * Return a pointer to the struct powerdomain that the specified clockdomain |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 420 | * @clkdm exists in, or returns NULL if @clkdm is NULL. |
Paul Walmsley | e89087c | 2008-05-20 18:41:35 -0600 | [diff] [blame] | 421 | */ |
| 422 | struct powerdomain *clkdm_get_pwrdm(struct clockdomain *clkdm) |
| 423 | { |
| 424 | if (!clkdm) |
| 425 | return NULL; |
| 426 | |
Paul Walmsley | 5b74c67 | 2009-02-03 02:10:03 -0700 | [diff] [blame] | 427 | return clkdm->pwrdm.ptr; |
Paul Walmsley | e89087c | 2008-05-20 18:41:35 -0600 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 431 | /* Hardware clockdomain control */ |
| 432 | |
| 433 | /** |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 434 | * clkdm_add_wkdep - add a wakeup dependency from clkdm2 to clkdm1 |
| 435 | * @clkdm1: wake this struct clockdomain * up (dependent) |
| 436 | * @clkdm2: when this struct clockdomain * wakes up (source) |
| 437 | * |
| 438 | * When the clockdomain represented by @clkdm2 wakes up, wake up |
| 439 | * @clkdm1. Implemented in hardware on the OMAP, this feature is |
| 440 | * designed to reduce wakeup latency of the dependent clockdomain @clkdm1. |
| 441 | * Returns -EINVAL if presented with invalid clockdomain pointers, |
| 442 | * -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or 0 upon |
| 443 | * success. |
| 444 | */ |
| 445 | int clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) |
| 446 | { |
| 447 | struct clkdm_dep *cd; |
| 448 | |
| 449 | if (!clkdm1 || !clkdm2) |
| 450 | return -EINVAL; |
| 451 | |
| 452 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs); |
| 453 | if (IS_ERR(cd)) { |
| 454 | pr_debug("clockdomain: hardware cannot set/clear wake up of " |
| 455 | "%s when %s wakes up\n", clkdm1->name, clkdm2->name); |
| 456 | return PTR_ERR(cd); |
| 457 | } |
| 458 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 459 | if (atomic_inc_return(&cd->wkdep_usecount) == 1) { |
| 460 | pr_debug("clockdomain: hardware will wake up %s when %s wakes " |
| 461 | "up\n", clkdm1->name, clkdm2->name); |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 462 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 463 | omap2_prm_set_mod_reg_bits((1 << clkdm2->dep_bit), |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 464 | clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP); |
| 465 | } |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * clkdm_del_wkdep - remove a wakeup dependency from clkdm2 to clkdm1 |
| 472 | * @clkdm1: wake this struct clockdomain * up (dependent) |
| 473 | * @clkdm2: when this struct clockdomain * wakes up (source) |
| 474 | * |
| 475 | * Remove a wakeup dependency causing @clkdm1 to wake up when @clkdm2 |
| 476 | * wakes up. Returns -EINVAL if presented with invalid clockdomain |
| 477 | * pointers, -ENOENT if @clkdm2 cannot wake up clkdm1 in hardware, or |
| 478 | * 0 upon success. |
| 479 | */ |
| 480 | int clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) |
| 481 | { |
| 482 | struct clkdm_dep *cd; |
| 483 | |
| 484 | if (!clkdm1 || !clkdm2) |
| 485 | return -EINVAL; |
| 486 | |
| 487 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs); |
| 488 | if (IS_ERR(cd)) { |
| 489 | pr_debug("clockdomain: hardware cannot set/clear wake up of " |
| 490 | "%s when %s wakes up\n", clkdm1->name, clkdm2->name); |
| 491 | return PTR_ERR(cd); |
| 492 | } |
| 493 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 494 | if (atomic_dec_return(&cd->wkdep_usecount) == 0) { |
| 495 | pr_debug("clockdomain: hardware will no longer wake up %s " |
| 496 | "after %s wakes up\n", clkdm1->name, clkdm2->name); |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 497 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 498 | omap2_prm_clear_mod_reg_bits((1 << clkdm2->dep_bit), |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 499 | clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP); |
| 500 | } |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 501 | |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * clkdm_read_wkdep - read wakeup dependency state from clkdm2 to clkdm1 |
| 507 | * @clkdm1: wake this struct clockdomain * up (dependent) |
| 508 | * @clkdm2: when this struct clockdomain * wakes up (source) |
| 509 | * |
| 510 | * Return 1 if a hardware wakeup dependency exists wherein @clkdm1 will be |
| 511 | * awoken when @clkdm2 wakes up; 0 if dependency is not set; -EINVAL |
| 512 | * if either clockdomain pointer is invalid; or -ENOENT if the hardware |
| 513 | * is incapable. |
| 514 | * |
| 515 | * REVISIT: Currently this function only represents software-controllable |
| 516 | * wakeup dependencies. Wakeup dependencies fixed in hardware are not |
| 517 | * yet handled here. |
| 518 | */ |
| 519 | int clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) |
| 520 | { |
| 521 | struct clkdm_dep *cd; |
| 522 | |
| 523 | if (!clkdm1 || !clkdm2) |
| 524 | return -EINVAL; |
| 525 | |
| 526 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs); |
| 527 | if (IS_ERR(cd)) { |
| 528 | pr_debug("clockdomain: hardware cannot set/clear wake up of " |
| 529 | "%s when %s wakes up\n", clkdm1->name, clkdm2->name); |
| 530 | return PTR_ERR(cd); |
| 531 | } |
| 532 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 533 | /* XXX It's faster to return the atomic wkdep_usecount */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 534 | return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP, |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 535 | (1 << clkdm2->dep_bit)); |
| 536 | } |
| 537 | |
| 538 | /** |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 539 | * clkdm_clear_all_wkdeps - remove all wakeup dependencies from target clkdm |
| 540 | * @clkdm: struct clockdomain * to remove all wakeup dependencies from |
| 541 | * |
| 542 | * Remove all inter-clockdomain wakeup dependencies that could cause |
| 543 | * @clkdm to wake. Intended to be used during boot to initialize the |
| 544 | * PRCM to a known state, after all clockdomains are put into swsup idle |
| 545 | * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or |
| 546 | * 0 upon success. |
| 547 | */ |
| 548 | int clkdm_clear_all_wkdeps(struct clockdomain *clkdm) |
| 549 | { |
| 550 | struct clkdm_dep *cd; |
| 551 | u32 mask = 0; |
| 552 | |
| 553 | if (!clkdm) |
| 554 | return -EINVAL; |
| 555 | |
| 556 | for (cd = clkdm->wkdep_srcs; cd && cd->clkdm_name; cd++) { |
| 557 | if (!omap_chip_is(cd->omap_chip)) |
| 558 | continue; |
| 559 | |
Paul Walmsley | 6f7f63c | 2010-09-14 15:56:53 -0600 | [diff] [blame] | 560 | if (!cd->clkdm && cd->clkdm_name) |
| 561 | cd->clkdm = _clkdm_lookup(cd->clkdm_name); |
| 562 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 563 | /* PRM accesses are slow, so minimize them */ |
| 564 | mask |= 1 << cd->clkdm->dep_bit; |
| 565 | atomic_set(&cd->wkdep_usecount, 0); |
| 566 | } |
| 567 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 568 | omap2_prm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs, PM_WKDEP); |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | /** |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 574 | * clkdm_add_sleepdep - add a sleep dependency from clkdm2 to clkdm1 |
| 575 | * @clkdm1: prevent this struct clockdomain * from sleeping (dependent) |
| 576 | * @clkdm2: when this struct clockdomain * is active (source) |
| 577 | * |
| 578 | * Prevent @clkdm1 from automatically going inactive (and then to |
| 579 | * retention or off) if @clkdm2 is active. Returns -EINVAL if |
| 580 | * presented with invalid clockdomain pointers or called on a machine |
| 581 | * that does not support software-configurable hardware sleep |
| 582 | * dependencies, -ENOENT if the specified dependency cannot be set in |
| 583 | * hardware, or 0 upon success. |
| 584 | */ |
| 585 | int clkdm_add_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) |
| 586 | { |
| 587 | struct clkdm_dep *cd; |
| 588 | |
| 589 | if (!cpu_is_omap34xx()) |
| 590 | return -EINVAL; |
| 591 | |
| 592 | if (!clkdm1 || !clkdm2) |
| 593 | return -EINVAL; |
| 594 | |
| 595 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs); |
| 596 | if (IS_ERR(cd)) { |
| 597 | pr_debug("clockdomain: hardware cannot set/clear sleep " |
| 598 | "dependency affecting %s from %s\n", clkdm1->name, |
| 599 | clkdm2->name); |
| 600 | return PTR_ERR(cd); |
| 601 | } |
| 602 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 603 | if (atomic_inc_return(&cd->sleepdep_usecount) == 1) { |
| 604 | pr_debug("clockdomain: will prevent %s from sleeping if %s " |
| 605 | "is active\n", clkdm1->name, clkdm2->name); |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 606 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 607 | omap2_cm_set_mod_reg_bits((1 << clkdm2->dep_bit), |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 608 | clkdm1->pwrdm.ptr->prcm_offs, |
| 609 | OMAP3430_CM_SLEEPDEP); |
| 610 | } |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * clkdm_del_sleepdep - remove a sleep dependency from clkdm2 to clkdm1 |
| 617 | * @clkdm1: prevent this struct clockdomain * from sleeping (dependent) |
| 618 | * @clkdm2: when this struct clockdomain * is active (source) |
| 619 | * |
| 620 | * Allow @clkdm1 to automatically go inactive (and then to retention or |
| 621 | * off), independent of the activity state of @clkdm2. Returns -EINVAL |
| 622 | * if presented with invalid clockdomain pointers or called on a machine |
| 623 | * that does not support software-configurable hardware sleep dependencies, |
| 624 | * -ENOENT if the specified dependency cannot be cleared in hardware, or |
| 625 | * 0 upon success. |
| 626 | */ |
| 627 | int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) |
| 628 | { |
| 629 | struct clkdm_dep *cd; |
| 630 | |
| 631 | if (!cpu_is_omap34xx()) |
| 632 | return -EINVAL; |
| 633 | |
| 634 | if (!clkdm1 || !clkdm2) |
| 635 | return -EINVAL; |
| 636 | |
| 637 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs); |
| 638 | if (IS_ERR(cd)) { |
| 639 | pr_debug("clockdomain: hardware cannot set/clear sleep " |
| 640 | "dependency affecting %s from %s\n", clkdm1->name, |
| 641 | clkdm2->name); |
| 642 | return PTR_ERR(cd); |
| 643 | } |
| 644 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 645 | if (atomic_dec_return(&cd->sleepdep_usecount) == 0) { |
| 646 | pr_debug("clockdomain: will no longer prevent %s from " |
| 647 | "sleeping if %s is active\n", clkdm1->name, |
| 648 | clkdm2->name); |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 649 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 650 | omap2_cm_clear_mod_reg_bits((1 << clkdm2->dep_bit), |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 651 | clkdm1->pwrdm.ptr->prcm_offs, |
| 652 | OMAP3430_CM_SLEEPDEP); |
| 653 | } |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 654 | |
| 655 | return 0; |
| 656 | } |
| 657 | |
| 658 | /** |
| 659 | * clkdm_read_sleepdep - read sleep dependency state from clkdm2 to clkdm1 |
| 660 | * @clkdm1: prevent this struct clockdomain * from sleeping (dependent) |
| 661 | * @clkdm2: when this struct clockdomain * is active (source) |
| 662 | * |
| 663 | * Return 1 if a hardware sleep dependency exists wherein @clkdm1 will |
| 664 | * not be allowed to automatically go inactive if @clkdm2 is active; |
| 665 | * 0 if @clkdm1's automatic power state inactivity transition is independent |
| 666 | * of @clkdm2's; -EINVAL if either clockdomain pointer is invalid or called |
| 667 | * on a machine that does not support software-configurable hardware sleep |
| 668 | * dependencies; or -ENOENT if the hardware is incapable. |
| 669 | * |
| 670 | * REVISIT: Currently this function only represents software-controllable |
| 671 | * sleep dependencies. Sleep dependencies fixed in hardware are not |
| 672 | * yet handled here. |
| 673 | */ |
| 674 | int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2) |
| 675 | { |
| 676 | struct clkdm_dep *cd; |
| 677 | |
| 678 | if (!cpu_is_omap34xx()) |
| 679 | return -EINVAL; |
| 680 | |
| 681 | if (!clkdm1 || !clkdm2) |
| 682 | return -EINVAL; |
| 683 | |
| 684 | cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs); |
| 685 | if (IS_ERR(cd)) { |
| 686 | pr_debug("clockdomain: hardware cannot set/clear sleep " |
| 687 | "dependency affecting %s from %s\n", clkdm1->name, |
| 688 | clkdm2->name); |
| 689 | return PTR_ERR(cd); |
| 690 | } |
| 691 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 692 | /* XXX It's faster to return the atomic sleepdep_usecount */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 693 | return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs, |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 694 | OMAP3430_CM_SLEEPDEP, |
| 695 | (1 << clkdm2->dep_bit)); |
| 696 | } |
| 697 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 698 | /** |
| 699 | * clkdm_clear_all_sleepdeps - remove all sleep dependencies from target clkdm |
| 700 | * @clkdm: struct clockdomain * to remove all sleep dependencies from |
| 701 | * |
| 702 | * Remove all inter-clockdomain sleep dependencies that could prevent |
| 703 | * @clkdm from idling. Intended to be used during boot to initialize the |
| 704 | * PRCM to a known state, after all clockdomains are put into swsup idle |
| 705 | * and woken up. Returns -EINVAL if @clkdm pointer is invalid, or |
| 706 | * 0 upon success. |
| 707 | */ |
| 708 | int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm) |
| 709 | { |
| 710 | struct clkdm_dep *cd; |
| 711 | u32 mask = 0; |
| 712 | |
| 713 | if (!cpu_is_omap34xx()) |
| 714 | return -EINVAL; |
| 715 | |
| 716 | if (!clkdm) |
| 717 | return -EINVAL; |
| 718 | |
| 719 | for (cd = clkdm->sleepdep_srcs; cd && cd->clkdm_name; cd++) { |
| 720 | if (!omap_chip_is(cd->omap_chip)) |
| 721 | continue; |
| 722 | |
Paul Walmsley | 6f7f63c | 2010-09-14 15:56:53 -0600 | [diff] [blame] | 723 | if (!cd->clkdm && cd->clkdm_name) |
| 724 | cd->clkdm = _clkdm_lookup(cd->clkdm_name); |
| 725 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 726 | /* PRM accesses are slow, so minimize them */ |
| 727 | mask |= 1 << cd->clkdm->dep_bit; |
| 728 | atomic_set(&cd->sleepdep_usecount, 0); |
| 729 | } |
| 730 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 731 | omap2_prm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs, |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 732 | OMAP3430_CM_SLEEPDEP); |
| 733 | |
| 734 | return 0; |
| 735 | } |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 736 | |
| 737 | /** |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 738 | * omap2_clkdm_clktrctrl_read - read the clkdm's current state transition mode |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 739 | * @clkdm: struct clkdm * of a clockdomain |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 740 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 741 | * Return the clockdomain @clkdm current state transition mode from the |
| 742 | * corresponding domain CM_CLKSTCTRL register. Returns -EINVAL if @clkdm |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 743 | * is NULL or the current mode upon success. |
| 744 | */ |
| 745 | static int omap2_clkdm_clktrctrl_read(struct clockdomain *clkdm) |
| 746 | { |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 747 | u32 v = 0; |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 748 | |
| 749 | if (!clkdm) |
| 750 | return -EINVAL; |
| 751 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 752 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
| 753 | v = __raw_readl(clkdm->clkstctrl_reg); |
| 754 | v &= clkdm->clktrctrl_mask; |
| 755 | v >>= __ffs(clkdm->clktrctrl_mask); |
| 756 | } else if (cpu_is_omap44xx()) { |
| 757 | pr_warn("OMAP4 clockdomain: missing wakeup/sleep deps\n"); |
| 758 | } else { |
| 759 | BUG(); |
| 760 | } |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 761 | |
| 762 | return v; |
| 763 | } |
| 764 | |
| 765 | /** |
| 766 | * omap2_clkdm_sleep - force clockdomain sleep transition |
| 767 | * @clkdm: struct clockdomain * |
| 768 | * |
| 769 | * Instruct the CM to force a sleep transition on the specified |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 770 | * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 771 | * clockdomain does not support software-initiated sleep; 0 upon |
| 772 | * success. |
| 773 | */ |
| 774 | int omap2_clkdm_sleep(struct clockdomain *clkdm) |
| 775 | { |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 776 | u32 bits, v; |
| 777 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 778 | if (!clkdm) |
| 779 | return -EINVAL; |
| 780 | |
| 781 | if (!(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) { |
| 782 | pr_debug("clockdomain: %s does not support forcing " |
| 783 | "sleep via software\n", clkdm->name); |
| 784 | return -EINVAL; |
| 785 | } |
| 786 | |
| 787 | pr_debug("clockdomain: forcing sleep on %s\n", clkdm->name); |
| 788 | |
| 789 | if (cpu_is_omap24xx()) { |
| 790 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 791 | omap2_cm_set_mod_reg_bits(OMAP24XX_FORCESTATE_MASK, |
Abhijit Pagare | 3790300 | 2010-01-26 20:12:51 -0700 | [diff] [blame] | 792 | clkdm->pwrdm.ptr->prcm_offs, OMAP2_PM_PWSTCTRL); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 793 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 794 | } else if (cpu_is_omap34xx()) { |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 795 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 796 | bits = (OMAP34XX_CLKSTCTRL_FORCE_SLEEP << |
| 797 | __ffs(clkdm->clktrctrl_mask)); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 798 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 799 | v = __raw_readl(clkdm->clkstctrl_reg); |
Abhijit Pagare | b099474 | 2010-01-26 20:12:53 -0700 | [diff] [blame] | 800 | v &= ~(clkdm->clktrctrl_mask); |
| 801 | v |= bits; |
| 802 | __raw_writel(v, clkdm->clkstctrl_reg); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 803 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 804 | } else if (cpu_is_omap44xx()) { |
| 805 | |
| 806 | omap4_cminst_clkdm_force_sleep(clkdm->prcm_partition, |
| 807 | clkdm->cm_inst, |
| 808 | clkdm->clkdm_offs); |
| 809 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 810 | } else { |
| 811 | BUG(); |
| 812 | }; |
| 813 | |
| 814 | return 0; |
| 815 | } |
| 816 | |
| 817 | /** |
| 818 | * omap2_clkdm_wakeup - force clockdomain wakeup transition |
| 819 | * @clkdm: struct clockdomain * |
| 820 | * |
| 821 | * Instruct the CM to force a wakeup transition on the specified |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 822 | * clockdomain @clkdm. Returns -EINVAL if @clkdm is NULL or if the |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 823 | * clockdomain does not support software-controlled wakeup; 0 upon |
| 824 | * success. |
| 825 | */ |
| 826 | int omap2_clkdm_wakeup(struct clockdomain *clkdm) |
| 827 | { |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 828 | u32 bits, v; |
| 829 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 830 | if (!clkdm) |
| 831 | return -EINVAL; |
| 832 | |
| 833 | if (!(clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)) { |
| 834 | pr_debug("clockdomain: %s does not support forcing " |
| 835 | "wakeup via software\n", clkdm->name); |
| 836 | return -EINVAL; |
| 837 | } |
| 838 | |
| 839 | pr_debug("clockdomain: forcing wakeup on %s\n", clkdm->name); |
| 840 | |
| 841 | if (cpu_is_omap24xx()) { |
| 842 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 843 | omap2_cm_clear_mod_reg_bits(OMAP24XX_FORCESTATE_MASK, |
Abhijit Pagare | 3790300 | 2010-01-26 20:12:51 -0700 | [diff] [blame] | 844 | clkdm->pwrdm.ptr->prcm_offs, OMAP2_PM_PWSTCTRL); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 845 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 846 | } else if (cpu_is_omap34xx()) { |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 847 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 848 | bits = (OMAP34XX_CLKSTCTRL_FORCE_WAKEUP << |
| 849 | __ffs(clkdm->clktrctrl_mask)); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 850 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 851 | v = __raw_readl(clkdm->clkstctrl_reg); |
Abhijit Pagare | b099474 | 2010-01-26 20:12:53 -0700 | [diff] [blame] | 852 | v &= ~(clkdm->clktrctrl_mask); |
| 853 | v |= bits; |
| 854 | __raw_writel(v, clkdm->clkstctrl_reg); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 855 | |
Paul Walmsley | bd2122c | 2010-12-21 21:05:15 -0700 | [diff] [blame^] | 856 | } else if (cpu_is_omap44xx()) { |
| 857 | |
| 858 | omap4_cminst_clkdm_force_wakeup(clkdm->prcm_partition, |
| 859 | clkdm->cm_inst, |
| 860 | clkdm->clkdm_offs); |
| 861 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 862 | } else { |
| 863 | BUG(); |
| 864 | }; |
| 865 | |
| 866 | return 0; |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * omap2_clkdm_allow_idle - enable hwsup idle transitions for clkdm |
| 871 | * @clkdm: struct clockdomain * |
| 872 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 873 | * Allow the hardware to automatically switch the clockdomain @clkdm into |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 874 | * active or idle states, as needed by downstream clocks. If the |
| 875 | * clockdomain has any downstream clocks enabled in the clock |
| 876 | * framework, wkdep/sleepdep autodependencies are added; this is so |
| 877 | * device drivers can read and write to the device. No return value. |
| 878 | */ |
| 879 | void omap2_clkdm_allow_idle(struct clockdomain *clkdm) |
| 880 | { |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 881 | if (!clkdm) |
| 882 | return; |
| 883 | |
| 884 | if (!(clkdm->flags & CLKDM_CAN_ENABLE_AUTO)) { |
| 885 | pr_debug("clock: automatic idle transitions cannot be enabled " |
| 886 | "on clockdomain %s\n", clkdm->name); |
| 887 | return; |
| 888 | } |
| 889 | |
| 890 | pr_debug("clockdomain: enabling automatic idle transitions for %s\n", |
| 891 | clkdm->name); |
| 892 | |
Abhijit Pagare | 91808a8 | 2010-02-22 22:09:07 -0700 | [diff] [blame] | 893 | /* |
| 894 | * XXX This should be removed once TI adds wakeup/sleep |
| 895 | * dependency code and data for OMAP4. |
| 896 | */ |
| 897 | if (cpu_is_omap44xx()) { |
| 898 | WARN_ONCE(1, "clockdomain: OMAP4 wakeup/sleep dependency " |
| 899 | "support is not yet implemented\n"); |
| 900 | } else { |
| 901 | if (atomic_read(&clkdm->usecount) > 0) |
| 902 | _clkdm_add_autodeps(clkdm); |
| 903 | } |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 904 | |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 905 | _enable_hwsup(clkdm); |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 906 | |
| 907 | pwrdm_clkdm_state_switch(clkdm); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /** |
| 911 | * omap2_clkdm_deny_idle - disable hwsup idle transitions for clkdm |
| 912 | * @clkdm: struct clockdomain * |
| 913 | * |
| 914 | * Prevent the hardware from automatically switching the clockdomain |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 915 | * @clkdm into inactive or idle states. If the clockdomain has |
| 916 | * downstream clocks enabled in the clock framework, wkdep/sleepdep |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 917 | * autodependencies are removed. No return value. |
| 918 | */ |
| 919 | void omap2_clkdm_deny_idle(struct clockdomain *clkdm) |
| 920 | { |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 921 | if (!clkdm) |
| 922 | return; |
| 923 | |
| 924 | if (!(clkdm->flags & CLKDM_CAN_DISABLE_AUTO)) { |
| 925 | pr_debug("clockdomain: automatic idle transitions cannot be " |
| 926 | "disabled on %s\n", clkdm->name); |
| 927 | return; |
| 928 | } |
| 929 | |
| 930 | pr_debug("clockdomain: disabling automatic idle transitions for %s\n", |
| 931 | clkdm->name); |
| 932 | |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 933 | _disable_hwsup(clkdm); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 934 | |
Abhijit Pagare | 91808a8 | 2010-02-22 22:09:07 -0700 | [diff] [blame] | 935 | /* |
| 936 | * XXX This should be removed once TI adds wakeup/sleep |
| 937 | * dependency code and data for OMAP4. |
| 938 | */ |
| 939 | if (cpu_is_omap44xx()) { |
| 940 | WARN_ONCE(1, "clockdomain: OMAP4 wakeup/sleep dependency " |
| 941 | "support is not yet implemented\n"); |
| 942 | } else { |
| 943 | if (atomic_read(&clkdm->usecount) > 0) |
| 944 | _clkdm_del_autodeps(clkdm); |
| 945 | } |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | |
| 949 | /* Clockdomain-to-clock framework interface code */ |
| 950 | |
| 951 | /** |
| 952 | * omap2_clkdm_clk_enable - add an enabled downstream clock to this clkdm |
| 953 | * @clkdm: struct clockdomain * |
| 954 | * @clk: struct clk * of the enabled downstream clock |
| 955 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 956 | * Increment the usecount of the clockdomain @clkdm and ensure that it |
| 957 | * is awake before @clk is enabled. Intended to be called by |
| 958 | * clk_enable() code. If the clockdomain is in software-supervised |
| 959 | * idle mode, force the clockdomain to wake. If the clockdomain is in |
| 960 | * hardware-supervised idle mode, add clkdm-pwrdm autodependencies, to |
| 961 | * ensure that devices in the clockdomain can be read from/written to |
| 962 | * by on-chip processors. Returns -EINVAL if passed null pointers; |
| 963 | * returns 0 upon success or if the clockdomain is in hwsup idle mode. |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 964 | */ |
| 965 | int omap2_clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk) |
| 966 | { |
| 967 | int v; |
| 968 | |
| 969 | /* |
| 970 | * XXX Rewrite this code to maintain a list of enabled |
| 971 | * downstream clocks for debugging purposes? |
| 972 | */ |
| 973 | |
Paul Walmsley | 30962d9 | 2010-02-22 22:09:38 -0700 | [diff] [blame] | 974 | if (!clkdm || !clk) |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 975 | return -EINVAL; |
| 976 | |
| 977 | if (atomic_inc_return(&clkdm->usecount) > 1) |
| 978 | return 0; |
| 979 | |
| 980 | /* Clockdomain now has one enabled downstream clock */ |
| 981 | |
| 982 | pr_debug("clockdomain: clkdm %s: clk %s now enabled\n", clkdm->name, |
| 983 | clk->name); |
| 984 | |
Paul Walmsley | 30962d9 | 2010-02-22 22:09:38 -0700 | [diff] [blame] | 985 | if (!clkdm->clkstctrl_reg) |
| 986 | return 0; |
| 987 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 988 | v = omap2_clkdm_clktrctrl_read(clkdm); |
| 989 | |
| 990 | if ((cpu_is_omap34xx() && v == OMAP34XX_CLKSTCTRL_ENABLE_AUTO) || |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 991 | (cpu_is_omap24xx() && v == OMAP24XX_CLKSTCTRL_ENABLE_AUTO)) { |
| 992 | /* Disable HW transitions when we are changing deps */ |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 993 | _disable_hwsup(clkdm); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 994 | _clkdm_add_autodeps(clkdm); |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 995 | _enable_hwsup(clkdm); |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 996 | } else { |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 997 | omap2_clkdm_wakeup(clkdm); |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 998 | } |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 999 | |
Tomi Valkeinen | 054ce50 | 2009-01-27 19:44:31 -0700 | [diff] [blame] | 1000 | pwrdm_wait_transition(clkdm->pwrdm.ptr); |
Peter 'p2' De Schrijver | fe617af | 2008-10-15 17:48:44 +0300 | [diff] [blame] | 1001 | pwrdm_clkdm_state_switch(clkdm); |
Tomi Valkeinen | 054ce50 | 2009-01-27 19:44:31 -0700 | [diff] [blame] | 1002 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 1003 | return 0; |
| 1004 | } |
| 1005 | |
| 1006 | /** |
| 1007 | * omap2_clkdm_clk_disable - remove an enabled downstream clock from this clkdm |
| 1008 | * @clkdm: struct clockdomain * |
| 1009 | * @clk: struct clk * of the disabled downstream clock |
| 1010 | * |
Paul Walmsley | f0271d6 | 2010-01-26 20:13:02 -0700 | [diff] [blame] | 1011 | * Decrement the usecount of this clockdomain @clkdm when @clk is |
| 1012 | * disabled. Intended to be called by clk_disable() code. If the |
| 1013 | * clockdomain usecount goes to 0, put the clockdomain to sleep |
| 1014 | * (software-supervised mode) or remove the clkdm autodependencies |
| 1015 | * (hardware-supervised mode). Returns -EINVAL if passed null |
| 1016 | * pointers; -ERANGE if the @clkdm usecount underflows and debugging |
| 1017 | * is enabled; or returns 0 upon success or if the clockdomain is in |
| 1018 | * hwsup idle mode. |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 1019 | */ |
| 1020 | int omap2_clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk) |
| 1021 | { |
| 1022 | int v; |
| 1023 | |
| 1024 | /* |
| 1025 | * XXX Rewrite this code to maintain a list of enabled |
| 1026 | * downstream clocks for debugging purposes? |
| 1027 | */ |
| 1028 | |
Paul Walmsley | 30962d9 | 2010-02-22 22:09:38 -0700 | [diff] [blame] | 1029 | if (!clkdm || !clk) |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 1030 | return -EINVAL; |
| 1031 | |
| 1032 | #ifdef DEBUG |
| 1033 | if (atomic_read(&clkdm->usecount) == 0) { |
| 1034 | WARN_ON(1); /* underflow */ |
| 1035 | return -ERANGE; |
| 1036 | } |
| 1037 | #endif |
| 1038 | |
| 1039 | if (atomic_dec_return(&clkdm->usecount) > 0) |
| 1040 | return 0; |
| 1041 | |
| 1042 | /* All downstream clocks of this clockdomain are now disabled */ |
| 1043 | |
| 1044 | pr_debug("clockdomain: clkdm %s: clk %s now disabled\n", clkdm->name, |
| 1045 | clk->name); |
| 1046 | |
Paul Walmsley | 30962d9 | 2010-02-22 22:09:38 -0700 | [diff] [blame] | 1047 | if (!clkdm->clkstctrl_reg) |
| 1048 | return 0; |
| 1049 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 1050 | v = omap2_clkdm_clktrctrl_read(clkdm); |
| 1051 | |
| 1052 | if ((cpu_is_omap34xx() && v == OMAP34XX_CLKSTCTRL_ENABLE_AUTO) || |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 1053 | (cpu_is_omap24xx() && v == OMAP24XX_CLKSTCTRL_ENABLE_AUTO)) { |
| 1054 | /* Disable HW transitions when we are changing deps */ |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 1055 | _disable_hwsup(clkdm); |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 1056 | _clkdm_del_autodeps(clkdm); |
Paul Walmsley | b170fbe | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 1057 | _enable_hwsup(clkdm); |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 1058 | } else { |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 1059 | omap2_clkdm_sleep(clkdm); |
Kalle Jokiniemi | a0219fb | 2009-10-14 16:40:37 -0600 | [diff] [blame] | 1060 | } |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 1061 | |
Peter 'p2' De Schrijver | fe617af | 2008-10-15 17:48:44 +0300 | [diff] [blame] | 1062 | pwrdm_clkdm_state_switch(clkdm); |
| 1063 | |
Paul Walmsley | d459bfe | 2008-08-19 11:08:43 +0300 | [diff] [blame] | 1064 | return 0; |
| 1065 | } |
| 1066 | |