Bug 195195

Summary: No audio playback/recording on Dell Venue 8 Pro 5855 tablet with cht-bsw-rt5672
Product: Drivers Reporter: RussianNeuroMancer (russianneuromancer)
Component: Sound(ALSA)Assignee: Jaroslav Kysela (perex)
Status: RESOLVED CODE_FIX    
Severity: normal CC: bardliao, pierre-louis.bossart, tsunghanliu, youling257
Priority: P1    
Hardware: Intel   
OS: Linux   
Kernel Version: 4.12 Subsystem:
Regression: No Bisected commit-id:
Attachments: dsdt.dsl from Dell 5855 (HD/2GB/WiFi+LTE revision)
register dump during audio playback on headphones
5670 regmap plug in/out headphone
5640 regmap plug in/out headphone

Description RussianNeuroMancer 2017-03-31 18:24:47 UTC
cht-bsw-rt5672 driver for audio adapter seems like loading:

~$ dmesg | grep cht-bsw-rt5672
[    9.404400] cht-bsw-rt5672 cht-bsw-rt5672: snd-soc-dummy-dai <-> media-cpu-dai mapping ok
[    9.404452] cht-bsw-rt5672 cht-bsw-rt5672: snd-soc-dummy-dai <-> deepbuffer-cpu-dai mapping ok
[    9.407737] cht-bsw-rt5672 cht-bsw-rt5672: rt5670-aif1 <-> ssp2-port mapping ok
[    9.411880] input: cherrytrailcraudio Headset as /devices/pci0000:00/808622A8:00/cht-bsw-rt5672/sound/card1/input11

~$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Audio [Intel HDMI/DP LPE Audio], device 0: HdmiLpeAudio [Intel HDMI/DP LPE Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: cherrytrailcrau [cherrytrailcraudio], device 0: Audio (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: cherrytrailcrau [cherrytrailcraudio], device 1: Deep-Buffer Audio (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

But only HDMI output is available for PulseAudio:

~$ pacmd list-sink-inputs
1 sink input(s) available.
    index: 13
        driver: <protocol-native.c>
        flags: 
        state: DRAINED
        sink: 0 <alsa_output.pci-0000_00_02.0-platform-hdmi-lpe-audio.analog-stereo>
        volume: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
                balance 0,00
        muted: no
        current latency: 0,00 ms
        requested latency: 125,00 ms
        sample spec: s24le 2-канальный 9600
        channel map: front-left,front-right
                     Стерео
        resample method: speex-float-1
        module: 11
        client: 13 <ALSA plug-in [aplay]>
        properties:
                media.name = "ALSA Playback"
                application.name = "ALSA plug-in [aplay]"
                native-protocol.peer = "UNIX socket client"
                native-protocol.version = "32"
                application.process.id = "2594"
                application.process.user = "nikita"
                application.process.host = "tablet2"
                application.process.binary = "aplay"
                application.language = "ru_RU.UTF-8"
                application.process.machine_id = "cf3bde80787942dc86c6dec44e52cb96"
                application.process.session_id = "4"
                module-stream-restore.id = "sink-input-by-application-name:ALSA plug-in [aplay]"

I guess this is because of lack of UCM-file for cht-bsw-rt5672. 

Dell Venue 8 Pro 5855
BIOS version: 1.7.0, A08
Linux 4.11 from drm-intel-nightly (commit d217cd61ada383a577dc686dd74f77856695ec84) nightly usage was required to get display working.
Ubuntu Gnome 17.04 Beta 2
Comment 1 RussianNeuroMancer 2017-06-04 19:33:14 UTC
With UCM config from https://bugzilla.kernel.org/show_bug.cgi?id=96691#c46 I get 

1. When I playback audio only to left channel - left speaker playback audio.
2. When I playback audio only to right channel - there is silence.
3. Left headphone playback audio from left and right channels, but audio from left channels seems like a bit louder. At the end of audio playback there is crackling sound.
4. Right headphone playback audio from left and right channels, but audio from right channels seems like a bit louder. At the end of audio playback there is crackling sound.
5. Headset microphone is not listed in input sources.
6. Internal microphone is doesn't record anything.
7. No automatic jack detection, so no automatic switch between speakers and headphones/headset.
8. In headphones quiet sounds seems like louder, and for some reason especially voices is always quieter (for example in song - music is always louder than signer voice).
Comment 2 RussianNeuroMancer 2017-07-19 16:22:07 UTC
Created attachment 257613 [details]
dsdt.dsl from Dell 5855 (HD/2GB/WiFi+LTE revision)
Comment 3 youling257 2017-07-23 11:03:41 UTC
thinkpad 8 z3770,alc5672

thinkpad 8 z3795 4GB RAM,alc5672

thinkpad 10 z3795,alc5672
Comment 4 Pierre Bossart 2017-08-19 19:14:02 UTC
I ran a couple of tests with the hardware kindly provided by RussianNeuroMancer (using stock Fedora 26 and just added the UCM file for rt5670 for Lenovo platforms)

There are indeed two problems
1. it doesn't look like there is a right speaker, but that can probably be sorted out by adding a new UCM output device which play right on left

2. there is a jack detection/configuration issue. The UCM file has to be commented out with the JackControl "Headphone Jack" removed to show up in the sound applet, and when I look at the alsa controls same thing 

[plb@Dell5585 ~]$ amixer -Dhw:1 cget  numid=170
numid=170,iface=CARD,name='Headphone Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off

Interestingly the headphone output works even without any configuration but the left and right channels get played on both sides.

@Bard, could you take a look at the registers and maybe suggest something?
Comment 5 Pierre Bossart 2017-08-19 19:16:13 UTC
Created attachment 258027 [details]
register dump during audio playback on headphones
Comment 6 youling257 2017-09-01 15:29:02 UTC
(In reply to Pierre Bossart from comment #5)
> Created attachment 258027 [details]
> register dump during audio playback on headphones

which branch can make speaker working?

i only found these,https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/?qt=grep&q=5670
https://github.com/plbossart/sound/commits/topic/cleanups-before-sof/sound/soc/intel
https://github.com/plbossart/UCM/commits/master

ThinkPad 10 and 8.
Comment 7 youling257 2017-09-01 15:35:02 UTC
(In reply to Pierre Bossart from comment #5)
> Created attachment 258027 [details]
> register dump during audio playback on headphones

https://github.com/plbossart/sound/commits/topic/cleanups-before-sof/
this branch is newest ?
Comment 8 Pierre Bossart 2017-09-01 21:02:08 UTC
(In reply to youling257 from comment #7)
> (In reply to Pierre Bossart from comment #5)
> > Created attachment 258027 [details]
> > register dump during audio playback on headphones
> 
> https://github.com/plbossart/sound/commits/topic/cleanups-before-sof/
> this branch is newest ?

yes and UCM files are up-to-date. The only missing part if the internal mic but I am waiting confirmation from Realtek that I am using the right dmic input (pin 5).
Comment 9 youling257 2017-09-04 16:02:15 UTC
(In reply to Pierre Bossart from comment #4)
> I ran a couple of tests with the hardware kindly provided by
> RussianNeuroMancer (using stock Fedora 26 and just added the UCM file for
> rt5670 for Lenovo platforms)
> 
> There are indeed two problems
> 1. it doesn't look like there is a right speaker, but that can probably be
> sorted out by adding a new UCM output device which play right on left
> 
> 2. there is a jack detection/configuration issue. The UCM file has to be
> commented out with the JackControl "Headphone Jack" removed to show up in
> the sound applet, and when I look at the alsa controls same thing 
> 
> [plb@Dell5585 ~]$ amixer -Dhw:1 cget  numid=170
> numid=170,iface=CARD,name='Headphone Jack'
>   ; type=BOOLEAN,access=r-------,values=1
>   : values=off
> 
> Interestingly the headphone output works even without any configuration but
> the left and right channels get played on both sides.
> 
> @Bard, could you take a look at the registers and maybe suggest something?

which Lenovo platform device ?

I get sound from headphone,only headphone work,speaker no sound,ThinkPad 8.


[   11.233653] intel_sst_acpi 80860F28:00: BYT-CR not detected
[   11.233820] intel_sst_acpi 80860F28:00: LPE base: 0xd0a00000 size:0x200000
[   11.233824] intel_sst_acpi 80860F28:00: IRAM base: 0xd0ac0000
[   11.233884] intel_sst_acpi 80860F28:00: DRAM base: 0xd0b00000
[   11.233892] intel_sst_acpi 80860F28:00: SHIM base: 0xd0b40000
[   11.233901] intel_sst_acpi 80860F28:00: Mailbox base: 0xd0b44000
[   11.233908] intel_sst_acpi 80860F28:00: DDR base: 0x20000000
[   11.234358] intel_sst_acpi 80860F28:00: Got drv data max stream 25
[   11.418853] cht-bsw-rt5672 cht-bsw-rt5672: snd-soc-dummy-dai <-> media-cpu-dai mapping ok
[   11.418902] cht-bsw-rt5672 cht-bsw-rt5672: snd-soc-dummy-dai <-> deepbuffer-cpu-dai mapping ok
[   11.418927] compress asoc: snd-soc-dummy-dai <-> compress-cpu-dai mapping ok
[   11.421839] cht-bsw-rt5672 cht-bsw-rt5672: rt5670-aif1 <-> ssp2-port mapping ok
[   11.428388] input: cht-bsw-rt5672 Headset as /devices/platform/80860F28:00/cht-bsw-rt5672/sound/card0/input5
Comment 10 youling257 2017-09-11 18:31:15 UTC
(In reply to Pierre Bossart from comment #5)
> Created attachment 258027 [details]
> register dump during audio playback on headphones

I get speaker/headphone working,but same problem:
Interestingly the headphone output works even without any configuration but the left and right channels get played on both sides.plug in/out headphone,

if plug in/out,regmap should be different,but them same.
Comment 11 youling257 2017-09-11 18:36:20 UTC
Created attachment 258307 [details]
5670 regmap plug in/out headphone
Comment 12 youling257 2017-09-11 18:37:19 UTC
Created attachment 258309 [details]
5640 regmap plug in/out headphone
Comment 13 Pierre Bossart 2017-09-11 20:26:13 UTC
(In reply to youling257 from comment #10)
> (In reply to Pierre Bossart from comment #5)
> > Created attachment 258027 [details]
> > register dump during audio playback on headphones
> 
> I get speaker/headphone working,but same problem:
> Interestingly the headphone output works even without any configuration but
> the left and right channels get played on both sides.plug in/out headphone,
> 
> if plug in/out,regmap should be different,but them same.

You probably don't have the right jd_mode. Before the quirks I submitted for 4.13, the headphone worked without configuration but left and right were identical.
Comment 14 youling257 2017-09-18 16:21:27 UTC
(In reply to Pierre Bossart from comment #13)
> (In reply to youling257 from comment #10)
> > (In reply to Pierre Bossart from comment #5)
> > > Created attachment 258027 [details]
> > > register dump during audio playback on headphones
> > 
> > I get speaker/headphone working,but same problem:
> > Interestingly the headphone output works even without any configuration but
> > the left and right channels get played on both sides.plug in/out headphone,
> > 
> > if plug in/out,regmap should be different,but them same.
> 
> You probably don't have the right jd_mode. Before the quirks I submitted for
> 4.13, the headphone worked without configuration but left and right were
> identical.

I test 4.14 rc1


[    8.431557] intel_sst_acpi 80860F28:00: BYT-CR not detected
[    8.431701] intel_sst_acpi 80860F28:00: LPE base: 0xd0a00000 size:0x200000
[    8.431704] intel_sst_acpi 80860F28:00: IRAM base: 0xd0ac0000
[    8.431737] intel_sst_acpi 80860F28:00: DRAM base: 0xd0b00000
[    8.431744] intel_sst_acpi 80860F28:00: SHIM base: 0xd0b40000
[    8.431751] intel_sst_acpi 80860F28:00: Mailbox base: 0xd0b44000
[    8.431756] intel_sst_acpi 80860F28:00: DDR base: 0x20000000
[    8.431957] intel_sst_acpi 80860F28:00: Got drv data max stream 25
[    8.473773] rt5640 i2c-10EC5640:01: Device with ID register 0x6271 is not rt5640/39


[    8.704721] bytcr_rt5640 bytcr_rt5640: quirk DMIC1_MAP enabled
[    8.704724] bytcr_rt5640 bytcr_rt5640: quirk DMIC enabled
[    8.704727] bytcr_rt5640 bytcr_rt5640: quirk MCLK_EN enabled
[    8.704750] bytcr_rt5640 bytcr_rt5640: ASoC: CODEC DAI rt5640-aif1 not registered
[    8.704756] bytcr_rt5640 bytcr_rt5640: devm_snd_soc_register_card failed -517
[    8.715507] input: PC Speaker as /devices/platform/pcspkr/input/input6
[    8.716085] bytcr_rt5640 bytcr_rt5640: quirk DMIC1_MAP enabled
[    8.716088] bytcr_rt5640 bytcr_rt5640: quirk DMIC enabled
[    8.716090] bytcr_rt5640 bytcr_rt5640: quirk MCLK_EN enabled
[    8.716120] bytcr_rt5640 bytcr_rt5640: ASoC: CODEC DAI rt5640-aif1 not registered
[    8.716125] bytcr_rt5640 bytcr_rt5640: devm_snd_soc_register_card failed -517
[    8.732905] rt5670 i2c-10EC5640:01: quirk dev_gpio
[    8.732909] rt5670 i2c-10EC5640:01: quirk DMIC enabled
[    8.732911] rt5670 i2c-10EC5640:01: quirk DMIC1 on IN2P pin
[    8.732913] rt5670 i2c-10EC5640:01: quirk JD mode 1

https://github.com/youling257/android-4.9/commits/4.14-rc1

		.callback = byt_thinkpad10_quirk_cb,
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
			DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad 8"),
		},
is it not working on 4.14 kernel ? 
it working on my 4.9 kernel
Comment 15 youling257 2017-09-18 16:22:32 UTC
(In reply to youling257 from comment #10)
> (In reply to Pierre Bossart from comment #5)
> > Created attachment 258027 [details]
> > register dump during audio playback on headphones
> 
> I get speaker/headphone working,but same problem:
> Interestingly the headphone output works even without any configuration but
> the left and right channels get played on both sides.plug in/out headphone,
> 
> if plug in/out,regmap should be different,but them same.

last week,i used my 4.9 kernel,get ThinkPad 8 speaker/headphone working on Android x86
Comment 17 Pierre Bossart 2017-09-18 18:10:49 UTC
(In reply to youling257 from comment #16)
> https://github.com/youling257/android-4.9/commits/August/sound
> 
> https://github.com/youling257/android-4.9/commits/4.14-rc1/sound

There is a magic tool called git bisect. If you don't provide more information on what stopped the audio from working on your platform not sure what help you expect from others.
Comment 18 youling257 2017-09-18 23:06:39 UTC
(In reply to Pierre Bossart from comment #17)
> (In reply to youling257 from comment #16)
> > https://github.com/youling257/android-4.9/commits/August/sound
> > 
> > https://github.com/youling257/android-4.9/commits/4.14-rc1/sound
> 
> There is a magic tool called git bisect. If you don't provide more
> information on what stopped the audio from working on your platform not sure
> what help you expect from others.

you need reply my comment #14,compare dmesg with comment #9

if add thinkpad 8 acpi quirk,should be load cht-bsw_rt5672,right ?

but,4.14 kernel,load bytcr-rt5640
Comment 19 youling257 2017-09-18 23:10:29 UTC
(In reply to Pierre Bossart from comment #17)
> (In reply to youling257 from comment #16)
> > https://github.com/youling257/android-4.9/commits/August/sound
> > 
> > https://github.com/youling257/android-4.9/commits/4.14-rc1/sound
> 
> There is a magic tool called git bisect. If you don't provide more
> information on what stopped the audio from working on your platform not sure
> what help you expect from others.

i just porting a lot of patches to 4.9 kernel,only one patch is add ThinkPad 8 acpi quirk

the 4.14 kernel only need ThinkPad 8 acpi quirk,but quirk not working.
Comment 20 youling257 2017-09-20 18:05:21 UTC
revert 7827d66946ad3af734ed46d1d68c23fa6974595c ,can load correct machine driver for ThinkPad 8 on 4.14 kernel Android x86


[    8.781775] intel_sst_acpi 80860F28:00: BYT-CR not detected
[    8.781959] intel_sst_acpi 80860F28:00: LPE base: 0xd0a00000 size:0x200000
[    8.781963] intel_sst_acpi 80860F28:00: IRAM base: 0xd0ac0000
[    8.782000] intel_sst_acpi 80860F28:00: DRAM base: 0xd0b00000
[    8.782025] intel_sst_acpi 80860F28:00: SHIM base: 0xd0b40000
[    8.782035] intel_sst_acpi 80860F28:00: Mailbox base: 0xd0b44000
[    8.782046] intel_sst_acpi 80860F28:00: DDR base: 0x20000000
[    8.782735] intel_sst_acpi 80860F28:00: Got drv data max stream 25
[    8.820248] rt5670 i2c-10EC5640:01: quirk dev_gpio
[    8.820254] rt5670 i2c-10EC5640:01: quirk DMIC enabled
[    8.820257] rt5670 i2c-10EC5640:01: quirk DMIC1 on IN2P pin
[    8.820260] rt5670 i2c-10EC5640:01: quirk JD mode 1
[    8.952337] cht-bsw-rt5672 cht-bsw-rt5672: snd-soc-dummy-dai <-> media-cpu-dai mapping ok
[    8.952385] cht-bsw-rt5672 cht-bsw-rt5672: snd-soc-dummy-dai <-> deepbuffer-cpu-dai mapping ok
[    8.952410] compress asoc: snd-soc-dummy-dai <-> compress-cpu-dai mapping ok
[    8.953153] cht-bsw-rt5672 cht-bsw-rt5672: rt5670-aif1 <-> ssp2-port mapping ok
[    8.956659] input: cht-bsw-rt5672 Headset as /devices/platform/80860F28:00/cht-bsw-rt5672/sound/card0/input6
Comment 21 Pierre Bossart 2017-09-20 18:18:55 UTC
(In reply to youling257 from comment #20)
> revert 7827d66946ad3af734ed46d1d68c23fa6974595c ,can load correct machine
> driver for ThinkPad 8 on 4.14 kernel Android x86

Humm, this dates from 4.12, so it's not really related to the changes made for rt5670 in my patches.
Can you please trace what is done in this patch to explain what is done wrong?
just add a printk(KERN_ERR and send the log
it could be a mistmatch in a quirk table.
Comment 22 youling257 2017-09-20 18:45:42 UTC
(In reply to Pierre Bossart from comment #21)
> (In reply to youling257 from comment #20)
> > revert 7827d66946ad3af734ed46d1d68c23fa6974595c ,can load correct machine
> > driver for ThinkPad 8 on 4.14 kernel Android x86
> 
> Humm, this dates from 4.12, so it's not really related to the changes made
> for rt5670 in my patches.
> Can you please trace what is done in this patch to explain what is done
> wrong?
> just add a printk(KERN_ERR and send the log
> it could be a mistmatch in a quirk table.

static struct sst_acpi_mach byt_thinkpad_10 = {
	.id = "10EC5640",
	.drv_name = "cht-bsw-rt5672",
	.fw_filename = "intel/fw_sst_0f28.bin",
	.board = "cht-bsw",
	.pdata = &byt_rvp_platform_data,

https://github.com/torvalds/linux/commit/7827d66946ad3af734ed46d1d68c23fa6974595c

cause 10ec5640 can't load cht-bsw-rt5672,revert it can load,just my case on Androidx86.

https://bugzilla.kernel.org/show_bug.cgi?id=96691#c97
Andrew Y only test 4.12 kernel,7827d66946ad3af734ed46d1d68c23fa6974595c begin in 4.13rc1

you need contact Andrew to verify,if he has same case on Ubuntu/Desktop Linux.
Comment 23 Pierre Bossart 2017-09-20 21:05:09 UTC
(In reply to youling257 from comment #22)
> (In reply to Pierre Bossart from comment #21)
> > (In reply to youling257 from comment #20)
> > > revert 7827d66946ad3af734ed46d1d68c23fa6974595c ,can load correct machine
> > > driver for ThinkPad 8 on 4.14 kernel Android x86
> > 
> > Humm, this dates from 4.12, so it's not really related to the changes made
> > for rt5670 in my patches.
> > Can you please trace what is done in this patch to explain what is done
> > wrong?
> > just add a printk(KERN_ERR and send the log
> > it could be a mistmatch in a quirk table.
> 
> static struct sst_acpi_mach byt_thinkpad_10 = {
>       .id = "10EC5640",
>       .drv_name = "cht-bsw-rt5672",
>       .fw_filename = "intel/fw_sst_0f28.bin",
>       .board = "cht-bsw",
>       .pdata = &byt_rvp_platform_data,
> 
> https://github.com/torvalds/linux/commit/
> 7827d66946ad3af734ed46d1d68c23fa6974595c
> 
> cause 10ec5640 can't load cht-bsw-rt5672,revert it can load,just my case on
> Androidx86.
> 
> https://bugzilla.kernel.org/show_bug.cgi?id=96691#c97
> Andrew Y only test 4.12 kernel,7827d66946ad3af734ed46d1d68c23fa6974595c
> begin in 4.13rc1
> 
> you need contact Andrew to verify,if he has same case on Ubuntu/Desktop
> Linux.

Sorry, this is not helping identify the issue. Keep in mind we don't have the hardware handy, so if you do not provide traces or information telling us something useful we are not going to progress.
So please add traces in the routine that supposedly creates the problem as well as in the byt_quirk function. It looks like you are a quirk which is not identified and I have no idea why. Also please share the dmi information and alsa-info.sh.
Comment 24 Pierre Bossart 2017-09-20 21:16:34 UTC
Actually there is something odd here, we don't assign the result of the machine quirk: can you try the fix below?

struct sst_acpi_mach *sst_acpi_find_machine(struct sst_acpi_mach *machines)
{
	struct sst_acpi_mach *mach;

	for (mach = machines; mach->id[0]; mach++) {
		if (sst_acpi_check_hid(mach->id) == true) {

                        if (mach->machine_quirk)
                             mach = mach->machine_quirk(mach);
                        return mach;
  
//			if (mach->machine_quirk == NULL)
//				return mach;

//			if (mach->machine_quirk(mach) != NULL)
//				return mach;
		}
	}
	return NULL;
}
EXPORT_SYMBOL_GPL(sst_acpi_find_machine);
Comment 25 youling257 2017-09-21 01:54:55 UTC
//			if (mach->machine_quirk == NULL)
//				return mach;

//			if (mach->machine_quirk(mach) != NULL)
//				return mach;

???

what different with revert ? https://github.com/youling257/android-4.9/commit/f51bda2b0aeba23e5162e38dc2ff69fac45d718a

just add a printk(KERN_ERR and send the log) ,how to do ?
Comment 26 Pierre Bossart 2017-09-21 14:33:30 UTC
(In reply to youling257 from comment #25)
> //                    if (mach->machine_quirk == NULL)
> //                            return mach;
> 
> //                    if (mach->machine_quirk(mach) != NULL)
> //                            return mach;
> 
> ???

the code is commented out, just use the lines above, they set the mach variable in case there is a quirk.
Comment 27 RussianNeuroMancer 2017-10-04 03:12:09 UTC
Hello, Pierre!

In Commentary 1 I mentioned "At the end of audio playback there is crackling sound" in Item 3 and Item 4.

I find easy way to reproduce this issue:
Playback YouTube video in web-browser, video or audio in mpv or any audio player, or somewhere else, wait until playback is finished, wait 5-15 seconds until app stop playback silence. When it happens, app is closed connection to PulseAudio, and you'll hear crackle.

It's much easier to use headphones to reproduce this issue, by the way this is how this issue disturb most of the time - when, for example, Gnome playback notification sound on every notification, there is loud crackle in headphones on, for example, every new message. (However, it also possible to hear it from speaker if you increase volume level. I just tested this, and I hear it quite clearly every time.)

https://github.com/plbossart/UCM/commit/9639c15027c78a5166c348d048e9ab782e3258fa#diff-ede37ed29620ae7aa535fe39fceabd69

I tested updated UCM, and can confirm that DMIC2 works on Dell 5855. I assume that automatic switch to headset's mic is not supposed to work yet?
Comment 28 Pierre Bossart 2017-10-04 15:01:41 UTC
The codec data sheet shows a set of registers for pop control, not sure which ones are necessary, maybe Realtek can help.
Another work-around is to let PulseAudio play all the time by removing the suspend-on-idle module. You'd take a small battery life hit but this should avoid on/off transitions which create the problem.
Comment 29 RussianNeuroMancer 2017-10-06 19:17:14 UTC
Meanwhile, I find that 4GB/64GB version of Dell 5855 behave differently from 2GB/32GB version. So far I noticed that:

1. If Speaker output is selected as default:
When headphones is not attached and I playback audio only to left channel - speaker playback audio.
When headphones is not attached and I playback audio only to right channel - there is silence.
When headphones is attached left headphone playback audio from left channel and right headphone playback audio from left channel 
So in this setup playback to headphones works as expected, while playback to speaker - not.
2. If MonoSpeaker output is selected as default:
When headphones is not attached speaker playback audio from both channels.
When headphones is attached and I playback audio only to left channel - left headphone playback audio.
When headphones is attached and I playback audio only to right channel - both headphones playback audio.
So in this setup playback to speaker works as expected, while playback to headphones - not.
3. No audio from DMIC2, which works in 2GB version case, as I stated above.

For issue 2 I tried to select MonoSpeaker as starting point, and then find that executing 
amixer -c1 cset name="Stereo DAC MIXL DAC R1 Switch" off
when Headphones is attached get audio from right channel only to right headphone, so I edited UCM like this:

> SectionDevice."Headphones" {
>    Comment "Headphones"
> 
>     Value {
>         PlaybackChannels "2"
>         JackControl "Headphone Jack"
>     }
> 
>     ConflictingDevice [
>         "MonoSpeaker"
>     ]
> 
>     EnableSequence [
>         cdev "hw:chtbswrt5672"
>         cset "name='Headphone Switch' on"
>         cset "name='Stereo DAC MIXL DAC R1 Switch' off"
>     ]
> 
>     DisableSequence [
>         cdev "hw:chtbswrt5672"
>         cset "name='Headphone Switch' off"
>         cset "name='Stereo DAC MIXL DAC R1 Switch' on"
>     ]
> }

However, according to amixer output
> ~$ amixer -c1 cget name="Stereo DAC MIXL DAC R1 Switch"
> numid=230,iface=MIXER,name='Stereo DAC MIXL DAC R1 Switch'
>   ; type=BOOLEAN,access=rw------,values=1
>   : values=on
This line seems like not executed or not applied on headphones attaching. Unless Headphones is selected in Gnome Settings manually, 'Stereo DAC MIXL DAC R1 Switch' remains on.

Did I done something wrong with Headphones EnableSequence or it's some issue?

Same story with DMIC2 mic, "Sto1 ADC MIXL ADC2 Switch" and "Sto1 ADC MIXR ADC2 Switch" was off for some reason (while "Int Mic Switch" so EnableSequence probably was executed) and as soon as I set it to on manually - recording from DMIC2 start working.

Maybe it's related to fact that if you go to Gnome Settings after login Headset Mic is always (after every login) selected as default for some reason? (Even if it was set to DMIC2 before logout/reboot/poweroff.)

Other findings, not sure if it's useful, but anyway:
a).
https://github.com/plbossart/UCM/blob/9639c15027c78a5166c348d048e9ab782e3258fa/cht-bsw-rt5672/HiFi#L272
https://github.com/plbossart/UCM/blob/9639c15027c78a5166c348d048e9ab782e3258fa/cht-bsw-rt5672/HiFi#L303
Probably should be "Stereo1 ADC L2 Mux" or "Stereo1 ADC R2 Mux" instead of "Stereo1 ADC 2 Mux"? "amixer controls -c1" doesn't mention "Stereo1 ADC 2 Mux" control.

b). According to amixer output
> ~$ amixer -c1 cget name="Mono ADC R1 Mux" 
> numid=196,iface=MIXER,name='Mono ADC R1 Mux'
>   ; type=ENUMERATED,access=rw------,values=1,items=2
>   ; Item #0 'Mono DAC MIXR'
>   ; Item #1 'ADC2'
>   : values=0
ADC1 seems like is not an option for "Mono ADC R1 Mux".

https://github.com/plbossart/UCM/blob/9639c15027c78a5166c348d048e9ab782e3258fa/cht-bsw-rt5672/HiFi#L338
https://github.com/plbossart/UCM/blob/9639c15027c78a5166c348d048e9ab782e3258fa/cht-bsw-rt5672/HiFi#L352
Is this Ok, or there should be something different in this line?
Comment 30 RussianNeuroMancer 2017-10-07 05:14:35 UTC
> while "Int Mic Switch" so EnableSequence probably was executed

* while "Int Mic Switch" is on, so
Comment 31 Pierre Bossart 2017-10-09 17:36:04 UTC
I suggest you use the alsa_ucm sequences (see top of HiFi file) with a console and aplay to remove pulseaudio-related issues.

In the case of the mono speaker, there is already a sequence which deals with the R->L mixer, e.g.
https://github.com/plbossart/UCM/blob/master/cht-bsw-rt5672/HiFi#L228

I am not sure why this sequence is not executed when disabling the speaker, that looks like a bug in PulseAudio to me.
Comment 32 RussianNeuroMancer 2018-03-08 18:17:11 UTC
As I understand all necessary patches in upstream since Linux 4.15.