diff options
author | Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com> | 2014-07-14 03:09:58 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-07-17 21:14:44 -0400 |
commit | b7d66397f4d282ddf2a2fe516fc9329c5a063459 (patch) | |
tree | e67a8ab952b337f4858a37d6ada0a0a46af5f172 | |
parent | ca17749259d26f7ddbb0678790d5d534018d0a6b (diff) |
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: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/serial/sh-sci.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 26dad3e87b52..2ba42069922f 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c | |||
@@ -1789,11 +1789,13 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, | |||
1789 | for (sr = 8; sr <= 32; sr++) { | 1789 | for (sr = 8; sr <= 32; sr++) { |
1790 | for (c = 0; c <= 3; c++) { | 1790 | for (c = 0; c <= 3; c++) { |
1791 | /* integerized formulas from HSCIF documentation */ | 1791 | /* integerized formulas from HSCIF documentation */ |
1792 | br = freq / (sr * (1 << (2 * c + 1)) * bps) - 1; | 1792 | br = DIV_ROUND_CLOSEST(freq, (sr * |
1793 | (1 << (2 * c + 1)) * bps)) - 1; | ||
1793 | if (br < 0 || br > 255) | 1794 | if (br < 0 || br > 255) |
1794 | continue; | 1795 | continue; |
1795 | err = freq / ((br + 1) * bps * sr * | 1796 | err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr * |
1796 | (1 << (2 * c + 1)) / 1000) - 1000; | 1797 | (1 << (2 * c + 1)) / 1000)) - |
1798 | 1000; | ||
1797 | if (min_err > err) { | 1799 | if (min_err > err) { |
1798 | min_err = err; | 1800 | min_err = err; |
1799 | *brr = br; | 1801 | *brr = br; |