ASoC: amd: acp: Add sound support for a line of HUAWEI laptops
Subsystems (3)
v3 cover ASoC: amd: acp: Add sound support for a line of HUAWEI laptops
This series adds support for a line of HUAWEI laptops with AMD CPUs that connect using the ACP3x module to a ES8336 CODEC.
The CODEC driver must be extended to support the S32 LE format and the MCLK div by 2 option. MCLK div by 2 is needed for one specific SKU, which uses a 48Mhz MCLK, which seems to be too high of a frequency for the CODEC and must be divided by 2.
The acp legacy driver must also be extended by using callbacks so that the more complicated handling of this specific CODEC can be moved outside the more generic ACP code.
Changes in v3:
- Modified commit message for patch 1: ASoC: es8316: Enable support for S32 LE format. The commit message implied that S32 LE format is the only one that is supported by the machine driver. The AMD ACP supports a wide variety of formats that are also supported by the CODEC. Now the purpose of the patch is to enable one additional format that is supported by the CODEC chip.
- Added new patch: Replace NR_SUPPORTED_MCLK_LRCK_RATIOS with ARRAY_SIZE() No need to have a special define when we can use ARRAY_SIZE() directly.
- Reworked the MCLK div by 2 option. Now the CODEC driver will first try to use halved frequency by checking if it can generate suitable clocking. If it can not, then the full MCLK will be used. In this way we can also support unknown SKU that have a too high MCLK frequency.
- Moved generic ACP code from patch 5, that introduces the new machine driver, to patch 4, that introduces ACP legacy callback mechanism.
- Removed the forced S32 LE format in the new machine driver.
Marian Postevca (5):
ASoC: es8316: Enable support for S32 LE format
ASoC: es8316: Replace NR_SUPPORTED_MCLK_LRCK_RATIOS with ARRAY_SIZE()
ASoC: es8316: Enable support for MCLK div by 2
ASoC: amd: acp: Add support for splitting the codec specific code from
the ACP driver
ASoC: amd: acp: Add machine driver that enables sound for systems with
a ES8336 codec
sound/soc/amd/acp-config.c | 70 +++ sound/soc/amd/acp/Makefile | 2 +- sound/soc/amd/acp/acp-legacy-mach.c | 102 +++- sound/soc/amd/acp/acp-mach-common.c | 8 + sound/soc/amd/acp/acp-mach.h | 67 +++ sound/soc/amd/acp/acp-renoir.c | 4 + sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c | 443 ++++++++++++++++++ sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.h | 12 + sound/soc/codecs/es8316.c | 52 +- sound/soc/codecs/es8316.h | 3 + 10 files changed, 736 insertions(+), 27 deletions(-) create mode 100644 sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c create mode 100644 sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.h
Signature · 1 line
2.41.0
PATCH v3 1/5 ASoC: es8316: Enable support for S32 LE format
This CODEC does support the S32 LE format in es8316_pcm_hw_params(), but doesn't have it enabled in ES8316_FORMATS. Enable it so that we have more options to match with components.
--- sound/soc/codecs/es8316.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/es8316.c +1 -1
@@ -526,7 +526,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,
Signature · 1 line
2.41.0
PATCH v3 2/5 ASoC: es8316: Replace NR_SUPPORTED_MCLK_LRCK_RATIOS with ARRAY_SIZE()
In reply to Marian PostevcaNo need for a special define since we can use ARRAY_SIZE() directly, and won't need to worry to keep it in sync.
--- sound/soc/codecs/es8316.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
sound/soc/codecs/es8316.c +4 -5
@@ -27,7 +27,6 @@* MCLK/LRCK ratios, but we also add ratio 400, which is commonly used on * Intel Cherry Trail platforms (19.2MHz MCLK, 48kHz LRCK). */ -#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 };
@@ -40,7 +39,7 @@ struct es8316_priv {struct snd_soc_jack *jack;int irq;unsigned int sysclk; -unsigned int allowed_rates[NR_SUPPORTED_MCLK_LRCK_RATIOS ]; +unsigned int allowed_rates[ARRAY_SIZE (supported_mclk_lrck_ratios)];struct snd_pcm_hw_constraint_list sysclk_constraints;bool jd_inverted; };
@@ -382,7 +381,7 @@ static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai,/* Limit supported sample rates to ones that can be autodetected * by the codec running in slave mode. */ -for (i =0 ; i <NR_SUPPORTED_MCLK_LRCK_RATIOS ; i++) { +for (i =0 ; i <ARRAY_SIZE (supported_mclk_lrck_ratios); i++) {const unsigned int ratio = supported_mclk_lrck_ratios[i];if (freq % ratio ==0 )
@@ -472,7 +471,7 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,int i;/* Validate supported sample rates that are autodetected from MCLK */ -for (i =0 ; i <NR_SUPPORTED_MCLK_LRCK_RATIOS ; i++) { +for (i =0 ; i <ARRAY_SIZE (supported_mclk_lrck_ratios); i++) {const unsigned int ratio = supported_mclk_lrck_ratios[i];if (es8316->sysclk % ratio !=0 )
@@ -480,7 +479,7 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,if (es8316->sysclk / ratio ==params_rate (params))break ; } -if (i ==NR_SUPPORTED_MCLK_LRCK_RATIOS ) +if (i ==ARRAY_SIZE (supported_mclk_lrck_ratios))return -EINVAL ; lrck_divider = es8316->sysclk /params_rate (params); bclk_divider = lrck_divider /4 ;
Signature · 1 line
2.41.0
PATCH v3 3/5 ASoC: es8316: Enable support for MCLK div by 2
In reply to Marian PostevcaTo properly support a line of Huawei laptops with an AMD CPU and an ES8336 codec connected to the ACP3X module, we need to enable the codec option to divide the MCLK by 2. This is needed because for at least one SKU that has a 48Mhz MCLK the sound is distorted unless the MCLK div by 2 option is enabled.
The option to divide the MCLK will first be tried. If no suitable clocking can be generated from this frequency, then the normal non-halved MCLK frequency will be tried.
--- sound/soc/codecs/es8316.c | 45 +++++++++++++++++++++++++++++---------- sound/soc/codecs/es8316.h | 3 +++ 2 files changed, 37 insertions(+), 11 deletions(-)
sound/soc/codecs/es8316.c +34 -11
@@ -469,19 +469,42 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,u8 bclk_divider;u16 lrck_divider;int i; +unsigned int clk = es8316->sysclk /2 ; +bool clk_valid = false; + +/* We will start with halved sysclk and see if we can use it +* for proper clocking. This is to minimise the risk of running +* the CODEC with a too high frequency. We have an SKU where +* the sysclk frequency is 48Mhz and this causes the sound to be +* sped up. If we can run with a halved sysclk, we will use it, +* if we can't use it, then full sysclk will be used. +*/ +do { +/* Validate supported sample rates that are autodetected from MCLK */ +for (i =0 ; i <ARRAY_SIZE (supported_mclk_lrck_ratios); i++) { +const unsigned int ratio = supported_mclk_lrck_ratios[i]; + +if (clk % ratio !=0 ) +continue ; +if (clk / ratio ==params_rate (params)) +break ; + } +if (i ==ARRAY_SIZE (supported_mclk_lrck_ratios)) { +if (clk == es8316->sysclk) +return -EINVAL ; + clk = es8316->sysclk; + }else { + clk_valid = true; + } + }while (!clk_valid); -/* Validate supported sample rates that are autodetected from MCLK */ -for (i =0 ; i <ARRAY_SIZE (supported_mclk_lrck_ratios); i++) { -const unsigned int ratio = supported_mclk_lrck_ratios[i]; - -if (es8316->sysclk % ratio !=0 ) -continue ; -if (es8316->sysclk / ratio ==params_rate (params)) -break ; +if (clk != es8316->sysclk) { +snd_soc_component_update_bits (component,ES8316_CLKMGR_CLKSW , +ES8316_CLKMGR_CLKSW_MCLK_DIV , +ES8316_CLKMGR_CLKSW_MCLK_DIV ); } -if (i ==ARRAY_SIZE (supported_mclk_lrck_ratios)) -return -EINVAL ; - lrck_divider = es8316->sysclk /params_rate (params); + + lrck_divider = clk /params_rate (params); bclk_divider = lrck_divider /4 ;switch (params_format (params)) {case SNDRV_PCM_FORMAT_S16_LE :
sound/soc/codecs/es8316.h +3 -0
@@ -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
Signature · 1 line
2.41.0
PATCH v3 4/5 ASoC: amd: acp: Add support for splitting the codec specific code from the ACP driver
In reply to Marian PostevcaThis commit adds support for splitting more complicated machine drivers, that need special handling, from the generic ACP code.
By adding support for callbacks to configure and handle codec specific implementation details, we can split them in separate files that don't clutter the ACP code.
--- sound/soc/amd/acp/acp-legacy-mach.c | 82 +++++++++++++++++++++++++---- sound/soc/amd/acp/acp-mach.h | 66 +++++++++++++++++++++++ 2 files changed, 137 insertions(+), 11 deletions(-)
sound/soc/amd/acp/acp-legacy-mach.c +71 -11
@@ -75,6 +75,33 @@ static struct acp_card_drvdata rt5682s_rt1019_rmb_data = { .tdm_mode = false, }; +static bool acp_asoc_init_ops (struct acp_card_drvdata *priv) +{ +return false; +} + +static int acp_asoc_suspend_pre (struct snd_soc_card *card) +{ +int ret; + + ret =acp_ops_suspend_pre (card); +if (ret ==1 ) +return 0 ; +else +return ret; +} + +static int acp_asoc_resume_post (struct snd_soc_card *card) +{ +int ret; + + ret =acp_ops_resume_post (card); +if (ret ==1 ) +return 0 ; +else +return ret; +} +static int acp_asoc_probe (struct platform_device *pdev) {struct snd_soc_card *card =NULL ;
@@ -83,35 +110,68 @@ static int acp_asoc_probe(struct platform_device *pdev)struct acp_card_drvdata *acp_card_drvdata;int ret; -if (!pdev->id_entry) -return -EINVAL ; +if (!pdev->id_entry) { + ret = -EINVAL ; + goto out; + } card =devm_kzalloc (dev,sizeof (*card),GFP_KERNEL ); -if (!card) -return -ENOMEM ; +if (!card) { + ret = -ENOMEM ; + goto out; + } + card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data; + acp_card_drvdata = card->drvdata; + acp_card_drvdata->acpi_mach = (struct snd_soc_acpi_mach *)pdev->dev.platform_data; card->dev = dev; card->owner =THIS_MODULE ; card->name = pdev->id_entry->name; - card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data; -/* Widgets and controls added per-codec in acp-mach-common.c */ - acp_card_drvdata = card->drvdata; +acp_asoc_init_ops (card->drvdata); + +/* If widgets and controls are not set in specific callback, +* they will be added per-codec in acp-mach-common.c +*/ + ret =acp_ops_configure_widgets (card); +if (ret <0 ) { +dev_err (&pdev->dev, +"Cannot configure widgets for card (%s): %d\n" , + card->name, ret); + goto out; + } + card->suspend_pre = acp_asoc_suspend_pre; + card->resume_post = acp_asoc_resume_post; + + ret =acp_ops_probe (card); +if (ret <0 ) { +dev_err (&pdev->dev, +"Cannot probe card (%s): %d\n" , + card->name, ret); + goto out; + } + dmi_id =dmi_first_match (acp_quirk_table);if (dmi_id && dmi_id->driver_data) acp_card_drvdata->tdm_mode = dmi_id->driver_data; -acp_legacy_dai_links_create (card); + ret =acp_legacy_dai_links_create (card); +if (ret) { +dev_err (&pdev->dev, +"Cannot create dai links for card (%s): %d\n" , + card->name, ret); + goto out; + } ret =devm_snd_soc_register_card (&pdev->dev, card);if (ret) {dev_err (&pdev->dev,"devm_snd_soc_register_card(%s) failed: %d\n" , card->name, ret); -return ret; + goto out; } - -return 0 ; +out: +return ret; }static const struct platform_device_id board_ids[] = {
sound/soc/amd/acp/acp-mach.h +66 -0
88 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH v3 5/5 ASoC: amd: acp: Add machine driver that enables sound for systems with a ES8336 codec
In reply to Marian PostevcaThis commit enables sound for a line of Huawei laptops that use the ES8336 codec which is connected to the ACP3X module.
--- sound/soc/amd/acp-config.c | 70 +++ sound/soc/amd/acp/Makefile | 2 +- sound/soc/amd/acp/acp-legacy-mach.c | 22 +- sound/soc/amd/acp/acp-mach-common.c | 8 + sound/soc/amd/acp/acp-mach.h | 1 + sound/soc/amd/acp/acp-renoir.c | 4 + sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c | 443 ++++++++++++++++++ sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.h | 12 + 8 files changed, 560 insertions(+), 2 deletions(-) create mode 100644 sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c create mode 100644 sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.h
sound/soc/amd/acp-config.c +70 -0
@@ -61,6 +61,76 @@ static const struct config_entry config_table[] = { {} }, }, + { + .flags = FLAG_AMD_LEGACY, + .device = ACP_PCI_DEV_ID, + .dmi_table = (const struct dmi_system_id []) { + { + .matches = { +DMI_EXACT_MATCH (DMI_BOARD_VENDOR ,"HUAWEI" ), +DMI_EXACT_MATCH (DMI_PRODUCT_NAME ,"KLVL-WXXW" ), +DMI_EXACT_MATCH (DMI_PRODUCT_VERSION ,"M1010" ), + }, + }, + {} + }, + }, + { + .flags = FLAG_AMD_LEGACY, + .device = ACP_PCI_DEV_ID, + .dmi_table = (const struct dmi_system_id []) { + { + .matches = { +DMI_EXACT_MATCH (DMI_BOARD_VENDOR ,"HUAWEI" ), +DMI_EXACT_MATCH (DMI_PRODUCT_NAME ,"KLVL-WXX9" ), +DMI_EXACT_MATCH (DMI_PRODUCT_VERSION ,"M1010" ), + }, + }, + {} + }, + }, + { + .flags = FLAG_AMD_LEGACY, + .device = ACP_PCI_DEV_ID, + .dmi_table = (const struct dmi_system_id []) { + { + .matches = { +DMI_EXACT_MATCH (DMI_BOARD_VENDOR ,"HUAWEI" ), +DMI_EXACT_MATCH (DMI_PRODUCT_NAME ,"BOM-WXX9" ), +DMI_EXACT_MATCH (DMI_PRODUCT_VERSION ,"M1010" ), + }, + }, + {} + }, + }, + { + .flags = FLAG_AMD_LEGACY, + .device = ACP_PCI_DEV_ID, + .dmi_table = (const struct dmi_system_id []) { + { + .matches = { +DMI_EXACT_MATCH (DMI_BOARD_VENDOR ,"HUAWEI" ), +DMI_EXACT_MATCH (DMI_PRODUCT_NAME ,"HVY-WXX9" ), +DMI_EXACT_MATCH (DMI_PRODUCT_VERSION ,"M1020" ), + }, + }, + {} + }, + }, + { + .flags = FLAG_AMD_LEGACY, + .device = ACP_PCI_DEV_ID, + .dmi_table = (const struct dmi_system_id []) { + { + .matches = { +DMI_EXACT_MATCH (DMI_BOARD_VENDOR ,"HUAWEI" ), +DMI_EXACT_MATCH (DMI_PRODUCT_NAME ,"HVY-WXX9" ), +DMI_EXACT_MATCH (DMI_PRODUCT_VERSION ,"M1040" ), + }, + }, + {} + }, + }, };int snd_amd_acp_find_config (struct pci_dev *pci)
sound/soc/amd/acp/Makefile +1 -1
@@ -17,7 +17,7 @@ snd-acp-rembrandt-objs := acp-rembrandt.o #machine specific driver snd-acp-mach-objs := acp-mach-common.o -snd-acp-legacy-mach-objs := acp-legacy-mach.o +snd-acp-legacy-mach-objs := acp-legacy-mach.o acp3x-es83xx/acp3x-es83xx.o snd-acp-sof-mach-objs := acp-sof-mach.o obj-$(CONFIG_SND_SOC_AMD_ACP_PCM) += snd-acp-pcm.o
sound/soc/amd/acp/acp-legacy-mach.c +21 -1
@@ -20,6 +20,7 @@#include <linux/module.h> #include "acp-mach.h" +#include "acp3x-es83xx/acp3x-es83xx.h" static struct acp_card_drvdata rt5682_rt1019_data = { .hs_cpu_id =I2S_SP ,
@@ -51,6 +52,14 @@ static struct acp_card_drvdata rt5682s_rt1019_data = { .tdm_mode = false, }; +static struct acp_card_drvdata es83xx_rn_data = { + .hs_cpu_id =I2S_SP , + .dmic_cpu_id =DMIC , + .hs_codec_id =ES83XX , + .dmic_codec_id =DMIC , + .platform =RENOIR , +}; +static struct acp_card_drvdata max_nau8825_data = { .hs_cpu_id =I2S_HS , .amp_cpu_id =I2S_HS ,
@@ -77,7 +86,13 @@ static struct acp_card_drvdata rt5682s_rt1019_rmb_data = {static bool acp_asoc_init_ops (struct acp_card_drvdata *priv) { -return false; +bool has_ops = false; + +if (priv->hs_codec_id ==ES83XX ) { + has_ops = true; +acp3x_es83xx_init_ops (&priv->ops); + } +return has_ops; }static int acp_asoc_suspend_pre (struct snd_soc_card *card)
@@ -187,6 +202,10 @@ static const struct platform_device_id board_ids[] = { .name = "acp3xalc5682s1019", .driver_data = (kernel_ulong_t)&rt5682s_rt1019_data, }, + { + .name = "acp3x-es83xx", + .driver_data = (kernel_ulong_t)&es83xx_rn_data, + }, { .name = "rmb-nau8825-max", .driver_data = (kernel_ulong_t)&max_nau8825_data,
@@ -213,6 +232,7 @@ MODULE_DESCRIPTION("ACP chrome audio support");MODULE_ALIAS ("platform:acp3xalc56821019" );MODULE_ALIAS ("platform:acp3xalc5682sm98360" );MODULE_ALIAS ("platform:acp3xalc5682s1019" ); +MODULE_ALIAS ("platform:acp3x-es83xx" );MODULE_ALIAS ("platform:rmb-nau8825-max" );MODULE_ALIAS ("platform:rmb-rt5682s-rt1019" );MODULE_LICENSE ("GPL v2" );
sound/soc/amd/acp/acp-mach-common.c +8 -0
@@ -1513,6 +1513,7 @@ int acp_legacy_dai_links_create(struct snd_soc_card *card)struct device *dev = card->dev;struct acp_card_drvdata *drv_data = card->drvdata;int i =0 , num_links =0 ; +int rc;if (drv_data->hs_cpu_id) num_links++;
@@ -1551,6 +1552,13 @@ int acp_legacy_dai_links_create(struct snd_soc_card *card) links[i].init = acp_card_rt5682s_init; links[i].ops = &acp_card_rt5682s_ops; } +if (drv_data->hs_codec_id ==ES83XX ) { + rc =acp_ops_configure_link (card, &links[i]); +if (rc !=0 ) { +dev_err (dev,"Failed to configure link for ES83XX: %d\n" , rc); +return rc; + } + } i++; }
sound/soc/amd/acp/acp-mach.h +1 -0
@@ -47,6 +47,7 @@ enum codec_endpoints {NAU8825 ,NAU8821 ,MAX98388 , + ES83XX, }; enum platform_end_point {
sound/soc/amd/acp/acp-renoir.c +4 -0
@@ -69,6 +69,10 @@ static struct snd_soc_acpi_mach snd_soc_acpi_amd_acp_machines[] = { .id = "AMDI1019", .drv_name = "renoir-acp", }, + { + .id = "ESSX8336", + .drv_name = "acp3x-es83xx", + }, {}, };
sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c new file +443 -0
443 lines not on this page · raw message
sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright 2023 Marian Postevca <[email protected]> +*/ + +#ifndef __ACP3X_ES83XX_H +#define __ACP3X_ES83XX_H + +void acp3x_es83xx_init_ops (struct acp_mach_ops *ops); + +#endif +
Signature · 1 line
2.41.0
Mark Brown
maintainerQuoted 9 lines · Marian Postevca
This series adds support for a line of HUAWEI laptops with AMD CPUs that connect using the ACP3x module to a ES8336 CODEC.
The CODEC driver must be extended to support the S32 LE format and the MCLK div by 2 option. MCLK div by 2 is needed for one specific SKU, which uses a 48Mhz MCLK, which seems to be too high of a frequency for the CODEC and must be divided by 2.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/5] ASoC: es8316: Enable support for S32 LE format
commit: 2f06f231f0bfe74711fee14e28a8789a3de9bc36
[2/5] ASoC: es8316: Replace NR_SUPPORTED_MCLK_LRCK_RATIOS with ARRAY_SIZE()
commit: a43c0dc1004cbe2edbae9b6e6793db71f6896449
[3/5] ASoC: es8316: Enable support for MCLK div by 2
commit: 869f30782cdad0a86598a700a864e4a2bf44f8cc
[4/5] ASoC: amd: acp: Add support for splitting the codec specific code from the ACP driver
commit: c680f57095411559e7605af689c7ce01f2281005
[5/5] ASoC: amd: acp: Add machine driver that enables sound for systems with a ES8336 codec
commit: 54fcd9dd44b2c82a0262e29b288c2d0b36c6bba5All 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