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