Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve quirks detection for es8336 #4756

Open
wants to merge 13 commits into
base: topic/sof-dev
Choose a base branch
from

Conversation

mchehab
Copy link

@mchehab mchehab commented Dec 29, 2023

Use _DSM table to detect GPIO level and AMIC. This change has @plbossart patches that apply, with some changes as discussed on #4112.

Tested on Huawei Matebook D15 ( BOHB-WAX9):

[    4.825981] es8316 i2c-ESSX8336:00: =========== EM83XX ACPI _DSM TABLE DUMP ===========
[    4.826009] es8316 i2c-ESSX8336:00: PLATFORM_MAINMIC_TYPE_ARG=0xbb
[    4.826023] es8316 i2c-ESSX8336:00: PLATFORM_HPMIC_TYPE_ARG=0xbb
[    4.826038] es8316 i2c-ESSX8336:00: PLATFORM_SPK_TYPE_ARG=0x2
[    4.826054] es8316 i2c-ESSX8336:00: PLATFORM_HPDET_INV_ARG=0x1
[    4.826267] es8316 i2c-ESSX8336:00: PLATFORM_MIC_DE_POP_ARG=0x0
[    4.826499] es8316 i2c-ESSX8336:00: PLATFORM_BUS_SLOT_ARG=0x0
[    4.826521] es8316 i2c-ESSX8336:00: HP_CODEC_LINEIN_PGA_GAIN_ARG=0x6
[    4.826547] es8316 i2c-ESSX8336:00: MAIN_CODEC_LINEIN_PGA_GAIN_ARG=0x8
[    4.826576] es8316 i2c-ESSX8336:00: HP_CODEC_D2SEPGA_GAIN_ARG=0x1
[    4.826606] es8316 i2c-ESSX8336:00: MAIN_CODEC_D2SEPGA_GAIN_ARG=0x1
[    4.826639] es8316 i2c-ESSX8336:00: HP_CODEC_ADC_VOLUME_ARG=0x0
[    4.826675] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_VOLUME_ARG=0x0
[    4.826713] es8316 i2c-ESSX8336:00: HP_CODEC_ADC_ALC_ENABLE_ARG=0x1
[    4.826750] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_ALC_ENABLE_ARG=0x1
[    4.826790] es8316 i2c-ESSX8336:00: HP_CODEC_ADC_ALC_TARGET_LEVEL_ARG=0xa
[    4.826820] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_ALC_TARGET_LEVEL_ARG=0xa
[    4.826845] es8316 i2c-ESSX8336:00: HP_CODEC_ADC_ALC_MAXGAIN_ARG=0x12
[    4.826880] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_ALC_MAXGAIN_ARG=0x12
[    4.826915] es8316 i2c-ESSX8336:00: HP_CODEC_ADC_ALC_MINGAIN_ARG=0x8
[    4.826943] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_ALC_MINGAIN_ARG=0x8
[    4.826977] es8316 i2c-ESSX8336:00: HP_CODEC_ADC_ALC_HLDTIME_ARG=0x0
[    4.827017] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_ALC_HLDTIME_ARG=0x0
[    4.827059] es8316 i2c-ESSX8336:00: HP_CODEC_ADC_ALC_DCYTIME_ARG=0x0
[    4.827117] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_ALC_DCYTIME_ARG=0x0
[    4.827156] es8316 i2c-ESSX8336:00: HP_CODEC_ADC_ALC_ATKTIME_ARG=0x2
[    4.827216] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_ALC_ATKTIME_ARG=0x2
[    4.827278] es8316 i2c-ESSX8336:00: HP_CODEC_ADC_ALC_NGTYPE_ARG=0x3
[    4.827324] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_ALC_NGTYPE_ARG=0x3
[    4.827369] es8316 i2c-ESSX8336:00: HP_CODEC_ADC_ALC_NGTHLD_ARG=0x1
[    4.827407] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_ALC_NGTHLD_ARG=0x1
[    4.827421] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_GUI_STEP_ARG=0x3
[    4.827437] es8316 i2c-ESSX8336:00: MAIN_CODEC_ADC_GUI_GAIN_RANGE_ARG=0x3
[    4.827764] es8316 i2c-ESSX8336:00: HP_CODEC_DAC_HPMIX_HIGAIN_ARG=0x0
[    4.827835] es8316 i2c-ESSX8336:00: SPK_CODEC_DAC_HPMIX_HIGAIN_ARG=0x0
[    4.827965] es8316 i2c-ESSX8336:00: HP_CODEC_DAC_HPMIX_VOLUME_ARG=0xbb
[    4.828018] es8316 i2c-ESSX8336:00: SPK_CODEC_DAC_HPMIX_VOLUME_ARG=0xbb
[    4.828079] es8316 i2c-ESSX8336:00: HP_CODEC_DAC_HPOUT_VOLUME_ARG=0x0
[    4.828147] es8316 i2c-ESSX8336:00: SPK_CODEC_DAC_HPOUT_VOLUME_ARG=0x0
[    4.828194] es8316 i2c-ESSX8336:00: HP_CODEC_LDAC_VOLUME_ARG=0x0
[    4.828265] es8316 i2c-ESSX8336:00: HP_CODEC_RDAC_VOLUME_ARG=0x0
[    4.828345] es8316 i2c-ESSX8336:00: SPK_CODEC_LDAC_VOLUME_ARG=0x0
[    4.828435] es8316 i2c-ESSX8336:00: SPK_CODEC_RDAC_VOLUME_ARG=0x0
[    4.828535] es8316 i2c-ESSX8336:00: HP_CODEC_DAC_AUTOMUTE_ARG=0x0
[    4.828630] es8316 i2c-ESSX8336:00: SPK_CODEC_DAC_AUTOMUTE_ARG=0x1
[    4.828723] es8316 i2c-ESSX8336:00: HP_CODEC_DAC_MONO_ARG=0x0
[    4.828803] es8316 i2c-ESSX8336:00: SPK_CODEC_DAC_MONO_ARG=0x0
[    4.829141] es8316 i2c-ESSX8336:00: SPK_CTL_IO_LEVEL_ARG=0x1
[    4.830289] es8316 i2c-ESSX8336:00: PLATFORM_MCLK_LRCK_FREQ_ARG=0x20
[    4.830292] es8316 i2c-ESSX8336:00: ===================================================
[    4.830312] es8316 i2c-ESSX8336:00: HP jack detect inverted 1
[    4.989925] sof-audio-pci-intel-cnl 0000:00:1f.3:  Topology file:     intel/sof-tplg/sof-cml-es8336-dmic2ch-ssp0.tplg
[    5.120526] es8316 i2c-ESSX8336:00: speaker gpio 1 active high, headphone gpio 0 active low
[    5.147442] es8316 i2c-ESSX8336:00: assuming static mclk

Pluging/unpluging jack events also work as expected, getting "jack unplugged" messages when removing the headset jack:

[    5.194858] es8316 i2c-ESSX8336:00: gpio flags 0x24
[   67.652212] es8316 i2c-ESSX8336:00: gpio flags 0x20
[   67.675464] es8316 i2c-ESSX8336:00: gpio flags 0x22
[   70.690092] es8316 i2c-ESSX8336:00: gpio flags 0x20
[   70.691194] es8316 i2c-ESSX8336:00: gpio flags 0x24
[   70.691550] es8316 i2c-ESSX8336:00: jack unplugged
[  147.101628] es8316 i2c-ESSX8336:00: gpio flags 0x20
[  147.123512] es8316 i2c-ESSX8336:00: gpio flags 0x22
[  186.022655] es8316 i2c-ESSX8336:00: gpio flags 0x20
[  186.024774] es8316 i2c-ESSX8336:00: gpio flags 0x24
[  186.027025] es8316 i2c-ESSX8336:00: jack unplugged
[  251.718579] es8316 i2c-ESSX8336:00: gpio flags 0x20
[  251.740952] es8316 i2c-ESSX8336:00: gpio flags 0x22
[  255.747784] es8316 i2c-ESSX8336:00: gpio flags 0x24
[  255.750680] es8316 i2c-ESSX8336:00: jack unplugged

Also tested basic audio on Matebook 14, although UCM logic for this device very likely needs to be patched to be more generic.

@sofci
Copy link
Collaborator

sofci commented Dec 29, 2023

Can one of the admins verify this patch?

reply test this please to run this test once

plbossart and others added 8 commits December 29, 2023 18:21
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.

Reviewed-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Co-developed-by: David Yang <yangxiaohua@everest-semi.com>
Signed-off-by: David Yang <yangxiaohua@everest-semi.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Read jack detection information from _DSM and pre-set value. The value
may be overridden with a property set by the machine driver.

[mchehab: only override JD inverted from _DSM if quirks is enabled]

Reviewed-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Read jack detection information from _DSM and pre-set value. The value
may be overridden with a property set by the machine driver.

[mchehab: only override JD inverted from _DSM if quirks is enabled]

Reviewed-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
The ACPI entry for es83xx should contain its configuration at
_DSM. It is helpful to debug problems by looking on its contents.

So, add a debug function that outputs its contents as read by the
Kernel.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
The enable GPIOs can either be low or high level activated.

Add a logic to detect it from _DSM.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
The _DSM method has an entry to detect the microphone type,
and where they're attached. Add support for checking it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Now that we can read GPIO enable level from ACPI _DSM, use it
to properly set the right GPIO levels.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Sometimes, the ACPI _DSM may not have a valuet set for
enable on low/high. So, a call to auto-detect it via:

	es83xx_dsm(dev, SPK_CTL_IO_LEVEL_ARG, &value);
and:
	es83xx_dsm(dev, HP_CTL_IO_LEVEL_ARG, &value);

returns 0xff. By default, when this is not defined, the
logic sets to GPIO_CTL_IO_LEVEL_HIGH, which matches the
expected behavior.

However, at least on Huawei Matebook D15 (BOHB-WAX9), setting
them both to GPIO_CTL_IO_LEVEL_HIGH is wrong.

So, add a quirk to ignore BIOS value for such fields.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
@mchehab mchehab force-pushed the sound-es8336 branch 3 times, most recently from 5d2be2f to 3ef3117 Compare December 30, 2023 15:53
@mchehab
Copy link
Author

mchehab commented Dec 30, 2023

Btw, did a quick test today on a different notebook: Huawei 14 2021: BIOS DSM is also not reliable there: quirks are needed. I'll try to add a patch on the top of this series adding support for it, depending on weather I'll be able to keep such notebook long enough to write the patches and test it.

@mchehab
Copy link
Author

mchehab commented Dec 31, 2023

Btw, did a quick test today on a different notebook: Huawei 14 2021: BIOS DSM is also not reliable there: quirks are needed. I'll try to add a patch on the top of this series adding support for it, depending on weather I'll be able to keep such notebook long enough to write the patches and test it.

Matebook 14 (2021) support for internal MIC is not trivial: it uses AMIC on TGL. Currently, it seems that this is not properly supported, as device probe is called with mach_params.dmic_num > 0. Maybe something needs to be changed at firmware topology level?

@mchehab
Copy link
Author

mchehab commented Dec 31, 2023

Btw, did a quick test today on a different notebook: Huawei 14 2021: BIOS DSM is also not reliable there: quirks are needed. I'll try to add a patch on the top of this series adding support for it, depending on weather I'll be able to keep such notebook long enough to write the patches and test it.

Matebook 14 (2021) support is not trivial: it uses AMIC on TGL. Currently, it seems that this is not properly supported. Maybe something needs to be changed at firmware topology level?

Trying to not enable DMIC on Huawei Matebook 14 (after some patches to address it) doesn't work, as sof-audio-pci-intel-tgl complains with:

[ 4.303999] sof-audio-pci-intel-tgl 0000:00:1f.3: Topology: ABI 3:22:1 Kernel ABI 3:23:0
[ 4.304028] sof-audio-pci-intel-tgl 0000:00:1f.3: error: can't connect DAI DMIC0.IN stream dmic01
[ 4.304029] sof-audio-pci-intel-tgl 0000:00:1f.3: error: failed to add widget id 0 type 28 name : DMIC0.IN stream dmic01
[ 4.304032] sof-essx8336 sof-essx8336: ASoC: failed to load widget DMIC0.IN
[ 4.304033] sof-essx8336 sof-essx8336: ASoC: topology: could not load header: -22
[ 4.304037] sof-audio-pci-intel-tgl 0000:00:1f.3: error: tplg component load failed -22
[ 4.304039] sof-audio-pci-intel-tgl 0000:00:1f.3: error: failed to load DSP topology -22
[ 4.304040] sof-audio-pci-intel-tgl 0000:00:1f.3: ASoC: error at snd_soc_component_probe on 0000:00:1f.3: -22
[ 4.304046] sof-essx8336 sof-essx8336: ASoC: failed to instantiate card -22
[ 4.304072] sof-essx8336 sof-essx8336: snd_soc_register_card failed: -22
[ 4.304078] sof-essx8336: probe of sof-essx8336 failed with error -22

I opened a separate issue describing the problem at: #4757

We need that to retrieve data from _DSM table, on an early
check at the driver probe time. So, move the code to the beginning
of the function.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Use the _DSM data to fill the analog microphone ports,
removing another quirk.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
As the headphone could be plugged or unplugged any time, including
when not streaming, and the stop/suspend events may be turning GPIOs
to disable both headphones and speakers, let the delayed workqueue
to be called every time Speaker supply event happens.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Despite what DSM reports, jack detection is not inverted on this
device.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
This notebook also requires quirks as BIOS is incorrect for
speaker/headset GPIOs.

According with _DSM:
	[    4.027413] es8316 i2c-ESSX8336:00: PLATFORM_HPDET_INV_ARG=0x1

However, jack is not inverted on this device.

The speaker/headphone output on this device is:
	speaker gpio 0 active high, headphone gpio 1 active low

However, _DSM reports only:
	[    4.030564] es8316 i2c-ESSX8336:00: SPK_CTL_IO_LEVEL_ARG=0x1
Missing information about headphone active on low.

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
@mchehab
Copy link
Author

mchehab commented Dec 31, 2023

Matebook 14 (2021) support is not trivial: it uses AMIC on TGL. Currently, it seems that this is not properly supported. Maybe something needs to be changed at firmware topology level?

Trying to not enable DMIC on Huawei Matebook 14 (after some patches to address it) doesn't work, as sof-audio-pci-intel-tgl.

Fixed a AMIC probing logic to better cope with AMIC. Still, TGL seems to be relying on having DMIC (perhaps due to UCM settings).

@plbossart
Copy link
Member

@mchehab can you attach the log where the DMIC is used instead of AMIC? The SOF driver relies on the ACPI NHLT table to figure out when to enable the DMICs, if that information is incorrect then yet another quirk is needed.

@plbossart
Copy link
Member

test this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants