From patchwork Wed Sep 21 10:44:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Ferre X-Patchwork-Id: 9343323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 371B0607D4 for ; Wed, 21 Sep 2016 11:03:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26F522A5D9 for ; Wed, 21 Sep 2016 11:03:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B7D72A5E6; Wed, 21 Sep 2016 11:03:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D65492A5D9 for ; Wed, 21 Sep 2016 11:03:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bmfGk-0000Yg-EW; Wed, 21 Sep 2016 11:00:50 +0000 Received: from exsmtp03.microchip.com ([198.175.253.49] helo=email.microchip.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bmfGd-0008WJ-LG for linux-arm-kernel@lists.infradead.org; Wed, 21 Sep 2016 11:00:47 +0000 Received: from tenerife.corp.atmel.com (10.10.76.4) by chn-sv-exch03.mchp-main.com (10.10.76.49) with Microsoft SMTP Server id 14.3.181.6; Wed, 21 Sep 2016 03:43:38 -0700 From: Nicolas Ferre To: , Ludovic Desroches , Boris BREZILLON , , Subject: [PATCH] tty/serial: atmel: fix fractional baud rate computation Date: Wed, 21 Sep 2016 12:44:14 +0200 Message-ID: <20160921104414.16241-1-nicolas.ferre@atmel.com> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAC+NgFvrDosTGxcLF5cOiG53yKNzg6cb3fzksvjYZW9z7tI3R4v610ywWG9rXMll0TFnFZPH/9WlWi2nT3zE7sAcwRLFm5iXlVySwZiy+fpCx4IJAxZOJV9gbGI/ydjFycQgJrGOUOH7qJ0sXIycHm4CuxNkJT9hAEiICexklLvw9wQ6SYBaYyiSx53geiC0s4CHR/vQDWJxFQFWib81jRhCbV8BG4kH/OrBBEgJyEg3n7zNDxAUlTs58wgIxR0Li4IsXYHEhARWJvvf97BD1gRJ/Xhxmg7CdJJZe2QA1x07i8PSLUDX2Et1LtzPC1Hz4/RbK1pbY/mofK4StI7HtYD9Ur63EnhkTmSBsd4kHj5ZD2b4Ssx42QNVESWzY95p9AqPYLCSnzkJy6gJGplWM0skZebrFZbqpFckZBsZ6uckZBbq5iZl5esn5uZsYITFjuINx0wO/Q4ySHExKorxT44+EC/El5adUZiQWZ8QXleakFh9ilODgURLhXXsaKMdbXJCYW5yZDpOS4eBQkuAVAkkJFqWmp1akZeaUpBZBpE8xSkqJ8x48BZQUAOnLKM2Dy11iFJUS5q3bC5TjKUgtys0sgYjfYhTmeMgkxJKXn5cqBXQiAxBoML5iFOdgVBLm1QNZxJOZVwJ3wiug65iAriu4cxjkupJEhJRUA2PNqdoVIeU6f6+5e2xk1lk48eFZwYPJ5uExZQ7hyd2PPsik3DQPiQg4+N4m9N0520MbDkxczvog/zLPl89nXHlb1skKvKgr1rE5t/dw3KPN/P+vn7B3TT2rzXZx8uKkb8vSanL+b97bqvQhOeMOz1lu1QSDauEIn1dVQrypsziaZmvGLs/5fFSJpTgj0VCLuag4EQAb23rFDwMAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160921_040043_793369_E1328396 X-CRM114-Status: UNSURE ( 9.82 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kroah-Hartman , Nicolas Ferre , linux-kernel@vger.kernel.org, Alexandre Belloni , Cyrille Pitchen , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Alexey Starikovskiy The problem with previous code was it rounded values in wrong place and produced wrong baud rate in some cases. Signed-off-by: Alexey Starikovskiy [nicolas.ferre@atmel.com: port to newer kernel and add commit log] Signed-off-by: Nicolas Ferre Reviewed-by: Boris Brezillon Reviewed-by: Uwe Kleine-König --- drivers/tty/serial/atmel_serial.c | 10 ++++++---- include/linux/atmel_serial.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 5f550d9feed9..fd8aa1f4ba78 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -2170,13 +2170,15 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, * accurately. This feature is enabled only when using normal mode. * baudrate = selected clock / (8 * (2 - OVER) * (CD + FP / 8)) * Currently, OVER is always set to 0 so we get - * baudrate = selected clock (16 * (CD + FP / 8)) + * baudrate = selected clock / (16 * (CD + FP / 8)) + * then + * 8 CD + FP = selected clock / (2 * baudrate) */ if (atmel_port->has_frac_baudrate && (mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_NORMAL) { - div = DIV_ROUND_CLOSEST(port->uartclk, baud); - cd = div / 16; - fp = DIV_ROUND_CLOSEST(div % 16, 2); + div = DIV_ROUND_CLOSEST(port->uartclk, baud * 2); + cd = div >> 3; + fp = div & ATMEL_US_FP_MASK; } else { cd = uart_get_divisor(port, baud); } diff --git a/include/linux/atmel_serial.h b/include/linux/atmel_serial.h index f8e452aa48d7..bd2560502f3c 100644 --- a/include/linux/atmel_serial.h +++ b/include/linux/atmel_serial.h @@ -119,6 +119,7 @@ #define ATMEL_US_BRGR 0x20 /* Baud Rate Generator Register */ #define ATMEL_US_CD GENMASK(15, 0) /* Clock Divider */ #define ATMEL_US_FP_OFFSET 16 /* Fractional Part */ +#define ATMEL_US_FP_MASK 0x7 #define ATMEL_US_RTOR 0x24 /* Receiver Time-out Register for USART */ #define ATMEL_UA_RTOR 0x28 /* Receiver Time-out Register for UART */