From patchwork Fri Apr 26 15:29:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 13645014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 448D2C4345F for ; Fri, 26 Apr 2024 15:34:26 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 77DCF20C5; Fri, 26 Apr 2024 17:34:14 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 77DCF20C5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1714145664; bh=hMVnOvoSMf+JRMF8t9uSLpRgdcu8Yz7Hi23L/8tCSL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=cjSEv59fYr+fe7/imJfZjHhiVXuieMlVYkcpIpsak4zcUbbx4RucvhyXF9J8SD1wm vfOYs9tBCNbsCcgHCVS7yxXXg3O5nR2k5LxwWN5o5pmaQ37sgXDlw2n9ytVHtdifOt G7Uhpq9C1OE7vxly3RQWWpP35tbGwAH6c+meBFEc= Received: by alsa1.perex.cz (Postfix, from userid 50401) id CBC67F806AF; Fri, 26 Apr 2024 17:30:19 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id F2A2EF806A6; Fri, 26 Apr 2024 17:30:18 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 39847F80601; Fri, 26 Apr 2024 17:30:11 +0200 (CEST) Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id F1C1AF80423 for ; Fri, 26 Apr 2024 17:29:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz F1C1AF80423 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=izxBXNIY Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-41ba1ba55e9so4048155e9.3 for ; Fri, 26 Apr 2024 08:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1714145396; x=1714750196; darn=alsa-project.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wdxkC9xy0JdUlM4HJdidG8uU38VPySKk64XDlad2PLg=; b=izxBXNIYPsQkUvHcOYZxP/CxbcRMXcVYFK6jtIkU6DhoZsxmVSSdCad167WgqNm2yk Ys4QOeHvKEUQDt/Hby4Fy4c6TGt3Mcb9stnPfy5OWmUEXuEQsCF5BakuEiREFgKMZBR/ 46vEl09v/EZ4hXhs2sTVoeB+n2fpVfFnFjBJDeSESBfAwRyeQKmoMtDGawg14kz5jw1d a4dYQW8uZ7FmEuwMRXIeDGSITynTpILxf/Zywf4JqgmSEwow9ZoEWfrhRcSMFQPMWJJP 0xLygQHgtY/ng5L80P5Cjcox2WAqEpkU6mc9O0xJG5vsbAUr2e8ciJLKOK/xhBH4gdQi H2rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714145396; x=1714750196; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wdxkC9xy0JdUlM4HJdidG8uU38VPySKk64XDlad2PLg=; b=dv3hfpe0EzZ/WGA3MQiG5y3LEPVWKaWWXZRseWV8aG9qojjWt36ixB/4463Fw0uZ4K YPVgfQYpKHVJvr+NN1ulKM+ZdO08fIBFAMEVwsgqVkBC3cMIdTFN4X/TXNVK2UIcVMjD KkFDE/5clXfsVs9iilMrrW8C0g/rWXlgDL3TdsWHqJPV+R5ipIMvDWes5Op6TjPn+gnP HLQ3m6/1Ue2i3J5e2zN/OB7XM+9Zcu1VZKzFiJeo8EWevE7Eh71lNYPhDZwif7Fq8juZ VK4+EyuknU+g5TRwzwKDhxBhNL5bHCaerhCh7HaPZ2C9Cuda4IJkAuRC0VimB+/pjVEM ge1g== X-Forwarded-Encrypted: i=1; AJvYcCULCXsgPMXBbGXVgEVNi6lbXVulFzHMPnVgOlZM/ss2ilGU6GXUjquJDUoXwkOltw4zQco2LdjEHruh3o3zljtkFT48eWFX/MAuXwE= X-Gm-Message-State: AOJu0YxI+3P9PAaTF3iuaZW2Njf/pATV9vDo3SNNSMn5yBJXZYyB/aDc FxWx61Z3PCc9tujXa23u3qm0VY8bWjWu3F1APyEJmKNFAJPRtMk9kPRWIqCSbmE= X-Google-Smtp-Source: AGHT+IHPpBP3QSa57mdn7C6mGnSnPPrJ1b15kSZTPSoFNzWhfVV6qwoJcqsNBhnR4twzoAilz89DKA== X-Received: by 2002:a05:600c:4ecf:b0:416:bc18:2a00 with SMTP id g15-20020a05600c4ecf00b00416bc182a00mr2136057wmq.38.1714145395834; Fri, 26 Apr 2024 08:29:55 -0700 (PDT) Received: from toaster.lan ([2a01:e0a:3c5:5fb1:1926:f73e:8b99:1c0a]) by smtp.googlemail.com with ESMTPSA id i13-20020a05600c354d00b00419fba938d8sm22628687wmq.27.2024.04.26.08.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 08:29:55 -0700 (PDT) From: Jerome Brunet To: Mark Brown , Liam Girdwood Cc: Jerome Brunet , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org Subject: [PATCH 1/4] ASoC: meson: axg-fifo: use threaded irq to check periods Date: Fri, 26 Apr 2024 17:29:38 +0200 Message-ID: <20240426152946.3078805-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426152946.3078805-1-jbrunet@baylibre.com> References: <20240426152946.3078805-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Message-ID-Hash: YQKFAPAXRV473M4A5P3LXVIWUZ5RYRA5 X-Message-ID-Hash: YQKFAPAXRV473M4A5P3LXVIWUZ5RYRA5 X-MailFrom: jbrunet@baylibre.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: With the AXG audio subsystem, there is a possible random channel shift on TDM capture, when the slot number per lane is more than 2, and there is more than one lane used. The problem has been there since the introduction of the axg audio support but such scenario is pretty uncommon. This is why there is no loud complains about the problem. Solving the problem require to make the links non-atomic and use the trigger() callback to start FEs and BEs in the appropriate order. This was tried in the past and reverted because it caused the block irq to sleep while atomic. However, instead of reverting, the solution is to call snd_pcm_period_elapsed() in a non atomic context. Use the bottom half of a threaded IRQ to do so. Fixes: 6dc4fa179fb8 ("ASoC: meson: add axg fifo base driver") Signed-off-by: Jerome Brunet --- sound/soc/meson/axg-fifo.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/sound/soc/meson/axg-fifo.c b/sound/soc/meson/axg-fifo.c index bebee0ca8e38..ecb3eb7a9723 100644 --- a/sound/soc/meson/axg-fifo.c +++ b/sound/soc/meson/axg-fifo.c @@ -204,18 +204,26 @@ static irqreturn_t axg_fifo_pcm_irq_block(int irq, void *dev_id) unsigned int status; regmap_read(fifo->map, FIFO_STATUS1, &status); - status = FIELD_GET(STATUS1_INT_STS, status); + axg_fifo_ack_irq(fifo, status); + + /* Use the thread to call period elapsed on nonatomic links */ if (status & FIFO_INT_COUNT_REPEAT) - snd_pcm_period_elapsed(ss); - else - dev_dbg(axg_fifo_dev(ss), "unexpected irq - STS 0x%02x\n", - status); + return IRQ_WAKE_THREAD; - /* Ack irqs */ - axg_fifo_ack_irq(fifo, status); + dev_dbg(axg_fifo_dev(ss), "unexpected irq - STS 0x%02x\n", + status); + + return IRQ_NONE; +} + +static irqreturn_t axg_fifo_pcm_irq_block_thread(int irq, void *dev_id) +{ + struct snd_pcm_substream *ss = dev_id; + + snd_pcm_period_elapsed(ss); - return IRQ_RETVAL(status); + return IRQ_HANDLED; } int axg_fifo_pcm_open(struct snd_soc_component *component, @@ -243,8 +251,9 @@ int axg_fifo_pcm_open(struct snd_soc_component *component, if (ret) return ret; - ret = request_irq(fifo->irq, axg_fifo_pcm_irq_block, 0, - dev_name(dev), ss); + ret = request_threaded_irq(fifo->irq, axg_fifo_pcm_irq_block, + axg_fifo_pcm_irq_block_thread, + IRQF_ONESHOT, dev_name(dev), ss); if (ret) return ret; From patchwork Fri Apr 26 15:29:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 13645015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97C1BC4345F for ; Fri, 26 Apr 2024 15:34:35 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id CABF82110; Fri, 26 Apr 2024 17:34:23 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz CABF82110 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1714145673; bh=twiWpSK9Cb/9sMit7KrauKpyDpxWaybLQZDeq8xxcKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=IroIK+Y/HXuWTDk475vXgHzzfZEBxspldhUyQRGXyZqIAgChNA7bAJK1FYRFpeFpI kHMAr7CPG4qZn2HSqA6+7sJQnAi05nZPn8obKQuRp2dXICvfsbFn7PikHHvA8oQqz/ 7sbopCpjwi70OCQHLRpych2ngtigIXdY+BDeHVD8= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 61EC4F806D6; Fri, 26 Apr 2024 17:30:22 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id B3870F806D2; Fri, 26 Apr 2024 17:30:21 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 53390F8065A; Fri, 26 Apr 2024 17:30:13 +0200 (CEST) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 13BFBF805CB for ; Fri, 26 Apr 2024 17:29:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 13BFBF805CB Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=KFYaVpcH Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-41ba1ba5591so4043495e9.1 for ; Fri, 26 Apr 2024 08:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1714145396; x=1714750196; darn=alsa-project.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Vj88fGfTuV4/ceY0CRDNjfucEqH3NJ0Iz+8z4tgOcCE=; b=KFYaVpcH85jFkilqqc8p78NFHIxEMz/wDvMiXWQf4Sek+nMfrbSQEUcJgv2uT/cqG9 tNaqmBkmHMbdsLchmVuI82Fp7wDrfKcQlENuRo4Yab3SlpRv0Sc+taOici/VNr0quHPQ 0oUPTEK3hrDcyRP8lgzvORQz/XvQKNfSv7feL75+O93/62y8UMM6rKwLsOlNuMiWr3qN qOAl3NWp2YYgp0bseeibyuf0n5bn/eh047niVZvrs0CXu65gkybzBuEZZnz0AYiqrG2K 4H12WuMwj19Ercyuu4/ULT5334+QqDP6vIS79ELNCoq+iN+K+UVhtRwBGoKGwE6CLyqA Ogzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714145396; x=1714750196; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vj88fGfTuV4/ceY0CRDNjfucEqH3NJ0Iz+8z4tgOcCE=; b=Rtlc3lZlBidAXcITFa7PbDenSimLtnQWUMGZOCw4YJ9FQHkCZD9Xu4uLZOWsxOUTbt F41sHDnmbIGC0RoFHTVMOyz6Gb1x72g/q9cKkuLB72oBZCylnXR78airPhbD43lsrnxb Q/iMDEVBIhENYKVmh1jJM6QreLr9q6jLLghtaW/0eg/PA7jOsDhPqiEHp20GXli8A4u2 Eeb94mSD0kVY/s4+rRarDuDU/3hpUqJLlK+1LJDMTEQS/CwHP8vJDFpiVwdypKb0eRhn djrRVZGVvec93Yo1Xt7rKs1GKhZP1nUkAP3gsPue+IG/UoIol/h19H9G5vRt894BO62Y /B/A== X-Forwarded-Encrypted: i=1; AJvYcCUrvovZZiTRQ975eUtbkBq24FjwUJM6YiM+kXsE2DKkp/qXCYqikSqneiilCWPV3uClc90Q7N9u7DFoi1bzPqncTN1Fk9CeTF/ZlrQ= X-Gm-Message-State: AOJu0YxjTda/CSxVXBDRrTM6C7CP29MF14lcTOLvKnTD7dlp9dKqvOoZ RjHfAttH8piuYdwnSjU1a3NXjsnLp0vDq+/kMV9UvOCphWccxMni3b0EZGHuS3c= X-Google-Smtp-Source: AGHT+IEJkZy/zcyYjS/mRx4ZV80tXFjeoyE7of0nB7BlzZ+4FKV/1yBAljbeQBu73IdnjR2X5uGAvA== X-Received: by 2002:a05:600c:b88:b0:418:f991:8ad4 with SMTP id fl8-20020a05600c0b8800b00418f9918ad4mr113607wmb.6.1714145396564; Fri, 26 Apr 2024 08:29:56 -0700 (PDT) Received: from toaster.lan ([2a01:e0a:3c5:5fb1:1926:f73e:8b99:1c0a]) by smtp.googlemail.com with ESMTPSA id i13-20020a05600c354d00b00419fba938d8sm22628687wmq.27.2024.04.26.08.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 08:29:56 -0700 (PDT) From: Jerome Brunet To: Mark Brown , Liam Girdwood Cc: Jerome Brunet , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org Subject: [PATCH 2/4] ASoC: meson: axg-card: make links nonatomic Date: Fri, 26 Apr 2024 17:29:39 +0200 Message-ID: <20240426152946.3078805-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426152946.3078805-1-jbrunet@baylibre.com> References: <20240426152946.3078805-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Message-ID-Hash: 3O4FQKU2LIZ3MCXPUAHUAADZ6UJ7AKDX X-Message-ID-Hash: 3O4FQKU2LIZ3MCXPUAHUAADZ6UJ7AKDX X-MailFrom: jbrunet@baylibre.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Non atomic operations need to be performed in the trigger callback of the TDM interfaces. Those are BEs but what matters is the nonatomic flag of the FE in the DPCM context. Just set nonatomic for everything so, at least, what is done is clear. Fixes: 7864a79f37b5 ("ASoC: meson: add axg sound card support") Signed-off-by: Jerome Brunet --- sound/soc/meson/axg-card.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/soc/meson/axg-card.c b/sound/soc/meson/axg-card.c index 3180aa4d3a15..8c5605c1e34e 100644 --- a/sound/soc/meson/axg-card.c +++ b/sound/soc/meson/axg-card.c @@ -318,6 +318,7 @@ static int axg_card_add_link(struct snd_soc_card *card, struct device_node *np, dai_link->cpus = cpu; dai_link->num_cpus = 1; + dai_link->nonatomic = true; ret = meson_card_parse_dai(card, np, dai_link->cpus); if (ret) From patchwork Fri Apr 26 15:29:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 13645012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 702E0C4345F for ; Fri, 26 Apr 2024 15:33:52 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id E54371926; Fri, 26 Apr 2024 17:33:40 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E54371926 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1714145630; bh=XL4wNAHbKdLtic6750ztJIoB/ro7CVmirV6b234wNGE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=mSh5Cjf7gnsFCyNTVLoAZCUGHmqdzDHP2cQT6+ka53FIw0so3qb6b74grNnEqzSf6 MlhoY7S+T29yYkEYdmEvpoT7Q8pByIGDAsWJFHZLBIgCF/8fkRIES6xyYWQA670+5R pmh8hW2+x9cCZhu7E2mpqoC/CgBJKIsMgmnyiaEE= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9BA22F80656; Fri, 26 Apr 2024 17:30:13 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id D2B63F8065A; Fri, 26 Apr 2024 17:30:12 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 076B5F80610; Fri, 26 Apr 2024 17:30:08 +0200 (CEST) Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8532EF805B2 for ; Fri, 26 Apr 2024 17:29:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8532EF805B2 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=sCCVJSRR Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-41b782405d5so10774125e9.2 for ; Fri, 26 Apr 2024 08:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1714145397; x=1714750197; darn=alsa-project.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LQ4CJQsXVTR1thlbAzx7uixAygG90ZyA723vL1wPyc4=; b=sCCVJSRRtP0j4/AqwxFywLOjvcvCRXEJn/IRI85PU0yyHSSgDmMy2KsaIA217vWxXX BAdA1BnE/wAIRH7S4MMW9IHEc3RQ656vFxDi15RvEPPG4eMVRvPTggyTM6Npmeap/sPq s7l1myVIQ2iLLx2lNzPcjo+LNBiqcbjSg14RNZOnc1GUAKG9vuKdSKNfv/Jnht96xWo9 a3rWj1h17IqE6ibuku/L2FqbdTM635uiHKCFFw7gEHeWyymbS5O3BzofgRKY9LpMYcIo OSY5DQ2GD6oJI/ZWS8xDmhNqwZKaHUYRqcnFTD/qL6qAXIuV7GP1ALJhn6c5hF9AuGzz v9fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714145397; x=1714750197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LQ4CJQsXVTR1thlbAzx7uixAygG90ZyA723vL1wPyc4=; b=uWyyYlRFSSi50lDRhIQDqxP5GJQLFBPkpU9hBk8IakhUsgXWu/D1G4u3hOPfQKUX3Y G/zAuepbYbqZLLK7szANNOL/xX7PXCM/IivqmSA1p2/ZHV+d9XqOpOf7iB0kzrDmls/p 6vtopuPDql1E9mwR9nVW7viYs8ycyb4b2bQfGR+eA61zTWaXHfiIGxYloBSylt3ct1xd zPGlIIVuqRzxVFtXd272veKeZYtba7JtLp6dtYawJj1Jhx/Hq7lNjiMNp9l6X3GGMaKl MM9/c6fIjcmwHKo4i9QmIKEufVUzv2HZ4/Atlmki2cX+RQtkg1JauajbyxGkjsyWsUKk 7Rnw== X-Forwarded-Encrypted: i=1; AJvYcCVOxpa6EdSIEvq/MFaoHsrnqYcqvfANY+ymjkfiBJMPHKnQo0wicOdjLAjjTNf5wqjUBm/ZWMr8gRUHBepO1XFD+A3bUCinPRA5W5s= X-Gm-Message-State: AOJu0Yy/bF7TvOti/Jdzj6NdIhvFA6VSjch0CMJG/JSV0+QIjP2O+lXK 3xo6tiFhXiUprUWAL9EJC1+jlaINr9Uverh3A5/vllLbEcEYQ31MRA83YcSkKOQ= X-Google-Smtp-Source: AGHT+IH1/5s5CRPWdPZqkFw1JsMyITFCO5/+y/SMhOfip3B1nJoETVweJYnD+9vnKbqKCb2dr/aCkw== X-Received: by 2002:a05:600c:4508:b0:418:37e1:3f73 with SMTP id t8-20020a05600c450800b0041837e13f73mr3024524wmo.2.1714145397352; Fri, 26 Apr 2024 08:29:57 -0700 (PDT) Received: from toaster.lan ([2a01:e0a:3c5:5fb1:1926:f73e:8b99:1c0a]) by smtp.googlemail.com with ESMTPSA id i13-20020a05600c354d00b00419fba938d8sm22628687wmq.27.2024.04.26.08.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 08:29:56 -0700 (PDT) From: Jerome Brunet To: Mark Brown , Liam Girdwood Cc: Jerome Brunet , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org Subject: [PATCH 3/4] ASoC: meson: axg-tdm-interface: manage formatters in trigger Date: Fri, 26 Apr 2024 17:29:40 +0200 Message-ID: <20240426152946.3078805-4-jbrunet@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426152946.3078805-1-jbrunet@baylibre.com> References: <20240426152946.3078805-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Message-ID-Hash: V7OKPSK6VSKQ5QC4VWFBSER4SKSKHBQS X-Message-ID-Hash: V7OKPSK6VSKQ5QC4VWFBSER4SKSKHBQS X-MailFrom: jbrunet@baylibre.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: <> List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: So far, the formatters have been reset/enabled using the .prepare() callback. This was done in this callback because walking the formatters use a mutex. A mutex is used because formatter handling require dealing possibly slow clock operation. With the support of non-atomic, .trigger() callback may be used which also allows to properly enable and disable formatters on start but also pause/resume. This solve a random shift on TDMIN as well repeated samples on for TDMOUT. Fixes: d60e4f1e4be5 ("ASoC: meson: add tdm interface driver") Signed-off-by: Jerome Brunet --- sound/soc/meson/axg-tdm-interface.c | 34 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/sound/soc/meson/axg-tdm-interface.c b/sound/soc/meson/axg-tdm-interface.c index bf708717635b..8bf3735dedaa 100644 --- a/sound/soc/meson/axg-tdm-interface.c +++ b/sound/soc/meson/axg-tdm-interface.c @@ -349,26 +349,31 @@ static int axg_tdm_iface_hw_params(struct snd_pcm_substream *substream, return 0; } -static int axg_tdm_iface_hw_free(struct snd_pcm_substream *substream, +static int axg_tdm_iface_trigger(struct snd_pcm_substream *substream, + int cmd, struct snd_soc_dai *dai) { - struct axg_tdm_stream *ts = snd_soc_dai_get_dma_data(dai, substream); + struct axg_tdm_stream *ts = + snd_soc_dai_get_dma_data(dai, substream); - /* Stop all attached formatters */ - axg_tdm_stream_stop(ts); + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + axg_tdm_stream_start(ts); + break; + case SNDRV_PCM_TRIGGER_SUSPEND: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + case SNDRV_PCM_TRIGGER_STOP: + axg_tdm_stream_stop(ts); + break; + default: + return -EINVAL; + } return 0; } -static int axg_tdm_iface_prepare(struct snd_pcm_substream *substream, - struct snd_soc_dai *dai) -{ - struct axg_tdm_stream *ts = snd_soc_dai_get_dma_data(dai, substream); - - /* Force all attached formatters to update */ - return axg_tdm_stream_reset(ts); -} - static int axg_tdm_iface_remove_dai(struct snd_soc_dai *dai) { int stream; @@ -412,8 +417,7 @@ static const struct snd_soc_dai_ops axg_tdm_iface_ops = { .set_fmt = axg_tdm_iface_set_fmt, .startup = axg_tdm_iface_startup, .hw_params = axg_tdm_iface_hw_params, - .prepare = axg_tdm_iface_prepare, - .hw_free = axg_tdm_iface_hw_free, + .trigger = axg_tdm_iface_trigger, }; /* TDM Backend DAIs */ From patchwork Fri Apr 26 15:29:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 13645013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4980C4345F for ; Fri, 26 Apr 2024 15:34:08 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id A3AC321E0; Fri, 26 Apr 2024 17:33:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz A3AC321E0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1714145646; bh=S7RONIxFeXwe67F6fo0qfGrsfEGqrrUtec1UUThnSXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=tDz+XRcGoF884TDf4PfWQO5FIbgD3ESgTQIYcI7SQmYXJ+2DOdcPuV2YRhPBEIrC/ FnSN7foS9fR44wBHxQWqVWLX5wC6bkTwveF+DmGEBmJ8rHm9qHM8I2zma1bObzuBAa u6JCX5HNqNgymhg43LUYEFRnXSmKipawW7xqgIc8= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 8A3B3F80690; Fri, 26 Apr 2024 17:30:16 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id E29E6F8068F; Fri, 26 Apr 2024 17:30:15 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 8F620F8060F; Fri, 26 Apr 2024 17:30:08 +0200 (CEST) Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 123F5F805AB for ; Fri, 26 Apr 2024 17:29:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 123F5F805AB Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=l9xA25CG Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-41b7a26326eso8175945e9.3 for ; Fri, 26 Apr 2024 08:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1714145398; x=1714750198; darn=alsa-project.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4bQrmumSWoqJQMi/l6xj2yc8RNYXdlpvWVWdoITuaG8=; b=l9xA25CG4ybOWVIXlzRgSrexw1HKs+4dKJ3bLhdDD2b3QlH0wBYi+69OAr+oObvZmh tdSNiV8hIUE1aOXM2ekVvY4Znerb9R/ONfqQfcmNhSxQvPuyV5hNmpJ9D0oEWqRZ/AmN mlFhNbHvl0v4c8RkXameBYT+dhrgXc2rK8GNkJQhPpf4RnrNjLEy2G8fksS/U0wvyCUk LV8SsMTj9keFeYoox9mLcg7Z/sRmWcIDF7nlCfFBgUWE2Y/QQXybK5mhOocErkkvIdAz nQnGOPNMjQ1tdeoC6dEHzDVH8tt5t4E++GgGeeSSLgSAXLs/zeCPcxzKCCcj/N489mgT SjMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714145398; x=1714750198; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4bQrmumSWoqJQMi/l6xj2yc8RNYXdlpvWVWdoITuaG8=; b=r//CEGjG4H8r2tgnhNKvCgWlt7Tq+x2jCQxisVMtJRHJfMhGzosGff3gXFF++NXCug 4M7yOwbewwBC53+jIA9Osr4zj6lMGNG5Sx8FZhfaeo218+nQ7Tlne6LwzIEfswOYKl4c IkvcJO982REcHRhyQw/kDgEaA6hXODXcRlGV4ae9pxEiwjZQr4+rTjGfnib62LDJYJYU ZEyLTqT0KNiFXOOYZrFClIgHOBVjCEmSI3+cqG4cYGrAdqs9fPgi+Px25Rn3Het8XmSR WoRrFADI/UtQ7k8ycXzATkHm88tQ5+FKR9mWrSs4dkUDA7oCibfkKbajosi7LV8iXbwv YFNQ== X-Forwarded-Encrypted: i=1; AJvYcCV8u7aPTgZJzqow30TpRS8JFYngddIlFonu+ytz0s8lNXKJ7ehMUbaQGXOUIDSVqIpUEFis+YW7bZWUDiVakIPEiGXcgE+rygz6Mvw= X-Gm-Message-State: AOJu0YwHMasNZpWlm+m81+28x7McUf9asJtLr9EHPqTLxWe1jepw3L12 cKB48h2OYceaZ8/PQ+pflq91iPRytatfqwnKawFXmBLBRV/AkWp6YuLpT/kA7Xo= X-Google-Smtp-Source: AGHT+IHMerJdt74ThT9W2AwuFt/nqHhB935A349L3A9erdfLScSRYmjfvTF+QLgGqsuEAmQiV3l5MA== X-Received: by 2002:a05:600c:4f11:b0:419:87ab:f6db with SMTP id l17-20020a05600c4f1100b0041987abf6dbmr2369314wmq.23.1714145398045; Fri, 26 Apr 2024 08:29:58 -0700 (PDT) Received: from toaster.lan ([2a01:e0a:3c5:5fb1:1926:f73e:8b99:1c0a]) by smtp.googlemail.com with ESMTPSA id i13-20020a05600c354d00b00419fba938d8sm22628687wmq.27.2024.04.26.08.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 08:29:57 -0700 (PDT) From: Jerome Brunet To: Mark Brown , Liam Girdwood Cc: Jerome Brunet , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org Subject: [PATCH 4/4] ASoC: meson: axg-tdm: add continuous clock support Date: Fri, 26 Apr 2024 17:29:41 +0200 Message-ID: <20240426152946.3078805-5-jbrunet@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426152946.3078805-1-jbrunet@baylibre.com> References: <20240426152946.3078805-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Message-ID-Hash: 7XPIC2LN7ZPGKBCOSU3V42UK6SBNILIS X-Message-ID-Hash: 7XPIC2LN7ZPGKBCOSU3V42UK6SBNILIS X-MailFrom: jbrunet@baylibre.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Some devices may need the clocks running, even while paused. Add support for this use case. Signed-off-by: Jerome Brunet --- sound/soc/meson/axg-tdm-formatter.c | 40 +++++++++++++++++++++++++++++ sound/soc/meson/axg-tdm-interface.c | 16 +++++++++++- sound/soc/meson/axg-tdm.h | 5 ++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/sound/soc/meson/axg-tdm-formatter.c b/sound/soc/meson/axg-tdm-formatter.c index 63333a2b0a9c..a6579efd3775 100644 --- a/sound/soc/meson/axg-tdm-formatter.c +++ b/sound/soc/meson/axg-tdm-formatter.c @@ -392,6 +392,46 @@ void axg_tdm_stream_free(struct axg_tdm_stream *ts) } EXPORT_SYMBOL_GPL(axg_tdm_stream_free); +int axg_tdm_stream_set_cont_clocks(struct axg_tdm_stream *ts, + unsigned int fmt) +{ + int ret = 0; + + if (fmt & SND_SOC_DAIFMT_CONT) { + /* Clock are already enabled - skipping */ + if (ts->clk_enabled) + return 0; + + ret = clk_prepare_enable(ts->iface->mclk); + if (ret) + return ret; + + ret = clk_prepare_enable(ts->iface->sclk); + if (ret) + goto err_sclk; + + ret = clk_prepare_enable(ts->iface->lrclk); + if (ret) + goto err_lrclk; + + ts->clk_enabled = true; + return 0; + } + + /* Clocks are already disabled - skipping */ + if (!ts->clk_enabled) + return 0; + + clk_disable_unprepare(ts->iface->lrclk); +err_lrclk: + clk_disable_unprepare(ts->iface->sclk); +err_sclk: + clk_disable_unprepare(ts->iface->mclk); + ts->clk_enabled = false; + return ret; +} +EXPORT_SYMBOL_GPL(axg_tdm_stream_set_cont_clocks); + MODULE_DESCRIPTION("Amlogic AXG TDM formatter driver"); MODULE_AUTHOR("Jerome Brunet "); MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/meson/axg-tdm-interface.c b/sound/soc/meson/axg-tdm-interface.c index 8bf3735dedaa..62057c71f742 100644 --- a/sound/soc/meson/axg-tdm-interface.c +++ b/sound/soc/meson/axg-tdm-interface.c @@ -309,6 +309,7 @@ static int axg_tdm_iface_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct axg_tdm_iface *iface = snd_soc_dai_get_drvdata(dai); + struct axg_tdm_stream *ts = snd_soc_dai_get_dma_data(dai, substream); int ret; switch (iface->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { @@ -346,7 +347,19 @@ static int axg_tdm_iface_hw_params(struct snd_pcm_substream *substream, return ret; } - return 0; + ret = axg_tdm_stream_set_cont_clocks(ts, iface->fmt); + if (ret) + dev_err(dai->dev, "failed to apply continuous clock setting\n"); + + return ret; +} + +static int axg_tdm_iface_hw_free(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct axg_tdm_stream *ts = snd_soc_dai_get_dma_data(dai, substream); + + return axg_tdm_stream_set_cont_clocks(ts, 0); } static int axg_tdm_iface_trigger(struct snd_pcm_substream *substream, @@ -417,6 +430,7 @@ static const struct snd_soc_dai_ops axg_tdm_iface_ops = { .set_fmt = axg_tdm_iface_set_fmt, .startup = axg_tdm_iface_startup, .hw_params = axg_tdm_iface_hw_params, + .hw_free = axg_tdm_iface_hw_free, .trigger = axg_tdm_iface_trigger, }; diff --git a/sound/soc/meson/axg-tdm.h b/sound/soc/meson/axg-tdm.h index 42f7470b9a7f..daaca10fec9e 100644 --- a/sound/soc/meson/axg-tdm.h +++ b/sound/soc/meson/axg-tdm.h @@ -58,12 +58,17 @@ struct axg_tdm_stream { unsigned int physical_width; u32 *mask; bool ready; + + /* For continuous clock tracking */ + bool clk_enabled; }; struct axg_tdm_stream *axg_tdm_stream_alloc(struct axg_tdm_iface *iface); void axg_tdm_stream_free(struct axg_tdm_stream *ts); int axg_tdm_stream_start(struct axg_tdm_stream *ts); void axg_tdm_stream_stop(struct axg_tdm_stream *ts); +int axg_tdm_stream_set_cont_clocks(struct axg_tdm_stream *ts, + unsigned int fmt); static inline int axg_tdm_stream_reset(struct axg_tdm_stream *ts) {