aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap2/clkt_dpll.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-omap2/clkt_dpll.c')
-rw-r--r--arch/arm/mach-omap2/clkt_dpll.c94
1 files changed, 24 insertions, 70 deletions
diff --git a/arch/arm/mach-omap2/clkt_dpll.c b/arch/arm/mach-omap2/clkt_dpll.c
index 6ce512e902c6..bcffee001bfa 100644
--- a/arch/arm/mach-omap2/clkt_dpll.c
+++ b/arch/arm/mach-omap2/clkt_dpll.c
@@ -24,7 +24,6 @@
24#include <plat/clock.h> 24#include <plat/clock.h>
25 25
26#include "clock.h" 26#include "clock.h"
27#include "cm.h"
28#include "cm-regbits-24xx.h" 27#include "cm-regbits-24xx.h"
29#include "cm-regbits-34xx.h" 28#include "cm-regbits-34xx.h"
30 29
@@ -78,7 +77,7 @@ static int _dpll_test_fint(struct clk *clk, u8 n)
78 dd = clk->dpll_data; 77 dd = clk->dpll_data;
79 78
80 /* DPLL divider must result in a valid jitter correction val */ 79 /* DPLL divider must result in a valid jitter correction val */
81 fint = clk->parent->rate / (n + 1); 80 fint = clk->parent->rate / n;
82 if (fint < DPLL_FINT_BAND1_MIN) { 81 if (fint < DPLL_FINT_BAND1_MIN) {
83 82
84 pr_debug("rejecting n=%d due to Fint failure, " 83 pr_debug("rejecting n=%d due to Fint failure, "
@@ -179,12 +178,11 @@ void omap2_init_dpll_parent(struct clk *clk)
179 if (!dd) 178 if (!dd)
180 return; 179 return;
181 180
182 /* Return bypass rate if DPLL is bypassed */
183 v = __raw_readl(dd->control_reg); 181 v = __raw_readl(dd->control_reg);
184 v &= dd->enable_mask; 182 v &= dd->enable_mask;
185 v >>= __ffs(dd->enable_mask); 183 v >>= __ffs(dd->enable_mask);
186 184
187 /* Reparent in case the dpll is in bypass */ 185 /* Reparent the struct clk in case the dpll is in bypass */
188 if (cpu_is_omap24xx()) { 186 if (cpu_is_omap24xx()) {
189 if (v == OMAP2XXX_EN_DPLL_LPBYPASS || 187 if (v == OMAP2XXX_EN_DPLL_LPBYPASS ||
190 v == OMAP2XXX_EN_DPLL_FRBYPASS) 188 v == OMAP2XXX_EN_DPLL_FRBYPASS)
@@ -261,50 +259,22 @@ u32 omap2_get_dpll_rate(struct clk *clk)
261/* DPLL rate rounding code */ 259/* DPLL rate rounding code */
262 260
263/** 261/**
264 * omap2_dpll_set_rate_tolerance: set the error tolerance during rate rounding
265 * @clk: struct clk * of the DPLL
266 * @tolerance: maximum rate error tolerance
267 *
268 * Set the maximum DPLL rate error tolerance for the rate rounding
269 * algorithm. The rate tolerance is an attempt to balance DPLL power
270 * saving (the least divider value "n") vs. rate fidelity (the least
271 * difference between the desired DPLL target rate and the rounded
272 * rate out of the algorithm). So, increasing the tolerance is likely
273 * to decrease DPLL power consumption and increase DPLL rate error.
274 * Returns -EINVAL if provided a null clock ptr or a clk that is not a
275 * DPLL; or 0 upon success.
276 */
277int omap2_dpll_set_rate_tolerance(struct clk *clk, unsigned int tolerance)
278{
279 if (!clk || !clk->dpll_data)
280 return -EINVAL;
281
282 clk->dpll_data->rate_tolerance = tolerance;
283
284 return 0;
285}
286
287/**
288 * omap2_dpll_round_rate - round a target rate for an OMAP DPLL 262 * omap2_dpll_round_rate - round a target rate for an OMAP DPLL
289 * @clk: struct clk * for a DPLL 263 * @clk: struct clk * for a DPLL
290 * @target_rate: desired DPLL clock rate 264 * @target_rate: desired DPLL clock rate
291 * 265 *
292 * Given a DPLL, a desired target rate, and a rate tolerance, round 266 * Given a DPLL and a desired target rate, round the target rate to a
293 * the target rate to a possible, programmable rate for this DPLL. 267 * possible, programmable rate for this DPLL. Attempts to select the
294 * Rate tolerance is assumed to be set by the caller before this 268 * minimum possible n. Stores the computed (m, n) in the DPLL's
295 * function is called. Attempts to select the minimum possible n 269 * dpll_data structure so set_rate() will not need to call this
296 * within the tolerance to reduce power consumption. Stores the 270 * (expensive) function again. Returns ~0 if the target rate cannot
297 * computed (m, n) in the DPLL's dpll_data structure so set_rate() 271 * be rounded, or the rounded rate upon success.
298 * will not need to call this (expensive) function again. Returns ~0
299 * if the target rate cannot be rounded, either because the rate is
300 * too low or because the rate tolerance is set too tightly; or the
301 * rounded rate upon success.
302 */ 272 */
303long omap2_dpll_round_rate(struct clk *clk, unsigned long target_rate) 273long omap2_dpll_round_rate(struct clk *clk, unsigned long target_rate)
304{ 274{
305 int m, n, r, e, scaled_max_m; 275 int m, n, r, scaled_max_m;
306 unsigned long scaled_rt_rp, new_rate; 276 unsigned long scaled_rt_rp;
307 int min_e = -1, min_e_m = -1, min_e_n = -1; 277 unsigned long new_rate = 0;
308 struct dpll_data *dd; 278 struct dpll_data *dd;
309 279
310 if (!clk || !clk->dpll_data) 280 if (!clk || !clk->dpll_data)
@@ -312,8 +282,8 @@ long omap2_dpll_round_rate(struct clk *clk, unsigned long target_rate)
312 282
313 dd = clk->dpll_data; 283 dd = clk->dpll_data;
314 284
315 pr_debug("clock: starting DPLL round_rate for clock %s, target rate " 285 pr_debug("clock: %s: starting DPLL round_rate, target rate %ld\n",
316 "%ld\n", clk->name, target_rate); 286 clk->name, target_rate);
317 287
318 scaled_rt_rp = target_rate / (dd->clk_ref->rate / DPLL_SCALE_FACTOR); 288 scaled_rt_rp = target_rate / (dd->clk_ref->rate / DPLL_SCALE_FACTOR);
319 scaled_max_m = dd->max_multiplier * DPLL_SCALE_FACTOR; 289 scaled_max_m = dd->max_multiplier * DPLL_SCALE_FACTOR;
@@ -348,39 +318,23 @@ long omap2_dpll_round_rate(struct clk *clk, unsigned long target_rate)
348 if (r == DPLL_MULT_UNDERFLOW) 318 if (r == DPLL_MULT_UNDERFLOW)
349 continue; 319 continue;
350 320
351 e = target_rate - new_rate; 321 pr_debug("clock: %s: m = %d: n = %d: new_rate = %ld\n",
352 pr_debug("clock: n = %d: m = %d: rate error is %d " 322 clk->name, m, n, new_rate);
353 "(new_rate = %ld)\n", n, m, e, new_rate);
354
355 if (min_e == -1 ||
356 min_e >= (int)(abs(e) - dd->rate_tolerance)) {
357 min_e = e;
358 min_e_m = m;
359 min_e_n = n;
360
361 pr_debug("clock: found new least error %d\n", min_e);
362 323
363 /* We found good settings -- bail out now */ 324 if (target_rate == new_rate) {
364 if (min_e <= dd->rate_tolerance) 325 dd->last_rounded_m = m;
365 break; 326 dd->last_rounded_n = n;
327 dd->last_rounded_rate = target_rate;
328 break;
366 } 329 }
367 } 330 }
368 331
369 if (min_e < 0) { 332 if (target_rate != new_rate) {
370 pr_debug("clock: error: target rate or tolerance too low\n"); 333 pr_debug("clock: %s: cannot round to rate %ld\n", clk->name,
334 target_rate);
371 return ~0; 335 return ~0;
372 } 336 }
373 337
374 dd->last_rounded_m = min_e_m; 338 return target_rate;
375 dd->last_rounded_n = min_e_n;
376 dd->last_rounded_rate = _dpll_compute_new_rate(dd->clk_ref->rate,
377 min_e_m, min_e_n);
378
379 pr_debug("clock: final least error: e = %d, m = %d, n = %d\n",
380 min_e, min_e_m, min_e_n);
381 pr_debug("clock: final rate: %ld (target rate: %ld)\n",
382 dd->last_rounded_rate, target_rate);
383
384 return dd->last_rounded_rate;
385} 339}
386 340