From patchwork Wed Dec 14 12:37:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 13073030 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 1E25EC4332F for ; Wed, 14 Dec 2022 12:39:25 +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 320122422; Wed, 14 Dec 2022 13:38:33 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 320122422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1671021563; bh=6UKyqhoE+104iGmuRgMEEkd+q+3dSfhpuzs6x2u26lY=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=Xe4wbP9rKgr1kQkJ1QwcjJhNeDM1YtXs9oxR5qb4b02XpRZHYdH+G4B5mZ474utoU BJ2DR+92VwTOEd4Q3A++CShTR0JCdl2GPQ6OyJ4m+zyxQqg3oRCLgq/+Gm8bH6gBzT 3woemFu6ZLfnLqLBVW4d/cpRKF1k20pQhgD9Bat4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id EC48BF804D0; Wed, 14 Dec 2022 13:38:11 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 828C5F804F1; Wed, 14 Dec 2022 13:38:08 +0100 (CET) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 672C4F80310 for ; Wed, 14 Dec 2022 13:38:06 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 672C4F80310 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=y1lyj8rz Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 3F7BC85104; Wed, 14 Dec 2022 13:38:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1671021485; bh=/73in4YIE8G8CYnWx0Er3I9VVvTCTYIHLYd83My0KlQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y1lyj8rztDUuWEwQvfddAazUNzjyPhv/ZgvWDuX5GQCWDOp3PCgGI1rbRYGxFtsu3 QFYHzd4roZ/kNz6LwXfmJv6YvE9wvRQEaiFKwoyJSfyU+3zN1s2YEbUWAt+KOYvhuc p2mLHdtMOFJm+vKFyvwyosBmLApcxNNTYfdJXbq27gvmh28aKAAC9xvLAxQu1R4lOa KwtLykZhJc4yy4EkrM5J7pJhwy3eajOTRDufW6MFXFyXy8mydRkMRjWvPLc2jvIa7Y TXL9iGNDHv3M1/z9mz7N11xQIAYC/aqtuDglNmpI74DZ5bR2ySJ0qMeT14c2euyYcu 147ezol8DSALQ== From: Lukasz Majewski To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Charles Keepax , Stephen Kitt Subject: [PATCH 1/4] ASoC: wm8940: Remove warning when no plat data present Date: Wed, 14 Dec 2022 13:37:40 +0100 Message-Id: <20221214123743.3713843-2-lukma@denx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221214123743.3713843-1-lukma@denx.de> References: <20221214123743.3713843-1-lukma@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 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: , Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Lukasz Majewski Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The lack of platform data in the contemporary Linux shall not be the reason to display warnings to the kernel logs. Signed-off-by: Lukasz Majewski Acked-by: Charles Keepax --- sound/soc/codecs/wm8940.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c index 8dac9fd88547..0b59020d747f 100644 --- a/sound/soc/codecs/wm8940.c +++ b/sound/soc/codecs/wm8940.c @@ -709,9 +709,7 @@ static int wm8940_probe(struct snd_soc_component *component) if (ret < 0) return ret; - if (!pdata) - dev_warn(component->dev, "No platform data supplied\n"); - else { + if (pdata) { reg = snd_soc_component_read(component, WM8940_OUTPUTCTL); ret = snd_soc_component_write(component, WM8940_OUTPUTCTL, reg | pdata->vroi); if (ret < 0) From patchwork Wed Dec 14 12:37:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 13073031 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 45561C001B2 for ; Wed, 14 Dec 2022 12:39: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 42BA429C0; Wed, 14 Dec 2022 13:39:00 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 42BA429C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1671021590; bh=d4at/HI/YF852u+T4AVn4E4xQUTlAvyEpNN1i1/2zew=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=uvXGi9Iv7f4JI8lwGUn7pzCkw95l9Dl+nrNYc03RUdxJghCyBJNmTK+3z2abyh6wD WvlqtrUaDWJkVHEbp7ZpQWB7RuJAVbeGb9T2ZWVdDgBOI7+EYkI0DWEyuECKS/T2Bf bzx2eDGeBbzBrItGoKsdtqKAdaGhwZVjcggSz29A= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 6EA57F804E0; Wed, 14 Dec 2022 13:38:12 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id A296DF80520; Wed, 14 Dec 2022 13:38:09 +0100 (CET) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 99DA9F804D7 for ; Wed, 14 Dec 2022 13:38:06 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 99DA9F804D7 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=geY+9KKL Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id AE0DE85112; Wed, 14 Dec 2022 13:38:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1671021486; bh=abd1MpTy2Dv7NXLZctEyPw0kePkmyEM/uEvzbgu2gpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=geY+9KKLM0h2RZND9Py7wjG0DwsT68/LnsKJmP7k4omOm3tmyCYT2S1mR2IuRFcRh 3GhfNkhi82QkYov0fRY0Ic4RK6ohZLJHLKRlmFYKoT5mD4k9AoFu/ueH90kfnrBmYq mgpWoXBAJFn5gneZiNZErc38qnUJ8APyE/ltUMiX+GY1HOtWbMqLMFjNCuFRYJxSqI 8nxFCcjgZzkWNy6rdwps9X/neVdSX6Tg4fd0Psywytstk6s132TtZMPXX4FIobcKB8 logZoRTGWjcJVlWT6R1e3pmiYFOrLmNnb7wquV6vBw6hWgUOmY1LeFH1Mg91fww+01 k67UudxYytTTg== From: Lukasz Majewski To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Charles Keepax , Stephen Kitt Subject: [PATCH 2/4] ASoC: wm8940: Rewrite code to set proper clocks Date: Wed, 14 Dec 2022 13:37:41 +0100 Message-Id: <20221214123743.3713843-3-lukma@denx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221214123743.3713843-1-lukma@denx.de> References: <20221214123743.3713843-1-lukma@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 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: , Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Lukasz Majewski Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Without this change, the wm8940 driver is not working when set_sysclk callback (wm8940_set_dai_sysclk) is called with frequency not listed in the switch clause. This change adjusts this driver to allow non-standard frequency set (just after the boot) being adjusted afterwards by the sound system core code. Moreover, support for internal wm8940's PLL is provided, so it can generate clocks when HOST system is not able to do it. Code in this commit is based on previous change done for wm8974 (SHA1: 51b2bb3f2568e6d9d81a001d38b8d70c2ba4af99). Signed-off-by: Lukasz Majewski --- sound/soc/codecs/wm8940.c | 103 ++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 20 deletions(-) diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c index 0b59020d747f..094e74905df9 100644 --- a/sound/soc/codecs/wm8940.c +++ b/sound/soc/codecs/wm8940.c @@ -37,7 +37,9 @@ #include "wm8940.h" struct wm8940_priv { - unsigned int sysclk; + unsigned int mclk; + unsigned int fs; + struct regmap *regmap; }; @@ -387,17 +389,24 @@ static int wm8940_set_dai_fmt(struct snd_soc_dai *codec_dai, return 0; } +static int wm8940_update_clocks(struct snd_soc_dai *dai); static int wm8940_i2s_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { struct snd_soc_component *component = dai->component; + struct wm8940_priv *priv = snd_soc_component_get_drvdata(component); u16 iface = snd_soc_component_read(component, WM8940_IFACE) & 0xFD9F; u16 addcntrl = snd_soc_component_read(component, WM8940_ADDCNTRL) & 0xFFF1; u16 companding = snd_soc_component_read(component, WM8940_COMPANDINGCTL) & 0xFFDF; int ret; + priv->fs = params_rate(params); + ret = wm8940_update_clocks(dai); + if (ret) + return ret; + /* LoutR control */ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE && params_channels(params) == 2) @@ -496,7 +505,6 @@ static int wm8940_set_bias_level(struct snd_soc_component *component, return ret; } } - /* ensure bufioen and biasen */ pwr_reg |= (1 << 2) | (1 << 3); /* set vmid to 300k for standby */ @@ -611,24 +619,6 @@ static int wm8940_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, return 0; } -static int wm8940_set_dai_sysclk(struct snd_soc_dai *codec_dai, - int clk_id, unsigned int freq, int dir) -{ - struct snd_soc_component *component = codec_dai->component; - struct wm8940_priv *wm8940 = snd_soc_component_get_drvdata(component); - - switch (freq) { - case 11289600: - case 12000000: - case 12288000: - case 16934400: - case 18432000: - wm8940->sysclk = freq; - return 0; - } - return -EINVAL; -} - static int wm8940_set_dai_clkdiv(struct snd_soc_dai *codec_dai, int div_id, int div) { @@ -653,6 +643,79 @@ static int wm8940_set_dai_clkdiv(struct snd_soc_dai *codec_dai, return ret; } +static unsigned int wm8940_get_mclkdiv(unsigned int f_in, unsigned int f_out, + int *mclkdiv) +{ + unsigned int ratio = 2 * f_in / f_out; + + if (ratio <= 2) { + *mclkdiv = WM8940_MCLKDIV_1; + ratio = 2; + } else if (ratio == 3) { + *mclkdiv = WM8940_MCLKDIV_1_5; + } else if (ratio == 4) { + *mclkdiv = WM8940_MCLKDIV_2; + } else if (ratio <= 6) { + *mclkdiv = WM8940_MCLKDIV_3; + ratio = 6; + } else if (ratio <= 8) { + *mclkdiv = WM8940_MCLKDIV_4; + ratio = 8; + } else if (ratio <= 12) { + *mclkdiv = WM8940_MCLKDIV_6; + ratio = 12; + } else if (ratio <= 16) { + *mclkdiv = WM8940_MCLKDIV_8; + ratio = 16; + } else { + *mclkdiv = WM8940_MCLKDIV_12; + ratio = 24; + } + + return f_out * ratio / 2; +} + +static int wm8940_update_clocks(struct snd_soc_dai *dai) +{ + struct snd_soc_component *codec = dai->component; + struct wm8940_priv *priv = snd_soc_component_get_drvdata(codec); + unsigned int fs256; + unsigned int fpll = 0; + unsigned int f; + int mclkdiv; + + if (!priv->mclk || !priv->fs) + return 0; + + fs256 = 256 * priv->fs; + + f = wm8940_get_mclkdiv(priv->mclk, fs256, &mclkdiv); + if (f != priv->mclk) { + /* The PLL performs best around 90MHz */ + fpll = wm8940_get_mclkdiv(22500000, fs256, &mclkdiv); + } + + wm8940_set_dai_pll(dai, 0, 0, priv->mclk, fpll); + wm8940_set_dai_clkdiv(dai, WM8940_MCLKDIV, mclkdiv); + + return 0; +} + +static int wm8940_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, + unsigned int freq, int dir) +{ + struct snd_soc_component *codec = dai->component; + struct wm8940_priv *priv = snd_soc_component_get_drvdata(codec); + + if (dir != SND_SOC_CLOCK_IN) + return -EINVAL; + + priv->mclk = freq; + + return wm8940_update_clocks(dai); +} + + #define WM8940_RATES SNDRV_PCM_RATE_8000_48000 #define WM8940_FORMATS (SNDRV_PCM_FMTBIT_S8 | \ From patchwork Wed Dec 14 12:37:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 13073033 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 3E26CC4332F for ; Wed, 14 Dec 2022 12:40:09 +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 70A602A16; Wed, 14 Dec 2022 13:39:17 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 70A602A16 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1671021607; bh=iIloGlatMDmAuaPNVuQmwCH9/jqZP4MlSm3Z9y2hlaQ=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=I3XF9fGKAZjqF96t6tZoTWtGbEeougxMqyNk7YKMnDKd0dIv3X4MahevIRHH87tXi Y7ozAAkGgSGvF/aBPiAIuQfWrSCCcRLV4wQL2oiYefLKJHaNl29RG8fBs7Jp6bTg9X IJ3IejJAcfeMCkARHhhSaj3vAumPXBTIdhf5bXYo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B61C8F80538; Wed, 14 Dec 2022 13:38:13 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9E7DCF80310; Wed, 14 Dec 2022 13:38:10 +0100 (CET) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 59CF1F804D0 for ; Wed, 14 Dec 2022 13:38:07 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 59CF1F804D0 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=o5UgHlc7 Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 28B5E85165; Wed, 14 Dec 2022 13:38:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1671021486; bh=6Jupxi3YTw8zb2A9Zvbmvr72UlqBukNaZRCAsj7GqjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o5UgHlc7BdfCg9o2XR7gT44W6Ksgs3OtjVtv8ynu0m10B2QzPRU+PC/kEWRkvFPfP acl5roqWq/GsUSGan5B3XwKx/OYt2Pt7chpee0qctOneZIh2EKdT+8t3H0H3cIIbfj 25DbmW865Sa3PAJ0S+ZrifUDk0UBtKfpQpMuY6+Dw277FYYfsYVpyqohBIR2f9CNsY MGUkEtxm5m/RVsyl4t9dyespT3Zmwpcur3weMXvUgq9H6DbcZs0hwVb/zKcYtK+WdD JEob0lISivpColvXh/iz+g3tB/r/AOcxp82bZgDE+fL9AJQsqO0bQe6xNT3fMlgCd1 p0QRaC44qiFAA== From: Lukasz Majewski To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Charles Keepax , Stephen Kitt Subject: [PATCH 3/4] ASoC: wm8940: Mute also the speaker output Date: Wed, 14 Dec 2022 13:37:42 +0100 Message-Id: <20221214123743.3713843-4-lukma@denx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221214123743.3713843-1-lukma@denx.de> References: <20221214123743.3713843-1-lukma@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 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: , Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Lukasz Majewski Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Without this change the BTL speaker produces some "distortion" noise when test program (speaker-test -t waw) is ended with ctrl+c. As our design uses speaker outputs to drive BTL speaker, it was necessary to also mute the speaker via the codec internal WM8940_SPKVOL register with setting WM8940_SPKMUTE bit. Signed-off-by: Lukasz Majewski --- sound/soc/codecs/wm8940.c | 11 ++++++++++- sound/soc/codecs/wm8940.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c index 094e74905df9..13cb57210b4b 100644 --- a/sound/soc/codecs/wm8940.c +++ b/sound/soc/codecs/wm8940.c @@ -465,9 +465,18 @@ static int wm8940_mute(struct snd_soc_dai *dai, int mute, int direction) { struct snd_soc_component *component = dai->component; u16 mute_reg = snd_soc_component_read(component, WM8940_DAC) & 0xffbf; + u16 spkvol_reg = snd_soc_component_read(component, WM8940_SPKVOL); + int ret; - if (mute) + spkvol_reg &= ~WM8940_SPKMUTE; + if (mute) { mute_reg |= 0x40; + spkvol_reg |= WM8940_SPKMUTE; + } + + ret = snd_soc_component_write(component, WM8940_SPKVOL, spkvol_reg); + if (ret) + return ret; return snd_soc_component_write(component, WM8940_DAC, mute_reg); } diff --git a/sound/soc/codecs/wm8940.h b/sound/soc/codecs/wm8940.h index 0d4f53ada2e6..eb051ed29bb8 100644 --- a/sound/soc/codecs/wm8940.h +++ b/sound/soc/codecs/wm8940.h @@ -95,5 +95,8 @@ struct wm8940_setup_data { #define WM8940_OPCLKDIV_3 2 #define WM8940_OPCLKDIV_4 3 +/* Bit definitions */ +#define WM8940_SPKMUTE BIT(6) + #endif /* _WM8940_H */ From patchwork Wed Dec 14 12:37:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 13073032 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 1504CC001B2 for ; Wed, 14 Dec 2022 12:39:59 +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 38B0023F4; Wed, 14 Dec 2022 13:39:07 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 38B0023F4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1671021597; bh=/YbLUsvgSr7xXcoYflW3WHwlVzGrGQrJ5ZMfGnZ0Hq8=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=Wi1JCWRrY2s/CS+KI/xxRSWrCGL1hC+EN8+1wT2LgtEmJwSnDYSZs6Aru5+32txNi qlvcLAAr3KXkd7TxB+/9N4l+08ieMzjAJbxICT9egAwZZz2yZ/06uQL0RzWq07WYzl RRIvCLXhn5QDk0kAUyY767jb/c6X2ZRiBwkObaeI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 1226CF80534; Wed, 14 Dec 2022 13:38:13 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B7D68F804D7; Wed, 14 Dec 2022 13:38:09 +0100 (CET) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B9BB8F80310 for ; Wed, 14 Dec 2022 13:38:07 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B9BB8F80310 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=TPftpv/V Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 978F385169; Wed, 14 Dec 2022 13:38:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1671021487; bh=azo7orbjiRSezN63u1QFsZfaSV1rIV/pBSbsk2QFUuQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TPftpv/VbeTQrvMqbqLhmRtuiZNvMJGxbLDrpQ8ADXPp3FvRUIYsm0CXNFt+46N1E kewJiPCBbL74uQ/zqtkbpGza9v3QmS1f2Ox7BtQolwsxASqF/kpJeVqJkLxY4ZEBlI N4eprHJ00BubbAo8pl93pVWnPm0hXn9e9PSulBgBd1N8I834/dRV3LxlO2yfLRVcl+ dymehn2B7u7L03eb/sv95hriJ18UGDyTeJrIKCfHxOiE4Nym6Ws23uwWrt64gFVXPK rTYJ0YhnJ/O3mk8pmfLsakNruTA9H+Lcu4CQ0DeGE1gfpW/sS1V4QpngjNU0VziuZy 9b3ZbaiiToFEQ== From: Lukasz Majewski To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Charles Keepax , Stephen Kitt Subject: [PATCH 4/4] ASoC: wm8940: Read chip ID when wm8940 codec probing Date: Wed, 14 Dec 2022 13:37:43 +0100 Message-Id: <20221214123743.3713843-5-lukma@denx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221214123743.3713843-1-lukma@denx.de> References: <20221214123743.3713843-1-lukma@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 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: , Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Lukasz Majewski Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The wm8940 provides the chip ID information via I2C. In this patch this information is read and if not matching expected value, the probe function is aborted. This prevents from using (i.e. inserting) other wm89* modules which use the sam I2C bus address. Signed-off-by: Lukasz Majewski Acked-by: Charles Keepax --- sound/soc/codecs/wm8940.c | 11 +++++++++++ sound/soc/codecs/wm8940.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c index 13cb57210b4b..244998ebab4d 100644 --- a/sound/soc/codecs/wm8940.c +++ b/sound/soc/codecs/wm8940.c @@ -769,6 +769,17 @@ static int wm8940_probe(struct snd_soc_component *component) int ret; u16 reg; + /* + * Check chip ID for wm8940 - value of 0x00 offset + * SOFTWARE_RESET on write + * CHIP_ID on read + */ + reg = snd_soc_component_read(component, WM8940_SOFTRESET); + if (reg != WM8940_CHIP_ID) { + dev_err(component->dev, "Wrong wm8940 chip ID: 0x%x\n", reg); + return -ENODEV; + } + ret = wm8940_reset(component); if (ret < 0) { dev_err(component->dev, "Failed to issue reset\n"); diff --git a/sound/soc/codecs/wm8940.h b/sound/soc/codecs/wm8940.h index eb051ed29bb8..8fbddcaa7449 100644 --- a/sound/soc/codecs/wm8940.h +++ b/sound/soc/codecs/wm8940.h @@ -98,5 +98,8 @@ struct wm8940_setup_data { /* Bit definitions */ #define WM8940_SPKMUTE BIT(6) +/* Chip ID */ +#define WM8940_CHIP_ID 0x8940 + #endif /* _WM8940_H */