Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752191AbdF3MFa (ORCPT ); Fri, 30 Jun 2017 08:05:30 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:37585 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752040AbdF3MFX (ORCPT ); Fri, 30 Jun 2017 08:05:23 -0400 From: Romain Perier To: Greg Kroah-Hartman Cc: linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Nandor Han , Romain Perier Subject: [PATCH 7/7] serial: imx: Fix imx_shutdown procedure Date: Fri, 30 Jun 2017 14:04:46 +0200 Message-Id: <20170630120446.13994-8-romain.perier@collabora.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170630120446.13994-1-romain.perier@collabora.com> References: <20170630120446.13994-1-romain.perier@collabora.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2713 Lines: 88 From: Nandor Han In some cases, It looks that interrupts can happen after the dma was disabled and port was not yet shutdown. This will result in interrupts handled by imx_rxint. This commits updates the shutdown function to ensure that underlying components are disabled in the right order. This disables RX and TX blocks, then it disabled interrupts. In case DMA is enabled, it disables DMA and free corresponding resources. It disables UART port and stop clocks. Signed-off-by: Nandor Han Signed-off-by: Romain Perier --- drivers/tty/serial/imx.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index d5b6e09..7dc6f0c 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -1404,44 +1404,44 @@ static void imx_shutdown(struct uart_port *port) unsigned long temp; unsigned long flags; - if (sport->dma_is_enabled) { - sport->dma_is_rxing = 0; - sport->dma_is_txing = 0; - dmaengine_terminate_sync(sport->dma_chan_tx); - dmaengine_terminate_sync(sport->dma_chan_rx); - + if (!sport->port.suspended) { spin_lock_irqsave(&sport->port.lock, flags); imx_stop_tx(port); imx_stop_rx(port); - imx_disable_dma(sport); spin_unlock_irqrestore(&sport->port.lock, flags); - imx_uart_dma_exit(sport); } - mctrl_gpio_disable_ms(sport->gpios); + if (sport->dma_is_inited) { + if (sport->dma_is_enabled) { + spin_lock_irqsave(&sport->port.lock, flags); + imx_disable_dma(sport); + spin_unlock_irqrestore(&sport->port.lock, flags); + } + imx_uart_dma_exit(sport); + } spin_lock_irqsave(&sport->port.lock, flags); temp = readl(sport->port.membase + UCR2); - temp &= ~(UCR2_TXEN); + temp &= ~(UCR2_TXEN | UCR2_RXEN); writel(temp, sport->port.membase + UCR2); + temp = readl(sport->port.membase + UCR4); + temp &= ~UCR4_OREN; + writel(temp, sport->port.membase + UCR4); spin_unlock_irqrestore(&sport->port.lock, flags); - /* - * Stop our timer. - */ - del_timer_sync(&sport->timer); + mctrl_gpio_disable_ms(sport->gpios); - /* - * Disable all interrupts, port and break condition. - */ + /* Stop our timer. */ + del_timer_sync(&sport->timer); + /* Disable port. */ spin_lock_irqsave(&sport->port.lock, flags); temp = readl(sport->port.membase + UCR1); - temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); - + temp &= ~UCR1_UARTEN; writel(temp, sport->port.membase + UCR1); spin_unlock_irqrestore(&sport->port.lock, flags); + /* Disable clocks. */ clk_disable_unprepare(sport->clk_per); clk_disable_unprepare(sport->clk_ipg); } -- 1.8.3.1