serial: 8250: Add Nuvoton NPCM UART
authorJoel Stanley <joel@jms.id.au>
Mon, 5 Mar 2018 11:47:38 +0000 (22:17 +1030)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 9 Mar 2018 19:01:19 +0000 (11:01 -0800)
The Nuvoton UART is almost compatible with the 8250 driver when probed
via the 8250_of driver, however it requires some extra configuration
at startup.

Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Documentation/devicetree/bindings/serial/8250.txt
drivers/tty/serial/8250/8250_of.c
drivers/tty/serial/8250/8250_port.c
include/uapi/linux/serial_core.h

index dad3b2ec66d45e8b8af037b2ef61b3770bec1256..aeb6db4e35c3bb816d41da1345f35eed1b83b09c 100644 (file)
@@ -24,6 +24,7 @@ Required properties:
        - "ti,da830-uart"
        - "aspeed,ast2400-vuart"
        - "aspeed,ast2500-vuart"
+       - "nuvoton,npcm750-uart"
        - "serial" if the port type is unknown.
 - reg : offset and length of the register set for the device.
 - interrupts : should contain uart interrupt.
index 160b8906d9b9cbb47e7f5459b23c604778e5eff5..9835b1c1cbe103516061af7b62291a28d38c714b 100644 (file)
@@ -316,6 +316,7 @@ static const struct of_device_id of_platform_serial_table[] = {
        { .compatible = "mrvl,mmp-uart",
                .data = (void *)PORT_XSCALE, },
        { .compatible = "ti,da830-uart", .data = (void *)PORT_DA830, },
+       { .compatible = "nuvoton,npcm750-uart", .data = (void *)PORT_NPCM, },
        { /* end of list */ },
 };
 MODULE_DEVICE_TABLE(of, of_platform_serial_table);
index ffbb955d1c06253f4195afc96e3e460d6c41227f..95833cbc4338eca2c82c645aabd67b52c44774cf 100644 (file)
 #define UART_EXAR_SLEEP                0x8b    /* Sleep mode */
 #define UART_EXAR_DVID         0x8d    /* Device identification */
 
+/* Nuvoton NPCM timeout register */
+#define UART_NPCM_TOR          7
+#define UART_NPCM_TOIE         BIT(7)  /* Timeout Interrupt Enable */
+
 /*
  * Debugging.
  */
@@ -293,6 +297,15 @@ static const struct serial8250_config uart_config[] = {
                                  UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
                .flags          = UART_CAP_FIFO,
        },
+       [PORT_NPCM] = {
+               .name           = "Nuvoton 16550",
+               .fifo_size      = 16,
+               .tx_loadsz      = 16,
+               .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 |
+                                 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
+               .rxtrig_bytes   = {1, 4, 8, 14},
+               .flags          = UART_CAP_FIFO,
+       },
 };
 
 /* Uart divisor latch read */
@@ -2141,6 +2154,15 @@ int serial8250_do_startup(struct uart_port *port)
                                UART_DA830_PWREMU_MGMT_FREE);
        }
 
+       if (port->type == PORT_NPCM) {
+               /*
+                * Nuvoton calls the scratch register 'UART_TOR' (timeout
+                * register). Enable it, and set TIOC (timeout interrupt
+                * comparator) to be 0x20 for correct operation.
+                */
+               serial_port_out(port, UART_NPCM_TOR, UART_NPCM_TOIE | 0x20);
+       }
+
 #ifdef CONFIG_SERIAL_8250_RSA
        /*
         * If this is an RSA port, see if we can kick it up to the
@@ -2463,6 +2485,15 @@ static unsigned int xr17v35x_get_divisor(struct uart_8250_port *up,
        return quot_16 >> 4;
 }
 
+/* Nuvoton NPCM UARTs have a custom divisor calculation */
+static unsigned int npcm_get_divisor(struct uart_8250_port *up,
+               unsigned int baud)
+{
+       struct uart_port *port = &up->port;
+
+       return DIV_ROUND_CLOSEST(port->uartclk, 16 * baud + 2) - 2;
+}
+
 static unsigned int serial8250_get_divisor(struct uart_8250_port *up,
                                           unsigned int baud,
                                           unsigned int *frac)
@@ -2483,6 +2514,8 @@ static unsigned int serial8250_get_divisor(struct uart_8250_port *up,
                quot = 0x8002;
        else if (up->port.type == PORT_XR17V35X)
                quot = xr17v35x_get_divisor(up, baud, frac);
+       else if (up->port.type == PORT_NPCM)
+               quot = npcm_get_divisor(up, baud);
        else
                quot = uart_get_divisor(port, baud);
 
index 1c8413f93e3daafc9f138e8a619093ec3fc96cd1..dce5f9dae1210455734e555044749f94d399594e 100644 (file)
@@ -76,6 +76,9 @@
 #define PORT_SUNZILOG  38
 #define PORT_SUNSAB    39
 
+/* Nuvoton UART */
+#define PORT_NPCM      40
+
 /* Intel EG20 */
 #define PORT_PCH_8LINE 44
 #define PORT_PCH_2LINE 45