Bug 187621

Summary: No sound card detected on HP x2 10-p000
Product: Drivers Reporter: Alexandrov Stanislav (neko)
Component: Sound(ALSA)Assignee: Jaroslav Kysela (perex)
Status: NEW ---    
Severity: normal CC: bardliao, pastas4, pierre-louis.bossart, tiwai, vinod.koul
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 4.8.7 Subsystem:
Regression: No Bisected commit-id:
Attachments: patch with ALC3276 HID
dsdt acpi table from HP x2 10-p000
decompiled dsdt table
dmesg log with patch applied
ucm config
move DAC2 Power to rt5640_dapm_widgets
small diff to HiFi
minor fix for ucm config for rt5640

Description Alexandrov Stanislav 2016-11-14 20:13:17 UTC
Created attachment 244441 [details]
patch with ALC3276 HID

This device is based on intel atom x5-z8350.

According to DSDT there is sound card with HID 10EC3276

            Device (RTKC)
            {
                Name (_ADR, Zero)  // _ADR: Address
                Name (_HID, "10EC3276")  // _HID: Hardware ID
                Name (_CID, "10EC3276")  // _CID: Compatible ID
                Name (_DDN, "ALC3276")  // _DDN: DOS Device Name
                Name (_SUB, "103C827C")  // _SUB: Subsystem ID
                Name (_PR0, Package (0x01)  // _PR0: Power Resources for D0


which in fact is rt5640.

So, i added this HID to rt5640.c and sst_acpi.c (see atttached patch). Sound card is now detected and speakers and headphones (but not microphone yet)
working fine with amixer settings from here https://github.com/burzumishi/linux-baytrail-flexx10/tree/master/sound/alsa_ctrl

aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: bytcrrt5640 [bytcr-rt5640], device 0: 1 []
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: bytcrrt5640 [bytcr-rt5640], device 1: Deep-Buffer Audio (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
Comment 1 Alexandrov Stanislav 2016-11-14 20:14:30 UTC
Created attachment 244451 [details]
dsdt acpi table from HP x2 10-p000
Comment 2 Vinod Koul 2016-11-15 02:42:58 UTC
(In reply to Alexandrov Stanislav from comment #0)
> Created attachment 244441 [details]
> patch with ALC3276 HID
> 
> This device is based on intel atom x5-z8350.
> 
> According to DSDT there is sound card with HID 10EC3276
> 
>             Device (RTKC)
>             {
>                 Name (_ADR, Zero)  // _ADR: Address
>                 Name (_HID, "10EC3276")  // _HID: Hardware ID
>                 Name (_CID, "10EC3276")  // _CID: Compatible ID
>                 Name (_DDN, "ALC3276")  // _DDN: DOS Device Name
>                 Name (_SUB, "103C827C")  // _SUB: Subsystem ID
>                 Name (_PR0, Package (0x01)  // _PR0: Power Resources for D0
> 
> 
> which in fact is rt5640.
> 
> So, i added this HID to rt5640.c and sst_acpi.c (see atttached patch). Sound
> card is now detected and speakers and headphones (but not microphone yet)
> working fine with amixer settings from here
> https://github.com/burzumishi/linux-baytrail-flexx10/tree/master/sound/
> alsa_ctrl
> 
> aplay -l
> **** List of PLAYBACK Hardware Devices ****
> card 0: bytcrrt5640 [bytcr-rt5640], device 0: 1 []
>   Subdevices: 0/1
>   Subdevice #0: subdevice #0
> card 0: bytcrrt5640 [bytcr-rt5640], device 1: Deep-Buffer Audio (*) []
>   Subdevices: 1/1
>   Subdevice #0: subdevice #0

the patch looks fine to me, can you send these change to alsa-devel please and CC me and Pierre
Comment 3 Pierre Bossart 2017-01-03 21:04:06 UTC
First time I see this one, thanks for the information. 
Can you share a human-readable version of your DSDT? Somehow I can't extract the information from the attachment but I do see 10E5640 in the binary.
Also send the result of cat /sys/bus/acpi/devices/10EC*/status
Last for all kernel patches you need to add the --signoff information to the git-format-patch command or we won't touch your changes.

Thanks!
Comment 4 Alexandrov Stanislav 2017-01-03 21:08:58 UTC
Created attachment 249981 [details]
decompiled dsdt table
Comment 5 Alexandrov Stanislav 2017-01-03 21:11:16 UTC
# cat /sys/bus/acpi/devices/10EC
10EC3276:00/ 10EC5640:00/ 10EC5670:00/ 
# cat /sys/bus/acpi/devices/10EC*/status
15
0
0
Comment 6 Alexandrov Stanislav 2017-01-03 21:22:59 UTC
(In reply to Pierre Bossart from comment #3)
> First time I see this one, thanks for the information. 
> Can you share a human-readable version of your DSDT? Somehow I can't extract
> the information from the attachment but I do see 10E5640 in the binary.
> Also send the result of cat /sys/bus/acpi/devices/10EC*/status
> Last for all kernel patches you need to add the --signoff information to the
> git-format-patch command or we won't touch your changes.
> 
> Thanks!

Thanks for replying. I will resend patch to mailing list with signoff information.

Also, internal microphone works fine too, just needed to tweak UCM config.

One note here is when sound card is initializing there is some errors in dmesg:

[    2.905339] rt5640 i2c-10EC3276:00: ASoC: no source widget found for DAC L2 Power
[    2.905342] rt5640 i2c-10EC3276:00: ASoC: Failed to add route DAC L2 Power -> direct -> IF2 DAC L
[    2.905350] rt5640 i2c-10EC3276:00: ASoC: no source widget found for DAC R2 Power
[    2.905352] rt5640 i2c-10EC3276:00: ASoC: Failed to add route DAC R2 Power -> direct -> IF2 DAC R

But however, this doesn't generate any issues.
Comment 7 Alexandrov Stanislav 2017-01-03 21:24:56 UTC
Created attachment 250011 [details]
dmesg log with patch applied
Comment 8 Pierre Bossart 2017-01-03 21:48:25 UTC
Can you share the UCM changes? If you are using DMIC this was never tested on my side so it's interesting.

For the errors I have no idea, you are not using AIF2 so no sure what it complains. Maybe Bard @ Realtek has an idea.
Comment 9 Alexandrov Stanislav 2017-01-03 21:58:45 UTC
Created attachment 250041 [details]
ucm config
Comment 10 Alexandrov Stanislav 2017-01-03 22:08:26 UTC
(In reply to Pierre Bossart from comment #8)
> Can you share the UCM changes? If you are using DMIC this was never tested
> on my side so it's interesting.
> 
> For the errors I have no idea, you are not using AIF2 so no sure what it
> complains. Maybe Bard @ Realtek has an idea.

I have attached my ucm config, it was slightly modified (added HP/Speaker Channel switch)

Umm... looks like i am not using Digital MIC, but internal MIC. Well, if i change in pulseaudio audio input source from internal mic to digital then nothing happens.
Comment 11 Pierre Bossart 2017-01-03 22:24:43 UTC
you seen to be using a very old UCM file, and I can't figure out which changes were made. Can you try comparing with https://github.com/plbossart/UCM/blob/master/bytcr-rt5640/HiFi and let me know which changes are really necessary?

The HP/Speaker Channel switches are already handled, not sure what else you need?
Comment 12 Alexandrov Stanislav 2017-01-03 23:11:08 UTC
(In reply to Pierre Bossart from comment #11)
> you seen to be using a very old UCM file, and I can't figure out which
> changes were made. Can you try comparing with
> https://github.com/plbossart/UCM/blob/master/bytcr-rt5640/HiFi and let me
> know which changes are really necessary?
> 
> The HP/Speaker Channel switches are already handled, not sure what else you
> need?

With this ucm config Speakers and Headphone playback is working, but for some reason internal microphone is not: i just can't enable microphone in pulseaudio. I'll try to find out what is difference.
Comment 13 Pierre Bossart 2017-01-03 23:34:59 UTC
you need to try with either INP1 internal mic or INP3 internal mic, they are not equivalent and correspond to different hardware wirings
Comment 14 Alexandrov Stanislav 2017-01-04 00:44:10 UTC
(In reply to Pierre Bossart from comment #13)
> you need to try with either INP1 internal mic or INP3 internal mic, they are
> not equivalent and correspond to different hardware wirings

do you mean remove/comment INP3 or INP1 from ucm onfig? or just set it as active audio source?

Strange, after reboot and series of alsaucm reset/reload/pulseaudio -k microphone works now, but it uses DigitalMics for some reason, and if i change audio input to another microphone and switch it back then it is doesn't work anymore until i kill pulseaudio.

I have tried to do next things:

1) Remove all mics from config except DigitalMics: mic works
2) Remove everything except IN1: mic doesn't work
3) Remove everything except IN1, but i have commented out this line:
Comment 15 Alexandrov Stanislav 2017-01-04 00:50:45 UTC
I am sorry for incomplete post.

3) Remove everything except IN1, but i have commented out this line:
    cset "name='Mono ADC Capture Switch' on"
   and microphone works.

4) Remove everything except IN3 and mic doesn't work, but after removing line 
   cset "name='Mono ADC Capture Switch' on" microphone works again.

This sound card is definitely not so simple..
Comment 16 Bard Liao 2017-01-04 02:04:43 UTC
(In reply to Alexandrov Stanislav from comment #15)
> 4) Remove everything except IN3 and mic doesn't work, but after removing
> line 
>    cset "name='Mono ADC Capture Switch' on" microphone works again.

That's strange. In theory, 'Mono ADC Capture Switch' should be on if you are using Mono ADC Mixer. Can you dump registers while recording with both 'Mono ADC Capture Switch'on and off cases?
Comment 17 Bard Liao 2017-01-04 02:38:16 UTC
Created attachment 250091 [details]
move DAC2 Power to rt5640_dapm_widgets

(In reply to Alexandrov Stanislav from comment #6)
> One note here is when sound card is initializing there is some errors in
> dmesg:
> 
> [    2.905339] rt5640 i2c-10EC3276:00: ASoC: no source widget found for DAC
> L2 Power
> [    2.905342] rt5640 i2c-10EC3276:00: ASoC: Failed to add route DAC L2
> Power -> direct -> IF2 DAC L
> [    2.905350] rt5640 i2c-10EC3276:00: ASoC: no source widget found for DAC
> R2 Power
> [    2.905352] rt5640 i2c-10EC3276:00: ASoC: Failed to add route DAC R2
> Power -> direct -> IF2 DAC R
> 
> But however, this doesn't generate any issues.

Thanks for the information. It is due to "DAC L2 Power" and "DAC R2 Power" is used by rt5639_specific_dapm_routes[], but is defined in rt5640_specific_dapm_widgets[]. Please apply the attached patch. It should remove the error messages.

Thanks.
Comment 18 Alexandrov Stanislav 2017-01-04 03:16:33 UTC
(In reply to Bard Liao from comment #16)
> (In reply to Alexandrov Stanislav from comment #15)
> > 4) Remove everything except IN3 and mic doesn't work, but after removing
> > line 
> >    cset "name='Mono ADC Capture Switch' on" microphone works again.
> 
> That's strange. In theory, 'Mono ADC Capture Switch' should be on if you are
> using Mono ADC Mixer. Can you dump registers while recording with both 'Mono
> ADC Capture Switch'on and off cases?

Actually, i think this is because i'm using 4.9.0 kernel and "Mono ADC Capture switch" doesn't exist here. Already compiling latest kernel...
Comment 19 Alexandrov Stanislav 2017-01-04 03:42:33 UTC
(In reply to Bard Liao from comment #17)
> 
> Thanks for the information. It is due to "DAC L2 Power" and "DAC R2 Power"
> is used by rt5639_specific_dapm_routes[], but is defined in
> rt5640_specific_dapm_widgets[]. Please apply the attached patch. It should
> remove the error messages.
> 
> Thanks.

Yes. this patch indeed removed that error messages, thanks.
Comment 20 Alexandrov Stanislav 2017-01-04 04:56:41 UTC
Well, now i have removed digitalmics and handset section in ucm config. Only in1 and in3 mics here.

i can change audio source between in1 and in3, microphone works on both of them. This is correct behavior? I thought that this is some kind of hardware ports where microphone connected?

then i've added headset section, looks like everything is fine for now: i can switch between in1, in3 and headset microphone. 

and after that i've added digitalmics section.. i can switch between in1, in3 and headset audio source, but if i switch to digital mic, microphone is still working! After that in1 or in3 doesn't work anymore, but i can switch again to digital mic.

Also there is new error in dmesg when enabling/disabling digitalmic on 4.10-rc2
[   27.801512] rt5640 i2c-10EC3276:00: Failed to set DMIC clock
[   27.801518] rt5640 i2c-10EC3276:00: ASoC: PRE_PMU: DMIC CLK event failed: -22
Comment 21 Alexandrov Stanislav 2017-01-04 04:59:42 UTC
Created attachment 250111 [details]
small diff to HiFi

small diff to HiFi ucm config
Comment 22 Pierre Bossart 2017-01-04 16:17:34 UTC
The patch looks ok, can you send an updated version with your signoff?

I don't think you can have Analog and digital mics enabled on the same device, and you should use the configuration matching what the quirk logs tells you in dmesg.

If you have analog working with INP1 or INP3 maybe it's because the default mixer value is fine or that I don't disable the input when switching to another. Anyway it's a good problem to have :-)

In case there is a dmic, then there is a fix needed, I used to set the sysclk to zero on idle and that should be 24567000. if you want to try replace the zero at this line
https://github.com/plbossart/sound/blob/experimental/codecs/sound/soc/intel/boards/bytcr_rt5640.c#L145
by 24576000
Comment 23 Alexandrov Stanislav 2017-01-04 19:27:37 UTC
(In reply to Pierre Bossart from comment #22)
> The patch looks ok, can you send an updated version with your signoff?
> 
> I don't think you can have Analog and digital mics enabled on the same
> device, and you should use the configuration matching what the quirk logs
> tells you in dmesg.
> 
> If you have analog working with INP1 or INP3 maybe it's because the default
> mixer value is fine or that I don't disable the input when switching to
> another. Anyway it's a good problem to have :-)
>

Yes, mic worked because "Stereo ADC MIXL ADC2" and "Stereo ADC MIXR ADC2" were switched on by default and for some reason if i switch between in1, in3 or headset
this settings won't switched to 'off'. Only if i switch to dmic and then switch back they switched off. This is strange, because when switching to another audio source pulseaudio executing "DisableSequence" for conflicting devices where "Stereo ADC MIX(L/R) ADC2 Switch off" is present. I'm not sure but this looks like bug inside pulseaudio or maybe alsaucm.

Anyway, both microphones: internal digital, and external headset is ok at kernel level.
 
> In case there is a dmic, then there is a fix needed, I used to set the
> sysclk to zero on idle and that should be 24567000. if you want to try
> replace the zero at this line
> https://github.com/plbossart/sound/blob/experimental/codecs/sound/soc/intel/
> boards/bytcr_rt5640.c#L145
> by 24576000

After changing this to 24576000 there is no more errors.
But i wonder, there is comment about jack detection... should this feature work already or it is not implemented yet for rt5640?
Comment 24 Alexandrov Stanislav 2017-01-04 19:29:05 UTC
Created attachment 250261 [details]
minor fix for ucm config for rt5640
Comment 25 Pierre Bossart 2017-01-04 20:01:18 UTC
Jack detection needs multiple quirks and it's not something I have time to work on. But you are welcome to send patches :-)

If you want to look https://github.com/plbossart/sound/commits/byt-jack-detection or https://github.com/plbossart/sound/pull/1

Disclaimer: these patches are not been looked at for a while and you will need of manual work to rebase them. Also it's not clear if they can be upstreamed, in general the jack detection is now part of the codec not of the machine driver.
Comment 26 Alexandrov Stanislav 2017-01-06 00:14:22 UTC
(In reply to Pierre Bossart from comment #25)
> Jack detection needs multiple quirks and it's not something I have time to
> work on. But you are welcome to send patches :-)
> 
> If you want to look
> https://github.com/plbossart/sound/commits/byt-jack-detection or
> https://github.com/plbossart/sound/pull/1
> 
> Disclaimer: these patches are not been looked at for a while and you will
> need of manual work to rebase them. Also it's not clear if they can be
> upstreamed, in general the jack detection is now part of the codec not of
> the machine driver.

Thanks, i'll look at this patches and try at least make jack detection work on my notebook.
Comment 27 Dainius Masiliūnas 2017-05-05 21:24:01 UTC
Any plans to include the sound chip detection patch in mainline? The jack detection part can be added later, I'd imagine.
Comment 28 Dainius Masiliūnas 2017-05-21 13:34:21 UTC
Oh, I just noticed that the detection part was in fact added in kernel 4.11. It works for me too, but only after I execute the amixer commands mentioned in the first post and try to `aplay` a file on the sound card. I wonder why; before doing that, PulseAudio simply fails to start the ALSA card. And there are a whole bunch of knobs in alsamixer that I can't even begin to understand...
Comment 29 Dainius Masiliūnas 2017-07-12 22:19:22 UTC
After doing a bit more research, now I know that this audio chip is quite something... And has a whole bunch of variants. The chip is identified as Baytrail CR, even though this hardware (HP x2 210 here, DSDT identical to OP) is Cherry Trail. And ACPI notes an rt5670 as well. That's pretty confusing. But the bytcr-rt5640 driver seems to work.

And so far my audio hardware has not spontaneously combusted, either, thankfully! Though while trying things out I did mess with a few knobs in alsamixer, which got me a bit uneasy now. Hopefully `alsaucm reset` and `reload` is enough to clear anything that may be unsafe?

And now I also figured out that we're supposed to follow the readme of https://github.com/plbossart/UCM/tree/master/bytcr-rt5640 to set the audio up. Good to know! PulseAudio now has some useful configuration.

Speakers work fine here (better than on Windows, even!). The mic doesn't seem to work when set to IN1 or IN3, but it now works with "DigitalMics capture, NOT TESTED", though the sound captured appears to be pretty low even at 100% in pavucontrol.

I haven't tested headphones yet.