From: Marian Postevca <posteuca@mutex.one>
To: Takashi Iwai <tiwai@suse.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>
Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
Marian Postevca <posteuca@mutex.one>
Subject: [PATCH v2 2/4] ASoC: es8316: Enable support for MCLK div by 2
Date: Fri, 25 Aug 2023 00:01:33 +0300 [thread overview]
Message-ID: <20230824210135.19303-3-posteuca@mutex.one> (raw)
In-Reply-To: <20230824210135.19303-1-posteuca@mutex.one>
To properly support a line of Huawei laptops with AMD CPU and a
ES8336 codec connected to the ACP3X module we need to enable
the codec option to divide the MCLK by 2.
The option to divide the MCLK will be enabled for one SKU with a
48Mhz MCLK. This frequency seems to be too high for the codec and
leads to distorted sounds when the option is not enabled.
Signed-off-by: Marian Postevca <posteuca@mutex.one>
---
sound/soc/codecs/es8316.c | 20 ++++++++++++++++++--
sound/soc/codecs/es8316.h | 3 +++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
index 09fc0b25f600..b506cfb9bd5d 100644
--- a/sound/soc/codecs/es8316.c
+++ b/sound/soc/codecs/es8316.c
@@ -26,12 +26,19 @@
/* In slave mode at single speed, the codec is documented as accepting 5
* MCLK/LRCK ratios, but we also add ratio 400, which is commonly used on
* Intel Cherry Trail platforms (19.2MHz MCLK, 48kHz LRCK).
+ * Ratio 1000 is needed for at least one AMD SKU where MCLK is 48Mhz.
*/
#define NR_SUPPORTED_MCLK_LRCK_RATIOS ARRAY_SIZE(supported_mclk_lrck_ratios)
static const unsigned int supported_mclk_lrck_ratios[] = {
- 256, 384, 400, 500, 512, 768, 1024
+ 256, 384, 400, 500, 512, 768, 1000, 1024
};
+/* In at least one AMD laptop the internal timing of the codec goes off
+ * if the MCLK (48Mhz) is not divided by 2. So we will divide all MCLK
+ * frequencies above and equal to 48MHz by 2.
+ */
+#define MAX_SUPPORTED_MCLK_FREQ 48000000
+
struct es8316_priv {
struct mutex lock;
struct clk *mclk;
@@ -470,6 +477,7 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,
u8 bclk_divider;
u16 lrck_divider;
int i;
+ unsigned int mclk_div = 1;
/* Validate supported sample rates that are autodetected from MCLK */
for (i = 0; i < NR_SUPPORTED_MCLK_LRCK_RATIOS; i++) {
@@ -482,7 +490,15 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,
}
if (i == NR_SUPPORTED_MCLK_LRCK_RATIOS)
return -EINVAL;
- lrck_divider = es8316->sysclk / params_rate(params);
+
+ if (es8316->sysclk >= MAX_SUPPORTED_MCLK_FREQ) {
+ snd_soc_component_update_bits(component, ES8316_CLKMGR_CLKSW,
+ ES8316_CLKMGR_CLKSW_MCLK_DIV,
+ ES8316_CLKMGR_CLKSW_MCLK_DIV);
+ mclk_div = 2;
+ }
+
+ lrck_divider = es8316->sysclk / params_rate(params) / mclk_div;
bclk_divider = lrck_divider / 4;
switch (params_format(params)) {
case SNDRV_PCM_FORMAT_S16_LE:
diff --git a/sound/soc/codecs/es8316.h b/sound/soc/codecs/es8316.h
index c335138e2837..0ff16f948690 100644
--- a/sound/soc/codecs/es8316.h
+++ b/sound/soc/codecs/es8316.h
@@ -129,4 +129,7 @@
#define ES8316_GPIO_FLAG_GM_NOT_SHORTED 0x02
#define ES8316_GPIO_FLAG_HP_NOT_INSERTED 0x04
+/* ES8316_CLKMGR_CLKSW */
+#define ES8316_CLKMGR_CLKSW_MCLK_DIV 0x80
+
#endif
--
2.41.0
next prev parent reply other threads:[~2023-08-24 21:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-24 21:01 [PATCH v2 0/4] ASoC: amd: acp: Add sound support for a line of HUAWEI laptops Marian Postevca
2023-08-24 21:01 ` [PATCH v2 1/4] ASoC: es8316: Enable support for S32 LE format Marian Postevca
2023-08-24 21:33 ` Mark Brown
2023-08-25 21:55 ` Marian Postevca
2023-08-26 11:24 ` Mark Brown
2023-08-24 21:01 ` Marian Postevca [this message]
2023-08-24 21:53 ` [PATCH v2 2/4] ASoC: es8316: Enable support for MCLK div by 2 Mark Brown
2023-08-27 21:50 ` Marian Postevca
2023-08-28 18:09 ` Mark Brown
2023-08-28 20:22 ` Marian Postevca
2023-08-29 10:18 ` Mark Brown
2023-08-24 21:01 ` [PATCH v2 3/4] ASoC: amd: acp: Add support for splitting the codec specific code from the ACP driver Marian Postevca
2023-08-24 21:01 ` [PATCH v2 4/4] ASoC: amd: acp: Add machine driver that enables sound for systems with a ES8336 codec Marian Postevca
2023-08-24 22:03 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230824210135.19303-3-posteuca@mutex.one \
--to=posteuca@mutex.one \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox