Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp437992pxb; Mon, 25 Oct 2021 11:11:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQgHtEXuscqKHPkL8FhTy4p2RgZrE4oolxix+dQ9b0VC/7kOjs5SzRO6OwgFkKXpedJlwB X-Received: by 2002:a05:6402:4405:: with SMTP id y5mr28136959eda.339.1635185472801; Mon, 25 Oct 2021 11:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635185472; cv=none; d=google.com; s=arc-20160816; b=BhevXMosqFntBffywaWOQJMANeVtk5pcwq5NOoUb9xZ5AVoJO4K+X8NwWCWiW3xw1/ fbnT9wQxYNce6mvavnjqXm7GipZp28SrNcLUOC357e/pN87Jy3MIamSXja329ZId6TTJ TavqxUnrYdYjbmEN8xeTPB6JNrjMis8d+HQztWUuQ3bCUdzM4TkxXMZqYb2xq17ul2EH w+s6uhJsmvDVZ9WKnplgnCb0l46gKQd1J8veaKwJKFWiEnin7aVnfMxBTwr/VT3Q5ATC z8oiGlr/Kvt8feKb7CI/y/5rs1CEnRHsvUT2FhUA1D5Qu9t4yyAd5HJmE9zc+CeJxIzB tR1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=hR+h0mj9eAIHJV+3ilRJChIbgb6EPcNV71c8l1Q/vvM=; b=E9fnPqbmK1EnEOPd7DQnWjegmhgp0FoE+LU32h4YOt9jTvO1XlWCGCeqjKcrbUvgj1 yoLO4gzy787Eia95SvHuaGsKBItgJ/XhrdK+GEK7nhgDH4oEQ5GRU4pQoxoYOwHWSxUM 1jyW924ytgHOHwm8c2M4SR/Mq5hrSoZApjIh5NIrsosM5CQ6+fQFcCOd4NHhEhMKcBjK 6PUx8ORSqAGiW4eSvwDtSnnUb23aOGvQBTCtvoR37YkSzY/UerLU4YFuOL5xj+NpsSqH mir3I76AFeEwR9uUejt0Wrsoc/xn8IrmZnUjYSE8SPMjgdzi0MZM+z0tbVWoTLa2d8Kr M98A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=yDL3uWZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nb6si7899938ejc.78.2021.10.25.11.10.44; Mon, 25 Oct 2021 11:11:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=yDL3uWZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232803AbhJYNpP (ORCPT + 99 others); Mon, 25 Oct 2021 09:45:15 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:43258 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232487AbhJYNpM (ORCPT ); Mon, 25 Oct 2021 09:45:12 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19P8D6SK003402; Mon, 25 Oct 2021 15:42:35 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=hR+h0mj9eAIHJV+3ilRJChIbgb6EPcNV71c8l1Q/vvM=; b=yDL3uWZJXZl0T5Zw23sTZJNBLrYKn2jeSEHxxqCqoYTZDdfsUJ2oDtgVnI3Zb5pe+4sQ jkThkutudBiFG+JfxvSlIcYGE9Zt13K7sYGMpUopc7uI/2iaHculeJn2gO5QYtMxp5ZT 0DyJnX5wx1FG29neF7BxVZSbwXyKlZl6mL78vc2Wfkj/gCDRqmXa4Bk86cIyHnnyT/jt pftVa8UytSjfBOtrbIiCQZSoJXN4U4uSpJ1uhaGGN/UOkmH/JuwBaR+LVQw6pwUi5+QU HDoBiu5yqEicz6yJWIJLaJT1YChISv7ikw5wQ0QZCzvJcHUYiiUF79P9hvpAb/fIph+2 yA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 3bwrvj1t9h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 25 Oct 2021 15:42:35 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 31024100034; Mon, 25 Oct 2021 15:42:35 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 2903F2309DF; Mon, 25 Oct 2021 15:42:35 +0200 (CEST) Received: from localhost (10.75.127.44) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 25 Oct 2021 15:42:34 +0200 From: Erwan Le Ray To: Greg Kroah-Hartman , Jiri Slaby , Maxime Coquelin , Alexandre Torgue CC: , , , , Erwan Le Ray , Fabrice Gasnier , Valentin Caron , Amelie Delaunay Subject: [PATCH 1/3] serial: stm32: rework RX dma initialization and release Date: Mon, 25 Oct 2021 15:42:27 +0200 Message-ID: <20211025134229.8456-2-erwan.leray@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211025134229.8456-1-erwan.leray@foss.st.com> References: <20211025134229.8456-1-erwan.leray@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-25_05,2021-10-25_02,2020-04-07_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The RX DMA channel is kept active forever (from the probe). That prevents going to low power mode when it is used. This change moves the DMA configuration and enabling procedures to startup routine to allow transition to low power mode. The DMA disabling procedure is implemented in stop_rx routine as this ops has to stop characters reception, and DMA transation in shutdown. Clean useless dma_async_tx_descriptor initialization to NULL value. Signed-off-by: Valentin Caron Signed-off-by: Erwan Le Ray diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index 7fd192e1e15d..ee3495c0abbb 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -761,6 +761,10 @@ static void stm32_usart_stop_rx(struct uart_port *port) struct stm32_port *stm32_port = to_stm32_port(port); const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; + /* Disable DMA request line. */ + if (stm32_port->rx_ch) + stm32_usart_clr_bits(port, ofs->cr3, USART_CR3_DMAR); + stm32_usart_clr_bits(port, ofs->cr1, stm32_port->cr1_irq); if (stm32_port->cr3_irq) stm32_usart_clr_bits(port, ofs->cr3, stm32_port->cr3_irq); @@ -777,6 +781,7 @@ static int stm32_usart_startup(struct uart_port *port) const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; const struct stm32_usart_config *cfg = &stm32_port->info->cfg; const char *name = to_platform_device(port->dev)->name; + struct dma_async_tx_descriptor *desc; u32 val; int ret; @@ -797,6 +802,33 @@ static int stm32_usart_startup(struct uart_port *port) if (ofs->rqr != UNDEF_REG) writel_relaxed(USART_RQR_RXFRQ, port->membase + ofs->rqr); + if (stm32_port->rx_ch) { + stm32_port->last_res = RX_BUF_L; + /* Prepare a DMA cyclic transaction */ + desc = dmaengine_prep_dma_cyclic(stm32_port->rx_ch, + stm32_port->rx_dma_buf, + RX_BUF_L, RX_BUF_P, + DMA_DEV_TO_MEM, + DMA_PREP_INTERRUPT); + if (!desc) { + dev_err(port->dev, "rx dma prep cyclic failed\n"); + ret = -ENODEV; + goto err; + } + + desc->callback = stm32_usart_rx_dma_complete; + desc->callback_param = port; + + /* Push current DMA transaction in the pending queue */ + ret = dma_submit_error(dmaengine_submit(desc)); + if (ret) { + dmaengine_terminate_sync(stm32_port->rx_ch); + goto err; + } + + /* Issue pending DMA requests */ + dma_async_issue_pending(stm32_port->rx_ch); + } /* * DMA request line not re-enabled at resume when port is throttled. * It will be re-enabled by unthrottle ops. @@ -809,6 +841,11 @@ static int stm32_usart_startup(struct uart_port *port) stm32_usart_set_bits(port, ofs->cr1, val); return 0; + +err: + free_irq(port->irq, port); + + return ret; } static void stm32_usart_shutdown(struct uart_port *port) @@ -836,6 +873,10 @@ static void stm32_usart_shutdown(struct uart_port *port) if (ret) dev_err(port->dev, "Transmission is not complete\n"); + /* Disable RX DMA. */ + if (stm32_port->rx_ch) + dmaengine_terminate_async(stm32_port->rx_ch); + /* flush RX & TX FIFO */ if (ofs->rqr != UNDEF_REG) writel_relaxed(USART_RQR_TXFRQ | USART_RQR_RXFRQ, @@ -1304,7 +1345,6 @@ static int stm32_usart_of_dma_rx_probe(struct stm32_port *stm32port, struct uart_port *port = &stm32port->port; struct device *dev = &pdev->dev; struct dma_slave_config config; - struct dma_async_tx_descriptor *desc = NULL; int ret; /* @@ -1332,32 +1372,6 @@ static int stm32_usart_of_dma_rx_probe(struct stm32_port *stm32port, return ret; } - /* Prepare a DMA cyclic transaction */ - desc = dmaengine_prep_dma_cyclic(stm32port->rx_ch, - stm32port->rx_dma_buf, - RX_BUF_L, RX_BUF_P, DMA_DEV_TO_MEM, - DMA_PREP_INTERRUPT); - if (!desc) { - dev_err(dev, "rx dma prep cyclic failed\n"); - stm32_usart_of_dma_rx_remove(stm32port, pdev); - return -ENODEV; - } - - /* Set DMA callback */ - desc->callback = stm32_usart_rx_dma_complete; - desc->callback_param = port; - - /* Push current DMA transaction in the pending queue */ - ret = dma_submit_error(dmaengine_submit(desc)); - if (ret) { - dmaengine_terminate_sync(stm32port->rx_ch); - stm32_usart_of_dma_rx_remove(stm32port, pdev); - return ret; - } - - /* Issue pending DMA requests */ - dma_async_issue_pending(stm32port->rx_ch); - return 0; } @@ -1535,7 +1549,6 @@ static int stm32_usart_serial_remove(struct platform_device *pdev) } if (stm32_port->rx_ch) { - dmaengine_terminate_async(stm32_port->rx_ch); stm32_usart_of_dma_rx_remove(stm32_port, pdev); dma_release_channel(stm32_port->rx_ch); } -- 2.17.1