diff options
author | Javi Merino <javi.merino@arm.com> | 2015-04-16 15:43:48 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-17 09:03:55 -0400 |
commit | aa7762010a4340a12a87a54b7a402adcdce8cfa9 (patch) | |
tree | a2126011ab39b8af6cd755be7285d6668f675536 /drivers/clk/bcm/clk-kona.c | |
parent | f766093ecb647f5a87bfa456715abbbccee547ce (diff) |
clk: bcm/kona: use DIV_ROUND_CLOSEST_ULL()
Now that the kernel provides DIV_ROUND_CLOSEST_ULL(), drop the internal
implementation and use the kernel one.
Signed-off-by: Javi Merino <javi.merino@arm.com>
Cc: Mike Turquette <mturquette@linaro.org>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Acked-by: Alex Elder <elder@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/clk/bcm/clk-kona.c')
-rw-r--r-- | drivers/clk/bcm/clk-kona.c | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/drivers/clk/bcm/clk-kona.c b/drivers/clk/bcm/clk-kona.c index 05abae89262e..a0ef4f75d457 100644 --- a/drivers/clk/bcm/clk-kona.c +++ b/drivers/clk/bcm/clk-kona.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include "clk-kona.h" | 15 | #include "clk-kona.h" |
16 | 16 | ||
17 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
18 | #include <linux/kernel.h> | ||
18 | 19 | ||
19 | /* | 20 | /* |
20 | * "Policies" affect the frequencies of bus clocks provided by a | 21 | * "Policies" affect the frequencies of bus clocks provided by a |
@@ -51,21 +52,6 @@ static inline u32 bitfield_replace(u32 reg_val, u32 shift, u32 width, u32 val) | |||
51 | 52 | ||
52 | /* Divider and scaling helpers */ | 53 | /* Divider and scaling helpers */ |
53 | 54 | ||
54 | /* | ||
55 | * Implement DIV_ROUND_CLOSEST() for 64-bit dividend and both values | ||
56 | * unsigned. Note that unlike do_div(), the remainder is discarded | ||
57 | * and the return value is the quotient (not the remainder). | ||
58 | */ | ||
59 | u64 do_div_round_closest(u64 dividend, unsigned long divisor) | ||
60 | { | ||
61 | u64 result; | ||
62 | |||
63 | result = dividend + ((u64)divisor >> 1); | ||
64 | (void)do_div(result, divisor); | ||
65 | |||
66 | return result; | ||
67 | } | ||
68 | |||
69 | /* Convert a divider into the scaled divisor value it represents. */ | 55 | /* Convert a divider into the scaled divisor value it represents. */ |
70 | static inline u64 scaled_div_value(struct bcm_clk_div *div, u32 reg_div) | 56 | static inline u64 scaled_div_value(struct bcm_clk_div *div, u32 reg_div) |
71 | { | 57 | { |
@@ -87,7 +73,7 @@ u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value, u32 billionths) | |||
87 | combined = (u64)div_value * BILLION + billionths; | 73 | combined = (u64)div_value * BILLION + billionths; |
88 | combined <<= div->u.s.frac_width; | 74 | combined <<= div->u.s.frac_width; |
89 | 75 | ||
90 | return do_div_round_closest(combined, BILLION); | 76 | return DIV_ROUND_CLOSEST_ULL(combined, BILLION); |
91 | } | 77 | } |
92 | 78 | ||
93 | /* The scaled minimum divisor representable by a divider */ | 79 | /* The scaled minimum divisor representable by a divider */ |
@@ -731,7 +717,7 @@ static unsigned long clk_recalc_rate(struct ccu_data *ccu, | |||
731 | scaled_rate = scale_rate(pre_div, parent_rate); | 717 | scaled_rate = scale_rate(pre_div, parent_rate); |
732 | scaled_rate = scale_rate(div, scaled_rate); | 718 | scaled_rate = scale_rate(div, scaled_rate); |
733 | scaled_div = divider_read_scaled(ccu, pre_div); | 719 | scaled_div = divider_read_scaled(ccu, pre_div); |
734 | scaled_parent_rate = do_div_round_closest(scaled_rate, | 720 | scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate, |
735 | scaled_div); | 721 | scaled_div); |
736 | } else { | 722 | } else { |
737 | scaled_parent_rate = scale_rate(div, parent_rate); | 723 | scaled_parent_rate = scale_rate(div, parent_rate); |
@@ -743,7 +729,7 @@ static unsigned long clk_recalc_rate(struct ccu_data *ccu, | |||
743 | * rate. | 729 | * rate. |
744 | */ | 730 | */ |
745 | scaled_div = divider_read_scaled(ccu, div); | 731 | scaled_div = divider_read_scaled(ccu, div); |
746 | result = do_div_round_closest(scaled_parent_rate, scaled_div); | 732 | result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, scaled_div); |
747 | 733 | ||
748 | return (unsigned long)result; | 734 | return (unsigned long)result; |
749 | } | 735 | } |
@@ -790,7 +776,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div, | |||
790 | scaled_rate = scale_rate(pre_div, parent_rate); | 776 | scaled_rate = scale_rate(pre_div, parent_rate); |
791 | scaled_rate = scale_rate(div, scaled_rate); | 777 | scaled_rate = scale_rate(div, scaled_rate); |
792 | scaled_pre_div = divider_read_scaled(ccu, pre_div); | 778 | scaled_pre_div = divider_read_scaled(ccu, pre_div); |
793 | scaled_parent_rate = do_div_round_closest(scaled_rate, | 779 | scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate, |
794 | scaled_pre_div); | 780 | scaled_pre_div); |
795 | } else { | 781 | } else { |
796 | scaled_parent_rate = scale_rate(div, parent_rate); | 782 | scaled_parent_rate = scale_rate(div, parent_rate); |
@@ -802,7 +788,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div, | |||
802 | * the best we can do. | 788 | * the best we can do. |
803 | */ | 789 | */ |
804 | if (!divider_is_fixed(div)) { | 790 | if (!divider_is_fixed(div)) { |
805 | best_scaled_div = do_div_round_closest(scaled_parent_rate, | 791 | best_scaled_div = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, |
806 | rate); | 792 | rate); |
807 | min_scaled_div = scaled_div_min(div); | 793 | min_scaled_div = scaled_div_min(div); |
808 | max_scaled_div = scaled_div_max(div); | 794 | max_scaled_div = scaled_div_max(div); |
@@ -815,7 +801,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div, | |||
815 | } | 801 | } |
816 | 802 | ||
817 | /* OK, figure out the resulting rate */ | 803 | /* OK, figure out the resulting rate */ |
818 | result = do_div_round_closest(scaled_parent_rate, best_scaled_div); | 804 | result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, best_scaled_div); |
819 | 805 | ||
820 | if (scaled_div) | 806 | if (scaled_div) |
821 | *scaled_div = best_scaled_div; | 807 | *scaled_div = best_scaled_div; |