mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-25 03:55:09 +08:00
clk: si5351: msynth: Switch to determine_rate
The SI5351 msynth clocks implements a mux with a set_parent hook, but doesn't provide a determine_rate implementation. This is a bit odd, since set_parent() is there to, as its name implies, change the parent of a clock. However, the most likely candidate to trigger that parent change is a call to clk_set_rate(), with determine_rate() figuring out which parent is the best suited for a given rate. The other trigger would be a call to clk_set_parent(), but it's far less used, and it doesn't look like there's any obvious user for that clock. So, the set_parent hook is effectively unused, possibly because of an oversight. However, it could also be an explicit decision by the original author to avoid any reparenting but through an explicit call to clk_set_parent(). The driver does implement round_rate() though, which means that we can change the rate of the clock, but we will never get to change the parent. However, It's hard to tell whether it's been done on purpose or not. Since we'll start mandating a determine_rate() implementation, let's convert the round_rate() implementation to a determine_rate(), which will also make the current behavior explicit. And if it was an oversight, the clock behaviour can be adjusted later on. Signed-off-by: Maxime Ripard <maxime@cerno.tech> Link: https://lore.kernel.org/r/20221018-clk-range-checks-fixes-v4-55-971d5077e7d2@cerno.tech Signed-off-by: Stephen Boyd <sboyd@kernel.org>
This commit is contained in:
parent
08add3c1d8
commit
4ab2bf813e
@ -642,11 +642,12 @@ static unsigned long si5351_msynth_recalc_rate(struct clk_hw *hw,
|
|||||||
return (unsigned long)rate;
|
return (unsigned long)rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
|
static int si5351_msynth_determine_rate(struct clk_hw *hw,
|
||||||
unsigned long *parent_rate)
|
struct clk_rate_request *req)
|
||||||
{
|
{
|
||||||
struct si5351_hw_data *hwdata =
|
struct si5351_hw_data *hwdata =
|
||||||
container_of(hw, struct si5351_hw_data, hw);
|
container_of(hw, struct si5351_hw_data, hw);
|
||||||
|
unsigned long rate = req->rate;
|
||||||
unsigned long long lltmp;
|
unsigned long long lltmp;
|
||||||
unsigned long a, b, c;
|
unsigned long a, b, c;
|
||||||
int divby4;
|
int divby4;
|
||||||
@ -681,10 +682,10 @@ static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
|
|||||||
b = 0;
|
b = 0;
|
||||||
c = 1;
|
c = 1;
|
||||||
|
|
||||||
*parent_rate = a * rate;
|
req->best_parent_rate = a * rate;
|
||||||
} else if (hwdata->num >= 6) {
|
} else if (hwdata->num >= 6) {
|
||||||
/* determine the closest integer divider */
|
/* determine the closest integer divider */
|
||||||
a = DIV_ROUND_CLOSEST(*parent_rate, rate);
|
a = DIV_ROUND_CLOSEST(req->best_parent_rate, rate);
|
||||||
if (a < SI5351_MULTISYNTH_A_MIN)
|
if (a < SI5351_MULTISYNTH_A_MIN)
|
||||||
a = SI5351_MULTISYNTH_A_MIN;
|
a = SI5351_MULTISYNTH_A_MIN;
|
||||||
if (a > SI5351_MULTISYNTH67_A_MAX)
|
if (a > SI5351_MULTISYNTH67_A_MAX)
|
||||||
@ -702,7 +703,7 @@ static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* determine integer part of divider equation */
|
/* determine integer part of divider equation */
|
||||||
a = *parent_rate / rate;
|
a = req->best_parent_rate / rate;
|
||||||
if (a < SI5351_MULTISYNTH_A_MIN)
|
if (a < SI5351_MULTISYNTH_A_MIN)
|
||||||
a = SI5351_MULTISYNTH_A_MIN;
|
a = SI5351_MULTISYNTH_A_MIN;
|
||||||
if (a > SI5351_MULTISYNTH_A_MAX)
|
if (a > SI5351_MULTISYNTH_A_MAX)
|
||||||
@ -710,7 +711,7 @@ static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
|
|||||||
|
|
||||||
/* find best approximation for b/c = fVCO mod fOUT */
|
/* find best approximation for b/c = fVCO mod fOUT */
|
||||||
denom = 1000 * 1000;
|
denom = 1000 * 1000;
|
||||||
lltmp = (*parent_rate) % rate;
|
lltmp = req->best_parent_rate % rate;
|
||||||
lltmp *= denom;
|
lltmp *= denom;
|
||||||
do_div(lltmp, rate);
|
do_div(lltmp, rate);
|
||||||
rfrac = (unsigned long)lltmp;
|
rfrac = (unsigned long)lltmp;
|
||||||
@ -724,7 +725,7 @@ static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* recalculate rate by fOUT = fIN / (a + b/c) */
|
/* recalculate rate by fOUT = fIN / (a + b/c) */
|
||||||
lltmp = *parent_rate;
|
lltmp = req->best_parent_rate;
|
||||||
lltmp *= c;
|
lltmp *= c;
|
||||||
do_div(lltmp, a * c + b);
|
do_div(lltmp, a * c + b);
|
||||||
rate = (unsigned long)lltmp;
|
rate = (unsigned long)lltmp;
|
||||||
@ -749,9 +750,11 @@ static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
|
|||||||
dev_dbg(&hwdata->drvdata->client->dev,
|
dev_dbg(&hwdata->drvdata->client->dev,
|
||||||
"%s - %s: a = %lu, b = %lu, c = %lu, divby4 = %d, parent_rate = %lu, rate = %lu\n",
|
"%s - %s: a = %lu, b = %lu, c = %lu, divby4 = %d, parent_rate = %lu, rate = %lu\n",
|
||||||
__func__, clk_hw_get_name(hw), a, b, c, divby4,
|
__func__, clk_hw_get_name(hw), a, b, c, divby4,
|
||||||
*parent_rate, rate);
|
req->best_parent_rate, rate);
|
||||||
|
|
||||||
return rate;
|
req->rate = rate;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int si5351_msynth_set_rate(struct clk_hw *hw, unsigned long rate,
|
static int si5351_msynth_set_rate(struct clk_hw *hw, unsigned long rate,
|
||||||
@ -791,7 +794,7 @@ static const struct clk_ops si5351_msynth_ops = {
|
|||||||
.set_parent = si5351_msynth_set_parent,
|
.set_parent = si5351_msynth_set_parent,
|
||||||
.get_parent = si5351_msynth_get_parent,
|
.get_parent = si5351_msynth_get_parent,
|
||||||
.recalc_rate = si5351_msynth_recalc_rate,
|
.recalc_rate = si5351_msynth_recalc_rate,
|
||||||
.round_rate = si5351_msynth_round_rate,
|
.determine_rate = si5351_msynth_determine_rate,
|
||||||
.set_rate = si5351_msynth_set_rate,
|
.set_rate = si5351_msynth_set_rate,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user