serial: sh-sci: Simplify baud rate calculation algorithms
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Fri, 6 Dec 2013 09:59:12 +0000 (10:59 +0100)
committerSimon Horman <horms+renesas@verge.net.au>
Tue, 24 Dec 2013 02:17:33 +0000 (11:17 +0900)
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>
drivers/tty/serial/sh-sci.c
include/linux/serial_sci.h

index eb59bb235a52d1316f0f72c3001e5a63cd458edf..f2fad4d8eb9e8bc873eefe4964b8d0c8015a9564 100644 (file)
@@ -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 */
index babc5fe070b91fc8cc1470fe57d311583836c916..12cf50c1c047d458b18b5e67e77f99a5306d9003 100644 (file)
 #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 */
 };