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