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 | * |
Hiroshi DOYU | 137b3ee | 2008-07-03 12:24:41 +0300 | [diff] [blame] | 4 | * Copyright (C) 2004 - 2008 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/kernel.h> |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 14 | #include <linux/init.h> |
| 15 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/list.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/err.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 19 | #include <linux/string.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 20 | #include <linux/clk.h> |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 21 | #include <linux/mutex.h> |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
Russell King | b851cb2 | 2008-05-22 16:38:50 +0100 | [diff] [blame] | 23 | #include <linux/cpufreq.h> |
Hiroshi DOYU | 137b3ee | 2008-07-03 12:24:41 +0300 | [diff] [blame] | 24 | #include <linux/debugfs.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 25 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 27 | #include <mach/clock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Juha Yrjola | 7df3450 | 2006-06-26 16:16:22 -0700 | [diff] [blame] | 29 | static LIST_HEAD(clocks); |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 30 | static DEFINE_MUTEX(clocks_mutex); |
Juha Yrjola | 7df3450 | 2006-06-26 16:16:22 -0700 | [diff] [blame] | 31 | static DEFINE_SPINLOCK(clockfw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 33 | static struct clk_functions *arch_clock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 35 | /*------------------------------------------------------------------------- |
Tony Lindgren | f07adc5 | 2006-01-17 15:27:09 -0800 | [diff] [blame] | 36 | * Standard clock functions defined in include/linux/clk.h |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 37 | *-------------------------------------------------------------------------*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 39 | /* |
| 40 | * Returns a clock. Note that we first try to use device id on the bus |
| 41 | * and clock name. If this fails, we try to use clock name only. |
| 42 | */ |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 43 | struct clk * clk_get(struct device *dev, const char *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
| 45 | struct clk *p, *clk = ERR_PTR(-ENOENT); |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 46 | int idno; |
| 47 | |
| 48 | if (dev == NULL || dev->bus != &platform_bus_type) |
| 49 | idno = -1; |
| 50 | else |
| 51 | idno = to_platform_device(dev)->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 53 | mutex_lock(&clocks_mutex); |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 54 | |
| 55 | list_for_each_entry(p, &clocks, node) { |
Russell King | eee5b19 | 2008-11-04 21:42:54 +0000 | [diff] [blame] | 56 | if (p->id == idno && strcmp(id, p->name) == 0) { |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 57 | clk = p; |
Tony Lindgren | 67d4d83 | 2006-04-09 22:21:05 +0100 | [diff] [blame] | 58 | goto found; |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | list_for_each_entry(p, &clocks, node) { |
Russell King | eee5b19 | 2008-11-04 21:42:54 +0000 | [diff] [blame] | 63 | if (strcmp(id, p->name) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | clk = p; |
| 65 | break; |
| 66 | } |
| 67 | } |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 68 | |
Tony Lindgren | 67d4d83 | 2006-04-09 22:21:05 +0100 | [diff] [blame] | 69 | found: |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 70 | mutex_unlock(&clocks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | return clk; |
| 73 | } |
| 74 | EXPORT_SYMBOL(clk_get); |
| 75 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 76 | int clk_enable(struct clk *clk) |
| 77 | { |
| 78 | unsigned long flags; |
| 79 | int ret = 0; |
| 80 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 81 | if (clk == NULL || IS_ERR(clk)) |
| 82 | return -EINVAL; |
| 83 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 84 | spin_lock_irqsave(&clockfw_lock, flags); |
Tony Lindgren | f07adc5 | 2006-01-17 15:27:09 -0800 | [diff] [blame] | 85 | if (arch_clock->clk_enable) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 86 | ret = arch_clock->clk_enable(clk); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 87 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 88 | |
| 89 | return ret; |
| 90 | } |
| 91 | EXPORT_SYMBOL(clk_enable); |
| 92 | |
| 93 | void clk_disable(struct clk *clk) |
| 94 | { |
| 95 | unsigned long flags; |
| 96 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 97 | if (clk == NULL || IS_ERR(clk)) |
| 98 | return; |
| 99 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 100 | spin_lock_irqsave(&clockfw_lock, flags); |
Tony Lindgren | 7cf9577 | 2007-08-07 05:20:00 -0700 | [diff] [blame] | 101 | if (clk->usecount == 0) { |
| 102 | printk(KERN_ERR "Trying disable clock %s with 0 usecount\n", |
| 103 | clk->name); |
| 104 | WARN_ON(1); |
| 105 | goto out; |
| 106 | } |
| 107 | |
Tony Lindgren | f07adc5 | 2006-01-17 15:27:09 -0800 | [diff] [blame] | 108 | if (arch_clock->clk_disable) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 109 | arch_clock->clk_disable(clk); |
Tony Lindgren | 7cf9577 | 2007-08-07 05:20:00 -0700 | [diff] [blame] | 110 | |
| 111 | out: |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 112 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 113 | } |
| 114 | EXPORT_SYMBOL(clk_disable); |
| 115 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 116 | int clk_get_usecount(struct clk *clk) |
| 117 | { |
| 118 | unsigned long flags; |
| 119 | int ret = 0; |
| 120 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 121 | if (clk == NULL || IS_ERR(clk)) |
| 122 | return 0; |
| 123 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 124 | spin_lock_irqsave(&clockfw_lock, flags); |
| 125 | ret = clk->usecount; |
| 126 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 127 | |
| 128 | return ret; |
| 129 | } |
| 130 | EXPORT_SYMBOL(clk_get_usecount); |
| 131 | |
| 132 | unsigned long clk_get_rate(struct clk *clk) |
| 133 | { |
| 134 | unsigned long flags; |
| 135 | unsigned long ret = 0; |
| 136 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 137 | if (clk == NULL || IS_ERR(clk)) |
| 138 | return 0; |
| 139 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 140 | spin_lock_irqsave(&clockfw_lock, flags); |
| 141 | ret = clk->rate; |
| 142 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 143 | |
| 144 | return ret; |
| 145 | } |
| 146 | EXPORT_SYMBOL(clk_get_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | void clk_put(struct clk *clk) |
| 149 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | EXPORT_SYMBOL(clk_put); |
| 152 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 153 | /*------------------------------------------------------------------------- |
Tony Lindgren | f07adc5 | 2006-01-17 15:27:09 -0800 | [diff] [blame] | 154 | * Optional clock functions defined in include/linux/clk.h |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 155 | *-------------------------------------------------------------------------*/ |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | long clk_round_rate(struct clk *clk, unsigned long rate) |
| 158 | { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 159 | unsigned long flags; |
| 160 | long ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 162 | if (clk == NULL || IS_ERR(clk)) |
| 163 | return ret; |
| 164 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 165 | spin_lock_irqsave(&clockfw_lock, flags); |
| 166 | if (arch_clock->clk_round_rate) |
| 167 | ret = arch_clock->clk_round_rate(clk, rate); |
| 168 | spin_unlock_irqrestore(&clockfw_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 170 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | EXPORT_SYMBOL(clk_round_rate); |
| 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | int clk_set_rate(struct clk *clk, unsigned long rate) |
| 175 | { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 176 | unsigned long flags; |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 177 | int ret = -EINVAL; |
| 178 | |
| 179 | if (clk == NULL || IS_ERR(clk)) |
| 180 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 182 | spin_lock_irqsave(&clockfw_lock, flags); |
| 183 | if (arch_clock->clk_set_rate) |
| 184 | ret = arch_clock->clk_set_rate(clk, rate); |
Russell King | c6af450 | 2008-11-13 13:01:32 +0000 | [diff] [blame^] | 185 | if (ret == 0 && (clk->flags & RATE_PROPAGATES)) |
| 186 | propagate_rate(clk); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 187 | spin_unlock_irqrestore(&clockfw_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | return ret; |
| 190 | } |
| 191 | EXPORT_SYMBOL(clk_set_rate); |
| 192 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 193 | int clk_set_parent(struct clk *clk, struct clk *parent) |
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 | unsigned long flags; |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 196 | int ret = -EINVAL; |
| 197 | |
| 198 | if (clk == NULL || IS_ERR(clk) || parent == NULL || IS_ERR(parent)) |
| 199 | return ret; |
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 | spin_lock_irqsave(&clockfw_lock, flags); |
| 202 | if (arch_clock->clk_set_parent) |
Russell King | c6af450 | 2008-11-13 13:01:32 +0000 | [diff] [blame^] | 203 | ret = arch_clock->clk_set_parent(clk, parent); |
| 204 | if (ret == 0 && (clk->flags & RATE_PROPAGATES)) |
| 205 | propagate_rate(clk); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 206 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 207 | |
| 208 | return ret; |
| 209 | } |
| 210 | EXPORT_SYMBOL(clk_set_parent); |
| 211 | |
| 212 | struct clk *clk_get_parent(struct clk *clk) |
| 213 | { |
Russell King | 2e777bf | 2009-02-08 17:49:22 +0000 | [diff] [blame] | 214 | return clk->parent; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 215 | } |
| 216 | EXPORT_SYMBOL(clk_get_parent); |
| 217 | |
| 218 | /*------------------------------------------------------------------------- |
| 219 | * OMAP specific clock functions shared between omap1 and omap2 |
| 220 | *-------------------------------------------------------------------------*/ |
| 221 | |
| 222 | unsigned int __initdata mpurate; |
| 223 | |
| 224 | /* |
| 225 | * By default we use the rate set by the bootloader. |
| 226 | * You can override this with mpurate= cmdline option. |
| 227 | */ |
| 228 | static int __init omap_clk_setup(char *str) |
| 229 | { |
| 230 | get_option(&str, &mpurate); |
| 231 | |
| 232 | if (!mpurate) |
| 233 | return 1; |
| 234 | |
| 235 | if (mpurate < 1000) |
| 236 | mpurate *= 1000000; |
| 237 | |
| 238 | return 1; |
| 239 | } |
| 240 | __setup("mpurate=", omap_clk_setup); |
| 241 | |
| 242 | /* Used for clocks that always have same value as the parent clock */ |
| 243 | void followparent_recalc(struct clk *clk) |
| 244 | { |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 245 | if (clk == NULL || IS_ERR(clk)) |
| 246 | return; |
| 247 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 248 | clk->rate = clk->parent->rate; |
Imre Deak | b1465bf | 2007-03-06 03:52:01 -0800 | [diff] [blame] | 249 | if (unlikely(clk->flags & RATE_PROPAGATES)) |
| 250 | propagate_rate(clk); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /* Propagate rate to children */ |
| 254 | void propagate_rate(struct clk * tclk) |
| 255 | { |
| 256 | struct clk *clkp; |
| 257 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 258 | if (tclk == NULL || IS_ERR(tclk)) |
| 259 | return; |
| 260 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 261 | list_for_each_entry(clkp, &clocks, node) { |
| 262 | if (likely(clkp->parent != tclk)) |
| 263 | continue; |
| 264 | if (likely((u32)clkp->recalc)) |
| 265 | clkp->recalc(clkp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Paul Walmsley | 6b8858a | 2008-03-18 10:35:15 +0200 | [diff] [blame] | 269 | /** |
| 270 | * recalculate_root_clocks - recalculate and propagate all root clocks |
| 271 | * |
| 272 | * Recalculates all root clocks (clocks with no parent), which if the |
| 273 | * clock's .recalc is set correctly, should also propagate their rates. |
| 274 | * Called at init. |
| 275 | */ |
| 276 | void recalculate_root_clocks(void) |
| 277 | { |
| 278 | struct clk *clkp; |
| 279 | |
| 280 | list_for_each_entry(clkp, &clocks, node) { |
| 281 | if (unlikely(!clkp->parent) && likely((u32)clkp->recalc)) |
| 282 | clkp->recalc(clkp); |
| 283 | } |
| 284 | } |
| 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | int clk_register(struct clk *clk) |
| 287 | { |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 288 | if (clk == NULL || IS_ERR(clk)) |
| 289 | return -EINVAL; |
| 290 | |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 291 | mutex_lock(&clocks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | list_add(&clk->node, &clocks); |
| 293 | if (clk->init) |
| 294 | clk->init(clk); |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 295 | mutex_unlock(&clocks_mutex); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | EXPORT_SYMBOL(clk_register); |
| 300 | |
| 301 | void clk_unregister(struct clk *clk) |
| 302 | { |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 303 | if (clk == NULL || IS_ERR(clk)) |
| 304 | return; |
| 305 | |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 306 | mutex_lock(&clocks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | list_del(&clk->node); |
Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 308 | mutex_unlock(&clocks_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | EXPORT_SYMBOL(clk_unregister); |
| 311 | |
Paul Walmsley | 6b8858a | 2008-03-18 10:35:15 +0200 | [diff] [blame] | 312 | void clk_enable_init_clocks(void) |
| 313 | { |
| 314 | struct clk *clkp; |
| 315 | |
| 316 | list_for_each_entry(clkp, &clocks, node) { |
| 317 | if (clkp->flags & ENABLE_ON_INIT) |
| 318 | clk_enable(clkp); |
| 319 | } |
| 320 | } |
| 321 | EXPORT_SYMBOL(clk_enable_init_clocks); |
| 322 | |
Russell King | 897dcde | 2008-11-04 16:35:03 +0000 | [diff] [blame] | 323 | /* |
| 324 | * Low level helpers |
| 325 | */ |
| 326 | static int clkll_enable_null(struct clk *clk) |
| 327 | { |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static void clkll_disable_null(struct clk *clk) |
| 332 | { |
| 333 | } |
| 334 | |
| 335 | const struct clkops clkops_null = { |
| 336 | .enable = clkll_enable_null, |
| 337 | .disable = clkll_disable_null, |
| 338 | }; |
| 339 | |
Paul Walmsley | 6b8858a | 2008-03-18 10:35:15 +0200 | [diff] [blame] | 340 | #ifdef CONFIG_CPU_FREQ |
| 341 | void clk_init_cpufreq_table(struct cpufreq_frequency_table **table) |
| 342 | { |
| 343 | unsigned long flags; |
| 344 | |
| 345 | spin_lock_irqsave(&clockfw_lock, flags); |
| 346 | if (arch_clock->clk_init_cpufreq_table) |
| 347 | arch_clock->clk_init_cpufreq_table(table); |
| 348 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 349 | } |
| 350 | EXPORT_SYMBOL(clk_init_cpufreq_table); |
| 351 | #endif |
| 352 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 353 | /*-------------------------------------------------------------------------*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Tony Lindgren | 90afd5c | 2006-09-25 13:27:20 +0300 | [diff] [blame] | 355 | #ifdef CONFIG_OMAP_RESET_CLOCKS |
| 356 | /* |
| 357 | * Disable any unused clocks left on by the bootloader |
| 358 | */ |
| 359 | static int __init clk_disable_unused(void) |
| 360 | { |
| 361 | struct clk *ck; |
| 362 | unsigned long flags; |
| 363 | |
| 364 | list_for_each_entry(ck, &clocks, node) { |
Russell King | 897dcde | 2008-11-04 16:35:03 +0000 | [diff] [blame] | 365 | if (ck->ops == &clkops_null) |
| 366 | continue; |
| 367 | |
| 368 | if (ck->usecount > 0 || ck->enable_reg == 0) |
Tony Lindgren | 90afd5c | 2006-09-25 13:27:20 +0300 | [diff] [blame] | 369 | continue; |
| 370 | |
| 371 | spin_lock_irqsave(&clockfw_lock, flags); |
| 372 | if (arch_clock->clk_disable_unused) |
| 373 | arch_clock->clk_disable_unused(ck); |
| 374 | spin_unlock_irqrestore(&clockfw_lock, flags); |
| 375 | } |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | late_initcall(clk_disable_unused); |
| 380 | #endif |
| 381 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 382 | int __init clk_init(struct clk_functions * custom_clocks) |
| 383 | { |
| 384 | if (!custom_clocks) { |
| 385 | printk(KERN_ERR "No custom clock functions registered\n"); |
| 386 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 389 | arch_clock = custom_clocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | return 0; |
| 392 | } |
Paul Walmsley | 6b8858a | 2008-03-18 10:35:15 +0200 | [diff] [blame] | 393 | |
Hiroshi DOYU | 137b3ee | 2008-07-03 12:24:41 +0300 | [diff] [blame] | 394 | #if defined(CONFIG_PM_DEBUG) && defined(CONFIG_DEBUG_FS) |
| 395 | /* |
| 396 | * debugfs support to trace clock tree hierarchy and attributes |
| 397 | */ |
| 398 | static struct dentry *clk_debugfs_root; |
| 399 | |
| 400 | static int clk_debugfs_register_one(struct clk *c) |
| 401 | { |
| 402 | int err; |
| 403 | struct dentry *d, *child; |
| 404 | struct clk *pa = c->parent; |
| 405 | char s[255]; |
| 406 | char *p = s; |
| 407 | |
| 408 | p += sprintf(p, "%s", c->name); |
| 409 | if (c->id != 0) |
| 410 | sprintf(p, ":%d", c->id); |
| 411 | d = debugfs_create_dir(s, pa ? pa->dent : clk_debugfs_root); |
Zhaolei | e621f26 | 2008-11-04 13:35:07 -0800 | [diff] [blame] | 412 | if (!d) |
| 413 | return -ENOMEM; |
Hiroshi DOYU | 137b3ee | 2008-07-03 12:24:41 +0300 | [diff] [blame] | 414 | c->dent = d; |
| 415 | |
| 416 | d = debugfs_create_u8("usecount", S_IRUGO, c->dent, (u8 *)&c->usecount); |
Zhaolei | e621f26 | 2008-11-04 13:35:07 -0800 | [diff] [blame] | 417 | if (!d) { |
| 418 | err = -ENOMEM; |
Hiroshi DOYU | 137b3ee | 2008-07-03 12:24:41 +0300 | [diff] [blame] | 419 | goto err_out; |
| 420 | } |
| 421 | d = debugfs_create_u32("rate", S_IRUGO, c->dent, (u32 *)&c->rate); |
Zhaolei | e621f26 | 2008-11-04 13:35:07 -0800 | [diff] [blame] | 422 | if (!d) { |
| 423 | err = -ENOMEM; |
Hiroshi DOYU | 137b3ee | 2008-07-03 12:24:41 +0300 | [diff] [blame] | 424 | goto err_out; |
| 425 | } |
| 426 | d = debugfs_create_x32("flags", S_IRUGO, c->dent, (u32 *)&c->flags); |
Zhaolei | e621f26 | 2008-11-04 13:35:07 -0800 | [diff] [blame] | 427 | if (!d) { |
| 428 | err = -ENOMEM; |
Hiroshi DOYU | 137b3ee | 2008-07-03 12:24:41 +0300 | [diff] [blame] | 429 | goto err_out; |
| 430 | } |
| 431 | return 0; |
| 432 | |
| 433 | err_out: |
| 434 | d = c->dent; |
| 435 | list_for_each_entry(child, &d->d_subdirs, d_u.d_child) |
| 436 | debugfs_remove(child); |
| 437 | debugfs_remove(c->dent); |
| 438 | return err; |
| 439 | } |
| 440 | |
| 441 | static int clk_debugfs_register(struct clk *c) |
| 442 | { |
| 443 | int err; |
| 444 | struct clk *pa = c->parent; |
| 445 | |
| 446 | if (pa && !pa->dent) { |
| 447 | err = clk_debugfs_register(pa); |
| 448 | if (err) |
| 449 | return err; |
| 450 | } |
| 451 | |
| 452 | if (!c->dent) { |
| 453 | err = clk_debugfs_register_one(c); |
| 454 | if (err) |
| 455 | return err; |
| 456 | } |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | static int __init clk_debugfs_init(void) |
| 461 | { |
| 462 | struct clk *c; |
| 463 | struct dentry *d; |
| 464 | int err; |
| 465 | |
| 466 | d = debugfs_create_dir("clock", NULL); |
Zhaolei | e621f26 | 2008-11-04 13:35:07 -0800 | [diff] [blame] | 467 | if (!d) |
| 468 | return -ENOMEM; |
Hiroshi DOYU | 137b3ee | 2008-07-03 12:24:41 +0300 | [diff] [blame] | 469 | clk_debugfs_root = d; |
| 470 | |
| 471 | list_for_each_entry(c, &clocks, node) { |
| 472 | err = clk_debugfs_register(c); |
| 473 | if (err) |
| 474 | goto err_out; |
| 475 | } |
| 476 | return 0; |
| 477 | err_out: |
| 478 | debugfs_remove(clk_debugfs_root); /* REVISIT: Cleanup correctly */ |
| 479 | return err; |
| 480 | } |
| 481 | late_initcall(clk_debugfs_init); |
| 482 | |
| 483 | #endif /* defined(CONFIG_PM_DEBUG) && defined(CONFIG_DEBUG_FS) */ |