From patchwork Tue May 21 15:45:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erwan Le Ray X-Patchwork-Id: 164735 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1768559ili; Tue, 21 May 2019 08:47:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqziLhhA0HXSAxyYVp2oPoC9rCYk1HlmYbOuxvCMik4o4P80IaIHgWd1pIWMe6bY+PjhOhP3 X-Received: by 2002:a63:c203:: with SMTP id b3mr52666861pgd.398.1558453620885; Tue, 21 May 2019 08:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558453620; cv=none; d=google.com; s=arc-20160816; b=O06T5qgAuSjcIYNEjB02gb3MjmIoAXHbPZOZnoxEnO5wgrbFnqfsDLfdP7v0fvhPlA Uk2PgrVd6AAI2Gexl0K8cTVVHG55sQfPVHj7SP9nUrp78nzwBPQDEwWjw/Kyx9yBFGKq SR3cu3UnPstFn/ZfpxX8tlwZq9Lw9wN4rsmoBVvLz9ddwlcvj+tZrDIign+pWcBEGqnS BohlNqezzW0Q0//6laNJnjMTTKKetpPGzVbiiuPWcKaASn+er/ZIMkqXw1Mb66LngMx5 1L3MHeNHmKw8C+2I/dVs5DN4Xl+FmQv3FV2fjRFD4Us6cCyk0AhpW6wDGpy43Pwk7omk PeQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=xrTHJ0r+41B9UrJgw1m/5JY+7XA7C34gtShA4N4DL9w=; b=ahDiW3bEYk2SN8101YDTsTSMaEsurI/x8i2ioY+0kdiT+rTmEihmbHNcSIc3tEnRQJ UyXZTwAgglpMlsMasALZZqJzDNnp1unhDJ64SiIaEr2GMuWDG2D+jSCb3iF490M6mTDG VXk4XD5o8Kxw0GzRen6wqFFhskOQv5hExhjAPv2DYRMA8LjLjwWa0ZjBhK+VIqqWu8jw 43/c7eTmFDIvWwPXKvOEQpgrM+BB8B3g3UZSI0stS5w9uMKXRUHxldDM0ipv4jOPmX4N v2VaHA3yC7Hu+GIatEMtxCcRnlEXgWE9PhdKT0gv1y8MNC2t8TCE13SEJQclw7/ED/v/ Gj8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b="LD3+dh/2"; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-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 n33si16140232pgl.403.2019.05.21.08.47.00; Tue, 21 May 2019 08:47:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b="LD3+dh/2"; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728882AbfEUPrA (ORCPT + 1 other); Tue, 21 May 2019 11:47:00 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:20724 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728183AbfEUPrA (ORCPT ); Tue, 21 May 2019 11:47:00 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4LFk1Hs004995; Tue, 21 May 2019 17:46:42 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=xrTHJ0r+41B9UrJgw1m/5JY+7XA7C34gtShA4N4DL9w=; b=LD3+dh/2tOz4V3p4dxXNTMik4VHrbynG3K0V2a7YfkJm9RB6f4hEvy083hEsXEKlSwEr MlfKX1Ef4B6lfoFoiIBIN/ZJNThNkEwShD9jTJT2xiScWu0GxAD+4U/oXTl0igBprNXg T7X1iWvWmOt7BQXfi+zMfl7JwyMbp4PGUHhLGyqWGDITLT8knrlsOExjLe/jqP7p95wF KF0nnOJ1Mn0WHkqbEH9ZQGIrZw6XXd2u6VRpoZddqBZRWlBTn0JGulgeXQbsbc4Ye4or Xgt+QhX7CgPX6McyGcXzn98YPjATOmYLTEZcikq+4lQbxsm2WEpIYJr0ww5y54g5Gojn jA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2sj7tu2h74-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 21 May 2019 17:46:42 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A517B38; Tue, 21 May 2019 15:46:41 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas22.st.com [10.75.90.92]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5F4592CEA; Tue, 21 May 2019 15:46:41 +0000 (GMT) Received: from SAFEX1HUBCAS23.st.com (10.75.90.46) by Safex1hubcas22.st.com (10.75.90.92) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 21 May 2019 17:46:41 +0200 Received: from localhost (10.201.23.31) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 21 May 2019 17:46:40 +0200 From: Erwan Le Ray To: Greg Kroah-Hartman , Jiri Slaby , Maxime Coquelin , "Alexandre Torgue" CC: , , , , "Erwan Le Ray" , Fabrice Gasnier Subject: [PATCH 5/7] serial: stm32: Add support of TC bit status check Date: Tue, 21 May 2019 17:45:45 +0200 Message-ID: <1558453547-22866-6-git-send-email-erwan.leray@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1558453547-22866-1-git-send-email-erwan.leray@st.com> References: <1558453547-22866-1-git-send-email-erwan.leray@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.31] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-05-21_03:, , signatures=0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Adds a check on the Transmission Complete bit status before closing the com port. Prevents the port closure before the end of the transmission. TC poll loop is moved from stm32_tx_dma_complete to stm32_shutdown routine, in order to check TC before shutdown in both dma and PIO tx modes. TC clear is added in stm32_transmit_char routine, in order to be cleared before transmitting in both dma and PIO tx modes. Fixes: 3489187204eb ("serial: stm32: adding dma support") Signed-off-by: Erwan Le Ray -- 1.9.1 diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index 2e7757d..d603be9 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -290,21 +290,6 @@ static void stm32_tx_dma_complete(void *arg) struct uart_port *port = arg; struct stm32_port *stm32port = to_stm32_port(port); struct stm32_usart_offsets *ofs = &stm32port->info->ofs; - unsigned int isr; - int ret; - - ret = readl_relaxed_poll_timeout_atomic(port->membase + ofs->isr, - isr, - (isr & USART_SR_TC), - 10, 100000); - - if (ret) - dev_err(port->dev, "terminal count not set\n"); - - if (ofs->icr == UNDEF_REG) - stm32_clr_bits(port, ofs->isr, USART_SR_TC); - else - stm32_set_bits(port, ofs->icr, USART_CR_TC); stm32_clr_bits(port, ofs->cr3, USART_CR3_DMAT); stm32port->tx_dma_busy = false; @@ -396,7 +381,6 @@ static void stm32_transmit_chars_dma(struct uart_port *port) /* Issue pending DMA TX requests */ dma_async_issue_pending(stm32port->tx_ch); - stm32_clr_bits(port, ofs->isr, USART_SR_TC); stm32_set_bits(port, ofs->cr3, USART_CR3_DMAT); xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1); @@ -425,6 +409,11 @@ static void stm32_transmit_chars(struct uart_port *port) return; } + if (ofs->icr == UNDEF_REG) + stm32_clr_bits(port, ofs->isr, USART_SR_TC); + else + stm32_set_bits(port, ofs->icr, USART_ICR_TCCF); + if (stm32_port->tx_ch) stm32_transmit_chars_dma(port); else @@ -601,12 +590,21 @@ static void stm32_shutdown(struct uart_port *port) struct stm32_port *stm32_port = to_stm32_port(port); struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; struct stm32_usart_config *cfg = &stm32_port->info->cfg; - u32 val; + u32 val, isr; + int ret; val = USART_CR1_TXEIE | USART_CR1_RXNEIE | USART_CR1_TE | USART_CR1_RE; val |= BIT(cfg->uart_enable_bit); if (stm32_port->fifoen) val |= USART_CR1_FIFOEN; + + ret = readl_relaxed_poll_timeout(port->membase + ofs->isr, + isr, (isr & USART_SR_TC), + 10, 100000); + + if (ret) + dev_err(port->dev, "transmission complete not set\n"); + stm32_clr_bits(port, ofs->cr1, val); dev_pm_clear_wake_irq(port->dev);