aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-01-20 22:00:46 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-20 22:00:46 -0500
commit3549d82279370295a11f1dec0284a9922c903b9a (patch)
tree45bc3960c75546ce6e5a7f3950cae5a94891f040
parent9638685e32af961943b679fcb72d4ddd458eb18f (diff)
parent6575a9c69a211ac1cf454f9c76be54f7a5fae9fe (diff)
Merge tag 'renesas-sh-drivers-for-v4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas
Pull SH driver updates from Simon Horman: "Clean up the clock API on legacy SH to make it more similar to the Common Clock Framework. This will avoid different behaviour in drivers shared between legacy and CCF-based platforms (e.g. SCIF)" * tag 'renesas-sh-drivers-for-v4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas: drivers: sh: clk: Avoid crashes when passing NULL clocks drivers: sh: clk: Remove obsolete and unused clk_round_parent()
-rw-r--r--drivers/sh/clk/core.c100
-rw-r--r--include/linux/sh_clk.h4
2 files changed, 12 insertions, 92 deletions
diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c
index be56b22ca941..92863e3818e5 100644
--- a/drivers/sh/clk/core.c
+++ b/drivers/sh/clk/core.c
@@ -469,6 +469,9 @@ void clk_enable_init_clocks(void)
469 469
470unsigned long clk_get_rate(struct clk *clk) 470unsigned long clk_get_rate(struct clk *clk)
471{ 471{
472 if (!clk)
473 return 0;
474
472 return clk->rate; 475 return clk->rate;
473} 476}
474EXPORT_SYMBOL_GPL(clk_get_rate); 477EXPORT_SYMBOL_GPL(clk_get_rate);
@@ -478,6 +481,9 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
478 int ret = -EOPNOTSUPP; 481 int ret = -EOPNOTSUPP;
479 unsigned long flags; 482 unsigned long flags;
480 483
484 if (!clk)
485 return 0;
486
481 spin_lock_irqsave(&clock_lock, flags); 487 spin_lock_irqsave(&clock_lock, flags);
482 488
483 if (likely(clk->ops && clk->ops->set_rate)) { 489 if (likely(clk->ops && clk->ops->set_rate)) {
@@ -535,12 +541,18 @@ EXPORT_SYMBOL_GPL(clk_set_parent);
535 541
536struct clk *clk_get_parent(struct clk *clk) 542struct clk *clk_get_parent(struct clk *clk)
537{ 543{
544 if (!clk)
545 return NULL;
546
538 return clk->parent; 547 return clk->parent;
539} 548}
540EXPORT_SYMBOL_GPL(clk_get_parent); 549EXPORT_SYMBOL_GPL(clk_get_parent);
541 550
542long clk_round_rate(struct clk *clk, unsigned long rate) 551long clk_round_rate(struct clk *clk, unsigned long rate)
543{ 552{
553 if (!clk)
554 return 0;
555
544 if (likely(clk->ops && clk->ops->round_rate)) { 556 if (likely(clk->ops && clk->ops->round_rate)) {
545 unsigned long flags, rounded; 557 unsigned long flags, rounded;
546 558
@@ -555,94 +567,6 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
555} 567}
556EXPORT_SYMBOL_GPL(clk_round_rate); 568EXPORT_SYMBOL_GPL(clk_round_rate);
557 569
558long clk_round_parent(struct clk *clk, unsigned long target,
559 unsigned long *best_freq, unsigned long *parent_freq,
560 unsigned int div_min, unsigned int div_max)
561{
562 struct cpufreq_frequency_table *freq, *best = NULL;
563 unsigned long error = ULONG_MAX, freq_high, freq_low, div;
564 struct clk *parent = clk_get_parent(clk);
565
566 if (!parent) {
567 *parent_freq = 0;
568 *best_freq = clk_round_rate(clk, target);
569 return abs(target - *best_freq);
570 }
571
572 cpufreq_for_each_valid_entry(freq, parent->freq_table) {
573 if (unlikely(freq->frequency / target <= div_min - 1)) {
574 unsigned long freq_max;
575
576 freq_max = (freq->frequency + div_min / 2) / div_min;
577 if (error > target - freq_max) {
578 error = target - freq_max;
579 best = freq;
580 if (best_freq)
581 *best_freq = freq_max;
582 }
583
584 pr_debug("too low freq %u, error %lu\n", freq->frequency,
585 target - freq_max);
586
587 if (!error)
588 break;
589
590 continue;
591 }
592
593 if (unlikely(freq->frequency / target >= div_max)) {
594 unsigned long freq_min;
595
596 freq_min = (freq->frequency + div_max / 2) / div_max;
597 if (error > freq_min - target) {
598 error = freq_min - target;
599 best = freq;
600 if (best_freq)
601 *best_freq = freq_min;
602 }
603
604 pr_debug("too high freq %u, error %lu\n", freq->frequency,
605 freq_min - target);
606
607 if (!error)
608 break;
609
610 continue;
611 }
612
613 div = freq->frequency / target;
614 freq_high = freq->frequency / div;
615 freq_low = freq->frequency / (div + 1);
616
617 if (freq_high - target < error) {
618 error = freq_high - target;
619 best = freq;
620 if (best_freq)
621 *best_freq = freq_high;
622 }
623
624 if (target - freq_low < error) {
625 error = target - freq_low;
626 best = freq;
627 if (best_freq)
628 *best_freq = freq_low;
629 }
630
631 pr_debug("%u / %lu = %lu, / %lu = %lu, best %lu, parent %u\n",
632 freq->frequency, div, freq_high, div + 1, freq_low,
633 *best_freq, best->frequency);
634
635 if (!error)
636 break;
637 }
638
639 if (parent_freq)
640 *parent_freq = best->frequency;
641
642 return error;
643}
644EXPORT_SYMBOL_GPL(clk_round_parent);
645
646#ifdef CONFIG_PM 570#ifdef CONFIG_PM
647static void clks_core_resume(void) 571static void clks_core_resume(void)
648{ 572{
diff --git a/include/linux/sh_clk.h b/include/linux/sh_clk.h
index 1f208b2a1ed6..645896b81244 100644
--- a/include/linux/sh_clk.h
+++ b/include/linux/sh_clk.h
@@ -113,10 +113,6 @@ long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
113long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min, 113long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min,
114 unsigned int mult_max, unsigned long rate); 114 unsigned int mult_max, unsigned long rate);
115 115
116long clk_round_parent(struct clk *clk, unsigned long target,
117 unsigned long *best_freq, unsigned long *parent_freq,
118 unsigned int div_min, unsigned int div_max);
119
120#define SH_CLK_MSTP(_parent, _enable_reg, _enable_bit, _status_reg, _flags) \ 116#define SH_CLK_MSTP(_parent, _enable_reg, _enable_bit, _status_reg, _flags) \
121{ \ 117{ \
122 .parent = _parent, \ 118 .parent = _parent, \