Received: by 10.223.185.116 with SMTP id b49csp1807666wrg; Sun, 11 Feb 2018 22:01:32 -0800 (PST) X-Google-Smtp-Source: AH8x226xfYkwWwzx6DO8jJSuirWxwjAjzPu3VVLqezTO07osUktF6gGaT+MQHJz8cD3TiU1S0my8 X-Received: by 10.98.130.193 with SMTP id w184mr10604535pfd.111.1518415292877; Sun, 11 Feb 2018 22:01:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518415292; cv=none; d=google.com; s=arc-20160816; b=ZYB70uuMuZXtGv2ui1hBsvKEQ41v4P6YZMRJKf0NfBPT3fvxgKmTA9km7smw9qqncq bdJ/gLS1K2H8HNmE772zLDsmvawl9+fWsOKroZDiAkmihssW67hRinjZAbrXlVCp/EFb WNCAs5vVdaBSKcZ5pKXX7dcS+78CW/FUf4zrZyS6s9dEgvEVVLjGyfFMkUGuKXMj9vLx GrPff6dT4t2zKM44r/FL+TH5UTgajTAYvZUOjp2V0yjAkX43xj8Eqy8o+KDMDgiu4p1d Naw7O2HbgzuVO6aWwVJBhCUQ66XeX7f5O3ildP7Cv8X4n1bI4H89rId/zgfaoVJKViEN H0zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=9tquttOhN9Wnn5laSmxTsLDW1LjC/y6+M+Z5Tri/0Bo=; b=w4pIMNFgOmgED8tdpPtAOLwJ6NCGE7ZEUmaFNGc921hKogmDVD0lbXQSQavTEn2ubw DrYLUACVvqwFBvNUr95V0v5ntKjOapuLNM8Y8noxPynFMLoR3QQr+O8YDQ+xfy58P+3u 9Ck517NTWawp5nJTbf56HBBVkCGuW2Z1oFs8fIYGTTfLZpDsHadONOC52dBO0cg3t5T4 MaLBUxupf26MwdAkkF3srmV7vydpPC/hz1WztQb1OdEAOBOVvSGEUK10Ok2LsNIi6xgs xAPa0SUwHoHML3m4jtY8z25Al/yVmN0EaH1ZSIx8tynF6ZuYnsXiUHv7cvOU1ZtLCl3d n6Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=hgveibjE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g6-v6si5509418pln.755.2018.02.11.22.01.18; Sun, 11 Feb 2018 22:01:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=hgveibjE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932612AbeBLEs2 (ORCPT + 99 others); Sun, 11 Feb 2018 23:48:28 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:41006 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932433AbeBLEs0 (ORCPT ); Sun, 11 Feb 2018 23:48:26 -0500 Received: by mail-pg0-f65.google.com with SMTP id t4so5730717pgp.8; Sun, 11 Feb 2018 20:48:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=9tquttOhN9Wnn5laSmxTsLDW1LjC/y6+M+Z5Tri/0Bo=; b=hgveibjE5Yn50CGoeGRUkL+TGWUgPH1y5bq1OYNIc8MZjeizYtvSyFCY+nmiV1mqNz 1scvIPVwvKYjL/CsqSU/N8v3rajTu1DlWdAIs13m5lUUi8IU7S0TKSC7rEDk3TNc+B9Z 6DVMrUDFFMrERueLTKBC44+PR0+zEPVf9vAz5FK0kE0qHKlwM4Z0XVEcJ6liOmUUwKV0 olOVAcOyFX2ma27HGn+x3P1CNa2iaKMeN4v4QkfD/vktFJatsO5oJ92EJE1f9xstKyfz EsAfR0BPp0rqNIt9o5Un58sFaJ/cZRYkp9WvbcaaWCdsJprzPO/CiHDMQDEJQ3dOHw13 rytA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=9tquttOhN9Wnn5laSmxTsLDW1LjC/y6+M+Z5Tri/0Bo=; b=ex/hd3BH3klOzzVSlbdtcdnb+hs4vFpyBa3Gqg3WtGODydxRKFc53hThq2b7OiWRRD ggt7fcx09TUXmHSTP1chusb/ENz3wx+ms3H7Dja3EHbY5gAmH3o/DV0ciPzfpHgY/Myt FVthJZsN6SbjmpN1s3hvjll8NhXeDyeqGUePGbPlPnfdr8pYSXwqtMhDPDAJ2wmUq5L6 82/5H0xQUseWy+7ZkfUka08cxOmen0uugVR50bL64+TIc53b0bQ6C1tiZCs3YY7in6B8 POSXG9cMWBE3W7XubIGJNe6fmCGuLsAXOwjwqxuQsxgXmOtHT1qvHzPy3FkAFRY0JGqN ahHw== X-Gm-Message-State: APf1xPCCUEsz6M5yX/+r6iAYet82GGRDFOc5XXwDb5x7iIjEptJUU8iT uCh+u3U+eWohth1TuWVq0097puiI X-Received: by 10.99.113.75 with SMTP id b11mr8673750pgn.271.1518410905016; Sun, 11 Feb 2018 20:48:25 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id a19sm26272862pfh.170.2018.02.11.20.48.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 11 Feb 2018 20:48:24 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Mon, 12 Feb 2018 15:18:16 +1030 From: Joel Stanley To: Greg Kroah-Hartman , Rob Herring , Mark Rutland Cc: linux-serial@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Tomer Maimon , Avi Fishman , Jeremy Kerr Subject: [PATCH] serial: 8250: Add Nuvoton NPCM UART Date: Mon, 12 Feb 2018 15:18:10 +1030 Message-Id: <20180212044810.23547-1-joel@jms.id.au> X-Mailer: git-send-email 2.15.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Joel Stanley --- Documentation/devicetree/bindings/serial/8250.txt | 1 + drivers/tty/serial/8250/8250_of.c | 1 + drivers/tty/serial/8250/8250_port.c | 30 +++++++++++++++++++++++ include/uapi/linux/serial_core.h | 3 +++ include/uapi/linux/serial_reg.h | 5 ++++ 5 files changed, 40 insertions(+) diff --git a/Documentation/devicetree/bindings/serial/8250.txt b/Documentation/devicetree/bindings/serial/8250.txt index dad3b2ec66d4..aeb6db4e35c3 100644 --- a/Documentation/devicetree/bindings/serial/8250.txt +++ b/Documentation/devicetree/bindings/serial/8250.txt @@ -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. diff --git a/drivers/tty/serial/8250/8250_of.c b/drivers/tty/serial/8250/8250_of.c index 160b8906d9b9..9835b1c1cbe1 100644 --- a/drivers/tty/serial/8250/8250_of.c +++ b/drivers/tty/serial/8250/8250_of.c @@ -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); diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 1328c7e70108..c2e7fc111338 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -293,6 +293,16 @@ 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 */ @@ -2140,6 +2150,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 @@ -2462,6 +2481,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) @@ -2482,6 +2510,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); diff --git a/include/uapi/linux/serial_core.h b/include/uapi/linux/serial_core.h index 1c8413f93e3d..3890ca4c5985 100644 --- a/include/uapi/linux/serial_core.h +++ b/include/uapi/linux/serial_core.h @@ -278,4 +278,7 @@ /* MediaTek BTIF */ #define PORT_MTK_BTIF 117 +/* Nuvoton UART */ +#define PORT_NPCM 118 + #endif /* _UAPILINUX_SERIAL_CORE_H */ diff --git a/include/uapi/linux/serial_reg.h b/include/uapi/linux/serial_reg.h index be07b5470f4b..f82f3c869df9 100644 --- a/include/uapi/linux/serial_reg.h +++ b/include/uapi/linux/serial_reg.h @@ -376,5 +376,10 @@ #define UART_ALTR_EN_TXFIFO_LW 0x01 /* Enable the TX FIFO Low Watermark */ #define UART_ALTR_TX_LOW 0x41 /* Tx FIFO Low Watermark */ + +/* Nuvoton NPCM timeout register */ +#define UART_NPCM_TOR 7 +#define UART_NPCM_TOIE BIT(7) /* Timeout Interrupt Enable */ + #endif /* _LINUX_SERIAL_REG_H */ -- 2.15.1