]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
sh: clkfwk: Add a helper for rate rounding by divisor ranges.
authorPaul Mundt <lethal@linux-sh.org>
Fri, 15 Oct 2010 09:33:24 +0000 (18:33 +0900)
committerPaul Mundt <lethal@linux-sh.org>
Fri, 15 Oct 2010 09:33:24 +0000 (18:33 +0900)
This adds a new clk_rate_div_range_round() for implementing rate rounding
by divisor ranges. This can be used trivially by clocks that support
arbitrary ranged divisors without the need for rate table construction.

This should only be used by clocks that both have large divisor ranges in
addition to clocks that will never be arbitrarily scaled, as the lack of
a backing frequency table will prevent cpufreq from being able to do much
of anything with them.

Primarily intended for use as a ->recalc helper.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
drivers/sh/clk.c
include/linux/sh_clk.h

index 3ac6fa0005b9bfbb0fe1ce65576302038e47cf00..018be37ef3392d157f0bafef7d91cd8008721415 100644 (file)
@@ -76,7 +76,7 @@ struct clk_rate_round_data;
 struct clk_rate_round_data {
        unsigned long rate;
        unsigned int min, max;
-       long (*func)(unsigned int pos, struct clk_rate_round_data *arg);
+       long (*func)(unsigned int, struct clk_rate_round_data *);
        void *arg;
 };
 
@@ -148,6 +148,26 @@ long clk_rate_table_round(struct clk *clk,
        return clk_rate_round_helper(&table_round);
 }
 
+static long clk_rate_div_range_iter(unsigned int pos,
+                                   struct clk_rate_round_data *rounder)
+{
+       return clk_get_rate(rounder->arg) / pos;
+}
+
+long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
+                             unsigned int div_max, unsigned long rate)
+{
+       struct clk_rate_round_data div_range_round = {
+               .min    = div_min,
+               .max    = div_max,
+               .func   = clk_rate_div_range_iter,
+               .arg    = clk_get_parent(clk),
+               .rate   = rate,
+       };
+
+       return clk_rate_round_helper(&div_range_round);
+}
+
 int clk_rate_table_find(struct clk *clk,
                        struct cpufreq_frequency_table *freq_table,
                        unsigned long rate)
index 49f6e9b6eda20a22258cd8e95da9012f61f06b3e..4dca992f3093771993ac9d98d1233df5e2f33cfa 100644 (file)
@@ -119,6 +119,9 @@ int clk_rate_table_find(struct clk *clk,
                        struct cpufreq_frequency_table *freq_table,
                        unsigned long rate);
 
+long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
+                             unsigned int div_max, unsigned long rate);
+
 #define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags)       \
 {                                                                      \
        .parent         = _parent,                                      \