Skip to content

Commit 088cefc

Browse files
Frank Oltmannswens
authored andcommitted
clk: sunxi-ng: nkm: Support finding closest rate
When finding the best rate for a NKM clock, consider rates that are higher than the requested rate, if the CCU_FEATURE_CLOSEST_RATE flag is set by using the helper function ccu_is_better_rate(). Accommodate ccu_mux_helper_determine_rate to this change. Acked-by: Maxime Ripard <[email protected]> Reviewed-by: Jernej Skrabec <[email protected]> Signed-off-by: Frank Oltmanns <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Chen-Yu Tsai <[email protected]>
1 parent c0380d1 commit 088cefc

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

drivers/clk/sunxi-ng/ccu_mux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int ccu_mux_helper_determine_rate(struct ccu_common *common,
139139
goto out;
140140
}
141141

142-
if ((req->rate - tmp_rate) < (req->rate - best_rate)) {
142+
if (ccu_is_better_rate(common, req->rate, tmp_rate, best_rate)) {
143143
best_rate = tmp_rate;
144144
best_parent_rate = parent_rate;
145145
best_parent = parent;

drivers/clk/sunxi-ng/ccu_nkm.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ struct _ccu_nkm {
1616
unsigned long m, min_m, max_m;
1717
};
1818

19-
static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *parent_hw,
19+
static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common,
20+
struct clk_hw *parent_hw,
2021
unsigned long *parent, unsigned long rate,
2122
struct _ccu_nkm *nkm)
2223
{
@@ -32,10 +33,8 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *parent_hw,
3233
tmp_parent = clk_hw_round_rate(parent_hw, rate * _m / (_n * _k));
3334

3435
tmp_rate = tmp_parent * _n * _k / _m;
35-
if (tmp_rate > rate)
36-
continue;
3736

38-
if ((rate - tmp_rate) < (rate - best_rate)) {
37+
if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) {
3938
best_rate = tmp_rate;
4039
best_parent_rate = tmp_parent;
4140
best_n = _n;
@@ -56,7 +55,7 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *parent_hw,
5655
}
5756

5857
static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate,
59-
struct _ccu_nkm *nkm)
58+
struct _ccu_nkm *nkm, struct ccu_common *common)
6059
{
6160
unsigned long best_rate = 0;
6261
unsigned long best_n = 0, best_k = 0, best_m = 0;
@@ -69,9 +68,7 @@ static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate,
6968

7069
tmp_rate = parent * _n * _k / _m;
7170

72-
if (tmp_rate > rate)
73-
continue;
74-
if ((rate - tmp_rate) < (rate - best_rate)) {
71+
if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) {
7572
best_rate = tmp_rate;
7673
best_n = _n;
7774
best_k = _k;
@@ -164,9 +161,10 @@ static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux,
164161
rate *= nkm->fixed_post_div;
165162

166163
if (!clk_hw_can_set_rate_parent(&nkm->common.hw))
167-
rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm);
164+
rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm, &nkm->common);
168165
else
169-
rate = ccu_nkm_find_best_with_parent_adj(parent_hw, parent_rate, rate, &_nkm);
166+
rate = ccu_nkm_find_best_with_parent_adj(&nkm->common, parent_hw, parent_rate, rate,
167+
&_nkm);
170168

171169
if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
172170
rate /= nkm->fixed_post_div;
@@ -201,7 +199,7 @@ static int ccu_nkm_set_rate(struct clk_hw *hw, unsigned long rate,
201199
_nkm.min_m = 1;
202200
_nkm.max_m = nkm->m.max ?: 1 << nkm->m.width;
203201

204-
ccu_nkm_find_best(parent_rate, rate, &_nkm);
202+
ccu_nkm_find_best(parent_rate, rate, &_nkm, &nkm->common);
205203

206204
spin_lock_irqsave(nkm->common.lock, flags);
207205

0 commit comments

Comments
 (0)