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