From eac98a31c3f654ac2e7d6d77dcc648d4a504c1a5 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Mon, 1 Apr 2019 06:30:04 +0200 Subject: [PATCH 2/2] serial: sh-sci: Fix HSCIF RX deviation calculation Doing the deviation calculation manually shows that's something wrong with the formula used by the driver: with SR = 10, the default sampling point at the center is at SR / 2 = 5, so the shift must be within [-4, +4], which is exceeded by using a value of 7. deviation = min_err * srr * last_stop / 2 / baud; With: min_err = -5 srr = 9 last_stop = 19 baud = 57600 Note that srr and baud are unsigned. Hence the multiplication and divisions are done in unsigned arithmetic, and we get deviation = 37282 instead of 0. Fix this. Additionally, use "(srr + 1)" instead of "srr", as the actual sampling rate factor is one more than the value programmed in HSSRR.SRCYC. Fixes: 63ba1e00f178a448 ("serial: sh-sci: Support for HSCIF RX sampling point adjustment") Signed-off-by: Geert Uytterhoeven --- drivers/tty/serial/sh-sci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 69896d586a29..971a2dee4d1e 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -2439,7 +2439,8 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, * center of the last stop bit in sampling clocks. */ int last_stop = bits * 2 - 1; - int deviation = min_err * srr * last_stop / 2 / baud; + int deviation = (int)(min_err * (srr + 1) * last_stop) / + 2 / (int)baud; if (abs(deviation) >= 2) { /* At least two sampling clocks off at the -- 2.20.0