Skip to content

Commit 5723879

Browse files
Frank Oltmannsjernejsk
authored andcommitted
clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate
The Allwinner A64 manual lists the following constraints for the PLL-MIPI clock: - M/N <= 3 - (PLL_VIDEO0)/M >= 24MHz The PLL-MIPI clock is implemented as ccu_nkm. Therefore, add support for these constraints. Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com> Signed-off-by: Frank Oltmanns <frank@oltmanns.dev> Link: https://lore.kernel.org/r/20240310-pinephone-pll-fixes-v4-3-46fc80c83637@oltmanns.dev Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
1 parent 4cece76 commit 5723879

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

drivers/clk/sunxi-ng/ccu_nkm.c

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

19+
static bool ccu_nkm_is_valid_rate(struct ccu_common *common, unsigned long parent,
20+
unsigned long n, unsigned long m)
21+
{
22+
struct ccu_nkm *nkm = container_of(common, struct ccu_nkm, common);
23+
24+
if (nkm->max_m_n_ratio && (m > nkm->max_m_n_ratio * n))
25+
return false;
26+
27+
if (nkm->min_parent_m_ratio && (parent < nkm->min_parent_m_ratio * m))
28+
return false;
29+
30+
return true;
31+
}
32+
1933
static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common,
2034
struct clk_hw *parent_hw,
2135
unsigned long *parent, unsigned long rate,
@@ -31,6 +45,10 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common
3145
unsigned long tmp_rate, tmp_parent;
3246

3347
tmp_parent = clk_hw_round_rate(parent_hw, rate * _m / (_n * _k));
48+
49+
if (!ccu_nkm_is_valid_rate(common, tmp_parent, _n, _m))
50+
continue;
51+
3452
tmp_rate = tmp_parent * _n * _k / _m;
3553

3654
if (ccu_is_better_rate(common, rate, tmp_rate, best_rate) ||
@@ -64,6 +82,9 @@ static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate,
6482
for (_k = nkm->min_k; _k <= nkm->max_k; _k++) {
6583
for (_n = nkm->min_n; _n <= nkm->max_n; _n++) {
6684
for (_m = nkm->min_m; _m <= nkm->max_m; _m++) {
85+
if (!ccu_nkm_is_valid_rate(common, parent, _n, _m))
86+
continue;
87+
6788
unsigned long tmp_rate;
6889

6990
tmp_rate = parent * _n * _k / _m;

drivers/clk/sunxi-ng/ccu_nkm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct ccu_nkm {
2727
struct ccu_mux_internal mux;
2828

2929
unsigned int fixed_post_div;
30+
unsigned long max_m_n_ratio;
31+
unsigned long min_parent_m_ratio;
3032

3133
struct ccu_common common;
3234
};

0 commit comments

Comments
 (0)