diff options
author | Valentin Longchamp <valentin.longchamp@keymile.com> | 2017-02-17 05:29:45 -0500 |
---|---|---|
committer | Scott Wood <oss@buserror.net> | 2017-04-30 02:31:51 -0400 |
commit | 2ccf80b7566cc035d903dd0ac5d7ebd25c2c1060 (patch) | |
tree | d6e142b7618268be43935a39e1168ab8fa2e1f28 | |
parent | b54ea82f01282253c85eb7e2fd2b6c96f7a027d8 (diff) |
soc/fsl/qe: round brg_freq to 1kHz granularity
Because of integer computation rounding in u-boot (that sets the QE
brg-frequency DTS prop), the clk value is 99999999 Hz even though it is
100 MHz.
When setting brg clks that are exact divisors of 100 MHz, this small
differnce plays a role and can result in lower clks to be output (for
instance 20 MHz - divide by 5 - results in 16.666 MHz - divide by 6).
This patch fixes that by "forcing" the brg_clk to the nearest kHz when
the difference is below 2 integer rounding errors (i.e. 4).
Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
Signed-off-by: Scott Wood <oss@buserror.net>
-rw-r--r-- | drivers/soc/fsl/qe/qe.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c index d9c04f588f7f..31a094573a9d 100644 --- a/drivers/soc/fsl/qe/qe.c +++ b/drivers/soc/fsl/qe/qe.c | |||
@@ -161,11 +161,15 @@ EXPORT_SYMBOL(qe_issue_cmd); | |||
161 | */ | 161 | */ |
162 | static unsigned int brg_clk = 0; | 162 | static unsigned int brg_clk = 0; |
163 | 163 | ||
164 | #define CLK_GRAN (1000) | ||
165 | #define CLK_GRAN_LIMIT (5) | ||
166 | |||
164 | unsigned int qe_get_brg_clk(void) | 167 | unsigned int qe_get_brg_clk(void) |
165 | { | 168 | { |
166 | struct device_node *qe; | 169 | struct device_node *qe; |
167 | int size; | 170 | int size; |
168 | const u32 *prop; | 171 | const u32 *prop; |
172 | unsigned int mod; | ||
169 | 173 | ||
170 | if (brg_clk) | 174 | if (brg_clk) |
171 | return brg_clk; | 175 | return brg_clk; |
@@ -183,6 +187,15 @@ unsigned int qe_get_brg_clk(void) | |||
183 | 187 | ||
184 | of_node_put(qe); | 188 | of_node_put(qe); |
185 | 189 | ||
190 | /* round this if near to a multiple of CLK_GRAN */ | ||
191 | mod = brg_clk % CLK_GRAN; | ||
192 | if (mod) { | ||
193 | if (mod < CLK_GRAN_LIMIT) | ||
194 | brg_clk -= mod; | ||
195 | else if (mod > (CLK_GRAN - CLK_GRAN_LIMIT)) | ||
196 | brg_clk += CLK_GRAN - mod; | ||
197 | } | ||
198 | |||
186 | return brg_clk; | 199 | return brg_clk; |
187 | } | 200 | } |
188 | EXPORT_SYMBOL(qe_get_brg_clk); | 201 | EXPORT_SYMBOL(qe_get_brg_clk); |