Commit 657f477a authored by Samuel Holland's avatar Samuel Holland Committed by Jernej Skrabec
Browse files

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: default avatarSamuel Holland <samuel@sholland.org>
Reviewed-by: default avatarJernej Skrabec <jernej.skrabec@gmail.com>
Reviewed-by: default avatarAndre Przywara <andre.przywara@arm.com>
Link: https://lore.kernel.org/r/20221231173055.42384-1-samuel@sholland.org


Signed-off-by: default avatarJernej Skrabec <jernej.skrabec@gmail.com>
parent 5ee541ae
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
#include "ccu_gate.h"
#include "ccu_mp.h"

static void ccu_mp_find_best(unsigned long parent, unsigned long rate,
static unsigned long ccu_mp_find_best(unsigned long parent, unsigned long rate,
				      unsigned int max_m, unsigned int max_p,
				      unsigned int *m, unsigned int *p)
{
@@ -35,6 +35,8 @@ static void ccu_mp_find_best(unsigned long parent, unsigned long rate,

	*m = best_m;
	*p = best_p;

	return best_rate;
}

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,
	max_p = cmp->p.max ?: 1 << ((1 << cmp->p.width) - 1);

	if (!clk_hw_can_set_rate_parent(&cmp->common.hw)) {
		ccu_mp_find_best(*parent_rate, rate, max_m, max_p, &m, &p);
		rate = *parent_rate / p / m;
		rate = ccu_mp_find_best(*parent_rate, rate, max_m, max_p, &m, &p);
	} else {
		rate = ccu_mp_find_best_with_parent_adj(hw, parent_rate, rate,
							max_m, max_p);
+5 −4
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ struct _ccu_nk {
	unsigned long	k, min_k, max_k;
};

static void ccu_nk_find_best(unsigned long parent, unsigned long rate,
static unsigned long ccu_nk_find_best(unsigned long parent, unsigned long rate,
				      struct _ccu_nk *nk)
{
	unsigned long best_rate = 0;
@@ -39,6 +39,8 @@ static void ccu_nk_find_best(unsigned long parent, unsigned long rate,

	nk->k = best_k;
	nk->n = best_n;

	return best_rate;
}

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,
	_nk.min_k = nk->k.min ?: 1;
	_nk.max_k = nk->k.max ?: 1 << nk->k.width;

	ccu_nk_find_best(*parent_rate, rate, &_nk);
	rate = *parent_rate * _nk.n * _nk.k;
	rate = ccu_nk_find_best(*parent_rate, rate, &_nk);

	if (nk->common.features & CCU_FEATURE_FIXED_POSTDIV)
		rate = rate / nk->fixed_post_div;
+5 −5
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ struct _ccu_nkm {
	unsigned long	m, min_m, max_m;
};

static void ccu_nkm_find_best(unsigned long parent, unsigned long rate,
static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate,
				       struct _ccu_nkm *nkm)
{
	unsigned long best_rate = 0;
@@ -45,6 +45,8 @@ static void ccu_nkm_find_best(unsigned long parent, unsigned long rate,
	nkm->n = best_n;
	nkm->k = best_k;
	nkm->m = best_m;

	return best_rate;
}

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,
	if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
		rate *= nkm->fixed_post_div;

	ccu_nkm_find_best(*parent_rate, rate, &_nkm);

	rate = *parent_rate * _nkm.n * _nkm.k / _nkm.m;
	rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm);

	if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
		rate /= nkm->fixed_post_div;
+5 −5
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ static unsigned long ccu_nkmp_calc_rate(unsigned long parent,
	return rate;
}

static void ccu_nkmp_find_best(unsigned long parent, unsigned long rate,
static unsigned long ccu_nkmp_find_best(unsigned long parent, unsigned long rate,
					struct _ccu_nkmp *nkmp)
{
	unsigned long best_rate = 0;
@@ -65,6 +65,8 @@ static void ccu_nkmp_find_best(unsigned long parent, unsigned long rate,
	nkmp->k = best_k;
	nkmp->m = best_m;
	nkmp->p = best_p;

	return best_rate;
}

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,
	_nkmp.min_p = 1;
	_nkmp.max_p = nkmp->p.max ?: 1 << ((1 << nkmp->p.width) - 1);

	ccu_nkmp_find_best(*parent_rate, rate, &_nkmp);
	rate = ccu_nkmp_find_best(*parent_rate, rate, &_nkmp);

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

+5 −4
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ static unsigned long ccu_nm_calc_rate(unsigned long parent,
	return rate;
}

static void ccu_nm_find_best(unsigned long parent, unsigned long rate,
static unsigned long ccu_nm_find_best(unsigned long parent, unsigned long rate,
				      struct _ccu_nm *nm)
{
	unsigned long best_rate = 0;
@@ -52,6 +52,8 @@ static void ccu_nm_find_best(unsigned long parent, unsigned long rate,

	nm->n = best_n;
	nm->m = best_m;

	return best_rate;
}

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,
	_nm.min_m = 1;
	_nm.max_m = nm->m.max ?: 1 << nm->m.width;

	ccu_nm_find_best(*parent_rate, rate, &_nm);
	rate = ccu_nm_calc_rate(*parent_rate, _nm.n, _nm.m);
	rate = ccu_nm_find_best(*parent_rate, rate, &_nm);

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