aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIcenowy Zheng <icenowy@aosc.io>2017-08-12 08:43:51 -0400
committerChen-Yu Tsai <wens@csie.org>2017-08-14 10:45:06 -0400
commita6653773d6e5f077bdc6cdd2c57cecdcb908d035 (patch)
treee4d3fda8d5aefe7bc508040aa8a0b6ac2534943f
parent721353c030a0d6f7b5e157dc2531da96b4dd73f3 (diff)
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: Icenowy Zheng <icenowy@aosc.io> [wens@csie.org: Fixed application of post-divider in set_rate callback] Signed-off-by: Chen-Yu Tsai <wens@csie.org>
-rw-r--r--drivers/clk/sunxi-ng/ccu_nkm.c22
-rw-r--r--drivers/clk/sunxi-ng/ccu_nkm.h2
2 files changed, 21 insertions, 3 deletions
diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c
index 44b16dc8fea6..841840e35e61 100644
--- a/drivers/clk/sunxi-ng/ccu_nkm.c
+++ b/drivers/clk/sunxi-ng/ccu_nkm.c
@@ -75,7 +75,7 @@ static unsigned long ccu_nkm_recalc_rate(struct clk_hw *hw,
75 unsigned long parent_rate) 75 unsigned long parent_rate)
76{ 76{
77 struct ccu_nkm *nkm = hw_to_ccu_nkm(hw); 77 struct ccu_nkm *nkm = hw_to_ccu_nkm(hw);
78 unsigned long n, m, k; 78 unsigned long n, m, k, rate;
79 u32 reg; 79 u32 reg;
80 80
81 reg = readl(nkm->common.base + nkm->common.reg); 81 reg = readl(nkm->common.base + nkm->common.reg);
@@ -98,7 +98,12 @@ static unsigned long ccu_nkm_recalc_rate(struct clk_hw *hw,
98 if (!m) 98 if (!m)
99 m++; 99 m++;
100 100
101 return parent_rate * n * k / m; 101 rate = parent_rate * n * k / m;
102
103 if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
104 rate /= nkm->fixed_post_div;
105
106 return rate;
102} 107}
103 108
104static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux, 109static 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,
117 _nkm.min_m = 1; 122 _nkm.min_m = 1;
118 _nkm.max_m = nkm->m.max ?: 1 << nkm->m.width; 123 _nkm.max_m = nkm->m.max ?: 1 << nkm->m.width;
119 124
125 if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
126 rate *= nkm->fixed_post_div;
127
120 ccu_nkm_find_best(*parent_rate, rate, &_nkm); 128 ccu_nkm_find_best(*parent_rate, rate, &_nkm);
121 129
122 return *parent_rate * _nkm.n * _nkm.k / _nkm.m; 130 rate = *parent_rate * _nkm.n * _nkm.k / _nkm.m;
131
132 if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
133 rate /= nkm->fixed_post_div;
134
135 return rate;
123} 136}
124 137
125static int ccu_nkm_determine_rate(struct clk_hw *hw, 138static 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,
139 unsigned long flags; 152 unsigned long flags;
140 u32 reg; 153 u32 reg;
141 154
155 if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV)
156 rate *= nkm->fixed_post_div;
157
142 _nkm.min_n = nkm->n.min ?: 1; 158 _nkm.min_n = nkm->n.min ?: 1;
143 _nkm.max_n = nkm->n.max ?: 1 << nkm->n.width; 159 _nkm.max_n = nkm->n.max ?: 1 << nkm->n.width;
144 _nkm.min_k = nkm->k.min ?: 1; 160 _nkm.min_k = nkm->k.min ?: 1;
diff --git a/drivers/clk/sunxi-ng/ccu_nkm.h b/drivers/clk/sunxi-ng/ccu_nkm.h
index 34580894f4d1..cc6efb70a102 100644
--- a/drivers/clk/sunxi-ng/ccu_nkm.h
+++ b/drivers/clk/sunxi-ng/ccu_nkm.h
@@ -34,6 +34,8 @@ struct ccu_nkm {
34 struct ccu_div_internal m; 34 struct ccu_div_internal m;
35 struct ccu_mux_internal mux; 35 struct ccu_mux_internal mux;
36 36
37 unsigned int fixed_post_div;
38
37 struct ccu_common common; 39 struct ccu_common common;
38}; 40};
39 41