From patchwork Fri Jan 25 14:13:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Murzin X-Patchwork-Id: 10781473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01F751515 for ; Fri, 25 Jan 2019 14:14:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1DC42E5CF for ; Fri, 25 Jan 2019 14:14:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D66332E656; Fri, 25 Jan 2019 14:14:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4D4AC2E5CF for ; Fri, 25 Jan 2019 14:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=TP4+nGybiwmq4NvVGw7/J50lQuPw8etOFB2djpIwPEg=; b=nN2LYKHQ07KKZWfJ2F/i9MIpNo X0EKv+/U+zDWMTrtMFK0dnN4VdvIHgABNtmqhithM6E9cMnetlZo2eoHjzuDa6hu0j9wToeh42xcC /uyFY+YsejL9TNA24WSAhP4NDxU8Q4NuyJBCXbh6AQYep9/rHeiIESJd8eygMCcthLyg8ZLb9pKys 2Bsnr4LyOaNCWk8z283CldYGhBE2nvLMPYI/M1qNCFC2kvBhW4fduzHuTfifZWbe1Y82b2EDFJDRG 8bfqMA5GMGCLBDHzfQR9sOsiexbr96jHXFdbsi2CNLd/DoMK0HU553LqhMnB2ZbwEGAmOvsxEMU02 cT9iEh2A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gn2Fp-00023M-9I; Fri, 25 Jan 2019 14:14:45 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gn2FM-0001YX-Ps for linux-arm-kernel@lists.infradead.org; Fri, 25 Jan 2019 14:14:22 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9353DEBD; Fri, 25 Jan 2019 06:14:11 -0800 (PST) Received: from login2.euhpc.arm.com (login2.euhpc.arm.com [10.6.27.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CB8E63F589; Fri, 25 Jan 2019 06:14:10 -0800 (PST) From: Vladimir Murzin To: linux-serial@vger.kernel.org Subject: [PATCH 1/2] serial: mps2-uart: move to dynamic port allocation Date: Fri, 25 Jan 2019 14:13:16 +0000 Message-Id: <1548425597-38175-2-git-send-email-vladimir.murzin@arm.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1548425597-38175-1-git-send-email-vladimir.murzin@arm.com> References: <1548425597-38175-1-git-send-email-vladimir.murzin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190125_061417_179780_72A70D8C X-CRM114-Status: GOOD ( 15.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, sudeep.holla@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Some designs, like MPS3, expose number of virtual serial ports which already close or exceeds MPS2_MAX_PORTS. Increasing MPS2_MAX_PORTS would have negative impact (in terms of memory consumption) on tiny MPS2 platform which, in fact, has only one physically populated UART. Start with converting existent static port array to idr. As a bonus it make driver not to fail in case when no alias was specified in device tree. Signed-off-by: Vladimir Murzin --- drivers/tty/serial/mps2-uart.c | 47 ++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/drivers/tty/serial/mps2-uart.c b/drivers/tty/serial/mps2-uart.c index 9f8f637..6da0633 100644 --- a/drivers/tty/serial/mps2-uart.c +++ b/drivers/tty/serial/mps2-uart.c @@ -22,6 +22,7 @@ #include #include #include +#include #define SERIAL_NAME "ttyMPS" #define DRIVER_NAME "mps2-uart" @@ -397,7 +398,7 @@ static const struct uart_ops mps2_uart_pops = { .verify_port = mps2_uart_verify_port, }; -static struct mps2_uart_port mps2_uart_ports[MPS2_MAX_PORTS]; +static DEFINE_IDR(ports_idr); #ifdef CONFIG_SERIAL_MPS2_UART_CONSOLE static void mps2_uart_console_putchar(struct uart_port *port, int ch) @@ -410,7 +411,8 @@ static void mps2_uart_console_putchar(struct uart_port *port, int ch) static void mps2_uart_console_write(struct console *co, const char *s, unsigned int cnt) { - struct uart_port *port = &mps2_uart_ports[co->index].port; + struct mps2_uart_port *mps_port = idr_find(&ports_idr, co->index); + struct uart_port *port = &mps_port->port; uart_console_write(port, s, cnt, mps2_uart_console_putchar); } @@ -426,7 +428,10 @@ static int mps2_uart_console_setup(struct console *co, char *options) if (co->index < 0 || co->index >= MPS2_MAX_PORTS) return -ENODEV; - mps_port = &mps2_uart_ports[co->index]; + mps_port = idr_find(&ports_idr, co->index); + + if (!mps_port) + return -ENODEV; if (options) uart_parse_options(options, &baud, &parity, &bits, &flow); @@ -487,27 +492,32 @@ static struct uart_driver mps2_uart_driver = { .cons = MPS2_SERIAL_CONSOLE, }; -static struct mps2_uart_port *mps2_of_get_port(struct platform_device *pdev) +static int mps2_of_get_port(struct platform_device *pdev, + struct mps2_uart_port *mps_port) { struct device_node *np = pdev->dev.of_node; int id; if (!np) - return NULL; + return -ENODEV; id = of_alias_get_id(np, "serial"); + + if (id < 0) + id = idr_alloc_cyclic(&ports_idr, (void *)mps_port, 0, MPS2_MAX_PORTS, GFP_KERNEL); + else + id = idr_alloc(&ports_idr, (void *)mps_port, id, MPS2_MAX_PORTS, GFP_KERNEL); + if (id < 0) - id = 0; + return id; - if (WARN_ON(id >= MPS2_MAX_PORTS)) - return NULL; + mps_port->port.line = id; - mps2_uart_ports[id].port.line = id; - return &mps2_uart_ports[id]; + return 0; } -static int mps2_init_port(struct mps2_uart_port *mps_port, - struct platform_device *pdev) +static int mps2_init_port(struct platform_device *pdev, + struct mps2_uart_port *mps_port) { struct resource *res; int ret; @@ -550,11 +560,16 @@ static int mps2_serial_probe(struct platform_device *pdev) struct mps2_uart_port *mps_port; int ret; - mps_port = mps2_of_get_port(pdev); - if (!mps_port) - return -ENODEV; + mps_port = devm_kzalloc(&pdev->dev, sizeof(struct mps2_uart_port), GFP_KERNEL); + + if (!mps_port) + return -ENOMEM; + + ret = mps2_of_get_port(pdev, mps_port); + if (ret) + return ret; - ret = mps2_init_port(mps_port, pdev); + ret = mps2_init_port(pdev, mps_port); if (ret) return ret; From patchwork Fri Jan 25 14:13:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Murzin X-Patchwork-Id: 10781471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 43F5A1515 for ; Fri, 25 Jan 2019 14:14:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 305372E611 for ; Fri, 25 Jan 2019 14:14:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 243EE2E65F; Fri, 25 Jan 2019 14:14:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9DC342E611 for ; Fri, 25 Jan 2019 14:14:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=2apXxHi2LADZSMZLB+ILp8ZYQT6wAAs18Mjb56swRbg=; b=Zs+BmmwfPe38I06jKT0uRiC/zI jGaOH/30mrM09Pfjm1C9wHhuICMWKGlJMwt76+d9PcuCp25Cyfolkj2VW1dRL5PoCBBfBBdlUJPtW jijFv0egfCLbAx2iABSMdztKaZWLpFZ9NcsEauh4l2f0sYXpotkux5KCbQr+BMsIU00HbXGcHvJUI JG7RKNdwm2u54E5vIqKa/2MrAtni+XXEe2ObAOzVfOIzVjXClGbjbN+907WobPrEgBypHgBnybwL9 isdr/e4VuRl+6o45yDVUdM39UH/qIHjgtG3dvOkpKgV5GIgrMS5t3OlRv7A3ljUHS6VOpM/w5+vPG te2HUvIg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gn2Fd-0001pj-18; Fri, 25 Jan 2019 14:14:33 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gn2FJ-0001Yo-WA for linux-arm-kernel@lists.infradead.org; Fri, 25 Jan 2019 14:14:15 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A11C51650; Fri, 25 Jan 2019 06:14:12 -0800 (PST) Received: from login2.euhpc.arm.com (login2.euhpc.arm.com [10.6.27.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D01893F589; Fri, 25 Jan 2019 06:14:11 -0800 (PST) From: Vladimir Murzin To: linux-serial@vger.kernel.org Subject: [PATCH 2/2] serial: mps2-uart: support combined tx and rx irq Date: Fri, 25 Jan 2019 14:13:17 +0000 Message-Id: <1548425597-38175-3-git-send-email-vladimir.murzin@arm.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1548425597-38175-1-git-send-email-vladimir.murzin@arm.com> References: <1548425597-38175-1-git-send-email-vladimir.murzin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190125_061414_045349_8310FAA7 X-CRM114-Status: GOOD ( 15.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, sudeep.holla@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP It turns out that some designs went for implementing only combined tx and rx interrupt, which is currently not supported by the driver. Support of combined irq is built on top of existent irq handlers and activated by the hint form device tree. Signed-off-by: Vladimir Murzin --- drivers/tty/serial/mps2-uart.c | 89 ++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 25 deletions(-) diff --git a/drivers/tty/serial/mps2-uart.c b/drivers/tty/serial/mps2-uart.c index 6da0633..e5fe764 100644 --- a/drivers/tty/serial/mps2-uart.c +++ b/drivers/tty/serial/mps2-uart.c @@ -66,11 +66,17 @@ #define MPS2_MAX_PORTS 3 +#define UART_PORT_COMBINED_IRQS BIT(0) + struct mps2_uart_port { struct uart_port port; struct clk *clk; - unsigned int tx_irq; + union { + unsigned int combined_irq; + unsigned int tx_irq; + }; unsigned int rx_irq; + unsigned int flags; }; static inline struct mps2_uart_port *to_mps2_port(struct uart_port *port) @@ -232,6 +238,17 @@ static irqreturn_t mps2_uart_txirq(int irq, void *data) return IRQ_HANDLED; } +static irqreturn_t mps2_uart_combinedirq(int irq, void *data) +{ + if (mps2_uart_rxirq(irq, data) == IRQ_HANDLED) + return IRQ_HANDLED; + + if (mps2_uart_txirq(irq, data) == IRQ_HANDLED) + return IRQ_HANDLED; + + return IRQ_NONE; +} + static irqreturn_t mps2_uart_oerrirq(int irq, void *data) { irqreturn_t handled = IRQ_NONE; @@ -275,26 +292,35 @@ static int mps2_uart_startup(struct uart_port *port) mps2_uart_write8(port, control, UARTn_CTRL); - ret = request_irq(mps_port->rx_irq, mps2_uart_rxirq, 0, - MAKE_NAME(-rx), mps_port); - if (ret) { - dev_err(port->dev, "failed to register rxirq (%d)\n", ret); - return ret; - } - - ret = request_irq(mps_port->tx_irq, mps2_uart_txirq, 0, - MAKE_NAME(-tx), mps_port); - if (ret) { - dev_err(port->dev, "failed to register txirq (%d)\n", ret); - goto err_free_rxirq; - } - ret = request_irq(port->irq, mps2_uart_oerrirq, IRQF_SHARED, MAKE_NAME(-overrun), mps_port); if (ret) { dev_err(port->dev, "failed to register oerrirq (%d)\n", ret); - goto err_free_txirq; + return ret; + } + + if (mps_port->flags & UART_PORT_COMBINED_IRQS) { + ret = request_irq(mps_port->combined_irq, mps2_uart_combinedirq, 0, + MAKE_NAME(-combined), mps_port); + if (ret) { + dev_err(port->dev, "failed to register combinedirq (%d)\n", ret); + goto err_free_oerrirq; + } + } else { + ret = request_irq(mps_port->rx_irq, mps2_uart_rxirq, 0, + MAKE_NAME(-rx), mps_port); + if (ret) { + dev_err(port->dev, "failed to register rxirq (%d)\n", ret); + goto err_free_oerrirq; + } + + ret = request_irq(mps_port->tx_irq, mps2_uart_txirq, 0, + MAKE_NAME(-tx), mps_port); + if (ret) { + dev_err(port->dev, "failed to register txirq (%d)\n", ret); + goto err_free_rxirq; + } } control |= UARTn_CTRL_RX_GRP | UARTn_CTRL_TX_GRP; @@ -303,10 +329,10 @@ static int mps2_uart_startup(struct uart_port *port) return 0; -err_free_txirq: - free_irq(mps_port->tx_irq, mps_port); err_free_rxirq: free_irq(mps_port->rx_irq, mps_port); +err_free_oerrirq: + free_irq(port->irq, mps_port); return ret; } @@ -320,8 +346,13 @@ static void mps2_uart_shutdown(struct uart_port *port) mps2_uart_write8(port, control, UARTn_CTRL); - free_irq(mps_port->rx_irq, mps_port); - free_irq(mps_port->tx_irq, mps_port); + if (mps_port->flags & UART_PORT_COMBINED_IRQS) { + free_irq(mps_port->combined_irq, mps_port); + } else { + free_irq(mps_port->rx_irq, mps_port); + free_irq(mps_port->tx_irq, mps_port); + } + free_irq(port->irq, mps_port); } @@ -511,6 +542,9 @@ static int mps2_of_get_port(struct platform_device *pdev, if (id < 0) return id; + if (of_property_read_bool(np, "arm,mps2-combined-irq-only")) + mps_port->flags |= UART_PORT_COMBINED_IRQS; + mps_port->port.line = id; return 0; @@ -529,11 +563,6 @@ static int mps2_init_port(struct platform_device *pdev, mps_port->port.mapbase = res->start; mps_port->port.mapsize = resource_size(res); - - mps_port->rx_irq = platform_get_irq(pdev, 0); - mps_port->tx_irq = platform_get_irq(pdev, 1); - mps_port->port.irq = platform_get_irq(pdev, 2); - mps_port->port.iotype = UPIO_MEM; mps_port->port.flags = UPF_BOOT_AUTOCONF; mps_port->port.fifosize = 1; @@ -552,6 +581,16 @@ static int mps2_init_port(struct platform_device *pdev, clk_disable_unprepare(mps_port->clk); + + if (mps_port->flags & UART_PORT_COMBINED_IRQS) { + mps_port->combined_irq = platform_get_irq(pdev, 0); + mps_port->port.irq = platform_get_irq(pdev, 1); + } else { + mps_port->rx_irq = platform_get_irq(pdev, 0); + mps_port->tx_irq = platform_get_irq(pdev, 1); + mps_port->port.irq = platform_get_irq(pdev, 2); + } + return ret; }