Re: [PATCH 2/2] ASoC: codecs: add ES7243E ADC driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On 09/07/2024 12:41, Igor Prusov wrote:
> Add support for Everest Semi es7243e, which is a 24 bit, 8 to 48 kHz
> stereo audio ADC with I2C control and I2S output.
> 
> Datasheet: https://www.pawpaw.cn/media/documents/2022-04/ES7243E_DS_pawpaw%E6%9C%A8%E7%93%9C%E7%A7%91%E6%8A%80.pdf
> 
> Signed-off-by: David Yang <yangxiaohua@xxxxxxxxxxxxxxxx>
> Signed-off-by: Igor Prusov <ivprusov@xxxxxxxxxxxxxxxxx>
> Signed-off-by: Viktor Prutyanov <vvprutyanov@xxxxxxxxxxxxxx>
> ---
>  sound/soc/codecs/Kconfig   |   3 +
>  sound/soc/codecs/Makefile  |   2 +
>  sound/soc/codecs/es7243e.c | 676 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 681 insertions(+)
>  create mode 100644 sound/soc/codecs/es7243e.c
> 
> diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
> index 4afc43d3f71f..bfc21073ea24 100644
> --- a/sound/soc/codecs/Kconfig
> +++ b/sound/soc/codecs/Kconfig
> @@ -1097,6 +1097,9 @@ config SND_SOC_ES7134
>  config SND_SOC_ES7241
>  	tristate "Everest Semi ES7241 CODEC"
>  
> +config SND_SOC_ES7243E
> +	tristate "Everest Semi ES7243E CODEC"
> +
>  config SND_SOC_ES83XX_DSM_COMMON
>  	depends on ACPI
>  	tristate
> diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
> index b4df22186e25..9469903662f8 100644
> --- a/sound/soc/codecs/Makefile
> +++ b/sound/soc/codecs/Makefile
> @@ -118,6 +118,7 @@ snd-soc-da9055-y := da9055.o
>  snd-soc-dmic-y := dmic.o
>  snd-soc-es7134-y := es7134.o
>  snd-soc-es7241-y := es7241.o
> +snd-soc-es7243-y := es7243.o
>  snd-soc-es83xx-dsm-common-y := es83xx-dsm-common.o
>  snd-soc-es8316-y := es8316.o
>  snd-soc-es8326-y := es8326.o
> @@ -515,6 +516,7 @@ obj-$(CONFIG_SND_SOC_DA9055)	+= snd-soc-da9055.o
>  obj-$(CONFIG_SND_SOC_DMIC)	+= snd-soc-dmic.o
>  obj-$(CONFIG_SND_SOC_ES7134)	+= snd-soc-es7134.o
>  obj-$(CONFIG_SND_SOC_ES7241)	+= snd-soc-es7241.o
> +obj-$(CONFIG_SND_SOC_ES7243E)	+= snd-soc-es7243e.o
>  obj-$(CONFIG_SND_SOC_ES83XX_DSM_COMMON)    += snd-soc-es83xx-dsm-common.o
>  obj-$(CONFIG_SND_SOC_ES8316)    += snd-soc-es8316.o
>  obj-$(CONFIG_SND_SOC_ES8326)    += snd-soc-es8326.o
> diff --git a/sound/soc/codecs/es7243e.c b/sound/soc/codecs/es7243e.c
> new file mode 100644
> index 000000000000..be877d980cec
> --- /dev/null
> +++ b/sound/soc/codecs/es7243e.c
> @@ -0,0 +1,676 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/**
> + * es7243e.c - ASoC Everest Semiconductor ES7243E audio ADC driver
> + *
> + * Copyright (c) 2024, SaluteDevices. All Rights Reserved.
> + *
> + * Authors: Viktor Prutyanov <vvprutyanov@xxxxxxxxxxxxxx>
> + *	    Igor Prusov <ivprusov@xxxxxxxxxxxxxxxxx>
> + *
> + * Based on ES7243E driver by David Yang <yangxiaohua@xxxxxxxxxxxxxxxx>
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/module.h>
> +#include <linux/moduleparam.h>

Same issues.


> +
> +static const struct regmap_config es7243e_regmap_config = {

But this one is correct...

> +	.reg_bits = 8,
> +	.val_bits = 8,
> +	.max_register = ES7243E_CHIP_VER,
> +	.cache_type = REGCACHE_MAPLE,
> +};
> +
> +struct coeff_div {

declarations go before definitions.

> +	u32 mclk;		/* mclk frequency */
> +	u32 sr_rate;		/* sample rate */
> +	u8 osr;			/* ADC over sample rate */
> +	u8 mclk_pre;		/* mclk prediv/premult */
> +	u8 cf_dsp_div;		/* adclrck divider and daclrck divider */
> +	u8 scale;		/* ADC gain scale up */
> +	u8 lrckdiv;		/* lrck divider */
> +	u8 bclkdiv;		/* sclk divider */
> +};
> +
> +static const struct coeff_div coeff_div[] = {
> +	/* mclk     lrck   osr   pre   div   scale lrdiv bclkdiv */
> +	{ 24576000, 8000,  0x20, 0x50, 0x00, 0x00, 0x0b, 0x2f },
> +	{ 24576000, 12000, 0x20, 0x30, 0x00, 0x00, 0x07, 0x1f },
> +	{ 24576000, 16000, 0x20, 0x20, 0x00, 0x00, 0x05, 0x17 },
> +	{ 24576000, 24000, 0x20, 0x10, 0x00, 0x00, 0x03, 0x0f },
> +	{ 24576000, 32000, 0x20, 0x21, 0x00, 0x00, 0x02, 0x0b },
> +	{ 24576000, 48000, 0x20, 0x00, 0x00, 0x00, 0x01, 0x07 },
> +	{ 12288000, 8000,  0x20, 0x20, 0x00, 0x00, 0x05, 0x17 },
> +	{ 12288000, 12000, 0x20, 0x10, 0x00, 0x00, 0x03, 0x0f },
> +	{ 12288000, 16000, 0x20, 0x21, 0x00, 0x00, 0x02, 0x0b },
> +	{ 12288000, 24000, 0x20, 0x00, 0x00, 0x00, 0x01, 0x07 },
> +	{ 12288000, 32000, 0x20, 0x22, 0x00, 0x00, 0x01, 0x05 },
> +	{ 12288000, 48000, 0x20, 0x01, 0x00, 0x00, 0x00, 0x03 },
> +	{ 6144000,  8000,  0x20, 0x21, 0x00, 0x00, 0x02, 0x0b },
> +	{ 6144000,  12000, 0x20, 0x00, 0x00, 0x00, 0x01, 0x07 },
> +	{ 6144000,  16000, 0x20, 0x22, 0x00, 0x00, 0x01, 0x05 },
> +	{ 6144000,  24000, 0x20, 0x01, 0x00, 0x00, 0x00, 0x03 },
> +	{ 6144000,  32000, 0x20, 0x23, 0x00, 0x00, 0x00, 0x02 },
> +	{ 6144000,  48000, 0x20, 0x02, 0x00, 0x00, 0x00, 0x01 },
> +	{ 3072000,  8000,  0x20, 0x22, 0x00, 0x00, 0x01, 0x05 },
> +	{ 3072000,  12000, 0x20, 0x01, 0x00, 0x00, 0x00, 0x03 },
> +	{ 3072000,  16000, 0x20, 0x23, 0x00, 0x00, 0x00, 0x02 },
> +	{ 3072000,  24000, 0x20, 0x02, 0x00, 0x00, 0x00, 0x01 },
> +	{ 3072000,  32000, 0x10, 0x03, 0x20, 0x04, 0x00, 0x02 },
> +	{ 3072000,  48000, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00 },
> +	{ 1536000,  8000,  0x20, 0x23, 0x00, 0x00, 0x00, 0x02 },
> +	{ 1536000,  12000, 0x20, 0x02, 0x00, 0x00, 0x00, 0x01 },
> +	{ 1536000,  16000, 0x10, 0x03, 0x20, 0x04, 0x00, 0x00 },
> +	{ 1536000,  24000, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00 },
> +	{ 32768000, 8000,  0x20, 0x70, 0x00, 0x00, 0x0f, 0x3f },
> +	{ 32768000, 16000, 0x20, 0x30, 0x00, 0x00, 0x07, 0x1f },
> +	{ 32768000, 32000, 0x20, 0x10, 0x00, 0x00, 0x03, 0x0f },
> +	{ 16384000, 8000,  0x20, 0x30, 0x00, 0x00, 0x07, 0x1f },
> +	{ 16384000, 16000, 0x20, 0x10, 0x00, 0x00, 0x03, 0x0f },
> +	{ 16384000, 32000, 0x20, 0x00, 0x00, 0x00, 0x01, 0x07 },
> +	{ 8192000,  8000,  0x20, 0x10, 0x00, 0x00, 0x03, 0x0f },
> +	{ 8192000,  16000, 0x20, 0x00, 0x00, 0x00, 0x01, 0x07 },
> +	{ 8192000,  32000, 0x20, 0x01, 0x00, 0x00, 0x00, 0x03 },
> +	{ 4096000,  8000,  0x20, 0x00, 0x00, 0x00, 0x01, 0x07 },
> +	{ 4096000,  16000, 0x20, 0x01, 0x00, 0x00, 0x00, 0x03 },
> +	{ 4096000,  32000, 0x20, 0x02, 0x00, 0x00, 0x00, 0x01 },
> +	{ 2048000,  8000,  0x20, 0x01, 0x00, 0x00, 0x00, 0x03 },
> +	{ 2048000,  16000, 0x20, 0x02, 0x00, 0x00, 0x00, 0x01 },
> +	{ 2048000,  32000, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00 },
> +	{ 1024000,  8000,  0x20, 0x02, 0x00, 0x00, 0x00, 0x01 },
> +	{ 1024000,  16000, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00 },
> +	{ 22579200, 11025, 0x20, 0x30, 0x00, 0x00, 0x07, 0x1f },
> +	{ 22579200, 22050, 0x20, 0x10, 0x00, 0x00, 0x03, 0x0f },
> +	{ 22579200, 44100, 0x20, 0x00, 0x00, 0x00, 0x01, 0x07 },
> +	{ 11289600, 11025, 0x20, 0x10, 0x00, 0x00, 0x03, 0x0f },
> +	{ 11289600, 22050, 0x20, 0x00, 0x00, 0x00, 0x01, 0x07 },
> +	{ 11289600, 44100, 0x20, 0x01, 0x00, 0x00, 0x00, 0x03 },
> +	{ 56448000, 11025, 0x20, 0x00, 0x00, 0x00, 0x01, 0x07 },
> +	{ 56448000, 22050, 0x20, 0x01, 0x00, 0x00, 0x00, 0x03 },
> +	{ 56448000, 44100, 0x20, 0x02, 0x00, 0x00, 0x00, 0x01 },
> +	{ 28224000, 11025, 0x20, 0x01, 0x00, 0x00, 0x00, 0x03 },
> +	{ 28224000, 22050, 0x20, 0x02, 0x00, 0x00, 0x00, 0x01 },
> +	{ 28224000, 44100, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00 },
> +	{ 14112000, 11025, 0x20, 0x02, 0x00, 0x00, 0x00, 0x01 },
> +	{ 14112000, 22050, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00 },
> +};
> +
> +static const struct coeff_div *get_coeff(int mclk, int rate)
> +{
> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(coeff_div); i++)
> +		if (coeff_div[i].sr_rate == rate && coeff_div[i].mclk == mclk)
> +			return &coeff_div[i];
> +
> +	return NULL;
> +}
> +
> +static unsigned int rates_12288[] = {

Not a const?

Best regards,
Krzysztof





[Index of Archives]     [Pulseaudio]     [Linux Audio Users]     [ALSA Devel]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux