Skip to contentSkip to conversation

ASoC: amd: acp: Add sound support for a line of HUAWEI laptops

PATCH Superseded Marian Postevca 2 participants 14 messages Aug 24, 2023 – Aug 29, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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 v2:

- Removed patch 4: "ASoC: amd: acp: Improve support for speaker power events". May be resubmitted separately.
- Split the first commit that enabled support for S32 LE format and the MCLK div by 2 option into two separate commits.
- Removed the MCLK div by 2 DT property that was previously enabled by the machine driver. Now it's enabled by the CODEC driver if the MCLK frequency is equal or greater than 48Mhz.
- Used normal conditional statements.
- Removed constraint rates from the machine driver, the CODEC should be able to set them.
- Moved the DAI format configuration.
- Uncoupled the speaker and headphone GPIOs. Now they can be handled independently

Marian Postevca (4):
ASoC: es8316: Enable support for S32 LE format
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 | 449 ++++++++++++++++++
 sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.h |  12 +
 sound/soc/codecs/es8316.c                     |  22 +-
 sound/soc/codecs/es8316.h                     |   3 +
 10 files changed, 724 insertions(+), 15 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
#1 lore raw

PATCH v2 1/4 ASoC: es8316: Enable support for S32 LE format

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 S32 LE format.

---
 sound/soc/codecs/es8316.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/es8316.c +1 -1
index a8f347f1affb..09fc0b25f600 100644
@@ -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
maintainer
#2 lore raw

Re: [PATCH v2 1/4] ASoC: es8316: Enable support for S32 LE format

Quoted 3 lines · Marian Postevca

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 S32 LE format.

What's the issue? The AMD code looks like it supports plenty of other formats in most places.

#3 lore raw

Re: [PATCH v2 1/4] ASoC: es8316: Enable support for S32 LE format

Quoted 6 lines · Mark Brown
Quoted 3 lines

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 S32 LE format.

What's the issue? The AMD code looks like it supports plenty of other formats in most places.

In previous version of the machine driver I used a different CPU component than acp-i2s-sp. For that one, I couldn't get it to have sound unless I specifically requested S32 LE format.

I removed S32_LE from the CODEC to test if it works and it seems it does work with acp-is2-sp. Format S16_LE is chosen by both components and sound can be heard. I guess this patch is not really needed.

maintainer
#4 lore raw

Re: [PATCH v2 1/4] ASoC: es8316: Enable support for S32 LE format

Quoted 4 lines · Marian Postevca

I removed S32_LE from the CODEC to test if it works and it seems it does work with acp-is2-sp. Format S16_LE is chosen by both components and sound can be heard. I guess this patch is not really needed.

If the device supports it it's a good change, it was just the bit about it being a fix that I was querying.

#5 lore raw

PATCH v2 2/4 ASoC: es8316: Enable support for MCLK div by 2

In reply to Marian Postevca

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.

---
 sound/soc/codecs/es8316.c | 20 ++++++++++++++++++--
 sound/soc/codecs/es8316.h |  3 +++
 2 files changed, 21 insertions(+), 2 deletions(-)
sound/soc/codecs/es8316.c +18 -2
index 09fc0b25f600..b506cfb9bd5d 100644
@@ -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:
sound/soc/codecs/es8316.h +3 -0
index c335138e2837..0ff16f948690 100644
@@ -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
maintainer
#6 lore raw

Re: [PATCH v2 2/4] ASoC: es8316: Enable support for MCLK div by 2

sound/soc/codecs/es8316.c line 40

Quoted 5 lines · Marian Postevca
sound/soc/codecs/es8316.c +5 -0
+/* 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

Given that the datasheet quotes a maximum MCLK of 51.2MHz I suspect that this is far too high and that performance is degrading well before this point, it sounds like it just so happens that you noticed issues on a machine with this MCLK rather than that's based on the spec. I would instead suggest applying the MCLK divider in any case where we can do so and still generate suitable clocking for the rest of the system, or at least hit 256fs (the datasheet quotes 256/384fs on the front page which suggests it's targetting 256fs, that'd be a fairly normal number, and there's mention of 12/24MHz USB clocks being directly usable). Doing this should either make no odds or result in better performance.

It's probably also more power efficient to use a lower MCLK, though most likely the difference is marginal. The earlier in the clock tree the divider is applied the lower more of the chip is clocked and all other things being equal a lower clock usually means lower power.

#7 lore raw

Re: [PATCH v2 2/4] ASoC: es8316: Enable support for MCLK div by 2

Quoted 10 lines · Mark Brown

Given that the datasheet quotes a maximum MCLK of 51.2MHz I suspect that this is far too high and that performance is degrading well before this point, it sounds like it just so happens that you noticed issues on a machine with this MCLK rather than that's based on the spec. I would instead suggest applying the MCLK divider in any case where we can do so and still generate suitable clocking for the rest of the system, or at least hit 256fs (the datasheet quotes 256/384fs on the front page which suggests it's targetting 256fs, that'd be a fairly normal number, and there's mention of 12/24MHz USB clocks being directly usable). Doing this should either make no odds or result in better performance.

Not 100% sure what checks should be done for a MCLK to determine if it generates suitable clocking. Would something along this patch make sense?

sound/soc/codecs/es8316.c +28 -11
index a8f347f1affb..667648de8105 100644
@@ -470,19 +470,36 @@ 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;
+
+	do {
+		/* Validate supported sample rates that are autodetected from MCLK */
+		for (i = 0; i < NR_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 == NR_SUPPORTED_MCLK_LRCK_RATIOS) {
+			if (clk == es8316->sysclk)
+				return -EINVAL;
+			else
+				clk = es8316->sysclk;
+		} else {
+			clk_valid = true;
+		}
+	} while(!clk_valid);
 
-	/* Validate supported sample rates that are autodetected from MCLK */
-	for (i = 0; i < NR_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 == NR_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:
maintainer
#8 lore raw

Re: [PATCH v2 2/4] ASoC: es8316: Enable support for MCLK div by 2

Quoted 10 lines · Marian Postevca
Quoted 7 lines · Mark Brown

machine with this MCLK rather than that's based on the spec. I would instead suggest applying the MCLK divider in any case where we can do so and still generate suitable clocking for the rest of the system, or at least hit 256fs (the datasheet quotes 256/384fs on the front page which suggests it's targetting 256fs, that'd be a fairly normal number, and there's mention of 12/24MHz USB clocks being directly usable). Doing this should either make no odds or result in better performance.

Quoted 3 lines

Not 100% sure what checks should be done for a MCLK to determine if it generates suitable clocking. Would something along this patch make sense?

In general a MCLK that allows you to configure the dividers in the CODEC appropriately for use. So long as it works your change looks fine I think modulo.

sound/soc/codecs/es8316.c static int es8316_pcm_hw_params(struct snd_pcm_substream *substream, · line 485

Quoted 10 lines
sound/soc/codecs/es8316.c +10 -0
+	do {
+		/* Validate supported sample rates that are autodetected from MCLK */
+		for (i = 0; i < NR_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;
+		}

Use ARRAY_SIZE()

#9 lore raw

Re: [PATCH v2 2/4] ASoC: es8316: Enable support for MCLK div by 2

Quoted 4 lines · Mark Brown

In general a MCLK that allows you to configure the dividers in the CODEC appropriately for use. So long as it works your change looks fine I think modulo.

Sorry, maybe this question is dumb, but I am not familiar with this expression. What do you mean by "your change looks fine I think modulo"?

Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/es8316.c +4 -0
+	do {
+		/* Validate supported sample rates that are autodetected from MCLK */
+		for (i = 0; i < NR_SUPPORTED_MCLK_LRCK_RATIOS; i++) {
+			const unsigned int ratio = supported_mclk_lrck_ratios[i];
Quoted 9 lines

sound/soc/codecs/es8316.c static int es8316_pcm_hw_params(struct snd_pcm_substream *substream, · line 485

Quoted 6 lines
sound/soc/codecs/es8316.c +6 -0
+
+			if (clk % ratio != 0)
+				continue;
+			if (clk / ratio == params_rate(params))
+				break;
+		}

Use ARRAY_SIZE()

Do you mean instead of all instances of NR_SUPPORTED_MCLK_LRCK_RATIOS? If so, it's already defined as:
#define NR_SUPPORTED_MCLK_LRCK_RATIOS ARRAY_SIZE(supported_mclk_lrck_ratios)

If not, then I don't see where else I could use it.

maintainer
#10 lore raw

Re: [PATCH v2 2/4] ASoC: es8316: Enable support for MCLK div by 2

Quoted 8 lines · Marian Postevca
Quoted 3 lines · Mark Brown

In general a MCLK that allows you to configure the dividers in the CODEC appropriately for use. So long as it works your change looks fine I think modulo.

Sorry, maybe this question is dumb, but I am not familiar with this expression. What do you mean by "your change looks fine I think modulo"?

"modulo" means "apart from".

Quoted 5 lines
Quoted 1 line

Use ARRAY_SIZE()

Do you mean instead of all instances of NR_SUPPORTED_MCLK_LRCK_RATIOS? If so, it's already defined as:
#define NR_SUPPORTED_MCLK_LRCK_RATIOS ARRAY_SIZE(supported_mclk_lrck_ratios)

Yes, that's what I meant - it might be as well to just drop the define then since it's prompting this question at use sites? One of the goals of ARRAY_SIZE() is to avoid having such defines and keep them in sync.

#11 lore raw

PATCH v2 3/4 ASoC: amd: acp: Add support for splitting the codec specific code from the ACP driver

In reply to Marian Postevca

This 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-mach.h | 65 ++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
sound/soc/amd/acp/acp-mach.h +65 -0
index 2b3ec6594023..31f38ec4b1d1 100644
@@ -20,6 +20,10 @@
 
 #define TDM_CHANNELS	8
 
+#define ACP_OPS(priv, cb)	((priv)->ops.cb)
+
+#define acp_get_drvdata(card) ((struct acp_card_drvdata *)(card)->drvdata)
+
 enum be_id {
 	HEADSET_BE_ID = 0,
 	AMP_BE_ID,
@@ -50,6 +54,14 @@ enum platform_end_point {
 	REMBRANDT,
 };
 
+struct acp_mach_ops {
+	int (*probe)(struct snd_soc_card *card);
+	int (*configure_link)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
+	int (*configure_widgets)(struct snd_soc_card *card);
+	int (*suspend_pre)(struct snd_soc_card *card);
+	int (*resume_post)(struct snd_soc_card *card);
+};
+
 struct acp_card_drvdata {
 	unsigned int hs_cpu_id;
 	unsigned int amp_cpu_id;
@@ -61,6 +73,8 @@ struct acp_card_drvdata {
 	unsigned int platform;
 	struct clk *wclk;
 	struct clk *bclk;
+	struct acp_mach_ops ops;
+	void *mach_priv;
 	bool soc_mclk;
 	bool tdm_mode;
 };
@@ -69,4 +83,55 @@ int acp_sofdsp_dai_links_create(struct snd_soc_card *card);
 int acp_legacy_dai_links_create(struct snd_soc_card *card);
 extern const struct dmi_system_id acp_quirk_table[];
 
+static inline int acp_ops_probe(struct snd_soc_card *card)
+{
+	int ret = 1;
+	struct acp_card_drvdata *priv = acp_get_drvdata(card);
+
+	if (ACP_OPS(priv, probe))
+		ret = ACP_OPS(priv, probe)(card);
+	return ret;
+}
+
+static inline int acp_ops_configure_link(struct snd_soc_card *card,
+					 struct snd_soc_dai_link *dai_link)
+{
+	int ret = 1;
+	struct acp_card_drvdata *priv = acp_get_drvdata(card);
+
+	if (ACP_OPS(priv, configure_link))
+		ret = ACP_OPS(priv, configure_link)(card, dai_link);
+	return ret;
+}
+
+static inline int acp_ops_configure_widgets(struct snd_soc_card *card)
+{
+	int ret = 1;
+	struct acp_card_drvdata *priv = acp_get_drvdata(card);
+
+	if (ACP_OPS(priv, configure_widgets))
+		ret = ACP_OPS(priv, configure_widgets)(card);
+	return ret;
+}
+
+static inline int acp_ops_suspend_pre(struct snd_soc_card *card)
+{
+	int ret = 1;
+	struct acp_card_drvdata *priv = acp_get_drvdata(card);
+
+	if (ACP_OPS(priv, suspend_pre))
+		ret = ACP_OPS(priv, suspend_pre)(card);
+	return ret;
+}
+
+static inline int acp_ops_resume_post(struct snd_soc_card *card)
+{
+	int ret = 1;
+	struct acp_card_drvdata *priv = acp_get_drvdata(card);
+
+	if (ACP_OPS(priv, resume_post))
+		ret = ACP_OPS(priv, resume_post)(card);
+	return ret;
+}
+
 #endif
Signature · 1 line
2.41.0
#12 lore raw

PATCH v2 4/4 ASoC: amd: acp: Add machine driver that enables sound for systems with a ES8336 codec

In reply to Marian Postevca

This 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           | 102 +++-
 sound/soc/amd/acp/acp-mach-common.c           |   8 +
 sound/soc/amd/acp/acp-mach.h                  |   2 +
 sound/soc/amd/acp/acp-renoir.c                |   4 +
 sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c | 449 ++++++++++++++++++
 sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.h |  12 +
 8 files changed, 637 insertions(+), 12 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
index f27c27580009..a58d646d28f6 100644
@@ -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
index 4e65fdbc8dca..dc70691bc293 100644
@@ -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 +91 -11

156 lines not on this page · raw message

sound/soc/amd/acp/acp-mach-common.c +8 -0
index a06af82b8056..8f968c12e54a 100644
@@ -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 +2 -0
index 31f38ec4b1d1..b0a3f6bd172f 100644
@@ -47,6 +47,7 @@ enum codec_endpoints {
 	NAU8825,
 	NAU8821,
 	MAX98388,
+	ES83XX,
 };
 
 enum platform_end_point {
@@ -74,6 +75,7 @@ struct acp_card_drvdata {
 	struct clk *wclk;
 	struct clk *bclk;
 	struct acp_mach_ops ops;
+	struct snd_soc_acpi_mach *acpi_mach;
 	void *mach_priv;
 	bool soc_mclk;
 	bool tdm_mode;
sound/soc/amd/acp/acp-renoir.c +4 -0
index 54235cad9cc9..b15cbdf7fa9b 100644
@@ -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 +449 -0

449 lines not on this page · raw message

sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.h new file +12 -0
new file mode 100644
index 000000000000..03551ffdd9da
@@ -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
maintainer
#13 lore raw

Re: [PATCH v2 4/4] ASoC: amd: acp: Add machine driver that enables sound for systems with a ES8336 codec

Quoted 11 lines · Marian Postevca
sound/soc/amd/acp/acp-legacy-mach.c +11 -0
+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;
+}
+

sound/soc/amd/acp/acp-legacy-mach.c static struct acp_card_drvdata rt5682s_rt1019_rmb_data = { · line 118

Quoted 10 lines
sound/soc/amd/acp/acp-legacy-mach.c +10 -0
+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;
+}

This feels like it should've been part of the prior commit adding support for more complex cards?

sound/soc/amd/acp/acp-legacy-mach.c static int acp_asoc_probe(struct platform_device *pdev) · line 141

Quoted 3 lines
sound/soc/amd/acp/acp-legacy-mach.c +3 -0
+	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;

Similarly these changes in probe() -

sound/soc/amd/acp/acp-legacy-mach.c static const struct platform_device_id board_ids[] = { · line 208

Quoted 4 lines
sound/soc/amd/acp/acp-legacy-mach.c +4 -0
+	{
+		.name = "acp3x-es83xx",
+		.driver_data = (kernel_ulong_t)&es83xx_rn_data,
+	},

The main thing I'd expect to see in the generic code in a patch adding a specific driver is table entries like this and the ones you had earlier.

sound/soc/amd/acp/acp-mach-common.c int acp_legacy_dai_links_create(struct snd_soc_card *card) · line 1561

Quoted 7 lines
sound/soc/amd/acp/acp-mach-common.c +7 -0
+		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;
+			}
+		}

This function should ideally have been using switch statemnts but that's not an issue your patch introduced.

sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c line 66

Quoted 9 lines
sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c new file +8 -0
+#define ES83XX_ENABLE_DMIC	BIT(4)
+#define ES83XX_48_MHZ_MCLK	BIT(5)
 
+static void acp3x_es83xx_set_gpios_values(struct acp3x_es83xx_private *priv,
+					  bool speaker, bool headphone)
+{
+	gpiod_set_value_cansleep(priv->gpio_speakers, speaker);
+	gpiod_set_value_cansleep(priv->gpio_headphone, headphone);
+}

I'm not clear what this function buys us other than just calling gpiolib directly in the DAPM events?

Otherewise the actual machine driver looks good.