Bug 213415

Summary: Wrong setting for Elitepad 1000 G2
Product: Drivers Reporter: Zhihao Wang (wangzhihao9)
Component: Sound(ALSA)Assignee: Jaroslav Kysela (perex)
Status: RESOLVED CODE_FIX    
Severity: high CC: jwrdegoede, pierre-louis.bossart
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: All Subsystem:
Regression: No Bisected commit-id:
Attachments: The chip on the board "ALC5642"
DSDT.dsl
dmesg info, which contains many drivers' bugs.
The sound card, ALC5642
The whole nice device, but with bad sound card and bad atom isp.
The driver from hp for windows
attachment-14316-0.html
attachment-16497-0.html
attachment-25755-0.html
attachment-29776-0.html
attachment-19723-0.html

Description Zhihao Wang 2021-06-11 13:06:22 UTC
Created attachment 297325 [details]
The chip on the board "ALC5642"

It need to be confirmed.

https://github.com/torvalds/linux/commit/55fc205600ff3b529631cfe03b58645e3844bd92#diff-c17e112b5db46deaa4c89b4acfe20aebf7f6d0cdc7c55c6266ac70a834bba99b
It breaks my microphone, headset and headphone. But the speakers work correctly. It’s so strange.

My Elitepad 1000 G2 is using rt5642 but not rt5640.
I get it by tearing down the device.
The commit is wrong.

It need to check if there are really some device using rt5640.
Comment 1 Zhihao Wang 2021-06-11 13:07:30 UTC
Besides, the quirk of this device need to be change too.
I will try to modify it and anything I can to help you.
Comment 2 Zhihao Wang 2021-06-11 13:19:27 UTC
Only the speaker works.
It seems that rt5640.c handled it incorrectly.
from the DSDT.dsl (i saw it uses SSP1 ?? )

It likes https://bugzilla.kernel.org/show_bug.cgi?id=86581
But nothing has done for this device. I will have a try later.
Comment 3 Zhihao Wang 2021-06-11 13:23:55 UTC
Created attachment 297327 [details]
DSDT.dsl
Comment 4 Zhihao Wang 2021-06-11 13:49:28 UTC
https://bugzilla.kernel.org/show_bug.cgi?id=187331

I have tried all the quirk, but nothing changed.
I found that the microphone inside should be directed to the microphone jack.
This device has two digital microphones and a 4 pin jack module with a lot of wires.
Comment 6 Zhihao Wang 2021-06-11 13:54:37 UTC
Created attachment 297331 [details]
dmesg info, which contains many drivers' bugs.
Comment 7 Zhihao Wang 2021-06-11 14:00:57 UTC
Created attachment 297335 [details]
The sound card, ALC5642
Comment 8 Zhihao Wang 2021-06-11 14:23:45 UTC
Created attachment 297339 [details]
The whole nice device, but with bad sound card and bad atom isp.
Comment 9 Zhihao Wang 2021-06-11 14:40:14 UTC
(In reply to Zhihao Wang from comment #2)
> Only the speaker works.
> It seems that rt5640.c handled it incorrectly.
> from the DSDT.dsl (i saw it uses SSP1 ?? )
> 
> It likes https://bugzilla.kernel.org/show_bug.cgi?id=86581
> But nothing has done for this device. I will have a try later.

https://github.com/torvalds/linux/blob/master/sound/soc/intel/common/soc-acpi-intel-byt-match.c

The elitepad 1000 g2 is non-CR device. But I found nothing in here.
I didn't know too much about the sound card driver. Sorry.
Comment 10 Zhihao Wang 2021-06-11 14:41:33 UTC
(In reply to Zhihao Wang from comment #9)
> (In reply to Zhihao Wang from comment #2)
> > Only the speaker works.
> > It seems that rt5640.c handled it incorrectly.
> > from the DSDT.dsl (i saw it uses SSP1 ?? )
> > 
> > It likes https://bugzilla.kernel.org/show_bug.cgi?id=86581
> > But nothing has done for this device. I will have a try later.
> 
> https://github.com/torvalds/linux/blob/master/sound/soc/intel/common/soc-
> acpi-intel-byt-match.c
> 
> The elitepad 1000 g2 is non-CR device. But I found nothing in here.
> I didn't know too much about the sound card driver. Sorry.

I find it, Sorry.
Comment 11 Zhihao Wang 2021-06-13 00:44:48 UTC
I find some useful things in the *.inf file:

[IntelSSTAudio.AddReg]

;****** D0/D3 RTPM enabling ******
HKR,PowerSettings,ConservationIdleTime,0x00010001,0x1e
HKR,PowerSettings,PerformanceIdleTime,0x00010001,0x1e
HKR,PowerSettings,IdlePowerState,0x00010001,0x3

;****** BT SSP Config ******
HKR,BTSSP,BTSSPFRMSyncMode,0x00010001,0
HKR,BTSSP,BTSSPFRMPolarity,0x00010001,1
HKR,BTSSP,BTSSPClockMode,0x00010001,0

;****** Audio Volume/Boost Config ******
HKR,AudioVolBoost,MicMaxVolume,0x00000000,30
HKR,AudioVolBoost,MicMinVolume,0x00000000,-18
HKR,AudioVolBoost,MicMaxBoostVolume,0x00000000,36
HKR,AudioVolBoost,MicMinBoostVolume,0x00000000,0
HKR,AudioVolBoost,SPKMaxVol,0x00000000,0
HKR,AudioVolBoost,SPKMinVol,0x00000000,-138
HKR,AudioVolBoost,SPKVolLimit,0x00000000,-12
;; For EU set GenerateVolLimitUI = 1 (else unset) and TimerVolLimitUI=cumulative listening time 
;; example EU recommended 20hrs value is 0x11940 seconds
;; IMPORTANT - to enable EU warning set GenerateVolLimitUI
HKR,AudioVolBoost,GenerateVolLimitUI,0x00010001,0
HKR,AudioVolBoost,TimerVolLimitUI,0x00010001,0x11940 

;; Waves Support: 
HKR,HeadsetStatus,HeadsetStatus,0x00010001,0

;======================================================
; interfaces
;======================================================
[IntcADSPModel.AddReg] 
;****** Audio AccessMode Config ******
;Bit [0] of AccessMode key defines location of debug registers 
;0- default location , 1- fixed location 
HKR,AccessSettings,AccessMode,1,01
;Bit [5] of OffloadPinCapabilities key defines if offload pins are to be supported 
;0- offload pins enabled <default value>
;1- offload pins disabled
HKR,GlobalSettings,OffloadPinCapabilities,1,00,00,00,00

HKLM,Software\Intel,SubClasses,,"Audio"
HKLM,Software\Intel\Audio,SubClasses,,"GlobalSettings"
HKLM,Software\Intel\Audio\GlobalSettings,OffloadPinCapabilities,1,00,00,00,00
;*********HEADSET*****************
[IntelSST.I.Wave]
AddReg=IntelSST.I.Wave.AddReg

[IntelSST.I.Wave.AddReg]
HKR,,CLSID,,%Proxy.CLSID%
HKR,,FriendlyName,,%IntelSST.Wave.szPname%

[IntelSST.I.Topo]
AddReg=IntelSST.I.Topo.AddReg

[IntelSST.I.Topo.AddReg]
HKR,,CLSID,,%Proxy.CLSID%
HKR,,FriendlyName,,%IntelSST.Topo.szPname%
;opt-in to pull mode.
HKR,"EP\\0",%PKEY_AudioEndpoint_Association%,,%KSNODETYPE_ANY%
HKR,"EP\\0",%PKEY_AudioEndpoint_Supports_EventDriven_Mode%,0x00010001,0x1
HKR,"EP\\1",%PKEY_AudioEndpoint_Association%,,%KSNODETYPE_ANY%
HKR,"EP\\1",%PKEY_AudioEndpoint_Supports_EventDriven_Mode%,0x00010001,0x1

;*********IHF*****************
[IntelSST.I.WaveIHF]
AddReg=IntelSST.I.WaveIHF.AddReg

[IntelSST.I.WaveIHF.AddReg]
HKR,,CLSID,,%Proxy.CLSID%
HKR,,FriendlyName,,%IntelSST.WaveIHF.szPname%

[IntelSST.I.TopoIHF]
AddReg=IntelSST.I.TopoIHF.AddReg,SysFx.AddReg
;;AddReg=IntelSST.I.TopoIHF.AddReg

[IntelSST.I.TopoIHF.AddReg]
HKR,,CLSID,,%Proxy.CLSID%
HKR,,FriendlyName,,%IntelSST.TopoIHF.szPname%
;opt-in to pull mode.
HKR,"EP\\0",%PKEY_AudioEndpoint_Association%,,%KSNODETYPE_ANY%
HKR,"EP\\0",%PKEY_AudioEndpoint_Supports_EventDriven_Mode%,0x00010001,0x1

;*********DMIC*****************
[IntelSST.I.WaveDMIC]
AddReg=IntelSST.I.WaveDMIC.AddReg

[IntelSST.I.WaveDMIC.AddReg]
HKR,,CLSID,,%Proxy.CLSID%
HKR,,FriendlyName,,%IntelSST.WaveDMIC.szPname%

[IntelSST.I.TopoDMIC]
AddReg=IntelSST.I.TopoDMIC.AddReg, SysRecFx.AddReg

[IntelSST.I.TopoDMIC.AddReg]
HKR,,CLSID,,%Proxy.CLSID%
HKR,,FriendlyName,,%IntelSST.TopoDMIC.szPname%
;opt-in to pull mode.
HKR,"EP\\0",%PKEY_AudioEndpoint_Association%,,%KSNODETYPE_ANY%
HKR,"EP\\0",%PKEY_AudioEndpoint_Supports_EventDriven_Mode%,0x00010001,0x1
Comment 12 Pierre Bossart 2021-06-14 14:39:56 UTC
try finding a configuration for the RT564x. All the settings above are related to the Intel controller side of things, they don't help in terms of quirks at teh codec level.
Comment 13 Zhihao Wang 2021-06-14 15:13:36 UTC
(In reply to Pierre Bossart from comment #12)
> try finding a configuration for the RT564x. All the settings above are
> related to the Intel controller side of things, they don't help in terms of
> quirks at teh codec level.

Thanks.
The driver for Windows didn't have some useful things.
Besides, the driver is signed by Realtek. I thought the config is inside a firmware called realtek_fw_sst.bin ? or the driver RTII2SAC.sys ? (hp provided some information to Realtek and the Realtek compiled the code?)
Comment 14 Pierre Bossart 2021-06-14 15:23:37 UTC
In the absence of information, you will have to use the trial and error method, based on the existing quirks in sound/soc/intel/boards/bytcr_rt5640.c

enum {
	BYT_RT5640_DMIC1_MAP,
	BYT_RT5640_DMIC2_MAP,
	BYT_RT5640_IN1_MAP,
	BYT_RT5640_IN3_MAP,
	BYT_RT5640_NO_INTERNAL_MIC_MAP,
};

enum {
	BYT_RT5640_JD_SRC_GPIO1		= (RT5640_JD_SRC_GPIO1 << 4),
	BYT_RT5640_JD_SRC_JD1_IN4P	= (RT5640_JD_SRC_JD1_IN4P << 4),
	BYT_RT5640_JD_SRC_JD2_IN4N	= (RT5640_JD_SRC_JD2_IN4N << 4),
	BYT_RT5640_JD_SRC_GPIO2		= (RT5640_JD_SRC_GPIO2 << 4),
	BYT_RT5640_JD_SRC_GPIO3		= (RT5640_JD_SRC_GPIO3 << 4),
	BYT_RT5640_JD_SRC_GPIO4		= (RT5640_JD_SRC_GPIO4 << 4),
};

enum {
	BYT_RT5640_OVCD_TH_600UA	= (6 << 8),
	BYT_RT5640_OVCD_TH_1500UA	= (15 << 8),
	BYT_RT5640_OVCD_TH_2000UA	= (20 << 8),
};

enum {
	BYT_RT5640_OVCD_SF_0P5		= (RT5640_OVCD_SF_0P5 << 13),
	BYT_RT5640_OVCD_SF_0P75		= (RT5640_OVCD_SF_0P75 << 13),
	BYT_RT5640_OVCD_SF_1P0		= (RT5640_OVCD_SF_1P0 << 13),
	BYT_RT5640_OVCD_SF_1P5		= (RT5640_OVCD_SF_1P5 << 13),
};

#define BYT_RT5640_MAP(quirk)		((quirk) &  GENMASK(3, 0))
#define BYT_RT5640_JDSRC(quirk)		(((quirk) & GENMASK(7, 4)) >> 4)
#define BYT_RT5640_OVCD_TH(quirk)	(((quirk) & GENMASK(12, 8)) >> 8)
#define BYT_RT5640_OVCD_SF(quirk)	(((quirk) & GENMASK(14, 13)) >> 13)
#define BYT_RT5640_JD_NOT_INV		BIT(16)
#define BYT_RT5640_MONO_SPEAKER		BIT(17)
#define BYT_RT5640_DIFF_MIC		BIT(18) /* default is single-ended */
#define BYT_RT5640_SSP2_AIF2		BIT(19) /* default is using AIF1  */
#define BYT_RT5640_SSP0_AIF1		BIT(20)
#define BYT_RT5640_SSP0_AIF2		BIT(21)
#define BYT_RT5640_MCLK_EN		BIT(22)
#define BYT_RT5640_MCLK_25MHZ		BIT(23)
#define BYT_RT5640_NO_SPEAKERS		BIT(24)

#define BYTCR_INPUT_DEFAULTS				\
	(BYT_RT5640_IN3_MAP |				\
	 BYT_RT5640_JD_SRC_JD1_IN4P |			\
	 BYT_RT5640_OVCD_TH_2000UA |			\
	 BYT_RT5640_OVCD_SF_0P75 |			\
	 BYT_RT5640_DIFF_MIC)


I would start adding the last quirk first, try the default inputs. We know your speakers work so you have the right SSP/AIF connection already.
Comment 15 Zhihao Wang 2021-06-14 15:36:42 UTC
(In reply to Pierre Bossart from comment #12)
> try finding a configuration for the RT564x. All the settings above are
> related to the Intel controller side of things, they don't help in terms of
> quirks at teh codec level.

Maybe the most useful information we could get is the ACPI table?
DSDT.dsl is attached already.

But, sorry. I don't know how the whole system work.

I have no idea what I can do. Maybe I need to tear it down and test the circuit and find out how the wire connected? 
I hope whether the sound card works or it dies a painful death. Although the device's battery life is very very good, and its TDP is very small. It's excellent and perfect with Linux, pretty fast.
But it is full of bug. Even I can't install Windows on it too because I can't get eMMC driver from HP. The Windows Installer disk doesn't contain it too. They don't provide it. I don't know why.

Here is the information in the DSDT which might be useful.

Device (RTEK)
            {
                Name (_ADR, Zero)  // _ADR: Address
                Name (_HID, "INTCCFFD")  // _HID: Hardware ID
                Name (_CID, "INTCCFFD")  // _CID: Compatible ID
                Name (_DDN, "RTEK Codec Controller ")  // _DDN: DOS Device Name
                Name (_UID, 0x02)  // _UID: Unique ID
                Method (_CRS, 0, NotSerialized)  // _CRS: Current Resource Settings
                {
                    Name (SBUF, ResourceTemplate ()
                    {
                        I2cSerialBusV2 (0x001C, ControllerInitiated, 0x00061A80,
                            AddressingMode7Bit, "\\_SB.I2C2",
                            0x00, ResourceConsumer, , Exclusive,
                            )
                        GpioInt (Edge, ActiveBoth, SharedAndWake, PullNone, 0x0000,
                            "\\_SB.GPO2", 0x00, ResourceConsumer, ,
                            )
                            {   // Pin list
                                0x000E
                            }
                        GpioInt (Edge, ActiveBoth, SharedAndWake, PullNone, 0x0000,
                            "\\_SB.GPO0", 0x00, ResourceConsumer, ,
                            )
                            {   // Pin list
                                0x0003
                            }
                        GpioInt (Edge, ActiveBoth, SharedAndWake, PullNone, 0x0000,
                            "\\_SB.GPO0", 0x00, ResourceConsumer, ,
                            )
                            {   // Pin list
                                0x0000
                            }
                        GpioIo (Shared, PullDefault, 0x0000, 0x0000, IoRestrictionInputOnly,
                            "\\_SB.GPO2", 0x00, ResourceConsumer, ,
                            )
                            {   // Pin list
                                0x000E
                            }
                        GpioIo (Shared, PullDefault, 0x0000, 0x0000, IoRestrictionInputOnly,
                            "\\_SB.GPO0", 0x00, ResourceConsumer, ,
                            )
                            {   // Pin list
                                0x0003,
                                0x0000
                            }
                    })
                    Return (SBUF) /* \_SB_.I2C2.RTEK._CRS.SBUF */
                }


Scope (_SB)
    {
        Device (LPEA)
        {
            Name (_ADR, Zero)  // _ADR: Address
            Name (_HID, "80860F28" /* Intel SST Audio DSP */)  // _HID: Hardware ID
            Name (_CID, "80860F28" /* Intel SST Audio DSP */)  // _CID: Compatible ID
            Name (_DDN, "Intel(R) Low Power Audio Controller - 80860F28")  // _DDN: DOS Device Name
            Name (_SUB, "80867270")  // _SUB: Subsystem ID
            Name (_UID, One)  // _UID: Unique ID
            Name (_DEP, Package (0x01)  // _DEP: Dependencies
            {
                ^I2C2.RTEK
            })
            Name (_PR0, Package (0x01)  // _PR0: Power Resources for D0
            {
                PLPE
            })
            Method (_STA, 0, NotSerialized)  // _STA: Status
            {
                If (LAnd (LEqual (LPEE, 0x02), LEqual (LPED, Zero)))
                {
                    Return (0x0F)
                }

                Return (Zero)
            }

            Method (_DIS, 0, NotSerialized)  // _DIS: Disable Device
            {
            }

            Name (RBUF, ResourceTemplate ()
            {
                Memory32Fixed (ReadWrite,
                    0xFE400000,         // Address Base
                    0x00200000,         // Address Length
                    _Y03)
                Memory32Fixed (ReadWrite,
                    0xFE830000,         // Address Base
                    0x00001000,         // Address Length
                    _Y04)
                Memory32Fixed (ReadWrite,
                    0x55AA55AA,         // Address Base
                    0x00100000,         // Address Length
                    _Y05)
                Interrupt (ResourceConsumer, Level, ActiveLow, Exclusive, ,, )
                {
                    0x00000018,
                }
                Interrupt (ResourceConsumer, Level, ActiveLow, Exclusive, ,, )
                {
                    0x00000019,
                }
                Interrupt (ResourceConsumer, Level, ActiveLow, Exclusive, ,, )
                {
                    0x0000001A,
                }
                Interrupt (ResourceConsumer, Level, ActiveLow, Exclusive, ,, )
                {
                    0x0000001B,
                }
                Interrupt (ResourceConsumer, Level, ActiveLow, Exclusive, ,, )
                {
                    0x0000001C,
                }
                Interrupt (ResourceConsumer, Level, ActiveLow, Exclusive, ,, )
                {
                    0x0000001D,
                }
                GpioInt (Edge, ActiveBoth, ExclusiveAndWake, PullNone, 0x0000,
                    "\\_SB.GPO2", 0x00, ResourceConsumer, ,
                    )
                    {   // Pin list
                        0x001C
                    }
            })
            Method (_CRS, 0, NotSerialized)  // _CRS: Current Resource Settings
            {
                CreateDWordField (RBUF, \_SB.LPEA._Y03._BAS, B0BA)  // _BAS: Base Address
                Store (LPE0, B0BA) /* \_SB_.LPEA._CRS.B0BA */
                CreateDWordField (RBUF, \_SB.LPEA._Y04._BAS, B1BA)  // _BAS: Base Address
                Store (LPE1, B1BA) /* \_SB_.LPEA._CRS.B1BA */
                CreateDWordField (RBUF, \_SB.LPEA._Y05._BAS, B2BA)  // _BAS: Base Address
                Store (LPE2, B2BA) /* \_SB_.LPEA._CRS.B2BA */
                Return (RBUF) /* \_SB_.LPEA.RBUF */
            }

            OperationRegion (KEYS, SystemMemory, LPE1, 0x0100)
            Field (KEYS, DWordAcc, NoLock, WriteAsZeros)
            {
                Offset (0x84), 
                PSAT,   32
            }

            PowerResource (PLPE, 0x05, 0x0000)
            {
                Method (_STA, 0, NotSerialized)  // _STA: Status
                {
                    Return (One)
                }

                Method (_ON, 0, NotSerialized)  // _ON_: Power On
                {
                    And (PSAT, 0xFFFFFFFC, PSAT) /* \_SB_.LPEA.PSAT */
                    Or (PSAT, Zero, PSAT) /* \_SB_.LPEA.PSAT */
                }

                Method (_OFF, 0, NotSerialized)  // _OFF: Power Off
                {
                    Or (PSAT, 0x03, PSAT) /* \_SB_.LPEA.PSAT */
                    Or (PSAT, Zero, PSAT) /* \_SB_.LPEA.PSAT */
                }
            }
        }
    }
Comment 16 Zhihao Wang 2021-06-14 15:37:13 UTC
About the INTCCFFD: https://github.com/LattePandaTeam/LattePanda-Win10-Software/tree/master/Drivers/4G64GB_Drivers/Audio

lattepanda use this "INTCCFFD" ACPI _HID too. Quite interesting.
Comment 17 Zhihao Wang 2021-06-14 15:40:00 UTC
(In reply to Pierre Bossart from comment #14)
> In the absence of information, you will have to use the trial and error
> method, based on the existing quirks in sound/soc/intel/boards/bytcr_rt5640.c
> 
> enum {
>       BYT_RT5640_DMIC1_MAP,
>       BYT_RT5640_DMIC2_MAP,
>       BYT_RT5640_IN1_MAP,
>       BYT_RT5640_IN3_MAP,
>       BYT_RT5640_NO_INTERNAL_MIC_MAP,
> };
> 
> enum {
>       BYT_RT5640_JD_SRC_GPIO1         = (RT5640_JD_SRC_GPIO1 << 4),
>       BYT_RT5640_JD_SRC_JD1_IN4P      = (RT5640_JD_SRC_JD1_IN4P << 4),
>       BYT_RT5640_JD_SRC_JD2_IN4N      = (RT5640_JD_SRC_JD2_IN4N << 4),
>       BYT_RT5640_JD_SRC_GPIO2         = (RT5640_JD_SRC_GPIO2 << 4),
>       BYT_RT5640_JD_SRC_GPIO3         = (RT5640_JD_SRC_GPIO3 << 4),
>       BYT_RT5640_JD_SRC_GPIO4         = (RT5640_JD_SRC_GPIO4 << 4),
> };
> 
> enum {
>       BYT_RT5640_OVCD_TH_600UA        = (6 << 8),
>       BYT_RT5640_OVCD_TH_1500UA       = (15 << 8),
>       BYT_RT5640_OVCD_TH_2000UA       = (20 << 8),
> };
> 
> enum {
>       BYT_RT5640_OVCD_SF_0P5          = (RT5640_OVCD_SF_0P5 << 13),
>       BYT_RT5640_OVCD_SF_0P75         = (RT5640_OVCD_SF_0P75 << 13),
>       BYT_RT5640_OVCD_SF_1P0          = (RT5640_OVCD_SF_1P0 << 13),
>       BYT_RT5640_OVCD_SF_1P5          = (RT5640_OVCD_SF_1P5 << 13),
> };
> 
> #define BYT_RT5640_MAP(quirk)         ((quirk) &  GENMASK(3, 0))
> #define BYT_RT5640_JDSRC(quirk)               (((quirk) & GENMASK(7, 4)) >>
> 4)
> #define BYT_RT5640_OVCD_TH(quirk)     (((quirk) & GENMASK(12, 8)) >> 8)
> #define BYT_RT5640_OVCD_SF(quirk)     (((quirk) & GENMASK(14, 13)) >> 13)
> #define BYT_RT5640_JD_NOT_INV         BIT(16)
> #define BYT_RT5640_MONO_SPEAKER               BIT(17)
> #define BYT_RT5640_DIFF_MIC           BIT(18) /* default is single-ended */
> #define BYT_RT5640_SSP2_AIF2          BIT(19) /* default is using AIF1  */
> #define BYT_RT5640_SSP0_AIF1          BIT(20)
> #define BYT_RT5640_SSP0_AIF2          BIT(21)
> #define BYT_RT5640_MCLK_EN            BIT(22)
> #define BYT_RT5640_MCLK_25MHZ         BIT(23)
> #define BYT_RT5640_NO_SPEAKERS                BIT(24)
> 
> #define BYTCR_INPUT_DEFAULTS                          \
>       (BYT_RT5640_IN3_MAP |                           \
>        BYT_RT5640_JD_SRC_JD1_IN4P |                   \
>        BYT_RT5640_OVCD_TH_2000UA |                    \
>        BYT_RT5640_OVCD_SF_0P75 |                      \
>        BYT_RT5640_DIFF_MIC)
> 
> 
> I would start adding the last quirk first, try the default inputs. We know
> your speakers work so you have the right SSP/AIF connection already.

Is the BYT_RT5640_JD_SRC or BYT_RT5640_MCLK_25MHZ affect the audio from the jack?

Another guy who faces same problem.
https://forum.manjaro.org/t/no-sound-from-headphone-jack-elitepad-1000-g2/66354
Comment 18 Pierre Bossart 2021-06-14 15:48:20 UTC
don't use BYT_RT5640_MCLK_25MHZ, I am not sure why we let it but it's not functional at all.

You have to give the other quirks a try.
Comment 19 Zhihao Wang 2021-06-14 16:25:33 UTC
I find that the internal mic is always ported to the jack no matter what the quirk is.
Comment 20 Zhihao Wang 2021-06-14 16:26:32 UTC
Would HP make a special mux?
Comment 21 Zhihao Wang 2021-06-14 16:28:45 UTC
Because the dock station of this pack can port audio out too.
https://www.amazon.com/HP-ElitePad-Dock-Docking-Black/dp/B00B5HYF94
I don't have one and I don't know whether this dock use a usb sound card or just port the audio from the internal rt5642 card.
Comment 22 Zhihao Wang 2021-06-14 16:36:04 UTC
Created attachment 297357 [details]
The driver from hp for windows

Maybe there are some interesting things could be found here.
Some magic setting, numbers, etc.
Comment 23 Zhihao Wang 2021-06-14 16:49:50 UTC
From the IDA

The symbol file is located at D:\Documents\Realtek\Source codes\RTII2SAC\coinstaller\x64\Win8.1Release\

Here is something about co-installer
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/co-installer-functionality

So I guess The configuration for rt5642 is written by the dll rtii2sac_coinstaller.dll.
Comment 24 Zhihao Wang 2021-06-14 17:02:03 UTC
or RtkCfg64.dll
Comment 25 Hans de Goede 2021-06-14 19:16:16 UTC
Pleas see:
https://bugzilla.kernel.org/show_bug.cgi?id=211485#c13

Where I explain how to find the right quirks in detail.
Comment 26 Zhihao Wang 2021-06-15 00:32:30 UTC
(In reply to Hans de Goede from comment #25)
> Pleas see:
> https://bugzilla.kernel.org/show_bug.cgi?id=211485#c13
> 
> Where I explain how to find the right quirks in detail.

Thanks! But there is no audio from the jack. No quirk affect this.
Comment 27 Zhihao Wang 2021-06-15 01:45:58 UTC
I have tried all the quirk 0x402fXX by setting grub, update-grub and reboot but nothing changed. The jack detect and the jack audio-out & audio-in.

But
While I use 0x402f20 I heard quite a lot of noise while I monitor the internal mic through pavucontrol.

The most IMPORTANT things is The internal microphone is actually wired to the jack audio-in. I can even record the audio of jackaudio-in if I switch to IN1, which should be the internal mic.

Information from HP: The microphone is Digital Microphone.
Audio:
HD audio with DTS Sound+
2 Integrated stereo speakers.
2 integrated microphones (dual-microphone array) (noise cancelling and beam forming)
Combo stereo/headphone/microphone jack
Comment 28 Zhihao Wang 2021-06-15 01:48:30 UTC
> Pleas see:
> https://bugzilla.kernel.org/show_bug.cgi?id=211485#c13
> 
> Where I explain how to find the right quirks in detail.

Maybe I should try newer kernel, however I can't bootup at 5.10.so sad.(In reply to Hans de Goede from comment #25)
Comment 29 Hans de Goede 2021-06-15 10:57:06 UTC
> Thanks! But there is no audio from the jack. No quirk affect this.

On these devices you need to explicitly select the output which you want to use, normally pulseaudio / pipewire will do this for you based on jack-detect but since you don't seem to have working jack-detect ...

If you set the jack detect nibble of the quirk (marked as X) to 0:
0x4034X0

So you get:

0x403400

Note as you can see I'm using 34 for the middle 2 nibbles, this is almost always the right value (and it does not matter until we get jack-detect to work).

Setting the jack-detect nibble to 0 should allow you to manually select the output in e.g. the GNOME sound settings.

Or you can manually switch by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Speaker

or:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Headphones
Comment 30 Hans de Goede 2021-06-15 10:57:56 UTC
To try and get the jackdetect functionality to work, it is best to test it independent of pulseaudio / pipewire doing the switching for you by monitoring the 5640 jack input-device.

Set the jackdetect nibble to 3, so you get: 0x403430 as quirk and then run:

sudo evemu-record

And select the 5640 jack input-device there and then plug in/out your headphones or headset jack, this should generate events.

If this does not work, try again with the jackdetect nibble set to 2, so you get: 0x403420 as quirk.
Comment 31 Hans de Goede 2021-06-15 11:03:59 UTC
Since the internal mic is described as "2 integrated microphones (dual-microphone array) (noise cancelling and beam forming)" this is probably a set of digital (MEMS) microphones, which are connected to the DMIC1 input, for this you need to set the internal-mic nibble (marked as X): 0x40340X to 0, so you get: 0x403400.

And then select the internal mic input by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Mic

As for the jack / headsetmic giving some sound on IN1, this likely is cross-talk since sofar on all known devices it is always connected to IN2, if you disable jackdetect by setting the jackdetect nibble to 0, e.g. use 0x403400 as quirk and then select the headsetmic by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Headset

Which will activate the IN2 input then I expect that you will get (better) sound there. Note it is possible that the jack-input is actually connected to IN1, but that would be a first (and we would need to extend the input mapping code in sound/soc/intel/boards/bytcr_rt5640.c to deal with this).
Comment 32 Zhihao Wang 2021-06-15 12:50:51 UTC
Created attachment 297361 [details]
attachment-14316-0.html

Thanks very much for your support. I find another thing: when I switch to the DMIC2, the input of mic all disappeared, just left a multi channel input. Can we guess something from it?

Get Outlook for Android<https://aka.ms/AAb9ysg>

________________________________
From: bugzilla-daemon@bugzilla.kernel.org <bugzilla-daemon@bugzilla.kernel.org>
Sent: Tuesday, June 15, 2021 7:03:59 PM
To: wangzhihao9@hotmail.com <wangzhihao9@hotmail.com>
Subject: [Bug 213415] Wrong setting for Elitepad 1000 G2

https://bugzilla.kernel.org/show_bug.cgi?id=213415

--- Comment #31 from Hans de Goede (jwrdegoede@fedoraproject.org) ---
Since the internal mic is described as "2 integrated microphones
(dual-microphone array) (noise cancelling and beam forming)" this is probably a
set of digital (MEMS) microphones, which are connected to the DMIC1 input, for
this you need to set the internal-mic nibble (marked as X): 0x40340X to 0, so
you get: 0x403400.

And then select the internal mic input by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Mic

As for the jack / headsetmic giving some sound on IN1, this likely is
cross-talk since sofar on all known devices it is always connected to IN2, if
you disable jackdetect by setting the jackdetect nibble to 0, e.g. use 0x403400
as quirk and then select the headsetmic by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Headset

Which will activate the IN2 input then I expect that you will get (better)
sound there. Note it is possible that the jack-input is actually connected to
IN1, but that would be a first (and we would need to extend the input mapping
code in sound/soc/intel/boards/bytcr_rt5640.c to deal with this).

--
You may reply to this email to add a comment.

You are receiving this mail because:
You reported the bug.
Comment 33 Zhihao Wang 2021-06-15 12:53:24 UTC
Created attachment 297363 [details]
attachment-16497-0.html

I will take it a try.

Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: bugzilla-daemon@bugzilla.kernel.org <bugzilla-daemon@bugzilla.kernel.org>
Sent: Tuesday, June 15, 2021 7:03:59 PM
To: wangzhihao9@hotmail.com <wangzhihao9@hotmail.com>
Subject: [Bug 213415] Wrong setting for Elitepad 1000 G2

https://bugzilla.kernel.org/show_bug.cgi?id=213415

--- Comment #31 from Hans de Goede (jwrdegoede@fedoraproject.org) ---
Since the internal mic is described as "2 integrated microphones
(dual-microphone array) (noise cancelling and beam forming)" this is probably a
set of digital (MEMS) microphones, which are connected to the DMIC1 input, for
this you need to set the internal-mic nibble (marked as X): 0x40340X to 0, so
you get: 0x403400.

And then select the internal mic input by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Mic

As for the jack / headsetmic giving some sound on IN1, this likely is
cross-talk since sofar on all known devices it is always connected to IN2, if
you disable jackdetect by setting the jackdetect nibble to 0, e.g. use 0x403400
as quirk and then select the headsetmic by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Headset

Which will activate the IN2 input then I expect that you will get (better)
sound there. Note it is possible that the jack-input is actually connected to
IN1, but that would be a first (and we would need to extend the input mapping
code in sound/soc/intel/boards/bytcr_rt5640.c to deal with this).

--
You may reply to this email to add a comment.

You are receiving this mail because:
You reported the bug.
Comment 34 Zhihao Wang 2021-06-15 13:17:12 UTC
Created attachment 297365 [details]
attachment-25755-0.html

still cannot work.
The DMIC is ported to the jack too.
While I plug in the headphone. I can see volume suddenly changed of the Internal Digital Microphone.

Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: bugzilla-daemon@bugzilla.kernel.org <bugzilla-daemon@bugzilla.kernel.org>
Sent: Tuesday, June 15, 2021 7:03:59 PM
To: wangzhihao9@hotmail.com <wangzhihao9@hotmail.com>
Subject: [Bug 213415] Wrong setting for Elitepad 1000 G2

https://bugzilla.kernel.org/show_bug.cgi?id=213415

--- Comment #31 from Hans de Goede (jwrdegoede@fedoraproject.org) ---
Since the internal mic is described as "2 integrated microphones
(dual-microphone array) (noise cancelling and beam forming)" this is probably a
set of digital (MEMS) microphones, which are connected to the DMIC1 input, for
this you need to set the internal-mic nibble (marked as X): 0x40340X to 0, so
you get: 0x403400.

And then select the internal mic input by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Mic

As for the jack / headsetmic giving some sound on IN1, this likely is
cross-talk since sofar on all known devices it is always connected to IN2, if
you disable jackdetect by setting the jackdetect nibble to 0, e.g. use 0x403400
as quirk and then select the headsetmic by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Headset

Which will activate the IN2 input then I expect that you will get (better)
sound there. Note it is possible that the jack-input is actually connected to
IN1, but that would be a first (and we would need to extend the input mapping
code in sound/soc/intel/boards/bytcr_rt5640.c to deal with this).

--
You may reply to this email to add a comment.

You are receiving this mail because:
You reported the bug.
Comment 35 Zhihao Wang 2021-06-15 13:25:32 UTC
Created attachment 297367 [details]
attachment-29776-0.html

quirk 0x403400
type the:
alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Headset

The recorder application freezed.
________________________________
From: 王 志豪 <wangzhihao9@hotmail.com>
Sent: Tuesday, June 15, 2021 9:17:08 PM
To: bugzilla-daemon@bugzilla.kernel.org <bugzilla-daemon@bugzilla.kernel.org>
Subject: Re: [Bug 213415] Wrong setting for Elitepad 1000 G2

still cannot work.
The DMIC is ported to the jack too.
While I plug in the headphone. I can see volume suddenly changed of the Internal Digital Microphone.

Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: bugzilla-daemon@bugzilla.kernel.org <bugzilla-daemon@bugzilla.kernel.org>
Sent: Tuesday, June 15, 2021 7:03:59 PM
To: wangzhihao9@hotmail.com <wangzhihao9@hotmail.com>
Subject: [Bug 213415] Wrong setting for Elitepad 1000 G2

https://bugzilla.kernel.org/show_bug.cgi?id=213415

--- Comment #31 from Hans de Goede (jwrdegoede@fedoraproject.org) ---
Since the internal mic is described as "2 integrated microphones
(dual-microphone array) (noise cancelling and beam forming)" this is probably a
set of digital (MEMS) microphones, which are connected to the DMIC1 input, for
this you need to set the internal-mic nibble (marked as X): 0x40340X to 0, so
you get: 0x403400.

And then select the internal mic input by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Mic

As for the jack / headsetmic giving some sound on IN1, this likely is
cross-talk since sofar on all known devices it is always connected to IN2, if
you disable jackdetect by setting the jackdetect nibble to 0, e.g. use 0x403400
as quirk and then select the headsetmic by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Headset

Which will activate the IN2 input then I expect that you will get (better)
sound there. Note it is possible that the jack-input is actually connected to
IN1, but that would be a first (and we would need to extend the input mapping
code in sound/soc/intel/boards/bytcr_rt5640.c to deal with this).

--
You may reply to this email to add a comment.

You are receiving this mail because:
You reported the bug.
Comment 36 Zhihao Wang 2021-06-15 13:37:41 UTC
A summary of trail and phenomenon:
Also I update the kernel, nothing changed.

1.No quirk will make the digital mic, headset and the headphone work.

2.quirk 0x403401, All the micphone disappear from the pavucontrol, only left a Multichannel input.
try to set alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Mic or Headset
return error: unable to find device 'Mic'

3.quirk 0x403400
type:
alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Headset

The recorder application such as audacity, pavucontrol or gnome-recoder freezed or cannot record any voice.

4.quirk 0x403420
bring me a lot of noise in the headphone,during the startup or opening the pavucontrol. But after I change the input device to headphone, The noise disappeared. I guess it is the signal of the Digital MIC, and it is ported to the jack.
Comment 37 Zhihao Wang 2021-06-15 14:19:30 UTC
Created attachment 297369 [details]
attachment-19723-0.html

The headphone still cannot work.

Get Outlook for Android<https://aka.ms/AAb9ysg>

________________________________
From: 王 志豪 <wangzhihao9@hotmail.com>
Sent: Tuesday, June 15, 2021 9:25:28 PM
To: bugzilla-daemon@bugzilla.kernel.org <bugzilla-daemon@bugzilla.kernel.org>
Subject: Re: [Bug 213415] Wrong setting for Elitepad 1000 G2

quirk 0x403400
type the:
alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Headset

The recorder application freezed.
________________________________
From: 王 志豪 <wangzhihao9@hotmail.com>
Sent: Tuesday, June 15, 2021 9:17:08 PM
To: bugzilla-daemon@bugzilla.kernel.org <bugzilla-daemon@bugzilla.kernel.org>
Subject: Re: [Bug 213415] Wrong setting for Elitepad 1000 G2

still cannot work.
The DMIC is ported to the jack too.
While I plug in the headphone. I can see volume suddenly changed of the Internal Digital Microphone.

Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: bugzilla-daemon@bugzilla.kernel.org <bugzilla-daemon@bugzilla.kernel.org>
Sent: Tuesday, June 15, 2021 7:03:59 PM
To: wangzhihao9@hotmail.com <wangzhihao9@hotmail.com>
Subject: [Bug 213415] Wrong setting for Elitepad 1000 G2

https://bugzilla.kernel.org/show_bug.cgi?id=213415

--- Comment #31 from Hans de Goede (jwrdegoede@fedoraproject.org) ---
Since the internal mic is described as "2 integrated microphones
(dual-microphone array) (noise cancelling and beam forming)" this is probably a
set of digital (MEMS) microphones, which are connected to the DMIC1 input, for
this you need to set the internal-mic nibble (marked as X): 0x40340X to 0, so
you get: 0x403400.

And then select the internal mic input by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Mic

As for the jack / headsetmic giving some sound on IN1, this likely is
cross-talk since sofar on all known devices it is always connected to IN2, if
you disable jackdetect by setting the jackdetect nibble to 0, e.g. use 0x403400
as quirk and then select the headsetmic by running:

alsaucm -c bytcr-rt5640 set _verb HiFi set _enadev Headset

Which will activate the IN2 input then I expect that you will get (better)
sound there. Note it is possible that the jack-input is actually connected to
IN1, but that would be a first (and we would need to extend the input mapping
code in sound/soc/intel/boards/bytcr_rt5640.c to deal with this).

--
You may reply to this email to add a comment.

You are receiving this mail because:
You reported the bug.
Comment 38 Zhihao Wang 2021-06-17 09:36:19 UTC
From the datasheet and the phenomena,

I think:

This device is using DMIC2 and JD2.

However, why the headphone doesn't work I have no idea.
Maybe it uses Line Output? It's crazy and I don't believe.
Comment 39 Hans de Goede 2021-07-18 21:03:12 UTC
I was curious about what exactly is going on here, so I've managed to get my hands on a HP Elitepad 1000 G2 to test / figure this all out myself.

What is going on here is that this tablet actually has 2 full (including mic support) headset jacks wired up. The regular headphones amp, and in2 input which is  normally always used for the headset-mic are wired to the docking connecter and are available on the jack in the dock when docked (the tablet which I bought 2nd hand luckily came with the dock).

The jack on the tablet is actually wired up as a second jack, using in1 for the headset-mic, as you already figured out; and using line-out with an external hp-amp to drive the headphones. This external amp also needs to be explictly enabled by driving the GPIO1 pin on the codec high.

The internal mics are indeed connected to the DMIC2 input.

I've been working on supporting this all; and I have the internal mics + the tablet-jack headphone output working. The tablet-jack headset input works when setting the quirk to an input map of in1, but then you loose the internal mics. I still need to add support for in1 being used as a third input (2nd jack input) option.

I've pushed the necessary kernel changes here:
https://github.com/jwrdegoede/linux-sunxi/commits/v5.13-footrail

And the matching alsa-ucm changes, which you also need are here:
https://github.com/jwrdegoede/alsa-ucm-conf/commits/master

You need to set "options snd_soc_sst_bytcr_rt5640 quirk=0x6400001" in modprobe.conf or add snd_soc_sst_bytcr_rt5640.quirk=0x6400001 to the kernel commandline for this to work (minus the tablet-jack headset-mic which I still need to implement).

Implementing the tablet-jack headset-mic support should be easy. But I've run out of time to work on this for now. And I won't have time to work on this for approx. the next 2 weeks. I'll finish this up by adding tablet-jack headset-mic support and submit this upstream after that.

###

I've also figured out how jack-detect works, since the codec's GPIO1 is used for the external-hp-amp enable, the jack-detect signals are directly connected to the Bay Trail SoC's GPIOs:

  -gpioget 'INT33FC:02' 14 && gpioget 'INT33FC:00' 0 && gpioget 'INT33FC:00' 3
   Nothing inserted: 1 1 0
   Headset  in dock: 0 1 0
   Headphon in dock: 0 1 1
   Headset  in tabl: 1 0 0
   Headphon in tabl: 1 0 0
   Conclusion:
   GPO2 pin 14: !jack in dock
   GPO0 pin  0: !jack in tablet
   GPO0 pin  3: 1 when jack in dock with no mic

And I believe that the mic on the tablet jack can be detected using the normal micBIAS over current detection which is normally also used.

This will require some special jack-detect handling inside the machine driver for this model. I plan to also add support for this when I have some time to work on this.
Comment 40 Zhihao Wang 2021-07-24 02:34:30 UTC
Thanks a lot! Sorry for my poor ability. 
As the dock is really rare, tablet-jack is enough. But of course with a dock this tablet is a good toy, as we can write a simple script to detect the GPIO(docked and play music).
I will have a try later.
Comment 41 Hans de Goede 2021-08-15 15:58:39 UTC
I've just completed adding jack-detect support for both jacks, also differentiating between headsets vs headphones for both jacks, see:

https://lore.kernel.org/alsa-devel/20210815154935.101178-1-hdegoede@redhat.com/T/#t

These patches are also sitting in the main branch of my tree:
https://github.com/jwrdegoede/linux-sunxi/commits/main

And the matching alsa-ucm changes, which you also need are here:
https://github.com/jwrdegoede/alsa-ucm-conf/commits/master