From patchwork Thu Aug 10 22:49:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Watts X-Patchwork-Id: 13350247 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 36A8EEB64DD for ; Fri, 11 Aug 2023 07:41:02 +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 E9709839; Fri, 11 Aug 2023 09:40:10 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E9709839 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1691739661; bh=4zCNg7WlXafTdFg+xZN6IDYf+gNB0ue1fiNNNkZJQYc=; 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=rmcalDl2GpuGoabB9Xl47vZdublED9XHnZuVFISj3x4+IBd1IH4j6gCsBm9Jjp/xN QOoroc4Z5DH+FNKxnogOC6pEL7XZKa3GoVhokr0JnkDuIqHWz7iPgasdTVrpOzx1pm LWfN74g6OVTpQRDDKpJobjTEtj7ULvy8um8Y40Sw= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 99AE4F80558; Fri, 11 Aug 2023 09:39:21 +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 DCB5DF80564; Fri, 11 Aug 2023 09:39:20 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 0BF59F800EE; Fri, 11 Aug 2023 00:49:54 +0200 (CEST) Received: from out-124.mta1.migadu.com (out-124.mta1.migadu.com [IPv6:2001:41d0:203:375::7c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 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 E1476F80166 for ; Fri, 11 Aug 2023 00:49:45 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E1476F80166 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=jookia.org header.i=@jookia.org header.a=rsa-sha256 header.s=key1 header.b=01K1Clo5 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jookia.org; s=key1; t=1691707785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NOt1sdSQzarb5tnZ/esvuAWXN80C1rxnQDdSGkr2tUk=; b=01K1Clo5tUXVhOGMDlAbBOlOOwcHAo5RT/lrxTGiIK/AC5POgCHYrmpcisnJD5PzcFj5hv dQIbBEM9GPPWfgeIxJRjm27c8VCCcFSczjMcfY9b0Zm2z7X12KN9UgeiBg/nSND71ShynG 4sb0q/7HBZsQcJx+6xLSgO3E84ngsDkYts7ulTYd9AIQ36TeWnNY0uGD8kx0SOPMbQ7iFz cg0QHmOaIJKuaL9LP/LK0gUUC392rni1LmiG8RsIXf7pJPS+X+FehGTc8YFZ2FTvglYg2+ OHXnDHBO/AvUebXLeGTQxOcPqOS6MOw4ycXcK1gyAzI1I9oY0orH/JbcIXxJZg== From: John Watts To: alsa-devel@alsa-project.org Cc: Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jaroslav Kysela , Takashi Iwai , John Watts , patches@opensource.cirrus.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] ASoC: wm8782: Handle maximum audio rate at runtime Date: Fri, 11 Aug 2023 08:49:28 +1000 Message-ID: <20230810224930.3216717-2-contact@jookia.org> In-Reply-To: <20230810224930.3216717-1-contact@jookia.org> References: <20230810224930.3216717-1-contact@jookia.org> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-MailFrom: contact@jookia.org X-Mailman-Rule-Hits: nonmember-moderation 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 Message-ID-Hash: G732GBQFTQRXHEDHTGU5DAXLMOQVBGA2 X-Message-ID-Hash: G732GBQFTQRXHEDHTGU5DAXLMOQVBGA2 X-Mailman-Approved-At: Fri, 11 Aug 2023 07:39:15 +0000 X-Mailman-Version: 3.3.8 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: The wm8782 supports up to 192kHz audio when pins are set correctly. Instead of hardcoding which rates are supported enable them all then refer to a max_rate variable at runtime. Signed-off-by: John Watts --- sound/soc/codecs/wm8782.c | 45 ++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/sound/soc/codecs/wm8782.c b/sound/soc/codecs/wm8782.c index 95ff4339d103..63ab63f3189a 100644 --- a/sound/soc/codecs/wm8782.c +++ b/sound/soc/codecs/wm8782.c @@ -23,6 +23,30 @@ #include #include +/* regulator power supply names */ +static const char *supply_names[] = { + "Vdda", /* analog supply, 2.7V - 3.6V */ + "Vdd", /* digital supply, 2.7V - 5.5V */ +}; + +struct wm8782_priv { + struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; + int max_rate; +}; + +static int wm8782_dai_hw_params(struct snd_pcm_substream *component, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct wm8782_priv *priv = + snd_soc_component_get_drvdata(dai->component); + + if (params_rate(params) > priv->max_rate) + return -EINVAL; + + return 0; +} + static const struct snd_soc_dapm_widget wm8782_dapm_widgets[] = { SND_SOC_DAPM_INPUT("AINL"), SND_SOC_DAPM_INPUT("AINR"), @@ -33,28 +57,22 @@ static const struct snd_soc_dapm_route wm8782_dapm_routes[] = { { "Capture", NULL, "AINR" }, }; +static const struct snd_soc_dai_ops wm8782_dai_ops = { + .hw_params = &wm8782_dai_hw_params, +}; + static struct snd_soc_dai_driver wm8782_dai = { .name = "wm8782", .capture = { .stream_name = "Capture", .channels_min = 2, .channels_max = 2, - /* For configurations with FSAMPEN=0 */ - .rates = SNDRV_PCM_RATE_8000_48000, + .rates = SNDRV_PCM_RATE_8000_192000, .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, }, -}; - -/* regulator power supply names */ -static const char *supply_names[] = { - "Vdda", /* analog supply, 2.7V - 3.6V */ - "Vdd", /* digital supply, 2.7V - 5.5V */ -}; - -struct wm8782_priv { - struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; + .ops = &wm8782_dai_ops, }; static int wm8782_soc_probe(struct snd_soc_component *component) @@ -121,6 +139,9 @@ static int wm8782_probe(struct platform_device *pdev) if (ret < 0) return ret; + /* For configurations with FSAMPEN=0 */ + priv->max_rate = 48000; + return devm_snd_soc_register_component(&pdev->dev, &soc_component_dev_wm8782, &wm8782_dai, 1); }