Skip to contentSkip to conversation

ASoC: Intel: bytcht_es8316: Determine quirks/routing through ACPI DSM

PATCH Superseded Hans de Goede 2 participants 7 messages Nov 4, 2023 – Nov 18, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ASoC: Intel: bytcht_es8316: Determine quirks/routing through ACPI DSM

Hi All,

This takes some of the work done to auto-configure quirks/routing for ESS83xx codecs by getting the info from ACPI from:
https://github.com/thesofproject/linux/pull/4112

And then builds on top of this to add auto-configuration to the bytcht_es8316 board driver.

Note compared to the pull-request, which deals with the ES8336, this series deals with the ES8316 (for which I have several devices to test on) and this moves all handling from the codec driver to the board driver where this IMHO belongs.

After this series audio now works properly on a CHT Chuwi Hi12 tablet without needing to add an extra quirk for that model.

This has also been tested on the following devices, where things are unchanged from before (the ACPI autoconfiguration gives the same results as the old defaults) :

Onda V80 plus (CHT)
GP-electronic T701 (BYT)

I also tested this on a Nanote UMPC-01, here the _DSM result for PLATFORM_SPK_TYPE_ARG wrongly returns 1 (mono) while the device actually has 2 speakers, so this model needs to keep its DMI quirk.

Regards,

Hans

Hans de Goede (2):
ASoC: Intel: bytcht_es8316: Add is_bytcr helper variable
ASoC: Intel: bytcht_es8316: Determine quirks/routing with codec-dev
ACPI DSM

Pierre-Louis Bossart (2):
ASoC: Intel: es83xx: add ACPI DSM helper module
ASoC: Intel: bytcht_es8316: Dump basic _DSM information

 sound/soc/intel/boards/Kconfig             |   5 +
 sound/soc/intel/boards/Makefile            |   2 +
 sound/soc/intel/boards/bytcht_es8316.c     |  71 +++-
 sound/soc/intel/boards/es83xx-dsm-common.c |  89 +++++
 sound/soc/intel/boards/es83xx-dsm-common.h | 393 +++++++++++++++++++++
 5 files changed, 557 insertions(+), 3 deletions(-)
 create mode 100644 sound/soc/intel/boards/es83xx-dsm-common.c
 create mode 100644 sound/soc/intel/boards/es83xx-dsm-common.h
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/4 ASoC: Intel: es83xx: add ACPI DSM helper module

From: Pierre-Louis Bossart <[email protected]>

Most of the ES83xx codec configuration is exposed in the DSDT table and accessible via a _DSM method. Start adding basic definitions and helpers to dump the information.

---
 sound/soc/intel/boards/Kconfig             |   4 +
 sound/soc/intel/boards/Makefile            |   2 +
 sound/soc/intel/boards/es83xx-dsm-common.c |  89 +++++
 sound/soc/intel/boards/es83xx-dsm-common.h | 393 +++++++++++++++++++++
 4 files changed, 488 insertions(+)
 create mode 100644 sound/soc/intel/boards/es83xx-dsm-common.c
 create mode 100644 sound/soc/intel/boards/es83xx-dsm-common.h
sound/soc/intel/boards/Kconfig +4 -0
index 9e427f00deac..3acd1aefda75 100644
@@ -222,6 +222,10 @@ config SND_SOC_INTEL_BYT_CHT_DA7213_MACH
 	  Say Y or m if you have such a device. This is a recommended option.
 	  If unsure select "N".
 
+config SND_SOC_INTEL_ES83XX_DSM_COMMON
+	depends on ACPI
+	tristate
+
 config SND_SOC_INTEL_BYT_CHT_ES8316_MACH
 	tristate "Baytrail & Cherrytrail with ES8316 codec"
 	depends on I2C && ACPI
sound/soc/intel/boards/Makefile +2 -0
index 943bf8b80e01..02a51373f383 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
+snd-soc-es83xx-dsm-common-objs := es83xx-dsm-common.o
 snd-soc-hsw-rt5640-objs := hsw_rt5640.o
 snd-soc-sst-bdw-rt5650-mach-objs := bdw-rt5650.o
 snd-soc-sst-bdw-rt5677-mach-objs := bdw-rt5677.o
@@ -45,6 +46,7 @@ snd-soc-sof-sdw-objs += sof_sdw.o				\
 			sof_sdw_cs42l42.o sof_sdw_cs42l43.o	\
 			sof_sdw_cs_amp.o			\
 			sof_sdw_hdmi.o
+obj-$(CONFIG_SND_SOC_INTEL_ES83XX_DSM_COMMON) += snd-soc-es83xx-dsm-common.o
 obj-$(CONFIG_SND_SOC_INTEL_SOF_RT5682_MACH) += snd-soc-sof_rt5682.o
 obj-$(CONFIG_SND_SOC_INTEL_SOF_CS42L42_MACH) += snd-soc-sof_cs42l42.o
 obj-$(CONFIG_SND_SOC_INTEL_SOF_ES8336_MACH) += snd-soc-sof_es8336.o
sound/soc/intel/boards/es83xx-dsm-common.c new file +89 -0

89 lines not on this page · raw message

sound/soc/intel/boards/es83xx-dsm-common.h new file +393 -0

393 lines not on this page · raw message

Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/4 ASoC: Intel: bytcht_es8316: Dump basic _DSM information

In reply to Hans de Goede

From: Pierre-Louis Bossart <[email protected]>

Instead of adding DMI quirks for each new tablet model which uses the ESS8316 codec, the plan is to switch to querying the same ACPI Device-Specific-Method (DSM) as Windows uses to determine things like speaker and mic routing.

Call the new es83xx_dsm_dump() helper which logs various basic settings which can be queried through the ACPI DSM method on the codec ACPI device, this is intended to help with developing a DSM based solution to replace most DMI quirks.

---
 sound/soc/intel/boards/Kconfig         | 1 +
 sound/soc/intel/boards/bytcht_es8316.c | 3 +++
 2 files changed, 4 insertions(+)
sound/soc/intel/boards/Kconfig +1 -0
index 3acd1aefda75..77dcb2701ebd 100644
@@ -233,6 +233,7 @@ config SND_SOC_INTEL_BYT_CHT_ES8316_MACH
 	depends on GPIOLIB || COMPILE_TEST
 	select SND_SOC_ACPI
 	select SND_SOC_ES8316
+	select SND_SOC_INTEL_ES83XX_DSM_COMMON
 	help
 	  This adds support for ASoC machine driver for Intel(R) Baytrail &
 	  Cherrytrail platforms with ES8316 audio codec.
sound/soc/intel/boards/bytcht_es8316.c +3 -0
index 8a0b0e864fbb..9a870bbae588 100644
@@ -27,6 +27,7 @@
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
 #include <sound/soc-acpi.h>
+#include "es83xx-dsm-common.h"
 #include "../atom/sst-atom-controls.h"
 #include "../common/soc-intel-quirks.h"
 
@@ -520,6 +521,8 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	es83xx_dsm_dump(priv->codec_dev);
+
 	/* Check for BYTCR or other platform and setup quirks */
 	dmi_id = dmi_first_match(byt_cht_es8316_quirk_table);
 	if (dmi_id) {
Signature · 1 line
2.41.0
#3 lore raw

PATCH 3/4 ASoC: Intel: bytcht_es8316: Add is_bytcr helper variable

In reply to Hans de Goede

Add a is_bytcr helper variable to probe().

This is a preparation patch for determining the quirks through querying the ACPI Device-Specific-Method (DSM) on the codec-device.

---
 sound/soc/intel/boards/bytcht_es8316.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/intel/boards/bytcht_es8316.c +3 -3
index 9a870bbae588..1cdb1ae31a93 100644
@@ -471,10 +471,10 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
 	struct byt_cht_es8316_private *priv;
 	const struct dmi_system_id *dmi_id;
 	struct fwnode_handle *fwnode;
+	bool sof_parent, is_bytcr;
 	const char *platform_name;
 	struct acpi_device *adev;
 	struct device *codec_dev;
-	bool sof_parent;
 	unsigned int cnt = 0;
 	int dai_index = 0;
 	int i;
@@ -524,11 +524,11 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
 	es83xx_dsm_dump(priv->codec_dev);
 
 	/* Check for BYTCR or other platform and setup quirks */
+	is_bytcr = soc_intel_is_byt() && mach->mach_params.acpi_ipc_irq_index == 0;
 	dmi_id = dmi_first_match(byt_cht_es8316_quirk_table);
 	if (dmi_id) {
 		quirk = (unsigned long)dmi_id->driver_data;
-	} else if (soc_intel_is_byt() &&
-		   mach->mach_params.acpi_ipc_irq_index == 0) {
+	} else if (is_bytcr) {
 		/* On BYTCR default to SSP0, internal-mic-in2-map, mono-spk */
 		quirk = BYT_CHT_ES8316_SSP0 | BYT_CHT_ES8316_INTMIC_IN2_MAP |
 			BYT_CHT_ES8316_MONO_SPEAKER;
Signature · 1 line
2.41.0
#4 lore raw

PATCH 4/4 ASoC: Intel: bytcht_es8316: Determine quirks/routing with codec-dev ACPI DSM

In reply to Hans de Goede

Add support for querying the same ACPI Device-Specific-Method (DSM) as Windows uses to determine things like speaker and mic routing.

This avoids the need to add DMI quirks for each new ESS8316 tablet model.

This has been tested on the following devices:

1. Chuwi Hi12 CHT with stereo speakers and IN2-mic-map, this avoids the need to add a DMI quirk for this model.

2. Nanote UMPC-01 CHT with stereo speakers and IN1-mic-map, the existing DMI quirk is still necessary because of a bug in the DSM return values for the speakers (it returns mono).

3. Onda V80 plus CHT with mono speaker and IN1-mic-map, DSM set quirks match the previously used defaults.

4. GP-electronic T701 BYT with mono speaker and IN2-mic-map, DSM set quirks match the previously used defaults.

---
 sound/soc/intel/boards/bytcht_es8316.c | 62 ++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
sound/soc/intel/boards/bytcht_es8316.c +62 -0
index 1cdb1ae31a93..5ca3d41112dc 100644
@@ -462,6 +462,66 @@ static const struct dmi_system_id byt_cht_es8316_quirk_table[] = {
 	{}
 };
 
+static int byt_cht_es8316_get_quirks_from_dsm(struct byt_cht_es8316_private *priv,
+					      bool is_bytcr)
+{
+	int ret, val1, val2, dsm_quirk = 0;
+
+	if (is_bytcr)
+		dsm_quirk |= BYT_CHT_ES8316_SSP0;
+
+	ret = es83xx_dsm(priv->codec_dev, PLATFORM_MAINMIC_TYPE_ARG, &val1);
+	if (ret < 0)
+		return ret;
+
+	ret = es83xx_dsm(priv->codec_dev, PLATFORM_HPMIC_TYPE_ARG, &val2);
+	if (ret < 0)
+		return ret;
+
+	if (val1 == PLATFORM_MIC_AMIC_LIN1RIN1 && val2 == PLATFORM_MIC_AMIC_LIN2RIN2) {
+		dsm_quirk |= BYT_CHT_ES8316_INTMIC_IN1_MAP;
+	} else if (val1 == PLATFORM_MIC_AMIC_LIN2RIN2 && val2 == PLATFORM_MIC_AMIC_LIN1RIN1) {
+		dsm_quirk |= BYT_CHT_ES8316_INTMIC_IN2_MAP;
+	} else {
+		dev_warn(priv->codec_dev, "Unknown mic settings mainmic 0x%02x hpmic 0x%02x\n",
+			 val1, val2);
+		return -EINVAL;
+	}
+
+	ret = es83xx_dsm(priv->codec_dev, PLATFORM_SPK_TYPE_ARG, &val1);
+	if (ret < 0)
+		return ret;
+
+	switch (val1) {
+	case PLATFORM_SPK_MONO:
+		dsm_quirk |= BYT_CHT_ES8316_MONO_SPEAKER;
+		break;
+	case PLATFORM_SPK_STEREO:
+		break;
+	default:
+		dev_warn(priv->codec_dev, "Unknown speaker setting 0x%02x\n", val1);
+		return -EINVAL;
+	}
+
+	ret = es83xx_dsm(priv->codec_dev, PLATFORM_HPDET_INV_ARG, &val1);
+	if (ret < 0)
+		return ret;
+
+	switch (val1) {
+	case PLATFORM_HPDET_NORMAL:
+		break;
+	case PLATFORM_HPDET_INVERTED:
+		dsm_quirk |= BYT_CHT_ES8316_JD_INVERTED;
+		break;
+	default:
+		dev_warn(priv->codec_dev, "Unknown hpdet-inv setting 0x%02x\n", val1);
+		return -EINVAL;
+	}
+
+	quirk = dsm_quirk;
+	return 0;
+}
+
 static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -528,6 +588,8 @@ static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
 	dmi_id = dmi_first_match(byt_cht_es8316_quirk_table);
 	if (dmi_id) {
 		quirk = (unsigned long)dmi_id->driver_data;
+	} else if (!byt_cht_es8316_get_quirks_from_dsm(priv, is_bytcr)) {
+		dev_info(dev, "Using ACPI DSM info for quirks\n");
 	} else if (is_bytcr) {
 		/* On BYTCR default to SSP0, internal-mic-in2-map, mono-spk */
 		quirk = BYT_CHT_ES8316_SSP0 | BYT_CHT_ES8316_INTMIC_IN2_MAP |
Signature · 1 line
2.41.0
#5 lore raw
In reply to Hans de Goede
Quoted 7 lines

This takes some of the work done to auto-configure quirks/routing for ESS83xx codecs by getting the info from ACPI from:
https://github.com/thesofproject/linux/pull/4112

And then builds on top of this to add auto-configuration to the bytcht_es8316 board driver.

Sounds good, thanks for doing this Hans! I only have two minor questions, see below.

Quoted 5 lines

Note compared to the pull-request, which deals with the ES8336, this series deals with the ES8316 (for which I have several devices to test on) and this moves all handling from the codec driver to the board driver where this IMHO belongs.

The ACPI stuff is in theory not Intel-specific, so not sure why it would belong in sound/soc/intel/boards? I initially put the code in sound/soc/codecs since the _DSM method is in the scope of the codec device HID.

Quoted 7 lines

After this series audio now works properly on a CHT Chuwi Hi12 tablet without needing to add an extra quirk for that model.

This has also been tested on the following devices, where things are unchanged from before (the ACPI autoconfiguration gives the same results as the old defaults) :

Quoted 7 lines

Onda V80 plus (CHT)
GP-electronic T701 (BYT)

I also tested this on a Nanote UMPC-01, here the _DSM result for PLATFORM_SPK_TYPE_ARG wrongly returns 1 (mono) while the device actually has 2 speakers, so this model needs to keep its DMI quirk.

What about the two others?

/* Irbis NB41 */
/* Teclast X98 Plus II */

Are they part of your set of devices and could the quirks be removed?

#6 lore raw

Hi Pierre-Louis,

Quoted 16 lines · Pierre-Louis Bossart
Quoted 7 lines

This takes some of the work done to auto-configure quirks/routing for ESS83xx codecs by getting the info from ACPI from:
https://github.com/thesofproject/linux/pull/4112

And then builds on top of this to add auto-configuration to the bytcht_es8316 board driver.

Sounds good, thanks for doing this Hans! I only have two minor questions, see below.

Quoted 5 lines

Note compared to the pull-request, which deals with the ES8336, this series deals with the ES8316 (for which I have several devices to test on) and this moves all handling from the codec driver to the board driver where this IMHO belongs.

Quoted 4 lines

The ACPI stuff is in theory not Intel-specific, so not sure why it would belong in sound/soc/intel/boards? I initially put the code in sound/soc/codecs since the _DSM method is in the scope of the codec device HID.

So my thinking was that the _DSM method is something which the Windows drivers use and since Windows on ARM is all kinda special, that means that this basically is a ACPI-x86 platforms thing.

The mistake which I made is that in my mind I replaced x86 with intel, so then it made sense to put this under sound/soc/intel. But of course there also is AMD (my main workstation actually uses an AMD CPU) and there also is sound/soc/amd .

So thinking about this again I agree that the best place for the _DSM helpers is under sound/soc/codecs, so I'll move them back for v2.

I do believe that at least for the ES8316 case the board driver is the right place to call the helpers though, since there the board driver sets up the MIC and speaker routes.

Quoted 15 lines
Quoted 7 lines

After this series audio now works properly on a CHT Chuwi Hi12 tablet without needing to add an extra quirk for that model.

This has also been tested on the following devices, where things are unchanged from before (the ACPI autoconfiguration gives the same results as the old defaults) :

Quoted 7 lines

Onda V80 plus (CHT)
GP-electronic T701 (BYT)

I also tested this on a Nanote UMPC-01, here the _DSM result for PLATFORM_SPK_TYPE_ARG wrongly returns 1 (mono) while the device actually has 2 speakers, so this model needs to keep its DMI quirk.

Quoted 6 lines

What about the two others?

/* Irbis NB41 */
/* Teclast X98 Plus II */

Are they part of your set of devices

No I don't have these 2 devices in my collection.

Quoted 1 line

and could the quirks be removed?

Maybe, but since I cannot test I have decided
to play it safe and leave the quirks in place.

I'll prepare a v2 series moving the generic _DSM helpers back to sound/soc/codecs.

Regards,

Hans