blob: efdff82ddfbbfa4ae99d6a573051407c9767c77b [file] [log] [blame]
From 09419333d40b298b7d6eeae4f53de1e00900e756 Mon Sep 17 00:00:00 2001
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Date: Fri, 6 Dec 2013 10:59:12 +0100
Subject: serial: sh-sci: Simplify baud rate calculation algorithms
Rewrite the baud rate register value calculations in easier to read
forms. The computed value isn't modified.
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
(cherry picked from commit 6557b1f69ea0961efde7ab33bfe0cb7e3bfed54e)
(Queued by Simon Horman for v3.14 but not yet in Linus's tree)
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
---
drivers/tty/serial/sh-sci.c | 8 ++++----
include/linux/serial_sci.h | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 80a91038c821..94e878cacd50 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1818,13 +1818,13 @@ static unsigned int sci_scbrr_calc(unsigned int algo_id, unsigned int bps,
{
switch (algo_id) {
case SCBRR_ALGO_1:
- return ((freq + 16 * bps) / (16 * bps) - 1);
+ return freq / (16 * bps);
case SCBRR_ALGO_2:
- return ((freq + 16 * bps) / (32 * bps) - 1);
+ return DIV_ROUND_CLOSEST(freq, 32 * bps) - 1;
case SCBRR_ALGO_3:
- return (((freq * 2) + 16 * bps) / (16 * bps) - 1);
+ return freq / (8 * bps);
case SCBRR_ALGO_4:
- return (((freq * 2) + 16 * bps) / (32 * bps) - 1);
+ return DIV_ROUND_CLOSEST(freq, 16 * bps) - 1;
}
/* Warn, but use a safe default */
diff --git a/include/linux/serial_sci.h b/include/linux/serial_sci.h
index 803068d764fb..eb787d40df02 100644
--- a/include/linux/serial_sci.h
+++ b/include/linux/serial_sci.h
@@ -11,10 +11,10 @@
#define SCIx_NOT_SUPPORTED (-1)
enum {
- SCBRR_ALGO_1, /* ((clk + 16 * bps) / (16 * bps) - 1) */
- SCBRR_ALGO_2, /* ((clk + 16 * bps) / (32 * bps) - 1) */
- SCBRR_ALGO_3, /* (((clk * 2) + 16 * bps) / (16 * bps) - 1) */
- SCBRR_ALGO_4, /* (((clk * 2) + 16 * bps) / (32 * bps) - 1) */
+ SCBRR_ALGO_1, /* clk / (16 * bps) */
+ SCBRR_ALGO_2, /* DIV_ROUND_CLOSEST(clk, 32 * bps) - 1 */
+ SCBRR_ALGO_3, /* clk / (8 * bps) */
+ SCBRR_ALGO_4, /* DIV_ROUND_CLOSEST(clk, 16 * bps) - 1 */
SCBRR_ALGO_6, /* HSCIF variable sample rate algorithm */
};
--
1.8.5.rc3