aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/sh/clk/core.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c
index b3840597ad6e..09615b51d591 100644
--- a/drivers/sh/clk/core.c
+++ b/drivers/sh/clk/core.c
@@ -561,57 +561,74 @@ long clk_round_parent(struct clk *clk, unsigned long target,
561 continue; 561 continue;
562 562
563 if (unlikely(freq->frequency / target <= div_min - 1)) { 563 if (unlikely(freq->frequency / target <= div_min - 1)) {
564 unsigned long freq_max = (freq->frequency + div_min / 2) / div_min; 564 unsigned long freq_max;
565
566 freq_max = (freq->frequency + div_min / 2) / div_min;
565 if (error > target - freq_max) { 567 if (error > target - freq_max) {
566 error = target - freq_max; 568 error = target - freq_max;
567 best = freq; 569 best = freq;
568 if (best_freq) 570 if (best_freq)
569 *best_freq = freq_max; 571 *best_freq = freq_max;
570 } 572 }
571 pr_debug("too low freq %lu, error %lu\n", freq->frequency, target - freq_max); 573
574 pr_debug("too low freq %lu, error %lu\n", freq->frequency,
575 target - freq_max);
576
572 if (!error) 577 if (!error)
573 break; 578 break;
579
574 continue; 580 continue;
575 } 581 }
576 582
577 if (unlikely(freq->frequency / target >= div_max)) { 583 if (unlikely(freq->frequency / target >= div_max)) {
578 unsigned long freq_min = (freq->frequency + div_max / 2) / div_max; 584 unsigned long freq_min;
585
586 freq_min = (freq->frequency + div_max / 2) / div_max;
579 if (error > freq_min - target) { 587 if (error > freq_min - target) {
580 error = freq_min - target; 588 error = freq_min - target;
581 best = freq; 589 best = freq;
582 if (best_freq) 590 if (best_freq)
583 *best_freq = freq_min; 591 *best_freq = freq_min;
584 } 592 }
585 pr_debug("too high freq %lu, error %lu\n", freq->frequency, freq_min - target); 593
594 pr_debug("too high freq %lu, error %lu\n", freq->frequency,
595 freq_min - target);
596
586 if (!error) 597 if (!error)
587 break; 598 break;
599
588 continue; 600 continue;
589 } 601 }
590 602
591
592 div = freq->frequency / target; 603 div = freq->frequency / target;
593 freq_high = freq->frequency / div; 604 freq_high = freq->frequency / div;
594 freq_low = freq->frequency / (div + 1); 605 freq_low = freq->frequency / (div + 1);
606
595 if (freq_high - target < error) { 607 if (freq_high - target < error) {
596 error = freq_high - target; 608 error = freq_high - target;
597 best = freq; 609 best = freq;
598 if (best_freq) 610 if (best_freq)
599 *best_freq = freq_high; 611 *best_freq = freq_high;
600 } 612 }
613
601 if (target - freq_low < error) { 614 if (target - freq_low < error) {
602 error = target - freq_low; 615 error = target - freq_low;
603 best = freq; 616 best = freq;
604 if (best_freq) 617 if (best_freq)
605 *best_freq = freq_low; 618 *best_freq = freq_low;
606 } 619 }
620
607 pr_debug("%u / %lu = %lu, / %lu = %lu, best %lu, parent %u\n", 621 pr_debug("%u / %lu = %lu, / %lu = %lu, best %lu, parent %u\n",
608 freq->frequency, div, freq_high, div + 1, freq_low, 622 freq->frequency, div, freq_high, div + 1, freq_low,
609 *best_freq, best->frequency); 623 *best_freq, best->frequency);
624
610 if (!error) 625 if (!error)
611 break; 626 break;
612 } 627 }
628
613 if (parent_freq) 629 if (parent_freq)
614 *parent_freq = best->frequency; 630 *parent_freq = best->frequency;
631
615 return error; 632 return error;
616} 633}
617EXPORT_SYMBOL_GPL(clk_round_parent); 634EXPORT_SYMBOL_GPL(clk_round_parent);