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 | #include <asm/div64.h> |
| 32 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 33 | #include <plat/sdrc.h> |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 34 | #include "sdrc.h" |
| 35 | #include "clock.h" |
| 36 | #include "prm.h" |
| 37 | #include "prm-regbits-24xx.h" |
| 38 | #include "cm.h" |
| 39 | #include "cm-regbits-24xx.h" |
| 40 | #include "cm-regbits-34xx.h" |
| 41 | |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 42 | /* DPLL rate rounding: minimum DPLL multiplier, divider values */ |
| 43 | #define DPLL_MIN_MULTIPLIER 1 |
| 44 | #define DPLL_MIN_DIVIDER 1 |
| 45 | |
| 46 | /* Possible error results from _dpll_test_mult */ |
Paul Walmsley | 85a5f78 | 2009-01-28 12:08:41 -0700 | [diff] [blame] | 47 | #define DPLL_MULT_UNDERFLOW -1 |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Scale factor to mitigate roundoff errors in DPLL rate rounding. |
| 51 | * The higher the scale factor, the greater the risk of arithmetic overflow, |
| 52 | * but the closer the rounded rate to the target rate. DPLL_SCALE_FACTOR |
| 53 | * must be a power of DPLL_SCALE_BASE. |
| 54 | */ |
| 55 | #define DPLL_SCALE_FACTOR 64 |
| 56 | #define DPLL_SCALE_BASE 2 |
| 57 | #define DPLL_ROUNDING_VAL ((DPLL_SCALE_BASE / 2) * \ |
| 58 | (DPLL_SCALE_FACTOR / DPLL_SCALE_BASE)) |
| 59 | |
Paul Walmsley | 95f538a | 2009-01-28 12:08:44 -0700 | [diff] [blame] | 60 | /* DPLL valid Fint frequency band limits - from 34xx TRM Section 4.7.6.2 */ |
| 61 | #define DPLL_FINT_BAND1_MIN 750000 |
| 62 | #define DPLL_FINT_BAND1_MAX 2100000 |
| 63 | #define DPLL_FINT_BAND2_MIN 7500000 |
| 64 | #define DPLL_FINT_BAND2_MAX 21000000 |
| 65 | |
| 66 | /* _dpll_test_fint() return codes */ |
| 67 | #define DPLL_FINT_UNDERFLOW -1 |
| 68 | #define DPLL_FINT_INVALID -2 |
| 69 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 70 | u8 cpu_mask; |
| 71 | |
| 72 | /*------------------------------------------------------------------------- |
Paul Walmsley | 333943b | 2008-08-19 11:08:45 +0300 | [diff] [blame] | 73 | * OMAP2/3 specific clock functions |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 74 | *-------------------------------------------------------------------------*/ |
| 75 | |
| 76 | /** |
Paul Walmsley | 439764c | 2009-01-28 12:35:03 -0700 | [diff] [blame] | 77 | * _omap2xxx_clk_commit - commit clock parent/rate changes in hardware |
| 78 | * @clk: struct clk * |
| 79 | * |
| 80 | * If @clk has the DELAYED_APP flag set, meaning that parent/rate changes |
| 81 | * don't take effect until the VALID_CONFIG bit is written, write the |
| 82 | * VALID_CONFIG bit and wait for the write to complete. No return value. |
| 83 | */ |
| 84 | static void _omap2xxx_clk_commit(struct clk *clk) |
| 85 | { |
| 86 | if (!cpu_is_omap24xx()) |
| 87 | return; |
| 88 | |
| 89 | if (!(clk->flags & DELAYED_APP)) |
| 90 | return; |
| 91 | |
| 92 | prm_write_mod_reg(OMAP24XX_VALID_CONFIG, OMAP24XX_GR_MOD, |
Tony Lindgren | 8e3bd35 | 2009-05-25 11:26:42 -0700 | [diff] [blame] | 93 | OMAP2_PRCM_CLKCFG_CTRL_OFFSET); |
Paul Walmsley | 439764c | 2009-01-28 12:35:03 -0700 | [diff] [blame] | 94 | /* OCP barrier */ |
Tony Lindgren | 8e3bd35 | 2009-05-25 11:26:42 -0700 | [diff] [blame] | 95 | prm_read_mod_reg(OMAP24XX_GR_MOD, OMAP2_PRCM_CLKCFG_CTRL_OFFSET); |
Paul Walmsley | 439764c | 2009-01-28 12:35:03 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Paul Walmsley | 95f538a | 2009-01-28 12:08:44 -0700 | [diff] [blame] | 98 | /* |
| 99 | * _dpll_test_fint - test whether an Fint value is valid for the DPLL |
| 100 | * @clk: DPLL struct clk to test |
| 101 | * @n: divider value (N) to test |
| 102 | * |
| 103 | * Tests whether a particular divider @n will result in a valid DPLL |
| 104 | * internal clock frequency Fint. See the 34xx TRM 4.7.6.2 "DPLL Jitter |
| 105 | * Correction". Returns 0 if OK, -1 if the enclosing loop can terminate |
| 106 | * (assuming that it is counting N upwards), or -2 if the enclosing loop |
| 107 | * should skip to the next iteration (again assuming N is increasing). |
| 108 | */ |
| 109 | static int _dpll_test_fint(struct clk *clk, u8 n) |
| 110 | { |
| 111 | struct dpll_data *dd; |
| 112 | long fint; |
| 113 | int ret = 0; |
| 114 | |
| 115 | dd = clk->dpll_data; |
| 116 | |
| 117 | /* DPLL divider must result in a valid jitter correction val */ |
| 118 | fint = clk->parent->rate / (n + 1); |
| 119 | if (fint < DPLL_FINT_BAND1_MIN) { |
| 120 | |
| 121 | pr_debug("rejecting n=%d due to Fint failure, " |
| 122 | "lowering max_divider\n", n); |
| 123 | dd->max_divider = n; |
| 124 | ret = DPLL_FINT_UNDERFLOW; |
| 125 | |
| 126 | } else if (fint > DPLL_FINT_BAND1_MAX && |
| 127 | fint < DPLL_FINT_BAND2_MIN) { |
| 128 | |
| 129 | pr_debug("rejecting n=%d due to Fint failure\n", n); |
| 130 | ret = DPLL_FINT_INVALID; |
| 131 | |
| 132 | } else if (fint > DPLL_FINT_BAND2_MAX) { |
| 133 | |
| 134 | pr_debug("rejecting n=%d due to Fint failure, " |
| 135 | "boosting min_divider\n", n); |
| 136 | dd->min_divider = n; |
| 137 | ret = DPLL_FINT_INVALID; |
| 138 | |
| 139 | } |
| 140 | |
| 141 | return ret; |
| 142 | } |
| 143 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 144 | /** |
Paul Walmsley | 333943b | 2008-08-19 11:08:45 +0300 | [diff] [blame] | 145 | * omap2_init_clk_clkdm - look up a clockdomain name, store pointer in clk |
| 146 | * @clk: OMAP clock struct ptr to use |
| 147 | * |
| 148 | * Convert a clockdomain name stored in a struct clk 'clk' into a |
| 149 | * clockdomain pointer, and save it into the struct clk. Intended to be |
| 150 | * called during clk_register(). No return value. |
| 151 | */ |
| 152 | void omap2_init_clk_clkdm(struct clk *clk) |
| 153 | { |
| 154 | struct clockdomain *clkdm; |
| 155 | |
| 156 | if (!clk->clkdm_name) |
| 157 | return; |
| 158 | |
| 159 | clkdm = clkdm_lookup(clk->clkdm_name); |
| 160 | if (clkdm) { |
| 161 | pr_debug("clock: associated clk %s to clkdm %s\n", |
| 162 | clk->name, clk->clkdm_name); |
| 163 | clk->clkdm = clkdm; |
| 164 | } else { |
| 165 | pr_debug("clock: could not associate clk %s to " |
| 166 | "clkdm %s\n", clk->name, clk->clkdm_name); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /** |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 171 | * omap2_init_clksel_parent - set a clksel clk's parent field from the hardware |
| 172 | * @clk: OMAP clock struct ptr to use |
| 173 | * |
| 174 | * Given a pointer to a source-selectable struct clk, read the hardware |
| 175 | * register and determine what its parent is currently set to. Update the |
| 176 | * clk->parent field with the appropriate clk ptr. |
| 177 | */ |
| 178 | void omap2_init_clksel_parent(struct clk *clk) |
| 179 | { |
| 180 | const struct clksel *clks; |
| 181 | const struct clksel_rate *clkr; |
| 182 | u32 r, found = 0; |
| 183 | |
| 184 | if (!clk->clksel) |
| 185 | return; |
| 186 | |
| 187 | r = __raw_readl(clk->clksel_reg) & clk->clksel_mask; |
| 188 | r >>= __ffs(clk->clksel_mask); |
| 189 | |
| 190 | for (clks = clk->clksel; clks->parent && !found; clks++) { |
| 191 | for (clkr = clks->rates; clkr->div && !found; clkr++) { |
| 192 | if ((clkr->flags & cpu_mask) && (clkr->val == r)) { |
| 193 | if (clk->parent != clks->parent) { |
| 194 | pr_debug("clock: inited %s parent " |
| 195 | "to %s (was %s)\n", |
| 196 | clk->name, clks->parent->name, |
| 197 | ((clk->parent) ? |
| 198 | clk->parent->name : "NULL")); |
Russell King | 3f0a820 | 2009-01-31 10:05:51 +0000 | [diff] [blame] | 199 | clk_reparent(clk, clks->parent); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 200 | }; |
| 201 | found = 1; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | if (!found) |
| 207 | printk(KERN_ERR "clock: init parent: could not find " |
| 208 | "regval %0x for clock %s\n", r, clk->name); |
| 209 | |
| 210 | return; |
| 211 | } |
| 212 | |
Russell King | c0bf313 | 2009-02-19 13:29:22 +0000 | [diff] [blame] | 213 | /** |
| 214 | * omap2_get_dpll_rate - returns the current DPLL CLKOUT rate |
| 215 | * @clk: struct clk * of a DPLL |
| 216 | * |
| 217 | * DPLLs can be locked or bypassed - basically, enabled or disabled. |
| 218 | * When locked, the DPLL output depends on the M and N values. When |
| 219 | * bypassed, on OMAP2xxx, the output rate is either the 32KiHz clock |
| 220 | * or sys_clk. Bypass rates on OMAP3 depend on the DPLL: DPLLs 1 and |
| 221 | * 2 are bypassed with dpll1_fclk and dpll2_fclk respectively |
| 222 | * (generated by DPLL3), while DPLL 3, 4, and 5 bypass rates are sys_clk. |
| 223 | * Returns the current DPLL CLKOUT rate (*not* CLKOUTX2) if the DPLL is |
| 224 | * locked, or the appropriate bypass rate if the DPLL is bypassed, or 0 |
| 225 | * if the clock @clk is not a DPLL. |
| 226 | */ |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 227 | u32 omap2_get_dpll_rate(struct clk *clk) |
| 228 | { |
| 229 | long long dpll_clk; |
Russell King | c0bf313 | 2009-02-19 13:29:22 +0000 | [diff] [blame] | 230 | u32 dpll_mult, dpll_div, v; |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 231 | struct dpll_data *dd; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 232 | |
| 233 | dd = clk->dpll_data; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 234 | if (!dd) |
| 235 | return 0; |
| 236 | |
Russell King | c0bf313 | 2009-02-19 13:29:22 +0000 | [diff] [blame] | 237 | /* Return bypass rate if DPLL is bypassed */ |
| 238 | v = __raw_readl(dd->control_reg); |
| 239 | v &= dd->enable_mask; |
| 240 | v >>= __ffs(dd->enable_mask); |
| 241 | |
| 242 | if (cpu_is_omap24xx()) { |
| 243 | if (v == OMAP2XXX_EN_DPLL_LPBYPASS || |
| 244 | v == OMAP2XXX_EN_DPLL_FRBYPASS) |
| 245 | return dd->clk_bypass->rate; |
| 246 | } else if (cpu_is_omap34xx()) { |
| 247 | if (v == OMAP3XXX_EN_DPLL_LPBYPASS || |
| 248 | v == OMAP3XXX_EN_DPLL_FRBYPASS) |
| 249 | return dd->clk_bypass->rate; |
| 250 | } |
| 251 | |
| 252 | v = __raw_readl(dd->mult_div1_reg); |
| 253 | dpll_mult = v & dd->mult_mask; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 254 | dpll_mult >>= __ffs(dd->mult_mask); |
Russell King | c0bf313 | 2009-02-19 13:29:22 +0000 | [diff] [blame] | 255 | dpll_div = v & dd->div1_mask; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 256 | dpll_div >>= __ffs(dd->div1_mask); |
| 257 | |
Russell King | c0bf313 | 2009-02-19 13:29:22 +0000 | [diff] [blame] | 258 | dpll_clk = (long long)dd->clk_ref->rate * dpll_mult; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 259 | do_div(dpll_clk, dpll_div + 1); |
| 260 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 261 | return dpll_clk; |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | * Used for clocks that have the same value as the parent clock, |
| 266 | * divided by some factor |
| 267 | */ |
Russell King | 8b9dbc1 | 2009-02-12 10:12:59 +0000 | [diff] [blame] | 268 | unsigned long omap2_fixed_divisor_recalc(struct clk *clk) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 269 | { |
| 270 | WARN_ON(!clk->fixed_div); |
| 271 | |
Russell King | 8b9dbc1 | 2009-02-12 10:12:59 +0000 | [diff] [blame] | 272 | return clk->parent->rate / clk->fixed_div; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | /** |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 276 | * omap2_clk_dflt_find_companion - find companion clock to @clk |
| 277 | * @clk: struct clk * to find the companion clock of |
| 278 | * @other_reg: void __iomem ** to return the companion clock CM_*CLKEN va in |
| 279 | * @other_bit: u8 ** to return the companion clock bit shift in |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 280 | * |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 281 | * Note: We don't need special code here for INVERT_ENABLE for the |
| 282 | * time being since INVERT_ENABLE only applies to clocks enabled by |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 283 | * CM_CLKEN_PLL |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 284 | * |
| 285 | * Convert CM_ICLKEN* <-> CM_FCLKEN*. This conversion assumes it's |
| 286 | * just a matter of XORing the bits. |
| 287 | * |
| 288 | * Some clocks don't have companion clocks. For example, modules with |
| 289 | * only an interface clock (such as MAILBOXES) don't have a companion |
| 290 | * clock. Right now, this code relies on the hardware exporting a bit |
| 291 | * in the correct companion register that indicates that the |
| 292 | * nonexistent 'companion clock' is active. Future patches will |
| 293 | * associate this type of code with per-module data structures to |
| 294 | * avoid this issue, and remove the casts. No return value. |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 295 | */ |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 296 | void omap2_clk_dflt_find_companion(struct clk *clk, void __iomem **other_reg, |
| 297 | u8 *other_bit) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 298 | { |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 299 | u32 r; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 300 | |
Russell King | c1168dc | 2008-11-04 21:24:00 +0000 | [diff] [blame] | 301 | /* |
| 302 | * Convert CM_ICLKEN* <-> CM_FCLKEN*. This conversion assumes |
| 303 | * it's just a matter of XORing the bits. |
| 304 | */ |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 305 | r = ((__force u32)clk->enable_reg ^ (CM_FCLKEN ^ CM_ICLKEN)); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 306 | |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 307 | *other_reg = (__force void __iomem *)r; |
| 308 | *other_bit = clk->enable_bit; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 309 | } |
| 310 | |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 311 | /** |
| 312 | * omap2_clk_dflt_find_idlest - find CM_IDLEST reg va, bit shift for @clk |
| 313 | * @clk: struct clk * to find IDLEST info for |
| 314 | * @idlest_reg: void __iomem ** to return the CM_IDLEST va in |
| 315 | * @idlest_bit: u8 ** to return the CM_IDLEST bit shift in |
| 316 | * |
| 317 | * Return the CM_IDLEST register address and bit shift corresponding |
| 318 | * to the module that "owns" this clock. This default code assumes |
| 319 | * that the CM_IDLEST bit shift is the CM_*CLKEN bit shift, and that |
| 320 | * the IDLEST register address ID corresponds to the CM_*CLKEN |
| 321 | * register address ID (e.g., that CM_FCLKEN2 corresponds to |
| 322 | * CM_IDLEST2). This is not true for all modules. No return value. |
| 323 | */ |
| 324 | void omap2_clk_dflt_find_idlest(struct clk *clk, void __iomem **idlest_reg, |
| 325 | u8 *idlest_bit) |
| 326 | { |
| 327 | u32 r; |
| 328 | |
| 329 | r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20); |
| 330 | *idlest_reg = (__force void __iomem *)r; |
| 331 | *idlest_bit = clk->enable_bit; |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * omap2_module_wait_ready - wait for an OMAP module to leave IDLE |
| 336 | * @clk: struct clk * belonging to the module |
| 337 | * |
| 338 | * If the necessary clocks for the OMAP hardware IP block that |
| 339 | * corresponds to clock @clk are enabled, then wait for the module to |
| 340 | * indicate readiness (i.e., to leave IDLE). This code does not |
| 341 | * belong in the clock code and will be moved in the medium term to |
| 342 | * module-dependent code. No return value. |
| 343 | */ |
| 344 | static void omap2_module_wait_ready(struct clk *clk) |
| 345 | { |
| 346 | void __iomem *companion_reg, *idlest_reg; |
| 347 | u8 other_bit, idlest_bit; |
| 348 | |
| 349 | /* Not all modules have multiple clocks that their IDLEST depends on */ |
| 350 | if (clk->ops->find_companion) { |
| 351 | clk->ops->find_companion(clk, &companion_reg, &other_bit); |
| 352 | if (!(__raw_readl(companion_reg) & (1 << other_bit))) |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | clk->ops->find_idlest(clk, &idlest_reg, &idlest_bit); |
| 357 | |
| 358 | omap2_cm_wait_idlest(idlest_reg, (1 << idlest_bit), clk->name); |
| 359 | } |
| 360 | |
| 361 | int omap2_dflt_clk_enable(struct clk *clk) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 362 | { |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 363 | u32 v; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 364 | |
Russell King | c0fc18c5 | 2008-09-05 15:10:27 +0100 | [diff] [blame] | 365 | if (unlikely(clk->enable_reg == NULL)) { |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 366 | pr_err("clock.c: Enable for %s without enable code\n", |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 367 | clk->name); |
| 368 | return 0; /* REVISIT: -EINVAL */ |
| 369 | } |
| 370 | |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 371 | v = __raw_readl(clk->enable_reg); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 372 | if (clk->flags & INVERT_ENABLE) |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 373 | v &= ~(1 << clk->enable_bit); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 374 | else |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 375 | v |= (1 << clk->enable_bit); |
| 376 | __raw_writel(v, clk->enable_reg); |
Paul Walmsley | f11fda6 | 2009-01-28 12:35:06 -0700 | [diff] [blame] | 377 | v = __raw_readl(clk->enable_reg); /* OCP barrier */ |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 378 | |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 379 | if (clk->ops->find_idlest) |
| 380 | omap2_module_wait_ready(clk); |
| 381 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 382 | return 0; |
| 383 | } |
| 384 | |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 385 | void omap2_dflt_clk_disable(struct clk *clk) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 386 | { |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 387 | u32 v; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 388 | |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 389 | if (!clk->enable_reg) { |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 390 | /* |
| 391 | * 'Independent' here refers to a clock which is not |
| 392 | * controlled by its parent. |
| 393 | */ |
| 394 | printk(KERN_ERR "clock: clk_disable called on independent " |
| 395 | "clock %s which has no enable_reg\n", clk->name); |
| 396 | return; |
| 397 | } |
| 398 | |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 399 | v = __raw_readl(clk->enable_reg); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 400 | if (clk->flags & INVERT_ENABLE) |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 401 | v |= (1 << clk->enable_bit); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 402 | else |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 403 | v &= ~(1 << clk->enable_bit); |
| 404 | __raw_writel(v, clk->enable_reg); |
Paul Walmsley | de07fed | 2009-01-28 12:35:01 -0700 | [diff] [blame] | 405 | /* No OCP barrier needed here since it is a disable operation */ |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 406 | } |
| 407 | |
Russell King | b36ee72 | 2008-11-04 17:59:52 +0000 | [diff] [blame] | 408 | const struct clkops clkops_omap2_dflt_wait = { |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 409 | .enable = omap2_dflt_clk_enable, |
Russell King | b36ee72 | 2008-11-04 17:59:52 +0000 | [diff] [blame] | 410 | .disable = omap2_dflt_clk_disable, |
Paul Walmsley | 72350b2 | 2009-07-24 19:44:03 -0600 | [diff] [blame] | 411 | .find_companion = omap2_clk_dflt_find_companion, |
| 412 | .find_idlest = omap2_clk_dflt_find_idlest, |
Russell King | b36ee72 | 2008-11-04 17:59:52 +0000 | [diff] [blame] | 413 | }; |
| 414 | |
Russell King | bc51da4 | 2008-11-04 18:59:32 +0000 | [diff] [blame] | 415 | const struct clkops clkops_omap2_dflt = { |
| 416 | .enable = omap2_dflt_clk_enable, |
| 417 | .disable = omap2_dflt_clk_disable, |
| 418 | }; |
| 419 | |
Russell King | b36ee72 | 2008-11-04 17:59:52 +0000 | [diff] [blame] | 420 | /* Enables clock without considering parent dependencies or use count |
| 421 | * REVISIT: Maybe change this to use clk->enable like on omap1? |
| 422 | */ |
| 423 | static int _omap2_clk_enable(struct clk *clk) |
| 424 | { |
| 425 | return clk->ops->enable(clk); |
| 426 | } |
| 427 | |
| 428 | /* Disables clock without considering parent dependencies or use count */ |
| 429 | static void _omap2_clk_disable(struct clk *clk) |
| 430 | { |
| 431 | clk->ops->disable(clk); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | void omap2_clk_disable(struct clk *clk) |
| 435 | { |
| 436 | if (clk->usecount > 0 && !(--clk->usecount)) { |
| 437 | _omap2_clk_disable(clk); |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 438 | if (clk->parent) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 439 | omap2_clk_disable(clk->parent); |
Paul Walmsley | 333943b | 2008-08-19 11:08:45 +0300 | [diff] [blame] | 440 | if (clk->clkdm) |
| 441 | omap2_clkdm_clk_disable(clk->clkdm, clk); |
| 442 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
| 446 | int omap2_clk_enable(struct clk *clk) |
| 447 | { |
| 448 | int ret = 0; |
| 449 | |
| 450 | if (clk->usecount++ == 0) { |
Paul Walmsley | 333943b | 2008-08-19 11:08:45 +0300 | [diff] [blame] | 451 | if (clk->clkdm) |
| 452 | omap2_clkdm_clk_enable(clk->clkdm, clk); |
| 453 | |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 454 | if (clk->parent) { |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 455 | ret = omap2_clk_enable(clk->parent); |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 456 | if (ret) |
| 457 | goto err; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 458 | } |
| 459 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 460 | ret = _omap2_clk_enable(clk); |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 461 | if (ret) { |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 462 | if (clk->parent) |
Paul Walmsley | 333943b | 2008-08-19 11:08:45 +0300 | [diff] [blame] | 463 | omap2_clk_disable(clk->parent); |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 464 | |
| 465 | goto err; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 466 | } |
| 467 | } |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 468 | return ret; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 469 | |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 470 | err: |
Russell King | 8263e5b | 2009-01-31 11:02:37 +0000 | [diff] [blame] | 471 | if (clk->clkdm) |
| 472 | omap2_clkdm_clk_disable(clk->clkdm, clk); |
Russell King | a7f8c59 | 2009-01-31 11:00:17 +0000 | [diff] [blame] | 473 | clk->usecount--; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 474 | return ret; |
| 475 | } |
| 476 | |
| 477 | /* |
| 478 | * Used for clocks that are part of CLKSEL_xyz governed clocks. |
| 479 | * REVISIT: Maybe change to use clk->enable() functions like on omap1? |
| 480 | */ |
Russell King | 8b9dbc1 | 2009-02-12 10:12:59 +0000 | [diff] [blame] | 481 | unsigned long omap2_clksel_recalc(struct clk *clk) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 482 | { |
Russell King | 8b9dbc1 | 2009-02-12 10:12:59 +0000 | [diff] [blame] | 483 | unsigned long rate; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 484 | u32 div = 0; |
| 485 | |
| 486 | pr_debug("clock: recalc'ing clksel clk %s\n", clk->name); |
| 487 | |
| 488 | div = omap2_clksel_get_divisor(clk); |
| 489 | if (div == 0) |
Russell King | 8b9dbc1 | 2009-02-12 10:12:59 +0000 | [diff] [blame] | 490 | return clk->rate; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 491 | |
Russell King | 8b9dbc1 | 2009-02-12 10:12:59 +0000 | [diff] [blame] | 492 | rate = clk->parent->rate / div; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 493 | |
Russell King | 8b9dbc1 | 2009-02-12 10:12:59 +0000 | [diff] [blame] | 494 | pr_debug("clock: new clock rate is %ld (div %d)\n", rate, div); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 495 | |
Russell King | 8b9dbc1 | 2009-02-12 10:12:59 +0000 | [diff] [blame] | 496 | return rate; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | /** |
| 500 | * omap2_get_clksel_by_parent - return clksel struct for a given clk & parent |
| 501 | * @clk: OMAP struct clk ptr to inspect |
| 502 | * @src_clk: OMAP struct clk ptr of the parent clk to search for |
| 503 | * |
| 504 | * Scan the struct clksel array associated with the clock to find |
| 505 | * the element associated with the supplied parent clock address. |
| 506 | * Returns a pointer to the struct clksel on success or NULL on error. |
| 507 | */ |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 508 | static const struct clksel *omap2_get_clksel_by_parent(struct clk *clk, |
| 509 | struct clk *src_clk) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 510 | { |
| 511 | const struct clksel *clks; |
| 512 | |
| 513 | if (!clk->clksel) |
| 514 | return NULL; |
| 515 | |
| 516 | for (clks = clk->clksel; clks->parent; clks++) { |
| 517 | if (clks->parent == src_clk) |
| 518 | break; /* Found the requested parent */ |
| 519 | } |
| 520 | |
| 521 | if (!clks->parent) { |
| 522 | printk(KERN_ERR "clock: Could not find parent clock %s in " |
| 523 | "clksel array of clock %s\n", src_clk->name, |
| 524 | clk->name); |
| 525 | return NULL; |
| 526 | } |
| 527 | |
| 528 | return clks; |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * omap2_clksel_round_rate_div - find divisor for the given clock and rate |
| 533 | * @clk: OMAP struct clk to use |
| 534 | * @target_rate: desired clock rate |
| 535 | * @new_div: ptr to where we should store the divisor |
| 536 | * |
| 537 | * Finds 'best' divider value in an array based on the source and target |
| 538 | * rates. The divider array must be sorted with smallest divider first. |
| 539 | * Note that this will not work for clocks which are part of CONFIG_PARTICIPANT, |
| 540 | * they are only settable as part of virtual_prcm set. |
| 541 | * |
| 542 | * Returns the rounded clock rate or returns 0xffffffff on error. |
| 543 | */ |
| 544 | u32 omap2_clksel_round_rate_div(struct clk *clk, unsigned long target_rate, |
| 545 | u32 *new_div) |
| 546 | { |
| 547 | unsigned long test_rate; |
| 548 | const struct clksel *clks; |
| 549 | const struct clksel_rate *clkr; |
| 550 | u32 last_div = 0; |
| 551 | |
Paul Walmsley | b7aee4b | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 552 | pr_debug("clock: clksel_round_rate_div: %s target_rate %ld\n", |
| 553 | clk->name, target_rate); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 554 | |
| 555 | *new_div = 1; |
| 556 | |
| 557 | clks = omap2_get_clksel_by_parent(clk, clk->parent); |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 558 | if (!clks) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 559 | return ~0; |
| 560 | |
| 561 | for (clkr = clks->rates; clkr->div; clkr++) { |
| 562 | if (!(clkr->flags & cpu_mask)) |
| 563 | continue; |
| 564 | |
| 565 | /* Sanity check */ |
| 566 | if (clkr->div <= last_div) |
Paul Walmsley | b7aee4b | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 567 | pr_err("clock: clksel_rate table not sorted " |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 568 | "for clock %s", clk->name); |
| 569 | |
| 570 | last_div = clkr->div; |
| 571 | |
| 572 | test_rate = clk->parent->rate / clkr->div; |
| 573 | |
| 574 | if (test_rate <= target_rate) |
| 575 | break; /* found it */ |
| 576 | } |
| 577 | |
| 578 | if (!clkr->div) { |
Paul Walmsley | b7aee4b | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 579 | pr_err("clock: Could not find divisor for target " |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 580 | "rate %ld for clock %s parent %s\n", target_rate, |
| 581 | clk->name, clk->parent->name); |
| 582 | return ~0; |
| 583 | } |
| 584 | |
| 585 | *new_div = clkr->div; |
| 586 | |
Paul Walmsley | b7aee4b | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 587 | pr_debug("clock: new_div = %d, new_rate = %ld\n", *new_div, |
| 588 | (clk->parent->rate / clkr->div)); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 589 | |
| 590 | return (clk->parent->rate / clkr->div); |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * omap2_clksel_round_rate - find rounded rate for the given clock and rate |
| 595 | * @clk: OMAP struct clk to use |
| 596 | * @target_rate: desired clock rate |
| 597 | * |
| 598 | * Compatibility wrapper for OMAP clock framework |
| 599 | * Finds best target rate based on the source clock and possible dividers. |
| 600 | * rates. The divider array must be sorted with smallest divider first. |
| 601 | * Note that this will not work for clocks which are part of CONFIG_PARTICIPANT, |
| 602 | * they are only settable as part of virtual_prcm set. |
| 603 | * |
| 604 | * Returns the rounded clock rate or returns 0xffffffff on error. |
| 605 | */ |
| 606 | long omap2_clksel_round_rate(struct clk *clk, unsigned long target_rate) |
| 607 | { |
| 608 | u32 new_div; |
| 609 | |
| 610 | return omap2_clksel_round_rate_div(clk, target_rate, &new_div); |
| 611 | } |
| 612 | |
| 613 | |
| 614 | /* Given a clock and a rate apply a clock specific rounding function */ |
| 615 | long omap2_clk_round_rate(struct clk *clk, unsigned long rate) |
| 616 | { |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 617 | if (clk->round_rate) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 618 | return clk->round_rate(clk, rate); |
| 619 | |
| 620 | if (clk->flags & RATE_FIXED) |
| 621 | printk(KERN_ERR "clock: generic omap2_clk_round_rate called " |
| 622 | "on fixed-rate clock %s\n", clk->name); |
| 623 | |
| 624 | return clk->rate; |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * omap2_clksel_to_divisor() - turn clksel field value into integer divider |
| 629 | * @clk: OMAP struct clk to use |
| 630 | * @field_val: register field value to find |
| 631 | * |
| 632 | * Given a struct clk of a rate-selectable clksel clock, and a register field |
| 633 | * value to search for, find the corresponding clock divisor. The register |
| 634 | * field value should be pre-masked and shifted down so the LSB is at bit 0 |
| 635 | * before calling. Returns 0 on error |
| 636 | */ |
| 637 | u32 omap2_clksel_to_divisor(struct clk *clk, u32 field_val) |
| 638 | { |
| 639 | const struct clksel *clks; |
| 640 | const struct clksel_rate *clkr; |
| 641 | |
| 642 | clks = omap2_get_clksel_by_parent(clk, clk->parent); |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 643 | if (!clks) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 644 | return 0; |
| 645 | |
| 646 | for (clkr = clks->rates; clkr->div; clkr++) { |
| 647 | if ((clkr->flags & cpu_mask) && (clkr->val == field_val)) |
| 648 | break; |
| 649 | } |
| 650 | |
| 651 | if (!clkr->div) { |
| 652 | printk(KERN_ERR "clock: Could not find fieldval %d for " |
| 653 | "clock %s parent %s\n", field_val, clk->name, |
| 654 | clk->parent->name); |
| 655 | return 0; |
| 656 | } |
| 657 | |
| 658 | return clkr->div; |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * omap2_divisor_to_clksel() - turn clksel integer divisor into a field value |
| 663 | * @clk: OMAP struct clk to use |
| 664 | * @div: integer divisor to search for |
| 665 | * |
| 666 | * Given a struct clk of a rate-selectable clksel clock, and a clock divisor, |
| 667 | * find the corresponding register field value. The return register value is |
Russell King | 9132f1b | 2009-02-14 13:24:10 +0000 | [diff] [blame] | 668 | * the value before left-shifting. Returns ~0 on error |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 669 | */ |
| 670 | u32 omap2_divisor_to_clksel(struct clk *clk, u32 div) |
| 671 | { |
| 672 | const struct clksel *clks; |
| 673 | const struct clksel_rate *clkr; |
| 674 | |
| 675 | /* should never happen */ |
| 676 | WARN_ON(div == 0); |
| 677 | |
| 678 | clks = omap2_get_clksel_by_parent(clk, clk->parent); |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 679 | if (!clks) |
Russell King | 9132f1b | 2009-02-14 13:24:10 +0000 | [diff] [blame] | 680 | return ~0; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 681 | |
| 682 | for (clkr = clks->rates; clkr->div; clkr++) { |
| 683 | if ((clkr->flags & cpu_mask) && (clkr->div == div)) |
| 684 | break; |
| 685 | } |
| 686 | |
| 687 | if (!clkr->div) { |
| 688 | printk(KERN_ERR "clock: Could not find divisor %d for " |
| 689 | "clock %s parent %s\n", div, clk->name, |
| 690 | clk->parent->name); |
Russell King | 9132f1b | 2009-02-14 13:24:10 +0000 | [diff] [blame] | 691 | return ~0; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | return clkr->val; |
| 695 | } |
| 696 | |
| 697 | /** |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 698 | * omap2_clksel_get_divisor - get current divider applied to parent clock. |
| 699 | * @clk: OMAP struct clk to use. |
| 700 | * |
| 701 | * Returns the integer divisor upon success or 0 on error. |
| 702 | */ |
| 703 | u32 omap2_clksel_get_divisor(struct clk *clk) |
| 704 | { |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 705 | u32 v; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 706 | |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 707 | if (!clk->clksel_mask) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 708 | return 0; |
| 709 | |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 710 | v = __raw_readl(clk->clksel_reg) & clk->clksel_mask; |
| 711 | v >>= __ffs(clk->clksel_mask); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 712 | |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 713 | return omap2_clksel_to_divisor(clk, v); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | int omap2_clksel_set_rate(struct clk *clk, unsigned long rate) |
| 717 | { |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 718 | u32 v, field_val, validrate, new_div = 0; |
| 719 | |
| 720 | if (!clk->clksel_mask) |
| 721 | return -EINVAL; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 722 | |
| 723 | validrate = omap2_clksel_round_rate_div(clk, rate, &new_div); |
| 724 | if (validrate != rate) |
| 725 | return -EINVAL; |
| 726 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 727 | field_val = omap2_divisor_to_clksel(clk, new_div); |
| 728 | if (field_val == ~0) |
| 729 | return -EINVAL; |
| 730 | |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 731 | v = __raw_readl(clk->clksel_reg); |
| 732 | v &= ~clk->clksel_mask; |
| 733 | v |= field_val << __ffs(clk->clksel_mask); |
| 734 | __raw_writel(v, clk->clksel_reg); |
Paul Walmsley | f11fda6 | 2009-01-28 12:35:06 -0700 | [diff] [blame] | 735 | v = __raw_readl(clk->clksel_reg); /* OCP barrier */ |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 736 | |
| 737 | clk->rate = clk->parent->rate / new_div; |
| 738 | |
Paul Walmsley | 439764c | 2009-01-28 12:35:03 -0700 | [diff] [blame] | 739 | _omap2xxx_clk_commit(clk); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | |
| 745 | /* Set the clock rate for a clock source */ |
| 746 | int omap2_clk_set_rate(struct clk *clk, unsigned long rate) |
| 747 | { |
| 748 | int ret = -EINVAL; |
| 749 | |
| 750 | pr_debug("clock: set_rate for clock %s to rate %ld\n", clk->name, rate); |
| 751 | |
| 752 | /* CONFIG_PARTICIPANT clocks are changed only in sets via the |
| 753 | rate table mechanism, driven by mpu_speed */ |
| 754 | if (clk->flags & CONFIG_PARTICIPANT) |
| 755 | return -EINVAL; |
| 756 | |
| 757 | /* dpll_ck, core_ck, virt_prcm_set; plus all clksel clocks */ |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 758 | if (clk->set_rate) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 759 | ret = clk->set_rate(clk, rate); |
| 760 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 761 | return ret; |
| 762 | } |
| 763 | |
| 764 | /* |
| 765 | * Converts encoded control register address into a full address |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 766 | * On error, the return value (parent_div) will be 0. |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 767 | */ |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 768 | static u32 _omap2_clksel_get_src_field(struct clk *src_clk, struct clk *clk, |
| 769 | u32 *field_val) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 770 | { |
| 771 | const struct clksel *clks; |
| 772 | const struct clksel_rate *clkr; |
| 773 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 774 | clks = omap2_get_clksel_by_parent(clk, src_clk); |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 775 | if (!clks) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 776 | return 0; |
| 777 | |
| 778 | for (clkr = clks->rates; clkr->div; clkr++) { |
Russell King | abf2396 | 2009-02-14 13:25:38 +0000 | [diff] [blame] | 779 | if (clkr->flags & cpu_mask && clkr->flags & DEFAULT_RATE) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 780 | break; /* Found the default rate for this platform */ |
| 781 | } |
| 782 | |
| 783 | if (!clkr->div) { |
| 784 | printk(KERN_ERR "clock: Could not find default rate for " |
| 785 | "clock %s parent %s\n", clk->name, |
| 786 | src_clk->parent->name); |
| 787 | return 0; |
| 788 | } |
| 789 | |
| 790 | /* Should never happen. Add a clksel mask to the struct clk. */ |
| 791 | WARN_ON(clk->clksel_mask == 0); |
| 792 | |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 793 | *field_val = clkr->val; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 794 | |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 795 | return clkr->div; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | int omap2_clk_set_parent(struct clk *clk, struct clk *new_parent) |
| 799 | { |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 800 | u32 field_val, v, parent_div; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 801 | |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 802 | if (clk->flags & CONFIG_PARTICIPANT) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 803 | return -EINVAL; |
| 804 | |
| 805 | if (!clk->clksel) |
| 806 | return -EINVAL; |
| 807 | |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 808 | parent_div = _omap2_clksel_get_src_field(new_parent, clk, &field_val); |
| 809 | if (!parent_div) |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 810 | return -EINVAL; |
| 811 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 812 | /* Set new source value (previous dividers if any in effect) */ |
Paul Walmsley | ee1eec3 | 2009-01-28 12:18:19 -0700 | [diff] [blame] | 813 | v = __raw_readl(clk->clksel_reg); |
| 814 | v &= ~clk->clksel_mask; |
| 815 | v |= field_val << __ffs(clk->clksel_mask); |
| 816 | __raw_writel(v, clk->clksel_reg); |
Paul Walmsley | f11fda6 | 2009-01-28 12:35:06 -0700 | [diff] [blame] | 817 | v = __raw_readl(clk->clksel_reg); /* OCP barrier */ |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 818 | |
Paul Walmsley | 439764c | 2009-01-28 12:35:03 -0700 | [diff] [blame] | 819 | _omap2xxx_clk_commit(clk); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 820 | |
Russell King | 3f0a820 | 2009-01-31 10:05:51 +0000 | [diff] [blame] | 821 | clk_reparent(clk, new_parent); |
Russell King | 41f3103 | 2009-02-19 13:25:16 +0000 | [diff] [blame] | 822 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 823 | /* CLKSEL clocks follow their parents' rates, divided by a divisor */ |
| 824 | clk->rate = new_parent->rate; |
| 825 | |
| 826 | if (parent_div > 0) |
| 827 | clk->rate /= parent_div; |
| 828 | |
| 829 | pr_debug("clock: set parent of %s to %s (new rate %ld)\n", |
| 830 | clk->name, clk->parent->name, clk->rate); |
| 831 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 832 | return 0; |
| 833 | } |
| 834 | |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 835 | /* DPLL rate rounding code */ |
| 836 | |
| 837 | /** |
| 838 | * omap2_dpll_set_rate_tolerance: set the error tolerance during rate rounding |
| 839 | * @clk: struct clk * of the DPLL |
| 840 | * @tolerance: maximum rate error tolerance |
| 841 | * |
| 842 | * Set the maximum DPLL rate error tolerance for the rate rounding |
| 843 | * algorithm. The rate tolerance is an attempt to balance DPLL power |
| 844 | * saving (the least divider value "n") vs. rate fidelity (the least |
| 845 | * difference between the desired DPLL target rate and the rounded |
| 846 | * rate out of the algorithm). So, increasing the tolerance is likely |
| 847 | * to decrease DPLL power consumption and increase DPLL rate error. |
| 848 | * Returns -EINVAL if provided a null clock ptr or a clk that is not a |
| 849 | * DPLL; or 0 upon success. |
| 850 | */ |
| 851 | int omap2_dpll_set_rate_tolerance(struct clk *clk, unsigned int tolerance) |
| 852 | { |
| 853 | if (!clk || !clk->dpll_data) |
| 854 | return -EINVAL; |
| 855 | |
| 856 | clk->dpll_data->rate_tolerance = tolerance; |
| 857 | |
| 858 | return 0; |
| 859 | } |
| 860 | |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 861 | static unsigned long _dpll_compute_new_rate(unsigned long parent_rate, |
| 862 | unsigned int m, unsigned int n) |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 863 | { |
| 864 | unsigned long long num; |
| 865 | |
| 866 | num = (unsigned long long)parent_rate * m; |
| 867 | do_div(num, n); |
| 868 | return num; |
| 869 | } |
| 870 | |
| 871 | /* |
| 872 | * _dpll_test_mult - test a DPLL multiplier value |
| 873 | * @m: pointer to the DPLL m (multiplier) value under test |
| 874 | * @n: current DPLL n (divider) value under test |
| 875 | * @new_rate: pointer to storage for the resulting rounded rate |
| 876 | * @target_rate: the desired DPLL rate |
| 877 | * @parent_rate: the DPLL's parent clock rate |
| 878 | * |
| 879 | * This code tests a DPLL multiplier value, ensuring that the |
| 880 | * resulting rate will not be higher than the target_rate, and that |
| 881 | * the multiplier value itself is valid for the DPLL. Initially, the |
| 882 | * integer pointed to by the m argument should be prescaled by |
| 883 | * multiplying by DPLL_SCALE_FACTOR. The code will replace this with |
| 884 | * a non-scaled m upon return. This non-scaled m will result in a |
| 885 | * new_rate as close as possible to target_rate (but not greater than |
| 886 | * target_rate) given the current (parent_rate, n, prescaled m) |
| 887 | * triple. Returns DPLL_MULT_UNDERFLOW in the event that the |
| 888 | * non-scaled m attempted to underflow, which can allow the calling |
| 889 | * function to bail out early; or 0 upon success. |
| 890 | */ |
| 891 | static int _dpll_test_mult(int *m, int n, unsigned long *new_rate, |
| 892 | unsigned long target_rate, |
| 893 | unsigned long parent_rate) |
| 894 | { |
Paul Walmsley | 85a5f78 | 2009-01-28 12:08:41 -0700 | [diff] [blame] | 895 | int r = 0, carry = 0; |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 896 | |
| 897 | /* Unscale m and round if necessary */ |
| 898 | if (*m % DPLL_SCALE_FACTOR >= DPLL_ROUNDING_VAL) |
| 899 | carry = 1; |
| 900 | *m = (*m / DPLL_SCALE_FACTOR) + carry; |
| 901 | |
| 902 | /* |
| 903 | * The new rate must be <= the target rate to avoid programming |
| 904 | * a rate that is impossible for the hardware to handle |
| 905 | */ |
| 906 | *new_rate = _dpll_compute_new_rate(parent_rate, *m, n); |
| 907 | if (*new_rate > target_rate) { |
| 908 | (*m)--; |
| 909 | *new_rate = 0; |
| 910 | } |
| 911 | |
| 912 | /* Guard against m underflow */ |
| 913 | if (*m < DPLL_MIN_MULTIPLIER) { |
| 914 | *m = DPLL_MIN_MULTIPLIER; |
| 915 | *new_rate = 0; |
Paul Walmsley | 85a5f78 | 2009-01-28 12:08:41 -0700 | [diff] [blame] | 916 | r = DPLL_MULT_UNDERFLOW; |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | if (*new_rate == 0) |
| 920 | *new_rate = _dpll_compute_new_rate(parent_rate, *m, n); |
| 921 | |
Paul Walmsley | 85a5f78 | 2009-01-28 12:08:41 -0700 | [diff] [blame] | 922 | return r; |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | /** |
| 926 | * omap2_dpll_round_rate - round a target rate for an OMAP DPLL |
| 927 | * @clk: struct clk * for a DPLL |
| 928 | * @target_rate: desired DPLL clock rate |
| 929 | * |
| 930 | * Given a DPLL, a desired target rate, and a rate tolerance, round |
| 931 | * the target rate to a possible, programmable rate for this DPLL. |
| 932 | * Rate tolerance is assumed to be set by the caller before this |
| 933 | * function is called. Attempts to select the minimum possible n |
| 934 | * within the tolerance to reduce power consumption. Stores the |
| 935 | * computed (m, n) in the DPLL's dpll_data structure so set_rate() |
| 936 | * will not need to call this (expensive) function again. Returns ~0 |
| 937 | * if the target rate cannot be rounded, either because the rate is |
| 938 | * too low or because the rate tolerance is set too tightly; or the |
| 939 | * rounded rate upon success. |
| 940 | */ |
| 941 | long omap2_dpll_round_rate(struct clk *clk, unsigned long target_rate) |
| 942 | { |
| 943 | int m, n, r, e, scaled_max_m; |
| 944 | unsigned long scaled_rt_rp, new_rate; |
| 945 | int min_e = -1, min_e_m = -1, min_e_n = -1; |
Paul Walmsley | b324504 | 2009-01-28 12:08:38 -0700 | [diff] [blame] | 946 | struct dpll_data *dd; |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 947 | |
| 948 | if (!clk || !clk->dpll_data) |
| 949 | return ~0; |
| 950 | |
Paul Walmsley | b324504 | 2009-01-28 12:08:38 -0700 | [diff] [blame] | 951 | dd = clk->dpll_data; |
| 952 | |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 953 | pr_debug("clock: starting DPLL round_rate for clock %s, target rate " |
| 954 | "%ld\n", clk->name, target_rate); |
| 955 | |
Russell King | c0bf313 | 2009-02-19 13:29:22 +0000 | [diff] [blame] | 956 | scaled_rt_rp = target_rate / (dd->clk_ref->rate / DPLL_SCALE_FACTOR); |
Paul Walmsley | b324504 | 2009-01-28 12:08:38 -0700 | [diff] [blame] | 957 | scaled_max_m = dd->max_multiplier * DPLL_SCALE_FACTOR; |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 958 | |
Paul Walmsley | b324504 | 2009-01-28 12:08:38 -0700 | [diff] [blame] | 959 | dd->last_rounded_rate = 0; |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 960 | |
Paul Walmsley | 95f538a | 2009-01-28 12:08:44 -0700 | [diff] [blame] | 961 | for (n = dd->min_divider; n <= dd->max_divider; n++) { |
| 962 | |
| 963 | /* Is the (input clk, divider) pair valid for the DPLL? */ |
| 964 | r = _dpll_test_fint(clk, n); |
| 965 | if (r == DPLL_FINT_UNDERFLOW) |
| 966 | break; |
| 967 | else if (r == DPLL_FINT_INVALID) |
| 968 | continue; |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 969 | |
| 970 | /* Compute the scaled DPLL multiplier, based on the divider */ |
| 971 | m = scaled_rt_rp * n; |
| 972 | |
| 973 | /* |
Paul Walmsley | 85a5f78 | 2009-01-28 12:08:41 -0700 | [diff] [blame] | 974 | * Since we're counting n up, a m overflow means we |
| 975 | * can bail out completely (since as n increases in |
| 976 | * the next iteration, there's no way that m can |
| 977 | * increase beyond the current m) |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 978 | */ |
| 979 | if (m > scaled_max_m) |
Paul Walmsley | 85a5f78 | 2009-01-28 12:08:41 -0700 | [diff] [blame] | 980 | break; |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 981 | |
| 982 | r = _dpll_test_mult(&m, n, &new_rate, target_rate, |
Russell King | c0bf313 | 2009-02-19 13:29:22 +0000 | [diff] [blame] | 983 | dd->clk_ref->rate); |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 984 | |
Paul Walmsley | 85a5f78 | 2009-01-28 12:08:41 -0700 | [diff] [blame] | 985 | /* m can't be set low enough for this n - try with a larger n */ |
| 986 | if (r == DPLL_MULT_UNDERFLOW) |
| 987 | continue; |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 988 | |
| 989 | e = target_rate - new_rate; |
| 990 | pr_debug("clock: n = %d: m = %d: rate error is %d " |
| 991 | "(new_rate = %ld)\n", n, m, e, new_rate); |
| 992 | |
| 993 | if (min_e == -1 || |
Paul Walmsley | b324504 | 2009-01-28 12:08:38 -0700 | [diff] [blame] | 994 | min_e >= (int)(abs(e) - dd->rate_tolerance)) { |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 995 | min_e = e; |
| 996 | min_e_m = m; |
| 997 | min_e_n = n; |
| 998 | |
| 999 | pr_debug("clock: found new least error %d\n", min_e); |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 1000 | |
Paul Walmsley | 85a5f78 | 2009-01-28 12:08:41 -0700 | [diff] [blame] | 1001 | /* We found good settings -- bail out now */ |
Paul Walmsley | 95f538a | 2009-01-28 12:08:44 -0700 | [diff] [blame] | 1002 | if (min_e <= dd->rate_tolerance) |
Paul Walmsley | 85a5f78 | 2009-01-28 12:08:41 -0700 | [diff] [blame] | 1003 | break; |
| 1004 | } |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | if (min_e < 0) { |
| 1008 | pr_debug("clock: error: target rate or tolerance too low\n"); |
| 1009 | return ~0; |
| 1010 | } |
| 1011 | |
Paul Walmsley | b324504 | 2009-01-28 12:08:38 -0700 | [diff] [blame] | 1012 | dd->last_rounded_m = min_e_m; |
| 1013 | dd->last_rounded_n = min_e_n; |
Russell King | c0bf313 | 2009-02-19 13:29:22 +0000 | [diff] [blame] | 1014 | dd->last_rounded_rate = _dpll_compute_new_rate(dd->clk_ref->rate, |
Paul Walmsley | b324504 | 2009-01-28 12:08:38 -0700 | [diff] [blame] | 1015 | min_e_m, min_e_n); |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 1016 | |
| 1017 | pr_debug("clock: final least error: e = %d, m = %d, n = %d\n", |
| 1018 | min_e, min_e_m, min_e_n); |
| 1019 | pr_debug("clock: final rate: %ld (target rate: %ld)\n", |
Paul Walmsley | b324504 | 2009-01-28 12:08:38 -0700 | [diff] [blame] | 1020 | dd->last_rounded_rate, target_rate); |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 1021 | |
Paul Walmsley | b324504 | 2009-01-28 12:08:38 -0700 | [diff] [blame] | 1022 | return dd->last_rounded_rate; |
Paul Walmsley | 88b8ba9 | 2008-07-03 12:24:46 +0300 | [diff] [blame] | 1023 | } |
| 1024 | |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 1025 | /*------------------------------------------------------------------------- |
| 1026 | * Omap2 clock reset and init functions |
| 1027 | *-------------------------------------------------------------------------*/ |
| 1028 | |
| 1029 | #ifdef CONFIG_OMAP_RESET_CLOCKS |
| 1030 | void omap2_clk_disable_unused(struct clk *clk) |
| 1031 | { |
| 1032 | u32 regval32, v; |
| 1033 | |
| 1034 | v = (clk->flags & INVERT_ENABLE) ? (1 << clk->enable_bit) : 0; |
| 1035 | |
| 1036 | regval32 = __raw_readl(clk->enable_reg); |
| 1037 | if ((regval32 & (1 << clk->enable_bit)) == v) |
| 1038 | return; |
| 1039 | |
Artem Bityutskiy | 0db4e82 | 2009-05-12 17:34:40 -0600 | [diff] [blame] | 1040 | printk(KERN_DEBUG "Disabling unused clock \"%s\"\n", clk->name); |
Tero Kristo | 8463e20 | 2009-01-28 12:27:45 -0700 | [diff] [blame] | 1041 | if (cpu_is_omap34xx()) { |
| 1042 | omap2_clk_enable(clk); |
| 1043 | omap2_clk_disable(clk); |
| 1044 | } else |
| 1045 | _omap2_clk_disable(clk); |
Peter 'p2' De Schrijver | fe617af | 2008-10-15 17:48:44 +0300 | [diff] [blame] | 1046 | if (clk->clkdm != NULL) |
| 1047 | pwrdm_clkdm_state_switch(clk->clkdm); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 1048 | } |
| 1049 | #endif |