mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Haavard Skinnemoen <hskinnemoen@atmel.com>
To: Andrew Victor <andrew@sanpeople.com>
Cc: Russell King <rmk+serial@arm.linux.org.uk>,
	linux-kernel@vger.kernel.org,
	Haavard Skinnemoen <hskinnemoen@atmel.com>
Subject: [PATCH 3/3] at91_serial: Fix roundoff error in at91_console_get_options
Date: Wed, 02 Aug 2006 16:51:48 +0200	[thread overview]
Message-ID: <11545303082800-git-send-email-hskinnemoen@atmel.com> (raw)
In-Reply-To: <11545303083943-git-send-email-hskinnemoen@atmel.com>

The at91_console_get_options() function initializes the baud,
parity and bits settings from the actual hardware setup, in
case it has been initialized by a e.g. boot loader.

The baud rate, however, is not necessarily exactly equal to one of
the standard baud rates (115200, etc.) This means that the baud rate
calculated by this function may be slightly higher or slightly lower
than one of the standard baud rates.

If the baud rate is slightly lower than the target, this causes
problems when uart_set_option() tries to match the detected baud rate
against the standard baud rate, as it will always select a baud rate
that is lower or equal to the target rate. For example if the
detected baud rate is slightly lower than 115200, usart_set_options()
will select 57600.

This patch fixes the problem by subtracting 1 from the value in BRGR
when calculating the baud rate. The detected baud rate will thus
always be higher than the nearest standard baud rate, and
uart_set_options() will end up doing the right thing.

Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
---
 drivers/serial/at91_serial.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/drivers/serial/at91_serial.c b/drivers/serial/at91_serial.c
index c759e7c..528d717 100644
--- a/drivers/serial/at91_serial.c
+++ b/drivers/serial/at91_serial.c
@@ -806,8 +806,14 @@ static void __init at91_console_get_opti
 	else if (mr == AT91_US_PAR_ODD)
 		*parity = 'o';
 
+	/*
+	 * The serial core only rounds down when matching this to a
+	 * supported baud rate. Make sure we don't end up slightly
+	 * lower than one of those, as it would make us fall through
+	 * to a much lower baud rate than we really want.
+	 */
 	quot = UART_GET_BRGR(port);
-	*baud = port->uartclk / (16 * (quot));
+	*baud = port->uartclk / (16 * (quot - 1));
 }
 
 static int __init at91_console_setup(struct console *co, char *options)
-- 
1.4.0


  reply	other threads:[~2006-08-02 14:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-02 14:51 [PATCH 0/3] at91_serial: Introduction Haavard Skinnemoen
2006-08-02 14:51 ` [PATCH 1/3] at91_serial: support AVR32 Haavard Skinnemoen
2006-08-02 14:51   ` [PATCH 2/3] at91_serial: Fix break handling Haavard Skinnemoen
2006-08-02 14:51     ` Haavard Skinnemoen [this message]
2006-08-02 15:17     ` Russell King
2006-08-02 16:14       ` Haavard Skinnemoen
2006-08-02 16:21         ` Russell King
2006-08-02 17:39       ` Haavard Skinnemoen
2006-08-02 15:15   ` [PATCH 1/3] at91_serial: support AVR32 Russell King
2006-08-02 16:00     ` Haavard Skinnemoen
2006-08-02 16:03       ` Russell King
2006-08-02 17:27         ` Haavard Skinnemoen
2006-09-23 21:14 ` [PATCH 0/3] at91_serial: Introduction Russell King
2006-09-25 12:01   ` Haavard Skinnemoen
2006-09-25 12:16     ` Russell King
2006-09-26  9:06   ` Andrew Victor
2006-09-26  9:27     ` Haavard Skinnemoen
2006-09-26  9:28       ` Andrew Victor
2006-09-26  9:48         ` Haavard Skinnemoen
2006-09-26 16:03           ` Andrew Victor
2006-09-27 13:31     ` Haavard Skinnemoen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11545303082800-git-send-email-hskinnemoen@atmel.com \
    --to=hskinnemoen@atmel.com \
    --cc=andrew@sanpeople.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmk+serial@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome