Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-omap2/clock.c |
| 3 | * |
Tony Lindgren | a16e970 | 2008-03-18 11:56:39 +0200 | [diff] [blame] | 4 | * Copyright (C) 2005-2008 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2004-2008 Nokia Corporation |
| 6 | * |
| 7 | * Contacts: |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 8 | * Richard Woodruff <r-woodruff2@ti.com> |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 9 | * Paul Walmsley |
| 10 | * |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
| 15 | #undef DEBUG |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/device.h> |
| 20 | #include <linux/list.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/clk.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 24 | #include <linux/io.h> |
Russell King | fbd3bdb | 2008-09-06 12:13:59 +0100 | [diff] [blame] | 25 | #include <linux/bitops.h> |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 26 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 27 | #include <plat/clock.h> |
| 28 | #include <plat/clockdomain.h> |
| 29 | #include <plat/cpu.h> |
| 30 | #include <plat/prcm.h> |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 31 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 32 | #include "clock.h" |
| 33 | #include "prm.h" |
| 34 | #include "prm-regbits-24xx.h" |
| 35 | #include "cm.h" |
| 36 | #include "cm-regbits-24xx.h" |
| 37 | #include "cm-regbits-34xx.h" |
| 38 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 39 | u8 cpu_mask; |
| 40 | |
| 41 | /*------------------------------------------------------------------------- |
Rajendra Nayak | 911bd73 | 2009-12-08 18:47:17 -0700 | [diff] [blame] | 42 | * OMAP2/3/4 specific clock functions |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 43 | *-------------------------------------------------------------------------*/ |
| 44 | |
Paul Walmsley | 4b1f76e | 2010-01-26 20:13:04 -0700 | [diff] [blame] | 45 | /* Private functions */ |
| 46 | |
| 47 | /** |
| 48 | * _omap2_module_wait_ready - wait for an OMAP module to leave IDLE |
| 49 | * @clk: struct clk * belonging to the module |
| 50 | * |
| 51 | * If the necessary clocks for the OMAP hardware IP block that |
| 52 | * corresponds to clock @clk are enabled, then wait for the module to |
| 53 | * indicate readiness (i.e., to leave IDLE). This code does not |
| 54 | * belong in the clock code and will be moved in the medium term to |
| 55 | * module-dependent code. No return value. |
| 56 | */ |
| 57 | static void _omap2_module_wait_ready(struct clk *clk) |
| 58 | { |
| 59 | void __iomem *companion_reg, *idlest_reg; |
| 60 | u8 other_bit, idlest_bit; |
| 61 | |
| 62 | /* Not all modules have multiple clocks that their IDLEST depends on */ |
| 63 | if (clk->ops->find_companion) { |
| 64 | clk->ops->find_companion(clk, &companion_reg, &other_bit); |
| 65 | if (!(__raw_readl(companion_reg) & (1 << other_bit))) |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | clk->ops->find_idlest(clk, &idlest_reg, &idlest_bit); |
| 70 | |
| 71 | omap2_cm_wait_idlest(idlest_reg, (1 << idlest_bit), clk->name); |
| 72 | } |
| 73 | |
| 74 | /* Enables clock without considering parent dependencies or use count |
| 75 | * REVISIT: Maybe change this to use clk->enable like on omap1? |
| 76 | */ |
| 77 | static int _omap2_clk_enable(struct clk *clk) |
| 78 | { |
| 79 | return clk->ops->enable(clk); |
| 80 | } |
| 81 | |
| 82 | /* Disables clock without considering parent dependencies or use count */ |
| 83 | static void _omap2_clk_disable(struct clk *clk) |
| 84 | { |
| 85 | clk->ops->disable(clk); |
| 86 | } |
| 87 | |
| 88 | /* Public functions */ |
| 89 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 90 | /** |
Paul Walmsley | df791b3 | 2010-01-26 20:13:04 -0700 | [diff] [blame] | 91 | * omap2xxx_clk_commit - commit clock parent/rate changes in hardware |
Paul Walmsley | 439764c | 2009-01-28 12:35:03 -0700 | [diff] [blame] | 92 | * @clk: struct clk * |
| 93 | * |
| 94 | * If @clk has the DELAYED_APP flag set, meaning that parent/rate changes |
| 95 | * don't take effect until the VALID_CONFIG bit is written, write the |
| 96 | * VALID_CONFIG bit and wait for the write to complete. No return value. |
| 97 | */ |
Paul Walmsley | df791b3 | 2010-01-26 20:13:04 -0700 | [diff] [blame] | 98 | void omap2xxx_clk_commit(struct clk *clk) |
Paul Walmsley | 439764c | 2009-01-28 12:35:03 -0700 | [diff] [blame] | 99 | { |
| 100 | if (!cpu_is_omap24xx()) |
| 101 | return; |
| 102 | |
| 103 | if (!(clk->flags & DELAYED_APP)) |
| 104 | return; |
| 105 | |
| 106 | prm_write_mod_reg(OMAP24XX_VALID_CONFIG, OMAP24XX_GR_MOD, |
Tony Lindgren | 8e3bd35 | 2009-05-25 11:26:42 -0700 | [diff] [blame] | 107 | OMAP2_PRCM_CLKCFG_CTRL_OFFSET); |
Paul Walmsley | 439764c | 2009-01-28 12:35:03 -0700 | [diff] [blame] | 108 | /* OCP barrier */ |
Tony Lindgren | 8e3bd35 | 2009-05-25 11:26:42 -0700 | [diff] [blame] | 109 | prm_read_mod_reg(OMAP24XX_GR_MOD, OMAP2_PRCM_CLKCFG_CTRL_OFFSET); |
Paul Walmsley | 439764c | 2009-01-28 12:35:03 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 112 | /** |
Paul Walmsley | 333943b | 2008-08-19 11:08:45 +0300 | [diff] [blame] | 113 | * omap2_init_clk_clkdm - look up a clockdomain name, store pointer in clk |
| 114 | * @clk: OMAP clock struct ptr to use |
| 115 | * |
| 116 | * Convert a clockdomain name stored in a struct clk 'clk' into a |
| 117 | * clockdomain pointer, and save it into the struct clk. Intended to be |
| 118 | * called during clk_register(). No return value. |
| 119 | */ |
| 120 | void omap2_init_clk_clkdm(struct clk *clk) |
| 121 | { |
| 122 | struct clockdomain *clkdm; |
| 123 | |
| 124 | if (!clk->clkdm_name) |
| 125 | return; |
| 126 | |
| 127 | clkdm = clkdm_lookup(clk->clkdm_name); |
| 128 | if (clkdm) { |
| 129 | pr_debug("clock: associated clk %s to clkdm %s\n", |
| 130 | clk->name, clk->clkdm_name); |
| 131 | clk->clkdm = clkdm; |
| 132 | } else { |
| 133 | pr_debug("clock: could not associate clk %s to " |
| 134 | "clkdm %s\n", clk->name, clk->clkdm_name); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /** |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 139 | * omap2_clk_dflt_find_companion - find companion clock to @clk |
| 140 | * @clk: struct clk * to find the companion clock of |
| 141 | * @other_reg: void __iomem ** to return the companion clock CM_*CLKEN va in |
| 142 | * @other_bit: u8 ** to return the companion clock bit shift in |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 143 | * |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 144 | * Note: We don't need special code here for INVERT_ENABLE for the |
| 145 | * time being since INVERT_ENABLE only applies to clocks enabled by |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 146 | * CM_CLKEN_PLL |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 147 | * |
| 148 | * Convert CM_ICLKEN* <-> CM_FCLKEN*. This conversion assumes it's |
| 149 | * just a matter of XORing the bits. |
| 150 | * |
| 151 | * Some clocks don't have companion clocks. For example, modules with |
| 152 | * only an interface clock (such as MAILBOXES) don't have a companion |
| 153 | * clock. Right now, this code relies on the hardware exporting a bit |
| 154 | * in the correct companion register that indicates that the |
| 155 | * nonexistent 'companion clock' is active. Future patches will |
| 156 | * associate this type of code with per-module data structures to |
| 157 | * avoid this issue, and remove the casts. No return value. |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 158 | */ |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 159 | void omap2_clk_dflt_find_companion(struct clk *clk, void __iomem **other_reg, |
| 160 | u8 *other_bit) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 161 | { |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 162 | u32 r; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 163 | |
Russell King | c1168dc | 2008-11-04 21:24:00 +0000 | [diff] [blame] | 164 | /* |
| 165 | * Convert CM_ICLKEN* <-> CM_FCLKEN*. This conversion assumes |
| 166 | * it's just a matter of XORing the bits. |
| 167 | */ |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 168 | r = ((__force u32)clk->enable_reg ^ (CM_FCLKEN ^ CM_ICLKEN)); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 169 | |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 170 | *other_reg = (__force void __iomem *)r; |
| 171 | *other_bit = clk->enable_bit; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 174 | /** |
| 175 | * omap2_clk_dflt_find_idlest - find CM_IDLEST reg va, bit shift for @clk |
| 176 | * @clk: struct clk * to find IDLEST info for |
| 177 | * @idlest_reg: void __iomem ** to return the CM_IDLEST va in |
| 178 | * @idlest_bit: u8 ** to return the CM_IDLEST bit shift in |
| 179 | * |
| 180 | * Return the CM_IDLEST register address and bit shift corresponding |
| 181 | * to the module that "owns" this clock. This default code assumes |
| 182 | * that the CM_IDLEST bit shift is the CM_*CLKEN bit shift, and that |
| 183 | * the IDLEST register address ID corresponds to the CM_*CLKEN |
| 184 | * register address ID (e.g., that CM_FCLKEN2 corresponds to |
| 185 | * CM_IDLEST2). This is not true for all modules. No return value. |
| 186 | */ |
| 187 | void omap2_clk_dflt_find_idlest(struct clk *clk, void __iomem **idlest_reg, |
| 188 | u8 *idlest_bit) |
| 189 | { |
| 190 | u32 r; |
| 191 | |
| 192 | r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20); |
| 193 | *idlest_reg = (__force void __iomem *)r; |
| 194 | *idlest_bit = clk->enable_bit; |
| 195 | } |
| 196 | |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 197 | int omap2_dflt_clk_enable(struct clk *clk) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 198 | { |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 199 | u32 v; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 200 | |
Russell King | c0fc18c | 2008-09-05 15:10:27 +0100 | [diff] [blame] | 201 | if (unlikely(clk->enable_reg == NULL)) { |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 202 | pr_err("clock.c: Enable for %s without enable code\n", |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 203 | clk->name); |
| 204 | return 0; /* REVISIT: -EINVAL */ |
| 205 | } |
| 206 | |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 207 | v = __raw_readl(clk->enable_reg); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 208 | if (clk->flags & INVERT_ENABLE) |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 209 | v &= ~(1 << clk->enable_bit); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 210 | else |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 211 | v |= (1 << clk->enable_bit); |
| 212 | __raw_writel(v, clk->enable_reg); |
Paul Walmsley | f11fda6 | 2009-01-28 12:35:06 -0700 | [diff] [blame] | 213 | v = __raw_readl(clk->enable_reg); /* OCP barrier */ |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 214 | |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 215 | if (clk->ops->find_idlest) |
Paul Walmsley | 4b1f76e | 2010-01-26 20:13:04 -0700 | [diff] [blame] | 216 | _omap2_module_wait_ready(clk); |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 217 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 218 | return 0; |
| 219 | } |
| 220 | |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 221 | void omap2_dflt_clk_disable(struct clk *clk) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 222 | { |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 223 | u32 v; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 224 | |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 225 | if (!clk->enable_reg) { |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 226 | /* |
| 227 | * 'Independent' here refers to a clock which is not |
| 228 | * controlled by its parent. |
| 229 | */ |
| 230 | printk(KERN_ERR "clock: clk_disable called on independent " |
| 231 | "clock %s which has no enable_reg\n", clk->name); |
| 232 | return; |
| 233 | } |
| 234 | |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 235 | v = __raw_readl(clk->enable_reg); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 236 | if (clk->flags & INVERT_ENABLE) |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 237 | v |= (1 << clk->enable_bit); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 238 | else |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 239 | v &= ~(1 << clk->enable_bit); |
| 240 | __raw_writel(v, clk->enable_reg); |
Paul Walmsley | de07fed | 2009-01-28 12:35:01 -0700 | [diff] [blame] | 241 | /* No OCP barrier needed here since it is a disable operation */ |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 242 | } |
| 243 | |
Russell King | b36ee72 | 2008-11-04 17:59:52 +0000 | [diff] [blame] | 244 | const struct clkops clkops_omap2_dflt_wait = { |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 245 | .enable = omap2_dflt_clk_enable, |
Russell King | b36ee72 | 2008-11-04 17:59:52 +0000 | [diff] [blame] | 246 | .disable = omap2_dflt_clk_disable, |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 247 | .find_companion = omap2_clk_dflt_find_companion, |
| 248 | .find_idlest = omap2_clk_dflt_find_idlest, |
Russell King | b36ee72 | 2008-11-04 17:59:52 +0000 | [diff] [blame] | 249 | }; |
| 250 | |
Russell King | bc51da4 | 2008-11-04 18:59:32 +0000 | [diff] [blame] | 251 | const struct clkops clkops_omap2_dflt = { |
| 252 | .enable = omap2_dflt_clk_enable, |
| 253 | .disable = omap2_dflt_clk_disable, |
| 254 | }; |
| 255 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 256 | void omap2_clk_disable(struct clk *clk) |
| 257 | { |
| 258 | if (clk->usecount > 0 && !(--clk->usecount)) { |
| 259 | _omap2_clk_disable(clk); |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 260 | if (clk->parent) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 261 | omap2_clk_disable(clk->parent); |
Paul Walmsley | 333943b | 2008-08-19 11:08:45 +0300 | [diff] [blame] | 262 | if (clk->clkdm) |
| 263 | omap2_clkdm_clk_disable(clk->clkdm, clk); |
| 264 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
| 268 | int omap2_clk_enable(struct clk *clk) |
| 269 | { |
| 270 | int ret = 0; |
| 271 | |
| 272 | if (clk->usecount++ == 0) { |
Paul Walmsley | 333943b | 2008-08-19 11:08:45 +0300 | [diff] [blame] | 273 | if (clk->clkdm) |
| 274 | omap2_clkdm_clk_enable(clk->clkdm, clk); |
| 275 | |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 276 | if (clk->parent) { |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 277 | ret = omap2_clk_enable(clk->parent); |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 278 | if (ret) |
| 279 | goto err; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 280 | } |
| 281 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 282 | ret = _omap2_clk_enable(clk); |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 283 | if (ret) { |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 284 | if (clk->parent) |
Paul Walmsley | 333943b | 2008-08-19 11:08:45 +0300 | [diff] [blame] | 285 | omap2_clk_disable(clk->parent); |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 286 | |
| 287 | goto err; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 288 | } |
| 289 | } |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 290 | return ret; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 291 | |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 292 | err: |
Russell King | 8263e5b | 2009-01-31 11:02:37 +0000 | [diff] [blame] | 293 | if (clk->clkdm) |
| 294 | omap2_clkdm_clk_disable(clk->clkdm, clk); |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 295 | clk->usecount--; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 296 | return ret; |
| 297 | } |
| 298 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 299 | /* Set the clock rate for a clock source */ |
| 300 | int omap2_clk_set_rate(struct clk *clk, unsigned long rate) |
| 301 | { |
| 302 | int ret = -EINVAL; |
| 303 | |
| 304 | pr_debug("clock: set_rate for clock %s to rate %ld\n", clk->name, rate); |
| 305 | |
| 306 | /* CONFIG_PARTICIPANT clocks are changed only in sets via the |
| 307 | rate table mechanism, driven by mpu_speed */ |
| 308 | if (clk->flags & CONFIG_PARTICIPANT) |
| 309 | return -EINVAL; |
| 310 | |
| 311 | /* dpll_ck, core_ck, virt_prcm_set; plus all clksel clocks */ |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 312 | if (clk->set_rate) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 313 | ret = clk->set_rate(clk, rate); |
| 314 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 315 | return ret; |
| 316 | } |
| 317 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 318 | int omap2_clk_set_parent(struct clk *clk, struct clk *new_parent) |
| 319 | { |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 320 | if (clk->flags & CONFIG_PARTICIPANT) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 321 | return -EINVAL; |
| 322 | |
| 323 | if (!clk->clksel) |
| 324 | return -EINVAL; |
| 325 | |
Paul Walmsley | df791b3 | 2010-01-26 20:13:04 -0700 | [diff] [blame] | 326 | return omap2_clksel_set_parent(clk, new_parent); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 327 | } |
| 328 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 329 | /*------------------------------------------------------------------------- |
| 330 | * Omap2 clock reset and init functions |
| 331 | *-------------------------------------------------------------------------*/ |
| 332 | |
| 333 | #ifdef CONFIG_OMAP_RESET_CLOCKS |
| 334 | void omap2_clk_disable_unused(struct clk *clk) |
| 335 | { |
| 336 | u32 regval32, v; |
| 337 | |
| 338 | v = (clk->flags & INVERT_ENABLE) ? (1 << clk->enable_bit) : 0; |
| 339 | |
| 340 | regval32 = __raw_readl(clk->enable_reg); |
| 341 | if ((regval32 & (1 << clk->enable_bit)) == v) |
| 342 | return; |
| 343 | |
Artem Bityutskiy | 0db4e82 | 2009-05-12 17:34:40 -0600 | [diff] [blame] | 344 | printk(KERN_DEBUG "Disabling unused clock \"%s\"\n", clk->name); |
Tero Kristo | 8463e20 | 2009-01-28 12:27:45 -0700 | [diff] [blame] | 345 | if (cpu_is_omap34xx()) { |
| 346 | omap2_clk_enable(clk); |
| 347 | omap2_clk_disable(clk); |
| 348 | } else |
| 349 | _omap2_clk_disable(clk); |
Peter 'p2' De Schrijver | fe617af | 2008-10-15 17:48:44 +0300 | [diff] [blame] | 350 | if (clk->clkdm != NULL) |
| 351 | pwrdm_clkdm_state_switch(clk->clkdm); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 352 | } |
| 353 | #endif |
Paul Walmsley | 69ecefc | 2010-01-26 20:13:04 -0700 | [diff] [blame] | 354 | |
| 355 | /* Common data */ |
| 356 | |
| 357 | struct clk_functions omap2_clk_functions = { |
| 358 | .clk_enable = omap2_clk_enable, |
| 359 | .clk_disable = omap2_clk_disable, |
| 360 | .clk_round_rate = omap2_clk_round_rate, |
| 361 | .clk_set_rate = omap2_clk_set_rate, |
| 362 | .clk_set_parent = omap2_clk_set_parent, |
| 363 | .clk_disable_unused = omap2_clk_disable_unused, |
| 364 | #ifdef CONFIG_CPU_FREQ |
| 365 | /* These will be removed when the OPP code is integrated */ |
| 366 | .clk_init_cpufreq_table = omap2_clk_init_cpufreq_table, |
| 367 | .clk_exit_cpufreq_table = omap2_clk_exit_cpufreq_table, |
| 368 | #endif |
| 369 | }; |
| 370 | |