提交 b7d66397 编写于 作者: N Nobuhiro Iwamatsu 提交者: Greg Kroah-Hartman

serial: sh-sci: Updated calculation of bit error rate and bit rate

Currently, the decimal point is discarded calculation of BRR.
Therefore, it can not calculate a value close to the correct value.
This patch fixes this problem by using DIV_ROUND_CLOSEST.
Signed-off-by: NNobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 ca177492
......@@ -1789,11 +1789,13 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
for (sr = 8; sr <= 32; sr++) {
for (c = 0; c <= 3; c++) {
/* integerized formulas from HSCIF documentation */
br = freq / (sr * (1 << (2 * c + 1)) * bps) - 1;
br = DIV_ROUND_CLOSEST(freq, (sr *
(1 << (2 * c + 1)) * bps)) - 1;
if (br < 0 || br > 255)
continue;
err = freq / ((br + 1) * bps * sr *
(1 << (2 * c + 1)) / 1000) - 1000;
err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
(1 << (2 * c + 1)) / 1000)) -
1000;
if (min_err > err) {
min_err = err;
*brr = br;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册