All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: codes: Add support for ES8316 producer mode
@ 2022-07-01  2:05 Zhu Ning
  2022-07-01  9:43 ` Mark Brown
  2022-07-01 13:44 ` Pierre-Louis Bossart
  0 siblings, 2 replies; 5+ messages in thread
From: Zhu Ning @ 2022-07-01  2:05 UTC (permalink / raw)
  To: alsa-devel
  Cc: Zhu Ning, pierre-louis.bossart, tiwai, broonie, vijendar.mukunda,
	David Yang

The AMD acp-es8336 machine driver requires ES8316 run in producer
mode, which is not supported previously.

Signed-off-by: David Yang <yangxiaohua@everest-semi.com>
Signed-off-by: Zhu Ning <zhuning0077@gmail.com>
---
 sound/soc/codecs/es8316.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
index 4407166bb338..34176dc8af8b 100644
--- a/sound/soc/codecs/es8316.c
+++ b/sound/soc/codecs/es8316.c
@@ -401,9 +401,8 @@ static int es8316_set_dai_fmt(struct snd_soc_dai *codec_dai,
 	u8 clksw;
 	u8 mask;
 
-	if ((fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) != SND_SOC_DAIFMT_CBC_CFC) {
-		dev_err(component->dev, "Codec driver only supports consumer mode\n");
-		return -EINVAL;
+	if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBP_CFP) {
+		serdata1|=ES8316_SERDATA1_MASTER;
 	}
 
 	if ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) != SND_SOC_DAIFMT_I2S) {
@@ -464,6 +463,8 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,
 	struct snd_soc_component *component = dai->component;
 	struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
 	u8 wordlen = 0;
+	u8 bclk_divider;
+	u16 lrck_divider;
 	int i;
 
 	/* Validate supported sample rates that are autodetected from MCLK */
@@ -477,19 +478,24 @@ 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);
+	bclk_divider = lrck_divider/4;
 	switch (params_format(params)) {
 	case SNDRV_PCM_FORMAT_S16_LE:
 		wordlen = ES8316_SERDATA2_LEN_16;
+		bclk_divider/=16;
 		break;
 	case SNDRV_PCM_FORMAT_S20_3LE:
 		wordlen = ES8316_SERDATA2_LEN_20;
+		bclk_divider/=32;
 		break;
 	case SNDRV_PCM_FORMAT_S24_LE:
 		wordlen = ES8316_SERDATA2_LEN_24;
+		bclk_divider/=24;
 		break;
 	case SNDRV_PCM_FORMAT_S32_LE:
 		wordlen = ES8316_SERDATA2_LEN_32;
+		bclk_divider/=32;
 		break;
 	default:
 		return -EINVAL;
@@ -499,6 +505,11 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,
 			    ES8316_SERDATA2_LEN_MASK, wordlen);
 	snd_soc_component_update_bits(component, ES8316_SERDATA_ADC,
 			    ES8316_SERDATA2_LEN_MASK, wordlen);
+	snd_soc_component_update_bits(component, ES8316_SERDATA1, 0x1f, bclk_divider);
+	snd_soc_component_update_bits(component, ES8316_CLKMGR_ADCDIV1, 0x0f, lrck_divider >> 8);
+	snd_soc_component_update_bits(component, ES8316_CLKMGR_ADCDIV2, 0xff, lrck_divider & 0xff);
+	snd_soc_component_update_bits(component, ES8316_CLKMGR_DACDIV1, 0x0f, lrck_divider >> 8);
+	snd_soc_component_update_bits(component, ES8316_CLKMGR_DACDIV2, 0xff, lrck_divider & 0xff);
 	return 0;
 }
 
@@ -510,7 +521,7 @@ static int es8316_mute(struct snd_soc_dai *dai, int mute, int direction)
 }
 
 #define ES8316_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
-			SNDRV_PCM_FMTBIT_S24_LE)
+			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
 
 static const struct snd_soc_dai_ops es8316_ops = {
 	.startup = es8316_pcm_startup,
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ASoC: codes: Add support for ES8316 producer mode
  2022-07-01  2:05 [PATCH] ASoC: codes: Add support for ES8316 producer mode Zhu Ning
@ 2022-07-01  9:43 ` Mark Brown
  2022-07-01 13:44 ` Pierre-Louis Bossart
  1 sibling, 0 replies; 5+ messages in thread
From: Mark Brown @ 2022-07-01  9:43 UTC (permalink / raw)
  To: Zhu Ning
  Cc: alsa-devel, vijendar.mukunda, pierre-louis.bossart, David Yang, tiwai

[-- Attachment #1: Type: text/plain, Size: 927 bytes --]

On Fri, Jul 01, 2022 at 10:05:37AM +0800, Zhu Ning wrote:

This looks basically good, a few small things:

> -	if ((fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) != SND_SOC_DAIFMT_CBC_CFC) {
> -		dev_err(component->dev, "Codec driver only supports consumer mode\n");
> -		return -EINVAL;
> +	if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBP_CFP) {
> +		serdata1|=ES8316_SERDATA1_MASTER;
>  	}

There's lots of small coding style things through this - for example
here the { } isn't needed and

> +	lrck_divider = es8316->sysclk/params_rate(params);
> +	bclk_divider = lrck_divider/4;

There's a lot of cases without spaces around /.

>  #define ES8316_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
> -			SNDRV_PCM_FMTBIT_S24_LE)
> +			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)

This is adding S32_LE support which is fine but wasn't mentioned in the
changelog, it should be a separate patch.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ASoC: codes: Add support for ES8316 producer mode
  2022-07-01  2:05 [PATCH] ASoC: codes: Add support for ES8316 producer mode Zhu Ning
  2022-07-01  9:43 ` Mark Brown
@ 2022-07-01 13:44 ` Pierre-Louis Bossart
  1 sibling, 0 replies; 5+ messages in thread
From: Pierre-Louis Bossart @ 2022-07-01 13:44 UTC (permalink / raw)
  To: Zhu Ning, alsa-devel; +Cc: broonie, tiwai, David Yang, vijendar.mukunda


>  	/* Validate supported sample rates that are autodetected from MCLK */
> @@ -477,19 +478,24 @@ 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);
> +	bclk_divider = lrck_divider/4;
>  	switch (params_format(params)) {
>  	case SNDRV_PCM_FORMAT_S16_LE:
>  		wordlen = ES8316_SERDATA2_LEN_16;
> +		bclk_divider/=16;
>  		break;
>  	case SNDRV_PCM_FORMAT_S20_3LE:
>  		wordlen = ES8316_SERDATA2_LEN_20;
> +		bclk_divider/=32;

S20_3LE uses 3 bytes, is the 32 divider correct here?

>  		break;
>  	case SNDRV_PCM_FORMAT_S24_LE:
>  		wordlen = ES8316_SERDATA2_LEN_24;
> +		bclk_divider/=24;>  		break;
>  	case SNDRV_PCM_FORMAT_S32_LE:
>  		wordlen = ES8316_SERDATA2_LEN_32;
> +		bclk_divider/=32;
>  		break;
>  	default:
>  		return -EINVAL;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ASoC: codes: Add support for ES8316 producer mode
  2022-07-04  1:24 Zhu Ning
@ 2022-07-04 15:57 ` Mark Brown
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2022-07-04 15:57 UTC (permalink / raw)
  To: zhuning0077, alsa-devel
  Cc: vijendar.mukunda, tiwai, yangxiaohua, pierre-louis.bossart

On Mon, 4 Jul 2022 09:24:16 +0800, Zhu Ning wrote:
> The AMD acp-es8336 machine driver requires ES8316 run in producer
> mode, which is not supported previously.
> 
> 

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: codes: Add support for ES8316 producer mode
      commit: 3684020a82ff43a64b5a7e42564ee7e2065d3011

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] ASoC: codes: Add support for ES8316 producer mode
@ 2022-07-04  1:24 Zhu Ning
  2022-07-04 15:57 ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Zhu Ning @ 2022-07-04  1:24 UTC (permalink / raw)
  To: alsa-devel
  Cc: Zhu Ning, pierre-louis.bossart, tiwai, broonie, vijendar.mukunda,
	David Yang

The AMD acp-es8336 machine driver requires ES8316 run in producer
mode, which is not supported previously.

Signed-off-by: David Yang <yangxiaohua@everest-semi.com>
Signed-off-by: Zhu Ning <zhuning0077@gmail.com>
---
 sound/soc/codecs/es8316.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
index 4407166bb338..af7706f49dbf 100644
--- a/sound/soc/codecs/es8316.c
+++ b/sound/soc/codecs/es8316.c
@@ -401,10 +401,8 @@ static int es8316_set_dai_fmt(struct snd_soc_dai *codec_dai,
 	u8 clksw;
 	u8 mask;
 
-	if ((fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) != SND_SOC_DAIFMT_CBC_CFC) {
-		dev_err(component->dev, "Codec driver only supports consumer mode\n");
-		return -EINVAL;
-	}
+	if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBP_CFP)
+		serdata1 |= ES8316_SERDATA1_MASTER;
 
 	if ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) != SND_SOC_DAIFMT_I2S) {
 		dev_err(component->dev, "Codec driver only supports I2S format\n");
@@ -464,6 +462,8 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,
 	struct snd_soc_component *component = dai->component;
 	struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
 	u8 wordlen = 0;
+	u8 bclk_divider;
+	u16 lrck_divider;
 	int i;
 
 	/* Validate supported sample rates that are autodetected from MCLK */
@@ -477,19 +477,24 @@ 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);
+	bclk_divider = lrck_divider / 4;
 	switch (params_format(params)) {
 	case SNDRV_PCM_FORMAT_S16_LE:
 		wordlen = ES8316_SERDATA2_LEN_16;
+		bclk_divider /= 16;
 		break;
 	case SNDRV_PCM_FORMAT_S20_3LE:
 		wordlen = ES8316_SERDATA2_LEN_20;
+		bclk_divider /= 20;
 		break;
 	case SNDRV_PCM_FORMAT_S24_LE:
 		wordlen = ES8316_SERDATA2_LEN_24;
+		bclk_divider /= 24;
 		break;
 	case SNDRV_PCM_FORMAT_S32_LE:
 		wordlen = ES8316_SERDATA2_LEN_32;
+		bclk_divider /= 32;
 		break;
 	default:
 		return -EINVAL;
@@ -499,6 +504,11 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,
 			    ES8316_SERDATA2_LEN_MASK, wordlen);
 	snd_soc_component_update_bits(component, ES8316_SERDATA_ADC,
 			    ES8316_SERDATA2_LEN_MASK, wordlen);
+	snd_soc_component_update_bits(component, ES8316_SERDATA1, 0x1f, bclk_divider);
+	snd_soc_component_update_bits(component, ES8316_CLKMGR_ADCDIV1, 0x0f, lrck_divider >> 8);
+	snd_soc_component_update_bits(component, ES8316_CLKMGR_ADCDIV2, 0xff, lrck_divider & 0xff);
+	snd_soc_component_update_bits(component, ES8316_CLKMGR_DACDIV1, 0x0f, lrck_divider >> 8);
+	snd_soc_component_update_bits(component, ES8316_CLKMGR_DACDIV2, 0xff, lrck_divider & 0xff);
 	return 0;
 }
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-07-04 16:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01  2:05 [PATCH] ASoC: codes: Add support for ES8316 producer mode Zhu Ning
2022-07-01  9:43 ` Mark Brown
2022-07-01 13:44 ` Pierre-Louis Bossart
2022-07-04  1:24 Zhu Ning
2022-07-04 15:57 ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.