Commit 50c6a503 authored by Stephen Boyd's avatar Stephen Boyd

clk: qcom: Consolidate frequency finding logic

There are two find_freq() functions in clk-rcg.c and clk-rcg2.c
that are almost exactly the same. Consolidate them into one
function to save on some code space.

Cc: Mike Turquette <mturquette@linaro.org>
Signed-off-by: default avatarStephen Boyd <sboyd@codeaurora.org>
parent dc1b3f65
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <asm/div64.h> #include <asm/div64.h>
#include "clk-rcg.h" #include "clk-rcg.h"
#include "common.h"
static u32 ns_to_src(struct src_sel *s, u32 ns) static u32 ns_to_src(struct src_sel *s, u32 ns)
{ {
...@@ -360,26 +361,13 @@ clk_dyn_rcg_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) ...@@ -360,26 +361,13 @@ clk_dyn_rcg_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
} }
} }
static const
struct freq_tbl *find_freq(const struct freq_tbl *f, unsigned long rate)
{
if (!f)
return NULL;
for (; f->freq; f++)
if (rate <= f->freq)
return f;
return NULL;
}
static long _freq_tbl_determine_rate(struct clk_hw *hw, static long _freq_tbl_determine_rate(struct clk_hw *hw,
const struct freq_tbl *f, unsigned long rate, const struct freq_tbl *f, unsigned long rate,
unsigned long *p_rate, struct clk **p) unsigned long *p_rate, struct clk **p)
{ {
unsigned long clk_flags; unsigned long clk_flags;
f = find_freq(f, rate); f = qcom_find_freq(f, rate);
if (!f) if (!f)
return -EINVAL; return -EINVAL;
...@@ -477,7 +465,7 @@ static int clk_rcg_set_rate(struct clk_hw *hw, unsigned long rate, ...@@ -477,7 +465,7 @@ static int clk_rcg_set_rate(struct clk_hw *hw, unsigned long rate,
struct clk_rcg *rcg = to_clk_rcg(hw); struct clk_rcg *rcg = to_clk_rcg(hw);
const struct freq_tbl *f; const struct freq_tbl *f;
f = find_freq(rcg->freq_tbl, rate); f = qcom_find_freq(rcg->freq_tbl, rate);
if (!f) if (!f)
return -EINVAL; return -EINVAL;
...@@ -497,7 +485,7 @@ static int __clk_dyn_rcg_set_rate(struct clk_hw *hw, unsigned long rate) ...@@ -497,7 +485,7 @@ static int __clk_dyn_rcg_set_rate(struct clk_hw *hw, unsigned long rate)
struct clk_dyn_rcg *rcg = to_clk_dyn_rcg(hw); struct clk_dyn_rcg *rcg = to_clk_dyn_rcg(hw);
const struct freq_tbl *f; const struct freq_tbl *f;
f = find_freq(rcg->freq_tbl, rate); f = qcom_find_freq(rcg->freq_tbl, rate);
if (!f) if (!f)
return -EINVAL; return -EINVAL;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <asm/div64.h> #include <asm/div64.h>
#include "clk-rcg.h" #include "clk-rcg.h"
#include "common.h"
#define CMD_REG 0x0 #define CMD_REG 0x0
#define CMD_UPDATE BIT(0) #define CMD_UPDATE BIT(0)
...@@ -172,27 +173,13 @@ clk_rcg2_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) ...@@ -172,27 +173,13 @@ clk_rcg2_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
return calc_rate(parent_rate, m, n, mode, hid_div); return calc_rate(parent_rate, m, n, mode, hid_div);
} }
static const
struct freq_tbl *find_freq(const struct freq_tbl *f, unsigned long rate)
{
if (!f)
return NULL;
for (; f->freq; f++)
if (rate <= f->freq)
return f;
/* Default to our fastest rate */
return f - 1;
}
static long _freq_tbl_determine_rate(struct clk_hw *hw, static long _freq_tbl_determine_rate(struct clk_hw *hw,
const struct freq_tbl *f, unsigned long rate, const struct freq_tbl *f, unsigned long rate,
unsigned long *p_rate, struct clk **p) unsigned long *p_rate, struct clk **p)
{ {
unsigned long clk_flags; unsigned long clk_flags;
f = find_freq(f, rate); f = qcom_find_freq(f, rate);
if (!f) if (!f)
return -EINVAL; return -EINVAL;
...@@ -268,7 +255,7 @@ static int __clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate) ...@@ -268,7 +255,7 @@ static int __clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate)
struct clk_rcg2 *rcg = to_clk_rcg2(hw); struct clk_rcg2 *rcg = to_clk_rcg2(hw);
const struct freq_tbl *f; const struct freq_tbl *f;
f = find_freq(rcg->freq_tbl, rate); f = qcom_find_freq(rcg->freq_tbl, rate);
if (!f) if (!f)
return -EINVAL; return -EINVAL;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/reset-controller.h> #include <linux/reset-controller.h>
#include "common.h" #include "common.h"
#include "clk-rcg.h"
#include "clk-regmap.h" #include "clk-regmap.h"
#include "reset.h" #include "reset.h"
...@@ -27,6 +28,21 @@ struct qcom_cc { ...@@ -27,6 +28,21 @@ struct qcom_cc {
struct clk *clks[]; struct clk *clks[];
}; };
const
struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, unsigned long rate)
{
if (!f)
return NULL;
for (; f->freq; f++)
if (rate <= f->freq)
return f;
/* Default to our fastest rate */
return f - 1;
}
EXPORT_SYMBOL_GPL(qcom_find_freq);
struct regmap * struct regmap *
qcom_cc_map(struct platform_device *pdev, const struct qcom_cc_desc *desc) qcom_cc_map(struct platform_device *pdev, const struct qcom_cc_desc *desc)
{ {
......
...@@ -18,6 +18,7 @@ struct regmap_config; ...@@ -18,6 +18,7 @@ struct regmap_config;
struct clk_regmap; struct clk_regmap;
struct qcom_reset_map; struct qcom_reset_map;
struct regmap; struct regmap;
struct freq_tbl;
struct qcom_cc_desc { struct qcom_cc_desc {
const struct regmap_config *config; const struct regmap_config *config;
...@@ -27,6 +28,9 @@ struct qcom_cc_desc { ...@@ -27,6 +28,9 @@ struct qcom_cc_desc {
size_t num_resets; size_t num_resets;
}; };
extern const struct freq_tbl *qcom_find_freq(const struct freq_tbl *f,
unsigned long rate);
extern struct regmap *qcom_cc_map(struct platform_device *pdev, extern struct regmap *qcom_cc_map(struct platform_device *pdev,
const struct qcom_cc_desc *desc); const struct qcom_cc_desc *desc);
extern int qcom_cc_really_probe(struct platform_device *pdev, extern int qcom_cc_really_probe(struct platform_device *pdev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment