Commit d754b159 authored by Maxime Ripard's avatar Maxime Ripard

clk: sunxi-ng: mux: Change pre-divider application function prototype

The current function name is a bit confusing, and doesn't really allow to
create an explicit function to reverse the operation.

We also for now change the parent rate through a pointer, while we don't
return anything.

In order to be less confusing, and easier to use for downstream users,
change the function name to something hopefully clearer, and return the
adjusted rate instead of changing the pointer.
Signed-off-by: default avatarMaxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: default avatarChen-Yu Tsai <wens@csie.org>
parent ea8edcde
...@@ -59,8 +59,8 @@ static unsigned long ccu_div_recalc_rate(struct clk_hw *hw, ...@@ -59,8 +59,8 @@ static unsigned long ccu_div_recalc_rate(struct clk_hw *hw,
val = reg >> cd->div.shift; val = reg >> cd->div.shift;
val &= (1 << cd->div.width) - 1; val &= (1 << cd->div.width) - 1;
ccu_mux_helper_adjust_parent_for_prediv(&cd->common, &cd->mux, -1, parent_rate = ccu_mux_helper_apply_prediv(&cd->common, &cd->mux, -1,
&parent_rate); parent_rate);
return divider_recalc_rate(hw, parent_rate, val, cd->div.table, return divider_recalc_rate(hw, parent_rate, val, cd->div.table,
cd->div.flags); cd->div.flags);
...@@ -83,8 +83,8 @@ static int ccu_div_set_rate(struct clk_hw *hw, unsigned long rate, ...@@ -83,8 +83,8 @@ static int ccu_div_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long val; unsigned long val;
u32 reg; u32 reg;
ccu_mux_helper_adjust_parent_for_prediv(&cd->common, &cd->mux, -1, parent_rate = ccu_mux_helper_apply_prediv(&cd->common, &cd->mux, -1,
&parent_rate); parent_rate);
val = divider_get_val(rate, parent_rate, cd->div.table, cd->div.width, val = divider_get_val(rate, parent_rate, cd->div.table, cd->div.width,
cd->div.flags); cd->div.flags);
......
...@@ -87,8 +87,8 @@ static unsigned long ccu_mp_recalc_rate(struct clk_hw *hw, ...@@ -87,8 +87,8 @@ static unsigned long ccu_mp_recalc_rate(struct clk_hw *hw,
u32 reg; u32 reg;
/* Adjust parent_rate according to pre-dividers */ /* Adjust parent_rate according to pre-dividers */
ccu_mux_helper_adjust_parent_for_prediv(&cmp->common, &cmp->mux, parent_rate = ccu_mux_helper_apply_prediv(&cmp->common, &cmp->mux, -1,
-1, &parent_rate); parent_rate);
reg = readl(cmp->common.base + cmp->common.reg); reg = readl(cmp->common.base + cmp->common.reg);
...@@ -123,8 +123,8 @@ static int ccu_mp_set_rate(struct clk_hw *hw, unsigned long rate, ...@@ -123,8 +123,8 @@ static int ccu_mp_set_rate(struct clk_hw *hw, unsigned long rate,
u32 reg; u32 reg;
/* Adjust parent_rate according to pre-dividers */ /* Adjust parent_rate according to pre-dividers */
ccu_mux_helper_adjust_parent_for_prediv(&cmp->common, &cmp->mux, parent_rate = ccu_mux_helper_apply_prediv(&cmp->common, &cmp->mux, -1,
-1, &parent_rate); parent_rate);
max_m = cmp->m.max ?: 1 << cmp->m.width; max_m = cmp->m.max ?: 1 << cmp->m.width;
max_p = cmp->p.max ?: 1 << ((1 << cmp->p.width) - 1); max_p = cmp->p.max ?: 1 << ((1 << cmp->p.width) - 1);
......
...@@ -88,8 +88,8 @@ static unsigned long ccu_mult_recalc_rate(struct clk_hw *hw, ...@@ -88,8 +88,8 @@ static unsigned long ccu_mult_recalc_rate(struct clk_hw *hw,
val = reg >> cm->mult.shift; val = reg >> cm->mult.shift;
val &= (1 << cm->mult.width) - 1; val &= (1 << cm->mult.width) - 1;
ccu_mux_helper_adjust_parent_for_prediv(&cm->common, &cm->mux, -1, parent_rate = ccu_mux_helper_apply_prediv(&cm->common, &cm->mux, -1,
&parent_rate); parent_rate);
return parent_rate * (val + cm->mult.offset); return parent_rate * (val + cm->mult.offset);
} }
...@@ -116,8 +116,8 @@ static int ccu_mult_set_rate(struct clk_hw *hw, unsigned long rate, ...@@ -116,8 +116,8 @@ static int ccu_mult_set_rate(struct clk_hw *hw, unsigned long rate,
else else
ccu_frac_helper_disable(&cm->common, &cm->frac); ccu_frac_helper_disable(&cm->common, &cm->frac);
ccu_mux_helper_adjust_parent_for_prediv(&cm->common, &cm->mux, -1, parent_rate = ccu_mux_helper_apply_prediv(&cm->common, &cm->mux, -1,
&parent_rate); parent_rate);
_cm.min = cm->mult.min; _cm.min = cm->mult.min;
......
...@@ -56,13 +56,12 @@ static u16 ccu_mux_get_prediv(struct ccu_common *common, ...@@ -56,13 +56,12 @@ static u16 ccu_mux_get_prediv(struct ccu_common *common,
return prediv; return prediv;
} }
void ccu_mux_helper_adjust_parent_for_prediv(struct ccu_common *common, unsigned long ccu_mux_helper_apply_prediv(struct ccu_common *common,
struct ccu_mux_internal *cm, struct ccu_mux_internal *cm,
int parent_index, int parent_index,
unsigned long *parent_rate) unsigned long parent_rate)
{ {
*parent_rate = *parent_rate / ccu_mux_get_prediv(common, cm, return parent_rate / ccu_mux_get_prediv(common, cm, parent_index);
parent_index);
} }
int ccu_mux_helper_determine_rate(struct ccu_common *common, int ccu_mux_helper_determine_rate(struct ccu_common *common,
...@@ -84,10 +83,8 @@ int ccu_mux_helper_determine_rate(struct ccu_common *common, ...@@ -84,10 +83,8 @@ int ccu_mux_helper_determine_rate(struct ccu_common *common,
best_parent = clk_hw_get_parent(hw); best_parent = clk_hw_get_parent(hw);
best_parent_rate = clk_hw_get_rate(best_parent); best_parent_rate = clk_hw_get_rate(best_parent);
adj_parent_rate = ccu_mux_helper_apply_prediv(common, cm, -1,
adj_parent_rate = best_parent_rate; best_parent_rate);
ccu_mux_helper_adjust_parent_for_prediv(common, cm, -1,
&adj_parent_rate);
best_rate = round(cm, best_parent, &adj_parent_rate, best_rate = round(cm, best_parent, &adj_parent_rate,
req->rate, data); req->rate, data);
...@@ -103,9 +100,9 @@ int ccu_mux_helper_determine_rate(struct ccu_common *common, ...@@ -103,9 +100,9 @@ int ccu_mux_helper_determine_rate(struct ccu_common *common,
if (!parent) if (!parent)
continue; continue;
adj_parent_rate = parent_rate = clk_hw_get_rate(parent); parent_rate = clk_hw_get_rate(parent);
ccu_mux_helper_adjust_parent_for_prediv(common, cm, i, adj_parent_rate = ccu_mux_helper_apply_prediv(common, cm, i,
&adj_parent_rate); parent_rate);
tmp_rate = round(cm, parent, &adj_parent_rate, req->rate, data); tmp_rate = round(cm, parent, &adj_parent_rate, req->rate, data);
if (tmp_rate == req->rate) { if (tmp_rate == req->rate) {
...@@ -215,10 +212,8 @@ static unsigned long ccu_mux_recalc_rate(struct clk_hw *hw, ...@@ -215,10 +212,8 @@ static unsigned long ccu_mux_recalc_rate(struct clk_hw *hw,
{ {
struct ccu_mux *cm = hw_to_ccu_mux(hw); struct ccu_mux *cm = hw_to_ccu_mux(hw);
ccu_mux_helper_adjust_parent_for_prediv(&cm->common, &cm->mux, -1, return ccu_mux_helper_apply_prediv(&cm->common, &cm->mux, -1,
&parent_rate); parent_rate);
return parent_rate;
} }
const struct clk_ops ccu_mux_ops = { const struct clk_ops ccu_mux_ops = {
......
...@@ -78,10 +78,10 @@ static inline struct ccu_mux *hw_to_ccu_mux(struct clk_hw *hw) ...@@ -78,10 +78,10 @@ static inline struct ccu_mux *hw_to_ccu_mux(struct clk_hw *hw)
extern const struct clk_ops ccu_mux_ops; extern const struct clk_ops ccu_mux_ops;
void ccu_mux_helper_adjust_parent_for_prediv(struct ccu_common *common, unsigned long ccu_mux_helper_apply_prediv(struct ccu_common *common,
struct ccu_mux_internal *cm, struct ccu_mux_internal *cm,
int parent_index, int parent_index,
unsigned long *parent_rate); unsigned long parent_rate);
int ccu_mux_helper_determine_rate(struct ccu_common *common, int ccu_mux_helper_determine_rate(struct ccu_common *common,
struct ccu_mux_internal *cm, struct ccu_mux_internal *cm,
struct clk_rate_request *req, struct clk_rate_request *req,
......
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