From patchwork Thu Jan 5 01:59:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Ranostay X-Patchwork-Id: 9498245 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 747EB606A9 for ; Thu, 5 Jan 2017 02:02:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CD2927FBC for ; Thu, 5 Jan 2017 02:02:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EFD12836D; Thu, 5 Jan 2017 02:02:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 057B427FBC for ; Thu, 5 Jan 2017 02:02:31 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id CE3F2267672; Thu, 5 Jan 2017 03:02:17 +0100 (CET) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id E7DD126767C; Thu, 5 Jan 2017 02:59:52 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 34B4726767C; Thu, 5 Jan 2017 02:59:33 +0100 (CET) Received: from mail-pf0-f182.google.com (mail-pf0-f182.google.com [209.85.192.182]) by alsa0.perex.cz (Postfix) with ESMTP id 0930F267662 for ; Thu, 5 Jan 2017 02:59:28 +0100 (CET) Received: by mail-pf0-f182.google.com with SMTP id i88so84569385pfk.2 for ; Wed, 04 Jan 2017 17:59:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ranostay-consulting.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=M7c7c7MXQRUzyXh1s2DsxP2UdlLUw8Yrg/M/tyNnT04=; b=aLOZfB862//n6ZzfcIZXoGEKV/RbZe0LgoBPD1A4/nDkoIfHcRgmJeR/yomkq5VAMY QJ+YPGpR8OSdVmSyKyoq2dA2jNRHvwLdtwvIr1+YjkxA31Ni2WW44rdabLpz+ZA5iQAm gbb+hjlelGFKDklma7B1Q/5ZgOGG7LdFhBelPQFDBcNl7fhWlyC5UdqrkEnsuF0D4+kt deUbPLkXYaI8NmIuioO9m9tZuJsAnYjWlUkIBZGbfkG8q0p/9idNrUMPGfmoGWyEcMls JrfWwA2n62vIpsmdulhByycGSouJQ4tD56NHvY9wuH/1XT9Q3tleNE58WSg6ybbkyil3 yGYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=M7c7c7MXQRUzyXh1s2DsxP2UdlLUw8Yrg/M/tyNnT04=; b=Tam+lqNTYetcH/u13JHTtoKhIZWVgOfEb+FaYJLOhqZwUrFVfaoJLpeHPPfR8zEQBF obWjVeEBUXRrCVTKYfmFLB4hNt0lksZIIZv/OswGNoOnjO5vj7WFlIYZQQ2rUxEQXPxl i5v+BKOf0RK3HummoEEXxs45EYen6ig3z52LAY+Z4aARncP/YuHCQ87M5IRNH++jQTuR dFbrz0Doy0LpZGqhET9kVYdIFn8v/Cc9pha6rWuDNKqjk+ttUqOPth4w0kSdzZhZ5mxM iHJczy2nDYJEsPA7RB7X+NBw7qpGZqoOa8903yvUtvnXQkBc/EcxlsXQ+el/Rl0y6A9G tsYA== X-Gm-Message-State: AIkVDXK0DJ3mbfpdwneK5Xm/8FUzBbNqnOn5Q0w7EClnVmkWOhah2yRhdt+zhZotIMUfDQ== X-Received: by 10.84.139.67 with SMTP id 61mr148991856plq.65.1483581567100; Wed, 04 Jan 2017 17:59:27 -0800 (PST) Received: from niteshade.hsd1.or.comcast.net (c-73-25-156-150.hsd1.or.comcast.net. [73.25.156.150]) by smtp.gmail.com with ESMTPSA id s5sm151232619pgj.19.2017.01.04.17.59.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jan 2017 17:59:26 -0800 (PST) From: Matt Ranostay To: alsa-devel@alsa-project.org, linux-omap@vger.kernel.org Date: Wed, 4 Jan 2017 17:59:18 -0800 Message-Id: <20170105015918.21621-1-matt@ranostay.consulting> X-Mailer: git-send-email 2.10.2 Cc: Tony Lindgren , Peter Ujfalusi , Matt Ranostay Subject: [alsa-devel] [PATCH v5] ASoC: omap-mcbsp: Add PM QoS support for McBSP to prevent glitches X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP We can get audio errors if hitting deeper idle states on omaps: [alsa.c:230] error: Fatal problem with alsa output, error -5. [audio.c:614] error: Error in writing audio (Input/output error?)! This seems to happen with off mode idle enabled as power for the whole SoC may get cut off between filling the McBSP fifo using DMA. While active DMA blocks deeper idle states in hardware, McBSP activity does not seem to do so. Basing the QoS latency calculation on the FIFO size, threshold, sample rate, and channels. Based on the original patch by Tony Lindgren Link: https://patchwork.kernel.org/patch/9305867/ Cc: Tony Lindgren Cc: Peter Ujfalusi Signed-off-by: Matt Ranostay Acked-by: Peter Ujfalusi --- Changes from v1: * add calculations for latency per number of FIFO locations Changes from v2: * add missing mcbsp.h header change Changes from v3: * base the latency calculations on threshold, buffer size, sample rate, and channels Changes from v4: * using Peter Ujfalusi's suggestions for restoring a higher latency on audio stream completion, or if not applicable remove the QoS request sound/soc/omap/mcbsp.c | 37 +++++++++++++++++++++++++++++++++++++ sound/soc/omap/mcbsp.h | 3 +++ sound/soc/omap/omap-mcbsp.c | 11 ++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c index 06fec5699cc8..f079650b71e3 100644 --- a/sound/soc/omap/mcbsp.c +++ b/sound/soc/omap/mcbsp.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -640,9 +641,28 @@ void omap_mcbsp_free(struct omap_mcbsp *mcbsp) */ void omap_mcbsp_start(struct omap_mcbsp *mcbsp, int tx, int rx) { + struct pm_qos_request *pm_qos_req = &mcbsp->pm_qos_req; + int stream1 = tx ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE; + int stream2 = tx ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; int enable_srg = 0; + int latency; u16 w; + /* Prevent omap hardware from hitting off between FIFO fills */ + if (!mcbsp->latency[stream2] || + mcbsp->latency[stream1] < mcbsp->latency[stream2]) + latency = mcbsp->latency[stream1]; + else + latency = mcbsp->latency[stream2]; + + if (latency) { + if (pm_qos_request_active(pm_qos_req)) + pm_qos_update_request(pm_qos_req, latency); + else + pm_qos_add_request(pm_qos_req, PM_QOS_CPU_DMA_LATENCY, + latency); + } + if (mcbsp->st_data) omap_st_start(mcbsp); @@ -731,6 +751,20 @@ void omap_mcbsp_stop(struct omap_mcbsp *mcbsp, int tx, int rx) if (mcbsp->st_data) omap_st_stop(mcbsp); + + if (pm_qos_request_active(&mcbsp->pm_qos_req)) { + int stream1 = tx ? SNDRV_PCM_STREAM_PLAYBACK : + SNDRV_PCM_STREAM_CAPTURE; + int stream2 = tx ? SNDRV_PCM_STREAM_CAPTURE : + SNDRV_PCM_STREAM_PLAYBACK; + + mcbsp->latency[stream1] = 0; + if (mcbsp->latency[stream2]) + pm_qos_update_request(&mcbsp->pm_qos_req, + mcbsp->latency[stream2]); + else + pm_qos_remove_request(&mcbsp->pm_qos_req); + } } int omap2_mcbsp_set_clks_src(struct omap_mcbsp *mcbsp, u8 fck_src_id) @@ -1098,6 +1132,9 @@ int omap_mcbsp_init(struct platform_device *pdev) void omap_mcbsp_cleanup(struct omap_mcbsp *mcbsp) { + if (pm_qos_request_active(&mcbsp->pm_qos_req)) + pm_qos_remove_request(&mcbsp->pm_qos_req); + if (mcbsp->pdata->buffer_size) sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group); diff --git a/sound/soc/omap/mcbsp.h b/sound/soc/omap/mcbsp.h index 61e93b1c185d..46ae1269a698 100644 --- a/sound/soc/omap/mcbsp.h +++ b/sound/soc/omap/mcbsp.h @@ -323,8 +323,11 @@ struct omap_mcbsp { unsigned int fmt; unsigned int in_freq; + unsigned int latency[2]; int clk_div; int wlen; + + struct pm_qos_request pm_qos_req; }; void omap_mcbsp_config(struct omap_mcbsp *mcbsp, diff --git a/sound/soc/omap/omap-mcbsp.c b/sound/soc/omap/omap-mcbsp.c index d018e966e533..7e00938271c6 100644 --- a/sound/soc/omap/omap-mcbsp.c +++ b/sound/soc/omap/omap-mcbsp.c @@ -226,6 +226,7 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream, int wlen, channels, wpf; int pkt_size = 0; unsigned int format, div, framesize, master; + unsigned int buffer_size = mcbsp->pdata->buffer_size; dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream); channels = params_channels(params); @@ -240,7 +241,9 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream, default: return -EINVAL; } - if (mcbsp->pdata->buffer_size) { + if (buffer_size) { + int latency; + if (mcbsp->dma_op_mode == MCBSP_DMA_MODE_THRESHOLD) { int period_words, max_thrsh; int divider = 0; @@ -271,6 +274,12 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream, /* Use packet mode for non mono streams */ pkt_size = channels; } + + latency = ((((buffer_size - pkt_size) / channels) * 1000) + / (params->rate_num / params->rate_den)); + + mcbsp->latency[substream->stream] = latency; + omap_mcbsp_set_threshold(substream, pkt_size); }