Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1986192imu; Fri, 14 Dec 2018 04:06:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/X4xZL/zurINHwe4eRF9zJJtl8m00mPeFhU7hytzFJ8DKVJXM5IAZBb+K0Jg+aDaQHnzbfO X-Received: by 2002:a63:304:: with SMTP id 4mr1973805pgd.99.1544789198859; Fri, 14 Dec 2018 04:06:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789198; cv=none; d=google.com; s=arc-20160816; b=GxwPJ96IS2dqn42I4I1G5YFUiDRifj33lNwUVGlh5fejOQD/m/VGPuyYCGp6e5fT/A kwjqlLKYiUyGPo+UO2cv/982wRx8rw8qvmwFS5HMyXuXk0zBk3OneO6o9arOGdV9gCnU nk8TMsl47Hr2tyuH4uLFFBPgWB8wylutfnZ1/wAY/bXmHdT9CEGuQZWL9ScYNEM7lXBy Du8LKMrubNr3kprnzp170/95cX0CyDyT0DCZj731FrG16f/2LGzCO+vAWztUtGNfKkfs Fr+5CHIHjv35Yj52j0UpnRtQ0SRwC54SCAoHAuqjhqd/v2s0q4/u8UfaNUm7YBWpSSI9 S5Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tfy8F30zwIifDqr00pJJbeX2aWHu2b+hySMPjRateOI=; b=Cw6Un3/v50UbDyOtrL2yv7V9/PmKC9Nr2mTRaG+duUSoeoC4r8pBGN5BPCIt2afHaC 4jKv2hRtVYdbPd0kLXJIRA4GjUfrlhYk+rz3O5CcjKpR+cTMpLMEdW/OXnlHwk5Ilplu a99pKxYkj2pFkFs2Qzj6bM7YiwdODB/+b5f70YnzvO3hr/kHE0RvWPSaLecxzLWD8KEO Rw3Ss3sjO7NoHZDJh78UByHzZ8fqM8DSibHeqa/01XUDwo47jt6xQl111xCB3B2lRsbP fipJ7m+FP5sfAoWgEd4Ax2tbFtxB6K6802kfzE2Ft+pwU2XZ2Q2ds1RC+DCzDCp5soxa 8ZEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VlV9OIIJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 p26si4367922pli.225.2018.12.14.04.06.24; Fri, 14 Dec 2018 04:06:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@kernel.org header.s=default header.b=VlV9OIIJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729931AbeLNMEU (ORCPT + 99 others); Fri, 14 Dec 2018 07:04:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:48946 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730442AbeLNMES (ORCPT ); Fri, 14 Dec 2018 07:04:18 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 158D42146E; Fri, 14 Dec 2018 12:04:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789057; bh=DVrn0PhYuJH23/mv4NOAJ9GaZ+ZBjjCQQjhveMLlqEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VlV9OIIJrSsSiY3PtUi9aWl1HCr93OqnHmsCXDTTs8s2Cc/CAxLIpAMlnizVO2SGP IDs15ArvsVEjzlWIoSRWeqmevjPfHQtCxYRMZJnt1Tv+qTdlx1wydWi7Ov+bajAIkV 8ObNJAT77M7ohrKw1coEolT1/iAOWvLe/GNi5Lb0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Ujfalusi , Jarkko Nikula , Mark Brown , Sasha Levin Subject: [PATCH 4.19 078/142] ASoC: omap-mcpdm: Add pm_qos handling to avoid under/overruns with CPU_IDLE Date: Fri, 14 Dec 2018 12:59:23 +0100 Message-Id: <20181214115750.185300545@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115747.053633987@linuxfoundation.org> References: <20181214115747.053633987@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 373a500e34aea97971c9d71e45edad458d3da98f ] We need to block sleep states which would require longer time to leave than the time the DMA must react to the DMA request in order to keep the FIFO serviced without under of overrun. Signed-off-by: Peter Ujfalusi Acked-by: Jarkko Nikula Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/omap/omap-mcpdm.c | 43 ++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/sound/soc/omap/omap-mcpdm.c b/sound/soc/omap/omap-mcpdm.c index 4c1be36c2207..7d5bdc5a2890 100644 --- a/sound/soc/omap/omap-mcpdm.c +++ b/sound/soc/omap/omap-mcpdm.c @@ -54,6 +54,8 @@ struct omap_mcpdm { unsigned long phys_base; void __iomem *io_base; int irq; + struct pm_qos_request pm_qos_req; + int latency[2]; struct mutex mutex; @@ -277,6 +279,9 @@ static void omap_mcpdm_dai_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai); + int tx = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); + int stream1 = tx ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE; + int stream2 = tx ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; mutex_lock(&mcpdm->mutex); @@ -289,6 +294,14 @@ static void omap_mcpdm_dai_shutdown(struct snd_pcm_substream *substream, } } + if (mcpdm->latency[stream2]) + pm_qos_update_request(&mcpdm->pm_qos_req, + mcpdm->latency[stream2]); + else if (mcpdm->latency[stream1]) + pm_qos_remove_request(&mcpdm->pm_qos_req); + + mcpdm->latency[stream1] = 0; + mutex_unlock(&mcpdm->mutex); } @@ -300,7 +313,7 @@ static int omap_mcpdm_dai_hw_params(struct snd_pcm_substream *substream, int stream = substream->stream; struct snd_dmaengine_dai_dma_data *dma_data; u32 threshold; - int channels; + int channels, latency; int link_mask = 0; channels = params_channels(params); @@ -344,14 +357,25 @@ static int omap_mcpdm_dai_hw_params(struct snd_pcm_substream *substream, dma_data->maxburst = (MCPDM_DN_THRES_MAX - threshold) * channels; + latency = threshold; } else { /* If playback is not running assume a stereo stream to come */ if (!mcpdm->config[!stream].link_mask) mcpdm->config[!stream].link_mask = (0x3 << 3); dma_data->maxburst = threshold * channels; + latency = (MCPDM_DN_THRES_MAX - threshold); } + /* + * The DMA must act to a DMA request within latency time (usec) to avoid + * under/overflow + */ + mcpdm->latency[stream] = latency * USEC_PER_SEC / params_rate(params); + + if (!mcpdm->latency[stream]) + mcpdm->latency[stream] = 10; + /* Check if we need to restart McPDM with this stream */ if (mcpdm->config[stream].link_mask && mcpdm->config[stream].link_mask != link_mask) @@ -366,6 +390,20 @@ static int omap_mcpdm_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai); + struct pm_qos_request *pm_qos_req = &mcpdm->pm_qos_req; + int tx = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); + int stream1 = tx ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE; + int stream2 = tx ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; + int latency = mcpdm->latency[stream2]; + + /* Prevent omap hardware from hitting off between FIFO fills */ + if (!latency || mcpdm->latency[stream1] < latency) + latency = mcpdm->latency[stream1]; + + if (pm_qos_request_active(pm_qos_req)) + pm_qos_update_request(pm_qos_req, latency); + else if (latency) + pm_qos_add_request(pm_qos_req, PM_QOS_CPU_DMA_LATENCY, latency); if (!omap_mcpdm_active(mcpdm)) { omap_mcpdm_start(mcpdm); @@ -427,6 +465,9 @@ static int omap_mcpdm_remove(struct snd_soc_dai *dai) free_irq(mcpdm->irq, (void *)mcpdm); pm_runtime_disable(mcpdm->dev); + if (pm_qos_request_active(&mcpdm->pm_qos_req)) + pm_qos_remove_request(&mcpdm->pm_qos_req); + return 0; } -- 2.19.1