All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] serial: sh-sci: Updated calculation of bit error rate and bit rate
@ 2014-07-14  7:09 ` Nobuhiro Iwamatsu
  0 siblings, 0 replies; 10+ messages in thread
From: Nobuhiro Iwamatsu @ 2014-07-14  7:09 UTC (permalink / raw)
  To: linux-sh
  Cc: gregkh, linux-serial, horms+renesas, magnus.damm, Nobuhiro Iwamatsu

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>
---
 drivers/tty/serial/sh-sci.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 88236da..ce80137 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1796,11 +1796,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;
-- 
2.0.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-11-02 13:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-14  7:09 [PATCH 1/3] serial: sh-sci: Updated calculation of bit error rate and bit rate Nobuhiro Iwamatsu
2014-07-14  7:09 ` Nobuhiro Iwamatsu
2014-07-14  7:09 ` [PATCH 2/3] serial: sh-sci: Fix range check of bit-rate for HSCIF Nobuhiro Iwamatsu
2014-07-14  7:09   ` Nobuhiro Iwamatsu
2014-07-14  7:10 ` [PATCH 3/3] serial: sh-sci: Add calculation recive margin " Nobuhiro Iwamatsu
2014-07-14  7:10   ` Nobuhiro Iwamatsu
2015-11-02 13:56   ` Geert Uytterhoeven
2015-11-02 13:56     ` Geert Uytterhoeven
2014-07-22  1:37 ` [PATCH 1/3] serial: sh-sci: Updated calculation of bit error rate and bit rate Simon Horman
2014-07-22  1:37   ` Simon Horman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.