Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * OMAP3/4 - specific DPLL control functions |
| 3 | * |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 4 | * Copyright (C) 2009-2010 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2009-2010 Nokia Corporation |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 6 | * |
| 7 | * Written by Paul Walmsley |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 8 | * Testing and integration fixes by Jouni Högander |
| 9 | * |
| 10 | * 36xx support added by Vishwanath BS, Richard Woodruff, and Nishanth |
| 11 | * Menon |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 12 | * |
| 13 | * Parts of this code are based on code written by |
| 14 | * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License version 2 as |
| 18 | * published by the Free Software Foundation. |
| 19 | */ |
| 20 | |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 21 | #include <linux/kernel.h> |
| 22 | #include <linux/device.h> |
| 23 | #include <linux/list.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/clk.h> |
| 27 | #include <linux/io.h> |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 28 | #include <linux/bitops.h> |
Jean-Christop PLAGNIOL-VILLARD | 6d803ba | 2010-11-17 10:04:33 +0100 | [diff] [blame] | 29 | #include <linux/clkdev.h> |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 30 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 31 | #include "clockdomain.h" |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 32 | #include "clock.h" |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 33 | |
| 34 | /* CM_AUTOIDLE_PLL*.AUTO_* bit values */ |
| 35 | #define DPLL_AUTOIDLE_DISABLE 0x0 |
| 36 | #define DPLL_AUTOIDLE_LOW_POWER_STOP 0x1 |
| 37 | |
| 38 | #define MAX_DPLL_WAIT_TRIES 1000000 |
| 39 | |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 40 | /* Private functions */ |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 41 | |
| 42 | /* _omap3_dpll_write_clken - write clken_bits arg to a DPLL's enable bits */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 43 | static void _omap3_dpll_write_clken(struct clk_hw_omap *clk, u8 clken_bits) |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 44 | { |
| 45 | const struct dpll_data *dd; |
| 46 | u32 v; |
| 47 | |
| 48 | dd = clk->dpll_data; |
| 49 | |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 50 | v = omap2_clk_readl(clk, dd->control_reg); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 51 | v &= ~dd->enable_mask; |
| 52 | v |= clken_bits << __ffs(dd->enable_mask); |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 53 | omap2_clk_writel(v, clk, dd->control_reg); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /* _omap3_wait_dpll_status: wait for a DPLL to enter a specific state */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 57 | static int _omap3_wait_dpll_status(struct clk_hw_omap *clk, u8 state) |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 58 | { |
| 59 | const struct dpll_data *dd; |
| 60 | int i = 0; |
| 61 | int ret = -EINVAL; |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 62 | const char *clk_name; |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 63 | |
| 64 | dd = clk->dpll_data; |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 65 | clk_name = __clk_get_name(clk->hw.clk); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 66 | |
| 67 | state <<= __ffs(dd->idlest_mask); |
| 68 | |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 69 | while (((omap2_clk_readl(clk, dd->idlest_reg) & dd->idlest_mask) |
| 70 | != state) && i < MAX_DPLL_WAIT_TRIES) { |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 71 | i++; |
| 72 | udelay(1); |
| 73 | } |
| 74 | |
| 75 | if (i == MAX_DPLL_WAIT_TRIES) { |
| 76 | printk(KERN_ERR "clock: %s failed transition to '%s'\n", |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 77 | clk_name, (state) ? "locked" : "bypassed"); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 78 | } else { |
| 79 | pr_debug("clock: %s transition to '%s' in %d loops\n", |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 80 | clk_name, (state) ? "locked" : "bypassed", i); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 81 | |
| 82 | ret = 0; |
| 83 | } |
| 84 | |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | /* From 3430 TRM ES2 4.7.6.2 */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 89 | static u16 _omap3_dpll_compute_freqsel(struct clk_hw_omap *clk, u8 n) |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 90 | { |
| 91 | unsigned long fint; |
| 92 | u16 f = 0; |
| 93 | |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 94 | fint = __clk_get_rate(clk->dpll_data->clk_ref) / n; |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 95 | |
| 96 | pr_debug("clock: fint is %lu\n", fint); |
| 97 | |
| 98 | if (fint >= 750000 && fint <= 1000000) |
| 99 | f = 0x3; |
| 100 | else if (fint > 1000000 && fint <= 1250000) |
| 101 | f = 0x4; |
| 102 | else if (fint > 1250000 && fint <= 1500000) |
| 103 | f = 0x5; |
| 104 | else if (fint > 1500000 && fint <= 1750000) |
| 105 | f = 0x6; |
| 106 | else if (fint > 1750000 && fint <= 2100000) |
| 107 | f = 0x7; |
| 108 | else if (fint > 7500000 && fint <= 10000000) |
| 109 | f = 0xB; |
| 110 | else if (fint > 10000000 && fint <= 12500000) |
| 111 | f = 0xC; |
| 112 | else if (fint > 12500000 && fint <= 15000000) |
| 113 | f = 0xD; |
| 114 | else if (fint > 15000000 && fint <= 17500000) |
| 115 | f = 0xE; |
| 116 | else if (fint > 17500000 && fint <= 21000000) |
| 117 | f = 0xF; |
| 118 | else |
| 119 | pr_debug("clock: unknown freqsel setting for %d\n", n); |
| 120 | |
| 121 | return f; |
| 122 | } |
| 123 | |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 124 | /* |
| 125 | * _omap3_noncore_dpll_lock - instruct a DPLL to lock and wait for readiness |
| 126 | * @clk: pointer to a DPLL struct clk |
| 127 | * |
| 128 | * Instructs a non-CORE DPLL to lock. Waits for the DPLL to report |
| 129 | * readiness before returning. Will save and restore the DPLL's |
| 130 | * autoidle state across the enable, per the CDP code. If the DPLL |
| 131 | * locked successfully, return 0; if the DPLL did not lock in the time |
| 132 | * allotted, or DPLL3 was passed in, return -EINVAL. |
| 133 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 134 | static int _omap3_noncore_dpll_lock(struct clk_hw_omap *clk) |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 135 | { |
Vikram Pandita | 55ffe16 | 2012-07-04 05:00:44 -0600 | [diff] [blame] | 136 | const struct dpll_data *dd; |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 137 | u8 ai; |
Vikram Pandita | 55ffe16 | 2012-07-04 05:00:44 -0600 | [diff] [blame] | 138 | u8 state = 1; |
| 139 | int r = 0; |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 140 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 141 | pr_debug("clock: locking DPLL %s\n", __clk_get_name(clk->hw.clk)); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 142 | |
Vikram Pandita | 55ffe16 | 2012-07-04 05:00:44 -0600 | [diff] [blame] | 143 | dd = clk->dpll_data; |
| 144 | state <<= __ffs(dd->idlest_mask); |
| 145 | |
| 146 | /* Check if already locked */ |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 147 | if ((omap2_clk_readl(clk, dd->idlest_reg) & dd->idlest_mask) == state) |
Vikram Pandita | 55ffe16 | 2012-07-04 05:00:44 -0600 | [diff] [blame] | 148 | goto done; |
| 149 | |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 150 | ai = omap3_dpll_autoidle_read(clk); |
| 151 | |
Vaibhav Bedia | d76316f | 2012-05-07 23:55:30 -0600 | [diff] [blame] | 152 | if (ai) |
| 153 | omap3_dpll_deny_idle(clk); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 154 | |
| 155 | _omap3_dpll_write_clken(clk, DPLL_LOCKED); |
| 156 | |
| 157 | r = _omap3_wait_dpll_status(clk, 1); |
| 158 | |
| 159 | if (ai) |
| 160 | omap3_dpll_allow_idle(clk); |
| 161 | |
Vikram Pandita | 55ffe16 | 2012-07-04 05:00:44 -0600 | [diff] [blame] | 162 | done: |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 163 | return r; |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * _omap3_noncore_dpll_bypass - instruct a DPLL to bypass and wait for readiness |
| 168 | * @clk: pointer to a DPLL struct clk |
| 169 | * |
| 170 | * Instructs a non-CORE DPLL to enter low-power bypass mode. In |
| 171 | * bypass mode, the DPLL's rate is set equal to its parent clock's |
| 172 | * rate. Waits for the DPLL to report readiness before returning. |
| 173 | * Will save and restore the DPLL's autoidle state across the enable, |
| 174 | * per the CDP code. If the DPLL entered bypass mode successfully, |
| 175 | * return 0; if the DPLL did not enter bypass in the time allotted, or |
| 176 | * DPLL3 was passed in, or the DPLL does not support low-power bypass, |
| 177 | * return -EINVAL. |
| 178 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 179 | static int _omap3_noncore_dpll_bypass(struct clk_hw_omap *clk) |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 180 | { |
| 181 | int r; |
| 182 | u8 ai; |
| 183 | |
| 184 | if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_BYPASS))) |
| 185 | return -EINVAL; |
| 186 | |
| 187 | pr_debug("clock: configuring DPLL %s for low-power bypass\n", |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 188 | __clk_get_name(clk->hw.clk)); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 189 | |
| 190 | ai = omap3_dpll_autoidle_read(clk); |
| 191 | |
| 192 | _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_BYPASS); |
| 193 | |
| 194 | r = _omap3_wait_dpll_status(clk, 0); |
| 195 | |
| 196 | if (ai) |
| 197 | omap3_dpll_allow_idle(clk); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 198 | |
| 199 | return r; |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | * _omap3_noncore_dpll_stop - instruct a DPLL to stop |
| 204 | * @clk: pointer to a DPLL struct clk |
| 205 | * |
| 206 | * Instructs a non-CORE DPLL to enter low-power stop. Will save and |
| 207 | * restore the DPLL's autoidle state across the stop, per the CDP |
| 208 | * code. If DPLL3 was passed in, or the DPLL does not support |
| 209 | * low-power stop, return -EINVAL; otherwise, return 0. |
| 210 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 211 | static int _omap3_noncore_dpll_stop(struct clk_hw_omap *clk) |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 212 | { |
| 213 | u8 ai; |
| 214 | |
| 215 | if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_STOP))) |
| 216 | return -EINVAL; |
| 217 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 218 | pr_debug("clock: stopping DPLL %s\n", __clk_get_name(clk->hw.clk)); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 219 | |
| 220 | ai = omap3_dpll_autoidle_read(clk); |
| 221 | |
| 222 | _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_STOP); |
| 223 | |
| 224 | if (ai) |
| 225 | omap3_dpll_allow_idle(clk); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 230 | /** |
Jon Hunter | a36795c | 2010-12-21 21:31:43 -0700 | [diff] [blame] | 231 | * _lookup_dco - Lookup DCO used by j-type DPLL |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 232 | * @clk: pointer to a DPLL struct clk |
| 233 | * @dco: digital control oscillator selector |
Jon Hunter | a36795c | 2010-12-21 21:31:43 -0700 | [diff] [blame] | 234 | * @m: DPLL multiplier to set |
| 235 | * @n: DPLL divider to set |
| 236 | * |
| 237 | * See 36xx TRM section 3.5.3.3.3.2 "Type B DPLL (Low-Jitter)" |
| 238 | * |
| 239 | * XXX This code is not needed for 3430/AM35xx; can it be optimized |
| 240 | * out in non-multi-OMAP builds for those chips? |
| 241 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 242 | static void _lookup_dco(struct clk_hw_omap *clk, u8 *dco, u16 m, u8 n) |
Jon Hunter | a36795c | 2010-12-21 21:31:43 -0700 | [diff] [blame] | 243 | { |
| 244 | unsigned long fint, clkinp; /* watch out for overflow */ |
| 245 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 246 | clkinp = __clk_get_rate(__clk_get_parent(clk->hw.clk)); |
Jon Hunter | a36795c | 2010-12-21 21:31:43 -0700 | [diff] [blame] | 247 | fint = (clkinp / n) * m; |
| 248 | |
| 249 | if (fint < 1000000000) |
| 250 | *dco = 2; |
| 251 | else |
| 252 | *dco = 4; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * _lookup_sddiv - Calculate sigma delta divider for j-type DPLL |
| 257 | * @clk: pointer to a DPLL struct clk |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 258 | * @sd_div: target sigma-delta divider |
| 259 | * @m: DPLL multiplier to set |
| 260 | * @n: DPLL divider to set |
| 261 | * |
| 262 | * See 36xx TRM section 3.5.3.3.3.2 "Type B DPLL (Low-Jitter)" |
| 263 | * |
| 264 | * XXX This code is not needed for 3430/AM35xx; can it be optimized |
| 265 | * out in non-multi-OMAP builds for those chips? |
| 266 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 267 | static void _lookup_sddiv(struct clk_hw_omap *clk, u8 *sd_div, u16 m, u8 n) |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 268 | { |
Jon Hunter | a36795c | 2010-12-21 21:31:43 -0700 | [diff] [blame] | 269 | unsigned long clkinp, sd; /* watch out for overflow */ |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 270 | int mod1, mod2; |
| 271 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 272 | clkinp = __clk_get_rate(__clk_get_parent(clk->hw.clk)); |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 273 | |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 274 | /* |
| 275 | * target sigma-delta to near 250MHz |
| 276 | * sd = ceil[(m/(n+1)) * (clkinp_MHz / 250)] |
| 277 | */ |
| 278 | clkinp /= 100000; /* shift from MHz to 10*Hz for 38.4 and 19.2 */ |
| 279 | mod1 = (clkinp * m) % (250 * n); |
| 280 | sd = (clkinp * m) / (250 * n); |
| 281 | mod2 = sd % 10; |
| 282 | sd /= 10; |
| 283 | |
| 284 | if (mod1 || mod2) |
| 285 | sd++; |
| 286 | *sd_div = sd; |
| 287 | } |
| 288 | |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 289 | /* |
| 290 | * _omap3_noncore_dpll_program - set non-core DPLL M,N values directly |
Jon Hunter | 3ff51ed | 2012-12-15 01:35:46 -0700 | [diff] [blame] | 291 | * @clk: struct clk * of DPLL to set |
| 292 | * @freqsel: FREQSEL value to set |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 293 | * |
Jon Hunter | 3ff51ed | 2012-12-15 01:35:46 -0700 | [diff] [blame] | 294 | * Program the DPLL with the last M, N values calculated, and wait for |
| 295 | * the DPLL to lock. Returns -EINVAL upon error, or 0 upon success. |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 296 | */ |
Jon Hunter | 3ff51ed | 2012-12-15 01:35:46 -0700 | [diff] [blame] | 297 | static int omap3_noncore_dpll_program(struct clk_hw_omap *clk, u16 freqsel) |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 298 | { |
| 299 | struct dpll_data *dd = clk->dpll_data; |
Jon Hunter | a36795c | 2010-12-21 21:31:43 -0700 | [diff] [blame] | 300 | u8 dco, sd_div; |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 301 | u32 v; |
| 302 | |
| 303 | /* 3430 ES2 TRM: 4.7.6.9 DPLL Programming Sequence */ |
| 304 | _omap3_noncore_dpll_bypass(clk); |
| 305 | |
Vishwanath BS | 5eb75f5 | 2010-02-24 12:05:57 -0700 | [diff] [blame] | 306 | /* |
Rajendra Nayak | ecf5164 | 2013-01-29 18:33:49 +0530 | [diff] [blame] | 307 | * Set jitter correction. Jitter correction applicable for OMAP343X |
| 308 | * only since freqsel field is no longer present on other devices. |
Vishwanath BS | 5eb75f5 | 2010-02-24 12:05:57 -0700 | [diff] [blame] | 309 | */ |
Tero Kristo | 2337c5b | 2014-07-02 11:47:43 +0300 | [diff] [blame] | 310 | if (ti_clk_features.flags & TI_CLK_DPLL_HAS_FREQSEL) { |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 311 | v = omap2_clk_readl(clk, dd->control_reg); |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 312 | v &= ~dd->freqsel_mask; |
| 313 | v |= freqsel << __ffs(dd->freqsel_mask); |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 314 | omap2_clk_writel(v, clk, dd->control_reg); |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /* Set DPLL multiplier, divider */ |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 318 | v = omap2_clk_readl(clk, dd->mult_div1_reg); |
Andrii Tseglytskyi | ce369a5 | 2014-05-16 05:45:58 -0500 | [diff] [blame] | 319 | |
| 320 | /* Handle Duty Cycle Correction */ |
| 321 | if (dd->dcc_mask) { |
| 322 | if (dd->last_rounded_rate >= dd->dcc_rate) |
| 323 | v |= dd->dcc_mask; /* Enable DCC */ |
| 324 | else |
| 325 | v &= ~dd->dcc_mask; /* Disable DCC */ |
| 326 | } |
| 327 | |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 328 | v &= ~(dd->mult_mask | dd->div1_mask); |
Jon Hunter | 3ff51ed | 2012-12-15 01:35:46 -0700 | [diff] [blame] | 329 | v |= dd->last_rounded_m << __ffs(dd->mult_mask); |
| 330 | v |= (dd->last_rounded_n - 1) << __ffs(dd->div1_mask); |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 331 | |
Jon Hunter | a36795c | 2010-12-21 21:31:43 -0700 | [diff] [blame] | 332 | /* Configure dco and sd_div for dplls that have these fields */ |
| 333 | if (dd->dco_mask) { |
Jon Hunter | 3ff51ed | 2012-12-15 01:35:46 -0700 | [diff] [blame] | 334 | _lookup_dco(clk, &dco, dd->last_rounded_m, dd->last_rounded_n); |
Jon Hunter | a36795c | 2010-12-21 21:31:43 -0700 | [diff] [blame] | 335 | v &= ~(dd->dco_mask); |
| 336 | v |= dco << __ffs(dd->dco_mask); |
| 337 | } |
| 338 | if (dd->sddiv_mask) { |
Jon Hunter | 3ff51ed | 2012-12-15 01:35:46 -0700 | [diff] [blame] | 339 | _lookup_sddiv(clk, &sd_div, dd->last_rounded_m, |
| 340 | dd->last_rounded_n); |
Jon Hunter | a36795c | 2010-12-21 21:31:43 -0700 | [diff] [blame] | 341 | v &= ~(dd->sddiv_mask); |
| 342 | v |= sd_div << __ffs(dd->sddiv_mask); |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 345 | omap2_clk_writel(v, clk, dd->mult_div1_reg); |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 346 | |
Jon Hunter | 3ff51ed | 2012-12-15 01:35:46 -0700 | [diff] [blame] | 347 | /* Set 4X multiplier and low-power mode */ |
| 348 | if (dd->m4xen_mask || dd->lpmode_mask) { |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 349 | v = omap2_clk_readl(clk, dd->control_reg); |
Jon Hunter | 3ff51ed | 2012-12-15 01:35:46 -0700 | [diff] [blame] | 350 | |
| 351 | if (dd->m4xen_mask) { |
| 352 | if (dd->last_rounded_m4xen) |
| 353 | v |= dd->m4xen_mask; |
| 354 | else |
| 355 | v &= ~dd->m4xen_mask; |
| 356 | } |
| 357 | |
| 358 | if (dd->lpmode_mask) { |
| 359 | if (dd->last_rounded_lpmode) |
| 360 | v |= dd->lpmode_mask; |
| 361 | else |
| 362 | v &= ~dd->lpmode_mask; |
| 363 | } |
| 364 | |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 365 | omap2_clk_writel(v, clk, dd->control_reg); |
Jon Hunter | 3ff51ed | 2012-12-15 01:35:46 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 368 | /* We let the clock framework set the other output dividers later */ |
| 369 | |
| 370 | /* REVISIT: Set ramp-up delay? */ |
| 371 | |
| 372 | _omap3_noncore_dpll_lock(clk); |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | /* Public functions */ |
| 378 | |
| 379 | /** |
| 380 | * omap3_dpll_recalc - recalculate DPLL rate |
| 381 | * @clk: DPLL struct clk |
| 382 | * |
| 383 | * Recalculate and propagate the DPLL rate. |
| 384 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 385 | unsigned long omap3_dpll_recalc(struct clk_hw *hw, unsigned long parent_rate) |
| 386 | { |
| 387 | struct clk_hw_omap *clk = to_clk_hw_omap(hw); |
Paul Walmsley | 455db9c | 2012-11-10 19:32:46 -0700 | [diff] [blame] | 388 | |
Paul Walmsley | 60c3f65 | 2010-01-26 20:13:11 -0700 | [diff] [blame] | 389 | return omap2_get_dpll_rate(clk); |
| 390 | } |
| 391 | |
| 392 | /* Non-CORE DPLL (e.g., DPLLs that do not control SDRC) clock functions */ |
| 393 | |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 394 | /** |
| 395 | * omap3_noncore_dpll_enable - instruct a DPLL to enter bypass or lock mode |
| 396 | * @clk: pointer to a DPLL struct clk |
| 397 | * |
| 398 | * Instructs a non-CORE DPLL to enable, e.g., to enter bypass or lock. |
| 399 | * The choice of modes depends on the DPLL's programmed rate: if it is |
| 400 | * the same as the DPLL's parent clock, it will enter bypass; |
| 401 | * otherwise, it will enter lock. This code will wait for the DPLL to |
| 402 | * indicate readiness before returning, unless the DPLL takes too long |
| 403 | * to enter the target state. Intended to be used as the struct clk's |
| 404 | * enable function. If DPLL3 was passed in, or the DPLL does not |
| 405 | * support low-power stop, or if the DPLL took too long to enter |
| 406 | * bypass or lock, return -EINVAL; otherwise, return 0. |
| 407 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 408 | int omap3_noncore_dpll_enable(struct clk_hw *hw) |
| 409 | { |
| 410 | struct clk_hw_omap *clk = to_clk_hw_omap(hw); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 411 | int r; |
| 412 | struct dpll_data *dd; |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 413 | struct clk *parent; |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 414 | |
| 415 | dd = clk->dpll_data; |
| 416 | if (!dd) |
| 417 | return -EINVAL; |
| 418 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 419 | if (clk->clkdm) { |
| 420 | r = clkdm_clk_enable(clk->clkdm, hw->clk); |
| 421 | if (r) { |
| 422 | WARN(1, |
| 423 | "%s: could not enable %s's clockdomain %s: %d\n", |
| 424 | __func__, __clk_get_name(hw->clk), |
| 425 | clk->clkdm->name, r); |
| 426 | return r; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | parent = __clk_get_parent(hw->clk); |
| 431 | |
| 432 | if (__clk_get_rate(hw->clk) == __clk_get_rate(dd->clk_bypass)) { |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 433 | WARN_ON(parent != dd->clk_bypass); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 434 | r = _omap3_noncore_dpll_bypass(clk); |
| 435 | } else { |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 436 | WARN_ON(parent != dd->clk_ref); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 437 | r = _omap3_noncore_dpll_lock(clk); |
| 438 | } |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 439 | |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 440 | return r; |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * omap3_noncore_dpll_disable - instruct a DPLL to enter low-power stop |
| 445 | * @clk: pointer to a DPLL struct clk |
| 446 | * |
| 447 | * Instructs a non-CORE DPLL to enter low-power stop. This function is |
| 448 | * intended for use in struct clkops. No return value. |
| 449 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 450 | void omap3_noncore_dpll_disable(struct clk_hw *hw) |
| 451 | { |
| 452 | struct clk_hw_omap *clk = to_clk_hw_omap(hw); |
| 453 | |
| 454 | _omap3_noncore_dpll_stop(clk); |
| 455 | if (clk->clkdm) |
| 456 | clkdm_clk_disable(clk->clkdm, hw->clk); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | |
| 460 | /* Non-CORE DPLL rate set code */ |
| 461 | |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 462 | /** |
| 463 | * omap3_noncore_dpll_set_rate - set non-core DPLL rate |
| 464 | * @clk: struct clk * of DPLL to set |
| 465 | * @rate: rounded target rate |
| 466 | * |
| 467 | * Set the DPLL CLKOUT to the target rate. If the DPLL can enter |
| 468 | * low-power bypass, and the target rate is the bypass source clock |
| 469 | * rate, then configure the DPLL for bypass. Otherwise, round the |
| 470 | * target rate if it hasn't been done already, then program and lock |
| 471 | * the DPLL. Returns -EINVAL upon error, or 0 upon success. |
| 472 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 473 | int omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate, |
| 474 | unsigned long parent_rate) |
| 475 | { |
| 476 | struct clk_hw_omap *clk = to_clk_hw_omap(hw); |
| 477 | struct clk *new_parent = NULL; |
Paul Walmsley | 0a26344 | 2014-07-25 06:11:15 -0600 | [diff] [blame] | 478 | unsigned long rrate; |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 479 | u16 freqsel = 0; |
| 480 | struct dpll_data *dd; |
| 481 | int ret; |
| 482 | |
| 483 | if (!hw || !rate) |
| 484 | return -EINVAL; |
| 485 | |
| 486 | dd = clk->dpll_data; |
| 487 | if (!dd) |
| 488 | return -EINVAL; |
| 489 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 490 | if (__clk_get_rate(dd->clk_bypass) == rate && |
| 491 | (dd->modes & (1 << DPLL_LOW_POWER_BYPASS))) { |
| 492 | pr_debug("%s: %s: set rate: entering bypass.\n", |
| 493 | __func__, __clk_get_name(hw->clk)); |
| 494 | |
Rajendra Nayak | 469d633 | 2013-03-31 20:22:23 -0600 | [diff] [blame] | 495 | __clk_prepare(dd->clk_bypass); |
| 496 | clk_enable(dd->clk_bypass); |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 497 | ret = _omap3_noncore_dpll_bypass(clk); |
| 498 | if (!ret) |
| 499 | new_parent = dd->clk_bypass; |
Rajendra Nayak | 469d633 | 2013-03-31 20:22:23 -0600 | [diff] [blame] | 500 | clk_disable(dd->clk_bypass); |
| 501 | __clk_unprepare(dd->clk_bypass); |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 502 | } else { |
Rajendra Nayak | 469d633 | 2013-03-31 20:22:23 -0600 | [diff] [blame] | 503 | __clk_prepare(dd->clk_ref); |
| 504 | clk_enable(dd->clk_ref); |
| 505 | |
Paul Walmsley | 0a26344 | 2014-07-25 06:11:15 -0600 | [diff] [blame] | 506 | /* XXX this check is probably pointless in the CCF context */ |
| 507 | if (dd->last_rounded_rate != rate) { |
| 508 | rrate = __clk_round_rate(hw->clk, rate); |
| 509 | if (rrate != rate) { |
| 510 | pr_warn("%s: %s: final rate %lu does not match desired rate %lu\n", |
| 511 | __func__, __clk_get_name(hw->clk), |
| 512 | rrate, rate); |
| 513 | rate = rrate; |
| 514 | } |
| 515 | } |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 516 | |
| 517 | if (dd->last_rounded_rate == 0) |
| 518 | return -EINVAL; |
| 519 | |
Rajendra Nayak | ecf5164 | 2013-01-29 18:33:49 +0530 | [diff] [blame] | 520 | /* Freqsel is available only on OMAP343X devices */ |
Tero Kristo | 2337c5b | 2014-07-02 11:47:43 +0300 | [diff] [blame] | 521 | if (ti_clk_features.flags & TI_CLK_DPLL_HAS_FREQSEL) { |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 522 | freqsel = _omap3_dpll_compute_freqsel(clk, |
| 523 | dd->last_rounded_n); |
Julia Lawall | f64d204 | 2012-12-16 11:30:02 -0800 | [diff] [blame] | 524 | WARN_ON(!freqsel); |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | pr_debug("%s: %s: set rate: locking rate to %lu.\n", |
| 528 | __func__, __clk_get_name(hw->clk), rate); |
| 529 | |
Jon Hunter | 3ff51ed | 2012-12-15 01:35:46 -0700 | [diff] [blame] | 530 | ret = omap3_noncore_dpll_program(clk, freqsel); |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 531 | if (!ret) |
| 532 | new_parent = dd->clk_ref; |
Rajendra Nayak | 469d633 | 2013-03-31 20:22:23 -0600 | [diff] [blame] | 533 | clk_disable(dd->clk_ref); |
| 534 | __clk_unprepare(dd->clk_ref); |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 535 | } |
| 536 | /* |
| 537 | * FIXME - this is all wrong. common code handles reparenting and |
| 538 | * migrating prepare/enable counts. dplls should be a multiplexer |
| 539 | * clock and this should be a set_parent operation so that all of that |
| 540 | * stuff is inherited for free |
| 541 | */ |
| 542 | |
Nishanth Menon | 110e884 | 2014-02-28 12:43:47 -0700 | [diff] [blame] | 543 | if (!ret && clk_get_parent(hw->clk) != new_parent) |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 544 | __clk_reparent(hw->clk, new_parent); |
| 545 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 546 | return 0; |
| 547 | } |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 548 | |
Tero Kristo | d539efa | 2014-10-03 16:57:11 +0300 | [diff] [blame^] | 549 | /** |
| 550 | * omap3_noncore_dpll_determine_rate - determine rate for a DPLL |
| 551 | * @hw: pointer to the clock to determine rate for |
| 552 | * @rate: target rate for the DPLL |
| 553 | * @best_parent_rate: pointer for returning best parent rate |
| 554 | * @best_parent_clk: pointer for returning best parent clock |
| 555 | * |
| 556 | * Determines which DPLL mode to use for reaching a desired target rate. |
| 557 | * Checks whether the DPLL shall be in bypass or locked mode, and if |
| 558 | * locked, calculates the M,N values for the DPLL via round-rate. |
| 559 | * Returns a positive clock rate with success, negative error value |
| 560 | * in failure. |
| 561 | */ |
| 562 | long omap3_noncore_dpll_determine_rate(struct clk_hw *hw, unsigned long rate, |
| 563 | unsigned long *best_parent_rate, |
| 564 | struct clk **best_parent_clk) |
| 565 | { |
| 566 | struct clk_hw_omap *clk = to_clk_hw_omap(hw); |
| 567 | struct dpll_data *dd; |
| 568 | |
| 569 | if (!hw || !rate) |
| 570 | return -EINVAL; |
| 571 | |
| 572 | dd = clk->dpll_data; |
| 573 | if (!dd) |
| 574 | return -EINVAL; |
| 575 | |
| 576 | if (__clk_get_rate(dd->clk_bypass) == rate && |
| 577 | (dd->modes & (1 << DPLL_LOW_POWER_BYPASS))) { |
| 578 | *best_parent_clk = dd->clk_bypass; |
| 579 | } else { |
| 580 | rate = omap2_dpll_round_rate(hw, rate, best_parent_rate); |
| 581 | *best_parent_clk = dd->clk_ref; |
| 582 | } |
| 583 | |
| 584 | *best_parent_rate = rate; |
| 585 | |
| 586 | return rate; |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * omap3_noncore_dpll_set_parent - set parent for a DPLL clock |
| 591 | * @hw: pointer to the clock to set parent for |
| 592 | * @index: parent index to select |
| 593 | * |
| 594 | * Sets parent for a DPLL clock. This sets the DPLL into bypass or |
| 595 | * locked mode. Returns 0 with success, negative error value otherwise. |
| 596 | */ |
| 597 | int omap3_noncore_dpll_set_parent(struct clk_hw *hw, u8 index) |
| 598 | { |
| 599 | struct clk_hw_omap *clk = to_clk_hw_omap(hw); |
| 600 | int ret; |
| 601 | |
| 602 | if (!hw) |
| 603 | return -EINVAL; |
| 604 | |
| 605 | if (index) |
| 606 | ret = _omap3_noncore_dpll_bypass(clk); |
| 607 | else |
| 608 | ret = _omap3_noncore_dpll_lock(clk); |
| 609 | |
| 610 | return ret; |
| 611 | } |
| 612 | |
| 613 | /** |
| 614 | * omap3_noncore_dpll_set_rate_new - set rate for a DPLL clock |
| 615 | * @hw: pointer to the clock to set parent for |
| 616 | * @rate: target rate for the clock |
| 617 | * @parent_rate: rate of the parent clock |
| 618 | * |
| 619 | * Sets rate for a DPLL clock. First checks if the clock parent is |
| 620 | * reference clock (in bypass mode, the rate of the clock can't be |
| 621 | * changed) and proceeds with the rate change operation. Returns 0 |
| 622 | * with success, negative error value otherwise. |
| 623 | */ |
| 624 | static int omap3_noncore_dpll_set_rate_new(struct clk_hw *hw, |
| 625 | unsigned long rate, |
| 626 | unsigned long parent_rate) |
| 627 | { |
| 628 | struct clk_hw_omap *clk = to_clk_hw_omap(hw); |
| 629 | struct dpll_data *dd; |
| 630 | u16 freqsel = 0; |
| 631 | int ret; |
| 632 | |
| 633 | if (!hw || !rate) |
| 634 | return -EINVAL; |
| 635 | |
| 636 | dd = clk->dpll_data; |
| 637 | if (!dd) |
| 638 | return -EINVAL; |
| 639 | |
| 640 | if (__clk_get_parent(hw->clk) != dd->clk_ref) |
| 641 | return -EINVAL; |
| 642 | |
| 643 | if (dd->last_rounded_rate == 0) |
| 644 | return -EINVAL; |
| 645 | |
| 646 | /* Freqsel is available only on OMAP343X devices */ |
| 647 | if (ti_clk_features.flags & TI_CLK_DPLL_HAS_FREQSEL) { |
| 648 | freqsel = _omap3_dpll_compute_freqsel(clk, dd->last_rounded_n); |
| 649 | WARN_ON(!freqsel); |
| 650 | } |
| 651 | |
| 652 | pr_debug("%s: %s: set rate: locking rate to %lu.\n", __func__, |
| 653 | __clk_get_name(hw->clk), rate); |
| 654 | |
| 655 | ret = omap3_noncore_dpll_program(clk, freqsel); |
| 656 | |
| 657 | return ret; |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * omap3_noncore_dpll_set_rate_and_parent - set rate and parent for a DPLL clock |
| 662 | * @hw: pointer to the clock to set rate and parent for |
| 663 | * @rate: target rate for the DPLL |
| 664 | * @parent_rate: clock rate of the DPLL parent |
| 665 | * @index: new parent index for the DPLL, 0 - reference, 1 - bypass |
| 666 | * |
| 667 | * Sets rate and parent for a DPLL clock. If new parent is the bypass |
| 668 | * clock, only selects the parent. Otherwise proceeds with a rate |
| 669 | * change, as this will effectively also change the parent as the |
| 670 | * DPLL is put into locked mode. Returns 0 with success, negative error |
| 671 | * value otherwise. |
| 672 | */ |
| 673 | int omap3_noncore_dpll_set_rate_and_parent(struct clk_hw *hw, |
| 674 | unsigned long rate, |
| 675 | unsigned long parent_rate, |
| 676 | u8 index) |
| 677 | { |
| 678 | int ret; |
| 679 | |
| 680 | if (!hw || !rate) |
| 681 | return -EINVAL; |
| 682 | |
| 683 | /* |
| 684 | * clk-ref at index[0], in which case we only need to set rate, |
| 685 | * the parent will be changed automatically with the lock sequence. |
| 686 | * With clk-bypass case we only need to change parent. |
| 687 | */ |
| 688 | if (index) |
| 689 | ret = omap3_noncore_dpll_set_parent(hw, index); |
| 690 | else |
| 691 | ret = omap3_noncore_dpll_set_rate_new(hw, rate, parent_rate); |
| 692 | |
| 693 | return ret; |
| 694 | } |
| 695 | |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 696 | /* DPLL autoidle read/set code */ |
| 697 | |
| 698 | /** |
| 699 | * omap3_dpll_autoidle_read - read a DPLL's autoidle bits |
| 700 | * @clk: struct clk * of the DPLL to read |
| 701 | * |
| 702 | * Return the DPLL's autoidle bits, shifted down to bit 0. Returns |
| 703 | * -EINVAL if passed a null pointer or if the struct clk does not |
| 704 | * appear to refer to a DPLL. |
| 705 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 706 | u32 omap3_dpll_autoidle_read(struct clk_hw_omap *clk) |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 707 | { |
| 708 | const struct dpll_data *dd; |
| 709 | u32 v; |
| 710 | |
| 711 | if (!clk || !clk->dpll_data) |
| 712 | return -EINVAL; |
| 713 | |
| 714 | dd = clk->dpll_data; |
| 715 | |
Vaibhav Bedia | d76316f | 2012-05-07 23:55:30 -0600 | [diff] [blame] | 716 | if (!dd->autoidle_reg) |
| 717 | return -EINVAL; |
| 718 | |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 719 | v = omap2_clk_readl(clk, dd->autoidle_reg); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 720 | v &= dd->autoidle_mask; |
| 721 | v >>= __ffs(dd->autoidle_mask); |
| 722 | |
| 723 | return v; |
| 724 | } |
| 725 | |
| 726 | /** |
| 727 | * omap3_dpll_allow_idle - enable DPLL autoidle bits |
| 728 | * @clk: struct clk * of the DPLL to operate on |
| 729 | * |
| 730 | * Enable DPLL automatic idle control. This automatic idle mode |
| 731 | * switching takes effect only when the DPLL is locked, at least on |
| 732 | * OMAP3430. The DPLL will enter low-power stop when its downstream |
| 733 | * clocks are gated. No return value. |
| 734 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 735 | void omap3_dpll_allow_idle(struct clk_hw_omap *clk) |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 736 | { |
| 737 | const struct dpll_data *dd; |
| 738 | u32 v; |
| 739 | |
| 740 | if (!clk || !clk->dpll_data) |
| 741 | return; |
| 742 | |
| 743 | dd = clk->dpll_data; |
| 744 | |
Paul Walmsley | 455db9c | 2012-11-10 19:32:46 -0700 | [diff] [blame] | 745 | if (!dd->autoidle_reg) |
Vaibhav Bedia | d76316f | 2012-05-07 23:55:30 -0600 | [diff] [blame] | 746 | return; |
Vaibhav Bedia | d76316f | 2012-05-07 23:55:30 -0600 | [diff] [blame] | 747 | |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 748 | /* |
| 749 | * REVISIT: CORE DPLL can optionally enter low-power bypass |
| 750 | * by writing 0x5 instead of 0x1. Add some mechanism to |
| 751 | * optionally enter this mode. |
| 752 | */ |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 753 | v = omap2_clk_readl(clk, dd->autoidle_reg); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 754 | v &= ~dd->autoidle_mask; |
| 755 | v |= DPLL_AUTOIDLE_LOW_POWER_STOP << __ffs(dd->autoidle_mask); |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 756 | omap2_clk_writel(v, clk, dd->autoidle_reg); |
Vaibhav Bedia | d76316f | 2012-05-07 23:55:30 -0600 | [diff] [blame] | 757 | |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /** |
| 761 | * omap3_dpll_deny_idle - prevent DPLL from automatically idling |
| 762 | * @clk: struct clk * of the DPLL to operate on |
| 763 | * |
| 764 | * Disable DPLL automatic idle control. No return value. |
| 765 | */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 766 | void omap3_dpll_deny_idle(struct clk_hw_omap *clk) |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 767 | { |
| 768 | const struct dpll_data *dd; |
| 769 | u32 v; |
| 770 | |
| 771 | if (!clk || !clk->dpll_data) |
| 772 | return; |
| 773 | |
| 774 | dd = clk->dpll_data; |
| 775 | |
Paul Walmsley | 455db9c | 2012-11-10 19:32:46 -0700 | [diff] [blame] | 776 | if (!dd->autoidle_reg) |
Vaibhav Bedia | d76316f | 2012-05-07 23:55:30 -0600 | [diff] [blame] | 777 | return; |
Vaibhav Bedia | d76316f | 2012-05-07 23:55:30 -0600 | [diff] [blame] | 778 | |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 779 | v = omap2_clk_readl(clk, dd->autoidle_reg); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 780 | v &= ~dd->autoidle_mask; |
| 781 | v |= DPLL_AUTOIDLE_DISABLE << __ffs(dd->autoidle_mask); |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 782 | omap2_clk_writel(v, clk, dd->autoidle_reg); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 783 | |
| 784 | } |
| 785 | |
| 786 | /* Clock control for DPLL outputs */ |
| 787 | |
Tomi Valkeinen | 994c41e | 2014-01-30 13:17:20 +0200 | [diff] [blame] | 788 | /* Find the parent DPLL for the given clkoutx2 clock */ |
| 789 | static struct clk_hw_omap *omap3_find_clkoutx2_dpll(struct clk_hw *hw) |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 790 | { |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 791 | struct clk_hw_omap *pclk = NULL; |
| 792 | struct clk *parent; |
| 793 | |
| 794 | /* Walk up the parents of clk, looking for a DPLL */ |
| 795 | do { |
| 796 | do { |
| 797 | parent = __clk_get_parent(hw->clk); |
| 798 | hw = __clk_get_hw(parent); |
| 799 | } while (hw && (__clk_get_flags(hw->clk) & CLK_IS_BASIC)); |
| 800 | if (!hw) |
| 801 | break; |
| 802 | pclk = to_clk_hw_omap(hw); |
| 803 | } while (pclk && !pclk->dpll_data); |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 804 | |
Paul Walmsley | a032d33 | 2012-08-03 09:21:10 -0600 | [diff] [blame] | 805 | /* clk does not have a DPLL as a parent? error in the clock data */ |
| 806 | if (!pclk) { |
| 807 | WARN_ON(1); |
Tomi Valkeinen | 994c41e | 2014-01-30 13:17:20 +0200 | [diff] [blame] | 808 | return NULL; |
Paul Walmsley | a032d33 | 2012-08-03 09:21:10 -0600 | [diff] [blame] | 809 | } |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 810 | |
Tomi Valkeinen | 994c41e | 2014-01-30 13:17:20 +0200 | [diff] [blame] | 811 | return pclk; |
| 812 | } |
| 813 | |
| 814 | /** |
| 815 | * omap3_clkoutx2_recalc - recalculate DPLL X2 output virtual clock rate |
| 816 | * @clk: DPLL output struct clk |
| 817 | * |
| 818 | * Using parent clock DPLL data, look up DPLL state. If locked, set our |
| 819 | * rate to the dpll_clk * 2; otherwise, just use dpll_clk. |
| 820 | */ |
| 821 | unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw, |
| 822 | unsigned long parent_rate) |
| 823 | { |
| 824 | const struct dpll_data *dd; |
| 825 | unsigned long rate; |
| 826 | u32 v; |
| 827 | struct clk_hw_omap *pclk = NULL; |
| 828 | |
| 829 | if (!parent_rate) |
| 830 | return 0; |
| 831 | |
| 832 | pclk = omap3_find_clkoutx2_dpll(hw); |
| 833 | |
| 834 | if (!pclk) |
| 835 | return 0; |
| 836 | |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 837 | dd = pclk->dpll_data; |
| 838 | |
| 839 | WARN_ON(!dd->enable_mask); |
| 840 | |
Tero Kristo | 519ab8b | 2013-10-22 11:49:58 +0300 | [diff] [blame] | 841 | v = omap2_clk_readl(pclk, dd->control_reg) & dd->enable_mask; |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 842 | v >>= __ffs(dd->enable_mask); |
Richard Woodruff | 358965d | 2010-02-22 22:09:08 -0700 | [diff] [blame] | 843 | if ((v != OMAP3XXX_EN_DPLL_LOCKED) || (dd->flags & DPLL_J_TYPE)) |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 844 | rate = parent_rate; |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 845 | else |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 846 | rate = parent_rate * 2; |
Rajendra Nayak | a1391d2 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 847 | return rate; |
| 848 | } |
Vaibhav Hiremath | 353cec4 | 2012-07-05 08:05:15 -0700 | [diff] [blame] | 849 | |
Tomi Valkeinen | 994c41e | 2014-01-30 13:17:20 +0200 | [diff] [blame] | 850 | int omap3_clkoutx2_set_rate(struct clk_hw *hw, unsigned long rate, |
| 851 | unsigned long parent_rate) |
| 852 | { |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | long omap3_clkoutx2_round_rate(struct clk_hw *hw, unsigned long rate, |
| 857 | unsigned long *prate) |
| 858 | { |
| 859 | const struct dpll_data *dd; |
| 860 | u32 v; |
| 861 | struct clk_hw_omap *pclk = NULL; |
| 862 | |
| 863 | if (!*prate) |
| 864 | return 0; |
| 865 | |
| 866 | pclk = omap3_find_clkoutx2_dpll(hw); |
| 867 | |
| 868 | if (!pclk) |
| 869 | return 0; |
| 870 | |
| 871 | dd = pclk->dpll_data; |
| 872 | |
| 873 | /* TYPE J does not have a clkoutx2 */ |
| 874 | if (dd->flags & DPLL_J_TYPE) { |
| 875 | *prate = __clk_round_rate(__clk_get_parent(pclk->hw.clk), rate); |
| 876 | return *prate; |
| 877 | } |
| 878 | |
| 879 | WARN_ON(!dd->enable_mask); |
| 880 | |
| 881 | v = omap2_clk_readl(pclk, dd->control_reg) & dd->enable_mask; |
| 882 | v >>= __ffs(dd->enable_mask); |
| 883 | |
| 884 | /* If in bypass, the rate is fixed to the bypass rate*/ |
| 885 | if (v != OMAP3XXX_EN_DPLL_LOCKED) |
| 886 | return *prate; |
| 887 | |
| 888 | if (__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT) { |
| 889 | unsigned long best_parent; |
| 890 | |
| 891 | best_parent = (rate / 2); |
| 892 | *prate = __clk_round_rate(__clk_get_parent(hw->clk), |
| 893 | best_parent); |
| 894 | } |
| 895 | |
| 896 | return *prate * 2; |
| 897 | } |
| 898 | |
Vaibhav Hiremath | 353cec4 | 2012-07-05 08:05:15 -0700 | [diff] [blame] | 899 | /* OMAP3/4 non-CORE DPLL clkops */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 900 | const struct clk_hw_omap_ops clkhwops_omap3_dpll = { |
| 901 | .allow_idle = omap3_dpll_allow_idle, |
| 902 | .deny_idle = omap3_dpll_deny_idle, |
| 903 | }; |