Skip to contentSkip to conversation

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

PATCH In review Hans de Goede 3 participants 7 messages Dec 2, 2023 – Dec 5, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

Changes in v2:
- Move es83xx-dsm-common.c back to sound/soc/codecs like the original version from: https://github.com/thesofproject/linux/pull/4112/

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 handling of the _DSM from the codec driver to the board driver since with the ES8316 the board driver takes care of setting up various routes for things like the mic and speakers.

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.

I don't have an IRBIS NB41 nor a TECLAST X98 Plus II, so the DMI quirks for those are left in place too on a better safe then sorry basis.

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: es83xx: add ACPI DSM helper module
ASoC: Intel: bytcht_es8316: Dump basic _DSM information

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

PATCH v2 1/4 ASoC: 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.

---
Changes in v2:
- Move es83xx-dsm-common.c back to sound/soc/codecs like the orignal version from: https://github.com/thesofproject/linux/pull/4112/

---
 sound/soc/codecs/Kconfig             |   4 +
 sound/soc/codecs/Makefile            |   2 +
 sound/soc/codecs/es83xx-dsm-common.c |  89 ++++++
 sound/soc/codecs/es83xx-dsm-common.h | 393 +++++++++++++++++++++++++++
 4 files changed, 488 insertions(+)
 create mode 100644 sound/soc/codecs/es83xx-dsm-common.c
 create mode 100644 sound/soc/codecs/es83xx-dsm-common.h
sound/soc/codecs/Kconfig +4 -0
index 3429419ca694..59f9742e9ff4 100644
@@ -1076,6 +1076,10 @@ config SND_SOC_ES7134
 config SND_SOC_ES7241
 	tristate "Everest Semi ES7241 CODEC"
 
+config SND_SOC_ES83XX_DSM_COMMON
+	depends on ACPI
+	tristate
+
 config SND_SOC_ES8316
 	tristate "Everest Semi ES8316 CODEC"
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index 2078bb0d981e..f53baa2b9565 100644
@@ -116,6 +116,7 @@ snd-soc-da9055-objs := da9055.o
 snd-soc-dmic-objs := dmic.o
 snd-soc-es7134-objs := es7134.o
 snd-soc-es7241-objs := es7241.o
+snd-soc-es83xx-dsm-common-objs := es83xx-dsm-common.o
 snd-soc-es8316-objs := es8316.o
 snd-soc-es8326-objs := es8326.o
 snd-soc-es8328-objs := es8328.o
@@ -505,6 +506,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_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
 obj-$(CONFIG_SND_SOC_ES8328)	+= snd-soc-es8328.o
sound/soc/codecs/es83xx-dsm-common.c new file +89 -0

89 lines not on this page · raw message

sound/soc/codecs/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 v2 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 9e427f00deac..7368628e7781 100644
@@ -229,6 +229,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_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..e6ab1ee6ab29 100644
@@ -27,6 +27,7 @@
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
 #include <sound/soc-acpi.h>
+#include "../../codecs/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 v2 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 e6ab1ee6ab29..0d6574678317 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 v2 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 0d6574678317..1564a88a885e 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
Reviewed-by on the v2 series
#5 lore raw
In reply to Hans de Goede
Quoted 30 lines · Hans de Goede

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.

Changes in v2:
- Move es83xx-dsm-common.c back to sound/soc/codecs like the original version from: https://github.com/thesofproject/linux/pull/4112/

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 handling of the _DSM from the codec driver to the board driver since with the ES8316 the board driver takes care of setting up various routes for things like the mic and speakers.

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)

Quoted 8 lines

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.

I don't have an IRBIS NB41 nor a TECLAST X98 Plus II, so the DMI quirks for those are left in place too on a better safe then sorry basis.

Thanks Hans!

maintainer
#6 lore raw
In reply to Hans de Goede
Quoted 8 lines · Hans de Goede

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.

[...]

Applied to

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

Thanks!

[1/4] ASoC: es83xx: add ACPI DSM helper module

      commit: 9c8bec3b63255ca04e5dad87471a35790aec06dc
[2/4] ASoC: Intel: bytcht_es8316: Dump basic _DSM information
      commit: b71e1d3789946a20e0e34349f4a874604ac65c3e
[3/4] ASoC: Intel: bytcht_es8316: Add is_bytcr helper variable
      commit: e8acf91a4013202934313f3c2968e6962daaffff
[4/4] ASoC: Intel: bytcht_es8316: Determine quirks/routing with codec-dev ACPI DSM
      commit: 7650862f4e72d2533356ec001b8ea8d5839aced0

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