Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1463016lqj; Tue, 4 Jun 2024 02:15:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUOaGXyIJMp18ODCHhY2k1QJz9YDFyfJ3LfY/MJa4eoHrqqywodJQvr71iumkaM8+LNXjTcYe9NTRlANLja1DfE1p5y9B/tWpcyFkIl7A== X-Google-Smtp-Source: AGHT+IGh20yBCuUnzEEETTABw+PfL4XJssWZe0Zu+e5wHSm8mrwt5DSq7T6oTpm0TAwQCNdHEkr/ X-Received: by 2002:a25:84c7:0:b0:df4:d875:a7e2 with SMTP id 3f1490d57ef6-dfa73db24f4mr10712625276.44.1717492521872; Tue, 04 Jun 2024 02:15:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717492521; cv=pass; d=google.com; s=arc-20160816; b=OE1l5DPoYDt+/vq+pF3MqHnEWsP6FtBT+p6OZYhl/lLEkEBD5qFkGply6L/GS3RJ3l tLrzdK7m9nyskITN8vUncVlOf5HeJDWG2y949Z2hU8lTaitdnacYqLPqT/7n2dOWExLe qK4GyiQSjeeOevOYG3xYDpDgw9ZF55H1AH0qUIi7hZ2bTyImuwLcNNyM/zNHrh7m5mWA NcCcWmWRs4+kNLmvNiLSwgK29MWj4PMPRi9gE2TcrktDiwndAuU0tph5gej39SYjXD+R NFEoQ/z6piK70UgPbafsXlEAdwTqUoKHHiC9TiqyvPApzqDhZyM6wi3WsLuFe6drG2Wf sSDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:to:from; bh=LtevzCCZX0EoYfEFGratBgcsFk1Kf3PXbH8vyBqI6Dw=; fh=8hBlDBHBXU+xpFzjCeRpURl00+LxBa5SzGZm40EQ2Kw=; b=SaJTG32sNsjS9sY7ixAbKF4glDOjxkUkhnuKnJUsNcAunzehburalaAoeAhYlfsWU4 r9m5jdVRLw9Za/cgjCZ4fbnyTuBIdsN1sMJQ3O3t/VXhlbOOsYdBR3YmqhMlX9GriW3Y IPv9erPRH1Fz6It6NV+Ea8aAyIQLQLa9apmaABeCeEl5bRfeFxa14WGApc/Sp57w4kSz vo+eGI17GCNxUtyCxG6E6Hp7XrJccwZC24Pn2y9sHXdabe7ipZWmrmeMuLafgTl5zKlU hcqymK4lD6A+j5U2ZR6s23lga+mzbX8SPhKD8OZE0E/rxrKrw24C6HoKjMSdzfotthmF pu8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel+bounces-200332-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200332-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43ff23ae2c0si105241111cf.59.2024.06.04.02.15.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 02:15:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200332-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel+bounces-200332-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200332-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 972D11C23056 for ; Tue, 4 Jun 2024 09:15:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53241143861; Tue, 4 Jun 2024 09:15:15 +0000 (UTC) Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B5FC1411F2; Tue, 4 Jun 2024 09:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=92.121.34.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717492514; cv=none; b=MwQwZL75I/AXFCimA1ulecX+hvJ2Tm5X0Ho12UnRn03nvaTMn5v+KGqYvHxAvmmHK+B3uxUbqkN6vw3kcD/v7xUOtKUqeJ+VxKNIOV448fiD9opOvmcj7jegXwzneZcW5kYDua4RrrXPYIX654KwuAaC4o2TtR7nxhm9wM75feQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717492514; c=relaxed/simple; bh=UBSE8GEPqxZdSjgPlJVW65yM+v8/dSAUhsYRVqOb1Jg=; h=From:To:Subject:Date:Message-Id; b=HCrYnaDEhJHWe3d+v0Y+/R/qbzWy8P/EwmCL7xDLlYhJQC2i9Rg27GyMUgW20DUCWGPF7scPusSjieTkmEWR/jBv6G18SbIeP4JY+EvcXqVTCoCCBmC/T8a5dWPhGMQ5hnWnH45qKq3DcaMIbb4NFIwNPVzxdf7fXQGBLRMLEks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; arc=none smtp.client-ip=92.121.34.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id B63131A1E06; Tue, 4 Jun 2024 11:15:05 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 54FFA1A1DCB; Tue, 4 Jun 2024 11:15:05 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 9DE281820F76; Tue, 4 Jun 2024 17:15:03 +0800 (+08) From: Shengjiu Wang To: lars@metafoo.de, perex@perex.cz, tiwai@suse.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, shengjiu.wang@gmail.com Subject: [PATCH] ASoC: dmaengine_pcm: terminate dmaengine before synchronize Date: Tue, 4 Jun 2024 16:58:57 +0800 Message-Id: <1717491537-9033-1-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: When dmaengine supports pause function, in suspend state, dmaengine_pause() is called instead of dmaengine_terminate_async(), In end of playback stream, the runtime->state will go to SNDRV_PCM_STATE_DRAINING, if system suspend & resume happen at this time, application will not resume playback stream, the stream will be closed directly, the dmaengine_terminate_async() will not be called before the dmaengine_synchronize(), which violates the call sequence for dmaengine_synchronize(). This behavior also happens for capture streams, but there is no SNDRV_PCM_STATE_DRAINING state for capture. So use dmaengine_tx_status() to check the DMA status if the status is DMA_PAUSED, then call dmaengine_terminate_async() to terminate dmaengine before dmaengine_synchronize(). Signed-off-by: Shengjiu Wang --- sound/core/pcm_dmaengine.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c index 12aa1cef11a1..7346c993a067 100644 --- a/sound/core/pcm_dmaengine.c +++ b/sound/core/pcm_dmaengine.c @@ -358,6 +358,12 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open_request_chan); int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream) { struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); + struct dma_tx_state state; + enum dma_status status; + + status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state); + if (status == DMA_PAUSED) + dmaengine_terminate_async(prtd->dma_chan); dmaengine_synchronize(prtd->dma_chan); kfree(prtd); @@ -378,6 +384,12 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close); int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream) { struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); + struct dma_tx_state state; + enum dma_status status; + + status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state); + if (status == DMA_PAUSED) + dmaengine_terminate_async(prtd->dma_chan); dmaengine_synchronize(prtd->dma_chan); dma_release_channel(prtd->dma_chan); -- 2.34.1