[PATCH] atmel_serial: Fix roundoff error in atmel_console_get_options
[firefly-linux-kernel-4.4.55.git] / drivers / serial / atmel_serial.c
index 34212df3980013c7013dcd33dcd78ddfefb8c336..955c46da580041de800d8ced1cc5c23af2b60dda 100644 (file)
 #include <asm/arch/at91rm9200_pdc.h>
 #include <asm/mach/serial_at91.h>
 #include <asm/arch/board.h>
+#ifdef CONFIG_ARM
 #include <asm/arch/system.h>
 #include <asm/arch/gpio.h>
+#endif
 
 #include "atmel_serial.h"
 
@@ -135,6 +137,7 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl)
        unsigned int control = 0;
        unsigned int mode;
 
+#ifdef CONFIG_ARM
        if (arch_identify() == ARCH_ID_AT91RM9200) {
                /*
                 * AT91RM9200 Errata #39: RTS0 is not internally connected to PA21.
@@ -147,6 +150,7 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl)
                                at91_set_gpio_value(AT91_PIN_PA21, 1);
                }
        }
+#endif
 
        if (mctrl & TIOCM_RTS)
                control |= ATMEL_US_RTSEN;
@@ -789,8 +793,14 @@ static void __init atmel_console_get_options(struct uart_port *port, int *baud,
        else if (mr == ATMEL_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 atmel_console_setup(struct console *co, char *options)