Commit ea8edcde authored by Maxime Ripard's avatar Maxime Ripard

clk: sunxi-ng: mux: split out the pre-divider computation code

The pre-divider retrieval code was merged into the function to apply the
current pre-divider onto the parent clock rate so that we can use that
adjusted value to do our factors computation.

However, since we'll need to do the reverse operation, we need to split out
that code into a function that will be shared.
Signed-off-by: default avatarMaxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: default avatarChen-Yu Tsai <wens@csie.org>
parent 73e3e04f
...@@ -15,24 +15,20 @@ ...@@ -15,24 +15,20 @@
#include "ccu_gate.h" #include "ccu_gate.h"
#include "ccu_mux.h" #include "ccu_mux.h"
void ccu_mux_helper_adjust_parent_for_prediv(struct ccu_common *common, static u16 ccu_mux_get_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)
{ {
u16 prediv = 1; u16 prediv = 1;
u32 reg; u32 reg;
int i;
if (!((common->features & CCU_FEATURE_FIXED_PREDIV) || if (!((common->features & CCU_FEATURE_FIXED_PREDIV) ||
(common->features & CCU_FEATURE_VARIABLE_PREDIV) || (common->features & CCU_FEATURE_VARIABLE_PREDIV) ||
(common->features & CCU_FEATURE_ALL_PREDIV))) (common->features & CCU_FEATURE_ALL_PREDIV)))
return; return 1;
if (common->features & CCU_FEATURE_ALL_PREDIV) { if (common->features & CCU_FEATURE_ALL_PREDIV)
*parent_rate = *parent_rate / common->prediv; return common->prediv;
return;
}
reg = readl(common->base + common->reg); reg = readl(common->base + common->reg);
if (parent_index < 0) { if (parent_index < 0) {
...@@ -40,10 +36,13 @@ void ccu_mux_helper_adjust_parent_for_prediv(struct ccu_common *common, ...@@ -40,10 +36,13 @@ void ccu_mux_helper_adjust_parent_for_prediv(struct ccu_common *common,
parent_index &= (1 << cm->width) - 1; parent_index &= (1 << cm->width) - 1;
} }
if (common->features & CCU_FEATURE_FIXED_PREDIV) if (common->features & CCU_FEATURE_FIXED_PREDIV) {
int i;
for (i = 0; i < cm->n_predivs; i++) for (i = 0; i < cm->n_predivs; i++)
if (parent_index == cm->fixed_predivs[i].index) if (parent_index == cm->fixed_predivs[i].index)
prediv = cm->fixed_predivs[i].div; prediv = cm->fixed_predivs[i].div;
}
if (common->features & CCU_FEATURE_VARIABLE_PREDIV) if (common->features & CCU_FEATURE_VARIABLE_PREDIV)
if (parent_index == cm->variable_prediv.index) { if (parent_index == cm->variable_prediv.index) {
...@@ -54,7 +53,16 @@ void ccu_mux_helper_adjust_parent_for_prediv(struct ccu_common *common, ...@@ -54,7 +53,16 @@ void ccu_mux_helper_adjust_parent_for_prediv(struct ccu_common *common,
prediv = div + 1; prediv = div + 1;
} }
*parent_rate = *parent_rate / prediv; return prediv;
}
void ccu_mux_helper_adjust_parent_for_prediv(struct ccu_common *common,
struct ccu_mux_internal *cm,
int parent_index,
unsigned long *parent_rate)
{
*parent_rate = *parent_rate / ccu_mux_get_prediv(common, cm,
parent_index);
} }
int ccu_mux_helper_determine_rate(struct ccu_common *common, int ccu_mux_helper_determine_rate(struct ccu_common *common,
......
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