Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6653773 authored by Icenowy Zheng's avatar Icenowy Zheng Committed by Chen-Yu Tsai
Browse files

clk: sunxi-ng: nkm: add support for fixed post-divider



SATA PLL on Allwinner R40 is of type (parent) * N * K / M / 6 where 6 is
the fixed post-divider.

Add post-divider support for NKM type clock.

Signed-off-by: default avatarIcenowy Zheng <icenowy@aosc.io>
[wens@csie.org: Fixed application of post-divider in set_rate callback]
Signed-off-by: default avatarChen-Yu Tsai <wens@csie.org>
parent 721353c0
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ static unsigned long ccu_nkm_recalc_rate(struct clk_hw *hw,
					unsigned long parent_rate)
{
	struct ccu_nkm *nkm = hw_to_ccu_nkm(hw);
	unsigned long n, m, k;
	unsigned long n, m, k, rate;
	u32 reg;

	reg = readl(nkm->common.base + nkm->common.reg);
@@ -98,7 +98,12 @@ static unsigned long ccu_nkm_recalc_rate(struct clk_hw *hw,
	if (!m)
		m++;

	return parent_rate * n  * k / m;
	rate = parent_rate * n  * k / m;

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

	return rate;
}

static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux,
@@ -117,9 +122,17 @@ static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux,
	_nkm.min_m = 1;
	_nkm.max_m = nkm->m.max ?: 1 << nkm->m.width;

	if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
		rate *= nkm->fixed_post_div;

	ccu_nkm_find_best(*parent_rate, rate, &_nkm);

	return *parent_rate * _nkm.n * _nkm.k / _nkm.m;
	rate = *parent_rate * _nkm.n * _nkm.k / _nkm.m;

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

	return rate;
}

static int ccu_nkm_determine_rate(struct clk_hw *hw,
@@ -139,6 +152,9 @@ static int ccu_nkm_set_rate(struct clk_hw *hw, unsigned long rate,
	unsigned long flags;
	u32 reg;

	if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
		rate *= nkm->fixed_post_div;

	_nkm.min_n = nkm->n.min ?: 1;
	_nkm.max_n = nkm->n.max ?: 1 << nkm->n.width;
	_nkm.min_k = nkm->k.min ?: 1;
+2 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ struct ccu_nkm {
	struct ccu_div_internal		m;
	struct ccu_mux_internal	mux;

	unsigned int		fixed_post_div;

	struct ccu_common	common;
};