Skip to content

Commit 657f477

Browse files
smaeuljernejsk
authored andcommitted
clk: sunxi-ng: Avoid computing the rate twice
The ccu_*_find_best() functions already compute a best_rate at the same time as the other factors. Return this value so the caller does not need to duplicate the computation. Signed-off-by: Samuel Holland <samuel@sholland.org> Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com> Reviewed-by: Andre Przywara <andre.przywara@arm.com> Link: https://lore.kernel.org/r/20221231173055.42384-1-samuel@sholland.org Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
1 parent 5ee541a commit 657f477

5 files changed

Lines changed: 26 additions & 23 deletions

File tree

drivers/clk/sunxi-ng/ccu_mp.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "ccu_gate.h"
1111
#include "ccu_mp.h"
1212

13-
static void ccu_mp_find_best(unsigned long parent, unsigned long rate,
14-
unsigned int max_m, unsigned int max_p,
15-
unsigned int *m, unsigned int *p)
13+
static unsigned long ccu_mp_find_best(unsigned long parent, unsigned long rate,
14+
unsigned int max_m, unsigned int max_p,
15+
unsigned int *m, unsigned int *p)
1616
{
1717
unsigned long best_rate = 0;
1818
unsigned int best_m = 0, best_p = 0;
@@ -35,6 +35,8 @@ static void ccu_mp_find_best(unsigned long parent, unsigned long rate,
3535

3636
*m = best_m;
3737
*p = best_p;
38+
39+
return best_rate;
3840
}
3941

4042
static unsigned long ccu_mp_find_best_with_parent_adj(struct clk_hw *hw,
@@ -109,8 +111,7 @@ static unsigned long ccu_mp_round_rate(struct ccu_mux_internal *mux,
109111
max_p = cmp->p.max ?: 1 << ((1 << cmp->p.width) - 1);
110112

111113
if (!clk_hw_can_set_rate_parent(&cmp->common.hw)) {
112-
ccu_mp_find_best(*parent_rate, rate, max_m, max_p, &m, &p);
113-
rate = *parent_rate / p / m;
114+
rate = ccu_mp_find_best(*parent_rate, rate, max_m, max_p, &m, &p);
114115
} else {
115116
rate = ccu_mp_find_best_with_parent_adj(hw, parent_rate, rate,
116117
max_m, max_p);

drivers/clk/sunxi-ng/ccu_nk.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ struct _ccu_nk {
1515
unsigned long k, min_k, max_k;
1616
};
1717

18-
static void ccu_nk_find_best(unsigned long parent, unsigned long rate,
19-
struct _ccu_nk *nk)
18+
static unsigned long ccu_nk_find_best(unsigned long parent, unsigned long rate,
19+
struct _ccu_nk *nk)
2020
{
2121
unsigned long best_rate = 0;
2222
unsigned int best_k = 0, best_n = 0;
@@ -39,6 +39,8 @@ static void ccu_nk_find_best(unsigned long parent, unsigned long rate,
3939

4040
nk->k = best_k;
4141
nk->n = best_n;
42+
43+
return best_rate;
4244
}
4345

4446
static void ccu_nk_disable(struct clk_hw *hw)
@@ -104,8 +106,7 @@ static long ccu_nk_round_rate(struct clk_hw *hw, unsigned long rate,
104106
_nk.min_k = nk->k.min ?: 1;
105107
_nk.max_k = nk->k.max ?: 1 << nk->k.width;
106108

107-
ccu_nk_find_best(*parent_rate, rate, &_nk);
108-
rate = *parent_rate * _nk.n * _nk.k;
109+
rate = ccu_nk_find_best(*parent_rate, rate, &_nk);
109110

110111
if (nk->common.features & CCU_FEATURE_FIXED_POSTDIV)
111112
rate = rate / nk->fixed_post_div;

drivers/clk/sunxi-ng/ccu_nkm.c

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

19-
static void ccu_nkm_find_best(unsigned long parent, unsigned long rate,
20-
struct _ccu_nkm *nkm)
19+
static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate,
20+
struct _ccu_nkm *nkm)
2121
{
2222
unsigned long best_rate = 0;
2323
unsigned long best_n = 0, best_k = 0, best_m = 0;
@@ -45,6 +45,8 @@ static void ccu_nkm_find_best(unsigned long parent, unsigned long rate,
4545
nkm->n = best_n;
4646
nkm->k = best_k;
4747
nkm->m = best_m;
48+
49+
return best_rate;
4850
}
4951

5052
static void ccu_nkm_disable(struct clk_hw *hw)
@@ -122,9 +124,7 @@ static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux,
122124
if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
123125
rate *= nkm->fixed_post_div;
124126

125-
ccu_nkm_find_best(*parent_rate, rate, &_nkm);
126-
127-
rate = *parent_rate * _nkm.n * _nkm.k / _nkm.m;
127+
rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm);
128128

129129
if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
130130
rate /= nkm->fixed_post_div;

drivers/clk/sunxi-ng/ccu_nkmp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ static unsigned long ccu_nkmp_calc_rate(unsigned long parent,
2929
return rate;
3030
}
3131

32-
static void ccu_nkmp_find_best(unsigned long parent, unsigned long rate,
33-
struct _ccu_nkmp *nkmp)
32+
static unsigned long ccu_nkmp_find_best(unsigned long parent, unsigned long rate,
33+
struct _ccu_nkmp *nkmp)
3434
{
3535
unsigned long best_rate = 0;
3636
unsigned long best_n = 0, best_k = 0, best_m = 0, best_p = 0;
@@ -65,6 +65,8 @@ static void ccu_nkmp_find_best(unsigned long parent, unsigned long rate,
6565
nkmp->k = best_k;
6666
nkmp->m = best_m;
6767
nkmp->p = best_p;
68+
69+
return best_rate;
6870
}
6971

7072
static void ccu_nkmp_disable(struct clk_hw *hw)
@@ -150,10 +152,8 @@ static long ccu_nkmp_round_rate(struct clk_hw *hw, unsigned long rate,
150152
_nkmp.min_p = 1;
151153
_nkmp.max_p = nkmp->p.max ?: 1 << ((1 << nkmp->p.width) - 1);
152154

153-
ccu_nkmp_find_best(*parent_rate, rate, &_nkmp);
155+
rate = ccu_nkmp_find_best(*parent_rate, rate, &_nkmp);
154156

155-
rate = ccu_nkmp_calc_rate(*parent_rate, _nkmp.n, _nkmp.k,
156-
_nkmp.m, _nkmp.p);
157157
if (nkmp->common.features & CCU_FEATURE_FIXED_POSTDIV)
158158
rate = rate / nkmp->fixed_post_div;
159159

drivers/clk/sunxi-ng/ccu_nm.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ static unsigned long ccu_nm_calc_rate(unsigned long parent,
2727
return rate;
2828
}
2929

30-
static void ccu_nm_find_best(unsigned long parent, unsigned long rate,
31-
struct _ccu_nm *nm)
30+
static unsigned long ccu_nm_find_best(unsigned long parent, unsigned long rate,
31+
struct _ccu_nm *nm)
3232
{
3333
unsigned long best_rate = 0;
3434
unsigned long best_n = 0, best_m = 0;
@@ -52,6 +52,8 @@ static void ccu_nm_find_best(unsigned long parent, unsigned long rate,
5252

5353
nm->n = best_n;
5454
nm->m = best_m;
55+
56+
return best_rate;
5557
}
5658

5759
static void ccu_nm_disable(struct clk_hw *hw)
@@ -157,8 +159,7 @@ static long ccu_nm_round_rate(struct clk_hw *hw, unsigned long rate,
157159
_nm.min_m = 1;
158160
_nm.max_m = nm->m.max ?: 1 << nm->m.width;
159161

160-
ccu_nm_find_best(*parent_rate, rate, &_nm);
161-
rate = ccu_nm_calc_rate(*parent_rate, _nm.n, _nm.m);
162+
rate = ccu_nm_find_best(*parent_rate, rate, &_nm);
162163

163164
if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV)
164165
rate /= nm->fixed_post_div;

0 commit comments

Comments
 (0)