Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Tony Lindgren | b915855 | 2005-07-10 19:58:14 +0100 | [diff] [blame] | 2 | * linux/arch/arm/plat-omap/clock.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 4 | * Copyright (C) 2004 - 2005 Nokia corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com> |
| 6 | * |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 7 | * Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com> |
| 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 13 | #include <linux/version.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/list.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/err.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 20 | #include <linux/string.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 21 | #include <linux/clk.h> |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 22 | #include <linux/mutex.h> |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 25 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/semaphore.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 28 | #include <asm/arch/clock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Juha Yrjola | 7df3450 | 2006-06-26 16:16:22 -0700 | [diff] [blame] | 30 | static LIST_HEAD(clocks); |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 31 | static DEFINE_MUTEX(clocks_mutex); |
Juha Yrjola | 7df3450 | 2006-06-26 16:16:22 -0700 | [diff] [blame] | 32 | static DEFINE_SPINLOCK(clockfw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 34 | static struct clk_functions *arch_clock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Juha Yrjola | 0ce3356 | 2006-12-06 17:13:49 -0800 | [diff] [blame] | 36 | #ifdef CONFIG_PM_DEBUG |
| 37 | |
| 38 | static void print_parents(struct clk *clk) |
| 39 | { |
| 40 | struct clk *p; |
| 41 | int printed = 0; |
| 42 | |
| 43 | list_for_each_entry(p, &clocks, node) { |
| 44 | if (p->parent == clk && p->usecount) { |
| 45 | if (!clk->usecount && !printed) { |
| 46 | printk("MISMATCH: %s\n", clk->name); |
| 47 | printed = 1; |
| 48 | } |
| 49 | printk("\t%-15s\n", p->name); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | void clk_print_usecounts(void) |
| 55 | { |
| 56 | unsigned long flags; |
| 57 | struct clk *p; |
| 58 | |
| 59 | spin_lock_irqsave(&clockfw_lock, flags); |
| 60 | list_for_each_entry(p, &clocks, node) { |
| 61 | if (p->usecount) |
| 62 | printk("%-15s: %d\n", p->name, p->usecount); |
| 63 | print_parents(p); |
| 64 | |
| 65 | } |
| 66 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 67 | } |
| 68 | |
| 69 | #endif |
| 70 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 71 | /*------------------------------------------------------------------------- |
Tony Lindgren | f07adc5 | 2006-01-17 15:27:09 -0800 | [diff] [blame] | 72 | * Standard clock functions defined in include/linux/clk.h |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 73 | *-------------------------------------------------------------------------*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 75 | /* |
| 76 | * Returns a clock. Note that we first try to use device id on the bus |
| 77 | * and clock name. If this fails, we try to use clock name only. |
| 78 | */ |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 79 | struct clk * clk_get(struct device *dev, const char *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
| 81 | struct clk *p, *clk = ERR_PTR(-ENOENT); |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 82 | int idno; |
| 83 | |
| 84 | if (dev == NULL || dev->bus != &platform_bus_type) |
| 85 | idno = -1; |
| 86 | else |
| 87 | idno = to_platform_device(dev)->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 89 | mutex_lock(&clocks_mutex); |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 90 | |
| 91 | list_for_each_entry(p, &clocks, node) { |
| 92 | if (p->id == idno && |
| 93 | strcmp(id, p->name) == 0 && try_module_get(p->owner)) { |
| 94 | clk = p; |
Tony Lindgren | 67d4d83 | 2006-04-09 22:21:05 +0100 | [diff] [blame] | 95 | goto found; |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | list_for_each_entry(p, &clocks, node) { |
| 100 | if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) { |
| 101 | clk = p; |
| 102 | break; |
| 103 | } |
| 104 | } |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 105 | |
Tony Lindgren | 67d4d83 | 2006-04-09 22:21:05 +0100 | [diff] [blame] | 106 | found: |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 107 | mutex_unlock(&clocks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | return clk; |
| 110 | } |
| 111 | EXPORT_SYMBOL(clk_get); |
| 112 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 113 | int clk_enable(struct clk *clk) |
| 114 | { |
| 115 | unsigned long flags; |
| 116 | int ret = 0; |
| 117 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 118 | if (clk == NULL || IS_ERR(clk)) |
| 119 | return -EINVAL; |
| 120 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 121 | spin_lock_irqsave(&clockfw_lock, flags); |
Tony Lindgren | f07adc5 | 2006-01-17 15:27:09 -0800 | [diff] [blame] | 122 | if (arch_clock->clk_enable) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 123 | ret = arch_clock->clk_enable(clk); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 124 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 125 | |
| 126 | return ret; |
| 127 | } |
| 128 | EXPORT_SYMBOL(clk_enable); |
| 129 | |
| 130 | void clk_disable(struct clk *clk) |
| 131 | { |
| 132 | unsigned long flags; |
| 133 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 134 | if (clk == NULL || IS_ERR(clk)) |
| 135 | return; |
| 136 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 137 | spin_lock_irqsave(&clockfw_lock, flags); |
Juha Yrjola | dee4564 | 2006-09-25 12:41:47 +0300 | [diff] [blame] | 138 | BUG_ON(clk->usecount == 0); |
Tony Lindgren | f07adc5 | 2006-01-17 15:27:09 -0800 | [diff] [blame] | 139 | if (arch_clock->clk_disable) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 140 | arch_clock->clk_disable(clk); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 141 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 142 | } |
| 143 | EXPORT_SYMBOL(clk_disable); |
| 144 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 145 | int clk_get_usecount(struct clk *clk) |
| 146 | { |
| 147 | unsigned long flags; |
| 148 | int ret = 0; |
| 149 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 150 | if (clk == NULL || IS_ERR(clk)) |
| 151 | return 0; |
| 152 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 153 | spin_lock_irqsave(&clockfw_lock, flags); |
| 154 | ret = clk->usecount; |
| 155 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 156 | |
| 157 | return ret; |
| 158 | } |
| 159 | EXPORT_SYMBOL(clk_get_usecount); |
| 160 | |
| 161 | unsigned long clk_get_rate(struct clk *clk) |
| 162 | { |
| 163 | unsigned long flags; |
| 164 | unsigned long ret = 0; |
| 165 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 166 | if (clk == NULL || IS_ERR(clk)) |
| 167 | return 0; |
| 168 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 169 | spin_lock_irqsave(&clockfw_lock, flags); |
| 170 | ret = clk->rate; |
| 171 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 172 | |
| 173 | return ret; |
| 174 | } |
| 175 | EXPORT_SYMBOL(clk_get_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | void clk_put(struct clk *clk) |
| 178 | { |
| 179 | if (clk && !IS_ERR(clk)) |
| 180 | module_put(clk->owner); |
| 181 | } |
| 182 | EXPORT_SYMBOL(clk_put); |
| 183 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 184 | /*------------------------------------------------------------------------- |
Tony Lindgren | f07adc5 | 2006-01-17 15:27:09 -0800 | [diff] [blame] | 185 | * Optional clock functions defined in include/linux/clk.h |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 186 | *-------------------------------------------------------------------------*/ |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | long clk_round_rate(struct clk *clk, unsigned long rate) |
| 189 | { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 190 | unsigned long flags; |
| 191 | long ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 193 | if (clk == NULL || IS_ERR(clk)) |
| 194 | return ret; |
| 195 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 196 | spin_lock_irqsave(&clockfw_lock, flags); |
| 197 | if (arch_clock->clk_round_rate) |
| 198 | ret = arch_clock->clk_round_rate(clk, rate); |
| 199 | spin_unlock_irqrestore(&clockfw_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 201 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | EXPORT_SYMBOL(clk_round_rate); |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | int clk_set_rate(struct clk *clk, unsigned long rate) |
| 206 | { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 207 | unsigned long flags; |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 208 | int ret = -EINVAL; |
| 209 | |
| 210 | if (clk == NULL || IS_ERR(clk)) |
| 211 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 213 | spin_lock_irqsave(&clockfw_lock, flags); |
| 214 | if (arch_clock->clk_set_rate) |
| 215 | ret = arch_clock->clk_set_rate(clk, rate); |
| 216 | spin_unlock_irqrestore(&clockfw_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | return ret; |
| 219 | } |
| 220 | EXPORT_SYMBOL(clk_set_rate); |
| 221 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 222 | int clk_set_parent(struct clk *clk, struct clk *parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 224 | unsigned long flags; |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 225 | int ret = -EINVAL; |
| 226 | |
| 227 | if (clk == NULL || IS_ERR(clk) || parent == NULL || IS_ERR(parent)) |
| 228 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 230 | spin_lock_irqsave(&clockfw_lock, flags); |
| 231 | if (arch_clock->clk_set_parent) |
| 232 | ret = arch_clock->clk_set_parent(clk, parent); |
| 233 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 234 | |
| 235 | return ret; |
| 236 | } |
| 237 | EXPORT_SYMBOL(clk_set_parent); |
| 238 | |
| 239 | struct clk *clk_get_parent(struct clk *clk) |
| 240 | { |
| 241 | unsigned long flags; |
| 242 | struct clk * ret = NULL; |
| 243 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 244 | if (clk == NULL || IS_ERR(clk)) |
| 245 | return ret; |
| 246 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 247 | spin_lock_irqsave(&clockfw_lock, flags); |
| 248 | if (arch_clock->clk_get_parent) |
| 249 | ret = arch_clock->clk_get_parent(clk); |
| 250 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 251 | |
| 252 | return ret; |
| 253 | } |
| 254 | EXPORT_SYMBOL(clk_get_parent); |
| 255 | |
| 256 | /*------------------------------------------------------------------------- |
| 257 | * OMAP specific clock functions shared between omap1 and omap2 |
| 258 | *-------------------------------------------------------------------------*/ |
| 259 | |
| 260 | unsigned int __initdata mpurate; |
| 261 | |
| 262 | /* |
| 263 | * By default we use the rate set by the bootloader. |
| 264 | * You can override this with mpurate= cmdline option. |
| 265 | */ |
| 266 | static int __init omap_clk_setup(char *str) |
| 267 | { |
| 268 | get_option(&str, &mpurate); |
| 269 | |
| 270 | if (!mpurate) |
| 271 | return 1; |
| 272 | |
| 273 | if (mpurate < 1000) |
| 274 | mpurate *= 1000000; |
| 275 | |
| 276 | return 1; |
| 277 | } |
| 278 | __setup("mpurate=", omap_clk_setup); |
| 279 | |
| 280 | /* Used for clocks that always have same value as the parent clock */ |
| 281 | void followparent_recalc(struct clk *clk) |
| 282 | { |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 283 | if (clk == NULL || IS_ERR(clk)) |
| 284 | return; |
| 285 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 286 | clk->rate = clk->parent->rate; |
Imre Deak | b1465bf | 2007-03-06 03:52:01 -0800 | [diff] [blame] | 287 | if (unlikely(clk->flags & RATE_PROPAGATES)) |
| 288 | propagate_rate(clk); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /* Propagate rate to children */ |
| 292 | void propagate_rate(struct clk * tclk) |
| 293 | { |
| 294 | struct clk *clkp; |
| 295 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 296 | if (tclk == NULL || IS_ERR(tclk)) |
| 297 | return; |
| 298 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 299 | list_for_each_entry(clkp, &clocks, node) { |
| 300 | if (likely(clkp->parent != tclk)) |
| 301 | continue; |
| 302 | if (likely((u32)clkp->recalc)) |
| 303 | clkp->recalc(clkp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | int clk_register(struct clk *clk) |
| 308 | { |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 309 | if (clk == NULL || IS_ERR(clk)) |
| 310 | return -EINVAL; |
| 311 | |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 312 | mutex_lock(&clocks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | list_add(&clk->node, &clocks); |
| 314 | if (clk->init) |
| 315 | clk->init(clk); |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 316 | mutex_unlock(&clocks_mutex); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | return 0; |
| 319 | } |
| 320 | EXPORT_SYMBOL(clk_register); |
| 321 | |
| 322 | void clk_unregister(struct clk *clk) |
| 323 | { |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 324 | if (clk == NULL || IS_ERR(clk)) |
| 325 | return; |
| 326 | |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 327 | mutex_lock(&clocks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | list_del(&clk->node); |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 329 | mutex_unlock(&clocks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | EXPORT_SYMBOL(clk_unregister); |
| 332 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 333 | void clk_deny_idle(struct clk *clk) |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 334 | { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 335 | unsigned long flags; |
| 336 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 337 | if (clk == NULL || IS_ERR(clk)) |
| 338 | return; |
| 339 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 340 | spin_lock_irqsave(&clockfw_lock, flags); |
| 341 | if (arch_clock->clk_deny_idle) |
| 342 | arch_clock->clk_deny_idle(clk); |
| 343 | spin_unlock_irqrestore(&clockfw_lock, flags); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 344 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 345 | EXPORT_SYMBOL(clk_deny_idle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 347 | void clk_allow_idle(struct clk *clk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 349 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 351 | if (clk == NULL || IS_ERR(clk)) |
| 352 | return; |
| 353 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 354 | spin_lock_irqsave(&clockfw_lock, flags); |
| 355 | if (arch_clock->clk_allow_idle) |
| 356 | arch_clock->clk_allow_idle(clk); |
| 357 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 358 | } |
| 359 | EXPORT_SYMBOL(clk_allow_idle); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 360 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 361 | /*-------------------------------------------------------------------------*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Tony Lindgren | 90afd5c | 2006-09-25 13:27:20 +0300 | [diff] [blame] | 363 | #ifdef CONFIG_OMAP_RESET_CLOCKS |
| 364 | /* |
| 365 | * Disable any unused clocks left on by the bootloader |
| 366 | */ |
| 367 | static int __init clk_disable_unused(void) |
| 368 | { |
| 369 | struct clk *ck; |
| 370 | unsigned long flags; |
| 371 | |
| 372 | list_for_each_entry(ck, &clocks, node) { |
| 373 | if (ck->usecount > 0 || (ck->flags & ALWAYS_ENABLED) || |
| 374 | ck->enable_reg == 0) |
| 375 | continue; |
| 376 | |
| 377 | spin_lock_irqsave(&clockfw_lock, flags); |
| 378 | if (arch_clock->clk_disable_unused) |
| 379 | arch_clock->clk_disable_unused(ck); |
| 380 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 381 | } |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | late_initcall(clk_disable_unused); |
| 386 | #endif |
| 387 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 388 | int __init clk_init(struct clk_functions * custom_clocks) |
| 389 | { |
| 390 | if (!custom_clocks) { |
| 391 | printk(KERN_ERR "No custom clock functions registered\n"); |
| 392 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 395 | arch_clock = custom_clocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
| 397 | return 0; |
| 398 | } |