[alsa-devel] Fixing EAPD for STAC9202 on an embedded platform.

Andy Davison andy at dvsn.net
Thu Sep 20 03:31:00 CEST 2018


> On 11 Sep 2018, at 06:53, Takashi Iwai wrote:
> 
> On Tue, 11 Sep 2018 02:24:11 +0200,
> Andy Davison wrote:
>> 
>> 
>>> On 10 Sep 2018, at 21:29, Takashi Iwai wrote:
>>> 
>>> On Mon, 10 Sep 2018 22:01:28 +0200,
>>> Andy Davison wrote:
>>>> 
>>>> 
>>>>> On 10 Sep 2018, at 16:31, Takashi Iwai wrote:
>>>>> 
>>>>> On Mon, 10 Sep 2018 11:51:52 +0200,
>>>>> Andy Davison wrote:
>>>>>> 
>>>>>> Hi everyone,
>>>>>> 
>>>>>> I’m hoping that somebody here might be able to spot where I’m going wrong; I'm working with a picture-frame-like device manufactured by the late OpenPeak Inc. known as the OpenFrame (or O2 Joggler in the UK). It has an internal speaker and a 3.5mm line out socket; none of the other connections to its STAC9202 codec chip are exposed to the end user. I've been porting Ubuntu Bionic to the device and everything is done, except for the audio driver.
>>>>>> 
>>>>>> Back in kernel 3.18 it was possible to use the following kernel patch and userland ALSA patch to have these two outputs work correctly, with the insertion of a plug into the line out properly muting the internal speaker.
>>>>>> 
>>>>>> https://github.com/andydvsn/OpenFrame-Kernel/blob/master/patches/03-stac9202-audio-pin-tweak.patch
>>>>>> https://github.com/andydvsn/OpenFrame-Ubuntu/blob/master/overlay-trusty/lib/firmware/of1-stac9202.patch
>>>>>> 
>>>>>> In kernel 4.14 the same trick no longer works, so I've rewritten the patch to more properly add support for this variant of STAC9202 to ALSA. It now looks like this:
>>>>>> 
>>>>>> https://gist.github.com/andydvsn/7bffa8de0ed691b14508485d75501ffc
>>>>>> 
>>>>>> This seems to line up the pin configurations appropriately, but when a plug is inserted to the line out, although the audio to the internal speaker is muted, the speaker emits a crackling sound whenever the device is processing. It seems that it is not being properly powered down and is amplifying general circuit noise. Disconnecting the plug returns sound to the internal speaker and the crackling ceases. This is reliable across multiple devices.
>>>>> 
>>>>> The patch looks changing too much than needed.
>>>>> 
>>>>> What exactly do you need to make things working at first?
>>>>> patch_stac925x() sets own_eapd_ctl, but only from some historical
>>>>> reason.  You can unset this flag in the quirk as well.
>>>> 
>>>> Thank you for getting back to me. I have recompiled 4.14.69 with no audio patches and the result is as follows:
>>>> 
>>>> 
>>>> - Switching: Presence or absence of line out / headphones is ignored.
>>>> 
>>>> - Auto-Mute Enabled (Default): Crackling is present on the right channel only of line out / headphones. No audio on line out / headphones. Speaker plays audio.
>>>> 
>>>> - Auto-Mute Disabled: Audio plays properly, but from both the speaker and line out / headphones simultaneously.
>>>> 
>>>> 
>>>> So it would seem the action of EAPD is reversed, muting the line out / headphones when they’re attached and not the internal speaker. The crackling remains, but strangely just in that right channel of line out / headphones.
>>> 
>>> Is it really about EAPD, or is it about the jack detection logic or
>>> the incorrect pin config?
>> 
>> That’s a good question.
>> 
>> 
>>> The first item, the missing LO / HP detection rather indicates the pin
>>> config issue.  What is the line out pin and what is the headphone pin?
>> 
>> I’ve managed to grab the codec information from the original, very cut-down, operating system:
>> 
>> https://gist.github.com/andydvsn/47640739d911abc23cc6fc838a59a404#file-codec-0
> 
> I see no patch file.  Did you figure out which pin NID is for the line
> out, which pin NID for headphone, and which for int and ext mics?

For output, from the board it looks as though 0x0a (PORTA_L & PORTA_R) and 0x0d (PORTD_L & PORTD_R) are the only output connections. NID 0x0d looks as though it feeds the internal amplifier; I can’t entirely ascertain the purpose of 0x0a. If I mark 0x0a as not connected in hdajackretask, internal speaker muting stops working, though it appears to lead to an unpopulated area of the board.

Here is the pinout as best I can make out: https://i.imgur.com/lO8hqc8.png

This is the main board (front): https://i.imgur.com/CvYkM7G.jpg

This is the main board (rear): https://i.imgur.com/fYJor9s.jpg


> You can use hdajackretask program to identify and reprogram the pin
> configs.  At least, the pins for I/O with the actual jacks can be
> identified with a jack detection (plugging / unplugging).

This patch makes sense from a labelling perspective, but I’m suspicious that separate HP/LO and internal speaker volumes may not be possible, as if 0x0d feeds the internal amplifier, I assume there is no individual level control.

https://gist.github.com/andydvsn/16bf774d236fdeaa5de22ab0378643c3

As described in the patch, this doesn’t fix the underlying issue of amplified circuit noise through the muted internal speakers. If that could be solved, everything would be working correctly. The kernel 3.18 patch appears to have relied upon 0x07 for this switching, but I’ve had no luck configuring this so far.


>> Hopefully that output makes sense as to what are the internal speakers and which is the LO / HP jack socket.
>> 
>> 
>>> Does the standard jack detection mechanism work for them individually?
>>> 
>>> Let's start from that.
>> 
>> I’m not sure how I would go about testing that; with no patches, inserting anything into the 3.5mm jack socket doesn’t appear to affect the system at all.
>> 
>> 
>>> The fact that the patch_stac925x() sets own_eapd_ctrl flag means that
>>> there is *no* dynamic EAPD bit flip as done in the generic driver.
>>> That is, it's just kept as set in the initialized state.  If EAPD is a
>>> must for some outputs, it has to be set either statically or
>>> dynamically.  But you can hear something if the auto-mute is off, and
>>> it implies that EAPD doesn't matter, actually.
>> 
>> Ah, okay. That’s interesting - yes, with auto-mute disabled the audio comes through the LO / HP socket just fine. It’s only when the auto-mute is active that there’s the issue with crackling.
> 
> The crackling is often because of some bad routing from analog
> loopback.  See whether the loopback is enabled unnecessarily.

There doesn’t appear to be a loopback entry in alsamixer or amixer, so I’m uncertain on how to check for this.

Thank you for your help, I really want to get to the bottom of this!

All the best,

    A.







More information about the Alsa-devel mailing list