From patchwork Mon Mar 5 11:47:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 130633 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp2588780lja; Mon, 5 Mar 2018 03:47:56 -0800 (PST) X-Google-Smtp-Source: AG47ELswbDVVR19sjbPj9X2L99pC7wxzaURxSTWaZkdT5kykUmHNCGmVg9kk1bucn7h6A5E21pui X-Received: by 2002:a17:902:b7c2:: with SMTP id v2-v6mr12754466plz.351.1520250476620; Mon, 05 Mar 2018 03:47:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520250476; cv=none; d=google.com; s=arc-20160816; b=Dbk1cHD8EMUK8WjC3MvZii1FCIkB95CqQCLBYqvKEjglcr6v4RgV/sUUM7mxNQr+6x OtoyU7JGJNZSxvDASxJuCV7x/Q9+3lmyNYaBqVfS64YgdTh9QCykPgiPDMA08kJDe+te vAs6k3Ririm5j9KMvrQ2WW79QhMIx6oFcQnfbrW1Z01dve9QlMfxv/BytFndG4NgpX+V iXzcfdCUVDYLW26qABDkILfSxKSYskZXId/d3dhDthyyP9yNpqSYbAZmN9krUbrLfsop 41jUJs/GgQrWPRb+NmbFaNRjlhoANLqbsKJO3nNotNWHg2gXdG9VyzBu9K63BVkd3h6j ysZA== 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=NWRsLqpeZRdtyNLAxeWNHD8VUmF8OMfSciHW0fRU7sk=; b=tr+yRIZMkJpLpi5H9CXjyb688Azfb3zxIWKOSaPp+dvYoUo5nI442/tYg8gWvnzINS pgm3awriWu+crb8A7MsSm9t3vGBYWVtSirK3CGzsaMzIj90LTES4q8sttTzqN5eTRTDp ThLug97MliTzTUdokgfCYWAalEosGlwjDxfnBlJFUzwcce5mMp9aR5lbq0quV+yP1NBQ zWqn0v6BuQjs2RpF9UDTvgPUYBJDthQIB0oa7NJ1ish43TFFJwrXhCo9jB3vrWWr3sju N+Ke2L3kn0+bnfxSBlcBtC3iC3Gjtwxs2axGGDJsFP34CKJ5R4+QEDLy0AscRdYfn4oJ yU7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=cdY1jjIL; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 e22si8334936pgn.59.2018.03.05.03.47.56; Mon, 05 Mar 2018 03:47:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=cdY1jjIL; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933154AbeCELry (ORCPT + 6 others); Mon, 5 Mar 2018 06:47:54 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:42487 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934228AbeCELrt (ORCPT ); Mon, 5 Mar 2018 06:47:49 -0500 Received: by mail-pf0-f196.google.com with SMTP id a16so7067300pfn.9; Mon, 05 Mar 2018 03:47:49 -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=w2OfT6ianlLRS45nKg85TEKWjHDq9u2CufUjvo6pX/g=; b=cdY1jjILyQ0FieQD/poXHmJHoR3yc6WQYcEBnIWYSXhTidC2gnyR7PoJH9dXvzFp83 eKtXz9IYKQv3b9n8S5QcbOvhMR5b06GRjktG7Z4OgrRd4U5sFaEmui3Tuf4/NRAyF2pF njDPJrRxc6SVjsCYV/eq029G2t/GADgVTs7NgZY+PUF0DHXzcXodj6HlVi/oGajADHch vl13UMlOPgug4f4t2CjgRvRq7Zy84hl4yYQRj+gUViGrjpaWi5tCSIfTdI+lzcuL2mFQ hNuzGl+t6adGggR07wplpuM/YLy236UaSixWCWToc+nEj3tR8oerMAYzcMAzLwHmwKay Yttg== 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=w2OfT6ianlLRS45nKg85TEKWjHDq9u2CufUjvo6pX/g=; b=ProAtx4ney79gYkAiedua5yL1AfGrNBAxxrwMppoMcllxk/BqCzZI5rMwK6sQ0p8Hp 286p8Q3ji6aHmeSQ638k4WDelXs2mIN2zA2azwOsbFIQegeygkR2W9oPXqCH+fuq1buX y0r9ADwPXve0l3GHY88Paaw2Xf4gzdpswhgpadn7ECTslKD55zD64+1K3Kc4zNdJyMyt zS3bdjV4QPjfRpWqB0WkKmQAqC4C6udsvk934PZn4wMwyubhbjuXsmXL+pS7X5ggZf0W TjIE1iBtqQlARF+b+RYPNDKS5MapKHleYBJ7GkE6uB85jwAUeIKkyjQXX0UD9CrDBVWs 7w9w== X-Gm-Message-State: APf1xPD0EBmUvuPc4eJRiJE05UJZEXfymsn7Q/8tIJlG2YRWCm7C18XG SppBiom2ffO0+ddXOgjlZIn7XM2b X-Received: by 10.99.113.94 with SMTP id b30mr12022998pgn.228.1520250468219; Mon, 05 Mar 2018 03:47:48 -0800 (PST) Received: from aurora.jms.id.au ([45.124.203.19]) by smtp.gmail.com with ESMTPSA id u9sm19910129pgb.11.2018.03.05.03.47.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Mar 2018 03:47:47 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Mon, 05 Mar 2018 22:17:40 +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 v2] serial: 8250: Add Nuvoton NPCM UART Date: Mon, 5 Mar 2018 22:17:38 +1030 Message-Id: <20180305114738.10276-1-joel@jms.id.au> X-Mailer: git-send-email 2.15.1 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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. Reviewed-by: Rob Herring Signed-off-by: Joel Stanley --- v2: Remove redundant whitespace Use port number 40 to fill in a gap v3: Remove some whitespace in serial_reg.h Move UART_NPCM_TOR and UART_NPCM_TOIE out of userspace header Add Rob's review --- Documentation/devicetree/bindings/serial/8250.txt | 1 + drivers/tty/serial/8250/8250_of.c | 1 + drivers/tty/serial/8250/8250_port.c | 33 +++++++++++++++++++++++ include/uapi/linux/serial_core.h | 3 +++ 4 files changed, 38 insertions(+) -- 2.15.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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..804c1af6fd33 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -47,6 +47,10 @@ #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 */ @@ -2140,6 +2153,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 +2484,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 +2513,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..dce5f9dae121 100644 --- a/include/uapi/linux/serial_core.h +++ b/include/uapi/linux/serial_core.h @@ -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